package com.njcn.serviceimpl.configuration;

import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.TimeInterval;
import com.njcn.utils.*;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.njcn.mapper.configuration.DicDataMapper;
import com.njcn.mapper.configuration.GDInforMapper;
import com.njcn.mapper.configuration.LineMapper;
import com.njcn.mapper.configuration.ProjectMapper;
import com.njcn.mapper.configuration.TreeMapper;
import com.njcn.mapper.data.AssesMapper;
import com.njcn.mapper.data.OfflLogMapper;
import com.njcn.mapper.data.SynDataMapper;
import com.njcn.pojo.commons.device.Tree;
import com.njcn.pojo.configuration.DicData;
import com.njcn.pojo.configuration.GDInformation;
import com.njcn.pojo.configuration.Line;
import com.njcn.pojo.data.PqsComasses;
import com.njcn.service.configuration.TreeService;
import com.njcn.shiro.token.TokenManager;

@Service
public class TreeServiceImpl implements TreeService {

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

	@Resource
	private TreeMapper treeMapper;

	@Resource
	private GDInforMapper gdInforMapper;

	@Resource
	private LineMapper lineMapper;

	@Autowired
	private AssesMapper assesMapper;

	@Autowired
	private ComAssesUtil comAssesUtil;

	@Autowired
	private UserUtil userUtil;

	@Autowired
	private BalanceInfo balanceInfo;

	@Autowired
	private ProjectMapper projectMapper;

	@Autowired
	private OfflLogMapper offlLogMapper;

	@Autowired
	private DicDataMapper dicDataMapper;

	@Resource
	private SynDataMapper synDataMapper;

	@Autowired
	private AppConfig appConfig;

