package com.njcn.device.line.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.device.biz.enums.DeviceResponseEnum;
import com.njcn.device.biz.pojo.dto.PollutionLineDTO;
import com.njcn.device.biz.pojo.po.Overlimit;
import com.njcn.device.device.mapper.DeviceMapper;
import com.njcn.device.line.mapper.LineMapper;
import com.njcn.device.line.service.LineService;
import com.njcn.device.line.mapper.LineDetailMapper;
import com.njcn.device.overlimit.service.IOverLimitService;
import com.njcn.device.pq.pojo.dto.OverLimitLineDTO;
import com.njcn.device.pq.pojo.dto.PollutionParamDTO;
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
import com.njcn.device.pq.pojo.dto.WarningSubstationDTO;
import com.njcn.device.pq.pojo.param.*;
import com.njcn.device.pq.pojo.po.Device;
import com.njcn.device.pq.pojo.po.Line;
import com.njcn.device.pq.pojo.po.LineDetail;
import com.njcn.device.pq.pojo.vo.*;
import com.njcn.device.rstatintegrity.mapper.RStatIntegrityDMapper;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * @author denghuajun
 * @date 2022/2/23
 * 监测点相关
 */
@Slf4j
@Api(tags = "监测点管理")
@RestController
@RequestMapping("/line")
@RequiredArgsConstructor
public class LineController extends BaseController {

    private final LineService lineService;

    private final DeviceMapper deviceMapper;

    private final LineMapper lineMapper;

    private final LineDetailMapper lineDetailMapper;

    private final RStatIntegrityDMapper integrityDMapper;

