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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.param.StatisticsBizBaseParam;
import com.njcn.event.mapper.majornetwork.RStatEventDMapper;
import com.njcn.event.mapper.majornetwork.RStatEventMMapper;
import com.njcn.event.mapper.majornetwork.RStatEventVoltageMMapper;
import com.njcn.event.pojo.param.REventMParam;
import com.njcn.event.pojo.param.StatSubstationBizBaseParam;
import com.njcn.event.pojo.po.*;
import com.njcn.event.pojo.vo.*;
import com.njcn.event.service.majornetwork.RStatEventMService;
import com.njcn.device.pq.utils.PublicDateUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.po.Dept;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author rui.wu
 * @since 2022-10-11
 */
@Service
@RequiredArgsConstructor
public class RStatEventMServiceImpl extends ServiceImpl<RStatEventMMapper, RStatEventM> implements RStatEventMService {

    private final RStatEventMMapper rStatEventMMapper;
    private final DicDataFeignClient dicDataFeignClient;
    private final RStatEventDMapper rStatEventDMapper;
    private final RStatEventVoltageMMapper rStatEventVoltageMMapper;
    private final DeptFeignClient deptFeignClient;


    @Override
    public List<RArrayVO> getRStatEventMAll(StatisticsBizBaseParam param) {
        //子节点 获取所有得干扰源类型（监测点类型）
        List<DictData> interferenceSourceTypeData = dicDataFeignClient.getDicDataByTypeCode(
                DicDataTypeEnum.MONITORING_LABELS.getCode()).getData();
        Map<String, DictData> interferenceMap = interferenceSourceTypeData.stream()
                .collect(Collectors.toMap(DictData::getId, Function.identity()));
        //对象主节点 获取所有得暂降类型
        List<DictData> lineTypeData = dicDataFeignClient.getDicDataByTypeCode(
                DicDataTypeEnum.EVENT_STATIS.getCode()).getData();
        Map<String, DictData> lineTypeMap = lineTypeData.stream()
                .collect(Collectors.toMap(DictData::getId, Function.identity()));
        //获取主网id信息
        DictData mainnetData = dicDataFeignClient.getDicDataByCode(DicDataEnum.MAINNET_POINT.getCode()).getData();

        //获取当前部门
        Dept dept = deptFeignClient.getDeptById(param.getId()).getData();
        StatSubstationBizBaseParam baseParam = BeanUtil.copyProperties(param, StatSubstationBizBaseParam.class);
        baseParam.setIds(Collections.singletonList(dept.getCode()));
        //数据库查询
        List<RStatEventM> list = rStatEventMMapper.selectInfoList(baseParam,mainnetData.getId());

        //初始化指标类型（横向）
        List<RArrayVO> arrayVOList = new ArrayList<>();
        List<RStatEventMVO> rm = new ArrayList<>();
        for (DictData lineTypeDatum : interferenceSourceTypeData) {
            RStatEventMVO r = new RStatEventMVO();
            r.setEventName(lineTypeDatum.getName());
            r.setSort(lineTypeDatum.getSort());
            r.setEventMeasurementAverage(0.0F);
            r.setEventMeasurementAccrued(0);
            r.setEventFreq(0.0F);
            r.setEventCount(0);
            r.setEventMeasurementRatioAverage(0.0F);
            r.setEventMeasurementRatioAccrued(0.0F);
            rm.add(r);
        }
        for (DictData lineTypeDatum : lineTypeData) {
            RArrayVO r = new RArrayVO();
            r.setRowName(lineTypeDatum.getName());
            r.setColumns(rm);
            r.setSort(lineTypeDatum.getSort());
            arrayVOList.add(r);
        }
        //根据暂态指标分组
        Map<String, List<RStatEventM>> MeasurementTypeClassMap = list.stream().collect(Collectors.groupingBy(RStatEventM::getEventType));
        //重新生成数据结构
        MeasurementTypeClassMap.forEach((key, value) -> {
            if (lineTypeMap.containsKey(key)) {
                RArrayVO arrayVO = new RArrayVO();
                DictData data = lineTypeMap.get(key);
                arrayVO.setRowName(data.getName());
                arrayVO.setSort(data.getSort());
                List<RStatEventMVO> b = new ArrayList<>();
                b.addAll(rm);
                for (RStatEventM rStatEventM : value) {
                    if(interferenceMap.containsKey(rStatEventM.getMeasurementTypeClass())){
                        RStatEventMVO r = BeanUtil.copyProperties(rStatEventM, RStatEventMVO.class);
                        DictData data1 = interferenceMap.get(rStatEventM.getMeasurementTypeClass());
                        r.setEventName(data1.getName());
                        r.setSort(data1.getSort());
                        b.add(r);
                    }

                }
                Map<String, RStatEventMVO> linkedHashMap = new LinkedHashMap<>();
                for (RStatEventMVO harmonicMVO : b) {
                    linkedHashMap.put(harmonicMVO.getEventName(), harmonicMVO);
                }
                List<RStatEventMVO> aa = new ArrayList<>(linkedHashMap.values());
                aa.sort(Comparator.comparing(rStatEventMVO -> rStatEventMVO.getSort()));
                arrayVO.setColumns(aa);
                arrayVOList.add(arrayVO);
            }
        });
        Map<String, RArrayVO> linkedHashMap = new LinkedHashMap<>();
        for (RArrayVO rArrayVO : arrayVOList) {
            linkedHashMap.put(rArrayVO.getRowName(), rArrayVO);
        }
        List<RArrayVO> aa = new ArrayList<>(linkedHashMap.values());
        arrayVOList.sort(Comparator.comparing(rArrayVO -> rArrayVO.getSort()));
        return aa;
    }

