Search in sources :

Example 1 with Dictionary

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

the class DictionaryServiceExtImpl method buildSortId.

/**
 * 构建排序编号
 * @param dictList
 */
private void buildSortId(List<Dictionary> dictList) {
    if (V.isEmpty(dictList)) {
        return;
    }
    for (int i = 0; i < dictList.size(); i++) {
        Dictionary dict = dictList.get(i);
        dict.setSortId(i);
    }
}
Also used : Dictionary(com.diboot.core.entity.Dictionary)

Example 2 with Dictionary

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

the class BaseServiceTest method tesExecuteMultipleUpdateSqls.

@Test
public void tesExecuteMultipleUpdateSqls() {
    List<String> sqls = new ArrayList<>();
    Long dictId = 20000l;
    sqls.add("INSERT INTO dictionary(id, parent_id, type, item_name) VALUES(" + dictId + ", 0, 'TEST', '')");
    sqls.add("DELETE FROM dictionary WHERE id=20000 AND is_deleted=1");
    boolean success = SqlFileInitializer.executeMultipleUpdateSqlsWithTransaction(sqls);
    Assert.assertTrue(success);
    Dictionary dict = dictionaryService.getEntity(dictId);
    Assert.assertTrue(dict != null);
    sqls.clear();
    sqls.add("DELETE FROM dictionary WHERE id=20000");
    success = SqlFileInitializer.executeMultipleUpdateSqlsWithTransaction(sqls);
    Assert.assertTrue(success);
    sqls.clear();
    sqls.add("INSERT INTO dictionary(id, parent_id, type, item_name) VALUES(" + dictId + ", 0, 'TEST', '')");
    sqls.add("UPDATE dictionary SET is_deleted=1 WHERE id=20000 AND deleted=1");
    success = SqlFileInitializer.executeMultipleUpdateSqlsWithTransaction(sqls);
    Assert.assertTrue(success == false);
    dict = dictionaryService.getEntity(dictId);
    Assert.assertTrue(dict == null);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Dictionary

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

the class BaseServiceTest method testGet.

@Test
public void testGet() {
    // 查询总数
    long count = dictionaryService.getEntityListCount(null);
    Assert.assertTrue(count > 0);
    // 查询list
    List<Dictionary> dictionaryList = dictionaryService.getEntityList(null);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    Assert.assertTrue(dictionaryList.size() == count);
    // 第一页数据
    List<Dictionary> pageList = dictionaryService.getEntityList(null, new Pagination());
    Assert.assertTrue(pageList.size() > 0 && pageList.size() <= BaseConfig.getPageSize());
    // 查询单个记录
    Long id = dictionaryList.get(0).getId();
    Dictionary first = dictionaryService.getEntity(id);
    Assert.assertTrue(first != null);
    // 只查询第一条记录对应type类型的
    LambdaQueryWrapper<Dictionary> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Dictionary::getType, first.getType());
    dictionaryList = dictionaryService.getEntityList(queryWrapper);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    // 结果type值一致
    dictionaryList.stream().forEach(m -> {
        Assert.assertTrue(m.getType().equals(first.getType()));
    });
    // 根据id集合去批量查询
    List<Long> ids = BeanUtils.collectIdToList(dictionaryList);
    dictionaryList = dictionaryService.getEntityListByIds(ids);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    // 获取map
    List<Map<String, Object>> mapList = dictionaryService.getMapList(null, new Pagination());
    Assert.assertTrue(mapList.size() > 0 && mapList.size() <= BaseConfig.getPageSize());
    List<Long> userIds = Arrays.asList(1001L, 1002L);
    Map<Long, String> id2NameMap = userService.getId2NameMap(userIds, User::getUsername);
    Assert.assertTrue(id2NameMap != null);
    Assert.assertTrue(id2NameMap.get(1001) != null);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) User(diboot.core.test.binder.entity.User) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Dictionary

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

the class BaseServiceTest method testGetLimit.

@Test
public void testGetLimit() {
    QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("type", "GENDER");
    queryWrapper.gt("parent_id", 0);
    Dictionary dictionary = dictionaryService.getSingleEntity(queryWrapper);
    Assert.assertTrue(dictionary != null);
    List<Dictionary> ids = dictionaryService.getEntityListLimit(queryWrapper, 5);
    Assert.assertTrue(ids.size() >= 2);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Dictionary

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

the class BaseServiceTest method testPagination.

@Test
public void testPagination() {
    Dictionary dict = new Dictionary();
    dict.setType("GENDER");
    dict.setParentId(null);
    QueryWrapper<Dictionary> queryWrapper = QueryBuilder.toQueryWrapper(dict);
    // 查询当前页的数据
    Pagination pagination = new Pagination();
    pagination.setPageSize(1);
    List<DictionaryVO> voList = dictionaryService.getViewObjectList(queryWrapper, pagination, DictionaryVO.class);
    Assert.assertTrue(voList.size() == 1);
    Assert.assertTrue(pagination.getTotalPage() >= 2);
    Assert.assertTrue(V.isEmpty(voList.get(0).getChildren()));
    pagination.setPageIndex(2);
    voList = dictionaryService.getViewObjectList(queryWrapper, pagination, DictionaryVO.class);
    Assert.assertTrue(voList.size() == 1);
}
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)

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