package com.njcn.advance.service.impl;

import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.advance.enums.EnumEvt;
import com.njcn.advance.mapper.RmpEventAdvanceMapper;
import com.njcn.advance.pojo.dto.waveAnalysis.*;
import com.njcn.advance.service.EventWaveAnalysisService;
import com.njcn.advance.utils.JnaCallBalance;
import com.njcn.advance.utils.JnaCallDllOrSo;
import com.njcn.advance.utils.Utils;
import com.njcn.advance.utils.WaveUtils;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.oss.constant.GeneralConstant;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * pqs
 *
 * @author cdf
 * @date 2023/7/28
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class EventWaveAnalysisServiceImpl implements EventWaveAnalysisService {

    private final DicDataFeignClient dicDataFeignClient;

    private final LineFeignClient lineFeignClient;


    private final FileStorageUtil fileStorageUtil;

    private final WaveUtils waveUtils;

    private final RmpEventAdvanceMapper rmpEventAdvanceMapper;


    @Override
    public EntityAdvancedData analysis(String eventIndex) {
        TimeInterval timeInterval = new TimeInterval();
        //调用方法获取暂降事件详情
        RmpEventDetailPO rmpEventDetailPO = rmpEventAdvanceMapper.selectById(eventIndex);
        EntityAdvancedData entityAdvancedData;

        //获取PT变比
        LineDetailDataVO lineDetailDataVO = lineFeignClient.getLineDetailData(rmpEventDetailPO.getLineId()).getData();


        if (rmpEventDetailPO.getFileFlag() == 1) {
            //获取所有暂态原因
            List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_TYPE.getCode()).getData();
            Map<Integer, DictData> eventTypeMap = dicDataList.stream().collect(Collectors.toMap(DictData::getAlgoDescribe, Function.identity()));
            List<DictData> reasonList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_REASON.getCode()).getData();
            Map<Integer, DictData> eventReasonMap = reasonList.stream().collect(Collectors.toMap(DictData::getAlgoDescribe, Function.identity()));
            InputStream inputStreamCfg;
            InputStream inputStreamDat;
            try {
                inputStreamCfg = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.CFG);
                inputStreamDat = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.DAT);
            } catch (Exception e) {
                try {
                    inputStreamCfg = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.CFG.toLowerCase());
                    inputStreamDat = fileStorageUtil.getFileStream(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.DAT.toLowerCase());
                } catch (Exception e1) {

                    throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
                }
            }

            //读取
            BufferedReader bufferedReader;
            InputStreamReader read = null;
            String strFileLine;
            byte[] array = {};
            List<String> temCfgList = new ArrayList<>();
            try {
                // 判断文件是否存在
                array = IoUtil.readBytes(inputStreamDat);
                // 考虑到编码格式
                read = new InputStreamReader(inputStreamCfg, StandardCharsets.UTF_8);
                bufferedReader = new BufferedReader(read);

                while ((strFileLine = bufferedReader.readLine()) != null) {
                    temCfgList.add(strFileLine);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (read != null) {
                        read.close();
                    }
                    if (inputStreamDat != null) {
                        inputStreamDat.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            //原始波形
            WaveData waveOriginalData = getWavedata(rmpEventDetailPO, temCfgList, array, 3);
            List<List<Float>> originalList = waveOriginalData.getSunData();

            entityAdvancedData = new EntityAdvancedData(originalList.size());

            for (int i = 0; i < originalList.size(); i++) {
                //坐标轴
                entityAdvancedData.smp_x[i] = originalList.get(i).get(0);
                entityAdvancedData.smp_a[i] = originalList.get(i).get(1);
                entityAdvancedData.smp_b[i] = originalList.get(i).get(2);
                entityAdvancedData.smp_c[i] = originalList.get(i).get(3);
            }
            entityAdvancedData.smp_len = originalList.size();

            //抽点方法计算波形
            WaveData wavePitchData = getWavedata(rmpEventDetailPO, temCfgList, array, 0);
            List<List<Float>> pitchList = wavePitchData.getSunData();

            // 将获取到的数据填充到结构体内
            Rect rect = new Rect();
            CauseStruct causeStruct = new CauseStruct();

            for (int i = 0; i < pitchList.size(); i++) {
                rect.smp_va[i] = pitchList.get(i).get(1);
                causeStruct.smp_va[i] = pitchList.get(i).get(1);

                rect.smp_vb[i] = pitchList.get(i).get(2);
                causeStruct.smp_vb[i] = pitchList.get(i).get(2);

                rect.smp_vc[i] = pitchList.get(i).get(3);
                causeStruct.smp_vc[i] = pitchList.get(i).get(3);
            }

            rect.smp_len = pitchList.size();

            //超过60s的波形直接抛异常给上面处理
            /*
             * 波形最大值计算
             */
            int MAX_LENGTH = 128 * 3000;
            if (rect.smp_len >= MAX_LENGTH) {
                throw new BusinessException("波形超过60S");
            }

            rect.smp_rate = (int) wavePitchData.getnOneWaveNum();
            causeStruct.smp_len = pitchList.size();
            causeStruct.smp_rate = (int) wavePitchData.getnOneWaveNum();

            String hdrStr = waveUtils.getFile(OssPath.WAVE_DIR + lineDetailDataVO.getIp() + StrUtil.SLASH + rmpEventDetailPO.getWavePath() + GeneralConstant.HDR_LOWER);
            JSONObject jsonObject = JSONObject.fromObject(hdrStr);
            translateData(jsonObject, rmpEventDetailPO.getStartTime(), entityAdvancedData);

            if (!Objects.equals(rmpEventDetailPO.getDealFlag(),1) ) {
                //如果存在三个文件但是没有调用dll/so计算
                getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
            }


            /****************************************************************
             * 根据返回的结果计算，获取暂降类型描述
             ****************************************************************/
            if (entityAdvancedData.backNumber > 0) {
                for (int i = 0; i < entityAdvancedData.backNumber; i++) {
                    entityAdvancedData.sagType[i] = eventTypeMap.get(entityAdvancedData.evt_buf[i].qvvr_cata_type[0]).getName();
                    entityAdvancedData.sagReason[i]= eventReasonMap.get(entityAdvancedData.evt_buf[i].qvvr_cata_cause[0]).getName();
                    switch (entityAdvancedData.evt_buf[i].qvvr_phasetype[0]) {
                        case 1:
                            entityAdvancedData.sagPhaseType[i] = "单相";
                            break;
                        case 2:
                            entityAdvancedData.sagPhaseType[i] = "两相";
                            break;
                        case 3:
                            entityAdvancedData.sagPhaseType[i] = "三相";
                            break;
                        default:
                            break;
                    }
                }
            }
        } else {
            throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
        }

        log.info("高级算法波形计算" + timeInterval.interval());
        return entityAdvancedData;
    }

    @Override
    public EntityAdvancedData analysisWlEvent(String eventIndex) {
        TimeInterval timeInterval = new TimeInterval();
        //调用方法获取暂降事件详情
        RmpEventDetailPO rmpEventDetailPO = rmpEventAdvanceMapper.selectById(eventIndex);
        EntityAdvancedData entityAdvancedData;

        if (Objects.isNull(rmpEventDetailPO.getFileFlag())) {
            throw new BusinessException("系统检测到波形文件未从装置招到本地,请联系管理员");
        }

        if (rmpEventDetailPO.getFileFlag() == 1) {
            //获取所有暂态原因
            List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_TYPE.getCode()).getData();
            Map<Integer, DictData> eventTypeMap = dicDataList.stream().collect(Collectors.toMap(DictData::getAlgoDescribe, Function.identity()));
            InputStream inputStreamCfg;
            InputStream inputStreamDat;
            try {
                inputStreamCfg = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath()+ GeneralConstant.CFG);
                inputStreamDat = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.DAT);
            } catch (Exception e) {
                try {
                    inputStreamCfg = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.CFG.toLowerCase());
                    inputStreamDat = fileStorageUtil.getFileStream(rmpEventDetailPO.getWavePath() + GeneralConstant.DAT.toLowerCase());
                } catch (Exception e1) {
                    throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
                }
            }

            //读取
            BufferedReader bufferedReader;
            InputStreamReader read = null;
            String strFileLine;
            byte[] array = {};
            List<String> temCfgList = new ArrayList<>();
            try {
                // 判断文件是否存在
                array = IoUtil.readBytes(inputStreamDat);
                // 考虑到编码格式
                read = new InputStreamReader(inputStreamCfg, StandardCharsets.UTF_8);
                bufferedReader = new BufferedReader(read);

                while ((strFileLine = bufferedReader.readLine()) != null) {
                    temCfgList.add(strFileLine);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (read != null) {
                        read.close();
                    }
                    if (inputStreamDat != null) {
                        inputStreamDat.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            //原始波形
            WaveData waveOriginalData = getWavedata(rmpEventDetailPO, temCfgList, array, 3);
            List<List<Float>> originalList = waveOriginalData.getSunData();

            entityAdvancedData = new EntityAdvancedData(originalList.size());

            for (int i = 0; i < originalList.size(); i++) {
                //坐标轴
                entityAdvancedData.smp_x[i] = originalList.get(i).get(0);
                entityAdvancedData.smp_a[i] = originalList.get(i).get(1);
                entityAdvancedData.smp_b[i] = originalList.get(i).get(2);
                entityAdvancedData.smp_c[i] = originalList.get(i).get(3);
            }
            entityAdvancedData.smp_len = originalList.size();

            //抽点方法计算波形
            WaveData wavePitchData = getWavedata(rmpEventDetailPO, temCfgList, array, 0);
            List<List<Float>> pitchList = wavePitchData.getSunData();

            // 将获取到的数据填充到结构体内
            Rect rect = new Rect();
            CauseStruct causeStruct = new CauseStruct();

            for (int i = 0; i < pitchList.size(); i++) {
                rect.smp_va[i] = pitchList.get(i).get(1);
                causeStruct.smp_va[i] = pitchList.get(i).get(1);

                rect.smp_vb[i] = pitchList.get(i).get(2);
                causeStruct.smp_vb[i] = pitchList.get(i).get(2);

                rect.smp_vc[i] = pitchList.get(i).get(3);
                causeStruct.smp_vc[i] = pitchList.get(i).get(3);
            }

            rect.smp_len = pitchList.size();

            //超过60s的波形直接抛异常给上面处理
            /*
             * 波形最大值计算
             */
            int MAX_LENGTH = 128 * 3000;
            if (rect.smp_len >= MAX_LENGTH) {
                throw new BusinessException("波形超过60S");
            }

            rect.smp_rate = (int) wavePitchData.getnOneWaveNum();
            causeStruct.smp_len = pitchList.size();
            causeStruct.smp_rate = (int) wavePitchData.getnOneWaveNum();

            if (rmpEventDetailPO.getDealFlag() != 1) {
                //如果存在三个文件但是没有调用dll/so计算
                getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
            } else {
                //已经处理过了，那就根据id获取暂降原因
                String reason = rmpEventDetailPO.getAdvanceReason();
                List<DictData> reasonList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_REASON.getCode()).getData();
                Map<String, DictData> eventReasonMap = reasonList.stream().collect(Collectors.toMap(DictData::getId, Function.identity()));
                if (ObjectUtil.isNotNull(eventReasonMap.get(reason))) {
                    entityAdvancedData.sagReason[0] = eventReasonMap.get(reason).getName();
                }
            }

            String hdrStr = null;
            try {
                hdrStr = waveUtils.getFile(rmpEventDetailPO.getWavePath() + GeneralConstant.HDR.toLowerCase());
            } catch (Exception e) {
                log.error("读取文件服务器波形数据异常：{}",e.getMessage());
            }
            if (hdrStr != null) {
                JSONObject jsonObject = JSONObject.fromObject(hdrStr);
                translateData(jsonObject, rmpEventDetailPO.getStartTime(), entityAdvancedData);
            }

//            if (rmpEventDetailPO.getDealFlag() != 1) {
//                //如果存在三个文件但是没有调用dll/so计算
//                getDataFromDLL(rmpEventDetailPO, waveOriginalData, rect, entityAdvancedData, causeStruct);
//            }

            /****************************************************************
             * 根据返回的结果计算，获取暂降类型描述
             ****************************************************************/
            if (entityAdvancedData.backNumber > 0) {
                for (int i = 0; i < entityAdvancedData.backNumber; i++) {
                    entityAdvancedData.sagType[i] = eventTypeMap.get(entityAdvancedData.evt_buf[i].qvvr_cata_type[0]).getName();
                    switch (entityAdvancedData.evt_buf[i].qvvr_phasetype[0]) {
                        case 1:
                            entityAdvancedData.sagPhaseType[i] = "单相";
                            break;
                        case 2:
                            entityAdvancedData.sagPhaseType[i] = "两相";
                            break;
                        case 3:
                            entityAdvancedData.sagPhaseType[i] = "三相";
                            break;
                        default:
                            break;
                    }
                }
            }
        } else {
            throw new BusinessException("暂降cfg,dat文件缺失,请联系管理员");
        }
        log.info("高级算法波形计算" + timeInterval.interval());
        return entityAdvancedData;
    }

    /**
     * 事件未进行高级算法处理：系统调用dll处理并保存结果
     */
    @Transactional(rollbackFor = Exception.class)
    public void getDataFromDLL(RmpEventDetailPO rmpEventDetailPOQuery, WaveData waveData, Rect rect, EntityAdvancedData entityAdvancedData, CauseStruct causeStruct) {

        if (StrUtil.isBlank(rmpEventDetailPOQuery.getAdvanceType())) {
            JnaCallDllOrSo jnaCallDllOrSo = new JnaCallBalance("qvvr_dll");
            jnaCallDllOrSo.setPath();
            // 计算暂降类
            JnaCallBalance.Eventlibrary INSTANTCE = JnaCallBalance.Eventlibrary.INSTANTCE;
            INSTANTCE.qvvr_fun(rect);

            initBackData(rect.evt_num, entityAdvancedData);

            /*
             * @判断是否调用成功
             * @成功执行更新pqs_eventdetail操作:更新dq持续时间、暂降类型、暂降原因、总分段数目
             */
            if (rect.evt_num > 0) {
                RmpEventDetailPO rmpEventDetailPO = new RmpEventDetailPO();
                rmpEventDetailPO.setEventId(rmpEventDetailPOQuery.getEventId());
                rmpEventDetailPO.setNum(rect.evt_num);
                rmpEventDetailPO.setDqTime((double) rect.evt_buf[0].hold_time_dq);
                rmpEventDetailPO.setFirstType((Integer.toString(rect.evt_buf[0].qvvr_cata_type[0])));
                rmpEventDetailPO.setFirstTime(waveData.getFirstTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
                rmpEventDetailPO.setFirstMs((double) waveData.getFirstMs());


                // 排序并获取多段中最小的数据
                float[] f = new float[rect.evt_num];

                for (int i = 0; i < rect.evt_num; i++) {
                    Arrays.parallelSort(rect.evt_buf[i].u3_min, 0, Math.max(rect.evt_buf[i].u_min_num - 1, 0));
                    f[i] = rect.evt_buf[i].u3_min[0];
                }

                float min = f[0];
                int index = 0;

                for (int len = 1; len < f.length; len++) {
                    if (min - f[len] > 0) {
                        index = len;
                        min = f[len];
                    }
                }

                /********************************************************************
                 * add by sw 返回的分段位置需根据采样率进行恢复
                 ********************************************************************/
                List<AnalyWaveModel.tagOneRate> list = waveData.getRatesCfg().OneRate;
                int rate = (int) waveData.getnOneWaveNum();
                int k = 0;
                int l = 0;

                for (int i = 0; i < list.size(); i++) {
                    if (i == 0) {
                        for (int j = 0; j < rect.evt_buf[0].SEG_T_num; j++) {
                            if (list.get(i).nOneSample >= rate && rect.evt_buf[0].SEG_T_idx[j] < list.get(i).nSampleNum
                                    / (list.get(i).nOneSample / rate)) {
                                rect.evt_buf[0].SEG_T_idx[j] = (int) (rect.evt_buf[0].SEG_T_idx[j]
                                        * (list.get(i).nOneSample / rate));
                                k++;
                            }
                        }

                        for (int j = 0; j < rect.evt_buf[0].u_min_num; j++) {
                            if (list.get(i).nOneSample >= rate && rect.evt_buf[0].order_min_idx[j] < list.get(i).nSampleNum
                                    / (list.get(i).nOneSample / rate)) {
                                rect.evt_buf[0].order_min_idx[j] = (int) (rect.evt_buf[0].order_min_idx[j]
                                        * (list.get(i).nOneSample / rate));
                                l++;
                            }
                        }
                    } else {
                        for (int j = k; j < rect.evt_buf[0].SEG_T_num; j++) {
                            int posb = 0;
                            int pose = 0;
                            int pos = 0;

                            for (int kk = 0; kk <= i; kk++) {
                                pose += (int) (list.get(kk).nSampleNum / list.get(kk).nOneSample * rate);

                                if (kk < i) {
                                    posb += (int) (list.get(kk).nSampleNum / list.get(kk).nOneSample * rate);
                                    pos += (int) list.get(kk).nSampleNum;
                                }
                            }

                            if (list.get(i).nOneSample >= rate
                                    && rect.evt_buf[0].SEG_T_idx[j] > posb
                                    && rect.evt_buf[0].SEG_T_idx[j] < pose) {
                                rect.evt_buf[0].SEG_T_idx[j] = (int) ((rect.evt_buf[0].SEG_T_idx[j] - posb) * list.get(i).nOneSample / rate) + pos;
                                k++;
                            }
                        }

                        for (int j = l; j < rect.evt_buf[0].u_min_num; j++) {
                            int posb = 0;
                            int pose = 0;
                            int pos = 0;

                            for (int kk = 0; kk <= i; kk++) {
                                pose += (int) (list.get(kk).nSampleNum / list.get(kk).nOneSample * rate);

                                if (kk < i) {
                                    posb += (int) (list.get(kk).nSampleNum / list.get(kk).nOneSample * rate);
                                    pos += (int) list.get(kk).nSampleNum;
                                }
                            }

                            if (list.get(i).nOneSample >= rate
                                    && rect.evt_buf[0].order_min_idx[j] > posb
                                    && rect.evt_buf[0].order_min_idx[j] < pose) {
                                rect.evt_buf[0].order_min_idx[j] = (int) ((rect.evt_buf[0].order_min_idx[j] - posb) * list.get(i).nSampleNum / rate) + pos;
                                l++;
                            }
                        }
                    }
                }


                List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_TYPE.getCode()).getData();
                Map<Integer, DictData> eventTypeMap = dicDataList.stream().collect(Collectors.toMap(DictData::getAlgoDescribe, Function.identity()));

                Integer tem = rect.evt_buf[index].qvvr_cata_type[0];
                if (eventTypeMap.containsKey(tem)) {
                    rmpEventDetailPO.setAdvanceType(eventTypeMap.get(tem).getId());
                }
                rmpEventDetailPO.setDealFlag(1);
                rmpEventAdvanceMapper.updateById(rmpEventDetailPO);
                //setEntityAdvanceData();
                //WriteData2File();
                //eventDetailMapper.updateDealFlag(1, eventIndex); //计算有结果
            } else if (rect.evt_num == 0) {
                //eventDetailMapper.updateDealFlag(2, eventIndex);//已计算无结果
            }
        }


        if (StrUtil.isBlank(rmpEventDetailPOQuery.getAdvanceReason())) {

            //暂降原因计算
            JnaCallDllOrSo jnaCallDllReason = new JnaCallBalance("qvvr_cause_dll");
            jnaCallDllReason.setPath();

            JnaCallBalance.Balancelibrary CAUSE = JnaCallBalance.Balancelibrary.INSTANTCE;
            CAUSE.qvvr_fun_cause(causeStruct);

            if (causeStruct.no_cal == 1) {
                causeStruct.cause = 0;
            }

            //获取所有暂态原因
            List<DictData> dicDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.EVENT_REASON.getCode()).getData();
            Map<Integer, DictData> eventReasonMap = dicDataList.stream().collect(Collectors.toMap(DictData::getAlgoDescribe, Function.identity()));

            // 暂降原因的结果更新到数据库
            if (eventReasonMap.containsKey(causeStruct.cause)) {
                RmpEventDetailPO updateRmpEventDetailPO = new RmpEventDetailPO();
                updateRmpEventDetailPO.setEventId(rmpEventDetailPOQuery.getEventId());
                updateRmpEventDetailPO.setAdvanceReason(eventReasonMap.get(causeStruct.cause).getId());
                rmpEventAdvanceMapper.updateById(updateRmpEventDetailPO);
                entityAdvancedData.sagReason[0] = eventReasonMap.get(causeStruct.cause).getName();
            }

        }


    }

    public void initBackData(int len, EntityAdvancedData entityAdvancedData) {
        len = (len == 0 ? 1 : len);

        entityAdvancedData.evt_buf = new BackData[len];

        for (int i = 0; i < len; i++) {
            entityAdvancedData.evt_buf[i] = new BackData();
        }
    }

    /**
     * 根据暂降事件索引获取波形数据
     * 注：当前只考虑本地的波形文件
     *
     * @param rmpEventDetailPO 暂态事件
     * @param flag             抽点方式 3.全部数据 1.抽点数据
     */

    public WaveData getWavedata(RmpEventDetailPO rmpEventDetailPO, List<String> temCfgList, byte[] array, int flag) {
        WaveData waveData = new WaveData();

        waveData.setEventValue(PubUtils.floatRound(2, rmpEventDetailPO.getFeatureAmplitude().floatValue() * 100));
        waveData.setPersistTime(PubUtils.floatRound(3, rmpEventDetailPO.getDuration().floatValue() / 1000));
        waveData.setTrigeTime(AnalyWave.getTimeWave());


        // 判断文件是否存在
        if (StrUtil.isNotBlank(rmpEventDetailPO.getWavePath())) {
            log.info(OssPath.WAVE_DIR + rmpEventDetailPO.getWavePath() + "路径下，文件找到了");
            //CFG文件路径 pathTemp
            //获取波形的瞬时值、RMS值数据
            AnalyWave analyWave = new AnalyWave();
            AnalyWaveModel.tagDataValue tagDataValue = analyWave.readComtrade(temCfgList, array, flag);
            //获取瞬时波形值
            List<List<Float>> shunWave = tagDataValue.getListWaveData();
            //RMS值波形
            List<List<Float>> rmsWave = analyWave.showValidData(shunWave);
            waveData.setnOneWaveNum(analyWave.getnOneWaveNum());
            waveData.setSunData(shunWave);
            waveData.setTmpWaveTitle(tagDataValue.getTmpWaveTitle());
            waveData.setFirstMs(analyWave.getFirstMs());
            waveData.setFirstTime(analyWave.getFirstTime());
            waveData.setRmsData(rmsWave);
            waveData.setRatesCfg(analyWave.getRatesCfg());
            /*********** Modify by yexibao ---Start **************/
            waveData.setiPhasic(tagDataValue.getiPhasic());
            /***********  Modify by yexibao ---End  **************/
            List<String> tmpWaveTitle = tagDataValue.getTmpWaveTitle();
            /*********** Modify by yexibao ---Start **************/
            for (int i = 0; i < tagDataValue.getiPhasic(); i++) {
                if (tmpWaveTitle.get(i + 1).substring(1).contains("A")) {
                    waveData.setA(tmpWaveTitle.get(i + 1).substring(1));
                }
                if (tmpWaveTitle.get(i + 1).substring(1).contains("B")) {
                    waveData.setB(tmpWaveTitle.get(i + 1).substring(1));
                }
                if (tmpWaveTitle.get(i + 1).substring(1).contains("C")) {
                    waveData.setC(tmpWaveTitle.get(i + 1).substring(1));
                }
            }
            /***********  Modify by yexibao ---End  **************/

        } else {
            log.error(OssPath.WAVE_DIR + rmpEventDetailPO.getWavePath() + "路径下，文件找不到了");
        }

        return waveData;
    }


    public void translateData(JSONObject jsonObject, LocalDateTime trigeTime, EntityAdvancedData entityAdvancedData) {
        int len = Utils.getIntValue(jsonObject.get(EnumEvt.EVT_NUM.getProperty()).toString(), 0);

        entityAdvancedData.backNumber = len;
        //初始化EntityAdvancedData的BackData数据
//        len = (len == 0 ? 1 : len);
        entityAdvancedData.evt_buf = new BackData[len];
        for (int i = 0; i < len; i++) {
            entityAdvancedData.evt_buf[i] = new BackData();
        }

        for (int offset = 0; offset < len; offset++) {
            BackData backData = new BackData();
            /*
             * @波形起始点(3相)
             */
            backData.POW_a = Utils.getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.POW_A.getProperty()).toString(), 0.0f);
            backData.POW_b = Utils.getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.POW_B.getProperty()).toString(), 0.0f);
            backData.POW_c = Utils.getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.POW_C.getProperty()).toString(), 0.0f);

            /*
             * @跳变段电压变化
             */
            backData.Voltagechange_Va = Utils.getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.VOLTAGECHANGE_VA.getProperty()).toString(), 0.0f);
            backData.Voltagechange_Vb = Utils.getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.VOLTAGECHANGE_VB.getProperty()).toString(), 0.0f);
            backData.Voltagechange_Vc = Utils.getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.VOLTAGECHANGE_VC.getProperty()).toString(), 0.0f);

            /*
             * @持续时间
             */
            backData.hold_time_rms = Utils.getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.HOLD_TIME_RMS.getProperty()).toString(), 0.0f);
            backData.hold_time_dq = Utils.getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.HOLD_TIME_DQ.getProperty()).toString(), 0.0f);

            /*
             * @分段信息
             */
            backData.SEG_T_num = Utils.getIntValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.SEG_T_NUM.getProperty()).toString(), 0);

            for (int i = 0; i < backData.SEG_T_num; i++) {
                backData.SEG_T_idx[i] = Utils.getIntValue(
                        jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.SEG_T_IDX.getProperty()).get(Integer.toString(i)).toString(),
                        -1);
            }

            /*
             * @特征幅值
             */
            backData.u_min_num = Utils.getIntValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                    .getJSONObject(offset).get(EnumEvt.U_MIN_NUM.getProperty()).toString(), 0);

            for (int j = 0; j < backData.u_min_num; j++) {
                backData.ua_min[j] = Utils
                        .getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.UA_MIN.getProperty()).get(Integer.toString(j)).toString(), 0.0f);
                backData.ub_min[j] = Utils
                        .getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.UB_MIN.getProperty()).get(Integer.toString(j)).toString(), 0.0f);
                backData.uc_min[j] = Utils
                        .getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.UC_MIN.getProperty()).get(Integer.toString(j)).toString(), 0.0f);
                backData.u3_min[j] = Utils
                        .getFloatValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.U3_MIN.getProperty()).get(Integer.toString(j)).toString(), 0.0f);

                /*
                 * @相位跳变
                 */
                backData.angle_diff_an[j] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.ANGLE_DIFF_AN.getProperty()).get(Integer.toString(j)).toString(),
                        0.0f);
                backData.angle_diff_bn[j] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.ANGLE_DIFF_BN.getProperty()).get(Integer.toString(j)).toString(),
                        0.0f);
                backData.angle_diff_cn[j] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.ANGLE_DIFF_CN.getProperty()).get(Integer.toString(j)).toString(),
                        0.0f);
                backData.angle_diff_ap[j] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.ANGLE_DIFF_AP.getProperty()).get(Integer.toString(j)).toString(),
                        0.0f);
                backData.angle_diff_bp[j] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.ANGLE_DIFF_BP.getProperty()).get(Integer.toString(j)).toString(),
                        0.0f);
                backData.angle_diff_cp[j] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.ANGLE_DIFF_CP.getProperty()).get(Integer.toString(j)).toString(),
                        0.0f);

                /*
                 * @不平衡度
                 */
                backData.bph_max_value[j] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty()).getJSONObject(offset)
                                .getJSONObject(EnumEvt.BPH_MAX_VALUE.getProperty()).get(Integer.toString(j)).toString(),
                        0.0f);

                /*
                 * @暂降原因
                 */
                backData.qvvr_cata_cause[j] = Utils.getIntValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                        .getJSONObject(offset).getJSONObject(EnumEvt.QVVR_CATA_CAUSE.getProperty())
                        .get(Integer.toString(j)).toString(), -1);

                /*
                 * @暂降类型
                 */
                backData.qvvr_cata_type[j] = Utils.getIntValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                        .getJSONObject(offset).getJSONObject(EnumEvt.QVVR_CATA_TYPE.getProperty())
                        .get(Integer.toString(j)).toString(), -1);

                /*
                 * @暂降相别
                 */
                backData.qvvr_phasetype[j] = Utils.getIntValue(jsonObject.getJSONArray(EnumEvt.EVT_BUF.getProperty())
                        .getJSONObject(offset).getJSONObject(EnumEvt.QVVR_PHASETYPE.getProperty())
                        .get(Integer.toString(j)).toString(), -1);
            }

            entityAdvancedData.evt_buf[offset] = backData;
        }

        if (jsonObject.containsKey(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty())) {
            if (!jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).isEmpty()) {
                entityAdvancedData.power_after_buf = new PowerData[1];
                PowerData power = new PowerData();
                float[] fundP = new float[5];
                fundP[0] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_P.getProperty()).get("A").toString(), 0.0f);
                fundP[1] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_P.getProperty()).get("B").toString(), 0.0f);
                fundP[2] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_P.getProperty()).get("C").toString(), 0.0f);
                fundP[3] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_P.getProperty()).get("total").toString(), 0.0f);
                fundP[4] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_P.getProperty()).get("zero").toString(), 0.0f);
                power.setFundP(fundP);

                float[] fundQ = new float[5];
                fundQ[0] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_Q.getProperty()).get("A").toString(), 0.0f);
                fundQ[1] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_Q.getProperty()).get("B").toString(), 0.0f);
                fundQ[2] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_Q.getProperty()).get("C").toString(), 0.0f);
                fundQ[3] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_Q.getProperty()).get("total").toString(), 0.0f);
                fundQ[4] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_Q.getProperty()).get("zero").toString(), 0.0f);
                power.setFundQ(fundQ);

                float[] fundS = new float[5];
                fundS[0] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_S.getProperty()).get("A").toString(), 0.0f);
                fundS[1] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_S.getProperty()).get("B").toString(), 0.0f);
                fundS[2] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_S.getProperty()).get("C").toString(), 0.0f);
                fundS[3] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_S.getProperty()).get("total").toString(), 0.0f);
                fundS[4] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.POWER_QVVR_AFTER_BUF.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.FUND_S.getProperty()).get("zero").toString(), 0.0f);
                power.setFundS(fundS);
                entityAdvancedData.power_after_buf[0] = power;
            }
        }
        if (jsonObject.containsKey(EnumEvt.QVVR_DIRECTION_INFO.getProperty())) {
            if (!jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).isEmpty()) {
                entityAdvancedData.qvvr_direction_info = new DirectionData[1];
                DirectionData direction = new DirectionData();
                int[] trigTime = new int[7];
                trigTime[0] = Utils.getIntValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("year").toString(), 0);
                trigTime[1] = Utils.getIntValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("month").toString(), 0);
                trigTime[2] = Utils.getIntValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("date").toString(), 0);
                trigTime[3] = Utils.getIntValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("hour").toString(), 0);
                trigTime[4] = Utils.getIntValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("minute").toString(), 0);
                trigTime[5] = Utils.getIntValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("second").toString(), 0);
                trigTime[6] = Utils.getIntValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("millisecond").toString(), 0);
                direction.setTrigTime(trigTime);

                float[] qvvrBeforeRms = new float[6];
                qvvrBeforeRms[0] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_RMS.getProperty()).get("Fund_Ua").toString(), 0.0f);
                qvvrBeforeRms[1] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_RMS.getProperty()).get("Fund_Ub").toString(), 0.0f);
                qvvrBeforeRms[2] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_RMS.getProperty()).get("Fund_Uc").toString(), 0.0f);
                qvvrBeforeRms[3] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_RMS.getProperty()).get("Fund_Ia").toString(), 0.0f);
                qvvrBeforeRms[4] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_RMS.getProperty()).get("Fund_Ib").toString(), 0.0f);
                qvvrBeforeRms[5] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_RMS.getProperty()).get("Fund_Ic").toString(), 0.0f);
                direction.setQvvrBeforeRms(qvvrBeforeRms);

                float[] qvvrBeforeZk = new float[6];
                qvvrBeforeZk[0] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_ZK.getProperty()).get("Za").toString(), 0.0f);
                qvvrBeforeZk[1] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_ZK.getProperty()).get("Zb").toString(), 0.0f);
                qvvrBeforeZk[2] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_ZK.getProperty()).get("Zc").toString(), 0.0f);
                qvvrBeforeZk[3] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_ZK.getProperty()).get("Zab").toString(), 0.0f);
                qvvrBeforeZk[4] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_ZK.getProperty()).get("Zbc").toString(), 0.0f);
                qvvrBeforeZk[5] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_BEFORE_ZK.getProperty()).get("Zca").toString(), 0.0f);
                direction.setQvvrBeforeZk(qvvrBeforeZk);

                float[] qvvrOccurRms = new float[6];
                qvvrOccurRms[0] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_RMS.getProperty()).get("Fund_Ua").toString(), 0.0f);
                qvvrOccurRms[1] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_RMS.getProperty()).get("Fund_Ub").toString(), 0.0f);
                qvvrOccurRms[2] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_RMS.getProperty()).get("Fund_Uc").toString(), 0.0f);
                qvvrOccurRms[3] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_RMS.getProperty()).get("Fund_Ia").toString(), 0.0f);
                qvvrOccurRms[4] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_RMS.getProperty()).get("Fund_Ib").toString(), 0.0f);
                qvvrOccurRms[5] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_RMS.getProperty()).get("Fund_Ic").toString(), 0.0f);
                direction.setQvvrOccurRms(qvvrOccurRms);

                float[] qvvrOccurZk = new float[6];
                qvvrOccurZk[0] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_ZK.getProperty()).get("Za").toString(), 0.0f);
                qvvrOccurZk[1] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_ZK.getProperty()).get("Zb").toString(), 0.0f);
                qvvrOccurZk[2] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_ZK.getProperty()).get("Zc").toString(), 0.0f);
                qvvrOccurZk[3] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_ZK.getProperty()).get("Zab").toString(), 0.0f);
                qvvrOccurZk[4] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_ZK.getProperty()).get("Zbc").toString(), 0.0f);
                qvvrOccurZk[5] = Utils.getFloatValue(
                        jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                                .getJSONObject(EnumEvt.QVVR_OCCUR_ZK.getProperty()).get("Zca").toString(), 0.0f);
                direction.setQvvrOccurZk(qvvrOccurZk);

                String[] qvvrPosInfo = new String[1];
                qvvrPosInfo[0] = jsonObject.getJSONArray(EnumEvt.QVVR_DIRECTION_INFO.getProperty()).getJSONObject(0)
                        .getJSONObject(EnumEvt.QVVR_POS_INFO.getProperty()).get("direction").toString();
                direction.setQvvrPosInfo(qvvrPosInfo);

                entityAdvancedData.qvvr_direction_info[0] = direction;
            }
        }
        if (jsonObject.containsKey(EnumEvt.QVVR_UTBL_INFO.getProperty())) {
            if (!jsonObject.getJSONArray(EnumEvt.QVVR_UTBL_INFO.getProperty()).isEmpty()) {
                entityAdvancedData.qvvr_utbl_info = new UtblData[1];
                UtblData direction = new UtblData();
                long[] trigTime = new long[1];
                String year = jsonObject.getJSONArray(EnumEvt.QVVR_UTBL_INFO.getProperty()).getJSONObject(0)
                        .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("year").toString();
                String month = jsonObject.getJSONArray(EnumEvt.QVVR_UTBL_INFO.getProperty()).getJSONObject(0)
                        .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("month").toString();
                String day = jsonObject.getJSONArray(EnumEvt.QVVR_UTBL_INFO.getProperty()).getJSONObject(0)
                        .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("date").toString();
                String hour = jsonObject.getJSONArray(EnumEvt.QVVR_UTBL_INFO.getProperty()).getJSONObject(0)
                        .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("hour").toString();
                String min = jsonObject.getJSONArray(EnumEvt.QVVR_UTBL_INFO.getProperty()).getJSONObject(0)
                        .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("minute").toString();
                String sec = jsonObject.getJSONArray(EnumEvt.QVVR_UTBL_INFO.getProperty()).getJSONObject(0)
                        .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("second").toString();
                String mil = jsonObject.getJSONArray(EnumEvt.QVVR_UTBL_INFO.getProperty()).getJSONObject(0)
                        .getJSONObject(EnumEvt.TRIG_TIME.getProperty()).get("millisecond").toString();
                SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
                Date utbl = null;
                try {
                    utbl = dfs.parse(year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec + "." + mil);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                long between = 0;
                if (utbl != null) {
                    between = utbl.getTime() - trigeTime.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
                }
                trigTime[0] = between;
                direction.setTrigTime(trigTime);
                entityAdvancedData.qvvr_utbl_info[0] = direction;
            }
        }


    }


}
