package com.njcn.serviceimpl.configuration;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.njcn.enums.TerminalLogsEnum;
import com.njcn.mapper.configuration.*;
import com.njcn.mapper.data.*;
import com.njcn.mapper.user.DeptsGdMapper;
import com.njcn.mapper.user.DeptsMapper;
import com.njcn.mapper.user.TransFormerMapper;
import com.njcn.mapper.user.UserMapper;
import com.njcn.pojo.commons.*;
import com.njcn.pojo.commons.area.*;
import com.njcn.pojo.commons.device.*;
import com.njcn.pojo.commons.runmanage.IntegrityAnalysisData;
import com.njcn.pojo.commons.runmanage.IntergralityData;
import com.njcn.pojo.commons.runmanage.IntergralityTable;
import com.njcn.pojo.commons.runmanage.OnlineRateData;
import com.njcn.pojo.configuration.*;
import com.njcn.pojo.data.ComInformation;
import com.njcn.pojo.data.EventDetail;
import com.njcn.pojo.data.Maps;
import com.njcn.pojo.user.Depts;
import com.njcn.pojo.user.DeptsGd;
import com.njcn.pojo.user.Role;
import com.njcn.pojo.user.TransFormer;
import com.njcn.service.configuration.DeviceService;
import com.njcn.shiro.token.TokenManager;
import com.njcn.sso.pojo.user.User;
import com.njcn.utils.*;
import com.njcn.utils.redis.JedisManager;
import com.njcn.utils.redis.RedisCacheUtil;
import net.sf.json.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * @author hongawen
 * @date 2018/4/4 14:44
 */
@Service
public class DeviceServiceImpl implements DeviceService {

