Commit 45cdf98e0446d7c5144f1ab39077e9475ff83d64
1 parent
f4c97b60
用户设备提交
Showing
7 changed files
with
84 additions
and
0 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/vo/DeviceDeptTreeRespVO.java
| ... | ... | @@ -50,6 +50,17 @@ public class DeviceDeptTreeRespVO { |
| 50 | 50 | * 节点类型:1部门 3设备 |
| 51 | 51 | */ |
| 52 | 52 | private Integer nodeType; |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 节点类型为设备时,该值有值 | |
| 56 | + * 产品名称 | |
| 57 | + */ | |
| 58 | + private String productName; | |
| 59 | + /** | |
| 60 | + * 节点类型为设备时,该值有值 | |
| 61 | + * 产品编码 | |
| 62 | + */ | |
| 63 | + private String productCode; | |
| 53 | 64 | /** |
| 54 | 65 | * 子节点,和当前一样的结构 |
| 55 | 66 | */ | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/vo/DeviceUserSaveReqVO.java
| ... | ... | @@ -35,6 +35,9 @@ public class DeviceUserSaveReqVO { |
| 35 | 35 | |
| 36 | 36 | @Data |
| 37 | 37 | public static class DeviceInfoDO { |
| 38 | + | |
| 39 | + private String productCode; | |
| 40 | + | |
| 38 | 41 | @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") |
| 39 | 42 | private String productName; |
| 40 | 43 | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/dataobject/deviceuser/DeviceUserDO.java
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/deviceuser/DeviceUserServiceImpl.java
| ... | ... | @@ -51,6 +51,7 @@ public class DeviceUserServiceImpl implements DeviceUserService { |
| 51 | 51 | DeviceUserDO deviceUser = new DeviceUserDO(); |
| 52 | 52 | deviceUser.setDeviceNo(deviceInfo.getDeviceNo()); |
| 53 | 53 | deviceUser.setDeviceName(deviceInfo.getDeviceName()); |
| 54 | + deviceUser.setProductCode(deviceInfo.getProductCode()); | |
| 54 | 55 | deviceUser.setProductName(deviceInfo.getProductName()); |
| 55 | 56 | deviceUser.setCompanyId(createReqVO.getCompanyId()); |
| 56 | 57 | deviceUser.setDeptId(createReqVO.getDeptId()); | ... | ... |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptServiceImpl.java
| ... | ... | @@ -51,6 +51,7 @@ public class DeptServiceImpl implements DeptService { |
| 51 | 51 | @Resource |
| 52 | 52 | private AdminUserMapper userMapper; |
| 53 | 53 | |
| 54 | + | |
| 54 | 55 | @Override |
| 55 | 56 | @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, |
| 56 | 57 | allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 |
| ... | ... | @@ -318,6 +319,7 @@ public class DeptServiceImpl implements DeptService { |
| 318 | 319 | UserDO userDO = new UserDO(); |
| 319 | 320 | userDO.setUserId(adminUserDO.getId()); |
| 320 | 321 | userDO.setUsername(adminUserDO.getUsername()); |
| 322 | + userDO.setCompanyId(getParentDeptId(adminUserDO.getDeptId())); | |
| 321 | 323 | userDO.setDeptId(adminUserDO.getDeptId()); |
| 322 | 324 | userDOList.add(userDO); |
| 323 | 325 | } |
| ... | ... | @@ -336,4 +338,61 @@ public class DeptServiceImpl implements DeptService { |
| 336 | 338 | sql.lambda().eq(DeptDO::getDeleted, 0); |
| 337 | 339 | return deptMapper.selectList(sql); |
| 338 | 340 | } |
| 341 | + | |
| 342 | + @Override | |
| 343 | + public Long getParentDeptId(Long deptId) { | |
| 344 | + if (deptId == null) { | |
| 345 | + return null; | |
| 346 | + } | |
| 347 | + | |
| 348 | + DeptDO dept = getDept(deptId); | |
| 349 | + if (dept == null) { | |
| 350 | + return null; | |
| 351 | + } | |
| 352 | + | |
| 353 | + // 顶级部门ID (parentId=0) | |
| 354 | + if (dept.getParentId().equals(0L)) { | |
| 355 | + return dept.getId(); | |
| 356 | + } | |
| 357 | + | |
| 358 | + // 直接是二级部门 (parentId=100) | |
| 359 | + if (dept.getParentId().equals(100L)) { | |
| 360 | + return dept.getId(); | |
| 361 | + } | |
| 362 | + | |
| 363 | + // 递归查找父部门链中parentId=100的部门 | |
| 364 | + Long result = findParentDeptWithParentId(dept.getParentId(), 100L); | |
| 365 | + // 如果找不到parentId=100的部门,返回当前部门的id作为默认值 | |
| 366 | + return result != null ? result : dept.getParentId(); | |
| 367 | + } | |
| 368 | + | |
| 369 | + /** | |
| 370 | + * 递归查找父部门链中parentId等于目标值的部门ID | |
| 371 | + * @param currentDeptId 当前部门ID | |
| 372 | + * @param targetParentId 目标parentId | |
| 373 | + * @return 匹配的部门ID,无则返回null | |
| 374 | + */ | |
| 375 | + private Long findParentDeptWithParentId(Long currentDeptId, Long targetParentId) { | |
| 376 | + if (currentDeptId == null) { | |
| 377 | + return null; | |
| 378 | + } | |
| 379 | + | |
| 380 | + DeptDO dept = getDept(currentDeptId); | |
| 381 | + if (dept == null) { | |
| 382 | + return null; | |
| 383 | + } | |
| 384 | + | |
| 385 | + // 找到目标父部门 | |
| 386 | + if (dept.getParentId().equals(targetParentId)) { | |
| 387 | + return dept.getId(); | |
| 388 | + } | |
| 389 | + | |
| 390 | + // 达到顶级部门,停止递归 | |
| 391 | + if (dept.getParentId().equals(0L)) { | |
| 392 | + return dept.getId(); // 改为返回顶级部门ID,而不是null | |
| 393 | + } | |
| 394 | + | |
| 395 | + // 继续向上查找 | |
| 396 | + return findParentDeptWithParentId(dept.getParentId(), targetParentId); | |
| 397 | + } | |
| 339 | 398 | } | ... | ... |