    @Override
    public List<RArrayVO> getPwRStatEventMAll(StatisticsBizBaseParam param) {
        //对象主节点 获取所有得暂降类型
        List<DictData> eventData = dicDataFeignClient.getDicDataByTypeCode(
                DicDataTypeEnum.EVENT_STATIS.getCode()).getData();
        Map<String, DictData> eventMap = eventData.stream()
                .collect(Collectors.toMap(DictData::getId, Function.identity()));

        //子节点 获取监测点类别
        List<DictData> lineData = dicDataFeignClient.getDicDataByTypeCode(
                DicDataTypeEnum.LINE_SORT.getCode()).getData();
        Map<String, DictData> lineMap = lineData.stream()
                .collect(Collectors.toMap(DictData::getId, Function.identity()));

        //获取配网id信息
        DictData distributionData = dicDataFeignClient.getDicDataByCode(DicDataEnum.DISTRIBUTION_POINT.getCode()).getData();
        //初始化指标类型（横向）
        List<RArrayVO> arrayVOList = new ArrayList<>();

        //获取当前部门下所有部门信息
        Dept dept = deptFeignClient.getDeptById(param.getId()).getData();
        StatSubstationBizBaseParam baseParam = BeanUtil.copyProperties(param, StatSubstationBizBaseParam.class);
        baseParam.setIds(Collections.singletonList(dept.getCode()));
        //数据库查询
        List<RStatEventM> list = rStatEventMMapper.selectInfoList(baseParam,distributionData.getId());

        //根据暂态指标分组
        Map<String, List<RStatEventM>> measurementMap = list.stream().collect(Collectors.groupingBy(RStatEventM::getEventType));
        //判断对象是否为空
        if (CollUtil.isNotEmpty(list)) {
            //重新生成数据结构
            measurementMap.forEach((key, value) -> {
                List<RStatEventMVO> eventVO = new ArrayList<>();
                if (eventMap.containsKey(key)) {
                    RArrayVO arrayVO = new RArrayVO();
                    DictData data = eventMap.get(key);
                    arrayVO.setRowName(data.getName());
                    arrayVO.setSort(data.getSort());
                    for (RStatEventM rStatEvent : value) {
                        if(lineMap.containsKey(rStatEvent.getMeasurementTypeClass())){
                            RStatEventMVO r = BeanUtil.copyProperties(rStatEvent, RStatEventMVO.class);
                            DictData data1 = lineMap.get(rStatEvent.getMeasurementTypeClass());
                            r.setEventName(data1.getName());
                            r.setSort(data1.getSort());
                            eventVO.add(r);
                        }

                    }
                    //根据监测点类别获取差集
                    Map<String, List<RStatEventM>> listMap = value.stream().collect(Collectors.groupingBy(RStatEventM::getMeasurementTypeClass));
                    List<DictData> differenceList = lineData.stream().filter(r -> !listMap.containsKey(r.getId()))
                            .collect(Collectors.toList());
                    this.assignDict(differenceList, eventVO, arrayVO);
                    eventVO.sort(Comparator.comparing(rStatEventMVO -> rStatEventMVO.getSort()));
                    arrayVOList.add(arrayVO);
                }
            });
        }

        //处理主节点不存在的集合
        List<DictData> notMeasurementList = eventData.stream().filter(r -> !measurementMap.containsKey(r.getId()))
                .collect(Collectors.toList());
        for (DictData notData : notMeasurementList) {
            List<RStatEventMVO> eventVO = new ArrayList<>();
            RArrayVO arrayVO = new RArrayVO();
            arrayVO.setRowName(notData.getName());
            arrayVO.setSort(notData.getSort());
            this.assignDict(lineData, eventVO, arrayVO);
            eventVO.sort(Comparator.comparing(rStatEventMVO -> rStatEventMVO.getSort()));
            arrayVOList.add(arrayVO);
        }
        arrayVOList.sort(Comparator.comparing(rArrayVO -> rArrayVO.getSort()));
        return arrayVOList;
    }

