package com.aucma.dms.controller;

//import com.hw.common.core.utils.poi.ExcelUtil;
//import com.hw.common.core.web.controller.BaseController;
//import com.hw.common.core.web.domain.AjaxResult;
//import com.hw.common.core.web.page.TableDataInfo;
//import com.hw.common.log.annotation.Log;
//import com.hw.common.log.enums.BusinessType;
//import com.hw.common.security.annotation.RequiresPermissions;
//import com.aucma.dms.domain.DmsBaseDeviceInstall;
//import com.aucma.dms.domain.DmsBaseDeviceLedger;
//import com.aucma.dms.service.IDmsBaseDeviceInstallService;
//import com.aucma.dms.service.IDmsBaseDeviceLedgerService;

import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.core.page.TableDataInfo;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.dms.domain.DmsBaseDeviceInstall;
import com.aucma.dms.domain.DmsBaseDeviceLedger;
import com.aucma.dms.service.IDmsBaseDeviceInstallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备安装信息Controller
 * 
 * @author xins
 * @date 2024-01-02
 */
@RestController
@RequestMapping("/dms/install")
public class DmsBaseDeviceInstallController extends BaseController
{
    @Autowired
    private IDmsBaseDeviceInstallService dmsBaseDeviceInstallService;



    /**
     * 查询设备安装信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:install:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsBaseDeviceInstall dmsBaseDeviceInstall)
    {
        startPage();
        List<DmsBaseDeviceInstall> list = dmsBaseDeviceInstallService.selectDmsBaseDeviceInstallList(dmsBaseDeviceInstall);
        return getDataTable(list);
    }

    /**
     * 导出设备安装信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:install:export')" )
    //@Log(title = "设备安装信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsBaseDeviceInstall dmsBaseDeviceInstall)
    {
        List<DmsBaseDeviceInstall> list = dmsBaseDeviceInstallService.selectDmsBaseDeviceInstallList(dmsBaseDeviceInstall);
        ExcelUtil<DmsBaseDeviceInstall> util = new ExcelUtil<DmsBaseDeviceInstall>(DmsBaseDeviceInstall.class);
        util.exportExcel(response, list, "设备安装信息数据");
    }

    /**
     * 获取设备安装信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:install:query')" )
    @GetMapping(value = "/{deviceInstallId}")
    public AjaxResult getInfo(@PathVariable("deviceInstallId") Long deviceInstallId)
    {
        return success(dmsBaseDeviceInstallService.selectDmsBaseDeviceInstallByDeviceInstallId(deviceInstallId));
    }

    /**
     * 新增设备安装信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:install:add')" )
    //@Log(title = "设备安装信息", businessType = BusinessType.INSERT)
    @PostMapping
    @Transactional
    public AjaxResult add(@RequestBody DmsBaseDeviceInstall dmsBaseDeviceInstall)
    {
        //添加设备安装记录时，也会更新设备台账中的设备位置
        DmsBaseDeviceLedger dmsBaseDeviceLedger = new DmsBaseDeviceLedger();
        dmsBaseDeviceLedger.setDeviceLocation(dmsBaseDeviceInstall.getInstallPosition());
        dmsBaseDeviceLedger.setDeviceId(dmsBaseDeviceInstall.getDeviceId());

        return toAjax(dmsBaseDeviceInstallService.insertDmsBaseDeviceInstall(dmsBaseDeviceInstall));
    }

    /**
     * 修改设备安装信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:install:edit')" )
    //@Log(title = "设备安装信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsBaseDeviceInstall dmsBaseDeviceInstall)
    {
        return toAjax(dmsBaseDeviceInstallService.updateDmsBaseDeviceInstall(dmsBaseDeviceInstall));
    }

    /**
     * 删除设备安装信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:install:remove')" )
    //@Log(title = "设备安装信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceInstallIds}")
    public AjaxResult remove(@PathVariable Long[] deviceInstallIds)
    {
        return toAjax(dmsBaseDeviceInstallService.deleteDmsBaseDeviceInstallByDeviceInstallIds(deviceInstallIds));
    }
}
