refactor(core): 替换 CollectionUtil 为 CollUtil 并优化代码结构
This commit is contained in:
+3
-3
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package cn.odboy.framework.mybatisplus.core;
|
package cn.odboy.framework.mybatisplus.core;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.base.KitBaseUserTimeTb;
|
import cn.odboy.base.KitBaseUserTimeTb;
|
||||||
@@ -131,7 +131,7 @@ public class KitMpQUtil {
|
|||||||
private static <R> void handleInOrNotQuery(boolean b, QueryWrapper<R> queryWrapper, String attributeName,
|
private static <R> void handleInOrNotQuery(boolean b, QueryWrapper<R> queryWrapper, String attributeName,
|
||||||
Object fieldVal) {
|
Object fieldVal) {
|
||||||
Collection<?> wrapNotInVal = (Collection<?>) fieldVal;
|
Collection<?> wrapNotInVal = (Collection<?>) fieldVal;
|
||||||
if (CollectionUtil.isNotEmpty(wrapNotInVal)) {
|
if (CollUtil.isNotEmpty(wrapNotInVal)) {
|
||||||
Optional<?> anyValOptional = wrapNotInVal.stream().findAny();
|
Optional<?> anyValOptional = wrapNotInVal.stream().findAny();
|
||||||
if (anyValOptional.isPresent()) {
|
if (anyValOptional.isPresent()) {
|
||||||
Object o = anyValOptional.get();
|
Object o = anyValOptional.get();
|
||||||
@@ -159,7 +159,7 @@ public class KitMpQUtil {
|
|||||||
if (fieldVal instanceof List) {
|
if (fieldVal instanceof List) {
|
||||||
List<Object> between = new ArrayList<>((List<?>) fieldVal);
|
List<Object> between = new ArrayList<>((List<?>) fieldVal);
|
||||||
int minLength = 2;
|
int minLength = 2;
|
||||||
if (CollectionUtil.isNotEmpty(between) && between.size() >= minLength) {
|
if (CollUtil.isNotEmpty(between) && between.size() >= minLength) {
|
||||||
queryWrapper.between(finalAttributeName, between.get(0), between.get(1));
|
queryWrapper.between(finalAttributeName, between.get(0), between.get(1));
|
||||||
} else {
|
} else {
|
||||||
throw new BadRequestException("BETWEEN类型的对象列表长度必须 >= 2");
|
throw new BadRequestException("BETWEEN类型的对象列表长度必须 >= 2");
|
||||||
|
|||||||
+8
-5
@@ -16,7 +16,6 @@
|
|||||||
package cn.odboy.system.service;
|
package cn.odboy.system.service;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.base.KitPageResult;
|
import cn.odboy.base.KitPageResult;
|
||||||
@@ -84,7 +83,7 @@ public class SystemDeptService {
|
|||||||
public void updateDeptById(SystemDeptTb args) {
|
public void updateDeptById(SystemDeptTb args) {
|
||||||
KitValidUtil.notNull(args);
|
KitValidUtil.notNull(args);
|
||||||
// 旧的父部门
|
// 旧的父部门
|
||||||
Long oldPid = this.getDeptVoById(args.getId()).getPid();
|
Long oldPid = this.getDeptById(args.getId()).getPid();
|
||||||
// 新的父部门
|
// 新的父部门
|
||||||
Long newPid = args.getPid();
|
Long newPid = args.getPid();
|
||||||
if (args.getPid() != null && args.getId().equals(args.getPid())) {
|
if (args.getPid() != null && args.getId().equals(args.getPid())) {
|
||||||
@@ -97,6 +96,10 @@ public class SystemDeptService {
|
|||||||
this.updateDeptSubCnt(newPid);
|
this.updateDeptSubCnt(newPid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SystemDeptTb getDeptById(Long id) {
|
||||||
|
return systemDeptMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*
|
*
|
||||||
@@ -322,11 +325,11 @@ public class SystemDeptService {
|
|||||||
deptSet.add(dept);
|
deptSet.add(dept);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (CollectionUtil.isEmpty(trees)) {
|
if (CollUtil.isEmpty(trees)) {
|
||||||
trees = deptSet;
|
trees = deptSet;
|
||||||
}
|
}
|
||||||
KitPageResult<SystemDeptVo> baseResult = new KitPageResult<>();
|
KitPageResult<SystemDeptVo> baseResult = new KitPageResult<>();
|
||||||
baseResult.setContent(CollectionUtil.isEmpty(trees) ? new ArrayList<>(deptSet) : new ArrayList<>(trees));
|
baseResult.setContent(CollUtil.isEmpty(trees) ? new ArrayList<>(deptSet) : new ArrayList<>(trees));
|
||||||
baseResult.setTotalElements(deptSet.size());
|
baseResult.setTotalElements(deptSet.size());
|
||||||
return baseResult;
|
return baseResult;
|
||||||
}
|
}
|
||||||
@@ -364,7 +367,7 @@ public class SystemDeptService {
|
|||||||
depts.add(this.getDeptVoById(id));
|
depts.add(this.getDeptVoById(id));
|
||||||
// 子部门
|
// 子部门
|
||||||
List<SystemDeptVo> deptList = this.listDeptVoByPid(id);
|
List<SystemDeptVo> deptList = this.listDeptVoByPid(id);
|
||||||
if (CollectionUtil.isNotEmpty(deptList)) {
|
if (CollUtil.isNotEmpty(deptList)) {
|
||||||
queryRelationDeptByArgs(deptList, depts);
|
queryRelationDeptByArgs(deptList, depts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -16,11 +16,9 @@
|
|||||||
package cn.odboy.system.service;
|
package cn.odboy.system.service;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.framework.exception.BadRequestException;
|
import cn.odboy.framework.exception.BadRequestException;
|
||||||
import cn.odboy.framework.logging.ExecutionTimeStatisticsFace;
|
|
||||||
import cn.odboy.system.constant.SystemTransferProtocolConst;
|
import cn.odboy.system.constant.SystemTransferProtocolConst;
|
||||||
import cn.odboy.system.constant.SystemYesOrNoChConst;
|
import cn.odboy.system.constant.SystemYesOrNoChConst;
|
||||||
import cn.odboy.system.dal.dataobject.SystemMenuTb;
|
import cn.odboy.system.dal.dataobject.SystemMenuTb;
|
||||||
@@ -337,7 +335,7 @@ public class SystemMenuService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuVo.setMeta(new SystemMenuMetaVo(menu.getTitle(), menu.getIcon(), !menu.getCache()));
|
menuVo.setMeta(new SystemMenuMetaVo(menu.getTitle(), menu.getIcon(), !menu.getCache()));
|
||||||
if (CollectionUtil.isNotEmpty(menuList)) {
|
if (CollUtil.isNotEmpty(menuList)) {
|
||||||
menuVo.setAlwaysShow(true);
|
menuVo.setAlwaysShow(true);
|
||||||
menuVo.setRedirect("noredirect");
|
menuVo.setRedirect("noredirect");
|
||||||
menuVo.setChildren(buildMenuVo(menuList));
|
menuVo.setChildren(buildMenuVo(menuList));
|
||||||
@@ -441,7 +439,7 @@ public class SystemMenuService {
|
|||||||
public List<SystemMenuVo> listMenuSuperior(List<Long> ids) {
|
public List<SystemMenuVo> listMenuSuperior(List<Long> ids) {
|
||||||
Set<SystemMenuVo> menus;
|
Set<SystemMenuVo> menus;
|
||||||
List<SystemMenuVo> systemMenuTbs;
|
List<SystemMenuVo> systemMenuTbs;
|
||||||
if (CollectionUtil.isNotEmpty(ids)) {
|
if (CollUtil.isNotEmpty(ids)) {
|
||||||
menus = new LinkedHashSet<>(this.listMenuByIds(ids));
|
menus = new LinkedHashSet<>(this.listMenuByIds(ids));
|
||||||
for (SystemMenuVo menu : menus) {
|
for (SystemMenuVo menu : menus) {
|
||||||
List<SystemMenuVo> menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>());
|
List<SystemMenuVo> menuList = this.querySuperiorMenuByArgs(menu, new ArrayList<>());
|
||||||
|
|||||||
+2
-3
@@ -16,7 +16,6 @@
|
|||||||
package cn.odboy.system.service;
|
package cn.odboy.system.service;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.base.KitPageResult;
|
import cn.odboy.base.KitPageResult;
|
||||||
@@ -74,7 +73,7 @@ public class SystemRoleService {
|
|||||||
SystemRoleTb roleTb = KitBeanUtil.copyToClass(args, SystemRoleTb.class);
|
SystemRoleTb roleTb = KitBeanUtil.copyToClass(args, SystemRoleTb.class);
|
||||||
systemRoleMapper.insert(roleTb);
|
systemRoleMapper.insert(roleTb);
|
||||||
// 判断是否有部门数据, 若有, 则需创建关联
|
// 判断是否有部门数据, 若有, 则需创建关联
|
||||||
if (CollectionUtil.isNotEmpty(args.getDepts())) {
|
if (CollUtil.isNotEmpty(args.getDepts())) {
|
||||||
systemRoleDeptService.batchInsertRoleDept(args.getDepts(), roleTb.getId());
|
systemRoleDeptService.batchInsertRoleDept(args.getDepts(), roleTb.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,7 +112,7 @@ public class SystemRoleService {
|
|||||||
// 删除关联部门数据
|
// 删除关联部门数据
|
||||||
systemRoleDeptService.batchDeleteRoleDept(Collections.singleton(args.getId()));
|
systemRoleDeptService.batchDeleteRoleDept(Collections.singleton(args.getId()));
|
||||||
// 判断是否有部门数据, 若有, 则需更新关联
|
// 判断是否有部门数据, 若有, 则需更新关联
|
||||||
if (CollectionUtil.isNotEmpty(args.getDepts())) {
|
if (CollUtil.isNotEmpty(args.getDepts())) {
|
||||||
systemRoleDeptService.batchInsertRoleDept(args.getDepts(), args.getId());
|
systemRoleDeptService.batchInsertRoleDept(args.getDepts(), args.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-8
@@ -16,7 +16,6 @@
|
|||||||
package cn.odboy.system.service;
|
package cn.odboy.system.service;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.odboy.base.KitPageArgs;
|
import cn.odboy.base.KitPageArgs;
|
||||||
import cn.odboy.base.KitPageResult;
|
import cn.odboy.base.KitPageResult;
|
||||||
@@ -62,7 +61,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -72,10 +70,6 @@ public class SystemUserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SystemUserMapper systemUserMapper;
|
private SystemUserMapper systemUserMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemJobService systemJobService;
|
|
||||||
@Autowired
|
|
||||||
private SystemRoleService systemRoleService;
|
|
||||||
@Autowired
|
|
||||||
private SystemDeptService systemDeptService;
|
private SystemDeptService systemDeptService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemUserJobService systemUserJobService;
|
private SystemUserJobService systemUserJobService;
|
||||||
@@ -479,10 +473,10 @@ public class SystemUserService {
|
|||||||
// 数据权限
|
// 数据权限
|
||||||
List<Long> dataScopes = systemDataService.queryDeptIdByArgs(this.getUserVoByUsername(currentUsername));
|
List<Long> dataScopes = systemDataService.queryDeptIdByArgs(this.getUserVoByUsername(currentUsername));
|
||||||
// args.getDeptIds() 不为空并且数据权限不为空则取交集
|
// args.getDeptIds() 不为空并且数据权限不为空则取交集
|
||||||
if (!CollectionUtils.isEmpty(args.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) {
|
if (!CollUtil.isEmpty(args.getDeptIds()) && !CollUtil.isEmpty(dataScopes)) {
|
||||||
// 取交集
|
// 取交集
|
||||||
args.getDeptIds().retainAll(dataScopes);
|
args.getDeptIds().retainAll(dataScopes);
|
||||||
if (!CollectionUtil.isEmpty(args.getDeptIds())) {
|
if (!CollUtil.isEmpty(args.getDeptIds())) {
|
||||||
return this.searchUserByArgs(args, page);
|
return this.searchUserByArgs(args, page);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user