	public List<Tree> getNodeTreedata(String name, Date startTime, Date endTime) {
		TimeInterval timeInterval = new TimeInterval();
		String dky = "电网拓扑";
		List<List<Integer>> splitList = null;

		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 = new ArrayList<>();
			List<Tree> gdInfo= new ArrayList<>();
			List<Tree> subInfo= new ArrayList<>();
			List<Tree> devInfo = new ArrayList<>();
			List<Tree> subvInfo =new ArrayList<>();
			List<Tree> lineInfo = new ArrayList<>();
			if(index.size()>1000){
				splitList = Utils.splitList(index,1000);
				for(List<Integer> item:splitList){
					List<Tree> proInfoTmp = treeMapper.getTreeProInfo(item);
					List<Tree> gdInfoTmp = treeMapper.getTreeGdInfo(item);
					List<Tree> subInfoTmp = treeMapper.getTreeSubInfo(item);
					List<Tree> devInfoTmp=null;
					if (appConfig.getSysType().equalsIgnoreCase(appConfig.getSysTypeWt())) {
						devInfoTmp = treeMapper.getWTTreeDevInfo(item);
					} else {
						devInfoTmp = treeMapper.getZTTreeDevInfo(item);
					}
					List<Tree> subvInfoTmp= treeMapper.getNodeTreeSubvInfo(item);
					List<Tree> lineInfoTmp = treeMapper.getLineInfo(item);
					if(CollectionUtils.isNotEmpty(proInfoTmp)){
						proInfo.addAll(proInfoTmp);
					}
					if(CollectionUtils.isNotEmpty(gdInfoTmp)){
						gdInfo.addAll(gdInfoTmp);
					}
					if(CollectionUtils.isNotEmpty(subInfoTmp)){
						subInfo.addAll(subInfoTmp);
					}
					if(CollectionUtils.isNotEmpty(devInfoTmp)){
						devInfo.addAll(devInfoTmp);
					}
					if(CollectionUtils.isNotEmpty(subvInfoTmp)){
						subvInfo.addAll(subvInfoTmp);
					}
					if(CollectionUtils.isNotEmpty(lineInfoTmp)){
						lineInfo.addAll(lineInfoTmp);
					}
				}
				//过滤重复
				proInfo = proInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
				gdInfo = gdInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
				subInfo = subInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
				devInfo = devInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
				subvInfo = subvInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
				lineInfo = lineInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
			}else {

				proInfo = treeMapper.getTreeProInfo(index);
				gdInfo = treeMapper.getTreeGdInfo(index);
				subInfo = treeMapper.getTreeSubInfo(index);
				if (appConfig.getSysType().equalsIgnoreCase(appConfig.getSysTypeWt())) {
					devInfo = treeMapper.getWTTreeDevInfo(index);
				} else {
					devInfo = treeMapper.getZTTreeDevInfo(index);
				}
				subvInfo= treeMapper.getNodeTreeSubvInfo(index);
				lineInfo = treeMapper.getLineInfo(index);
			}



			if (proInfo == null || gdInfo == null || subInfo == null || devInfo == 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);


				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);


				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);


					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) {
					int subvId = subvInfo.get(i).getNodeIndex();
					List<Tree> lines = lineInfo.stream().filter(item->item.getpId() == subvId).collect(Collectors.toList());
					if(CollectionUtil.isEmpty(lines)){
						continue;
					}
					for (Tree linetmp : lines) {
						if(index.contains(linetmp.getNodeIndex())){
							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());
							dto.setPowerType(linetmp.getPowerType());


							list.add(dto);
							value3.put(subvInfo.get(i).getNodeIndex(), p3);
						}
					}
				}
			}

			return list;
		}
	}

	@Override
	public List<Tree> getNodePlateTreedata(String name, Date startTime, Date endTime) {
		String dky = "电网拓扑";

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

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

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

		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> devInfo = new ArrayList<>();
			if (appConfig.getSysType().equalsIgnoreCase(appConfig.getSysTypeWt())) {
				devInfo = treeMapper.getWTTreeDevInfoOffline(index);
			} else {
				devInfo = treeMapper.getZTTreeDevInfo(index);
			}
			List<Tree> subvInfo = treeMapper.getNodeTreeSubvInfo(index);
			List<Tree> lineInfo = treeMapper.getLineInfo(index);
			if (proInfo.size() == 0 || gdInfo.size() == 0 || subInfo.size() == 0 || devInfo.size() == 0 || subvInfo.size() == 0
					|| lineInfo.size() == 0) {
				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<Line> lines = lineMapper.getLinesByPro(proIndex);
//				List<Integer> indexs = new ArrayList<>();
//				for (int n = 0; n < lines.size(); n++) {
//					indexs.add(lines.get(n).getLineIndex().intValue());
//				}
//				Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//				int lvl = getLevel(synDatas);
//				dto.setQualityAss(lvl);
				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<Line> lines = lineMapper.select(gd_line);
//				List<Integer> indexs = new ArrayList<>();
//				for (int n = 0; n < lines.size(); n++) {
//					indexs.add(lines.get(n).getLineIndex().intValue());
//				}
//				Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//				int lvl = getLevel(synDatas);
//				dto.setQualityAss(lvl);
				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<Line> lines = lineMapper.select(sub_line);
//					List<Integer> indexs = new ArrayList<>();
//					for (int n = 0; n < lines.size(); n++) {
//						indexs.add(lines.get(n).getLineIndex().intValue());
//					}
//					Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//					int lvl = getLevel(synDatas);
//					dto.setQualityAss(lvl);
					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 = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
					for (Tree linetmp : lines) {
						if(index.contains(linetmp.getNodeIndex())){
							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());
							dto.setPowerType(linetmp.getPowerType());

//							List<Integer> indexs = new ArrayList<>();
//							for (int n = 0; n < lines.size(); n++) {
//								indexs.add(lines.get(n).getNodeIndex());
//							}
//							Float synDatas = getSynData(indexs, startTime, endTime, linetmp.getNodeIndex(), 6l);
//							int lvl = getLevel(synDatas);
//							dto.setQualityAss(lvl);
							list.add(dto);
							value3.put(subvInfo.get(i).getNodeIndex(), p3);
						}
					}
				}
			}

			return list;
		}
	}

	public List<Tree> getScaleTree(String name, Date startTime, Date endTime) {
		String dky = "设备树";

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

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

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


		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 {
			List<DicData> devtype = new ArrayList<>();
			List<List<Integer>> lineTmpList =null;
			if(index.size()>1000){
				lineTmpList = Utils.splitList(index,1000);
				for(List<Integer> itemL:lineTmpList){
					List<DicData> tmp = dicDataMapper.getTreeScale(itemL);
					if(CollectionUtil.isNotEmpty(tmp)){
						devtype.addAll(tmp);
					}
				}
				if(CollectionUtil.isNotEmpty(devtype)){
					//去重
					devtype = devtype.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<DicData>(Comparator.comparing(DicData::getDicName))), ArrayList::new));
				}
			}else{
				devtype = dicDataMapper.getTreeScale(index);
			}

			if (CollectionUtil.isEmpty(devtype)) {
				return list;
			} else {

				for (int y = 1; y <= devtype.size(); y++) {
					List<Tree> proInfo =new ArrayList<>();
					List<Tree> gdInfo = new ArrayList<>();
					List<Tree> subInfo = new ArrayList<>();
					List<Tree> subvInfo = new ArrayList<>();
					DicData tmp = devtype.get(y - 1);
					Map<Integer, Integer> value8 = new HashMap<Integer, Integer>();
					int p8 = 100 * y;
					Tree dt = new Tree();
					dt.setId(p8);
					dt.setName(devtype.get(y - 1).getDicName());
					dt.setpId(0);
					dt.setPpId(0);
					dt.setNodeIndex(y);
					dt.setNodeType(0);

					list.add(dt);
					value8.put(y, p8);

					//超过1000个监测点处理
					if(counterpart.size()>1000){
						for(List<Integer> itemL:lineTmpList){
							List<Tree> proInfoTmp = treeMapper.getScaleProVInfo(itemL, tmp.getDicIndex());
							List<Tree> gdInfoTmp = treeMapper.getScaleGdInfo(itemL, tmp.getDicIndex());
							List<Tree> subInfoTmp = treeMapper.getScaleSubInfo(itemL, tmp.getDicIndex());
							List<Tree> subvInfoTmp = treeMapper.getScaleSubvInfo(itemL, tmp.getDicIndex());
							if(CollectionUtil.isNotEmpty(proInfoTmp)){
								proInfo.addAll(proInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(gdInfoTmp)){
								gdInfo.addAll(gdInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(subInfoTmp)){
								subInfo.addAll(subInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(subvInfoTmp)){
								subvInfo.addAll(subvInfoTmp);
							}
						}
						//去重
						proInfo = proInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						gdInfo = gdInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						subInfo = subInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						subvInfo = subvInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
					}else{
						proInfo = treeMapper.getScaleProVInfo(counterpart, tmp.getDicIndex());
						gdInfo = treeMapper.getScaleGdInfo(counterpart, tmp.getDicIndex());
						subInfo = treeMapper.getScaleSubInfo(counterpart, tmp.getDicIndex());
						subvInfo = treeMapper.getScaleSubvInfo(counterpart, tmp.getDicIndex());
					}


					//List<Tree> devInfo = treeMapper.getScaleDevInfo(index, tmp.getDicIndex());


					if (proInfo == null || subInfo == null || subvInfo == null) {
						return list;
					}

					Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
					int p0 = pIdNumber+p8;
					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(p8);
						dto.setPpId(y);
						dto.setNodeIndex(proInfo.get(i).getNodeIndex());
						dto.setNodeType(1);

//						int proIndex = proInfo.get(i).getNodeIndex();
//						List<Line> lines = lineMapper.getLinesByPro(proIndex);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value0.put(proInfo.get(i).getNodeIndex(), p0);
					}

					Map<Integer, Integer> value = new HashMap<Integer, Integer>();
					int p = pIdNumber * 2+p8;
					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<Line> lines = lineMapper.select(gd_line);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value.put(gdInfo.get(i).getNodeIndex(), p);
					}

					Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
					int p1 = pIdNumber * 3+p8;
					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<Line> lines = lineMapper.select(sub_line);
//							List<Integer> indexs = new ArrayList<>();
//							for (int n = 0; n < lines.size(); n++) {
//								indexs.add(lines.get(n).getLineIndex().intValue());
//							}
//							Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//							int lvl = getLevel(synDatas);
//							dto.setQualityAss(lvl);
							list.add(dto);
							value1.put(subInfo.get(i).getNodeIndex(), p1);
						}
					}

					Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
					int p3 = pIdNumber * 5+p8;
					for (int i = 0; i < subvInfo.size(); i++) {
						if (value1.get(subvInfo.get(i).getpId()) != null) {
							List<Tree> lines = new ArrayList<>();
							if(index.size()>1000){
								for(List<Integer> item:lineTmpList){
									List<Tree> Tmp = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),item);
									if(CollectionUtil.isNotEmpty(Tmp)){
										lines.addAll(Tmp);
									}
								}
							}else{
								lines = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
							}

							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());
								dto.setPowerType(linetmp.getPowerType());

