微调
This commit is contained in:
@@ -43,6 +43,17 @@ public class DictTreeController extends BaseController {
|
||||
|
||||
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)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增字典树数据")
|
||||
|
||||
@@ -58,9 +58,17 @@ public interface IDictTreeService extends IService<DictTree> {
|
||||
List<DictTree> queryTree();
|
||||
|
||||
/**
|
||||
* 根据code查询自动树
|
||||
* 根据code查询字典树
|
||||
*
|
||||
* @param code 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.text.StrPool;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
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.pojo.param.DictTreeParam;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||
import com.njcn.gather.system.dictionary.pojo.vo.DictTreeVO;
|
||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||
import com.njcn.gather.system.pojo.constant.DictConst;
|
||||
import com.njcn.gather.system.pojo.enums.SystemResponseEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -75,10 +80,16 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
|
||||
|
||||
@Override
|
||||
public boolean deleteDictTree(String id) {
|
||||
boolean result = this.lambdaUpdate().set(DictTree::getState, DictConst.DELETE).in(DictTree::getId, id).update();
|
||||
// if (result) {
|
||||
// refreshDictTreeCache();
|
||||
// }
|
||||
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) {
|
||||
// refreshRolesFunctionsCache();
|
||||
// }
|
||||
} else {
|
||||
throw new BusinessException(SystemResponseEnum.EXISTS_CHILDREN_NOT_DELETE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -158,6 +169,39 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
|
||||
}).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) {
|
||||
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表达式,定时任务是否为空!"),
|
||||
|
||||
DICT_PQ_NAME_EXIST("A00389", "当前数据模型及相别下已存在相同名称"),
|
||||
EXISTS_CHILDREN_NOT_DELETE("A00390", "当前字典下存在子字典,不能删除"),
|
||||
|
||||
/**
|
||||
* 审计日志模块异常响应
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user