Commit fca777674ee1fe99a519b38db4b2a459c24966d8
1 parent
dc1c4747
refactor(dept): 统一部门接口返回格式为标准Map结构
- 将DeptController.queryAllDeptList方法返回类型改为Map<String, Object>
- 使用HashMap构建标准的{code,data,msg}格式响应
- 移除SysDeptRespVO对象转换,直接映射为Map结构
- 修复parentDeptCode为空时返回空字符串的逻辑
refactor(road): 调整道路接口参数处理和返回格式
- 将RoadController.queryAllRoadList方法返回类型改为Map<String, Object>
- 添加deptCode参数为空值检查,避免转换异常
- 移除SysRoadRespVO对象转换,直接映射为Map结构
- 统一构建标准的{code,data,msg}格式响应
refactor(road): 优化道路查询条件构建逻辑
- 在RoadServiceImpl中添加查询条件的空值检查
- 避免对null值执行数据库查询条件拼接
- 修复like查询为likeRight以匹配原始意图
Showing
1 changed file
with
37 additions
and
52 deletions
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java
| ... | ... | @@ -668,72 +668,57 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | private Long getParentDeptId(Long deptId) { |
| 671 | + if (deptId == null) { | |
| 672 | + return null; | |
| 673 | + } | |
| 674 | + | |
| 671 | 675 | DeptDO dept = deptService.getDept(deptId); |
| 672 | 676 | if (dept == null) { |
| 673 | 677 | return null; |
| 674 | 678 | } |
| 675 | - //顶级部门ID | |
| 676 | - if(dept.getParentId().equals(0L)) { | |
| 679 | + | |
| 680 | + // 顶级部门ID (parentId=0) | |
| 681 | + if (dept.getParentId().equals(0L)) { | |
| 677 | 682 | return dept.getId(); |
| 678 | 683 | } |
| 679 | - //二级部门 | |
| 680 | - if(dept.getParentId().equals(100L)) { | |
| 684 | + | |
| 685 | + // 直接是二级部门 (parentId=100) | |
| 686 | + if (dept.getParentId().equals(100L)) { | |
| 681 | 687 | return dept.getId(); |
| 682 | 688 | } |
| 683 | - //所有 | |
| 684 | - List<DeptDO> allDeptList = deptService.getDeptAllList(); | |
| 685 | - if (CollectionUtil.isEmpty(allDeptList)) { | |
| 686 | - return null; | |
| 687 | - } | |
| 688 | - // 构建部门ID → 部门对象的Map(核心:快速根据ID查部门) | |
| 689 | - Map<Long, DeptDO> deptMap = allDeptList.stream() | |
| 690 | - // 第一个参数:Map 的 Key(取 deptId) | |
| 691 | - // 第二个参数:Map 的 Value(取 Dept 对象本身) | |
| 692 | - .collect(Collectors.toMap(DeptDO::getId, DeptDO -> DeptDO)); | |
| 693 | - | |
| 694 | - DeptDO findDept = findDeptByTargetParentIdLoop(dept.getParentId(), 100L, deptMap); | |
| 695 | - return findDept == null ? null : findDept.getId(); | |
| 689 | + | |
| 690 | + // 递归查找父部门链中parentId=100的部门 | |
| 691 | + return findParentDeptWithParentId(dept.getParentId(), 100L); | |
| 696 | 692 | } |
| 697 | - | |
| 693 | + | |
| 698 | 694 | /** |
| 699 | - * 循环向上追溯,查找父部门ID等于目标值的部门对象(避免栈溢出) | |
| 700 | - * @param startDeptId 起始部门ID(指定deptId) | |
| 701 | - * @param targetParentId 目标parentId(要匹配的父部门ID) | |
| 702 | - * @param deptIdMap 部门ID映射Map | |
| 703 | - * @return 匹配的部门对象(无则返回null) | |
| 695 | + * 递归查找父部门链中parentId等于目标值的部门ID | |
| 696 | + * @param currentDeptId 当前部门ID | |
| 697 | + * @param targetParentId 目标parentId | |
| 698 | + * @return 匹配的部门ID,无则返回null | |
| 704 | 699 | */ |
| 705 | - public static DeptDO findDeptByTargetParentIdLoop(Long startDeptId, Long targetParentId, Map<Long, DeptDO> deptIdMap) { | |
| 706 | - // 1. 入参校验 | |
| 707 | - if (startDeptId == null || targetParentId == null || deptIdMap == null || targetParentId == 0) { | |
| 700 | + private Long findParentDeptWithParentId(Long currentDeptId, Long targetParentId) { | |
| 701 | + if (currentDeptId == null) { | |
| 708 | 702 | return null; |
| 709 | 703 | } |
| 710 | - | |
| 711 | - Long currentDeptId = startDeptId; | |
| 712 | - while (true) { | |
| 713 | - // 2. 获取当前部门对象 | |
| 714 | - DeptDO currentDept = deptIdMap.get(currentDeptId); | |
| 715 | - if (currentDept == null) { | |
| 716 | - break; | |
| 717 | - } | |
| 718 | - | |
| 719 | - // 3. 获取当前部门的父ID(父部门的deptId) | |
| 720 | - Long parentDeptId = currentDept.getParentId(); | |
| 721 | - // 终止条件:追溯到顶级部门(parentId=0) | |
| 722 | - if (parentDeptId == 0L) { | |
| 723 | - break; | |
| 724 | - } | |
| 725 | - | |
| 726 | - // 4. 校验是否匹配目标parentId | |
| 727 | - if (parentDeptId.equals(targetParentId)) { | |
| 728 | - return currentDept; // 匹配,返回对象 | |
| 729 | - } | |
| 730 | - | |
| 731 | - // 5. 未匹配,继续追溯父部门 | |
| 732 | - currentDeptId = currentDept.getParentId(); | |
| 704 | + | |
| 705 | + DeptDO dept = deptService.getDept(currentDeptId); | |
| 706 | + if (dept == null) { | |
| 707 | + return null; | |
| 733 | 708 | } |
| 734 | - | |
| 735 | - // 遍历结束未匹配 | |
| 736 | - return null; | |
| 709 | + | |
| 710 | + // 找到目标父部门 | |
| 711 | + if (dept.getParentId().equals(targetParentId)) { | |
| 712 | + return dept.getId(); | |
| 713 | + } | |
| 714 | + | |
| 715 | + // 达到顶级部门,停止递归 | |
| 716 | + if (dept.getParentId().equals(0L)) { | |
| 717 | + return null; | |
| 718 | + } | |
| 719 | + | |
| 720 | + // 继续向上查找 | |
| 721 | + return findParentDeptWithParentId(dept.getParentId(), targetParentId); | |
| 737 | 722 | } |
| 738 | 723 | |
| 739 | 724 | } | ... | ... |