use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class MessagePluginInitializer method insertInitData.
/**
* 插入初始化数据
*/
private void insertInitData() {
// 插入iam组件所需的数据字典
DictionaryService dictionaryService = ContextHelper.getBean(DictionaryService.class);
if (dictionaryService != null && !dictionaryService.exists(Dictionary::getType, "MESSAGE_CHANNEL")) {
// 插入iam组件所需的数据字典
String[] DICT_INIT_DATA = { "{\"type\":\"MESSAGE_STATUS\", \"itemName\":\"消息状态\", \"description\":\"message消息状态\", \"children\":[{\"itemName\":\"发送中\", \"itemValue\":\"SENDING\", \"sortId\":1},{\"itemName\":\"发送异常\", \"itemValue\":\"EXCEPTION\", \"sortId\":2},{\"itemName\":\"已送达\", \"itemValue\":\"DELIVERY\", \"sortId\":3},{\"itemName\":\"未读\", \"itemValue\":\"UNREAD\", \"sortId\":4},{\"itemName\":\"已读\", \"itemValue\":\"READ\", \"sortId\":5}]}", "{\"type\":\"MESSAGE_CHANNEL\", \"itemName\":\"发送通道\", \"description\":\"message发送通道\", \"children\":[{\"itemName\":\"站内信\", \"itemValue\":\"WEBSOCKET\", \"sortId\":1},{\"itemName\":\"短信\", \"itemValue\":\"TEXT_MESSAGE\", \"sortId\":2},{\"itemName\":\"邮件\", \"itemValue\":\"EMAIL\", \"sortId\":3}]}" };
// 插入数据字典
for (String dictJson : DICT_INIT_DATA) {
DictionaryVO dictVo = JSON.toJavaObject(dictJson, DictionaryVO.class);
dictionaryService.createDictAndChildren(dictVo);
}
DICT_INIT_DATA = null;
}
}
use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class DictionaryServiceExtImpl method createDictAndChildren.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean createDictAndChildren(DictionaryVO dictVO) {
Dictionary dictionary = dictVO;
dictionary.setIsDeletable(true).setIsEditable(true);
if (!super.createEntity(dictionary)) {
log.warn("新建数据字典定义失败,type=" + dictVO.getType());
return false;
}
List<Dictionary> children = dictVO.getChildren();
this.buildSortId(children);
if (V.notEmpty(children)) {
for (Dictionary dict : children) {
dict.setParentId(dictionary.getId()).setType(dictionary.getType()).setIsDeletable(dictionary.getIsDeletable()).setIsEditable(dictionary.getIsEditable());
}
// 批量保存
boolean success = super.createEntities(children);
if (!success) {
String errorMsg = "新建数据字典子项失败,type=" + dictVO.getType();
log.warn(errorMsg);
throw new BusinessException(Status.FAIL_OPERATION, errorMsg);
}
}
return true;
}
use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class DictionaryServiceExtImpl method updateDictAndChildren.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateDictAndChildren(DictionaryVO dictVO) {
Dictionary oldDictionary = super.getEntity(dictVO.getId());
// 将DictionaryVO转化为Dictionary
Dictionary dictionary = dictVO;
dictionary.setIsDeletable(oldDictionary.getIsDeletable()).setIsEditable(oldDictionary.getIsEditable());
if (!super.updateEntity(dictionary)) {
log.warn("更新数据字典定义失败,type=" + dictVO.getType());
return false;
}
// 获取原 子数据字典list
QueryWrapper<Dictionary> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(Dictionary::getParentId, dictVO.getId());
List<Dictionary> oldDictList = super.getEntityList(queryWrapper);
List<Dictionary> newDictList = dictVO.getChildren();
Set<Long> dictItemIds = new HashSet<>();
this.buildSortId(newDictList);
if (V.notEmpty(newDictList)) {
for (Dictionary dict : newDictList) {
dict.setType(dictVO.getType()).setParentId(dictVO.getId()).setIsDeletable(dictionary.getIsDeletable()).setIsEditable(dictionary.getIsEditable());
if (V.notEmpty(dict.getId())) {
dictItemIds.add(dict.getId());
if (!super.updateEntity(dict)) {
log.warn("更新字典子项失败,itemName=" + dict.getItemName());
throw new BusinessException(Status.FAIL_EXCEPTION, "更新字典子项异常");
}
} else {
if (!super.createEntity(dict)) {
log.warn("新建字典子项失败,itemName=" + dict.getItemName());
throw new BusinessException(Status.FAIL_EXCEPTION, "新建字典子项异常");
}
}
}
}
if (V.notEmpty(oldDictList)) {
for (Dictionary dict : oldDictList) {
if (!dictItemIds.contains(dict.getId())) {
if (!super.deleteEntity(dict.getId())) {
log.warn("删除子数据字典失败,itemName=" + dict.getItemName());
throw new BusinessException(Status.FAIL_EXCEPTION, "删除字典子项异常");
}
}
}
}
return true;
}
use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class VTest method testEquals.
@Test
public void testEquals() {
Long val1 = 128L, val2 = 128L;
Assert.assertFalse(val1 == val2);
Assert.assertTrue(V.equals(val1, val2));
List<Long> list1 = new ArrayList<>(), list2 = new ArrayList<>();
list1.add(127L);
list1.add(128L);
list2.add(127L);
list2.add(128L);
Assert.assertTrue(V.equals(list1, list2));
Field field = BeanUtils.extractField(Dictionary.class, "createTime");
Assert.assertTrue(V.equals(field.getType(), Date.class));
Assert.assertTrue(V.equals(field.getType().getName(), "java.util.Date"));
Dictionary dictionary = BeanUtils.cloneBean(new Dictionary());
Dictionary dictionary1 = JSON.parseObject("{}", Dictionary.class);
Assert.assertTrue(V.equals(dictionary.getClass(), dictionary1.getClass()));
field = BeanUtils.extractField(Dictionary.class, "isDeletable");
Assert.assertTrue(V.equals(Boolean.class, field.getType()));
field = BeanUtils.extractField(Dictionary.class, "deleted");
Assert.assertTrue(V.equals(boolean.class, field.getType()));
}
use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class TestEntityListBinder method testDictionaryBinder.
@Test
public void testDictionaryBinder() {
// 查询是否创建成功
LambdaQueryWrapper<Dictionary> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Dictionary::getType, "GENDER");
queryWrapper.eq(Dictionary::getParentId, 0L);
Dictionary dictionary = dictionaryService.getSingleEntity(queryWrapper);
DictionaryVO vo = Binder.convertAndBindRelations(dictionary, DictionaryVO.class);
Assert.assertTrue(vo.getChildren().size() > 0);
}
Aggregations