Commit a7160ef96c86aad0e7e7f7267d89b67c7de61e58

Authored by 戈灵虎
1 parent 4a1a8777

feat(dept): 添加部门子节点查询功能并优化园林模块数据权限配置

urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/framework/datapermission/config/TreeDataPermissionConfiguration.java
@@ -21,4 +21,4 @@ public class TreeDataPermissionConfiguration { @@ -21,4 +21,4 @@ public class TreeDataPermissionConfiguration {
21 }; 21 };
22 } 22 }
23 23
24 -}  
25 \ No newline at end of file 24 \ No newline at end of file
  25 +}
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/tree/TreeServiceImpl.java
@@ -11,6 +11,7 @@ import com.zteits.urbanops.module.garden.dal.mysql.treechangelog.TreeChangeLogMa @@ -11,6 +11,7 @@ import com.zteits.urbanops.module.garden.dal.mysql.treechangelog.TreeChangeLogMa
11 import com.zteits.urbanops.module.garden.service.road.RoadService; 11 import com.zteits.urbanops.module.garden.service.road.RoadService;
12 import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO; 12 import com.zteits.urbanops.module.system.dal.dataobject.dept.DeptDO;
13 import com.zteits.urbanops.module.system.dal.mysql.dept.DeptMapper; 13 import com.zteits.urbanops.module.system.dal.mysql.dept.DeptMapper;
  14 +import com.zteits.urbanops.module.system.service.dept.DeptService;
