Commit 795d49714340033adeb521082f69bde9254bd388

Authored by 王富生
1 parent e7f5653c

优化查询部门接口

urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java
@@ -93,7 +93,7 @@ public class InspectionPlanController { @@ -93,7 +93,7 @@ public class InspectionPlanController {
93 93
94 @DeleteMapping("/delete-stop-plan") 94 @DeleteMapping("/delete-stop-plan")
95 @Parameter(name = "batchNo", description = "批次号", required = true) 95 @Parameter(name = "batchNo", description = "批次号", required = true)
96 - @Operation(summary = "根据batch_no删除巡检计划汇总") 96 + @Operation(summary = "根据batch_no终止计划")
97 @PreAuthorize("@ss.hasPermission('garden:inspection-plan:delete')") 97 @PreAuthorize("@ss.hasPermission('garden:inspection-plan:delete')")
98 public CommonResult<Boolean> stopPlanInspectionPlan(@RequestParam("batch_no") @NotBlank String batchNo) { 98 public CommonResult<Boolean> stopPlanInspectionPlan(@RequestParam("batch_no") @NotBlank String batchNo) {
99 inspectionPlanService.stopPlanInspectionPlan(batchNo); 99 inspectionPlanService.stopPlanInspectionPlan(batchNo);
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/oauth2/OAuth2TokenServiceImpl.java
@@ -184,7 +184,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { @@ -184,7 +184,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
184 AdminUserDO user = adminUserService.getUser(userId); 184 AdminUserDO user = adminUserService.getUser(userId);
185 OAuth2RefreshTokenDO refreshToken = new OAuth2RefreshTokenDO().setRefreshToken(generateRefreshToken()) 185 OAuth2RefreshTokenDO refreshToken = new OAuth2RefreshTokenDO().setRefreshToken(generateRefreshToken())
186 .setUserId(userId).setUserType(userType) 186 .setUserId(userId).setUserType(userType)
187 - .setCompanyId(getParentDeptId(user.getDeptId())) 187 + .setCompanyId(user.getCompanyId())
188 .setBusiLine(user.getBusiLine()) 188 .setBusiLine(user.getBusiLine())
189 .setClientId(clientDO.getClientId()).setScopes(scopes) 189 .setClientId(clientDO.getClientId()).setScopes(scopes)
190 .setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getRefreshTokenValiditySeconds())); 190 .setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getRefreshTokenValiditySeconds()));
@@ -192,75 +192,6 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { @@ -192,75 +192,6 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
192 return refreshToken; 192 return refreshToken;
193 } 193 }
194 194
195 - private Long getParentDeptId(Long deptId) {  
196 - DeptDO dept = deptService.getDept(deptId);  
197 - if (dept == null) {  
198 - return null;  
199 - }  
200 - //顶级部门ID  
201 - if(dept.getParentId().equals(0L)) {  
202 - return dept.getId();  
203 - }  
204 - //二级部门  
205 - if(dept.getParentId().equals(100L)) {  
206 - return dept.getId();  
207 - }  
208 - //一级以下查二级  
209 - List<DeptDO> allDeptList = deptService.getSubDeptAllList();  
210 - if (CollectionUtil.isEmpty(allDeptList)) {  
211 - return null;  
212 - }  
213 - // 构建部门ID → 部门对象的Map(核心:快速根据ID查部门)  
214 - Map<Long, DeptDO> deptMap = allDeptList.stream()  
215 - // 第一个参数:Map 的 Key(取 deptId)  
216 - // 第二个参数:Map 的 Value(取 Dept 对象本身)  
217 - .collect(Collectors.toMap(DeptDO::getId, DeptDO -> DeptDO));  
218 -  
219 - DeptDO findDept = findDeptByTargetParentIdLoop(dept.getParentId(), 100L, deptMap);  
220 - return findDept == null ? null : findDept.getId();  
221 - }  
222 -  
223 - /**  
224 - * 循环向上追溯,查找父部门ID等于目标值的部门对象(避免栈溢出)  
225 - * @param startDeptId 起始部门ID(指定deptId)  
226 - * @param targetParentId 目标parentId(要匹配的父部门ID)  
227 - * @param deptIdMap 部门ID映射Map  
228 - * @return 匹配的部门对象(无则返回null)  
229 - */  
230 - public static DeptDO findDeptByTargetParentIdLoop(Long startDeptId, Long targetParentId, Map<Long, DeptDO> deptIdMap) {  
231 - // 1. 入参校验  
232 - if (startDeptId == null || targetParentId == null || deptIdMap == null || targetParentId == 0) {  
233 - return null;  
234 - }  
235 -  
236 - Long currentDeptId = startDeptId;  
237 - while (true) {  
238 - // 2. 获取当前部门对象  
239 - DeptDO currentDept = deptIdMap.get(currentDeptId);  
240 - if (currentDept == null) {  
241 - break;  
242 - }  
243 -  
244 - // 3. 获取当前部门的父ID(父部门的deptId)  
245 - Long parentDeptId = currentDept.getParentId();  
246 - // 终止条件:追溯到顶级部门(parentId=0)  
247 - if (parentDeptId == 0L) {  
248 - break;  
249 - }  
250 -  
251 - // 4. 校验是否匹配目标parentId  
252 - if (parentDeptId.equals(targetParentId)) {  
253 - return currentDept; // 匹配,返回对象  
254 - }  
255 -  
256 - // 5. 未匹配,继续追溯父部门  
257 - currentDeptId = currentDept.getParentId();  
258 - }  
259 -  
260 - // 遍历结束未匹配  
261 - return null;  
262 - }  
263 -  
264 private OAuth2AccessTokenDO convertToAccessToken(OAuth2RefreshTokenDO refreshTokenDO) { 195 private OAuth2AccessTokenDO convertToAccessToken(OAuth2RefreshTokenDO refreshTokenDO) {
265 OAuth2AccessTokenDO accessTokenDO = BeanUtils.toBean(refreshTokenDO, OAuth2AccessTokenDO.class) 196 OAuth2AccessTokenDO accessTokenDO = BeanUtils.toBean(refreshTokenDO, OAuth2AccessTokenDO.class)
266 .setAccessToken(refreshTokenDO.getRefreshToken()); 197 .setAccessToken(refreshTokenDO.getRefreshToken());
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java
@@ -284,7 +284,11 @@ public class AdminUserServiceImpl implements AdminUserService { @@ -284,7 +284,11 @@ public class AdminUserServiceImpl implements AdminUserService {
284 284
285 @Override 285 @Override
286 public AdminUserDO getUser(Long id) { 286 public AdminUserDO getUser(Long id) {
287 - return userMapper.selectById(id); 287 + AdminUserDO adminUserDO = userMapper.selectById(id);
  288 + if (null != adminUserDO) {
  289 + adminUserDO.setCompanyId(getParentDeptId(adminUserDO.getDeptId()));
  290 + }
  291 + return adminUserDO;
288 } 292 }
289 293
290 @Override 294 @Override
@@ -531,4 +535,73 @@ public class AdminUserServiceImpl implements AdminUserService { @@ -531,4 +535,73 @@ public class AdminUserServiceImpl implements AdminUserService {
531 return passwordEncoder.encode(password); 535 return passwordEncoder.encode(password);
532 } 536 }
533 537
  538 + private Long getParentDeptId(Long deptId) {
  539 + DeptDO dept = deptService.getDept(deptId);
  540 + if (dept == null) {
  541 + return null;
  542 + }
  543 + //顶级部门ID
  544 + if(dept.getParentId().equals(0L)) {
  545 + return dept.getId();
  546 + }
  547 + //二级部门
  548 + if(dept.getParentId().equals(100L)) {
  549 + return dept.getId();
  550 + }
  551 + //一级以下查二级
  552 + List<DeptDO> allDeptList = deptService.getSubDeptAllList();
  553 + if (CollectionUtil.isEmpty(allDeptList)) {
  554 + return null;
  555 + }
  556 + // 构建部门ID → 部门对象的Map(核心:快速根据ID查部门)
  557 + Map<Long, DeptDO> deptMap = allDeptList.stream()
  558 + // 第一个参数:Map 的 Key(取 deptId)
  559 + // 第二个参数:Map 的 Value(取 Dept 对象本身)
  560 + .collect(Collectors.toMap(DeptDO::getId, DeptDO -> DeptDO));
  561 +
  562 + DeptDO findDept = findDeptByTargetParentIdLoop(dept.getParentId(), 100L, deptMap);
  563 + return findDept == null ? null : findDept.getId();
  564 + }
  565 +
  566 + /**
  567 + * 循环向上追溯,查找父部门ID等于目标值的部门对象(避免栈溢出)
  568 + * @param startDeptId 起始部门ID(指定deptId)
  569 + * @param targetParentId 目标parentId(要匹配的父部门ID)
  570 + * @param deptIdMap 部门ID映射Map
  571 + * @return 匹配的部门对象(无则返回null)
  572 + */
  573 + public static DeptDO findDeptByTargetParentIdLoop(Long startDeptId, Long targetParentId, Map<Long, DeptDO> deptIdMap) {
  574 + // 1. 入参校验
  575 + if (startDeptId == null || targetParentId == null || deptIdMap == null || targetParentId == 0) {
  576 + return null;
  577 + }
  578 +
  579 + Long currentDeptId = startDeptId;
  580 + while (true) {
  581 + // 2. 获取当前部门对象
  582 + DeptDO currentDept = deptIdMap.get(currentDeptId);
  583 + if (currentDept == null) {
  584 + break;
  585 + }
  586 +
  587 + // 3. 获取当前部门的父ID(父部门的deptId)
  588 + Long parentDeptId = currentDept.getParentId();
  589 + // 终止条件:追溯到顶级部门(parentId=0)
  590 + if (parentDeptId == 0L) {
  591 + break;
  592 + }
  593 +
  594 + // 4. 校验是否匹配目标parentId
  595 + if (parentDeptId.equals(targetParentId)) {
  596 + return currentDept; // 匹配,返回对象
  597 + }
  598 +
  599 + // 5. 未匹配,继续追溯父部门
  600 + currentDeptId = currentDept.getParentId();
  601 + }
  602 +
  603 + // 遍历结束未匹配
  604 + return null;
  605 + }
  606 +
534 } 607 }