Skip to content

Commit

Permalink
refactor: 优化 Query 相关注解使用方式
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jan 24, 2024
1 parent 9648cf6 commit 15b1520
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@

package top.charles7c.continew.admin.monitor.model.query;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import lombok.Data;

import cn.hutool.core.date.DatePattern;
import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import cn.hutool.core.date.DatePattern;

import top.charles7c.continew.starter.data.mybatis.plus.query.Query;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryType;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
* 登录日志查询条件
*
Expand All @@ -49,7 +45,6 @@ public class LoginLogQuery implements Serializable {
* 登录状态
*/
@Schema(description = "登录状态(1:成功;2:失败)", example = "1")
@Query
private Integer status;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class OperationLogQuery implements Serializable {
* 操作状态
*/
@Schema(description = "操作状态(1:成功;2:失败)", example = "1")
@Query
private Integer status;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import top.charles7c.continew.admin.monitor.service.LogService;
import top.charles7c.continew.starter.core.util.ReflectUtils;
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryHelper;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryWrapperHelper;
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;

Expand All @@ -58,7 +58,7 @@ public class LogServiceImpl implements LogService {
@Override
@AutoOperate(type = OperationLogResp.class, on = "list")
public PageResp<OperationLogResp> page(OperationLogQuery query, PageQuery pageQuery) {
QueryWrapper<LogDO> queryWrapper = QueryHelper.build(query);
QueryWrapper<LogDO> queryWrapper = QueryWrapperHelper.build(query);
// 限定查询信息
List<String> fieldNameList = ReflectUtils.getNonStaticFieldsName(OperationLogResp.class);
List<String> columnNameList = fieldNameList.stream()
Expand All @@ -74,7 +74,7 @@ public PageResp<OperationLogResp> page(OperationLogQuery query, PageQuery pageQu
@Override
@AutoOperate(type = LoginLogResp.class, on = "list")
public PageResp<LoginLogResp> page(LoginLogQuery query, PageQuery pageQuery) {
QueryWrapper<LogDO> queryWrapper = QueryHelper.build(query);
QueryWrapper<LogDO> queryWrapper = QueryWrapperHelper.build(query);
queryWrapper.eq("module", "登录");
// 限定查询信息
List<String> fieldNameList = ReflectUtils.getNonStaticFieldsName(LoginLogResp.class);
Expand All @@ -91,7 +91,7 @@ public PageResp<LoginLogResp> page(LoginLogQuery query, PageQuery pageQuery) {
@Override
@AutoOperate(type = SystemLogResp.class, on = "list")
public PageResp<SystemLogResp> page(SystemLogQuery query, PageQuery pageQuery) {
QueryWrapper<LogDO> queryWrapper = QueryHelper.build(query);
QueryWrapper<LogDO> queryWrapper = QueryWrapperHelper.build(query);
// 限定查询信息
List<String> fieldNameList = ReflectUtils.getNonStaticFieldsName(SystemLogResp.class);
List<String> columnNameList = fieldNameList.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@

package top.charles7c.continew.admin.auth.model.resp;

import cn.hutool.core.util.DesensitizedUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.charles7c.continew.admin.common.enums.GenderEnum;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Set;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import com.fasterxml.jackson.annotation.JsonIgnore;

import cn.hutool.core.util.DesensitizedUtil;

import top.charles7c.continew.admin.common.enums.GenderEnum;

/**
* 用户信息
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

package top.charles7c.continew.admin.system.model.query;

import java.io.Serial;
import java.io.Serializable;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import top.charles7c.continew.starter.data.mybatis.plus.query.Query;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryType;

import java.io.Serial;
import java.io.Serializable;

/**
* 公告查询条件
*
Expand All @@ -50,6 +48,5 @@ public class AnnouncementQuery implements Serializable {
* 类型
*/
@Schema(description = "类型", example = "1")
@Query
private String type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

package top.charles7c.continew.admin.system.model.query;

import java.io.Serial;
import java.io.Serializable;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import top.charles7c.continew.starter.data.mybatis.plus.query.Query;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryType;

import java.io.Serial;
import java.io.Serializable;

/**
* 部门查询条件
*
Expand All @@ -50,6 +48,5 @@ public class DeptQuery implements Serializable {
* 状态
*/
@Schema(description = "状态(1:启用;2:禁用)", example = "1")
@Query
private Integer status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

package top.charles7c.continew.admin.system.model.query;

import java.io.Serial;
import java.io.Serializable;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import top.charles7c.continew.starter.data.mybatis.plus.query.Query;
import java.io.Serial;
import java.io.Serializable;

/**
* 字典项查询条件
Expand All @@ -42,6 +39,5 @@ public class DictItemQuery implements Serializable {
* 字典 ID
*/
@Schema(description = "字典 ID")
@Query
private Long dictId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

package top.charles7c.continew.admin.system.model.query;

import java.io.Serial;
import java.io.Serializable;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import top.charles7c.continew.starter.data.mybatis.plus.query.Query;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryType;

import java.io.Serial;
import java.io.Serializable;

/**
* 文件查询条件
*
Expand All @@ -50,6 +48,5 @@ public class FileQuery implements Serializable {
* 类型
*/
@Schema(description = "类型")
@Query
private Integer type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

package top.charles7c.continew.admin.system.model.query;

import java.io.Serial;
import java.io.Serializable;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import top.charles7c.continew.starter.data.mybatis.plus.query.Query;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryType;

import java.io.Serial;
import java.io.Serializable;

/**
* 菜单查询条件
*
Expand All @@ -50,6 +48,5 @@ public class MenuQuery implements Serializable {
* 状态
*/
@Schema(description = "状态(1:启用;2:禁用)", example = "1")
@Query
private Integer status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

package top.charles7c.continew.admin.system.model.query;

import java.io.Serializable;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import top.charles7c.continew.starter.data.mybatis.plus.query.Query;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryIgnore;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryType;

import java.io.Serializable;

/**
* 消息查询条件
*
Expand All @@ -41,7 +40,6 @@ public class MessageQuery implements Serializable {
* ID
*/
@Schema(description = "ID", example = "1")
@Query
private Long id;

/**
Expand All @@ -55,18 +53,19 @@ public class MessageQuery implements Serializable {
* 类型
*/
@Schema(description = "类型(1:系统消息)", example = "1")
@Query
private Integer type;

/**
* 是否已读
*/
@Schema(description = "是否已读", example = "true")
@QueryIgnore
private Boolean isRead;

/**
* 用户 ID
*/
@Schema(hidden = true)
@QueryIgnore
private Long userId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ public class RoleQuery implements Serializable {
* 状态
*/
@Schema(description = "状态(1:启用;2:禁用)", example = "1")
@Query
private Integer status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

package top.charles7c.continew.admin.system.model.query;

import java.io.Serial;
import java.io.Serializable;

import lombok.Data;

import io.swagger.v3.oas.annotations.media.Schema;

import lombok.Data;
import top.charles7c.continew.starter.data.mybatis.plus.query.Query;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryType;

import java.io.Serial;
import java.io.Serializable;

/**
* 存储库查询条件
*
Expand All @@ -50,6 +48,5 @@ public class StorageQuery implements Serializable {
* 状态
*/
@Schema(description = "状态")
@Query
private Integer status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class UserQuery implements Serializable {
* 状态
*/
@Schema(description = "状态(1:启用;2:禁用)", example = "1")
@Query
private Integer status;

/**
Expand All @@ -67,6 +66,5 @@ public class UserQuery implements Serializable {
* 部门 ID
*/
@Schema(description = "部门 ID", example = "1")
@Query
private Long deptId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import top.charles7c.continew.admin.system.service.MessageService;
import top.charles7c.continew.admin.system.service.MessageUserService;
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryHelper;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryWrapperHelper;
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;

Expand All @@ -54,7 +54,7 @@ public class MessageServiceImpl implements MessageService {
@Override
@AutoOperate(type = MessageResp.class, on = "list")
public PageResp<MessageResp> page(MessageQuery query, PageQuery pageQuery) {
QueryWrapper<MessageDO> queryWrapper = QueryHelper.build(query);
QueryWrapper<MessageDO> queryWrapper = QueryWrapperHelper.build(query);
queryWrapper.apply(null != query.getUserId(), "t2.user_id={0}", query.getUserId())
.apply(null != query.getIsRead(), "t2.is_read={0}", query.getIsRead());
IPage<MessageResp> page = baseMapper.selectPageByUserId(pageQuery.toPage(), queryWrapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import top.charles7c.continew.admin.system.model.req.OptionResetValueReq;
import top.charles7c.continew.admin.system.model.resp.OptionResp;
import top.charles7c.continew.admin.system.service.OptionService;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryHelper;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryWrapperHelper;

import java.util.List;

Expand All @@ -46,7 +46,7 @@ public class OptionServiceImpl implements OptionService {

@Override
public List<OptionResp> list(OptionQuery query) {
return BeanUtil.copyToList(baseMapper.selectList(QueryHelper.build(query)), OptionResp.class);
return BeanUtil.copyToList(baseMapper.selectList(QueryWrapperHelper.build(query)), OptionResp.class);
}

@Override
Expand Down

0 comments on commit 15b1520

Please sign in to comment.