组织修改
This commit is contained in:
@@ -31,7 +31,7 @@ public class OrgController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/tree")
|
@PostMapping("/tree")
|
||||||
public ResponseResult tree(OrgQueryDto queryDto) {
|
public ResponseResult tree(@RequestBody @Validated OrgQueryDto queryDto) {
|
||||||
Long userId = StpUtil.getLoginIdAsLong();
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
return orgService.getTree(queryDto, userId);
|
return orgService.getTree(queryDto, userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public interface OrgMapper extends BaseMapper<Org> {
|
|||||||
List<Long> getCListByOrgId(Long pOrgId);
|
List<Long> getCListByOrgId(Long pOrgId);
|
||||||
|
|
||||||
List<OrgVo> getList(@Param("queryDto") OrgQueryDto queryDto);
|
List<OrgVo> getList(@Param("queryDto") OrgQueryDto queryDto);
|
||||||
|
|
||||||
|
List<OrgVo> getListAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -141,12 +141,11 @@ public class OrgServiceImpl extends ServiceImpl<OrgMapper, Org>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseResult getTree(OrgQueryDto queryDto, Long userId) {
|
public ResponseResult getTree(OrgQueryDto queryDto, Long userId) {
|
||||||
if( queryDto.getId() == null){
|
if(queryDto.getId() == null){
|
||||||
return ResponseResult.error("参数缺失");
|
return ResponseResult.error("参数缺失");
|
||||||
}
|
}
|
||||||
OrgQueryDto queryDto1 = new OrgQueryDto();
|
OrgQueryDto queryDto1 = new OrgQueryDto();
|
||||||
queryDto1.setId(queryDto.getId());
|
List<OrgVo> list = baseMapper.getListAll();
|
||||||
List<OrgVo> list = baseMapper.getList(queryDto1);
|
|
||||||
for (OrgVo orgVo : list){
|
for (OrgVo orgVo : list){
|
||||||
List<StandardCategory> standardCategorys = standardCategoryMapper.selectListByOrgId(orgVo.getId());
|
List<StandardCategory> standardCategorys = standardCategoryMapper.selectListByOrgId(orgVo.getId());
|
||||||
orgVo.setStandardCategorys(standardCategorys);
|
orgVo.setStandardCategorys(standardCategorys);
|
||||||
|
|||||||
@@ -24,9 +24,36 @@ public class TreeUtil {
|
|||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1.构建 ID -> Node 的映射(为了快速查找和组装)
|
||||||
|
Map<Object, T> nodeMap = list.stream()
|
||||||
|
.collect(Collectors.toMap(TreeNode::getId, node -> node, (a, b) -> a));
|
||||||
|
|
||||||
|
// 2.组装所有的父子关系(一次性组装整棵树)
|
||||||
|
// 这一步之后,map里的所有节点都已经包含了它的children
|
||||||
|
for (T node : list) {
|
||||||
|
T parent = nodeMap.get(node.getParentId());
|
||||||
|
if (parent != null) {
|
||||||
|
List<T> children = parent.getChildren();
|
||||||
|
if (children == null) {
|
||||||
|
children = new ArrayList<>();
|
||||||
|
parent.setChildren(children);
|
||||||
|
}
|
||||||
|
children.add(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3.根据 rootId 判断返回策略
|
||||||
|
|
||||||
|
// 情况 A: 找到了指定的节点(例如 rootId=100,且列表中有ID为100的节点)
|
||||||
|
if (rootId != null && nodeMap.containsKey(rootId)) {
|
||||||
|
T rootNode = nodeMap.get(rootId);
|
||||||
|
return Collections.singletonList(rootNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 情况 B: 没找到指定节点(例如 rootId=0 或 null,或者 ID 不在列表中)
|
||||||
|
// 这里退化为原逻辑:返回直属子节点
|
||||||
return list.stream()
|
return list.stream()
|
||||||
.filter(node -> Objects.equals(node.getParentId(), rootId))
|
.filter(node -> Objects.equals(node.getParentId(), rootId))
|
||||||
.peek(node -> node.setChildren(getChildren(node, list)))
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,24 +37,44 @@
|
|||||||
left join sys_org_laboratory_standard ol on o.id = ol.org_id
|
left join sys_org_laboratory_standard ol on o.id = ol.org_id
|
||||||
<where>
|
<where>
|
||||||
and o.is_deleted = 0
|
and o.is_deleted = 0
|
||||||
<if test="queryDto.id != null">
|
<if test="queryDto.id != null">
|
||||||
and o.id = #{queryDto.id}
|
and o.id = #{queryDto.id}
|
||||||
</if>
|
</if>
|
||||||
<if test="queryDto.name != null">
|
<if test="queryDto.name != null">
|
||||||
and o.name like concat('%',#{queryDto.name},'%')
|
and o.name like concat('%',#{queryDto.name},'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="queryDto.type != null">
|
<if test="queryDto.type != null">
|
||||||
and o.type = #{queryDto.type}
|
and o.type = #{queryDto.type}
|
||||||
</if>
|
</if>
|
||||||
<if test="queryDto.code != null">
|
<if test="queryDto.code != null">
|
||||||
and o.code like concat('%',#{queryDto.code},'%')
|
and o.code like concat('%',#{queryDto.code},'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="queryDto.remark != null">
|
<if test="queryDto.remark != null">
|
||||||
and o.remark like concat('%',#{queryDto.remark},'%')
|
and o.remark like concat('%',#{queryDto.remark},'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="queryDto.standardCategoryId != null">
|
<if test="queryDto.standardCategoryId != null">
|
||||||
and ol.standard_category_id = #{queryDto.standardCategoryId}
|
and ol.standard_category_id = #{queryDto.standardCategoryId}
|
||||||
</if>
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
<select id="getListAll" resultType="com.dc.dc_project.model.vo.OrgVo">
|
||||||
|
select
|
||||||
|
o.name as name,
|
||||||
|
o.code as code,
|
||||||
|
o.type as type,
|
||||||
|
o.sort_order as sortOrder,
|
||||||
|
o.remark as remark,
|
||||||
|
o.leader_id as leaderId,
|
||||||
|
p.name as leaderName,
|
||||||
|
o.parent_id as parentId,
|
||||||
|
o1.name as parentName,
|
||||||
|
o.id as id
|
||||||
|
from sys_org o
|
||||||
|
left join sys_personnel p on o.leader_id = p.id
|
||||||
|
left join sys_org o1 on o.parent_id = o1.id
|
||||||
|
left join sys_org_laboratory_standard ol on o.id = ol.org_id
|
||||||
|
<where>
|
||||||
|
and o.is_deleted = 0
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user