package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IdxBizFanPointProcessVariableClassificationDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IdxBizPvPointProcessVariableClassificationDto;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.*;
import com.yeejoin.amos.boot.module.jxiop.biz.mapper2.*;
import com.yeejoin.amos.component.influxdb.InfluxdbUtil;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Service
public class CommonServiceImpl {
    //utc时间格式
    public static final String FORMAT_UTC = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    public static final String FORMAT_DEFAULT = "yyyy-MM-dd HH:mm:ss";
    private static final Logger logger = LoggerFactory.getLogger(CommonServiceImpl.class);
    //-----------------调用算法时间间隔----------------
    @Value("${sleep.time:10}")
    Integer sleepTime;
    @Value("${sleep.time:30}")
    Integer zxzsleepTime;
    @Value("${base.url:http://36.40.66.175:30009/maas/maas/processes/api/}")
    String baseUrl;
    //----------------工况变量工况变量划分请求属性配置------------------------
    @Value("${gkblhffan.url:74435221-796d-43c0-ae72-319792b8f89e}")
    String gkqjhfurlfan;
    @Value("${gkblhfpv.url:e884fccf-b7ac-4fa4-bdb7-a5b6ff7319ec}")
    String gkqjhfurlpv;
    @Value("${gkblhf.key:input 1}")
    String gkqjhfkey;
    //----------------工况变量相关性计算请求属性配置------------------------
    @Value("${gkxgxfxfan.url:b5797e0a-d456-44d3-9f21-9528e5321b74}")
    String gkxgxfxurlfan;
    @Value("${gkxgxfxpv.url:f5457bfe-0780-418d-9287-c4f31d3fb4c7}")
    String gkxgxfxurlpv;
    @Value("${gkxgxfx.key:input 1}")
    String gkxgxfxkey;
    //----------------工况变量中心值计算相关请求属性配置------------------------
    @Value("${gkzxzjsfan.url:a6f8d689-0028-445e-b797-493b5ac65e42}")
    String gkzxzjsurlfan;
    @Value("${gkzxzjspv.url:5c9fc897-a9f2-4563-8d7b-8cf60c6a663f}")
    String gkzxzjsurlpv;
    @Value("${gkzxzjs.key:input 1}")
    String gkzxzjskey1;

    @Value("${gkzxzjs.key:input 2}")
    String gkzxzjskey2;

    //----------------健康指数值计算相关请求属性配置------------------------
    @Value("${jkzsjs.url:aec8ad20-6d63-4f62-99f6-2d71756cacb6}")
    String jkzsjsfjurl;

    @Value("${jkzsjs.url:a9a404d4-6ead-440e-9fcb-b95d5a239b10}")
    String jkzsgfurl;

    //    {"tableName": "idx_biz_fan_point_process_variable_classification"} 风机工况变量划分
    //    {"tableName": "idx_biz_pv_point_process_variable_classification"}  光伏工况变量画分
    //    {"tableName": "idx_biz_fan_point_var_correlation"} 风机相关性
    //    {"tableName": "idx_biz_pv_point_var_correlation"} 光伏相关性
    @Autowired
    private IdxBizFanPointProcessVariableClassificationMapper idxBizFanPointProcessVariableClassificationMapper;
    @Autowired
    private IdxBizPvPointProcessVariableClassificationMapper idxBizPvPointProcessVariableClassificationMapper;
    @Autowired
    private IdxBizFanPointVarCorrelationMapper idxBizFanPointVarCorrelationMapper;
    @Autowired
    private IdxBizPvPointVarCorrelationMapper idxBizPvPointVarCorrelationMapper;
    @Autowired
    private InfluxdbUtil influxdbUtil;
    @Autowired
    IdxBizFanHealthIndexServiceImpl idxBizFanHealthIndexService;

    @Autowired
    IdxBizPvHealthIndexServiceImpl idxBizPvHealthIndexService;
    @Autowired
    IdxBizFanHealthLevelMapper idxBizFanHealthLevelMapper;
    @Autowired
    IdxBizPvHealthLevelMapper idxBizPvHealthLevelMapper;

    @Autowired
    private ElasticsearchRestTemplate elasticsearchTemplate;

    @Autowired
    IdxBizFanPointVarCentralValueMapper idxBizFanPointVarCentralValueMapper;

    @Autowired
    IdxBizPvPointVarCentralValueMapper idxBizPvPointVarCentralValueMapper;

    /**
     * @return
     * @deprecated 获取工况变量列表风机
     */
    public HashMap<String, List<IdxBizFanPointProcessVariableClassification>> getIdxBizFanPointProcessVariableClassificationList() {

        HashMap<String, List<IdxBizFanPointProcessVariableClassification>> idxBizFanPointProcessVariableClassification = new HashMap<>();
        List<String> gateWayIdList = idxBizFanPointProcessVariableClassificationMapper.gateWayIdListFan();
        List<IdxBizFanPointProcessVariableClassification> IdxBizFanPointProcessVariableClassificationList = idxBizFanPointProcessVariableClassificationMapper.selectList(new QueryWrapper<IdxBizFanPointProcessVariableClassification>().isNotNull("SEQUENCE_NBR").eq("TAG_CODE", "工况变量"));
        List<IdxBizFanPointProcessVariableClassification> finalIdxBizFanPointProcessVariableClassificationList = IdxBizFanPointProcessVariableClassificationList;
        gateWayIdList.forEach(s -> {
            idxBizFanPointProcessVariableClassification.put("iot_data_" + s, finalIdxBizFanPointProcessVariableClassificationList.stream().filter(idxBizFanPointProcessVariableClassification1 -> idxBizFanPointProcessVariableClassification1.getGatewayId().toString().equals(s)).collect(Collectors.toList()));
        });
        return idxBizFanPointProcessVariableClassification;
    }

    /**
     * @return
     * @deprecated 获取工况变量列表光伏
     */
    public HashMap<String, List<IdxBizPvPointProcessVariableClassification>> getIdxBizPvPointProcessVariableClassificationList() {

        HashMap<String, List<IdxBizPvPointProcessVariableClassification>> idxBizPvPointProcessVariableClassificationHashMap = new HashMap<>();
        List<String> gateWayIdList = idxBizPvPointProcessVariableClassificationMapper.gateWayIdListPv();
        List<IdxBizPvPointProcessVariableClassification> idxBizPvPointProcessVariableClassificationList = idxBizPvPointProcessVariableClassificationMapper.selectList(new QueryWrapper<IdxBizPvPointProcessVariableClassification>().isNotNull("SEQUENCE_NBR").eq("TAG_CODE", "工况变量"));
        List<IdxBizPvPointProcessVariableClassification> finalIdxBizPvPointProcessVariableClassificationList = idxBizPvPointProcessVariableClassificationList;
        gateWayIdList.forEach(s -> {
            idxBizPvPointProcessVariableClassificationHashMap.put("iot_data_" + s, finalIdxBizPvPointProcessVariableClassificationList.stream().filter(idxBizFanPointProcessVariableClassification -> idxBizFanPointProcessVariableClassification.getGatewayId().toString().equals(s)).collect(Collectors.toList()));
        });
        return idxBizPvPointProcessVariableClassificationHashMap;
    }

    //遍历工况列表数据-风机
    public void getFanConditionVariablesByTime(String startTime, String endTime) {
        String startTimeUTC = getUtcTimeString(startTime);
        String endTimeUTC =getUtcTimeString(endTime);
        HashMap<String, List<IdxBizFanPointProcessVariableClassification>> idxBizFanPointProcessVariableClassificationHashMap = getIdxBizFanPointProcessVariableClassificationList();
        idxBizFanPointProcessVariableClassificationHashMap.keySet().forEach(s -> {
            List<IdxBizFanPointProcessVariableClassification> list = idxBizFanPointProcessVariableClassificationHashMap.get(s);
            if (list.size() > 0) {
                foreachHandlerConditionVariabFan(s, list, startTimeUTC, endTimeUTC);
            }
        });
    }

    //遍历工况列表数据-光伏
    public void getPvConditionVariablesByTime(String startTime, String endTime) {
        String startTimeUTC = getUtcTimeString(startTime);
        String endTimeUTC =getUtcTimeString(endTime);
        HashMap<String, List<IdxBizPvPointProcessVariableClassification>> idxBizPvPointProcessVariableClassificationHashMap = getIdxBizPvPointProcessVariableClassificationList();
        idxBizPvPointProcessVariableClassificationHashMap.keySet().forEach(s -> {
            List<IdxBizPvPointProcessVariableClassification> list = idxBizPvPointProcessVariableClassificationHashMap.get(s);
            if (list.size() > 0) {
                foreachHandlerConditionVariabPv(s, list, startTimeUTC, endTimeUTC);
            }
        });
    }

