微调
This commit is contained in:
@@ -6,9 +6,9 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
druid:
|
druid:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://192.168.1.24:13306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=CTT
|
url: jdbc:mysql://127.0.0.1:3306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=CTT
|
||||||
username: root
|
username: root
|
||||||
password: njcnpqs
|
password: 123456
|
||||||
#初始化建立物理连接的个数、最小、最大连接数
|
#初始化建立物理连接的个数、最小、最大连接数
|
||||||
initial-size: 5
|
initial-size: 5
|
||||||
min-idle: 5
|
min-idle: 5
|
||||||
|
|||||||
@@ -43,6 +43,17 @@ public class DictTreeController extends BaseController {
|
|||||||
|
|
||||||
private final IDictTreeService dictTreeService;
|
private final IDictTreeService dictTreeService;
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@GetMapping("/likeName")
|
||||||
|
@ApiOperation("按照名称模糊查询字典树")
|
||||||
|
@ApiImplicitParam(name = "keyword", value = "查询参数", required = true)
|
||||||
|
public HttpResult<List<DictTree>> getDictTreeByKeyword(@RequestParam String keyword) {
|
||||||
|
String methodDescribe = getMethodDescribe("getDictTreeByKeyword");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, keyword);
|
||||||
|
List<DictTree> result = dictTreeService.getDictTreeByKeyword(keyword);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
@ApiOperation("新增字典树数据")
|
@ApiOperation("新增字典树数据")
|
||||||
|
|||||||
@@ -58,9 +58,17 @@ public interface IDictTreeService extends IService<DictTree> {
|
|||||||
List<DictTree> queryTree();
|
List<DictTree> queryTree();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据code查询自动树
|
* 根据code查询字典树
|
||||||
*
|
*
|
||||||
* @param code code
|
* @param code code
|
||||||
*/
|
*/
|
||||||
List<DictTree> queryByCodeList(String code);
|
List<DictTree> queryByCodeList(String code);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据关键字查询字典树
|
||||||
|
*
|
||||||
|
* @param keyword 关键字
|
||||||
|
* @return 字典树
|
||||||
|
*/
|
||||||
|
List<DictTree> getDictTreeByKeyword(String keyword);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,24 @@ package com.njcn.gather.system.dictionary.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.text.StrPool;
|
import cn.hutool.core.text.StrPool;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.gather.system.dictionary.mapper.DictTreeMapper;
|
import com.njcn.gather.system.dictionary.mapper.DictTreeMapper;
|
||||||
import com.njcn.gather.system.dictionary.pojo.param.DictTreeParam;
|
import com.njcn.gather.system.dictionary.pojo.param.DictTreeParam;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
import com.njcn.gather.system.dictionary.pojo.vo.DictTreeVO;
|
import com.njcn.gather.system.dictionary.pojo.vo.DictTreeVO;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||||
import com.njcn.gather.system.pojo.constant.DictConst;
|
import com.njcn.gather.system.pojo.constant.DictConst;
|
||||||
|
import com.njcn.gather.system.pojo.enums.SystemResponseEnum;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -75,10 +80,16 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteDictTree(String id) {
|
public boolean deleteDictTree(String id) {
|
||||||
boolean result = this.lambdaUpdate().set(DictTree::getState, DictConst.DELETE).in(DictTree::getId, id).update();
|
boolean result = false;
|
||||||
|
List<DictTree> childrenList = this.lambdaQuery().eq(DictTree::getState, DataStateEnum.ENABLE.getCode()).eq(DictTree::getPid, id).list();
|
||||||
|
if (CollectionUtils.isEmpty(childrenList)) {
|
||||||
|
result = this.lambdaUpdate().set(DictTree::getState, DataStateEnum.DELETED.getCode()).in(DictTree::getId, id).update();
|
||||||
// if (result) {
|
// if (result) {
|
||||||
// refreshDictTreeCache();
|
// refreshRolesFunctionsCache();
|
||||||
// }
|
// }
|
||||||
|
} else {
|
||||||
|
throw new BusinessException(SystemResponseEnum.EXISTS_CHILDREN_NOT_DELETE);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +169,39 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
|
|||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DictTree> getDictTreeByKeyword(String keyword) {
|
||||||
|
List<DictTree> dictTree = this.queryTree();
|
||||||
|
this.filterTreeByName(dictTree, keyword);
|
||||||
|
return dictTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DictTree> filterTreeByName(List<DictTree> tree, String keyword) {
|
||||||
|
if (CollectionUtils.isEmpty(tree) || !StrUtil.isNotBlank(keyword)) {
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
filter(tree, keyword);
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void filter(List<DictTree> list, String keyword) {
|
||||||
|
for (int i = list.size() - 1; i >= 0; i--) {
|
||||||
|
DictTree dictTree = list.get(i);
|
||||||
|
List<DictTree> children = dictTree.getChildren();
|
||||||
|
if (!dictTree.getName().contains(keyword)) {
|
||||||
|
if (!CollectionUtils.isEmpty(children)) {
|
||||||
|
filter(children, keyword);
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isEmpty(dictTree.getChildren())) {
|
||||||
|
list.remove(i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!CollectionUtils.isEmpty(children)) {
|
||||||
|
filter(children, keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<DictTree> getChildren(DictTree dictTree, List<DictTree> all) {
|
private List<DictTree> getChildren(DictTree dictTree, List<DictTree> all) {
|
||||||
return all.stream().filter(item -> item.getPid().equals(dictTree.getId())).peek(item -> {
|
return all.stream().filter(item -> item.getPid().equals(dictTree.getId())).peek(item -> {
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ public enum SystemResponseEnum {
|
|||||||
EXE_EMPTY_PARAM("A00361", "请检查定时器的id,定时器cron表达式,定时任务是否为空!"),
|
EXE_EMPTY_PARAM("A00361", "请检查定时器的id,定时器cron表达式,定时任务是否为空!"),
|
||||||
|
|
||||||
DICT_PQ_NAME_EXIST("A00389", "当前数据模型及相别下已存在相同名称"),
|
DICT_PQ_NAME_EXIST("A00389", "当前数据模型及相别下已存在相同名称"),
|
||||||
|
EXISTS_CHILDREN_NOT_DELETE("A00390", "当前字典下存在子字典,不能删除"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 审计日志模块异常响应
|
* 审计日志模块异常响应
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ public enum UserResponseEnum {
|
|||||||
EXISTS_SAME_MENU_CHILDREN("A010006", "当前菜单下已存在相同的子菜单"),
|
EXISTS_SAME_MENU_CHILDREN("A010006", "当前菜单下已存在相同的子菜单"),
|
||||||
EXISTS_CHILDREN_NOT_UPDATE("A010008", "该菜单下存在子节点,无法将菜单修改为按钮"),
|
EXISTS_CHILDREN_NOT_UPDATE("A010008", "该菜单下存在子节点,无法将菜单修改为按钮"),
|
||||||
EXISTS_CHILDREN_NOT_DELETE("A010007", "该节点下存在子节点,无法删除"),
|
EXISTS_CHILDREN_NOT_DELETE("A010007", "该节点下存在子节点,无法删除"),
|
||||||
ADMINSTRATOR_ROLE_CANNOT_DELETE("A010009", "超级管理员及管理员角色禁止删除"),;
|
SUPER_ADMINSTRATOR_ROLE_CANNOT_UPDATE("A010009", "禁止修改超级管理员角色"),
|
||||||
|
SUPER_ADMINSTRATOR_ROLE_CANNOT_DELETE("A010009", "禁止删除超级管理员角色"),;
|
||||||
|
|
||||||
private String code;
|
private String code;
|
||||||
private String message;
|
private String message;
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ public class SysFunctionController extends BaseController {
|
|||||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
@PostMapping("/list")
|
@GetMapping("/likeName")
|
||||||
@ApiOperation("分页查询菜单树")
|
@ApiOperation("按照名称模糊查询菜单树")
|
||||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
@ApiImplicitParam(name = "keyword", value = "查询参数", required = true)
|
||||||
public HttpResult<List<SysFunction>> list(@RequestBody @Validated SysFunctionParam.QueryParam queryParam) {
|
public HttpResult<List<SysFunction>> getFunctionTreeByKeyword(@RequestParam @Validated String keyword) {
|
||||||
String methodDescribe = getMethodDescribe("list");
|
String methodDescribe = getMethodDescribe("getFunctionTreeByKeyword");
|
||||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, keyword);
|
||||||
List<SysFunction> result = sysFunctionService.listFunction(queryParam);
|
List<SysFunction> result = sysFunctionService.getFunctionTreeByKeyword(keyword);
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,9 @@ public class SysFunctionParam {
|
|||||||
@Pattern(regexp = PatternRegex.FUNCTION_NAME, message = UserValidMessage.NAME_FORMAT_ERROR)
|
@Pattern(regexp = PatternRegex.FUNCTION_NAME, message = UserValidMessage.NAME_FORMAT_ERROR)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ApiModelProperty("资源类型")
|
// @ApiModelProperty("资源类型")
|
||||||
@Range(min = 0, max = 3, message = UserValidMessage.PARAM_FORMAT_ERROR)
|
// @Range(min = 0, max = 3, message = UserValidMessage.PARAM_FORMAT_ERROR)
|
||||||
private Integer type;
|
// private Integer type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ import java.util.List;
|
|||||||
public interface ISysFunctionService extends IService<SysFunction> {
|
public interface ISysFunctionService extends IService<SysFunction> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取菜单(资源)列表
|
* 根据关键字模糊查询菜单(资源)树
|
||||||
*
|
*
|
||||||
* @param queryParam 查询参数
|
* @param keyword 关键字
|
||||||
* @return 菜单列表
|
* @return 菜单(资源)树
|
||||||
*/
|
*/
|
||||||
List<SysFunction> listFunction(SysFunctionParam.QueryParam queryParam);
|
List<SysFunction> getFunctionTreeByKeyword(String keyword);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加菜单(资源)
|
* 添加菜单(资源)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.njcn.gather.user.user.service.impl;
|
package com.njcn.gather.user.user.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@@ -37,17 +36,10 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
|||||||
private final ISysRoleFunctionService sysRoleFunctionService;
|
private final ISysRoleFunctionService sysRoleFunctionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysFunction> listFunction(SysFunctionParam.QueryParam queryParam) {
|
public List<SysFunction> getFunctionTreeByKeyword(String keyword) {
|
||||||
LambdaQueryWrapper<SysFunction> wrapper = new LambdaQueryWrapper<>();
|
List<SysFunction> functionTree = this.getFunctionTree(true);
|
||||||
if (ObjectUtil.isNotNull(queryParam)) {
|
filterTreeByName(functionTree, keyword);
|
||||||
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), SysFunction::getName, queryParam.getName()).eq(ObjectUtil.isNotNull(queryParam.getType()), SysFunction::getType, queryParam.getType());
|
return functionTree;
|
||||||
}
|
|
||||||
wrapper.eq(SysFunction::getState, DataStateEnum.ENABLE.getCode());
|
|
||||||
List<SysFunction> allFunctions = this.list(wrapper);
|
|
||||||
return allFunctions.stream().filter(fun -> Objects.equals(FunctionConst.FATHER_PID, fun.getPid()))
|
|
||||||
.peek(funS -> funS.setChildren(getChildrenList(funS, allFunctions)))
|
|
||||||
.sorted(Comparator.comparingInt(SysFunction::getSort))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -200,4 +192,31 @@ public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFu
|
|||||||
throw new BusinessException(UserResponseEnum.EXISTS_SAME_MENU_CHILDREN);
|
throw new BusinessException(UserResponseEnum.EXISTS_SAME_MENU_CHILDREN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<SysFunction> filterTreeByName(List<SysFunction> tree, String keyword) {
|
||||||
|
if (CollectionUtils.isEmpty(tree) || !StrUtil.isNotBlank(keyword)) {
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
filter(tree, keyword);
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void filter(List<SysFunction> list, String keyword) {
|
||||||
|
for (int i = list.size() - 1; i >= 0; i--) {
|
||||||
|
SysFunction function = list.get(i);
|
||||||
|
List<SysFunction> children = function.getChildren();
|
||||||
|
if (!function.getName().contains(keyword)) {
|
||||||
|
if (!CollectionUtils.isEmpty(children)) {
|
||||||
|
filter(children, keyword);
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isEmpty(function.getChildren())) {
|
||||||
|
list.remove(i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!CollectionUtils.isEmpty(children)) {
|
||||||
|
filter(children, keyword);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -64,6 +64,13 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateRole(SysRoleParam.UpdateParam updateParam) {
|
public boolean updateRole(SysRoleParam.UpdateParam updateParam) {
|
||||||
checkRepeat(updateParam, true);
|
checkRepeat(updateParam, true);
|
||||||
|
//不能修改超级管理员角色
|
||||||
|
Integer count = this.lambdaQuery()
|
||||||
|
.in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR)
|
||||||
|
.eq(SysRole::getId, updateParam.getId()).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).count();
|
||||||
|
if (count > 0) {
|
||||||
|
throw new BusinessException(UserResponseEnum.SUPER_ADMINSTRATOR_ROLE_CANNOT_UPDATE);
|
||||||
|
}
|
||||||
SysRole role = new SysRole();
|
SysRole role = new SysRole();
|
||||||
BeanUtil.copyProperties(updateParam, role);
|
BeanUtil.copyProperties(updateParam, role);
|
||||||
return this.updateById(role);
|
return this.updateById(role);
|
||||||
@@ -71,12 +78,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteRole(List<String> ids) {
|
public boolean deleteRole(List<String> ids) {
|
||||||
//超级管理员、管理员角色不能删除
|
//不能删除超级管理员角色
|
||||||
Integer count = this.lambdaQuery()
|
Integer count = this.lambdaQuery()
|
||||||
.in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR, RoleConst.TYPE_ADMINISTRATOR)
|
.in(SysRole::getType, RoleConst.TYPE_SUPER_ADMINISTRATOR)
|
||||||
.in(SysRole::getId, ids).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).count();
|
.in(SysRole::getId, ids).eq(SysRole::getState, DataStateEnum.ENABLE.getCode()).count();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
throw new BusinessException(UserResponseEnum.ADMINSTRATOR_ROLE_CANNOT_DELETE);
|
throw new BusinessException(UserResponseEnum.SUPER_ADMINSTRATOR_ROLE_CANNOT_DELETE);
|
||||||
}
|
}
|
||||||
// 删除角色和用户的绑定
|
// 删除角色和用户的绑定
|
||||||
sysUserRoleService.deleteUserRoleByRoleIds(ids);
|
sysUserRoleService.deleteUserRoleByRoleIds(ids);
|
||||||
|
|||||||
Reference in New Issue
Block a user