refactor(system): 重构系统服务模块代码结构和功能实现
This commit is contained in:
+1
-1
@@ -29,13 +29,13 @@ import cn.odboy.system.framework.permission.core.handler.UserDetailsHandler;
|
||||
import cn.odboy.util.KitBeanUtil;
|
||||
import cn.odboy.util.KitRsaEncryptUtil;
|
||||
import cn.odboy.util.KitValidUtil;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 用户认证
|
||||
|
||||
+1
-1
@@ -25,9 +25,9 @@ import cn.odboy.framework.redis.KitRedisHelper;
|
||||
import cn.odboy.system.dal.model.response.SystemCaptchaVo;
|
||||
import cn.odboy.system.dal.redis.SystemCacheKey;
|
||||
import com.wf.captcha.base.Captcha;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
|
||||
+2
-2
@@ -20,14 +20,14 @@ import cn.odboy.system.constant.SystemDataScopeEnum;
|
||||
import cn.odboy.system.dal.dataobject.SystemDeptTb;
|
||||
import cn.odboy.system.dal.dataobject.SystemRoleTb;
|
||||
import cn.odboy.system.dal.model.response.SystemUserVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 数据权限
|
||||
|
||||
+233
-162
@@ -36,6 +36,10 @@ import cn.odboy.util.KitClassUtil;
|
||||
import cn.odboy.util.KitValidUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -47,10 +51,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class SystemDeptService {
|
||||
@@ -99,16 +99,6 @@ public class SystemDeptService {
|
||||
this.updateDeptSubCnt(newPid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门id查询部门信息 -> TestPassed
|
||||
*
|
||||
* @param id 部门id
|
||||
* @return /
|
||||
*/
|
||||
private SystemDeptTb getDeptById(Long id) {
|
||||
return systemDeptMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
@@ -139,43 +129,6 @@ public class SystemDeptService {
|
||||
}
|
||||
}
|
||||
|
||||
private long countDeptByPid(Long pid) {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getPid, pid);
|
||||
return systemDeptMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选出 list 中没有父部门(即 pid 不在其他部门 id 列表中的部门)的部门列表
|
||||
*/
|
||||
private List<SystemDeptTb> deduplication(List<SystemDeptTb> list) {
|
||||
List<SystemDeptTb> deptList = new ArrayList<>();
|
||||
// 使用 Set 存储所有部门的 id
|
||||
Set<Long> idSet = list.stream().map(SystemDeptTb::getId).collect(Collectors.toSet());
|
||||
// 遍历部门列表, 筛选出没有父部门的部门
|
||||
for (SystemDeptTb dept : list) {
|
||||
if (!idSet.contains(dept.getPid())) {
|
||||
deptList.add(dept);
|
||||
}
|
||||
}
|
||||
return deptList;
|
||||
}
|
||||
|
||||
private List<SystemDeptTb> queryDeptByArgs(SystemQueryDeptArgs args) {
|
||||
KitValidUtil.notNull(args);
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(CollUtil.isNotEmpty(args.getIds()), SystemDeptTb::getId, args.getIds());
|
||||
wrapper.like(StrUtil.isNotBlank(args.getName()), SystemDeptTb::getName, args.getName());
|
||||
wrapper.eq(args.getEnabled() != null, SystemDeptTb::getEnabled, args.getEnabled());
|
||||
wrapper.eq(args.getPid() != null, SystemDeptTb::getPid, args.getPid());
|
||||
wrapper.isNull(args.getPidIsNull() != null, SystemDeptTb::getPid);
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemDeptTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
wrapper.orderByAsc(SystemDeptTb::getDeptSort);
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有数据
|
||||
*
|
||||
@@ -213,7 +166,7 @@ public class SystemDeptService {
|
||||
List<SystemDeptTb> list = this.queryDeptByArgs(args);
|
||||
// 如果为空, 就代表为自定义权限或者本级权限, 就需要去重, 不理解可以注释掉,看查询结果
|
||||
if (StrUtil.isBlank(dataScopeType)) {
|
||||
return this.deduplication(list);
|
||||
return this.filterRootDeptList(list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -229,25 +182,11 @@ public class SystemDeptService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门下所有关联的部门
|
||||
* 根据部门id遍历所有部门和子部门id集合
|
||||
*
|
||||
* @param deptTbList /
|
||||
* @param depts /
|
||||
* @param deptList 部门集合
|
||||
* @param deptPidMap 父部门id和子部门集合的映射关系
|
||||
*/
|
||||
private void queryRelationDeptByArgs(List<SystemDeptVo> deptTbList, Set<SystemDeptVo> depts) {
|
||||
for (SystemDeptVo dept : deptTbList) {
|
||||
depts.add(dept);
|
||||
List<SystemDeptVo> deptList = this.listDeptVoByPid(dept.getId());
|
||||
if (CollUtil.isNotEmpty(deptList)) {
|
||||
queryRelationDeptByArgs(deptList, depts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<SystemDeptVo> listDeptVoByPid(Long pid) {
|
||||
return KitBeanUtil.copyToList(this.listDeptByPid(pid), SystemDeptVo.class);
|
||||
}
|
||||
|
||||
public List<Long> queryChildDeptIdByDeptIds(List<SystemDeptTb> deptList, Map<Long, List<SystemDeptTb>> deptPidMap) {
|
||||
List<Long> list = new ArrayList<>();
|
||||
for (SystemDeptTb systemDeptTb : deptList) {
|
||||
@@ -262,28 +201,6 @@ public class SystemDeptService {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询同级与上级数据
|
||||
*
|
||||
* @param dept /
|
||||
* @param deptList /
|
||||
* @return /
|
||||
*/
|
||||
private List<SystemDeptVo> querySuperiorDeptByPid(SystemDeptVo dept, List<SystemDeptVo> deptList) {
|
||||
if (dept.getPid() == null) {
|
||||
deptList.addAll(this.listRootDept());
|
||||
return deptList;
|
||||
}
|
||||
deptList.addAll(this.listDeptVoByPid(dept.getPid()));
|
||||
return querySuperiorDeptByPid(this.getDeptVoById(dept.getPid()), deptList);
|
||||
}
|
||||
|
||||
private List<SystemDeptVo> listRootDept() {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.isNull(SystemDeptTb::getPid);
|
||||
return KitBeanUtil.copyToList(systemDeptMapper.selectList(wrapper), SystemDeptVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建树形数据
|
||||
*
|
||||
@@ -357,16 +274,10 @@ public class SystemDeptService {
|
||||
}
|
||||
}
|
||||
|
||||
private List<SystemDeptTb> listEnabledDepts() {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getEnabled, 1);
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 遍历所有部门和子部门
|
||||
* 根据部门id遍历所有部门和子部门
|
||||
*
|
||||
* @param ids /
|
||||
* @param ids 部门id集合
|
||||
*/
|
||||
public Set<SystemDeptVo> traverseDeptByIdWithPids(Set<Long> ids) {
|
||||
Set<SystemDeptVo> depts = new HashSet<>();
|
||||
@@ -376,61 +287,27 @@ public class SystemDeptService {
|
||||
// 子部门
|
||||
List<SystemDeptVo> deptList = this.listDeptVoByPid(id);
|
||||
if (CollUtil.isNotEmpty(deptList)) {
|
||||
queryRelationDeptByArgs(deptList, depts);
|
||||
this.queryRelationDeptByArgs(deptList, depts);
|
||||
}
|
||||
}
|
||||
return depts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件 数据源
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemProductLineVo> listDeptSelectDataSource() {
|
||||
List<SystemDeptTb> depts = this.listEnabledDepts();
|
||||
return buildDeptSelectOptions(depts);
|
||||
}
|
||||
|
||||
private List<SystemProductLineVo> buildDeptSelectOptions(List<SystemDeptTb> depts) {
|
||||
// 查询所有部门并按父子关系组织
|
||||
Map<Long, SystemDeptTb> deptMap =
|
||||
depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity()));
|
||||
List<SystemProductLineVo> options = new ArrayList<>();
|
||||
for (SystemDeptTb dept : depts) {
|
||||
// 构建部门ID路径
|
||||
List<Long> pathIds = new ArrayList<>();
|
||||
buildDeptIdPath(dept, deptMap, pathIds);
|
||||
// 反转路径,从顶级部门到当前部门
|
||||
Collections.reverse(pathIds);
|
||||
SystemProductLineVo dto = new SystemProductLineVo();
|
||||
dto.setValue(dept.getId());
|
||||
dto.setIdPath(pathIds.stream().map(String::valueOf).collect(Collectors.joining("-")));
|
||||
// 保留名称路径用于显示
|
||||
dto.setLabel(buildNamePath(dept, deptMap));
|
||||
options.add(dto);
|
||||
}
|
||||
// 按部门名称路径排序
|
||||
options.sort(Comparator.comparing(SystemProductLineVo::getLabel));
|
||||
return options;
|
||||
}
|
||||
|
||||
private void buildDeptIdPath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap, List<Long> pathIds) {
|
||||
pathIds.add(dept.getId());
|
||||
if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) {
|
||||
buildDeptIdPath(deptMap.get(dept.getPid()), deptMap, pathIds);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildNamePath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap) {
|
||||
List<String> pathNames = new ArrayList<>();
|
||||
buildDeptNamePath(dept, deptMap, pathNames);
|
||||
Collections.reverse(pathNames);
|
||||
return String.join(" / ", pathNames);
|
||||
}
|
||||
|
||||
private void buildDeptNamePath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap, List<String> pathNames) {
|
||||
pathNames.add(dept.getName());
|
||||
if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) {
|
||||
buildDeptNamePath(deptMap.get(dept.getPid()), deptMap, pathNames);
|
||||
}
|
||||
return this.buildDeptSelectOptions(depts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件Pro版 数据源
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemProductLineTreeVo> listDeptSelectProDataSource() {
|
||||
List<SystemDeptTb> depts = this.listEnabledDepts();
|
||||
// 查询所有部门并按父子关系组织
|
||||
@@ -441,7 +318,7 @@ public class SystemDeptService {
|
||||
for (SystemDeptTb dept : depts) {
|
||||
// 只处理顶级部门(pid为null或0的部门)
|
||||
if (dept.getPid() == null || dept.getPid() == 0) {
|
||||
SystemProductLineTreeVo vo = buildDeptTreePro(dept, deptMap);
|
||||
SystemProductLineTreeVo vo = this.buildDeptTreePro(dept, deptMap);
|
||||
options.add(vo);
|
||||
}
|
||||
}
|
||||
@@ -453,6 +330,49 @@ public class SystemDeptService {
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父部门id查询部门集合
|
||||
*
|
||||
* @param pid 父部门id
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemDeptTb> listDeptByPid(long pid) {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getPid, pid);
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出部门数据
|
||||
*
|
||||
* @param response /
|
||||
* @param args /
|
||||
*/
|
||||
public void exportDeptXlsx(HttpServletResponse response, SystemQueryDeptArgs args) throws Exception {
|
||||
List<SystemDeptTb> systemDeptTbs = this.queryAllDeptByArgs(args, false);
|
||||
List<SystemDeptExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemDeptTb dataObject : systemDeptTbs) {
|
||||
SystemDeptExportRowVo rowVo = new SystemDeptExportRowVo();
|
||||
rowVo.setName(dataObject.getName());
|
||||
rowVo.setEnabled(dataObject.getEnabled() ? SystemZhConst.ENABLE_STR : SystemZhConst.DISABLE_STR);
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "部门数据", SystemDeptExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询父部门非空且启用的部门数据
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemDeptTb> listPidNonNull() {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getEnabled, 1);
|
||||
wrapper.isNotNull(SystemDeptTb::getPid);
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归构建部门树
|
||||
*
|
||||
@@ -468,7 +388,7 @@ public class SystemDeptService {
|
||||
List<SystemProductLineTreeVo> children = new ArrayList<>();
|
||||
for (SystemDeptTb childDept : deptMap.values()) {
|
||||
if (dept.getId().equals(childDept.getPid())) {
|
||||
children.add(buildDeptTreePro(childDept, deptMap));
|
||||
children.add(this.buildDeptTreePro(childDept, deptMap));
|
||||
}
|
||||
}
|
||||
// 子部门按排序字段排序
|
||||
@@ -480,29 +400,180 @@ public class SystemDeptService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
public List<SystemDeptTb> listDeptByPid(long pid) {
|
||||
/**
|
||||
* 产品线选择组件使用
|
||||
*
|
||||
* @param depts 部门集合
|
||||
* @return /
|
||||
*/
|
||||
private List<SystemProductLineVo> buildDeptSelectOptions(List<SystemDeptTb> depts) {
|
||||
// 查询所有部门并按父子关系组织
|
||||
Map<Long, SystemDeptTb> deptMap =
|
||||
depts.stream().collect(Collectors.toMap(SystemDeptTb::getId, Function.identity()));
|
||||
List<SystemProductLineVo> options = new ArrayList<>();
|
||||
for (SystemDeptTb dept : depts) {
|
||||
// 构建部门ID路径
|
||||
List<Long> pathIds = new ArrayList<>();
|
||||
this.buildDeptIdPath(dept, deptMap, pathIds);
|
||||
// 反转路径,从顶级部门到当前部门
|
||||
Collections.reverse(pathIds);
|
||||
SystemProductLineVo dto = new SystemProductLineVo();
|
||||
dto.setValue(dept.getId());
|
||||
dto.setIdPath(pathIds.stream().map(String::valueOf).collect(Collectors.joining("-")));
|
||||
// 保留名称路径用于显示
|
||||
dto.setLabel(this.buildNamePath(dept, deptMap));
|
||||
options.add(dto);
|
||||
}
|
||||
// 按部门名称路径排序
|
||||
options.sort(Comparator.comparing(SystemProductLineVo::getLabel));
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件使用
|
||||
*/
|
||||
private void buildDeptIdPath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap, List<Long> pathIds) {
|
||||
pathIds.add(dept.getId());
|
||||
if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) {
|
||||
this.buildDeptIdPath(deptMap.get(dept.getPid()), deptMap, pathIds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件使用
|
||||
*/
|
||||
private String buildNamePath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap) {
|
||||
List<String> pathNames = new ArrayList<>();
|
||||
this.buildDeptNamePath(dept, deptMap, pathNames);
|
||||
Collections.reverse(pathNames);
|
||||
return String.join(" / ", pathNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品线选择组件使用
|
||||
*/
|
||||
private void buildDeptNamePath(SystemDeptTb dept, Map<Long, SystemDeptTb> deptMap, List<String> pathNames) {
|
||||
pathNames.add(dept.getName());
|
||||
if (dept.getPid() != null && dept.getPid() != 0 && deptMap.containsKey(dept.getPid())) {
|
||||
this.buildDeptNamePath(deptMap.get(dept.getPid()), deptMap, pathNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询启用的所有部门集合
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
private List<SystemDeptTb> listEnabledDepts() {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getPid, pid);
|
||||
wrapper.eq(SystemDeptTb::getEnabled, 1);
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
public void exportDeptXlsx(HttpServletResponse response, SystemQueryDeptArgs args) throws Exception {
|
||||
List<SystemDeptTb> systemDeptTbs = this.queryAllDeptByArgs(args, false);
|
||||
List<SystemDeptExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemDeptTb dataObject : systemDeptTbs) {
|
||||
SystemDeptExportRowVo rowVo = new SystemDeptExportRowVo();
|
||||
rowVo.setName(dataObject.getName());
|
||||
rowVo.setEnabled(dataObject.getEnabled() ? SystemZhConst.ENABLE_STR : SystemZhConst.DISABLE_STR);
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
rowVos.add(rowVo);
|
||||
/**
|
||||
* 查询部门下所有关联的部门
|
||||
*
|
||||
* @param deptTbList /
|
||||
* @param depts /
|
||||
*/
|
||||
private void queryRelationDeptByArgs(List<SystemDeptVo> deptTbList, Set<SystemDeptVo> depts) {
|
||||
for (SystemDeptVo dept : deptTbList) {
|
||||
depts.add(dept);
|
||||
List<SystemDeptVo> deptList = this.listDeptVoByPid(dept.getId());
|
||||
if (CollUtil.isNotEmpty(deptList)) {
|
||||
this.queryRelationDeptByArgs(deptList, depts);
|
||||
}
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "部门数据", SystemDeptExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
public List<SystemDeptTb> listPidNonNull() {
|
||||
private List<SystemDeptVo> listDeptVoByPid(Long pid) {
|
||||
return KitBeanUtil.copyToList(this.listDeptByPid(pid), SystemDeptVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询同级与上级数据
|
||||
*
|
||||
* @param dept /
|
||||
* @param deptList /
|
||||
* @return /
|
||||
*/
|
||||
private List<SystemDeptVo> querySuperiorDeptByPid(SystemDeptVo dept, List<SystemDeptVo> deptList) {
|
||||
if (dept.getPid() == null) {
|
||||
deptList.addAll(this.listRootDept());
|
||||
return deptList;
|
||||
}
|
||||
deptList.addAll(this.listDeptVoByPid(dept.getPid()));
|
||||
return querySuperiorDeptByPid(this.getDeptVoById(dept.getPid()), deptList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有根部门
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
private List<SystemDeptVo> listRootDept() {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getEnabled, 1);
|
||||
wrapper.isNotNull(SystemDeptTb::getPid);
|
||||
wrapper.isNull(SystemDeptTb::getPid);
|
||||
return KitBeanUtil.copyToList(systemDeptMapper.selectList(wrapper), SystemDeptVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门id查询部门信息 -> TestPassed
|
||||
*
|
||||
* @param id 部门id
|
||||
* @return /
|
||||
*/
|
||||
private SystemDeptTb getDeptById(Long id) {
|
||||
return systemDeptMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父部门id统计数量
|
||||
*
|
||||
* @param pid 父部门id
|
||||
* @return /
|
||||
*/
|
||||
private long countDeptByPid(Long pid) {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemDeptTb::getPid, pid);
|
||||
return systemDeptMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 筛选出 list 中没有父部门(即 pid 不在其他部门 id 列表中的部门)的部门列表
|
||||
*/
|
||||
private List<SystemDeptTb> filterRootDeptList(List<SystemDeptTb> list) {
|
||||
List<SystemDeptTb> deptList = new ArrayList<>();
|
||||
// 使用 Set 存储所有部门的 id
|
||||
Set<Long> idSet = list.stream().map(SystemDeptTb::getId).collect(Collectors.toSet());
|
||||
// 遍历部门列表, 筛选出没有父部门的部门
|
||||
for (SystemDeptTb dept : list) {
|
||||
if (!idSet.contains(dept.getPid())) {
|
||||
deptList.add(dept);
|
||||
}
|
||||
}
|
||||
return deptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据复杂条件查询部门集合
|
||||
*
|
||||
* @param args /
|
||||
* @return /
|
||||
*/
|
||||
private List<SystemDeptTb> queryDeptByArgs(SystemQueryDeptArgs args) {
|
||||
LambdaQueryWrapper<SystemDeptTb> wrapper = new LambdaQueryWrapper<>();
|
||||
if (args != null) {
|
||||
wrapper.in(CollUtil.isNotEmpty(args.getIds()), SystemDeptTb::getId, args.getIds());
|
||||
wrapper.like(StrUtil.isNotBlank(args.getName()), SystemDeptTb::getName, args.getName());
|
||||
wrapper.eq(args.getEnabled() != null, SystemDeptTb::getEnabled, args.getEnabled());
|
||||
wrapper.eq(args.getPid() != null, SystemDeptTb::getPid, args.getPid());
|
||||
wrapper.isNull(args.getPidIsNull() != null, SystemDeptTb::getPid);
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemDeptTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByAsc(SystemDeptTb::getDeptSort);
|
||||
return systemDeptMapper.selectList(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-5
@@ -31,14 +31,14 @@ import cn.odboy.util.KitValidUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class SystemDictDetailService {
|
||||
@@ -84,6 +84,11 @@ public class SystemDictDetailService {
|
||||
systemDictDetailMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典id集合删除字典明细
|
||||
*
|
||||
* @param ids 字典id集合
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteDictDetailByDictIds(Set<Long> ids) {
|
||||
if (CollUtil.isNotEmpty(ids)) {
|
||||
@@ -100,8 +105,10 @@ public class SystemDictDetailService {
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
public KitPageResult<SystemDictDetailVo> searchDictDetail(SystemQueryDictDetailArgs args,
|
||||
Page<SystemDictDetailTb> page) {
|
||||
public KitPageResult<SystemDictDetailVo> searchDictDetail(
|
||||
SystemQueryDictDetailArgs args,
|
||||
Page<SystemDictDetailTb> page
|
||||
) {
|
||||
IPage<SystemDictDetailVo> iPage = systemDictDetailMapper.selectPageByArgs(page, args);
|
||||
List<Long> dictIds =
|
||||
iPage.getRecords().stream().map(SystemDictDetailVo::getDictId).collect(Collectors.toList());
|
||||
|
||||
+29
-11
@@ -29,13 +29,13 @@ import cn.odboy.util.KitPageUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class SystemDictService {
|
||||
@@ -96,19 +96,24 @@ public class SystemDictService {
|
||||
return KitPageUtil.toPage(selectPage);
|
||||
}
|
||||
|
||||
private void injectQueryParams(SystemQueryDictArgs args, LambdaQueryWrapper<SystemDictTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemDictTb::getName, args.getBlurry()).or()
|
||||
.like(SystemDictTb::getDescription, args.getBlurry()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂条件查询字典列表
|
||||
*
|
||||
* @param args /
|
||||
* @return /
|
||||
*/
|
||||
public List<SystemDictTb> queryDictByArgs(SystemQueryDictArgs args) {
|
||||
LambdaQueryWrapper<SystemDictTb> wrapper = new LambdaQueryWrapper<>();
|
||||
this.injectQueryParams(args, wrapper);
|
||||
return systemDictMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出字典数据
|
||||
*
|
||||
* @param response /
|
||||
* @param args /
|
||||
*/
|
||||
public void exportDictXlsx(HttpServletResponse response, SystemQueryDictArgs args) {
|
||||
List<SystemDictTb> systemDictTbs = this.queryDictByArgs(args);
|
||||
List<SystemDictExportRowVo> rowVos = new ArrayList<>();
|
||||
@@ -136,4 +141,17 @@ public class SystemDictService {
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "字典数据", SystemDictExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*
|
||||
* @param args /
|
||||
* @param wrapper /
|
||||
*/
|
||||
private void injectQueryParams(SystemQueryDictArgs args, LambdaQueryWrapper<SystemDictTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemDictTb::getName, args.getBlurry()).or()
|
||||
.like(SystemDictTb::getDescription, args.getBlurry()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-14
@@ -30,11 +30,11 @@ import cn.odboy.system.dal.model.request.SystemSendEmailArgs;
|
||||
import cn.odboy.system.dal.mysql.SystemEmailConfigMapper;
|
||||
import cn.odboy.util.KitDesEncryptUtil;
|
||||
import cn.odboy.util.KitResourceTemplateUtil;
|
||||
import java.util.Collections;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Collections;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -108,19 +108,6 @@ public class SystemEmailService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验邮箱验证码 -> TestPassed
|
||||
*/
|
||||
public void checkEmailCaptchaV1(SystemCaptchaBizEnum biEnum, String email, String code) {
|
||||
String redisKey = biEnum.getRedisKey() + email;
|
||||
String value = redisHelper.get(redisKey, String.class);
|
||||
if (value == null || !value.equals(code)) {
|
||||
throw new BadRequestException("无效验证码");
|
||||
} else {
|
||||
redisHelper.del(redisKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送给邮箱验证码
|
||||
*/
|
||||
@@ -148,11 +135,19 @@ public class SystemEmailService {
|
||||
sendEmail(sendEmailRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询邮箱配置
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public SystemEmailConfigTb getLastEmailConfig() {
|
||||
SystemEmailConfigTb systemEmailConfigTb = systemEmailConfigMapper.selectById(1L);
|
||||
return systemEmailConfigTb == null ? new SystemEmailConfigTb() : systemEmailConfigTb;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验邮箱验证码 -> TestPassed
|
||||
*/
|
||||
public void checkEmailCaptcha(SystemCheckEmailCaptchaArgs args) {
|
||||
SystemCaptchaBizEnum biEnum = SystemCaptchaBizEnum.getByBizCode(args.getBizCode());
|
||||
if (biEnum == null) {
|
||||
@@ -160,4 +155,14 @@ public class SystemEmailService {
|
||||
}
|
||||
this.checkEmailCaptchaV1(biEnum, args.getEmail(), args.getCode());
|
||||
}
|
||||
|
||||
public void checkEmailCaptchaV1(SystemCaptchaBizEnum biEnum, String email, String code) {
|
||||
String redisKey = biEnum.getRedisKey() + email;
|
||||
String value = redisHelper.get(redisKey, String.class);
|
||||
if (value == null || !value.equals(code)) {
|
||||
throw new BadRequestException("无效验证码");
|
||||
} else {
|
||||
redisHelper.del(redisKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-20
@@ -29,13 +29,13 @@ import cn.odboy.util.KitPageUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class SystemJobService {
|
||||
@@ -119,6 +119,22 @@ public class SystemJobService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出岗位数据 -> TestPassed
|
||||
*/
|
||||
public void exportJobXlsx(HttpServletResponse response, SystemQueryJobArgs args) {
|
||||
List<SystemJobTb> systemJobTbs = this.queryJobByArgs(args);
|
||||
List<SystemJobExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemJobTb dataObject : systemJobTbs) {
|
||||
SystemJobExportRowVo rowVo = new SystemJobExportRowVo();
|
||||
rowVo.setName(dataObject.getName());
|
||||
rowVo.setEnabled(dataObject.getEnabled() ? "启用" : "停用");
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "岗位数据", SystemJobExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据岗位名称查询岗位是否存在 -> TestPassed
|
||||
*/
|
||||
@@ -138,6 +154,12 @@ public class SystemJobService {
|
||||
return systemJobMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*
|
||||
* @param args /
|
||||
* @param wrapper /
|
||||
*/
|
||||
private void injectQueryParams(SystemQueryJobArgs args, LambdaQueryWrapper<SystemJobTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.like(StrUtil.isNotBlank(args.getName()), SystemJobTb::getName, args.getName());
|
||||
@@ -148,20 +170,4 @@ public class SystemJobService {
|
||||
}
|
||||
wrapper.orderByDesc(SystemJobTb::getJobSort, SystemJobTb::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出岗位数据 -> TestPassed
|
||||
*/
|
||||
public void exportJobXlsx(HttpServletResponse response, SystemQueryJobArgs args) {
|
||||
List<SystemJobTb> systemJobTbs = this.queryJobByArgs(args);
|
||||
List<SystemJobExportRowVo> rowVos = new ArrayList<>();
|
||||
for (SystemJobTb dataObject : systemJobTbs) {
|
||||
SystemJobExportRowVo rowVo = new SystemJobExportRowVo();
|
||||
rowVo.setName(dataObject.getName());
|
||||
rowVo.setEnabled(dataObject.getEnabled() ? "启用" : "停用");
|
||||
rowVo.setCreateTime(dataObject.getCreateTime());
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "岗位数据", SystemJobExportRowVo.class, rowVos);
|
||||
}
|
||||
}
|
||||
|
||||
+29
-21
@@ -35,16 +35,16 @@ import cn.odboy.util.KitPageUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -133,29 +133,13 @@ public class SystemLocalStorageService {
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
public KitPageResult<SystemLocalStorageTb> searchLocalStorage(SystemQueryStorageArgs args,
|
||||
Page<SystemLocalStorageTb> page) {
|
||||
public KitPageResult<SystemLocalStorageTb> searchLocalStorage(SystemQueryStorageArgs args, Page<SystemLocalStorageTb> page) {
|
||||
LambdaQueryWrapper<SystemLocalStorageTb> wrapper = new LambdaQueryWrapper<>();
|
||||
this.injectQueryParams(args, wrapper);
|
||||
Page<SystemLocalStorageTb> selectPage = systemLocalStorageMapper.selectPage(page, wrapper);
|
||||
return KitPageUtil.toPage(selectPage);
|
||||
}
|
||||
|
||||
private void injectQueryParams(SystemQueryStorageArgs args, LambdaQueryWrapper<SystemLocalStorageTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
|
||||
c -> c.like(SystemLocalStorageTb::getName, args.getBlurry()).or()
|
||||
.like(SystemLocalStorageTb::getSuffix, args.getBlurry()).or()
|
||||
.like(SystemLocalStorageTb::getType, args.getBlurry()).or()
|
||||
.like(SystemLocalStorageTb::getCreateBy, args.getBlurry()));
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemLocalStorageTb::getUpdateTime, args.getCreateTime().get(0),
|
||||
args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(SystemLocalStorageTb::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件上传记录 -> TestPassed
|
||||
*/
|
||||
@@ -186,4 +170,28 @@ public class SystemLocalStorageService {
|
||||
List<SystemLocalStorageExportRowVo> rowVos = KitBeanUtil.copyToList(systemLocalStorageTbs, SystemLocalStorageExportRowVo.class);
|
||||
KitExcelExporter.exportSimple(response, "文件上传记录数据", SystemLocalStorageExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*
|
||||
* @param args /
|
||||
* @param wrapper /
|
||||
*/
|
||||
private void injectQueryParams(SystemQueryStorageArgs args, LambdaQueryWrapper<SystemLocalStorageTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.and(
|
||||
StrUtil.isNotBlank(args.getBlurry()),
|
||||
c -> c.like(SystemLocalStorageTb::getName, args.getBlurry()).or()
|
||||
.like(SystemLocalStorageTb::getSuffix, args.getBlurry()).or()
|
||||
.like(SystemLocalStorageTb::getType, args.getBlurry()).or()
|
||||
.like(SystemLocalStorageTb::getCreateBy, args.getBlurry())
|
||||
);
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemLocalStorageTb::getUpdateTime, args.getCreateTime().get(0),
|
||||
args.getCreateTime().get(1)
|
||||
);
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(SystemLocalStorageTb::getId);
|
||||
}
|
||||
}
|
||||
|
||||
+175
-175
@@ -95,56 +95,6 @@ public class SystemMenuService {
|
||||
this.updateMenuSubCnt(args.getPid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据组件名称查询菜单是否存在 -> TestPassed
|
||||
*
|
||||
* @param componentName 组件名称
|
||||
* @return /
|
||||
*/
|
||||
private boolean existMenuWithComponentName(String componentName) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getComponentName, componentName);
|
||||
return systemMenuMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据组件名称查询菜单是否存在 -> TestPassed
|
||||
*
|
||||
* @param componentName 组件名称
|
||||
* @return /
|
||||
*/
|
||||
private boolean existMenuWithComponentNameNeSelf(String componentName, Long currentMenuId) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getComponentName, componentName);
|
||||
wrapper.ne(SystemMenuTb::getId, currentMenuId);
|
||||
return systemMenuMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单标题查询菜单是否存在 -> TestPassed
|
||||
*
|
||||
* @param title 菜单标题
|
||||
* @return /
|
||||
*/
|
||||
private boolean existMenuWithTitle(String title) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getTitle, title);
|
||||
return systemMenuMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单标题查询菜单是否存在 -> TestPassed
|
||||
*
|
||||
* @param title 菜单标题
|
||||
* @return /
|
||||
*/
|
||||
private boolean existMenuWithTitleNeSelf(String title, Long currentMenuId) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getTitle, title);
|
||||
wrapper.ne(SystemMenuTb::getId, currentMenuId);
|
||||
return systemMenuMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑 -> TestPassed
|
||||
*
|
||||
@@ -222,7 +172,7 @@ public class SystemMenuService {
|
||||
}
|
||||
// 查询所有菜单数据
|
||||
List<SystemMenuTb> allMenus = systemMenuMapper.listAll();
|
||||
// 根据ID集合获取当前菜单和其子菜单
|
||||
// 根据ID集合查询当前菜单和其子菜单
|
||||
Set<Long> allMenuIds = this.getAllMenuIdsWithChildren(ids, allMenus);
|
||||
if (CollUtil.isNotEmpty(allMenuIds)) {
|
||||
// 删除角色菜单关联
|
||||
@@ -234,60 +184,6 @@ public class SystemMenuService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从所有菜单中找出指定ID及其子菜单ID
|
||||
*
|
||||
* @param rootIds 要删除的根菜单ID集合
|
||||
* @param allMenus 所有菜单数据
|
||||
* @return 包含根菜单及其所有子菜单的ID集合
|
||||
*/
|
||||
private Set<Long> getAllMenuIdsWithChildren(Set<Long> rootIds, List<SystemMenuTb> allMenus) {
|
||||
Set<Long> result = new HashSet<>(rootIds);
|
||||
Set<Long> currentLevelIds = new HashSet<>(rootIds);
|
||||
// 构建父ID到子菜单的映射
|
||||
Map<Long, List<SystemMenuTb>> parentToChildrenMap = allMenus.stream().filter(menu -> menu.getPid() != null)
|
||||
.collect(Collectors.groupingBy(SystemMenuTb::getPid));
|
||||
while (!currentLevelIds.isEmpty()) {
|
||||
Set<Long> nextLevelIds = new HashSet<>();
|
||||
// 对于当前层级的每个菜单ID,查找其子菜单
|
||||
for (Long parentId : currentLevelIds) {
|
||||
List<SystemMenuTb> children = parentToChildrenMap.get(parentId);
|
||||
if (children != null && !children.isEmpty()) {
|
||||
for (SystemMenuTb child : children) {
|
||||
if (result.add(child.getId())) { // 如果成功添加(之前不存在),则继续查找其子菜单
|
||||
nextLevelIds.add(child.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
currentLevelIds = nextLevelIds;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新被删除菜单的父菜单子节点计数
|
||||
*/
|
||||
private void updateParentMenuCounts(Set<Long> deletedMenuIds, List<SystemMenuTb> allMenus) {
|
||||
// 获取被删除菜单的父ID
|
||||
Set<Long> parentIds =
|
||||
allMenus.stream().filter(menu -> deletedMenuIds.contains(menu.getId()) && menu.getPid() != null)
|
||||
.map(SystemMenuTb::getPid).collect(Collectors.toSet());
|
||||
// 更新每个父菜单的子节点计数
|
||||
for (Long parentId : parentIds) {
|
||||
proxyService.updateMenuSubCnt(parentId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单id查询目录 -> TestPassed
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
private SystemMenuTb getMenuById(Long id) {
|
||||
return systemMenuMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateMenuSubCnt(Long menuId) {
|
||||
if (menuId != null) {
|
||||
@@ -341,24 +237,6 @@ public class SystemMenuService {
|
||||
return systemRoleMenuService.listMenuByRoleIds(roleIds, false);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 查询所有子节点, 包含自身ID
|
||||
// *
|
||||
// * @param menuList /
|
||||
// * @param menuSet /
|
||||
// * @return /
|
||||
// */
|
||||
// public Set<SystemMenuTb> queryChildMenuByArgs(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet) {
|
||||
// for (SystemMenuTb menu : menuList) {
|
||||
// menuSet.add(menu);
|
||||
// List<SystemMenuTb> menus = this.listMenuByPid(menu.getId());
|
||||
// if (CollUtil.isNotEmpty(menus)) {
|
||||
// queryChildMenuByArgs(menus, menuSet);
|
||||
// }
|
||||
// }
|
||||
// return menuSet;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 懒加载菜单数据
|
||||
*
|
||||
@@ -473,62 +351,10 @@ public class SystemMenuService {
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 MenuResponse
|
||||
*
|
||||
* @param menu /
|
||||
* @param menuVo /
|
||||
* @return /
|
||||
*/
|
||||
private SystemMenuRouterVo getMenuVo(SystemMenuVo menu, SystemMenuRouterVo menuVo) {
|
||||
SystemMenuRouterVo menuVo1 = new SystemMenuRouterVo();
|
||||
menuVo1.setMeta(menuVo.getMeta());
|
||||
// 非外链
|
||||
if (!menu.getIFrame()) {
|
||||
menuVo1.setPath("index");
|
||||
menuVo1.setName(menuVo.getName());
|
||||
menuVo1.setComponent(menuVo.getComponent());
|
||||
} else {
|
||||
menuVo1.setPath(menu.getPath());
|
||||
}
|
||||
return menuVo1;
|
||||
}
|
||||
|
||||
public List<SystemMenuTb> listMenuByIds(List<Long> ids) {
|
||||
return systemMenuMapper.selectByIds(ids);
|
||||
}
|
||||
|
||||
private Long countMenuByPid(Long pid) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getPid, pid);
|
||||
return systemMenuMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
private List<SystemMenuTb> queryMenuByArgs(SystemQueryMenuArgs args) {
|
||||
KitValidUtil.notNull(args);
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.isNull(args.getPidIsNull() != null, SystemMenuTb::getPid);
|
||||
wrapper.eq(args.getPid() != null, SystemMenuTb::getPid, args.getPid());
|
||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemMenuTb::getTitle, args.getBlurry()).or()
|
||||
.like(SystemMenuTb::getComponentName, args.getBlurry()).or()
|
||||
.like(SystemMenuTb::getPermission, args.getBlurry()));
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemMenuTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
wrapper.orderByAsc(SystemMenuTb::getMenuSort);
|
||||
return systemMenuMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询根目录 -> TestPassed
|
||||
*/
|
||||
private List<SystemMenuTb> listRootMenu() {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.isNull(SystemMenuTb::getPid);
|
||||
wrapper.orderByAsc(SystemMenuTb::getMenuSort);
|
||||
return systemMenuMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
public List<SystemMenuRouterVo> buildFrontMenus() {
|
||||
List<SystemMenuTb> originMenus = this.listMenuByUserId(KitSecurityHelper.getCurrentUserId());
|
||||
List<SystemMenuVo> targetMenus = this.buildMenuTree(originMenus);
|
||||
@@ -584,4 +410,178 @@ public class SystemMenuService {
|
||||
}
|
||||
KitExcelExporter.exportSimple(response, "菜单数据", SystemMenuExportRowVo.class, rowVos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 MenuResponse
|
||||
*
|
||||
* @param menu /
|
||||
* @param menuVo /
|
||||
* @return /
|
||||
*/
|
||||
private SystemMenuRouterVo getMenuVo(SystemMenuVo menu, SystemMenuRouterVo menuVo) {
|
||||
SystemMenuRouterVo menuVo1 = new SystemMenuRouterVo();
|
||||
menuVo1.setMeta(menuVo.getMeta());
|
||||
// 非外链
|
||||
if (!menu.getIFrame()) {
|
||||
menuVo1.setPath("index");
|
||||
menuVo1.setName(menuVo.getName());
|
||||
menuVo1.setComponent(menuVo.getComponent());
|
||||
} else {
|
||||
menuVo1.setPath(menu.getPath());
|
||||
}
|
||||
return menuVo1;
|
||||
}
|
||||
|
||||
private Long countMenuByPid(Long pid) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getPid, pid);
|
||||
return systemMenuMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
private List<SystemMenuTb> queryMenuByArgs(SystemQueryMenuArgs args) {
|
||||
KitValidUtil.notNull(args);
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.isNull(args.getPidIsNull() != null, SystemMenuTb::getPid);
|
||||
wrapper.eq(args.getPid() != null, SystemMenuTb::getPid, args.getPid());
|
||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemMenuTb::getTitle, args.getBlurry()).or()
|
||||
.like(SystemMenuTb::getComponentName, args.getBlurry()).or()
|
||||
.like(SystemMenuTb::getPermission, args.getBlurry()));
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemMenuTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
wrapper.orderByAsc(SystemMenuTb::getMenuSort);
|
||||
return systemMenuMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询根目录 -> TestPassed
|
||||
*/
|
||||
private List<SystemMenuTb> listRootMenu() {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.isNull(SystemMenuTb::getPid);
|
||||
wrapper.orderByAsc(SystemMenuTb::getMenuSort);
|
||||
return systemMenuMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据组件名称查询菜单是否存在 -> TestPassed
|
||||
*
|
||||
* @param componentName 组件名称
|
||||
* @return /
|
||||
*/
|
||||
private boolean existMenuWithComponentName(String componentName) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getComponentName, componentName);
|
||||
return systemMenuMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据组件名称查询菜单是否存在 -> TestPassed
|
||||
*
|
||||
* @param componentName 组件名称
|
||||
* @return /
|
||||
*/
|
||||
private boolean existMenuWithComponentNameNeSelf(String componentName, Long currentMenuId) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getComponentName, componentName);
|
||||
wrapper.ne(SystemMenuTb::getId, currentMenuId);
|
||||
return systemMenuMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单标题查询菜单是否存在 -> TestPassed
|
||||
*
|
||||
* @param title 菜单标题
|
||||
* @return /
|
||||
*/
|
||||
private boolean existMenuWithTitle(String title) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getTitle, title);
|
||||
return systemMenuMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单标题查询菜单是否存在 -> TestPassed
|
||||
*
|
||||
* @param title 菜单标题
|
||||
* @return /
|
||||
*/
|
||||
private boolean existMenuWithTitleNeSelf(String title, Long currentMenuId) {
|
||||
LambdaQueryWrapper<SystemMenuTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemMenuTb::getTitle, title);
|
||||
wrapper.ne(SystemMenuTb::getId, currentMenuId);
|
||||
return systemMenuMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从所有菜单中找出指定ID及其子菜单ID
|
||||
*
|
||||
* @param rootIds 要删除的根菜单ID集合
|
||||
* @param allMenus 所有菜单数据
|
||||
* @return 包含根菜单及其所有子菜单的ID集合
|
||||
*/
|
||||
private Set<Long> getAllMenuIdsWithChildren(Set<Long> rootIds, List<SystemMenuTb> allMenus) {
|
||||
Set<Long> result = new HashSet<>(rootIds);
|
||||
Set<Long> currentLevelIds = new HashSet<>(rootIds);
|
||||
// 构建父ID到子菜单的映射
|
||||
Map<Long, List<SystemMenuTb>> parentToChildrenMap = allMenus.stream().filter(menu -> menu.getPid() != null)
|
||||
.collect(Collectors.groupingBy(SystemMenuTb::getPid));
|
||||
while (!currentLevelIds.isEmpty()) {
|
||||
Set<Long> nextLevelIds = new HashSet<>();
|
||||
// 对于当前层级的每个菜单ID,查找其子菜单
|
||||
for (Long parentId : currentLevelIds) {
|
||||
List<SystemMenuTb> children = parentToChildrenMap.get(parentId);
|
||||
if (children != null && !children.isEmpty()) {
|
||||
for (SystemMenuTb child : children) {
|
||||
if (result.add(child.getId())) { // 如果成功添加(之前不存在),则继续查找其子菜单
|
||||
nextLevelIds.add(child.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
currentLevelIds = nextLevelIds;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新被删除菜单的父菜单子节点计数
|
||||
*/
|
||||
private void updateParentMenuCounts(Set<Long> deletedMenuIds, List<SystemMenuTb> allMenus) {
|
||||
// 查询被删除菜单的父ID
|
||||
Set<Long> parentIds =
|
||||
allMenus.stream().filter(menu -> deletedMenuIds.contains(menu.getId()) && menu.getPid() != null)
|
||||
.map(SystemMenuTb::getPid).collect(Collectors.toSet());
|
||||
// 更新每个父菜单的子节点计数
|
||||
for (Long parentId : parentIds) {
|
||||
proxyService.updateMenuSubCnt(parentId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单id查询目录 -> TestPassed
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
private SystemMenuTb getMenuById(Long id) {
|
||||
return systemMenuMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有子节点, 包含自身ID
|
||||
*
|
||||
* @param menuList /
|
||||
* @param menuSet /
|
||||
* @return /
|
||||
*/
|
||||
private Set<SystemMenuTb> queryChildMenuByArgs(List<SystemMenuTb> menuList, Set<SystemMenuTb> menuSet) {
|
||||
for (SystemMenuTb menu : menuList) {
|
||||
menuSet.add(menu);
|
||||
List<SystemMenuTb> menus = this.listMenuByPid(menu.getId());
|
||||
if (CollUtil.isNotEmpty(menus)) {
|
||||
queryChildMenuByArgs(menus, menuSet);
|
||||
}
|
||||
}
|
||||
return menuSet;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-9
@@ -20,13 +20,6 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.util.KitFileUtil;
|
||||
import cn.odboy.util.KitIPUtil;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import oshi.SystemInfo;
|
||||
@@ -39,6 +32,13 @@ import oshi.software.os.OSFileStore;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
import oshi.util.FormatUtil;
|
||||
import oshi.util.Util;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -141,8 +141,10 @@ public class SystemMonitorService {
|
||||
memoryInfo.put("total", FormatUtil.formatBytes(memory.getTotal()));
|
||||
memoryInfo.put("available", FormatUtil.formatBytes(memory.getAvailable()));
|
||||
memoryInfo.put("used", FormatUtil.formatBytes(memory.getTotal() - memory.getAvailable()));
|
||||
memoryInfo.put("usageRate",
|
||||
df.format((memory.getTotal() - memory.getAvailable()) / (double) memory.getTotal() * 100));
|
||||
memoryInfo.put(
|
||||
"usageRate",
|
||||
df.format((memory.getTotal() - memory.getAvailable()) / (double) memory.getTotal() * 100)
|
||||
);
|
||||
return memoryInfo;
|
||||
}
|
||||
|
||||
|
||||
+32
-2
@@ -21,9 +21,9 @@ import cn.odboy.system.dal.model.request.SystemQueryStorageArgs;
|
||||
import cn.odboy.system.dal.model.response.SystemOssStorageVo;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -35,13 +35,43 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*/
|
||||
public interface SystemOssStorageService extends IService<SystemOssStorageTb> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param args 查询条件
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
KitPageResult<SystemOssStorageVo> searchOssStorage(SystemQueryStorageArgs args, Page<SystemOssStorageTb> page);
|
||||
|
||||
/**
|
||||
* 复杂条件查询
|
||||
*
|
||||
* @param args 查询条件
|
||||
* @return /
|
||||
*/
|
||||
List<SystemOssStorageVo> queryOssStorage(SystemQueryStorageArgs args);
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param file /
|
||||
* @return /
|
||||
*/
|
||||
String uploadFile(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 根据id删除文件
|
||||
*
|
||||
* @param ids 文件记录id
|
||||
*/
|
||||
void deleteFileByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 导出文件上传记录
|
||||
*
|
||||
* @param response /
|
||||
* @param args 查询条件
|
||||
*/
|
||||
void exportOssStorageXlsx(HttpServletResponse response, SystemQueryStorageArgs args);
|
||||
}
|
||||
|
||||
+53
-40
@@ -37,15 +37,15 @@ import cn.odboy.util.KitPageUtil;
|
||||
import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.quartz.CronExpression;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class SystemQuartzJobService {
|
||||
@@ -59,19 +59,6 @@ public class SystemQuartzJobService {
|
||||
@Autowired
|
||||
private KitRedisHelper redisHelper;
|
||||
|
||||
/**
|
||||
* 验证Bean是不是合法的, 合法的定时任务 Bean 需要用 @Service 定义
|
||||
*
|
||||
* @param beanName Bean名称
|
||||
*/
|
||||
private void checkBean(String beanName) {
|
||||
// 避免调用攻击者可以从SpringContextHolder获得控制jdbcTemplate类
|
||||
// 并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,执行任意sql命令。
|
||||
if (!KitSpringBeanHolder.getAllServiceBeanName().contains(beanName)) {
|
||||
throw new BadRequestException("非法的 Bean,请重新输入!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 -> TestPassed
|
||||
*
|
||||
@@ -207,28 +194,6 @@ public class SystemQuartzJobService {
|
||||
return KitPageUtil.toPage(systemQuartzJobMapper.selectPage(page, wrapper));
|
||||
}
|
||||
|
||||
private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper<SystemQuartzJobTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzJobTb::getJobName, args.getJobName());
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemQuartzJobTb::getUpdateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(SystemQuartzJobTb::getId);
|
||||
}
|
||||
|
||||
private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper<SystemQuartzLogTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzLogTb::getJobName, args.getJobName());
|
||||
wrapper.eq(args.getIsSuccess() != null, SystemQuartzLogTb::getIsSuccess, args.getIsSuccess());
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemQuartzLogTb::getCreateTime, args.getCreateTime().get(0),
|
||||
args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(SystemQuartzLogTb::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询日志 -> TestPassed
|
||||
*
|
||||
@@ -324,4 +289,52 @@ public class SystemQuartzJobService {
|
||||
public SystemQuartzJobTb getQuartzJobById(Long id) {
|
||||
return systemQuartzJobMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*
|
||||
* @param args /
|
||||
* @param wrapper /
|
||||
*/
|
||||
private void injectQuartzJobQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper<SystemQuartzJobTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzJobTb::getJobName, args.getJobName());
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemQuartzJobTb::getUpdateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(SystemQuartzJobTb::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*
|
||||
* @param args /
|
||||
* @param wrapper /
|
||||
*/
|
||||
private void injectQuartzLogQueryParams(SystemQueryQuartzJobArgs args, LambdaQueryWrapper<SystemQuartzLogTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.like(StrUtil.isNotBlank(args.getJobName()), SystemQuartzLogTb::getJobName, args.getJobName());
|
||||
wrapper.eq(args.getIsSuccess() != null, SystemQuartzLogTb::getIsSuccess, args.getIsSuccess());
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemQuartzLogTb::getCreateTime, args.getCreateTime().get(0),
|
||||
args.getCreateTime().get(1)
|
||||
);
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(SystemQuartzLogTb::getId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证Bean是不是合法的, 合法的定时任务 Bean 需要用 @Service 定义
|
||||
*
|
||||
* @param beanName Bean名称
|
||||
*/
|
||||
private void checkBean(String beanName) {
|
||||
// 避免调用攻击者可以从SpringContextHolder获得控制jdbcTemplate类
|
||||
// 并使用getDeclaredMethod调用jdbcTemplate的queryForMap函数,执行任意sql命令。
|
||||
if (!KitSpringBeanHolder.getAllServiceBeanName().contains(beanName)) {
|
||||
throw new BadRequestException("非法的 Bean,请重新输入!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -20,12 +20,12 @@ import cn.odboy.system.dal.dataobject.SystemDeptTb;
|
||||
import cn.odboy.system.dal.dataobject.SystemRoleDeptTb;
|
||||
import cn.odboy.system.dal.mysql.SystemRoleDeptMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class SystemRoleDeptService {
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ public class SystemRoleMenuService {
|
||||
// menuWrapper.ne(SystemMenuTb::getType, 2);
|
||||
// menuWrapper.orderByAsc(SystemMenuTb::getMenuSort);
|
||||
// return systemMenuMapper.selectList(menuWrapper);
|
||||
if (hasButton){
|
||||
if (hasButton) {
|
||||
return systemRoleMenuMapper.listMenuWithRoleIds(roleIds);
|
||||
}
|
||||
return systemRoleMenuMapper.listMenuWithRoleIdsNeButton(roleIds);
|
||||
|
||||
+64
-29
@@ -66,7 +66,7 @@ public class SystemRoleService {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveRole(SystemCreateRoleArgs args) {
|
||||
checkRoleLevels(args.getLevel());
|
||||
this.checkRoleLevels(args.getLevel());
|
||||
if (this.existRoleWithName(args.getName())) {
|
||||
throw new BadRequestException("角色名称已存在");
|
||||
}
|
||||
@@ -78,19 +78,6 @@ public class SystemRoleService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean existRoleWithName(String name) {
|
||||
LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemRoleTb::getName, name);
|
||||
return systemRoleMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
private boolean existRoleWithNameNeSelf(String name, Long roleId) {
|
||||
LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemRoleTb::getName, name);
|
||||
wrapper.eq(SystemRoleTb::getId, roleId);
|
||||
return systemRoleMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 -> TestPassed
|
||||
*
|
||||
@@ -98,7 +85,7 @@ public class SystemRoleService {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateRoleById(SystemRoleVo args) {
|
||||
checkRoleLevels(args.getLevel());
|
||||
this.checkRoleLevels(args.getLevel());
|
||||
SystemRoleTb role = systemRoleMapper.selectById(args.getId());
|
||||
if (this.existRoleWithNameNeSelf(args.getName(), role.getId())) {
|
||||
throw new BadRequestException("角色名称已存在");
|
||||
@@ -125,7 +112,7 @@ public class SystemRoleService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateBindMenuById(SystemRoleVo args) {
|
||||
SystemRoleTb role = systemRoleMapper.selectById(args.getId());
|
||||
checkRoleLevels(role.getLevel());
|
||||
this.checkRoleLevels(role.getLevel());
|
||||
// 更新菜单
|
||||
systemRoleMenuService.deleteRoleMenuByRoleId(role.getId());
|
||||
Set<SystemMenuTb> menus = args.getMenus();
|
||||
@@ -143,7 +130,7 @@ public class SystemRoleService {
|
||||
public void deleteRoleByIds(Set<Long> ids) {
|
||||
List<Integer> roleLevels = systemRoleMapper.listRoleLevelByRoleIds(new ArrayList<>(ids));
|
||||
for (Integer roleLevel : roleLevels) {
|
||||
checkRoleLevels(roleLevel);
|
||||
this.checkRoleLevels(roleLevel);
|
||||
}
|
||||
// 验证是否被用户关联
|
||||
this.verifyBindRelationByIds(ids);
|
||||
@@ -176,17 +163,6 @@ public class SystemRoleService {
|
||||
return systemRoleMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
private void injectQueryParams(SystemQueryRoleArgs args, LambdaQueryWrapper<SystemRoleTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemRoleTb::getName, args.getBlurry()).or()
|
||||
.like(SystemRoleTb::getDescription, args.getBlurry()));
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemRoleTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByAsc(SystemRoleTb::getLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询角色 -> TestPassed
|
||||
*
|
||||
@@ -239,6 +215,12 @@ public class SystemRoleService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色id查询用户可访问的部门和菜单信息
|
||||
*
|
||||
* @param id 角色id
|
||||
* @return /
|
||||
*/
|
||||
public SystemRoleVo getRoleVoById(Long id) {
|
||||
SystemRoleTb roleTb = systemRoleMapper.selectById(id);
|
||||
if (roleTb == null) {
|
||||
@@ -247,8 +229,55 @@ public class SystemRoleService {
|
||||
return systemUserRoleService.convertToRoleVo(roleTb);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前用户角色级别
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public Dict getCurrentUserRoleLevel() {
|
||||
return Dict.create().set("level", checkRoleLevels(null));
|
||||
return Dict.create().set("level", this.checkRoleLevels(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*
|
||||
* @param args /
|
||||
* @param wrapper /
|
||||
*/
|
||||
private void injectQueryParams(SystemQueryRoleArgs args, LambdaQueryWrapper<SystemRoleTb> wrapper) {
|
||||
if (args != null) {
|
||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()), c -> c.like(SystemRoleTb::getName, args.getBlurry()).or()
|
||||
.like(SystemRoleTb::getDescription, args.getBlurry()));
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemRoleTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByAsc(SystemRoleTb::getLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询角色名称是否存在
|
||||
*
|
||||
* @param name 角色名称
|
||||
* @return /
|
||||
*/
|
||||
private boolean existRoleWithName(String name) {
|
||||
LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemRoleTb::getName, name);
|
||||
return systemRoleMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询角色名称是否存在(排除本身)
|
||||
*
|
||||
* @param name 角色名称
|
||||
* @return /
|
||||
*/
|
||||
private boolean existRoleWithNameNeSelf(String name, Long roleId) {
|
||||
LambdaQueryWrapper<SystemRoleTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemRoleTb::getName, name);
|
||||
wrapper.eq(SystemRoleTb::getId, roleId);
|
||||
return systemRoleMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,6 +296,12 @@ public class SystemRoleService {
|
||||
return min;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出部门数据
|
||||
*
|
||||
* @param response /
|
||||
* @param args /
|
||||
*/
|
||||
public void exportRoleXlsx(HttpServletResponse response, SystemQueryRoleArgs args) {
|
||||
List<SystemRoleTb> systemRoleVos = this.queryRoleByArgs(args, null);
|
||||
List<SystemRoleExportRowVo> rowVos = new ArrayList<>();
|
||||
|
||||
+1
-1
@@ -18,9 +18,9 @@ package cn.odboy.system.service;
|
||||
import cn.odboy.system.dal.dataobject.SystemUserTb;
|
||||
import cn.odboy.system.dal.mysql.SystemUserMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import java.util.Set;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class SystemUserDeptService {
|
||||
|
||||
+3
-3
@@ -20,12 +20,12 @@ import cn.odboy.system.dal.dataobject.SystemJobTb;
|
||||
import cn.odboy.system.dal.dataobject.SystemUserJobTb;
|
||||
import cn.odboy.system.dal.mysql.SystemUserJobMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class SystemUserJobService {
|
||||
|
||||
+179
-108
@@ -45,6 +45,13 @@ import cn.odboy.util.xlsx.KitExcelExporter;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -54,13 +61,6 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
public class SystemUserService {
|
||||
@@ -117,27 +117,6 @@ public class SystemUserService {
|
||||
systemUserRoleService.batchInsertUserRole(args.getRoles(), record.getId());
|
||||
}
|
||||
|
||||
private boolean existUserWithPhone(String phone) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getPhone, phone);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
private boolean existUserWithEmail(String email) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getEmail, email);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
private boolean existUserWithUsername(String username) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getUsername, username);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑用户 -> TestPassed
|
||||
*
|
||||
@@ -178,27 +157,6 @@ public class SystemUserService {
|
||||
systemUserRoleService.batchInsertUserRole(args.getRoles(), args.getId());
|
||||
}
|
||||
|
||||
private boolean existUserWithPhoneNeSelf(String phone, Long currentUserId) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getPhone, phone);
|
||||
wrapper.ne(SystemUserTb::getId, currentUserId);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
private boolean existUserWithEmailNeSelf(String email, Long currentUserId) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getEmail, email);
|
||||
wrapper.ne(SystemUserTb::getId, currentUserId);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
private boolean existUserWithUsernameNeSelf(String username, Long currentUserId) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getUsername, username);
|
||||
wrapper.ne(SystemUserTb::getId, currentUserId);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户自助修改资料 -> TestPassed
|
||||
*
|
||||
@@ -354,8 +312,8 @@ public class SystemUserService {
|
||||
* @return /
|
||||
*/
|
||||
public KitPageResult<SystemUserVo> searchUserByArgs(SystemQueryUserArgs args, Page<SystemUserTb> page) {
|
||||
// 查询用户基本信息
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = this.buildUserQueryWrapper(args);
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
this.injectQueryParams(args, wrapper);
|
||||
IPage<SystemUserTb> userPage = systemUserMapper.selectPage(page, wrapper);
|
||||
List<SystemUserTb> users = userPage.getRecords();
|
||||
// 转换为SystemUserVo并关联查询
|
||||
@@ -363,11 +321,24 @@ public class SystemUserService {
|
||||
return KitPageUtil.toPage(userVos, userPage.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 复杂条件统计用户数量
|
||||
*
|
||||
* @param args /
|
||||
* @return /
|
||||
*/
|
||||
public long countUserByArgs(SystemQueryUserArgs args) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = this.buildUserQueryWrapper(args);
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
this.injectQueryParams(args, wrapper);
|
||||
return systemUserMapper.selectCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊查询用户基础信息,限制返回的条数
|
||||
*
|
||||
* @param pageArgs 分页参数
|
||||
* @return /
|
||||
*/
|
||||
public List<KitSelectOptionVo> queryUserMetadataOptions(KitPageArgs<SystemQueryUserArgs> pageArgs) {
|
||||
SystemQueryUserArgs args = pageArgs.getArgs();
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
@@ -392,62 +363,11 @@ public class SystemUserService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建用户查询条件 -> TestPassed
|
||||
* 根据用户名查询启用的用户信息
|
||||
*
|
||||
* @param args 查询条件
|
||||
* @param username 用户名
|
||||
* @return /
|
||||
*/
|
||||
private LambdaQueryWrapper<SystemUserTb> buildUserQueryWrapper(SystemQueryUserArgs args) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
if (args != null) {
|
||||
if (args.getId() != null) {
|
||||
wrapper.eq(SystemUserTb::getId, args.getId());
|
||||
}
|
||||
if (args.getEnabled() != null) {
|
||||
wrapper.eq(SystemUserTb::getEnabled, args.getEnabled());
|
||||
}
|
||||
if (CollUtil.isNotEmpty(args.getDeptIds())) {
|
||||
wrapper.in(SystemUserTb::getDeptId, args.getDeptIds());
|
||||
}
|
||||
if (StrUtil.isNotBlank(args.getBlurry())) {
|
||||
wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry()).or()
|
||||
.like(SystemUserTb::getNickName, args.getBlurry()).or().like(SystemUserTb::getEmail, args.getBlurry()));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemUserTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(SystemUserTb::getCreateTime);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为SystemUserVo并关联查询部门、角色、岗位信息 -> TestPassed
|
||||
*
|
||||
* @param user 用户基本信息
|
||||
* @param includePassword 是否包含用户密码
|
||||
* @return 包含关联信息的SystemUserVo
|
||||
*/
|
||||
private SystemUserVo convertToUserVo(SystemUserTb user, boolean includePassword) {
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
if (!includePassword) {
|
||||
// 查询用户时,清空密码
|
||||
user.setPassword(null);
|
||||
}
|
||||
SystemUserVo userVo = KitBeanUtil.copyToClass(user, SystemUserVo.class);
|
||||
// 查询关联的部门信息
|
||||
if (user.getDeptId() != null) {
|
||||
userVo.setDept(systemDeptService.getDeptVoById(user.getDeptId()));
|
||||
}
|
||||
// 查询关联的岗位信息
|
||||
userVo.setJobs(systemUserJobService.listUserJobByUserId(user.getId()));
|
||||
// 查询关联的角色信息
|
||||
userVo.setRoles(systemUserRoleService.listUserRoleByUserId(user.getId()));
|
||||
return userVo;
|
||||
}
|
||||
|
||||
public SystemUserTb getUserByUsername(String username) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getUsername, username);
|
||||
@@ -455,10 +375,22 @@ public class SystemUserService {
|
||||
return systemUserMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户的部门、岗位和角色信息,用户信息中有密码数据
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return /
|
||||
*/
|
||||
public SystemUserVo getUserVoWithPasswordByUsername(String username) {
|
||||
return this.convertToUserVo(this.getUserByUsername(username), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户的部门、岗位和角色信息,用户信息中无密码数据
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return /
|
||||
*/
|
||||
public SystemUserVo getUserVoByUsername(String username) {
|
||||
return this.convertToUserVo(this.getUserByUsername(username), false);
|
||||
}
|
||||
@@ -466,8 +398,10 @@ public class SystemUserService {
|
||||
/**
|
||||
* 聚合查询 -> TestPassed
|
||||
*/
|
||||
public KitPageResult<SystemUserVo> aggregationSearchUserByArgs(Page<SystemUserTb> page, SystemQueryUserArgs args,
|
||||
String currentUsername) {
|
||||
public KitPageResult<SystemUserVo> aggregationSearchUserByArgs(
|
||||
Page<SystemUserTb> page, SystemQueryUserArgs args,
|
||||
String currentUsername
|
||||
) {
|
||||
if (!ObjectUtils.isEmpty(args.getDeptId())) {
|
||||
args.getDeptIds().add(args.getDeptId());
|
||||
// 先查找是否存在子节点
|
||||
@@ -518,6 +452,143 @@ public class SystemUserService {
|
||||
rowVos.add(rowVo);
|
||||
}
|
||||
return rowVos;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询手机号是否存在
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @return /
|
||||
*/
|
||||
private boolean existUserWithPhone(String phone) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getPhone, phone);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询邮箱是否存在
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @return /
|
||||
*/
|
||||
private boolean existUserWithEmail(String email) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getEmail, email);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户名是否存在
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return /
|
||||
*/
|
||||
private boolean existUserWithUsername(String username) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getUsername, username);
|
||||
wrapper.eq(SystemUserTb::getEnabled, 1);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询手机号是否存在(排除指定用户)
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @param currentUserId 指定用户id
|
||||
* @return /
|
||||
*/
|
||||
private boolean existUserWithPhoneNeSelf(String phone, Long currentUserId) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getPhone, phone);
|
||||
wrapper.ne(SystemUserTb::getId, currentUserId);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询邮箱是否存在(排除指定用户)
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @param currentUserId 指定用户id
|
||||
* @return /
|
||||
*/
|
||||
private boolean existUserWithEmailNeSelf(String email, Long currentUserId) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getEmail, email);
|
||||
wrapper.ne(SystemUserTb::getId, currentUserId);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户名是否存在(排除指定用户)
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param currentUserId 指定用户id
|
||||
* @return /
|
||||
*/
|
||||
private boolean existUserWithUsernameNeSelf(String username, Long currentUserId) {
|
||||
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SystemUserTb::getUsername, username);
|
||||
wrapper.ne(SystemUserTb::getId, currentUserId);
|
||||
return systemUserMapper.exists(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询条件
|
||||
*
|
||||
* @param args /
|
||||
* @param wrapper /
|
||||
*/
|
||||
private void injectQueryParams(SystemQueryUserArgs args, LambdaQueryWrapper<SystemUserTb> wrapper) {
|
||||
if (args != null) {
|
||||
if (args.getId() != null) {
|
||||
wrapper.eq(SystemUserTb::getId, args.getId());
|
||||
}
|
||||
if (args.getEnabled() != null) {
|
||||
wrapper.eq(SystemUserTb::getEnabled, args.getEnabled());
|
||||
}
|
||||
if (CollUtil.isNotEmpty(args.getDeptIds())) {
|
||||
wrapper.in(SystemUserTb::getDeptId, args.getDeptIds());
|
||||
}
|
||||
if (StrUtil.isNotBlank(args.getBlurry())) {
|
||||
wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry()).or()
|
||||
.like(SystemUserTb::getNickName, args.getBlurry()).or().like(SystemUserTb::getEmail, args.getBlurry()));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemUserTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
|
||||
}
|
||||
}
|
||||
wrapper.orderByDesc(SystemUserTb::getCreateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为SystemUserVo并关联查询部门、角色、岗位信息 -> TestPassed
|
||||
*
|
||||
* @param user 用户基本信息
|
||||
* @param includePassword 是否包含用户密码
|
||||
* @return 包含关联信息的SystemUserVo
|
||||
*/
|
||||
private SystemUserVo convertToUserVo(SystemUserTb user, boolean includePassword) {
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
if (!includePassword) {
|
||||
// 查询用户时,清空密码
|
||||
user.setPassword(null);
|
||||
}
|
||||
SystemUserVo userVo = KitBeanUtil.copyToClass(user, SystemUserVo.class);
|
||||
// 查询关联的部门信息
|
||||
if (user.getDeptId() != null) {
|
||||
userVo.setDept(systemDeptService.getDeptVoById(user.getDeptId()));
|
||||
}
|
||||
// 查询关联的岗位信息
|
||||
userVo.setJobs(systemUserJobService.listUserJobByUserId(user.getId()));
|
||||
// 查询关联的角色信息
|
||||
userVo.setRoles(systemUserRoleService.listUserRoleByUserId(user.getId()));
|
||||
return userVo;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-10
@@ -39,13 +39,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -69,8 +69,10 @@ public class SystemMinioStorageServiceImpl extends ServiceImpl<SystemOssStorageM
|
||||
private SystemOssStorageMapper systemOssStorageMapper;
|
||||
|
||||
@Override
|
||||
public KitPageResult<SystemOssStorageVo> searchOssStorage(SystemQueryStorageArgs args,
|
||||
Page<SystemOssStorageTb> page) {
|
||||
public KitPageResult<SystemOssStorageVo> searchOssStorage(
|
||||
SystemQueryStorageArgs args,
|
||||
Page<SystemOssStorageTb> page
|
||||
) {
|
||||
IPage<SystemOssStorageVo> ossStorageTbs = this.selectOssStorageByArgs(args, page);
|
||||
for (SystemOssStorageVo storageVo : ossStorageTbs.getRecords()) {
|
||||
storageVo.setFileSizeDesc(KitFileUtil.getSize(storageVo.getFileSize()));
|
||||
@@ -78,18 +80,23 @@ public class SystemMinioStorageServiceImpl extends ServiceImpl<SystemOssStorageM
|
||||
return KitPageUtil.toPage(ossStorageTbs);
|
||||
}
|
||||
|
||||
private IPage<SystemOssStorageVo> selectOssStorageByArgs(SystemQueryStorageArgs args,
|
||||
Page<SystemOssStorageTb> page) {
|
||||
private IPage<SystemOssStorageVo> selectOssStorageByArgs(
|
||||
SystemQueryStorageArgs args,
|
||||
Page<SystemOssStorageTb> page
|
||||
) {
|
||||
KitValidUtil.notNull(args);
|
||||
LambdaQueryWrapper<SystemOssStorageTb> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.and(StrUtil.isNotBlank(args.getBlurry()),
|
||||
wrapper.and(
|
||||
StrUtil.isNotBlank(args.getBlurry()),
|
||||
c -> c.like(SystemOssStorageTb::getFileName, args.getBlurry()).or()
|
||||
.like(SystemOssStorageTb::getFilePrefix, args.getBlurry()).or()
|
||||
.like(SystemOssStorageTb::getFileMime, args.getBlurry()).or()
|
||||
.like(SystemOssStorageTb::getFileMd5, args.getBlurry()));
|
||||
.like(SystemOssStorageTb::getFileMd5, args.getBlurry())
|
||||
);
|
||||
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
|
||||
wrapper.between(SystemOssStorageTb::getUpdateTime, args.getCreateTime().get(0),
|
||||
args.getCreateTime().get(1));
|
||||
args.getCreateTime().get(1)
|
||||
);
|
||||
}
|
||||
wrapper.orderByAsc(SystemOssStorageTb::getId);
|
||||
return systemOssStorageMapper.selectPage(page, wrapper)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cutejava-module-task-v1</artifactId>
|
||||
<name>任务模块:强制停止任务线程</name>
|
||||
<name>任务模块V1:强制停止任务线程</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.odboy</groupId>
|
||||
|
||||
Reference in New Issue
Block a user