package com.njcn.serviceimpl.user;

import com.njcn.enums.ProjectEnum;
import com.njcn.mapper.configuration.DeviceMapper;
import com.njcn.mapper.configuration.GDInforMapper;
import com.njcn.mapper.configuration.ProvinceMapper;
import com.njcn.mapper.user.DeptsLineTreeMapper;
import com.njcn.mapper.user.DeptsMapper;
import com.njcn.pojo.configuration.Province;
import com.njcn.pojo.user.Depts;
import com.njcn.pojo.user.DeptslineTree;
import com.njcn.service.user.DeptsLineTreeService;
import com.njcn.utils.AppConfig;
import com.njcn.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DeptsLineTreeServiceImpl implements DeptsLineTreeService {

    @Autowired
    private AppConfig appConfig;

    @Autowired
    private UserUtil userUtil;

    @Resource
    private DeptsLineTreeMapper deptsLineTreeMapper;

    @Resource
    private GDInforMapper gdInforMapper;

    @Autowired
    private DeviceMapper deviceMapper;

    @Autowired
    private ProvinceMapper provinceMapper;

    @Autowired
    private DeptsMapper deptsMapper;


    //非自定义查询所属省级下的监测点
    @Override
    public List<DeptslineTree> getDeptsLineTree(String area) {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "监测点详情";

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

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

        if (index.size() == 0) {
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            return list;
        } else {
            if (userUtil.getSysType().equals(ProjectEnum.PQS9000.getKey())) {
                dataType.add(1);
                dataType.add(2);
            } else {
                dataType.add(0);
                dataType.add(2);
            }
            Map<String, Object> optionMap = new HashMap<>();
            optionMap.put("gdindex", index);
            optionMap.put("dataType", dataType);
            optionMap.put("area", area);
            //虚拟
            List<DeptslineTree> provinceX = deptsLineTreeMapper.getOffTreeProVInfosX(optionMap);
            List<DeptslineTree> gdInfoX = deptsLineTreeMapper.getTreeGdInfoX(optionMap);
            List<DeptslineTree> subInfoX = deptsLineTreeMapper.getOffTreeSubInfoX(optionMap);
            List<DeptslineTree> lineInfoX = deptsLineTreeMapper.getOffTreeLineInfoX(optionMap);
            //在线
            List<DeptslineTree> provinceZ = deptsLineTreeMapper.getOffTreeProVInfosZ(optionMap);
            List<DeptslineTree> gdInfoZ = deptsLineTreeMapper.getTreeGdInfoZ(optionMap);
            List<DeptslineTree> subInfoZ = deptsLineTreeMapper.getOffTreeSubInfoZ(optionMap);
            List<DeptslineTree> lineInfoZ = deptsLineTreeMapper.getOffTreeLineInfoZ(optionMap);
            //离线
            List<DeptslineTree> provinceL = deptsLineTreeMapper.getOffTreeProVInfosL(optionMap);
            List<DeptslineTree> gdInfoL = deptsLineTreeMapper.getTreeGdInfoL(optionMap);
            List<DeptslineTree> subInfoL = deptsLineTreeMapper.getOffTreeSubInfoL(optionMap);
            List<DeptslineTree> lineInfoL = deptsLineTreeMapper.getOffTreeLineInfoL(optionMap);
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);

            if (provinceX == null || gdInfoX == null || subInfoX == null || lineInfoX == null || provinceZ == null
                    || gdInfoZ == null || subInfoZ == null || lineInfoZ == null || provinceL == null || gdInfoL == null || subInfoL == null || lineInfoL == null) {
                return list;
            } else {
                Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value11 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value111 = new HashMap<Integer, Integer>();//离线
                int p1 = pIdNumber;
                for (int i = 0; i < provinceX.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceX.get(i).getName());
                    dto.setpId(101);
                    dto.setPpId(101);
                    dto.setNodeIndex(provinceX.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value1.put(provinceX.get(i).getNodeIndex(), p1);
                }
                for (int i = 0; i < provinceZ.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceZ.get(i).getName());
                    dto.setpId(102);
                    dto.setPpId(102);
                    dto.setNodeIndex(provinceZ.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value11.put(provinceZ.get(i).getNodeIndex(), p1);
                }

                for (int i = 0; i < provinceL.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceL.get(i).getName());
                    dto.setpId(103);
                    dto.setPpId(103);
                    dto.setNodeIndex(provinceL.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value111.put(provinceL.get(i).getNodeIndex(), p1);
                }
                Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value22 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value222 = new HashMap<Integer, Integer>();//离线
                int p2 = pIdNumber * 2;
                for (int i = 0; i < gdInfoX.size(); i++) {
                    if (value1.get(gdInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoX.get(i).getName());
                        dto.setpId(value1.get(gdInfoX.get(i).getpId()));
                        dto.setPpId(gdInfoX.get(i).getpId());
                        dto.setNodeIndex(gdInfoX.get(i).getNodeIndex());
                        dto.setNodeType(2);

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

                for (int i = 0; i < gdInfoZ.size(); i++) {
                    if (value11.get(gdInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoZ.get(i).getName());
                        dto.setpId(value11.get(gdInfoZ.get(i).getpId()));
                        dto.setPpId(gdInfoZ.get(i).getpId());
                        dto.setNodeIndex(gdInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value22.put(gdInfoZ.get(i).getNodeIndex(), p2);
                    }
                }

                for (int i = 0; i < gdInfoL.size(); i++) {
                    if (value111.get(gdInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoL.get(i).getName());
                        dto.setpId(value111.get(gdInfoL.get(i).getpId()));
                        dto.setPpId(gdInfoL.get(i).getpId());
                        dto.setNodeIndex(gdInfoL.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value222.put(gdInfoL.get(i).getNodeIndex(), p2);
                    }
                }
                Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value33 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value333 = new HashMap<Integer, Integer>();//离线
                int p3 = pIdNumber * 3;
                for (int i = 0; i < subInfoX.size(); i++) {
                    if (value2.get(subInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoX.get(i).getName());
                        dto.setpId(value2.get(subInfoX.get(i).getpId()));
                        dto.setPpId(subInfoX.get(i).getpId());
                        dto.setNodeIndex(subInfoX.get(i).getNodeIndex());
                        dto.setNodeType(3);

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

                for (int i = 0; i < subInfoZ.size(); i++) {
                    if (value22.get(subInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoZ.get(i).getName());
                        dto.setpId(value22.get(subInfoZ.get(i).getpId()));
                        dto.setPpId(subInfoZ.get(i).getpId());
                        dto.setNodeIndex(subInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value33.put(subInfoZ.get(i).getNodeIndex(), p3);
                    }
                }

                for (int i = 0; i < subInfoL.size(); i++) {
                    if (value222.get(subInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoL.get(i).getName());
                        dto.setpId(value222.get(subInfoL.get(i).getpId()));
                        dto.setPpId(subInfoL.get(i).getpId());
                        dto.setNodeIndex(subInfoL.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value333.put(subInfoL.get(i).getNodeIndex(), p3);
                    }
                }

                int p4 = pIdNumber * 4;
                for (int i = 0; i < lineInfoX.size(); i++) {
                    if (value3.get(lineInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoX.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoX.get(i).getNodeIndex()) + ")");
                        dto.setpId(value3.get(lineInfoX.get(i).getpId()));
                        dto.setPpId(lineInfoX.get(i).getpId());
                        dto.setNodeIndex(lineInfoX.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoZ.size(); i++) {
                    if (value33.get(lineInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoZ.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoZ.get(i).getNodeIndex()) + ")");
                        dto.setpId(value33.get(lineInfoZ.get(i).getpId()));
                        dto.setPpId(lineInfoZ.get(i).getpId());
                        dto.setNodeIndex(lineInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoL.size(); i++) {
                    if (value333.get(lineInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoL.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoL.get(i).getNodeIndex()) + ")");
                        dto.setpId(value333.get(lineInfoL.get(i).getpId()));
                        dto.setPpId(lineInfoL.get(i).getpId());
                        dto.setNodeIndex(lineInfoL.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                return list;
            }
        }
    }

    //自定义未绑定的
    @Override
    public List<DeptslineTree> getDeptsLineTreeNo(String deptsIndex, String area) {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "监测点详情";

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

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

        if (index.size() == 0) {
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            return list;
        } else {
            if (userUtil.getSysType().equals(ProjectEnum.PQS9000.getKey())) {
                dataType.add(1);
                dataType.add(2);
            } else {
                dataType.add(0);
                dataType.add(2);
            }
            Map<String, Object> optionMap = new HashMap<>();
            optionMap.put("gdindex", index);
            optionMap.put("dataType", dataType);
            optionMap.put("sysType", userUtil.getSysType());
            optionMap.put("deptsIndex", deptsIndex);
            List<DeptslineTree> provinceX = new ArrayList<>();//虚拟
            List<DeptslineTree> provinceZ = new ArrayList<>();//在线
            List<DeptslineTree> provinceL = new ArrayList<>();//离线
            if (area.equals("0")) {
                provinceX = deptsLineTreeMapper.getOffTreeProVInfoX(optionMap);
                provinceZ = deptsLineTreeMapper.getOffTreeProVInfoZ(optionMap);
                provinceL = deptsLineTreeMapper.getOffTreeProVInfoL(optionMap);
            } else {
                List<Province> provinces = provinceMapper.getArea(area);//虚拟
                if (!provinces.isEmpty()) {
                    optionMap.put("area", area);
                    provinceX = deptsLineTreeMapper.getOffTreeProVInfosX(optionMap);
                    provinceZ = deptsLineTreeMapper.getOffTreeProVInfosZ(optionMap);
                    provinceL = deptsLineTreeMapper.getOffTreeProVInfosL(optionMap);
                } else {
                    String area1 = deptsMapper.getParentArea(area);
                    if (area1 != null) {
                        optionMap.put("area", area1);
                        provinceX = deptsLineTreeMapper.getOffTreeProVInfosX(optionMap);
                        provinceZ = deptsLineTreeMapper.getOffTreeProVInfosZ(optionMap);
                        provinceL = deptsLineTreeMapper.getOffTreeProVInfosL(optionMap);
                    }
                }
            }
            List<DeptslineTree> gdInfoX = deptsLineTreeMapper.getTreeGdInfoX(optionMap);
            List<DeptslineTree> subInfoX = deptsLineTreeMapper.getOffTreeSubInfoX(optionMap);
            List<DeptslineTree> lineInfoX = deptsLineTreeMapper.getOffTreeLineInfoX(optionMap);
            List<DeptslineTree> gdInfoZ = deptsLineTreeMapper.getTreeGdInfoZ(optionMap);
            List<DeptslineTree> subInfoZ = deptsLineTreeMapper.getOffTreeSubInfoZ(optionMap);
            List<DeptslineTree> lineInfoZ = deptsLineTreeMapper.getOffTreeLineInfoZ(optionMap);
            List<DeptslineTree> gdInfoL = deptsLineTreeMapper.getTreeGdInfoL(optionMap);
            List<DeptslineTree> subInfoL = deptsLineTreeMapper.getOffTreeSubInfoL(optionMap);
            List<DeptslineTree> lineInfoL = deptsLineTreeMapper.getOffTreeLineInfoL(optionMap);
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            if (provinceX == null || gdInfoX == null || subInfoX == null || lineInfoX == null || provinceZ == null
                    || gdInfoZ == null || subInfoZ == null || lineInfoZ == null || provinceL == null || gdInfoL == null || subInfoL == null || lineInfoL == null) {
                return list;
            } else {
                Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value11 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value111 = new HashMap<Integer, Integer>();//离线
                int p1 = pIdNumber;
                for (int i = 0; i < provinceX.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceX.get(i).getName());
                    dto.setpId(101);
                    dto.setPpId(101);
                    dto.setNodeIndex(provinceX.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value1.put(provinceX.get(i).getNodeIndex(), p1);
                }
                for (int i = 0; i < provinceZ.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceZ.get(i).getName());
                    dto.setpId(102);
                    dto.setPpId(102);
                    dto.setNodeIndex(provinceZ.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value11.put(provinceZ.get(i).getNodeIndex(), p1);
                }

                for (int i = 0; i < provinceL.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceL.get(i).getName());
                    dto.setpId(103);
                    dto.setPpId(103);
                    dto.setNodeIndex(provinceL.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value111.put(provinceL.get(i).getNodeIndex(), p1);
                }
                Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value22 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value222 = new HashMap<Integer, Integer>();//离线
                int p2 = pIdNumber * 2;
                for (int i = 0; i < gdInfoX.size(); i++) {
                    if (value1.get(gdInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoX.get(i).getName());
                        dto.setpId(value1.get(gdInfoX.get(i).getpId()));
                        dto.setPpId(gdInfoX.get(i).getpId());
                        dto.setNodeIndex(gdInfoX.get(i).getNodeIndex());
                        dto.setNodeType(2);

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

                for (int i = 0; i < gdInfoZ.size(); i++) {
                    if (value11.get(gdInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoZ.get(i).getName());
                        dto.setpId(value11.get(gdInfoZ.get(i).getpId()));
                        dto.setPpId(gdInfoZ.get(i).getpId());
                        dto.setNodeIndex(gdInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value22.put(gdInfoZ.get(i).getNodeIndex(), p2);
                    }
                }

                for (int i = 0; i < gdInfoL.size(); i++) {
                    if (value111.get(gdInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoL.get(i).getName());
                        dto.setpId(value111.get(gdInfoL.get(i).getpId()));
                        dto.setPpId(gdInfoL.get(i).getpId());
                        dto.setNodeIndex(gdInfoL.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value222.put(gdInfoL.get(i).getNodeIndex(), p2);
                    }
                }
                Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value33 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value333 = new HashMap<Integer, Integer>();//离线
                int p3 = pIdNumber * 3;
                for (int i = 0; i < subInfoX.size(); i++) {
                    if (value2.get(subInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoX.get(i).getName());
                        dto.setpId(value2.get(subInfoX.get(i).getpId()));
                        dto.setPpId(subInfoX.get(i).getpId());
                        dto.setNodeIndex(subInfoX.get(i).getNodeIndex());
                        dto.setNodeType(3);

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

                for (int i = 0; i < subInfoZ.size(); i++) {
                    if (value22.get(subInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoZ.get(i).getName());
                        dto.setpId(value22.get(subInfoZ.get(i).getpId()));
                        dto.setPpId(subInfoZ.get(i).getpId());
                        dto.setNodeIndex(subInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value33.put(subInfoZ.get(i).getNodeIndex(), p3);
                    }
                }

                for (int i = 0; i < subInfoL.size(); i++) {
                    if (value222.get(subInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoL.get(i).getName());
                        dto.setpId(value222.get(subInfoL.get(i).getpId()));
                        dto.setPpId(subInfoL.get(i).getpId());
                        dto.setNodeIndex(subInfoL.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value333.put(subInfoL.get(i).getNodeIndex(), p3);
                    }
                }

                int p4 = pIdNumber * 4;
                for (int i = 0; i < lineInfoX.size(); i++) {
                    if (value3.get(lineInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoX.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoX.get(i).getNodeIndex()) + ")");
                        dto.setpId(value3.get(lineInfoX.get(i).getpId()));
                        dto.setPpId(lineInfoX.get(i).getpId());
                        dto.setNodeIndex(lineInfoX.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoZ.size(); i++) {
                    if (value33.get(lineInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoZ.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoZ.get(i).getNodeIndex()) + ")");
                        dto.setpId(value33.get(lineInfoZ.get(i).getpId()));
                        dto.setPpId(lineInfoZ.get(i).getpId());
                        dto.setNodeIndex(lineInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoL.size(); i++) {
                    if (value333.get(lineInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoL.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoL.get(i).getNodeIndex()) + ")");
                        dto.setpId(value333.get(lineInfoL.get(i).getpId()));
                        dto.setPpId(lineInfoL.get(i).getpId());
                        dto.setNodeIndex(lineInfoL.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                return list;
            }
        }
    }

    //自定义、非自定义本身绑定的
    @Override
    public List<DeptslineTree> getDeptsLineTreeMyself(String deptsIndex, String area) {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "本身绑定的监测点";

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

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

        if (index.size() == 0) {
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            return list;
        } else {
            if (userUtil.getSysType().equals(ProjectEnum.PQS9000.getKey())) {
                dataType.add(1);
                dataType.add(2);
            } else {
                dataType.add(0);
                dataType.add(2);
            }
            Map<String, Object> optionMap = new HashMap<>();
            List<DeptslineTree> provinceX = new ArrayList<>();
            List<DeptslineTree> provinceZ = new ArrayList<>();
            List<DeptslineTree> provinceL = new ArrayList<>();
            if (area.equals("0")) {
                optionMap.put("gdindex", index);
                optionMap.put("dataType", dataType);
                optionMap.put("deptsIndex", deptsIndex);
                optionMap.put("sysType", userUtil.getSysType());
                provinceX = deptsLineTreeMapper.getOffTreeProVInfomyselfX(optionMap);
                provinceZ = deptsLineTreeMapper.getOffTreeProVInfomyselfZ(optionMap);
                provinceL = deptsLineTreeMapper.getOffTreeProVInfomyselfL(optionMap);
            } else {
                List<Province> provinces = provinceMapper.getArea(area);
                if (!provinces.isEmpty()) {
                    optionMap.put("gdindex", index);
                    optionMap.put("dataType", dataType);
                    optionMap.put("deptsIndex", deptsIndex);
                    optionMap.put("sysType", userUtil.getSysType());
                    optionMap.put("area", area);
                    provinceX = deptsLineTreeMapper.getOffTreeProVInfosmyselfX(optionMap);
                    provinceZ = deptsLineTreeMapper.getOffTreeProVInfosmyselfZ(optionMap);
                    provinceL = deptsLineTreeMapper.getOffTreeProVInfosmyselfL(optionMap);
                } else {
                    String area1 = deptsMapper.getParentArea(area);
                    if (area1 != null) {
                        optionMap.put("gdindex", index);
                        optionMap.put("dataType", dataType);
                        optionMap.put("deptsIndex", deptsIndex);
                        optionMap.put("sysType", userUtil.getSysType());
                        optionMap.put("area", area1);
                        provinceX = deptsLineTreeMapper.getOffTreeProVInfosmyselfX(optionMap);
                        provinceZ = deptsLineTreeMapper.getOffTreeProVInfosmyselfZ(optionMap);
                        provinceL = deptsLineTreeMapper.getOffTreeProVInfosmyselfL(optionMap);
                    }
                }
            }
            List<DeptslineTree> gdInfoX = deptsLineTreeMapper.getTreeGdInfomyselfX(optionMap);
            List<DeptslineTree> subInfoX = deptsLineTreeMapper.getOffTreeSubInfomyselfX(optionMap);
            List<DeptslineTree> lineInfoX = deptsLineTreeMapper.getOffTreeLineInfomyselfX(optionMap);
            List<DeptslineTree> gdInfoZ = deptsLineTreeMapper.getTreeGdInfomyselfZ(optionMap);
            List<DeptslineTree> subInfoZ = deptsLineTreeMapper.getOffTreeSubInfomyselfZ(optionMap);
            List<DeptslineTree> lineInfoZ = deptsLineTreeMapper.getOffTreeLineInfomyselfZ(optionMap);
            List<DeptslineTree> gdInfoL = deptsLineTreeMapper.getTreeGdInfomyselfL(optionMap);
            List<DeptslineTree> subInfoL = deptsLineTreeMapper.getOffTreeSubInfomyselfL(optionMap);
            List<DeptslineTree> lineInfoL = deptsLineTreeMapper.getOffTreeLineInfomyselfL(optionMap);
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            if (provinceX == null || gdInfoX == null || subInfoX == null || lineInfoX == null || provinceZ == null
                    || gdInfoZ == null || subInfoZ == null || lineInfoZ == null || provinceL == null || gdInfoL == null || subInfoL == null || lineInfoL == null) {
                return list;
            } else {
                Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value11 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value111 = new HashMap<Integer, Integer>();//离线
                int p1 = pIdNumber;
                for (int i = 0; i < provinceX.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceX.get(i).getName());
                    dto.setpId(101);
                    dto.setPpId(101);
                    dto.setNodeIndex(provinceX.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value1.put(provinceX.get(i).getNodeIndex(), p1);
                }
                for (int i = 0; i < provinceZ.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceZ.get(i).getName());
                    dto.setpId(102);
                    dto.setPpId(102);
                    dto.setNodeIndex(provinceZ.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value11.put(provinceZ.get(i).getNodeIndex(), p1);
                }

                for (int i = 0; i < provinceL.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceL.get(i).getName());
                    dto.setpId(103);
                    dto.setPpId(103);
                    dto.setNodeIndex(provinceL.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value111.put(provinceL.get(i).getNodeIndex(), p1);
                }
                Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value22 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value222 = new HashMap<Integer, Integer>();//离线
                int p2 = pIdNumber * 2;
                for (int i = 0; i < gdInfoX.size(); i++) {
                    if (value1.get(gdInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoX.get(i).getName());
                        dto.setpId(value1.get(gdInfoX.get(i).getpId()));
                        dto.setPpId(gdInfoX.get(i).getpId());
                        dto.setNodeIndex(gdInfoX.get(i).getNodeIndex());
                        dto.setNodeType(2);

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

                for (int i = 0; i < gdInfoZ.size(); i++) {
                    if (value11.get(gdInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoZ.get(i).getName());
                        dto.setpId(value11.get(gdInfoZ.get(i).getpId()));
                        dto.setPpId(gdInfoZ.get(i).getpId());
                        dto.setNodeIndex(gdInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value22.put(gdInfoZ.get(i).getNodeIndex(), p2);
                    }
                }

                for (int i = 0; i < gdInfoL.size(); i++) {
                    if (value111.get(gdInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoL.get(i).getName());
                        dto.setpId(value111.get(gdInfoL.get(i).getpId()));
                        dto.setPpId(gdInfoL.get(i).getpId());
                        dto.setNodeIndex(gdInfoL.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value222.put(gdInfoL.get(i).getNodeIndex(), p2);
                    }
                }
                Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value33 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value333 = new HashMap<Integer, Integer>();//离线
                int p3 = pIdNumber * 3;
                for (int i = 0; i < subInfoX.size(); i++) {
                    if (value2.get(subInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoX.get(i).getName());
                        dto.setpId(value2.get(subInfoX.get(i).getpId()));
                        dto.setPpId(subInfoX.get(i).getpId());
                        dto.setNodeIndex(subInfoX.get(i).getNodeIndex());
                        dto.setNodeType(3);

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

                for (int i = 0; i < subInfoZ.size(); i++) {
                    if (value22.get(subInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoZ.get(i).getName());
                        dto.setpId(value22.get(subInfoZ.get(i).getpId()));
                        dto.setPpId(subInfoZ.get(i).getpId());
                        dto.setNodeIndex(subInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value33.put(subInfoZ.get(i).getNodeIndex(), p3);
                    }
                }

                for (int i = 0; i < subInfoL.size(); i++) {
                    if (value222.get(subInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoL.get(i).getName());
                        dto.setpId(value222.get(subInfoL.get(i).getpId()));
                        dto.setPpId(subInfoL.get(i).getpId());
                        dto.setNodeIndex(subInfoL.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value333.put(subInfoL.get(i).getNodeIndex(), p3);
                    }
                }

                int p4 = pIdNumber * 4;
                for (int i = 0; i < lineInfoX.size(); i++) {
                    if (value3.get(lineInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoX.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoX.get(i).getNodeIndex()) + ")");
                        dto.setpId(value3.get(lineInfoX.get(i).getpId()));
                        dto.setPpId(lineInfoX.get(i).getpId());
                        dto.setNodeIndex(lineInfoX.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoZ.size(); i++) {
                    if (value33.get(lineInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoZ.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoZ.get(i).getNodeIndex()) + ")");
                        dto.setpId(value33.get(lineInfoZ.get(i).getpId()));
                        dto.setPpId(lineInfoZ.get(i).getpId());
                        dto.setNodeIndex(lineInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoL.size(); i++) {
                    if (value333.get(lineInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoL.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoL.get(i).getNodeIndex()) + ")");
                        dto.setpId(value333.get(lineInfoL.get(i).getpId()));
                        dto.setPpId(lineInfoL.get(i).getpId());
                        dto.setNodeIndex(lineInfoL.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                return list;
            }
        }
    }

    @Override
    public List<DeptslineTree> getDeptsLineTreeNoF(String deptsIndex, String area) {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "未绑定的监测点";

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

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

        if (index.size() == 0) {
            DeptslineTree dto = new DeptslineTree();
            dto.setId(100);
            dto.setNodeType(0);
            dto.setpId(0);
            dto.setPpId(0);
            dto.setName(dky);
            list.add(dto);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            return list;
        } else {
            if (userUtil.getSysType().equals(ProjectEnum.PQS9000.getKey())) {
                dataType.add(1);
                dataType.add(2);
            } else {
                dataType.add(0);
                dataType.add(2);
            }
            Map<String, Object> optionMap = new HashMap<>();
            optionMap.put("gdindex", index);
            optionMap.put("dataType", dataType);
            optionMap.put("sysType", userUtil.getSysType());
            optionMap.put("deptsIndex", deptsIndex);
            List<DeptslineTree> provinceX = new ArrayList<>();
            List<DeptslineTree> provinceZ = new ArrayList<>();
            List<DeptslineTree> provinceL = new ArrayList<>();
            if (area.equals("0")) {
                //说明是省级部门，需要查看是否有省份1.获取本身的area
                Depts depts = new Depts();
                depts.setDeptsIndex(deptsIndex);
                depts = deptsMapper.selectOne(depts);
                String areas = depts.getArea();
                //查询是否有省份
                List<Province> provinces = provinceMapper.getArea(areas);
                if (!provinces.isEmpty()) {
                    optionMap.put("area", areas);
                    provinceX = deptsLineTreeMapper.getOffTreeProVInfonoareaX(optionMap);
                    provinceZ = deptsLineTreeMapper.getOffTreeProVInfonoareaZ(optionMap);
                    provinceL = deptsLineTreeMapper.getOffTreeProVInfonoareaL(optionMap);
                } else {
                    provinceX = deptsLineTreeMapper.getOffTreeProVInfonoX(optionMap);
                    provinceZ = deptsLineTreeMapper.getOffTreeProVInfonoZ(optionMap);
                    provinceL = deptsLineTreeMapper.getOffTreeProVInfonoL(optionMap);
                }
            } else {
                List<Province> provinces = provinceMapper.getArea(area);
                if (!provinces.isEmpty()) {
                    optionMap.put("area", area);
                    provinceX = deptsLineTreeMapper.getOffTreeProVInfonoareaX(optionMap);
                    provinceZ = deptsLineTreeMapper.getOffTreeProVInfonoareaZ(optionMap);
                    provinceL = deptsLineTreeMapper.getOffTreeProVInfonoareaL(optionMap);
                } else {
                    String area1 = deptsMapper.getParentArea(area);
                    if (area1 != null) {
                        optionMap.put("area", area1);
                        provinceX = deptsLineTreeMapper.getOffTreeProVInfonoareaX(optionMap);
                        provinceZ = deptsLineTreeMapper.getOffTreeProVInfonoareaZ(optionMap);
                        provinceL = deptsLineTreeMapper.getOffTreeProVInfonoareaL(optionMap);
                    }
                }
            }
            List<DeptslineTree> gdInfoX = deptsLineTreeMapper.getTreeGdInfonoX(optionMap);
            List<DeptslineTree> subInfoX = deptsLineTreeMapper.getOffTreeSubInfonoX(optionMap);
            List<DeptslineTree> lineInfoX = deptsLineTreeMapper.getOffTreeLineInfonoX(optionMap);
            List<DeptslineTree> gdInfoZ = deptsLineTreeMapper.getTreeGdInfonoZ(optionMap);
            List<DeptslineTree> subInfoZ = deptsLineTreeMapper.getOffTreeSubInfonoZ(optionMap);
            List<DeptslineTree> lineInfoZ = deptsLineTreeMapper.getOffTreeLineInfonoZ(optionMap);
            List<DeptslineTree> gdInfoL = deptsLineTreeMapper.getTreeGdInfonoL(optionMap);
            List<DeptslineTree> subInfoL = deptsLineTreeMapper.getOffTreeSubInfonoL(optionMap);
            List<DeptslineTree> lineInfoL = deptsLineTreeMapper.getOffTreeLineInfonoL(optionMap);
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            if (provinceX == null || gdInfoX == null || subInfoX == null || lineInfoX == null || provinceZ == null
                    || gdInfoZ == null || subInfoZ == null || lineInfoZ == null || provinceL == null || gdInfoL == null || subInfoL == null || lineInfoL == null) {
                return list;
            } else {
                Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value11 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value111 = new HashMap<Integer, Integer>();//离线
                int p1 = pIdNumber;
                for (int i = 0; i < provinceX.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceX.get(i).getName());
                    dto.setpId(101);
                    dto.setPpId(101);
                    dto.setNodeIndex(provinceX.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value1.put(provinceX.get(i).getNodeIndex(), p1);
                }
                for (int i = 0; i < provinceZ.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceZ.get(i).getName());
                    dto.setpId(102);
                    dto.setPpId(102);
                    dto.setNodeIndex(provinceZ.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value11.put(provinceZ.get(i).getNodeIndex(), p1);
                }

                for (int i = 0; i < provinceL.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceL.get(i).getName());
                    dto.setpId(103);
                    dto.setPpId(103);
                    dto.setNodeIndex(provinceL.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value111.put(provinceL.get(i).getNodeIndex(), p1);
                }
                Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value22 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value222 = new HashMap<Integer, Integer>();//离线
                int p2 = pIdNumber * 2;
                for (int i = 0; i < gdInfoX.size(); i++) {
                    if (value1.get(gdInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoX.get(i).getName());
                        dto.setpId(value1.get(gdInfoX.get(i).getpId()));
                        dto.setPpId(gdInfoX.get(i).getpId());
                        dto.setNodeIndex(gdInfoX.get(i).getNodeIndex());
                        dto.setNodeType(2);

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

                for (int i = 0; i < gdInfoZ.size(); i++) {
                    if (value11.get(gdInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoZ.get(i).getName());
                        dto.setpId(value11.get(gdInfoZ.get(i).getpId()));
                        dto.setPpId(gdInfoZ.get(i).getpId());
                        dto.setNodeIndex(gdInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value22.put(gdInfoZ.get(i).getNodeIndex(), p2);
                    }
                }

                for (int i = 0; i < gdInfoL.size(); i++) {
                    if (value111.get(gdInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoL.get(i).getName());
                        dto.setpId(value111.get(gdInfoL.get(i).getpId()));
                        dto.setPpId(gdInfoL.get(i).getpId());
                        dto.setNodeIndex(gdInfoL.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value222.put(gdInfoL.get(i).getNodeIndex(), p2);
                    }
                }
                Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value33 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value333 = new HashMap<Integer, Integer>();//离线
                int p3 = pIdNumber * 3;
                for (int i = 0; i < subInfoX.size(); i++) {
                    if (value2.get(subInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoX.get(i).getName());
                        dto.setpId(value2.get(subInfoX.get(i).getpId()));
                        dto.setPpId(subInfoX.get(i).getpId());
                        dto.setNodeIndex(subInfoX.get(i).getNodeIndex());
                        dto.setNodeType(3);

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

                for (int i = 0; i < subInfoZ.size(); i++) {
                    if (value22.get(subInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoZ.get(i).getName());
                        dto.setpId(value22.get(subInfoZ.get(i).getpId()));
                        dto.setPpId(subInfoZ.get(i).getpId());
                        dto.setNodeIndex(subInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value33.put(subInfoZ.get(i).getNodeIndex(), p3);
                    }
                }

                for (int i = 0; i < subInfoL.size(); i++) {
                    if (value222.get(subInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoL.get(i).getName());
                        dto.setpId(value222.get(subInfoL.get(i).getpId()));
                        dto.setPpId(subInfoL.get(i).getpId());
                        dto.setNodeIndex(subInfoL.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value333.put(subInfoL.get(i).getNodeIndex(), p3);
                    }
                }

                int p4 = pIdNumber * 4;
                for (int i = 0; i < lineInfoX.size(); i++) {
                    if (value3.get(lineInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoX.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoX.get(i).getNodeIndex()) + ")");
                        dto.setpId(value3.get(lineInfoX.get(i).getpId()));
                        dto.setPpId(lineInfoX.get(i).getpId());
                        dto.setNodeIndex(lineInfoX.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoZ.size(); i++) {
                    if (value33.get(lineInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoZ.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoZ.get(i).getNodeIndex()) + ")");
                        dto.setpId(value33.get(lineInfoZ.get(i).getpId()));
                        dto.setPpId(lineInfoZ.get(i).getpId());
                        dto.setNodeIndex(lineInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoL.size(); i++) {
                    if (value333.get(lineInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoL.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoL.get(i).getNodeIndex()) + ")");
                        dto.setpId(value333.get(lineInfoL.get(i).getpId()));
                        dto.setPpId(lineInfoL.get(i).getpId());
                        dto.setNodeIndex(lineInfoL.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                return list;
            }
        }
    }

    @Override
    public List<DeptslineTree> getDeptsLineTreeOther(String deptsIndex, String area) {
        int pIdNumber = Integer.parseInt(appConfig.getPidNumber());
        String dky = "其他部门绑定的监测点";

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

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

        if (index.size() == 0) {
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            return list;
        } else {
            if (userUtil.getSysType().equals(ProjectEnum.PQS9000.getKey())) {
                dataType.add(1);
                dataType.add(2);
            } else {
                dataType.add(0);
                dataType.add(2);
            }
            Map<String, Object> optionMap = new HashMap<>();
            optionMap.put("gdindex", index);
            optionMap.put("dataType", dataType);
            optionMap.put("sysType", userUtil.getSysType());
            optionMap.put("deptsIndex", deptsIndex);
            List<DeptslineTree> provinceX = new ArrayList<>();
            List<DeptslineTree> provinceZ = new ArrayList<>();
            List<DeptslineTree> provinceL = new ArrayList<>();
            if (area.equals("0")) {
                //说明是省级部门，需要查看是否有省份1.获取本身的area
                Depts depts = new Depts();
                depts.setDeptsIndex(deptsIndex);
                depts = deptsMapper.selectOne(depts);
                String areas = depts.getArea();
                //查询是否有省份
                List<Province> provinces = provinceMapper.getArea(areas);
                if (!provinces.isEmpty()) {
                    optionMap.put("area", area);
                    provinceX = deptsLineTreeMapper.getOffTreeProVInfootherareaX(optionMap);
                    provinceZ = deptsLineTreeMapper.getOffTreeProVInfootherareaZ(optionMap);
                    provinceL = deptsLineTreeMapper.getOffTreeProVInfootherareaL(optionMap);
                } else {
                    provinceX = deptsLineTreeMapper.getOffTreeProVInfootherX(optionMap);
                    provinceZ = deptsLineTreeMapper.getOffTreeProVInfootherZ(optionMap);
                    provinceL = deptsLineTreeMapper.getOffTreeProVInfootherL(optionMap);
                }
            } else {
                List<Province> provinces = provinceMapper.getArea(area);
                if (!provinces.isEmpty()) {
                    optionMap.put("area", area);
                    provinceX = deptsLineTreeMapper.getOffTreeProVInfootherareaX(optionMap);
                    provinceZ = deptsLineTreeMapper.getOffTreeProVInfootherareaZ(optionMap);
                    provinceL = deptsLineTreeMapper.getOffTreeProVInfootherareaL(optionMap);
                } else {
                    String area1 = deptsMapper.getParentArea(area);
                    if (area1 != null) {
                        optionMap.put("area", area1);
                        provinceX = deptsLineTreeMapper.getOffTreeProVInfootherareaX(optionMap);
                        provinceZ = deptsLineTreeMapper.getOffTreeProVInfootherareaZ(optionMap);
                        provinceL = deptsLineTreeMapper.getOffTreeProVInfootherareaL(optionMap);
                    }
                }
            }
            List<DeptslineTree> gdInfoX = deptsLineTreeMapper.getTreeGdInfootherX(optionMap);
            List<DeptslineTree> subInfoX = deptsLineTreeMapper.getOffTreeSubInfootherX(optionMap);
            List<DeptslineTree> lineInfoX = deptsLineTreeMapper.getOffTreeLineInfootherX(optionMap);
            List<DeptslineTree> gdInfoZ = deptsLineTreeMapper.getTreeGdInfootherZ(optionMap);
            List<DeptslineTree> subInfoZ = deptsLineTreeMapper.getOffTreeSubInfootherZ(optionMap);
            List<DeptslineTree> lineInfoZ = deptsLineTreeMapper.getOffTreeLineInfootherZ(optionMap);
            List<DeptslineTree> gdInfoL = deptsLineTreeMapper.getTreeGdInfootherL(optionMap);
            List<DeptslineTree> subInfoL = deptsLineTreeMapper.getOffTreeSubInfootherL(optionMap);
            List<DeptslineTree> lineInfoL = deptsLineTreeMapper.getOffTreeLineInfootherL(optionMap);
            DeptslineTree dt = new DeptslineTree();
            dt.setId(100);
            dt.setNodeType(0);
            dt.setpId(0);
            dt.setPpId(0);
            dt.setName(dky);
            list.add(dt);
            DeptslineTree dtoX = new DeptslineTree();
            //虚拟
            dtoX.setId(101);
            dtoX.setNodeType(1);
            dtoX.setpId(100);
            dtoX.setPpId(100);
            dtoX.setName("虚拟");
            list.add(dtoX);
            DeptslineTree dtoZ = new DeptslineTree();
            //在线
            dtoZ.setId(102);
            dtoZ.setNodeType(2);
            dtoZ.setpId(100);
            dtoZ.setPpId(100);
            dtoZ.setName("在线");
            list.add(dtoZ);
            DeptslineTree dtoL = new DeptslineTree();
            //离线
            dtoL.setId(103);
            dtoL.setNodeType(3);
            dtoL.setpId(100);
            dtoL.setPpId(100);
            dtoL.setName("离线");
            list.add(dtoL);
            if (provinceX == null || gdInfoX == null || subInfoX == null || lineInfoX == null || provinceZ == null
                    || gdInfoZ == null || subInfoZ == null || lineInfoZ == null || provinceL == null || gdInfoL == null || subInfoL == null || lineInfoL == null) {
                return list;
            } else {
                Map<Integer, Integer> value1 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value11 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value111 = new HashMap<Integer, Integer>();//离线
                int p1 = pIdNumber;
                for (int i = 0; i < provinceX.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceX.get(i).getName());
                    dto.setpId(101);
                    dto.setPpId(101);
                    dto.setNodeIndex(provinceX.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value1.put(provinceX.get(i).getNodeIndex(), p1);
                }
                for (int i = 0; i < provinceZ.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceZ.get(i).getName());
                    dto.setpId(102);
                    dto.setPpId(102);
                    dto.setNodeIndex(provinceZ.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value11.put(provinceZ.get(i).getNodeIndex(), p1);
                }

                for (int i = 0; i < provinceL.size(); i++) {
                    DeptslineTree dto = new DeptslineTree();
                    dto.setId(++p1);
                    dto.setName(provinceL.get(i).getName());
                    dto.setpId(103);
                    dto.setPpId(103);
                    dto.setNodeIndex(provinceL.get(i).getNodeIndex());
                    dto.setNodeType(1);

                    list.add(dto);
                    value111.put(provinceL.get(i).getNodeIndex(), p1);
                }
                Map<Integer, Integer> value2 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value22 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value222 = new HashMap<Integer, Integer>();//离线
                int p2 = pIdNumber * 2;
                for (int i = 0; i < gdInfoX.size(); i++) {
                    if (value1.get(gdInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoX.get(i).getName());
                        dto.setpId(value1.get(gdInfoX.get(i).getpId()));
                        dto.setPpId(gdInfoX.get(i).getpId());
                        dto.setNodeIndex(gdInfoX.get(i).getNodeIndex());
                        dto.setNodeType(2);

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

                for (int i = 0; i < gdInfoZ.size(); i++) {
                    if (value11.get(gdInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoZ.get(i).getName());
                        dto.setpId(value11.get(gdInfoZ.get(i).getpId()));
                        dto.setPpId(gdInfoZ.get(i).getpId());
                        dto.setNodeIndex(gdInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value22.put(gdInfoZ.get(i).getNodeIndex(), p2);
                    }
                }

                for (int i = 0; i < gdInfoL.size(); i++) {
                    if (value111.get(gdInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p2);
                        dto.setName(gdInfoL.get(i).getName());
                        dto.setpId(value111.get(gdInfoL.get(i).getpId()));
                        dto.setPpId(gdInfoL.get(i).getpId());
                        dto.setNodeIndex(gdInfoL.get(i).getNodeIndex());
                        dto.setNodeType(2);

                        list.add(dto);
                        value222.put(gdInfoL.get(i).getNodeIndex(), p2);
                    }
                }
                Map<Integer, Integer> value3 = new HashMap<Integer, Integer>();//虚拟
                Map<Integer, Integer> value33 = new HashMap<Integer, Integer>();//在线
                Map<Integer, Integer> value333 = new HashMap<Integer, Integer>();//离线
                int p3 = pIdNumber * 3;
                for (int i = 0; i < subInfoX.size(); i++) {
                    if (value2.get(subInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoX.get(i).getName());
                        dto.setpId(value2.get(subInfoX.get(i).getpId()));
                        dto.setPpId(subInfoX.get(i).getpId());
                        dto.setNodeIndex(subInfoX.get(i).getNodeIndex());
                        dto.setNodeType(3);

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

                for (int i = 0; i < subInfoZ.size(); i++) {
                    if (value22.get(subInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoZ.get(i).getName());
                        dto.setpId(value22.get(subInfoZ.get(i).getpId()));
                        dto.setPpId(subInfoZ.get(i).getpId());
                        dto.setNodeIndex(subInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value33.put(subInfoZ.get(i).getNodeIndex(), p3);
                    }
                }

                for (int i = 0; i < subInfoL.size(); i++) {
                    if (value222.get(subInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p3);
                        dto.setName(subInfoL.get(i).getName());
                        dto.setpId(value222.get(subInfoL.get(i).getpId()));
                        dto.setPpId(subInfoL.get(i).getpId());
                        dto.setNodeIndex(subInfoL.get(i).getNodeIndex());
                        dto.setNodeType(3);

                        list.add(dto);
                        value333.put(subInfoL.get(i).getNodeIndex(), p3);
                    }
                }

                int p4 = pIdNumber * 4;
                for (int i = 0; i < lineInfoX.size(); i++) {
                    if (value3.get(lineInfoX.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoX.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoX.get(i).getNodeIndex()) + ")");
                        dto.setpId(value3.get(lineInfoX.get(i).getpId()));
                        dto.setPpId(lineInfoX.get(i).getpId());
                        dto.setNodeIndex(lineInfoX.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoZ.size(); i++) {
                    if (value33.get(lineInfoZ.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoZ.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoZ.get(i).getNodeIndex()) + ")");
                        dto.setpId(value33.get(lineInfoZ.get(i).getpId()));
                        dto.setPpId(lineInfoZ.get(i).getpId());
                        dto.setNodeIndex(lineInfoZ.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                for (int i = 0; i < lineInfoL.size(); i++) {
                    if (value333.get(lineInfoL.get(i).getpId()) != null) {
                        DeptslineTree dto = new DeptslineTree();
                        dto.setId(++p4);
                        dto.setName(lineInfoL.get(i).getName() + "(" + deviceMapper.getIpByLineIndex(lineInfoL.get(i).getNodeIndex()) + ")");
                        dto.setpId(value333.get(lineInfoL.get(i).getpId()));
                        dto.setPpId(lineInfoL.get(i).getpId());
                        dto.setNodeIndex(lineInfoL.get(i).getNodeIndex());
                        dto.setNodeType(4);

                        list.add(dto);
                    }
                }

                return list;
            }
        }
    }

}
