package com.zksy.web.controller.WaterSupply.DeviceAbnormal;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.base.domain.vo.AbnormalDeviceVO;
import com.zksy.base.service.WaterSupplyDeviceService;
import com.zksy.common.annotation.Log;
import com.zksy.common.core.domain.AjaxResult;
import com.zksy.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/waterSupply/device/abnormal")
@Api(tags = "供水设备-异常管理")
public class DeviceAbnormalController {

    @Autowired
    private WaterSupplyDeviceService waterSupplyDeviceService;

    @GetMapping("/page")
    @ApiOperation("异常设备分页查询")
    @PreAuthorize("@ss.hasPermi('waterSupply:device:abnormal:list')")
    public AjaxResult getAbnormalDevicePage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") long pageNum,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") long pageSize,
            @ApiParam("设备名称") @RequestParam(required = false) String equipmentName,
            @ApiParam("设备编码") @RequestParam(required = false) String equipmentCode,
            @ApiParam("设备类型ID") @RequestParam(required = false) String equipmentTypeId,
            @ApiParam("告警等级 1-4") @RequestParam(required = false) Integer alertLevel) {
        Page<AbnormalDeviceVO> page = waterSupplyDeviceService.getAbnormalDevicePage(
                pageNum, pageSize, equipmentName, equipmentCode, equipmentTypeId, alertLevel);
        return AjaxResult.success(page);
    }

    @GetMapping("/gisPoints")
    @ApiOperation("获取异常设备GIS点位（地图高亮用）")
    @PreAuthorize("@ss.hasPermi('waterSupply:device:abnormal:list')")
    public AjaxResult getAbnormalGisPoints(
            @ApiParam("设备类型ID") @RequestParam(required = false) String equipmentTypeId) {
        List<AbnormalDeviceVO> list = waterSupplyDeviceService.getAbnormalDeviceGisPoints(equipmentTypeId);
        return AjaxResult.success(list);
    }

    @PostMapping("/export")
    @ApiOperation("导出异常设备台账")
    @Log(title = "导出异常设备", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('waterSupply:device:abnormal:export')")
    public AjaxResult exportAbnormalDevices(
            @ApiParam("设备名称") @RequestParam(required = false) String equipmentName,
            @ApiParam("设备编码") @RequestParam(required = false) String equipmentCode,
            @ApiParam("设备类型ID") @RequestParam(required = false) String equipmentTypeId,
            @ApiParam("告警等级") @RequestParam(required = false) Integer alertLevel) {
        log.info("导出异常设备：name={}, code={}, typeId={}, level={}",
                equipmentName, equipmentCode, equipmentTypeId, alertLevel);
        return AjaxResult.success("导出功能待对接EasyExcel");
    }
}
