upd: 编码规范

This commit is contained in:
2025-04-09 20:06:14 +08:00
parent f3719b3f1c
commit 1414e17444
7 changed files with 43 additions and 43 deletions
@@ -37,7 +37,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
// 获取用户的权限 // 获取用户的权限
List<RoleCodeModel> authorities = roleService.buildPermissions(user); List<RoleCodeModel> authorities = roleService.buildPermissions(user);
// 初始化JwtUserDto // 初始化JwtUserDto
userJwtModel = new UserJwtModel(user, dataService.selectDeptIdByUserIdWithDeptId(user), authorities); userJwtModel = new UserJwtModel(user, dataService.describeDeptIdListByUserIdWithDeptId(user), authorities);
// 添加缓存数据 // 添加缓存数据
userCacheService.cacheUserJwtModelByUserName(username, userJwtModel); userCacheService.cacheUserJwtModelByUserName(username, userJwtModel);
} }
@@ -38,14 +38,14 @@ public class DeptController {
@GetMapping(value = "/download") @GetMapping(value = "/download")
@PreAuthorize("@el.check('dept:list')") @PreAuthorize("@el.check('dept:list')")
public void exportDept(HttpServletResponse response, QueryDeptRequest criteria) throws Exception { public void exportDept(HttpServletResponse response, QueryDeptRequest criteria) throws Exception {
deptService.downloadExcel(deptService.selectDeptByCriteria(criteria, false), response); deptService.downloadDeptExcel(deptService.describeDeptList(criteria, false), response);
} }
@ApiOperation("查询部门") @ApiOperation("查询部门")
@GetMapping @GetMapping
@PreAuthorize("@el.check('user:list','dept:list')") @PreAuthorize("@el.check('user:list','dept:list')")
public ResponseEntity<PageResult<Dept>> queryDept(QueryDeptRequest criteria) throws Exception { public ResponseEntity<PageResult<Dept>> queryDept(QueryDeptRequest criteria) throws Exception {
List<Dept> depts = deptService.selectDeptByCriteria(criteria, true); List<Dept> depts = deptService.describeDeptList(criteria, true);
return new ResponseEntity<>(PageUtil.toPage(depts), HttpStatus.OK); return new ResponseEntity<>(PageUtil.toPage(depts), HttpStatus.OK);
} }
@@ -55,8 +55,8 @@ public class DeptController {
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids, @RequestParam(defaultValue = "false") Boolean exclude) { public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids, @RequestParam(defaultValue = "false") Boolean exclude) {
Set<Dept> deptSet = new LinkedHashSet<>(); Set<Dept> deptSet = new LinkedHashSet<>();
for (Long id : ids) { for (Long id : ids) {
Dept dept = deptService.getDeptById(id); Dept dept = deptService.describeDeptById(id);
List<Dept> depts = deptService.selectSuperiorDeptByPid(dept, new ArrayList<>()); List<Dept> depts = deptService.describeSuperiorDeptListByPid(dept, new ArrayList<>());
if (exclude) { if (exclude) {
for (Dept data : depts) { for (Dept data : depts) {
if (data.getId().equals(dept.getPid())) { if (data.getId().equals(dept.getPid())) {
@@ -68,7 +68,7 @@ public class DeptController {
} }
deptSet.addAll(depts); deptSet.addAll(depts);
} }
return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptSet)), HttpStatus.OK); return new ResponseEntity<>(deptService.buildDeptTree(new ArrayList<>(deptSet)), HttpStatus.OK);
} }
@ApiOperation("新增部门") @ApiOperation("新增部门")
@@ -83,7 +83,7 @@ public class DeptController {
@PostMapping(value = "/updateDept") @PostMapping(value = "/updateDept")
@PreAuthorize("@el.check('dept:edit')") @PreAuthorize("@el.check('dept:edit')")
public ResponseEntity<Object> updateDept(@Validated(Dept.Update.class) @RequestBody Dept resources) { public ResponseEntity<Object> updateDept(@Validated(Dept.Update.class) @RequestBody Dept resources) {
deptService.updateDept(resources); deptService.modifyDept(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} }
@@ -75,12 +75,12 @@ public class UserController {
if (!ObjectUtils.isEmpty(criteria.getDeptId())) { if (!ObjectUtils.isEmpty(criteria.getDeptId())) {
criteria.getDeptIds().add(criteria.getDeptId()); criteria.getDeptIds().add(criteria.getDeptId());
// 先查找是否存在子节点 // 先查找是否存在子节点
List<Dept> data = deptService.selectDeptByPid(criteria.getDeptId()); List<Dept> data = deptService.describeDeptListByPid(criteria.getDeptId());
// 然后把子节点的ID都加入到集合中 // 然后把子节点的ID都加入到集合中
criteria.getDeptIds().addAll(deptService.selectChildDeptIdByDeptIds(data)); criteria.getDeptIds().addAll(deptService.describeChildDeptIdListByDeptIds(data));
} }
// 数据权限 // 数据权限
List<Long> dataScopes = dataService.selectDeptIdByUserIdWithDeptId(userService.getUserByUsername(SecurityHelper.getCurrentUsername())); List<Long> dataScopes = dataService.describeDeptIdListByUserIdWithDeptId(userService.getUserByUsername(SecurityHelper.getCurrentUsername()));
// criteria.getDeptIds() 不为空并且数据权限不为空则取交集 // criteria.getDeptIds() 不为空并且数据权限不为空则取交集
if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) { if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) {
// 取交集 // 取交集
@@ -15,5 +15,5 @@ public interface DataService {
* @param user / * @param user /
* @return / * @return /
*/ */
List<Long> selectDeptIdByUserIdWithDeptId(User user); List<Long> describeDeptIdListByUserIdWithDeptId(User user);
} }
@@ -20,7 +20,7 @@ public interface DeptService extends IService<Dept> {
* @return / * @return /
* @throws Exception / * @throws Exception /
*/ */
List<Dept> selectDeptByCriteria(QueryDeptRequest criteria, Boolean isQuery) throws Exception; List<Dept> describeDeptList(QueryDeptRequest criteria, Boolean isQuery) throws Exception;
/** /**
* 根据ID查询 * 根据ID查询
@@ -28,7 +28,7 @@ public interface DeptService extends IService<Dept> {
* @param id / * @param id /
* @return / * @return /
*/ */
Dept getDeptById(Long id); Dept describeDeptById(Long id);
/** /**
* 创建 * 创建
@@ -42,7 +42,7 @@ public interface DeptService extends IService<Dept> {
* *
* @param resources / * @param resources /
*/ */
void updateDept(Dept resources); void modifyDept(Dept resources);
/** /**
* 删除 * 删除
@@ -57,7 +57,7 @@ public interface DeptService extends IService<Dept> {
* @param pid / * @param pid /
* @return / * @return /
*/ */
List<Dept> selectDeptByPid(long pid); List<Dept> describeDeptListByPid(long pid);
/** /**
* 根据角色ID查询 * 根据角色ID查询
@@ -65,7 +65,7 @@ public interface DeptService extends IService<Dept> {
* @param id / * @param id /
* @return / * @return /
*/ */
Set<Dept> selectDeptByRoleId(Long id); Set<Dept> describeDeptByRoleId(Long id);
/** /**
* 导出数据 * 导出数据
@@ -74,7 +74,7 @@ public interface DeptService extends IService<Dept> {
* @param response / * @param response /
* @throws IOException / * @throws IOException /
*/ */
void downloadExcel(List<Dept> depts, HttpServletResponse response) throws IOException; void downloadDeptExcel(List<Dept> depts, HttpServletResponse response) throws IOException;
/** /**
* 获取部门下所有关联的部门 * 获取部门下所有关联的部门
@@ -83,7 +83,7 @@ public interface DeptService extends IService<Dept> {
* @param depts / * @param depts /
* @return / * @return /
*/ */
Set<Dept> selectRelationDept(List<Dept> deptList, Set<Dept> depts); Set<Dept> describeRelationDeptSet(List<Dept> deptList, Set<Dept> depts);
/** /**
* 根据ID获取同级与上级数据 * 根据ID获取同级与上级数据
@@ -92,7 +92,7 @@ public interface DeptService extends IService<Dept> {
* @param depts / * @param depts /
* @return / * @return /
*/ */
List<Dept> selectSuperiorDeptByPid(Dept dept, List<Dept> depts); List<Dept> describeSuperiorDeptListByPid(Dept dept, List<Dept> depts);
/** /**
* 构建树形数据 * 构建树形数据
@@ -100,7 +100,7 @@ public interface DeptService extends IService<Dept> {
* @param depts / * @param depts /
* @return / * @return /
*/ */
BaseResult<Object> buildTree(List<Dept> depts); BaseResult<Object> buildDeptTree(List<Dept> depts);
/** /**
* 获取 * 获取
@@ -108,7 +108,7 @@ public interface DeptService extends IService<Dept> {
* @param deptList 、 * @param deptList 、
* @return 、 * @return 、
*/ */
List<Long> selectChildDeptIdByDeptIds(List<Dept> deptList); List<Long> describeChildDeptIdListByDeptIds(List<Dept> deptList);
/** /**
* 验证是否被角色或用户关联 * 验证是否被角色或用户关联
@@ -36,7 +36,7 @@ public class DataServiceImpl implements DataService {
* @return / * @return /
*/ */
@Override @Override
public List<Long> selectDeptIdByUserIdWithDeptId(User user) { public List<Long> describeDeptIdListByUserIdWithDeptId(User user) {
String key = SystemRedisKey.DATA_USER + user.getId(); String key = SystemRedisKey.DATA_USER + user.getId();
List<Long> ids = redisHelper.getList(key, Long.class); List<Long> ids = redisHelper.getList(key, Long.class);
if (CollUtil.isEmpty(ids)) { if (CollUtil.isEmpty(ids)) {
@@ -71,12 +71,12 @@ public class DataServiceImpl implements DataService {
* @return 数据权限ID * @return 数据权限ID
*/ */
public Set<Long> getCustomize(Set<Long> deptIds, Role role) { public Set<Long> getCustomize(Set<Long> deptIds, Role role) {
Set<Dept> deptList = deptService.selectDeptByRoleId(role.getId()); Set<Dept> deptList = deptService.describeDeptByRoleId(role.getId());
for (Dept dept : deptList) { for (Dept dept : deptList) {
deptIds.add(dept.getId()); deptIds.add(dept.getId());
List<Dept> deptChildren = deptService.selectDeptByPid(dept.getId()); List<Dept> deptChildren = deptService.describeDeptListByPid(dept.getId());
if (CollUtil.isNotEmpty(deptChildren)) { if (CollUtil.isNotEmpty(deptChildren)) {
deptIds.addAll(deptService.selectChildDeptIdByDeptIds(deptChildren)); deptIds.addAll(deptService.describeChildDeptIdListByDeptIds(deptChildren));
} }
} }
return deptIds; return deptIds;
@@ -46,7 +46,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
private final RedisHelper redisHelper; private final RedisHelper redisHelper;
@Override @Override
public List<Dept> selectDeptByCriteria(QueryDeptRequest criteria, Boolean isQuery) throws Exception { public List<Dept> describeDeptList(QueryDeptRequest criteria, Boolean isQuery) throws Exception {
String dataScopeType = SecurityHelper.getDataScopeType(); String dataScopeType = SecurityHelper.getDataScopeType();
if (isQuery) { if (isQuery) {
if (dataScopeType.equals(DataScopeEnum.ALL.getValue())) { if (dataScopeType.equals(DataScopeEnum.ALL.getValue())) {
@@ -81,7 +81,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
} }
@Override @Override
public Dept getDeptById(Long id) { public Dept describeDeptById(Long id) {
String key = SystemRedisKey.DEPT_ID + id; String key = SystemRedisKey.DEPT_ID + id;
Dept dept = redisHelper.get(key, Dept.class); Dept dept = redisHelper.get(key, Dept.class);
if (dept == null) { if (dept == null) {
@@ -92,12 +92,12 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
} }
@Override @Override
public List<Dept> selectDeptByPid(long pid) { public List<Dept> describeDeptListByPid(long pid) {
return deptMapper.queryDeptListByPid(pid); return deptMapper.queryDeptListByPid(pid);
} }
@Override @Override
public Set<Dept> selectDeptByRoleId(Long id) { public Set<Dept> describeDeptByRoleId(Long id) {
return deptMapper.queryDeptSetByRoleId(id); return deptMapper.queryDeptSetByRoleId(id);
} }
@@ -113,9 +113,9 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateDept(Dept resources) { public void modifyDept(Dept resources) {
// 旧的部门 // 旧的部门
Long oldPid = getDeptById(resources.getId()).getPid(); Long oldPid = describeDeptById(resources.getId()).getPid();
Long newPid = resources.getPid(); Long newPid = resources.getPid();
if (resources.getPid() != null && resources.getId().equals(resources.getPid())) { if (resources.getPid() != null && resources.getId().equals(resources.getPid())) {
throw new BadRequestException("上级不能为自己"); throw new BadRequestException("上级不能为自己");
@@ -142,7 +142,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
} }
@Override @Override
public void downloadExcel(List<Dept> deptList, HttpServletResponse response) throws IOException { public void downloadDeptExcel(List<Dept> deptList, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
for (Dept dept : deptList) { for (Dept dept : deptList) {
Map<String, Object> map = new LinkedHashMap<>(); Map<String, Object> map = new LinkedHashMap<>();
@@ -155,25 +155,25 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
} }
@Override @Override
public Set<Dept> selectRelationDept(List<Dept> menuList, Set<Dept> deptSet) { public Set<Dept> describeRelationDeptSet(List<Dept> menuList, Set<Dept> deptSet) {
for (Dept dept : menuList) { for (Dept dept : menuList) {
deptSet.add(dept); deptSet.add(dept);
List<Dept> deptList = deptMapper.queryDeptListByPid(dept.getId()); List<Dept> deptList = deptMapper.queryDeptListByPid(dept.getId());
if (CollUtil.isNotEmpty(deptList)) { if (CollUtil.isNotEmpty(deptList)) {
selectRelationDept(deptList, deptSet); describeRelationDeptSet(deptList, deptSet);
} }
} }
return deptSet; return deptSet;
} }
@Override @Override
public List<Long> selectChildDeptIdByDeptIds(List<Dept> deptList) { public List<Long> describeChildDeptIdListByDeptIds(List<Dept> deptList) {
List<Long> list = new ArrayList<>(); List<Long> list = new ArrayList<>();
deptList.forEach(dept -> { deptList.forEach(dept -> {
if (dept != null && dept.getEnabled()) { if (dept != null && dept.getEnabled()) {
List<Dept> deptList1 = deptMapper.queryDeptListByPid(dept.getId()); List<Dept> deptList1 = deptMapper.queryDeptListByPid(dept.getId());
if (CollUtil.isNotEmpty(deptList1)) { if (CollUtil.isNotEmpty(deptList1)) {
list.addAll(selectChildDeptIdByDeptIds(deptList1)); list.addAll(describeChildDeptIdListByDeptIds(deptList1));
} }
list.add(dept.getId()); list.add(dept.getId());
} }
@@ -183,17 +183,17 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
} }
@Override @Override
public List<Dept> selectSuperiorDeptByPid(Dept dept, List<Dept> deptList) { public List<Dept> describeSuperiorDeptListByPid(Dept dept, List<Dept> deptList) {
if (dept.getPid() == null) { if (dept.getPid() == null) {
deptList.addAll(deptMapper.queryDeptListByPidIsNull()); deptList.addAll(deptMapper.queryDeptListByPidIsNull());
return deptList; return deptList;
} }
deptList.addAll(deptMapper.queryDeptListByPid(dept.getPid())); deptList.addAll(deptMapper.queryDeptListByPid(dept.getPid()));
return selectSuperiorDeptByPid(getDeptById(dept.getPid()), deptList); return describeSuperiorDeptListByPid(describeDeptById(dept.getPid()), deptList);
} }
@Override @Override
public BaseResult<Object> buildTree(List<Dept> deptList) { public BaseResult<Object> buildDeptTree(List<Dept> deptList) {
Set<Dept> trees = new LinkedHashSet<>(); Set<Dept> trees = new LinkedHashSet<>();
Set<Dept> deptSet = new LinkedHashSet<>(); Set<Dept> deptSet = new LinkedHashSet<>();
List<String> deptNames = deptList.stream().map(Dept::getName).collect(Collectors.toList()); List<String> deptNames = deptList.stream().map(Dept::getName).collect(Collectors.toList());
@@ -214,7 +214,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
} }
if (isChild) { if (isChild) {
deptSet.add(dept); deptSet.add(dept);
} else if (dept.getPid() != null && !deptNames.contains(getDeptById(dept.getPid()).getName())) { } else if (dept.getPid() != null && !deptNames.contains(describeDeptById(dept.getPid()).getName())) {
deptSet.add(dept); deptSet.add(dept);
} }
} }
@@ -242,11 +242,11 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
public void traverseDeptByIdWithPids(Set<Long> ids, Set<Dept> depts) { public void traverseDeptByIdWithPids(Set<Long> ids, Set<Dept> depts) {
for (Long id : ids) { for (Long id : ids) {
// 根部门 // 根部门
depts.add(getDeptById(id)); depts.add(describeDeptById(id));
// 子部门 // 子部门
List<Dept> deptList = selectDeptByPid(id); List<Dept> deptList = describeDeptListByPid(id);
if (CollectionUtil.isNotEmpty(deptList)) { if (CollectionUtil.isNotEmpty(deptList)) {
depts = selectRelationDept(deptList, depts); depts = describeRelationDeptSet(deptList, depts);
} }
} }
} }