    @Override
    public List<RStatEventMVO> getRStatHarmonicIcon(REventMParam param) {
        //干扰数据类型（监测对象）
        DictData measurementData;
        //指标对象类型属性
        DictData eventData;
        //判断是是否传入检测点信息值（电压）
        if (StrUtil.isBlank(param.getStasisID()) && StrUtil.isBlank(param.getMonitorID())) {
            //干扰数据类型（监测对象）
            List<DictData> interferenceSourceTypeData = dicDataFeignClient.getDicDataByTypeCode(
                    DicDataTypeEnum.MONITORING_LABELS.getCode()).getData();
            interferenceSourceTypeData.sort(Comparator.comparing(data -> data.getSort()));
            measurementData = interferenceSourceTypeData.get(0);
            //指标对象类型
            List<DictData> indicatorTypeDate = dicDataFeignClient.getDicDataByTypeCode(
                    DicDataTypeEnum.EVENT_STATIS.getCode()).getData();
            indicatorTypeDate.sort(Comparator.comparing(data -> data.getSort()));
            eventData = indicatorTypeDate.get(0);
        } else {
            //获取检测点对象（电压）
            measurementData = dicDataFeignClient.getDicDataById(
                    param.getMonitorID()).getData();
            //获取指标对象（频率偏差）
            eventData = dicDataFeignClient.getDicDataById(
                    param.getStasisID()).getData();
        }
        //反防止参数查询数据报错
        Assert.isTrue(
                ObjectUtil.isNotNull(measurementData) || ObjectUtil.isNotNull(eventData)
                , "干扰源类型或者指标类型为空,请检查入参是否准确");
        //获取电压字典
        List<DictData> devVoltageData = dicDataFeignClient.getDicDataByTypeCode(
                DicDataTypeEnum.DEV_VOLTAGE.getCode()).getData();
        Map<String, DictData> devVoltageMap = devVoltageData.stream()
                .collect(Collectors.toMap(DictData::getId, Function.identity()));

        //获取主网id信息
        DictData mainnetData = dicDataFeignClient.getDicDataByCode(DicDataEnum.MAINNET_POINT.getCode()).getData();

        //获取当前部门
        Dept dept = deptFeignClient.getDeptById(param.getId()).getData();
        StatSubstationBizBaseParam baseParam = BeanUtil.copyProperties(param, StatSubstationBizBaseParam.class);
        baseParam.setIds(Collections.singletonList(dept.getCode()));
        //数据库查询
        List<RStatEventVoltageM> rStatHarmonicVoltageMS = rStatEventVoltageMMapper
                .selectInfoList(baseParam,mainnetData.getId(), measurementData.getId(),eventData.getId());

        //初始化对象
        List<RStatEventMVO> arrayVOList = new ArrayList<>();

        //将数据转换为map进行便利
        Map<String, RStatEventVoltageM> voltageMMap = rStatHarmonicVoltageMS.stream()
                .collect(Collectors.toMap(RStatEventVoltageM::getVoltageType, Function.identity()));
        //对象
        if (CollUtil.isNotEmpty(rStatHarmonicVoltageMS)) {
            voltageMMap.forEach((key, value) -> {
                if (devVoltageMap.containsKey(key)) {
                    DictData data = devVoltageMap.get(key);
                    RStatEventMVO riconvo = new RStatEventMVO();
                    riconvo.setEventName(data.getName());
                    riconvo.setSort(data.getSort());
                    riconvo.setEventMeasurementAverage(value.getEventMeasurementAverage());
                    riconvo.setEventMeasurementAccrued(value.getEventMeasurementAccrued());
                    riconvo.setEventFreq(value.getEventFreq());
                    riconvo.setEventCount(value.getEventCount());
                    riconvo.setEventMeasurementRatioAverage(value.getEventMeasurementRatioAverage());
                    riconvo.setEventMeasurementRatioAccrued(value.getEventMeasurementRatioAccrued());
                    arrayVOList.add(riconvo);
                }
            });
        }
        //处理主节点不存在的集合
        List<DictData> notMeasurementList = devVoltageData.stream().filter(r -> !voltageMMap.containsKey(r.getId()))
                .collect(Collectors.toList());
        for (DictData notData : notMeasurementList) {
            RStatEventMVO iconVO = new RStatEventMVO();
            iconVO.setSort(notData.getSort());
            iconVO.setEventName(notData.getName());
            iconVO.setEventMeasurementAverage(0.0F);
            iconVO.setEventMeasurementAccrued(0);
            iconVO.setEventFreq(0.0F);
            iconVO.setEventCount(0);
            iconVO.setEventMeasurementRatioAverage(0.0F);
            iconVO.setEventMeasurementRatioAccrued(0.0F);
            arrayVOList.add(iconVO);
        }
        arrayVOList.sort(Comparator.comparing(rIconVO -> rIconVO.getSort()));
        return arrayVOList;
    }

