Commit a8c56be5 authored by 胡秀武's avatar 胡秀武

胡秀武:模型列表树导航树update

parent 19ee44e9
...@@ -2,10 +2,7 @@ package com.pms.ocp.common.utils; ...@@ -2,10 +2,7 @@ package com.pms.ocp.common.utils;
import com.pms.ocp.model.entity.TreeNode; import com.pms.ocp.model.entity.TreeNode;
import java.util.ArrayList; import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author huxiuwu * @author huxiuwu
...@@ -20,7 +17,7 @@ public class TreeUtils { ...@@ -20,7 +17,7 @@ public class TreeUtils {
List<T> treeList = new ArrayList<>(); List<T> treeList = new ArrayList<>();
for(T treeNode : treeNodes) { for(T treeNode : treeNodes) {
if (pid.equals(treeNode.getPid())) { if (pid.equals(treeNode.getpCode())) {
treeList.add(findChildren(treeNodes, treeNode)); treeList.add(findChildren(treeNodes, treeNode));
} }
} }
...@@ -33,7 +30,7 @@ public class TreeUtils { ...@@ -33,7 +30,7 @@ public class TreeUtils {
*/ */
private static <T extends TreeNode> T findChildren(List<T> treeNodes, T rootNode) { private static <T extends TreeNode> T findChildren(List<T> treeNodes, T rootNode) {
for(T treeNode : treeNodes) { for(T treeNode : treeNodes) {
if(rootNode.getId().equals(treeNode.getPid())) { if(rootNode.getCode().equals(treeNode.getpCode())) {
rootNode.getChildren().add(findChildren(treeNodes, treeNode)); rootNode.getChildren().add(findChildren(treeNodes, treeNode));
} }
} }
...@@ -47,18 +44,21 @@ public class TreeUtils { ...@@ -47,18 +44,21 @@ public class TreeUtils {
List<T> result = new ArrayList<>(); List<T> result = new ArrayList<>();
//list转map //list转map
Map<Long, T> nodeMap = new LinkedHashMap<>(treeNodes.size()); Map<String, T> nodeMap = new LinkedHashMap<>(treeNodes.size());
for(T treeNode : treeNodes){ for(T treeNode : treeNodes){
nodeMap.put(treeNode.getId(), treeNode); nodeMap.put(treeNode.getCode(), treeNode);
} }
for(T node : nodeMap.values()) { for(T node : nodeMap.values()) {
T parent = nodeMap.get(node.getPid()); T parent = nodeMap.get(node.getpCode());
if(parent != null && !(node.getId().equals(parent.getId()))){ if(parent != null && (node.getpCode().equals(parent.getCode()))
&& (!"".equals(node.getpCode())|| !"".equals(parent.getCode()))){
if (parent.getChildren() == null){
parent.setChildren(new LinkedList<>());
}
parent.getChildren().add(node); parent.getChildren().add(node);
continue; continue;
} }
result.add(node); result.add(node);
} }
......
...@@ -53,6 +53,16 @@ public class ModelBaseController { ...@@ -53,6 +53,16 @@ public class ModelBaseController {
@Autowired @Autowired
private ModelRelationService modelRelationService; private ModelRelationService modelRelationService;
/**
* 模型分类-查询
*
* @return
*/
// @ApiOperation("模型分类-查询")
// @GetMapping("/get/model/type")
// public ResponseVO getModelType() {
// return modelGroupService.getModelType();
// }
/** /**
* 模型-增加 * 模型-增加
...@@ -319,4 +329,10 @@ public class ModelBaseController { ...@@ -319,4 +329,10 @@ public class ModelBaseController {
return ResponseVO.ok(modelRelationService.deleteModelRelation(objId, modelCode)); return ResponseVO.ok(modelRelationService.deleteModelRelation(objId, modelCode));
} }
@ApiOperation("模型列表-导航树")
@GetMapping("/delete/model/modelListNavigation")
public ResponseVO modelListNavigation(@RequestParam(required = false) String searchCondition) {
return modelSubscribeService.modelListNavigation(searchCondition);
}
} }
...@@ -2,7 +2,11 @@ package com.pms.ocp.mapper; ...@@ -2,7 +2,11 @@ package com.pms.ocp.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pms.ocp.model.entity.ModelSubscribe; import com.pms.ocp.model.entity.ModelSubscribe;
import com.pms.ocp.model.entity.TreeNode;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* @Auther: wangjian * @Auther: wangjian
...@@ -12,4 +16,8 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -12,4 +16,8 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface ModelSubscribeMapper extends BaseMapper<ModelSubscribe> { public interface ModelSubscribeMapper extends BaseMapper<ModelSubscribe> {
List<TreeNode> selectOrganData();
List<TreeNode> selectModelAndModelGroup(@Param("searchCondition") String searchCondition);
} }
package com.pms.ocp.model.entity; package com.pms.ocp.model.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -9,43 +12,42 @@ import java.util.List; ...@@ -9,43 +12,42 @@ import java.util.List;
* @version 1.0 * @version 1.0
* @date 2022/3/8 17:53 * @date 2022/3/8 17:53
*/ */
public class TreeNode<T> implements Serializable { @Data
@ApiModel("树节点表")
public class TreeNode implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* 主键 * 主键
*/ */
private Long id;
@ApiModelProperty("编码")
private String code;
/** /**
* 上级ID * 上级ID
*/ */
private Long pid; @ApiModelProperty("父类编码")
/** private String pCode;
* 子节点列表
*/
private List<T> children = new ArrayList<>();
public Long getId() { @ApiModelProperty("名称")
return id; private String name;
}
public void setId(Long id) { @ApiModelProperty("公司编码")
this.id = id; private String companyCode;
}
public Long getPid() { @ApiModelProperty("子类")
return pid; private List<TreeNode> children;
}
public void setPid(Long pid) { @ApiModelProperty("子类")
this.pid = pid; private int belongLevel;
}
public List<T> getChildren() { public String getCode() {
return children; return code == null ? "":code;
} }
public String getpCode() {
public void setChildren(List<T> children) { return pCode == null ? "": pCode;
this.children = children; }
public String getCompanyCode() {
return companyCode == null ? "":companyCode;
} }
} }
...@@ -2,6 +2,7 @@ package com.pms.ocp.service; ...@@ -2,6 +2,7 @@ package com.pms.ocp.service;
import com.pms.ocp.model.dto.ModelSubscribeDTO; import com.pms.ocp.model.dto.ModelSubscribeDTO;
import com.pms.ocp.model.entity.ModelSubscribe; import com.pms.ocp.model.entity.ModelSubscribe;
import com.pms.ocp.model.vo.ResponseVO;
import java.util.List; import java.util.List;
...@@ -59,4 +60,7 @@ public interface ModelSubscribeService { ...@@ -59,4 +60,7 @@ public interface ModelSubscribeService {
* @return * @return
*/ */
ModelSubscribeDTO getModelSubscribe(String modelId); ModelSubscribeDTO getModelSubscribe(String modelId);
ResponseVO modelListNavigation(String searchCondition);
} }
package com.pms.ocp.service.impl; package com.pms.ocp.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pms.ocp.common.constants.CodeEnum;
import com.pms.ocp.common.utils.TreeUtils;
import com.pms.ocp.mapper.ModelSubscribeMapper; import com.pms.ocp.mapper.ModelSubscribeMapper;
import com.pms.ocp.model.dto.ModelSubscribeDTO; import com.pms.ocp.model.dto.ModelSubscribeDTO;
import com.pms.ocp.model.entity.ModelSubscribe; import com.pms.ocp.model.entity.ModelSubscribe;
import com.pms.ocp.model.entity.TreeNode;
import com.pms.ocp.model.vo.ResponseVO;
import com.pms.ocp.service.ModelSubscribeService; import com.pms.ocp.service.ModelSubscribeService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -11,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -11,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List; import java.util.List;
/** /**
...@@ -81,4 +87,38 @@ public class ModelSubscribeServiceImpl implements ModelSubscribeService { ...@@ -81,4 +87,38 @@ public class ModelSubscribeServiceImpl implements ModelSubscribeService {
public ModelSubscribeDTO getModelSubscribe(String modelId) { public ModelSubscribeDTO getModelSubscribe(String modelId) {
return null; return null;
} }
/**
* 服务列表导航树
* @author huxiuwu
* @date 2022/3/11
*
* @return pms.ocp.model.vo.ResponseVO
**/
@Override
public ResponseVO modelListNavigation(String searchCondition) {
//查询模型和模型属性表列表
List<TreeNode> modelProperList = modelSubscribeMapper.selectModelAndModelGroup(searchCondition);
if (CollectionUtil.isEmpty(modelProperList)){
return ResponseVO.error(CodeEnum.NO_DATA);
}
List<TreeNode> modelGroupList = TreeUtils.build(modelProperList);
//查询组织机构表
List<TreeNode> organList = modelSubscribeMapper.selectOrganData();
//将分类放入各自所属于的组织机构下
organList.forEach(org
->{
modelGroupList.forEach(group->{
if (org.getCompanyCode().equals(group.getCompanyCode())){
if(org.getChildren() == null){
org.setChildren(new LinkedList<>());
}
org.getChildren().add(group);
}
});
});
List<TreeNode> result = TreeUtils.build(organList);
return ResponseVO.ok(result);
}
} }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pms.ocp.mapper.ModelSubscribeMapper">
<resultMap id="modelAndModelGroupMap" type="com.pms.ocp.model.entity.TreeNode" >
<result column="model_group_code" property="code"/>
<result column="model_group_pcode" property="pCode"/>
<result column="group_company_code" property="companyCode"/>
<result column="model_group_name" property="name"/>
<result column="groupModelBelongLevel" property="belongLevel"/>
<collection property="children" ofType="com.pms.ocp.model.entity.TreeNode">
<result column="model_name" property="name"/>
<result column="model_code" property="code"/>
<result column="modelLevel" property="belongLevel"/>
</collection>
</resultMap>
<select id="selectModelAndModelGroup" parameterType="java.lang.String" resultMap="modelAndModelGroupMap">
select
2 AS groupModelBelongLevel,
3 AS modelLevel,
omg.model_group_pcode,
omg.group_company_code,
omg.model_group_name,
omg.model_group_code,
omb.model_name,
omb.model_code
from
ocp_model_group as omg
left join
ocp_model_base omb
on omg.model_group_code = omb.model_group_code
<if test="_parameter != null and _parameter != '' ">
where
model_name LIKE concat('%',#{searchCondition}::text ,'%')
</if>
</select>
<select id="selectOrganData" resultType="com.pms.ocp.model.entity.TreeNode">
select
1 AS belongLevel,
parent_id AS pCode,
org_name AS name ,
org_id AS code,
org_code AS companyCode
from
t_public_organization
where
trim(org_level) != ''
and
org_level::int4 &lt;= 4
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment