src/main/java/org/springblade/modules/system/controller/DeptController.java
@@ -145,8 +145,8 @@ * @return */ @GetMapping("/lazy-tree-users") public R<List<TreeNodes>> lazyTreeUsers(String tenantId, Long parentId, BladeUser bladeUser) { List<TreeNodes> tree = deptService.lazyTreeUsers(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()), parentId); public R<List<TreeNodes>> lazyTreeUsers(Integer type,Long deptId) { List<TreeNodes> tree = deptService.lazyTreeUsers(type,deptId); return R.data(tree); } src/main/java/org/springblade/modules/system/mapper/DeptMapper.java
@@ -117,5 +117,26 @@ */ @MapKey(value = "id") @SqlParser(filter=true) Map<Long, TreeNodes> lazyTreeUsers(@Param("parentId") Long parentId); Map<Long, TreeNodes> lazyTreeUsers(@Param("type") Integer type, @Param("deptId") Long deptId, @Param("jurisdiction")String jurisdiction); /** * 懒加载获取部门树形结构(包含用户数据),只查下一级的数据 * @return */ @MapKey(value = "id") @SqlParser(filter=true) Map<Long, TreeNodes> lazyTreeUsersPublicSecurity(@Param("type") Integer type, @Param("deptId") Long deptId, @Param("jurisdiction")String jurisdiction); /** * 懒加载获取部门树形结构(包含用户数据),只查下一级的数据 * @return */ @MapKey(value = "id") @SqlParser(filter=true) Map<Long, TreeNodes> lazyTreeUsersPublicSecuritys(@Param("type") Integer type, @Param("deptId") Long deptId, @Param("jurisdiction")String jurisdiction); } src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
@@ -328,11 +328,17 @@ ) AS "has_children" FROM blade_dept dept left join sys_information si on si.departmentid = dept.id WHERE dept.is_deleted = 0 <if test="parentId!=null and parentId!='' or parentId==0"> <if test="type==1"> and dept_category=1 AND dept.parent_id = #{parentId} </if> <if test="deptId!=null and deptId!=''"> and dept.id = #{deptId} </if> ) @@ -352,9 +358,133 @@ bd.id = bu.dept_id where 1=1 and bu.is_deleted = 0 <if test="parentId!=null and parentId!='' or parentId==0"> <if test="type==1"> and dept_category=1 AND bu.dept_id = #{parentId} </if> <if test="type==2 or type==3"> and dept_category=2 </if> <if test="deptId!=null and deptId!=''"> and bu.dept_id = #{deptId} </if> <if test="jurisdiction!=null and jurisdiction!=''"> and bu.jurisdiction = #{jurisdiction} </if> ) )c </select> <!--懒加载获取部门树形结构(包含用户数据)--> <select id="lazyTreeUsersPublicSecurity" resultType="org.springblade.modules.system.node.TreeNodes" > select DISTINCT * from ( (SELECT dept.id, dept.parent_id parentId, dept.dept_name AS title, dept.id AS "value", dept.id AS "key", ( SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM blade_dept WHERE parent_id = dept.id and is_deleted = 0 ) AS "has_children" FROM blade_dept dept left join sys_information si on si.departmentid = dept.id WHERE dept.is_deleted = 0 <if test="type==2 or type==3"> and dept_category=2 </if> <if test="deptId!=null and deptId!=''"> and (dept.parent_id = #{deptId} or dept.id = #{deptId}) </if> ) union (select bu.id, bu.dept_id parentId, bu.real_name AS title, bu.id AS "value", bu.id AS "key", 0 as "has_children" from blade_user bu left join blade_dept bd on bd.id = bu.dept_id where 1=1 and bu.is_deleted = 0 <if test="type==2 or type==3"> and dept_category=2 </if> <if test="deptId!=null and deptId!=''"> and (bd.parent_id = #{deptId} or bd.id = #{deptId}) </if> ) )c </select> <!--懒加载获取部门树形结构(包含用户数据)--> <select id="lazyTreeUsersPublicSecuritys" resultType="org.springblade.modules.system.node.TreeNodes" > select DISTINCT * from ( (SELECT dept.id, dept.parent_id parentId, dept.dept_name AS title, dept.id AS "value", dept.id AS "key", ( SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM blade_dept WHERE parent_id = dept.id and is_deleted = 0 ) AS "has_children" FROM blade_dept dept left join sys_information si on si.departmentid = dept.id WHERE dept.is_deleted = 0 <if test="type==2 or type==3"> and dept_category=2 </if> ) union (select bu.id, bu.dept_id parentId, bu.real_name AS title, bu.id AS "value", bu.id AS "key", 0 as "has_children" from blade_user bu left join blade_dept bd on bd.id = bu.dept_id where 1=1 and bu.is_deleted = 0 <if test="type==2 or type==3"> and dept_category=2 </if> ) )c src/main/java/org/springblade/modules/system/service/IDeptService.java
@@ -156,5 +156,5 @@ * 懒加载获取部门树形结构(包含用户数据),只查下一级的数据 * @return */ List<TreeNodes> lazyTreeUsers(String tenantId, Long parentId); List<TreeNodes> lazyTreeUsers(Integer type,Long deptId); } src/main/java/org/springblade/modules/system/service/impl/DeptServiceImpl.java
@@ -19,13 +19,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.AllArgsConstructor; import org.springblade.common.cache.SysCache; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Condition; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.node.ForestNodeMerger; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringPool; import org.springblade.modules.information.entity.Information; import org.springblade.modules.information.service.IInformationService; import org.springblade.modules.jurisdiction.entity.Jurisdiction; import org.springblade.modules.jurisdiction.service.JurisdictionService; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.mapper.DeptMapper; import org.springblade.modules.system.node.TreeNode; @@ -36,6 +42,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -46,9 +53,14 @@ * @author Chill */ @Service @AllArgsConstructor public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService { private static final String TENANT_ID = "tenantId"; private static final String PARENT_ID = "parentId"; private final IInformationService iInformationService; private final JurisdictionService jurisdictionService; @Override public List<DeptVO> lazyList(String tenantId, Long parentId, Map<String, Object> param) { @@ -241,13 +253,40 @@ * @return */ @Override public List<TreeNodes> lazyTreeUsers(String tenantId, Long parentId) { Map<Long,TreeNodes> map = baseMapper.lazyTreeUsers(parentId); System.out.println("map = " + map.size()); public List<TreeNodes> lazyTreeUsers(Integer type,Long deptId) { Map<Long,TreeNodes> map = new HashMap<>(); //保安向保安汇报 if(type==1){ map = baseMapper.lazyTreeUsers(type,deptId,null); } //保安向民警汇报 if(type==2){ //查询当前保安所在的辖区 Information information = new Information(); information.setDepartmentid(deptId.toString()); Information one = iInformationService.getOne(Condition.getQueryWrapper(information)); if (null!=one) { //找辖区对应的组织机构id Jurisdiction jurisdiction = jurisdictionService.getById(one.getJurisdiction()); if (null != jurisdiction) { Dept dept = new Dept(); dept.setDeptName(jurisdiction.getDeptName()); Dept dept1 = this.getOne(Condition.getQueryWrapper(dept)); map = baseMapper.lazyTreeUsersPublicSecurity(type, dept1.getId(), one.getJurisdiction()); } } } //民警向民警汇报,需要南昌市及当前民警所在辖区的部门数据 if(type==3){ //当前取所有的民警数据 map = baseMapper.lazyTreeUsersPublicSecuritys(type,null,null); } List<TreeNodes> tree = new ArrayList<>(); map.forEach((id,treeNodes) ->{ if (map.containsKey(treeNodes.getParentId())){ map.get(treeNodes.getParentId()).getChildren().add(treeNodes); Map<Long, TreeNodes> finalMap = map; map.forEach((id, treeNodes) ->{ if (finalMap.containsKey(treeNodes.getParentId())){ finalMap.get(treeNodes.getParentId()).getChildren().add(treeNodes); }else { tree.add(treeNodes); }