    @SneakyThrows
    @Override
    public List<REventPolylineVO> getRStatHarmonicIcon2(REventMParam param) {
        //初始化对象
        List<REventPolylineVO> iconList = new ArrayList<>();
        DictData measurementDate;
        //指标对象类型属性
        DictData harmonicDate;
        //判断是是否传入检测点信息值（电压）
        if (StrUtil.isBlank(param.getStasisID()) && StrUtil.isBlank(param.getMonitorID())) {
            //干扰数据类型（监测对象）
            List<DictData> interferenceSourceTypeData = dicDataFeignClient.getDicDataByTypeCode(
                    DicDataTypeEnum.MONITORING_LABELS.getCode()).getData();
            interferenceSourceTypeData.sort(Comparator.comparing(data -> data.getSort()));
            measurementDate = interferenceSourceTypeData.get(0);
            //指标对象类型
            List<DictData> indicatorTypeDate = dicDataFeignClient.getDicDataByTypeCode(
                    DicDataTypeEnum.EVENT_STATIS.getCode()).getData();
            indicatorTypeDate.sort(Comparator.comparing(data -> data.getSort()));
            harmonicDate = indicatorTypeDate.get(0);
        } else {
            //获取检测点对象（电压）
            measurementDate = dicDataFeignClient.getDicDataById(
                    param.getMonitorID()).getData();
            //获取指标对象（频率偏差）
            harmonicDate = dicDataFeignClient.getDicDataById(
                    param.getStasisID()).getData();
        }
        //反防止参数查询数据报错
        Assert.isTrue(
                ObjectUtil.isNotNull(measurementDate) || ObjectUtil.isNotNull(harmonicDate)
                , "干扰源类型或者指标类型为空,请检查入参是否准确");
        //获取主网id信息
        DictData mainnetData = dicDataFeignClient.getDicDataByCode(DicDataEnum.MAINNET_POINT.getCode()).getData();

        //获取当前部门
        Dept dept = deptFeignClient.getDeptById(param.getId()).getData();
        StatSubstationBizBaseParam baseParam = BeanUtil.copyProperties(param, StatSubstationBizBaseParam.class);
        baseParam.setIds(Collections.singletonList(dept.getCode()));
        //数据库查询
        List<RStatEventD> rStatHarmonicVoltageMS = rStatEventDMapper
                .selectInfoList(baseParam,mainnetData.getId(), measurementDate.getId(),harmonicDate.getId());


        Map<LocalDate, List<RStatEventD>> rStatEventDMap =
                rStatHarmonicVoltageMS.stream().collect(Collectors.groupingBy(RStatEventD::getDataDate));
        //获取月份
        List<String> intervalTime = this.getIntervalTime(param.getStartTime(), param.getEndTime());
        for (String interTime : intervalTime) {
            //生成初始时间
            String startTime = PublicDateUtil.getFisrtDayOfMonth(Integer.parseInt(interTime.substring(0, 4)), Integer.parseInt(interTime.substring(5)));
            String endTime = PublicDateUtil.getLastDayOfMonth(Integer.parseInt(interTime.substring(0, 4)), Integer.parseInt(interTime.substring(5)));
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date dt = simpleDateFormat.parse(startTime);
            Date dtDate = simpleDateFormat.parse(endTime);
            Integer year = Integer.valueOf(String.format("%tY", dt));
            Integer mon = Integer.valueOf(String.format("%tm", dt));
            Integer day = Integer.valueOf(String.format("%td", dtDate));
            //生成月份数据
            List<String> dayTime = this.getIntervalDateTime(year, mon, day);
            for (String s : dayTime) {
                REventPolylineVO rPolylineVO = new REventPolylineVO();
                rPolylineVO.setDate(s);
                if (rStatEventDMap.containsKey(LocalDateTimeUtil.parseDate(s, "yyyy-MM-dd"))) {
                    List<RStatEventD> rSd = rStatEventDMap.get(LocalDateTimeUtil.parseDate(s, "yyyy-MM-dd"));
                    rPolylineVO.setEventCount(rSd.get(0).getEventCount());
                    rPolylineVO.setEventMeasurement(rSd.get(0).getEventMeasurement());
                    rPolylineVO.setEventMeasurementRatio(rSd.get(0).getEventMeasurementRatio());
                    rPolylineVO.setEventFreq(1);
                } else {
                    rPolylineVO.setEventMeasurement(0);
                    rPolylineVO.setEventMeasurementRatio(0.0F);
                    rPolylineVO.setEventCount(0);
                    rPolylineVO.setEventFreq(0);
                }
                iconList.add(rPolylineVO);
            }

        }
        return iconList;
    }

