mirror of https://gitee.com/stylefeng/roses
【dict】更新一个获取字典树的接口
parent
e9ff5d2e9a
commit
039cbdc748
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.dict.api;
|
||||
|
||||
import cn.stylefeng.roses.kernel.dict.api.pojo.DictTreeDto;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -66,4 +67,15 @@ public interface DictApi {
|
|||
*/
|
||||
void deleteByDictId(Long dictId);
|
||||
|
||||
/**
|
||||
* 构建一个完整的字典树
|
||||
* <p>
|
||||
* 包含字典的类型和字典底下的详情信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/15 18:55
|
||||
*/
|
||||
List<DictTreeDto> buildDictTreeStructure();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package cn.stylefeng.roses.kernel.dict.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典值
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/15 18:44
|
||||
*/
|
||||
@Data
|
||||
public class DictTreeDto {
|
||||
|
||||
/**
|
||||
* 字典的名称
|
||||
*/
|
||||
private String dictLabel;
|
||||
|
||||
/**
|
||||
* 字典的编码
|
||||
*/
|
||||
private String dictValue;
|
||||
|
||||
/**
|
||||
* 字典的子集
|
||||
*/
|
||||
private List<DictTreeDto> children;
|
||||
|
||||
}
|
|
@ -25,7 +25,9 @@
|
|||
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.DictApi;
|
||||
import cn.stylefeng.roses.kernel.dict.api.constants.DictConstants;
|
||||
import cn.stylefeng.roses.kernel.dict.api.pojo.DictTreeDto;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictTypeRequest;
|
||||
import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService;
|
||||
|
@ -57,6 +59,9 @@ public class DictTypeController {
|
|||
@Resource
|
||||
private DictTypeService dictTypeService;
|
||||
|
||||
@Resource
|
||||
private DictApi dictApi;
|
||||
|
||||
/**
|
||||
* 添加字典类型
|
||||
*
|
||||
|
@ -169,4 +174,15 @@ public class DictTypeController {
|
|||
return new SuccessResponseData<>(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的字典类型树
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/11/15 19:08
|
||||
*/
|
||||
@GetResource(name = "获取所有的字典类型树", path = "/dictType/dictTreeBuild", requiredPermission = false)
|
||||
public ResponseData<List<DictTreeDto>> dictTreeBuild() {
|
||||
return new SuccessResponseData<>(dictApi.buildDictTreeStructure());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package cn.stylefeng.roses.kernel.dict.modular.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
|
@ -34,6 +35,7 @@ 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.api.exception.DictException;
|
||||
import cn.stylefeng.roses.kernel.dict.api.exception.enums.DictExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.dict.api.pojo.DictTreeDto;
|
||||
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;
|
||||
|
@ -55,7 +57,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -224,6 +228,58 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
|
|||
this.removeById(dictId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DictTreeDto> buildDictTreeStructure() {
|
||||
|
||||
// 获取所有字典类型
|
||||
LambdaQueryWrapper<SysDictType> dictTypeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
dictTypeLambdaQueryWrapper.select(SysDictType::getDictTypeCode, SysDictType::getDictTypeName);
|
||||
dictTypeLambdaQueryWrapper.orderByAsc(SysDictType::getDictTypeSort);
|
||||
List<SysDictType> dictTypeList = this.dictTypeService.list(dictTypeLambdaQueryWrapper);
|
||||
|
||||
// 获取所有字典信息
|
||||
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDictLambdaQueryWrapper.select(SysDict::getDictCode, SysDict::getDictName, SysDict::getDictTypeCode);
|
||||
sysDictLambdaQueryWrapper.orderByAsc(SysDict::getDictSort);
|
||||
List<SysDict> dictList = this.list(sysDictLambdaQueryWrapper);
|
||||
|
||||
// 构建字典类型基本信息
|
||||
Map<String, DictTreeDto> typeCodeMap = new HashMap<>();
|
||||
for (SysDictType sysDictType : dictTypeList) {
|
||||
DictTreeDto dictTreeDto = new DictTreeDto();
|
||||
dictTreeDto.setDictLabel(sysDictType.getDictTypeName());
|
||||
dictTreeDto.setDictValue(sysDictType.getDictTypeCode());
|
||||
typeCodeMap.put(sysDictType.getDictTypeCode(), dictTreeDto);
|
||||
}
|
||||
|
||||
// 遍历所有字典,把字典信息装配到字典类型信息里
|
||||
for (SysDict sysDict : dictList) {
|
||||
String dictTypeCode = sysDict.getDictTypeCode();
|
||||
if (StrUtil.isBlank(dictTypeCode)) {
|
||||
continue;
|
||||
}
|
||||
DictTreeDto dictTreeDto = typeCodeMap.get(dictTypeCode);
|
||||
if (dictTreeDto == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<DictTreeDto> children = dictTreeDto.getChildren();
|
||||
if (ObjectUtil.isEmpty(children)) {
|
||||
children = new ArrayList<>();
|
||||
}
|
||||
|
||||
DictTreeDto dictValue = new DictTreeDto();
|
||||
dictValue.setDictLabel(sysDict.getDictName());
|
||||
dictValue.setDictValue(sysDict.getDictCode());
|
||||
|
||||
children.add(dictValue);
|
||||
dictTreeDto.setChildren(children);
|
||||
}
|
||||
|
||||
// map转化为树形结构
|
||||
return ListUtil.list(true, typeCodeMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详细信息
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue