Search in sources :

Example 21 with Dictionary

use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.

the class TestMultipleColumnsJoinBinder method testBinder.

@Test
public void testBinder() {
    QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("type", "GENDER");
    queryWrapper.gt("parent_id", 0);
    List<Long> ids = dictionaryService.getValuesOfField(queryWrapper, Dictionary::getId);
    // 加载测试数据
    List<MulColJoinVO> voList = new ArrayList<>();
    MulColJoinVO vo1 = new MulColJoinVO();
    vo1.setDictType("GENDER");
    vo1.setDictId(ids.get(0));
    vo1.setOrgPid(0L);
    vo1.setTelphone("0512-62988949");
    voList.add(vo1);
    MulColJoinVO vo2 = new MulColJoinVO();
    vo2.setDictType("GENDER");
    vo2.setDictId(ids.get(1));
    vo2.setOrgPid(0L);
    vo2.setTelphone("028-62988949");
    voList.add(vo2);
    // 自动绑定
    Binder.bindRelations(voList);
    // 验证绑定结果
    Assert.assertTrue(V.notEmpty(voList));
    // 验证直接关联和通过中间表间接关联的绑定
    Assert.assertNotNull(voList.get(0).getParentDict().getType().equals(vo1.getDictType()));
    Assert.assertNotNull(voList.get(0).getParentDictName().equals("性别"));
    Assert.assertNotNull(voList.get(0).getOrgList().size() == 1);
    // 验证枚举值已绑定
    Assert.assertNotNull(voList.get(0).getOrgNames().contains("苏州帝博"));
    Assert.assertNotNull(voList.get(1).getParentDict().getType().equals(vo1.getDictType()));
    Assert.assertNotNull(voList.get(1).getParentDictName().equals("男"));
    Assert.assertNotNull(voList.get(1).getOrgList().size() == 1);
    // 验证枚举值已绑定
    Assert.assertNotNull(voList.get(1).getOrgNames().contains("成都帝博"));
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList) MulColJoinVO(diboot.core.test.binder.vo.MulColJoinVO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with Dictionary

use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.

the class BaseServiceTest method testCreateUpdateAndDelete.

@Test
@Transactional
public void testCreateUpdateAndDelete() {
    // 创建
    String TYPE = "ID_TYPE";
    Dictionary dictionary = new Dictionary();
    dictionary.setType(TYPE);
    dictionary.setItemName("证件类型");
    dictionary.setParentId(0L);
    dictionaryService.createEntity(dictionary);
    Assert.assertTrue(dictionary.getPrimaryKeyVal() != null);
    // 查询是否创建成功
    LambdaQueryWrapper<Dictionary> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Dictionary::getType, TYPE);
    List<Dictionary> dictionaryList = dictionaryService.getEntityList(queryWrapper);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    // 更新
    dictionary.setItemName("证件类型定义");
    dictionaryService.updateEntity(dictionary);
    Dictionary dictionary2 = dictionaryService.getEntity(dictionary.getId());
    Assert.assertTrue(dictionary2.getItemName().equals(dictionary.getItemName()));
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Dictionary

use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.

the class BaseServiceTest method testCreateUpdateDeleteEntityAndRelatedEntities.

/**
 * 测试1-多的批量新建/更新/删除操作
 */
@Test
@Transactional
public void testCreateUpdateDeleteEntityAndRelatedEntities() {
    // 创建
    String TYPE = "ID_TYPE";
    // 定义
    Dictionary dictionary = new Dictionary();
    dictionary.setType(TYPE);
    dictionary.setItemName("证件类型");
    dictionary.setParentId(0L);
    // 子项
    List<Dictionary> dictionaryList = new ArrayList<>();
    String[] itemNames = { "身份证", "驾照", "护照" }, itemValues = { "SFZ", "JZ", "HZ" };
    for (int i = 0; i < itemNames.length; i++) {
        Dictionary dict = new Dictionary();
        dict.setType(TYPE);
        dict.setItemName(itemNames[i]);
        dict.setItemValue(itemValues[i]);
        dict.setParentId(dictionary.getId());
        dictionaryList.add(dict);
    }
    boolean success = dictionaryService.createEntityAndRelatedEntities(dictionary, dictionaryList, Dictionary::setParentId);
    Assert.assertTrue(success);
    dictionary.setItemName(dictionary.getItemName() + "_2");
    dictionaryList.remove(1);
    Dictionary dict = new Dictionary();
    dict.setType(TYPE);
    dict.setItemName("港澳通行证");
    dict.setItemValue("GATXZ");
    dictionaryList.add(dict);
    success = dictionaryService.updateEntityAndRelatedEntities(dictionary, dictionaryList, Dictionary::setParentId);
    Assert.assertTrue(success);
    // 查询是否创建成功
    LambdaQueryWrapper<Dictionary> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Dictionary::getType, TYPE).ne(Dictionary::getParentId, 0);
    List<Dictionary> dictionaryList2 = dictionaryService.getEntityList(queryWrapper);
    Assert.assertTrue(V.notEmpty(dictionaryList2));
    List<String> itemNames2 = BeanUtils.collectToList(dictionaryList2, Dictionary::getItemName);
    Assert.assertTrue(itemNames2.contains("港澳通行证"));
    // success = dictionaryService.updateEntityAndRelatedEntities(dictionary, null, Dictionary::setParentId);
    // Assert.assertTrue(success);
    // dictionaryList2 = dictionaryService.getEntityList(queryWrapper);
    // Assert.assertTrue(V.isEmpty(dictionaryList2));
    success = dictionaryService.deleteEntityAndRelatedEntities(dictionary.getId(), Dictionary.class, Dictionary::setParentId);
    Assert.assertTrue(success);
    dictionaryList2 = dictionaryService.getEntityList(queryWrapper);
    Assert.assertTrue(V.isEmpty(dictionaryList2));
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with Dictionary

use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.

the class BaseServiceTest method testDictVo.

@Test
public void testDictVo() {
    Dictionary dict = new Dictionary();
    dict.setParentId(0L);
    dict.setType("GENDER");
    QueryWrapper<Dictionary> queryWrapper = QueryBuilder.toQueryWrapper(dict);
    List<DictionaryVO> voList = dictionaryService.getViewObjectList(queryWrapper, null, DictionaryVO.class);
    Assert.assertTrue(voList.size() == 1);
    Assert.assertTrue(voList.get(0).getChildren().size() >= 2);
    List<LabelValue> options = dictionaryService.getLabelValueList("GENDER");
    Assert.assertTrue(options.size() >= 2);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) SimpleDictionaryVO(diboot.core.test.binder.vo.SimpleDictionaryVO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with Dictionary

use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.

the class BaseServiceTest method testBatchCreate.

@Test
@Transactional
public void testBatchCreate() {
    // 创建
    String TYPE = "ID_TYPE";
    // 定义
    Dictionary dictionary = new Dictionary();
    dictionary.setType(TYPE);
    dictionary.setItemName("证件类型");
    dictionary.setParentId(0L);
    boolean success = dictionaryService.createEntity(dictionary);
    Assert.assertTrue(success);
    // 子项
    List<Dictionary> dictionaryList = new ArrayList<>();
    String[] itemNames = { "身份证", "驾照", "护照" }, itemValues = { "SFZ", "JZ", "HZ" };
    for (int i = 0; i < itemNames.length; i++) {
        Dictionary dict = new Dictionary();
        dict.setType(TYPE);
        dict.setItemName(itemNames[i]);
        dict.setItemValue(itemValues[i]);
        dict.setParentId(dictionary.getId());
        dictionaryList.add(dict);
    }
    success = dictionaryService.createEntities(dictionaryList);
    Assert.assertTrue(success);
    dictionaryList.get(2).setCreateTime(new Date());
    dictionaryList.get(2).setItemValue("HZ2");
    dictionaryService.updateEntity(dictionaryList.get(2));
    Assert.assertTrue(success);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

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