Ver código fonte

客户端导图循环问题、后台合同段树结构问题

liuyc 3 anos atrás
pai
commit
8d13b0ea03

+ 192 - 24
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/WbsTreeContractVO.java

@@ -1,40 +1,208 @@
 package org.springblade.manager.vo;
 
-
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import lombok.Data;
-import java.io.Serializable;
+import org.springblade.core.tool.node.INode;
+import org.springblade.core.tool.node.TreeNode;
+
+import java.util.ArrayList;
+import java.util.List;
 
 
 /**
- * wbs合同段树关系实体类
+ * WbsTreeContract树形结构VO
  *
  * @author liuyc
- * @since 2022-05-23
+ * @since 2022-08-02
  */
 @Data
-public class WbsTreeContractVO implements Serializable {
+public class WbsTreeContractVO implements INode<WbsTreeContractVO> {
     private static final long serialVersionUID = 1L;
 
-    /**
-     * 主键id
-     */
+    @JsonSerialize(using = ToStringSerializer.class)
     private Long id;
-    /**
-     * wbsId
-     */
-    private String wbsId;
-    /**
-     * 项目id
-     */
-    private String projectId;
-    /**
-     * 项目名称
-     */
-    private String projectName;
-    /**
-     * 合同id
-     */
-    private String contractId;
 
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long parentId;
+
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private List<WbsTreeContractVO> children;
+
+    private String title;
+    @JsonSerialize(
+            using = ToStringSerializer.class
+    )
+    private Long key;
+    @JsonSerialize(
+            using = ToStringSerializer.class
+    )
+    private Long value;
+
+    private Integer type;
+
+    private Integer wbsType;
+
+    private Integer deptCategory;
+
+    private String primaryKeyId;
+
+    private String partitionCode;
+
+    private String oldId;
+
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
+    private Boolean hasChildren;
+
+    public WbsTreeContractVO() {
+    }
+
+    @Override
+    public List<WbsTreeContractVO> getChildren() {
+        if (this.children == null) {
+            this.children = new ArrayList<>();
+        }
+        return this.children;
+    }
+
+    @Override
+    public Boolean getHasChildren() {
+        return hasChildren;
+    }
+
+    public Integer getDeptCategory() {
+        return deptCategory;
+    }
+
+    public void setDeptCategory(Integer deptCategory) {
+        this.deptCategory = deptCategory;
+    }
+
+    public Integer getWbsType() {
+        return wbsType;
+    }
+
+    public void setWbsType(Integer wbsType) {
+        this.wbsType = wbsType;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public String getTitle() {
+        return this.title;
+    }
+
+    public Long getKey() {
+        return this.key;
+    }
+
+    public Long getValue() {
+        return this.value;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public void setTitle(final String title) {
+        this.title = title;
+    }
+
+    public void setKey(final Long key) {
+        this.key = key;
+    }
+
+    public void setValue(final Long value) {
+        this.value = value;
+    }
+
+
+    @Override
+    public String toString() {
+        return "WbsTreeContractVO{" +
+                "id=" + id +
+                ", parentId=" + parentId +
+                ", children=" + children +
+                ", title='" + title + '\'' +
+                ", key=" + key +
+                ", value=" + value +
+                ", type=" + type +
+                ", wbsType=" + wbsType +
+                ", deptCategory=" + deptCategory +
+                ", primaryKeyId='" + primaryKeyId + '\'' +
+                ", partitionCode='" + partitionCode + '\'' +
+                ", oldId='" + oldId + '\'' +
+                ", hasChildren=" + hasChildren +
+                '}';
+    }
+
+    public boolean equals(final Object o) {
+        if (o == this) {
+            return true;
+        } else if (!(o instanceof TreeNode)) {
+            return false;
+        } else {
+            TreeNodeVO other = (TreeNodeVO) o;
+            if (!other.canEqual(this)) {
+                return false;
+            } else {
+                label47:
+                {
+                    Object this$key = this.getKey();
+                    Object other$key = other.getKey();
+                    if (this$key == null) {
+                        if (other$key == null) {
+                            break label47;
+                        }
+                    } else if (this$key.equals(other$key)) {
+                        break label47;
+                    }
+
+                    return false;
+                }
+
+                Object this$value = this.getValue();
+                Object other$value = other.getValue();
+                if (this$value == null) {
+                    if (other$value != null) {
+                        return false;
+                    }
+                } else if (!this$value.equals(other$value)) {
+                    return false;
+                }
+
+                Object this$title = this.getTitle();
+                Object other$title = other.getTitle();
+                if (this$title == null) {
+                    if (other$title != null) {
+                        return false;
+                    }
+                } else if (!this$title.equals(other$title)) {
+                    return false;
+                }
+
+                return true;
+            }
+        }
+    }
+
+    protected boolean canEqual(final Object other) {
+        return other instanceof TreeNode;
+    }
+
+    public int hashCode() {
+        boolean PRIME = true;
+        int result = 1;
+        Object $key = this.getKey();
+        result = result * 59 + ($key == null ? 43 : $key.hashCode());
+        Object $value = this.getValue();
+        result = result * 59 + ($value == null ? 43 : $value.hashCode());
+        Object $title = this.getTitle();
+        result = result * 59 + ($title == null ? 43 : $title.hashCode());
+        return result;
+    }
 
 }

+ 1 - 1
blade-service/blade-business/src/main/java/org/springblade/business/controller/InformationWriteQueryController.java

@@ -504,7 +504,7 @@ public class InformationWriteQueryController extends BladeController {
 			this.setRootNodeName(parentId, childList);
 			if(childList != null && childList.size() == 1){
 				//需要向下展开
-				this.foreachQueryChildNode(childList, childList.get(0).getContractIdRelation(), contractInfo.getContractType());
+				this.foreachQueryChildNode(childList, childList.get(0).getContractIdRelation(), 1);
 			}
 			if(StringUtils.isEmpty(contractIdRelation) && "0".equals(parentId)){
 				//给个顶点

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ContractInfoController.java

@@ -428,7 +428,7 @@ public class ContractInfoController extends BladeController {
             @ApiImplicitParam(name = "合同段id", value = "contractId", required = true)
     })
     public R tree(String wbsId, String projectId, String contractId) {
-        List<WbsTreeContractTreeVO> tree = contractInfoService.tree(wbsId, projectId, contractId);
+        List<WbsTreeContractVO> tree = contractInfoService.tree(wbsId, projectId, contractId);
         if (tree != null && tree.size() > 0) {
             return R.data(tree);
         }

+ 6 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ContractInfoMapper.java

@@ -71,6 +71,12 @@ public interface ContractInfoMapper extends BaseMapper<ContractInfo> {
                                      @Param("wbsType") Integer wbsType,
                                      @Param("parentId") String parentId);
 
+    List<WbsTreeContractVO> tree2(@Param("wbsId") String wbsId,
+                                  @Param("projectId") String projectId,
+                                  @Param("contractId") String contractId,
+                                  @Param("wbsType") Integer wbsType,
+                                  @Param("parentId") String parentId);
+
 
     List<WbsTreeContractVO3> selectLists(@Param("contractInfo") ContractInfo contractInfo, @Param("contractType") Integer contractType);
 

+ 51 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ContractInfoMapper.xml

@@ -63,6 +63,20 @@
         <result column="old_id" property="oldId"/>
     </resultMap>
 
+    <resultMap id="treeNodeResultMap2" type="org.springblade.manager.vo.WbsTreeContractVO">
+        <id column="id" property="id"/>
+        <result column="parentId" property="parentId"/>
+        <result column="title" property="title"/>
+        <result column="value" property="value"/>
+        <result column="key" property="key"/>
+        <result column="has_children" property="hasChildren"/>
+        <result column="type" property="type"/>
+        <result column="primaryKeyId" property="primaryKeyId"/>
+        <result column="wbsType" property="wbsType"/>
+        <result column="partition_code" property="partitionCode"/>
+        <result column="old_id" property="oldId"/>
+    </resultMap>
+
     <resultMap id="resultMap2" type="org.springblade.manager.vo.ContractInfoVO">
         <id column="id" property="id"/>
         <collection property="idList" ofType="org.springblade.manager.vo.WbsTreeContractVO3">
@@ -236,6 +250,43 @@
         ORDER BY sort
     </select>
 
+    <select id="tree2" resultMap="treeNodeResultMap2">
+        SELECT
+        d.p_key_id AS "primaryKeyId",
+        d.wbs_type AS "wbsType",
+        d.id,
+        d.parent_id AS "parentId",
+        IFNULL(if(length(trim(full_name)) > 0, full_name, dept_name),dept_name) AS title,
+        d.type AS "type",
+        d.dept_category AS "deptCategory",
+        d.id AS "value",
+        d.id AS "key",
+        partition_code,
+        old_id
+        FROM m_wbs_tree_contract d
+        WHERE
+        d.is_deleted = 0
+        AND d.status = 1
+        AND (major_data_type != 5 or major_data_type is null)
+        AND d.type = 1
+        <if test="wbsId!=null and wbsId!=''">
+            and wbs_id = #{wbsId}
+        </if>
+        <if test="projectId !=null and projectId!=''">
+            and project_id = #{projectId}
+        </if>
+        <if test="contractId!=null and contractId!=''">
+            and contract_id = #{contractId}
+        </if>
+        <if test="wbsType != null and wbsType != ''">
+            and wbs_type = #{wbsType}
+        </if>
+        <if test="parentId != null and parentId != ''">
+            and parent_id = #{parentId}
+        </if>
+        ORDER BY d.sort
+    </select>
+
     <select id="selectByCondition" resultMap="resultMap2">
         SELECT t.p_key_id             AS "pKeyId",
                t.contract_id          AS "contractId",

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IContractInfoService.java

@@ -59,7 +59,7 @@ public interface IContractInfoService extends BaseService<ContractInfo> {
 
     Boolean deleteFile(String url);
 
-    List<WbsTreeContractTreeVO> tree(String wbsId, String projectId, String contractId);
+    List<WbsTreeContractVO> tree(String wbsId, String projectId, String contractId);
 
     List<WbsTreeContractVO2> treeTwo(String projectId);
 

+ 30 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ContractInfoServiceImpl.java

@@ -136,8 +136,36 @@ public class ContractInfoServiceImpl
     }
 
     @Override
-    public List<WbsTreeContractTreeVO> tree(String wbsId, String projectId, String contractId) {
-        return ForestNodeMerger.merge(baseMapper.tree(wbsId, projectId, contractId, null, null));
+    public List<WbsTreeContractVO> tree(String wbsId, String projectId, String contractId) {
+
+        //方式1:数据量过大时格式异常
+        //return ForestNodeMerger.merge(baseMapper.tree(wbsId, projectId, contractId, null, null));
+
+        //方式2
+        List<WbsTreeContractVO> wbsTreeContractVOS = baseMapper.tree2(wbsId, projectId, contractId,null,null);
+        return buildWbsTreeByStream(wbsTreeContractVOS);
+    }
+
+    private List<WbsTreeContractVO> buildWbsTreeByStream(List<WbsTreeContractVO> wbsTreeVO2s) {
+        //根节点
+        List<WbsTreeContractVO> list = wbsTreeVO2s.stream().filter(f -> f.getParentId() == 0L).collect(Collectors.toList());
+        //子节点分组
+        Map<Long, List<WbsTreeContractVO>> map = wbsTreeVO2s.stream().collect(Collectors.groupingBy(WbsTreeContractVO::getParentId));
+        this.recursionFnTree(list, map);
+        return list;
+    }
+
+    private void recursionFnTree(List<WbsTreeContractVO> list, Map<Long, List<WbsTreeContractVO>> map) {
+        for (WbsTreeContractVO wbsTreeContractVO : list) {
+            List<WbsTreeContractVO> childrenList = map.get(wbsTreeContractVO.getId());
+            wbsTreeContractVO.setChildren(childrenList);
+            if (childrenList != null && childrenList.size() > 0) {
+                //存在子级
+                wbsTreeContractVO.setHasChildren(true);
+                //递归查询
+                recursionFnTree(childrenList, map);
+            }
+        }
     }
 
     @Override