package com.ruoyi.web.controller.doubleDefense;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.doubledefense.dto.DeviceDTO;
import com.ruoyi.doubledefense.dto.res.DeviceResultDTO;
import com.ruoyi.doubledefense.service.IDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 设备设施Controller
 *
 * @author ruoyi
 * @date 2023-08-03
 */
@Api(tags = "设备设施相关接口")
@RestController
@RequestMapping("/doubledefense/device")
public class DeviceController extends BaseController {
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询设备设施列表
     */
    @ApiOperation("查询设备设施列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceDTO device) {
        startPage();
        List<DeviceResultDTO> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    /**
     * 导出设备设施列表
     */
    @ApiOperation("导出设备设施列表")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:device:export')")
    @Log(title = "设备设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceDTO device) {
        List<DeviceResultDTO> list = deviceService.selectDeviceList(device);
        ExcelUtil<DeviceResultDTO> util = new ExcelUtil<DeviceResultDTO>(DeviceResultDTO.class);
        util.exportExcel(response, list, "设备设施数据");
    }

    /**
     * 获取设备设施详细信息
     */
    @ApiOperation("获取设备设施详细信息")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(deviceService.selectDeviceById(id));
    }

    /**
     * 新增设备设施
     */
    @ApiOperation("新增设备设施")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", value = "设备编号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "deviceName", value = "设备名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "deptId", value = "所属部门ID", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "areaId", value = "区域ID", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
            @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
            @ApiImplicitParam(name = "deviceType", value = "设备类型，1视频监控，2应急物资，3安全仪表，4安全阀，5可燃有毒气体检测报警器，6特种设备，7消防设施，8其他", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "expirationDate", value = "过期时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "status", value = "启停状态：0-启动；1-停用；2-保养；3-保障；4-维修；5-报废；(原->0启用，1停用，2报废)", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "remarkInfo", value = "备注", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:device:add')")
    @Log(title = "设备设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceDTO device) {
        return toAjax(deviceService.insertDevice(device));
    }

    /**
     * 修改设备设施
     */
    @ApiOperation("修改设备设施")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "deviceCode", value = "设备编号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "deviceName", value = "设备名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "deptId", value = "所属部门ID", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "areaId", value = "区域ID", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
            @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
            @ApiImplicitParam(name = "deviceType", value = "设备类型，1视频监控，2应急物资，3安全仪表，4安全阀，5可燃有毒气体检测报警器，6特种设备，7消防设施，8其他", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "expirationDate", value = "过期时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "status", value = "启停状态：0-启动；1-停用；2-保养；3-保障；4-维修；5-报废；(原->0启用，1停用，2报废)", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "remarkInfo", value = "备注", dataType = "String", dataTypeClass = String.class)
    })
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:device:edit')")
    @Log(title = "设备设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceDTO device) {
        return toAjax(deviceService.updateDevice(device));
    }

    /**
     * 删除设备设施
     */
    @ApiOperation("删除设备设施")
    //TODO 20230920PreAuthorize("@ss.hasPermi('doubledefense:device:remove')")
    @Log(title = "设备设施", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(deviceService.deleteDeviceByIds(ids));
    }
}
