From b30aa8fad2e48d8b7afa16d89517094bf102603a Mon Sep 17 00:00:00 2001
From: liyj <1003249715@qq.com>
Date: Mon, 09 Sep 2024 15:38:03 +0800
Subject: [PATCH] 1、新增纠纷类型js格式查询接口

---
 dyh-service/dyh-sys/src/main/java/cn/huge/module/kind/service/SyCauseService.java |   72 ++++++++++++++++++++++++++++++++++-
 1 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/kind/service/SyCauseService.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/kind/service/SyCauseService.java
index 3ff313d..27375bd 100644
--- a/dyh-service/dyh-sys/src/main/java/cn/huge/module/kind/service/SyCauseService.java
+++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/kind/service/SyCauseService.java
@@ -4,19 +4,23 @@
 import cn.huge.base.common.utils.DateUtils;
 import cn.huge.base.common.utils.IdUtils;
 import cn.huge.module.client.api.impl.UtilsClientImpl;
+import cn.huge.module.constant.BaseConsts;
 import cn.huge.module.kind.dao.mapper.SyCauseMapper;
+import cn.huge.module.kind.domain.dto.CauseSelectJSDTO;
 import cn.huge.module.kind.domain.po.SyCause;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.collect.Maps;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.annotation.PostConstruct;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -26,7 +30,7 @@
  * @Description 纠纷类型表业务逻辑处理
  * @company hugeinfo
  * @author liyj
- * @Time 2024-08-28 20:06:20
+ * @Time 2024-09-09 14:31:21
  * @version 1.0.0
  */
 @Slf4j
@@ -130,4 +134,66 @@
         }
     }
 
+    /**
+     * 查询js树形结构
+     * @return
+     */
+    public List<CauseSelectJSDTO> listSelectJS(){
+        try{
+            List<CauseSelectJSDTO> causeSelectJSDTOList = mapper.listSelectJS();
+            return this.createTree(causeSelectJSDTOList, null);
+        }catch (Exception e){
+            log.error("[SyCauseService.listSelectJS]调用失败,异常信息:"+e, e);
+            throw new ServiceException("SyCauseService.listSelectJS", e);
+        }
+    }
+
+    /**
+     * 创建某一级树形结构
+     * @param allList 所有集合
+     * @param firstId 某一级编号
+     * @return List
+     */
+    public List<CauseSelectJSDTO> createTree(List<CauseSelectJSDTO> allList, String firstId) {
+        List<CauseSelectJSDTO> firstMapList = new ArrayList<>();
+        for (CauseSelectJSDTO causeSelectJSDTO : allList) {
+            for (CauseSelectJSDTO currentParam : allList) {
+                if (currentParam.getValue().equals(causeSelectJSDTO.getParentId())) {
+                    addToMBean(currentParam, causeSelectJSDTO);
+                    break;
+                }
+            }
+        }
+        //取第一级节点
+        for (CauseSelectJSDTO causeSelectJSDTO : allList) {
+            if (StringUtils.isNotEmpty(firstId)) {
+                if (firstId.equals(causeSelectJSDTO.getValue())) {
+                    firstMapList.add(causeSelectJSDTO);
+                }
+            } else {
+                if (BaseConsts.ROOT.equals(causeSelectJSDTO.getParentId()) || StringUtils.isEmpty(causeSelectJSDTO.getParentId())) {
+                    firstMapList.add(causeSelectJSDTO);
+                }
+            }
+        }
+        return firstMapList;
+    }
+
+    /**
+     * 获取子级数组
+     * @param target  目标
+     * @param child 子级
+     */
+    public void addToMBean(CauseSelectJSDTO target, CauseSelectJSDTO child) {
+        List<CauseSelectJSDTO> childListObj = target.getChildren();
+        List<CauseSelectJSDTO> childList = null;
+        if (CollectionUtils.isEmpty(childListObj)) {
+            childList = new ArrayList();
+            target.setChildren(childList);
+        } else {
+            childList = childListObj;
+        }
+        childList.add(child);
+    }
+
 }

--
Gitblit v1.8.0