//								List<Integer> indexs = new ArrayList<>();
//								for (int n = 0; n < lines.size(); n++) {
//									indexs.add(lines.get(n).getNodeIndex());
//								}
//								Float synDatas = getSynData(indexs, startTime, endTime,
//										linetmp.getNodeIndex(), 6l);
//								int lvl = getLevel(synDatas);
//								dto.setQualityAss(lvl);
								list.add(dto);
								value3.put(subvInfo.get(i).getNodeIndex(), p3);
							}
						}
					}
				}
				return list;
			}
		}
	}

	public List<Tree> getScalePlateTree(String name, Date startTime, Date endTime) {
		String dky = "设备树";

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

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

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

		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 {
			List<DicData> devtype = dicDataMapper.getTreeScale(index);
			if (devtype == null) {
				return list;
			} else {
				for (int y = 1; y <= devtype.size(); y++) {
					DicData tmp = devtype.get(y - 1);
					Map<Integer, Integer> value8 = new HashMap<Integer, Integer>();
					int p8 = 100 * y;
					Tree dt = new Tree();
					dt.setId(p8);
					dt.setName(devtype.get(y - 1).getDicName());
					dt.setpId(0);
					dt.setPpId(0);
					dt.setNodeIndex(y);
					dt.setNodeType(0);

					list.add(dt);
					value8.put(y, p8);

					List<Tree> proInfo = treeMapper.getScaleProVInfo(index, tmp.getDicIndex());
					List<Tree> gdInfo = treeMapper.getScaleGdInfo(index, tmp.getDicIndex());
					List<Tree> subInfo = treeMapper.getScaleSubInfo(index, tmp.getDicIndex());
					List<Tree> devInfo = treeMapper.getScaleDevInfo(index, tmp.getDicIndex());
					List<Tree> subvInfo = treeMapper.getScaleSubvInfo(index, tmp.getDicIndex());

					if (proInfo == null || subInfo == null || subvInfo == null) {
						return list;
					}

					Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
					int p0 = pIdNumber+p8;
					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(p8);
						dto.setPpId(y);
						dto.setNodeIndex(proInfo.get(i).getNodeIndex());
						dto.setNodeType(1);

//						int proIndex = proInfo.get(i).getNodeIndex();
//						List<Line> lines = lineMapper.getLinesByPro(proIndex);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value0.put(proInfo.get(i).getNodeIndex(), p0);
					}

					Map<Integer, Integer> value = new HashMap<Integer, Integer>();
					int p = pIdNumber * 2+p8;
					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<Line> lines = lineMapper.select(gd_line);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value.put(gdInfo.get(i).getNodeIndex(), p);
					}

					Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
					int p1 = pIdNumber * 3+p8;
					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<Line> lines = lineMapper.select(sub_line);
//							List<Integer> indexs = new ArrayList<>();
//							for (int n = 0; n < lines.size(); n++) {
//								indexs.add(lines.get(n).getLineIndex().intValue());
//							}
//							Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//							int lvl = getLevel(synDatas);
//							dto.setQualityAss(lvl);
							list.add(dto);
							value1.put(subInfo.get(i).getNodeIndex(), p1);
						}
					}

					Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
					int p3 = pIdNumber * 5+p8;
					for (int i = 0; i < subvInfo.size(); i++) {
						if (value1.get(subvInfo.get(i).getpId()) != null) {
							List<Tree> lines = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
							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());
								dto.setPowerType(linetmp.getPowerType());

//								List<Integer> indexs = new ArrayList<>();
//								for (int n = 0; n < lines.size(); n++) {
//									indexs.add(lines.get(n).getNodeIndex());
//								}
//								Float synDatas = getSynData(indexs, startTime, endTime,
//										linetmp.getNodeIndex(), 6l);
//								int lvl = getLevel(synDatas);
//								dto.setQualityAss(lvl);
								list.add(dto);
								value3.put(subvInfo.get(i).getNodeIndex(), p3);
							}
						}
					}
				}
				return list;
			}
		}
	}

	public List<Tree> getMancTree(String name, Date startTime, Date endTime) {
		String dky = "设备树";

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

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

		List<Integer> index = userUtil.listLine();
		List<Integer> counterpart = new ArrayList<>(index);
		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 {
			List<DicData> devtype=new ArrayList<>();
			List<List<Integer>> lineTmpList=null;
			if(index.size()>1000){
				lineTmpList = Utils.splitList(index,1000);
				for(List<Integer> item:lineTmpList){
					List<DicData> tmp =dicDataMapper.getTreeManc(item);
					if(CollectionUtil.isNotEmpty(tmp)){
						devtype.addAll(tmp);
					}
				}
				if(CollectionUtil.isNotEmpty(devtype)){
					//去重
					devtype = devtype.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<DicData>(Comparator.comparing(DicData::getDicName))), ArrayList::new));
				}
			}else{
				devtype = dicDataMapper.getTreeManc(index);
			}

			if (CollectionUtil.isEmpty(devtype)) {
				return list;
			} else {


				for (int y = 1; y <= devtype.size(); y++) {
					List<Tree> proInfo =new ArrayList<>();
					List<Tree> gdInfo = new ArrayList<>();
					List<Tree> subInfo = new ArrayList<>();
					List<Tree> subvInfo = new ArrayList<>();
					DicData tmp = devtype.get(y - 1);
					Map<Integer, Integer> value8 = new HashMap<Integer, Integer>();
					int p8 = 100 * y;
					Tree dt = new Tree();
					dt.setId(p8);
					dt.setName(devtype.get(y - 1).getDicName());
					dt.setpId(0);
					dt.setPpId(0);
					dt.setNodeIndex(y);
					dt.setNodeType(0);

					list.add(dt);
					value8.put(y, p8);


					//超过1000个监测点处理
					if(counterpart.size()>1000){
						for(List<Integer> item:lineTmpList){
							List<Tree> proInfoTmp = treeMapper.getMancProVInfo(item, tmp.getDicIndex());
							List<Tree> gdInfoTmp = treeMapper.getMancGdInfo(item, tmp.getDicIndex());
							List<Tree> subInfoTmp = treeMapper.getMancSubInfo(item, tmp.getDicIndex());
							List<Tree> subvInfoTmp = treeMapper.getMancSubvInfo(item, tmp.getDicIndex());
							if(CollectionUtil.isNotEmpty(proInfoTmp)){
								proInfo.addAll(proInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(gdInfoTmp)){
								gdInfo.addAll(gdInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(subInfoTmp)){
								subInfo.addAll(subInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(subvInfoTmp)){
								subvInfo.addAll(subvInfoTmp);
							}
						}
						//去重
						proInfo = proInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						gdInfo = gdInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						subInfo = subInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						subvInfo = subvInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
					}else{
						proInfo = treeMapper.getMancProVInfo(counterpart, tmp.getDicIndex());
						gdInfo = treeMapper.getMancGdInfo(counterpart, tmp.getDicIndex());
						subInfo = treeMapper.getMancSubInfo(counterpart, tmp.getDicIndex());
						subvInfo = treeMapper.getMancSubvInfo(counterpart, tmp.getDicIndex());
						//List<Tree> devInfo = treeMapper.getMancDevInfo(index, tmp.getDicIndex());

					}



					if (proInfo == null || subInfo == null || subvInfo == null) {
						return list;
					}

					Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
					int p0 = pIdNumber+p8;
					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(p8);
						dto.setPpId(y);
						dto.setNodeIndex(proInfo.get(i).getNodeIndex());
						dto.setNodeType(1);

//						int proIndex = proInfo.get(i).getNodeIndex();
//						List<Line> lines = lineMapper.getLinesByPro(proIndex);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value0.put(proInfo.get(i).getNodeIndex(), p0);
					}

					Map<Integer, Integer> value = new HashMap<Integer, Integer>();
					int p = pIdNumber * 2+p8;
					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<Line> lines = lineMapper.select(gd_line);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value.put(gdInfo.get(i).getNodeIndex(), p);
					}

					Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
					int p1 = pIdNumber * 3+p8;
					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<Line> lines = lineMapper.select(sub_line);
//							List<Integer> indexs = new ArrayList<>();
//							for (int n = 0; n < lines.size(); n++) {
//								indexs.add(lines.get(n).getLineIndex().intValue());
//							}
//							Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//							int lvl = getLevel(synDatas);
//							dto.setQualityAss(lvl);
							list.add(dto);
							value1.put(subInfo.get(i).getNodeIndex(), p1);
						}
					}

					Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
					int p3 = pIdNumber * 4+p8;
					for (int i = 0; i < subvInfo.size(); i++) {
						if (value1.get(subvInfo.get(i).getpId()) != null) {
							List<Tree> lines = new ArrayList<>();
							if(index.size()>1000){
								for(List<Integer> item:lineTmpList){
									List<Tree> Tmp = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),item);
									if(CollectionUtil.isNotEmpty(Tmp)){
										lines.addAll(Tmp);
									}
								}
							}else{
								lines = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
							}

							if(CollectionUtil.isNotEmpty(lines)){
								lines = lines.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));

							}


							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());
								dto.setPowerType(linetmp.getPowerType());

