Merge branch '1.0.x' into dev
This commit is contained in:
commit
c1fbabaaa7
@ -26,12 +26,13 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
import top.charles7c.cnadmin.common.annotation.Query;
|
import top.charles7c.cnadmin.common.annotation.Query;
|
||||||
|
import top.charles7c.cnadmin.common.exception.BadRequestException;
|
||||||
import top.charles7c.cnadmin.common.util.ReflectUtils;
|
import top.charles7c.cnadmin.common.util.ReflectUtils;
|
||||||
|
import top.charles7c.cnadmin.common.util.validate.ValidationUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询助手
|
* 查询助手
|
||||||
@ -100,6 +101,10 @@ public class QueryHelper {
|
|||||||
|
|
||||||
// 解析查询条件
|
// 解析查询条件
|
||||||
parse(queryAnnotation, field.getName(), fieldValue, queryWrapper);
|
parse(queryAnnotation, field.getName(), fieldValue, queryWrapper);
|
||||||
|
} catch (BadRequestException e) {
|
||||||
|
log.error("Build query occurred an validation error: {}. Query: {}, Field: {}.", e.getMessage(), query,
|
||||||
|
field, e);
|
||||||
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Build query occurred an error: {}. Query: {}, Field: {}.", e.getMessage(), query, field, e);
|
log.error("Build query occurred an error: {}. Query: {}, Field: {}.", e.getMessage(), query, field, e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -140,8 +145,7 @@ public class QueryHelper {
|
|||||||
// 如果没有单独指定属性名,就和使用该注解的属性的名称一致
|
// 如果没有单独指定属性名,就和使用该注解的属性的名称一致
|
||||||
// 注意:数据库规范中列采用下划线连接法命名,程序规范中变量采用驼峰法命名
|
// 注意:数据库规范中列采用下划线连接法命名,程序规范中变量采用驼峰法命名
|
||||||
String property = queryAnnotation.property();
|
String property = queryAnnotation.property();
|
||||||
fieldName = StrUtil.blankToDefault(property, fieldName);
|
String columnName = StrUtil.toUnderlineCase(StrUtil.blankToDefault(property, fieldName));
|
||||||
String columnName = StrUtil.toUnderlineCase(fieldName);
|
|
||||||
Query.Type queryType = queryAnnotation.type();
|
Query.Type queryType = queryAnnotation.type();
|
||||||
switch (queryType) {
|
switch (queryType) {
|
||||||
case EQUAL:
|
case EQUAL:
|
||||||
@ -164,9 +168,8 @@ public class QueryHelper {
|
|||||||
break;
|
break;
|
||||||
case BETWEEN:
|
case BETWEEN:
|
||||||
List<Object> between = new ArrayList<>((List<Object>)fieldValue);
|
List<Object> between = new ArrayList<>((List<Object>)fieldValue);
|
||||||
if (between.size() >= 2) {
|
ValidationUtils.throwIf(between.size() != 2, "[{}] 必须是一个范围", fieldName);
|
||||||
queryWrapper.between(columnName, between.get(0), between.get(1));
|
queryWrapper.between(columnName, between.get(0), between.get(1));
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case LEFT_LIKE:
|
case LEFT_LIKE:
|
||||||
queryWrapper.likeLeft(columnName, fieldValue);
|
queryWrapper.likeLeft(columnName, fieldValue);
|
||||||
@ -178,14 +181,12 @@ public class QueryHelper {
|
|||||||
queryWrapper.likeRight(columnName, fieldValue);
|
queryWrapper.likeRight(columnName, fieldValue);
|
||||||
break;
|
break;
|
||||||
case IN:
|
case IN:
|
||||||
if (CollUtil.isNotEmpty((List<Object>)fieldValue)) {
|
ValidationUtils.throwIfEmpty(fieldValue, "[{}] 不能为空", fieldName);
|
||||||
queryWrapper.in(columnName, (List<Object>)fieldValue);
|
queryWrapper.in(columnName, (List<Object>)fieldValue);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case NOT_IN:
|
case NOT_IN:
|
||||||
if (CollUtil.isNotEmpty((List<Object>)fieldValue)) {
|
ValidationUtils.throwIfEmpty(fieldValue, "[{}] 不能为空", fieldName);
|
||||||
queryWrapper.notIn(columnName, (List<Object>)fieldValue);
|
queryWrapper.notIn(columnName, (List<Object>)fieldValue);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case IS_NULL:
|
case IS_NULL:
|
||||||
queryWrapper.isNull(columnName);
|
queryWrapper.isNull(columnName);
|
||||||
|
@ -16,6 +16,16 @@
|
|||||||
|
|
||||||
package top.charles7c.cnadmin.system.mapper;
|
package top.charles7c.cnadmin.system.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||||
|
|
||||||
|
import top.charles7c.cnadmin.common.annotation.DataPermission;
|
||||||
import top.charles7c.cnadmin.common.base.BaseMapper;
|
import top.charles7c.cnadmin.common.base.BaseMapper;
|
||||||
import top.charles7c.cnadmin.system.model.entity.UserDO;
|
import top.charles7c.cnadmin.system.model.entity.UserDO;
|
||||||
|
|
||||||
@ -25,4 +35,23 @@ import top.charles7c.cnadmin.system.model.entity.UserDO;
|
|||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 2022/12/22 21:47
|
* @since 2022/12/22 21:47
|
||||||
*/
|
*/
|
||||||
public interface UserMapper extends BaseMapper<UserDO> {}
|
public interface UserMapper extends BaseMapper<UserDO> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DataPermission
|
||||||
|
List<UserDO> selectList(@Param(Constants.WRAPPER) Wrapper<UserDO> queryWrapper);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DataPermission
|
||||||
|
<P extends IPage<UserDO>> P selectPage(P page, @Param(Constants.WRAPPER) Wrapper<UserDO> queryWrapper);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名查询
|
||||||
|
*
|
||||||
|
* @param username
|
||||||
|
* 用户名
|
||||||
|
* @return 用户信息
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM `sys_user` WHERE `username` = #{username}")
|
||||||
|
UserDO selectByUsername(@Param("username") String username);
|
||||||
|
}
|
||||||
|
@ -238,7 +238,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDO getByUsername(String username) {
|
public UserDO getByUsername(String username) {
|
||||||
return baseMapper.lambdaQuery().eq(UserDO::getUsername, username).one();
|
return baseMapper.selectByUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,4 +6,5 @@ module.exports = {
|
|||||||
quoteProps: 'consistent',
|
quoteProps: 'consistent',
|
||||||
htmlWhitespaceSensitivity: 'strict',
|
htmlWhitespaceSensitivity: 'strict',
|
||||||
vueIndentScriptAndStyle: true,
|
vueIndentScriptAndStyle: true,
|
||||||
|
endOfLine: 'auto',
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user