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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations