Search in sources :

Example 16 with Dictionary

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;
    }
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) DictionaryService(com.diboot.core.service.DictionaryService) DictionaryVO(com.diboot.core.vo.DictionaryVO)

Example 17 with Dictionary

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;
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) BusinessException(com.diboot.core.exception.BusinessException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with Dictionary

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;
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) BusinessException(com.diboot.core.exception.BusinessException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with Dictionary

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()));
}
Also used : Field(java.lang.reflect.Field) Dictionary(com.diboot.core.entity.Dictionary) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 20 with Dictionary

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);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) DictionaryVO(com.diboot.core.vo.DictionaryVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Dictionary (com.diboot.core.entity.Dictionary)27 Test (org.junit.Test)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)8 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)5 DictionaryVO (com.diboot.core.vo.DictionaryVO)5 Transactional (org.springframework.transaction.annotation.Transactional)5 BusinessException (com.diboot.core.exception.BusinessException)3 DictionaryService (com.diboot.core.service.DictionaryService)3 SimpleDictionaryVO (diboot.core.test.binder.vo.SimpleDictionaryVO)3 User (diboot.core.test.binder.entity.User)2 ArrayList (java.util.ArrayList)2 BaseMapper (com.baomidou.mybatisplus.core.mapper.BaseMapper)1 EntityInfoCache (com.diboot.core.binding.parser.EntityInfoCache)1 DynamicMemoryCacheManager (com.diboot.core.cache.DynamicMemoryCacheManager)1 IamResourcePermissionListVO (com.diboot.iam.vo.IamResourcePermissionListVO)1 IamMember (com.diboot.mobile.entity.IamMember)1 IamMemberService (com.diboot.mobile.service.IamMemberService)1 CcCityInfo (diboot.core.test.binder.entity.CcCityInfo)1 MulColJoinVO (diboot.core.test.binder.vo.MulColJoinVO)1