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.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.DmsBaseDeviceLedger;
import com.aucma.dms.domain.DmsBaseTransferInfo;
import com.aucma.dms.service.IDmsBaseTransferInfoService;
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/info")
public class DmsBaseTransferInfoController extends BaseController
{
    @Autowired
    private IDmsBaseTransferInfoService dmsBaseTransferInfoService;


    /**
     * 查询设备转移信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:info:list')" )
    @GetMapping("/list")
    public TableDataInfo list(DmsBaseTransferInfo dmsBaseTransferInfo)
    {
        startPage();
        List<DmsBaseTransferInfo> list = dmsBaseTransferInfoService.selectDmsBaseTransferInfoList(dmsBaseTransferInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备转移信息列表
     */
    //@PreAuthorize("@ss.hasPermi('dms:info:export')" )
    //@Log(title = "设备转移信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsBaseTransferInfo dmsBaseTransferInfo)
    {
        List<DmsBaseTransferInfo> list = dmsBaseTransferInfoService.selectDmsBaseTransferInfoList(dmsBaseTransferInfo);
        ExcelUtil<DmsBaseTransferInfo> util = new ExcelUtil<DmsBaseTransferInfo>(DmsBaseTransferInfo.class);
        util.exportExcel(response, list, "设备转移信息数据");
    }

    /**
     * 获取设备转移信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:info:query')" )
    @GetMapping(value = "/{transferInfoId}")
    public AjaxResult getInfo(@PathVariable("transferInfoId") Long transferInfoId)
    {
        return success(dmsBaseTransferInfoService.selectDmsBaseTransferInfoByTransferInfoId(transferInfoId));
    }

    /**
     * 新增设备转移信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:info:add')" )
    //@Log(title = "设备转移信息", businessType = BusinessType.INSERT)
    @PostMapping
    @Transactional
    public AjaxResult add(@RequestBody DmsBaseTransferInfo dmsBaseTransferInfo)
    {
        //转移时修改设备信息
        DmsBaseDeviceLedger dmsBaseDeviceLedger = new DmsBaseDeviceLedger();
        dmsBaseDeviceLedger.setDeviceId(dmsBaseTransferInfo.getDeviceId());
        dmsBaseDeviceLedger.setDeviceLocation(dmsBaseTransferInfo.getDevicePositionNew());

        return toAjax(dmsBaseTransferInfoService.insertDmsBaseTransferInfo(dmsBaseTransferInfo));
    }

    /**
     * 修改设备转移信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:info:edit')" )
    //@Log(title = "设备转移信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsBaseTransferInfo dmsBaseTransferInfo)
    {
        //转移时修改设备信息
        DmsBaseDeviceLedger dmsBaseDeviceLedger = new DmsBaseDeviceLedger();
        dmsBaseDeviceLedger.setDeviceId(dmsBaseTransferInfo.getDeviceId());
        dmsBaseDeviceLedger.setDeviceLocation(dmsBaseTransferInfo.getDevicePositionNew());

        return toAjax(dmsBaseTransferInfoService.updateDmsBaseTransferInfo(dmsBaseTransferInfo));
    }

    /**
     * 删除设备转移信息
     */
    //@PreAuthorize("@ss.hasPermi('dms:info:remove')" )
    //@Log(title = "设备转移信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{transferInfoIds}")
    public AjaxResult remove(@PathVariable Long[] transferInfoIds)
    {
        return toAjax(dmsBaseTransferInfoService.deleteDmsBaseTransferInfoByTransferInfoIds(transferInfoIds));
    }
}
