refactor: 优化字符串模板方法 API 使用

This commit is contained in:
2024-02-18 22:47:18 +08:00
parent 370f9cf796
commit 0f393845a1
4 changed files with 9 additions and 9 deletions

View File

@@ -133,7 +133,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptRes
*/
private String getAncestors(Long parentId) {
DeptDO parentDept = this.getByParentId(parentId);
return String.format("%s,%s", parentDept.getAncestors(), parentId);
return "%s,%s".formatted(parentDept.getAncestors(), parentId);
}
/**
@@ -155,7 +155,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptRes
* @return 子部门列表
*/
private List<DeptDO> listChildren(Long id) {
return baseMapper.lambdaQuery().apply(String.format("find_in_set(%s, ancestors)", id)).list();
return baseMapper.lambdaQuery().apply("find_in_set(%s, ancestors)".formatted(id)).list();
}
/**
@@ -170,7 +170,7 @@ public class DeptServiceImpl extends BaseServiceImpl<DeptMapper, DeptDO, DeptRes
return 0L;
}
return ids.stream()
.mapToLong(id -> baseMapper.lambdaQuery().apply(String.format("find_in_set(%s, ancestors)", id)).count())
.mapToLong(id -> baseMapper.lambdaQuery().apply("find_in_set(%s, ancestors)".formatted(id)).count())
.sum();
}