package com.njcn.harmonic.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njcn.common.utils.PubUtils;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
import com.njcn.device.biz.pojo.dto.LineDevGetDTO;
import com.njcn.device.biz.pojo.po.Overlimit;
import com.njcn.device.biz.pojo.po.PqsDeviceUnit;
import com.njcn.device.biz.utils.COverlimitUtil;
import com.njcn.event.api.EventDetailFeignClient;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.harmonic.mapper.HistoryDataMapper;
import com.njcn.harmonic.pojo.QueryResultLimitVO;
import com.njcn.harmonic.pojo.param.HarmonicHistoryParam;
import com.njcn.harmonic.pojo.param.HistoryParam;
import com.njcn.harmonic.pojo.vo.EventDetailVO;
import com.njcn.harmonic.pojo.vo.HistoryDataResultVO;
import com.njcn.harmonic.service.OracleResultService;
import com.njcn.influx.pojo.bo.HarmonicHistoryData;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.pojo.po.DictData;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author wr
 * @description
 * @date 2024/1/11 16:15
 */
@Service
@AllArgsConstructor
public class OracleResultServiceImpl implements OracleResultService {
    private final EventDetailFeignClient eventDetailFeignClient;
    private final CommTerminalGeneralClient commTerminalGeneralClient;
    private final DicDataFeignClient dicDataFeignClient;
    private final HistoryDataMapper HistoryDataMapper;

    @Override
    public List<HistoryDataResultVO> getHistoryResult(HistoryParam historyParam) {
        List<HistoryDataResultVO> historyDataResultVOList = new ArrayList<>();
        //获取监测点
        String[] points = historyParam.getLineId();
        Integer number = 0;
        for (int i = 0; i < points.length; i++) {
            HistoryDataResultVO historyDataResultVO;
            List<EventDetail> eventDetailList = eventDetailFeignClient.getEventDetailData(points[i], historyParam.getSearchBeginTime(), historyParam.getSearchEndTime()).getData();
            List<EventDetailVO> eventDetailVOList = new ArrayList<>();
            if (!eventDetailList.isEmpty()) {
                for (EventDetail eventdetail : eventDetailList) {
                    String timeText = eventdetail.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
                    EventDetailVO eventDetailVO = new EventDetailVO();
                    eventDetailVO.setId(eventdetail.getEventId());
                    eventDetailVO.setTime(timeText);
                    eventDetailVOList.add(eventDetailVO);
                }
            }
            //获取指标
            String[] contions = historyParam.getCondition();
            for (int j = 0; j < contions.length; j++) {
                if ("40".equals(contions[j]) || "41".equals(contions[j]) || "42".equals(contions[j]) || "43".equals(contions[j])
                        || "44".equals(contions[j]) || "45".equals(contions[j]) || "50".equals(contions[j]) || "51".equals(contions[j])
                        || "52".equals(contions[j])) {
                    number = historyParam.getHarmonic();
                }
                if ("46".equals(contions[j]) || "47".equals(contions[j]) || "48".equals(contions[j]) || "49".equals(contions[j])) {
                    number = historyParam.getInHarmonic();
                }
                historyDataResultVO = getCondition(historyParam.getSearchBeginTime(), historyParam.getSearchEndTime(), points[i], contions[j], number, historyParam.getValueType(), historyParam.getPtType());
                historyDataResultVO.setEventDetail(eventDetailVOList);
                historyDataResultVOList.add(historyDataResultVO);
            }
        }
        return historyDataResultVOList;
    }

    @Override
    public List<HistoryDataResultVO> getHistoryResult2(HistoryParam historyParam) {
       HarmonicHistoryParam param=new HarmonicHistoryParam();
        param.setStartTime("2023-12-01 00:00:00");
        param.setEndTime("2023-12-01 23:59:59");
        param.setValueTypeName("");
        List<HarmonicHistoryData> data_v = HistoryDataMapper.getDataFluc(param);
        param.setValueTypeName("MAX");
        List<HarmonicHistoryData> data_v2 = HistoryDataMapper.getDataFluc(param);
        param.setValueTypeName("MIN");
        List<HarmonicHistoryData> data_v3 = HistoryDataMapper.getDataFluc(param);
        param.setValueTypeName("CP95");
        List<HarmonicHistoryData> data_v4 = HistoryDataMapper.getDataFluc(param);

        return null;
    }

