use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project diboot by dibo-software.
the class IamAccountServiceImpl method getAuthAccount.
@Override
public String getAuthAccount(String userType, Long userId) {
LambdaQueryWrapper<IamAccount> queryWrapper = new QueryWrapper<IamAccount>().lambda().select(IamAccount::getAuthAccount).eq(IamAccount::getUserType, userType).eq(IamAccount::getUserId, userId);
IamAccount account = getSingleEntity(queryWrapper);
return account != null ? account.getAuthAccount() : null;
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project diboot by dibo-software.
the class ServiceAdaptor method optimizeSelect.
/**
* 基于VO提取最小集select字段
* @param queryWrapper
* @param voClass
*/
public static <T> Wrapper<T> optimizeSelect(Wrapper<T> queryWrapper, Class<T> entityClass, Class<?> voClass) {
if (!(queryWrapper instanceof QueryWrapper) || queryWrapper.getSqlSelect() != null) {
return queryWrapper;
}
List<TableFieldInfo> allColumns = TableInfoHelper.getTableInfo(entityClass).getFieldList();
if (V.isEmpty(allColumns)) {
return queryWrapper;
}
List<String> columns = new ArrayList<>();
String pk = ContextHelper.getIdColumnName(entityClass);
if (V.notEmpty(pk)) {
columns.add(pk);
}
Map<String, Field> fieldsMap = BindingCacheManager.getFieldsMap(voClass);
for (TableFieldInfo col : allColumns) {
if (fieldsMap.containsKey(col.getField().getName()) && V.notEmpty(col.getColumn()) && !col.isLogicDelete()) {
columns.add(col.getSqlSelect());
}
}
// select全部列,不特殊处理
if (allColumns.size() <= columns.size()) {
return queryWrapper;
}
return ((QueryWrapper) queryWrapper).select(S.toStringArray(columns));
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper 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.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project diboot by dibo-software.
the class BaseServiceTest method testCache.
@Test
public void testCache() {
EntityInfoCache entityInfoCache = BindingCacheManager.getEntityInfoByClass(Dictionary.class);
Assert.assertTrue(entityInfoCache != null);
Assert.assertTrue(entityInfoCache.getDeletedColumn().equals("is_deleted"));
entityInfoCache = BindingCacheManager.getEntityInfoByClass(CcCityInfo.class);
Assert.assertTrue(entityInfoCache != null);
Assert.assertTrue(entityInfoCache.getIdColumn().equals("id"));
Assert.assertTrue(entityInfoCache.getDeletedColumn() == null);
BaseMapper baseMapper = BindingCacheManager.getMapperByTable("user_role");
Assert.assertTrue(baseMapper != null);
Class<?> entityClass = BindingCacheManager.getEntityClassBySimpleName("Dictionary");
Assert.assertTrue(entityClass != null && entityClass.getName().equals(Dictionary.class.getName()));
// 测试PropInfo缓存
QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", "GENDER").eq("item_value", "F");
Dictionary dictionary = dictionaryService.getSingleEntity(queryWrapper);
DictionaryVO dictionaryVO = RelationsBinder.convertAndBind(dictionary, DictionaryVO.class);
Assert.assertTrue(dictionaryVO.getPrimaryKeyVal().equals(dictionary.getId()));
Assert.assertTrue(ContextHelper.getIdFieldName(dictionaryVO.getClass()).equals("id"));
}
use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project diboot by dibo-software.
the class MiddleTable method queryByMapper.
/**
* 通过定义的Mapper查询结果
* @param linkage
* @param trunkObjCol2ValuesMap
* @return
*/
private List<Map<String, Object>> queryByMapper(EntityInfoCache linkage, Map<String, List> trunkObjCol2ValuesMap) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.setEntityClass(linkage.getEntityClass());
// select所需字段
queryWrapper.select(getSelectColumns());
for (Map.Entry<String, List> entry : trunkObjCol2ValuesMap.entrySet()) {
String column = entry.getKey();
if (column != null && V.notEmpty(entry.getValue())) {
queryWrapper.in(column, entry.getValue());
}
}
if (additionalConditions != null) {
for (String condition : additionalConditions) {
queryWrapper.apply(condition);
}
}
BaseMapper mapper = linkage.getBaseMapper();
List<Map<String, Object>> resultSetMapList = mapper.selectMaps(queryWrapper);
return resultSetMapList;
}
Aggregations