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

import com.alibaba.druid.util.StringUtils;
import com.casic.missiles.core.application.context.AbstractPermissionContext;
import com.casic.missiles.core.datascope.DataScope;
import com.casic.missiles.model.response.ResponseData;
import com.casic.missiles.modular.system.dto.statistic.*;
import com.casic.missiles.modular.system.service.DeviceDataListService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
public class DeviceDataListController {
    @Resource
    private AbstractPermissionContext permissionService;
    @Resource
    private DeviceDataListService deviceDataListService;


    @GetMapping(value = "/welldata/list")
    public Object wellDataList(String devcode, String wellCode, String beginTime, String endTime) {
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataWellCover> list = deviceDataListService.selectWellDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(list);
    }

    /**
     * 开挖监测仪数据查询
     *
     * @param devcode
     * @param wellCode
     * @param beginTime
     * @param endTime
     * @return
     */
    //@Permission
    @GetMapping(value = "/digdata/list")
    public Object digDataList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataDig> mapList = deviceDataListService.selectDigDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(mapList);
    }


    @GetMapping(value = "/liquiddata/list")
    //@Permission
    public Object liquidDataList(String devcode, String wellCode, String beginTime, String endTime) {
        //查询数据权限 使用默认DEPTID 字段
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataLiquid> list = deviceDataListService.selectLiquidDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(list);
    }


    @GetMapping(value = "/gasdata/list")
    public Object gasDataList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataGas> deviceDataExcelDtoList = deviceDataListService.selectGasDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(deviceDataExcelDtoList);
    }

    @GetMapping(value = "/noisedata/list")
    public Object noiseDataList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataNoise> mapList = deviceDataListService.selectNoiseDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(mapList);
    }

    @GetMapping(value = "/harmfuldata/list")
    public Object harmfulDataList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataHarmfulGas> mapList = deviceDataListService.selectHarmfulDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(mapList);
    }

    @GetMapping(value = "/tempdata/list")
    public Object tempDataList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataTempHum> mapList = deviceDataListService.selectTempDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(mapList);
    }

    @GetMapping(value = "/welllocadata/list")
    public Object wellLocDataList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataWellCoverLoca> mapList = deviceDataListService.selectWellLocDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(mapList);
    }

    @GetMapping(value = "/liquidGasData/list")
    public Object liquidGasDataList(String devcode, String wellCode, String sensorType, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataGasLiquid> mapList = deviceDataListService.selectGasLiquidDataScope(dataScope, sensorType, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(mapList);
    }

    @GetMapping(value = "/tubedata/list")
    //@Permission
    public Object tubeDataList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DateTube> mapList = deviceDataListService.selectTubeDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(mapList);
    }

    /**
     * 消防栓列表
     */
    @GetMapping(value = "/hydrant/list")
    public Object hydrantList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataHydrant> mapList = deviceDataListService.getHydrantlist(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(mapList);
    }

    /**
     * 硫化氢列表
     */
    @GetMapping(value = "/h2s/list")
    public Object h2sList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataH2s> mapList = deviceDataListService.getH2sDataScope(dataScope, devcode, beginTime, endTime, wellCode);
        for (DataH2s dataH2s : mapList) {
            dataH2s.setStrength(!StringUtils.isEmpty(dataH2s.getStrength()) &&
                    Float.valueOf(dataH2s.getStrength()) >= 100 ? "浓度溢出" : dataH2s.getStrength());
        }
        return ResponseData.success(mapList);
    }

    /**
     * 燃气列表
     */
    @GetMapping(value = "/gasdector/list")
    public Object gasdectorList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataGasdector> dataGasdectorList = deviceDataListService.getGasdectorList(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(dataGasdectorList);
    }

    /**
     * 硫化氢列表
     */
    @GetMapping(value = "/pantilt/list")
    public Object pantiltList(String devcode, String wellCode, String beginTime, String endTime) {
        DataScope dataScope = permissionService.getAuthService().getLoginUserDataScope();
        List<DataPantilt> dataPantiltList = deviceDataListService.getPantiltList(dataScope, devcode, beginTime, endTime, wellCode);
        return ResponseData.success(dataPantiltList);
    }

}