    @SneakyThrows
    @Override
    public List<REventPolylineVO> getPwRStatHarmonicIcon2(REventMParam param) {
        //初始化对象
        List<REventPolylineVO> iconList = new ArrayList<>();
        DictData measurementData;
        //指标对象类型属性
        DictData eventData;
        //判断是是否传入监测点信息值
        if (StrUtil.isBlank(param.getStasisID()) && StrUtil.isBlank(param.getMonitorID())) {
            //干扰数据类型（监测对象）
            List<DictData> interferenceSourceTypeData = dicDataFeignClient.getDicDataByTypeCode(
                    DicDataTypeEnum.LINE_SORT.getCode()).getData();
            interferenceSourceTypeData.sort(Comparator.comparing(data -> data.getSort()));
            measurementData = interferenceSourceTypeData.get(0);
            //指标对象类型
            List<DictData> indicatorTypeDate = dicDataFeignClient.getDicDataByTypeCode(
                    DicDataTypeEnum.EVENT_STATIS.getCode()).getData();
            indicatorTypeDate.sort(Comparator.comparing(data -> data.getSort()));
            eventData = indicatorTypeDate.get(0);
        } else {
            //获取检测点对象（电压）
            measurementData = dicDataFeignClient.getDicDataById(
                    param.getMonitorID()).getData();
            //获取指标对象（频率偏差）
            eventData = dicDataFeignClient.getDicDataById(
                    param.getStasisID()).getData();
        }
        //反防止参数查询数据报错
        Assert.isTrue(
                ObjectUtil.isNotNull(measurementData) || ObjectUtil.isNotNull(eventData)
                , "干扰源类型或者指标类型为空,请检查入参是否准确");
        //获取配网信息
        DictData distributionData = dicDataFeignClient.getDicDataByCode(DicDataEnum.DISTRIBUTION_POINT.getCode()).getData();
        //获取当前部门下所有部门信息
        Dept dept = deptFeignClient.getDeptById(param.getId()).getData();
        StatSubstationBizBaseParam baseParam = BeanUtil.copyProperties(param, StatSubstationBizBaseParam.class);
        baseParam.setIds(Collections.singletonList(dept.getCode()));
        //数据库查询
        List<RStatEventD> rStatHarmonicVoltageMS = rStatEventDMapper
                .selectInfoList(baseParam,distributionData.getId(), measurementData.getId(),eventData.getId());

        Map<LocalDate, List<RStatEventD>> rStatEventDMap =
                rStatHarmonicVoltageMS.stream().collect(Collectors.groupingBy(RStatEventD::getDataDate));
        //获取月份
        List<String> intervalTime = this.getIntervalTime(param.getStartTime(), param.getEndTime());
        for (String interTime : intervalTime) {
            //生成初始时间
            String startTime = PublicDateUtil.getFisrtDayOfMonth(Integer.parseInt(interTime.substring(0, 4)), Integer.parseInt(interTime.substring(5)));
            String endTime = PublicDateUtil.getLastDayOfMonth(Integer.parseInt(interTime.substring(0, 4)), Integer.parseInt(interTime.substring(5)));
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date dt = simpleDateFormat.parse(startTime);
            Date dtDate = simpleDateFormat.parse(endTime);
            Integer year = Integer.valueOf(String.format("%tY", dt));
            Integer mon = Integer.valueOf(String.format("%tm", dt));
            Integer day = Integer.valueOf(String.format("%td", dtDate));
            //生成月份数据
            List<String> dayTime = this.getIntervalDateTime(year, mon, day);
            for (String s : dayTime) {
                REventPolylineVO rPolylineVO = new REventPolylineVO();
                rPolylineVO.setDate(s);
                if (rStatEventDMap.containsKey(LocalDateTimeUtil.parseDate(s, "yyyy-MM-dd"))) {
                    List<RStatEventD> rSd = rStatEventDMap.get(LocalDateTimeUtil.parseDate(s, "yyyy-MM-dd"));
                    rPolylineVO.setEventCount(rSd.get(0).getEventCount());
                    rPolylineVO.setEventMeasurement(rSd.get(0).getEventMeasurement());
                    rPolylineVO.setEventMeasurementRatio(rSd.get(0).getEventMeasurementRatio());
                    rPolylineVO.setEventFreq(1);
                } else {
                    rPolylineVO.setEventMeasurement(0);
                    rPolylineVO.setEventMeasurementRatio(0.0F);
                    rPolylineVO.setEventCount(0);
                    rPolylineVO.setEventFreq(0);
                }
                iconList.add(rPolylineVO);
            }

        }
        return iconList;
    }

