package com.njcn.executor.handler;

import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.device.api.LineFeignClient;
import com.njcn.executor.pojo.vo.*;
import com.njcn.harmonic.constant.Param;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.InfluxDB;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/5/10 14:10
 */
@Slf4j
@Component
@AllArgsConstructor
public class DayJob {

    private final String DATABASE = "pqsbase";

    private final InfluxDbUtils influxDbUtils;

    private final LineFeignClient lineFeignClient;

    @XxlJob("dayJobHandler")
    public void getDayData() throws ParseException {
        List<String> paramList = new ArrayList<>();
        List<String> lineList = new ArrayList<>();
        String command = XxlJobHelper.getJobParam();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)-1, 0, 0, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH)-1, 23, 59, 59);
        calendar2.set(Calendar.MILLISECOND, 0);
        String startTime = format.format(calendar.getTime());
        String endTime = format.format(calendar2.getTime());
        if (!StringUtils.isEmpty(command)){
            paramList = Arrays.asList(command.split(","));
            startTime = paramList.get(0);
            endTime = paramList.get(1);
            lineList = paramList.subList(2,paramList.size());
            if (CollectionUtils.isEmpty(lineList)){
                log.info("补招传入的参数，未传监测点id");
                lineList = lineFeignClient.getLineList().getData();
            }
            boolean s1 = Pattern.matches(PatternRegex.TIME_FORMAT,startTime);
            boolean e1 = Pattern.matches(PatternRegex.TIME_FORMAT,endTime);
            if (!s1 || !e1){
                log.error("补招时间格式错误");
                return;
            } else {
                startTime = startTime + " 00:00:00";
                endTime = endTime + " 23:59:59";
            }
        } else {
            lineList = lineFeignClient.getLineList().getData();
        }
        long diff,diffDays,a,b = 0;
        Date d1 = format.parse(startTime);
        Date d2 = format.parse(endTime);
        diff = d2.getTime() - d1.getTime();
        diffDays = diff / (24 * 60 * 60 * 1000-1000);
        int days = (int) diffDays;
        for (int i = 1; i <= days; i++) {
            a = d1.getTime() + (long)(i-1)*(24 * 60 * 60) * 1000;
            b = d1.getTime() + (long)i*(24 * 60 * 60) * 1000-1000;
            startTime = format.format(a);
            endTime = format.format(b);
            //生成dayV表
            List<DataV> dataV = getDataV(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataV)){
                insertDayV(dataV,a);
            }
            //生成dayI表
            List<DataI> dataI = getDataI(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataI)){
                insertDayI(dataI,a);
            }
            //生成dayFlicker表
            List<DataFlicker> dataFlicker = getDataFlicker(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataFlicker)){
                insertDayFlicker(dataFlicker,a);
            }
            //生成dayFluc表
            List<DataFluc> dataFluc = getDataFluc(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataFluc)){
                insertDayFluc(dataFluc,a);
            }
            //生成dayHarmphasicI表
            List<DataHarmPhasicI> dataHarmphasicI = getDataHarmphasicI(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataHarmphasicI)){
                insertDayHarmphasicI(dataHarmphasicI,a);
            }
            //生成dayHarmphasicV表
            List<DataHarmPhasicV> dataHarmphasicV = getDataHarmphasicV(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataHarmphasicV)){
                insertDayHarmphasicV(dataHarmphasicV,a);
            }
            //生成dayHarmPowerP表
            List<DataHarmPowerP> dataHarmPowerP = getDataHarmPowerP(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataHarmPowerP)){
                insertDayHarmPowerP(dataHarmPowerP,a);
            }
            //生成dayHarmPowerQ表
            List<DataHarmPowerQ> dataHarmPowerQ = getDataHarmPowerQ(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataHarmPowerQ)){
                insertDayHarmPowerQ(dataHarmPowerQ,a);
            }
            //生成dayHarmPowerS表
            List<DataHarmPowerS> dataHarmPowerS = getDataHarmPowerS(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataHarmPowerS)){
                insertDayHarmPowerS(dataHarmPowerS,a);
            }
            //生成dayHarmRateI
            List<DataHarmRateI> dataHarmRateI = getDataHarmRateI(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataHarmRateI)){
                insertDayHarmRateI(dataHarmRateI,a);
            }
            //生成dayHarmRateV
            List<DataHarmRateV> dataHarmRateV = getDataHarmRateV(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataHarmRateV)){
                insertDayHarmRateV(dataHarmRateV,a);
            }
            //生成dayInHarmI
            List<DataInHarmI> dataInHarmI = getDataInHarmI(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataInHarmI)){
                insertDayInHarmI(dataInHarmI,a);
            }
            //生成dayInHarmV
            List<DataInHarmV> dataInHarmV = getDataInHarmV(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataInHarmV)){
                insertDayInHarmV(dataInHarmV,a);
            }
            //生成dayInHarmRateI
            List<DataInHarmRateI> dataInHarmRateI = getDataInHarmRateI(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataInHarmRateI)){
                insertDayInHarmRateI(dataInHarmRateI,a);
            }
            //生成dayInHarmRateV
            List<DataInHarmRateV> dataInHarmRateV = getDataInHarmRateV(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataInHarmRateV)){
                insertDayInHarmRateV(dataInHarmRateV,a);
            }
            //生成dayPlt
            List<DataPlt> dataPlt = getDataPlt(lineList,startTime,endTime);
            if (!CollectionUtils.isEmpty(dataPlt)){
                insertDayPlt(dataPlt,a);
            }
        }
    }

    /**
     * 功能描述:获取dataV数据
     * @author xy
     * @param lineList    监测点集合
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataV>
     */
    public List<DataV> getDataV(List<String> lineList, String startTime, String endTime){
        List<DataV> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        stringBuilder1.append("min(freq) AS freq,min(freq_dev) AS freq_dev,min(rms) AS rms,min(rms_lvr) AS rms_lvr,min(v_neg) AS v_neg,min(v_pos) AS v_pos,min(v_thd) AS v_thd,min(v_unbalance) AS v_unbalance,min(v_zero) AS v_zero,min(vl_dev) AS vl_dev,min(vu_dev) AS vu_dev,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_v where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataV> list1 = resultMapper1.toPOJO(sqlResult1, DataV.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        stringBuilder3.append("max(freq) AS freq,max(freq_dev) AS freq_dev,max(rms) AS rms,max(rms_lvr) AS rms_lvr,max(v_neg) AS v_neg,max(v_pos) AS v_pos,max(v_thd) AS v_thd,max(v_unbalance) AS v_unbalance,max(v_zero) AS v_zero,max(vl_dev) AS vl_dev,max(vu_dev) AS vu_dev,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_v where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataV> list2 = resultMapper2.toPOJO(sqlResult2, DataV.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        stringBuilder5.append("mean(freq) AS freq,mean(freq_dev) AS freq_dev,mean(rms) AS rms,mean(rms_lvr) AS rms_lvr,mean(v_neg) AS v_neg,mean(v_pos) AS v_pos,mean(v_thd) AS v_thd,mean(v_unbalance) AS v_unbalance,mean(v_zero) AS v_zero,mean(vl_dev) AS vl_dev,mean(vu_dev) AS vu_dev,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_v where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataV> list3 = resultMapper3.toPOJO(sqlResult3, DataV.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        stringBuilder7.append("percentile(freq,95) AS freq,percentile(freq_dev,95) AS freq_dev,percentile(rms,95) AS rms,percentile(rms_lvr,95) AS rms_lvr,percentile(v_neg,95) AS v_neg,percentile(v_pos,95) AS v_pos,percentile(v_thd,95) AS v_thd,percentile(v_unbalance,95) AS v_unbalance,percentile(v_zero,95) AS v_zero,percentile(vl_dev,95) AS vl_dev,percentile(vu_dev,95) AS vu_dev,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i);
            } else {
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_v where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataV> list4 = resultMapper4.toPOJO(sqlResult4, DataV.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入dayV表数据
     * @author xy
     * @param list dataV集合
     * @param time 时间戳
     * @date 2022/5/11 14:55
     */
    private void insertDayV(List<DataV> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("freq",item.getFreq());
            fields.put("freq_dev",item.getFreqDev());
            fields.put("rms",item.getRms());
            fields.put("rms_lvr",item.getRmsLvr());
            fields.put("v_neg",item.getVNeg());
            fields.put("v_pos",item.getVPos());
            fields.put("v_thd",item.getVThd());
            fields.put("v_unbalance",item.getVUnbalance());
            fields.put("v_zero",item.getVZero());
            fields.put("vl_dev",item.getVlDev());
            fields.put("vu_dev",item.getVuDev());
            fields.put("v_1",item.getV1());
            fields.put("v_2",item.getV2());
            fields.put("v_3",item.getV3());
            fields.put("v_4",item.getV4());
            fields.put("v_5",item.getV5());
            fields.put("v_6",item.getV6());
            fields.put("v_7",item.getV7());
            fields.put("v_8",item.getV8());
            fields.put("v_9",item.getV9());
            fields.put("v_10",item.getV10());
            fields.put("v_11",item.getV11());
            fields.put("v_12",item.getV12());
            fields.put("v_13",item.getV13());
            fields.put("v_14",item.getV14());
            fields.put("v_15",item.getV15());
            fields.put("v_16",item.getV16());
            fields.put("v_17",item.getV17());
            fields.put("v_18",item.getV18());
            fields.put("v_19",item.getV19());
            fields.put("v_20",item.getV20());
            fields.put("v_21",item.getV21());
            fields.put("v_22",item.getV22());
            fields.put("v_23",item.getV23());
            fields.put("v_24",item.getV24());
            fields.put("v_25",item.getV25());
            fields.put("v_26",item.getV26());
            fields.put("v_27",item.getV27());
            fields.put("v_28",item.getV28());
            fields.put("v_29",item.getV29());
            fields.put("v_30",item.getV30());
            fields.put("v_31",item.getV31());
            fields.put("v_32",item.getV32());
            fields.put("v_33",item.getV33());
            fields.put("v_34",item.getV34());
            fields.put("v_35",item.getV35());
            fields.put("v_36",item.getV36());
            fields.put("v_37",item.getV37());
            fields.put("v_38",item.getV38());
            fields.put("v_39",item.getV39());
            fields.put("v_40",item.getV40());
            fields.put("v_41",item.getV41());
            fields.put("v_42",item.getV42());
            fields.put("v_43",item.getV43());
            fields.put("v_44",item.getV44());
            fields.put("v_45",item.getV45());
            fields.put("v_46",item.getV46());
            fields.put("v_47",item.getV47());
            fields.put("v_48",item.getV48());
            fields.put("v_49",item.getV49());
            fields.put("v_50",item.getV50());
            Point point = influxDbUtils.pointBuilder("day_v", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }


    /**
     * 功能描述:获取dataI数据
     * @author xy
     * @param lineList    监测点集合
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataI>
     */
    public List<DataI> getDataI(List<String> lineList, String startTime, String endTime){
        List<DataI> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        stringBuilder1.append("min(rms) AS rms,min(i_neg) AS i_neg,min(i_pos) AS i_pos,min(i_thd) AS i_thd,min(i_unbalance) AS i_unbalance,min(i_zero) AS i_zero,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_i where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataI> list1 = resultMapper1.toPOJO(sqlResult1, DataI.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        stringBuilder3.append("max(rms) AS rms,max(i_neg) AS i_neg,max(i_pos) AS i_pos,max(i_thd) AS i_thd,max(i_unbalance) AS i_unbalance,max(i_zero) AS i_zero,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_i where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataI> list2 = resultMapper2.toPOJO(sqlResult2, DataI.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        stringBuilder5.append("mean(rms) AS rms,mean(i_neg) AS i_neg,mean(i_pos) AS i_pos,mean(i_thd) AS i_thd,mean(i_unbalance) AS i_unbalance,mean(i_zero) AS i_zero,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_i where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataI> list3 = resultMapper3.toPOJO(sqlResult3, DataI.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        stringBuilder7.append("percentile(rms,95) AS rms,percentile(i_neg,95) AS i_neg,percentile(i_pos,95) AS i_pos,percentile(i_thd,95) AS i_thd,percentile(i_unbalance,95) AS i_unbalance,percentile(i_zero,95) AS i_zero,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i);
            } else {
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_i where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataI> list4 = resultMapper4.toPOJO(sqlResult4, DataI.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入dayI表数据
     * @author xy
     * @param list dataI集合
     * @param time 时间戳
     * @date 2022/5/11 14:55
     */
    private void insertDayI(List<DataI> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("rms",item.getRms());
            fields.put("i_neg",item.getINeg());
            fields.put("i_pos",item.getIPos());
            fields.put("i_thd",item.getIThd());
            fields.put("i_unbalance",item.getIUnbalance());
            fields.put("i_zero",item.getIZero());
            fields.put("i_1",item.getI1());
            fields.put("i_2",item.getI2());
            fields.put("i_3",item.getI3());
            fields.put("i_4",item.getI4());
            fields.put("i_5",item.getI5());
            fields.put("i_6",item.getI6());
            fields.put("i_7",item.getI7());
            fields.put("i_8",item.getI8());
            fields.put("i_9",item.getI9());
            fields.put("i_10",item.getI10());
            fields.put("i_11",item.getI11());
            fields.put("i_12",item.getI12());
            fields.put("i_13",item.getI13());
            fields.put("i_14",item.getI14());
            fields.put("i_15",item.getI15());
            fields.put("i_16",item.getI16());
            fields.put("i_17",item.getI17());
            fields.put("i_18",item.getI18());
            fields.put("i_19",item.getI19());
            fields.put("i_20",item.getI20());
            fields.put("i_21",item.getI21());
            fields.put("i_22",item.getI22());
            fields.put("i_23",item.getI23());
            fields.put("i_24",item.getI24());
            fields.put("i_25",item.getI25());
            fields.put("i_26",item.getI26());
            fields.put("i_27",item.getI27());
            fields.put("i_28",item.getI28());
            fields.put("i_29",item.getI29());
            fields.put("i_30",item.getI30());
            fields.put("i_31",item.getI31());
            fields.put("i_32",item.getI32());
            fields.put("i_33",item.getI33());
            fields.put("i_34",item.getI34());
            fields.put("i_35",item.getI35());
            fields.put("i_36",item.getI36());
            fields.put("i_37",item.getI37());
            fields.put("i_38",item.getI38());
            fields.put("i_39",item.getI39());
            fields.put("i_40",item.getI40());
            fields.put("i_41",item.getI41());
            fields.put("i_42",item.getI42());
            fields.put("i_43",item.getI43());
            fields.put("i_44",item.getI44());
            fields.put("i_45",item.getI45());
            fields.put("i_46",item.getI46());
            fields.put("i_47",item.getI47());
            fields.put("i_48",item.getI48());
            fields.put("i_49",item.getI49());
            fields.put("i_50",item.getI50());
            Point point = influxDbUtils.pointBuilder("day_i", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }


    /**
     * 功能描述:获取dataFlicker数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataFlicker>
     */
    public List<DataFlicker> getDataFlicker(List<String> lineList, String startTime, String endTime){
        List<DataFlicker> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        String sql1 = "select min(fluc) AS fluc,min(plt) AS plt,min(pst) AS pst from data_flicker where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataFlicker> list1 = resultMapper1.toPOJO(sqlResult1, DataFlicker.class);
        list1.forEach(item->{
            item.setValueType("MIN");
        });
        //最大值
        String sql2 = "select max(fluc) AS fluc,max(plt) AS plt,max(pst) AS pst from data_flicker where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataFlicker> list2 = resultMapper2.toPOJO(sqlResult2, DataFlicker.class);
        list2.forEach(item->{
            item.setValueType("MAX");
        });
        //平均值
        String sql3 = "select mean(fluc) AS fluc,mean(plt) AS plt,mean(pst) AS pst from data_flicker where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3= new InfluxDBResultMapper();
        List<DataFlicker> list3 = resultMapper3.toPOJO(sqlResult3, DataFlicker.class);
        list3.forEach(item->{
            item.setValueType("AVG");
        });
        //CP95值
        String sql4 = "select percentile(fluc,95) AS fluc,percentile(plt,95) AS plt,percentile(pst,95) AS pst from data_flicker where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4= new InfluxDBResultMapper();
        List<DataFlicker> list4 = resultMapper4.toPOJO(sqlResult4, DataFlicker.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入dayFlicker表数据
     * @author xy
     * @param list dataFlicker集合
     * @param time 时间戳
     * @date 2022/5/11 14:55
     */
    private void insertDayFlicker(List<DataFlicker> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("fluc",item.getFluc());
            fields.put("plt",item.getPlt());
            fields.put("pst",item.getPst());
            Point point = influxDbUtils.pointBuilder("day_flicker", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }


    /**
     * 功能描述:获取dataFluc数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataFluc>
     */
    public List<DataFluc> getDataFluc(List<String> lineList, String startTime, String endTime){
        List<DataFluc> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        String sql1 = "select min(fluc) AS fluc,min(fluccf) AS fluccf from data_fluc where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataFluc> list1 = resultMapper1.toPOJO(sqlResult1, DataFluc.class);
        list1.forEach(item->{
            item.setValueType("MIN");
        });
        //最大值
        String sql2 = "select max(fluc) AS fluc,max(fluccf) AS fluccf from data_fluc where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataFluc> list2 = resultMapper2.toPOJO(sqlResult2, DataFluc.class);
        list2.forEach(item->{
            item.setValueType("MAX");
        });
        //平均值
        String sql3 = "select mean(fluc) AS fluc,mean(fluccf) AS fluccf from data_fluc where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3= new InfluxDBResultMapper();
        List<DataFluc> list3 = resultMapper3.toPOJO(sqlResult3, DataFluc.class);
        list3.forEach(item->{
            item.setValueType("AVG");
        });
        //CP95值
        String sql4 = "select percentile(fluc,95) AS fluc,percentile(fluccf,95) AS fluccf from data_fluc where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4= new InfluxDBResultMapper();
        List<DataFluc> list4 = resultMapper4.toPOJO(sqlResult4, DataFluc.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入dayFluc表数据
     * @author xy
     * @param list dataFluc集合
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayFluc(List<DataFluc> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("fluc",item.getFluc());
            fields.put("fluccf",item.getFluccf());
            Point point = influxDbUtils.pointBuilder("day_fluc", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }


    /**
     * 功能描述:获取data_harmphasic_i数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataHarmPhasicI>
     */
    public List<DataHarmPhasicI> getDataHarmphasicI(List<String> lineList, String startTime, String endTime){
        List<DataHarmPhasicI> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_harmphasic_i where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataHarmPhasicI> list1 = resultMapper1.toPOJO(sqlResult1, DataHarmPhasicI.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_harmphasic_i where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataHarmPhasicI> list2 = resultMapper2.toPOJO(sqlResult2, DataHarmPhasicI.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_harmphasic_i where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataHarmPhasicI> list3 = resultMapper3.toPOJO(sqlResult3, DataHarmPhasicI.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i);
            } else {
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_harmphasic_i where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataHarmPhasicI> list4 = resultMapper4.toPOJO(sqlResult4, DataHarmPhasicI.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_harmphasic_i表数据
     * @author xy
     * @param list data_harmphasic_i表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayHarmphasicI(List<DataHarmPhasicI> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("i_1",item.getI1());
            fields.put("i_2",item.getI2());
            fields.put("i_3",item.getI3());
            fields.put("i_4",item.getI4());
            fields.put("i_5",item.getI5());
            fields.put("i_6",item.getI6());
            fields.put("i_7",item.getI7());
            fields.put("i_8",item.getI8());
            fields.put("i_9",item.getI9());
            fields.put("i_10",item.getI10());
            fields.put("i_11",item.getI11());
            fields.put("i_12",item.getI12());
            fields.put("i_13",item.getI13());
            fields.put("i_14",item.getI14());
            fields.put("i_15",item.getI15());
            fields.put("i_16",item.getI16());
            fields.put("i_17",item.getI17());
            fields.put("i_18",item.getI18());
            fields.put("i_19",item.getI19());
            fields.put("i_20",item.getI20());
            fields.put("i_21",item.getI21());
            fields.put("i_22",item.getI22());
            fields.put("i_23",item.getI23());
            fields.put("i_24",item.getI24());
            fields.put("i_25",item.getI25());
            fields.put("i_26",item.getI26());
            fields.put("i_27",item.getI27());
            fields.put("i_28",item.getI28());
            fields.put("i_29",item.getI29());
            fields.put("i_30",item.getI30());
            fields.put("i_31",item.getI31());
            fields.put("i_32",item.getI32());
            fields.put("i_33",item.getI33());
            fields.put("i_34",item.getI34());
            fields.put("i_35",item.getI35());
            fields.put("i_36",item.getI36());
            fields.put("i_37",item.getI37());
            fields.put("i_38",item.getI38());
            fields.put("i_39",item.getI39());
            fields.put("i_40",item.getI40());
            fields.put("i_41",item.getI41());
            fields.put("i_42",item.getI42());
            fields.put("i_43",item.getI43());
            fields.put("i_44",item.getI44());
            fields.put("i_45",item.getI45());
            fields.put("i_46",item.getI46());
            fields.put("i_47",item.getI47());
            fields.put("i_48",item.getI48());
            fields.put("i_49",item.getI49());
            fields.put("i_50",item.getI50());
            Point point = influxDbUtils.pointBuilder("day_harmphasic_i", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_harmphasic_v数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataHarmPhasicV>
     */
    public List<DataHarmPhasicV> getDataHarmphasicV(List<String> lineList, String startTime, String endTime){
        List<DataHarmPhasicV> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_harmphasic_v where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataHarmPhasicV> list1 = resultMapper1.toPOJO(sqlResult1, DataHarmPhasicV.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_harmphasic_v where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataHarmPhasicV> list2 = resultMapper2.toPOJO(sqlResult2, DataHarmPhasicV.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_harmphasic_v where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataHarmPhasicV> list3 = resultMapper3.toPOJO(sqlResult3, DataHarmPhasicV.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i);
            } else {
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_harmphasic_v where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataHarmPhasicV> list4 = resultMapper4.toPOJO(sqlResult4, DataHarmPhasicV.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_harmphasic_V表数据
     * @author xy
     * @param list data_harmphasic_V表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayHarmphasicV(List<DataHarmPhasicV> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("v_1",item.getV1());
            fields.put("v_2",item.getV2());
            fields.put("v_3",item.getV3());
            fields.put("v_4",item.getV4());
            fields.put("v_5",item.getV5());
            fields.put("v_6",item.getV6());
            fields.put("v_7",item.getV7());
            fields.put("v_8",item.getV8());
            fields.put("v_9",item.getV9());
            fields.put("v_10",item.getV10());
            fields.put("v_11",item.getV11());
            fields.put("v_12",item.getV12());
            fields.put("v_13",item.getV13());
            fields.put("v_14",item.getV14());
            fields.put("v_15",item.getV15());
            fields.put("v_16",item.getV16());
            fields.put("v_17",item.getV17());
            fields.put("v_18",item.getV18());
            fields.put("v_19",item.getV19());
            fields.put("v_20",item.getV20());
            fields.put("v_21",item.getV21());
            fields.put("v_22",item.getV22());
            fields.put("v_23",item.getV23());
            fields.put("v_24",item.getV24());
            fields.put("v_25",item.getV25());
            fields.put("v_26",item.getV26());
            fields.put("v_27",item.getV27());
            fields.put("v_28",item.getV28());
            fields.put("v_29",item.getV29());
            fields.put("v_30",item.getV30());
            fields.put("v_31",item.getV31());
            fields.put("v_32",item.getV32());
            fields.put("v_33",item.getV33());
            fields.put("v_34",item.getV34());
            fields.put("v_35",item.getV35());
            fields.put("v_36",item.getV36());
            fields.put("v_37",item.getV37());
            fields.put("v_38",item.getV38());
            fields.put("v_39",item.getV39());
            fields.put("v_40",item.getV40());
            fields.put("v_41",item.getV41());
            fields.put("v_42",item.getV42());
            fields.put("v_43",item.getV43());
            fields.put("v_44",item.getV44());
            fields.put("v_45",item.getV45());
            fields.put("v_46",item.getV46());
            fields.put("v_47",item.getV47());
            fields.put("v_48",item.getV48());
            fields.put("v_49",item.getV49());
            fields.put("v_50",item.getV50());
            Point point = influxDbUtils.pointBuilder("day_harmphasic_v", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_harmpower_p数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataHarmPowerP>
     */
    public List<DataHarmPowerP> getDataHarmPowerP(List<String> lineList, String startTime, String endTime){
        List<DataHarmPowerP> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        stringBuilder1.append("min(p) AS p,min(df) AS df,min(pf) AS pf,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(p_").append(i).append(") AS p_").append(i);
            } else {
                stringBuilder1.append("min(p_").append(i).append(") AS p_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_harmpower_p where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataHarmPowerP> list1 = resultMapper1.toPOJO(sqlResult1, DataHarmPowerP.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        stringBuilder3.append("max(p) AS p,max(df) AS df,max(pf) AS pf,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(p_").append(i).append(") AS p_").append(i);
            } else {
                stringBuilder3.append("max(p_").append(i).append(") AS p_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_harmpower_p where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataHarmPowerP> list2 = resultMapper2.toPOJO(sqlResult2, DataHarmPowerP.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        stringBuilder5.append("mean(p) AS p,mean(df) AS df,mean(pf) AS pf,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(p_").append(i).append(") AS p_").append(i);
            } else {
                stringBuilder5.append("mean(p_").append(i).append(") AS p_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_harmpower_p where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataHarmPowerP> list3 = resultMapper3.toPOJO(sqlResult3, DataHarmPowerP.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        stringBuilder7.append("percentile(p,95) AS p,percentile(df,95) AS df,percentile(pf,95) AS pf,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(p_").append(i).append(",95) AS p_").append(i);
            } else {
                stringBuilder7.append("percentile(p_").append(i).append(",95) AS p_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_harmpower_p where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataHarmPowerP> list4 = resultMapper4.toPOJO(sqlResult4, DataHarmPowerP.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_harmpower_p表数据
     * @author xy
     * @param list data_harmpower_p表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayHarmPowerP(List<DataHarmPowerP> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("df",item.getDf());
            fields.put("pf",item.getPf());
            fields.put("p",item.getP());
            fields.put("p_1",item.getP1());
            fields.put("p_2",item.getP2());
            fields.put("p_3",item.getP3());
            fields.put("p_4",item.getP4());
            fields.put("p_5",item.getP5());
            fields.put("p_6",item.getP6());
            fields.put("p_7",item.getP7());
            fields.put("p_8",item.getP8());
            fields.put("p_9",item.getP9());
            fields.put("p_10",item.getP10());
            fields.put("p_11",item.getP11());
            fields.put("p_12",item.getP12());
            fields.put("p_13",item.getP13());
            fields.put("p_14",item.getP14());
            fields.put("p_15",item.getP15());
            fields.put("p_16",item.getP16());
            fields.put("p_17",item.getP17());
            fields.put("p_18",item.getP18());
            fields.put("p_19",item.getP19());
            fields.put("p_20",item.getP20());
            fields.put("p_21",item.getP21());
            fields.put("p_22",item.getP22());
            fields.put("p_23",item.getP23());
            fields.put("p_24",item.getP24());
            fields.put("p_25",item.getP25());
            fields.put("p_26",item.getP26());
            fields.put("p_27",item.getP27());
            fields.put("p_28",item.getP28());
            fields.put("p_29",item.getP29());
            fields.put("p_30",item.getP30());
            fields.put("p_31",item.getP31());
            fields.put("p_32",item.getP32());
            fields.put("p_33",item.getP33());
            fields.put("p_34",item.getP34());
            fields.put("p_35",item.getP35());
            fields.put("p_36",item.getP36());
            fields.put("p_37",item.getP37());
            fields.put("p_38",item.getP38());
            fields.put("p_39",item.getP39());
            fields.put("p_40",item.getP40());
            fields.put("p_41",item.getP41());
            fields.put("p_42",item.getP42());
            fields.put("p_43",item.getP43());
            fields.put("p_44",item.getP44());
            fields.put("p_45",item.getP45());
            fields.put("p_46",item.getP46());
            fields.put("p_47",item.getP47());
            fields.put("p_48",item.getP48());
            fields.put("p_49",item.getP49());
            fields.put("p_50",item.getP50());
            Point point = influxDbUtils.pointBuilder("day_harmpower_p", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }


    /**
     * 功能描述:获取data_harmpower_q数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataHarmPowerQ>
     */
    public List<DataHarmPowerQ> getDataHarmPowerQ(List<String> lineList, String startTime, String endTime){
        List<DataHarmPowerQ> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        stringBuilder1.append("min(q) AS q,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(q_").append(i).append(") AS q_").append(i);
            } else {
                stringBuilder1.append("min(q_").append(i).append(") AS q_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_harmpower_q where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataHarmPowerQ> list1 = resultMapper1.toPOJO(sqlResult1, DataHarmPowerQ.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        stringBuilder3.append("max(q) AS q,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(q_").append(i).append(") AS q_").append(i);
            } else {
                stringBuilder3.append("max(q_").append(i).append(") AS q_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_harmpower_q where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataHarmPowerQ> list2 = resultMapper2.toPOJO(sqlResult2, DataHarmPowerQ.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        stringBuilder5.append("mean(q) AS q,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(q_").append(i).append(") AS q_").append(i);
            } else {
                stringBuilder5.append("mean(q_").append(i).append(") AS q_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_harmpower_q where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataHarmPowerQ> list3 = resultMapper3.toPOJO(sqlResult3, DataHarmPowerQ.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        stringBuilder7.append("percentile(q,95) AS q,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(q_").append(i).append(",95) AS q_").append(i);
            } else {
                stringBuilder7.append("percentile(q_").append(i).append(",95) AS q_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_harmpower_q where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataHarmPowerQ> list4 = resultMapper4.toPOJO(sqlResult4, DataHarmPowerQ.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_harmpower_q表数据
     * @author xy
     * @param list data_harmpower_q表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayHarmPowerQ(List<DataHarmPowerQ> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("q",item.getQ());
            fields.put("q_1",item.getQ1());
            fields.put("q_2",item.getQ2());
            fields.put("q_3",item.getQ3());
            fields.put("q_4",item.getQ4());
            fields.put("q_5",item.getQ5());
            fields.put("q_6",item.getQ6());
            fields.put("q_7",item.getQ7());
            fields.put("q_8",item.getQ8());
            fields.put("q_9",item.getQ9());
            fields.put("q_10",item.getQ10());
            fields.put("q_11",item.getQ11());
            fields.put("q_12",item.getQ12());
            fields.put("q_13",item.getQ13());
            fields.put("q_14",item.getQ14());
            fields.put("q_15",item.getQ15());
            fields.put("q_16",item.getQ16());
            fields.put("q_17",item.getQ17());
            fields.put("q_18",item.getQ18());
            fields.put("q_19",item.getQ19());
            fields.put("q_20",item.getQ20());
            fields.put("q_21",item.getQ21());
            fields.put("q_22",item.getQ22());
            fields.put("q_23",item.getQ23());
            fields.put("q_24",item.getQ24());
            fields.put("q_25",item.getQ25());
            fields.put("q_26",item.getQ26());
            fields.put("q_27",item.getQ27());
            fields.put("q_28",item.getQ28());
            fields.put("q_29",item.getQ29());
            fields.put("q_30",item.getQ30());
            fields.put("q_31",item.getQ31());
            fields.put("q_32",item.getQ32());
            fields.put("q_33",item.getQ33());
            fields.put("q_34",item.getQ34());
            fields.put("q_35",item.getQ35());
            fields.put("q_36",item.getQ36());
            fields.put("q_37",item.getQ37());
            fields.put("q_38",item.getQ38());
            fields.put("q_39",item.getQ39());
            fields.put("q_40",item.getQ40());
            fields.put("q_41",item.getQ41());
            fields.put("q_42",item.getQ42());
            fields.put("q_43",item.getQ43());
            fields.put("q_44",item.getQ44());
            fields.put("q_45",item.getQ45());
            fields.put("q_46",item.getQ46());
            fields.put("q_47",item.getQ47());
            fields.put("q_48",item.getQ48());
            fields.put("q_49",item.getQ49());
            fields.put("q_50",item.getQ50());
            Point point = influxDbUtils.pointBuilder("day_harmpower_q", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_harmpower_s数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataHarmPowerS>
     */
    public List<DataHarmPowerS> getDataHarmPowerS(List<String> lineList, String startTime, String endTime){
        List<DataHarmPowerS> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        stringBuilder1.append("min(s) AS s,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(s_").append(i).append(") AS s_").append(i);
            } else {
                stringBuilder1.append("min(s_").append(i).append(") AS s_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_harmpower_s where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataHarmPowerS> list1 = resultMapper1.toPOJO(sqlResult1, DataHarmPowerS.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        stringBuilder3.append("max(s) AS s,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(s_").append(i).append(") AS s_").append(i);
            } else {
                stringBuilder3.append("max(s_").append(i).append(") AS s_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_harmpower_s where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataHarmPowerS> list2 = resultMapper2.toPOJO(sqlResult2, DataHarmPowerS.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        stringBuilder5.append("mean(s) AS s,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(s_").append(i).append(") AS s_").append(i);
            } else {
                stringBuilder5.append("mean(s_").append(i).append(") AS s_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_harmpower_s where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataHarmPowerS> list3 = resultMapper3.toPOJO(sqlResult3, DataHarmPowerS.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        stringBuilder7.append("percentile(s,95) AS s,");
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(s_").append(i).append(",95) AS s_").append(i);
            } else {
                stringBuilder7.append("percentile(s_").append(i).append(",95) AS s_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_harmpower_s where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataHarmPowerS> list4 = resultMapper4.toPOJO(sqlResult4, DataHarmPowerS.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_harmpower_q表数据
     * @author xy
     * @param list data_harmpower_q表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayHarmPowerS(List<DataHarmPowerS> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("s",item.getS());
            fields.put("s_1",item.getS1());
            fields.put("s_2",item.getS2());
            fields.put("s_3",item.getS3());
            fields.put("s_4",item.getS4());
            fields.put("s_5",item.getS5());
            fields.put("s_6",item.getS6());
            fields.put("s_7",item.getS7());
            fields.put("s_8",item.getS8());
            fields.put("s_9",item.getS9());
            fields.put("s_10",item.getS10());
            fields.put("s_11",item.getS11());
            fields.put("s_12",item.getS12());
            fields.put("s_13",item.getS13());
            fields.put("s_14",item.getS14());
            fields.put("s_15",item.getS15());
            fields.put("s_16",item.getS16());
            fields.put("s_17",item.getS17());
            fields.put("s_18",item.getS18());
            fields.put("s_19",item.getS19());
            fields.put("s_20",item.getS20());
            fields.put("s_21",item.getS21());
            fields.put("s_22",item.getS22());
            fields.put("s_23",item.getS23());
            fields.put("s_24",item.getS24());
            fields.put("s_25",item.getS25());
            fields.put("s_26",item.getS26());
            fields.put("s_27",item.getS27());
            fields.put("s_28",item.getS28());
            fields.put("s_29",item.getS29());
            fields.put("s_30",item.getS30());
            fields.put("s_31",item.getS31());
            fields.put("s_32",item.getS32());
            fields.put("s_33",item.getS33());
            fields.put("s_34",item.getS34());
            fields.put("s_35",item.getS35());
            fields.put("s_36",item.getS36());
            fields.put("s_37",item.getS37());
            fields.put("s_38",item.getS38());
            fields.put("s_39",item.getS39());
            fields.put("s_40",item.getS40());
            fields.put("s_41",item.getS41());
            fields.put("s_42",item.getS42());
            fields.put("s_43",item.getS43());
            fields.put("s_44",item.getS44());
            fields.put("s_45",item.getS45());
            fields.put("s_46",item.getS46());
            fields.put("s_47",item.getS47());
            fields.put("s_48",item.getS48());
            fields.put("s_49",item.getS49());
            fields.put("s_50",item.getS50());
            Point point = influxDbUtils.pointBuilder("day_harmpower_s", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_harmrate_i数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataHarmRateI>
     */
    public List<DataHarmRateI> getDataHarmRateI(List<String> lineList, String startTime, String endTime){
        List<DataHarmRateI> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_harmrate_i where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataHarmRateI> list1 = resultMapper1.toPOJO(sqlResult1, DataHarmRateI.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_harmrate_i where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataHarmRateI> list2 = resultMapper2.toPOJO(sqlResult2, DataHarmRateI.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_harmrate_i where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataHarmRateI> list3 = resultMapper3.toPOJO(sqlResult3, DataHarmRateI.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i);
            } else {
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_harmrate_i where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataHarmRateI> list4 = resultMapper4.toPOJO(sqlResult4, DataHarmRateI.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_harmrate_i表数据
     * @author xy
     * @param list data_harmrate_i表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayHarmRateI(List<DataHarmRateI> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("i_1",item.getI1());
            fields.put("i_2",item.getI2());
            fields.put("i_3",item.getI3());
            fields.put("i_4",item.getI4());
            fields.put("i_5",item.getI5());
            fields.put("i_6",item.getI6());
            fields.put("i_7",item.getI7());
            fields.put("i_8",item.getI8());
            fields.put("i_9",item.getI9());
            fields.put("i_10",item.getI10());
            fields.put("i_11",item.getI11());
            fields.put("i_12",item.getI12());
            fields.put("i_13",item.getI13());
            fields.put("i_14",item.getI14());
            fields.put("i_15",item.getI15());
            fields.put("i_16",item.getI16());
            fields.put("i_17",item.getI17());
            fields.put("i_18",item.getI18());
            fields.put("i_19",item.getI19());
            fields.put("i_20",item.getI20());
            fields.put("i_21",item.getI21());
            fields.put("i_22",item.getI22());
            fields.put("i_23",item.getI23());
            fields.put("i_24",item.getI24());
            fields.put("i_25",item.getI25());
            fields.put("i_26",item.getI26());
            fields.put("i_27",item.getI27());
            fields.put("i_28",item.getI28());
            fields.put("i_29",item.getI29());
            fields.put("i_30",item.getI30());
            fields.put("i_31",item.getI31());
            fields.put("i_32",item.getI32());
            fields.put("i_33",item.getI33());
            fields.put("i_34",item.getI34());
            fields.put("i_35",item.getI35());
            fields.put("i_36",item.getI36());
            fields.put("i_37",item.getI37());
            fields.put("i_38",item.getI38());
            fields.put("i_39",item.getI39());
            fields.put("i_40",item.getI40());
            fields.put("i_41",item.getI41());
            fields.put("i_42",item.getI42());
            fields.put("i_43",item.getI43());
            fields.put("i_44",item.getI44());
            fields.put("i_45",item.getI45());
            fields.put("i_46",item.getI46());
            fields.put("i_47",item.getI47());
            fields.put("i_48",item.getI48());
            fields.put("i_49",item.getI49());
            fields.put("i_50",item.getI50());
            Point point = influxDbUtils.pointBuilder("day_harmrate_i", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_harmrate_v数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataHarmRateV>
     */
    public List<DataHarmRateV> getDataHarmRateV(List<String> lineList, String startTime, String endTime){
        List<DataHarmRateV> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_harmrate_v where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataHarmRateV> list1 = resultMapper1.toPOJO(sqlResult1, DataHarmRateV.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_harmrate_v where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataHarmRateV> list2 = resultMapper2.toPOJO(sqlResult2, DataHarmRateV.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_harmrate_v where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataHarmRateV> list3 = resultMapper3.toPOJO(sqlResult3, DataHarmRateV.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i);
            } else {
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_harmrate_v where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataHarmRateV> list4 = resultMapper4.toPOJO(sqlResult4, DataHarmRateV.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_harmrate_v表数据
     * @author xy
     * @param list data_harmrate_v表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayHarmRateV(List<DataHarmRateV> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("v_1",item.getV1());
            fields.put("v_2",item.getV2());
            fields.put("v_3",item.getV3());
            fields.put("v_4",item.getV4());
            fields.put("v_5",item.getV5());
            fields.put("v_6",item.getV6());
            fields.put("v_7",item.getV7());
            fields.put("v_8",item.getV8());
            fields.put("v_9",item.getV9());
            fields.put("v_10",item.getV10());
            fields.put("v_11",item.getV11());
            fields.put("v_12",item.getV12());
            fields.put("v_13",item.getV13());
            fields.put("v_14",item.getV14());
            fields.put("v_15",item.getV15());
            fields.put("v_16",item.getV16());
            fields.put("v_17",item.getV17());
            fields.put("v_18",item.getV18());
            fields.put("v_19",item.getV19());
            fields.put("v_20",item.getV20());
            fields.put("v_21",item.getV21());
            fields.put("v_22",item.getV22());
            fields.put("v_23",item.getV23());
            fields.put("v_24",item.getV24());
            fields.put("v_25",item.getV25());
            fields.put("v_26",item.getV26());
            fields.put("v_27",item.getV27());
            fields.put("v_28",item.getV28());
            fields.put("v_29",item.getV29());
            fields.put("v_30",item.getV30());
            fields.put("v_31",item.getV31());
            fields.put("v_32",item.getV32());
            fields.put("v_33",item.getV33());
            fields.put("v_34",item.getV34());
            fields.put("v_35",item.getV35());
            fields.put("v_36",item.getV36());
            fields.put("v_37",item.getV37());
            fields.put("v_38",item.getV38());
            fields.put("v_39",item.getV39());
            fields.put("v_40",item.getV40());
            fields.put("v_41",item.getV41());
            fields.put("v_42",item.getV42());
            fields.put("v_43",item.getV43());
            fields.put("v_44",item.getV44());
            fields.put("v_45",item.getV45());
            fields.put("v_46",item.getV46());
            fields.put("v_47",item.getV47());
            fields.put("v_48",item.getV48());
            fields.put("v_49",item.getV49());
            fields.put("v_50",item.getV50());
            Point point = influxDbUtils.pointBuilder("day_harmrate_v", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_inharm_i数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataInHarmI>
     */
    public List<DataInHarmI> getDataInHarmI(List<String> lineList, String startTime, String endTime){
        List<DataInHarmI> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_inharm_i where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataInHarmI> list1 = resultMapper1.toPOJO(sqlResult1, DataInHarmI.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_inharm_i where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataInHarmI> list2 = resultMapper2.toPOJO(sqlResult2, DataInHarmI.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_inharm_i where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataInHarmI> list3 = resultMapper3.toPOJO(sqlResult3, DataInHarmI.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i);
            } else {
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_inharm_i where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataInHarmI> list4 = resultMapper4.toPOJO(sqlResult4, DataInHarmI.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_inharm_i表数据
     * @author xy
     * @param list data_inharm_i表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayInHarmI(List<DataInHarmI> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("i_1",item.getI1());
            fields.put("i_2",item.getI2());
            fields.put("i_3",item.getI3());
            fields.put("i_4",item.getI4());
            fields.put("i_5",item.getI5());
            fields.put("i_6",item.getI6());
            fields.put("i_7",item.getI7());
            fields.put("i_8",item.getI8());
            fields.put("i_9",item.getI9());
            fields.put("i_10",item.getI10());
            fields.put("i_11",item.getI11());
            fields.put("i_12",item.getI12());
            fields.put("i_13",item.getI13());
            fields.put("i_14",item.getI14());
            fields.put("i_15",item.getI15());
            fields.put("i_16",item.getI16());
            fields.put("i_17",item.getI17());
            fields.put("i_18",item.getI18());
            fields.put("i_19",item.getI19());
            fields.put("i_20",item.getI20());
            fields.put("i_21",item.getI21());
            fields.put("i_22",item.getI22());
            fields.put("i_23",item.getI23());
            fields.put("i_24",item.getI24());
            fields.put("i_25",item.getI25());
            fields.put("i_26",item.getI26());
            fields.put("i_27",item.getI27());
            fields.put("i_28",item.getI28());
            fields.put("i_29",item.getI29());
            fields.put("i_30",item.getI30());
            fields.put("i_31",item.getI31());
            fields.put("i_32",item.getI32());
            fields.put("i_33",item.getI33());
            fields.put("i_34",item.getI34());
            fields.put("i_35",item.getI35());
            fields.put("i_36",item.getI36());
            fields.put("i_37",item.getI37());
            fields.put("i_38",item.getI38());
            fields.put("i_39",item.getI39());
            fields.put("i_40",item.getI40());
            fields.put("i_41",item.getI41());
            fields.put("i_42",item.getI42());
            fields.put("i_43",item.getI43());
            fields.put("i_44",item.getI44());
            fields.put("i_45",item.getI45());
            fields.put("i_46",item.getI46());
            fields.put("i_47",item.getI47());
            fields.put("i_48",item.getI48());
            fields.put("i_49",item.getI49());
            fields.put("i_50",item.getI50());
            Point point = influxDbUtils.pointBuilder("day_inharm_i", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_inharm_v数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataInHarmV>
     */
    public List<DataInHarmV> getDataInHarmV(List<String> lineList, String startTime, String endTime){
        List<DataInHarmV> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_inharm_v where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataInHarmV> list1 = resultMapper1.toPOJO(sqlResult1, DataInHarmV.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_inharm_v where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataInHarmV> list2 = resultMapper2.toPOJO(sqlResult2, DataInHarmV.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_inharm_v where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataInHarmV> list3 = resultMapper3.toPOJO(sqlResult3, DataInHarmV.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i);
            } else {
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_inharm_v where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataInHarmV> list4 = resultMapper4.toPOJO(sqlResult4, DataInHarmV.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_inharm_v表数据
     * @author xy
     * @param list data_inharm_v表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayInHarmV(List<DataInHarmV> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("v_1",item.getV1());
            fields.put("v_2",item.getV2());
            fields.put("v_3",item.getV3());
            fields.put("v_4",item.getV4());
            fields.put("v_5",item.getV5());
            fields.put("v_6",item.getV6());
            fields.put("v_7",item.getV7());
            fields.put("v_8",item.getV8());
            fields.put("v_9",item.getV9());
            fields.put("v_10",item.getV10());
            fields.put("v_11",item.getV11());
            fields.put("v_12",item.getV12());
            fields.put("v_13",item.getV13());
            fields.put("v_14",item.getV14());
            fields.put("v_15",item.getV15());
            fields.put("v_16",item.getV16());
            fields.put("v_17",item.getV17());
            fields.put("v_18",item.getV18());
            fields.put("v_19",item.getV19());
            fields.put("v_20",item.getV20());
            fields.put("v_21",item.getV21());
            fields.put("v_22",item.getV22());
            fields.put("v_23",item.getV23());
            fields.put("v_24",item.getV24());
            fields.put("v_25",item.getV25());
            fields.put("v_26",item.getV26());
            fields.put("v_27",item.getV27());
            fields.put("v_28",item.getV28());
            fields.put("v_29",item.getV29());
            fields.put("v_30",item.getV30());
            fields.put("v_31",item.getV31());
            fields.put("v_32",item.getV32());
            fields.put("v_33",item.getV33());
            fields.put("v_34",item.getV34());
            fields.put("v_35",item.getV35());
            fields.put("v_36",item.getV36());
            fields.put("v_37",item.getV37());
            fields.put("v_38",item.getV38());
            fields.put("v_39",item.getV39());
            fields.put("v_40",item.getV40());
            fields.put("v_41",item.getV41());
            fields.put("v_42",item.getV42());
            fields.put("v_43",item.getV43());
            fields.put("v_44",item.getV44());
            fields.put("v_45",item.getV45());
            fields.put("v_46",item.getV46());
            fields.put("v_47",item.getV47());
            fields.put("v_48",item.getV48());
            fields.put("v_49",item.getV49());
            fields.put("v_50",item.getV50());
            Point point = influxDbUtils.pointBuilder("day_inharm_v", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }


    /**
     * 功能描述:获取data_inharmrate_i数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataInHarmRateI>
     */
    public List<DataInHarmRateI> getDataInHarmRateI(List<String> lineList, String startTime, String endTime){
        List<DataInHarmRateI> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder1.append("min(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_inharmrate_i where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataInHarmRateI> list1 = resultMapper1.toPOJO(sqlResult1, DataInHarmRateI.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder3.append("max(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_inharmrate_i where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataInHarmRateI> list2 = resultMapper2.toPOJO(sqlResult2, DataInHarmRateI.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i);
            } else {
                stringBuilder5.append("mean(i_").append(i).append(") AS i_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_inharmrate_i where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataInHarmRateI> list3 = resultMapper3.toPOJO(sqlResult3, DataInHarmRateI.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i);
            } else {
                stringBuilder7.append("percentile(i_").append(i).append(",95) AS i_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_inharmrate_i where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataInHarmRateI> list4 = resultMapper4.toPOJO(sqlResult4, DataInHarmRateI.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_inharmrate_i表数据
     * @author xy
     * @param list data_inharmrate_i表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayInHarmRateI(List<DataInHarmRateI> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("i_1",item.getI1());
            fields.put("i_2",item.getI2());
            fields.put("i_3",item.getI3());
            fields.put("i_4",item.getI4());
            fields.put("i_5",item.getI5());
            fields.put("i_6",item.getI6());
            fields.put("i_7",item.getI7());
            fields.put("i_8",item.getI8());
            fields.put("i_9",item.getI9());
            fields.put("i_10",item.getI10());
            fields.put("i_11",item.getI11());
            fields.put("i_12",item.getI12());
            fields.put("i_13",item.getI13());
            fields.put("i_14",item.getI14());
            fields.put("i_15",item.getI15());
            fields.put("i_16",item.getI16());
            fields.put("i_17",item.getI17());
            fields.put("i_18",item.getI18());
            fields.put("i_19",item.getI19());
            fields.put("i_20",item.getI20());
            fields.put("i_21",item.getI21());
            fields.put("i_22",item.getI22());
            fields.put("i_23",item.getI23());
            fields.put("i_24",item.getI24());
            fields.put("i_25",item.getI25());
            fields.put("i_26",item.getI26());
            fields.put("i_27",item.getI27());
            fields.put("i_28",item.getI28());
            fields.put("i_29",item.getI29());
            fields.put("i_30",item.getI30());
            fields.put("i_31",item.getI31());
            fields.put("i_32",item.getI32());
            fields.put("i_33",item.getI33());
            fields.put("i_34",item.getI34());
            fields.put("i_35",item.getI35());
            fields.put("i_36",item.getI36());
            fields.put("i_37",item.getI37());
            fields.put("i_38",item.getI38());
            fields.put("i_39",item.getI39());
            fields.put("i_40",item.getI40());
            fields.put("i_41",item.getI41());
            fields.put("i_42",item.getI42());
            fields.put("i_43",item.getI43());
            fields.put("i_44",item.getI44());
            fields.put("i_45",item.getI45());
            fields.put("i_46",item.getI46());
            fields.put("i_47",item.getI47());
            fields.put("i_48",item.getI48());
            fields.put("i_49",item.getI49());
            fields.put("i_50",item.getI50());
            Point point = influxDbUtils.pointBuilder("day_inharmrate_i", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_inharmrate_v数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataInHarmRateV>
     */
    public List<DataInHarmRateV> getDataInHarmRateV(List<String> lineList, String startTime, String endTime){
        List<DataInHarmRateV> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        StringBuilder stringBuilder1 = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder1.append("min(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder2.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MIN' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql1 = "select "+stringBuilder1+" from data_inharmrate_v where "+stringBuilder+stringBuilder2;
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataInHarmRateV> list1 = resultMapper1.toPOJO(sqlResult1, DataInHarmRateV.class);
        //最大值
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder3.append("max(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder4.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'MAX' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql2 = "select "+stringBuilder3+" from data_inharmrate_v where "+stringBuilder+stringBuilder4;
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataInHarmRateV> list2 = resultMapper2.toPOJO(sqlResult2, DataInHarmRateV.class);
        //平均值
        StringBuilder stringBuilder5 = new StringBuilder();
        StringBuilder stringBuilder6 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i);
            } else {
                stringBuilder5.append("mean(v_").append(i).append(") AS v_").append(i).append(",");
            }
        }
        stringBuilder6.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql3 = "select "+stringBuilder5+" from data_inharmrate_v where "+stringBuilder+stringBuilder6;
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3 = new InfluxDBResultMapper();
        List<DataInHarmRateV> list3 = resultMapper3.toPOJO(sqlResult3, DataInHarmRateV.class);
        //CP95值
        StringBuilder stringBuilder7 = new StringBuilder();
        StringBuilder stringBuilder8 = new StringBuilder();
        for (int i = 1; i <=50 ; i++) {
            if (i==50){
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i);
            } else {
                stringBuilder7.append("percentile(v_").append(i).append(",95) AS v_").append(i).append(",");
            }
        }
        stringBuilder8.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and value_type = 'AVG' group by line_id,phasic_type,value_type,quality_flag tz('Asia/Shanghai')");
        String sql4 = "select "+stringBuilder7+" from data_inharmrate_v where "+stringBuilder+stringBuilder8;
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4 = new InfluxDBResultMapper();
        List<DataInHarmRateV> list4 = resultMapper4.toPOJO(sqlResult4, DataInHarmRateV.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_inharmrate_v表数据
     * @author xy
     * @param list data_inharmrate_v表数据
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayInHarmRateV(List<DataInHarmRateV> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("v_1",item.getV1());
            fields.put("v_2",item.getV2());
            fields.put("v_3",item.getV3());
            fields.put("v_4",item.getV4());
            fields.put("v_5",item.getV5());
            fields.put("v_6",item.getV6());
            fields.put("v_7",item.getV7());
            fields.put("v_8",item.getV8());
            fields.put("v_9",item.getV9());
            fields.put("v_10",item.getV10());
            fields.put("v_11",item.getV11());
            fields.put("v_12",item.getV12());
            fields.put("v_13",item.getV13());
            fields.put("v_14",item.getV14());
            fields.put("v_15",item.getV15());
            fields.put("v_16",item.getV16());
            fields.put("v_17",item.getV17());
            fields.put("v_18",item.getV18());
            fields.put("v_19",item.getV19());
            fields.put("v_20",item.getV20());
            fields.put("v_21",item.getV21());
            fields.put("v_22",item.getV22());
            fields.put("v_23",item.getV23());
            fields.put("v_24",item.getV24());
            fields.put("v_25",item.getV25());
            fields.put("v_26",item.getV26());
            fields.put("v_27",item.getV27());
            fields.put("v_28",item.getV28());
            fields.put("v_29",item.getV29());
            fields.put("v_30",item.getV30());
            fields.put("v_31",item.getV31());
            fields.put("v_32",item.getV32());
            fields.put("v_33",item.getV33());
            fields.put("v_34",item.getV34());
            fields.put("v_35",item.getV35());
            fields.put("v_36",item.getV36());
            fields.put("v_37",item.getV37());
            fields.put("v_38",item.getV38());
            fields.put("v_39",item.getV39());
            fields.put("v_40",item.getV40());
            fields.put("v_41",item.getV41());
            fields.put("v_42",item.getV42());
            fields.put("v_43",item.getV43());
            fields.put("v_44",item.getV44());
            fields.put("v_45",item.getV45());
            fields.put("v_46",item.getV46());
            fields.put("v_47",item.getV47());
            fields.put("v_48",item.getV48());
            fields.put("v_49",item.getV49());
            fields.put("v_50",item.getV50());
            Point point = influxDbUtils.pointBuilder("day_inharmrate_v", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    /**
     * 功能描述:获取data_plt数据
     * @author xy
     * @param startTime   起始时间
     * @param endTime     结束时间
     * @date 2022/5/10 14:56
     * @return List<DataPlt>
     */
    public List<DataPlt> getDataPlt(List<String> lineList, String startTime, String endTime){
        List<DataPlt> result = new ArrayList<>();
        StringBuilder stringBuilder = lineStringBuilder(lineList);
        //最小值
        String sql1 = "select min(plt) AS plt from data_plt where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult1 = influxDbUtils.query(sql1);
        InfluxDBResultMapper resultMapper1 = new InfluxDBResultMapper();
        List<DataPlt> list1 = resultMapper1.toPOJO(sqlResult1, DataPlt.class);
        list1.forEach(item->{
            item.setValueType("MIN");
        });
        //最大值
        String sql2 = "select max(plt) AS plt from data_plt where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult2 = influxDbUtils.query(sql2);
        InfluxDBResultMapper resultMapper2 = new InfluxDBResultMapper();
        List<DataPlt> list2 = resultMapper2.toPOJO(sqlResult2, DataPlt.class);
        list2.forEach(item->{
            item.setValueType("MAX");
        });
        //平均值
        String sql3 = "select mean(plt) AS plt from data_plt where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult3 = influxDbUtils.query(sql3);
        InfluxDBResultMapper resultMapper3= new InfluxDBResultMapper();
        List<DataPlt> list3 = resultMapper3.toPOJO(sqlResult3, DataPlt.class);
        list3.forEach(item->{
            item.setValueType("AVG");
        });
        //CP95值
        String sql4 = "select percentile(plt,95) AS plt from data_plt where "+stringBuilder+" time >= '" + startTime + "' and time <= '" + endTime + "' group by line_id,phasic_type,quality_flag tz('Asia/Shanghai')";
        QueryResult sqlResult4 = influxDbUtils.query(sql4);
        InfluxDBResultMapper resultMapper4= new InfluxDBResultMapper();
        List<DataPlt> list4 = resultMapper4.toPOJO(sqlResult4, DataPlt.class);
        list4.forEach(item->{
            item.setValueType("CP95");
        });
        result.addAll(list1);
        result.addAll(list2);
        result.addAll(list3);
        result.addAll(list4);
        return result;
    }

    /**
     * 功能描述:插入day_plt表数据
     * @author xy
     * @param list data_plt集合
     * @param time 时间戳
     * @date 2022/5/12 8:55
     */
    private void insertDayPlt(List<DataPlt> list, long time){
        List<String> records = new ArrayList<>();
        list.forEach(item->{
            Map<String, String> tags = new HashMap<>();
            Map<String, Object> fields = new HashMap<>();
            tags.put("line_id",item.getLineId());
            tags.put("phasic_type",item.getPhaseType());
            tags.put("quality_flag",item.getQualityFlag());
            tags.put("value_type",item.getValueType());
            fields.put("plt",item.getPlt());
            Point point = influxDbUtils.pointBuilder("day_plt", time, TimeUnit.MILLISECONDS, tags, fields);
            BatchPoints batchPoints = BatchPoints.database(DATABASE).tag("line_id", item.getLineId()).tag("phasic_type",item.getPhaseType()).tag("quality_flag",item.getQualityFlag()).tag("value_type",item.getValueType()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
            batchPoints.point(point);
            records.add(batchPoints.lineProtocol());
        });
        influxDbUtils.batchInsert(DATABASE,"", InfluxDB.ConsistencyLevel.ALL, records);
    }

    public StringBuilder lineStringBuilder(List<String> list) {
        StringBuilder stringBuilder = new StringBuilder();
        if (!CollectionUtils.isEmpty(list)){
            stringBuilder.append("(");
            for (int i = 0; i < list.size(); i++) {
                if (list.size() - i != 1) {
                    stringBuilder.append("line_id ='").append(list.get(i)).append("' or ");
                } else {
                    stringBuilder.append("line_id ='").append(list.get(i)).append("') and ");
                }
            }
        }
        return stringBuilder;
    }

}
