fix: 新增字典处理

This commit is contained in:
wangyu 2021-03-22 00:37:50 +08:00
parent df3748068a
commit 5e21b17f8e

View File

@ -54,25 +54,29 @@ public class DictionaryProcessor implements InitializingBean {
BlankEnum.class != annotation.enumType())
.map(annotation -> dictionaryService
.getByCode(annotation.value())
.map(dictionary -> {
if (CollectionUtils.isEmpty(dictionary.getValues())) {
dictionary.setValues(mapValues(annotation.enumType()));
}
return dictionary;
})
.orElseGet(() -> {
Dictionary dictionary = new Dictionary();
dictionary.setCode(annotation.value());
dictionary.setValues(mapValues(annotation.enumType()));
dictionary.setName(StringUtils.isNotBlank(annotation.name()) ? annotation.name() : annotation.value());
return dictionary;
}))
.map(dictionary -> applyDictProps(dictionary, annotation))
.orElseGet(() -> applyDictProps(new Dictionary(), annotation)))
.distinct()
.collect(Collectors.toList());
dictionaryService.updateBatch(dictionaries);
}
}
/**
* 给字典属性赋值
*
* @param dictionary 字典
* @param annotation 注解
* @return 结果
*/
private Dictionary applyDictProps(Dictionary dictionary, DictValue annotation) {
dictionary.setCode(annotation.value());
if (CollectionUtils.isEmpty(dictionary.getValues())) {
dictionary.setValues(mapValues(annotation.enumType()));
}
dictionary.setName(StringUtils.isNotBlank(annotation.name()) ? annotation.name() : annotation.value());
return dictionary;
}
/**
* 映射值转换为字典表的值