Search in sources :

Example 1 with QueryWrapper

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;
}
Also used : IamAccount(com.diboot.iam.entity.IamAccount) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 2 with QueryWrapper

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));
}
Also used : Field(java.lang.reflect.Field) TableFieldInfo(com.baomidou.mybatisplus.core.metadata.TableFieldInfo) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ArrayList(java.util.ArrayList)

Example 3 with QueryWrapper

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);
}
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 4 with QueryWrapper

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"));
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) CcCityInfo(diboot.core.test.binder.entity.CcCityInfo) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BaseMapper(com.baomidou.mybatisplus.core.mapper.BaseMapper) SimpleDictionaryVO(diboot.core.test.binder.vo.SimpleDictionaryVO) EntityInfoCache(com.diboot.core.binding.parser.EntityInfoCache) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with QueryWrapper

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;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BaseMapper(com.baomidou.mybatisplus.core.mapper.BaseMapper)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)723 Transactional (org.springframework.transaction.annotation.Transactional)98 IPage (com.baomidou.mybatisplus.core.metadata.IPage)82 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)74 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)72 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)65 ArrayList (java.util.ArrayList)61 Session (org.apache.shiro.session.Session)61 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)60 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)55 Problem (top.hcode.hoj.pojo.entity.problem.Problem)50 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)45 Date (java.util.Date)44 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 HashMap (java.util.HashMap)34 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)34 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)34 ApiOperation (io.swagger.annotations.ApiOperation)32 HttpSession (javax.servlet.http.HttpSession)31 Judge (top.hcode.hoj.pojo.entity.judge.Judge)30