Commit 8d4a74f6fd2bb1018bdc03e92dccbdf266a0183a
Merge branch 'master' into dev
Showing
11 changed files
with
194 additions
and
21 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/DeviceUserController.java
| @@ -40,19 +40,26 @@ public class DeviceUserController { | @@ -40,19 +40,26 @@ public class DeviceUserController { | ||
| 40 | 40 | ||
| 41 | @PostMapping("/create") | 41 | @PostMapping("/create") |
| 42 | @Operation(summary = "创建设备用户关系") | 42 | @Operation(summary = "创建设备用户关系") |
| 43 | - @PreAuthorize("@ss.hasPermission('garden:device-user:create')") | 43 | + // @PreAuthorize("@ss.hasPermission('garden:device-user:create')") |
| 44 | public CommonResult<Long> createDeviceUser(@Valid @RequestBody DeviceUserSaveReqVO createReqVO) { | 44 | public CommonResult<Long> createDeviceUser(@Valid @RequestBody DeviceUserSaveReqVO createReqVO) { |
| 45 | return success(deviceUserService.createDeviceUser(createReqVO)); | 45 | return success(deviceUserService.createDeviceUser(createReqVO)); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | - @PutMapping("/update") | 48 | + @PutMapping("/update/device") |
| 49 | @Operation(summary = "更新设备用户关系") | 49 | @Operation(summary = "更新设备用户关系") |
| 50 | - @PreAuthorize("@ss.hasPermission('garden:device-user:update')") | ||
| 51 | - public CommonResult<Boolean> updateDeviceUser(@Valid @RequestBody DeviceUserSaveReqVO updateReqVO) { | ||
| 52 | - deviceUserService.updateDeviceUser(updateReqVO); | 50 | + //@PreAuthorize("@ss.hasPermission('garden:device-user:update')") |
| 51 | + public CommonResult<Boolean> updateDevice(@Valid @RequestBody DeviceUserUpdateReqVO updateReqVO) { | ||
| 52 | + deviceUserService.updateDevice(updateReqVO); | ||
| 53 | return success(true); | 53 | return success(true); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | + @GetMapping("/get/device_no") | ||
| 57 | + @Operation(summary = "通过设备编码获取设备绑定信息") | ||
| 58 | + public CommonResult<DeviceUserRespVO> getDeviceUserByDeviceNo(@RequestParam("device_no") @NotBlank String deviceNo) { | ||
| 59 | + DeviceUserRespVO deviceUser = deviceUserService.getDeviceUserByDeviceNo(deviceNo); | ||
| 60 | + return success(deviceUser); | ||
| 61 | + } | ||
| 62 | + | ||
| 56 | @DeleteMapping("/delete") | 63 | @DeleteMapping("/delete") |
| 57 | @Operation(summary = "删除设备用户关系") | 64 | @Operation(summary = "删除设备用户关系") |
| 58 | @Parameter(name = "id", description = "编号", required = true) | 65 | @Parameter(name = "id", description = "编号", required = true) |
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,6 +50,17 @@ public class DeviceDeptTreeRespVO { | ||
| 50 | * 节点类型:1部门 3设备 | 50 | * 节点类型:1部门 3设备 |
| 51 | */ | 51 | */ |
| 52 | private Integer nodeType; | 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,8 +35,10 @@ public class DeviceUserSaveReqVO { | @@ -35,8 +35,10 @@ public class DeviceUserSaveReqVO { | ||
| 35 | 35 | ||
| 36 | @Data | 36 | @Data |
| 37 | public static class DeviceInfoDO { | 37 | public static class DeviceInfoDO { |
| 38 | + | ||
| 39 | + private String productCode; | ||
| 40 | + | ||
| 38 | @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | 41 | @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") |
| 39 | - @NotEmpty(message = "产品名称不能为空") | ||
| 40 | private String productName; | 42 | private String productName; |
| 41 | 43 | ||
| 42 | @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED) | 44 | @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED) |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/deviceuser/vo/DeviceUserUpdateReqVO.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.Valid; | ||
| 5 | +import jakarta.validation.constraints.NotEmpty; | ||
| 6 | +import jakarta.validation.constraints.NotNull; | ||
| 7 | +import jakarta.validation.constraints.Size; | ||
| 8 | +import lombok.Data; | ||
| 9 | + | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +@Schema(description = "管理后台 - 设备用户关系新增/修改 Request VO") | ||
| 13 | +@Data | ||
| 14 | +public class DeviceUserUpdateReqVO { | ||
| 15 | + | ||
| 16 | + @Schema(description = "设备信息") | ||
| 17 | + @NotNull | ||
| 18 | + @Size(min = 1, message = "道路信息不能为空") | ||
| 19 | + @Valid | ||
| 20 | + private List<DeviceUserSaveReqVO.DeviceInfoDO> deviceInfoList; | ||
| 21 | + | ||
| 22 | + @Data | ||
| 23 | + public static class DeviceInfoDO { | ||
| 24 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | ||
| 25 | + @NotEmpty(message = "产品名称不能为空") | ||
| 26 | + private String productName; | ||
| 27 | + | ||
| 28 | + @Schema(description = "设备标识", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 29 | + @NotEmpty(message = "设备标识不能为空") | ||
| 30 | + private String deviceNo; | ||
| 31 | + | ||
| 32 | + @Schema(description = "设备名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | ||
| 33 | + @NotEmpty(message = "设备名称不能为空") | ||
| 34 | + private String deviceName; | ||
| 35 | + | ||
| 36 | + @Schema(description = "连接状态 : 在线:ONLINE || 离线:OFFLINE || 未连接:INIT", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 37 | + @NotEmpty(message = "连接状态 : 在线:ONLINE || 离线:OFFLINE || 未连接:INIT") | ||
| 38 | + private String deviceState; | ||
| 39 | + | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | +} | ||
| 0 | \ No newline at end of file | 43 | \ No newline at end of file |
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/DeviceUserService.java
| @@ -5,10 +5,6 @@ import jakarta.validation.*; | @@ -5,10 +5,6 @@ import jakarta.validation.*; | ||
| 5 | import com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo.*; | 5 | import com.zteits.urbanops.module.garden.controller.admin.deviceuser.vo.*; |
| 6 | import com.zteits.urbanops.module.garden.dal.dataobject.deviceuser.DeviceUserDO; | 6 | import com.zteits.urbanops.module.garden.dal.dataobject.deviceuser.DeviceUserDO; |
| 7 | import com.zteits.urbanops.framework.common.pojo.PageResult; | 7 | import com.zteits.urbanops.framework.common.pojo.PageResult; |
| 8 | -import com.zteits.urbanops.framework.common.pojo.PageParam; | ||
| 9 | -import jakarta.validation.constraints.NotNull; | ||
| 10 | -import org.springframework.web.bind.annotation.RequestBody; | ||
| 11 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 12 | 8 | ||
| 13 | /** | 9 | /** |
| 14 | * 设备用户关系 Service 接口 | 10 | * 设备用户关系 Service 接口 |
| @@ -78,4 +74,18 @@ public interface DeviceUserService { | @@ -78,4 +74,18 @@ public interface DeviceUserService { | ||
| 78 | */ | 74 | */ |
| 79 | DeviceDeptTreeRespVO findDeviceDeptTree(DeviceDeptTreeReqVO reqVO); | 75 | DeviceDeptTreeRespVO findDeviceDeptTree(DeviceDeptTreeReqVO reqVO); |
| 80 | 76 | ||
| 77 | + /** | ||
| 78 | + * IOT更新设备信息 | ||
| 79 | + * | ||
| 80 | + * @param updateReqVO 更新信息 | ||
| 81 | + * @return 更新结果 | ||
| 82 | + */ | ||
| 83 | + Boolean updateDevice(DeviceUserUpdateReqVO updateReqVO); | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 通过设备编码查询对象 | ||
| 87 | + * @return 设备用户关系树 | ||
| 88 | + */ | ||
| 89 | + DeviceUserRespVO getDeviceUserByDeviceNo(String deviceNo); | ||
| 90 | + | ||
| 81 | } | 91 | } |
| 82 | \ No newline at end of file | 92 | \ No newline at end of file |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/deviceuser/DeviceUserServiceImpl.java
| @@ -3,14 +3,16 @@ package com.zteits.urbanops.module.garden.service.deviceuser; | @@ -3,14 +3,16 @@ package com.zteits.urbanops.module.garden.service.deviceuser; | ||
| 3 | import cn.hutool.core.collection.CollectionUtil; | 3 | import cn.hutool.core.collection.CollectionUtil; |
| 4 | import com.alibaba.fastjson.JSONArray; | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 6 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
| 7 | +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | ||
| 6 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; | 8 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; |
| 7 | import com.zteits.urbanops.module.garden.util.DeviceDeptTreeUtils; | 9 | import com.zteits.urbanops.module.garden.util.DeviceDeptTreeUtils; |
| 8 | import com.zteits.urbanops.module.garden.util.http.OkHttpClientUtil; | 10 | import com.zteits.urbanops.module.garden.util.http.OkHttpClientUtil; |
| 9 | import org.springframework.beans.factory.annotation.Value; | 11 | import org.springframework.beans.factory.annotation.Value; |
| 10 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 11 | import jakarta.annotation.Resource; | 13 | import jakarta.annotation.Resource; |
| 14 | +import org.springframework.util.StringUtils; | ||
| 12 | import org.springframework.validation.annotation.Validated; | 15 | import org.springframework.validation.annotation.Validated; |
| 13 | -import org.springframework.transaction.annotation.Transactional; | ||
| 14 | 16 | ||
| 15 | import java.time.LocalDateTime; | 17 | import java.time.LocalDateTime; |
| 16 | import java.util.*; | 18 | import java.util.*; |
| @@ -49,20 +51,21 @@ public class DeviceUserServiceImpl implements DeviceUserService { | @@ -49,20 +51,21 @@ public class DeviceUserServiceImpl implements DeviceUserService { | ||
| 49 | DeviceUserDO deviceUser = new DeviceUserDO(); | 51 | DeviceUserDO deviceUser = new DeviceUserDO(); |
| 50 | deviceUser.setDeviceNo(deviceInfo.getDeviceNo()); | 52 | deviceUser.setDeviceNo(deviceInfo.getDeviceNo()); |
| 51 | deviceUser.setDeviceName(deviceInfo.getDeviceName()); | 53 | deviceUser.setDeviceName(deviceInfo.getDeviceName()); |
| 54 | + deviceUser.setProductCode(deviceInfo.getProductCode()); | ||
| 52 | deviceUser.setProductName(deviceInfo.getProductName()); | 55 | deviceUser.setProductName(deviceInfo.getProductName()); |
| 53 | deviceUser.setCompanyId(createReqVO.getCompanyId()); | 56 | deviceUser.setCompanyId(createReqVO.getCompanyId()); |
| 54 | deviceUser.setDeptId(createReqVO.getDeptId()); | 57 | deviceUser.setDeptId(createReqVO.getDeptId()); |
| 55 | deviceUser.setUserId(Long.parseLong(userId)); | 58 | deviceUser.setUserId(Long.parseLong(userId)); |
| 56 | deviceUser.setUserName(userName); | 59 | deviceUser.setUserName(userName); |
| 57 | - deviceUser.setCreateTime( now); | 60 | + deviceUser.setCreateTime(now); |
| 58 | deviceUser.setCreator(userId); | 61 | deviceUser.setCreator(userId); |
| 59 | deviceUser.setCreatorName(userName); | 62 | deviceUser.setCreatorName(userName); |
| 60 | deviceUser.setUpdater(userId); | 63 | deviceUser.setUpdater(userId); |
| 61 | - deviceUser.setUpdateTime( now); | 64 | + deviceUser.setUpdateTime(now); |
| 62 | list.add(deviceUser); | 65 | list.add(deviceUser); |
| 63 | }); | 66 | }); |
| 64 | // 插入 | 67 | // 插入 |
| 65 | - deviceUserMapper.insert( list); | 68 | + deviceUserMapper.insert(list); |
| 66 | return 1L; | 69 | return 1L; |
| 67 | } | 70 | } |
| 68 | 71 | ||
| @@ -84,10 +87,10 @@ public class DeviceUserServiceImpl implements DeviceUserService { | @@ -84,10 +87,10 @@ public class DeviceUserServiceImpl implements DeviceUserService { | ||
| 84 | } | 87 | } |
| 85 | 88 | ||
| 86 | @Override | 89 | @Override |
| 87 | - public void deleteDeviceUserListByIds(List<Long> ids) { | 90 | + public void deleteDeviceUserListByIds(List<Long> ids) { |
| 88 | // 删除 | 91 | // 删除 |
| 89 | deviceUserMapper.deleteByIds(ids); | 92 | deviceUserMapper.deleteByIds(ids); |
| 90 | - } | 93 | + } |
| 91 | 94 | ||
| 92 | 95 | ||
| 93 | private void validateDeviceUserExists(Long id) { | 96 | private void validateDeviceUserExists(Long id) { |
| @@ -118,19 +121,19 @@ public class DeviceUserServiceImpl implements DeviceUserService { | @@ -118,19 +121,19 @@ public class DeviceUserServiceImpl implements DeviceUserService { | ||
| 118 | params.put("deviceName", reqVO.getDeviceName()); | 121 | params.put("deviceName", reqVO.getDeviceName()); |
| 119 | params.put("deviceDeptName", reqVO.getDeviceDeptName()); | 122 | params.put("deviceDeptName", reqVO.getDeviceDeptName()); |
| 120 | String json = OkHttpClientUtil.doPostJson(iotHost + "/deviceApi/findDeviceDeptTree", params); | 123 | String json = OkHttpClientUtil.doPostJson(iotHost + "/deviceApi/findDeviceDeptTree", params); |
| 121 | - JSONObject jsonObject =JSONObject.parseObject(json); | ||
| 122 | - if(!jsonObject.getInteger("code").equals(200)){ | 124 | + JSONObject jsonObject = JSONObject.parseObject(json); |
| 125 | + if (!jsonObject.getInteger("code").equals(200)) { | ||
| 123 | return null; | 126 | return null; |
| 124 | } | 127 | } |
| 125 | 128 | ||
| 126 | List<DeviceDeptTreeRespVO> deviceDeptTreeList = JSONArray.parseArray(jsonObject.getString("data"), DeviceDeptTreeRespVO.class); | 129 | List<DeviceDeptTreeRespVO> deviceDeptTreeList = JSONArray.parseArray(jsonObject.getString("data"), DeviceDeptTreeRespVO.class); |
| 127 | - if(CollectionUtil.isEmpty(deviceDeptTreeList)){ | 130 | + if (CollectionUtil.isEmpty(deviceDeptTreeList)) { |
| 128 | return null; | 131 | return null; |
| 129 | } | 132 | } |
| 130 | //获取所有已绑定设备列表 | 133 | //获取所有已绑定设备列表 |
| 131 | List<DeviceUserDO> list = deviceUserMapper.selectList(); | 134 | List<DeviceUserDO> list = deviceUserMapper.selectList(); |
| 132 | - if(CollectionUtil.isEmpty(list)){ | ||
| 133 | - return deviceDeptTreeList.get(0); | 135 | + if (CollectionUtil.isEmpty(list)) { |
| 136 | + return deviceDeptTreeList.get(0); | ||
| 134 | } | 137 | } |
| 135 | List<String> deviceNos = list.stream().map(deviceUserDO -> deviceUserDO.getDeviceNo()).collect(Collectors.toList()); | 138 | List<String> deviceNos = list.stream().map(deviceUserDO -> deviceUserDO.getDeviceNo()).collect(Collectors.toList()); |
| 136 | // | 139 | // |
| @@ -138,4 +141,32 @@ public class DeviceUserServiceImpl implements DeviceUserService { | @@ -138,4 +141,32 @@ public class DeviceUserServiceImpl implements DeviceUserService { | ||
| 138 | return deviceDeptTreeList.get(0); | 141 | return deviceDeptTreeList.get(0); |
| 139 | } | 142 | } |
| 140 | 143 | ||
| 144 | + @Override | ||
| 145 | + public Boolean updateDevice(DeviceUserUpdateReqVO updateReqVO) { | ||
| 146 | + updateReqVO.getDeviceInfoList().forEach(deviceInfo -> { | ||
| 147 | + UpdateWrapper<DeviceUserDO> updateWrapper = new UpdateWrapper<>(); | ||
| 148 | + updateWrapper.lambda().set(!StringUtils.isEmpty(deviceInfo.getProductName()), DeviceUserDO::getProductName, deviceInfo.getProductName()) | ||
| 149 | + .set(!StringUtils.isEmpty(deviceInfo.getDeviceName()), DeviceUserDO::getDeviceName, deviceInfo.getDeviceName()) | ||
| 150 | + .set(!StringUtils.isEmpty(deviceInfo.getDeviceState()), DeviceUserDO::getDeviceState, deviceInfo.getDeviceState()) | ||
| 151 | + .eq(DeviceUserDO::getDeviceNo, deviceInfo.getDeviceNo()); | ||
| 152 | + deviceUserMapper.update(updateWrapper); | ||
| 153 | + }); | ||
| 154 | + | ||
| 155 | + return true; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + @Override | ||
| 159 | + public DeviceUserRespVO getDeviceUserByDeviceNo(String deviceNo) { | ||
| 160 | + QueryWrapper<DeviceUserDO> query = new QueryWrapper<>(); | ||
| 161 | + query.lambda().eq(DeviceUserDO::getDeviceNo, deviceNo); | ||
| 162 | + List<DeviceUserDO> list = deviceUserMapper.selectList(query); | ||
| 163 | + if (CollectionUtil.isEmpty(list)) { | ||
| 164 | + return null; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + DeviceUserRespVO deviceUserRes = new DeviceUserRespVO(); | ||
| 168 | + BeanUtils.copyProperties(list.get(0), deviceUserRes); | ||
| 169 | + return deviceUserRes; | ||
| 170 | + } | ||
| 171 | + | ||
| 141 | } | 172 | } |
| 142 | \ No newline at end of file | 173 | \ No newline at end of file |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/dept/DeptService.java
| @@ -158,4 +158,10 @@ public interface DeptService { | @@ -158,4 +158,10 @@ public interface DeptService { | ||
| 158 | * @return | 158 | * @return |
| 159 | */ | 159 | */ |
| 160 | List<DeptDO> getDeptAllList(); | 160 | List<DeptDO> getDeptAllList(); |
| 161 | + /** | ||
| 162 | + * 获取部门父级部门id(公司) | ||
| 163 | + * @param deptId | ||
| 164 | + * @return | ||
| 165 | + */ | ||
| 166 | + Long getParentDeptId(Long deptId); | ||
| 161 | } | 167 | } |
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,6 +51,7 @@ public class DeptServiceImpl implements DeptService { | ||
| 51 | @Resource | 51 | @Resource |
| 52 | private AdminUserMapper userMapper; | 52 | private AdminUserMapper userMapper; |
| 53 | 53 | ||
| 54 | + | ||
| 54 | @Override | 55 | @Override |
| 55 | @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, | 56 | @CacheEvict(cacheNames = RedisKeyConstants.DEPT_CHILDREN_ID_LIST, |
| 56 | allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 | 57 | allEntries = true) // allEntries 清空所有缓存,因为操作一个部门,涉及到多个缓存 |
| @@ -318,6 +319,7 @@ public class DeptServiceImpl implements DeptService { | @@ -318,6 +319,7 @@ public class DeptServiceImpl implements DeptService { | ||
| 318 | UserDO userDO = new UserDO(); | 319 | UserDO userDO = new UserDO(); |
| 319 | userDO.setUserId(adminUserDO.getId()); | 320 | userDO.setUserId(adminUserDO.getId()); |
| 320 | userDO.setUsername(adminUserDO.getUsername()); | 321 | userDO.setUsername(adminUserDO.getUsername()); |
| 322 | + userDO.setCompanyId(getParentDeptId(adminUserDO.getDeptId())); | ||
| 321 | userDO.setDeptId(adminUserDO.getDeptId()); | 323 | userDO.setDeptId(adminUserDO.getDeptId()); |
| 322 | userDOList.add(userDO); | 324 | userDOList.add(userDO); |
| 323 | } | 325 | } |
| @@ -336,4 +338,61 @@ public class DeptServiceImpl implements DeptService { | @@ -336,4 +338,61 @@ public class DeptServiceImpl implements DeptService { | ||
| 336 | sql.lambda().eq(DeptDO::getDeleted, 0); | 338 | sql.lambda().eq(DeptDO::getDeleted, 0); |
| 337 | return deptMapper.selectList(sql); | 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 | } |
urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/util/tree/UserDO.java
urbanops-server/src/main/resources/application.yaml
| @@ -271,6 +271,7 @@ urbanops: | @@ -271,6 +271,7 @@ urbanops: | ||
| 271 | security: | 271 | security: |
| 272 | permit-all_urls: | 272 | permit-all_urls: |
| 273 | - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,不需要登录 | 273 | - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,不需要登录 |
| 274 | + - /admin-api/garden/device-user/** | ||
| 274 | api-encrypt: | 275 | api-encrypt: |
| 275 | enable: true # 是否开启 API 加密 | 276 | enable: true # 是否开启 API 加密 |
| 276 | algorithm: AES # 加密算法,支持 AES、RSA 等 | 277 | algorithm: AES # 加密算法,支持 AES、RSA 等 |