    private final static Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class);

    @Autowired
    private AppConfig appConfig;

    @Resource
    private TreeMapper treeMapper;

    @Autowired
    private UserUtil userUtil;

    @Autowired
    GDInforMapper gdMapper;

    @Autowired
    private RedisCacheUtil redisCacheUtil;

    @Resource
    private DeviceInfoMapper deviceInfoMapper;

    @Autowired
    private LineMapper lineMapper;

    @Autowired
    private LineDetailMapper lineDetailMapper;

    @Autowired
    private LimitRateMapper limitRateMapper;

    @Autowired
    private HistoryDataMapper historyDataMapper;

    @Resource
    private GDInforMapper gdInforMapper;

    @Resource
    private DeptsGdMapper deptsGdMapper;

    @Resource
    private SubStationMapper subStationMapper;

    @Resource
    private SubVoltageMapper subVoltageMapper;

    @Resource
    private MapMapper mapMapper;

    @Autowired
    private EventDetailMapper eventDetailMapper;

    @Resource
    private DeviceMapper deviceMapper;

    @Resource
    private DeviceDetailMapper deviceDetailMapper;

    @Resource
    private DeviceDetailInfoMapper deviceDetailInfoMapper;

    @Autowired
    private ComInformationMapper comInformationMapper;

    @Resource
    private DicDataMapper dicDataMapper;

    @Resource
    private DicDataTypeMapper dicDataTypeMapper;

    @Resource
    private NodeInformationMapper nodeInformationMapper;

    @Resource
    private TransFormerMapper transFormerMapper;

    @Resource
    private UserMapper userMapper;


    @Autowired
    private OverLimitMapper overLimitMapper;

    @Autowired
    private OnlineRateMapper onlineRateMapper;

    @Autowired
    private IntegrityMapper integrityMapper;

    @Autowired
    private JedisManager jedisManager;

    @Resource
    private EventDataMapper eventdataMapper;

    @Resource
    private TerminalLogsMapper terminalLogsMapper;

    @Resource
    private EventPushLogsDetailMapper eventPushLogsDetailMapper;

    /**
     * 概览--》终端运行状态
     */
    @Override
    public DeviceGeneral getDeviceData(String overview, Date startTime, Date endTime) {
        DeviceGeneral deviceGeneral;
        List<AreaGeneralData> areaGeneralDatas = userUtil.getAreaGeneral();
        if (CollectionUtils.isEmpty(areaGeneralDatas)) {
            return null;
        }
        deviceGeneral = getDeviceData(overview, areaGeneralDatas, startTime, endTime);
        deviceGeneral.setCityName(userUtil.getCurrentDept().getArea());
        return deviceGeneral;
    }

    /**
     * 区域统计--》终端运行状态
     *
     * @param overview 概览标识
     * @param area     区域
     */
    @Override
    public DeviceGeneral getDeviceData(String overview, String area, Date startTime, Date endTime) {
        DeviceGeneral deviceGeneral;
        List<AreaGeneralData> areaGeneralDatasTemp;
        if ("overview".equalsIgnoreCase(area)) {
            areaGeneralDatasTemp = userUtil.getAreaGeneral();
        } else {
            areaGeneralDatasTemp = userUtil.getAreaDataByInfo(area);
        }
        if (CollectionUtils.isEmpty(areaGeneralDatasTemp)) {
            return null;
        }
        deviceGeneral = getDeviceData(overview, areaGeneralDatasTemp, startTime, endTime);
        deviceGeneral.setCityName(userUtil.getCurrentDept().getArea());
        return deviceGeneral;
    }

    /**
     * 区域统计--》终端运行状态(筛)
     *
     * @param overview 概览标识
     * @param area     区域
     */
    @Override
    public DeviceGeneral getDeviceSiftData(String overview, String area, String scale, String manc, String loadtype, Integer monitorNature,
                                           Date startTime, Date endTime) {
        String devLocation = null;
        DeviceGeneral deviceGeneral;
        List<AreaGeneralData> areaGeneralDatasTemp;
        if ("overview".equalsIgnoreCase(area)) {
            areaGeneralDatasTemp = userUtil.getAreaGeneral();
        } else {
            areaGeneralDatasTemp = userUtil.getAreaDataByInfo(area);
        }
        if (!Objects.isNull(monitorNature) && monitorNature == 0) {
            devLocation = "电网侧";
        } else if (!Objects.isNull(monitorNature) && monitorNature == 1) {
            devLocation = "用户侧";
        }
        areaGeneralDatasTemp = userUtil.siftAreaGeneralData(areaGeneralDatasTemp, scale, manc, loadtype, devLocation);
        if (CollectionUtils.isEmpty(areaGeneralDatasTemp)) {
            return null;
        }
        deviceGeneral = getDeviceData(overview, areaGeneralDatasTemp, startTime, endTime);
        deviceGeneral.setCityName(userUtil.getCurrentDept().getArea());
        return deviceGeneral;
    }

    //抽取概览和区域统计中终端状态的共同代码
    private DeviceGeneral getDeviceData(String overview, List<AreaGeneralData> areaGeneralDatas, Date startTime, Date endTime) {
        DeviceGeneral deviceGeneral = new DeviceGeneral();
        List<DeviceValue> area = new ArrayList<>();
        List<Integer> deviceIndexs = new ArrayList<>();

        // 按区域
        for (AreaGeneralData areaData : areaGeneralDatas) {
            DeviceValue de = getDeviceValueArea(areaData, startTime, endTime);
            area.add(de);
            deviceIndexs.addAll(areaData.getDeviceIndexs());
        }
        Collections.sort(area);
        deviceGeneral.setArea(area);
        if (StringUtils.isEmpty(overview)) {
            //按终端厂家
            deviceGeneral.setInterval(getManufacturerData(deviceIndexs, startTime, endTime));

            //按电压等级
            deviceGeneral.setVol(getScaleData(deviceIndexs, startTime, endTime));

            //按干扰源类型终
            deviceGeneral.setLoadtype(getLoadTypeData(deviceIndexs, startTime, endTime));
        }
        return deviceGeneral;
    }

    /**
     * 概览--》终端在线率
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     */
    @Override
    public DeviceGeneral getDeviceOnlineRate(Date startTime, Date endTime, String overview) {
        DeviceGeneral deviceGeneral;
        List<AreaGeneralData> areaGeneralDatas = userUtil.getAreaGeneral();
        if (CollectionUtils.isEmpty(areaGeneralDatas)) {
            return null;
        }
        deviceGeneral = getDeviceOnlineRate(startTime, endTime, overview, areaGeneralDatas);
        return deviceGeneral;
    }

    /**
     * 区域统计--》在线率
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param area      区域
     */
    @Override
    public DeviceGeneral getDeviceOnlineRate(Date startTime, Date endTime, String overview, String area) {
        DeviceGeneral deviceGeneral;
        List<AreaGeneralData> areaGeneralDatasTemp = userUtil.getAreaDataByInfoRun(area);
        if (CollectionUtils.isEmpty(areaGeneralDatasTemp)) {
            return null;
        }
        deviceGeneral = getDeviceOnlineRate(startTime, endTime, overview, areaGeneralDatasTemp);
        return deviceGeneral;
    }

    /**
     * 运行管理--》终端在线率
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param area      查询的区域
     */
    @Override
    public List<OnlineRateData> getOnlineRate(Date startTime, Date endTime, String area) {
        List<Integer> deviceIndexs = new ArrayList<>();
        List<AreaGeneralData> areaGeneralDatasTemp = userUtil.getAreaDataByInfoRun(area);
        if (CollectionUtils.isEmpty(areaGeneralDatasTemp)) {
            return null;
        }
        for (int i = 0; i < areaGeneralDatasTemp.size(); i++) {
            deviceIndexs.addAll(areaGeneralDatasTemp.get(i).getDeviceIndexs());
        }
        if (CollectionUtils.isEmpty(deviceIndexs)) {
            return null;
        }
        return getOnlineRateData(deviceIndexs, startTime, endTime);
    }

    /**
     * 运行管理--》监测点数据完整性
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param area      区域
     */
    @Override
    public IntergralityData getDataIntegralityTable(Date startTime, Date endTime, String area,Integer devflag,Integer powerId,Integer runFlag) {
        IntergralityData intergralityData = new IntergralityData();

        List<AreaGeneralData> areaGeneralDataList = userUtil.getAreaGeneralRun(devflag,area,powerId);
        List<Integer> lineIndexs = areaGeneralDataList.stream().flatMap(item->item.getLineIndexs().stream()).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(lineIndexs)) {
            return null;
        }
        //全网监测点的数据完整性
        List<IntergralityTable> list1 = getIntegralityTable(startTime, endTime, lineIndexs);
        if (CollUtil.isNotEmpty(list1)){
            List<IntergralityTable> offline = list1.stream().filter(item->Objects.equals(Integer.parseInt(item.getStatus()),0)).collect(Collectors.toList());
            List<IntergralityTable> online = list1.stream().filter(item->Objects.equals(Integer.parseInt(item.getStatus()),1)).collect(Collectors.toList());
            intergralityData.setAllOfflineNum(CollUtil.isNotEmpty(offline)?offline.size():0);
            intergralityData.setAllOnlineNum(CollUtil.isNotEmpty(online)?online.size():0);
            if (!Objects.isNull(runFlag)){
                list1 = Objects.equals(runFlag,0) ? offline : online;
            }
        }
        intergralityData.setAllNets(list1);
        //国网监测点
        List<Integer> countryLineIndexs = getAllGwLine(lineIndexs);
        if (!CollectionUtils.isEmpty(countryLineIndexs)) {
            List<IntergralityTable> list2 = getGWIntegralityTable(startTime, endTime, countryLineIndexs);
            if (CollUtil.isNotEmpty(list2)){
                List<IntergralityTable> offline = list2.stream().filter(item->Objects.equals(Integer.parseInt(item.getStatus()),0)).collect(Collectors.toList());
                List<IntergralityTable> online = list2.stream().filter(item->Objects.equals(Integer.parseInt(item.getStatus()),1)).collect(Collectors.toList());
                intergralityData.setCountryOfflineNum(CollUtil.isNotEmpty(offline)?offline.size():0);
                intergralityData.setCountryOnlineNum(CollUtil.isNotEmpty(online)?online.size():0);
                if (!Objects.isNull(runFlag)){
                    list2 = Objects.equals(runFlag,0) ? offline : online;
                }
            }
            intergralityData.setCountryNets(list2);
        }
        return intergralityData;
    }

    /**
     * 分片处理获取监测点数据完整性所有数据
     *
     * @param startTime  起始时间
     * @param endTime    截止时间
     * @param lineIndexs 监测点索引
     */
    private List<IntergralityTable> getIntegralityTable(Date startTime, Date endTime, List<Integer> lineIndexs) {
        List<IntergralityTable> intergralityTables = new ArrayList<>();
        //分片1000个监测点
        if (lineIndexs.size() > 1000) {
            int times = lineIndexs.size() / 1000 + 1;
            for (int i = 1; i <= times; i++) {
                if (lineIndexs.size() > 1000) {
                    List<Integer> tempIndexs = lineIndexs.subList(0, 1000);
                    List<IntergralityTable> tempTables = integrityMapper.selectIntegrityData(tempIndexs, startTime, endTime);
                    intergralityTables.addAll(tempTables);
                    tempIndexs.clear();
                } else {
                    List<IntergralityTable> tempTables = integrityMapper.selectIntegrityData(lineIndexs, startTime, endTime);
                    intergralityTables.addAll(tempTables);
                }
            }
        } else {
            intergralityTables = integrityMapper.selectIntegrityData(lineIndexs, startTime, endTime);
        }
        return intergralityTables;
    }

    /**
     * 分片处理获取监测点数据完整性所有数据
     *
     * @param startTime  起始时间
     * @param endTime    截止时间
     * @param lineIndexs 监测点索引
     */
    private List<IntergralityTable> getGWIntegralityTable(Date startTime, Date endTime, List<Integer> lineIndexs) {
        List<IntergralityTable> intergralityTables = new ArrayList<>();
        //分片1000个监测点
        if (lineIndexs.size() > 1000) {
            int times = lineIndexs.size() / 1000 + 1;
            for (int i = 1; i <= times; i++) {
                if (lineIndexs.size() > 1000) {
                    List<Integer> tempIndexs = lineIndexs.subList(0, 1000);
                    List<IntergralityTable> tempTables = integrityMapper.selectGWIntegrityData(tempIndexs, startTime, endTime);
                    intergralityTables.addAll(tempTables);
                    tempIndexs.clear();
                } else {
                    List<IntergralityTable> tempTables = integrityMapper.selectGWIntegrityData(lineIndexs, startTime, endTime);
                    intergralityTables.addAll(tempTables);
                }
            }
        } else {
            intergralityTables = integrityMapper.selectGWIntegrityData(lineIndexs, startTime, endTime);
        }
        return intergralityTables;
    }

    /**
     * 根据装置索引，查询出需要展示的数据
     */
    private List<OnlineRateData> getOnlineRateData(List<Integer> deviceIndexs, Date startTime, Date endTime) {
        List<OnlineRateData> onlineRateDatas = new ArrayList<>();
        //分片1000个终端
        if (deviceIndexs.size() > 1000) {
            int times = deviceIndexs.size() / 1000 + 1;
            for (int i = 1; i <= times; i++) {
                if (deviceIndexs.size() > 1000) {
                    List<Integer> tempIndexs = deviceIndexs.subList(0, 1000);
                    List<OnlineRateData> tempDatas = onlineRateMapper.selectOnlineRate(tempIndexs, startTime, endTime);
                    onlineRateDatas.addAll(tempDatas);
                    tempIndexs.clear();
                } else {
                    List<OnlineRateData> tempDatas = onlineRateMapper.selectOnlineRate(deviceIndexs, startTime, endTime);
                    onlineRateDatas.addAll(tempDatas);
                }
            }
        } else {
            onlineRateDatas = onlineRateMapper.selectOnlineRate(deviceIndexs, startTime, endTime);
        }
        return onlineRateDatas;
    }


    //抽取概览与区域统计的在线率共同代码
    private DeviceGeneral getDeviceOnlineRate(Date startTime, Date endTime, String overview, List<AreaGeneralData> areaGeneralDatas) {
        DeviceGeneral deviceGeneral = new DeviceGeneral();
        List<DeviceValue> area = new ArrayList<>();
        List<Integer> deviceIndexs = new ArrayList<>();
        // 按区域
        for (AreaGeneralData areaData : areaGeneralDatas) {
            List<Integer> tempDeviceIndex = new ArrayList<>();
            //提取终端状态为投运的装置索引
            DeviceValue deviceValue = new DeviceValue();
            // 区域名
            deviceValue.setName(areaData.getName());
            if (CollectionUtils.isEmpty(areaData.getDeviceIndexs())) {
                deviceValue.setAmounts("0");
                deviceValue.setGwamounts("0");
                deviceValue.setOnline("3.1415");
                deviceValue.setGwonline("3.1415");
            } else {
                tempDeviceIndex = deviceMapper.getRunDeviceIndex(areaData.getDeviceIndexs());
                // 终端点数
                deviceValue.setAmounts(String.valueOf(tempDeviceIndex.size()));
                // 在线率
                deviceValue.setOnline(getOnline(tempDeviceIndex, startTime, endTime));
                //获取含有国网监测点的装置
                getGwData(deviceValue, getGwLine(areaData.getLineIndexs()), startTime, endTime);
            }
            deviceIndexs.addAll(tempDeviceIndex);
            deviceValue.setDeptsIndex(areaData.getDeptIndex());
            area.add(deviceValue);
        }
        deviceGeneral.setArea(area);
        if (StringUtils.isEmpty(overview)) {
            //按终端厂家
            deviceGeneral.setInterval(getManufacturerDataOnlineRate(deviceIndexs, startTime, endTime));
        }
        return deviceGeneral;
    }

    /**
     * 概览--》终端在线率--》指定区域查询终端在线率
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param gist      城市名
     */
    @Override
    public List<SimpleValue> getCityOnlineRate(Date startTime, Date endTime, String gist) {
        List<AreaGeneralData> areaGenerals = userUtil.getAreaGeneral();
        List<Integer> deviceIndexs = new ArrayList<>();
        if (CollectionUtils.isEmpty(areaGenerals)) {
            return null;
        }
        for (AreaGeneralData areaGeneral : areaGenerals) {
            if (areaGeneral.getName().equalsIgnoreCase(gist)) {
                deviceIndexs.addAll(areaGeneral.getDeviceIndexs());
                break;
            }
        }
        //终端索引为空
        if (CollectionUtils.isEmpty(deviceIndexs)) {
            return null;
        }
        return getGistOnlineRate(deviceIndexs, startTime, endTime);
    }


    /**
     * 概览--》终端在线率--》指定电压等级查询终端在线率
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param gist      电压等级
     */
    @Override
    public List<SimpleValue> getVoltageOnlineRate(Date startTime, Date endTime, String gist) {
        List<AreaGeneralData> areaGenerals = userUtil.getAreaGeneral();
        List<Integer> deviceIndex = new ArrayList<>();
        if (CollectionUtils.isEmpty(areaGenerals)) {
            return null;
        } else {
            for (AreaGeneralData areaGeneralData : areaGenerals) {
                deviceIndex.addAll(areaGeneralData.getDeviceIndexs());
            }
        }
        List<VoltageData> voltageData = userUtil.getVoltageData(deviceIndex);
        List<Integer> deviceIndexs = new ArrayList<>();
        if (CollectionUtils.isEmpty(voltageData)) {
            return null;
        }
        for (VoltageData vol : voltageData) {
            if (vol.getVol().equalsIgnoreCase(gist)) {
                deviceIndexs.addAll(vol.getDeviceIndexs());
                break;
            }
        }
        if (CollectionUtils.isEmpty(deviceIndexs)) {
            return null;
        }
        return getGistOnlineRate(deviceIndexs, startTime, endTime);
    }

    /**
     * 概览--》终端在线率--》指定终端厂家查询终端在线率
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param gist      终端厂家
     */
    @Override
    public List<SimpleValue> getCompanyOnlineRate(Date startTime, Date endTime, String gist) {
        List<AreaGeneralData> areaGenerals = userUtil.getAreaGeneral();
        List<Integer> deviceIndex = new ArrayList<>();
        if (CollectionUtils.isEmpty(areaGenerals)) {
            return null;
        } else {
            for (AreaGeneralData areaGeneralData : areaGenerals) {
                deviceIndex.addAll(areaGeneralData.getDeviceIndexs());
            }
        }
        List<CompanyValue> companyValues = userUtil.getCompanyData(deviceIndex);
        List<Integer> deviceIndexs = new ArrayList<>();
        for (CompanyValue companyValue : companyValues) {
            if (companyValue.getCompanyName().equalsIgnoreCase(gist)) {
                deviceIndexs = companyValue.getDeviceIndexs();
                break;
            }
        }
        if (CollectionUtils.isEmpty(deviceIndexs)) {
            return null;
        }
        return getGistOnlineRate(deviceIndexs, startTime, endTime);
    }

    /**
     * 查询指定终端在线率
     *
     * @param deviceIndexs 终端索引
     * @param startTime    起始时间
     * @param endTime      截止时间
     */
    public List<SimpleValue> getGistOnlineRate(List<Integer> deviceIndexs, Date startTime, Date endTime) {
        List<SimpleValue> sims = new ArrayList<>();
        try {
            List<Integer> devIndexTemp = new ArrayList<>(deviceIndexs);
            int length = devIndexTemp.size();
            if (length > 1000) {
                //需要循环的次数
                int times = length / 1000 + 1;
                for (int i = 1; i <= times; i++) {
                    if (length > 1000) {
                        List<Integer> temp = devIndexTemp.subList(0, 1000);
                        List<SimpleValue> simTemp = onlineRateMapper.selectCityOnlineRate(temp, startTime, endTime);
                        if (!CollectionUtils.isEmpty(simTemp)) {
                            sims.addAll(simTemp);
                        }
                        temp.clear();
                        length = length - 1000;
                    } else {
                        List<SimpleValue> simTemp = onlineRateMapper.selectCityOnlineRate(devIndexTemp, startTime, endTime);
                        if (!CollectionUtils.isEmpty(simTemp)) {
                            sims.addAll(simTemp);
                        }
                    }
                }
            } else {
                sims = onlineRateMapper.selectCityOnlineRate(deviceIndexs, startTime, endTime);
            }
        } catch (Exception e) {
            logger.error("查询终端在线率发生异常，异常是" + e.getMessage());
        }
        return sims;
    }

    /**
     * 概览--》数据完整性
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     */
    @Override
    public DeviceGeneral getDataIntegrality(Date startTime, Date endTime, String overview) {
        List<AreaGeneralData> areaGeneralDatas = userUtil.getAreaGeneralRun();
        if (CollectionUtils.isEmpty(areaGeneralDatas)) {
            return null;
        }
        return getDataIntegrality(startTime, endTime, overview, areaGeneralDatas);
    }

    /**
     * 区域统计--》数据完整性
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param area      区域
     */
    @Override
    public DeviceGeneral getDataIntegrality(Date startTime, Date endTime, String overview, String area,
                                            String scale, String manc, String loadtype, Integer monitorNature) {
        DeviceGeneral deviceGeneral;
        List<AreaGeneralData> areaGeneralDatasTemp = userUtil.getAreaDataByInfoRun(area);
        if (CollectionUtils.isEmpty(areaGeneralDatasTemp)) {
            return null;
        }
        deviceGeneral = getDataIntegrality(startTime, endTime, overview, areaGeneralDatasTemp, scale, manc, loadtype, monitorNature);

        return deviceGeneral;
    }

    private DeviceGeneral getDataIntegrality(Date startTime, Date endTime, String overview, List<AreaGeneralData> areaGeneralDatas,
                                             String scale, String manc, String loadtype, Integer monitorNature) {
        DeviceGeneral deviceGeneral = new DeviceGeneral();
        List<DeviceValue> area = new ArrayList<>();
        List<Integer> deviceLindexs = new ArrayList<>();
        if (CollectionUtils.isEmpty(areaGeneralDatas)) {
            return null;
        }
        if (!Objects.isNull(monitorNature) && monitorNature == -1) {
            monitorNature = null;
        }
        //区域
        for (AreaGeneralData areaGeneralData : areaGeneralDatas) {
            if (CollectionUtils.isEmpty(areaGeneralData.getLineIndexs())) {
                continue;
            }
            area.add(getDataIntegralityArea(areaGeneralData, startTime, endTime, scale, manc, loadtype, monitorNature));
            deviceLindexs.addAll(areaGeneralData.getDeviceIndexs());
        }
        deviceGeneral.setArea(area);
        if (StringUtils.isEmpty(overview)) {
            //电压等级
            deviceGeneral.setVol(getDataIntegralityVol(deviceLindexs, startTime, endTime, scale, manc, loadtype, monitorNature));
            //终端厂家
            deviceGeneral.setInterval(getDataIntegralityCompany(deviceLindexs, startTime, endTime, scale, manc, loadtype, monitorNature));
            //干扰源类型终
            deviceGeneral.setLoadtype(getDataIntegralityLoadType(deviceLindexs, startTime, endTime, scale, manc, loadtype, monitorNature));
        }
        return deviceGeneral;
    }

    //抽取概览与区域统计的数据完整性的共同代码
    private DeviceGeneral getDataIntegrality(Date startTime, Date endTime, String overview, List<AreaGeneralData> areaGeneralDatas) {
        DeviceGeneral deviceGeneral = new DeviceGeneral();
        List<DeviceValue> area = new ArrayList<>();
        List<Integer> deviceLindexs = new ArrayList<>();
        if (CollectionUtils.isEmpty(areaGeneralDatas)) {
            return null;
        }
        //区域
        for (AreaGeneralData areaGeneralData : areaGeneralDatas) {
            area.add(getDataIntegralityArea(areaGeneralData, startTime, endTime));
            deviceLindexs.addAll(areaGeneralData.getDeviceIndexs());
        }
        deviceGeneral.setArea(area);
        if (StringUtils.isEmpty(overview)) {
            //电压等级
            deviceGeneral.setVol(getDataIntegralityVol(deviceLindexs, startTime, endTime));
            //终端厂家
            deviceGeneral.setInterval(getDataIntegralityCompany(deviceLindexs, startTime, endTime));
        }
        return deviceGeneral;
    }


    /**
     * 概览---》数据完整性---》区域点击查询
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param gist      城市名
     */
    @Override
    public List<SimpleValue> getCityIntegrality(Date startTime, Date endTime, String gist) {
        List<AreaGeneralData> areaGenerals = userUtil.getAreaGeneralRun();
        if (CollectionUtils.isEmpty(areaGenerals)) {
            return null;
        }
        List<Integer> lineIndexs = new ArrayList<>();
        for (AreaGeneralData areaGeneralData : areaGenerals) {
            if (areaGeneralData.getName().equalsIgnoreCase(gist)) {
                lineIndexs.addAll(areaGeneralData.getLineIndexs());
                break;
            }
        }
        if (CollectionUtils.isEmpty(lineIndexs)) {
            return null;
        }
        return getGistIntegralityRate(lineIndexs, startTime, endTime);
    }

    /**
     * 概览---》数据完整性---》电压等级点击查询
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param gist      电压等级
     */
    @Override
    public List<SimpleValue> getVoltageIntegrality(Date startTime, Date endTime, String gist) {
        List<AreaGeneralData> areaGenerals = userUtil.getAreaGeneralRun();
        List<Integer> deviceIndex = new ArrayList<>();
        if (CollectionUtils.isEmpty(areaGenerals)) {
            return null;
        } else {
            for (AreaGeneralData areaGeneralData : areaGenerals) {
                deviceIndex.addAll(areaGeneralData.getDeviceIndexs());
            }
        }
        List<VoltageData> voltageData = userUtil.getVoltageData(deviceIndex);
        if (CollectionUtils.isEmpty(voltageData)) {
            return null;
        }
        List<Integer> lineIndexs = new ArrayList<>();
        for (VoltageData vol : voltageData) {
            if (vol.getVol().equalsIgnoreCase(gist)) {
                lineIndexs.addAll(vol.getLineIndexs());
                break;
            }
        }
        if (CollectionUtils.isEmpty(lineIndexs)) {
            return null;
        }
        return getGistIntegralityRate(lineIndexs, startTime, endTime);
    }

    /**
     * 概览---》数据完整性---》终端厂家点击查询
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @param gist      终端厂家
     */
    @Override
    public List<SimpleValue> getCompanyIntegrality(Date startTime, Date endTime, String gist) {
        List<AreaGeneralData> areaGenerals = userUtil.getAreaGeneralRun();
        List<Integer> deviceIndex = new ArrayList<>();
        if (CollectionUtils.isEmpty(areaGenerals)) {
            return null;
        } else {
            for (AreaGeneralData areaGeneralData : areaGenerals) {
                deviceIndex.addAll(areaGeneralData.getDeviceIndexs());
            }
        }
        List<CompanyValue> companyValues = userUtil.getCompanyData(deviceIndex);
        if (CollectionUtils.isEmpty(companyValues)) {
            return null;
        }
        List<Integer> lineIndexs = new ArrayList<>();
        for (CompanyValue companyValue : companyValues) {
            if (companyValue.getCompanyName().equalsIgnoreCase(gist)) {
                lineIndexs.addAll(companyValue.getLineIndexs());
                break;
            }
        }
        if (CollectionUtils.isEmpty(lineIndexs)) {
            return null;
        }
        return getGistIntegralityRate(lineIndexs, startTime, endTime);
    }

    /**
     * 查询指定监测点的数据完整性
     *
     * @param lineIndexs 监测点索引
     * @param startTime  起始时间
     * @param endTime    截止时间
     */
    public List<SimpleValue> getGistIntegralityRate(List<Integer> lineIndexs, Date startTime, Date endTime) {
        List<SimpleValue> sims = new ArrayList<>();
        try {
            List<Integer> lineIndexTemp = new ArrayList<>(lineIndexs);
            int length = lineIndexTemp.size();
            if (length > 1000) {
                //需要循环的次数
                int times = length / 1000 + 1;
                for (int i = 1; i <= times; i++) {
                    if (length > 1000) {
                        List<Integer> temp = lineIndexTemp.subList(0, 1000);
                        List<SimpleValue> simTemp = integrityMapper.selectGistIntegrality(temp, startTime, endTime);
                        if (!CollectionUtils.isEmpty(simTemp)) {
                            sims.addAll(simTemp);
                        }
                        temp.clear();
                        length = length - 1000;
                    } else {
                        List<SimpleValue> simTemp = integrityMapper.selectGistIntegrality(lineIndexTemp, startTime, endTime);
                        if (!CollectionUtils.isEmpty(simTemp)) {
                            sims.addAll(simTemp);
                        }
                    }
                }
            } else {
                sims = integrityMapper.selectGistIntegrality(lineIndexs, startTime, endTime);
            }
        } catch (Exception e) {
            logger.error("查询数据完整性发生异常，异常是" + e.getMessage());
        }
        return sims;


    }


    /**
     * 根据用户当前身份，按终端厂家获取数据完整性
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     */
    private List<DeviceValue> getDataIntegralityCompany(List<Integer> deviceLindexs, Date startTime, Date endTime) {
        List<DeviceValue> deviceValues = new ArrayList<>();
        List<CompanyValue> companyValues = userUtil.getCompanyData(deviceLindexs);
        if (CollectionUtils.isEmpty(companyValues)) {
            return null;
        }
        for (CompanyValue companyValue : companyValues) {
            DeviceValue deviceValue = new DeviceValue();
            deviceValue.setName(companyValue.getCompanyName());
            List<Integer> lineIndexs = companyValue.getLineIndexs();
            if (CollectionUtils.isEmpty(lineIndexs)) {
                deviceValue.setAmounts("0");
                deviceValue.setDataIntegrity("3.1415");
                deviceValue.setGwamounts("0");
                deviceValue.setGwdataIntegrity("3.1415");
            } else {
                deviceValue.setAmounts(String.valueOf(lineIndexs.size()));
                //获取数据完整性
                deviceValue.setDataIntegrity(getIntegrality(lineIndexs, startTime, endTime));
                List<Integer> temp = getGwLine(lineIndexs);
                deviceValue.setGwamounts(temp.size() + "");
                deviceValue.setGwdataIntegrity(getGwIntegrality(temp, startTime, endTime));
            }
            deviceValues.add(deviceValue);
        }
        return deviceValues;
    }

    private List<DeviceValue> getDataIntegralityCompany(List<Integer> deviceLindexs, Date startTime, Date endTime,
                                                        String scale, String manc, String loadtype, Integer monitorNature) {
        List<DeviceValue> deviceValues = new ArrayList<>();
        List<CompanyValue> companyValues = userUtil.getCompanyData(deviceLindexs);
        if (CollectionUtils.isEmpty(companyValues)) {
            return null;
        }
        for (CompanyValue companyValue : companyValues) {
            DeviceValue deviceValue = new DeviceValue();
            deviceValue.setName(companyValue.getCompanyName());
            List<Integer> lineIndexs = companyValue.getLineIndexs();
            if (CollectionUtils.isEmpty(lineIndexs)) {
                continue;
            }
            lineIndexs = lineMapper.siftLineIndexs(lineIndexs, scale, manc, loadtype, monitorNature);
            if (CollectionUtils.isEmpty(lineIndexs)) {
                deviceValue.setAmounts("0");
                deviceValue.setDataIntegrity("3.1415");
                deviceValue.setGwamounts("0");
                deviceValue.setGwdataIntegrity("3.1415");
            } else {
                deviceValue.setAmounts(String.valueOf(lineIndexs.size()));
                //获取数据完整性
                deviceValue.setDataIntegrity(getIntegrality(lineIndexs, startTime, endTime));
                List<Integer> temp = getGwLine(lineIndexs);
                deviceValue.setGwamounts(temp.size() + "");
                deviceValue.setGwdataIntegrity(getGwIntegrality(temp, startTime, endTime));
            }
            deviceValues.add(deviceValue);
        }
        return deviceValues;
    }

    /**
     * 根据用户当前的身份，获取按电压等级的数据完整性
     *
     * @param deviceLindexs 用户权限下的终端索引
     * @param startTime     起始时间
     * @param endTime       截止时间
     */
    private List<DeviceValue> getDataIntegralityVol(List<Integer> deviceLindexs, Date startTime, Date endTime) {
        List<DeviceValue> deviceValues = new ArrayList<>();
        List<VoltageData> voltageDatas = userUtil.getVoltageData(deviceLindexs);
        if (CollectionUtils.isEmpty(voltageDatas)) {
            return null;
        }
        for (VoltageData voltageData : voltageDatas) {
            if (!CollectionUtils.isEmpty(voltageData.getLineIndexs())) {
                DeviceValue deviceValue = new DeviceValue();
                deviceValue.setName(voltageData.getVol());
                deviceValue.setAmounts(String.valueOf(voltageData.getLineIndexs().size()));
                //获取数据完整性
                deviceValue.setDataIntegrity(getIntegrality(voltageData.getLineIndexs(), startTime, endTime));
                List<Integer> temp = getGwLine(voltageData.getLineIndexs());
                deviceValue.setGwamounts(String.valueOf(temp.size()));
                deviceValue.setGwdataIntegrity(getGwIntegrality(temp, startTime, endTime));
                deviceValues.add(deviceValue);
            } else {
                DeviceValue deviceValue = new DeviceValue();
                deviceValue.setName(voltageData.getVol());
                deviceValue.setGwamounts("0");
                deviceValue.setAmounts("0");
                deviceValue.setDataIntegrity("3.1415");
                deviceValue.setGwdataIntegrity("3.1415");
            }
        }
        return deviceValues;
    }

    private List<DeviceValue> getDataIntegralityVol(List<Integer> deviceLindexs, Date startTime, Date endTime,
                                                    String scale, String manc, String loadtype, Integer monitorNature) {
        List<DeviceValue> deviceValues = new ArrayList<>();
        List<VoltageData> voltageDatas = userUtil.getVoltageData(deviceLindexs);
        if (CollectionUtils.isEmpty(voltageDatas)) {
            return null;
        }
        for (VoltageData voltageData : voltageDatas) {
            List<Integer> lines = voltageData.getLineIndexs();
            if (!CollectionUtils.isEmpty(lines)) {
                lines = lineMapper.siftLineIndexs(lines, scale, manc, loadtype, monitorNature);
                DeviceValue deviceValue = new DeviceValue();
                deviceValue.setName(voltageData.getVol());
                deviceValue.setAmounts(String.valueOf(lines.size()));
                //获取数据完整性
                deviceValue.setDataIntegrity(getIntegrality(lines, startTime, endTime));
                List<Integer> temp = getGwLine(lines);
                deviceValue.setGwamounts(String.valueOf(temp.size()));
                deviceValue.setGwdataIntegrity(getGwIntegrality(temp, startTime, endTime));
                deviceValues.add(deviceValue);
            } else {
                DeviceValue deviceValue = new DeviceValue();
                deviceValue.setName(voltageData.getVol());
                deviceValue.setGwamounts("0");
                deviceValue.setAmounts("0");
                deviceValue.setDataIntegrity("3.1415");
                deviceValue.setGwdataIntegrity("3.1415");
            }
        }
        return deviceValues;
    }

    /**
     * 根据用户当前的身份，获取按电压等级的数据完整性
     */
    private List<DeviceValue> getDataIntegralityLoadType(List<Integer> deviceLindexs, Date startTime, Date endTime,
                                                         String scale, String manc, String loadtype, Integer monitorNature) {
        List<DeviceValue> deviceValues = new ArrayList<>();
        List<LoadTypeValue> loadtypes = userUtil.getLoadTypeValue(deviceLindexs);
        if (CollectionUtils.isEmpty(loadtypes)) {
            return null;
        }
        for (LoadTypeValue type : loadtypes) {
            List<Integer> lines = type.getLineIndexs();
            if (!CollectionUtils.isEmpty(lines)) {
                lines = lineMapper.siftLineIndexs(lines, scale, manc, loadtype, monitorNature);
                DeviceValue deviceValue = new DeviceValue();
                deviceValue.setName(type.getType());
                deviceValue.setAmounts(String.valueOf(lines.size()));
                //获取数据完整性
                deviceValue.setDataIntegrity(getIntegrality(lines, startTime, endTime));
                List<Integer> temp = getGwLine(lines);
                deviceValue.setGwamounts(String.valueOf(temp.size()));
                deviceValue.setGwdataIntegrity(getGwIntegrality(temp, startTime, endTime));
                deviceValues.add(deviceValue);
            } else {
                DeviceValue deviceValue = new DeviceValue();
                deviceValue.setName(type.getType());
                deviceValue.setGwamounts("0");
                deviceValue.setAmounts("0");
                deviceValue.setDataIntegrity("3.1415");
                deviceValue.setGwdataIntegrity("3.1415");
            }
        }
        return deviceValues;
    }

    /**
     * 获取指定区域的数据完整性
     *
     * @param areaGeneralData 区域数据
     * @param startTime       起始时间
     * @param endTime         截止时间
     */
    private DeviceValue getDataIntegralityArea(AreaGeneralData areaGeneralData, Date startTime, Date endTime) {
        DeviceValue deviceValue = new DeviceValue();
        List<Integer> lines = areaGeneralData.getLineIndexs();
        String name = areaGeneralData.getName();
        deviceValue.setName(name);
        deviceValue.setAmounts(lines.size() + "");
        //根据监测点索引计算数据完整性
        deviceValue.setDataIntegrity(getIntegrality(lines, startTime, endTime));

        List<Integer> gwLines = getGwLine(lines);
        deviceValue.setGwamounts(gwLines.size() + "");
        //根据监测点索引计算数据完整性
        deviceValue.setGwdataIntegrity(getGwIntegrality(gwLines, startTime, endTime));
        deviceValue.setDeptsIndex(areaGeneralData.getDeptIndex());
        return deviceValue;
    }

    private DeviceValue getDataIntegralityArea(AreaGeneralData areaGeneralData, Date startTime, Date endTime,
                                               String scale, String manc, String loadtype, Integer monitorNature) {
        DeviceValue deviceValue = new DeviceValue();
        List<Integer> lines = areaGeneralData.getLineIndexs();
        lines = lineMapper.siftLineIndexs(lines, scale, manc, loadtype, monitorNature);
        String name = areaGeneralData.getName();
        deviceValue.setName(name);
        deviceValue.setAmounts(lines.size() + "");
        //根据监测点索引计算数据完整性
        deviceValue.setDataIntegrity(getIntegrality(lines, startTime, endTime));

        List<Integer> gwLines = getGwLine(lines);
        deviceValue.setGwamounts(gwLines.size() + "");
        //根据监测点索引计算数据完整性
        deviceValue.setGwdataIntegrity(getGwIntegrality(gwLines, startTime, endTime));
        deviceValue.setDeptsIndex(areaGeneralData.getDeptIndex());
        return deviceValue;
    }

    /**
     * 所有监测点
     *
     * @param lines 获取国网监测点ID
     */
    private List<Integer> getGwLine(List<Integer> lines) {
        if (CollectionUtils.isEmpty(lines)) {
            return new ArrayList<>();
        }
        List<Integer> lineTemp = new ArrayList<>(lines);
        List<Integer> tempLine = new ArrayList<>();
        if (lineTemp.size() > 1000) {
            int times = lineTemp.size() / 1000 + 1;
            for (int i = 0; i < times; i++) {
                if (lineTemp.size() > 1000) {
                    List<Integer> subList = lineTemp.subList(0, 1000);
                    List<Integer> temp = lineMapper.getGWLines(subList);
                    subList.clear();
                    tempLine.addAll(temp);
                } else {
                    tempLine.addAll(lineMapper.getGWLines(lineTemp));
                }
            }
        } else {
            tempLine.addAll(lineMapper.getGWLines(lineTemp));
        }
        return tempLine;
    }

    private List<Integer> getAllGwLine(List<Integer> lines) {
        if (CollectionUtils.isEmpty(lines)) {
            return new ArrayList<>();
        }
        List<Integer> lineTemp = new ArrayList<>(lines);
        List<Integer> tempLine = new ArrayList<>();
        if (lineTemp.size() > 1000) {
            int times = lineTemp.size() / 1000 + 1;
            for (int i = 0; i < times; i++) {
                if (lineTemp.size() > 1000) {
                    List<Integer> subList = lineTemp.subList(0, 1000);
                    List<Integer> temp = lineMapper.getAllGWLines(subList);
                    subList.clear();
                    tempLine.addAll(temp);
                } else {
                    tempLine.addAll(lineMapper.getAllGWLines(lineTemp));
                }
            }
        } else {
            tempLine.addAll(lineMapper.getAllGWLines(lineTemp));
        }
        return tempLine;
    }

    /**
     * 根据监测点索引获取当前的数据完整性
     *
     * @param lineIndexs 监测点索引
     * @param startTime  起始时间
     * @param endTime    截止时间
     */
    private String getIntegrality(List<Integer> lineIndexs, Date startTime, Date endTime) {
        SimpleValue sim;
        if (CollectionUtils.isEmpty(lineIndexs)) {
            return "3.1415";
        } else {
            sim = userUtil.selectIntegralityByLineIndexAndTime(lineIndexs, startTime, endTime);
        }
        if (null == sim || sim.getCountAll() == null || sim.getCountAll() == 0) {
            return "3.14159";
        }
        float num = Float.valueOf(sim.getCountOnline()) / Float.valueOf(sim.getCountAll()) * 100;
        //限制不超过100%
        if (num > 100) {
            return "100.0";
        }
        if (num < 0) {
            return "0.0";
        }
        DecimalFormat df = new DecimalFormat("0.00");// 格式化小数
        return df.format(num);
    }

    /**
     * 根据监测点索引获取当前的在线率(国网)
     *
     * @param lineIndexs 监测点索引
     * @param startTime  起始时间
     * @param endTime    截止时间
     */
    private String getGwIntegrality(List<Integer> lineIndexs, Date startTime, Date endTime) {
        SimpleValue sim;
        if (CollectionUtils.isEmpty(lineIndexs)) {
            return "3.1415";
        } else {
            sim = userUtil.selectGwIntegralityByLineIndexAndTime(lineIndexs, startTime, endTime);
        }
        if (null == sim || sim.getCountAll() == null || sim.getCountAll() == 0) {
            return "3.14159";
        }
        float num = Float.valueOf(sim.getCountOnline()) / Float.valueOf(sim.getCountAll()) * 100;
        //限制不超过100%
        if (num > 100) {
            return "100.0";
        }
        if (num < 0) {
            return "0.0";
        }
        DecimalFormat df = new DecimalFormat("0.00");// 格式化小数
        return df.format(num);
    }

    /**
     * 获取指定区域的终端运行状态
     *
     * @param areaGeneralData 部门对应的所有数据
     */
    private DeviceValue getDeviceValueArea(AreaGeneralData areaGeneralData, Date startTime, Date endTime) {
        DeviceValue deviceValue = new DeviceValue();
        // 区域名
        deviceValue.setName(areaGeneralData.getName());
        deviceValue.setDeptsIndex(areaGeneralData.getDeptIndex());
        // 终端数
        deviceValue.setAmounts(String.valueOf(areaGeneralData.getDeviceIndexs().size()));
        List<Device> devices = userUtil.getDevicesByDevIndexs(areaGeneralData.getDeviceIndexs());
        // 运行状态
        Status status = getStatus(devices);
        //获取该区域下的在线率
        if (CollectionUtils.isEmpty(areaGeneralData.getDeviceIndexs())) {
            deviceValue.setGwamounts("0");
            deviceValue.setOnline("3.1415");
            deviceValue.setGwonline("3.1415");
        } else {
            List<Integer> tempDeviceIndex = deviceMapper.getRunDeviceIndex(areaGeneralData.getDeviceIndexs());
            // 在线率
            deviceValue.setOnline(getOnline(tempDeviceIndex, startTime, endTime));
            //获取含有国网监测点的装置
            getGwData(deviceValue, getGwLine(areaGeneralData.getLineIndexs()), startTime, endTime);

        }
        deviceValue.setStatus(status);
        return deviceValue;
    }


    /**
     * 根据终端索引获取当前的在线率
     *
     * @param devIndex  终端索引
     * @param startTime 起始时间
     * @param endTime   截止时间
     */
    private String getOnline(List<Integer> devIndex, Date startTime, Date endTime) {
        SimpleValue sim;
        if (CollectionUtils.isEmpty(devIndex)) {
            return "3.1415";
        } else {
            sim = selectOnlineRateByDeviceIndexAndTime(devIndex, startTime, endTime);
        }
        if (null == sim || sim.getCountAll() == null || sim.getCountAll() == 0) {
            return "3.14159";
        }
        float num = Float.valueOf(sim.getCountOnline()) / Float.valueOf(sim.getCountAll()) * 100;
        if (num > 100) {
            return "100.0";
        }
        if (num < 0) {
            return "0.0";
        }
        DecimalFormat df = new DecimalFormat("0.00");// 格式化小数
        return df.format(num);
    }

    /**
     * 根据终端索引获取在线率
     */
    private SimpleValue selectOnlineRateByDeviceIndexAndTime(List<Integer> devIndex, Date startTime, Date endTime) {
        SimpleValue sim = new SimpleValue();
        try {
            //根据终端
            List<Integer> devIndexTemp = new ArrayList<>(devIndex);
            int length = devIndexTemp.size();
            if (length > 1000) {
                //需要循环的次数
                int times = length / 1000 + 1;
                for (int i = 1; i <= times; i++) {
                    if (length > 1000) {
                        List<Integer> temp = devIndexTemp.subList(0, 1000);
                        SimpleValue simTemp = onlineRateMapper.selectOnlineRateByDeviceIndexAndTime(temp, startTime, endTime);
                        if (simTemp != null) {
                            sim = userUtil.mergeSim(sim, simTemp);
                        }
                        temp.clear();
                        length = length - 1000;
                    } else {
                        SimpleValue simTemp = onlineRateMapper.selectOnlineRateByDeviceIndexAndTime(devIndexTemp, startTime, endTime);
                        if (simTemp != null) {
                            sim.setCountOnline(sim.getCountOnline() + simTemp.getCountOnline());
                            sim.setCountAll(sim.getCountAll() + simTemp.getCountAll());
                        }
                    }
                }
            } else {
                sim = onlineRateMapper.selectOnlineRateByDeviceIndexAndTime(devIndex, startTime, endTime);
            }
        } catch (Exception e) {
            logger.error("查询终端在线率发生异常，异常是" + e.getMessage());
        }
        return sim;
    }


    /**
     * 按终端厂家获取终端运行状态
     */
    private List<DeviceValue> getManufacturerData(List<Integer> deviceIndexs, Date startTime, Date endTime) {
        List<DeviceValue> interval = new ArrayList<>();

        List<CompanyValue> companyValues = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(deviceIndexs)) {

            if (deviceIndexs.size() > 1000) {
                int count = deviceIndexs.size() / 1000 + 1;
                for (int i = 0; i < count; i++) {
                    List<CompanyValue> temRes = null;
                    if (deviceIndexs.size() > 1000) {
                        List<Integer> temList = deviceIndexs.subList(0, 1000);
                        temRes = userUtil.getCompanyData(temList);
                        temList.clear();
                    } else {
                        temRes = userUtil.getCompanyData(deviceIndexs);
                    }
                    if (CollectionUtil.isNotEmpty(temRes)) {
                        companyValues.addAll(temRes);
                    }
                }
            } else {
                companyValues = userUtil.getCompanyData(deviceIndexs);
            }
        }


        if (CollectionUtils.isEmpty(companyValues)) {
            return null;
        }
        for (CompanyValue companyValue : companyValues) {
            DeviceValue deviceValue = new DeviceValue();
            deviceValue.setName(companyValue.getCompanyName());
            List<Integer> devIndexs = companyValue.getDeviceIndexs();
            if (CollectionUtils.isEmpty(devIndexs)) {
                deviceValue.setStatus(new Status());
                deviceValue.setAmounts("0");
                deviceValue.setOnline("3.1415");
                deviceValue.setGwonline("3.1415");
                deviceValue.setGwamounts("0");
            } else {
                deviceValue.setAmounts(String.valueOf(companyValue.getDeviceIndexs().size()));
                List<Device> devices = userUtil.getDevicesByDevIndexs(companyValue.getDeviceIndexs());
                deviceValue.setStatus(getStatus(devices));
                List<Integer> tempDeviceIndex = deviceMapper.getRunDeviceIndex(companyValue.getDeviceIndexs());
                // 在线率
                deviceValue.setOnline(getOnline(tempDeviceIndex, startTime, endTime));
                //获取含有国网监测点的装置
                getGwData(deviceValue, getGwLine(companyValue.getLineIndexs()), startTime, endTime);

            }
            interval.add(deviceValue);
        }
        Collections.sort(interval);
        return interval;
    }

    /**
     * 按电压等级获取终端运行状态
     */
    private List<DeviceValue> getScaleData(List<Integer> deviceIndexs, Date startTime, Date endTime) {
        List<DeviceValue> interval = new ArrayList<>();
        List<VoltageData> voltageValues = userUtil.getVoltageData(deviceIndexs);
        if (CollectionUtils.isEmpty(voltageValues)) {
            return null;
        }
        for (VoltageData voltageValue : voltageValues) {
            DeviceValue deviceValue = new DeviceValue();
            deviceValue.setName(voltageValue.getVol());
            List<Integer> devIndexs = voltageValue.getDeviceIndexs();
            if (CollectionUtils.isEmpty(devIndexs)) {
                continue;
            } else {
                deviceValue.setAmounts(String.valueOf(voltageValue.getDeviceIndexs().size()));
                List<Device> devices = userUtil.getDevicesByDevIndexs(voltageValue.getDeviceIndexs());
                deviceValue.setStatus(getStatus(devices));
                List<Integer> tempDeviceIndex = deviceMapper.getRunDeviceIndex(voltageValue.getDeviceIndexs());
                // 在线率
                deviceValue.setOnline(getOnline(tempDeviceIndex, startTime, endTime));
                //获取含有国网监测点的装置
                getGwData(deviceValue, getGwLine(voltageValue.getLineIndexs()), startTime, endTime);

            }
            interval.add(deviceValue);
        }
        Collections.sort(interval);
        return interval;
    }

    /**
     * 按干扰源类型终获取终端运行状态
     */
    private List<DeviceValue> getLoadTypeData(List<Integer> deviceIndexs, Date startTime, Date endTime) {
        List<DeviceValue> interval = new ArrayList<>();
        List<LoadTypeValue> loadtypeValues = userUtil.getLoadTypeValue(deviceIndexs);
        if (CollectionUtils.isEmpty(loadtypeValues)) {
            return null;
        }
        for (LoadTypeValue loadtypeValue : loadtypeValues) {
            DeviceValue deviceValue = new DeviceValue();
            deviceValue.setName(loadtypeValue.getType());
            List<Integer> devIndexs = loadtypeValue.getDevIndexs();
            if (CollectionUtils.isEmpty(devIndexs)) {
                continue;
            } else {
                deviceValue.setAmounts(String.valueOf(loadtypeValue.getDevIndexs().size()));
                List<Device> devices = userUtil.getDevicesByDevIndexs(loadtypeValue.getDevIndexs());
                deviceValue.setStatus(getStatus(devices));
                List<Integer> tempDeviceIndex = deviceMapper.getRunDeviceIndex(loadtypeValue.getDevIndexs());
                // 在线率
                deviceValue.setOnline(getOnline(tempDeviceIndex, startTime, endTime));
                //获取含有国网监测点的装置
                getGwData(deviceValue, getGwLine(loadtypeValue.getLineIndexs()), startTime, endTime);

            }
            interval.add(deviceValue);
        }
        Collections.sort(interval);
        return interval;
    }

    /**
     * 获取按终端厂家统计的在线率数据
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     */
    private List<DeviceValue> getManufacturerDataOnlineRate(List<Integer> deviceIndexs, Date startTime, Date endTime) {
        List<DeviceValue> interval = new ArrayList<>();
//        List<CompanyValue> companyValues = userUtil.getCompanyData(deviceIndexs);
//        if (CollectionUtils.isEmpty(companyValues)) {
//            return null;
//        }
//        for (CompanyValue companyValue : companyValues) {
//            DeviceValue deviceValue = new DeviceValue();
//            deviceValue.setName(companyValue.getCompanyName());
//            List<Integer> devIndexs = companyValue.getDeviceIndexs();
//            if (CollectionUtils.isEmpty(devIndexs)) {
//                deviceValue.setAmounts("0");
//                deviceValue.setOnline("3.1415");
//                deviceValue.setGwamounts("0");
//                deviceValue.setGwonline("3.1415");
//            } else {
//                // 在线率
//                deviceValue.setAmounts(String.valueOf(companyValue.getDeviceIndexs().size()));
//                deviceValue.setOnline(getOnline(devIndexs, startTime, endTime));
//                //获取含有国网监测点的装置
//                getGwData(deviceValue, getGwLine(companyValue.getLineIndexs()), startTime, endTime);
//            }
//            interval.add(deviceValue);
//        }
        return interval;
    }

    /**
     * 根据监测点，返回国网的在线率数据
     */
    private DeviceValue getGwData(DeviceValue deviceValue, List<Integer> lineIndex, Date startTime, Date endTime) {
        if (CollectionUtils.isEmpty(lineIndex)) {
            deviceValue.setGwamounts("0");
            deviceValue.setGwonline("3.1415");
        } else {
            //根据检测点获取装置索引
            List<Integer> deviceIndex = deviceMapper.getDeviceIndexByLineIndex(lineIndex);
            deviceValue.setGwamounts(deviceIndex.size() + "");
            //根据当前装置获取设备运行状态
            List<Device> devices = userUtil.getDevicesByDevIndexs(deviceIndex);
            deviceValue.setGdStatus(getStatus(devices));
            Float onlineTemp = onlineRateMapper.getGWOnlineRate(lineIndex, startTime, endTime);
            if (null == onlineTemp) {
                deviceValue.setGwonline("3.14159");
            } else {
                if (onlineTemp > 100) {
                    onlineTemp = 100.0f;
                } else if (onlineTemp < 0) {
                    onlineTemp = 0.0f;
                }
                deviceValue.setGwonline(FloatUtils.get2Float(onlineTemp) + "");
            }
        }
        return deviceValue;
    }


    /**
     * 根据传递的终端集合，获取出这些终端的运行状态
     *
     * @param device 终端集合
     */
    private Status getStatus(List<Device> device) {
        Integer normal = 0;
        Integer breaks = 0;
        Integer shutdown = 0;
        if (CollectionUtils.isEmpty(device)) {
            return new Status();
        } else {
            for (Device device2 : device) {
                if (device2.getDevFlag() == 0) {
                    normal = normal + 1;
                } else if (device2.getDevFlag() == 1) {
                    breaks = breaks + 1;
                } else {
                    shutdown = shutdown + 1;
                }
            }
        }
        Status temp = new Status();
        Integer counts;
        counts = normal + breaks + shutdown;
        temp.setBreaksData(breaks);
        temp.setNormalData(normal);
        temp.setShutdownData(shutdown);
        float num = Float.valueOf(normal) / Float.valueOf(counts);
        num = num * 100;
        DecimalFormat df = new DecimalFormat("0.00");// 格式化小数
        temp.setNormal(df.format(num));
        float bre = Float.valueOf(breaks) / Float.valueOf(counts);
        bre = bre * 100;
        temp.setBreaks(df.format(bre));
        float sh = Float.valueOf(shutdown) / Float.valueOf(counts);
        sh = sh * 100;
        temp.setShutdown(df.format(sh));
        return temp;
    }

    /**
     * 监测点--》终端在线率
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     */
    @Override
    public String getDeviceOnline(Date startTime, Date endTime, Long lineIndex) {
        Line line = lineMapper.queryLineData(lineIndex);
        List<Integer> temps = new ArrayList<>();
        temps.add(Integer.parseInt(line.getDevIndex().toString()));
        SimpleValue temp;
        temp = selectOnlineRateByDeviceIndexAndTime(temps, startTime, endTime);
        if (null == temp) {
            return "0.00";
        }

        Integer online = temp.getCountOnline();
        Integer count = temp.getCountAll();
        float num = Float.valueOf(online) / Float.valueOf(count);
        num = num * 100;
        DecimalFormat df = new DecimalFormat("0.00");// 格式化小数
        String tempOnlineRate = df.format(num);// 返回的是String类型
        return tempOnlineRate;
    }

    /**
     * 监测点--》终端在线率
     *
     * @param startTime 起始时间
     * @param endTime   截止时间
     */
    @Override
    public List<DeviceOnline> getDeviceOnlineRate(Date startTime, Date endTime, Long lineIndex) {
        List<DeviceOnline> result = new ArrayList<>();
        Line line = lineMapper.queryLineData(lineIndex);
        List<Integer> temps = new ArrayList<>();
        temps.add(Integer.parseInt(line.getDevIndex().toString()));

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        // 获取两个时间的之间的月份
        List<String> intervalTime = this.getIntervalTime(sdf.format(startTime), sdf.format(endTime));
        for (String interTime : intervalTime) {
            String onlineRate;
            DeviceOnline inter = new DeviceOnline();
            inter.setMonth(interTime.substring(5));
            inter.setYear(interTime.substring(0, 4));
            try {
                SimpleDateFormat sdff = new SimpleDateFormat("yyyy-MM-dd");
                startTime = sdff.parse(interTime + "-01");
                endTime = sdff.parse(interTime + "-31");
            } catch (ParseException e) {
                logger.error("时间转化发生异常，异常是" + e.getMessage());
            }

            SimpleValue temp;
            temp = selectOnlineRateByDeviceIndexAndTime(temps, startTime, endTime);
            if (null == temp) {
                onlineRate = "0.00";
            } else {
                Integer online = temp.getCountOnline();
                Integer count = temp.getCountAll();
                float num = Float.valueOf(online) / Float.valueOf(count);
                num = num * 100;
                DecimalFormat df = new DecimalFormat("0.00");// 格式化小数
                onlineRate = df.format(num);// 返回的是String类型
            }

            inter.setOnlineRate(onlineRate);
            result.add(inter);
        }
        return result;
    }

    // 获取终端运行状态信息
    @Override
    public List<Communication> getRunInfo(Long lineIndex, Date startTime, Date endTime) {
        List<Communication> result = new ArrayList<>();
        List<ComInformation> info;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar ca = Calendar.getInstance();
        ca.setTime(startTime);
        info = deviceInfoMapper.getRunInfo(lineIndex, startTime, endTime);

        Line line = lineMapper.selectByPrimaryKey(lineIndex);
        Device dev = deviceMapper.selectByPrimaryKey(line.getDevIndex());

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startTime);
        calendar.add(calendar.SECOND, -1);
        Date lastend = calendar.getTime();
        calendar.add(calendar.MONTH, -1);
        Date laststart = calendar.getTime();
        List<ComInformation> lasttype = deviceInfoMapper.getRunInfo(lineIndex, laststart, lastend);

        Integer bgsbzt = 0;
        if (lasttype != null && lasttype.size() > 0) {
            bgsbzt = lasttype.get(lasttype.size() - 1).getType();
        }

        if (dev.getLogonTime().getTime() > endTime.getTime()) {
            bgsbzt = 0;
        }
        if (dev.getUpdateTime().getTime() < startTime.getTime() || info.size() == 0) {
            if (dev.getStatus() != null && dev.getStatus() == 0) {
                bgsbzt = 0;
            } else if (dev.getStatus() != null && dev.getStatus() == 1) {
                bgsbzt = 1;
            } else {
                bgsbzt = -1;
            }
        }
        Communication begin = new Communication();
        begin.setTime(startTime.getTime());
        begin.setSbzt((long) bgsbzt);
        result.add(begin);

        if (info.size() == 0) {
            Communication finish = new Communication();

            finish.setTime(endTime.getTime());
            finish.setSbzt((long) bgsbzt);
            result.add(finish);
        } else {
            for (int n = 0; n < info.size(); n++) {
                Communication tmp = new Communication();
                Integer sbzt = info.get(n).getType();
                switch (sbzt) {
                    case 0:
                        sbzt = 0;
                        break;
                    case 1:
                        sbzt = 1;
                        break;
                    default:
                        sbzt = -1;
                        break;
                }

                if (n == 0) {
                    tmp.setTime(info.get(n).getUpdateTime().getTime());
                    tmp.setSbzt((long) bgsbzt);
                    result.add(tmp);
                    if (sbzt != bgsbzt) {
                        tmp = new Communication();
                        tmp.setTime(info.get(n).getUpdateTime().getTime());
                        tmp.setSbzt((long) sbzt);
                        result.add(tmp);
                    }
                } else {
                    Integer sbzttmp = info.get(n - 1).getType();
                    switch (sbzttmp) {
                        case 0:
                            sbzttmp = 0;
                            break;
                        case 1:
                            sbzttmp = 1;
                            break;
                        default:
                            sbzttmp = -1;
                            break;
                    }
                    tmp = new Communication();
                    tmp.setTime(info.get(n).getUpdateTime().getTime());
                    tmp.setSbzt((long) sbzttmp);
                    result.add(tmp);

                    if (sbzttmp != sbzt) {
                        tmp = new Communication();
                        tmp.setTime(info.get(n).getUpdateTime().getTime());
                        tmp.setSbzt((long) sbzt);
                        result.add(tmp);
                    }
                }
            }

            Communication finish = new Communication();
            Integer endsbzt = info.get(info.size() - 1).getType();
            switch (endsbzt) {
                case 0:
                    endsbzt = 0;
                    break;
                case 1:
                    endsbzt = 1;
                    break;
                default:
                    endsbzt = -1;
                    break;
            }
            finish.setTime(endTime.getTime());
            finish.setSbzt((long) endsbzt);
            result.add(finish);

//			LineDetail lineInfo = new LineDetail();
//			lineInfo.setLineIndex(lineIndex);
//
//			lineInfo = lineDetailMapper.selectOne(lineInfo);
//
//			int interval = lineInfo.getTInterval();
//
//			int arg = (int) ((endTime.getTime() - startTime.getTime()) / (1000*60*interval));
//			int num = 0;
//
//			long sbzttmp = 1;
//			for(int i=num;i<arg;i++){
//				String sign="";
//				num++;
//				Communication tmp = new Communication();
//				Communication tmp2 = new Communication();
//				Date pointTime = ca.getTime();
//				ca.add(Calendar.MINUTE, interval);
//
//				for(int n=0;n<info.size();n++){
//					Date updatetime = info.get(n).getUpdateTime();
//					Calendar cal = Calendar.getInstance();
//					cal.setTime(updatetime);
//					cal.set(Calendar.SECOND,0);
//					updatetime = cal.getTime();
//
//					Integer sbzt = info.get(n).getType();
//					if(pointTime.getTime() < updatetime.getTime()){
//						if((int) ((updatetime.getTime() - pointTime.getTime()) / (1000*60))>1439){
//							i=i+1440/interval;
//							ca.add(Calendar.MINUTE, 1435);
//						}else if((int) ((updatetime.getTime() - pointTime.getTime()) / (1000*60))>59){
//							i=i+60;
//							ca.add(Calendar.MINUTE, 55);
//						}
//						tmp = new Communication();
//						tmp.setTime(pointTime.getTime());
//						tmp.setSbzt(sbzttmp);
//
//						result.add(tmp);
//						break;
//					}else if(pointTime.getTime() == updatetime.getTime()){
//						tmp = new Communication();
//						tmp2 = new Communication();
//						tmp.setTime(pointTime.getTime());
//						tmp2.setTime(pointTime.getTime());
//						tmp.setSbzt(sbzttmp);
//						result.add(tmp);
//
//						if(sbzt != null && sbzt == 0){
//							tmp2.setSbzt((long) 1);
//							sbzttmp = (long) 1;
//						}else if(sbzt != null && sbzt == 1){
//							tmp2.setSbzt((long) 0);
//							sbzttmp = (long) 0;
//						}else{
//							tmp2.setSbzt((long) -1);
//							sbzttmp = (long) -1;
//						}
//						result.add(tmp2);
//						break;
//					}else{
//						if(n == info.size()-1){
//							tmp = new Communication();
//							tmp.setTime(pointTime.getTime());
//							tmp.setSbzt(sbzttmp);
//							result.add(tmp);
//
//							int pass = 1440/interval;
//							i=i+pass;
//
//							ca.add(Calendar.MINUTE, 1439);
////							tmp.setTime(endTime.getTime());
////							tmp.setSbzt(sbzttmp);
////							result.add(tmp);
////							sign = "break";
//							break;
//						}else{
//							continue;
//						}
//					}
//				}
//
//				if(sign.equals( "break")){
//					break;
//				}
//			}
        }
        return result;
    }

    @Override
    public ValueOfTargetanaly getSteady(Date startTime, Date endTime, Long lineIndex) {
        ValueOfTargetanaly result;

        result = limitRateMapper.getsteadyoutoflimit(startTime, endTime, lineIndex);
        return result;
    }

    @Override
    public List<ValueOfTargetanaly> getSteadyTB(Date startTime, Date endTime, Date laststartTime, Date lastendTime, Long lineIndex) {
        List<ValueOfTargetanaly> result = new ArrayList<>();
        ValueOfTargetanaly tmp1;
        ValueOfTargetanaly tmp2;

        tmp1 = limitRateMapper.getsteadyoutoflimit(startTime, endTime, lineIndex);
        tmp2 = limitRateMapper.getsteadyoutoflimit(laststartTime, lastendTime, lineIndex);

        result.add(tmp1);
        result.add(tmp2);
        return result;
    }

    @Override
    public List<HistoryData> getHistoryData(String startTime, String endTime, Long lineIndex, String start, String end,
                                            String type, String number, int flagday, int dataType) {
        List<HistoryData> result = new ArrayList<>();

        int behour = Integer.parseInt(start.substring(0, 2));
        int endhour = Integer.parseInt(end.substring(0, 2));
        String be = startTime + " " + start;
        String en = endTime + " " + end;
        if (type.equals("getXVrValue")) {
            result = historyDataMapper.getXVrValue(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getLVrValue")) {
            result = historyDataMapper.getLVrValue(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getDypc")) {
            result = historyDataMapper.getDypc(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getSxbphd")) {
            result = historyDataMapper.getSxbphd(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getBphdy")) {
            result = historyDataMapper.getBphdy(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getDyzjbl")) {
            result = historyDataMapper.getDyzjbl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getDlyxz")) {
            result = historyDataMapper.getDlyxz(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getFxdl")) {
            result = historyDataMapper.getFxdl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getPl")) {
            result = historyDataMapper.getPl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getJbhyl")) {
            result = historyDataMapper.getJbhyl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getXbhyl")) {
            result = historyDataMapper.getXbhyl(number, lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getXbdlfz")) {
            result = historyDataMapper.getXbdlfz(number, lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getJxbhyl")) {
            result = historyDataMapper.getJxbhyl(number, lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getYggl")) {
            result = historyDataMapper.getYggl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getWggl")) {
            result = historyDataMapper.getWggl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getSzgl")) {
            result = historyDataMapper.getSzgl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getYgzgl")) {
            result = historyDataMapper.getYgzgl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getSzglys")) {
            result = historyDataMapper.getSzglys(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getWyglys")) {
            result = historyDataMapper.getWyglys(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getZSzglys")) {
            result = historyDataMapper.getZSzglys(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getZWyglys")) {
            result = historyDataMapper.getZWyglys(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getWgzgl")) {
            result = historyDataMapper.getWgzgl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getSzzgl")) {
            result = historyDataMapper.getSzzgl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getDlzjbl")) {
            result = historyDataMapper.getDlzjbl(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getCssb")) {
            result = historyDataMapper.getCssb(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getDssb")) {
            result = historyDataMapper.getDssb(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getDybd")) {
            result = historyDataMapper.getDybd(lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getXbVXj")) {
            result = historyDataMapper.getXbVXj(number,lineIndex, be, en, start, end, flagday);
        } else if (type.equals("getXbIXj")) {
            result = historyDataMapper.getXbIXj(number,lineIndex, be, en, start, end, flagday);
        }else if (type.equals("getXbYgGl")) {
            result = historyDataMapper.getXbYGGl(number,lineIndex, be, en, start, end, flagday);
        }else if (type.equals("getXbWgGl")) {
            result = historyDataMapper.getXbWGGl(number,lineIndex, be, en, start, end, flagday);
        }else if (type.equals("getXbSzGl")) {
            result = historyDataMapper.getXbSZGl(number,lineIndex, be, en, start, end, flagday);
        }


        if (dataType == 0) {  //只有在线历史趋势才需要剔除
            result = delaNotDate(result, behour, endhour + 1);
        }

        return result;
    }

    /**
     * 剔除不在时间段里的数据
     *
     * @author cdf
     * @date 2021/3/23
     */
    private List<HistoryData> delaNotDate(List<HistoryData> list, int start, int end) {
        if (CollectionUtil.isEmpty(list)) {
            return list;
        }
        Calendar calendar = Calendar.getInstance();
        return list.stream().filter(new Predicate<HistoryData>() {
            @Override
            public boolean test(HistoryData historyData) {
                calendar.setTime(historyData.getTimeId());
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                if (hour < end && hour >= start) {
                    return true;
                }
                return false;
            }
        }).collect(Collectors.toList());
    }


    @Override
    public List<List> getSbyc() {
        List<List> deviceList = new ArrayList<List>();
        List<Integer> lineList = userUtil.listLineRun();
        List<DeviceDetail> details = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(lineList)) {
            if (lineList.size() > 1000) {
                int count = lineList.size() / 1000 + 1;
                for (int i = 0; i < count; i++) {
                    List<DeviceDetail> tem = null;
                    if (lineList.size() > 1000) {
                        List<Integer> temList = lineList.subList(0, 1000);
                        tem = deviceDetailMapper.getSbyc(temList);
                        temList.clear();
                    } else {
                        tem = deviceDetailMapper.getSbyc(lineList);
                    }
                    if (CollectionUtil.isNotEmpty(tem)) {
                        details.addAll(tem);
                    }
                }
            } else {
                details = deviceDetailMapper.getSbyc(lineList);
            }
        }

        if (details.isEmpty()) {
            return deviceList;
        } else {
            for (int i = 0; i < details.size(); i++) {
                List<String> temp = new ArrayList<String>();
                GDInformation gdInformation = new GDInformation();
                gdInformation.setGdIndex(details.get(i).getGdName());
                gdInformation = gdMapper.selectOne(gdInformation);
                temp.add(gdInformation.getName());
                temp.add(details.get(i).getName());
                temp.add(details.get(i).getPointName());
                temp.add(details.get(i).getSubName());
                temp.add(details.get(i).getTime());
                temp.add(details.get(i).getDevType());
                temp.add(details.get(i).getIP());
                temp.add(details.get(i).getPortid().toString());
                temp.add(details.get(i).getDevflag());
                temp.add(details.get(i).getUpdatetime());
                deviceList.add(temp);
            }
        }
        return deviceList;
    }

    /**
     * 更新终端信息
     */
    @Override
    public String updateDeviceInfo(DeviceInfo device) {
        String name = device.getName();
        Long devIndex = device.getDevIndex();

        List<Device> dev = deviceMapper.testName(name, device.getSubIndex(), devIndex);
        if (dev.size() > 0) {
            return "修改失败a";
        } else {
            Device tmp = deviceMapper.selectByPrimaryKey(device.getDevIndex());
            DeviceDetailInfo detail = deviceDetailInfoMapper.selectByPrimaryKey(device.getDevIndex());

            if (device.getDevType() != null) {
                tmp.setDevType(device.getDevType());
            }
            if (device.getLogonTime() != null) {
                tmp.setLogonTime(device.getLogonTime());
            }
            if (device.getName() != null) {
                tmp.setName(device.getName());
            }
            if (device.getNodeIndex() != null) {
                tmp.setNodeIndex(device.getNodeIndex());
            }
            if (device.getIp1() != null && device.getIp2() != null && device.getIp3() != null && device.getIp4() != null) {
                String ip = String.valueOf(device.getIp4()) + "." + String.valueOf(device.getIp3()) + "." + String.valueOf(device.getIp2()) + "." + String.valueOf(device.getIp1());
                tmp.setIp(ip);
            }
            if (device.getDevmodel() != null) {
                tmp.setDevmodel(device.getDevmodel());
            }
            if (device.getDatatype() != null) {
                tmp.setDatatype(device.getDatatype());
            }

            if (device.getSeries() != null) {
                String series = ThreeDes.encryptThreeDes(device.getSeries());
                tmp.setSeries(series);
            } else if (tmp.getSeries() == null) {
                tmp.setSeries("");
            }
            if (device.getKey() != null) {
                String key = ThreeDes.encryptThreeDes(device.getKey());
                tmp.setKey(key);
            } else if (tmp.getKey() == null) {
                tmp.setKey("");
            }


            if (device.getManufacturer() != null) {
                detail.setManufacturer(device.getManufacturer());
            }
            if (device.getNextTimeCheck() != null) {
                detail.setNextTimeCheck(device.getNextTimeCheck());
            }

            try {
                int flag = deviceMapper.updateByPrimaryKey(tmp);
                int flag1 = deviceDetailInfoMapper.updateByPrimaryKey(detail);
                redisCacheUtil.clearConData();
                return "修改成功";
            } catch (Exception e) {
                return "修改失败";
            }
        }

    }

    @Override
    public String delDeviceInfo(Long devIndex) {
        SubVoltage tmp = new SubVoltage();
        tmp.setDevIndex(devIndex);

        List<SubVoltage> subVoltage = subVoltageMapper.select(tmp);

        if (subVoltage.size() > 0) {
            return "删除失败a";
        } else {
            DeviceDetailInfo detail = new DeviceDetailInfo();
            try {
                int flag = deviceMapper.deleteByPrimaryKey(devIndex);
                int flag1 = deviceDetailInfoMapper.deleteByPrimaryKey(devIndex);
                redisCacheUtil.clearConData();

                return "删除成功";
            } catch (Exception e) {
                return "删除失败b";
            }
        }
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateDevice(Integer name, Integer devflag, String terminalDescribe) {
        int flag = 200;
        //判断描述是否为空
        if (!StringUtils.isBlank(terminalDescribe)) {
            try {
                String deviceDescribe = deviceMapper.deviceDescribe(name);
                //更新人
                String userIndex = TokenManager.getToken().getUserIndex();
                String userName = TokenManager.getToken().getName();
                TerminalLogs terminalLogs = new TerminalLogs();
                terminalLogs.setLogsIndex(UUID.randomUUID().toString());
                terminalLogs.setObjIndex(name.toString());
                terminalLogs.setUserIndex(userIndex);
                terminalLogs.setUpdateTime(new Date());
                terminalLogs.setTerminalType(TerminalLogsEnum.deviceLogs.getTerminalIndex());
                terminalLogs.setTerminalDescribe(userName + deviceDescribe + terminalDescribe);
                terminalLogsMapper.insert(terminalLogs);//增加日志
                deviceMapper.updateDevice(name, devflag);
                lineMapper.updateLineStatus(devflag, name.longValue());
            } catch (Exception e) {
                flag = 500;
            }
        } else {
            flag = 300;
        }
        return flag;
    }

    /**
     * 根据字典类型查询字典数据
     */
    @Override
    public List<DicData> getdicdata(String dictypeName) {
        List<DicData> result;

        DicType type;

        type = dicDataTypeMapper.querybyname(dictypeName);

        String typrid = type.getDicTypeIndex();
        result = dicDataMapper.selAll(typrid);

        return result;
    }

    /**
     * 查询字典表省份区域
     */
    @Override
    public List<DicData> getDicPro() {
        List<DicData> result;

        DicType type;

        type = dicDataTypeMapper.querybyname("行政区域");

        String typrid = type.getDicTypeIndex();
        result = dicDataMapper.queryDicPro(typrid);

        return result;
    }

    @Override
    public DeviceInfo loadDevice(Long devIndex) {
        DeviceInfo result = new DeviceInfo();
        Device tmp;
        DeviceDetailInfo temp;

        tmp = deviceMapper.selectByPrimaryKey(devIndex);
        temp = deviceDetailInfoMapper.selectByPrimaryKey(devIndex);

        result.setDevIndex(tmp.getDevIndex());
        result.setCallFlag(tmp.getCallFlag());
        result.setDevFlag(tmp.getDevFlag());
        result.setGdIndex(tmp.getGdIndex());

        String ip = tmp.getIp();
        String[] ipn = ip.split("\\.");
        result.setIp1(Integer.valueOf(ipn[3]));
        result.setIp2(Integer.valueOf(ipn[2]));
        result.setIp3(Integer.valueOf(ipn[1]));
        result.setIp4(Integer.valueOf(ipn[0]));
        result.setName(tmp.getName());
        result.setNodeIndex(tmp.getNodeIndex());
        result.setStatus(tmp.getStatus());
        result.setSubIndex(tmp.getSubIndex());
        result.setDevType(tmp.getDevType());

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String logonTime = sdf.format(tmp.getLogonTime());
        String updateTime = sdf.format(tmp.getUpdateTime());
        String ThisTimeCheck = sdf.format(temp.getThisTimeCheck());
        String NextTimeCheck = sdf.format(temp.getNextTimeCheck());

        result.setLogTime(logonTime);
        result.setUpdTime(updateTime);
        result.setThisTime(ThisTimeCheck);
        result.setNextTime(NextTimeCheck);

        result.setManufacturer(temp.getManufacturer());

        result.setDatatype(tmp.getDatatype());
        result.setDevmodel(tmp.getDevmodel());

        String series = tmp.getSeries();
        String key = tmp.getKey();

        if (series != null) {
            result.setSeries(ThreeDes.decryptThreeDes(series));
        } else {
            result.setSeries("");
        }

        if (key != null) {
            result.setKey(ThreeDes.decryptThreeDes(key));
        } else {
            result.setKey("");
        }

        return result;
    }

    @Override
    public List<NodeInformation> getNodeInfo() {
        List<NodeInformation> result = new ArrayList<>();

        NodeInformation tmp = new NodeInformation();
        tmp.setNodeStatus(Long.valueOf(1));

        result = nodeInformationMapper.select(tmp);

        return result;
    }

    @Override
    public GDInformation loadGd(Long gdIndex) {
        GDInformation result = new GDInformation();
        result = gdInforMapper.selectByPrimaryKey(gdIndex);

        return result;
    }

    @Override
    public String delGd(Long gdIndex) {
        SubStation subtmp = new SubStation();
        subtmp.setGdIndex(gdIndex);
        Device devtmp = new Device();
        devtmp.setGdIndex(gdIndex);
        SubVoltage subvtmp = new SubVoltage();
        subvtmp.setGdIndex(gdIndex);
        Line linetmp = new Line();
        linetmp.setGdIndex(gdIndex);

        DeptsGd dep = new DeptsGd();
        dep.setGDIndex(gdIndex);

        List<SubStation> sub = subStationMapper.select(subtmp);
        List<Device> dev = deviceMapper.select(devtmp);
        List<SubVoltage> subv = subVoltageMapper.select(subvtmp);
        List<Line> line = lineMapper.select(linetmp);

        if (line.size() > 0) {
            for (int i = 0; i < line.size(); i++) {
                delLine(line.get(i).getLineIndex());
            }
        }
        if (subv.size() > 0) {
            for (int i = 0; i < subv.size(); i++) {
                delSubv(subv.get(i).getSubvIndex());
            }
        }
        if (dev.size() > 0) {
            for (int i = 0; i < dev.size(); i++) {
                delDeviceInfo(dev.get(i).getDevIndex());
            }
        }
        if (sub.size() > 0) {
            for (int i = 0; i < sub.size(); i++) {
                delSub(sub.get(i).getSubIndex());
            }
        }
        try {
            int flag = gdInforMapper.deleteByPrimaryKey(gdIndex);
            int flag1 = deptsGdMapper.delete(dep);
            redisCacheUtil.clearConData();
            return "删除成功";
        } catch (Exception e) {
            return "删除失败b";
        }

    }

    @Override
    public SubInfo loadSub(Long subIndex) {
        SubInfo result;
        result = subStationMapper.getSubDetail(subIndex);

        return result;
    }

    @Override
    public String updateSub(Long gdIndex, Long subIndex, String name, Float longitude, Float latitude, String mapIndex) {
        SubStation tmp = new SubStation();
        tmp.setName(name);

        List<SubStation> sub = subStationMapper.testName(name, subIndex,gdIndex);
        if (sub.size() > 0) {
            return "更新失败a";
        } else {
            Maps map;
            map = mapMapper.selectByPrimaryKey(mapIndex);
            map.setLatItude(latitude);
            map.setLongItude(longitude);
            tmp.setGdIndex(gdIndex);
            tmp.setSubIndex(subIndex);

            try {
                int flag = subStationMapper.updateByPrimaryKey(tmp);
                int flag2 = mapMapper.updateByPrimaryKey(map);
                redisCacheUtil.clearConData();
                return "更新成功";
            } catch (Exception e) {
                return "更新失败";
            }
        }
    }

    @Override
    public String delSub(Long subIndex) {
        Device tmp = new Device();
        tmp.setSubIndex(subIndex);

        TransFormer tf = new TransFormer();
        tf.setSubIndex(subIndex.intValue());

        List<Device> device = deviceMapper.select(tmp);
        List<TransFormer> trans = transFormerMapper.select(tf);

        Maps map = new Maps();
        map.setSubIndex(subIndex);
        map.setState(Long.valueOf("1"));
        map = mapMapper.selectOne(map);

        if (map != null) {
            map.setState(Long.valueOf("0"));
        }

        if (device.size() > 0) {
            return "删除失败a";
        } else if (trans.size() > 0) {
            return "删除失败c";
        } else {
            try {
                int flag = subStationMapper.deleteByPrimaryKey(subIndex);
                int flag1 = mapMapper.updateByPrimaryKey(map);
                redisCacheUtil.clearConData();

// 				Long kind =(long) 1;
// 				String tableName = String.format("%5d", subIndex).replace(" ", "0");
// 				TestProcedures.delTable(tableName, kind);

                return "删除成功";
            } catch (Exception e) {
                return "删除失败b";
            }
        }
    }

    @Override
    public SubVoltage loadSubv(Long subvIndex) {
        SubVoltage result;
        result = subVoltageMapper.selectByPrimaryKey(subvIndex);

        return result;
    }

    @Override
    public String updateSubv(String subvName, Long gdIndex, Long subIndex, Long devIndex, Long subvIndex, int subvnum,
                             String scale, Long subvModel) {
        SubVoltage tmp = new SubVoltage();

        tmp.setGdIndex(gdIndex);
        tmp.setSubIndex(subIndex);
        tmp.setDevIndex(devIndex);
        tmp.setSubvIndex(subvIndex);
        tmp.setName(subvName);
        tmp.setScale(scale);
        tmp.setSubvNum(subvnum);
        tmp.setSubvModel(subvModel);

        DicData dicScale = dicDataMapper.selectId(scale);
        if (Objects.isNull(dicScale)) {
            return "更新失败";
        }
        String tmpname = dicScale.getDicName();
        float jzcmp = getJZCmp(tmpname);
        float nScale = Float.parseFloat(tmpname.substring(0, tmpname.length() - 2));
        try {
            subVoltageMapper.updateByPrimaryKey(tmp);
            lineMapper.updateScale(scale, jzcmp, nScale * 1000, subvName, subvIndex);
            List<Line> lineList = lineMapper.getLineListBySubVId(subvIndex);
            if (CollectionUtil.isNotEmpty(lineList)) {
                for (Line line : lineList) {
                    //float[] fLimit = COverlimit.GetOverLimit(tmpname, line.getDlcMp(), line.getJzcMp(), line.getXycMp(), line.getDevcMp());

                    OverLimit overlimit = COverlimitUtil.globalAssemble(nScale,line.getXycMp(),line.getDevcMp(),line.getDlcMp());
                    overlimit.setMyIndex(line.getLineIndex());

                    overLimitMapper.deleteByPrimaryKey(line.getLineIndex());
                    overLimitMapper.insert(overlimit);
                }
            }
            redisCacheUtil.clearConData();
            return "更新成功";
        } catch (Exception e) {
            return "更新失败";
        }

    }

    @Override
    public String delSubv(Long subvIndex) {
        Line tmp = new Line();
        tmp.setSubvIndex(subvIndex);

        List<Line> line = lineMapper.select(tmp);

        if (line.size() > 0) {
            return "删除失败a";
        } else {
            try {
                int flag = subVoltageMapper.deleteByPrimaryKey(subvIndex);
                redisCacheUtil.clearConData();

// 				Long kind =(long) 3;
// 				String tableName = String.format("%5d", subvIndex).replace(" ", "0");
// 				TestProcedures.delTable(tableName, kind);

                return "删除成功";
            } catch (Exception e) {
                return "删除失败b";
            }
        }
    }

    @Override
    public String delLine(Long lineIndex) {
        Line line = lineMapper.selectByPrimaryKey(lineIndex);
        Device dev = deviceMapper.selectByPrimaryKey(line.getDevIndex());
        try {
            int flag = lineMapper.deleteByPrimaryKey(lineIndex);
            int flag1 = lineDetailMapper.deleteByPrimaryKey(lineIndex);
            int flag2 = comInformationMapper.delByIndex(lineIndex);
            int flag3 = overLimitMapper.deleteByPrimaryKey(lineIndex);

            if (dev.getDatatype() == 1 || dev.getDatatype() == 2) {
                String tableName = String.format("%5d", lineIndex).replace(" ", "0");
                TestProcedures.delNodesTable(tableName);
            }

            redisCacheUtil.clearConData();
            return "删除成功";
        } catch (Exception e) {
            return "删除失败";
        }
    }

    @Override
    public LineDetailInfo loadLine(Long lineIndex) {
        LineDetailInfo result = new LineDetailInfo();
        Line line = new Line();
        LineDetail detail = new LineDetail();
        line = lineMapper.selectByPrimaryKey(lineIndex);
        detail = lineDetailMapper.selectByPrimaryKey(lineIndex);

        result.setLineIndex(lineIndex);
        result.setGdIndex(line.getGdIndex());
        result.setSubIndex(line.getSubIndex());
        result.setSubvIndex(line.getSubvIndex());
        result.setDevIndex(line.getDevIndex());
        result.setName(line.getName());
        result.setPt1(line.getPt1());
        result.setPt2(line.getPt2());
        result.setCt1(line.getCt1());
        result.setCt2(line.getCt2());
        result.setDevcMp(line.getDevcMp());
        result.setDlcMp(line.getDlcMp());
        result.setJzcMp(line.getJzcMp());
        result.setXycMp(line.getXycMp());
        result.setSubVNo(line.getSubVNo());
        result.setScale(line.getScale());
        result.setSubvName(line.getSubvName());
        result.setPtType(detail.getPtType());
        result.setTinterval(detail.getTInterval());
        result.setLoadType(detail.getLoadType());
        result.setBusinessType(detail.getBusinessType());
        result.setRemark(detail.getRemark());
        result.setMonitorId(detail.getMonitorId());

        return result;
    }

    @Override
    public String updateLine(Line line, LineDetail detail) {
        String name = line.getName();
        Long lineIndex = line.getLineIndex();
// 		List<Line> list = lineMapper.testName(name, lineIndex);
        //
// 		if (list.size() > 0) {
// 			return "更新失败a";
// 		} else {
        Line tmp = lineMapper.selectByPrimaryKey(line.getLineIndex());
        LineDetail temp = lineDetailMapper.selectByPrimaryKey(lineIndex);
        if (tmp == null) {
            return "更新失败";
        }

        if (line.getName() != null) {
            tmp.setName(line.getName());
        }
        if (line.getDlcMp() != null) {
            tmp.setDlcMp(line.getDlcMp());
        }
        if (line.getXycMp() != null) {
            tmp.setXycMp(line.getXycMp());
        }
        if (line.getDevcMp() != null) {
            tmp.setDevcMp(line.getDevcMp());
        }
        if (line.getCt1() != null) {
            tmp.setCt1(line.getCt1());
        }
        if (line.getCt2() != null) {
            tmp.setCt2(line.getCt2());
        }
        if (line.getPt1() != null) {
            tmp.setPt1(line.getPt1());
        }
        if (line.getPt2() != null) {
            tmp.setPt2(line.getPt2());
        }

        if (detail.getLineName() != null) {
            temp.setLineName(detail.getLineName());
        }
        if (detail.getPtType() != null) {
            temp.setPtType(detail.getPtType());
        }
        if (detail.getTInterval() != null) {
            temp.setTInterval(detail.getTInterval());
        }
        if (detail.getLoadType() != null) {
            temp.setLoadType(detail.getLoadType());
        }
        if (detail.getBusinessType() != null) {
            temp.setBusinessType(detail.getBusinessType());
        }
        if (detail.getRemark() != null) {
            temp.setRemark(detail.getRemark());
        } else if (temp.getRemark() == null) {
            temp.setRemark("");
        }
        if (detail.getMonitorId() != null) {
            temp.setMonitorId(detail.getMonitorId());
        } else if (temp.getMonitorId() == null) {
            temp.setMonitorId("");
        }
        temp.setLastTime(new Date());

        try {
            int flag = lineMapper.updateByPrimaryKey(tmp);
            int flag1 = lineDetailMapper.updateByPrimaryKey(temp);
            redisCacheUtil.clearConData();
            return "更新成功";
        } catch (Exception e) {
            return "更新失败";
        }
// 		}
    }


    @Override
    public List<NodeInformation> loadNodeInfo() {
        List<NodeInformation> result = new ArrayList<>();
        NodeInformation tmp = new NodeInformation();
        tmp.setNodeStatus(Long.valueOf("1"));

        result = nodeInformationMapper.select(tmp);
        if (CollectionUtil.isNotEmpty(result)) {
            result = result.stream().sorted(Comparator.comparing(NodeInformation::getNodeOrder)).collect(Collectors.toList());
        }
        return result;
    }

    @Override
    public String delNode(Long nodeIndex) {
        NodeInformation node = nodeInformationMapper.selectByPrimaryKey(nodeIndex);
        node.setNodeStatus(Long.valueOf("0"));
        try {
            nodeInformationMapper.updateByPrimaryKey(node);
            return "删除成功";
        } catch (Exception e) {
            return "删除失败";
        }
    }

    @Override
    public String saveNode(String nodeName, String nodeDesc, String ip4, String ip3, String ip2, String ip1, Integer nodeGrade, Integer nodeDevNum) {
        NodeInformation node = new NodeInformation();
        node.setNodeName(nodeName);
        node.setNodeStatus(Long.valueOf("1"));

        List<NodeInformation> tmp = nodeInformationMapper.select(node);

        if (tmp.size() > 0) {
            return "添加失败a";
        } else {
            Long index = nodeInformationMapper.selectMaxIndex();
            Integer order = nodeInformationMapper.getMaxOrder();
            if (Objects.isNull(order)) {
                order = 1;
            }
            node.setNodeIndex(index + 1);
            node.setNodeDesc(nodeDesc);
            node.setNodeIP(ip4 + "." + ip3 + "." + ip2 + "." + ip1);
            node.setNodeStatus(Long.valueOf(1));
            node.setNodeGrade(nodeGrade);
            node.setNodeDevNum(nodeDevNum);
            node.setNodeOrder(order + 1);
            try {
                nodeInformationMapper.insert(node);
                return "添加成功";
            } catch (Exception e) {
                return "添加失败";
            }
        }
    }

    @Override
    public List<String> loadNode(Long nodeIndex) {
        List<String> result = new ArrayList<>();
        NodeInformation tmp = new NodeInformation();

        tmp = nodeInformationMapper.selectByPrimaryKey(nodeIndex);

        result.add(tmp.getNodeName());
        result.add(tmp.getNodeDesc());


        String ip = tmp.getNodeIP();
        String[] ipn = ip.split("\\.");
        result.add(ipn[0]);
        result.add(ipn[1]);
        result.add(ipn[2]);
        result.add(ipn[3]);
        result.add(tmp.getNodeGrade().toString());

        if (Objects.nonNull(tmp.getNodeDevNum())) {
            result.add(tmp.getNodeDevNum().toString());
        } else {
            result.add("");
        }

        if (Objects.nonNull(tmp.getNodeOrder())) {
            result.add(tmp.getNodeOrder().toString());
        } else {
            result.add("");
        }

        return result;
    }

    @Override
    public String updateNode(Long nodeIndex, String nodeName, String nodeDesc, String ip4, String ip3, String ip2, String ip1, Integer nodeGrade, Integer nodeDevNum, Integer nodeOrder) {
        List<NodeInformation> tmp;

        tmp = nodeInformationMapper.testName(nodeName, nodeIndex);
        if (tmp.size() > 0) {
            return "更新失败a";
        } else {
            NodeInformation node = new NodeInformation();
            node.setNodeIndex(nodeIndex);
            node.setNodeName(nodeName);
            node.setNodeDesc(nodeDesc);
            node.setNodeIP(ip4 + "." + ip3 + "." + ip2 + "." + ip1);
            node.setNodeStatus(Long.valueOf(1));
            node.setNodeGrade(nodeGrade);
            node.setNodeDevNum(nodeDevNum);
            node.setNodeOrder(nodeOrder);
            try {
                nodeInformationMapper.updateByPrimaryKey(node);
                return "更新成功";
            } catch (Exception e) {
                return "更新失败";
            }
        }
    }

    @Override
    public List<Tree> getDeviceMainTree() {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "终端运维管理";

        List<Tree> list = new ArrayList<Tree>();

        List<Integer> index1 = new ArrayList<>();
        List<Integer> index0 = new ArrayList<>();
        List<Integer> index = new ArrayList<>();
        List<Tree> proj = treeMapper.getProjInfo();

        if (proj.size() == 0) {
            Tree dto = new Tree();
            dto.setId(100);
            dto.setNodeType(0);
            dto.setpId(0);
            dto.setPpId(0);
            dto.setName(dky);
            list.add(dto);
            return list;
        } else {
            Tree dt = new Tree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);

            //项目
            Map<Integer, Integer> value00 = new HashMap<Integer, Integer>();
            int p00 = pIdNumber / 10;
            for (int i = 0; i < proj.size(); i++) {
                Tree dto = new Tree();
                dto.setId(++p00);
                dto.setName(proj.get(i).getName());
                dto.setpId(100);
                dto.setPpId(100);
                dto.setNodeIndex(proj.get(i).getNodeIndex());
                dto.setNodeType(1);
                list.add(dto);
                value00.put(proj.get(i).getNodeIndex(), p00);
            }

            for (int i = 0; i < proj.size(); i++) {
                index0.add(proj.get(i).getNodeIndex());
            }
            List<Tree> pro = treeMapper.getProByProj(index0);

            //省份
            if (pro.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
            int p0 = pIdNumber;
            for (int i = 0; i < pro.size(); i++) {
                if (value00.get(pro.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p0);
                    dto.setName(userUtil.getDicnameByIndex(pro.get(i).getName()));
                    dto.setpId(value00.get(pro.get(i).getpId()));
                    dto.setPpId(pro.get(i).getpId());
                    dto.setNodeIndex(pro.get(i).getNodeIndex());
                    dto.setNodeType(2);
                    list.add(dto);
                    value0.put(pro.get(i).getNodeIndex(), p0);
                }
            }

            for (int m = 0; m < pro.size(); m++) {
                index1.add(pro.get(m).getNodeIndex());
            }
            List<Tree> gdInfo = treeMapper.getGdByPro(index1);

            //供电公司
            if (gdInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value = new HashMap<Integer, Integer>();
            int p = pIdNumber * 2;
            for (int i = 0; i < gdInfo.size(); i++) {
                if (value0.get(gdInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p);
                    dto.setName(gdInfo.get(i).getName());
                    dto.setpId(value0.get(gdInfo.get(i).getpId()));
                    dto.setPpId(gdInfo.get(i).getpId());
                    dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
                    dto.setNodeType(3);
                    list.add(dto);
                    value.put(gdInfo.get(i).getNodeIndex(), p);
                }
            }
            for (int n = 0; n < gdInfo.size(); n++) {
                index.add(gdInfo.get(n).getNodeIndex());
            }
            List<Tree> subInfo = treeMapper.getSubInfo(index);

            //变电站
            if (subInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
            int p1 = pIdNumber * 3;
            for (int i = 0; i < subInfo.size(); i++) {
                if (value.get(subInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p1);
                    dto.setName(subInfo.get(i).getName());
                    dto.setpId(value.get(subInfo.get(i).getpId()));
                    dto.setPpId(subInfo.get(i).getpId());
                    dto.setNodeIndex(subInfo.get(i).getNodeIndex());
                    dto.setNodeType(4);
                    list.add(dto);
                    value1.put(subInfo.get(i).getNodeIndex(), p1);
                }
            }

            List<Tree> devInfo = new ArrayList<>();
            String systype = TokenManager.getSysType();
            String systypezt = appConfig.getSysTypeZt();
            String systypewt = appConfig.getSysTypeWt();
            if (systype.equals(systypezt)) {
                devInfo = treeMapper.getDeviceZT(index);
            } else {
                devInfo = treeMapper.getDeviceWT(index);
            }

            //终端
            if (devInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();
            int p2 = pIdNumber * 4;
            for (int i = 0; i < devInfo.size(); i++) {
                if (value1.get(devInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p2);
                    dto.setName(devInfo.get(i).getName());
                    dto.setpId(value1.get(devInfo.get(i).getpId()));
                    dto.setPpId(devInfo.get(i).getpId());
                    dto.setNodeIndex(devInfo.get(i).getNodeIndex());
                    dto.setNodeType(5);
                    list.add(dto);
                    value2.put(devInfo.get(i).getNodeIndex(), p2);
                }
            }

            List<Tree> subvInfo = treeMapper.getSubv(index);

            //母线
            if (subvInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
            int p3 = pIdNumber * 5;
            for (int i = 0; i < subvInfo.size(); i++) {
                if (value2.get(subvInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p3);
                    dto.setName(subvInfo.get(i).getName());
                    dto.setpId(value2.get(subvInfo.get(i).getpId()));
                    dto.setPpId(subvInfo.get(i).getpId());
                    dto.setNodeIndex(subvInfo.get(i).getNodeIndex());
                    dto.setNodeType(6);
                    list.add(dto);
                    value3.put(subvInfo.get(i).getNodeIndex(), p3);
                }
            }

            List<Tree> lineInfo = treeMapper.getLineInfo(index);

            //监测点
            if (lineInfo.size() == 0) {
                return list;
            }
            int p4 = pIdNumber * 6;
            for (int i = 0; i < lineInfo.size(); i++) {
                if (value3.get(lineInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p4);
                    dto.setName(lineInfo.get(i).getName());
                    dto.setpId(value3.get(lineInfo.get(i).getpId()));
                    dto.setPpId(lineInfo.get(i).getpId());
                    dto.setNodeIndex(lineInfo.get(i).getNodeIndex());
                    dto.setNodeType(7);
                    dto.setState(lineInfo.get(i).getState());
                    dto.setStatus(lineInfo.get(i).getStatus());
                    list.add(dto);
                }
            }

            return list;
        }
    }


    /**
     * 获取冀北国网监测点台账设备树
     */
    @Override
    public List<Tree> getGWDeviceTree() {
        String dky = "台账管理";
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        List<Tree> list = new ArrayList<>();
        List<Integer> index = userUtil.getGWLine();
        if (index.size() == 0) {
            Tree dto = new Tree();
            dto.setId(100);
            dto.setNodeType(0);
            dto.setpId(0);
            dto.setPpId(0);
            dto.setName(dky);
            list.add(dto);
            return list;
        } else {
            Tree dt = new Tree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);

            List<Tree> proInfo = treeMapper.getTreeProInfo(index);
            List<Tree> gdInfo = treeMapper.getTreeGdInfoByGw(index);
            List<Tree> subInfo = treeMapper.getTreeSubInfoByGw(index);
            List<Tree> devInfo;
            if (appConfig.getSysType().equalsIgnoreCase(appConfig.getSysTypeWt())) {
                devInfo = treeMapper.getWTTreeDevInfo(index);
            } else {
                devInfo = treeMapper.getZTTreeDevInfo(index);
            }
            List<Tree> subvInfo = treeMapper.getTreeSubvInfoByGw(index);
            List<Tree> lineInfo = treeMapper.getLineInfoByGw(index);
            if (proInfo == null || gdInfo == null || subInfo == null || devInfo == null || subvInfo == null || lineInfo == null) {
                return list;
            }
            Map<Integer, Integer> value0 = new HashMap<>();
            int p0 = pIdNumber;
            for (int i = 0; i < proInfo.size(); i++) {
                Tree dto = new Tree();
                dto.setId(++p0);
                dto.setName(userUtil.getDicnameByIndex(proInfo.get(i).getName()));
                dto.setpId(100);
                dto.setPpId(100);
                dto.setNodeIndex(proInfo.get(i).getNodeIndex());
                dto.setNodeType(1);
                list.add(dto);
                value0.put(proInfo.get(i).getNodeIndex(), p0);
            }

            Map<Integer, Integer> value = new HashMap<>();
            int p = pIdNumber * 2;
            for (int i = 0; i < gdInfo.size(); i++) {
                Tree dto = new Tree();
                dto.setId(++p);
                dto.setName(gdInfo.get(i).getName());
                dto.setpId(value0.get(gdInfo.get(i).getpId()));
                dto.setPpId(gdInfo.get(i).getpId());
                dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
                dto.setNodeType(2);
                list.add(dto);
                value.put(gdInfo.get(i).getNodeIndex(), p);
            }

            Map<Integer, Integer> value1 = new HashMap<>();
            int p1 = pIdNumber * 3;
            for (int i = 0; i < subInfo.size(); i++) {
                if (value.get(subInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p1);
                    dto.setName(subInfo.get(i).getName());
                    dto.setpId(value.get(subInfo.get(i).getpId()));
                    dto.setPpId(subInfo.get(i).getpId());
                    dto.setNodeIndex(subInfo.get(i).getNodeIndex());
                    dto.setNodeType(3);
                    list.add(dto);
                    value1.put(subInfo.get(i).getNodeIndex(), p1);
                }
            }

            Map<Integer, Integer> value2 = new HashMap<>();
            int p2 = pIdNumber * 4;
            for (int i = 0; i < devInfo.size(); i++) {
                if (value1.get(devInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p2);
                    dto.setName(devInfo.get(i).getName());
                    dto.setpId(value1.get(devInfo.get(i).getpId()));
                    dto.setPpId(devInfo.get(i).getpId());
                    dto.setNodeIndex(devInfo.get(i).getNodeIndex());
                    dto.setNodeType(4);
                    dto.setIp(devInfo.get(i).getIp());
                    list.add(dto);
                    value2.put(devInfo.get(i).getNodeIndex(), p2);
                }
            }

            Map<Integer, Integer> value3 = new HashMap<>();
            int p3 = pIdNumber * 5;
            for (int i = 0; i < subvInfo.size(); i++) {
                if (value2.get(subvInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p3);
                    dto.setName(subvInfo.get(i).getName());
                    dto.setpId(value2.get(subvInfo.get(i).getpId()));
                    dto.setPpId(subvInfo.get(i).getpId());
                    dto.setNodeIndex(subvInfo.get(i).getNodeIndex());
                    dto.setNodeType(5);
                    list.add(dto);
                    value3.put(subvInfo.get(i).getNodeIndex(), p3);
                }
            }

            int p4 = pIdNumber * 6;
            for (int i = 0; i < lineInfo.size(); i++) {
                if (value3.get(lineInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p4);
                    dto.setName(lineInfo.get(i).getName());
                    dto.setpId(value3.get(lineInfo.get(i).getpId()));
                    dto.setPpId(lineInfo.get(i).getpId());
                    dto.setNodeIndex(lineInfo.get(i).getNodeIndex());
                    dto.setNodeIndexStr(lineInfo.get(i).getNodeIndexStr());
                    dto.setNodeType(6);
                    dto.setState(lineInfo.get(i).getState());
                    dto.setStatus(lineInfo.get(i).getStatus());
                    List<Integer> indexs = new ArrayList<>();
                    indexs.add(lineInfo.get(i).getNodeIndex());
                    list.add(dto);
                }
            }
            return list;
        }
    }

    @Override
    public int getConnect(Long lineIndex) {
        return deviceMapper.getConnect(lineIndex);
    }


    @Override
    public List<Tree> getDeviceTree() {

        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "台账管理";

        List<Tree> list = new ArrayList<Tree>();

        List<Integer> index1 = new ArrayList<>();
        List<Integer> index0 = new ArrayList<>();
        List<Integer> index = new ArrayList<>();
        List<Tree> proj = treeMapper.getProjInfo();

        if (proj.size() == 0) {
            Tree dto = new Tree();
            dto.setId(100);
            dto.setNodeType(0);
            dto.setpId(0);
            dto.setPpId(0);
            dto.setName(dky);
            list.add(dto);
            return list;
        } else {
            Tree dt = new Tree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);

            //项目
            Map<Integer, Integer> value00 = new HashMap<Integer, Integer>();
            int p00 = pIdNumber / 10;
            for (int i = 0; i < proj.size(); i++) {
                Tree dto = new Tree();
                dto.setId(++p00);
                dto.setName(proj.get(i).getName());
                dto.setpId(100);
                dto.setPpId(100);
                dto.setNodeIndex(proj.get(i).getNodeIndex());
                dto.setNodeType(1);
                list.add(dto);
                value00.put(proj.get(i).getNodeIndex(), p00);
            }

            for (int i = 0; i < proj.size(); i++) {
                index0.add(proj.get(i).getNodeIndex());
            }
            List<Tree> pro = treeMapper.getProByProj(index0);

            //省份
            if (pro.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
            int p0 = pIdNumber;
            for (int i = 0; i < pro.size(); i++) {
                if (value00.get(pro.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p0);
                    dto.setName(userUtil.getDicnameByIndex(pro.get(i).getName()));
                    dto.setpId(value00.get(pro.get(i).getpId()));
                    dto.setPpId(pro.get(i).getpId());
                    dto.setNodeIndex(pro.get(i).getNodeIndex());
                    dto.setNodeType(2);
                    list.add(dto);
                    value0.put(pro.get(i).getNodeIndex(), p0);
                }
            }

            for (int m = 0; m < pro.size(); m++) {
                index1.add(pro.get(m).getNodeIndex());
            }
            List<Tree> gdInfo = treeMapper.getGdByPro(index1);

            //供电公司
            if (gdInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value = new HashMap<Integer, Integer>();
            int p = pIdNumber * 2;
            for (int i = 0; i < gdInfo.size(); i++) {
                if (value0.get(gdInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p);
                    dto.setName(gdInfo.get(i).getName());
                    dto.setpId(value0.get(gdInfo.get(i).getpId()));
                    dto.setPpId(gdInfo.get(i).getpId());
                    dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
                    dto.setNodeType(3);
                    list.add(dto);
                    value.put(gdInfo.get(i).getNodeIndex(), p);
                }
            }
            for (int n = 0; n < gdInfo.size(); n++) {
                index.add(gdInfo.get(n).getNodeIndex());
            }
            List<Tree> subInfo = treeMapper.getSubInfo(index);

            //变电站
            if (subInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
            int p1 = pIdNumber * 3;
            for (int i = 0; i < subInfo.size(); i++) {
                if (value.get(subInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p1);
                    dto.setName(subInfo.get(i).getName());
                    dto.setpId(value.get(subInfo.get(i).getpId()));
                    dto.setPpId(subInfo.get(i).getpId());
                    dto.setNodeIndex(subInfo.get(i).getNodeIndex());
                    dto.setNodeType(4);
                    list.add(dto);
                    value1.put(subInfo.get(i).getNodeIndex(), p1);
                }
            }

            List<Tree> devInfo = new ArrayList<>();
            String systype = TokenManager.getSysType();
            String systypezt = appConfig.getSysTypeZt();
            String systypewt = appConfig.getSysTypeWt();
            if (systype.equals(systypezt)) {
                devInfo = treeMapper.getDeviceZT(index);
            } else {
                devInfo = treeMapper.getDeviceWT(index);
            }

            //终端
            if (devInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();
            int p2 = pIdNumber * 4;
            for (int i = 0; i < devInfo.size(); i++) {
                if (value1.get(devInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p2);
                    dto.setName(devInfo.get(i).getName());
                    dto.setpId(value1.get(devInfo.get(i).getpId()));
                    dto.setPpId(devInfo.get(i).getpId());
                    dto.setNodeIndex(devInfo.get(i).getNodeIndex());
                    dto.setNodeType(5);
                    list.add(dto);
                    value2.put(devInfo.get(i).getNodeIndex(), p2);
                }
            }

            List<Tree> subvInfo = treeMapper.getSubv(index);

            //母线
            if (subvInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
            int p3 = pIdNumber * 5;
            for (int i = 0; i < subvInfo.size(); i++) {
                if (value2.get(subvInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p3);
                    dto.setName(subvInfo.get(i).getName());
                    dto.setpId(value2.get(subvInfo.get(i).getpId()));
                    dto.setPpId(subvInfo.get(i).getpId());
                    dto.setNodeIndex(subvInfo.get(i).getNodeIndex());
                    dto.setNodeType(6);
                    list.add(dto);
                    value3.put(subvInfo.get(i).getNodeIndex(), p3);
                }
            }

            List<Tree> lineInfo = treeMapper.getLineInfo(index);

            //监测点
            if (lineInfo.size() == 0) {
                return list;
            }
            int p4 = pIdNumber * 6;
            for (int i = 0; i < lineInfo.size(); i++) {
                if (value3.get(lineInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p4);
                    dto.setName(lineInfo.get(i).getName());
                    dto.setpId(value3.get(lineInfo.get(i).getpId()));
                    dto.setPpId(lineInfo.get(i).getpId());
                    dto.setNodeIndex(lineInfo.get(i).getNodeIndex());
                    dto.setNodeType(7);
                    dto.setState(lineInfo.get(i).getState());
                    dto.setStatus(lineInfo.get(i).getStatus());
                    list.add(dto);
                }
            }

            return list;
        }
    }

    /**
     * @Author chendaofei
     * @Description 仅仅获取终端设备（供电公司+变电+设备）
     * @Date 14:07 2020/7/24
     **/
    @Override
    public List<Tree> getTerminalDeviceTree() {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "台账管理";

        List<Tree> list = new ArrayList<Tree>();

        List<Integer> index1 = new ArrayList<>();
        List<Integer> index0 = new ArrayList<>();
        List<Integer> index = new ArrayList<>();
        List<Tree> proj = treeMapper.getProjInfo();

        if (proj.size() == 0) {
            Tree dto = new Tree();
            dto.setId(100);
            dto.setNodeType(0);
            dto.setpId(0);
            dto.setPpId(0);
            dto.setName(dky);
            list.add(dto);
            return list;
        } else {
            Tree dt = new Tree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);

            //项目
            Map<Integer, Integer> value00 = new HashMap<Integer, Integer>();
            int p00 = pIdNumber / 10;
            for (int i = 0; i < proj.size(); i++) {
                Tree dto = new Tree();
                dto.setId(++p00);
                dto.setName(proj.get(i).getName());
                dto.setpId(100);
                dto.setPpId(100);
                dto.setNodeIndex(proj.get(i).getNodeIndex());
                dto.setNodeType(1);
                list.add(dto);
                value00.put(proj.get(i).getNodeIndex(), p00);
            }

            for (int i = 0; i < proj.size(); i++) {
                index0.add(proj.get(i).getNodeIndex());
            }
            List<Tree> pro = treeMapper.getProByProj(index0);

            //省份
            if (pro.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
            int p0 = pIdNumber;
            for (int i = 0; i < pro.size(); i++) {
                if (value00.get(pro.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p0);
                    dto.setName(userUtil.getDicnameByIndex(pro.get(i).getName()));
                    dto.setpId(value00.get(pro.get(i).getpId()));
                    dto.setPpId(pro.get(i).getpId());
                    dto.setNodeIndex(pro.get(i).getNodeIndex());
                    dto.setNodeType(2);
                    list.add(dto);
                    value0.put(pro.get(i).getNodeIndex(), p0);
                }
            }

            for (int m = 0; m < pro.size(); m++) {
                index1.add(pro.get(m).getNodeIndex());
            }
            List<Tree> gdInfo = treeMapper.getGdByPro(index1);

            //供电公司
            if (gdInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value = new HashMap<Integer, Integer>();
            int p = pIdNumber * 2;
            for (int i = 0; i < gdInfo.size(); i++) {
                if (value0.get(gdInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p);
                    dto.setName(gdInfo.get(i).getName());
                    dto.setpId(value0.get(gdInfo.get(i).getpId()));
                    dto.setPpId(gdInfo.get(i).getpId());
                    dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
                    dto.setNodeType(3);
                    list.add(dto);
                    value.put(gdInfo.get(i).getNodeIndex(), p);
                }
            }
            for (int n = 0; n < gdInfo.size(); n++) {
                index.add(gdInfo.get(n).getNodeIndex());
            }
            List<Tree> subInfo = treeMapper.getSubInfo(index);

            //变电站
            if (subInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
            int p1 = pIdNumber * 3;
            for (int i = 0; i < subInfo.size(); i++) {
                if (value.get(subInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p1);
                    dto.setName(subInfo.get(i).getName());
                    dto.setpId(value.get(subInfo.get(i).getpId()));
                    dto.setPpId(subInfo.get(i).getpId());
                    dto.setNodeIndex(subInfo.get(i).getNodeIndex());
                    dto.setNodeType(4);
                    list.add(dto);
                    value1.put(subInfo.get(i).getNodeIndex(), p1);
                }
            }

            List<Tree> devInfo = new ArrayList<>();
            String systype = TokenManager.getSysType();
            String systypezt = appConfig.getSysTypeZt();
            if (systype.equals(systypezt)) {
                devInfo = treeMapper.getDeviceZT(index);
            } else {
                devInfo = treeMapper.getDeviceWT(index);
            }

            //终端
            if (devInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();
            int p2 = pIdNumber * 4;
            for (int i = 0; i < devInfo.size(); i++) {
                if (value1.get(devInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p2);
                    dto.setName(devInfo.get(i).getName());
                    dto.setpId(value1.get(devInfo.get(i).getpId()));
                    dto.setPpId(devInfo.get(i).getpId());
                    dto.setNodeIndex(devInfo.get(i).getNodeIndex());
                    dto.setNodeType(5);
                    list.add(dto);
                    value2.put(devInfo.get(i).getNodeIndex(), p2);
                }
            }

            return list;
        }
    }


    @Override
    public List<DeviceDetail> getDeviceDetails(String status, String devflag, String gdName, String
            manufacturer, String area, String type) {
        List<DeviceDetail> result = new ArrayList<>();

        List<Integer> listline = userUtil.listLineDepts(area);
        if("1".equals(type)){
            listline =getGwLine(listline);
        }
        if (listline.size() == 0) {
            return null;
        } else {
            if (listline.size() > 1000) {
                int count = listline.size() / 1000 + 1;
                for (int i = 0; i < count; i++) {
                    List<DeviceDetail> deviceDetails = new ArrayList<>();
                    if (listline.size() > 1000) {
                        List<Integer> temLine = listline.subList(0, 1000);
                        deviceDetails = deviceDetailMapper.getDeviceDetails(status, devflag, gdName, manufacturer, temLine);
                        temLine.clear();
                    } else {
                        deviceDetails = deviceDetailMapper.getDeviceDetails(status, devflag, gdName, manufacturer, listline);
                    }
                    if (CollectionUtil.isNotEmpty(deviceDetails)) {
                        result.addAll(deviceDetails);
                    }
                }

            } else {
                result = deviceDetailMapper.getDeviceDetails(status, devflag, gdName, manufacturer, listline);
            }
            return result;
        }
    }

    @Override
    public List<DeviceDetail> getGdname() {
        List<DeviceDetail> result = new ArrayList<>();

        List<Integer> listGD = userUtil.listGD();
        if (listGD.size() > 1000) {
            int count = listGD.size() / 1000 + 1;
            for (int i = 0; i < count; i++) {
                List<DeviceDetail> deviceDetails = new ArrayList<>();
                if (listGD.size() > 1000) {
                    List<Integer> temLine = listGD.subList(0, 1000);
                    deviceDetails = deviceDetailMapper.getGdname(temLine);
                    temLine.clear();
                } else {
                    deviceDetails = deviceDetailMapper.getGdname(listGD);
                }
                if (CollectionUtil.isNotEmpty(deviceDetails)) {
                    result.addAll(deviceDetails);
                }
            }
        } else {
            result = deviceDetailMapper.getGdname(listGD);
        }

        return result;
    }

    @Override
    public List<DeviceDetail> getManufacturers() {
        List<DeviceDetail> result = new ArrayList<>();

        List<Integer> listline = userUtil.listLine();

        if (listline.size() > 1000) {
            int count = listline.size() / 1000 + 1;
            for (int i = 0; i < count; i++) {
                List<DeviceDetail> deviceDetails = new ArrayList<>();
                if (listline.size() > 1000) {
                    List<Integer> temLine = listline.subList(0, 1000);
                    deviceDetails = deviceDetailMapper.getManufacturers(temLine);
                    temLine.clear();
                } else {
                    deviceDetails = deviceDetailMapper.getManufacturers(listline);
                }
                if (CollectionUtil.isNotEmpty(deviceDetails)) {
                    //去重
                    result.addAll(deviceDetails);
                    result = result.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<DeviceDetail>(Comparator.comparing(DeviceDetail::getManufacturer))), ArrayList::new));
                }
            }
        } else {
            result = deviceDetailMapper.getManufacturers(listline);
        }
        return result;
    }

    @Override
    public List<DeviceDetail> queryDeviceDetailById(String lineIndex) {
        List<DeviceDetail> result;
        Line line = lineMapper.selectByPrimaryKey(Long.valueOf(lineIndex));
        Long devIndex = line.getDevIndex();

        result = deviceDetailMapper.queryDeviceDetailById(devIndex);
        return result;
    }

    @Override
    public List<DeviceDetail> getSelName(String name) {
        return deviceDetailMapper.getSelName(name);
    }

    @Override
    public Device selectDeviceByIndex(Long devIndex) {
        Device device = new Device();
        device.setDevIndex(devIndex);
        device = deviceMapper.selectOne(device);
        return device;
    }

    @Override
    public Device getDevflag(Long name) {
        Device d = new Device();
        d.setDevIndex(name);
        return deviceMapper.selectOne(d);
    }

    @Override
    public Device devNameType(String devName) {
        return deviceMapper.devNameType(devName);
    }

    @Override
    public Device devIndexType(String devIndex) {
        return deviceMapper.devIndexType(Long.valueOf(devIndex));
    }

    @Override
    public Device devIndexsType(String lineIndex) {
        return deviceMapper.devIndexsType(Long.valueOf(lineIndex));
    }

    /**
     * 概览--》获取终端状态滚动事件
     */
    @Override
    public List<DeviceDetail> getTj() {
        List<Integer> list = userUtil.listLineRun();
        List<DeviceDetail> deviceDetails = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(list)) {
            if (list.size() > 1000) {
                Integer all = 0;
                int count = list.size() / 1000 + 1;
                for (int i = 0; i < count; i++) {
                    List<DeviceDetail> temList = null;
                    if (list.size() > 1000) {
                        List<Integer> subLine = list.subList(0, 1000);
                        temList = deviceDetailMapper.getTj(subLine);
                        subLine.clear();
                    } else {
                        temList = deviceDetailMapper.getTj(list);
                    }
                    if (CollectionUtil.isNotEmpty(temList)) {
                        all += temList.get(0).getyAxis().intValue();
                    }
                }
                DeviceDetail deviceDetail = new DeviceDetail();
                deviceDetail.setyAxis(all.longValue());
                deviceDetails.add(deviceDetail);
            } else {
                deviceDetails = deviceDetailMapper.getTj(list);
            }
        }
        return deviceDetails;
    }


    /**
     * 按电压等级
     *
     * @param endTime   起始时间
     * @param startTime 截止时间
     */
    private List<DeviceValue> getVolData(List<Integer> devIndexs, Date startTime, Date endTime) {
        // 电压等级的数据字典
        List<DeviceValue> vol = new ArrayList<>();
        List<VoltageData> voltageData = userUtil.getVoltageData(devIndexs);
        if (CollectionUtils.isEmpty(voltageData)) {
            return null;
        } else {
            for (VoltageData vols : voltageData) {
                if (!CollectionUtils.isEmpty(vols.getDeviceIndexs())) {
                    DeviceValue de = getDeviceValueVol(vols, startTime, endTime);
                    vol.add(de);
                }
            }
            return vol;
        }
    }


    /**
     * 根据电压等级获取运行状态
     *
     * @param voltageData 电压等级数据
     * @param startTime   起始时间
     * @param endTime     截止时间
     */
    private DeviceValue getDeviceValueVol(VoltageData voltageData, Date startTime, Date endTime) {
        DeviceValue deviceValue = new DeviceValue();
        // 电压等级
        deviceValue.setName(voltageData.getVol());
        // ******监测点数
        if (CollectionUtils.isEmpty(voltageData.getLineIndexs())) {
            deviceValue.setAmounts("0");
        } else {
            deviceValue.setAmounts(String.valueOf(voltageData.getLineIndexs().size()));
        }
        // ****************运行状态
        List<Device> devices = getDevicesByDevIndexs(voltageData.getDeviceIndexs());
        Status status = getStatus(devices);
        deviceValue.setStatus(status);
        return deviceValue;

    }


    /**
     * 根据终端索引获取终端信息（只需要运行状态字段）
     * 添加进redis
     * key为：方法名+参数toString
     *
     * @param devIndex 终端索引
     */
    private List<Device> getDevicesByDevIndexs(List<Integer> devIndex) {
        if (CollectionUtils.isEmpty(devIndex)) {
            return null;
        }
        List<Device> tempDevice = new ArrayList<>();
        List<Integer> lineIndexTemp = new ArrayList<>(devIndex);
        String key = "getDevicesByDevIndexs";
        for (Integer i : devIndex) {
            key = key + i;
        }
        try {
            jedisManager.deleteByKey(RedisDB.SHORT_TIME_QUERY, key);
            String jsonStr = jedisManager.getValueByKey(RedisDB.SHORT_TIME_QUERY, key);
            if (org.apache.commons.lang.StringUtils.isBlank(jsonStr)) {
                //分片1000个终端
                int length = lineIndexTemp.size();
                if (length > 1000) {
                    //需要循环的次数
                    int times = length / 1000 + 1;
                    for (int i = 1; i <= times; i++) {
                        if (length > 1000) {
                            List<Integer> temp = lineIndexTemp.subList(0, 999);
                            List<Device> tempList;
                            tempList = deviceMapper.getDevicesByDevIndexs(temp);
                            tempDevice.addAll(tempList);
                            temp.clear();
                            length = length - 1000;
                        } else {
                            List<Device> tempList;
                            tempList = deviceMapper.getDevicesByDevIndexs(lineIndexTemp);
                            tempDevice.addAll(tempList);
                        }
                    }
                } else {
                    tempDevice = deviceMapper.getDevicesByDevIndexs(lineIndexTemp);
                }
                JSONArray ja = JSONArray.fromObject(tempDevice);
                String value = ja.toString();
                jedisManager.saveValueByKey(RedisDB.SHORT_TIME_QUERY, key, value, RedisDB.SHORT_TIME);
            } else {
                JSONArray ja = JSONArray.fromObject(jsonStr);
                tempDevice = (List<Device>) JSONArray.toCollection(ja, Device.class);
            }
        } catch (Exception e) {
            logger.error("redis缓存的存取出现异常，方法为：getDevicesByDevIndexs");
        }
        return tempDevice;


    }


    @Override
    public List<DeviceDetail> getDevtype() {
        List<DeviceDetail> result;

        result = deviceDetailMapper.getDevtype(userUtil.listLine());
        return result;
    }

    @Override
    public List<DeviceDetail> getManufacturer() {
        List<DeviceDetail> result = new ArrayList<>();

        result = deviceDetailMapper.getManufacturer(userUtil.listLine());

        return result;
    }

    @Override
    public List<DeviceDetail> getScale() {
        List<DeviceDetail> result;

        result = deviceDetailMapper.getScale(userUtil.listLine());

        return result;
    }

    @Override
    public List<DeviceDetail> getArea() {
        List<DeviceDetail> result = new ArrayList<>();

        // 获取到用户的部门，根据部门node判断是否为省级专职
        List<AreaGeneralData> areaGeneral = userUtil.getAreaGeneral();
        if (!CollectionUtils.isEmpty(areaGeneral)) {
            // 按区域
            for (AreaGeneralData areaData : areaGeneral) {
                DeviceDetail deviceValue = new DeviceDetail();
                if (areaData.getMonitors() != 0) {
                    // 区域名
                    deviceValue.setArea(areaData.getName());
                    // 检测点数
                    deviceValue.setyAxis((long) areaData.getDeviceIndexs().size());
                    result.add(deviceValue);
                }
            }
        }
        return result;
    }

    @Override
    public NodeInformation setIp(int nodeIdex) {
        return nodeInformationMapper.setIp(nodeIdex);
    }

    /*
     * 获取暂降点图数据
     *
     * @see
     * com.pqs9200.service.configuration.DeviceService#getEventDataList(java.
     * lang.String, java.lang.String, int)
     */
    @Override
    public List<EventDataList> getEventDataList(Date startTime, Date endTime, String lineIndex) {
        List<EventDataList> result = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        result = eventdataMapper.getEventDataList(Integer.parseInt(lineIndex), startTime, endTime);

        for (int i = 0; i < result.size(); i++) {
            float per = (float) (Math.round((result.get(i).getPersisttime()) * 100)) / 100;
            float eve = (float) (Math.round(result.get(i).getEventvalue() * 100 * 100)) / 100;

            result.get(i).setEventvalue(eve);
        }

        return result;
    }

    /**
     * 根据用户选择的时间区间返回月份日期
     */
    private List<String> getIntervalTime(String startTime, String endTime) {
        List<String> times = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Date start = null;
        Date end = null;
        try {
            start = sdf.parse(startTime);
            end = sdf.parse(endTime);
        } catch (ParseException e) {
            logger.error("时间转化发生异常，异常是" + e.getMessage());
        }
        // 同月
        if (start.getTime() == end.getTime()) {
            String time = startTime.substring(0, 7);
            times.add(time);
        } else if (start.getYear() == end.getYear()) {
            // 同年
            int startM = start.getMonth() + 1;
            int endM = end.getMonth() + 1;
            int temp = endM - startM;
            for (int i = 0; i <= temp; i++) {
                String time = start.getYear() + 1900 + "";
                int month = startM + i;
                if (month < 10) {
                    time = time + "-0" + month;
                } else {
                    time = time + "-" + month;
                }
                times.add(time);
            }
        } else {
            // 不同年!!!!这里忽略了年份之间跨年的情况
            int startY = start.getYear() + 1900;
            int startM = start.getMonth() + 1;
            int endY = end.getYear() + 1900;
            int endM = end.getMonth() + 1;
            int tempS = 12 - startM;
            // 连续的年份
            if (endY - startY == 1) {
                // 第一年的时间获取
                for (int i = 0; i <= tempS; i++) {
                    int month = startM + i;
                    String time = startY + "-";
                    if (month < 10) {
                        time = time + "0" + month;
                    } else {
                        time = time + month;
                    }
                    times.add(time);
                }
                // 第二年的时间获取

                for (int i = 1; i <= endM; i++) {
                    String time = endY + "-";
                    if (i < 10) {
                        time = time + "0" + i;
                    } else {
                        time = time + i;
                    }
                    times.add(time);
                }
            } else {
                // 不连续的年份
                // 第一年的时间获取
                for (int i = 0; i <= tempS; i++) {
                    int month = startM + i;
                    String time = startY + "-";
                    if (month < 10) {
                        time = time + "0" + month;
                    } else {
                        time = time + month;
                    }
                    times.add(time);
                }
                int tempY = endY - startY;
                // 中间年份的时间
                for (int i = 1; i < tempY; i++) {
                    for (int j = 1; j <= 12; j++) {
                        String time = startY + i + "-";
                        if (j < 10) {
                            time = time + "0" + j;
                        } else {
                            time = time + j;
                        }
                        times.add(time);
                    }
                }
                // 最后一年的时间获取
                for (int i = 1; i <= endM; i++) {
                    String time = endY + "-";
                    if (i < 10) {
                        time = time + "0" + i;
                    } else {
                        time = time + i;
                    }
                    times.add(time);
                }
            }

        }
        return times;
    }

    @Override
    public List<Interval> getEventTime(Date startTime, Date endTime, String lineIndex) {
        List<Interval> result = new ArrayList<>();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        // 获取两个时间的之间的月份
        List<String> intervalTime = this.getIntervalTime(sdf.format(startTime), sdf.format(endTime));
        for (String interTime : intervalTime) {
            Interval inter = new Interval();
            inter.setMonth(interTime.substring(5));
            inter.setYear(interTime.substring(0, 4));
            // 从事件总汇表获取对应时间的所有事件数量
            Integer count = 0;

            count = eventdataMapper.getCountsByInterval(Integer.parseInt(lineIndex), interTime);

            if (null == count) {
                count = 0;
            }
            // 获取当前月的事件总数
            inter.setTimes(count);
            result.add(inter);
        }

        return result;
    }

    @Override
    public List<EventTypeList> getEventType(Date startTime, Date endTime, String lineIndex) {
        return eventdataMapper.getEventTypeCount(Integer.parseInt(lineIndex), startTime, endTime);
    }

    @Override
    public List<EventCause> getEventCause(Date startTime, Date endTime, String lineIndex) {
        List<EventCause> result = new ArrayList<>();
        List<EventDataList> typeresult;
        List<DicData> name;
        DicType type;
        typeresult = eventdataMapper.getEventDataList(Integer.parseInt(lineIndex), startTime, endTime);

        String dicTypename = "暂降原因";
        type = dicDataTypeMapper.querybyname(dicTypename);
        String typrid = type.getDicTypeIndex();
        name = dicDataMapper.selAll(type.getDicTypeIndex());

//        EventCause t1 = new EventCause();
//        EventCause t2 = new EventCause();
//        EventCause t3 = new EventCause();
//        EventCause t4 = new EventCause();
//
//        t1.setCause(name.get(3).getDicName());
//        t2.setCause(name.get(2).getDicName());
//        t3.setCause(name.get(1).getDicName());
//        t4.setCause(name.get(0).getDicName());

        for (DicData n : name) {
            EventCause t = new EventCause();
            t.setCause(n.getDicName());
            for (EventDataList r : typeresult) {
                if (r.getEventReason().equals(n.getDicName())) {
                    t.setCount(t.getCount() + 1);
                }
            }
            result.add(t);
        }

//        for (int i = 0; i < typeresult.size(); i++) {
//            if (typeresult.get(i).getEventReason() != null) {
//                if (typeresult.get(i).getEventReason().equals(name.get(3).getDicName())) {
//                    t1.setCount(t1.getCount() + 1);
//                } else if (typeresult.get(i).getEventReason().equals(name.get(2).getDicName())) {
//                    t2.setCount(t2.getCount() + 1);
//                } else if (typeresult.get(i).getEventReason().equals(name.get(1).getDicName())) {
//                    t3.setCount(t3.getCount() + 1);
//                } else if (typeresult.get(i).getEventReason().equals(name.get(0).getDicName())) {
//                    t4.setCount(t4.getCount() + 1);
//                }
//            }
//        }
//
//        result.add(t1);
//        result.add(t2);
//        result.add(t3);
//        result.add(t4);

        return result;
    }

    @Override
    public ReasonStatisc eventStatistic(Date startTime, Date endTime, String lineIndex) {
        ReasonStatisc result = new ReasonStatisc();
        List<StatisticsEventDetail> detail = new ArrayList<>();
        List<Integer> linesIndex = new ArrayList<>();
        linesIndex.add(Integer.valueOf(lineIndex));
        if (linesIndex.isEmpty()) {
            detail = null;
        } else {
            detail = eventDetailMapper.queryEventDetail(startTime, endTime, linesIndex);
        }
        //初始化集合
        List<VoltageReason> reasons = new ArrayList<>();
        List<DicData> voltageReason = redisCacheUtil.getVoltageReason();
        for (DicData dicData : voltageReason) {
            VoltageReason temp = new VoltageReason();
            temp.setReason(dicData.getDicName());
            temp.setTimes(0);
            reasons.add(temp);
        }

        List<VoltageType> types = new ArrayList<>();
        List<String> names = new ArrayList<>();
        List<DicData> voltageType = redisCacheUtil.getVoltageType();
        for (DicData dicData : voltageType) {
            if (!names.contains(dicData.getBackUp())) {
                names.add(dicData.getBackUp());
            }
        }
        for (String name : names) {
            VoltageType temp = new VoltageType();
            temp.setType(name);
            temp.setTimes(0);
            types.add(temp);
        }

        if (CollectionUtils.isEmpty(detail)) {
            reasons = null;
            types = null;
        } else {
            for (StatisticsEventDetail d : detail) {
                for (VoltageReason volR : reasons) {
                    if (volR.getReason().equalsIgnoreCase(d.getEventReason())) {
                        volR.setTimes(volR.getTimes() + 1);
                        if (d.getEventReason().equalsIgnoreCase("短路故障")) {
                            for (VoltageType volT : types) {
                                if (volT.getType().equalsIgnoreCase(d.getEventType())) {
                                    volT.setTimes(volT.getTimes() + 1);
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }

        result.setDetail(detail);
        result.setReasons(reasons);
        result.setTypes(types);
        return result;
    }

    @Override
    public EventChance getEventChance(Date startTime, Date endTime, String lineIndex) {
        EventChance result = new EventChance();

        List<EventDataList> info = new ArrayList<>();

        info = eventdataMapper.getEventDataList(Integer.parseInt(lineIndex), startTime, endTime);

        int totalnum = info.size();
        int sist1 = 0;
        int sist2 = 0;
        int sist3 = 0;
        int sist4 = 0;
        int sist5 = 0;
        int sist6 = 0;
        int sist7 = 0;
        int sist8 = 0;
        int value1 = 0;
        int value2 = 0;
        int value3 = 0;
        int value4 = 0;
        int value5 = 0;
        int value6 = 0;
        int value7 = 0;
        int value8 = 0;

        int persist1 = 0;
        int persist2 = 0;
        int persist3 = 0;
        int persist4 = 0;
        int persist5 = 0;
        int persist6 = 0;
        int persist7 = 0;
        int persist8 = 0;
        int pervalue1 = 0;
        int pervalue2 = 0;
        int pervalue3 = 0;
        int pervalue4 = 0;
        int pervalue5 = 0;
        int pervalue6 = 0;
        int pervalue7 = 0;
        int pervalue8 = 0;
        for (int i = 0; i < totalnum; i++) {
            float persisttime = info.get(i).getPersisttime();
            float eventValue = info.get(i).getEventvalue() * 100;

            if (persisttime < 0.100 && persisttime > 0.01) {
                persist1++;
                persist2++;
                persist3++;
                persist4++;
                persist5++;
                persist6++;
                persist7++;
                persist8++;
                sist1++;
            } else if (persisttime < 0.250) {
                persist2++;
                persist3++;
                persist4++;
                persist5++;
                persist6++;
                persist7++;
                persist8++;
                sist2++;
            } else if (persisttime < 0.500) {
                persist3++;
                persist4++;
                persist5++;
                persist6++;
                persist7++;
                persist8++;
                sist3++;
            } else if (persisttime < 1.000) {
                persist4++;
                persist5++;
                persist6++;
                persist7++;
                persist8++;
                sist4++;
            } else if (persisttime < 3.000) {
                persist5++;
                persist6++;
                persist7++;
                persist8++;
                sist5++;
            } else if (persisttime < 20.000) {
                persist6++;
                persist7++;
                persist8++;
                sist6++;
            } else if (persisttime < 60.000) {
                persist7++;
                persist8++;
                sist7++;
            } else if (persisttime < 180.000) {
                persist8++;
                sist8++;
            }

            if (eventValue < 10) {
                value1++;
                value2++;
                value3++;
                value4++;
                value5++;
                value6++;
                value7++;
                value8++;
                pervalue1++;
            } else if (eventValue < 20) {
                value2++;
                value3++;
                value4++;
                value5++;
                value6++;
                value7++;
                value8++;
                pervalue2++;
            } else if (eventValue < 30) {
                value3++;
                value4++;
                value5++;
                value6++;
                value7++;
                value8++;
                pervalue3++;
            } else if (eventValue < 40) {
                value4++;
                value5++;
                value6++;
                value7++;
                value8++;
                pervalue4++;
            } else if (eventValue < 50) {
                value5++;
                value6++;
                value7++;
                value8++;
                pervalue5++;
            } else if (eventValue < 60) {
                value6++;
                value7++;
                value8++;
                pervalue6++;
            } else if (eventValue < 70) {
                value7++;
                value8++;
                pervalue7++;
            } else if (eventValue < 80) {
                value8++;
                pervalue8++;
            }
        }

        List<String> sis = new ArrayList<>();
        List<String> val = new ArrayList<>();
        List<String> persis = new ArrayList<>();
        List<String> perval = new ArrayList<>();

        DecimalFormat df = new DecimalFormat("#.00");

        List<String> zero = new ArrayList<>();
        for (int m = 0; m < 9; m++) {
            zero.add("0");
        }

        if (totalnum == 0) {
            sis.addAll(zero);
            persis.addAll(zero);
            val.addAll(zero);
            val.add("0");
            perval.addAll(zero);
        } else {
            sis.add(df.format((float) 0));
            sis.add(df.format(((float) persist1 / (float) totalnum) * 100));
            sis.add(df.format(((float) persist2 / (float) totalnum) * 100));
            sis.add(df.format(((float) persist3 / (float) totalnum) * 100));
            sis.add(df.format(((float) persist4 / (float) totalnum) * 100));
            sis.add(df.format(((float) persist5 / (float) totalnum) * 100));
            sis.add(df.format(((float) persist6 / (float) totalnum) * 100));
            sis.add(df.format(((float) persist7 / (float) totalnum) * 100));
            sis.add(df.format(((float) persist8 / (float) totalnum) * 100));

            persis.add(df.format((float) 0));
            persis.add(df.format(((float) sist1 / (float) totalnum) * 100));
            persis.add(df.format(((float) sist2 / (float) totalnum) * 100));
            persis.add(df.format(((float) sist3 / (float) totalnum) * 100));
            persis.add(df.format(((float) sist4 / (float) totalnum) * 100));
            persis.add(df.format(((float) sist5 / (float) totalnum) * 100));
            persis.add(df.format(((float) sist6 / (float) totalnum) * 100));
            persis.add(df.format(((float) sist7 / (float) totalnum) * 100));
            persis.add(df.format(((float) sist8 / (float) totalnum) * 100));

            val.add(df.format((float) 0));
            val.add(df.format(((float) value1 / (float) totalnum) * 100));
            val.add(df.format(((float) value2 / (float) totalnum) * 100));
            val.add(df.format(((float) value3 / (float) totalnum) * 100));
            val.add(df.format(((float) value4 / (float) totalnum) * 100));
            val.add(df.format(((float) value5 / (float) totalnum) * 100));
            val.add(df.format(((float) value6 / (float) totalnum) * 100));
            val.add(df.format(((float) value7 / (float) totalnum) * 100));
            val.add(df.format(((float) value8 / (float) totalnum) * 100));
            val.add(df.format((float) 100));

            perval.add(df.format((float) 0));
            perval.add(df.format(((float) pervalue1 / (float) totalnum) * 100));
            perval.add(df.format(((float) pervalue2 / (float) totalnum) * 100));
            perval.add(df.format(((float) pervalue3 / (float) totalnum) * 100));
            perval.add(df.format(((float) pervalue4 / (float) totalnum) * 100));
            perval.add(df.format(((float) pervalue5 / (float) totalnum) * 100));
            perval.add(df.format(((float) pervalue6 / (float) totalnum) * 100));
            perval.add(df.format(((float) pervalue7 / (float) totalnum) * 100));
            perval.add(df.format(((float) pervalue8 / (float) totalnum) * 100));
        }
        result.setEventvalue(val);
        result.setSisttime(sis);
        result.setPereventvalue(perval);
        result.setPersisttime(persis);

        return result;
    }

    /*
     * 获取暂降密度图数据
     *
     * @see
     * com.pqs9200.service.configuration.DeviceService#getEventDensity(java.lang
     * .String, java.lang.String, int)
     */
    public List<EventDensity> getEventDensity(Date startTime, Date endTime, String lineIndex) {
        List<EventDensity> result = new ArrayList<>();
        List<EventDataList> info = new ArrayList<>();

        info = eventdataMapper.getEventDataList(Integer.parseInt(lineIndex), startTime, endTime);

        EventDensity a0 = new EventDensity();
        a0.setX(0);
        a0.setY(0);
        a0.setZ(0);
        result.add(a0);
        EventDensity a1 = new EventDensity();
        a1.setX(0);
        a1.setY(1);
        a1.setZ(0);
        result.add(a1);
        EventDensity a2 = new EventDensity();
        a2.setX(0);
        a2.setY(2);
        a2.setZ(0);
        result.add(a2);
        EventDensity a3 = new EventDensity();
        a3.setX(0);
        a3.setY(3);
        a3.setZ(0);
        result.add(a3);
        EventDensity a4 = new EventDensity();
        a4.setX(0);
        a4.setY(4);
        a4.setZ(0);
        result.add(a4);
        EventDensity a5 = new EventDensity();
        a5.setX(0);
        a5.setY(5);
        a5.setZ(0);
        result.add(a5);
        EventDensity a6 = new EventDensity();
        a6.setX(0);
        a6.setY(6);
        a6.setZ(0);
        result.add(a6);
        EventDensity a7 = new EventDensity();
        a7.setX(0);
        a7.setY(7);
        a7.setZ(0);
        result.add(a7);
        EventDensity a8 = new EventDensity();
        a8.setX(0);
        a8.setY(8);
        a8.setZ(0);
        result.add(a8);

        EventDensity b0 = new EventDensity();
        b0.setX(1);
        b0.setY(0);
        b0.setZ(0);
        result.add(b0);
        EventDensity b1 = new EventDensity();
        b1.setX(1);
        b1.setY(1);
        b1.setZ(0);
        result.add(b1);
        EventDensity b2 = new EventDensity();
        b2.setX(1);
        b2.setY(2);
        b2.setZ(0);
        result.add(b2);
        EventDensity b3 = new EventDensity();
        b3.setX(1);
        b3.setY(3);
        b3.setZ(0);
        result.add(b3);
        EventDensity b4 = new EventDensity();
        b4.setX(1);
        b4.setY(4);
        b4.setZ(0);
        result.add(b4);
        EventDensity b5 = new EventDensity();
        b5.setX(1);
        b5.setY(5);
        b5.setZ(0);
        result.add(b5);
        EventDensity b6 = new EventDensity();
        b6.setX(1);
        b6.setY(6);
        b6.setZ(0);
        result.add(b6);
        EventDensity b7 = new EventDensity();
        b7.setX(1);
        b7.setY(7);
        b7.setZ(0);
        result.add(b7);
        EventDensity b8 = new EventDensity();
        b8.setX(1);
        b8.setY(8);
        b8.setZ(0);
        result.add(b8);

        EventDensity c0 = new EventDensity();
        c0.setX(2);
        c0.setY(0);
        c0.setZ(0);
        result.add(c0);
        EventDensity c1 = new EventDensity();
        c1.setX(2);
        c1.setY(1);
        c1.setZ(0);
        result.add(c1);
        EventDensity c2 = new EventDensity();
        c2.setX(2);
        c2.setY(2);
        c2.setZ(0);
        result.add(c2);
        EventDensity c3 = new EventDensity();
        c3.setX(2);
        c3.setY(3);
        c3.setZ(0);
        result.add(c3);
        EventDensity c4 = new EventDensity();
        c4.setX(2);
        c4.setY(4);
        c4.setZ(0);
        result.add(c4);
        EventDensity c5 = new EventDensity();
        c5.setX(2);
        c5.setY(5);
        c5.setZ(0);
        result.add(c5);
        EventDensity c6 = new EventDensity();
        c6.setX(2);
        c6.setY(6);
        c6.setZ(0);
        result.add(c6);
        EventDensity c7 = new EventDensity();
        c7.setX(2);
        c7.setY(7);
        c7.setZ(0);
        result.add(c7);
        EventDensity c8 = new EventDensity();
        c8.setX(2);
        c8.setY(8);
        c8.setZ(0);
        result.add(c8);

        EventDensity d0 = new EventDensity();
        d0.setX(3);
        d0.setY(0);
        d0.setZ(0);
        result.add(d0);
        EventDensity d1 = new EventDensity();
        d1.setX(3);
        d1.setY(1);
        d1.setZ(0);
        result.add(d1);
        EventDensity d2 = new EventDensity();
        d2.setX(3);
        d2.setY(2);
        d2.setZ(0);
        result.add(d2);
        EventDensity d3 = new EventDensity();
        d3.setX(3);
        d3.setY(3);
        d3.setZ(0);
        result.add(d3);
        EventDensity d4 = new EventDensity();
        d4.setX(3);
        d4.setY(4);
        d4.setZ(0);
        result.add(d4);
        EventDensity d5 = new EventDensity();
        d5.setX(3);
        d5.setY(5);
        d5.setZ(0);
        result.add(d5);
        EventDensity d6 = new EventDensity();
        d6.setX(3);
        d6.setY(6);
        d6.setZ(0);
        result.add(d6);
        EventDensity d7 = new EventDensity();
        d7.setX(3);
        d7.setY(7);
        d7.setZ(0);
        result.add(d7);
        EventDensity d8 = new EventDensity();
        d8.setX(3);
        d8.setY(8);
        d8.setZ(0);
        result.add(d8);

        EventDensity e0 = new EventDensity();
        e0.setX(4);
        e0.setY(0);
        e0.setZ(0);
        result.add(e0);
        EventDensity e1 = new EventDensity();
        e1.setX(4);
        e1.setY(1);
        e1.setZ(0);
        result.add(e1);
        EventDensity e2 = new EventDensity();
        e2.setX(4);
        e2.setY(2);
        e2.setZ(0);
        result.add(e2);
        EventDensity e3 = new EventDensity();
        e3.setX(4);
        e3.setY(3);
        e3.setZ(0);
        result.add(e3);
        EventDensity e4 = new EventDensity();
        e4.setX(4);
        e4.setY(4);
        e4.setZ(0);
        result.add(e4);
        EventDensity e5 = new EventDensity();
        e5.setX(4);
        e5.setY(5);
        e5.setZ(0);
        result.add(e5);
        EventDensity e6 = new EventDensity();
        e6.setX(4);
        e6.setY(6);
        e6.setZ(0);
        result.add(e6);
        EventDensity e7 = new EventDensity();
        e7.setX(4);
        e7.setY(7);
        e7.setZ(0);
        result.add(e7);
        EventDensity e8 = new EventDensity();
        e8.setX(4);
        e8.setY(8);
        e8.setZ(0);
        result.add(e8);

        EventDensity f0 = new EventDensity();
        f0.setX(5);
        f0.setY(0);
        f0.setZ(0);
        result.add(f0);
        EventDensity f1 = new EventDensity();
        f1.setX(5);
        f1.setY(1);
        f1.setZ(0);
        result.add(f1);
        EventDensity f2 = new EventDensity();
        f2.setX(5);
        f2.setY(2);
        f2.setZ(0);
        result.add(f2);
        EventDensity f3 = new EventDensity();
        f3.setX(5);
        f3.setY(3);
        f3.setZ(0);
        result.add(f3);
        EventDensity f4 = new EventDensity();
        f4.setX(5);
        f4.setY(4);
        f4.setZ(0);
        result.add(f4);
        EventDensity f5 = new EventDensity();
        f5.setX(5);
        f5.setY(5);
        f5.setZ(0);
        result.add(f5);
        EventDensity f6 = new EventDensity();
        f6.setX(5);
        f6.setY(6);
        f6.setZ(0);
        result.add(f6);
        EventDensity f7 = new EventDensity();
        f7.setX(5);
        f7.setY(7);
        f7.setZ(0);
        result.add(f7);
        EventDensity f8 = new EventDensity();
        f8.setX(5);
        f8.setY(8);
        f8.setZ(0);
        result.add(f8);

        EventDensity g0 = new EventDensity();
        g0.setX(6);
        g0.setY(0);
        g0.setZ(0);
        result.add(g0);
        EventDensity g1 = new EventDensity();
        g1.setX(6);
        g1.setY(1);
        g1.setZ(0);
        result.add(g1);
        EventDensity g2 = new EventDensity();
        g2.setX(6);
        g2.setY(2);
        g2.setZ(0);
        result.add(g2);
        EventDensity g3 = new EventDensity();
        g3.setX(6);
        g3.setY(3);
        g3.setZ(0);
        result.add(g3);
        EventDensity g4 = new EventDensity();
        g4.setX(6);
        g4.setY(4);
        g4.setZ(0);
        result.add(g4);
        EventDensity g5 = new EventDensity();
        g5.setX(6);
        g5.setY(5);
        g5.setZ(0);
        result.add(g5);
        EventDensity g6 = new EventDensity();
        g6.setX(6);
        g6.setY(6);
        g6.setZ(0);
        result.add(g6);
        EventDensity g7 = new EventDensity();
        g7.setX(6);
        g7.setY(7);
        g7.setZ(0);
        result.add(g7);
        EventDensity g8 = new EventDensity();
        g8.setX(6);
        g8.setY(8);
        g8.setZ(0);
        result.add(g8);

        EventDensity h0 = new EventDensity();
        h0.setX(7);
        h0.setY(0);
        h0.setZ(0);
        result.add(h0);
        EventDensity h1 = new EventDensity();
        h1.setX(7);
        h1.setY(1);
        h1.setZ(0);
        result.add(h1);
        EventDensity h2 = new EventDensity();
        h2.setX(7);
        h2.setY(2);
        h2.setZ(0);
        result.add(h2);
        EventDensity h3 = new EventDensity();
        h3.setX(7);
        h3.setY(3);
        h3.setZ(0);
        result.add(h3);
        EventDensity h4 = new EventDensity();
        h4.setX(7);
        h4.setY(4);
        h4.setZ(0);
        result.add(h4);
        EventDensity h5 = new EventDensity();
        h5.setX(7);
        h5.setY(5);
        h5.setZ(0);
        result.add(h5);
        EventDensity h6 = new EventDensity();
        h6.setX(7);
        h6.setY(6);
        h6.setZ(0);
        result.add(h6);
        EventDensity h7 = new EventDensity();
        h7.setX(7);
        h7.setY(7);
        h7.setZ(0);
        result.add(h7);
        EventDensity h8 = new EventDensity();
        h8.setX(7);
        h8.setY(8);
        h8.setZ(0);
        result.add(h8);

        EventDensity i0 = new EventDensity();
        i0.setX(8);
        i0.setY(0);
        i0.setZ(0);
        result.add(i0);
        EventDensity i1 = new EventDensity();
        i1.setX(8);
        i1.setY(1);
        i1.setZ(0);
        result.add(i1);
        EventDensity i2 = new EventDensity();
        i2.setX(8);
        i2.setY(2);
        i2.setZ(0);
        result.add(i2);
        EventDensity i3 = new EventDensity();
        i3.setX(8);
        i3.setY(3);
        i3.setZ(0);
        result.add(i3);
        EventDensity i4 = new EventDensity();
        i4.setX(8);
        i4.setY(4);
        i4.setZ(0);
        result.add(i4);
        EventDensity i5 = new EventDensity();
        i5.setX(8);
        i5.setY(5);
        i5.setZ(0);
        result.add(i5);
        EventDensity i6 = new EventDensity();
        i6.setX(8);
        i6.setY(6);
        i6.setZ(0);
        result.add(i6);
        EventDensity i7 = new EventDensity();
        i7.setX(8);
        i7.setY(7);
        i7.setZ(0);
        result.add(i7);
        EventDensity i8 = new EventDensity();
        i8.setX(8);
        i8.setY(8);
        i8.setZ(0);
        result.add(i8);

        EventDensity j0 = new EventDensity();
        j0.setX(9);
        j0.setY(0);
        j0.setZ(0);
        result.add(j0);
        EventDensity j1 = new EventDensity();
        j1.setX(9);
        j1.setY(1);
        j1.setZ(0);
        result.add(j1);
        EventDensity j2 = new EventDensity();
        j2.setX(9);
        j2.setY(2);
        j2.setZ(0);
        result.add(j2);
        EventDensity j3 = new EventDensity();
        j3.setX(9);
        j3.setY(3);
        j3.setZ(0);
        result.add(j3);
        EventDensity j4 = new EventDensity();
        j4.setX(9);
        j4.setY(4);
        j4.setZ(0);
        result.add(j4);
        EventDensity j5 = new EventDensity();
        j5.setX(9);
        j5.setY(5);
        j5.setZ(0);
        result.add(j5);
        EventDensity j6 = new EventDensity();
        j6.setX(9);
        j6.setY(6);
        j6.setZ(0);
        result.add(j6);
        EventDensity j7 = new EventDensity();
        j7.setX(9);
        j7.setY(7);
        j7.setZ(0);
        result.add(j7);
        EventDensity j8 = new EventDensity();
        j8.setX(9);
        j8.setY(8);
        j8.setZ(0);
        result.add(j8);

        for (int i = 0; i < info.size(); i++) {
            EventDensity dto = new EventDensity();
            if (info.get(i).getEventvalue() >= 0 && info.get(i).getEventvalue() <= 0.1) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(0).getZ();
                    dto.setX(0);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(0, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(1).getZ();
                    dto.setX(0);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(1, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(2).getZ();
                    dto.setX(0);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(2, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(3).getZ();
                    dto.setX(0);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(3, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(4).getZ();
                    dto.setX(0);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(4, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(5).getZ();
                    dto.setX(0);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(5, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(6).getZ();
                    dto.setX(0);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(6, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(7).getZ();
                    dto.setX(0);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(7, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    // result.get(8).setX(0);
                    // result.get(8).setY(8);
                    // result.get(8).setZ(result.get(8).getZ()+1);
                    int z = result.get(8).getZ();
                    dto.setX(0);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(8, dto);
                }
            } else if (info.get(i).getEventvalue() > 0.1 && info.get(i).getEventvalue() <= 0.2) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(9).getZ();
                    dto.setX(1);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(9, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(10).getZ();
                    dto.setX(1);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(10, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(11).getZ();
                    dto.setX(1);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(11, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(12).getZ();
                    dto.setX(1);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(12, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(13).getZ();
                    dto.setX(1);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(13, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(14).getZ();
                    dto.setX(1);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(14, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(15).getZ();
                    dto.setX(1);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(15, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(16).getZ();
                    dto.setX(1);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(16, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(17).getZ();
                    dto.setX(1);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(17, dto);
                }
            } else if (info.get(i).getEventvalue() > 0.2 && info.get(i).getEventvalue() <= 0.3) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(18).getZ();
                    dto.setX(2);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(18, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(19).getZ();
                    dto.setX(2);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(19, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(20).getZ();
                    dto.setX(2);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(20, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(21).getZ();
                    dto.setX(2);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(21, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(22).getZ();
                    dto.setX(2);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(22, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(23).getZ();
                    dto.setX(2);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(23, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(24).getZ();
                    dto.setX(2);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(24, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(25).getZ();
                    dto.setX(2);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(25, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(26).getZ();
                    dto.setX(2);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(26, dto);
                }
            } else if (info.get(i).getEventvalue() > 0.3 && info.get(i).getEventvalue() <= 0.4) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(27).getZ();
                    dto.setX(3);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(27, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(28).getZ();
                    dto.setX(3);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(28, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(29).getZ();
                    dto.setX(3);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(29, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(30).getZ();
                    dto.setX(3);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(30, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(31).getZ();
                    dto.setX(3);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(31, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(32).getZ();
                    dto.setX(3);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(32, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(33).getZ();
                    dto.setX(3);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(33, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(34).getZ();
                    dto.setX(3);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(34, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(35).getZ();
                    dto.setX(3);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(35, dto);
                }
            } else if (info.get(i).getEventvalue() > 0.4 && info.get(i).getEventvalue() <= 0.5) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(36).getZ();
                    dto.setX(4);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(36, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(37).getZ();
                    dto.setX(4);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(37, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(38).getZ();
                    dto.setX(4);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(38, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(39).getZ();
                    dto.setX(4);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(39, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(40).getZ();
                    dto.setX(4);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(40, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(41).getZ();
                    dto.setX(4);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(41, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(42).getZ();
                    dto.setX(4);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(42, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(43).getZ();
                    dto.setX(4);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(43, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(44).getZ();
                    dto.setX(4);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(44, dto);
                }
            } else if (info.get(i).getEventvalue() > 0.5 && info.get(i).getEventvalue() <= 0.6) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(45).getZ();
                    dto.setX(5);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(45, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(46).getZ();
                    dto.setX(5);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(46, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(47).getZ();
                    dto.setX(5);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(47, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(48).getZ();
                    dto.setX(5);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(48, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(49).getZ();
                    dto.setX(5);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(49, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(50).getZ();
                    dto.setX(5);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(50, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(51).getZ();
                    dto.setX(5);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(51, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(52).getZ();
                    dto.setX(5);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(52, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(53).getZ();
                    dto.setX(5);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(53, dto);
                }
            } else if (info.get(i).getEventvalue() > 0.6 && info.get(i).getEventvalue() <= 0.7) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(54).getZ();
                    dto.setX(6);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(54, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(55).getZ();
                    dto.setX(6);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(55, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(56).getZ();
                    dto.setX(6);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(56, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(57).getZ();
                    dto.setX(6);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(57, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(58).getZ();
                    dto.setX(6);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(58, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(59).getZ();
                    dto.setX(6);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(59, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(60).getZ();
                    dto.setX(6);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(60, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(61).getZ();
                    dto.setX(6);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(61, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(62).getZ();
                    dto.setX(6);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(62, dto);
                }
            } else if (info.get(i).getEventvalue() > 0.7 && info.get(i).getEventvalue() <= 0.8) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(63).getZ();
                    dto.setX(7);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(63, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(64).getZ();
                    dto.setX(7);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(64, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(65).getZ();
                    dto.setX(7);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(65, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(66).getZ();
                    dto.setX(7);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(66, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(67).getZ();
                    dto.setX(7);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(67, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(68).getZ();
                    dto.setX(7);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(68, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(69).getZ();
                    dto.setX(7);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(69, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(70).getZ();
                    dto.setX(7);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(70, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(71).getZ();
                    dto.setX(7);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(71, dto);
                }
            } else if (info.get(i).getEventvalue() > 0.8 && info.get(i).getEventvalue() <= 0.9) {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(72).getZ();
                    dto.setX(8);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(72, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(73).getZ();
                    dto.setX(8);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(73, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(74).getZ();
                    dto.setX(8);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(74, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(75).getZ();
                    dto.setX(8);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(75, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(76).getZ();
                    dto.setX(8);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(76, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(77).getZ();
                    dto.setX(8);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(77, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(78).getZ();
                    dto.setX(8);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(78, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(79).getZ();
                    dto.setX(8);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(79, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(80).getZ();
                    dto.setX(8);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(80, dto);
                }
            } else {
                if (info.get(i).getPersisttime() > 0 && info.get(i).getPersisttime() <= 0.020) {
                    int z = result.get(81).getZ();
                    dto.setX(9);
                    dto.setY(0);
                    dto.setZ(z + 1);
                    result.set(81, dto);
                } else if (info.get(i).getPersisttime() <= 0.040 && info.get(i).getPersisttime() > 0.020) {
                    int z = result.get(82).getZ();
                    dto.setX(9);
                    dto.setY(1);
                    dto.setZ(z + 1);
                    result.set(82, dto);
                } else if (info.get(i).getPersisttime() <= 0.060 && info.get(i).getPersisttime() > 0.040) {
                    int z = result.get(83).getZ();
                    dto.setX(9);
                    dto.setY(2);
                    dto.setZ(z + 1);
                    result.set(83, dto);
                } else if (info.get(i).getPersisttime() <= 0.080 && info.get(i).getPersisttime() > 0.060) {
                    int z = result.get(84).getZ();
                    dto.setX(9);
                    dto.setY(3);
                    dto.setZ(z + 1);
                    result.set(84, dto);
                } else if (info.get(i).getPersisttime() <= 0.120 && info.get(i).getPersisttime() > 0.080) {
                    int z = result.get(85).getZ();
                    dto.setX(9);
                    dto.setY(4);
                    dto.setZ(z + 1);
                    result.set(85, dto);
                } else if (info.get(i).getPersisttime() > 0.120 && info.get(i).getPersisttime() < 0.200) {
                    int z = result.get(86).getZ();
                    dto.setX(9);
                    dto.setY(5);
                    dto.setZ(z + 1);
                    result.set(87, dto);
                } else if (info.get(i).getPersisttime() >= 0.200 && info.get(i).getPersisttime() < 0.400) {
                    int z = result.get(87).getZ();
                    dto.setX(9);
                    dto.setY(6);
                    dto.setZ(z + 1);
                    result.set(87, dto);
                } else if (info.get(i).getPersisttime() >= 0.400 && info.get(i).getPersisttime() < 0.600) {
                    int z = result.get(88).getZ();
                    dto.setX(9);
                    dto.setY(7);
                    dto.setZ(z + 1);
                    result.set(88, dto);
                } else if (info.get(i).getPersisttime() >= 0.600 && info.get(i).getPersisttime() <= 1.200) {
                    int z = result.get(89).getZ();
                    dto.setX(9);
                    dto.setY(8);
                    dto.setZ(z + 1);
                    result.set(89, dto);
                }
            }
        }

        return result;
    }

    public List<List> getEventDisdip(Date startTime, Date endTime, String lineIndex) {
        List<List> result = new ArrayList<>();
        List<EventDataList> info = new ArrayList<>();

        info = eventdataMapper.getEventDataList(Integer.parseInt(lineIndex), startTime, endTime);

        int a1 = 0, b1 = 0, c1 = 0, d1 = 0, e1 = 0, f1 = 0, g1 = 0, h1 = 0;
        int a2 = 0, b2 = 0, c2 = 0, d2 = 0, e2 = 0, f2 = 0, g2 = 0, h2 = 0;
        int a3 = 0, b3 = 0, c3 = 0, d3 = 0, e3 = 0, f3 = 0, g3 = 0, h3 = 0;
        int a4 = 0, b4 = 0, c4 = 0, d4 = 0, e4 = 0, f4 = 0, g4 = 0, h4 = 0;
        int a5 = 0, b5 = 0, c5 = 0, d5 = 0, e5 = 0, f5 = 0, g5 = 0, h5 = 0;

        for (int i = 0; i < info.size(); i++) {
            float eventvalue = info.get(i).getEventvalue();
            float persisttime = info.get(i).getPersisttime() * 1000;

            if (eventvalue * 100 < 10) {
                if (persisttime < 20) {
                    a5++;
                } else if (persisttime < 100) {
                    b5++;
                } else if (persisttime < 500) {
                    c5++;
                } else if (persisttime < 1000) {
                    d5++;
                } else if (persisttime < 3000) {
                    e5++;
                } else if (persisttime < 20000) {
                    f5++;
                } else if (persisttime < 60000) {
                    g5++;
                } else if (persisttime < 180000) {
                    h5++;
                }
            } else if (eventvalue * 100 < 40) {
                if (persisttime < 20) {
                    a4++;
                } else if (persisttime < 100) {
                    b4++;
                } else if (persisttime < 500) {
                    c4++;
                } else if (persisttime < 1000) {
                    d4++;
                } else if (persisttime < 3000) {
                    e4++;
                } else if (persisttime < 20000) {
                    f4++;
                } else if (persisttime < 60000) {
                    g4++;
                } else if (persisttime < 180000) {
                    h4++;
                }
            } else if (eventvalue * 100 < 70) {
                if (persisttime < 20) {
                    a3++;
                } else if (persisttime < 100) {
                    b3++;
                } else if (persisttime < 500) {
                    c3++;
                } else if (persisttime < 1000) {
                    d3++;
                } else if (persisttime < 3000) {
                    e3++;
                } else if (persisttime < 20000) {
                    f3++;
                } else if (persisttime < 60000) {
                    g3++;
                } else if (persisttime < 180000) {
                    h3++;
                }
            } else if (eventvalue * 100 < 85) {
                if (persisttime < 20) {
                    a2++;
                } else if (persisttime < 100) {
                    b2++;
                } else if (persisttime < 500) {
                    c2++;
                } else if (persisttime < 1000) {
                    d2++;
                } else if (persisttime < 3000) {
                    e2++;
                } else if (persisttime < 20000) {
                    f2++;
                } else if (persisttime < 60000) {
                    g2++;
                } else if (persisttime < 180000) {
                    h2++;
                }
            } else if (eventvalue * 100 <= 90) {
                if (persisttime < 20) {
                    a1++;
                } else if (persisttime < 100) {
                    b1++;
                } else if (persisttime < 500) {
                    c1++;
                } else if (persisttime < 1000) {
                    d1++;
                } else if (persisttime < 3000) {
                    e1++;
                } else if (persisttime < 20000) {
                    f1++;
                } else if (persisttime < 60000) {
                    g1++;
                } else if (persisttime < 180000) {
                    h1++;
                }
            }
        }

        List<String> tmp1 = new ArrayList<>();
        List<String> tmp2 = new ArrayList<>();
        List<String> tmp3 = new ArrayList<>();
        List<String> tmp4 = new ArrayList<>();
        List<String> tmp5 = new ArrayList<>();

        tmp1.add("90%");
        tmp2.add("85%");
        tmp3.add("70%");
        tmp4.add("40%");
        tmp5.add("10%");
        tmp1.add(String.valueOf(a1));
        tmp1.add(String.valueOf(b1));
        tmp1.add(String.valueOf(c1));
        tmp1.add(String.valueOf(d1));
        tmp1.add(String.valueOf(e1));
        tmp1.add(String.valueOf(f1));
        tmp1.add(String.valueOf(g1));
        tmp1.add(String.valueOf(h1));
        tmp2.add(String.valueOf(a2));
        tmp2.add(String.valueOf(b2));
        tmp2.add(String.valueOf(c2));
        tmp2.add(String.valueOf(d2));
        tmp2.add(String.valueOf(e2));
        tmp2.add(String.valueOf(f2));
        tmp2.add(String.valueOf(g2));
        tmp2.add(String.valueOf(h2));
        tmp3.add(String.valueOf(a3));
        tmp3.add(String.valueOf(b3));
        tmp3.add(String.valueOf(c3));
        tmp3.add(String.valueOf(d3));
        tmp3.add(String.valueOf(e3));
        tmp3.add(String.valueOf(f3));
        tmp3.add(String.valueOf(g3));
        tmp3.add(String.valueOf(h3));
        tmp4.add(String.valueOf(a4));
        tmp4.add(String.valueOf(b4));
        tmp4.add(String.valueOf(c4));
        tmp4.add(String.valueOf(d4));
        tmp4.add(String.valueOf(e4));
        tmp4.add(String.valueOf(f4));
        tmp4.add(String.valueOf(g4));
        tmp4.add(String.valueOf(h4));
        tmp5.add(String.valueOf(a5));
        tmp5.add(String.valueOf(b5));
        tmp5.add(String.valueOf(c5));
        tmp5.add(String.valueOf(d5));
        tmp5.add(String.valueOf(e5));
        tmp5.add(String.valueOf(f5));
        tmp5.add(String.valueOf(g5));
        tmp5.add(String.valueOf(h5));

        result.add(tmp1);
        result.add(tmp2);
        result.add(tmp3);
        result.add(tmp4);
        result.add(tmp5);
        return result;
    }

    public List<List> getIEC411(Date startTime, Date endTime, String lineIndex) {
        List<List> result = new ArrayList<>();
        List<EventDataList> info = new ArrayList<>();

        info = eventdataMapper.getEventDataList(Integer.parseInt(lineIndex), startTime, endTime);

        int a1 = 0, b1 = 0, c1 = 0, d1 = 0, e1 = 0, f1 = 0;
        int a2 = 0, b2 = 0, c2 = 0, d2 = 0, e2 = 0, f2 = 0;
        int a3 = 0, b3 = 0, c3 = 0, d3 = 0, e3 = 0, f3 = 0;

        for (int i = 0; i < info.size(); i++) {
            float eventvalue = info.get(i).getEventvalue();
            float persisttime = info.get(i).getPersisttime() * 1000;

            if (eventvalue * 100 < 1) {
                if (persisttime < 20 && persisttime >= 10) {
                    a3++;
                } else if (persisttime < 100) {
                    b3++;
                } else if (persisttime < 200) {
                    c3++;
                } else if (persisttime < 400) {
                    d3++;
                } else if (persisttime < 1000) {
                    e3++;
                } else {
                    f3++;
                }
            } else if (eventvalue * 100 < 40) {
                if (persisttime < 20 && persisttime >= 10) {
                    a2++;
                } else if (persisttime < 100) {
                    b2++;
                } else if (persisttime < 200) {
                    c2++;
                } else if (persisttime < 400) {
                    d2++;
                } else if (persisttime < 1000) {
                    e2++;
                } else {
                    f2++;
                }
            } else if (eventvalue * 100 <= 70) {
                if (persisttime < 20 && persisttime >= 10) {
                    a1++;
                } else if (persisttime < 100) {
                    b1++;
                } else if (persisttime < 200) {
                    c1++;
                } else if (persisttime < 400) {
                    d1++;
                } else if (persisttime < 1000) {
                    e1++;
                } else {
                    f1++;
                }
            }
        }

        List<String> tmp1 = new ArrayList<>();
        List<String> tmp2 = new ArrayList<>();
        List<String> tmp3 = new ArrayList<>();

        tmp1.add("40~70%");
        tmp2.add("1~40%");
        tmp3.add("<1%");
        tmp1.add(String.valueOf(a1));
        tmp1.add(String.valueOf(b1));
        tmp1.add(String.valueOf(c1));
        tmp1.add(String.valueOf(d1));
        tmp1.add(String.valueOf(e1));
        tmp1.add(String.valueOf(f1));
        tmp2.add(String.valueOf(a2));
        tmp2.add(String.valueOf(b2));
        tmp2.add(String.valueOf(c2));
        tmp2.add(String.valueOf(d2));
        tmp2.add(String.valueOf(e2));
        tmp2.add(String.valueOf(f2));
        tmp3.add(String.valueOf(a3));
        tmp3.add(String.valueOf(b3));
        tmp3.add(String.valueOf(c3));
        tmp3.add(String.valueOf(d3));
        tmp3.add(String.valueOf(e3));
        tmp3.add(String.valueOf(f3));

        result.add(tmp1);
        result.add(tmp2);
        result.add(tmp3);
        return result;
    }

    @Override
    public List<List> getIEC28(Date startTime, Date endTime, String lineIndex) {
        List<List> result = new ArrayList<>();
        List<EventDataList> info = new ArrayList<>();

        info = eventdataMapper.getEventDataList(Integer.parseInt(lineIndex), startTime, endTime);

        int a1 = 0, b1 = 0, c1 = 0, d1 = 0, e1 = 0, f1 = 0, g1 = 0, h1 = 0;
        int a2 = 0, b2 = 0, c2 = 0, d2 = 0, e2 = 0, f2 = 0, g2 = 0, h2 = 0;
        int a3 = 0, b3 = 0, c3 = 0, d3 = 0, e3 = 0, f3 = 0, g3 = 0, h3 = 0;
        int a4 = 0, b4 = 0, c4 = 0, d4 = 0, e4 = 0, f4 = 0, g4 = 0, h4 = 0;
        int a5 = 0, b5 = 0, c5 = 0, d5 = 0, e5 = 0, f5 = 0, g5 = 0, h5 = 0;
        int a6 = 0, b6 = 0, c6 = 0, d6 = 0, e6 = 0, f6 = 0, g6 = 0, h6 = 0;
        int a7 = 0, b7 = 0, c7 = 0, d7 = 0, e7 = 0, f7 = 0, g7 = 0, h7 = 0;
        int a8 = 0, b8 = 0, c8 = 0, d8 = 0, e8 = 0, f8 = 0, g8 = 0, h8 = 0;
        int a9 = 0, b9 = 0, c9 = 0, d9 = 0, e9 = 0, f9 = 0, g9 = 0, h9 = 0;
        int a10 = 0, b10 = 0, c10 = 0, d10 = 0, e10 = 0, f10 = 0, g10 = 0, h10 = 0;
        int a11 = 0, b11 = 0, c11 = 0, d11 = 0, e11 = 0, f11 = 0, g11 = 0, h11 = 0;
        int a12 = 0, b12 = 0, c12 = 0, d12 = 0, e12 = 0, f12 = 0, g12 = 0, h12 = 0;
        int a13 = 0, b13 = 0, c13 = 0, d13 = 0, e13 = 0, f13 = 0, g13 = 0, h13 = 0;
        int a14 = 0, b14 = 0, c14 = 0, d14 = 0, e14 = 0, f14 = 0, g14 = 0, h14 = 0;
        int a15 = 0, b15 = 0, c15 = 0, d15 = 0, e15 = 0, f15 = 0, g15 = 0, h15 = 0;
        int a16 = 0, b16 = 0, c16 = 0, d16 = 0, e16 = 0, f16 = 0, g16 = 0, h16 = 0;
        int a17 = 0, b17 = 0, c17 = 0, d17 = 0, e17 = 0, f17 = 0, g17 = 0, h17 = 0;

        for (int i = 0; i < info.size(); i++) {
            float eventvalue = info.get(i).getEventvalue();
            float persisttime = info.get(i).getPersisttime() * 1000;

            if (eventvalue * 100 < 1 && eventvalue * 100 >= 0) {
                if (persisttime > 10 && persisttime <= 100) {
                    a17++;
                } else if (persisttime <= 250) {
                    b17++;
                } else if (persisttime <= 500) {
                    c17++;
                } else if (persisttime <= 1000) {
                    d17++;
                } else if (persisttime <= 3000) {
                    e17++;
                } else if (persisttime <= 20000) {
                    f17++;
                } else if (persisttime <= 60000) {
                    g17++;
                } else if (persisttime <= 180000) {
                    h17++;
                }
            } else if (eventvalue * 100 < 10) {
                if (persisttime > 10 && persisttime <= 100) {
                    a16++;
                } else if (persisttime <= 250) {
                    b16++;
                } else if (persisttime <= 500) {
                    c16++;
                } else if (persisttime <= 1000) {
                    d16++;
                } else if (persisttime <= 3000) {
                    e16++;
                } else if (persisttime <= 20000) {
                    f16++;
                } else if (persisttime <= 60000) {
                    g16++;
                } else if (persisttime <= 180000) {
                    h16++;
                }
            } else if (eventvalue * 100 < 20) {
                if (persisttime > 10 && persisttime <= 100) {
                    a15++;
                } else if (persisttime <= 250) {
                    b15++;
                } else if (persisttime <= 500) {
                    c15++;
                } else if (persisttime <= 1000) {
                    d15++;
                } else if (persisttime <= 3000) {
                    e15++;
                } else if (persisttime <= 20000) {
                    f15++;
                } else if (persisttime <= 60000) {
                    g15++;
                } else if (persisttime <= 180000) {
                    h15++;
                }
            } else if (eventvalue * 100 < 30) {
                if (persisttime > 10 && persisttime <= 100) {
                    a14++;
                } else if (persisttime <= 250) {
                    b14++;
                } else if (persisttime <= 500) {
                    c14++;
                } else if (persisttime <= 1000) {
                    d14++;
                } else if (persisttime <= 3000) {
                    e14++;
                } else if (persisttime <= 20000) {
                    f14++;
                } else if (persisttime <= 60000) {
                    g14++;
                } else if (persisttime <= 180000) {
                    h14++;
                }
            } else if (eventvalue * 100 < 40) {
                if (persisttime > 10 && persisttime <= 100) {
                    a13++;
                } else if (persisttime <= 250) {
                    b13++;
                } else if (persisttime <= 500) {
                    c13++;
                } else if (persisttime <= 1000) {
                    d13++;
                } else if (persisttime <= 3000) {
                    e13++;
                } else if (persisttime <= 20000) {
                    f13++;
                } else if (persisttime <= 60000) {
                    g13++;
                } else if (persisttime <= 180000) {
                    h13++;
                }
            } else if (eventvalue * 100 < 50) {
                if (persisttime > 10 && persisttime <= 100) {
                    a12++;
                } else if (persisttime <= 250) {
                    b12++;
                } else if (persisttime <= 500) {
                    c12++;
                } else if (persisttime <= 1000) {
                    d12++;
                } else if (persisttime <= 3000) {
                    e12++;
                } else if (persisttime <= 20000) {
                    f12++;
                } else if (persisttime <= 60000) {
                    g12++;
                } else if (persisttime <= 180000) {
                    h12++;
                }
            } else if (eventvalue * 100 < 60) {
                if (persisttime > 10 && persisttime <= 100) {
                    a11++;
                } else if (persisttime <= 250) {
                    b11++;
                } else if (persisttime <= 500) {
                    c11++;
                } else if (persisttime <= 1000) {
                    d11++;
                } else if (persisttime <= 3000) {
                    e11++;
                } else if (persisttime <= 20000) {
                    f11++;
                } else if (persisttime <= 60000) {
                    g11++;
                } else if (persisttime <= 180000) {
                    h11++;
                }
            } else if (eventvalue * 100 < 70) {
                if (persisttime > 10 && persisttime <= 100) {
                    a10++;
                } else if (persisttime <= 250) {
                    b10++;
                } else if (persisttime <= 500) {
                    c10++;
                } else if (persisttime <= 1000) {
                    d10++;
                } else if (persisttime <= 3000) {
                    e10++;
                } else if (persisttime <= 20000) {
                    f10++;
                } else if (persisttime <= 60000) {
                    g10++;
                } else if (persisttime <= 180000) {
                    h10++;
                }
            } else if (eventvalue * 100 < 80) {
                if (persisttime > 10 && persisttime <= 100) {
                    a9++;
                } else if (persisttime <= 250) {
                    b9++;
                } else if (persisttime <= 500) {
                    c9++;
                } else if (persisttime <= 1000) {
                    d9++;
                } else if (persisttime <= 3000) {
                    e9++;
                } else if (persisttime <= 20000) {
                    f9++;
                } else if (persisttime <= 60000) {
                    g9++;
                } else if (persisttime <= 180000) {
                    h9++;
                }
            } else if (eventvalue * 100 <= 90) {
                if (persisttime > 10 && persisttime <= 100) {
                    a8++;
                } else if (persisttime <= 250) {
                    b8++;
                } else if (persisttime <= 500) {
                    c8++;
                } else if (persisttime <= 1000) {
                    d8++;
                } else if (persisttime <= 3000) {
                    e8++;
                } else if (persisttime <= 20000) {
                    f8++;
                } else if (persisttime <= 60000) {
                    g8++;
                } else if (persisttime <= 180000) {
                    h8++;
                }
            } else if (eventvalue * 100 < 120 && eventvalue * 100 >= 110) {
                if (persisttime > 10 && persisttime <= 100) {
                    a7++;
                } else if (persisttime <= 250) {
                    b7++;
                } else if (persisttime <= 500) {
                    c7++;
                } else if (persisttime <= 1000) {
                    d7++;
                } else if (persisttime <= 3000) {
                    e7++;
                } else if (persisttime <= 20000) {
                    f7++;
                } else if (persisttime <= 60000) {
                    g7++;
                } else if (persisttime <= 180000) {
                    h7++;
                }
            } else if (eventvalue * 100 < 130) {
                if (persisttime > 10 && persisttime <= 100) {
                    a6++;
                } else if (persisttime <= 250) {
                    b6++;
                } else if (persisttime <= 500) {
                    c6++;
                } else if (persisttime <= 1000) {
                    d6++;
                } else if (persisttime <= 3000) {
                    e6++;
                } else if (persisttime <= 20000) {
                    f6++;
                } else if (persisttime <= 60000) {
                    g6++;
                } else if (persisttime <= 180000) {
                    h6++;
                }
            } else if (eventvalue * 100 < 140) {
                if (persisttime > 10 && persisttime <= 100) {
                    a5++;
                } else if (persisttime <= 250) {
                    b5++;
                } else if (persisttime <= 500) {
                    c5++;
                } else if (persisttime <= 1000) {
                    d5++;
                } else if (persisttime <= 3000) {
                    e5++;
                } else if (persisttime <= 20000) {
                    f5++;
                } else if (persisttime <= 60000) {
                    g5++;
                } else if (persisttime <= 180000) {
                    h5++;
                }
            } else if (eventvalue * 100 < 150) {
                if (persisttime > 10 && persisttime <= 100) {
                    a4++;
                } else if (persisttime <= 250) {
                    b4++;
                } else if (persisttime <= 500) {
                    c4++;
                } else if (persisttime <= 1000) {
                    d4++;
                } else if (persisttime <= 3000) {
                    e4++;
                } else if (persisttime <= 20000) {
                    f4++;
                } else if (persisttime <= 60000) {
                    g4++;
                } else if (persisttime <= 180000) {
                    h4++;
                }
            } else if (eventvalue * 100 < 160) {
                if (persisttime > 10 && persisttime <= 100) {
                    a3++;
                } else if (persisttime <= 250) {
                    b3++;
                } else if (persisttime <= 500) {
                    c3++;
                } else if (persisttime <= 1000) {
                    d3++;
                } else if (persisttime <= 3000) {
                    e3++;
                } else if (persisttime <= 20000) {
                    f3++;
                } else if (persisttime <= 60000) {
                    g3++;
                } else if (persisttime <= 180000) {
                    h3++;
                }
            } else if (eventvalue * 100 < 170) {
                if (persisttime > 10 && persisttime <= 100) {
                    a2++;
                } else if (persisttime <= 250) {
                    b2++;
                } else if (persisttime <= 500) {
                    c2++;
                } else if (persisttime <= 1000) {
                    d2++;
                } else if (persisttime <= 3000) {
                    e2++;
                } else if (persisttime <= 20000) {
                    f2++;
                } else if (persisttime <= 60000) {
                    g2++;
                } else if (persisttime <= 180000) {
                    h2++;
                }
            } else if (eventvalue * 100 <= 180) {
                if (persisttime > 10 && persisttime <= 100) {
                    a1++;
                } else if (persisttime <= 250) {
                    b1++;
                } else if (persisttime <= 500) {
                    c1++;
                } else if (persisttime <= 1000) {
                    d1++;
                } else if (persisttime <= 3000) {
                    e1++;
                } else if (persisttime <= 20000) {
                    f1++;
                } else if (persisttime <= 60000) {
                    g1++;
                } else if (persisttime <= 180000) {
                    h1++;
                }
            }
        }

        List<String> tmp1 = new ArrayList<>();
        List<String> tmp2 = new ArrayList<>();
        List<String> tmp3 = new ArrayList<>();
        List<String> tmp4 = new ArrayList<>();
        List<String> tmp5 = new ArrayList<>();
        List<String> tmp6 = new ArrayList<>();
        List<String> tmp7 = new ArrayList<>();
        List<String> tmp8 = new ArrayList<>();
        List<String> tmp9 = new ArrayList<>();
        List<String> tmp10 = new ArrayList<>();
        List<String> tmp11 = new ArrayList<>();
        List<String> tmp12 = new ArrayList<>();
        List<String> tmp13 = new ArrayList<>();
        List<String> tmp14 = new ArrayList<>();
        List<String> tmp15 = new ArrayList<>();
        List<String> tmp16 = new ArrayList<>();
        List<String> tmp17 = new ArrayList<>();

        tmp1.add("180>=U>=170");
        tmp2.add("170>U>=160");
        tmp3.add("160>U>=150");
        tmp4.add("150>U>=140");
        tmp5.add("140>U>=130");
        tmp6.add("130>U>=120");
        tmp7.add("120>U>=110");
        tmp8.add("90>=U>=80");
        tmp9.add("80>U>=70");
        tmp10.add("70>U>=60");
        tmp11.add("60>U>=50");
        tmp12.add("50>U>=40");
        tmp13.add("40>U>=30");
        tmp14.add("30>U>=20");
        tmp15.add("20>U>=10");
        tmp16.add("10>U>=1");
        tmp17.add("1>U>=0");
        tmp1.add(String.valueOf(a1));
        tmp1.add(String.valueOf(b1));
        tmp1.add(String.valueOf(c1));
        tmp1.add(String.valueOf(d1));
        tmp1.add(String.valueOf(e1));
        tmp1.add(String.valueOf(f1));
        tmp1.add(String.valueOf(g1));
        tmp1.add(String.valueOf(h1));
        tmp2.add(String.valueOf(a2));
        tmp2.add(String.valueOf(b2));
        tmp2.add(String.valueOf(c2));
        tmp2.add(String.valueOf(d2));
        tmp2.add(String.valueOf(e2));
        tmp2.add(String.valueOf(f2));
        tmp2.add(String.valueOf(g2));
        tmp2.add(String.valueOf(h2));
        tmp3.add(String.valueOf(a3));
        tmp3.add(String.valueOf(b3));
        tmp3.add(String.valueOf(c3));
        tmp3.add(String.valueOf(d3));
        tmp3.add(String.valueOf(e3));
        tmp3.add(String.valueOf(f3));
        tmp3.add(String.valueOf(g3));
        tmp3.add(String.valueOf(h3));
        tmp4.add(String.valueOf(a4));
        tmp4.add(String.valueOf(b4));
        tmp4.add(String.valueOf(c4));
        tmp4.add(String.valueOf(d4));
        tmp4.add(String.valueOf(e4));
        tmp4.add(String.valueOf(f4));
        tmp4.add(String.valueOf(g4));
        tmp4.add(String.valueOf(h4));
        tmp5.add(String.valueOf(a5));
        tmp5.add(String.valueOf(b5));
        tmp5.add(String.valueOf(c5));
        tmp5.add(String.valueOf(d5));
        tmp5.add(String.valueOf(e5));
        tmp5.add(String.valueOf(f5));
        tmp5.add(String.valueOf(g5));
        tmp5.add(String.valueOf(h5));
        tmp6.add(String.valueOf(a6));
        tmp6.add(String.valueOf(b6));
        tmp6.add(String.valueOf(c6));
        tmp6.add(String.valueOf(d6));
        tmp6.add(String.valueOf(e6));
        tmp6.add(String.valueOf(f6));
        tmp6.add(String.valueOf(g6));
        tmp6.add(String.valueOf(h6));
        tmp7.add(String.valueOf(a7));
        tmp7.add(String.valueOf(b7));
        tmp7.add(String.valueOf(c7));
        tmp7.add(String.valueOf(d7));
        tmp7.add(String.valueOf(e7));
        tmp7.add(String.valueOf(f7));
        tmp7.add(String.valueOf(g7));
        tmp7.add(String.valueOf(h7));
        tmp8.add(String.valueOf(a8));
        tmp8.add(String.valueOf(b8));
        tmp8.add(String.valueOf(c8));
        tmp8.add(String.valueOf(d8));
        tmp8.add(String.valueOf(e8));
        tmp8.add(String.valueOf(f8));
        tmp8.add(String.valueOf(g8));
        tmp8.add(String.valueOf(h8));
        tmp9.add(String.valueOf(a9));
        tmp9.add(String.valueOf(b9));
        tmp9.add(String.valueOf(c9));
        tmp9.add(String.valueOf(d9));
        tmp9.add(String.valueOf(e9));
        tmp9.add(String.valueOf(f9));
        tmp9.add(String.valueOf(g9));
        tmp9.add(String.valueOf(h9));
        tmp10.add(String.valueOf(a10));
        tmp10.add(String.valueOf(b10));
        tmp10.add(String.valueOf(c10));
        tmp10.add(String.valueOf(d10));
        tmp10.add(String.valueOf(e10));
        tmp10.add(String.valueOf(f10));
        tmp10.add(String.valueOf(g10));
        tmp10.add(String.valueOf(h10));
        tmp11.add(String.valueOf(a11));
        tmp11.add(String.valueOf(b11));
        tmp11.add(String.valueOf(c11));
        tmp11.add(String.valueOf(d11));
        tmp11.add(String.valueOf(e11));
        tmp11.add(String.valueOf(f11));
        tmp11.add(String.valueOf(g11));
        tmp11.add(String.valueOf(h11));
        tmp12.add(String.valueOf(a12));
        tmp12.add(String.valueOf(b12));
        tmp12.add(String.valueOf(c12));
        tmp12.add(String.valueOf(d12));
        tmp12.add(String.valueOf(e12));
        tmp12.add(String.valueOf(f12));
        tmp12.add(String.valueOf(g12));
        tmp12.add(String.valueOf(h12));
        tmp13.add(String.valueOf(a13));
        tmp13.add(String.valueOf(b13));
        tmp13.add(String.valueOf(c13));
        tmp13.add(String.valueOf(d13));
        tmp13.add(String.valueOf(e13));
        tmp13.add(String.valueOf(f13));
        tmp13.add(String.valueOf(g13));
        tmp13.add(String.valueOf(h13));
        tmp14.add(String.valueOf(a14));
        tmp14.add(String.valueOf(b14));
        tmp14.add(String.valueOf(c14));
        tmp14.add(String.valueOf(d14));
        tmp14.add(String.valueOf(e14));
        tmp14.add(String.valueOf(f14));
        tmp14.add(String.valueOf(g14));
        tmp14.add(String.valueOf(h14));
        tmp15.add(String.valueOf(a15));
        tmp15.add(String.valueOf(b15));
        tmp15.add(String.valueOf(c15));
        tmp15.add(String.valueOf(d15));
        tmp15.add(String.valueOf(e15));
        tmp15.add(String.valueOf(f15));
        tmp15.add(String.valueOf(g15));
        tmp15.add(String.valueOf(h15));
        tmp16.add(String.valueOf(a16));
        tmp16.add(String.valueOf(b16));
        tmp16.add(String.valueOf(c16));
        tmp16.add(String.valueOf(d16));
        tmp16.add(String.valueOf(e16));
        tmp16.add(String.valueOf(f16));
        tmp16.add(String.valueOf(g16));
        tmp16.add(String.valueOf(h16));
        tmp17.add(String.valueOf(a17));
        tmp17.add(String.valueOf(b17));
        tmp17.add(String.valueOf(c17));
        tmp17.add(String.valueOf(d17));
        tmp17.add(String.valueOf(e17));
        tmp17.add(String.valueOf(f17));
        tmp17.add(String.valueOf(g17));
        tmp17.add(String.valueOf(h17));

        result.add(tmp1);
        result.add(tmp2);
        result.add(tmp3);
        result.add(tmp4);
        result.add(tmp5);
        result.add(tmp6);
        result.add(tmp7);
        result.add(tmp8);
        result.add(tmp9);
        result.add(tmp10);
        result.add(tmp11);
        result.add(tmp12);
        result.add(tmp13);
        result.add(tmp14);
        result.add(tmp15);
        result.add(tmp16);
        result.add(tmp17);
        return result;
    }


    @Override
    public List<AnalyzeInfo> queryanalyzeinfo(Date startTime, Date endTime, String lineIndex) {
        List<AnalyzeInfo> result = new ArrayList<>();
        List<EventDataList> info;
        info = eventdataMapper.getEventDataList(Integer.parseInt(lineIndex), startTime, endTime);

        for (int i = 0; i < info.size(); i++) {
            if (info.get(i).getEventReason() != null || info.get(i).getEventType() != null) {
                AnalyzeInfo record = new AnalyzeInfo();
                record.setEventDetailIndex(info.get(i).getEventDetailIndex());
                record.setIndex(lineIndex);
                record.setTime(info.get(i).getTime());
                float eventvaule = info.get(i).getEventvalue() * 100;
                float persisttime = info.get(i).getPersisttime() * 1000;
                record.setEventvaule(String.valueOf((float) Math.round(eventvaule * 100) / 100));
                record.setPersisttime(String.valueOf(info.get(i).getPersisttime()));
                record.setReason(info.get(i).getEventReason());
                record.setWavetype(info.get(i).getType());
                record.setType(info.get(i).getEventType());
                float yzd = info.get(i).getSeverity();
                if (yzd == 0.0) {
                    float temp = info.get(i).getEventvalue();
                    if (persisttime <= 20) {
                        yzd = 1 - temp;
                    } else if (persisttime > 20 && persisttime <= 200) {
                        yzd = 2 * (1 - temp);
                    } else if (persisttime > 200 && persisttime <= 500) {
                        yzd = 3.3f * (1 - temp);
                    } else if (persisttime > 500 && persisttime <= 10000) {
                        yzd = 5 * (1 - temp);
                    } else {
                        yzd = 10 * (1 - temp);
                    }
                }
                record.setYzd((float) (Math.round(yzd * 100)) / 100);

                record.setFileFlag(info.get(i).getFileFlag());
                result.add(record);
            }
        }

        return result;
    }

    @Override
    public LineInfo getDeviceInfo(Long line_index) {

        LineInfo result = new LineInfo();
        result.setLine_index(String.valueOf(line_index));
        result = deviceInfoMapper.getDeviceInfo(line_index);

        float PT1 = (result.getPT1()) / 1000;
        String pt1 = String.valueOf(PT1);
        float PT2 = (result.getPT2()) / 1000;
        String pt2 = String.valueOf(PT2);
        String pt = pt1 + "/" + pt2;
        result.setPT(pt);

        float CT1 = result.getCT1();
        int cto = (int) CT1;
        String ct1 = String.valueOf(cto);
        float CT2 = result.getCT2();
        int ctt = (int) CT2;
        String ct2 = String.valueOf(ctt);
        String ct = ct1 + "/" + ct2;
        result.setCT(ct);

        String name = result.getName() + "监测点信息";
        result.setName(name);

        if (Long.valueOf("0").equals(result.getStatus())) {
            result.setTxzt("中断");
        } else {
            result.setTxzt("正常");
        }

        DicData dic = new DicData();
        dic = dicDataMapper.selectId(result.getScale());
        result.setScale(dic.getDicName());

        DicData devtype = new DicData();
        devtype = dicDataMapper.selectId(result.getDevType());
        result.setDevType(devtype.getDicName());

        DicData loadType = new DicData();
        loadType = dicDataMapper.selectId(result.getLoadType());
        result.setLoadType(loadType.getDicName());

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String time = sdf.format(result.getUpdatetime());
        result.setTime(time);

        if (result.getDevType().lastIndexOf("_CLD") > 0) {
            LineInfo tmp = deviceInfoMapper.getFlowInfo(line_index);
            if (tmp == null) {
                result.setBaseFlow(0);
                result.setExtendFlow(0);
                result.setUseFlow(0);
            } else {
                result.setBaseFlow(tmp.getBaseFlow());
                result.setExtendFlow(tmp.getExtendFlow());
                float used = 100 * tmp.getUseFlow();
                result.setUseFlow((float) (Math.round(used * 100)) / 100);
            }
        }

        return result;
    }

    /**
     * 获取在线和离线均有的设备树
     * 需求：
     * 1：装置下没有监测点，则装置节点不显示
     * 2：变电站下没有装置，则变电站节点不显示
     * 3：供电公司下没有变电站，则供电公司不显示
     * 4：省会下没有供电公司，则省会不显示
     * pid父节点ID
     * ppid父节点nodeIndex
     */
    @Override
    public List<Tree> getOnlineDeviceTree() {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String localTree = "全国";
        //待返回的设备树
        List<Tree> treeList = new ArrayList<>();
        //超级根节点（全国）
        treeList.add(getTreeNode(localTree, 100, 0, false, 0, 0, 0, 0, 0, 1));
        //查询出有监测点的装置（需要区分离线、在线；暂降、稳态系统）
        DeviceType deviceType = userUtil.getOnLineDeviceType();
        List<Tree> pro = treeMapper.getProInfoByDevice(deviceType.getDevModel(), deviceType.getDataType());
        //无省会，返回全国根节点
        if (CollectionUtils.isEmpty(pro)) {
            return treeList;
        } else {
            //填充省会节点
            int p = pIdNumber, gdp = pIdNumber * 2, subp = pIdNumber * 3, devp = pIdNumber * 4, svp = pIdNumber * 5, linep = pIdNumber * 6;
            for (int i = 0; i < pro.size(); i++) {
                //省会节点 userUtil.getDicnameByIndex(proInfo.get(i).getName())
                treeList.add(getTreeNode(pro.get(i).getName(), ++p, 1, true, 100, 0, pro.get(i).getNodeIndex(), 0, 0, 1));
                //根据当前省会索引获取供电公司的树信息
                List<Tree> gdInfomation = treeMapper.getGDInfoByDevice(deviceType.getDevModel(), deviceType.getDataType(), pro.get(i).getNodeIndex());
                //填充供电公司节点
                for (int g = 0; g < gdInfomation.size(); g++) {
                    //供电公司节点
                    treeList.add(getTreeNode(gdInfomation.get(g).getName(), ++gdp, 2, false, p, pro.get(i).getNodeIndex(), gdInfomation.get(g).getNodeIndex(), 0, 0, 1));
                    //根据当前供电公司获取变电站的树信息
                    List<Tree> subInfo = treeMapper.getSubInfoByDevice(deviceType.getDevModel(), deviceType.getDataType(), gdInfomation.get(g).getNodeIndex());
                    //填充变电站节点
                    for (int s = 0; s < subInfo.size(); s++) {
                        treeList.add(getTreeNode(subInfo.get(s).getName(), ++subp, 3, false, gdp, gdInfomation.get(g).getNodeIndex(), subInfo.get(s).getNodeIndex(), 0, 0, 1));
                        //根据当前变电站获取装置的树信息
                        List<Tree> devInfo = treeMapper.getDevInfoByDevice(deviceType.getDevModel(), deviceType.getDataType(), subInfo.get(s).getNodeIndex());
                        //填充装置节点
                        for (int d = 0; d < devInfo.size(); d++) {
                            treeList.add(getTreeNode(devInfo.get(d).getName(), ++devp, 4, false, subp, subInfo.get(s).getNodeIndex(), devInfo.get(d).getNodeIndex(), 0, 0, 1));
                            //根据当前装置获取母线的树信息
                            List<Tree> subvInfo = treeMapper.getSubvInfoByDevice(devInfo.get(d).getNodeIndex());
                            //填充母线节点
                            for (int sv = 0; sv < subvInfo.size(); sv++) {
                                treeList.add(getTreeNode(subvInfo.get(sv).getName(), ++svp, 5, false, devp, devInfo.get(d).getNodeIndex(), subvInfo.get(sv).getNodeIndex(), 0, 0, 1));
                                //根据当前母线获取监测点的树信息
                                List<Tree> lineInfo = treeMapper.getLineInfoByDevice(subvInfo.get(sv).getNodeIndex());
                                //填充监测点节点
                                for (int l = 0; l < lineInfo.size(); l++) {
                                    treeList.add(getTreeNode(lineInfo.get(l).getName(), ++linep, 6, false, svp, subvInfo.get(sv).getNodeIndex(), lineInfo.get(l).getNodeIndex(), lineInfo.get(l).getState(), lineInfo.get(l).getStatus(), 2));
                                }
                            }
                        }
                    }
                }

            }
        }
        return treeList;
    }

    /**
     * 获取离线设备树，提供给用户添加波形文件
     */
    @Override
    public List<Tree> getOfflineDeviceTree() {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "台账管理";
        List<Tree> list = new ArrayList<>();
        List<Integer> index0 = new ArrayList<>();
        List<Integer> index = new ArrayList<>();
        List<Tree> pro = treeMapper.getProInfo();
        if (pro.size() == 0) {
            //库中没有省信息，直接返回一个裸节点树回去
            list.add(getTreeNode(dky, 100, 0, false, 0, 0, 0, 0, 0, 1));
            return list;
        } else {
            //根据省索引，获取下属所有供电公司信息
            for (int i = 0; i < pro.size(); i++) {
                index0.add(pro.get(i).getNodeIndex());
            }
            List<Tree> gdInfo = treeMapper.getGdByPro(index0);
            //没有任何供电公司信息，直接返回省信息树
            if (gdInfo == null || gdInfo.size() == 0) {
                int p = pIdNumber;
                for (int i = 0; i < pro.size(); i++) {
                    //省会节点
                    list.add(getTreeNode(userUtil.getDicnameByIndex(pro.get(i).getName()), ++p, 1, true, 0, 0, pro.get(i).getNodeIndex(), 0, 0, 1));
                }
                return list;
            } else {
                for (int n = 0; n < gdInfo.size(); n++) {
                    index.add(gdInfo.get(n).getNodeIndex());
                }
            }

            //首先存入省会、供电公司的树节点
            //省会
            int p0 = pIdNumber;
            Map<Integer, Integer> value0 = new HashMap<>();
            for (int i = 0; i < pro.size(); i++) {
                //省会节点
                list.add(getTreeNode(pro.get(i).getName(), ++p0, 1, true, 0, 0, pro.get(i).getNodeIndex(), 0, 0, 1));
                value0.put(pro.get(i).getNodeIndex(), p0);
            }
            //供电公司
            int p = pIdNumber * 2;
            Map<Integer, Integer> value = new HashMap<>();
            for (int i = 0; i < gdInfo.size(); i++) {
                //供电公司节点
                list.add(getTreeNode(gdInfo.get(i).getName(), ++p, 2, false, value0.get(gdInfo.get(i).getpId()), gdInfo.get(i).getpId(), gdInfo.get(i).getNodeIndex(), 0, 0, 1));
                value.put(gdInfo.get(i).getNodeIndex(), p);
            }
            //查询变电站，没有变电站，直接返回之前的数据
            List<Tree> subInfo = treeMapper.getSubInfo(index);
            if (subInfo == null || subInfo.size() == 0) {
                return list;
            }
            //否则存入变电站的树节点
            //变电站
            Map<Integer, Integer> value1 = new HashMap<>();
            int p1 = pIdNumber * 3;
            for (int i = 0; i < subInfo.size(); i++) {
                if (value.get(subInfo.get(i).getpId()) != null) {
                    //变电站节点
                    list.add(getTreeNode(subInfo.get(i).getName(), ++p1, 3, false, value.get(subInfo.get(i).getpId()), subInfo.get(i).getpId(), subInfo.get(i).getNodeIndex(), 0, 0, 1));
                    value1.put(subInfo.get(i).getNodeIndex(), p1);
                }
            }
            //查询装置，没有装置，直接返回
            DeviceType deviceType = userUtil.getOffLineDeviceType();
            List<Tree> devInfo = treeMapper.getOffLineDevice(index, deviceType.getDevModel(), deviceType.getDataType());
            if (devInfo == null || devInfo.size() == 0) {
                return list;
            }
            //否则存入装置的树节点
            //装置
            Map<Integer, Integer> value2 = new HashMap<>();
            int p2 = pIdNumber * 4;
            for (int i = 0; i < devInfo.size(); i++) {
                if (value1.get(devInfo.get(i).getpId()) != null) {
                    //装置节点
                    list.add(getTreeNode(devInfo.get(i).getName(), ++p2, 4, false, value1.get(devInfo.get(i).getpId()), devInfo.get(i).getpId(), devInfo.get(i).getNodeIndex(), 0, 0, 1));
                    value2.put(devInfo.get(i).getNodeIndex(), p2);
                }
            }
            //母线没有数据，直接返回
            List<Tree> subvInfo = treeMapper.getSubv(index);
            if (subvInfo == null || subvInfo.size() == 0) {
                return list;
            }
            //否则存入母线的树节点
            //母线
            Map<Integer, Integer> value3 = new HashMap<>();
            int p3 = pIdNumber * 5;
            for (int i = 0; i < subvInfo.size(); i++) {
                if (value2.get(subvInfo.get(i).getpId()) != null) {
                    //母线节点
                    list.add(getTreeNode(subvInfo.get(i).getName(), ++p3, 5, false, value2.get(subvInfo.get(i).getpId()), subvInfo.get(i).getpId(), subvInfo.get(i).getNodeIndex(), 0, 0, 1));
                    value3.put(subvInfo.get(i).getNodeIndex(), p3);
                }
            }
            //监测点没有数据，直接返回
            List<Tree> lineInfo = treeMapper.getLineInfo(index);
            if (lineInfo == null || lineInfo.size() == 0) {
                return list;
            }
            //否则存入监测点的树节点
            //监测点
            int p4 = pIdNumber * 6;
            for (int i = 0; i < lineInfo.size(); i++) {
                if (value3.get(lineInfo.get(i).getpId()) != null) {
                    //监测点信息
                    list.add(getTreeNode(lineInfo.get(i).getName(), ++p4, 6, false, value3.get(lineInfo.get(i).getpId()), lineInfo.get(i).getpId(), lineInfo.get(i).getNodeIndex(), lineInfo.get(i).getState(), lineInfo.get(i).getStatus(), 2));
                }
            }
            return list;
        }
    }

    /**
     * 获取在线设备树，提供给用户添加暂态波形文件（只展示省份及以下）
     */
    @Override
    public List<Tree> getOnlineTreeAllSys() {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "全国";

        List<Tree> list = new ArrayList<Tree>();

        List<Integer> index1 = new ArrayList<>();
        List<Integer> index0 = new ArrayList<>();
        List<Integer> index = new ArrayList<>();
        List<Tree> proj = treeMapper.getProjInfoByName(dky);

        if (proj.size() == 0) {
            Tree dto = new Tree();
            dto.setId(100);
            dto.setNodeType(0);
            dto.setpId(0);
            dto.setPpId(0);
            dto.setName(dky);
            list.add(dto);
            return list;
        } else {
            /*Tree dt = new Tree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);*/

            //项目
            Map<Integer, Integer> value00 = new HashMap<Integer, Integer>();
            int p00 = pIdNumber / 10;
            for (int i = 0; i < proj.size(); i++) {
                /*Tree dto = new Tree();
                dto.setId(++p00);
                dto.setName(proj.get(i).getName());
                dto.setpId(100);
                dto.setPpId(100);
                dto.setNodeIndex(proj.get(i).getNodeIndex());
                dto.setNodeType(1);
                list.add(dto);*/
                value00.put(proj.get(i).getNodeIndex(), p00);
            }

            for (int i = 0; i < proj.size(); i++) {
                index0.add(proj.get(i).getNodeIndex());
            }
            List<Tree> pro = treeMapper.getProByProj(index0);

            //省份
            if (pro.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
            int p0 = pIdNumber;
            for (int i = 0; i < pro.size(); i++) {
                if (value00.get(pro.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p0);
                    dto.setName(userUtil.getDicnameByIndex(pro.get(i).getName()));
                    dto.setpId(value00.get(pro.get(i).getpId()));
                    dto.setPpId(pro.get(i).getpId());
                    dto.setNodeIndex(pro.get(i).getNodeIndex());
                    dto.setNodeType(2);
                    list.add(dto);
                    value0.put(pro.get(i).getNodeIndex(), p0);
                }
            }

            for (int m = 0; m < pro.size(); m++) {
                index1.add(pro.get(m).getNodeIndex());
            }
            List<Tree> gdInfo = treeMapper.getGdByPro(index1);

            //供电公司
            if (gdInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value = new HashMap<Integer, Integer>();
            int p = pIdNumber * 2;
            for (int i = 0; i < gdInfo.size(); i++) {
                if (value0.get(gdInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p);
                    dto.setName(gdInfo.get(i).getName());
                    dto.setpId(value0.get(gdInfo.get(i).getpId()));
                    dto.setPpId(gdInfo.get(i).getpId());
                    dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
                    dto.setNodeType(3);
                    list.add(dto);
                    value.put(gdInfo.get(i).getNodeIndex(), p);
                }
            }
            for (int n = 0; n < gdInfo.size(); n++) {
                index.add(gdInfo.get(n).getNodeIndex());
            }
            List<Tree> subInfo = treeMapper.getSubInfo(index);

            //变电站
            if (subInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
            int p1 = pIdNumber * 3;
            for (int i = 0; i < subInfo.size(); i++) {
                if (value.get(subInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p1);
                    dto.setName(subInfo.get(i).getName());
                    dto.setpId(value.get(subInfo.get(i).getpId()));
                    dto.setPpId(subInfo.get(i).getpId());
                    dto.setNodeIndex(subInfo.get(i).getNodeIndex());
                    dto.setNodeType(4);
                    list.add(dto);
                    value1.put(subInfo.get(i).getNodeIndex(), p1);
                }
            }

            List<Tree> devInfo = new ArrayList<>();
            String systype = TokenManager.getSysType();
            String systypezt = appConfig.getSysTypeZt();
            String systypewt = appConfig.getSysTypeWt();
            if (systype.equals(systypezt)) {
                devInfo = treeMapper.getDeviceZT(index);
            } else {
                devInfo = treeMapper.getDeviceWT(index);
            }

            //终端
            if (devInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();
            int p2 = pIdNumber * 4;
            for (int i = 0; i < devInfo.size(); i++) {
                if (value1.get(devInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p2);
                    dto.setName(devInfo.get(i).getName());
                    dto.setpId(value1.get(devInfo.get(i).getpId()));
                    dto.setPpId(devInfo.get(i).getpId());
                    dto.setNodeIndex(devInfo.get(i).getNodeIndex());
                    dto.setNodeType(5);
                    list.add(dto);
                    value2.put(devInfo.get(i).getNodeIndex(), p2);
                }
            }

            List<Tree> subvInfo = treeMapper.getSubv(index);

            //母线
            if (subvInfo.size() == 0) {
                return list;
            }
            Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
            int p3 = pIdNumber * 5;
            for (int i = 0; i < subvInfo.size(); i++) {
                if (value2.get(subvInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p3);
                    dto.setName(subvInfo.get(i).getName());
                    dto.setpId(value2.get(subvInfo.get(i).getpId()));
                    dto.setPpId(subvInfo.get(i).getpId());
                    dto.setNodeIndex(subvInfo.get(i).getNodeIndex());
                    dto.setNodeType(6);
                    list.add(dto);
                    value3.put(subvInfo.get(i).getNodeIndex(), p3);
                }
            }

            List<Tree> lineInfo = treeMapper.getLineInfo(index);

            //监测点
            if (lineInfo.size() == 0) {
                return list;
            }
            int p4 = pIdNumber * 6;
            for (int i = 0; i < lineInfo.size(); i++) {
                if (value3.get(lineInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p4);
                    dto.setName(lineInfo.get(i).getName());
                    dto.setpId(value3.get(lineInfo.get(i).getpId()));
                    dto.setPpId(lineInfo.get(i).getpId());
                    dto.setNodeIndex(lineInfo.get(i).getNodeIndex());
                    dto.setNodeType(7);
                    dto.setState(lineInfo.get(i).getState());
                    dto.setStatus(lineInfo.get(i).getStatus());
                    list.add(dto);
                }
            }

            return list;
        }
    }

    /**
     * 根据当前装置的索引，返回该装置的IP
     *
     * @param deviceIndex 装置索引
     */
    @Override
    public String getIPByIndex(String deviceIndex) {
        Device device = new Device();
        try {
            device.setDevIndex(Long.parseLong(deviceIndex));
            device = deviceMapper.selectOne(device);
        } catch (Exception e) {
            logger.error("根据装置索引获取IP异常，原因：" + e.toString());
            //可能转换异常或者查询异常，返回空索引
            return "";
        }
        if (null == device || StringUtils.isEmpty(device.getIp())) {
            return "";
        } else {
            return device.getIp();
        }
    }

    /**
     * 根据事件索引获取装置IP
     *
     * @param index 事件索引
     */
    @Override
    public String getIPByEventIndex(String index) {
        String ip = deviceMapper.getIPByEventIndex(index);
        return StringUtils.isEmpty(ip) ? "" : ip;
    }

    /**
     * 创建节点
     */
    private Tree getTreeNode(String name, int id, int nodeType, boolean open, int pid, int ppid, int nodeIndex, int state, int status, int flagType) {
        Tree dto = new Tree();
        if (flagType == 1) {
            //最基础的，比如省会、供电公司
            dto.setId(id);
            dto.setNodeType(nodeType);
            dto.setpId(pid);
            dto.setPpId(ppid);
            dto.setName(name);
            dto.setNodeIndex(nodeIndex);
            dto.setOpen(open);
        } else if (flagType == 2) {
            dto.setId(id);
            dto.setNodeType(nodeType);
            dto.setpId(pid);
            dto.setPpId(ppid);
            dto.setName(name);
            dto.setNodeIndex(nodeIndex);
            dto.setState(state);
            dto.setStatus(status);
            dto.setOpen(open);
        }
        return dto;
    }

    @Override
    public String getZIPFileInfo(HttpServletResponse response, String eventIndex) {
        LineInfo result = new LineInfo();
        String dlresult;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String path = appConfig.getWavePath();
        EventDetail eventDetail;
        eventDetail = eventDetailMapper.selectByIndex(eventIndex);
        Long lineId = eventDetail.getLineId();
        Line line = new Line();
        line.setLineIndex(lineId);
        line = lineMapper.selectOne(line);
        Device device = new Device();
        device.setDevIndex(line.getDevIndex());
        device = deviceMapper.selectOne(device);
        if (null == result) {
            dlresult = "失败";
        } else {
            String ip = File.separator + device.getIp();
            path = path + ip;
            String timeID = "";
            Date date = eventDetail.getTimeId();
            String dateString = sdf.format(date);
            String year = dateString.substring(0, 10);
            year = year.replaceAll("-", "");
            String hour = dateString.substring(11);
            hour = hour.replaceAll(":", "");
            timeID = year + "_" + hour + "_" + PubUtils.getMs(eventDetail.getMs());

            boolean flags = PubUtils.judgeWaveName(eventDetail, path, null);
            String path1, path2;
            if (flags) {
                path1 = path + File.separator + eventDetail.getWaveName() + ".CFG";
                path2 = path + File.separator + eventDetail.getWaveName() + ".DAT";
            } else {
                timeID = lineId + "_" + timeID;
                path1 = path + File.separator + eventDetail.getWaveName() + ".CFG";
                path2 = path + File.separator + eventDetail.getWaveName() + ".DAT";
            }
            String filename1 = "";
            filename1 = timeID + ".CFG";
            String filename2 = "";
            filename2 = timeID + ".DAT";
            String zipName = timeID + ".zip";
            String zipPath = path + File.separator + zipName;
            if (filename1 == null || filename2 == null) {
                logger.error("导出失败！文件不存在");
                dlresult = "失败";
            } else {
                File file1 = new File(path1);
                File file2 = new File(path2);
                List<File> files = new ArrayList<>();
                if (file1.exists() && file2.exists()) {
                    dlresult = "成功";
                } else {
                    dlresult = "失败";
                }
            }
        }

        return dlresult;
    }

    @Override
    public void downZIPFileInfo(HttpServletResponse response, String eventIndex) {
        LineInfo result = new LineInfo();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String path = appConfig.getWavePath();
        EventDetail eventDetail;
        eventDetail = eventDetailMapper.selectByIndex(eventIndex);

        Long lineId = eventDetail.getLineId();
        Line line = new Line();
        line.setLineIndex(lineId);
        line = lineMapper.selectOne(line);
        Device device = new Device();
        device.setDevIndex(line.getDevIndex());
        device = deviceMapper.selectOne(device);

        if (result == null) {
            logger.error("导出失败！");
        } else {
            String ip = File.separator + device.getIp();
            path = path + ip;
            String timeID = "";
            Date date = eventDetail.getTimeId();
            String dateString = sdf.format(date);
            String year = dateString.substring(0, 10);
            year = year.replaceAll("-", "");
            String hour = dateString.substring(11);
            hour = hour.replaceAll(":", "");
            timeID = year + "_" + hour + "_" + PubUtils.getMs(eventDetail.getMs());

            boolean flags = PubUtils.judgeWaveName(eventDetail, path, null);
            String path1, path2;
            if (flags) {
                path1 = path + File.separator + eventDetail.getWaveName() + ".CFG";
                path2 = path + File.separator + eventDetail.getWaveName() + ".DAT";
            } else {
                timeID = lineId + "_" + timeID;
                path1 = path + File.separator + eventDetail.getWaveName() + ".CFG";
                path2 = path + File.separator + eventDetail.getWaveName() + ".DAT";
            }

            String filename1 = "";
            filename1 = timeID + ".CFG";

            String filename2 = "";
            filename2 = timeID + ".DAT";

            String zipName = timeID + ".zip";
            String zipPath = path + File.separator + zipName;

            if (filename1 == null || filename2 == null) {
                logger.error("导出失败！文件不存在");
            } else {
                File file1 = new File(path1);
                File file2 = new File(path2);
                List<File> files = new ArrayList<>();

                if (file1.exists() && file2.exists()) {
                    files.add(file1);
                    files.add(file2);

                    try {
                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(zipPath));
                        ZipOutputStream zos = new ZipOutputStream(bos);
                        ZipEntry ze = null;
                        for (int i = 0; i < files.size(); i++) {//将所有需要下载的pdf文件都写入临时zip文件
                            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(files.get(i)));
                            ze = new ZipEntry(files.get(i).getName());
                            zos.putNextEntry(ze);
                            int s = -1;
                            while ((s = bis.read()) != -1) {
                                zos.write(s);
                            }
                            bis.close();
                        }
                        zos.flush();
                        zos.close();
                    } catch (IOException e) {
                        logger.error("读取文件发生异常，异常是" + e.getMessage());
                    }
                    // 设置强制下载不打开
                    response.setContentType("application/force-download");
                    // 设置文件名
                    response.addHeader("Content-Disposition",
                            "attachment;fileName=" + zipName);
                    byte[] buffer = new byte[1024];
                    FileInputStream fis = null;
                    BufferedInputStream bis = null;
                    File zipfile = new File(zipPath);
                    try {
                        fis = new FileInputStream(zipfile);
                        bis = new BufferedInputStream(fis);
                        OutputStream os = response.getOutputStream();
                        int i = bis.read(buffer);
                        while (i != -1) {
                            os.write(buffer, 0, i);
                            i = bis.read(buffer);
                        }
                        logger.info("success");
                    } catch (Exception e) {
                        logger.info("fall");
                    } finally {
                        if (bis != null) {
                            try {
                                bis.close();
                            } catch (IOException e) {
                                logger.error("bis关闭连接失败，原因是" + e.getMessage());
                            }
                        }
                        if (fis != null) {
                            try {
                                fis.close();
                            } catch (IOException e) {
                                logger.error("fis");
                            }
                        }
                        zipfile.delete();
                    }
                } else {
                    logger.error("导出失败！文件不全");
                }
            }
        }
    }

    @Override
    public int getRole(String url) {
        List<Role> list = userUtil.getRoles(TokenManager.getUserId());
        List<String> listRole = new ArrayList<>();

        if (list == null || list.size() == 0) {
            return 0;
        }

        for (Role role : list) {
            listRole.add(role.getRoleIndex());
        }

        return lineMapper.getRole(url, listRole) > 0 ? 1 : 0;
    }

    @Override
    public DeviceMapInfo getMsgInfo(Date start, Date end) {
        DeviceGeneral deviceGeneral = getDeviceOnlineRate(start, end, "");
        DeviceMapInfo deviceMapInfo = new DeviceMapInfo();
        List<AreaGeneralData> areaGeneralDatas = userUtil.getAreaGeneralRun();

        List<Integer> lineList = new ArrayList<>();
        List<Integer> devList = new ArrayList<>();
        List<Integer> gwLineList = new ArrayList<>();
        List<Integer> gwDevList = new ArrayList<>();
        for (AreaGeneralData areaGeneralData : areaGeneralDatas) {
            lineList.addAll(areaGeneralData.getLineIndexs());
            devList.addAll(areaGeneralData.getDeviceIndexs());
            gwLineList.addAll(getGwLine(areaGeneralData.getLineIndexs()));
        }

        lineList = this.hashList(lineList);
        gwLineList = this.hashList(gwLineList);
        devList = this.hashList(devList);
        if (gwLineList.size() > 0) {
            gwDevList = deviceMapper.getDeviceIndexByLineIndex(gwLineList);
            gwDevList = this.hashList(gwDevList);
        }

        Depts dep = userUtil.getCurrentDept();
        deviceMapInfo.setName(dep.getArea());
        deviceMapInfo.setPointCount(String.valueOf(lineList.size()));
        deviceMapInfo.setGwPointCount(String.valueOf(gwLineList.size()));

        if (deviceGeneral != null) {
            float f = 0f;
            float f1 = 0f;
            int k = 0;
            int m = 0;

            deviceMapInfo.setCount(String.valueOf(devList.size()));
            deviceMapInfo.setGwCount(String.valueOf(gwDevList.size()));

            DeviceValue tmp = new DeviceValue();
            getGwData(tmp, gwLineList, start, end);

            String onlinerate = getOnline(devList, start, end);
            //在线率
            deviceMapInfo.setOnline(onlinerate.equals("3.14159") ? "0" : onlinerate);
            deviceMapInfo.setGwOnline(tmp.getGwonline().equals("3.14159") ? "0" : tmp.getGwonline());

            String dataIntegrality = getIntegrality(lineList, start, end);
            String gwdataIntegrality = getGwIntegrality(gwLineList, start, end);
            //数据完整率
            deviceMapInfo.setDataIntegrality(dataIntegrality.equals("3.14159") ? "0" : dataIntegrality);
            deviceMapInfo.setGwDataIntegrality(gwdataIntegrality.equals("3.14159") ? "0" : gwdataIntegrality);
        }

        return deviceMapInfo;
    }


    @Override
    public List<Tree> getStrategyTree(String name) {
        String dky = "电网拓扑";

        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());

        List<Tree> list = new ArrayList<>();

        List<Integer> index = userUtil.listLine();

        if (index.size() == 0) {
            Tree dto = new Tree();
            dto.setId(100);
            dto.setNodeType(0);
            dto.setpId(0);
            dto.setPpId(0);
            dto.setName(dky);
            list.add(dto);
            return list;
        } else {
            Tree dt = new Tree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);

            List<Tree> proInfo = treeMapper.getTreeProInfo(index);
            List<Tree> gdInfo = treeMapper.getTreeGdInfo(index);
            List<Tree> subInfo = treeMapper.getTreeSubInfo(index);

            List<Tree> subvInfo = treeMapper.getNodeTreeSubvInfo(index);
            List<Tree> lineInfo = treeMapper.getLineInfo(index);
            if (proInfo == null || gdInfo == null || subInfo == null || subvInfo == null
                    || lineInfo == null) {
                return list;
            }

            Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
            int p0 = pIdNumber;
            for (int i = 0; i < proInfo.size(); i++) {
                Tree dto = new Tree();
                dto.setId(++p0);
                dto.setName(userUtil.getDicnameByIndex(proInfo.get(i).getName()));
                dto.setpId(100);
                dto.setPpId(100);
                dto.setNodeIndex(proInfo.get(i).getNodeIndex());
                dto.setNodeType(1);

                int proIndex = proInfo.get(i).getNodeIndex();
                list.add(dto);
                value0.put(proInfo.get(i).getNodeIndex(), p0);
            }

            Map<Integer, Integer> value = new HashMap<Integer, Integer>();
            int p = pIdNumber * 2;
            for (int i = 0; i < gdInfo.size(); i++) {
                Tree dto = new Tree();
                dto.setId(++p);
                dto.setName(gdInfo.get(i).getName());
                dto.setpId(value0.get(gdInfo.get(i).getpId()));
                dto.setPpId(gdInfo.get(i).getpId());
                dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
                dto.setNodeType(2);

                Line gd_line = new Line();
                gd_line.setGdIndex((long) gdInfo.get(i).getNodeIndex());
                list.add(dto);
                value.put(gdInfo.get(i).getNodeIndex(), p);
            }

            Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
            int p1 = pIdNumber * 3;
            for (int i = 0; i < subInfo.size(); i++) {
                if (value.get(subInfo.get(i).getpId()) != null) {
                    Tree dto = new Tree();
                    dto.setId(++p1);
                    dto.setName(subInfo.get(i).getName());
                    dto.setpId(value.get(subInfo.get(i).getpId()));
                    dto.setPpId(subInfo.get(i).getpId());
                    dto.setNodeIndex(subInfo.get(i).getNodeIndex());
                    dto.setNodeType(3);

                    Line sub_line = new Line();
                    sub_line.setSubIndex((long) subInfo.get(i).getNodeIndex());
                    list.add(dto);
                    value1.put(subInfo.get(i).getNodeIndex(), p1);
                }
            }

            Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
            int p3 = pIdNumber * 4;
            for (int i = 0; i < subvInfo.size(); i++) {
                if (value1.get(subvInfo.get(i).getpId()) != null) {
                    List<Tree> lines = treeMapper.getTreeBySubv((long) subvInfo.get(i).getNodeIndex());
                    for (Tree linetmp : lines) {
                        String nameinfo = subvInfo.get(i).getName() + "_" + linetmp.getName();
                        Tree dto = new Tree();
                        dto.setId(++p3);
                        dto.setName(nameinfo);
                        dto.setpId(value1.get(subvInfo.get(i).getpId()));
                        dto.setPpId(subvInfo.get(i).getpId());
                        dto.setNodeIndex(linetmp.getNodeIndex());
                        dto.setNodeType(4);
                        dto.setState(linetmp.getState());
                        dto.setStatus(linetmp.getStatus());
                        dto.setPttype(linetmp.getPttype());

                        List<Integer> indexs = new ArrayList<>();
                        for (int n = 0; n < lines.size(); n++) {
                            indexs.add(lines.get(n).getNodeIndex());
                        }
                        list.add(dto);
                        value3.put(subvInfo.get(i).getNodeIndex(), p3);
                    }
                }
            }

            return list;


        }
    }

    public List<Integer> hashList(List<Integer> lists) {
        List<Integer> result = new ArrayList<>();
        HashSet hset = new HashSet(lists);
        Iterator i = hset.iterator();
        while (i.hasNext()) {
            result.add((Integer) i.next());
        }

        return result;
    }

    @Override
    public List<DeviceDetail> selState(Integer devIndex) {
        // TODO Auto-generated method stub
        return deviceDetailMapper.selState(devIndex, userUtil.listGD());
    }

    @Override
    public List<List> getTerminalLogsDetail(String terminalType, Date startTime, Date endTime) {
        //获取本系统下的所有终端id
        List<Integer> devIndex = userUtil.getDevIndex();
        List<Integer> lineIdex = userUtil.getLineIndexsByDeviceIndexs(devIndex);
        List<TerminalLogs> terminalLogs = new ArrayList<>();
        List<List> devicedetail = new ArrayList<>();
        if (terminalType.equals("")) {
            terminalLogs = terminalLogsMapper.selectLogs(startTime, endTime);
        } else {
            terminalLogs = terminalLogsMapper.selectLog(terminalType, startTime, endTime);
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < terminalLogs.size(); i++) {
            int numbers = i + 1;
            List<String> devicedetails = new ArrayList<>();
            devicedetails.add(String.valueOf(numbers));//序号
            if (terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.deviceLogs.getTerminalIndex())
                    || terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.flowLogs.getTerminalIndex())
                    || terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.constantValueInLog.getTerminalIndex())
                    || terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.versonDevLog.getTerminalIndex())) {
                if (devIndex.contains(Integer.valueOf(terminalLogs.get(i).getObjIndex()))) {
                    Device device = new Device();
                    device = deviceMapper.selectByPrimaryKey(Long.valueOf(terminalLogs.get(i).getObjIndex()));
                    devicedetails.add(device.getName());//名称
                    devicedetails.add(TerminalLogsEnum.getValue(terminalLogs.get(i).getTerminalType()));
                    User user = new User();
                    user.setUserIndex(terminalLogs.get(i).getUserIndex());
                    user = userMapper.selectOne(user);
                    devicedetails.add(user.getLoginName());//更新人
                    devicedetails.add(formatter.format(terminalLogs.get(i).getUpdateTime()));
                    devicedetails.add(terminalLogs.get(i).getTerminalDescribe());
                    devicedetail.add(devicedetails);
                }
            } else if (terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.lineLogs.getTerminalIndex())
                    ||terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.repairInteginte.getTerminalIndex())
                    || terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.constantValueOutLog.getTerminalIndex())) {
                if (lineIdex.contains(Integer.valueOf(terminalLogs.get(i).getObjIndex()))) {
                    Line line = new Line();
                    line = lineMapper.selectByPrimaryKey(Long.valueOf(terminalLogs.get(i).getObjIndex()));
                    devicedetails.add(line.getName());//名称
                    //类型
                    devicedetails.add(TerminalLogsEnum.getValue(terminalLogs.get(i).getTerminalType()));
                    User user = new User();
                    user.setUserIndex(terminalLogs.get(i).getUserIndex());
                    user = userMapper.selectOne(user);
                    devicedetails.add(user.getLoginName());//更新人
                    devicedetails.add(formatter.format(terminalLogs.get(i).getUpdateTime()));
                    devicedetails.add(terminalLogs.get(i).getTerminalDescribe());
                    devicedetail.add(devicedetails);
                }
            } else if (terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.appUser.getTerminalIndex())
                    || terminalLogs.get(i).getTerminalType().equals(TerminalLogsEnum.webUser.getTerminalIndex())) {
                User user = new User();
                user.setUserIndex(terminalLogs.get(i).getObjIndex());
                user = userMapper.selectOne(user);
                devicedetails.add(user.getName());//名称
                //类型
                devicedetails.add(TerminalLogsEnum.getValue(terminalLogs.get(i).getTerminalType()));
                User users = new User();
                users.setUserIndex(terminalLogs.get(i).getUserIndex());
                users = userMapper.selectOne(users);
                devicedetails.add(users.getLoginName());//更新人
                devicedetails.add(formatter.format(terminalLogs.get(i).getUpdateTime()));
                devicedetails.add(terminalLogs.get(i).getTerminalDescribe());
                devicedetail.add(devicedetails);
            }
        }
        return devicedetail;
    }

    @Override
    public List<TerminalLogs> getLogByDevId(String devId,Date startTime,Date endTime){
        return terminalLogsMapper.selectLogByDevId(devId,TerminalLogsEnum.deviceLogs.getTerminalIndex(),startTime,endTime);
    }

    @Override
    public List<EventPushLogsDetail> getEventPushDetail(Date startTime, Date endTime, int resultStatus) {
        List<EventPushLogsDetail> eventPushLogsDetails = new ArrayList<>();
        if (resultStatus == -1) {
            eventPushLogsDetails = eventPushLogsDetailMapper.getEventPushLogsDetails(startTime, endTime);
        } else {
            eventPushLogsDetails = eventPushLogsDetailMapper.getEventPushLogsDetail(resultStatus, startTime, endTime);
        }
        return eventPushLogsDetails;
    }

    @Override
    public int updatEventPushLog(String eventDetailIndex, Integer lineId) {
        return eventPushLogsDetailMapper.updatEventPushLog(eventDetailIndex, lineId, new Date());
    }

    @Override
    public List<IntegrityAnalysisData> getStatisticalAnalysis(String startTime, String endTime, String area, Integer postType, Integer powerId) {
        List<IntegrityAnalysisData> list = new ArrayList<>();
        List<LineInfo> allArea = new ArrayList<>();
        List<AreaGeneralData> ag = userUtil.getAreaDataByInfo(area);
        for (AreaGeneralData item : ag) {
            IntegrityAnalysisData data = new IntegrityAnalysisData();
            data.setDeptName(item.getName());
            data.setDeptIndex(item.getDeptIndex());
            data.setSort(1);
            if (CollUtil.isNotEmpty(item.getLineIndexs())) {
                List<LineInfo> lineInfos = integrityMapper.getLineInfo(item.getLineIndexs(),postType,powerId);
                allArea.addAll(lineInfos);
                List<IntegrityAnalysisData.TypeList> typeList = new ArrayList<>();
                IntegrityAnalysisData.TypeList type = new IntegrityAnalysisData.TypeList();
                type.setName("所属前置机");
                type.setDataLists(getFrontList(lineInfos));

                IntegrityAnalysisData.TypeList type2 = new IntegrityAnalysisData.TypeList();
                type2.setName("监测点状态");
                type2.setDataLists(getLineStatusList(lineInfos));

                typeList.add(type);
                typeList.add(type2);
                data.setTypeLists(typeList);
            }
            list.add(data);
        }
        //新增冀北省
        Depts depts = userUtil.getDeptsByIndex(area);
        if (Objects.equals(depts.getParentNodeId(),"10001")) {
            IntegrityAnalysisData data = new IntegrityAnalysisData();
            data.setDeptName("冀北省");
            data.setDeptIndex(area);
            List<IntegrityAnalysisData.TypeList> typeList = new ArrayList<>();
            IntegrityAnalysisData.TypeList type = new IntegrityAnalysisData.TypeList();
            type.setName("所属前置机");
            type.setDataLists(getFrontList(allArea));
            IntegrityAnalysisData.TypeList type2 = new IntegrityAnalysisData.TypeList();
            type2.setName("监测点状态");
            type2.setDataLists(getLineStatusList(allArea));
            typeList.add(type);
            typeList.add(type2);
            data.setTypeLists(typeList);
            data.setSort(0);
            list.add(data);
        }
        return list.stream().sorted(Comparator.comparing(IntegrityAnalysisData::getSort)).collect(Collectors.toList());
    }

    public List<IntegrityAnalysisData.DataList> getFrontList(List<LineInfo> lineInfos) {
        List<IntegrityAnalysisData.DataList> result = new ArrayList<>();
        Map<String,List<LineInfo>> frontMap = lineInfos.stream().collect(Collectors.groupingBy(LineInfo::getDevName));
        if (CollectionUtils.isEmpty(frontMap)) {
            IntegrityAnalysisData.DataList dataList = new IntegrityAnalysisData.DataList();
            dataList.setName("/");
            dataList.setAllLineCount(0);
            dataList.setRunLineCount(0);
            dataList.setCheckLineCount(0);
            dataList.setBackLineCount(0);
            result.add(dataList);
        } else {
            frontMap.forEach((k,v)->{
                IntegrityAnalysisData.DataList dataList = new IntegrityAnalysisData.DataList();
                dataList.setName(k);
                Map<Long,List<LineInfo>> statusMap = v.stream().collect(Collectors.groupingBy(LineInfo::getStatus));
                dataList.setAllLineCount(v.size());
                dataList.setRunLineCount(CollUtil.isNotEmpty(statusMap.get(0L))?statusMap.get(0L).size():0);
                dataList.setCheckLineCount(CollUtil.isNotEmpty(statusMap.get(1L))?statusMap.get(1L).size():0);
                dataList.setBackLineCount(CollUtil.isNotEmpty(statusMap.get(2L))?statusMap.get(2L).size():0);
                result.add(dataList);
            });
        }
        return result;
    }

    public List<IntegrityAnalysisData.DataList> getLineStatusList(List<LineInfo> lineInfos) {
        List<IntegrityAnalysisData.DataList> result = new ArrayList<>();
        Map<Long,List<LineInfo>> statusMap = lineInfos.stream().collect(Collectors.groupingBy(LineInfo::getStatus));
        IntegrityAnalysisData.DataList dataList = new IntegrityAnalysisData.DataList();
        dataList.setName("/");
        dataList.setAllLineCount(lineInfos.size());
        dataList.setRunLineCount(CollUtil.isNotEmpty(statusMap.get(0L))?statusMap.get(0L).size():0);
        dataList.setCheckLineCount(CollUtil.isNotEmpty(statusMap.get(1L))?statusMap.get(1L).size():0);
        dataList.setBackLineCount(CollUtil.isNotEmpty(statusMap.get(2L))?statusMap.get(2L).size():0);
        result.add(dataList);
        return result;
    }


    /**
     * 根据电压等级返回基准容量
     *
     * @author cdf
     * @date 2021/11/17
     */
    public float getJZCmp(String tmpname) {
        if (tmpname.equals("6kV") || tmpname.equals("10kV")) {
            return 100;
        } else if (tmpname.equals("20kV")) {
            return 200;
        } else if (tmpname.equals("35kV")) {
            return 250;
        } else if (tmpname.equals("66kV")) {
            return 500;
        } else if (tmpname.equals("110kV")) {
            return 750;
        } else if (tmpname.equals("220kV")) {
            return 2000;
        } else if (tmpname.equals("330kV")) {
            return 3000;
        } else if (tmpname.equals("500kV")) {
            return 4500;
        } else if (tmpname.equals("750kV")) {
            return 7000;
        } else if (tmpname.equals("1000kV")) {
            return 9000;
        } else {
            return 10;
        }
    }

}