    /**
     * 根据用户选择的时间区间返回月份日期
     */
    @SneakyThrows
    private List<String> getIntervalTime(String startTime, String endTime) {
        List<String> times = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Date start = sdf.parse(startTime);
        Date end = sdf.parse(endTime);
        // 同月
        if (start.getTime() == end.getTime()) {
            String time = startTime.substring(0, 7);
            times.add(time);
        } else if (start.getYear() == end.getYear()) {
            // 同年
            int startM = start.getMonth() + 1;
            int endM = end.getMonth() + 1;
            int temp = endM - startM;
            for (int i = 0; i <= temp; i++) {
                String time = start.getYear() + 1900 + "";
                int month = startM + i;
                if (month < 10) {
                    time = time + "-0" + month;
                } else {
                    time = time + "-" + month;
                }
                times.add(time);
            }
        } else {
            // 不同年!!!!这里忽略了年份之间跨年的情况
            int startY = start.getYear() + 1900;
            int startM = start.getMonth() + 1;
            int endY = end.getYear() + 1900;
            int endM = end.getMonth() + 1;
            int tempS = 12 - startM;
            // 连续的年份
            if (endY - startY == 1) {
                // 第一年的时间获取
                for (int i = 0; i <= tempS; i++) {
                    int month = startM + i;
                    String time = startY + "-";
                    if (month < 10) {
                        time = time + "0" + month;
                    } else {
                        time = time + month;
                    }
                    times.add(time);
                }
                // 第二年的时间获取

                for (int i = 1; i <= endM; i++) {
                    String time = endY + "-";
                    if (i < 10) {
                        time = time + "0" + i;
                    } else {
                        time = time + i;
                    }
                    times.add(time);
                }
            } else {
                // 不连续的年份
                // 第一年的时间获取
                for (int i = 0; i <= tempS; i++) {
                    int month = startM + i;
                    String time = startY + "-";
                    if (month < 10) {
                        time = time + "0" + month;
                    } else {
                        time = time + month;
                    }
                    times.add(time);
                }
                int tempY = endY - startY;
                // 中间年份的时间
                for (int i = 1; i < tempY; i++) {
                    for (int j = 1; j <= 12; j++) {
                        String time = startY + i + "-";
                        if (j < 10) {
                            time = time + "0" + j;
                        } else {
                            time = time + j;
                        }
                        times.add(time);
                    }
                }
                // 最后一年的时间获取
                for (int i = 1; i <= endM; i++) {
                    String time = endY + "-";
                    if (i < 10) {
                        time = time + "0" + i;
                    } else {
                        time = time + i;
                    }
                    times.add(time);
                }
            }

        }
        return times;
    }