//								List<Integer> indexs = new ArrayList<>();
//								for (int n = 0; n < lines.size(); n++) {
//									indexs.add(lines.get(n).getNodeIndex());
//								}
//								Float synDatas = getSynData(indexs, startTime, endTime,
//										linetmp.getNodeIndex(), 6l);
//								int lvl = getLevel(synDatas);
//								dto.setQualityAss(lvl);
								list.add(dto);
								value3.put(subvInfo.get(i).getNodeIndex(), p3);
							}
						}
					}
				}
				return list;
			}
		}
	}

	public List<Tree> getMancPlateTree(String name, Date startTime, Date endTime) {
		String dky = "设备树";

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

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

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

		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 {
			List<DicData> devtype = dicDataMapper.getTreeManc(index);
			if (devtype == null) {
				return list;
			} else {
				for (int y = 1; y <= devtype.size(); y++) {
					DicData tmp = devtype.get(y - 1);
					Map<Integer, Integer> value8 = new HashMap<Integer, Integer>();
					int p8 = 100 * y;
					Tree dt = new Tree();
					dt.setId(p8);
					dt.setName(devtype.get(y - 1).getDicName());
					dt.setpId(0);
					dt.setPpId(0);
					dt.setNodeIndex(y);
					dt.setNodeType(0);

					list.add(dt);
					value8.put(y, p8);

					List<Tree> proInfo = treeMapper.getMancProVInfo(index, tmp.getDicIndex());
					List<Tree> gdInfo = treeMapper.getMancGdInfo(index, tmp.getDicIndex());
					List<Tree> subInfo = treeMapper.getMancSubInfo(index, tmp.getDicIndex());
					List<Tree> devInfo = treeMapper.getMancDevInfo(index, tmp.getDicIndex());
					List<Tree> subvInfo = treeMapper.getMancSubvInfo(index, tmp.getDicIndex());

					if (proInfo == null || subInfo == null || subvInfo == null) {
						return list;
					}

					Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
					int p0 = pIdNumber+p8;
					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(p8);
						dto.setPpId(y);
						dto.setNodeIndex(proInfo.get(i).getNodeIndex());
						dto.setNodeType(1);

//						int proIndex = proInfo.get(i).getNodeIndex();
//						List<Line> lines = lineMapper.getLinesByPro(proIndex);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value0.put(proInfo.get(i).getNodeIndex(), p0);
					}

					Map<Integer, Integer> value = new HashMap<Integer, Integer>();
					int p = pIdNumber * 2+p8;
					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<Line> lines = lineMapper.select(gd_line);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value.put(gdInfo.get(i).getNodeIndex(), p);
					}

					Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
					int p1 = pIdNumber * 3+p8;
					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<Line> lines = lineMapper.select(sub_line);
//							List<Integer> indexs = new ArrayList<>();
//							for (int n = 0; n < lines.size(); n++) {
//								indexs.add(lines.get(n).getLineIndex().intValue());
//							}
//							Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//							int lvl = getLevel(synDatas);
//							dto.setQualityAss(lvl);
							list.add(dto);
							value1.put(subInfo.get(i).getNodeIndex(), p1);
						}
					}

					Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
					int p3 = pIdNumber * 4+p8;
					for (int i = 0; i < subvInfo.size(); i++) {
						if (value1.get(subvInfo.get(i).getpId()) != null) {
							List<Tree> lines = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
							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());
								dto.setPowerType(linetmp.getPowerType());

//								List<Integer> indexs = new ArrayList<>();
//								for (int n = 0; n < lines.size(); n++) {
//									indexs.add(lines.get(n).getNodeIndex());
//								}
//								Float synDatas = getSynData(indexs, startTime, endTime,
//										linetmp.getNodeIndex(), 6l);
//								int lvl = getLevel(synDatas);
//								dto.setQualityAss(lvl);
								list.add(dto);
								value3.put(subvInfo.get(i).getNodeIndex(), p3);
							}
						}
					}
				}
				return list;
			}
		}
	}

	public List<Tree> getLoadTypeTree(String name, Date startTime, Date endTime) {
		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 {
			List<DicData> devtype = new ArrayList<>();
			List<List<Integer>> ll=null;
			if(index.size()>1000){
				ll = Utils.splitList(index,1000);
				for(List<Integer> item:ll){
					List<DicData> tmp = dicDataMapper.getTreeLoadType(item);
					if(CollectionUtil.isNotEmpty(tmp)){
						devtype.addAll(tmp);
					}
				}
				if(CollectionUtil.isNotEmpty(devtype)){
					//去重
					devtype = devtype.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<DicData>(Comparator.comparing(DicData::getDicIndex))), ArrayList::new));
				}
			}else{
				devtype = dicDataMapper.getTreeLoadType(index);
			}

			if (devtype == null) {
				return list;
			} else {

				for (int y = 1; y <= devtype.size(); y++) {
					List<Tree> proInfo =new ArrayList<>();
					List<Tree> gdInfo = new ArrayList<>();
					List<Tree> subInfo = new ArrayList<>();
					List<Tree> subvInfo = new ArrayList<>();

					DicData tmp = devtype.get(y - 1);
					Map<Integer, Integer> value8 = new HashMap<Integer, Integer>();
					int p8 = 100 * y;
					Tree dt = new Tree();
					dt.setId(p8);
					dt.setName(devtype.get(y - 1).getDicName());
					dt.setpId(0);
					dt.setPpId(0);
					dt.setNodeIndex(y);
					dt.setNodeType(0);

					list.add(dt);
					value8.put(y, p8);


					//超过1000个监测点处理
					if(index.size()>1000){

						for(List<Integer> item:ll){
							List<Tree> proInfoTmp = treeMapper.getLoadTypeProVInfo(item, tmp.getDicIndex());
							List<Tree> gdInfoTmp = treeMapper.getLoadTypeGdInfo(item, tmp.getDicIndex());
							List<Tree> subInfoTmp = treeMapper.getLoadTypeSubInfo(item, tmp.getDicIndex());
							List<Tree> subvInfoTmp = treeMapper.getLoadTypeSubvInfo(item, tmp.getDicIndex());
							if(CollectionUtil.isNotEmpty(proInfoTmp)){
								proInfo.addAll(proInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(gdInfoTmp)){
								gdInfo.addAll(gdInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(subInfoTmp)){
								subInfo.addAll(subInfoTmp);
							}
							if(CollectionUtil.isNotEmpty(subvInfoTmp)){
								subvInfo.addAll(subvInfoTmp);
							}
						}
						//去重
						proInfo = proInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						gdInfo = gdInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						subInfo = subInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
						subvInfo = subvInfo.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));
					}else{
						proInfo = treeMapper.getLoadTypeProVInfo(index, tmp.getDicIndex());
						gdInfo = treeMapper.getLoadTypeGdInfo(index, tmp.getDicIndex());
						subInfo = treeMapper.getLoadTypeSubInfo(index, tmp.getDicIndex());
						subvInfo = treeMapper.getLoadTypeSubvInfo(index, tmp.getDicIndex());
					}



					if (proInfo == null || subInfo == null || subvInfo == null) {
						return list;
					}

					Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
					int p0 = pIdNumber+p8;
					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(p8);
						dto.setPpId(y);
						dto.setNodeIndex(proInfo.get(i).getNodeIndex());
						dto.setNodeType(1);

//						int proIndex = proInfo.get(i).getNodeIndex();
//						List<Line> lines = lineMapper.getLinesByPro(proIndex);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value0.put(proInfo.get(i).getNodeIndex(), p0);
					}

					Map<Integer, Integer> value = new HashMap<Integer, Integer>();
					int p = pIdNumber * 2+p8;
					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<Line> lines = lineMapper.select(gd_line);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value.put(gdInfo.get(i).getNodeIndex(), p);
					}

					Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
					int p1 = pIdNumber * 3+p8;
					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<Line> lines = lineMapper.select(sub_line);