    @SneakyThrows
    private HistoryDataResultVO getCondition(String startTime, String endTime, String lineId, String contion, Integer number, Integer valueType, Integer ptType) {
        HistoryDataResultVO historyDataResultVO = new HistoryDataResultVO();
        QueryResultLimitVO queryResultLimitVO = getQueryResult(startTime, endTime, lineId, contion, number, valueType, ptType);
        List<HarmonicHistoryData> harmonicHistoryDataList = queryResultLimitVO.getHarmonicHistoryDataList();
        BeanUtil.copyProperties(queryResultLimitVO, historyDataResultVO);
        //时间轴
        List<Date> time = new ArrayList<>();
        //A相值
        List<Float> aValue;
        //B相值
        List<Float> bValue = new ArrayList<>();
        //C相值
        List<Float> cValue = new ArrayList<>();
        //针对统计相别为T时存放的数据
        List<Float> fValue = new ArrayList<>();
        List<List<Object>> objectListData = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(harmonicHistoryDataList)) {
            //相别统计为T时，业务数据处理
            if (StrUtil.isBlank(harmonicHistoryDataList.get(0).getPhasicType()) || harmonicHistoryDataList.get(0).getPhasicType().equalsIgnoreCase("t")) {
                for (HarmonicHistoryData harmonicHistoryData : harmonicHistoryDataList) {
                    time.add(PubUtils.instantToDate(harmonicHistoryData.getTime()));
                    fValue.add(BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, RoundingMode.HALF_UP).floatValue());
                    //返回结果有多个值，需要额外处理下
                    if (Integer.parseInt(contion) == 14) {
                        bValue.add(BigDecimal.valueOf(harmonicHistoryData.getBValue()).setScale(4, RoundingMode.HALF_UP).floatValue());
                        cValue.add(BigDecimal.valueOf(harmonicHistoryData.getCValue()).setScale(4, RoundingMode.HALF_UP).floatValue());
                    }
                }
                //组装二维数组
                for (int i = 0; i < time.size(); i++) {
                    List<Object> objects = new ArrayList<>();
                    objects.add(time.get(i));
                    objects.add(fValue.get(i));
                    if (Integer.parseInt(contion) == 14) {
                        objects.add(bValue.get(i));
                        objects.add(cValue.get(i));
                    }
                    objectListData.add(objects);
                }
                historyDataResultVO.setTopLimit(queryResultLimitVO.getTopLimit());
                historyDataResultVO.setLowerLimit(queryResultLimitVO.getLowerLimit());
                historyDataResultVO.setMinValue(Collections.min(fValue));
                historyDataResultVO.setMaxValue(Collections.max(fValue));
                historyDataResultVO.setValue(objectListData);
            } else {
                //按时间分组
                Map<Instant,List<HarmonicHistoryData>> map = harmonicHistoryDataList.stream().collect(Collectors.groupingBy(HarmonicHistoryData::getTime,TreeMap::new, Collectors.toList()));

                Float maxI = null;
                Float minI = null;
                for (Map.Entry<Instant, List<HarmonicHistoryData>> entry : map.entrySet()) {
                    List<HarmonicHistoryData> val = entry.getValue();
                    Object[] objects = {PubUtils.instantToDate(entry.getKey()),0,0,0};
                    //需要保证val的长度为3
                    if(val.size()!=3){
                        for(int i =0;i<3-val.size();i++){
                            HarmonicHistoryData tem = new HarmonicHistoryData();
                            tem.setAValue(0f);
                            val.add(tem);
                        }
                    }
                    for (HarmonicHistoryData harmonicHistoryData : val) {
                        if (InfluxDBTableConstant.PHASE_TYPE_A.equalsIgnoreCase(harmonicHistoryData.getPhasicType())) {

                            BigDecimal a = BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, RoundingMode.HALF_UP);
                            objects[1] =a;
                            maxI = max(maxI, a.floatValue());
                            minI = min(minI, a.floatValue());

                        } else if (InfluxDBTableConstant.PHASE_TYPE_B.equalsIgnoreCase(harmonicHistoryData.getPhasicType())) {
                            BigDecimal b = BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, RoundingMode.HALF_UP);
                            objects[2] = b;
                            maxI = max(maxI, b.floatValue());
                            minI = min(minI, b.floatValue());

                        } else if (InfluxDBTableConstant.PHASE_TYPE_C.equalsIgnoreCase(harmonicHistoryData.getPhasicType())) {
                            BigDecimal c = BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, RoundingMode.HALF_UP);
                            objects[3] = c;
                            maxI = max(maxI, c.floatValue());
                            minI = min(minI, c.floatValue());

                        }
                    }
                    List<Object> list = new ArrayList<>(Arrays.asList(objects));

                    objectListData.add(list);

                };

                historyDataResultVO.setMaxValue(maxI);
                historyDataResultVO.setMinValue(minI);
                historyDataResultVO.setTopLimit(queryResultLimitVO.getTopLimit());
                historyDataResultVO.setLowerLimit(queryResultLimitVO.getLowerLimit());
                historyDataResultVO.setValue(objectListData);
            }

        } else {
            return historyDataResultVO;
        }
        return historyDataResultVO;
    }


    private QueryResultLimitVO getQueryResult(String startTime, String endTime, String lineId, String contion, Integer number, Integer valueType, Integer ptType) {
        PqsDeviceUnit pqsDeviceUnit = commTerminalGeneralClient.lineUnitDetail(lineId).getData();

        QueryResultLimitVO queryResultLimitVO = new QueryResultLimitVO();
        if (!lineId.isEmpty()) {
            Float topLimit = 0f;
            Float lowerLimit = 0f;
            Integer type=0;
            //获取监测点信息
            LineDevGetDTO lineDetailDataVO = commTerminalGeneralClient.getMonitorDetail(lineId).getData();
            //获取限值
            Overlimit overlimit = commTerminalGeneralClient.getOverLimitData(lineId).getData();
            if(Objects.isNull(overlimit)){
                //对配网没有限值的统一处理
                DictData dictData = dicDataFeignClient.getDicDataById(lineDetailDataVO.getVoltageLevel()).getData();
                type=1;
                float voltageLevel = Float.parseFloat(dictData.getValue());
                float shortVal = COverlimitUtil.getDlCapByVoltageLevel(voltageLevel);
                overlimit = COverlimitUtil.globalAssemble(voltageLevel,10f,10f,shortVal,1,1);
            }

            String valueTypeName = "";
            switch (valueType) {
                case 1:
                    valueTypeName = "";
                    break;
                case 2:
                    valueTypeName = "MIN";
                    break;
                case 3:
                    valueTypeName = "MAX";
                    break;
                case 4:
                    valueTypeName = "CP95";
                    break;
                default:
                    break;
            }
            List<String> phasicType = new ArrayList<>();
            List<String> unit = new ArrayList<>();
            String targetName = "";
            switch (Integer.parseInt(contion)) {
                case 10:
                    //相电压有效值
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add(pqsDeviceUnit.getPhaseVoltage());
                    targetName = "相电压有效值";
                    break;
                case 11:
                    //线电压有效值
                    phasicType.add("AB相");
                    phasicType.add("BC相");
                    phasicType.add("CA相");
                    unit.add(pqsDeviceUnit.getLineVoltage());
                    targetName = "线电压有效值";
                    break;
                case 12:
                    //电压偏差
                    topLimit = overlimit.getVoltageDev();
                    lowerLimit = overlimit.getUvoltageDev();
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    unit.add("%");
                    targetName = "电压偏差";
                    break;
                case 13:
                    //三相电压不平衡度
                    topLimit = overlimit.getUbalance();
                    phasicType.add("三相电压不平衡度");
                    unit.add("%");
                    targetName = "三相电压不平衡度";
                    break;
                case 14:
                    //电压不平衡
                    phasicType.add("零序电压");
                    phasicType.add("正序电压");
                    phasicType.add("负序电压");
                    unit.add(pqsDeviceUnit.getNoPositiveV());
                    unit.add(pqsDeviceUnit.getPositiveV());
                    unit.add(pqsDeviceUnit.getNoPositiveV());
                    targetName = "电压不平衡";
                    break;
                case 15:
                    //电压总谐波畸变率
                    topLimit = overlimit.getUaberrance();
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    unit.add("%");
                    targetName = "电压总谐波畸变率";
                    break;
                case 20:
                    //电流有效值
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add("A");
                    targetName = "电流有效值";
                    break;
                case 21:
                    //电流总畸变率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add("%");
                    targetName = "电流总谐波畸变率";
                    break;
                case 22:
                    //负序电流
                    topLimit = overlimit.getINeg();
                    phasicType.add("负序电流");
                    unit.add("A");
                    targetName = "负序电流";
                    break;
                case 30:
                    //频率 V9暂时代表Freq
                    topLimit = 50 + overlimit.getFreqDev();
                    lowerLimit = 50 - overlimit.getFreqDev();
                    phasicType.add("频率");
                    unit.add("Hz");
                    targetName = "频率";
                    break;
                case 40:
                    //谐波电压含有率
                    if (number != 1) {
                        if (number < 26) {
                            topLimit = PubUtils.getValueByMethod(overlimit, "getUharm", number);
                        }
                    }
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    unit.add("%");
                    targetName = "谐波电压含有率";
                    break;
                case 41:
                    //谐波电流含有率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add("%");
                    targetName = "谐波电流含有率";
                    break;
                case 42:
                    //谐波电压幅值
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    if (number == 1) {
                        unit.add(pqsDeviceUnit.getVfundEffective());
                    } else {
                        unit.add("V");
                    }
                    targetName = "谐波电压幅值";
                    break;
                case 43:
                    //谐波电流幅值
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add("A");
                    targetName = "谐波电流幅值";
                    break;
                case 44:
                    //谐波电压相角
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    unit.add("°");
                    targetName = "谐波电压相角";
                    break;
                case 45:
                    //谐波电流相角
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add("°");
                    targetName = "谐波电流相角";
                    break;
                case 46:
                    //间谐波电压含有率
                    topLimit = PubUtils.getValueByMethod(overlimit, "getInuharm", number);
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    unit.add("%");
                    targetName = "间谐波电压含有率";
                    break;
                case 47:
                    //间谐波电流含有率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add("%");
                    targetName = "间谐波电流含有率";
                    break;
                case 48:
                    //间谐波电压幅值
                    targetName = "间谐波电压幅值";
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    unit.add(pqsDeviceUnit.getPhaseVoltage());
                    break;
                case 49:
                    //间谐波电流幅值
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add("A");
                    targetName = "间谐波电流幅值";
                    break;
                case 50:
                    //谐波有功功率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    if (number == 1) {
                        unit.add(pqsDeviceUnit.getFundActiveP());
                    } else {
                        unit.add("W");
                    }
                    targetName = "谐波有功功率";
                    break;
                case 51:
                    //谐波无功功率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    if (number == 1) {
                        unit.add(pqsDeviceUnit.getTotalNoP());
                    } else {
                        unit.add("Var");
                    }
                    targetName = "谐波无功功率";
                    break;
                case 52:
                    //谐波视在功率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    if (number == 1) {
                        unit.add(pqsDeviceUnit.getTotalViewP());
                    } else {
                        unit.add("VA");
                    }
                    targetName = "谐波视在功率";
                    break;
                case 53:
                    //三相有功功率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add(pqsDeviceUnit.getTotalActiveP());
                    targetName = "三相有功功率";
                    break;
                case 54:
                    //三相无功功率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add(pqsDeviceUnit.getTotalNoP());
                    targetName = "三相无功功率";
                    break;
                case 55:
                    //三相视在功率
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    unit.add(pqsDeviceUnit.getTotalViewP());
                    targetName = "三相视在功率";
                    break;
                case 56:
                    //三相总有功功率
                    phasicType.add("三相总有功功率");
                    unit.add(pqsDeviceUnit.getTotalActiveP());
                    targetName = "三相总有功功率";
                    break;
                case 57:
                    //三相总无功功率
                    phasicType.add("三相总无功功率");
                    unit.add(pqsDeviceUnit.getTotalNoP());
                    targetName = "三相总无功功率";
                    break;
                case 58:
                    //三相总视在功率
                    phasicType.add("三相总视在功率");
                    unit.add(pqsDeviceUnit.getTotalViewP());
                    targetName = "三相总视在功率";
                    break;
                case 59:
                    //视在功率因数
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    targetName = "视在功率因数";
                    break;
                case 591:
                    //位移功率因数
                    phasicType.add("A相");
                    phasicType.add("B相");
                    phasicType.add("C相");
                    targetName = "位移功率因数";
                    break;
                case 592:
                    //总视在功率因数
                    phasicType.add("总视在功率因数");
                    targetName = "总视在功率因数";
                    break;
                case 593:
                    //总位移功率因数
                    phasicType.add("总位移功率因数");
                    targetName = "总位移功率因数";
                    break;
                case 61:
                    //长时闪变
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    topLimit = overlimit.getFlicker();
                    targetName = "长时闪变";
                    break;
                case 60:
                    //短时闪变
                    topLimit = overlimit.getFlicker();
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    targetName = "短时闪变";
                    break;
                case 62:
                    //电压波动
                    if (ptType == 0) {
                        phasicType.add("A相");
                        phasicType.add("B相");
                        phasicType.add("C相");
                    } else {
                        phasicType.add("AB相");
                        phasicType.add("BC相");
                        phasicType.add("CA相");
                    }
                    targetName = "电压波动";
                    break;
                default:
                    break;
            }
            //大致有3种类型
            //1、一次查询返回3条记录，分别为A/B/C三相的结果
            //2、一次查询返回一条记录，以T相为条件，返回某3个指标值
            //3、一次查询返回一条记录，以T相为条件，返回某1个指标值
            HarmonicHistoryParam historyParam=new HarmonicHistoryParam();
            historyParam.setStartTime(startTime+InfluxDBTableConstant.START_TIME);
            historyParam.setEndTime(endTime+InfluxDBTableConstant.END_TIME);
            historyParam.setValueTypeName(valueTypeName);
            historyParam.setLineId(lineId);
            queryResultLimitVO.setHarmonicHistoryDataList(setHistoryDataList(historyParam,contion,number,type));
            queryResultLimitVO.setTopLimit(topLimit);
            queryResultLimitVO.setLowerLimit(lowerLimit);
            queryResultLimitVO.setPhaiscType(phasicType);
            queryResultLimitVO.setUnit(unit);
            queryResultLimitVO.setLineName(lineDetailDataVO.getPointName());
            queryResultLimitVO.setHarmNum(number);
            queryResultLimitVO.setTargetName(targetName);
        } else {
            return queryResultLimitVO;
        }
        return queryResultLimitVO;
    }

    /**
     * 数值赋值
     * @param historyParam
     * @param contion
     * @param number
     * @param type 区分主配网
     * @return
     */
    private List<HarmonicHistoryData> setHistoryDataList(HarmonicHistoryParam historyParam,String contion,Integer number,Integer type){
        List<HarmonicHistoryData> harmonicHistoryData = new ArrayList<>();
        switch (Integer.parseInt(contion)) {
            case 10:
                harmonicHistoryData=HistoryDataMapper.getDataFluc(historyParam);
                break;
            case 11:
                //线电压有效值
                harmonicHistoryData=HistoryDataMapper.getDataV_lvr(historyParam);
                break;
            case 12:
                //电压偏差
                harmonicHistoryData=HistoryDataMapper.getDataV_vu_dev(historyParam);
                break;
            case 13:
                //三相电压不平衡度
                harmonicHistoryData=HistoryDataMapper.getDataV_v_unbalance(historyParam);
                break;
            case 14:
                //电压不平衡
                harmonicHistoryData=HistoryDataMapper.getDataV_v_zero(historyParam);
                break;
            case 15:
                //电压总谐波畸变率
                harmonicHistoryData=HistoryDataMapper.getDataV_v_thd(historyParam);
                break;
            case 20:
                //电流有效值
                harmonicHistoryData=HistoryDataMapper.getDataI_rms(historyParam);
                break;
            case 21:
                //电流总畸变率
                harmonicHistoryData=HistoryDataMapper.getDataI_i_thd(historyParam);
                break;
            case 22:
                //负序电流
                harmonicHistoryData=HistoryDataMapper.getDataI_i_neg(historyParam);
                break;
            case 30:
                //频率 V9暂时代表Freq
                harmonicHistoryData=HistoryDataMapper.getDataV_i_neg(historyParam);
                break;
            case 40:
                //谐波电压含有率
                harmonicHistoryData=HistoryDataMapper.getDataHarmratV_v(historyParam,number);
                break;
            case 41:
                //谐波电流含有率
                harmonicHistoryData=HistoryDataMapper.getDataHarmratI_i(historyParam,number);
                break;
            case 42:
                //谐波电压幅值
                harmonicHistoryData=HistoryDataMapper.getDataV_v(historyParam,number);
                break;
            case 43:
                //谐波电流幅值
                harmonicHistoryData=HistoryDataMapper.getDataI_i(historyParam,number);
                break;
            case 44:
                //谐波电压相角
                harmonicHistoryData=HistoryDataMapper.getDataHarmphasic_v(historyParam,number);
                break;
            case 45:
                //谐波电流相角
                harmonicHistoryData=HistoryDataMapper.getDataHarmphasic_i(historyParam,number);
                break;
            case 46:
                //间谐波电压含有率

                break;
            case 47:
                //间谐波电流含有率

                break;
            case 48:
                //间谐波电压幅值
                harmonicHistoryData=HistoryDataMapper.getDataInharmrateV_v(historyParam,number);
                break;
            case 49:
                //间谐波电流幅值
                harmonicHistoryData=HistoryDataMapper.getDataInharmrateI_i(historyParam,number);
                break;
            case 50:
                //谐波有功功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerP_p(historyParam,number);
                break;
            case 51:
                //谐波无功功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerQ_q(historyParam,number);
                break;
            case 52:
                //谐波视在功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerS_s(historyParam,number);
                break;
            case 53:
                //三相有功功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerP(historyParam);
                break;
            case 54:
                //三相无功功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerQ(historyParam);
                break;
            case 55:
                //三相视在功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerS(historyParam);
                break;
            case 56:
                //三相总有功功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerP_t(historyParam);
                break;
            case 57:
                //三相总无功功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerQ_t(historyParam);
                break;
            case 58:
                //三相总视在功率
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerS_t(historyParam);
                break;
            case 59:
                //视在功率因数
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerP_pf(historyParam);
                break;
            case 591:
                //位移功率因数
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerP_df(historyParam);
                break;
            case 592:
                //总视在功率因数
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerP_pf_T(historyParam);
                break;
            case 593:
                //总位移功率因数
                harmonicHistoryData=HistoryDataMapper.getDataHarmpowerP_df_T(historyParam);
                break;
            case 61:
                //长时闪变
                harmonicHistoryData=HistoryDataMapper.getDataPlt(historyParam);
                break;
            case 60:
                //短时闪变
                harmonicHistoryData=HistoryDataMapper.getDataFlicker(historyParam);
                break;
            case 62:
                //电压波动
                harmonicHistoryData=HistoryDataMapper.getDataFluc(historyParam);
                break;
            default:
                break;
        }
        return harmonicHistoryData;
    }

    private Float max(Float ding,Float a){
        if(Objects.isNull(ding)){
            ding = a;
        }
        if(a>ding){
            ding = a;
        }
        return  ding;
    }

    private Float min(Float ding,Float a){
        if(Objects.isNull(ding)){
            ding = a;
        }
        if(a<ding){
            ding = a;
        }
        return  ding;
    }
}
