package com.unis.base.server.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.unis.base.common.vo.CcsbtzjsmxVO;
import com.unis.base.common.vo.OrganizationInfo;
import com.unis.base.server.dao.CcsbtzjsmxDao;
import com.unis.base.server.entity.CcsbtzjsmxDO;
import com.unis.base.server.service.CcsbtzjsmxService;
import com.unis.base.server.service.OrgainzeService;
import com.unis.common.utils.CurrentUtil;
import com.unis.common.utils.ResponseWrapper;
import com.unis.user.common.vo.org.OrgainzeVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Classname CcsbtzjsmxServiceImpl
 * @Description 仓储设备投资建设明细
 * @Date 2024/1/2 10:51
 * @Created by rising123sun
 */
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class CcsbtzjsmxServiceImpl implements CcsbtzjsmxService {

    @Resource
    private CcsbtzjsmxDao ccsbtzjsmxDao;

    @Resource
    private OrgainzeService orgainzeService;

    @Override
    public JSONArray queryCcsbtzjsmx(CcsbtzjsmxVO ccsbtzjsmxVO) {
        JSONArray jsonArray = new JSONArray();
        List<CcsbtzjsmxDO> ccsjList = new ArrayList<>();
        if (StringUtils.isNotBlank(ccsbtzjsmxVO.getOrgCode())) {
            String tyshxydm = ccsbtzjsmxDao.selectTyshxydmByOrgCode(ccsbtzjsmxVO.getOrgCode());
            ccsbtzjsmxVO.setSskddm(tyshxydm);
            CcsbtzjsmxDO ccsbtzjsmxDO = new CcsbtzjsmxDO();
            // 根据orgCode查询企业级别以及企业名称
            OrganizationInfo organizationInfo = ccsbtzjsmxDao.selectQyjbByOrgCode(ccsbtzjsmxVO.getOrgCode());
            if (null != organizationInfo) {
                ccsbtzjsmxDO.setSskddm(tyshxydm);
                ccsbtzjsmxDO.setSskdmc(organizationInfo.getOrgName());
                ccsbtzjsmxDO.setOrgCode(organizationInfo.getOrgCode());
                ccsbtzjsmxDO.setParentOrgCode(organizationInfo.getParentOrgCode());
            }
            List<CcsbtzjsmxDO> ccsbtzjsmxVOS = ccsbtzjsmxDao.selectForHz(ccsbtzjsmxVO);
            for (CcsbtzjsmxDO vo : ccsbtzjsmxVOS) {
                if ("粮食设备".equals(vo.getSbyjlb()) || "仓储器材".equals(vo.getSbyjlb())) {
                    vo.setSbyjlb(vo.getSbmc());
                }
                if ("3".equals(vo.getSblx())) {
                    vo.setSbyjlb(vo.getSbejlb());
                }
                // 设置一级设备名称
                OrganizationInfo organizationInfo1 = ccsbtzjsmxDao.getYjsblbByEnuname(vo.getSbyjlb());
                if ("1".equals(vo.getSblx())) {
                    if (null != organizationInfo1 && organizationInfo1.getParentid() == 5476) {
                        vo.setSbyjlb(organizationInfo1.getEnumname());
                    } else {
                        String sbyjlb = getYjsblb(organizationInfo1.getParentid());
                        vo.setSbyjlb(sbyjlb);
                    }
                } else if ("3".equals(vo.getSblx())) {
                    if (null != organizationInfo1 && organizationInfo1.getParentid() == 5475) {
                        vo.setSbyjlb(organizationInfo1.getEnumname());
                    } else {
                        String sbyjlb = getYjsblb(organizationInfo1.getParentid());
                        vo.setSbyjlb(sbyjlb);
                    }
                }
            }
            List<CcsbtzjsmxDO> lssbList = ccsbtzjsmxVOS.stream().filter(ccsbtzjsmxDO1 -> "1".equals(ccsbtzjsmxDO1.getSblx())).collect(Collectors.toList());
            List<CcsbtzjsmxDO> ccqcList = ccsbtzjsmxVOS.stream().filter(ccsbtzjsmxDO1 -> "3".equals(ccsbtzjsmxDO1.getSblx())).collect(Collectors.toList());
            Integer allGrsl = ccsbtzjsmxVOS.stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0);
            BigDecimal allHj = ccsbtzjsmxVOS.stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
            Integer lssbGrsl = lssbList.stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0);
            BigDecimal lssbHj = lssbList.stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
            Integer ccqcGrsl = ccqcList.stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0);
            BigDecimal ccqcHj = ccqcList.stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
            JSONObject sblxObject = new JSONObject();
            // 先将ccsbtzjsmxVOS的grsl的和放入按设备类型分当中
            sblxObject.put("name", "按设备类型分");
            sblxObject.put("grsl", allGrsl);
            // 将bigDecimal类型的jrje加在一起，保留两位小数
            sblxObject.put("hj", formatJeNumber(allHj));
            // 分别创建sblx为1的粮食设备和sblx为3的仓储器材的jsonObject，放入到sblxObject的children中
            JSONObject lssbObject = new JSONObject();
            lssbObject.put("name", "        粮食设备");
            lssbObject.put("grsl", lssbGrsl);
            lssbObject.put("hj", formatJeNumber(lssbHj));
            JSONObject ccqcObject = new JSONObject();
            ccqcObject.put("name", "        仓储器材");
            ccqcObject.put("grsl", ccqcGrsl);
            ccqcObject.put("hj", formatJeNumber(ccqcHj));
            sblxObject.put("children", new JSONArray() {{
                add(lssbObject);
                add(ccqcObject);
            }});
            JSONObject sbqclbObject = new JSONObject();
            sbqclbObject.put("name", "按设备器材类别分");
            sbqclbObject.put("grsl", allGrsl);
            sbqclbObject.put("hj", formatJeNumber(allHj));

            // 按设备器材类别分分为按粮食设备类别分和按仓储器材类别分两大类,放入sbqclbObject的children中
            JSONObject lssblbObject = new JSONObject();
            lssblbObject.put("name", "      按粮食设备类别分");
            lssblbObject.put("grsl", lssbGrsl);
            lssblbObject.put("hj", formatJeNumber(lssbHj));
            JSONObject ccqclbObject = new JSONObject();
            ccqclbObject.put("name", "      按仓储器材类别分");
            ccqclbObject.put("grsl", ccqcGrsl);
            ccqclbObject.put("hj", formatJeNumber(ccqcHj));
            sbqclbObject.put("children", new JSONArray() {{
                add(lssblbObject);
                add(ccqclbObject);
            }});

            // 分别设置按粮食设备类别分和按仓储器材类别分的children，分类是通过sblx,sbyjlb分组
            Map<String, List<CcsbtzjsmxDO>> lssbMap = lssbList.stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSbyjlb));
            Map<String, List<CcsbtzjsmxDO>> ccqcMap = ccqcList.stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSbyjlb));
            JSONArray lssbArray = new JSONArray();
            JSONArray ccqcArray = new JSONArray();
            for (Map.Entry<String, List<CcsbtzjsmxDO>> entry : lssbMap.entrySet()) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("name", "                " + entry.getKey());
                jsonObject.put("grsl", entry.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                BigDecimal bigDecimal = entry.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                jsonObject.put("hj", formatJeNumber(bigDecimal));
                lssbArray.add(jsonObject);
                // 遍历lssbArray，分别设置children
                Map<String, List<CcsbtzjsmxDO>> lssbMap1 = entry.getValue().stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSbejlb));
                JSONArray lssbArray1 = new JSONArray();
                for (Map.Entry<String, List<CcsbtzjsmxDO>> entry1 : lssbMap1.entrySet()) {
                    JSONObject jsonObject1 = new JSONObject();
                    jsonObject1.put("name", "                       " + entry1.getKey());
                    jsonObject1.put("grsl", entry1.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                    BigDecimal bigDecimal1 = entry1.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                    jsonObject1.put("hj", formatJeNumber(bigDecimal1));
                    lssbArray1.add(jsonObject1);

                    // 保存到集合，便于后面保存到数据库
                    CcsbtzjsmxDO ccsj = new CcsbtzjsmxDO();
                    ccsj.setSblx("1");
                    ccsj.setSbmc(entry1.getKey());
                    ccsj.setSskddm(ccsbtzjsmxDO.getSskddm());
                    ccsj.setSskdmc(ccsbtzjsmxDO.getSskdmc());
                    ccsj.setParentOrgCode(ccsbtzjsmxDO.getParentOrgCode());
                    ccsj.setSbyjlb(entry.getKey());
                    ccsj.setSbejlb(entry1.getKey());
                    ccsj.setGrsl(jsonObject1.getInteger("grsl"));
                    ccsj.setJrje(formatJeNumber(jsonObject1.getBigDecimal("hj")));
                    ccsj.setOrgCode(ccsbtzjsmxVO.getOrgCode());
                    ccsjList.add(ccsj);
                }
                jsonObject.put("children", lssbArray1);
            }
            for (Map.Entry<String, List<CcsbtzjsmxDO>> entry : ccqcMap.entrySet()) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("name", "                " + entry.getKey());
                jsonObject.put("grsl", entry.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                BigDecimal bigDecimal = entry.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                jsonObject.put("hj", formatJeNumber(bigDecimal));
                ccqcArray.add(jsonObject);
                // 遍历ccqcArray，分别设置children
                Map<String, List<CcsbtzjsmxDO>> ccqcMap1 = entry.getValue().stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSbejlb));
                JSONArray ccqcArray1 = new JSONArray();
                for (Map.Entry<String, List<CcsbtzjsmxDO>> entry1 : ccqcMap1.entrySet()) {
                    JSONObject jsonObject1 = new JSONObject();
                    jsonObject1.put("name", "                       " + entry1.getKey());
                    jsonObject1.put("grsl", entry1.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                    BigDecimal bigDecimal1 = entry1.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                    jsonObject1.put("hj", formatJeNumber(bigDecimal1));
                    ccqcArray1.add(jsonObject1);

                    // 保存到集合，便于后面保存到数据库
                    CcsbtzjsmxDO ccsj = new CcsbtzjsmxDO();
                    ccsj.setSblx("3");
                    ccsj.setSbmc(entry1.getKey());
                    ccsj.setSskddm(ccsbtzjsmxDO.getSskddm());
                    ccsj.setSskdmc(ccsbtzjsmxDO.getSskdmc());
                    ccsj.setParentOrgCode(ccsbtzjsmxDO.getParentOrgCode());
                    ccsj.setSbyjlb(entry.getKey());
                    ccsj.setSbejlb(entry1.getKey());
                    ccsj.setGrsl(jsonObject1.getInteger("grsl"));
                    ccsj.setJrje(formatJeNumber(jsonObject1.getBigDecimal("hj")));
                    ccsj.setOrgCode(ccsbtzjsmxVO.getOrgCode());
                    ccsjList.add(ccsj);
                }
                jsonObject.put("children", ccqcArray1);
            }
            lssblbObject.put("children", lssbArray);
            ccqclbObject.put("children", ccqcArray);

            // 合计
            JSONObject hjObject = new JSONObject();
            hjObject.put("name", "合计");
            hjObject.put("grsl", allGrsl);
            hjObject.put("hj", formatJeNumber(allHj));
            jsonArray.add(sblxObject);
            jsonArray.add(sbqclbObject);
            jsonArray.add(hjObject);
            JSONObject ccsbJson = new JSONObject();
            ccsbJson.put("ccsjList", ccsjList);
            jsonArray.add(ccsbJson);

            return jsonArray;
        }
        return null;
    }

    @Override
    public ResponseWrapper saveCcsbtzjsmx(String orgCode, String sbnf, List<CcsbtzjsmxDO> ccsjList) {
        // 删除当前企业的上报数据
        CcsbtzjsmxDO oldCcsbtzjsmxDO = new CcsbtzjsmxDO();
        oldCcsbtzjsmxDO.setOrgCode(orgCode);
        oldCcsbtzjsmxDO.setSbnf(sbnf);
        oldCcsbtzjsmxDO.setJrje(null);
        ccsbtzjsmxDao.delete(oldCcsbtzjsmxDO);

        // 保存当前企业的上报数据
        if (null != ccsjList && ccsjList.size() > 0) {
            for (CcsbtzjsmxDO ccsbtzjsmxDO : ccsjList) {
                ccsbtzjsmxDO.setId(UUID.randomUUID().toString().replace("-", ""));
                ccsbtzjsmxDO.setSbnf(sbnf);
                ccsbtzjsmxDO.setOrgCode(orgCode);
                ccsbtzjsmxDO.setSbzt("1");
                ccsbtzjsmxDO.setSbsj(new Date());
                ccsbtzjsmxDao.insert(ccsbtzjsmxDO);
            }
        }
        return ResponseWrapper.success("上报成功");
    }

    @Override
    public JSONArray queryCcsbtzjsmxForHz(CcsbtzjsmxVO ccsbtzjsmxVO) {
        if (StringUtils.isNotBlank(ccsbtzjsmxVO.getOrgCode()) && StringUtils.isNotBlank(ccsbtzjsmxVO.getSbnf())) {

            Example example = new Example(CcsbtzjsmxDO.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andLike("orgCode", ccsbtzjsmxVO.getOrgCode() + "%");
            criteria.andEqualTo("sbnf", ccsbtzjsmxVO.getSbnf());
            List<CcsbtzjsmxDO> ccsbtzjsmxDOList = ccsbtzjsmxDao.selectByExample(example);

            if (ccsbtzjsmxDOList.size() > 0) {
                // 将ccsbtzjsmxDOList 按照sblx分组
                List<CcsbtzjsmxDO> lssbList = ccsbtzjsmxDOList.stream().filter(ccsbtzjsmxDO -> "1".equals(ccsbtzjsmxDO.getSblx())).collect(Collectors.toList());
                List<CcsbtzjsmxDO> ccqcList = ccsbtzjsmxDOList.stream().filter(ccsbtzjsmxDO -> "3".equals(ccsbtzjsmxDO.getSblx())).collect(Collectors.toList());
                Integer allGrsl = ccsbtzjsmxDOList.stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0);
                BigDecimal allHj = ccsbtzjsmxDOList.stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                Integer lssbGrsl = lssbList.stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0);
                BigDecimal lssbHj = lssbList.stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                Integer ccqcGrsl = ccqcList.stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0);
                BigDecimal ccqcHj = ccqcList.stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);

                // 按设备类型分
                JSONObject sblxObject = new JSONObject();
                sblxObject.put("name", "按设备类型分");
                sblxObject.put("grsl", allGrsl);
                sblxObject.put("hj", formatJeNumber(allHj));
                JSONObject lssbObject = new JSONObject();
                lssbObject.put("name", "        粮食设备");
                lssbObject.put("grsl", lssbGrsl);
                lssbObject.put("hj", formatJeNumber(lssbHj));
                JSONObject ccqcObject = new JSONObject();
                ccqcObject.put("name", "        仓储器材");
                ccqcObject.put("grsl", ccqcGrsl);
                ccqcObject.put("hj", formatJeNumber(ccqcHj));
                sblxObject.put("children", new JSONArray() {{
                    add(lssbObject);
                    add(ccqcObject);
                }});

                // 按设备器材类别分
                JSONObject sbqclbObject = new JSONObject();
                sbqclbObject.put("name", "按设备器材类别分");
                sbqclbObject.put("grsl", allGrsl);
                sbqclbObject.put("hj", formatJeNumber(allHj));
                JSONObject lssblbObject = new JSONObject();
                lssblbObject.put("name", "        按粮食设备类别分");
                lssblbObject.put("grsl", lssbGrsl);
                lssblbObject.put("hj", formatJeNumber(lssbHj));
                JSONObject ccqclbObject = new JSONObject();
                ccqclbObject.put("name", "        按仓储器材类别分");
                ccqclbObject.put("grsl", ccqcGrsl);
                ccqclbObject.put("hj", formatJeNumber(ccqcHj));
                sbqclbObject.put("children", new JSONArray() {{
                    add(lssblbObject);
                    add(ccqclbObject);
                }});

                // 按粮食设备类别分
                Map<String, List<CcsbtzjsmxDO>> lssbMap = lssbList.stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSbyjlb));
                JSONArray lssbArray = new JSONArray();
                for (Map.Entry<String, List<CcsbtzjsmxDO>> entry : lssbMap.entrySet()) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("name", "                " + entry.getKey());
                    jsonObject.put("grsl", entry.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                    BigDecimal bigDecimal = entry.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                    jsonObject.put("hj", formatJeNumber(bigDecimal));
                    lssbArray.add(jsonObject);
                    // 遍历lssbArray，分别设置children
                    Map<String, List<CcsbtzjsmxDO>> lssbMap1 = entry.getValue().stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSbejlb));
                    JSONArray lssbArray1 = new JSONArray();
                    for (Map.Entry<String, List<CcsbtzjsmxDO>> entry1 : lssbMap1.entrySet()) {
                        JSONObject jsonObject1 = new JSONObject();
                        jsonObject1.put("name", "                       " + entry1.getKey());
                        jsonObject1.put("grsl", entry1.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                        BigDecimal bigDecimal1 = entry1.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                        jsonObject1.put("hj", formatJeNumber(bigDecimal1));
                        lssbArray1.add(jsonObject1);
                    }
                    jsonObject.put("children", lssbArray1);
                }
                lssblbObject.put("children", lssbArray);

                // 按仓储器材类别分
                Map<String, List<CcsbtzjsmxDO>> ccqcMap = ccqcList.stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSbyjlb));
                JSONArray ccqcArray = new JSONArray();
                for (Map.Entry<String, List<CcsbtzjsmxDO>> entry : ccqcMap.entrySet()) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("name", "                " + entry.getKey());
                    jsonObject.put("grsl", entry.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                    BigDecimal bigDecimal = entry.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                    jsonObject.put("hj", formatJeNumber(bigDecimal));
                    ccqcArray.add(jsonObject);
                    // 遍历ccqcArray，分别设置children
                    Map<String, List<CcsbtzjsmxDO>> ccqcMap1 = entry.getValue().stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSbejlb));
                    JSONArray ccqcArray1 = new JSONArray();
                    for (Map.Entry<String, List<CcsbtzjsmxDO>> entry1 : ccqcMap1.entrySet()) {
                        JSONObject jsonObject1 = new JSONObject();
                        jsonObject1.put("name", "                       " + entry1.getKey());
                        jsonObject1.put("grsl", entry1.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                        BigDecimal bigDecimal1 = entry1.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
                        jsonObject1.put("hj", formatJeNumber(bigDecimal1));
                        ccqcArray1.add(jsonObject1);
                    }
                    jsonObject.put("children", ccqcArray1);
                }
                ccqclbObject.put("children", ccqcArray);

                // 合计
                JSONObject hjObject = new JSONObject();
                hjObject.put("name", "合计");
                hjObject.put("grsl", allGrsl);
                hjObject.put("hj", formatJeNumber(allHj));

                JSONArray jsonArray = new JSONArray();
                jsonArray.add(sblxObject);
                jsonArray.add(sbqclbObject);
                jsonArray.add(hjObject);
                return jsonArray;

            } else {
                // 所有都设置为0
                JSONObject sblxObject = new JSONObject();
                sblxObject.put("name", "按设备类型分");
                sblxObject.put("grsl", 0);
                sblxObject.put("hj", 0);
                JSONObject lssbObject = new JSONObject();
                lssbObject.put("name", "        粮食设备");
                lssbObject.put("grsl", 0);
                lssbObject.put("hj", 0);
                JSONObject ccqcObject = new JSONObject();
                ccqcObject.put("name", "        仓储器材");
                ccqcObject.put("grsl", 0);
                ccqcObject.put("hj", 0);
                sblxObject.put("children", new JSONArray() {{
                    add(lssbObject);
                    add(ccqcObject);
                }});
                JSONObject sbqclbObject = new JSONObject();
                sbqclbObject.put("name", "按设备器材类别分");
                sbqclbObject.put("grsl", 0);
                sbqclbObject.put("hj", 0);
                JSONObject lssblbObject = new JSONObject();
                lssblbObject.put("name", "        按粮食设备类别分");
                lssblbObject.put("grsl", 0);
                lssblbObject.put("hj", 0);
                JSONObject ccqclbObject = new JSONObject();
                ccqclbObject.put("name", "        按仓储器材类别分");
                ccqclbObject.put("grsl", 0);
                ccqclbObject.put("hj", 0);
                sbqclbObject.put("children", new JSONArray() {{
                    add(lssblbObject);
                    add(ccqclbObject);
                }});

                // 合计
                JSONObject hjObject = new JSONObject();
                hjObject.put("name", "合计");
                hjObject.put("grsl", 0);
                hjObject.put("hj", 0);

                JSONArray jsonArray = new JSONArray();
                jsonArray.add(sblxObject);
                jsonArray.add(sbqclbObject);
                jsonArray.add(hjObject);
                return jsonArray;
            }
        }
        return null;
    }

    public static BigDecimal formatJeNumber(BigDecimal number) {
        // 如果为空，返回0
        if (null == number) {
            return BigDecimal.ZERO;
        }
        if (number.scale() > 0 && number.stripTrailingZeros().scale() > 0) {
            return number.setScale(2, RoundingMode.HALF_UP);
        } else {
            return number.setScale(0, RoundingMode.HALF_UP);
        }
    }

    @Override
    public JSONObject queryCcsbtzjsmxForMx(CcsbtzjsmxVO ccsbtzjsmxVO) {
        OrgainzeVO organization = orgainzeService.getOrganization();
        OrgainzeVO organization1 = getOrganization(ccsbtzjsmxVO.getOrgCode(), organization);
        JSONObject jsonObject = new JSONObject();
        if (null != organization1) {
            // 获取organization1和他的子节点以及子节点的子节点的orgName
            List<String> orgNameList = getOrgNameList(organization1);
            // 把自己去掉
            orgNameList.remove(organization1.getOrgName());
            String sbnf = ccsbtzjsmxVO.getSbnf();
            Example example = new Example(CcsbtzjsmxDO.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("sbnf", sbnf);
            // 查询当前sbnf的上报数据
            List<CcsbtzjsmxDO> ccsbtzjsmxDOList = ccsbtzjsmxDao.selectByExample(example);
            JSONArray jsonArray = new JSONArray();
            // 将orgNameList和ccsbtzjsmxDOList进行匹配，如果ccsbtzjsmxDOList中的sskdmc包含在orgNameList中，则将该条数据放入到jsonArray中
            // orgNameList不在ccsbtzjsmxDOList中的数据，放入到另一个集合中，进行下一步处理
            List<String> bczList = new ArrayList<>();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (String orgName : orgNameList) {
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("kqmc", orgName);
                boolean flag = false;
                for (CcsbtzjsmxDO ccsbtzjsmxDO : ccsbtzjsmxDOList) {
                    if (ccsbtzjsmxDO.getSskdmc().equals(orgName)) {
                        flag = true;
                        jsonObject1.put("sblx", "1".equals(ccsbtzjsmxDO.getSblx()) ? "粮食设备" : "仓储器材");
                        jsonObject1.put("sblb", ccsbtzjsmxDO.getSbyjlb());
                        jsonObject1.put("sbmc", ccsbtzjsmxDO.getSbmc());
                        jsonObject1.put("grsl", ccsbtzjsmxDO.getGrsl());
                        jsonObject1.put("jrhj", formatJeNumber(ccsbtzjsmxDO.getJrje()));
                        jsonObject1.put("zt", "已上报");
                        jsonObject1.put("qrsj", sdf.format(ccsbtzjsmxDO.getSbsj()));
                        jsonArray.add(jsonObject1);
                        break;
                    }
                }
                if (!flag) {
                    bczList.add(orgName);
                }
            }
            // 不存在的数据，设置查询数据库
            if (bczList.size() > 0) {
                CcsbtzjsmxVO ccsbtzjsmxVO1 = new CcsbtzjsmxVO();
                ccsbtzjsmxVO1.setSbnf(sbnf);
                ccsbtzjsmxVO1.setSskdmcList(bczList);
                List<CcsbtzjsmxDO> ccsbtzjsmxVOS = ccsbtzjsmxDao.selectForHz(ccsbtzjsmxVO);
                // 根据sskdmc分组
                if (ccsbtzjsmxVOS.size() > 0) {
                    Map<String, List<CcsbtzjsmxDO>> ccsbtzjsmxDOMap = ccsbtzjsmxVOS.stream().collect(Collectors.groupingBy(CcsbtzjsmxDO::getSskdmc));
                    // bczList没在ccsbtzjsmxDOMap的key当中的元素，将这个设置为未上报，所有数据都设置成空
                    for (String s : bczList) {
                        if (!ccsbtzjsmxDOMap.containsKey(s)) {
                            JSONObject jsonObject1 = new JSONObject();
                            jsonObject1.put("kqmc", s);
                            jsonObject1.put("sblx", "");
                            jsonObject1.put("sblb", "");
                            jsonObject1.put("sbmc", "");
                            jsonObject1.put("grsl", null);
                            jsonObject1.put("jrhj", null);
                            jsonObject1.put("zt", "未上报");
                            jsonObject1.put("qrsj", null);
                            jsonArray.add(jsonObject1);
                        } else {
                            // ccsbtzjsmxDOMap中包含的数据，设置为未确认
                            List<CcsbtzjsmxDO> ccsbtzjsmxDOList1 = ccsbtzjsmxDOMap.get(s);
                            for (CcsbtzjsmxDO vo : ccsbtzjsmxDOList1) {
                                if ("粮食设备".equals(vo.getSbyjlb()) || "仓储器材".equals(vo.getSbyjlb())) {
                                    vo.setSbyjlb(vo.getSbmc());
                                }
                                if ("3".equals(vo.getSblx())) {
                                    vo.setSbyjlb(vo.getSbejlb());
                                }
                                // 设置一级设备名称
                                OrganizationInfo organizationInfo1 = ccsbtzjsmxDao.getYjsblbByEnuname(vo.getSbyjlb());
                                if ("1".equals(vo.getSblx())) {
                                    if (null != organizationInfo1 && organizationInfo1.getParentid() == 5476) {
                                        vo.setSbyjlb(organizationInfo1.getEnumname());
                                    } else {
                                        String sbyjlb = getYjsblb(organizationInfo1.getParentid());
                                        vo.setSbyjlb(sbyjlb);
                                    }
                                } else if ("3".equals(vo.getSblx())) {
                                    if (null != organizationInfo1 && organizationInfo1.getParentid() == 5475) {
                                        vo.setSbyjlb(organizationInfo1.getEnumname());
                                    } else {
                                        String sbyjlb = getYjsblb(organizationInfo1.getParentid());
                                        vo.setSbyjlb(sbyjlb);
                                    }
                                }
                            }
                            //将ccsbtzjsmxDOList1先根据sblx,再根据sbyjlb最后根据sbejlb分组,最后得到新的Map
                            Map<String, List<CcsbtzjsmxDO>> groupedMap = ccsbtzjsmxDOList1.stream()
                                    .collect(Collectors.groupingBy(
                                            ccsbtzjsmxDO -> ccsbtzjsmxDO.getSblx() + "_" + ccsbtzjsmxDO.getSbyjlb() + "_" + ccsbtzjsmxDO.getSbejlb()
                                    ));
                            // 遍历groupedMap,将每个key对应的value的grsl和jrje相加,得到新的ccsbtzjsmxDOList2
                            List<CcsbtzjsmxDO> ccsbtzjsmxDOList2 = new ArrayList<>();
                            for (Map.Entry<String, List<CcsbtzjsmxDO>> entry : groupedMap.entrySet()) {
                                CcsbtzjsmxDO ccsbtzjsmxDO = new CcsbtzjsmxDO();
                                ccsbtzjsmxDO.setSblx(entry.getValue().get(0).getSblx());
                                ccsbtzjsmxDO.setSbyjlb(entry.getValue().get(0).getSbyjlb());
                                ccsbtzjsmxDO.setSbejlb(entry.getValue().get(0).getSbejlb());
                                ccsbtzjsmxDO.setGrsl(entry.getValue().stream().map(CcsbtzjsmxDO::getGrsl).reduce(Integer::sum).orElse(0));
                                ccsbtzjsmxDO.setJrje(entry.getValue().stream().map(CcsbtzjsmxDO::getJrje).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP));
                                ccsbtzjsmxDOList2.add(ccsbtzjsmxDO);
                            }

                            for (CcsbtzjsmxDO ccsbtzjsmxDO : ccsbtzjsmxDOList2) {
                                JSONObject jsonObject1 = new JSONObject();
                                jsonObject1.put("kqmc", ccsbtzjsmxDO.getSskdmc());
                                jsonObject1.put("sblx", "1".equals(ccsbtzjsmxDO.getSblx()) ? "粮食设备" : "仓储器材");
                                jsonObject1.put("sblb", ccsbtzjsmxDO.getSbyjlb());
                                jsonObject1.put("sbmc", ccsbtzjsmxDO.getSbmc());
                                jsonObject1.put("grsl", ccsbtzjsmxDO.getGrsl());
                                jsonObject1.put("jrhj", formatJeNumber(ccsbtzjsmxDO.getJrje()));
                                jsonObject1.put("zt", "未确认");
                                jsonObject1.put("qrsj", null);
                                jsonArray.add(jsonObject1);
                            }
                        }
                    }

                }

            }
            // 添加合计，是所有数据的合计
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("kqmc", "合计");
            jsonObject1.put("sblx", "");
            jsonObject1.put("sblb", "");
            jsonObject1.put("sbmc", "");
            Integer grsl = jsonArray.stream().filter(o -> null != ((JSONObject) o).getInteger("grsl")).map(o -> ((JSONObject) o).getInteger("grsl")).reduce(Integer::sum).orElse(0);
            jsonObject1.put("grsl", grsl);
            BigDecimal jrje = jsonArray.stream().filter(o -> null != ((JSONObject) o).getBigDecimal("jrhj")).map(o -> ((JSONObject) o).getBigDecimal("jrhj")).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).setScale(3, BigDecimal.ROUND_HALF_UP);
            jsonObject1.put("jrhj", formatJeNumber(jrje));
            jsonObject1.put("zt", "");
            jsonObject1.put("qrsj", null);
            jsonArray.add(jsonObject1);

            jsonObject.put("data", jsonArray);

        } else {
            jsonObject.put("data", new JSONArray());
        }
        return jsonObject;
    }

    @Override
    public JSONObject queryCcsbtzjsmxForMxGld(CcsbtzjsmxVO ccsbtzjsmxVO) {
        if (CurrentUtil.getOrgId().equals("LS001")) {
            // 市局查看
            OrgainzeVO organization = orgainzeService.getOrganization();
            // 把organization的children的orgName为和平区发改委，河东区发改委，河西区发改委，南开区发改委,河北区发改委，红桥区发改委剔除掉
            List<OrgainzeVO> children = organization.getChildren();
            List<OrgainzeVO> children1 = new ArrayList<>();
            for (OrgainzeVO orgainzeVO : children) {
                if (!"和平区发改委".equals(orgainzeVO.getOrgName()) && !"河东区发改委".equals(orgainzeVO.getOrgName()) && !"河西区发改委".equals(orgainzeVO.getOrgName()) && !"南开区发改委".equals(orgainzeVO.getOrgName()) && !"河北区发改委".equals(orgainzeVO.getOrgName()) && !"红桥区发改委".equals(orgainzeVO.getOrgName())) {
                    children1.add(orgainzeVO);
                }
            }
            organization.setChildren(children1);
            JSONArray jsonArray = new JSONArray();
            if (organization.getChildren().size() > 0) {
                for (OrgainzeVO child : organization.getChildren()) {
                    CcsbtzjsmxVO ccsbtzjsmxVO1 = new CcsbtzjsmxVO();
                    ccsbtzjsmxVO1.setOrgCode(child.getOrgCode());
                    ccsbtzjsmxVO1.setSbnf(ccsbtzjsmxVO.getSbnf());
                    JSONObject jsonObject = queryCcsbtzjsmxForMx(ccsbtzjsmxVO1);
                    JSONArray data = jsonObject.getJSONArray("data");
                    // 过滤掉kqmc为合计的数据
                    JSONArray jsonArray1 = new JSONArray();
                    for (Object o : data) {
                        JSONObject jsonObject1 = (JSONObject) o;
                        if (!"合计".equals(jsonObject1.getString("kqmc"))) {
                            jsonArray1.add(jsonObject1);
                        }
                    }
                    data = jsonArray1;
                    JSONObject jsonObject1 = new JSONObject();
                    if (child.getOrgName().equals("天津市粮食储备有限公司")) {
                        jsonObject1.put("异地库", data);
                    } else {
                        // 如果包含发改委三个字，就截取掉
                        if (child.getOrgName().contains("发改委")) {
                            jsonObject1.put(child.getOrgName().replace("发改委", ""), data);
                        } else {
                            jsonObject1.put(child.getOrgName(), data);
                        }
                    }
                    jsonArray.add(jsonObject1);
                }
            }
            // 进行筛选条件的过滤
            if (StringUtils.isNotBlank(ccsbtzjsmxVO.getSsqymc())) {
                // 过滤掉不包含ssqymc的数据
                JSONArray jsonArray1 = new JSONArray();
                for (Object o : jsonArray) {
                    JSONObject jsonObject = (JSONObject) o;
                    // 模糊查询
                    String key = jsonObject.keySet().iterator().next();
                    if (key.contains(ccsbtzjsmxVO.getSsqymc())) {
                        jsonArray1.add(jsonObject);
                    }
                }
                jsonArray = jsonArray1;
            }
            // 所属库点
            if (StringUtils.isNotBlank(ccsbtzjsmxVO.getSskdmc())) {
                // 过滤掉不包含sskdmc的数据
                JSONArray jsonArray1 = new JSONArray();
                for (Object o : jsonArray) {
                    JSONObject jsonObject = (JSONObject) o;
                    if (jsonObject.containsKey("异地库")) {
                        JSONArray jsonArray2 = jsonObject.getJSONArray("异地库");
                        JSONArray jsonArray3 = new JSONArray();
                        for (Object o1 : jsonArray2) {
                            JSONObject jsonObject1 = (JSONObject) o1;
                            if (jsonObject1.getString("kqmc").contains(ccsbtzjsmxVO.getSskdmc())) {
                                jsonArray3.add(jsonObject1);
                            }
                        }
                        jsonObject.put("异地库", jsonArray3);
                        jsonArray1.add(jsonObject);
                    } else {
                        // 获取orgName的value
                        String orgName = jsonObject.keySet().iterator().next();
                        JSONArray jsonArray2 = jsonObject.getJSONArray(orgName);
                        JSONArray jsonArray3 = new JSONArray();
                        for (Object o1 : jsonArray2) {
                            JSONObject jsonObject1 = (JSONObject) o1;
                            if (jsonObject1.getString("kqmc").contains(ccsbtzjsmxVO.getSskdmc())) {
                                jsonArray3.add(jsonObject1);
                            }
                        }
                        jsonObject.put(orgName, jsonArray3);
                        jsonArray1.add(jsonObject);
                    }
                }
                jsonArray = jsonArray1;
            }
            // 设备类型过滤
            if (StringUtils.isNotBlank(ccsbtzjsmxVO.getSblx())) {
                // 过滤掉不包含sblx的数据
                JSONArray jsonArray1 = new JSONArray();
                for (Object o : jsonArray) {
                    JSONObject jsonObject = (JSONObject) o;
                    if (jsonObject.containsKey("异地库")) {
                        JSONArray jsonArray2 = jsonObject.getJSONArray("异地库");
                        JSONArray jsonArray3 = new JSONArray();
                        for (Object o1 : jsonArray2) {
                            JSONObject jsonObject1 = (JSONObject) o1;
                            if (jsonObject1.getString("sblx").contains(ccsbtzjsmxVO.getSblx())) {
                                jsonArray3.add(jsonObject1);
                            }
                        }
                        jsonObject.put("异地库", jsonArray3);
                        jsonArray1.add(jsonObject);
                    } else {
                        // 获取orgName的value
                        String orgName = jsonObject.keySet().iterator().next();
                        JSONArray jsonArray2 = jsonObject.getJSONArray(orgName);
                        JSONArray jsonArray3 = new JSONArray();
                        for (Object o1 : jsonArray2) {
                            JSONObject jsonObject1 = (JSONObject) o1;
                            if (jsonObject1.getString("sblx").contains(ccsbtzjsmxVO.getSblx())) {
                                jsonArray3.add(jsonObject1);
                            }
                        }
                        jsonObject.put(orgName, jsonArray3);
                        jsonArray1.add(jsonObject);
                    }
                }
                jsonArray = jsonArray1;
            }
            // 设备器材类别过滤
            if (StringUtils.isNotBlank(ccsbtzjsmxVO.getSbyjlb())) {
                // 过滤掉不包含sblb的数据
                JSONArray jsonArray1 = new JSONArray();
                for (Object o : jsonArray) {
                    JSONObject jsonObject = (JSONObject) o;
                    if (jsonObject.containsKey("异地库")) {
                        JSONArray jsonArray2 = jsonObject.getJSONArray("异地库");
                        JSONArray jsonArray3 = new JSONArray();
                        for (Object o1 : jsonArray2) {
                            JSONObject jsonObject1 = (JSONObject) o1;
                            if (jsonObject1.getString("sblb").contains(ccsbtzjsmxVO.getSbyjlb())) {
                                jsonArray3.add(jsonObject1);
                            }
                        }
                        jsonObject.put("异地库", jsonArray3);
                        jsonArray1.add(jsonObject);
                    } else {
                        // 获取orgName的value
                        String orgName = jsonObject.keySet().iterator().next();
                        JSONArray jsonArray2 = jsonObject.getJSONArray(orgName);
                        JSONArray jsonArray3 = new JSONArray();
                        for (Object o1 : jsonArray2) {
                            JSONObject jsonObject1 = (JSONObject) o1;
                            if (jsonObject1.getString("sblb").contains(ccsbtzjsmxVO.getSbyjlb())) {
                                jsonArray3.add(jsonObject1);
                            }
                        }
                        jsonObject.put(orgName, jsonArray3);
                        jsonArray1.add(jsonObject);
                    }
                }
                jsonArray = jsonArray1;
            }
            // 设备器材名称过滤
            if (StringUtils.isNotBlank(ccsbtzjsmxVO.getSbmc())) {
                // 过滤掉不包含sbmc的数据
                JSONArray jsonArray1 = new JSONArray();
                for (Object o : jsonArray) {
                    JSONObject jsonObject = (JSONObject) o;
                    if (jsonObject.containsKey("异地库")) {
                        JSONArray jsonArray2 = jsonObject.getJSONArray("异地库");
                        JSONArray jsonArray3 = new JSONArray();
                        for (Object o1 : jsonArray2) {
                            JSONObject jsonObject1 = (JSONObject) o1;
                            if (jsonObject1.getString("sbmc").contains(ccsbtzjsmxVO.getSbmc())) {
                                jsonArray3.add(jsonObject1);
                            }
                        }
                        jsonObject.put("异地库", jsonArray3);
                        jsonArray1.add(jsonObject);
                    } else {
                        // 获取orgName的value
                        String orgName = jsonObject.keySet().iterator().next();
                        JSONArray jsonArray2 = jsonObject.getJSONArray(orgName);
                        JSONArray jsonArray3 = new JSONArray();
                        for (Object o1 : jsonArray2) {
                            JSONObject jsonObject1 = (JSONObject) o1;
                            if (jsonObject1.getString("sbmc").contains(ccsbtzjsmxVO.getSbmc())) {
                                jsonArray3.add(jsonObject1);
                            }
                        }
                        jsonObject.put(orgName, jsonArray3);
                        jsonArray1.add(jsonObject);
                    }
                }
                jsonArray = jsonArray1;
            }

            // 添加合计，是所有数据的合计
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("kqmc", "");
            jsonObject1.put("sblx", "");
            jsonObject1.put("sblb", "");
            jsonObject1.put("sbmc", "");
            // 购入数量遍历所有数据，相加
            Integer grsl = 0;
            // 金额遍历所有数据，相加
            BigDecimal jrje = BigDecimal.ZERO;
            for (Object o : jsonArray) {
                JSONObject jsonObject = (JSONObject) o;
                if (jsonObject.containsKey("异地库")) {
                    JSONArray jsonArray2 = jsonObject.getJSONArray("异地库");
                    for (Object o1 : jsonArray2) {
                        JSONObject jsonObject2 = (JSONObject) o1;
                        grsl += jsonObject2.getInteger("grsl") == null ? 0 : jsonObject2.getInteger("grsl");
                        jrje = jrje.add(jsonObject2.getBigDecimal("jrhj") == null ? BigDecimal.ZERO : jsonObject2.getBigDecimal("jrhj"));
                    }
                } else {
                    // 获取orgName的value
                    String orgName = jsonObject.keySet().iterator().next();
                    JSONArray jsonArray2 = jsonObject.getJSONArray(orgName);
                    for (Object o1 : jsonArray2) {
                        JSONObject jsonObject2 = (JSONObject) o1;
                        grsl += jsonObject2.getInteger("grsl") == null ? 0 : jsonObject2.getInteger("grsl");
                        jrje = jrje.add(jsonObject2.getBigDecimal("jrhj") == null ? BigDecimal.ZERO : jsonObject2.getBigDecimal("jrhj"));
                    }
                }
            }
            jsonObject1.put("grsl", grsl);
            jsonObject1.put("jrhj", formatJeNumber(jrje));
            jsonObject1.put("zt", "");
            jsonObject1.put("qrsj", null);
            JSONArray jsonArray1 = new JSONArray();
            jsonArray1.add(jsonObject1);
            JSONObject hjObject = new JSONObject();
            hjObject.put("合计", jsonArray1);
            jsonArray.add(hjObject);

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("data", jsonArray);
            return jsonObject;
        }
        return null;
    }

    @Override
    public JSONArray querySbqclb(String sblxCode) {
        List<String> sblbList = ccsbtzjsmxDao.querySbqclb(sblxCode);
        if (sblbList.size() > 0) {
            JSONArray jsonArray = new JSONArray();
            for (String s : sblbList) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("sblb", s);
                jsonArray.add(jsonObject);
            }
            return jsonArray;
        }
        return null;
    }

    // 根据当前企业的orgCode查询相关层级的OrgainzeVO
    public OrgainzeVO getOrganization(String orgCode, OrgainzeVO organization) {
        // 判断当前orgCode是否是当前企业的orgCode,如果是则返回
        if (organization.getOrgCode().equals(orgCode)) {
            return organization;
        } else {
            // 逐级遍历children
            List<OrgainzeVO> children = organization.getChildren();
            for (OrgainzeVO orgainzeVO : children) {
                OrgainzeVO result = getOrganization(orgCode, orgainzeVO);
                if (result != null) {
                    // 如果找到匹配的节点，返回该节点
                    return result;
                }
            }
            // 如果所有子节点都不匹配，返回null
            return null;
        }
    }

    // 递归获取OrgainzeVO以及他的所有子节点的orgName
    public List<String> getOrgNameList(OrgainzeVO organization) {
        List<String> orgNameList = new ArrayList<>();
        addOrgNames(organization, orgNameList);
        return orgNameList;
    }

    private void addOrgNames(OrgainzeVO organization, List<String> orgNameList) {
        orgNameList.add(organization.getOrgName());
        List<OrgainzeVO> children = organization.getChildren();
        for (OrgainzeVO orgainzeVO : children) {
            addOrgNames(orgainzeVO, orgNameList); // 直接将子节点的名称添加到同一个列表
        }
    }


    private String getYjsblb(Integer sbyjlb) {
        String yjsblb = "";
        if (sbyjlb != null) {
            OrganizationInfo organizationInfo = ccsbtzjsmxDao.getYjsblbByEnumid(sbyjlb.toString());
            if (null != organizationInfo) {
                if (organizationInfo.getParentid() == 5476 || organizationInfo.getParentid() == 5475) {
                    yjsblb = organizationInfo.getEnumname();
                } else {
                    yjsblb = getYjsblb(organizationInfo.getParentid());
                }
            }
        }
        return yjsblb;
    }

}
