【8.0.5】【dict】更新字典类型查询

pull/60/head
fengshuonan 2024-01-07 17:59:24 +08:00
parent f251d45b4f
commit aff0f62e41
4 changed files with 111 additions and 0 deletions

View File

@ -25,6 +25,7 @@
package cn.stylefeng.roses.kernel.dict.api;
import cn.stylefeng.roses.kernel.dict.api.pojo.DictDetail;
import cn.stylefeng.roses.kernel.dict.api.pojo.DictTreeDto;
import cn.stylefeng.roses.kernel.dict.api.pojo.SimpleDictUpdateParam;
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
@ -101,4 +102,14 @@ public interface DictApi {
*/
void simpleEditDict(SimpleDictUpdateParam simpleDictUpdateParam);
/**
*
* <p>
*
*
* @author fengshuonan
* @since 2023/11/15 18:55
*/
List<DictTreeDto> buildDictTreeStructure();
}

View File

@ -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;
}

View File

@ -24,6 +24,7 @@
*/
package cn.stylefeng.roses.kernel.dict.modular.controller;
import cn.stylefeng.roses.kernel.dict.api.pojo.DictTreeDto;
import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
@ -32,6 +33,7 @@ import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
*
@ -57,4 +59,15 @@ public class CommonDictController {
return new SuccessResponseData<>(this.dictService.getPinyin(name));
}
/**
*
*
* @author fengshuonan
* @since 2023/11/15 19:08
*/
@GetResource(name = "获取所有的字典类型树", path = "/dictType/dictTreeBuild")
public ResponseData<List<DictTreeDto>> dictTreeBuild() {
return new SuccessResponseData<>(dictService.buildDictTreeStructure());
}
}

View File

@ -25,11 +25,13 @@
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.dict.api.exception.DictException;
import cn.stylefeng.roses.kernel.dict.api.exception.enums.DictExceptionEnum;
import cn.stylefeng.roses.kernel.dict.api.pojo.DictDetail;
import cn.stylefeng.roses.kernel.dict.api.pojo.DictTreeDto;
import cn.stylefeng.roses.kernel.dict.api.pojo.SimpleDictUpdateParam;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
@ -54,7 +56,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;
/**
@ -324,6 +328,58 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
this.edit(dictRequest);
}
@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::getDictTypeId);
sysDictLambdaQueryWrapper.orderByAsc(SysDict::getDictSort);
List<SysDict> dictList = this.list(sysDictLambdaQueryWrapper);
// 构建字典类型基本信息
Map<Long, DictTreeDto> dictTypeMap = new HashMap<>();
for (SysDictType sysDictType : dictTypeList) {
DictTreeDto dictTreeDto = new DictTreeDto();
dictTreeDto.setDictLabel(sysDictType.getDictTypeName());
dictTreeDto.setDictValue(sysDictType.getDictTypeCode());
dictTypeMap.put(sysDictType.getDictTypeId(), dictTreeDto);
}
// 遍历所有字典,把字典信息装配到字典类型信息里
for (SysDict sysDict : dictList) {
Long dictTypeId = sysDict.getDictTypeId();
if (ObjectUtil.isNotEmpty(dictTypeId)) {
continue;
}
DictTreeDto dictTreeDto = dictTypeMap.get(dictTypeId);
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, dictTypeMap.values());
}
@Override
public String getPinyin(String name) {
if (ObjectUtil.isNotEmpty(name)) {