    @SneakyThrows
    private List<String> getIntervalDateTime(Integer startTime, Integer endTime, Integer dd) {
        List<String> list = new ArrayList<>();
        Calendar calendar = Calendar.getInstance(Locale.CHINA);
        calendar.set(startTime, endTime - 1, 1);
        //年份
        int year = calendar.get(Calendar.YEAR);
        //月份
        int month = calendar.get(Calendar.MONTH) + 1;
        for (int i = 1; i <= dd; i++) {
            String date = null;
            if (month < 10 && i < 10) {
                date = year + "-0" + month + "-0" + i;
            }
            if (month < 10 && i >= 10) {
                date = year + "-0" + month + "-" + i;
            }
            if (month >= 10 && i < 10) {
                date = year + "-" + month + "-0" + i;
            }
            if (month >= 10 && i >= 10) {
                date = year + "-" + month + "-" + i;
            }

            list.add(date);
        }
        return list;
    }

    /**
     * 便利赋值
     *
     * @param DictDataList 暂态类型集合
     * @param eventVO      暂态监测点
     * @param arrayVO      初始化对象
     */
    private void assignDict(List<DictData> DictDataList, List<RStatEventMVO> eventVO, RArrayVO arrayVO) {
        for (DictData dictData : DictDataList) {
            RStatEventMVO notEventVO = new RStatEventMVO();
            notEventVO.setEventName(dictData.getName());
            notEventVO.setSort(dictData.getSort());
            notEventVO.setEventMeasurementAverage(0.0F);
            notEventVO.setEventMeasurementAccrued(0);
            notEventVO.setEventFreq(0.0F);
            notEventVO.setEventCount(0);
            notEventVO.setEventMeasurementRatioAverage(0.0F);
            notEventVO.setEventMeasurementRatioAccrued(0.0F);
            eventVO.add(notEventVO);
        }
        arrayVO.setColumns(eventVO);
    }
}
