diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java index d5a2cac..2afb508 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java @@ -5,6 +5,7 @@ import com.zteits.urbanops.framework.common.pojo.CommonResult; import com.zteits.urbanops.framework.common.pojo.PageParam; import com.zteits.urbanops.framework.common.pojo.PageResult; import com.zteits.urbanops.framework.common.util.object.BeanUtils; +import com.zteits.urbanops.framework.datapermission.core.annotation.DataPermission; import com.zteits.urbanops.framework.datapermission.core.util.DataPermissionUtils; import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; @@ -40,6 +41,7 @@ import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RA @RequestMapping("/garden/inspection-plan") @Validated @Slf4j +@DataPermission(enable = false) public class InspectionPlanController { @Resource diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java index 9b42aa2..225d92c 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java @@ -5,6 +5,7 @@ import com.zteits.urbanops.framework.common.pojo.CommonResult; import com.zteits.urbanops.framework.common.pojo.PageParam; import com.zteits.urbanops.framework.common.pojo.PageResult; import com.zteits.urbanops.framework.common.util.object.BeanUtils; +import com.zteits.urbanops.framework.datapermission.core.annotation.DataPermission; import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; import com.zteits.urbanops.module.garden.controller.admin.maintainplan.vo.MaintainPlanPageReqVO; @@ -39,6 +40,7 @@ import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RA @RequestMapping("/garden/maintain-plan") @Validated @Slf4j +@DataPermission(enable = false) public class MaintainPlanController { @Resource diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java index 13ec0d0..ab684d6 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.zteits.urbanops.framework.common.pojo.CommonResult; import com.zteits.urbanops.framework.common.pojo.PageResult; import com.zteits.urbanops.framework.common.util.object.BeanUtils; +import com.zteits.urbanops.framework.datapermission.core.annotation.DataPermission; import com.zteits.urbanops.framework.dict.core.DictFrameworkUtils; import com.zteits.urbanops.framework.mybatis.core.util.MyBatisUtils; import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; @@ -296,6 +297,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { * * @param list 分页对象 */ + private void addDataInspectionPlan(List list) { if (CollectionUtils.isEmpty(list)) { return; diff --git a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java index 95610df..45973ba 100644 --- a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java +++ b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java @@ -152,4 +152,10 @@ public interface DeptService { * @return 部门树 */ List getDeptAndUserTree(); + + /** + * 查询所有部门信息 + * @return + */ + List getDeptAllList(); } diff --git a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptServiceImpl.java b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptServiceImpl.java index 05a226c..3bbcabe 100644 --- a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptServiceImpl.java +++ b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptServiceImpl.java @@ -329,4 +329,11 @@ public class DeptServiceImpl implements DeptService { } return TreeUtils.getTreeList(deptListT); } + + @Override + public List getDeptAllList() { + QueryWrapper sql = new QueryWrapper<>(); + sql.lambda().eq(DeptDO::getDeleted, 0); + return deptMapper.selectList(sql); + } } diff --git a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java index 399b2a0..3d93326 100644 --- a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java +++ b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java @@ -668,72 +668,59 @@ public class AdminUserServiceImpl implements AdminUserService { } private Long getParentDeptId(Long deptId) { + if (deptId == null) { + return null; + } + DeptDO dept = deptService.getDept(deptId); if (dept == null) { return null; } - //顶级部门ID - if(dept.getParentId().equals(0L)) { + + // 顶级部门ID (parentId=0) + if (dept.getParentId().equals(0L)) { return dept.getId(); } - //二级部门 - if(dept.getParentId().equals(100L)) { + + // 直接是二级部门 (parentId=100) + if (dept.getParentId().equals(100L)) { return dept.getId(); } - //一级以下查二级 - List allDeptList = deptService.getSubDeptAllList(); - if (CollectionUtil.isEmpty(allDeptList)) { - return null; - } - // 构建部门ID → 部门对象的Map(核心:快速根据ID查部门) - Map deptMap = allDeptList.stream() - // 第一个参数:Map 的 Key(取 deptId) - // 第二个参数:Map 的 Value(取 Dept 对象本身) - .collect(Collectors.toMap(DeptDO::getId, DeptDO -> DeptDO)); - - DeptDO findDept = findDeptByTargetParentIdLoop(dept.getParentId(), 100L, deptMap); - return findDept == null ? null : findDept.getId(); + + // 递归查找父部门链中parentId=100的部门 + Long result = findParentDeptWithParentId(dept.getParentId(), 100L); + // 如果找不到parentId=100的部门,返回当前部门的id作为默认值 + return result != null ? result : dept.getParentId(); } - + /** - * 循环向上追溯,查找父部门ID等于目标值的部门对象(避免栈溢出) - * @param startDeptId 起始部门ID(指定deptId) - * @param targetParentId 目标parentId(要匹配的父部门ID) - * @param deptIdMap 部门ID映射Map - * @return 匹配的部门对象(无则返回null) + * 递归查找父部门链中parentId等于目标值的部门ID + * @param currentDeptId 当前部门ID + * @param targetParentId 目标parentId + * @return 匹配的部门ID,无则返回null */ - public static DeptDO findDeptByTargetParentIdLoop(Long startDeptId, Long targetParentId, Map deptIdMap) { - // 1. 入参校验 - if (startDeptId == null || targetParentId == null || deptIdMap == null || targetParentId == 0) { + private Long findParentDeptWithParentId(Long currentDeptId, Long targetParentId) { + if (currentDeptId == null) { return null; } - - Long currentDeptId = startDeptId; - while (true) { - // 2. 获取当前部门对象 - DeptDO currentDept = deptIdMap.get(currentDeptId); - if (currentDept == null) { - break; - } - - // 3. 获取当前部门的父ID(父部门的deptId) - Long parentDeptId = currentDept.getParentId(); - // 终止条件:追溯到顶级部门(parentId=0) - if (parentDeptId == 0L) { - break; - } - - // 4. 校验是否匹配目标parentId - if (parentDeptId.equals(targetParentId)) { - return currentDept; // 匹配,返回对象 - } - - // 5. 未匹配,继续追溯父部门 - currentDeptId = currentDept.getParentId(); + + DeptDO dept = deptService.getDept(currentDeptId); + if (dept == null) { + return null; } - - // 遍历结束未匹配 - return null; + + // 找到目标父部门 + if (dept.getParentId().equals(targetParentId)) { + return dept.getId(); + } + + // 达到顶级部门,停止递归 + if (dept.getParentId().equals(0L)) { + return dept.getId(); // 改为返回顶级部门ID,而不是null + } + + // 继续向上查找 + return findParentDeptWithParentId(dept.getParentId(), targetParentId); } } diff --git a/urbanops-server/src/main/resources/application.yaml b/urbanops-server/src/main/resources/application.yaml index d67b2e4..2cfeef0 100644 --- a/urbanops-server/src/main/resources/application.yaml +++ b/urbanops-server/src/main/resources/application.yaml @@ -3,7 +3,7 @@ spring: name: urbanops-server profiles: - active: dev + active: prod main: allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。