package com.njcn.harmonic.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pq.pojo.dto.OverLimitLineDTO;
import com.njcn.device.pq.pojo.dto.PollutionParamDTO;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.enums.HarmonicResponseEnum;
import com.njcn.harmonic.pojo.photoVO.WarningAreaVO;
import com.njcn.harmonic.pojo.photoVO.WarningMonitorVO;
import com.njcn.harmonic.pojo.po.EventDetail;
import com.njcn.harmonic.pojo.po.LimitRate;
import com.njcn.harmonic.pojo.po.LimitTarget;
import com.njcn.harmonic.pojo.vo.OverAreaVO;
import com.njcn.harmonic.service.PhotovoltaicService;
import com.njcn.influx.imapper.CommonMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/7/7 9:26
 */
@Slf4j
@Service
@AllArgsConstructor
public class PhotovoltaicServiceImpl implements PhotovoltaicService {

    private final GeneralDeviceInfoClient generalDeviceInfoClient;

    private final LineFeignClient lineFeignClient;

    private final CommonMapper commonMapper;

    @Override
    @SuppressWarnings("unchecked")
    public Page<WarningAreaVO> areaWarningManage(OverAreaVO param) {
        List<String> line = new ArrayList<>();
        Map<String, List<LimitRate>> map = new HashMap<>();
        Map<String, List<EventDetail>> map2 = new HashMap<>();
        Page<WarningAreaVO> page = new Page<>();
        List<WarningAreaVO> list = new ArrayList<>();
        page.setSize(param.getPageSize());
        page.setCurrent(param.getPageNum());
        List<GeneralDeviceDTO> subList = generalDeviceInfoClient.getPracticalRunDeviceInfo(param).getData();
        if (!CollectionUtils.isEmpty(subList)) {
            page.setTotal(subList.size());
            int pages = (int) Math.ceil(subList.size() * 1.0 / param.getPageSize());
            page.setPages(pages);
            List<List<GeneralDeviceDTO>> pageList = Lists.partition(subList, param.getPageSize());
            List<GeneralDeviceDTO> temList = pageList.get(param.getPageNum() - 1);
            temList.forEach(item -> {
                line.addAll(item.getLineIndexes());
            });
            if (!CollectionUtils.isEmpty(line)) {
                List<LimitRate> limitRateList = (List<LimitRate>) getAllData(line, param.getSearchBeginTime(), param.getSearchEndTime(), Param.LIMIT_RATE);
                if (!CollectionUtils.isEmpty(limitRateList)) {
                    map = limitRateList.stream().collect(Collectors.groupingBy(LimitRate::getLineId));
                }
                List<EventDetail> eventDetailList = getEventDetail(line, param.getSearchBeginTime(), param.getSearchEndTime());
                if (!CollectionUtils.isEmpty(eventDetailList)) {
                    map2 = eventDetailList.stream().collect(Collectors.groupingBy(EventDetail::getLineId));
                }
            }
            if (!CollectionUtils.isEmpty(temList)) {
                for (GeneralDeviceDTO item : temList) {
                    int onlineMonitorCount = 0, alertMonitorCount = 0, alertCount = 0, freqCount = 0, voltageCount = 0, ubalanceCount = 0, flickerCount = 0, iNegCount = 0, uharmCount = 0, iharmCount = 0, inuharmCount = 0;
                    int freqCounts = 0, voltageCounts = 0, uharmCounts = 0, iharmCounts = 0, ubalanceCounts = 0, flickerCounts = 0, inuharmCounts = 0, iNegCounts = 0;
                    int eventUp = 0, eventDown = 0, eventInterrupt = 0, eventUps = 0, eventDowns = 0, eventInterrupts = 0;
                    WarningAreaVO warningAreaVO = new WarningAreaVO();
                    //单位id
                    warningAreaVO.setId(item.getIndex());
                    //单位名称
                    warningAreaVO.setName(item.getName());
                    if (!CollectionUtils.isEmpty(item.getLineIndexes())) {
                        for (String item2 : item.getLineIndexes()) {
                            //谐波统计
                            if (!CollectionUtils.isEmpty(map.get(item2))) {
                                LimitRate limitRate = map.get(item2).get(0);
                                if (!Objects.isNull(limitRate)) {
                                    onlineMonitorCount++;
                                    if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0) {
                                        alertMonitorCount++;
                                    }
                                    if (limitRate.getFreqDevOverTime() > 0) {
                                        freqCount++;
                                        freqCounts = freqCounts + limitRate.getFreqDevOverTime();
                                    }
                                    if (limitRate.getVoltageDevOverTime() > 0) {
                                        voltageCount++;
                                        voltageCounts = voltageCounts + limitRate.getVoltageDevOverTime();
                                    }
                                    if (limitRate.getUHarm2OverTime() > 0) {
                                        uharmCount++;
                                        uharmCounts = uharmCounts + limitRate.getUHarm2OverTime();
                                    }
                                    if (limitRate.getIHarm2OverTime() > 0) {
                                        iharmCount++;
                                        iharmCounts = iharmCounts + limitRate.getIHarm2OverTime();
                                    }
                                    if (limitRate.getUBalanceOverTime() > 0) {
                                        ubalanceCount++;
                                        ubalanceCounts = ubalanceCounts + limitRate.getUBalanceOverTime();
                                    }
                                    if (limitRate.getFlickerOverTime() > 0) {
                                        flickerCount++;
                                        flickerCounts = flickerCounts + limitRate.getFlickerOverTime();
                                    }
                                    if (limitRate.getInuHarm1OverTime() > 0) {
                                        inuharmCount++;
                                        inuharmCounts = inuharmCounts + limitRate.getInuHarm1OverTime();
                                    }
                                    if (limitRate.getINegOverTime() > 0) {
                                        iNegCount++;
                                        iNegCounts = iNegCounts + limitRate.getINegOverTime();
                                    }
                                    alertCount = limitRate.getFreqDevOverTime() + limitRate.getVoltageDevOverTime() + limitRate.getUBalanceOverTime() + limitRate.getFlickerOverTime() + limitRate.getINegOverTime() + limitRate.getUHarm2OverTime() + limitRate.getIHarm2OverTime() + limitRate.getInuHarm1OverTime();
                                } else {
                                    log.info("此监测点在限值表中无数据:" + item2);
                                    throw new BusinessException(HarmonicResponseEnum.LIMIT_MISSING_ERROR);
                                }
                            }
                            //暂降统计
                            if (!CollectionUtils.isEmpty(map2.get(item2))) {
                                List<EventDetail> eventDetailList = map2.get(item2);
                                if (!CollectionUtils.isEmpty(eventDetailList)) {
                                    for (EventDetail item3 : eventDetailList) {
                                        if (item3.getWaveType() == 1) {
                                            eventDowns++;
                                        } else if (item3.getWaveType() == 2) {
                                            eventUps++;
                                        } else if (item3.getWaveType() == 3) {
                                            eventInterrupts++;
                                        }
                                    }
                                }
                            }
                            if (eventDowns > 0) {
                                eventDown++;
                            }
                            if (eventUps > 0) {
                                eventUp++;
                            }
                            if (eventInterrupts > 0) {
                                eventInterrupt++;
                            }
                        }
                    }
                    //在线监测点数量(个)
                    warningAreaVO.setOnlineMonitorCounts(onlineMonitorCount);
                    if (onlineMonitorCount != 0) {
                        //告警监测点数量(个)
                        warningAreaVO.setAlertMonitorCounts(alertMonitorCount);
                        //告警次数
                        warningAreaVO.setAlertCounts(alertCount);
                        //告警频次(次/点)
                        warningAreaVO.setAlertAlarmFrequency(alertMonitorCount == 0 ? 0 : BigDecimal.valueOf(alertCount * 1.0 / alertMonitorCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //频率偏差
                        warningAreaVO.setFrequencyDeviation(freqCount == 0 ? 0 : BigDecimal.valueOf(freqCounts * 1.0 / freqCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //电压偏差
                        warningAreaVO.setVoltageDeviation(voltageCount == 0 ? 0 : BigDecimal.valueOf(voltageCounts * 1.0 / voltageCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //谐波电压
                        warningAreaVO.setHarmonicVoltage(uharmCount == 0 ? 0 : BigDecimal.valueOf(uharmCounts * 1.0 / uharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //谐波电流
                        warningAreaVO.setHarmonicCurrent(iharmCount == 0 ? 0 : BigDecimal.valueOf(iharmCounts * 1.0 / iharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //三相电压不平衡
                        warningAreaVO.setThreePhaseVoltageUnbalance(ubalanceCount == 0 ? 0 : BigDecimal.valueOf(ubalanceCounts * 1.0 / ubalanceCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //闪变
                        warningAreaVO.setFlicker(flickerCount == 0 ? 0 : BigDecimal.valueOf(flickerCounts * 1.0 / flickerCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //间谐波电压
                        warningAreaVO.setInterHarmonic(inuharmCount == 0 ? 0 : BigDecimal.valueOf(inuharmCounts * 1.0 / inuharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //负序电流
                        warningAreaVO.setNegative(iNegCount == 0 ? 0 : BigDecimal.valueOf(iNegCounts * 1.0 / iNegCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //电压暂降
                        warningAreaVO.setVoltageDip(eventDown == 0 ? 0 : BigDecimal.valueOf(eventDowns * 1.0 / eventDown).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //电压暂升
                        warningAreaVO.setVoltageSwell(eventUp == 0 ? 0 : BigDecimal.valueOf(eventUps * 1.0 / eventUp).setScale(2, RoundingMode.HALF_UP).doubleValue());
                        //短时中断
                        warningAreaVO.setShortInterruption(eventInterrupt == 0 ? 0 : BigDecimal.valueOf(eventInterrupts * 1.0 / eventInterrupt).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    }
                    list.add(warningAreaVO);
                }
            }
        }
        if (!CollectionUtils.isEmpty(list)) {
            List<WarningAreaVO> recordList = new ArrayList<>();
            //默认 在线监测点数量 倒叙排序
            recordList = list.stream().sorted(Comparator.comparing(WarningAreaVO::getOnlineMonitorCounts).reversed().thenComparing(WarningAreaVO::getName)).collect(Collectors.toList());
            page.setRecords(recordList);
            return page;
        }
        return page;
    }

    @Override
    @SuppressWarnings("unchecked")
    public Page<WarningMonitorVO> monitorWarningManage(OverAreaVO param) {
        List<String> line = new ArrayList<>(), temList = new ArrayList<>();
        Map<String, List<LimitRate>> map = new HashMap<>();
        Map<String, List<EventDetail>> map2 = new HashMap<>();
        Page<WarningMonitorVO> page = new Page<>();
        List<WarningMonitorVO> list = new ArrayList<>();
        page.setSize(param.getPageSize());
        page.setCurrent(param.getPageNum());
        List<GeneralDeviceDTO> areaList = generalDeviceInfoClient.getPracticalRunDeviceInfo(param).getData();
        if (!CollectionUtils.isEmpty(areaList)) {
            areaList.forEach(item -> {
                line.addAll(item.getLineIndexes());
            });
            if (!CollectionUtils.isEmpty(line)) {
                page.setTotal(line.size());
                int pages = (int) Math.ceil(line.size() * 1.0 / param.getPageSize());
                page.setPages(pages);
                List<List<String>> pageList = Lists.partition(line, param.getPageSize());
                temList = pageList.get(param.getPageNum() - 1);
            }
            if (!CollectionUtils.isEmpty(temList)) {
                List<LimitRate> limitRateList = (List<LimitRate>) getAllData(temList, param.getSearchBeginTime(), param.getSearchEndTime(), Param.LIMIT_RATE);
                if (!CollectionUtils.isEmpty(limitRateList)) {
                    map = limitRateList.stream().collect(Collectors.groupingBy(LimitRate::getLineId));
                }
                List<EventDetail> eventDetailList = getEventDetail(temList, param.getSearchBeginTime(), param.getSearchEndTime());
                if (!CollectionUtils.isEmpty(eventDetailList)) {
                    map2 = eventDetailList.stream().collect(Collectors.groupingBy(EventDetail::getLineId));
                }
                PollutionParamDTO pollutionParamDTO = new PollutionParamDTO();
                pollutionParamDTO.setLineList(temList);
                List<OverLimitLineDTO> overLimitLineList = lineFeignClient.getOverLimitLineInfo(pollutionParamDTO).getData();
                for (OverLimitLineDTO pojo : overLimitLineList) {
                    String item = pojo.getId();
                    String name = pojo.getLineName();
                    int alertMonitorCount = 0, alertCount = 0, freqCount = 0, voltageCount = 0, ubalanceCount = 0, flickerCount = 0, iNegCount = 0, uharmCount = 0, iharmCount = 0, inuharmCount = 0;
                    int freqCounts = 0, voltageCounts = 0, uharmCounts = 0, iharmCounts = 0, ubalanceCounts = 0, flickerCounts = 0, inuharmCounts = 0, iNegCounts = 0;
                    int eventUp = 0, eventDown = 0, eventInterrupt = 0, eventUps = 0, eventDowns = 0, eventInterrupts = 0;
                    WarningMonitorVO warningMonitorVO = new WarningMonitorVO();
                    //监测点id
                    warningMonitorVO.setId(item);
                    //监测点名称
                    warningMonitorVO.setName(name);
                    //谐波统计
                    if (!CollectionUtils.isEmpty(map.get(item))) {
                        LimitRate limitRate = map.get(item).get(0);
                        if (!Objects.isNull(limitRate)) {
                            if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0) {
                                alertMonitorCount++;
                            }
                            if (limitRate.getFreqDevOverTime() > 0) {
                                freqCount++;
                                freqCounts = freqCounts + limitRate.getFreqDevOverTime();
                            }
                            if (limitRate.getVoltageDevOverTime() > 0) {
                                voltageCount++;
                                voltageCounts = voltageCounts + limitRate.getVoltageDevOverTime();
                            }
                            if (limitRate.getUHarm2OverTime() > 0) {
                                uharmCount++;
                                uharmCounts = uharmCounts + limitRate.getUHarm2OverTime();
                            }
                            if (limitRate.getIHarm2OverTime() > 0) {
                                iharmCount++;
                                iharmCounts = iharmCounts + limitRate.getIHarm2OverTime();
                            }
                            if (limitRate.getUBalanceOverTime() > 0) {
                                ubalanceCount++;
                                ubalanceCounts = ubalanceCounts + limitRate.getUBalanceOverTime();
                            }
                            if (limitRate.getFlickerOverTime() > 0) {
                                flickerCount++;
                                flickerCounts = flickerCounts + limitRate.getFlickerOverTime();
                            }
                            if (limitRate.getInuHarm1OverTime() > 0) {
                                inuharmCount++;
                                inuharmCounts = inuharmCounts + limitRate.getInuHarm1OverTime();
                            }
                            if (limitRate.getINegOverTime() > 0) {
                                iNegCount++;
                                iNegCounts = iNegCounts + limitRate.getINegOverTime();
                            }
                            alertCount = limitRate.getFreqDevOverTime() + limitRate.getVoltageDevOverTime() + limitRate.getUBalanceOverTime() + limitRate.getFlickerOverTime() + limitRate.getINegOverTime() + limitRate.getUHarm2OverTime() + limitRate.getIHarm2OverTime() + limitRate.getInuHarm1OverTime();
                        } else {
                            log.info("此监测点在限值表中无数据:" + item);
                            throw new BusinessException(HarmonicResponseEnum.LIMIT_MISSING_ERROR);
                        }
                    }
                    //暂降统计
                    if (!CollectionUtils.isEmpty(map2.get(item))) {
                        List<EventDetail> eventDetailList2 = map2.get(item);
                        if (!CollectionUtils.isEmpty(eventDetailList2)) {
                            for (EventDetail item3 : eventDetailList2) {
                                if (item3.getWaveType() == 1) {
                                    eventDowns++;
                                } else if (item3.getWaveType() == 2) {
                                    eventUps++;
                                } else if (item3.getWaveType() == 3) {
                                    eventInterrupts++;
                                }
                            }
                        }
                    }
                    if (eventDowns > 0) {
                        eventDown++;
                    }
                    if (eventUps > 0) {
                        eventUp++;
                    }
                    if (eventInterrupts > 0) {
                        eventInterrupt++;
                    }
                    //告警次数
                    warningMonitorVO.setAlertCounts(alertCount);
                    //告警频次(次/点)
                    warningMonitorVO.setAlertAlarmFrequency(alertMonitorCount == 0 ? 0 : BigDecimal.valueOf(alertCount * 1.0 / alertMonitorCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //频率偏差
                    warningMonitorVO.setFrequencyDeviation(freqCount == 0 ? 0 : BigDecimal.valueOf(freqCounts * 1.0 / freqCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //电压偏差
                    warningMonitorVO.setVoltageDeviation(voltageCount == 0 ? 0 : BigDecimal.valueOf(voltageCounts * 1.0 / voltageCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //谐波电压
                    warningMonitorVO.setHarmonicVoltage(uharmCount == 0 ? 0 : BigDecimal.valueOf(uharmCounts * 1.0 / uharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //谐波电流
                    warningMonitorVO.setHarmonicCurrent(iharmCount == 0 ? 0 : BigDecimal.valueOf(iharmCounts * 1.0 / iharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //三相电压不平衡
                    warningMonitorVO.setThreePhaseVoltageUnbalance(ubalanceCount == 0 ? 0 : BigDecimal.valueOf(ubalanceCounts * 1.0 / ubalanceCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //闪变
                    warningMonitorVO.setFlicker(flickerCount == 0 ? 0 : BigDecimal.valueOf(flickerCounts * 1.0 / flickerCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //间谐波电压
                    warningMonitorVO.setInterHarmonic(inuharmCount == 0 ? 0 : BigDecimal.valueOf(inuharmCounts * 1.0 / inuharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //负序电流
                    warningMonitorVO.setNegative(iNegCount == 0 ? 0 : BigDecimal.valueOf(iNegCounts * 1.0 / iNegCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //电压暂降
                    warningMonitorVO.setVoltageDip(eventDown == 0 ? 0 : BigDecimal.valueOf(eventDowns * 1.0 / eventDown).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //电压暂升
                    warningMonitorVO.setVoltageSwell(eventUp == 0 ? 0 : BigDecimal.valueOf(eventUps * 1.0 / eventUp).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    //短时中断
                    warningMonitorVO.setShortInterruption(eventInterrupt == 0 ? 0 : BigDecimal.valueOf(eventInterrupts * 1.0 / eventInterrupt).setScale(2, RoundingMode.HALF_UP).doubleValue());
                    list.add(warningMonitorVO);
                }
            }
            if (!CollectionUtils.isEmpty(list)) {
                List<WarningMonitorVO> recordList = new ArrayList<>();
                //默认 监测点告警次数 倒叙排序
                recordList = list.stream().sorted(Comparator.comparing(WarningMonitorVO::getAlertCounts).reversed()).collect(Collectors.toList());
                page.setRecords(recordList);
                return page;
            }
        }
        return page;
    }


    /**
     * 功能描述: 处理区域在线监测点数、超标监测点数
     *
     * @param list 集合
     * @return
     * @author xy
     * @date 2022/2/25 15:05
     */
    private List<?> getAllData(List<String> list, String startTime, String endTime, String databaseName) {
        List<?> result = new ArrayList<>();
        StringBuilder stringBuilder = new StringBuilder();
        StringBuilder stringBuilder1 = new StringBuilder();
        stringBuilder.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and (");
        for (int i = 0; i < list.size(); i++) {
            if (list.size() - i != 1) {
                stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("' or ");
            } else {
                stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("')");
            }
        }
        stringBuilder.append(" group by line_id tz('Asia/Shanghai')");
        stringBuilder1.append("sum(freq_dev_overtime) AS freq_dev_overtime,sum(voltage_dev_overtime) AS voltage_dev_overtime,sum(ubalance_overtime) AS ubalance_overtime,sum(flicker_overtime) AS flicker_overtime,sum(i_neg_overtime) AS i_neg_overtime,");
        stringBuilder1.append("sum(uaberrance_overtime)+");
        for (int i = 2; i <= 25; i++) {
            if (i == 25) {
                stringBuilder1.append("sum(uharm_").append(i).append("_overtime) AS ").append("uharm_2").append("_overtime,");
            } else {
                stringBuilder1.append("sum(uharm_").append(i).append("_overtime)+");
            }
        }
        for (int i = 2; i <= 25; i++) {
            if (i == 25) {
                stringBuilder1.append("sum(iharm_").append(i).append("_overtime) AS ").append("iharm_2").append("_overtime,");
            } else {
                stringBuilder1.append("sum(iharm_").append(i).append("_overtime)+");
            }
        }
        for (int i = 1; i <= 16; i++) {
            if (i == 16) {
                stringBuilder1.append("sum(inuharm_").append(i).append("_overtime) AS ").append("inuharm_1").append("_overtime");
            } else {
                stringBuilder1.append("sum(inuharm_").append(i).append("_overtime)+");
            }
        }
        String sql = "select " + stringBuilder1 + " from " + databaseName + " where " + stringBuilder;
        switch (databaseName) {
            case Param.LIMIT_TARGET:
                result = commonMapper.selectLimitTargetBySql(sql);
                break;
            case Param.LIMIT_RATE:
                result = commonMapper.selectLimitTargetBySql(sql);
                break;
            default:
                break;
        }
        return result;
    }

    public List<EventDetail> getEventDetail(List<String> list, String startTime, String endTime) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and (");
        for (int i = 0; i < list.size(); i++) {
            if (list.size() - i != 1) {
                stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("' or ");
            } else {
                stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("')");
            }
        }
        stringBuilder.append(" group by line_id tz('Asia/Shanghai')");
        String sql = "select * from pqs_eventdetail where " + stringBuilder;
//        QueryResult sqlResult = influxDbUtils.query(sql);
        InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
        return null;
    }

}
