mirror of https://gitee.com/stylefeng/roses
【7.6.0】【dict】更新获取字典列表树接口
parent
d1cc285b63
commit
0c154bb625
|
@ -24,8 +24,6 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.dict.modular.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.dict.api.constants.DictConstants;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.pojo.TreeDictInfo;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
|
||||
|
@ -58,6 +56,18 @@ public class DictController {
|
|||
@Resource
|
||||
private DictService dictService;
|
||||
|
||||
/**
|
||||
* 获取树形字典列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/27 16:52
|
||||
*/
|
||||
@GetResource(name = "获取树形字典列表", path = "/dict/getDictTreeList")
|
||||
public ResponseData<List<TreeDictInfo>> getDictTreeList(@Validated(DictRequest.treeList.class) DictRequest dictRequest) {
|
||||
List<TreeDictInfo> treeDictList = this.dictService.getTreeDictList(dictRequest);
|
||||
return new SuccessResponseData<>(treeDictList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字典条目
|
||||
*
|
||||
|
@ -103,7 +113,7 @@ public class DictController {
|
|||
* @author fengshuonan
|
||||
* @since 2020/10/29 16:35
|
||||
*/
|
||||
@GetResource(name = "获取字典详情", path = "/dict/detail", requiredPermission = false)
|
||||
@GetResource(name = "获取字典详情", path = "/dict/detail")
|
||||
public ResponseData<SysDict> detail(@Validated(BaseRequest.detail.class) DictRequest dictRequest) {
|
||||
SysDict detail = this.dictService.detail(dictRequest);
|
||||
return new SuccessResponseData<>(detail);
|
||||
|
@ -115,47 +125,9 @@ public class DictController {
|
|||
* @author fengshuonan
|
||||
* @since 2020/10/29 16:35
|
||||
*/
|
||||
@GetResource(name = "获取字典列表", path = "/dict/list", requiredPermission = false)
|
||||
@GetResource(name = "获取字典列表", path = "/dict/list")
|
||||
public ResponseData<List<SysDict>> list(DictRequest dictRequest) {
|
||||
return new SuccessResponseData<>(this.dictService.findList(dictRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树形字典列表(antdv在用)
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2020/10/29 16:36
|
||||
*/
|
||||
@GetResource(name = "获取树形字典列表", path = "/dict/getDictTreeList", requiredPermission = false)
|
||||
public ResponseData<List<TreeDictInfo>> getDictTreeList(@Validated(DictRequest.treeList.class) DictRequest dictRequest) {
|
||||
List<TreeDictInfo> treeDictList = this.dictService.getTreeDictList(dictRequest);
|
||||
return new SuccessResponseData<>(treeDictList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统配置分组字典列表(分页)(给系统配置界面,左侧获取配置的分类用)
|
||||
*
|
||||
* @author chenjinlong
|
||||
* @since 2021/1/25 11:47
|
||||
*/
|
||||
@GetResource(name = "获取系统配置分组字典列表", path = "/dict/getConfigGroupPage", requiredPermission = false)
|
||||
public ResponseData<PageResult<SysDict>> getConfigGroupPage(DictRequest dictRequest) {
|
||||
dictRequest.setDictTypeCode(DictConstants.CONFIG_GROUP_DICT_TYPE_CODE);
|
||||
PageResult<SysDict> page = this.dictService.findPage(dictRequest);
|
||||
return new SuccessResponseData<>(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多语言字典列表(分页)(给多语言界面,左侧获取多语言的分类用)
|
||||
*
|
||||
* @author chenjinlong
|
||||
* @since 2021/1/25 11:47
|
||||
*/
|
||||
@GetResource(name = "获取多语言字典列表", path = "/dict/getLanguagesPage", requiredPermission = false)
|
||||
public ResponseData<PageResult<SysDict>> getLanguagesPage(DictRequest dictRequest) {
|
||||
dictRequest.setDictTypeCode(DictConstants.LANGUAGES_DICT_TYPE_CODE);
|
||||
PageResult<SysDict> page = this.dictService.findPage(dictRequest);
|
||||
return new SuccessResponseData<>(page);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
|||
import cn.stylefeng.roses.kernel.rule.tree.factory.base.AbstractTreeNode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -59,6 +60,12 @@ public class TreeDictInfo implements AbstractTreeNode<TreeDictInfo> {
|
|||
@ChineseDescription("字典名称")
|
||||
private String dictName;
|
||||
|
||||
/**
|
||||
* 排序,带小数点
|
||||
*/
|
||||
@ChineseDescription("排序")
|
||||
private BigDecimal dictSort;
|
||||
|
||||
/**
|
||||
* 上级字典id
|
||||
*/
|
||||
|
|
|
@ -47,14 +47,14 @@ public class DictRequest extends BaseRequest {
|
|||
/**
|
||||
* 字典id
|
||||
*/
|
||||
@NotNull(message = "id不能为空", groups = {edit.class, delete.class, detail.class, updateStatus.class})
|
||||
@NotNull(message = "id不能为空", groups = {edit.class, delete.class, detail.class})
|
||||
@ChineseDescription("字典id")
|
||||
private Long dictId;
|
||||
|
||||
/**
|
||||
* 字典编码
|
||||
*/
|
||||
@NotBlank(message = "字典编码不能为空", groups = {add.class, edit.class, validateAvailable.class})
|
||||
@NotBlank(message = "字典编码不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("字典编码")
|
||||
private String dictCode;
|
||||
|
||||
|
@ -78,11 +78,11 @@ public class DictRequest extends BaseRequest {
|
|||
private String dictEncode;
|
||||
|
||||
/**
|
||||
* 字典类型编码
|
||||
* 字典类型id
|
||||
*/
|
||||
@NotBlank(message = "字典类型编码不能为空", groups = {add.class, edit.class, treeList.class, dictZTree.class})
|
||||
@ChineseDescription("字典类型编码")
|
||||
private String dictTypeCode;
|
||||
@NotBlank(message = "字典类型id不能为空", groups = {add.class, edit.class, treeList.class})
|
||||
@ChineseDescription("字典类型id")
|
||||
private String dictTypeId;
|
||||
|
||||
/**
|
||||
* 字典简称
|
||||
|
@ -109,8 +109,8 @@ public class DictRequest extends BaseRequest {
|
|||
/**
|
||||
* 状态(1:启用,2:禁用),参考 StatusEnum
|
||||
*/
|
||||
@NotNull(message = "状态不能为空", groups = {updateStatus.class})
|
||||
@StatusValue(groups = updateStatus.class)
|
||||
@NotNull(message = "状态不能为空", groups = {add.class, edit.class})
|
||||
@StatusValue(groups = {add.class, edit.class})
|
||||
@ChineseDescription("状态")
|
||||
private Integer statusFlag;
|
||||
|
||||
|
@ -127,12 +127,6 @@ public class DictRequest extends BaseRequest {
|
|||
@ChineseDescription("所有的父级id")
|
||||
private String dictPids;
|
||||
|
||||
/**
|
||||
* 字典类型id,用在作为查询条件
|
||||
*/
|
||||
@ChineseDescription("字典类型id")
|
||||
private Long dictTypeId;
|
||||
|
||||
/**
|
||||
* 获取树形列表
|
||||
*/
|
||||
|
@ -140,18 +134,4 @@ public class DictRequest extends BaseRequest {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验编码是否重复
|
||||
*/
|
||||
public @interface validateAvailable {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验ztree必备参数
|
||||
*/
|
||||
public @interface dictZTree {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,14 @@ import java.util.List;
|
|||
*/
|
||||
public interface DictService extends IService<SysDict>, DictApi {
|
||||
|
||||
/**
|
||||
* 获取树形字典列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/6/27 16:58
|
||||
*/
|
||||
List<TreeDictInfo> getTreeDictList(DictRequest dictRequest);
|
||||
|
||||
/**
|
||||
* 新增字典
|
||||
*
|
||||
|
@ -98,16 +106,6 @@ public interface DictService extends IService<SysDict>, DictApi {
|
|||
*/
|
||||
PageResult<SysDict> findPage(DictRequest dictRequest);
|
||||
|
||||
/**
|
||||
* 获取树形字典列表(antdv在用)
|
||||
*
|
||||
* @param dictRequest 查询条件
|
||||
* @return 字典信息列表
|
||||
* @author fengshuonan
|
||||
* @since 2020/10/29 18:50
|
||||
*/
|
||||
List<TreeDictInfo> getTreeDictList(DictRequest dictRequest);
|
||||
|
||||
/**
|
||||
* 删除字典类型下的所有字典
|
||||
*
|
||||
|
|
|
@ -35,7 +35,6 @@ import cn.stylefeng.roses.kernel.dict.api.constants.DictConstants;
|
|||
import cn.stylefeng.roses.kernel.dict.api.exception.DictException;
|
||||
import cn.stylefeng.roses.kernel.dict.api.exception.enums.DictExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.mapper.DictMapper;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.pojo.TreeDictInfo;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
|
||||
|
@ -79,6 +78,31 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
|
||||
private static final String CACHE_PREFIX = "dict:";
|
||||
|
||||
@Override
|
||||
public List<TreeDictInfo> getTreeDictList(DictRequest dictRequest) {
|
||||
|
||||
// 获取字典类型下所有的字典
|
||||
List<SysDict> sysDictList = this.findList(dictRequest);
|
||||
if (ObjectUtil.isEmpty(sysDictList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 构造树节点信息
|
||||
ArrayList<TreeDictInfo> treeDictInfos = new ArrayList<>();
|
||||
for (SysDict sysDict : sysDictList) {
|
||||
TreeDictInfo treeDictInfo = new TreeDictInfo();
|
||||
treeDictInfo.setDictId(sysDict.getDictId());
|
||||
treeDictInfo.setDictParentId(sysDict.getDictParentId());
|
||||
treeDictInfo.setDictCode(sysDict.getDictCode());
|
||||
treeDictInfo.setDictName(sysDict.getDictName());
|
||||
treeDictInfo.setDictSort(sysDict.getDictSort());
|
||||
treeDictInfos.add(treeDictInfo);
|
||||
}
|
||||
|
||||
// 构建菜单树
|
||||
return new DefaultTreeBuildFactory<TreeDictInfo>().doTreeBuild(treeDictInfos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(DictRequest dictRequest) {
|
||||
|
@ -133,7 +157,13 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
|
||||
@Override
|
||||
public List<SysDict> findList(DictRequest dictRequest) {
|
||||
return this.list(this.createWrapper(dictRequest));
|
||||
|
||||
LambdaQueryWrapper<SysDict> wrapper = this.createWrapper(dictRequest);
|
||||
|
||||
// 只查询有用字段
|
||||
wrapper.select(SysDict::getDictName, SysDict::getDictCode, SysDict::getDictSort, SysDict::getDictId, SysDict::getDictParentId);
|
||||
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -142,31 +172,6 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
return PageResultFactory.createPageResult(page);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<TreeDictInfo> getTreeDictList(DictRequest dictRequest) {
|
||||
|
||||
// 获取字典类型下所有的字典
|
||||
List<SysDict> sysDictList = this.findList(dictRequest);
|
||||
if (sysDictList == null || sysDictList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 构造树节点信息
|
||||
ArrayList<TreeDictInfo> treeDictInfos = new ArrayList<>();
|
||||
for (SysDict sysDict : sysDictList) {
|
||||
TreeDictInfo treeDictInfo = new TreeDictInfo();
|
||||
treeDictInfo.setDictId(sysDict.getDictId());
|
||||
treeDictInfo.setDictCode(sysDict.getDictCode());
|
||||
treeDictInfo.setDictParentId(sysDict.getDictParentId());
|
||||
treeDictInfo.setDictName(sysDict.getDictName());
|
||||
treeDictInfos.add(treeDictInfo);
|
||||
}
|
||||
|
||||
// 构建菜单树
|
||||
return new DefaultTreeBuildFactory<TreeDictInfo>().doTreeBuild(treeDictInfos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByDictTypeId(Long dictTypeId) {
|
||||
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
@ -210,7 +215,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
@Override
|
||||
public List<SimpleDict> getDictDetailsByDictTypeCode(String dictTypeCode) {
|
||||
DictRequest dictRequest = new DictRequest();
|
||||
dictRequest.setDictTypeCode(dictTypeCode);
|
||||
dictRequest.setDictTypeId(dictTypeCode);
|
||||
LambdaQueryWrapper<SysDict> wrapper = createWrapper(dictRequest);
|
||||
List<SysDict> dictList = this.list(wrapper);
|
||||
if (dictList.isEmpty()) {
|
||||
|
@ -264,21 +269,17 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
private LambdaQueryWrapper<SysDict> createWrapper(DictRequest dictRequest) {
|
||||
LambdaQueryWrapper<SysDict> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 如果传递了dictTypeId,先把dictTypeId转化为字典类型编码
|
||||
if (ObjectUtil.isNotEmpty(dictRequest.getDictTypeId())) {
|
||||
SysDictType sysDictType = dictTypeService.getById(dictRequest.getDictTypeId());
|
||||
if (sysDictType != null) {
|
||||
dictRequest.setDictTypeCode(sysDictType.getDictTypeCode());
|
||||
}
|
||||
// 根据名称或者编码进行查询
|
||||
String searchText = dictRequest.getSearchText();
|
||||
if (ObjectUtil.isNotEmpty(searchText)) {
|
||||
queryWrapper.like(SysDict::getDictName, searchText);
|
||||
queryWrapper.or().like(SysDict::getDictCode, searchText);
|
||||
queryWrapper.or().like(SysDict::getDictNamePinyin, searchText);
|
||||
}
|
||||
|
||||
// SQL拼接
|
||||
queryWrapper.eq(ObjectUtil.isNotNull(dictRequest.getDictId()), SysDict::getDictId, dictRequest.getDictId());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(dictRequest.getDictTypeCode()), SysDict::getDictTypeId, dictRequest.getDictTypeCode());
|
||||
queryWrapper.eq(StrUtil.isNotBlank(dictRequest.getDictCode()), SysDict::getDictCode, dictRequest.getDictCode());
|
||||
queryWrapper.like(StrUtil.isNotBlank(dictRequest.getDictName()), SysDict::getDictName, dictRequest.getDictName());
|
||||
// 根据字典类型id查询字典
|
||||
queryWrapper.eq(StrUtil.isNotBlank(dictRequest.getDictTypeId()), SysDict::getDictTypeId, dictRequest.getDictTypeId());
|
||||
|
||||
queryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
@ -292,7 +293,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
|
||||
// 检验同字典类型下是否有一样的编码
|
||||
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDictLambdaQueryWrapper.eq(SysDict::getDictTypeId, dictRequest.getDictTypeCode());
|
||||
sysDictLambdaQueryWrapper.eq(SysDict::getDictTypeId, dictRequest.getDictTypeId());
|
||||
sysDictLambdaQueryWrapper.eq(SysDict::getDictCode, dictRequest.getDictCode());
|
||||
if (editFlag) {
|
||||
sysDictLambdaQueryWrapper.ne(SysDict::getDictId, dictRequest.getDictId());
|
||||
|
@ -300,12 +301,12 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
sysDictLambdaQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||
long count = this.count(sysDictLambdaQueryWrapper);
|
||||
if (count > 0) {
|
||||
throw new DictException(DictExceptionEnum.DICT_CODE_REPEAT, dictRequest.getDictTypeCode(), dictRequest.getDictCode());
|
||||
throw new DictException(DictExceptionEnum.DICT_CODE_REPEAT, dictRequest.getDictTypeId(), dictRequest.getDictCode());
|
||||
}
|
||||
|
||||
// 检验同字典类型下是否有一样的名称
|
||||
LambdaQueryWrapper<SysDict> dictNameWrapper = new LambdaQueryWrapper<>();
|
||||
dictNameWrapper.eq(SysDict::getDictTypeId, dictRequest.getDictTypeCode());
|
||||
dictNameWrapper.eq(SysDict::getDictTypeId, dictRequest.getDictTypeId());
|
||||
dictNameWrapper.eq(SysDict::getDictName, dictRequest.getDictName());
|
||||
if (editFlag) {
|
||||
dictNameWrapper.ne(SysDict::getDictId, dictRequest.getDictId());
|
||||
|
@ -313,7 +314,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
dictNameWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode());
|
||||
long dictNameCount = this.count(dictNameWrapper);
|
||||
if (dictNameCount > 0) {
|
||||
throw new DictException(DictExceptionEnum.DICT_NAME_REPEAT, dictRequest.getDictTypeCode(), dictRequest.getDictCode());
|
||||
throw new DictException(DictExceptionEnum.DICT_NAME_REPEAT, dictRequest.getDictTypeId(), dictRequest.getDictCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue