Commit 1701fd6ac2d1e624fe51d346e0dfd72065d47572

Authored by wangqian
2 parents f4d685a4 c00f8782

Merge branch 'master' into dev

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;
5 5 import com.zteits.urbanops.framework.common.pojo.PageParam;
6 6 import com.zteits.urbanops.framework.common.pojo.PageResult;
7 7 import com.zteits.urbanops.framework.common.util.object.BeanUtils;
  8 +import com.zteits.urbanops.framework.datapermission.core.annotation.DataPermission;
8 9 import com.zteits.urbanops.framework.datapermission.core.util.DataPermissionUtils;
9 10 import com.zteits.urbanops.framework.excel.core.util.ExcelUtils;
10 11 import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils;
... ... @@ -40,6 +41,7 @@ import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RA
40 41 @RequestMapping("/garden/inspection-plan")
41 42 @Validated
42 43 @Slf4j
  44 +@DataPermission(enable = false)
43 45 public class InspectionPlanController {
44 46  
45 47 @Resource
... ...
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;
5 5 import com.zteits.urbanops.framework.common.pojo.PageParam;
6 6 import com.zteits.urbanops.framework.common.pojo.PageResult;
7 7 import com.zteits.urbanops.framework.common.util.object.BeanUtils;
  8 +import com.zteits.urbanops.framework.datapermission.core.annotation.DataPermission;
8 9 import com.zteits.urbanops.framework.excel.core.util.ExcelUtils;
9 10 import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils;
10 11 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
39 40 @RequestMapping("/garden/maintain-plan")
40 41 @Validated
41 42 @Slf4j
  43 +@DataPermission(enable = false)
42 44 public class MaintainPlanController {
43 45  
44 46 @Resource
... ...
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;
9 9 import com.zteits.urbanops.framework.common.pojo.CommonResult;
10 10 import com.zteits.urbanops.framework.common.pojo.PageResult;
11 11 import com.zteits.urbanops.framework.common.util.object.BeanUtils;
  12 +import com.zteits.urbanops.framework.datapermission.core.annotation.DataPermission;
12 13 import com.zteits.urbanops.framework.dict.core.DictFrameworkUtils;
13 14 import com.zteits.urbanops.framework.mybatis.core.util.MyBatisUtils;
14 15 import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils;
... ... @@ -296,6 +297,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
296 297 *
297 298 * @param list 分页对象
298 299 */
  300 +
299 301 private void addDataInspectionPlan(List<InspectionPlanRespVO> list) {
300 302 if (CollectionUtils.isEmpty(list)) {
301 303 return;
... ...
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java
... ... @@ -152,4 +152,10 @@ public interface DeptService {
152 152 * @return 部门树
153 153 */
154 154 List<Dept> getDeptAndUserTree();
  155 +
  156 + /**
  157 + * 查询所有部门信息
  158 + * @return
  159 + */
  160 + List<DeptDO> getDeptAllList();
155 161 }
... ...
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptServiceImpl.java
... ... @@ -329,4 +329,11 @@ public class DeptServiceImpl implements DeptService {
329 329 }
330 330 return TreeUtils.getTreeList(deptListT);
331 331 }
  332 +
  333 + @Override
  334 + public List<DeptDO> getDeptAllList() {
  335 + QueryWrapper<DeptDO> sql = new QueryWrapper<>();
  336 + sql.lambda().eq(DeptDO::getDeleted, 0);
  337 + return deptMapper.selectList(sql);
  338 + }
332 339 }
... ...
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java
... ... @@ -668,72 +668,59 @@ 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.getSubDeptAllList();
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 + Long result = findParentDeptWithParentId(dept.getParentId(), 100L);
  692 + // 如果找不到parentId=100的部门,返回当前部门的id作为默认值
  693 + return result != null ? result : dept.getParentId();
696 694 }
697   -
  695 +
698 696 /**
699   - * 循环向上追溯,查找父部门ID等于目标值的部门对象(避免栈溢出)
700   - * @param startDeptId 起始部门ID(指定deptId)
701   - * @param targetParentId 目标parentId(要匹配的父部门ID)
702   - * @param deptIdMap 部门ID映射Map
703   - * @return 匹配的部门对象(无则返回null)
  697 + * 递归查找父部门链中parentId等于目标值的部门ID
  698 + * @param currentDeptId 当前部门ID
  699 + * @param targetParentId 目标parentId
  700 + * @return 匹配的部门ID,无则返回null
704 701 */
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) {
  702 + private Long findParentDeptWithParentId(Long currentDeptId, Long targetParentId) {
  703 + if (currentDeptId == null) {
708 704 return null;
709 705 }
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();
  706 +
  707 + DeptDO dept = deptService.getDept(currentDeptId);
  708 + if (dept == null) {
  709 + return null;
733 710 }
734   -
735   - // 遍历结束未匹配
736   - return null;
  711 +
  712 + // 找到目标父部门
  713 + if (dept.getParentId().equals(targetParentId)) {
  714 + return dept.getId();
  715 + }
  716 +
  717 + // 达到顶级部门,停止递归
  718 + if (dept.getParentId().equals(0L)) {
  719 + return dept.getId(); // 改为返回顶级部门ID,而不是null
  720 + }
  721 +
  722 + // 继续向上查找
  723 + return findParentDeptWithParentId(dept.getParentId(), targetParentId);
737 724 }
738 725  
739 726 }
... ...
urbanops-server/src/main/resources/application.yaml
... ... @@ -3,7 +3,7 @@ spring:
3 3 name: urbanops-server
4 4  
5 5 profiles:
6   - active: dev
  6 + active: prod
7 7  
8 8 main:
9 9 allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
... ...