14 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.data.redis.core.RedisTemplate; 16 import org.springframework.data.redis.core.RedisTemplate;
16 import org.springframework.data.redis.core.StringRedisTemplate; 17 import org.springframework.data.redis.core.StringRedisTemplate;
@@ -61,7 +62,7 @@ public class TreeServiceImpl implements TreeService { @@ -61,7 +62,7 @@ public class TreeServiceImpl implements TreeService {
61 private RedisTemplate redisTemplate; 62 private RedisTemplate redisTemplate;
62 63
63 @Resource 64 @Resource
64 - private DeptMapper deptMapper; 65 + private DeptService deptService;
65 66
66 public static final String CACHE_REPEAT_KEY = "gardenTree:repeat:"; 67 public static final String CACHE_REPEAT_KEY = "gardenTree:repeat:";
67 68
@@ -178,80 +179,28 @@ public class TreeServiceImpl implements TreeService { @@ -178,80 +179,28 @@ public class TreeServiceImpl implements TreeService {
178 179
179 @Override 180 @Override
180 public List<CompanyDeptRoadVO> getCompanyDeptRoadTreeData(TreeVO tree) { 181 public List<CompanyDeptRoadVO> getCompanyDeptRoadTreeData(TreeVO tree) {
181 -// List<DeptDO> sysDepts = deptMapper.selectList(); 182 + List<DeptDO> companies = deptService.getSubDeptListAll();
  183 +
182 184
183 List<CompanyDeptRoadVO> companyDeptRoadVOS = treeMapper.selectCompanyDeptRoadTreeData(tree); 185 List<CompanyDeptRoadVO> companyDeptRoadVOS = treeMapper.selectCompanyDeptRoadTreeData(tree);
184 186
  187 + if (!CollectionUtils.isEmpty(companyDeptRoadVOS) && !CollectionUtils.isEmpty(companies)) {
  188 + Map<Long, String> companyNameMap = companies.stream()
  189 + .collect(Collectors.toMap(DeptDO::getId, DeptDO::getName, (a, b) -> a));
  190 + companyDeptRoadVOS.stream()
  191 + .filter(Objects::nonNull)
  192 + .forEach(vo -> {
  193 + Long cid = vo.getCompanyId();
  194 + if (cid == null) {
  195 + return;
  196 + }
  197 + String name = companyNameMap.get(cid);
  198 + if (StringUtils.hasText(name)) {
  199 + vo.setCompanyName(name);
  200 + }
  201 + });
  202 + }
185 203
186 -// // 按公司分组所有部门  
187 -// Map<Long, List<DeptDO>> companyDeptsMap = sysDepts.stream()  
188 -// .filter(d -> d.getParentId() != null)  
189 -// .collect(Collectors.groupingBy(DeptDO::getParentId));  
190 -//  
191 -// // 过滤出叶子部门(没有子部门的部门)  
192 -// Map<Long, List<DeptDO>> companyLeafDeptsMap = new HashMap<>();  
193 -// for (Map.Entry<Long, List<DeptDO>> entry : companyDeptsMap.entrySet()) {  
194 -// Long companyId = entry.getKey();  
195 -// List<DeptDO> depts = entry.getValue();  
196 -//  
197 -// // 构建部门ID到部门的映射  
198 -// Map<Long, DeptDO> deptMap = depts.stream()  
199 -// .collect(Collectors.toMap(DeptDO::getId, d -> d));  
200 -//  
201 -// // 找出叶子部门(其parentId不在deptMap中的部门,或者其parentId为0的部门)  
202 -// List<DeptDO> leafDepts = depts.stream()  
203 -// .filter(d -> d.getParentId() == 0 || !deptMap.containsKey(d.getParentId()))  
204 -// .collect(Collectors.toList());  
205 -//  
206 -// companyLeafDeptsMap.put(companyId, leafDepts);  
207 -// }  
208 -//  
209 -// // 建立现有结果的映射: 公司ID -> CompanyDeptRoadVO  
210 -// Map<Long, CompanyDeptRoadVO> existingCompanyMap = companyDeptRoadVOS.stream()  
211 -// .collect(Collectors.toMap(  
212 -// CompanyDeptRoadVO::getCompanyId,  
213 -// vo -> vo,  
214 -// (existing, replacement) -> existing  
215 -// ));  
216 -//  
217 -// // 遍历所有公司,补充缺失的公司和部门  
218 -// for (Map.Entry<Long, List<DeptDO>> entry : companyLeafDeptsMap.entrySet()) {  
219 -// Long companyId = entry.getKey();  
220 -// List<DeptDO> depts = entry.getValue();  
221 -//  
222 -// CompanyDeptRoadVO companyVO;  
223 -// if (!existingCompanyMap.containsKey(companyId)) {  
224 -// // 如果公司不存在,创建新的公司对象  
225 -// companyVO = new CompanyDeptRoadVO();  
226 -// companyVO.setCompanyId(companyId);  
227 -// companyVO.setCompanyName(DictFrameworkUtils.parseDictDataValue("belongCompanyId", companyId + ""));  
228 -// companyVO.setDepts(new ArrayList<>());  
229 -// companyDeptRoadVOS.add(companyVO);  
230 -// } else {  
231 -// companyVO = existingCompanyMap.get(companyId);  
232 -// }  
233 -//  
234 -// // 建立该公司下已存在的部门映射: 部门ID -> DeptVO  
235 -// Map<Long, CompanyDeptRoadVO.DeptVO> existingDeptMap = companyVO.getDepts().stream()  
236 -// .collect(Collectors.toMap(  
237 -// deptVO -> Long.valueOf(deptVO.getDeptId()),  
238 -// deptVO -> deptVO,  
239 -// (existing, replacement) -> existing  
240 -// ));  
241 -//  
242 -// // 补充缺失的部门(仅叶子部门)  
243 -// for (DeptDO sysDept : depts) {  
244 -// Long deptId = sysDept.getId();  
245 -// if (!existingDeptMap.containsKey(deptId)) {  
246 -// // 创建缺失的部门对象  
247 -// CompanyDeptRoadVO.DeptVO missingDept = new CompanyDeptRoadVO.DeptVO();  
248 -// missingDept.setDeptId(deptId);  
249 -// missingDept.setDeptName(sysDept.getName());  
250 -// missingDept.setRoads(new ArrayList<>());  
251 -// companyVO.getDepts().add(missingDept);  
252 -// }  
253 -// }  
254 -// }  
255 return companyDeptRoadVOS; 204 return companyDeptRoadVOS;
256 } 205 }
257 206
@@ -269,4 +218,4 @@ public class TreeServiceImpl implements TreeService { @@ -269,4 +218,4 @@ public class TreeServiceImpl implements TreeService {
269 return new PageResult<>(roadTreeVOS, treePage.getTotal()); 218 return new PageResult<>(roadTreeVOS, treePage.getTotal());
270 } 219 }
271 220
272 -}  
273 \ No newline at end of file 221 \ No newline at end of file
  222 +}
urbanops-module-garden/src/main/resources/mapper/tree/TreeMapper.xml
@@ -27,9 +27,7 @@ @@ -27,9 +27,7 @@
27 </resultMap> 27 </resultMap>
28 28
29 <select id="selectCompanyDeptRoadTreeData" resultMap="CompanyDeptRoadMap"> 29 <select id="selectCompanyDeptRoadTreeData" resultMap="CompanyDeptRoadMap">
30 - SELECT  
31 - c.id AS companyId,  
32 - c.name AS companyName, 30 + SELECT r.company_id AS companyId,
33 d.id AS deptId, 31 d.id AS deptId,
34 d.name AS deptName, 32 d.name AS deptName,
35 r.id AS roadId, 33 r.id AS roadId,
@@ -38,23 +36,14 @@ @@ -38,23 +36,14 @@
38 r.end_remark AS endRemark, 36 r.end_remark AS endRemark,
39 COALESCE(r.tree_area, 0) AS treeCount, 37 COALESCE(r.tree_area, 0) AS treeCount,
40 COUNT(t.id) AS recordedCount 38 COUNT(t.id) AS recordedCount
41 - FROM system_dept c  
42 - JOIN system_dept d ON d.parent_id = c.id AND d.status = 0  
43 - LEFT JOIN garden_road r ON d.id = r.dept_id  
44 - LEFT JOIN garden_tree t ON r.id = t.road AND t.deleted = 0  
45 - WHERE  
46 - c.status = 0 and c.parent_id = 100  
47 - <if test="belongCompanyId != null">  
48 - AND d.parent_id = #{belongCompanyId}  
49 - </if> 39 + FROM garden_tree t
  40 + LEFT JOIN garden_road r ON t.road = r.id
  41 + LEFT JOIN system_dept d ON r.dept_id = d.id AND d.status = 0
  42 + WHERE r.company_id = #{belongCompanyId}
50 <if test="roadName != null and roadName != ''"> 43 <if test="roadName != null and roadName != ''">
51 AND r.road_name LIKE CONCAT('%', #{roadName}, '%') 44 AND r.road_name LIKE CONCAT('%', #{roadName}, '%')
52 </if> 45 </if>
53 - <if test="deptId != null">  
54 - AND d.id = #{deptId}  
55 - </if>  
56 - GROUP BY c.id, c.name, d.id, d.name,  
57 - r.id, r.road_name, r.starting_remark, r.end_remark, r.tree_area 46 + GROUP BY r.company_id, d.id, d.name, r.id, r.road_name, r.starting_remark, r.end_remark, r.tree_area
58 ORDER BY treeCount DESC, recordedCount DESC 47 ORDER BY treeCount DESC, recordedCount DESC
59 </select> 48 </select>
60 </mapper> 49 </mapper>
61 \ No newline at end of file 50 \ No newline at end of file
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java
@@ -65,6 +65,7 @@ public interface DeptService { @@ -65,6 +65,7 @@ public interface DeptService {
65 * @return 部门信息数组 65 * @return 部门信息数组
66 */ 66 */
67 List<DeptDO> getSubDeptList(); 67 List<DeptDO> getSubDeptList();
  68 + List<DeptDO> getSubDeptListAll();
68 69
69 /** 70 /**
70 * 筛选部门列表 71 * 筛选部门列表
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptServiceImpl.java
@@ -206,6 +206,12 @@ public class DeptServiceImpl implements DeptService { @@ -206,6 +206,12 @@ public class DeptServiceImpl implements DeptService {
206 } 206 }
207 207
208 @Override 208 @Override
  209 + @DataPermission(enable = false)
  210 + public List<DeptDO> getSubDeptListAll() {
  211 + return deptMapper.selectList(DeptDO::getParentId, 100);
  212 + }
  213 +
  214 + @Override
209 public List<DeptDO> getDeptList(DeptListReqVO reqVO) { 215 public List<DeptDO> getDeptList(DeptListReqVO reqVO) {
210 List<DeptDO> list = deptMapper.selectList(reqVO); 216 List<DeptDO> list = deptMapper.selectList(reqVO);
211 list.sort(Comparator.comparing(DeptDO::getSort)); 217 list.sort(Comparator.comparing(DeptDO::getSort));