增加数据字典接口

This commit is contained in:
2023-09-09 22:35:39 +08:00
parent 3ad42b6011
commit 6a7ac03b25
9 changed files with 71 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@Data
@@ -28,17 +29,40 @@ public class TreeDto {
private List<TreeDto> children;
public static List<TreeDto> buildList(Object object, boolean flatten) {
public static List<TreeDto> buildList(Object object){
List<TreeDto> ans;
if (object instanceof Iterable<?>) {
return buildList0((Iterable<?>) object);
ans = buildList0((Iterable<?>) object);
} else {
ans = buildList0(Arrays.asList(object));
}
return buildList0(Arrays.asList(object));
if (flatten) {
ans = flatten(ans);
}
return ans;
}
private static List<TreeDto> flatten(List<TreeDto> ans) {
return ans.stream().flatMap(x -> {
if (x.getChildren() != null) {
return Stream.concat(Stream.of(x), flatten(x.getChildren()).stream());
} else {
return Stream.of(x);
}
}).toList();
}
@@ -70,7 +94,7 @@ public class TreeDto {
private static List<TreeDto> getChildren(Object x) {
if (x instanceof TreeDto) {
return ((TreeDto) x).getChildren().stream().map( TreeDto::buildTree).toList();
return ((TreeDto) x).getChildren().stream().map(TreeDto::buildTree).toList();
}

View File

@@ -14,6 +14,8 @@ public class CreateDictionaryDto extends CommonDto
private String componentType;
private String componentTypeName;
@Comment("字典类型 1 静态字典 2 动态字典")
private String dictType;

View File

@@ -13,6 +13,8 @@ public class DictionaryDto extends CommonDto
private String dictType;
private String dictTypeName;
private String componentType;
private String componentTypeName;
private ScriptEntity script;

View File

@@ -12,8 +12,9 @@ public class UpdateDictionaryDto extends CommonDto
{
private String componentType;
private String componentTypeName;
@Comment("字典类型 1 静态字典 2 动态字典")
private String dictType;
@OneToOne

View File

@@ -38,6 +38,21 @@ public class DictionaryEntity extends CommonEntity {
" and i.code = dict_type)")
private String dictTypeName;
@Comment("字典类型 1 枚举 2 树")
private String componentType;
@Formula("(select i.name\n" +
"from t_dictionary d,\n" +
" t_dictionary_item i\n" +
"where d.id = i.dictionary_id\n" +
" and d.code = 'dict.componentType'\n" +
" and i.code = component_type)")
private String componentTypeName;
@OneToOne
@Comment("动态字典关联的脚本")
private ScriptEntity script;

View File

@@ -54,10 +54,10 @@ public class DictionaryService extends BaseService<DictionaryEntity, DictionaryR
public List<TreeDto> tree(DictTreeRequest request) {
DictionaryEntity dict = this.repository.findByCode(request.getCode());
boolean flatten = StringUtils.equalsIgnoreCase(dict.getComponentType(), "1");
if (dict.getDictType().equalsIgnoreCase("1")) {
return TreeDto.buildList(dict.getItem());
return TreeDto.buildList(dict.getItem(), flatten);
}
if (dict.getDictType().equalsIgnoreCase("2")) {
@@ -69,7 +69,7 @@ public class DictionaryService extends BaseService<DictionaryEntity, DictionaryR
if (StringUtils.isNotEmpty(result.getStackTrace())) {
log.warn("执行脚本出错 id:{}\nparams:{}\nstacktrace:{}\nlogs:{}", result.getId(), result.getParams().toString(), result.getStackTrace(), result.getLogs());
}
return TreeDto.buildList(result.getResponse());
return TreeDto.buildList(result.getResponse(), flatten);
}
throw new BizException("不支持的字典类型 " + dict.getDictTypeName());

View File

@@ -33,6 +33,21 @@
]
},
{
"code": "dict.componentType",
"name": "字典组件类型",
"item": [
{
"code": "1",
"name": "枚举"
},
{
"code": "2",
"name": "树"
}
]
},
{
"code": "syslog.status",
"name": "系统日志状态",

View File

@@ -10,5 +10,5 @@ def controller = ioc.getBean(RoleController.class)
return TreeDto.buildList(controller.list(new CommonQuery()))
return TreeDto.buildList(controller.list(new CommonQuery()), flatten)

View File

@@ -6,5 +6,5 @@ ApplicationContext ioc = ioc;
def scriptService = ioc.getBean(ScriptService.class)
return TreeDto.buildList(scriptService.findAll())
return TreeDto.buildList(scriptService.findAll(), flatten)