package com.njcn.process.service.alarm.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.pojo.dto.SimpleDTO;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.pms.pojo.param.PmsDeviceInfoParam;
import com.njcn.device.pms.pojo.param.RStatPwAlarmDetailParam;
import com.njcn.device.pms.pojo.po.Monitor;
import com.njcn.device.pms.pojo.vo.RStatAlarmDetailVO;
import com.njcn.process.service.alarm.RMpAlarmDetailDService;
import com.njcn.process.mapper.RMpOnlineMonitorOverproofProblemMapper;
import com.njcn.process.pojo.po.RMpOnlineMonitorOverproofProblem;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.web.utils.RequestUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * pqs
 *
 * @author cdf
 * @date 2024/3/18
 */
@Service
@RequiredArgsConstructor
public class RMpAlarmDetailDServiceImpl implements RMpAlarmDetailDService {

    private final CommTerminalGeneralClient commTerminalGeneralClient;

    private final RMpOnlineMonitorOverproofProblemMapper rMpOnlineMonitorOverproofProblemMapper;

    private final DeptFeignClient deptFeignClient;



    @Override
    public List<RMpOnlineMonitorOverproofProblem> getAllAlarmDetailList(RStatPwAlarmDetailParam rStatPwAlarmDetailParam) {
        List<RMpOnlineMonitorOverproofProblem> resultList = new ArrayList<>();


        //提取参数
        String startTime = rStatPwAlarmDetailParam.getStartTime(); //开始时间
        String endTime = rStatPwAlarmDetailParam.getEndTime(); //结束时间
        //获取登录人当前部门
        String deptIndex = RequestUtil.getDeptIndex();

        PmsDeviceInfoParam pmsDeviceInfoParam = new PmsDeviceInfoParam();
        pmsDeviceInfoParam.setStatisticalType(new SimpleDTO());
        pmsDeviceInfoParam.setDeptIndex(deptIndex);

        //获取主网台账信息
        List<String> zwMonitorIds = commTerminalGeneralClient.getRunMonitorIds().getData();

        List<String> deptIds = deptFeignClient.getDepSonSelfCodetByDeptId(RequestUtil.getDeptIndex()).getData();

        //查询告警明细
        LambdaQueryWrapper<RMpOnlineMonitorOverproofProblem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .ge(StringUtils.isNotBlank(startTime), RMpOnlineMonitorOverproofProblem::getDataDate, startTime)
                .le(StringUtils.isNotBlank(endTime), RMpOnlineMonitorOverproofProblem::getDataDate, endTime);
        List<RMpOnlineMonitorOverproofProblem> list = rMpOnlineMonitorOverproofProblemMapper.selectList(lambdaQueryWrapper);
        if(CollUtil.isEmpty(list)){
            return resultList;
        }

        List<String> monitorIds = list.stream().map(RMpOnlineMonitorOverproofProblem::getMeasurementPointId).distinct().collect(Collectors.toList());

        //commTerminalGeneralClient.getMonitorDetailList()




        return resultList;
    }
}
