fix(system): 修复根据 ID 查询部门信息时的潜在问题(工作流调用时候)

- 在 selectDeptById 方法中添加了对 deptId 参数的空值检查,避免不必要的缓存查询
- 在 selectDeptNameByIds 方法中增加了对 id 的非空判断,提高了代码的健壮性
- 优化了缓存注解的使用,添加了 condition 属性以减少不必要的缓存操作
master
zch 2 weeks ago
parent 8f6249e843
commit 7caa10f7a0

@ -161,9 +161,12 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @param deptId ID
* @return
*/
@Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
@Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId", condition = "#deptId != null")
@Override
public SysDeptVo selectDeptById(Long deptId) {
if (ObjectUtil.isNull(deptId)) {
return null;
}
SysDeptVo dept = baseMapper.selectVoById(deptId);
if (ObjectUtil.isNull(dept)) {
return null;
@ -198,9 +201,11 @@ public class SysDeptServiceImpl implements ISysDeptService {
public String selectDeptNameByIds(String deptIds) {
List<String> list = new ArrayList<>();
for (Long id : StringUtils.splitTo(deptIds, Convert::toLong)) {
SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(id);
if (ObjectUtil.isNotNull(vo)) {
list.add(vo.getDeptName());
if (ObjectUtil.isNotNull(id)) {
SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(id);
if (ObjectUtil.isNotNull(vo)) {
list.add(vo.getDeptName());
}
}
}
return String.join(StringUtils.SEPARATOR, list);

Loading…
Cancel
Save