package com.njcn.event.service.majornetwork.Impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.dto.SimpleDTO;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.device.pq.pojo.param.LargeScreenParam;
import com.njcn.device.pq.pojo.param.MonitoringPointScaleParam;
import com.njcn.device.pq.pojo.vo.*;
import com.njcn.event.mapper.majornetwork.LargeScreenMapper;
import com.njcn.event.service.majornetwork.LargeScreenService;
import com.njcn.harmonic.pojo.dto.ComAssessDTO;
import com.njcn.harmonic.pojo.po.PQSComAssesPO;
import com.njcn.harmonic.utils.HarmonicComAssesUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.enums.StatisticsEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @version 1.0.0
 * @author: zbj
 * @date: 2023/03/31
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class LargeScreenServiceImpl implements LargeScreenService {

    private final GeneralDeviceInfoClient generalDeviceInfoClient;

    private final LargeScreenMapper largeScreenMapper;

    private final HarmonicComAssesUtil comAssesUtil;

    private final DicDataFeignClient dicDataFeignClient;
    /**
     * 暂降事件区域
     */
    @Override
    public AreaDownVO getAreaDownStatistics(LargeScreenParam largeScreenParam) {
        //创建返回VO
        AreaDownVO result = new AreaDownVO();
        ArrayList<MonitoringPointScaleParam> list = new ArrayList<>();
        DeviceInfoParam.BusinessParam deviceInfoParam = new DeviceInfoParam.BusinessParam();
        //部门索引
        deviceInfoParam.setDeptIndex(largeScreenParam.getDeptIndex());
        //统计类型
        SimpleDTO simpleDTO = new SimpleDTO();
        simpleDTO.setCode(String.valueOf(StatisticsEnum.POWER_NETWORK));
        deviceInfoParam.setStatisticalType(simpleDTO);
        //添加时间
        deviceInfoParam.setSearchBeginTime(largeScreenParam.getSearchBeginTime());
        deviceInfoParam.setSearchEndTime(largeScreenParam.getSearchEndTime());
        //添加服务名
        deviceInfoParam.setServerName("event-boot");
        // 获取所有数据
        List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();

        for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
            if (generalDeviceDTO.getLineIndexes().size() == 0) {
                MonitoringPointScaleParam param = new MonitoringPointScaleParam();
                param.setName(generalDeviceDTO.getName());
                param.setIndex(generalDeviceDTO.getIndex());
                param.setCount(0);
                param.setSize(0);
                list.add(param);
            } else {
                int count = largeScreenMapper.selectDownCount(generalDeviceDTO.getLineIndexes(), largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());
                MonitoringPointScaleParam param = new MonitoringPointScaleParam();
                param.setName(generalDeviceDTO.getName());
                param.setIndex(generalDeviceDTO.getIndex());
                param.setCount(count);
                param.setSize(generalDeviceDTO.getLineIndexes().size());
                list.add(param);
            }
        }
        result.setParam(list);
        return result;
    }

    /**
     * 暂降事件负荷类型
     */
    @Override
    public List<LoadTypeVO> getLoadType(LargeScreenParam largeScreenParam) {
        //创建返回VO
        List<LoadTypeVO> result = new ArrayList<>();
        DeviceInfoParam.BusinessParam deviceInfoParam = new DeviceInfoParam.BusinessParam();
        //部门索引
        deviceInfoParam.setDeptIndex(largeScreenParam.getDeptIndex());
        //统计类型
        SimpleDTO simpleDTO = new SimpleDTO();
        simpleDTO.setCode(String.valueOf(StatisticsEnum.LOAD_TYPE));
        deviceInfoParam.setStatisticalType(simpleDTO);
        //添加时间
        deviceInfoParam.setSearchBeginTime(largeScreenParam.getSearchBeginTime());
        deviceInfoParam.setSearchEndTime(largeScreenParam.getSearchEndTime());
        //添加服务名
        deviceInfoParam.setServerName("event-boot");
        // 获取所有数据
        List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();

        //获取所有监测点集合
        List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());

        List<Map<String, Object>> maps = largeScreenMapper.selectLoadTypeCount(lineIds, largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());

        Map<String, Integer> countMap = new HashMap<>();
        for (Map<String, Object> map : maps) {
            for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
                for (String lineIndex : generalDeviceDTO.getLineIndexes()) {
                    if (map.get("id").equals(lineIndex)) {
                        if (countMap.containsKey(generalDeviceDTO.getName())) {
                            int id = Integer.parseInt(map.get("count").toString());
                            countMap.put(generalDeviceDTO.getName(), countMap.get(generalDeviceDTO.getName()) + id);
                            break;
                        } else {
                            int id = Integer.parseInt(map.get("count").toString());
                            countMap.put(generalDeviceDTO.getName(), id);
                            break;
                        }
                    }
                }
            }

        }
        List<String> nameList = generalDeviceDTOList.stream().map(GeneralDeviceDTO::getName).collect(Collectors.toList());
        for (String s : nameList) {
            if (!countMap.containsKey(s)) {
                countMap.put(s, 0);
            }
        }
        for (String s : countMap.keySet()) {
            LoadTypeVO loadTypeVO = new LoadTypeVO();
            loadTypeVO.setName(s);
            loadTypeVO.setCount(countMap.get(s));
            result.add(loadTypeVO);
        }
        return result;
    }

    /**
     * 暂降事件时间统计
     */
    @Override
    public List<DownTimeVO> getTimeCount(LargeScreenParam largeScreenParam) {
        //创建返回VO
        List<DownTimeVO> result = new ArrayList<>();
        DeviceInfoParam.BusinessParam deviceInfoParam = new DeviceInfoParam.BusinessParam();
        //部门索引
        deviceInfoParam.setDeptIndex(largeScreenParam.getDeptIndex());
        //统计类型
        SimpleDTO simpleDTO = new SimpleDTO();
        simpleDTO.setCode(String.valueOf(StatisticsEnum.LOAD_TYPE));
        deviceInfoParam.setStatisticalType(simpleDTO);
        //添加时间
        deviceInfoParam.setSearchBeginTime(largeScreenParam.getSearchBeginTime());
        deviceInfoParam.setSearchEndTime(largeScreenParam.getSearchEndTime());
        //添加服务名
        deviceInfoParam.setServerName("event-boot");
        // 获取所有数据
        List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();

        //获取所有监测点集合
        List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());

        List<Map<String, Object>> maps = largeScreenMapper.getTimeCount(lineIds, largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());

        Map<LocalDate, Integer> eventMap = new HashedMap();

        for (Map<String, Object> map : maps) {
            eventMap.put(LocalDate.parse(map.get("day").toString()), Integer.parseInt(map.get("count").toString()));
        }

        // 创建返回结果的Map集合
        Map<LocalDate, Integer> resultMap = new HashMap<>();
        // 定义事件日期区间
        LocalDate start = LocalDate.parse(largeScreenParam.getSearchBeginTime()); // 开始日期
        LocalDate end = LocalDate.parse(largeScreenParam.getSearchEndTime()); // 结束日期
        // 循环遍历事件日期区间中的每一天，并尝试从事件日期的Map集合中获取对应的值
        for (LocalDate date = start; !date.isAfter(end); date = date.plusDays(1)) {
            Integer value = eventMap.get(date);

            // 如果事件日期的Map集合中存在这一天，则将对应键值对添加到返回结果的Map集合中
            if (value != null) {
                resultMap.put(date, value);
            }
            // 否则，将这一天添加到返回结果的Map集合中，并将值设为0，表示这一天没有事件
            else {
                resultMap.put(date, 0);
            }
        }
        // 输出返回结果的Map集合中的每一个键值对
