package com.casic.missiles.modular.system.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.casic.missiles.core.application.context.AbstractPermissionContext;
import com.casic.missiles.core.base.controller.ExportController;
import com.casic.missiles.core.common.annotion.Permission;
import com.casic.missiles.core.datascope.DataScope;
import com.casic.missiles.core.page.PageFactory;
import com.casic.missiles.model.response.ResponseData;
import com.casic.missiles.modular.system.dto.AlarmDeptStaticsDto;
import com.casic.missiles.modular.system.dto.ExcelModel.*;
import com.casic.missiles.modular.system.enums.DeviceExportEnum;
import com.casic.missiles.modular.system.service.IDataAnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

/**
 * 设备相关数据查询
 *
 * @author lwh
 */
@Slf4j
@RestController
public class DeviceWellDataController extends ExportController {
    @Resource
    private IDataAnalysisService deviceService;
    @Resource
    private AbstractPermissionContext permissionService;


    @GetMapping(value = "/welldata/list-page")
    @Permission
    public Object wellDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<WellCoverDataDto> page = PageFactory.defaultPage();
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<WellCoverDataDto> wellCoverDataDtoList = deviceService.selectWellDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        wellCoverDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        page.setRecords(wellCoverDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    /**
     * 井盖状态检测仪
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/welldata/export")
    @Permission
    public void batchExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {

        Page<WellCoverDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<WellCoverDataDto> wellCoverDataDtoList = deviceService.selectWellDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        wellCoverDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        super.exportExcel(WellCoverDataDto.class, wellCoverDataDtoList, DeviceExportEnum.WELLDATA_EXPORT.getFileName());

    }

    /**
     * 井盖液位一体化列表
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/wellliquiddata/list-page")
    @Permission
    public Object wellliquiddataListPage(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<DataWellLiquidDto> page = PageFactory.defaultPage();
        if (CollectionUtil.isEmpty(page.orders())) {
            OrderItem orderItem = new OrderItem();
            orderItem.setColumn("UPTIME");
            orderItem.setAsc(false);
            page.addOrder(orderItem);
        }
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataWellLiquidDto> deviceDataDtoList = deviceService.getWellliquiddataList(dataScope, page, deptid, beginTime, endTime, keywords);
        deviceDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        page.setRecords(deviceDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    /**
     * 井盖液位一体化导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/wellliquiddata/export")
    @Permission
    public void wellliquiddataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<DataWellLiquidDto> page = PageFactory.defaultPage();
        if (CollectionUtil.isEmpty(page.orders())) {
            OrderItem orderItem = new OrderItem();
            orderItem.setColumn("UPTIME");
            orderItem.setAsc(false);
            page.addOrder(orderItem);
        }
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataWellLiquidDto> deviceDataDtoList = deviceService.getWellliquiddataList(dataScope, page, deptid, beginTime, endTime, keywords);
        deviceDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        super.exportExcel(DataWellLiquidDto.class, deviceDataDtoList, DeviceExportEnum.WELLLIQUIDDATA_EXPORT.getFileName());
    }


    /**
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/liquiddata/list-page")
    public Object liquidDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<LiquidDataExcelDto> page = PageFactory.defaultPage();
        if (CollectionUtil.isEmpty(page.orders())) {
            OrderItem orderItem = new OrderItem();
            orderItem.setColumn("UPTIME");
            orderItem.setAsc(false);
            page.addOrder(orderItem);
        }
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<LiquidDataExcelDto> deviceDataDtoList = deviceService.selectLiquidDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        deviceDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        page.setRecords(deviceDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    /**
     * 液体导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/liquiddata/export")
    @Permission
    public void liquidDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<LiquidDataExcelDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<LiquidDataExcelDto> deviceDataDtoList = deviceService.selectLiquidDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        deviceDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        super.exportExcel(LiquidDataExcelDto.class, deviceDataDtoList, DeviceExportEnum.LIQUIDDATA_EXPORT.getFileName());
    }

    @GetMapping(value = "/gasdata/list-page")
    @Permission
    public Object gasDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<DeviceDataExcelDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DeviceDataExcelDto> deviceDataDtoList = deviceService.selectGasDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        deviceDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        page.setRecords(deviceDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    @GetMapping(value = "/tubedata/list-page")
    @Permission
    public Object tubeDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<DeviceDataExcelDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DeviceDataExcelDto> deviceDataDtoList = deviceService.selectTubeDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        deviceDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        page.setRecords(deviceDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }


    /**
     * 管盯数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/tubedata/export")
    @Permission
    public void tubeDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<DeviceDataExcelDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();

        List<DeviceDataExcelDto> tubeDatalist = deviceService.selectTubeDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        tubeDatalist.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        super.exportExcel(DeviceDataExcelDto.class, tubeDatalist, DeviceExportEnum.TUBEDATA_EXPORT.getFileName());
    }

    /**
     * 燃气数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/gasdata/export")
    public void gasDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<DeviceDataExcelDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DeviceDataExcelDto> deviceDataList = deviceService.selectGasDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        deviceDataList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        //TODO 导出表头设置
        super.exportExcel(DeviceDataExcelDto.class, deviceDataList, DeviceExportEnum.GASDATA_EXPORT.getFileName());
    }


    /**
     * 有害气体数据查询
     *
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/harmfuldata/list-page")
    public Object harmfulDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<HarmfulDataDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<HarmfulDataDto> harmfulDataDtoList = deviceService.selectHarmfulDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        harmfulDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        page.setRecords(harmfulDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    /**
     * 有害气体数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/harmfuldata/export")
    public void harmfulDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<HarmfulDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<HarmfulDataDto> harmfulDataDtoList = deviceService.selectHarmfulDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        harmfulDataDtoList.forEach(harmfulDataDto -> {
            harmfulDataDto.setDeptName(permissionService.getDeptService().getDeptName(harmfulDataDto.getDeptid()));
        });
        //TODO 导出表头设置
        super.exportExcel(HarmfulDataDto.class, harmfulDataDtoList, DeviceExportEnum.HARMFULDATA_EXPORT.getFileName());
    }

    /**
     * 温湿度数据查询
     *
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/tempdata/list-page")
    public Object tempDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<TemhumDataDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<TemhumDataDto> mapList = deviceService.selectTempDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        mapList.forEach(temhumDataDto -> {
            temhumDataDto.setDeptName(permissionService.getDeptService().getDeptName(temhumDataDto.getDeptid()));
        });
        page.setRecords(mapList);
        return ResponseData.success(super.packForBT(page));
    }


    /**
     * 温湿度压力数据查询
     *
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/temppressdata/list-page")
    public Object tempPressdataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<TemppressDataDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<TemppressDataDto> temppressDataDtoList = deviceService.selectTempPressDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        temppressDataDtoList.forEach(temppressDataDto -> {
            temppressDataDto.setDeptName(permissionService.getDeptService().getDeptName(temppressDataDto.getDeptid()));
        });
        page.setRecords(temppressDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }


    /**
     * 温度压力数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/temppressdata/export")
    public void temppressDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<TemppressDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<TemppressDataDto> temppressDataDtoList = deviceService.selectTempPressDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        temppressDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        super.exportExcel(TemppressDataDto.class, temppressDataDtoList, DeviceExportEnum.TEMPPRESSDATA_EXPORT.getFileName());
    }


    //TODO 导出表头设置


    /**
     * 温湿度数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/tempdata/export")
    public void tempDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<TemhumDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<TemhumDataDto> temhumDataDtoList = deviceService.selectTempDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        temhumDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        //TODO 导出表头设置
        super.exportExcel(TemhumDataDto.class, temhumDataDtoList, DeviceExportEnum.TEMPDATA_EXPORT.getFileName());
    }

    /**
     * 开挖监测仪数据查询
     *
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/digdata/list-page")
    public Object digDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<DigNoiseDataDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DigNoiseDataDto> digNoiseDataDtoList = deviceService.selectDigDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        digNoiseDataDtoList.forEach(digNoiseDataDto -> {
            digNoiseDataDto.setDeptName(permissionService.getDeptService().getDeptName(digNoiseDataDto.getDeptid()));
        });
        page.setRecords(digNoiseDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    /**
     * 开挖监测仪数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/digdata/export")
    public void digDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<DigNoiseDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DigNoiseDataDto> digNoiseDataDtoList = deviceService.selectDigDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        digNoiseDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        //TODO 导出表头设置
        super.exportExcel(DigNoiseDataDto.class, digNoiseDataDtoList, DeviceExportEnum.DIGDATA_EXPORT.getFileName());
    }

    /**
     * 井盖定位监测仪数据查询
     *
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/welllocadata/list-page")
    public Object wellLocDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<WellAppointDataDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<WellAppointDataDto> wellAppointDataDtoList = deviceService.selectWellLocDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        wellAppointDataDtoList.forEach(wellAppointDataDto -> {
            wellAppointDataDto.setDeptName(permissionService.getDeptService().getDeptName(wellAppointDataDto.getDeptid()));
        });
        page.setRecords(wellAppointDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    /**
     * 井盖定位监测仪数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/welllocadata/export")
    public void wellLocDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<WellAppointDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<WellAppointDataDto> wellAppointDataDtoList = deviceService.selectWellLocDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        wellAppointDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        //TODO 导出表头设置
        super.exportExcel(WellAppointDataDto.class, wellAppointDataDtoList, DeviceExportEnum.WELLLOCDATA_EXPORT.getFileName());
    }

    /**
     * 噪声记录仪数据查询
     *
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/noisedata/list-page")
    public Object noiseDataList(String keywords, String deptid, String beginTime, String endTime) {
        Page<DigNoiseDataDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DigNoiseDataDto> digNoiseDataDtoList = deviceService.selectNoiseDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        digNoiseDataDtoList.forEach(digNoiseDataDto -> {
            digNoiseDataDto.setDeptName(permissionService.getDeptService().getDeptName(digNoiseDataDto.getDeptid()));
        });
        page.setRecords(digNoiseDataDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    /**
     * 噪声记录仪数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/noisedata/export")
    public void noiseDataExport(HttpServletResponse response, String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<DigNoiseDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DigNoiseDataDto> digNoiseDataDtoList = deviceService.selectNoiseDataScopePage(dataScope, page, deptid, beginTime, endTime, keywords);
        digNoiseDataDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        //TODO 导出表头设置
        super.exportExcel(DigNoiseDataDto.class, digNoiseDataDtoList, DeviceExportEnum.NOISEDATA_EXPORT.getFileName());
    }


    /**
     * 根据权属单位统计报警次数
     *
     * @param deviceType
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/statics/alarmsByDept")
    @Permission
    public Object alarmsByDept(Long deviceType, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        //根据权属单位查询告警次数及告警设备数
        List<AlarmDeptStaticsDto> list = deviceService.alarmsStaticsByDept(deviceType, beginTime, endTime, dataScope,
                permissionService.getAuthService().getLoginUser().getDeptId());
        return ResponseData.success(list);
    }


    /**
     * 燃气液位一体化数据查询
     *
     * @param keywords
     * @param deptid
     * @param sensorType
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping(value = "/liquidGasData/list-page")
    public Object liquidGasDataList(String keywords, String deptid, String sensorType, String beginTime, String endTime) {
        Page<GasLiquidDataExcelDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<GasLiquidDataExcelDto> deviceDataExcelDtoList = deviceService.selectGasLiquidDataScopePage(dataScope, page, sensorType, deptid, beginTime, endTime, keywords);
        deviceDataExcelDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        page.setRecords(deviceDataExcelDtoList);
        return ResponseData.success(super.packForBT(page));
    }

    /**
     * 燃气液位一体化数据导出
     *
     * @param response
     * @param keywords
     * @param deptid
     * @param sensorType
     * @param beginTime
     * @param endTime
     * @throws IOException
     */
    @GetMapping(value = "/liquidGasData/export")
    public void liquidGasDataExport(HttpServletResponse response, String keywords, String deptid, String sensorType, String beginTime, String endTime) throws IOException {
        Page<GasLiquidDataExcelDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<GasLiquidDataExcelDto> deviceDataExcelDtoList = deviceService.selectGasLiquidDataScopePage(dataScope, page, sensorType, deptid, beginTime, endTime, keywords);
        deviceDataExcelDtoList.forEach(deviceDataExcelDto -> {
                    if ("gas".equals(sensorType)) {
                        Double dValue = Double.valueOf(StrUtil.isEmpty(deviceDataExcelDto.getData()) ? "0" : deviceDataExcelDto.getData());
                        if (dValue <= 20.0) {
                            deviceDataExcelDto.setData(dValue + "%LEL");
                        } else {
                            DecimalFormat df = new DecimalFormat("0.00");
                            dValue = dValue / 20.0;
                            deviceDataExcelDto.setData(df.format(dValue) + "%VOL");
                        }
                    }
                }
        );
        //TODO 导出表头设置
        deviceDataExcelDtoList.forEach(deviceDto -> {
            deviceDto.setDeptName(permissionService.getDeptService().getDeptName(deviceDto.getDeptid()));
        });
        //TODO 导出表头设置
        super.exportExcel(GasLiquidDataExcelDto.class, deviceDataExcelDtoList, DeviceExportEnum.LIQUIDGASDATA_EXPORT.getFileName());
    }


    /**
     * 数据列表查询
     */
    @GetMapping(value = "/data/list")
    public Object dataList(String wellCode, String watchType, String beginTime, String endTime) {
        if (StrUtil.isEmpty(watchType)) {
            return ResponseData.success("缺少监测类型参数，请重传");
        }
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<Map<String, Object>> mapList = deviceService.selectDataList(dataScope, wellCode, watchType, beginTime, endTime);
        mapList.forEach(deviceDto -> {
            deviceDto.put("deptName", permissionService.getDeptService().getDeptName(deviceDto.get("deptid").toString()));
        });
        return ResponseData.success(mapList);
    }

    /**
     * 消防栓列表
     */
    @GetMapping(value = "/hydrant/list-page")
    public Object hydrantlist(String keywords, String deptid, String beginTime, String endTime) {
        Page<HydrantDataDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        ResponseData responseData = deviceService.getHydrantlist(dataScope, page, deptid, beginTime, endTime, keywords);
        responseData.setData(super.packForBT(page));
        return responseData;
    }

    /**
     * 消防栓导出
     */
    @GetMapping(value = "/hydrant/export")
    public void hydrantExport(String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<HydrantDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        deviceService.getHydrantlist(dataScope, page, deptid, beginTime, endTime, keywords);
        super.exportExcel(HydrantDataDto.class, page.getRecords(), DeviceExportEnum.HYDRANT_EXPORT.getFileName());
    }

    /**
     * 硫化氢列表
     */
    @GetMapping(value = "/h2s/list-page")
    public Object h2sList(String keywords, String deptid, String beginTime, String endTime) {
        Page<H2SDataDto> page = PageFactory.defaultPage();
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        ResponseData responseData = deviceService.getH2slist(dataScope, page, keywords, beginTime, endTime, deptid);
        responseData.setData(super.packForBT(page));
        return responseData;
    }

    /**
     * 硫化氢栓导出
     */
    @GetMapping(value = "/h2s/export")
    public void h2sExport(String keywords, String deptid, String beginTime, String endTime) throws IOException {
        Page<H2SDataDto> page = PageFactory.defaultPage();
        page.setCurrent(1);
        page.setSearchCount(false);
        page.setSize(Integer.MAX_VALUE);
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        deviceService.getH2slist(dataScope, page, deptid, beginTime, endTime, keywords);
        super.exportExcel(H2SDataDto.class, page.getRecords(), DeviceExportEnum.H2S_EXPORT.getFileName());
    }

}