    private final IOverLimitService overLimitService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineDetailData")
    @ApiOperation("根据监测点id获取监测点详情")
    @ApiImplicitParam(name = "id", value = "监测点id", required = true)
    public HttpResult<LineDetailDataVO> getLineDetailData(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getLineDetailData");
        LineDetailDataVO result = lineService.getLineDetailData(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据装置id获取装置详情")
    @ApiImplicitParam(name = "id", value = "装置id", required = true)
    @PostMapping("/getDeviceDetailData")
    HttpResult<DeviceVO> getDeviceDetailData(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("getDeviceDetailData");
        DeviceVO result = lineService.getDeviceDetailData(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getSubstationData")
    @ApiOperation("根据变电站id获取变电站详情")
    @ApiImplicitParam(name = "id", value = "监测点id", required = true)
    public HttpResult<List<SubstationDetailVO>> getSubstationData(@RequestBody List<String> id) {
        String methodDescribe = getMethodDescribe("getSubstationData");
        List<SubstationDetailVO> result = lineService.getSubstationData(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 根据变电站id获取子节数据
     *
     * @param id 变电站id
     * @return 结果
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据变电站id获取子节数据")
    @PostMapping("getSubIndexLineDetail")
    public HttpResult<List<Line>> getSubIndexLineDetail(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("getSubIndexLineDetail");
        List<Line> result = lineService.getSubIndexLineDetail(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    };

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getComFlagInfoData")
    @ApiOperation("根据监测点Id终端状态信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "监测点id", required = true),
            @ApiImplicitParam(name = "searchBeginTime", value = "起始时间"),
            @ApiImplicitParam(name = "searchEndTime", value = "截止时间")
    })
    public HttpResult<CommunicateVO> getComFlagInfoData(@RequestParam(required = false) @ApiParam("id") String id,
                                                        @RequestParam("searchBeginTime") String searchBeginTime,
                                                        @RequestParam("searchEndTime") String searchEndTime) {
        String methodDescribe = getMethodDescribe("getComFlagInfoData");
        CommunicateVO result = lineService.getComFlagInfoData(id, searchBeginTime, searchEndTime);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineIdByDevId")
    @ApiOperation("根据监测点Id终端状态信息")
    @ApiImplicitParam(name = "id", value = "监测点id", required = true)
    public HttpResult<String> getLineIdByDevId(@RequestParam(required = false) @ApiParam("id") String id) {
        String methodDescribe = getMethodDescribe("getComFlagInfoData");
        String result = lineService.getLineIdByDevId(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDevListByLineIdList")
    @ApiOperation("根据监测点id集合获取装置id集合")
    @ApiImplicitParam(name = "list", value = "监测点id集合", required = true)
    public HttpResult<Set<String>> getDevListByLineIdList(@RequestBody List<String> list) {
        String methodDescribe = getMethodDescribe("getDevListByLineIdList");
        Set<String> result = lineService.getDevListByLineIdList(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 获取投运在线的监测点的限值
     *
     * @author cdf
     * @date 2022/3/23
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getAllLineOverLimit")
    @ApiOperation("获取投运在线的监测点的限值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serverName", value = "服务名称", required = true),
            @ApiImplicitParam(name = "deptId", value = "部门id")
    })
    public HttpResult<List<Overlimit>> getAllLineOverLimit(@RequestParam("serverName") String serverName, @RequestParam(value = "deptId", required = false) String deptId) {
        String methodDescribe = getMethodDescribe("getAllLineOverLimit");
        List<Overlimit> result = overLimitService.getAllLineOverLimit(serverName, deptId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getAllLine")
    @ApiOperation("获取所有监测点")
    @ApiImplicitParam(name = "id", value = "监测点集合", required = true)
    public HttpResult<List<LineDeviceStateVO>> getAllLine(@RequestBody List<String> id) {
        String methodDescribe = getMethodDescribe("getAllLine");
        List<LineDeviceStateVO> result = lineMapper.getLineDeviceStateVO(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDeviceState")
    @ApiOperation("获取变电站详情(pq_line)")
    @ApiImplicitParam(name = "id", value = "变电站id", required = true)
    public HttpResult<Integer> getDeviceState(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getDeviceState");
        String result = lineService.getLineIdByDevId(id);
        Device device = deviceMapper.selectById(result);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, device.getComFlag(), methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getSubstationInfo")
    @ApiOperation("获取变电站信息")
    @ApiImplicitParam(name = "id", value = "变电站id", required = true)
    @ApiIgnore
    public HttpResult<PollutionSubstationDTO> getSubstationInfo(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getSubstationInfo");
        LogUtil.njcnDebug(log, "{}，变电站id：{}", methodDescribe, id);
        PollutionSubstationDTO pollutionSubstation = lineService.getSubstationInfo(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pollutionSubstation, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineInfo")
    @ApiOperation("获取监测点信息")
    @ApiImplicitParam(name = "pollutionParamDTO", value = "对象", required = true)
    @ApiIgnore
    public HttpResult<List<PollutionLineDTO>> getLineInfo(@RequestBody PollutionParamDTO pollutionParamDTO) {
        String methodDescribe = getMethodDescribe("getLineInfo");
        LogUtil.njcnDebug(log, "{}，对象：{}", methodDescribe, pollutionParamDTO);
        List<PollutionLineDTO> result = lineService.getLineInfo(pollutionParamDTO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineSubGdDetail")
    @ApiOperation("根据监测点id集合获取详细信息")
    @ApiImplicitParam(name = "id", value = "监测点集合", required = true)
    @ApiIgnore
    public HttpResult<LineDetailVO> getLineSubGdDetail(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getLineSubGdDetail");
        LineDetailVO result = lineMapper.getLineSubGdDetail(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineInfoVO")
    @ApiOperation("根据监测点id集合获取详细信息")
    @ApiIgnore
    public HttpResult<LineDetailVO> getLineInfoVO(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getLineInfoVO");
        LineDetailVO result = lineMapper.getLineInfoVO(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("/updateDeviceRunFlag")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("更新终端运行状态")
    @ApiIgnore
    public HttpResult<Boolean> updateDeviceRunFlag(@RequestParam("deviceId")String deviceId, @RequestParam("status")Integer status){
        String methodDescribe = getMethodDescribe("updateDeviceRunFlag");
        deviceMapper.updateDeviceRunFlag(deviceId,status);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    @PostMapping("/updateLineRunFlag")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("更新监测点运行状态")
    @ApiIgnore
    public HttpResult<Boolean> updateLineRunFlag(@RequestParam("lineId")String lineId, @RequestParam("status")Integer status){
        String methodDescribe = getMethodDescribe("updateLineRunFlag");
        lineDetailMapper.updateLineRunFlag(lineId,status);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }



    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getWarningSub")
    @ApiOperation("获取告警变电站信息")
    @ApiImplicitParam(name = "list", value = "变电站集合", required = true)
    @ApiIgnore
    public HttpResult<List<WarningSubstationDTO>> getWarningSub(@RequestParam("list") List<String> list) {
        String methodDescribe = getMethodDescribe("getWarningSub");
        LogUtil.njcnDebug(log, "{}，变电站集合：{}", methodDescribe, list);
        List<WarningSubstationDTO> result = lineMapper.getWarningSub(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getOverLimitLineInfo")
    @ApiOperation("监测点稳态超标信息")
    @ApiImplicitParam(name = "pollutionParamDTO", value = "实体", required = true)
    public HttpResult<List<OverLimitLineDTO>> getOverLimitLineInfo(@RequestBody PollutionParamDTO pollutionParamDTO) {
        String methodDescribe = getMethodDescribe("getOverLimitLineInfo");
        LogUtil.njcnDebug(log, "{}，变电站集合：{}", methodDescribe, pollutionParamDTO);
        List<OverLimitLineDTO> result = lineMapper.getOverLimitLineInfo(pollutionParamDTO.getLineList());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineList")
    @ApiOperation("获取生成limitRate的监测点")
    @ApiIgnore
    public HttpResult<List<String>> getLineList() {
        String methodDescribe = getMethodDescribe("getLineList");
        List<String> result = lineMapper.getLineList();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getOverLimitByList")
    @ApiOperation("获取监测点限值")
    @ApiImplicitParam(name = "pollutionParamDTO", value = "实体", required = true)
    @ApiIgnore
    public HttpResult<List<Overlimit>> getOverLimitByList(@RequestBody PollutionParamDTO pollutionParamDTO) {
        String methodDescribe = getMethodDescribe("getOverLimitByList");
        LogUtil.njcnDebug(log, "{}，监测点集合：{}", methodDescribe, pollutionParamDTO);
        List<Overlimit> result = lineService.getOverLimitByList(pollutionParamDTO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 获取监测点及以上层的基础信息(含区域信息)
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getBaseLineAreaInfo")
    @ApiOperation("获取监测点及以上层的基础信息(含区域信息)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineIndex", value = "监测点集合", required = true)
    })
    public HttpResult<List<AreaLineInfoVO>> getBaseLineAreaInfo(@RequestBody List<String> lineIndex) {
        String methodDescribe = getMethodDescribe("getBaseLineAreaInfo");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineService.getBaseLineAreaInfo(lineIndex,null,null), methodDescribe);
    }

    /**
     * 获取丰富的监测点信息(扩展模糊查询)
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getRichLineInfo")
    @ApiOperation("获取丰富的监测点信息(扩展模糊查询)")
    @ApiImplicitParam(name = "lineBaseQueryParam", value = "监测点参数", required = true)
    public HttpResult<List<AreaLineInfoVO>> getRichLineInfo(@RequestBody @Validated LineBaseQueryParam lineBaseQueryParam) {
        String methodDescribe = getMethodDescribe("getRichLineInfo");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineService.getBaseLineAreaInfo(lineBaseQueryParam.getLineIds(),lineBaseQueryParam.getSearchValue(),lineBaseQueryParam.getComFlag()), methodDescribe);
    }



    /**
     * 根据监测点ids获取监测点基本信息
     * @author cdf
     * @date 2022/6/30
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getBaseLineList")
    @ApiOperation("获取最基础的监测点信息")
    @ApiImplicitParam(name = "lineIndex", value = "监测点集合", required = true)
    public HttpResult<List<Line>> getBaseLineList(@RequestBody List<String> lineIndex) {
        String methodDescribe = getMethodDescribe("getBaseLineList");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineService.getBaseLineList(lineIndex), methodDescribe);
    }

    /**
     * 功能描述: 获取指定条件的监测点信息
     * @author xy
     * @date 2022/7/8 14:24
     * @return 监测点详情集合
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getLineDetail")
    @ApiOperation("根据监测点集合获取监测点详情")
    @ApiImplicitParam(name = "list", value = "监测点集合")
    @ApiIgnore
    public HttpResult<List<LineDetail>> getLineDetail(@RequestBody(required = false) List<String> list) {
        String methodDescribe = getMethodDescribe("getLineDetail");
        LogUtil.njcnDebug(log, "{}，监测点集合：{}", methodDescribe, list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineDetailMapper.getSpecifyLineDetail(list), methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDeviceList")
    @ApiOperation("获取生成在线率的装置Id")
    @ApiIgnore
    public HttpResult<List<String>> getDeviceList() {
        String methodDescribe = getMethodDescribe("getDeviceList");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineMapper.getDeviceList(), methodDescribe);
    }


    /**
     * 获取当前状态在线的监测点数量
     * @param lineIds 监测点集合
     * @return  在线的监测点数量
     * @author cdf
     * @date 2022/8/1
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getOnLineCount")
    @ApiOperation("获取当前状态在线的监测点数量")
    @ApiImplicitParam(name = "lineIds", value = "监测点集合", required = true)
    public HttpResult<Integer> getOnLineCount(@RequestBody List<String> lineIds) {
        String methodDescribe = getMethodDescribe("getOnLineCount");
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, lineMapper.getOnLineCount(lineIds), methodDescribe);
    }

    /**
     * 获取当前状态在线和离线的监测点
     * @param lineBaseQueryParam 监测点查询参数
     * @return  在线的监测点id集
     * @author cdf
     * @date 2022/8/1
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getOnOrUnLine")
    @ApiOperation("获取当前状态在线和离线的监测点")
    @ApiImplicitParam(name = "lineBaseQueryParam", value = "监测点查询参数", required = true)
    public HttpResult<List<String>> getOnOrUnLine(@RequestBody @Validated LineBaseQueryParam lineBaseQueryParam) {
        String methodDescribe = getMethodDescribe("getOnOrUnLine");
        if(Objects.isNull(lineBaseQueryParam.getComFlag())){
            throw new BusinessException(DeviceResponseEnum.PARAM_VAL_ERR);
        }
        List<String> idsRes = lineMapper.getOnOrUnLine(lineBaseQueryParam.getLineIds(),lineBaseQueryParam.getComFlag());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,idsRes, methodDescribe);
    }




    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDeptLineCount")
    @ApiOperation("根据部门索引，查询出该部门的直接子部门关联的监测点数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceInfoParam", value = "监测点查询条件", required = true)
    })
    public HttpResult<List<DeptLineCountVO>> getDeptLineCount(@RequestBody @Validated DeviceInfoParam deviceInfoParam) {
        String methodDescribe = getMethodDescribe("getDeptLineCount");
        List<DeptLineCountVO> deptLineCountVOS = lineService.getDeptLineCount(deviceInfoParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deptLineCountVOS, methodDescribe);

    }

    @PostMapping("/getLineBySubstationRelation")
    @ApiOperation("获取变电站和监测点的关系（分稳态暂态）")
    @ApiImplicitParam(name = "devDataType", value = "数据类型（0：暂态系统；1：稳态系统；）", required = true)
    public HttpResult<Map<String,List<String>>> getLineBySubstationRelation(@RequestParam("devDataType") Integer devDataType) {
        String methodDescribe = getMethodDescribe("getLineBySubstationRelation");
        Map<String,List<String>> map= lineService.getLineBySubstationRelation(devDataType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, map, methodDescribe);
    }


    /**
     * 获取基础监测点详细信息
     * @author cdf
     * @date 2022/10/26
     */
    @PostMapping("/getLineDetailList")
    @ApiOperation("获取基础监测点详细信息")
    @ApiImplicitParam(name = "lineIds", value = "监测点id集合", required = true)
    public HttpResult<List<LineDetailDataVO>> getLineDetailList(@RequestBody List<String> lineIds) {
        String methodDescribe = getMethodDescribe("getLineDetailList");
        List<LineDetailDataVO> resList= lineService.getLineDetailList(lineIds);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resList, methodDescribe);
    }


    @PostMapping("/getLineCountBySubstation")
    @ApiOperation("获取变电站下监测点数")
    @ApiImplicitParam(name = "subIndex", value = "数据类型（0：暂态系统；1：稳态系统；）", required = true)
    public HttpResult<Integer> getLineCountBySubstation(@RequestParam("subIndex") String subIndex) {
        String methodDescribe = getMethodDescribe("getLineBySubstationRelation");
        Integer count = lineService.getLineCountBySubstation(subIndex);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, count, methodDescribe);
    }

    @PostMapping("/getDeviceCountBySubstation")
    @ApiOperation("获取变电站下终端数")
    @ApiImplicitParam(name = "subIndex", value = "数据类型（0：暂态系统；1：稳态系统；）", required = true)
    public HttpResult<Integer> getDeviceCountBySubstation(@RequestParam("subIndex") String subIndex) {
        String methodDescribe = getMethodDescribe("getDeviceCountBySubstation");
        Integer count = lineService.getDeviceCountBySubstation(subIndex);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, count, methodDescribe);
    }

    @PostMapping("/getOnIntegrityByIds")
    @ApiOperation("监测点数据完整率（谐波专用）")
    @ApiImplicitParam(name = "param", value = "参数实体", required = true)
    public HttpResult<List<RStatIntegrityVO>> getOnIntegrityByIds(@RequestBody OnlineRateParam param) {
        String methodDescribe = getMethodDescribe("getOnlineRateByDevIds");
        List<RStatIntegrityVO> onIntegrityByIds = integrityDMapper.getOnIntegrityByIds(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,onIntegrityByIds,methodDescribe);
    }


    @PostMapping("/getOnIntegrityByIdsAndTime")
    @ApiOperation("监测点数据完整率")
    @ApiImplicitParam(name = "param", value = "参数实体", required = true)
    public HttpResult<List<RStatIntegrityVO>> getOnIntegrityByIdsAndTime(@RequestBody LineBaseQueryParam param) {
        String methodDescribe = getMethodDescribe("getOnIntegrityByIdsAndTime");
        List<RStatIntegrityVO> onIntegrityByIds = integrityDMapper.getOnIntegrityByIdsAndTime (param.getLineIds(),param.getStartTime(),param.getEndTime());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,onIntegrityByIds,methodDescribe);
    }
    @PostMapping("/getHalfReport")
    @ApiOperation("监测点半月报")
    @ApiImplicitParam(name = "param", value = "参数实体", required = true)
    public HttpResult<Page<HalfReportVO>> getHalfReport(@RequestBody TerminalMainQueryParam param) {
        String methodDescribe = getMethodDescribe("getHalfReport");
        Page<HalfReportVO> halfReportVOS = lineService.halfReport(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,halfReportVOS,methodDescribe);
    }

    @PostMapping("/getLineDetailByIds")
    @ApiOperation("根据监测点id获取监测点集合")
    @ApiImplicitParam(name = "ids", value = "参数实体", required = true)
    public HttpResult<List<LineDetailVO.Detail>> getLineDetailByIds(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("getLineDetailByIds");
        List<LineDetailVO.Detail> line = lineService.getLineDetailByIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,line,methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据装置部门和模糊搜索获取装置详情")
    @PostMapping("/getDeptDeviceDetailData")
    HttpResult<List<LineDetailVO.Detail>> getDeptDeviceDetailData(@RequestBody DataParam param){
        String methodDescribe = getMethodDescribe("getDeptDeviceDetailData");
        List<LineDetailVO.Detail> deptDeviceDetailData = lineService.getDeptDeviceDetailData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deptDeviceDetailData, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("获取当日无数据的监测点")
    @PostMapping("/getNoDataLine")
    HttpResult<List<LineDetailVO.noDataLineInfo>> getNoDataLine(){
        String methodDescribe = getMethodDescribe("getNoDataLine");
        List<LineDetailVO.noDataLineInfo> result = lineService.getNoDataLine();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据监测点id获取预告警单基础信息")
    @PostMapping("/getReportLineInfo")
    HttpResult<List<ReportLineInfoVo>> getReportLineInfo(@RequestBody List<String> ids){
        String methodDescribe = getMethodDescribe("getReportLineInfo");
        List<ReportLineInfoVo> result = lineService.getReportLineInfo(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据监测点名称和电网侧变电站名称模糊搜索")
    @PostMapping("/getByName")
    HttpResult<List<LineDetail>> getByName(@RequestBody LineBaseQueryParam param){
        String methodDescribe = getMethodDescribe("getByName");
        List<LineDetail> list = lineService.getByName(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("获取部门下终端信息和终端下监测点信息")
    @GetMapping("/getByDeptDevLine")
    HttpResult<List<DevAndLine>> getByDeptDevLine(String id){
        String methodDescribe = getMethodDescribe("getByDeptDevLine");
        List<DevAndLine> list = lineService.getByDeptDevLine(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据部门获取所有指定等级的监测点id")
    @GetMapping("/getLevelMonitorIdByDept")
    HttpResult<List<String>> getLevelMonitorIdByDept(@RequestParam("level") String level,@RequestParam("deptId")String deptId){
        String methodDescribe = getMethodDescribe("getLevelMonitorIdByDept");
        List<String> list = lineService.getLevelMonitorByDept(level,deptId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据对象名称获取监测到信息")
    @GetMapping("/getMonitorByObjId")
    public HttpResult<List<LineDetail>> getMonitorByObjId(@RequestParam("objId") String objId){
        String methodDescribe = getMethodDescribe("getMonitorByObjId");
        List<LineDetail> list = lineService.getMonitorByObjId(objId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据监测点集合获取电网侧以及用户侧场站")
    @PostMapping("/getPowerStationByMonitorIds")
    public HttpResult<List<PollutionSubstationDTO>> getPowerStationByMonitorIds(@RequestBody List<String> ids){
        String methodDescribe = getMethodDescribe("getPowerStationByMonitorIds");
        List<PollutionSubstationDTO> list = lineService.getPowerStationByMonitorIds(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("获取指定层级的下拉数据")
    @GetMapping("/getSelectList")
    public HttpResult<List<Line>> getSelectList(@RequestParam Integer level){
        String methodDescribe = getMethodDescribe("getSelectList");
        List<Line> list = lineService.lambdaQuery().select(Line::getId,Line::getName).orderByAsc(Line::getSort).eq(Line::getLevel,level).eq(Line::getState, DataStateEnum.ENABLE.getCode()).list();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}