//        resultMap.entrySet().forEach(System.out::println);
        for (LocalDate s : resultMap.keySet()) {
            DownTimeVO downTimeVO = new DownTimeVO();
            downTimeVO.setTime(s.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
            downTimeVO.setCount(resultMap.get(s));
            result.add(downTimeVO);
        }
        //集合反向循环
        List<DownTimeVO> list = new ArrayList<>();
        for (int i = result.size() - 1; i >= 0; i--) {
            list.add(result.get(i));
        }
        return list;
    }

    /**
     * 大屏获取暂降事件最新50条数据
     */
    @Override
    public List<EventVO> eventLists(LargeScreenParam largeScreenParam) {
        DeviceInfoParam.BusinessParam deviceInfoParam = new DeviceInfoParam.BusinessParam();
        //部门索引
        deviceInfoParam.setDeptIndex(largeScreenParam.getDeptIndex());
        //统计类型
        SimpleDTO simpleDTO = new SimpleDTO();
        simpleDTO.setCode(String.valueOf(StatisticsEnum.POWER_NETWORK));
        deviceInfoParam.setStatisticalType(simpleDTO);
        //添加时间
        deviceInfoParam.setSearchBeginTime(largeScreenParam.getSearchBeginTime());
        deviceInfoParam.setSearchEndTime(largeScreenParam.getSearchEndTime());
        //添加服务名
        deviceInfoParam.setServerName("event-boot");
        // 获取所有数据
        List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();

        //获取所有监测点集合
        List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());

        DictData dictData = dicDataFeignClient.getDicDataByCode(DicDataEnum.VOLTAGE_DIP.getCode()).getData();
        return largeScreenMapper.eventLists(lineIds, largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime(), dictData.getId());
    }

    /**
     * 大屏中间所有数据
     */
    @Override
    public List<AllDataVO> getAllData(LargeScreenParam largeScreenParam) {
        //创建返回VO
        List<AllDataVO> result = new ArrayList<>();
        DeviceInfoParam.BusinessParam deviceInfoParam = new DeviceInfoParam.BusinessParam();
        //部门索引
        deviceInfoParam.setDeptIndex(largeScreenParam.getDeptIndex());
        //统计类型
        SimpleDTO simpleDTO = new SimpleDTO();
        simpleDTO.setCode(String.valueOf(StatisticsEnum.POWER_NETWORK));
        deviceInfoParam.setStatisticalType(simpleDTO);
        //添加时间
        deviceInfoParam.setSearchBeginTime(largeScreenParam.getSearchBeginTime());
        deviceInfoParam.setSearchEndTime(largeScreenParam.getSearchEndTime());
        //添加服务名
        //deviceInfoParam.setServerName("event-boot");
        // 获取所有数据
        List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
        for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
            if (generalDeviceDTO.getDeviceIndexes().size() > 0) {
                AllDataVO allDataVO = largeScreenMapper.getFlagCount(generalDeviceDTO.getDeviceIndexes());
                allDataVO.setAreaName(generalDeviceDTO.getName());
                allDataVO.setIndex(generalDeviceDTO.getIndex());
                allDataVO.setNum(generalDeviceDTO.getLineIndexes().size());
                allDataVO.setSteadyLoad("0.0");
                if (generalDeviceDTO.getLineIndexes().size() > 0) {
                    Map<String, Object> map = largeScreenMapper.getDownCount(generalDeviceDTO.getLineIndexes(), largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());
                    allDataVO.setEventCounts(map.get("count").toString());
                } else {
                    allDataVO.setEventCounts("0");
                }
                result.add(allDataVO);
            } else {
                AllDataVO allDataVO = new AllDataVO();
                allDataVO.setAreaName(generalDeviceDTO.getName());
                allDataVO.setIndex(generalDeviceDTO.getIndex());
                allDataVO.setNum(generalDeviceDTO.getLineIndexes().size());
                allDataVO.setRunning("0");
                allDataVO.setHotSpare("0");
                allDataVO.setShutdown("0");
                allDataVO.setNormal("0");
                allDataVO.setBreakdown("0");
                allDataVO.setSteadyLoad("0.0");
                if (generalDeviceDTO.getLineIndexes().size() > 0) {
                    Map<String, Object> map = largeScreenMapper.getDownCount(generalDeviceDTO.getLineIndexes(), largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());
                    allDataVO.setEventCounts(map.get("count").toString());
                } else {
                    allDataVO.setEventCounts("0");
                }
                result.add(allDataVO);
            }
        }
        //部门id集合
        List<String> indexIds = generalDeviceDTOList.stream().map(GeneralDeviceDTO::getIndex).collect(Collectors.toList());
        List<Map<String, Object>> homeostasisArea = largeScreenMapper.getHomeostasisArea(indexIds, largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());
        float f = 0.0f;
        for (AllDataVO allDataVO : result) {
            for (Map<String, Object> map : homeostasisArea) {
                if (Objects.equals(map.get("id"), allDataVO.getIndex())) {
                    f = Float.parseFloat(map.get("avg").toString());
                    allDataVO.setSteadyLoad(String.valueOf((1 - f) * 100));
                }
            }
        }
        List<ComAssessDTO> comAssessDTOS = new ArrayList<>();
        for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
            if (!CollectionUtils.isEmpty(generalDeviceDTO.getLineIndexes())) {
                List<PQSComAssesPO> pqsComAssesPOS = getComAccessData(generalDeviceDTO.getLineIndexes(), largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());
                setResults(pqsComAssesPOS, comAssessDTOS);
                float allComAss = comAssesUtil.getAllComAss(comAssessDTOS);
                /*String lv = getLevel(allComAss);*/
                /*comAssessVO.setData(allComAss);*/
                for (AllDataVO allDataVO : result) {
                    if (Objects.equals(generalDeviceDTO.getIndex(), allDataVO.getIndex())) {
                        allDataVO.setData(String.valueOf(allComAss));
                    }
                }
            }
            /*comAssessVO.setLevel(lv);*/
        }
        for (AllDataVO allDataVO : result) {
            if (Objects.isNull(allDataVO.getData())) {
                allDataVO.setData("-1");
            }
        }
        return result;
    }

    /**
     * 大屏中间暂态
     */
    @Override
    public EventListVO getMiddleDown(LargeScreenParam largeScreenParam) {
        DeviceInfoParam.BusinessParam deviceInfoParam = new DeviceInfoParam.BusinessParam();
        //部门索引
        deviceInfoParam.setDeptIndex(largeScreenParam.getDeptIndex());
        //统计类型
        SimpleDTO simpleDTO = new SimpleDTO();
        simpleDTO.setCode(String.valueOf(StatisticsEnum.LOAD_TYPE));
        deviceInfoParam.setStatisticalType(simpleDTO);
        //添加时间
        deviceInfoParam.setSearchBeginTime(largeScreenParam.getSearchBeginTime());
        deviceInfoParam.setSearchEndTime(largeScreenParam.getSearchEndTime());
        //添加服务名
        deviceInfoParam.setServerName("event-boot");
        // 获取所有数据
        List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
        //获取所有监测点集合
        List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
        Page<EventVO> eventVOS = largeScreenMapper.getMiddleDown(new Page<>(largeScreenParam.getPageNum(), largeScreenParam.getPageSize()), lineIds, largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());
        EventListVO listVO = new EventListVO();
        listVO.setList(eventVOS.getRecords());
        listVO.setSize(eventVOS.getTotal());
        return listVO;
    }

    /**
     * 大屏中间终端异常信息
     */
    @Override
    public MiddleTerminalListVO getMiddleTerminal(LargeScreenParam largeScreenParam) {
        //创建返回VO
        List<MiddleTerminalVO> result = new ArrayList<>();
        DeviceInfoParam.BusinessParam deviceInfoParam = new DeviceInfoParam.BusinessParam();
        //部门索引
        deviceInfoParam.setDeptIndex(largeScreenParam.getDeptIndex());
        //统计类型
        SimpleDTO simpleDTO = new SimpleDTO();
        simpleDTO.setCode(String.valueOf(StatisticsEnum.POWER_NETWORK));
        deviceInfoParam.setStatisticalType(simpleDTO);
        //添加时间
        deviceInfoParam.setSearchBeginTime(largeScreenParam.getSearchBeginTime());
        deviceInfoParam.setSearchEndTime(largeScreenParam.getSearchEndTime());

        // 获取所有数据
        List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
        //获取所有监测点集合
        List<String> deviceIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getDeviceIndexes().stream()).collect(Collectors.toList());
        Page<MiddleChildVO> map = largeScreenMapper.getMiddleTerminal(new Page<>(largeScreenParam.getPageNum(), largeScreenParam.getPageSize()), deviceIds, largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());

        float base = 0.0f;
        float ream = 0.0f;
        float statusValue = 0.0f;
        float v = 0.0f;

        for (MiddleChildVO middleChildVO : map.getRecords()) {
            MiddleTerminalVO vo = new MiddleTerminalVO();
            base = middleChildVO.getBase();
            ream = middleChildVO.getReam();
            statusValue = middleChildVO.getStatusValue();
            statusValue = statusValue / 1024.0f / 1024.0f;
            v = statusValue / (base + ream);
            vo.setName(middleChildVO.getName());
            vo.setIp(middleChildVO.getIp());
            vo.setPort(middleChildVO.getPort());
            vo.setComFlag(middleChildVO.getComFlag());
            vo.setProportion(formatFloat(v));
            result.add(vo);
        }
        MiddleTerminalListVO listVO = new MiddleTerminalListVO();
        listVO.setList(result);
        listVO.setSize(map.getTotal());
        return listVO;
    }

    public static String formatFloat(Float value) {
        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(2);//保留一位小数，即四舍五入到小数点后一位
        nf.setRoundingMode(RoundingMode.HALF_UP);//设置四舍五入模式为四舍五入
        float v = Float.parseFloat(nf.format(value));
        return String.format("%.1f", Double.parseDouble(String.valueOf(v * 100)));
    }

    /**
     * 大屏中间稳态越线信息
     */
    @Override
    public Page<MiddleLimitRateVO> getMiddleLimitRate(LargeScreenParam largeScreenParam) {
        DeviceInfoParam.BusinessParam deviceInfoParam = new DeviceInfoParam.BusinessParam();
        //部门索引
        deviceInfoParam.setDeptIndex(largeScreenParam.getDeptIndex());
        //统计类型
        SimpleDTO simpleDTO = new SimpleDTO();
        simpleDTO.setCode(String.valueOf(StatisticsEnum.POWER_NETWORK));
        deviceInfoParam.setStatisticalType(simpleDTO);
        //添加时间
        deviceInfoParam.setSearchBeginTime(largeScreenParam.getSearchBeginTime());
        deviceInfoParam.setSearchEndTime(largeScreenParam.getSearchEndTime());

        // 获取所有数据
        List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
        //获取所有监测点集合
        List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
        Page<MiddleLimitRateVO> middleLimitRate = largeScreenMapper.getMiddleLimitRate(new Page<>(largeScreenParam.getPageNum(), largeScreenParam.getPageSize()), lineIds, largeScreenParam.getSearchBeginTime(), largeScreenParam.getSearchEndTime());
        return middleLimitRate;

    }

    //设置保留四位小数
    @Override
    public void setResults(List<PQSComAssesPO> pqsComAssesPOS, List<ComAssessDTO> comAssessDTOS) {
        if (CollectionUtil.isNotEmpty(pqsComAssesPOS)) {
            for (int i = 0; i < pqsComAssesPOS.size(); i++) {
                float v1 = new BigDecimal(pqsComAssesPOS.get(i).getVuDev1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                ComAssessDTO comAssessDTO = new ComAssessDTO();
                comAssessDTO.setVuDev1(v1);
                float v2 = new BigDecimal(pqsComAssesPOS.get(i).getVuDev2()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVuDev2(v2);
                float v3 = new BigDecimal(pqsComAssesPOS.get(i).getVuDev3()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVuDev3(v3);
                float v4 = new BigDecimal(pqsComAssesPOS.get(i).getVuDev4()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVuDev4(v4);
                float v5 = new BigDecimal(pqsComAssesPOS.get(i).getVuDev5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVuDev5(v5);
                float f1 = new BigDecimal(pqsComAssesPOS.get(i).getFreqDev1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setFreqDev1(f1);
                float f2 = new BigDecimal(pqsComAssesPOS.get(i).getFreqDev2()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setFreqDev2(f2);
                float f3 = new BigDecimal(pqsComAssesPOS.get(i).getFreqDev3()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setFreqDev3(f3);
                float f4 = new BigDecimal(pqsComAssesPOS.get(i).getFreqDev4()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setFreqDev4(f4);
                float f5 = new BigDecimal(pqsComAssesPOS.get(i).getFreqDev5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setFreqDev5(f5);
                float d1 = new BigDecimal(pqsComAssesPOS.get(i).getDataPlt1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setDataPlT1(d1);
                float d2 = new BigDecimal(pqsComAssesPOS.get(i).getDataPlt2()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setDataPlT2(d2);
                float d3 = new BigDecimal(pqsComAssesPOS.get(i).getDataPlt3()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setDataPlT3(d3);
                float d4 = new BigDecimal(pqsComAssesPOS.get(i).getDataPlt4()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setDataPlT4(d4);
                float d5 = new BigDecimal(pqsComAssesPOS.get(i).getDataPlt5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setDataPlT5(d5);
                float vu1 = new BigDecimal(pqsComAssesPOS.get(i).getVUnbalance1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVUnbalance1(vu1);
                float vu2 = new BigDecimal(pqsComAssesPOS.get(i).getVUnbalance2()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVUnbalance2(vu2);
                float vu3 = new BigDecimal(pqsComAssesPOS.get(i).getVUnbalance3()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVUnbalance3(vu3);
                float vu4 = new BigDecimal(pqsComAssesPOS.get(i).getVUnbalance4()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVUnbalance4(vu4);
                float vu5 = new BigDecimal(pqsComAssesPOS.get(i).getVUnbalance5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVUnbalance5(vu5);
                float vt1 = new BigDecimal(pqsComAssesPOS.get(i).getVThd1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVTHD1(vt1);
                float vt2 = new BigDecimal(pqsComAssesPOS.get(i).getVThd2()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVTHD2(vt2);
                float vt3 = new BigDecimal(pqsComAssesPOS.get(i).getVThd3()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVTHD3(vt3);
                float vt4 = new BigDecimal(pqsComAssesPOS.get(i).getVThd4()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVTHD4(vt4);
                float vt5 = new BigDecimal(pqsComAssesPOS.get(i).getVThd5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setVTHD5(vt5);
                float e1 = new BigDecimal(pqsComAssesPOS.get(i).getEvent1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setEvent1(e1);
                float e2 = new BigDecimal(pqsComAssesPOS.get(i).getEvent2()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setEvent2(e2);
                float e3 = new BigDecimal(pqsComAssesPOS.get(i).getEvent3()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setEvent3(e3);
                float e4 = new BigDecimal(pqsComAssesPOS.get(i).getEvent4()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setEvent4(e4);
                float e5 = new BigDecimal(pqsComAssesPOS.get(i).getEvent5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
                comAssessDTO.setEvent5(e5);
                comAssessDTOS.add(comAssessDTO);
            }
        }
    }

    /**
     * influxDB查询综合评估相关信息
     * 返回每个监测点在时间段的各指标平均数
     *
     * @param lineIndexes
     * @param searchBeginTime
     * @param searchEndTime
     */
    @Override
    public List<PQSComAssesPO> getComAccessData(List<String> lineIndexes, String searchBeginTime, String searchEndTime) {
        if (CollectionUtil.isNotEmpty(lineIndexes)) {
            List<PQSComAssesPO> avgCount = largeScreenMapper.getAvgCount(lineIndexes,
                    DateUtil.beginOfDay(DateUtil.parse(searchBeginTime)).toString(),
                    DateUtil.beginOfDay(DateUtil.parse(searchEndTime)).toString());
            if (CollUtil.isNotEmpty(avgCount)) {
                return avgCount;
            }
        }
        return new ArrayList<>();
    }
}