//							List<Integer> indexs = new ArrayList<>();
//							for (int n = 0; n < lines.size(); n++) {
//								indexs.add(lines.get(n).getLineIndex().intValue());
//							}
//							Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//							int lvl = getLevel(synDatas);
//							dto.setQualityAss(lvl);
							list.add(dto);
							value1.put(subInfo.get(i).getNodeIndex(), p1);
						}
					}

					Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
					int p3 = pIdNumber * 4+p8;
					for (int i = 0; i < subvInfo.size(); i++) {
						if (value1.get(subvInfo.get(i).getpId()) != null) {
							List<Tree> lines = new ArrayList<>();
							if(index.size()>1000){
								for(List<Integer> item:ll){
									List<Tree> Tmp = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),item);
									if(CollectionUtil.isNotEmpty(Tmp)){
										lines.addAll(Tmp);
									}
								}
							}else{
								lines = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
							}

							if(CollectionUtil.isNotEmpty(lines)){
								lines = lines.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()->new TreeSet<Tree>(Comparator.comparing(Tree::getNodeIndex))), ArrayList::new));

							}


							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());
								dto.setPowerType(linetmp.getPowerType());

//								List<Integer> indexs = new ArrayList<>();
//								for (int n = 0; n < lines.size(); n++) {
//									indexs.add(lines.get(n).getNodeIndex());
//								}
//								Float synDatas = getSynData(indexs, startTime, endTime,
//										linetmp.getNodeIndex(), 6l);
//								int lvl = getLevel(synDatas);
//								dto.setQualityAss(lvl);
								list.add(dto);
								value3.put(subvInfo.get(i).getNodeIndex(), p3);
							}
						}
					}
				}
				return list;
			}
		}
	}

	public List<Tree> getLoadTypePlateTree(String name, Date startTime, Date endTime) {
		String dky = "设备树";

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

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

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

		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 {
			List<DicData> devtype = dicDataMapper.getTreeLoadType(index);
			if (devtype == null) {
				return list;
			} else {
				for (int y = 1; y <= devtype.size(); y++) {
					DicData tmp = devtype.get(y - 1);
					Map<Integer, Integer> value8 = new HashMap<Integer, Integer>();
					int p8 = 100 * y;
					Tree dt = new Tree();
					dt.setId(p8);
					dt.setName(devtype.get(y - 1).getDicName());
					dt.setpId(0);
					dt.setPpId(0);
					dt.setNodeIndex(y);
					dt.setNodeType(0);

					list.add(dt);
					value8.put(y, p8);

					List<Tree> proInfo = treeMapper.getLoadTypeProVInfo(index, tmp.getDicIndex());
					List<Tree> gdInfo = treeMapper.getLoadTypeGdInfo(index, tmp.getDicIndex());
					List<Tree> subInfo = treeMapper.getLoadTypeSubInfo(index, tmp.getDicIndex());
					List<Tree> devInfo = treeMapper.getLoadTypeDevInfo(index, tmp.getDicIndex());
					List<Tree> subvInfo = treeMapper.getLoadTypeSubvInfo(index, tmp.getDicIndex());

					if (proInfo == null || subInfo == null || subvInfo == null) {
						return list;
					}

					Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
					int p0 = pIdNumber+p8;
					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(p8);
						dto.setPpId(y);
						dto.setNodeIndex(proInfo.get(i).getNodeIndex());
						dto.setNodeType(1);

//						int proIndex = proInfo.get(i).getNodeIndex();
//						List<Line> lines = lineMapper.getLinesByPro(proIndex);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value0.put(proInfo.get(i).getNodeIndex(), p0);
					}

					Map<Integer, Integer> value = new HashMap<Integer, Integer>();
					int p = pIdNumber * 2+p8;
					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<Line> lines = lineMapper.select(gd_line);
//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getLineIndex().intValue());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value.put(gdInfo.get(i).getNodeIndex(), p);
					}

					Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
					int p1 = pIdNumber * 3+p8;
					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<Line> lines = lineMapper.select(sub_line);
//							List<Integer> indexs = new ArrayList<>();
//							for (int n = 0; n < lines.size(); n++) {
//								indexs.add(lines.get(n).getLineIndex().intValue());
//							}
//							Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//							int lvl = getLevel(synDatas);
//							dto.setQualityAss(lvl);
							list.add(dto);
							value1.put(subInfo.get(i).getNodeIndex(), p1);
						}
					}

					Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();
					int p3 = pIdNumber * 4+p8;
					for (int i = 0; i < subvInfo.size(); i++) {
						if (value1.get(subvInfo.get(i).getpId()) != null) {
							List<Tree> lines = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
							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());
								dto.setPowerType(linetmp.getPowerType());

//								List<Integer> indexs = new ArrayList<>();
//								for (int n = 0; n < lines.size(); n++) {
//									indexs.add(lines.get(n).getNodeIndex());
//								}
//								Float synDatas = getSynData(indexs, startTime, endTime,
//										linetmp.getNodeIndex(), 6l);
//								int lvl = getLevel(synDatas);
//								dto.setQualityAss(lvl);
								list.add(dto);
								value3.put(subvInfo.get(i).getNodeIndex(), p3);
							}
						}
					}
				}
				return list;
			}
		}
	}

	public List<Tree> getMonitorTree(String name, Date startTime, Date endTime) {
		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.getTreeGdInfo(index);
			List<Tree> subInfo = treeMapper.getTreeSubInfo(index);
			List<Tree> devInfo = new ArrayList<>();
			if (appConfig.getSysType().equalsIgnoreCase(appConfig.getSysTypeWt())) {
				devInfo = treeMapper.getWTTreeDevInfo(index);
			} else {
				devInfo = treeMapper.getZTTreeDevInfo(index);
			}
			List<Tree> subvInfo = treeMapper.getNodeTreeSubvInfo(index);
			List<Tree> lineInfo = treeMapper.getLineInfo(index);
			if (proInfo == null || gdInfo == null || subInfo == null || devInfo == 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<Line> lines = lineMapper.getLinesByPro(proIndex);
//				List<Integer> indexs = new ArrayList<>();
//				for (int n = 0; n < lines.size(); n++) {
//					indexs.add(lines.get(n).getLineIndex().intValue());
//				}
//				Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//				int lvl = getLevel(synDatas);
//				dto.setQualityAss(lvl);
				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<Line> lines = lineMapper.select(gd_line);
//				List<Integer> indexs = new ArrayList<>();
//				for (int n = 0; n < lines.size(); n++) {
//					indexs.add(lines.get(n).getLineIndex().intValue());
//				}
//				Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//				int lvl = getLevel(synDatas);
//				dto.setQualityAss(lvl);
				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<Line> lines = lineMapper.select(sub_line);
//					List<Integer> indexs = new ArrayList<>();
//					for (int n = 0; n < lines.size(); n++) {
//						indexs.add(lines.get(n).getLineIndex().intValue());
//					}
//					Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//					int lvl = getLevel(synDatas);
//					dto.setQualityAss(lvl);
					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 = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
					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());
						dto.setPowerType(linetmp.getPowerType());

//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getNodeIndex());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime,
//								linetmp.getNodeIndex(), 6l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value3.put(subvInfo.get(i).getNodeIndex(), p3);
					}
				}
			}

			return list;
		}
	}

	public List<Tree> getMonitorPlateTree(String name, Date startTime, Date endTime) {
		String dky = "国网上报";

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

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

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

		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> devInfo = new ArrayList<>();
			if (appConfig.getSysType().equalsIgnoreCase(appConfig.getSysTypeWt())) {
				devInfo = treeMapper.getWTTreeDevInfo(index);
			} else {
				devInfo = treeMapper.getZTTreeDevInfo(index);
			}
			List<Tree> subvInfo = treeMapper.getNodeTreeSubvInfo(index);
			List<Tree> lineInfo = treeMapper.getLineInfo(index);
			if (proInfo == null || gdInfo == null || subInfo == null || devInfo == 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<Line> lines = lineMapper.getLinesByPro(proIndex);
//				List<Integer> indexs = new ArrayList<>();
//				for (int n = 0; n < lines.size(); n++) {
//					indexs.add(lines.get(n).getLineIndex().intValue());
//				}
//				Float synDatas = getSynData(indexs, startTime, endTime, proIndex, 1l);
//				int lvl = getLevel(synDatas);
//				dto.setQualityAss(lvl);
				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<Line> lines = lineMapper.select(gd_line);
//				List<Integer> indexs = new ArrayList<>();
//				for (int n = 0; n < lines.size(); n++) {
//					indexs.add(lines.get(n).getLineIndex().intValue());
//				}
//				Float synDatas = getSynData(indexs, startTime, endTime, gdInfo.get(i).getNodeIndex(), 2l);
//				int lvl = getLevel(synDatas);
//				dto.setQualityAss(lvl);
				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<Line> lines = lineMapper.select(sub_line);
//					List<Integer> indexs = new ArrayList<>();
//					for (int n = 0; n < lines.size(); n++) {
//						indexs.add(lines.get(n).getLineIndex().intValue());
//					}
//					Float synDatas = getSynData(indexs, startTime, endTime, subInfo.get(i).getNodeIndex(), 3l);
//					int lvl = getLevel(synDatas);
//					dto.setQualityAss(lvl);
					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 = lineMapper.getTreeBySubv((long)subvInfo.get(i).getNodeIndex(),index);
					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());
						dto.setPowerType(linetmp.getPowerType());

//						List<Integer> indexs = new ArrayList<>();
//						for (int n = 0; n < lines.size(); n++) {
//							indexs.add(lines.get(n).getNodeIndex());
//						}
//						Float synDatas = getSynData(indexs, startTime, endTime,
//								linetmp.getNodeIndex(), 6l);
//						int lvl = getLevel(synDatas);
//						dto.setQualityAss(lvl);
						list.add(dto);
						value3.put(subvInfo.get(i).getNodeIndex(), p3);
					}
				}
			}

			return list;
		}
	}

	public List<Tree> getRunTimeTreedata(String name) {
		String dky = "设备树";

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

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

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

		List<Tree> gdInfo = treeMapper.getGdInfo(index);

		if (gdInfo == null) {
			Tree dto = new Tree();
			dto.setId(100);
			dto.setNodeType(0);
			dto.setpId(0);
			dto.setPpId(0);
			dto.setName(dky);
			list.add(dto);
			return list;
		}

		List<Tree> subInfo = treeMapper.getSubInfo(index);// 变电站
		if (subInfo == null) {
			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> value = new HashMap<Integer, Integer>();
			int p = pIdNumber;
			for (int i = 0; i < gdInfo.size(); i++) {
				Tree dto = new Tree();
				dto.setId(++p);
				dto.setName(gdInfo.get(i).getName());
				dto.setpId(100);
				dto.setPpId(100);
				dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
				dto.setNodeType(1);
				list.add(dto);
				value.put(gdInfo.get(i).getNodeIndex(), p);
			}

			return list;
		}

		List<Tree> devInfo = treeMapper.getDevInfo(index); // 终端
		if (devInfo == null) {
			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> value = new HashMap<Integer, Integer>();
			int p = pIdNumber;
			for (int i = 0; i < gdInfo.size(); i++) {
				Tree dto = new Tree();
				dto.setId(++p);
				dto.setName(gdInfo.get(i).getName());
				dto.setpId(100);
				dto.setPpId(100);
				dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
				dto.setNodeType(1);
				list.add(dto);
				value.put(gdInfo.get(i).getNodeIndex(), p);
			}

			Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
			int p1 = pIdNumber * 2;
			for (int i = 0; i < subInfo.size(); i++) {
				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(2);
				list.add(dto);
				value1.put(subInfo.get(i).getNodeIndex(), p1);
			}

			return list;
		}

		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> value = new HashMap<Integer, Integer>();
		int p = pIdNumber;
		for (int i = 0; i < gdInfo.size(); i++) {
			Tree dto = new Tree();
			dto.setId(++p);
			dto.setName(gdInfo.get(i).getName());
			dto.setpId(100);
			dto.setPpId(100);
			dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
			dto.setNodeType(1);
			list.add(dto);
			value.put(gdInfo.get(i).getNodeIndex(), p);
		}

		Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
		int p1 = pIdNumber * 2;
		for (int i = 0; i < subInfo.size(); i++) {
			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(2);
			list.add(dto);
			value1.put(subInfo.get(i).getNodeIndex(), p1);
		}

		Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();
		int p2 = pIdNumber * 3;
		for (int i = 0; i < devInfo.size(); i++) {
			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(3);
			list.add(dto);
			value2.put(devInfo.get(i).getNodeIndex(), p2);
		}
		return list;
	}

	// 获取变电站与变压器的节点树
	public List<Tree> getTransTreedata() {

		int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
		String dky = "变压器台账";

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

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

		List<Integer> suIndex = userUtil.listSu();// 获取变电站Id

		List<Tree> gdInfo = treeMapper.getGdInfo(index);

		if (gdInfo == null) {
			Tree dto = new Tree();
			dto.setId(100);
			dto.setNodeType(0);
			dto.setpId(0);
			dto.setPpId(0);
			dto.setName(dky);
			list.add(dto);
			return list;
		}

		List<Tree> subInfo = treeMapper.getSubInfo(index);// 获取变电站
		if (subInfo == null) {
			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> value = new HashMap<Integer, Integer>();
			int p = pIdNumber;
			for (int i = 0; i < gdInfo.size(); i++) {
				Tree dto = new Tree();
				dto.setId(++p);
				dto.setName(gdInfo.get(i).getName());
				dto.setpId(100);
				dto.setPpId(100);
				dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
				dto.setNodeType(1);
				list.add(dto);
				value.put(gdInfo.get(i).getNodeIndex(), p);
			}

			return list;
		}

		List<Tree> transInfo = treeMapper.getTransInfo(suIndex);// 获取变压器
		if (transInfo == null) {
			Tree dt = new Tree();
			dt.setId(100);
			dt.setNodeType(3);
			dt.setpId(0);
			dt.setPpId(0);
			dt.setName(dky);
			list.add(dt);

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

			return list;
		}

		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> value = new HashMap<Integer, Integer>();
		int p = pIdNumber;
		for (int i = 0; i < gdInfo.size(); i++) {
			Tree dto = new Tree();
			dto.setId(++p);
			dto.setName(gdInfo.get(i).getName());
			dto.setpId(100);
			dto.setPpId(100);
			dto.setNodeIndex(gdInfo.get(i).getNodeIndex());
			dto.setNodeType(1);
			list.add(dto);
			value.put(gdInfo.get(i).getNodeIndex(), p);
		}

		// 变电站
		Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();
		int p1 = pIdNumber * 2;
		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(2);
				list.add(dto);
				value1.put(subInfo.get(i).getNodeIndex(), p1);
			}
		}

		// 变压器
		Map<String, Integer> value2 = new HashMap<String, Integer>();
		int p2 = pIdNumber * 3;
		for (int i = 0; i < transInfo.size(); i++) {
			if (value1.get(transInfo.get(i).getpId()) != null) {
				Tree dto = new Tree();
				dto.setId(++p2);
				dto.setName(transInfo.get(i).getName());
				dto.setpId(value1.get(transInfo.get(i).getpId()));
				dto.setPpId(transInfo.get(i).getpId());
				dto.setNodeTf(transInfo.get(i).getNodeTf());
				dto.setNodeType(3);
				list.add(dto);
				value2.put(transInfo.get(i).getNodeTf(), p2);
			}
		}
		return list;
	}

	/**
	 * 根据监测点集合，返回对应的综合电能质量评估
	 *
	 * @param lineIndexs
	 *            监测点集合
	 * @param startTime
	 *            起始时间
	 * @param endTime
	 *            截止时间
	 */
	private Float getSynData(List<Integer> lineIndexs, Date startTime, Date endTime, int myIndex, Long node) {
		Float synData = 0f;
		if (appConfig.getSysType() == appConfig.getSysTypeWt()) {
			List<PqsComasses> pqsComasses = new ArrayList<>();
			List<Integer> lineTemps = new ArrayList<>(lineIndexs);
			if (CollectionUtils.isNotEmpty(lineTemps)) {
				if (lineTemps.size() > 1000) {
					int size = lineTemps.size();
					for (int i = 1; i <= size; i++) {
						if (lineTemps.size() > 1000) {
							List<Integer> temp = lineTemps.subList(0, 1000);
							List<PqsComasses> tempComass = assesMapper.getSynData(temp, startTime, endTime);
							pqsComasses.addAll(tempComass);
							temp.clear();
						} else {
							List<PqsComasses> tempComass = assesMapper.getSynData(lineTemps, startTime, endTime);
							pqsComasses.addAll(tempComass);
						}
					}
				} else {
					List<PqsComasses> tempComass = assesMapper.getSynData(lineTemps, startTime, endTime);
					pqsComasses.addAll(tempComass);
				}

			} else {
				return 3.1415f;// 无监测点前台统一替换为“/”
			}
			if (CollectionUtils.isEmpty(pqsComasses)) {
				return 3.14159f;// 有监测点，但是无数据的处理
			}
			synData = comAssesUtil.getAllComAss(pqsComasses);
		} else {
			synData = synDataMapper.getSynData(myIndex, node);
		}
		return synData;
	}

	// 获取综合得分等级
	private int getLevel(Float synDatas) {
		if (appConfig.getSysType() == appConfig.getSysTypeWt()) {
			if (synDatas == 3.14159f) {
				return 0;
			}
			if (0 <= synDatas && synDatas < 3) {
				return 1;
			} else if (3 <= synDatas && synDatas < 4) {
				return 2;
			} else if (4 <= synDatas && synDatas < 4.5) {
				return 3;
			} else {
				return 4;
			}
		} else {
			if (synDatas == null || synDatas == 3.14159f) {
				return 0;
			}
			if (0 <= synDatas && synDatas < 0.4) {
				return 1;
			} else if (0.4 <= synDatas && synDatas < 0.8) {
				return 2;
			} else if (0.8 <= synDatas && synDatas < 1.2) {
				return 3;
			} else {
				return 4;
			}
		}
	}

	public List<Tree> getOffLineTree(String name, int type) {
		String dky = "离线设备树";

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

		List<Tree> list = new ArrayList<>();
		List<Integer> index = new ArrayList<>();
		if (type == 0) {
			String systype = TokenManager.getSysType();
			index = lineMapper.getOffLineIndexWT(systype);
		} else {
			index = userUtil.listOffLine();
		}
		//
		// logger.error("供电公司索引：" + index.toString());

		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 {
			List<Tree> project = treeMapper.getOffTreeProJInfo(index);
			List<Tree> province = treeMapper.getOffTreeProVInfo(index);
			List<Tree> subInfo = treeMapper.getOffTreeSubInfo(index);
			List<Tree> lineInfo = treeMapper.getOffTreeLineInfo(index);
			Tree dt = new Tree();
			dt.setId(100);
			dt.setNodeType(0);
			dt.setpId(0);
			dt.setPpId(0);
			dt.setName(dky);
			list.add(dt);

			if (project == null || province == null || subInfo == null || lineInfo == null) {
				return list;
			} else {
				Map<Integer, Integer> value = new HashMap<Integer, Integer>();
				int p = pIdNumber;
				for (int i = 0; i < project.size(); i++) {
					Tree dto = new Tree();
					dto.setId(++p);
					dto.setName(project.get(i).getName());
					dto.setpId(100);
					dto.setPpId(100);
					dto.setNodeIndex(project.get(i).getNodeIndex());
					dto.setNodeType(1);

					list.add(dto);
					value.put(project.get(i).getNodeIndex(), p);
				}

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

						list.add(dto);
						value1.put(province.get(i).getNodeIndex(), p1);
					}
				}

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

						list.add(dto);
						value2.put(subInfo.get(i).getNodeIndex(), p2);
					}
				}

				int p3 = pIdNumber * 4;
				for (int i = 0; i < lineInfo.size(); i++) {
					if (value2.get(lineInfo.get(i).getpId()) != null) {
						Tree dto = new Tree();
						dto.setId(++p3);
						dto.setName(lineInfo.get(i).getName());
						dto.setpId(value2.get(lineInfo.get(i).getpId()));
						dto.setPpId(lineInfo.get(i).getpId());
						dto.setNodeIndex(lineInfo.get(i).getNodeIndex());
						dto.setNodeType(4);
						dto.setPttype(lineInfo.get(i).getPttype());

						list.add(dto);
					}
				}

				return list;
			}
		}
	}

	public List<Tree> getOffYearTree(String name) {
		String dky = "离线设备树";

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

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

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

		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 {
			List<String> year = offlLogMapper.getYearByGd(index);
			Tree dt = new Tree();
			dt.setId(100);
			dt.setNodeType(0);
			dt.setpId(0);
			dt.setPpId(0);
			dt.setName(dky);
			list.add(dt);

			if (year == null) {
				return list;
			} else {
				List<Tree> project = treeMapper.getOffYearProJInfo(index, year);
				Map<Integer, Integer> value = new HashMap<Integer, Integer>();
				int p = pIdNumber;
				for (int i = 0; i < project.size(); i++) {
					Tree dto = new Tree();
					dto.setId(++p);
					dto.setName(project.get(i).getName());
					dto.setpId(100);
					dto.setPpId(100);
					dto.setNodeIndex(project.get(i).getNodeIndex());
					dto.setNodeType(1);

					list.add(dto);
					value.put(project.get(i).getNodeIndex(), p);
				}

				for (int y = 0; y < year.size(); y++) {
					List<Tree> province = treeMapper.getOffYearProVInfo(index, year.get(y));
					List<Tree> subInfo = treeMapper.getOffYearSubInfo(index, year.get(y));
					List<Tree> lineInfo = treeMapper.getOffYearLineInfo(index, year.get(y));

					if (project == null || province == null || subInfo == null || lineInfo == null) {
						return list;
					}

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

							list.add(dto);
							value1.put(province.get(i).getNodeIndex(), p1);
						}
					}

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

							list.add(dto);
							value2.put(subInfo.get(i).getNodeIndex(), p2);
						}
					}

					int p3 = pIdNumber * 4 + y;
					for (int i = 0; i < lineInfo.size(); i++) {
						if (value2.get(lineInfo.get(i).getpId()) != null) {
							Tree dto = new Tree();
							dto.setId(++p3);
							dto.setName(lineInfo.get(i).getName());
							dto.setpId(value2.get(lineInfo.get(i).getpId()));
							dto.setPpId(lineInfo.get(i).getpId());
							dto.setNodeIndex(lineInfo.get(i).getNodeIndex());
							dto.setNodeType(4);
							dto.setPttype(lineInfo.get(i).getPttype());

							list.add(dto);
						}
					}
				}

				return list;
			}
		}
	}

	public List<Tree> getOffTypeTree(String name) {
		String dky = "离线设备树";

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

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

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

		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 {
			List<DicData> loadtype = dicDataMapper.getOffTreeType(index);
			if (loadtype == null) {
				return list;
			} else {
				for (int y = 1; y <= loadtype.size(); y++) {
					DicData tmp = loadtype.get(y - 1);
					Map<Integer, Integer> value0 = new HashMap<Integer, Integer>();
					int p0 = 100 * y;
					Tree dt = new Tree();
					dt.setId(p0);
					dt.setName(loadtype.get(y - 1).getDicName());
					dt.setpId(0);
					dt.setPpId(0);
					dt.setNodeIndex(y);
					dt.setNodeType(0);

					list.add(dt);
					value0.put(y, p0);

					List<Tree> project = treeMapper.getOffTypeProJInfo(index, tmp.getDicIndex());
					List<Tree> province = treeMapper.getOffTypeProVInfo(index, tmp.getDicIndex());
					List<Tree> subInfo = treeMapper.getOffTypeSubInfo(index, tmp.getDicIndex());
					List<Tree> lineInfo = treeMapper.getOffTypeLineInfo(index, tmp.getDicIndex());

					if (project == null || province == null || subInfo == null || lineInfo == null) {
						return list;
					}

					Map<Integer, Integer> value = new HashMap<Integer, Integer>();
					int p = pIdNumber + p0;
					for (int i = 0; i < project.size(); i++) {
						Tree dto = new Tree();
						dto.setId(++p);
						dto.setName(project.get(i).getName());
						dto.setpId(p0);
						dto.setPpId(y);
						dto.setNodeIndex(project.get(i).getNodeIndex());
						dto.setNodeType(1);

						list.add(dto);
						value.put(project.get(i).getNodeIndex(), p);
					}

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

							list.add(dto);
							value1.put(province.get(i).getNodeIndex(), p1);
						}
					}

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

							list.add(dto);
							value2.put(subInfo.get(i).getNodeIndex(), p2);
						}
					}

					int p3 = pIdNumber * 4 + p0;
					for (int i = 0; i < lineInfo.size(); i++) {
						if (value2.get(lineInfo.get(i).getpId()) != null) {
							Tree dto = new Tree();
							dto.setId(++p3);
							dto.setName(lineInfo.get(i).getName());
							dto.setpId(value2.get(lineInfo.get(i).getpId()));
							dto.setPpId(lineInfo.get(i).getpId());
							dto.setNodeIndex(lineInfo.get(i).getNodeIndex());
							dto.setNodeType(4);
							dto.setPttype(lineInfo.get(i).getPttype());

							list.add(dto);
						}
					}
				}

				return list;
			}
		}
	}




}