    //遍历查询数据并调用并计算-风机
    public void foreachHandlerConditionVariabFan(String tableName, List<IdxBizFanPointProcessVariableClassification> list, String startTime, String endTime) {
        list.forEach(idxBizFanPointProcessVariableClassification -> {
            logger.info("--------------------------------------------风机：：开始查询influxdb--------------------------------");
            List<Map<String, Object>> params = new ArrayList<>();
            String sql = String.format("select value from %s where address='%s' and  time >= '%s' and  time <= '%s' ", tableName, idxBizFanPointProcessVariableClassification.getIndexAddress(),startTime,endTime);
            List<Map<String, Object>> returnList = influxdbUtil.query(sql);
            returnList.forEach((k) -> {
                Map<String, Object> map = new HashMap<>();
                map.put("processVariable", Double.parseDouble(k.get("value").toString()));
                map.put("processVariableId", Long.parseLong(idxBizFanPointProcessVariableClassification.getSequenceNbr()));
                params.add(map);
            });
            if (!params.isEmpty()) {
                logger.info("------------------------------------------风机：：开始调用工况变量区间划分算法----------------------------------------");
                HashMap<String, Object> realParams = new HashMap<>();
                realParams.put(gkqjhfkey, params);
                String repsonse = HttpUtil.createPost(baseUrl + gkqjhfurlfan).body(JSON.toJSONString(realParams)).execute().body();
                if (repsonse.contains("\"status\":200")) {
                    JSONObject jsonObject = JSONObject.parseObject(repsonse);
                    JSONObject result = (JSONObject) jsonObject.get("result");
                    JSONObject result1 = (JSONObject) result.get("result1");
                    JSONArray rows = (JSONArray) result1.get("rows");
                    JSONObject values = rows.getJSONObject(0);
                    idxBizFanPointProcessVariableClassification.setIntervalValue5(values.getDoubleValue("intervalValue5"));
                    idxBizFanPointProcessVariableClassification.setIntervalValue4(values.getDoubleValue("intervalValue4"));
                    idxBizFanPointProcessVariableClassification.setIntervalValue3(values.getDoubleValue("intervalValue3"));
                    idxBizFanPointProcessVariableClassification.setIntervalValue2(values.getDoubleValue("intervalValue2"));
                    idxBizFanPointProcessVariableClassification.setIntervalValue1(values.getDoubleValue("intervalValue1"));
                    idxBizFanPointProcessVariableClassificationMapper.updateById(idxBizFanPointProcessVariableClassification);
                    logger.info("------------------------------------------风机：：工况变量区间划分更新业务表成功----------------------------------------");
                }
                try {
                    logger.info(repsonse);
                    TimeUnit.SECONDS.sleep(sleepTime);
                    logger.info("------------------------------------------风机：：调用工况变量区间划分算法结束----------------------------------------");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

    }

    //遍历查询数据并调用并计算-光伏
    public void foreachHandlerConditionVariabPv(String tableName, List<IdxBizPvPointProcessVariableClassification> list, String startTime, String endTime) {
        list.forEach(idxBizPvPointProcessVariableClassification -> {
            logger.info("--------------------------------------------光伏：：开始查询influxdb--------------------------------");
            List<Map<String, Object>> params = new ArrayList<>();
            String sql = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s'  ", tableName, idxBizPvPointProcessVariableClassification.getIndexAddress(),startTime,endTime);
            List<Map<String, Object>> returnList = influxdbUtil.query(sql);
            returnList.forEach((k) -> {
                Map<String, Object> map = new HashMap<>();
                map.put("processVariable", Double.parseDouble(k.get("value").toString()));
                map.put("processVariableId", Long.parseLong(idxBizPvPointProcessVariableClassification.getSequenceNbr()));
                params.add(map);
            });
            if (!params.isEmpty()) {
                logger.info("------------------------------------------光伏：：开始调用工况变量区间划分算法----------------------------------------");
                HashMap<String, Object> realParams = new HashMap<>();
                realParams.put(gkqjhfkey, params);
                String repsonse = HttpUtil.createPost(baseUrl + gkqjhfurlpv).body(JSON.toJSONString(realParams)).execute().body();
                if (repsonse.contains("\"status\":200")) {
                    JSONObject jsonObject = JSONObject.parseObject(repsonse);
                    JSONObject result = (JSONObject) jsonObject.get("result");
                    JSONObject result1 = (JSONObject) result.get("result1");
                    JSONArray rows = (JSONArray) result1.get("rows");
                    JSONObject values = rows.getJSONObject(0);
                    idxBizPvPointProcessVariableClassification.setIntervalValue5(values.getDoubleValue("intervalValue5"));
                    idxBizPvPointProcessVariableClassification.setIntervalValue4(values.getDoubleValue("intervalValue4"));
                    idxBizPvPointProcessVariableClassification.setIntervalValue3(values.getDoubleValue("intervalValue3"));
                    idxBizPvPointProcessVariableClassification.setIntervalValue2(values.getDoubleValue("intervalValue2"));
                    idxBizPvPointProcessVariableClassification.setIntervalValue1(values.getDoubleValue("intervalValue1"));
                    idxBizPvPointProcessVariableClassificationMapper.updateById(idxBizPvPointProcessVariableClassification);
                    logger.info("------------------------------------------风机：：工况变量区间划分更新业务表成功----------------------------------------");
                }
                try {
                    logger.info(repsonse);
                    TimeUnit.SECONDS.sleep(sleepTime);
                    logger.info("------------------------------------------光伏：：调用工况变量区间划分算法结束----------------------------------------");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

    }

    //获取相关性基础数据-风机
    public HashMap<String, List<IdxBizFanPointProcessVariableClassification>> getIdxBizFanPointProcessVariableClassificationListOfAnaLyse() {

        HashMap<String, List<IdxBizFanPointProcessVariableClassification>> IdxBizFanPointProcessVariableClassificationHashMap = new HashMap<>();
        List<String> gateWayIdList = idxBizFanPointProcessVariableClassificationMapper.gateWayIdListFan();
        List<IdxBizFanPointProcessVariableClassification> IdxBizFanPointProcessVariableClassificationListFengxi = idxBizFanPointProcessVariableClassificationMapper.selectList(new QueryWrapper<IdxBizFanPointProcessVariableClassification>().isNotNull("SEQUENCE_NBR").eq("TAG_CODE", "分析变量"));
        List<IdxBizFanPointProcessVariableClassification> finalIdxBizFanPointProcessVariableClassificationList = IdxBizFanPointProcessVariableClassificationListFengxi;
        gateWayIdList.forEach(s -> {
            IdxBizFanPointProcessVariableClassificationHashMap.put("iot_data_" + s, finalIdxBizFanPointProcessVariableClassificationList.stream().filter(IdxBizFanPointProcessVariableClassification -> IdxBizFanPointProcessVariableClassification.getGatewayId().toString().equals(s)).collect(Collectors.toList()));
        });
        return IdxBizFanPointProcessVariableClassificationHashMap;
    }

    //获取相关性基础数据-光伏
    public HashMap<String, List<IdxBizPvPointProcessVariableClassification>> getIdxBizPvPointProcessVariableClassificationListOfAnaLyse() {

        HashMap<String, List<IdxBizPvPointProcessVariableClassification>> idxBizPvPointProcessVariableClassificationHashMap = new HashMap<>();
        List<String> gateWayIdList = idxBizPvPointProcessVariableClassificationMapper.gateWayIdListPv();
        List<IdxBizPvPointProcessVariableClassification> idxBizPvPointProcessVariableClassificationListFengxi = idxBizPvPointProcessVariableClassificationMapper.selectList(new QueryWrapper<IdxBizPvPointProcessVariableClassification>().isNotNull("SEQUENCE_NBR").eq("TAG_CODE", "分析变量"));
        List<IdxBizPvPointProcessVariableClassification> finalIdxBizPvPointProcessVariableClassificationList = idxBizPvPointProcessVariableClassificationListFengxi;
        gateWayIdList.forEach(s -> {
            idxBizPvPointProcessVariableClassificationHashMap.put("iot_data_" + s, finalIdxBizPvPointProcessVariableClassificationList.stream().filter(idxBizPvPointProcessVariableClassification -> idxBizPvPointProcessVariableClassification.getGatewayId().toString().equals(s)).collect(Collectors.toList()));
        });
        return idxBizPvPointProcessVariableClassificationHashMap;
    }

    //相关性分析-风机入口
    public void getFanConditionVariablesByTimeAnalyse(String startTime, String endTime) {
        String startTimeUTC = getUtcTimeString(startTime);
        String endTimeUTC =getUtcTimeString(endTime);
        HashMap<String, List<IdxBizFanPointProcessVariableClassification>> idxBizFanPointProcessVariableClassificationHashMap = getIdxBizFanPointProcessVariableClassificationListOfAnaLyse();
        idxBizFanPointProcessVariableClassificationHashMap.keySet().forEach(s -> {
            List<IdxBizFanPointProcessVariableClassification> list = idxBizFanPointProcessVariableClassificationHashMap.get(s);
            list.forEach(IdxBizFanPointProcessVariableClassification -> {
                List<IdxBizFanPointVarCorrelation> gongkuangList = idxBizFanPointVarCorrelationMapper.selectList(new QueryWrapper<IdxBizFanPointVarCorrelation>().eq("ANALYSIS_GATEWAY_ID", IdxBizFanPointProcessVariableClassification.getGatewayId()).eq("ANALYSIS_POINT_ID", IdxBizFanPointProcessVariableClassification.getSequenceNbr()));
                if (gongkuangList.size() > 0) {
                    foreachHandlerConditionVariabAnalyseFan(s, gongkuangList, startTimeUTC, endTimeUTC, IdxBizFanPointProcessVariableClassification);
                }
            });
        });
    }

    //相关性分析-光伏入口
    public void getPvConditionVariablesByTimeAnalyse(String startTime, String endTime) {
        String startTimeUTC = getUtcTimeString(startTime);
        String endTimeUTC =getUtcTimeString(endTime);
        HashMap<String, List<IdxBizPvPointProcessVariableClassification>> idxBizPvPointProcessVariableClassificationHashMap = getIdxBizPvPointProcessVariableClassificationListOfAnaLyse();
        idxBizPvPointProcessVariableClassificationHashMap.keySet().forEach(s -> {
            List<IdxBizPvPointProcessVariableClassification> list = idxBizPvPointProcessVariableClassificationHashMap.get(s);
            list.forEach(idxBizPvPointProcessVariableClassification -> {
                List<IdxBizPvPointVarCorrelation> gongkuangList = idxBizPvPointVarCorrelationMapper.selectList(new QueryWrapper<IdxBizPvPointVarCorrelation>().eq("ANALYSIS_GATEWAY_ID", idxBizPvPointProcessVariableClassification.getGatewayId()).eq("ANALYSIS_POINT_ID", idxBizPvPointProcessVariableClassification.getSequenceNbr()));
                if (gongkuangList.size() > 0) {
                    foreachHandlerConditionVariabAnalysePv(s, gongkuangList, startTimeUTC, endTimeUTC, idxBizPvPointProcessVariableClassification);
                }
            });
        });
    }

    //遍历处理数据-组装风机
    public void foreachHandlerConditionVariabAnalyseFan(String tableName, List<IdxBizFanPointVarCorrelation> list, String startTime, String endTime, IdxBizFanPointProcessVariableClassification idxBizFanPointProcessVariableClassification) {

        String sql1 = String.format("select value from %s where address='%s' and  time >= '%s' and where time <= '%s' ", tableName, idxBizFanPointProcessVariableClassification.getIndexAddress(),startTime,endTime);
        List<Map<String, Object>> returnList = influxdbUtil.query(sql1);
        List<Map<String, Object>> params = new ArrayList<>();
        returnList.forEach((k) -> {
            Map<String, Object> map = new HashMap<>();
            map.put("analysisVariable", Double.parseDouble(k.get("value").toString()));
            map.put("analysisVariableId", Long.parseLong(idxBizFanPointProcessVariableClassification.getSequenceNbr()));
            params.add(map);
        });
        List<Map<String, Object>> tempParams = params;
        list.forEach(idxBizFanPointVarCorrelation -> {
            logger.info("---------------------------------风机相关性-----------开始查询influxdb--------------------------------");
            List<Map<String, Object>> params1 = new ArrayList<>();
            List<Map<String, Object>> requestParams = new ArrayList<>();
            String sql = String.format("select value from %s where address='%s' and  time >= '%s' and where time <= '%s' ", tableName, idxBizFanPointVarCorrelation.getProcessIndexAddress(),startTime,endTime);
            List<Map<String, Object>> returnList1 = influxdbUtil.query(sql);
            returnList.forEach((k) -> {
                Map<String, Object> map = new HashMap<>();
                map.put("processVariable", Double.parseDouble(k.get("value").toString()));
                map.put("processVariableId", Long.parseLong(idxBizFanPointVarCorrelation.getProcessPointId().toString()));
                params1.add(map);
            });

            if (tempParams.size() >= params1.size()) {
                requestParams = megreMapList(tempParams, params1);
            } else {
                requestParams = megreMapList(params1, tempParams);
            }
            if (!requestParams.isEmpty()) {
                logger.info("------------------------------风机相关性------------分析变量与工况变量相关性分析算法开始----------------------------------------");
                HashMap<String, Object> realParams = new HashMap<>();
                realParams.put(gkxgxfxkey, requestParams);
                logger.info("------------------------------风机相关性------------分析变量与工况变量相关性分析算参数---------------------------------------" + JSON.toJSONString(realParams));
                String repsonse = HttpUtil.createPost(baseUrl + gkxgxfxurlfan).body(JSON.toJSONString(realParams)).execute().body();
                if (repsonse.contains("\"status\":200")) {
                    JSONObject jsonObject = JSONObject.parseObject(repsonse);
                    JSONObject result = (JSONObject) jsonObject.get("result");
                    JSONObject result1 = (JSONObject) result.get("result1");
                    JSONArray rows = (JSONArray) result1.get("rows");
                    JSONObject values = rows.getJSONObject(0);
                    idxBizFanPointVarCorrelation.setCorrelationCoefficient(values.getDoubleValue("correlation_coefficient"));
                    idxBizFanPointVarCorrelationMapper.updateById(idxBizFanPointVarCorrelation);
                    logger.info("------------------------------------------风机相关性：：相关性更新业务表成功----------------------------------------");
                }
                try {
                    logger.info("response-------------" + repsonse);
                    TimeUnit.SECONDS.sleep(sleepTime);
                    logger.info("----------------------------风机相关性--------------分析变量与工况变量相关性分析算法结束----------------------------------------");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }

    //遍历处理数据-组装风机
    public void foreachHandlerConditionVariabAnalysePv(String tableName, List<IdxBizPvPointVarCorrelation> list, String startTime, String endTime, IdxBizPvPointProcessVariableClassification idxBizPvPointProcessVariableClassification) {
        String sql1 = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s' ", tableName, idxBizPvPointProcessVariableClassification.getIndexAddress(),startTime,endTime);
        List<Map<String, Object>> returnList = influxdbUtil.query(sql1);
        List<Map<String, Object>> params = new ArrayList<>();
        returnList.forEach((k) -> {
            Map<String, Object> map = new HashMap<>();
            map.put("analysisVariable", Double.parseDouble(k.get("value").toString()));
            map.put("analysisVariableId", Long.parseLong(idxBizPvPointProcessVariableClassification.getSequenceNbr()));
            params.add(map);
        });
        list.forEach(idxBizPvPointVarCorrelation -> {
            logger.info("-------------------------------------光伏相关性-------开始查询influxdb--------------------------------");
            List<Map<String, Object>> params1 = new ArrayList<>();
            List<Map<String, Object>> requestParams = new ArrayList<>();
            String sql = String.format("select value from %s where address='%s' and  time >= '%s' and  time <= '%s'  ", tableName, idxBizPvPointVarCorrelation.getProcessIndexAddress(),startTime,endTime);
            List<Map<String, Object>> returnList1 = influxdbUtil.query(sql);
            returnList.forEach((k) -> {
                Map<String, Object> map = new HashMap<>();
                map.put("processVariable", Double.parseDouble(k.get("value").toString()));
                map.put("processVariableId", Long.parseLong(idxBizPvPointVarCorrelation.getProcessPointId().toString()));
                params1.add(map);
            });
            if (params.size() >= params1.size()) {
                requestParams = megreMapList(params, params1);
            } else {
                requestParams = megreMapList(params1, params);
            }
            if (!requestParams.isEmpty()) {
                logger.info("---------------------------------光伏相关性---------分析变量与工况变量相关性分析算法开始----------------------------------------");
                HashMap<String, Object> realParams = new HashMap<>();
                realParams.put(gkxgxfxkey, requestParams);
                String repsonse = HttpUtil.createPost(baseUrl + gkxgxfxurlpv).body(JSON.toJSONString(realParams)).execute().body();
                if (repsonse.contains("\"status\":200")) {
                    JSONObject jsonObject = JSONObject.parseObject(repsonse);
                    JSONObject result = (JSONObject) jsonObject.get("result");
                    JSONObject result1 = (JSONObject) result.get("result1");
                    JSONArray rows = (JSONArray) result1.get("rows");
                    JSONObject values = rows.getJSONObject(0);
                    idxBizPvPointVarCorrelation.setCorrelationCoefficient(values.getDoubleValue("correlation_coefficient"));
                    idxBizPvPointVarCorrelationMapper.updateById(idxBizPvPointVarCorrelation);
                    logger.info("------------------------------------------风机相关性：：相关性更新业务表成功----------------------------------------");
                }
                try {
                    logger.info("response----光伏相关性---------" + repsonse);
                    TimeUnit.SECONDS.sleep(sleepTime);
                    logger.info("----------------------------------光伏相关性--------分析变量与工况变量相关性分析算法结束----------------------------------------");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }

    public List<Map<String, Object>> megreMapList(List<Map<String, Object>> longList, List<Map<String, Object>> shortList) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (int i = 0; i < longList.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.putAll(longList.get(i));
            Map<String, Object> mapOfShortList = new HashMap<>();
            if (i < shortList.size() - 1) {
                mapOfShortList.putAll(shortList.get(i));
            } else {
                mapOfShortList.putAll(shortList.get(shortList.size() - 1));
            }

            if (!map.containsKey("processVariable")) {
                map.put("processVariable", mapOfShortList.get("processVariable"));
                map.put("processVariableId", mapOfShortList.get("processVariableId"));
            } else {
                map.put("analysisVariable", mapOfShortList.get("analysisVariable"));
                map.put("analysisVariableId", mapOfShortList.get("analysisVariableId"));
            }
            resultList.add(map);
        }
        return resultList;
    }

    //中心值计算-风电
    public void getFanConditionVariablesByTimeAnalyse1(String startTime, String endTime) {
        String startTimeUTC = getUtcTimeString(startTime);
        String endTimeUTC =getUtcTimeString(endTime);
        HashMap<String, List<IdxBizFanPointProcessVariableClassification>> IdxBizFanPointProcessVariableClassificationHashMap = getIdxBizFanPointProcessVariableClassificationListOfAnaLyse();
        IdxBizFanPointProcessVariableClassificationHashMap.keySet().forEach(s -> {
            List<IdxBizFanPointProcessVariableClassification> list = IdxBizFanPointProcessVariableClassificationHashMap.get(s);
            list.forEach(IdxBizFanPointProcessVariableClassification -> {
                List<IdxBizFanPointVarCorrelation> gongkuangList = idxBizFanPointVarCorrelationMapper.selectList(new QueryWrapper<IdxBizFanPointVarCorrelation>().eq("ANALYSIS_GATEWAY_ID", IdxBizFanPointProcessVariableClassification.getGatewayId()).eq("ANALYSIS_POINT_ID", IdxBizFanPointProcessVariableClassification.getSequenceNbr()).orderByDesc("CORRELATION_COEFFICIENT").last("limit 0,3"));
                if (gongkuangList.size() > 0) {
                    foreachHandlerConditionVariabAnalyse1Fan(s, gongkuangList, startTimeUTC, endTimeUTC, IdxBizFanPointProcessVariableClassification);
                }
            });
        });
    }

    //中心值计算-光伏
    public void getPvConditionVariablesByTimeAnalyse1(String startTime, String endTime) {
        String startTimeUTC = getUtcTimeString(startTime);
        String endTimeUTC =getUtcTimeString(endTime);
        HashMap<String, List<IdxBizPvPointProcessVariableClassification>> idxBizPvPointProcessVariableClassificationHashMap = getIdxBizPvPointProcessVariableClassificationListOfAnaLyse();
        idxBizPvPointProcessVariableClassificationHashMap.keySet().forEach(s -> {
            List<IdxBizPvPointProcessVariableClassification> list = idxBizPvPointProcessVariableClassificationHashMap.get(s);
            list.forEach(idxBizPvPointProcessVariableClassification -> {
                List<IdxBizPvPointVarCorrelation> gongkuangList = idxBizPvPointVarCorrelationMapper.selectList(new QueryWrapper<IdxBizPvPointVarCorrelation>().eq("ANALYSIS_GATEWAY_ID", idxBizPvPointProcessVariableClassification.getGatewayId()).eq("ANALYSIS_POINT_ID", idxBizPvPointProcessVariableClassification.getSequenceNbr()).orderByDesc("CORRELATION_COEFFICIENT").last("limit 0,3"));
                if (gongkuangList.size() > 0) {
                    foreachHandlerConditionVariabAnalyse1Pv(s, gongkuangList, startTimeUTC, endTimeUTC, idxBizPvPointProcessVariableClassification);
                }

            });
        });
    }

    //中心值参数组装-风电
    public void foreachHandlerConditionVariabAnalyse1Fan(String tableName, List<IdxBizFanPointVarCorrelation> list, String startTime, String endTime, IdxBizFanPointProcessVariableClassification IdxBizFanPointProcessVariableClassification) {
        String sql0 = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s' ", tableName, IdxBizFanPointProcessVariableClassification.getIndexAddress(),startTime,endTime);
        List<Map<String, Object>> returnList = influxdbUtil.query(sql0);
        List<Map<String, Object>> params = new ArrayList<>();
        returnList.forEach((k) -> {
            Map<String, Object> map = new HashMap<>();
            map.put("analysisVariable", Double.parseDouble(k.get("value").toString()));
            map.put("analysisVariableId", (IdxBizFanPointProcessVariableClassification.getSequenceNbr().toString()));
            params.add(map);
        });
        logger.info("--------------------------------------风机中心值------开始查询influxdb--------------------------------");
        List<Map<String, Object>> params1 = new ArrayList<>();
        List<Map<String, Object>> requestParams = new ArrayList<>();
//            String sql = String.format("select value from %s where address='%s' and where time >= '%s' and where time <= '%s' ", tableName, IdxBizFanPointProcessVariableClassification.getIndexAddress(), startTime, endTime);
        String sql = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s'  ", tableName, list.get(0).getProcessIndexAddress(),startTime,endTime);
        String sql1 = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s' ", tableName, list.get(1).getProcessIndexAddress(),startTime,endTime);
        String sql2 = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s' ", tableName, list.get(2).getProcessIndexAddress(),startTime,endTime);
        List<HashMap<String, Object>> values = new ArrayList<>();
        List<String> processPointIds = list.stream().map(idxBizFanPointVarCorrelation -> idxBizFanPointVarCorrelation.getProcessPointId().toString()).collect(Collectors.toList());
        List<IdxBizFanPointProcessVariableClassification> idxBizFanPointProcessVariableClassificationList = idxBizFanPointProcessVariableClassificationMapper.selectList(new QueryWrapper<IdxBizFanPointProcessVariableClassification>().in("SEQUENCE_NBR", processPointIds));
        //区间值1
        HashMap<String, Object> value1 = new HashMap<>();
        value1.put("processVariable1", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue1()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue1());
        value1.put("processVariable2", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue1()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue1());
        value1.put("processVariable3", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue1()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue1());
        values.add(value1);
        //区间值2
        HashMap<String, Object> value2 = new HashMap<>();
        value2.put("processVariable1", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue2()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue2());
        value2.put("processVariable2", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue2()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue2());
        value2.put("processVariable3", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue2()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue2());
        values.add(value2);
        //区间值3
        HashMap<String, Object> value3 = new HashMap<>();
        value3.put("processVariable1", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue3()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue3());
        value3.put("processVariable2", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue3()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue3());
        value3.put("processVariable3", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue3()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue3());
        values.add(value3);
        //区间值4
        HashMap<String, Object> value4 = new HashMap<>();
        value4.put("processVariable1", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue4()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue4());
        value4.put("processVariable2", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue4()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue4());
        value4.put("processVariable3", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue4()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue4());
        values.add(value4);
        //区间值5
        HashMap<String, Object> value5 = new HashMap<>();
        value5.put("processVariable1", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue5()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(2).getIntervalValue5());
        value5.put("processVariable2", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue5()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(1).getIntervalValue5());
        value5.put("processVariable3", ObjectUtils.isEmpty(idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue5()) ? 0.0 : idxBizFanPointProcessVariableClassificationList.get(0).getIntervalValue5());
        values.add(value5);
        List<Map<String, Object>> returnList0 = influxdbUtil.query(sql);
        List<Map<String, Object>> maxList = returnList0;
        List<Map<String, Object>> returnList1 = influxdbUtil.query(sql);
        maxList = maxList.size() > returnList1.size() ? maxList : returnList1;
        List<Map<String, Object>> returnList2 = influxdbUtil.query(sql);
        maxList = maxList.size() > returnList2.size() ? maxList : returnList2;
        for (int j = 0; j < maxList.size(); j++) {
            Map<String, Object> map = new HashMap<>();
            Map<String, Object> map1 = new HashMap<>();
            Map<String, Object> map2 = new HashMap<>();
            Map<String, Object> map3 = new HashMap<>();
            if (j < returnList0.size() - 1) {
                map1 = returnList0.get(j);
            } else {
                map1 = returnList0.get(returnList0.size() - 1);
            }
            if (j < returnList1.size() - 1) {
                map2 = returnList1.get(j);
            } else {
                map2 = returnList1.get(returnList1.size() - 1);
            }
            if (j < returnList2.size() - 1) {
                map3 = returnList2.get(j);
            } else {
                map3 = returnList2.get(returnList2.size() - 1);
            }
            map.put("processVariable1", Double.parseDouble(map1.get("value").toString()));
            map.put("processVariable1Id", list.get(0).getProcessPointId().toString());
            map.put("processVariable2", Double.parseDouble(map2.get("value").toString()));
            map.put("processVariable2Id", list.get(1).getProcessPointId().toString());
            map.put("processVariable3", Double.parseDouble(map3.get("value").toString()));
            map.put("processVariable3Id", list.get(2).getProcessPointId().toString());
            params1.add(map);
        }
        if (params.size() >= params1.size()) {
            requestParams = megreMapList1(params, params1);
        } else {
            requestParams = megreMapList1(params1, params);
        }
        if (!requestParams.isEmpty()) {
            logger.info("---------------------------------风机中心值---------开始调用中心值计算算法开始----------------------------------------");
            HashMap<String, Object> realParams = new HashMap<>();
            realParams.put(gkzxzjskey1, values);
            realParams.put(gkzxzjskey2, requestParams);
            logger.info("------------------------------风机中心值------请求参数---------------------------------------" + JSON.toJSONString(realParams));
            String response = HttpUtil.createPost(baseUrl + gkzxzjsurlfan).body(JSON.toJSONString(realParams)).execute().body();
            if (response.contains("\"status\":200")) {
                JSONObject jsonObject = JSONObject.parseObject(response);
                JSONObject result = (JSONObject) jsonObject.get("result");
                JSONObject result1 = (JSONObject) result.get("result1");
                JSONArray rows = (JSONArray) result1.get("rows");
                JSONObject resultValues = rows.getJSONObject(0);
                idxBizFanPointVarCentralValueMapper.delete(new QueryWrapper<IdxBizFanPointVarCentralValue>().eq("ANALYSIS_POINT_ID",resultValues.get("analysisVariableId")));
                for (int i = 0; i <rows.size() ; i++) {
                    JSONObject idxCentralValue = rows.getJSONObject(i);
                    IdxBizFanPointVarCentralValue idxBizFanPointVarCentralValue =new IdxBizFanPointVarCentralValue();
                    idxBizFanPointVarCentralValue.setProcess1Min(idxCentralValue.getDoubleValue("process1Min"));
                    idxBizFanPointVarCentralValue.setProcess2Min(idxCentralValue.getDoubleValue("process2Min"));
                    idxBizFanPointVarCentralValue.setProcess3Min(idxCentralValue.getDoubleValue("process3Min"));
                    idxBizFanPointVarCentralValue.setProcess1Max(idxCentralValue.getDoubleValue("process1Max"));
                    idxBizFanPointVarCentralValue.setPorcess2Max(idxCentralValue.getDoubleValue("process1Max"));
                    idxBizFanPointVarCentralValue.setProcess3Max(idxCentralValue.getDoubleValue("process1Max"));
                    idxBizFanPointVarCentralValue.setAnalysisPointId(idxCentralValue.getString("analysisVariableId"));
                    idxBizFanPointVarCentralValue.setAnalysisPointName(IdxBizFanPointProcessVariableClassification.getPointName());
                    idxBizFanPointVarCentralValue.setProcessPoint1Id(idxCentralValue.getString("processVariable1Id"));
                    idxBizFanPointVarCentralValue.setProcessPoint1Name(idxBizFanPointProcessVariableClassificationList.get(2).getPointName());
                    idxBizFanPointVarCentralValue.setProcessPoint2Id(idxCentralValue.getString("processVariable2Id"));
                    idxBizFanPointVarCentralValue.setProcessPoint2Name(idxBizFanPointProcessVariableClassificationList.get(1).getPointName());
                    idxBizFanPointVarCentralValue.setProcessPoint3Id(idxCentralValue.getString("processVariable3Id"));
                    idxBizFanPointVarCentralValue.setProcessPoint3Name(idxBizFanPointProcessVariableClassificationList.get(0).getPointName());
                    idxBizFanPointVarCentralValue.setAnalysisStdDev(idxCentralValue.getDoubleValue("stdDev"));
                    idxBizFanPointVarCentralValue.setAnalysisCenterValue(idxCentralValue.getDoubleValue("centerValue"));
                    idxBizFanPointVarCentralValue.setArae(IdxBizFanPointProcessVariableClassification.getArae());
                    idxBizFanPointVarCentralValue.setStation(IdxBizFanPointProcessVariableClassification.getStation());
                    idxBizFanPointVarCentralValue.setSubSystem(IdxBizFanPointProcessVariableClassification.getSubSystem());
                    idxBizFanPointVarCentralValue.setNumber(IdxBizFanPointProcessVariableClassification.getNumber());
                    idxBizFanPointVarCentralValue.setEquipmentName(IdxBizFanPointProcessVariableClassification.getEquipmentName());
                    idxBizFanPointVarCentralValueMapper.insert(idxBizFanPointVarCentralValue);
                }
                logger.info("------------------------------------------风机中心值：：中心值更新业务表成功----------------------------------------");
            }

            try {
                logger.info("------------------风机中心值--repsonse： " + response);
                TimeUnit.SECONDS.sleep(zxzsleepTime);
                logger.info("-----------------------------------风机中心值-------调用中心值计算算法结束----------------------------------------");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    //中心值参数组装-光伏
    public void foreachHandlerConditionVariabAnalyse1Pv(String tableName, List<IdxBizPvPointVarCorrelation> list, String startTime, String endTime, IdxBizPvPointProcessVariableClassification idxBizPvPointProcessVariableClassification) {
        String sql0 = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s' ", tableName, idxBizPvPointProcessVariableClassification.getIndexAddress(),startTime,endTime);
        List<Map<String, Object>> returnList = influxdbUtil.query(sql0);
        List<Map<String, Object>> params = new ArrayList<>();
        returnList.forEach((k) -> {
            Map<String, Object> map = new HashMap<>();
            map.put("analysisVariable", Double.parseDouble(k.get("value").toString()));
            map.put("analysisVariableId", Long.parseLong(idxBizPvPointProcessVariableClassification.getSequenceNbr()));
            params.add(map);
        });
        logger.info("-----------------------------------光伏中心值---------开始查询influxdb--------------------------------");
        List<Map<String, Object>> params1 = new ArrayList<>();
        List<Map<String, Object>> requestParams = new ArrayList<>();
        String sql = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s' ", tableName, list.get(0).getProcessIndexAddress(),startTime,endTime);
        String sql1 = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s' ", tableName, list.get(1).getProcessIndexAddress(),startTime,endTime);
        String sql2 = String.format("select value from %s where address='%s' and  time >= '%s' and time <= '%s' ", tableName, list.get(2).getProcessIndexAddress(),startTime,endTime);
        List<HashMap<String, Object>> values = new ArrayList<>();
        List<String> processPointIds = list.stream().map(idxBizPvPointVarCorrelation -> idxBizPvPointVarCorrelation.getProcessPointId().toString()).collect(Collectors.toList());
        List<IdxBizPvPointProcessVariableClassification> idxBizPvPointProcessVariableClassificationList = idxBizPvPointProcessVariableClassificationMapper.selectList(new QueryWrapper<IdxBizPvPointProcessVariableClassification>().in("SEQUENCE_NBR", processPointIds));
        //区间值1
        HashMap<String, Object> value1 = new HashMap<>();
        value1.put("processVariable1", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue1()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue1());
        value1.put("processVariable2", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue1()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue1());
        value1.put("processVariable3", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue1()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue1());
        values.add(value1);
        //区间值2
        HashMap<String, Object> value2 = new HashMap<>();
        value2.put("processVariable1", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue2()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue2());
        value2.put("processVariable2", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue2()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue2());
        value2.put("processVariable3", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue2()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue2());
        values.add(value2);
        //区间值3
        HashMap<String, Object> value3 = new HashMap<>();
        value3.put("processVariable1", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue3()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue3());
        value3.put("processVariable2", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue3()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue3());
        value3.put("processVariable3", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue3()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue3());
        values.add(value3);
        //区间值4
        HashMap<String, Object> value4 = new HashMap<>();
        value4.put("processVariable1", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue4()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue4());
        value4.put("processVariable2", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue4()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue4());
        value4.put("processVariable3", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue4()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue4());
        values.add(value4);
        //区间值5
        HashMap<String, Object> value5 = new HashMap<>();
        value5.put("processVariable1", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue5()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(2).getIntervalValue5());
        value5.put("processVariable2", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue5()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(1).getIntervalValue5());
        value5.put("processVariable3", ObjectUtils.isEmpty(idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue5()) ? 0.0 : idxBizPvPointProcessVariableClassificationList.get(0).getIntervalValue5());
        values.add(value5);
        List<Map<String, Object>> returnList0 = influxdbUtil.query(sql);
        List<Map<String, Object>> maxList = returnList0;
        List<Map<String, Object>> returnList1 = influxdbUtil.query(sql);
        maxList = maxList.size() > returnList1.size() ? maxList : returnList1;
        List<Map<String, Object>> returnList2 = influxdbUtil.query(sql);
        maxList = maxList.size() > returnList2.size() ? maxList : returnList2;
        for (int j = 0; j < maxList.size(); j++) {
            Map<String, Object> map = new HashMap<>();
            Map<String, Object> map1 = new HashMap<>();
            Map<String, Object> map2 = new HashMap<>();
            Map<String, Object> map3 = new HashMap<>();
            if (j < returnList0.size() - 1) {
                map1 = returnList0.get(j);
            } else {
                map1 = returnList0.get(returnList0.size() - 1);
            }
            if (j < returnList1.size() - 1) {
                map2 = returnList1.get(j);
            } else {
                map2 = returnList1.get(returnList1.size() - 1);
            }
            if (j < returnList2.size() - 1) {
                map3 = returnList2.get(j);
            } else {
                map3 = returnList2.get(returnList2.size() - 1);
            }
            map.put("processVariable1", Double.parseDouble(map1.get("value").toString()));
            map.put("processVariable1Id", Long.parseLong(list.get(0).getProcessPointId().toString()));
            map.put("processVariable2", Double.parseDouble(map2.get("value").toString()));
            map.put("processVariable2Id", Long.parseLong(list.get(1).getProcessPointId().toString()));
            map.put("processVariable3", Double.parseDouble(map3.get("value").toString()));
            map.put("processVariable3Id", Long.parseLong(list.get(2).getProcessPointId().toString()));
            params1.add(map);
        }
        if (params.size() >= params1.size()) {
            requestParams = megreMapList1(params, params1);
        } else {
            requestParams = megreMapList1(params1, params);
        }
        if (!requestParams.isEmpty()) {
            logger.info("-------------------------------------光伏中心值-----开始调用中心值计算算法----------------------------------------");
            HashMap<String, Object> realParams = new HashMap<>();
            realParams.put(gkzxzjskey1, values);
            realParams.put(gkzxzjskey2, requestParams);
            String response = HttpUtil.createPost(baseUrl + gkzxzjsurlpv).body(JSON.toJSONString(realParams)).execute().body();
            if (response.contains("\"status\":200")) {
                JSONObject jsonObject = JSONObject.parseObject(response);
                JSONObject result = (JSONObject) jsonObject.get("result");
                JSONObject result1 = (JSONObject) result.get("result1");
                JSONArray rows = (JSONArray) result1.get("rows");
                JSONObject resultValues = rows.getJSONObject(0);
                idxBizPvPointVarCentralValueMapper.delete(new QueryWrapper<IdxBizPvPointVarCentralValue>().eq("ANALYSIS_POINT_ID",resultValues.get("analysisVariableId")));
                for (int i = 0; i <rows.size() ; i++) {
                    JSONObject idxCentralValue = rows.getJSONObject(i);
                    IdxBizPvPointVarCentralValue idxBizPvPointVarCentralValue =new IdxBizPvPointVarCentralValue();
                    idxBizPvPointVarCentralValue.setProcess1Min(idxCentralValue.getDoubleValue("process1Min"));
                    idxBizPvPointVarCentralValue.setProcess2Min(idxCentralValue.getDoubleValue("process2Min"));
                    idxBizPvPointVarCentralValue.setProcess3Min(idxCentralValue.getDoubleValue("process3Min"));
                    idxBizPvPointVarCentralValue.setProcess1Max(idxCentralValue.getDoubleValue("process1Max"));
                    idxBizPvPointVarCentralValue.setProcess2Max(idxCentralValue.getDoubleValue("process1Max"));
                    idxBizPvPointVarCentralValue.setProcess3Max(idxCentralValue.getDoubleValue("process1Max"));
                    idxBizPvPointVarCentralValue.setAnalysisPointId(idxCentralValue.getString("analysisVariableId"));
                    idxBizPvPointVarCentralValue.setAnalysisPointIdName(idxBizPvPointProcessVariableClassification.getPointName());
                    idxBizPvPointVarCentralValue.setProcessPoint1Id(idxCentralValue.getString("processVariable1Id"));
                    idxBizPvPointVarCentralValue.setProcessPoint1IdName(idxBizPvPointProcessVariableClassificationList.get(2).getPointName());
                    idxBizPvPointVarCentralValue.setProcessPoint2Id(idxCentralValue.getString("processVariable2Id"));
                    idxBizPvPointVarCentralValue.setProcessPoint2IdName(idxBizPvPointProcessVariableClassificationList.get(1).getPointName());
                    idxBizPvPointVarCentralValue.setProcessPoint2Id(idxCentralValue.getString("processVariable3Id"));
                    idxBizPvPointVarCentralValue.setProcessPoint3IdName(idxBizPvPointProcessVariableClassificationList.get(0).getPointName());
                    idxBizPvPointVarCentralValue.setAnalysisStdDev(idxCentralValue.getDoubleValue("stdDev"));
                    idxBizPvPointVarCentralValue.setAnalysisCenterValue(idxCentralValue.getDoubleValue("centerValue"));
                    idxBizPvPointVarCentralValue.setArae(idxBizPvPointProcessVariableClassification.getArae());
                    idxBizPvPointVarCentralValue.setStation(idxBizPvPointProcessVariableClassification.getStation());
                    idxBizPvPointVarCentralValue.setSubarray(idxBizPvPointProcessVariableClassification.getSubarray());
                    idxBizPvPointVarCentralValue.setManufacturer(idxBizPvPointProcessVariableClassification.getManufacturer());
                    idxBizPvPointVarCentralValue.setEquipmentName(idxBizPvPointProcessVariableClassification.getEquipmentName());
                    idxBizPvPointVarCentralValueMapper.insert(idxBizPvPointVarCentralValue);
                }
                logger.info("------------------------------------------光伏中心值：：中心值更新业务表成功----------------------------------------");
            }
            try {
                logger.info("-------------光伏中心值-------repsonse： " + response);
                TimeUnit.SECONDS.sleep(sleepTime);
                logger.info("-----------------------------------光伏中心值-------调用中心值计算算法结束----------------------------------------");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }


    }

    public List<Map<String, Object>> megreMapList1(List<Map<String, Object>> longList, List<Map<String, Object>> shortList) {
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (int i = 0; i < longList.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.putAll(longList.get(i));
            Map<String, Object> mapOfShortList = new HashMap<>();
            if (i < shortList.size() - 1) {
                mapOfShortList.putAll(shortList.get(i));
            } else {
                mapOfShortList.putAll(shortList.get(shortList.size() - 1));
            }
            if (!map.containsKey("processVariable1")) {
                map.put("processVariable1", mapOfShortList.get("processVariable1"));
                map.put("processVariable1Id", mapOfShortList.get("processVariable1Id"));
                map.put("processVariable2", mapOfShortList.get("processVariable2"));
                map.put("processVariable2Id", mapOfShortList.get("processVariable2Id"));
                map.put("processVariable3", mapOfShortList.get("processVariable3"));
                map.put("processVariable3Id", mapOfShortList.get("processVariable3Id"));
            } else {
                map.put("analysisVariable", mapOfShortList.get("analysisVariable"));
                map.put("analysisVariableId", mapOfShortList.get("analysisVariableId"));
            }
            resultList.add(map);
        }
        return resultList;
    }

    public Map<String, Object> getInfluxdbDataByConditon(String stationType, String pointId, String startTime, String endTime) {
        HashMap<String, Object> resultLast = new HashMap();
        String sql = "";
        if ("FD".equals(stationType)) {
            IdxBizFanPointProcessVariableClassification idxBizFanPointProcessVariableClassification = idxBizFanPointProcessVariableClassificationMapper.selectOne(new QueryWrapper<IdxBizFanPointProcessVariableClassification>().eq("SEQUENCE_NBR", pointId));
            sql = String.format("select * from iot_data_%s where address ='%s' and time > '%s' and time < '%s' ;", idxBizFanPointProcessVariableClassification.getGatewayId(), idxBizFanPointProcessVariableClassification.getIndexAddress(), getUtcTimeString(startTime), getUtcTimeString(endTime));
        } else {
            IdxBizPvPointProcessVariableClassification idxBizPvPointProcessVariableClassification = idxBizPvPointProcessVariableClassificationMapper.selectOne(new QueryWrapper<IdxBizPvPointProcessVariableClassification>().eq("SEQUENCE_NBR", pointId));
            sql = String.format("select * from iot_data_%s where address ='%s' and time > '%s' and time < '%s' ;", idxBizPvPointProcessVariableClassification.getGatewayId(), idxBizPvPointProcessVariableClassification.getIndexAddress(), getUtcTimeString(startTime), getUtcTimeString(endTime));
        }
        List<Map<String, Object>> reuslt = influxdbUtil.query(sql);
        List<String> seriesData_valuse = new ArrayList<>();
        List<String> axisData_valuse = new ArrayList<>();
        reuslt.forEach(item -> {
            seriesData_valuse.add(item.get("value").toString());
            axisData_valuse.add(item.get("time").toString());
        });
        resultLast.put("seriesData", seriesData_valuse);
        resultLast.put("axisData", axisData_valuse);
        return resultLast;
    }

    public String getUtcTimeString(String timeStr) {
        SimpleDateFormat dateFormatUTC = new SimpleDateFormat(FORMAT_UTC);
        SimpleDateFormat dateFormatDefault = new SimpleDateFormat(FORMAT_DEFAULT);
        Date time1 = null;
        try {
            time1 = dateFormatDefault.parse(timeStr);
        } catch (ParseException e) {
            logger.info("输入的时间格式错误");
        }
        String s = dateFormatUTC.format(time1);
        return s;
    }

    //    @Scheduled(cron = "0 0/10 * * * ?")
    private void healthWarningMinuteByFJ() {
        List<IdxBizFanPointProcessVariableClassificationDto> data = idxBizFanPointProcessVariableClassificationMapper.getInfluxDBData();
        Map<String, List<IdxBizFanPointProcessVariableClassificationDto>> maps = data.stream().collect(Collectors.groupingBy(IdxBizFanPointProcessVariableClassificationDto::getGatewayId));
        BoolQueryBuilder boolMustAll = QueryBuilders.boolQuery();
        List<QueryBuilder> should = boolMustAll.should();
        for (String s : maps.keySet()) {
            BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
            List<String> address = maps.get(s).stream().map(IdxBizFanPointProcessVariableClassificationDto::getIndexAddress).collect(Collectors.toList());
            boolQueryBuilder.must(QueryBuilders.termsQuery("address.keyword", address)).must(QueryBuilders.matchQuery("gatewayId.keyword", s));
            should.add(boolQueryBuilder);
        }

        // 创建查询构造器
        NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder()
                //过滤条件
                .withQuery(boolMustAll);
        List<ESEquipments> equipments = new LinkedList<>();
        long totle = 0;
        try {
            SearchHits<ESEquipments> searchHits = elasticsearchTemplate.search(queryBuilder.build(), ESEquipments.class);

            for (SearchHit searchHit : searchHits.getSearchHits()) {
                JSONObject jsonObject = (JSONObject) JSONObject.toJSON(searchHit.getContent());
                ESEquipments eSAlertCalled = JSONObject.toJavaObject(jsonObject, ESEquipments.class);
                equipments.add(eSAlertCalled);
            }
            totle = searchHits.getTotalHits();
        } catch (Exception e) {
            // TODO: handle exception
        }


        for (IdxBizFanPointProcessVariableClassificationDto datum : data) {
            for (ESEquipments equipment : equipments) {
                if (equipment.getAddress().equals(datum.getIndexAddress()) && equipment.getGatewayId().equals(datum.getGatewayId())) {
                    datum.setCurrentValue(equipment.getValueDouble());
                }
            }
        }

        LambdaQueryWrapper<IdxBizFanPointVarCentralValue> wrapper = new LambdaQueryWrapper<>();
        List<IdxBizFanPointVarCentralValue> idxBizUhefs = idxBizFanPointVarCentralValueMapper.selectList(wrapper);
        List<Map<String, Object>> datas = new ArrayList<>();
        Map<String, Map<String, Object>> resultMap = new HashMap<>();
        for (IdxBizFanPointVarCentralValue idxBizUhef : idxBizUhefs) {
            double value1 = 0.00;
            double value2 = 0.00;
            double value3 = 0.00;
            double value4 = 0.00;
            for (IdxBizFanPointProcessVariableClassificationDto datum : data) {
                if (idxBizUhef.getProcessPoint1Id().equals(datum.getSequenceNbr())) {
                    value1 = datum.getCurrentValue();
                }
                if (idxBizUhef.getProcessPoint2Id().equals(datum.getSequenceNbr())) {
                    value2 = datum.getCurrentValue();
                }
                if (idxBizUhef.getProcessPoint3Id().equals(datum.getSequenceNbr())) {
                    value3 = datum.getCurrentValue();
                }
                if (idxBizUhef.getAnalysisPointId().equals(datum.getSequenceNbr())) {
                    value4 = datum.getCurrentValue();
                }
            }
            Map<String, Object> map = new HashMap<>();
            if (idxBizUhef.getProcess1Min() <= value1 && value1 <= idxBizUhef.getProcess1Max() &&
                    idxBizUhef.getProcess2Min() <= value2 && value2 <= idxBizUhef.getPorcess2Max() &&
                    idxBizUhef.getProcess3Min() <= value3 && value3 <= idxBizUhef.getProcess3Max()) {
                map.put("analysisVariable", value4);
                map.put("stdDev", idxBizUhef.getAnalysisStdDev());
                map.put("centerValue", idxBizUhef.getAnalysisCenterValue());
                map.put("analysisVariableId", idxBizUhef.getAnalysisPointId());
                resultMap.put(idxBizUhef.getAnalysisPointId(), map);
            }
        }
        Collection<Map<String, Object>> values = resultMap.values();
        if (!values.isEmpty()) {
            logger.info("------------------------------------------开始调用健康指数计算算法开始----------------------------------------");
            HashMap<String, Object> realParams = new HashMap<>();
            realParams.put(gkzxzjskey1, values);
            String response = HttpUtil.createPost(baseUrl + jkzsjsfjurl).body(JSON.toJSONString(realParams)).execute().body();
            JSONObject result = JSON.parseObject(response).getJSONObject("result");
            if (null != result){
                JSONObject jsonObject =result .getJSONObject("result1").getJSONObject("rows");
                List<JSONObject> jsonObjects = JSON.parseArray(JSON.toJSONString(jsonObject), JSONObject.class);
                List<String> ids = new ArrayList<>();
                jsonObjects.stream().forEach(e-> ids.add(e.getString("analysisVariableId")));

                LambdaQueryWrapper<IdxBizFanPointProcessVariableClassification> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.in(IdxBizFanPointProcessVariableClassification::getSequenceNbr,ids);
                List<IdxBizFanPointProcessVariableClassification> list = idxBizFanPointProcessVariableClassificationMapper.selectList(queryWrapper);
                List<IdxBizFanHealthIndex> idxBizFanHealthIndexs = new ArrayList<>();
                for (IdxBizFanPointProcessVariableClassification obj : list) {
                    for (JSONObject object : jsonObjects) {
                        if (obj.getSequenceNbr().equals(object.getString("analysisVariableId"))){
                            IdxBizFanHealthIndex idxBizFanHealthIndex = new IdxBizFanHealthIndex();
                            BeanUtils.copyProperties(idxBizFanHealthIndex,obj);
                            idxBizFanHealthIndex.setHealthIndex(object.getDouble("indexValue"));
                            idxBizFanHealthIndex.setAnalysisObjSeq(obj.getSequenceNbr());
                            idxBizFanHealthIndex.setRecDate(new Date());
                            //获取健康指数对应等级
                            LambdaQueryWrapper<IdxBizFanHealthLevel> query = new LambdaQueryWrapper<>();
                            query.eq(IdxBizFanHealthLevel::getAnalysisObjType,"设备");
                            query.eq(IdxBizFanHealthLevel::getStatus,obj.getStation());
                            query.le(IdxBizFanHealthLevel::getGroupLowerLimit,object.getDouble("indexValue"));
                            query.ge(IdxBizFanHealthLevel::getGroupUpperLimit,object.getDouble("indexValue"));
                            IdxBizFanHealthLevel idxBizFanHealthLevel = idxBizFanHealthLevelMapper.selectOne(query);
                            idxBizFanHealthIndex.setHealthLevel(idxBizFanHealthLevel.getHealthLevel());
                            idxBizFanHealthIndex.setAnalysisType("按时刻");
                            idxBizFanHealthIndex.setANOMALY(object.getDouble("scoreValue"));
                            idxBizFanHealthIndexs.add(idxBizFanHealthIndex);
                        }
                    }
                }
                idxBizFanHealthIndexService.saveBatch(idxBizFanHealthIndexs);
                }

                try {
                logger.info("--------------------repsonse： "+response);
                logger.info("------------------------------------------调用健康指数计算算法结束----------------------------------------");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Scheduled(cron = "0 0/10 * * * ?")
    private void healthWarningMinuteByGF() {
        List<IdxBizPvPointProcessVariableClassificationDto> data = idxBizPvPointProcessVariableClassificationMapper.getInfluxDBData();
        Map<String, List<IdxBizPvPointProcessVariableClassificationDto>> maps = data.stream().collect(Collectors.groupingBy(IdxBizPvPointProcessVariableClassificationDto::getGatewayId));
        BoolQueryBuilder boolMustAll = QueryBuilders.boolQuery();
        List<QueryBuilder> should = boolMustAll.should();
        for (String s : maps.keySet()) {
            BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
            List<String> address = maps.get(s).stream().map(IdxBizPvPointProcessVariableClassificationDto::getIndexAddress).collect(Collectors.toList());
            boolQueryBuilder.must(QueryBuilders.termsQuery("address.keyword", address)).must(QueryBuilders.matchQuery("gatewayId.keyword", s));
            should.add(boolQueryBuilder);
        }

        // 创建查询构造器
        NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder()
                //过滤条件
                .withQuery(boolMustAll);
        List<ESEquipments> equipments = new LinkedList<>();
        long totle = 0;
        try {
            SearchHits<ESEquipments> searchHits = elasticsearchTemplate.search(queryBuilder.build(), ESEquipments.class);

            for (SearchHit searchHit : searchHits.getSearchHits()) {
                JSONObject jsonObject = (JSONObject) JSONObject.toJSON(searchHit.getContent());
                ESEquipments eSAlertCalled = JSONObject.toJavaObject(jsonObject, ESEquipments.class);
                equipments.add(eSAlertCalled);
            }
            totle = searchHits.getTotalHits();
        } catch (Exception e) {
            // TODO: handle exception
        }


        for (IdxBizPvPointProcessVariableClassificationDto datum : data) {
            for (ESEquipments equipment : equipments) {
                if (equipment.getAddress().equals(datum.getIndexAddress()) && equipment.getGatewayId().equals(datum.getGatewayId())){
                    datum.setCurrentValue(equipment.getValueDouble());
                }
            }
        }

        LambdaQueryWrapper<IdxBizPvPointVarCentralValue> wrapper = new LambdaQueryWrapper<>();
        List<IdxBizPvPointVarCentralValue> idxBizUhefs = idxBizPvPointVarCentralValueMapper.selectList(wrapper);
        List< Map<String, Object>> datas = new ArrayList<>();
        Map<String, Map<String, Object>> resultMap = new HashMap<>();
        for (IdxBizPvPointVarCentralValue idxBizUhef : idxBizUhefs) {
            double value1 = 0.00;
            double value2 = 0.00;
            double value3 = 0.00;
            double value4 = 0.00;
            for (IdxBizPvPointProcessVariableClassificationDto datum : data) {
                if (idxBizUhef.getProcessPoint1Id().equals(datum.getSequenceNbr())){
                    value1 = datum.getCurrentValue();
                }
                if (idxBizUhef.getProcessPoint2Id().equals(datum.getSequenceNbr())) {
                    value2 = datum.getCurrentValue();
                }
                if (idxBizUhef.getProcessPoint3Id().equals(datum.getSequenceNbr())) {
                    value3 = datum.getCurrentValue();
                }
                if (idxBizUhef.getAnalysisPointId().equals(datum.getSequenceNbr())) {
                    value4 = datum.getCurrentValue();
                }
            }
            Map<String, Object> map = new HashMap<>();
            if (idxBizUhef.getProcess1Min() <= value1 && value1 <= idxBizUhef.getProcess1Max() &&
                    idxBizUhef.getProcess2Min() <= value2 && value2 <= idxBizUhef.getProcess2Max() &&
                    idxBizUhef.getProcess3Min() <= value3 && value3 <= idxBizUhef.getProcess3Max()){
                map.put("analysisVariable",value4);
                map.put("stdDev",idxBizUhef.getAnalysisStdDev());
                map.put("centerValue",idxBizUhef.getAnalysisCenterValue());
                map.put("analysisVariableId",idxBizUhef.getAnalysisPointId());
                resultMap.put(idxBizUhef.getAnalysisPointId(),map);
            }
        }
        Collection<Map<String, Object>> values = resultMap.values();
        if (!values.isEmpty()) {
            logger.info("------------------------------------------开始调用健康指数计算算法开始----------------------------------------");
            HashMap<String, Object> realParams = new HashMap<>();
            realParams.put(gkzxzjskey1, values);
            String response = HttpUtil.createPost(baseUrl + jkzsgfurl).body(JSON.toJSONString(realParams)).execute().body();
            JSONObject result = JSON.parseObject(response).getJSONObject("result");
            if (null != result){
                JSONObject jsonObject =result .getJSONObject("result1").getJSONObject("rows");
                List<JSONObject> jsonObjects = JSON.parseArray(JSON.toJSONString(jsonObject), JSONObject.class);
                List<String> ids = new ArrayList<>();
                jsonObjects.stream().forEach(e-> ids.add(e.getString("analysisVariableId")));

                LambdaQueryWrapper<IdxBizPvPointProcessVariableClassification> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.in(IdxBizPvPointProcessVariableClassification::getSequenceNbr,ids);
                List<IdxBizPvPointProcessVariableClassification> list = idxBizPvPointProcessVariableClassificationMapper.selectList(queryWrapper);
                List<IdxBizPvHealthIndex> idxBizPvHealthIndexs = new ArrayList<>();
                for (IdxBizPvPointProcessVariableClassification obj : list) {
                    for (JSONObject object : jsonObjects) {
                        if (obj.getSequenceNbr().equals(object.getString("analysisVariableId"))){
                            IdxBizPvHealthIndex idxBizFanHealthIndex = new IdxBizPvHealthIndex();
                            BeanUtils.copyProperties(idxBizFanHealthIndex,obj);
                            idxBizFanHealthIndex.setHealthIndex(object.getDouble("indexValue"));
                            idxBizFanHealthIndex.setAnalysisObjSeq(obj.getSequenceNbr());
                            idxBizFanHealthIndex.setRecDate(new Date());
                            //获取健康指数对应等级
                            LambdaQueryWrapper<IdxBizPvHealthLevel> query = new LambdaQueryWrapper<>();
                            query.eq(IdxBizPvHealthLevel::getAnalysisObjType,"设备");
                            query.eq(IdxBizPvHealthLevel::getStatus,obj.getStation());
                            query.le(IdxBizPvHealthLevel::getGroupLowerLimit,object.getDouble("indexValue"));
                            query.ge(IdxBizPvHealthLevel::getGroupUpperLimit,object.getDouble("indexValue"));
                            IdxBizPvHealthLevel idxBizFanHealthLevel = idxBizPvHealthLevelMapper.selectOne(query);
                            idxBizFanHealthIndex.setHealthLevel(idxBizFanHealthLevel.getHealthLevel());
                            idxBizFanHealthIndex.setAnalysisType("按时刻");
                            idxBizFanHealthIndex.setANOMALY(object.getDouble("scoreValue"));
                            idxBizPvHealthIndexs.add(idxBizFanHealthIndex);
                        }
                    }
                }
                idxBizPvHealthIndexService.saveBatch(idxBizPvHealthIndexs);
            }

            try {
                logger.info("--------------------repsonse： " + response);
                logger.info("------------------------------------------调用健康指数计算算法结束----------------------------------------");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
