Skip to content

Commit

Permalink
feat: 添加多条件搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyudong committed Aug 5, 2023
1 parent 098d3e9 commit 58f179c
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ protected void addAttachmentStorage(MultipartFile file, AttachmentInfo attachmen

@Override
protected void deleteAttachmentStorage(List<Integer> attachmentInfoIds) {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ private PageHelperUtils() {

private static final int DEFAULT_PAGE_SIZE = 10;

private static final String DEFAULT_ORDER_BY = "order_num";
private static final String DEFAULT_ORDER_BY = "create_time";

private static final String DEFAULT_ORDER_TYPE = "desc";
private static final String ORDER_TYPE_DESC = "desc";

private static final String FONT_ORDER_TYPE_DESC = "descending";

private static final String FONT_ORDER_TYPE_ASC = "ascending";

private static final String FONT_ORDER_TYPE_SUFFIX = "ending";

private static final String FONT_DEFAULT_ORDER_BY = "normal";

/**
* 分页包装
Expand All @@ -49,17 +54,30 @@ public static void startPage(PageQuery pageQuery, String... orderParams) {
pageQuery.setOrderBy(orderParams[0]);
pageQuery.setOrderType(orderParams[1]);
}
} else {
}
if (StringUtils.isBlank(pageQuery.getOrderBy()) ||
StringUtils.isBlank(pageQuery.getOrderType()) ||
Objects.equals(pageQuery.getOrderType(), "null")) {
pageQuery.setOrderBy(DEFAULT_ORDER_BY);
pageQuery.setOrderType(DEFAULT_ORDER_TYPE);
pageQuery.setOrderType(ORDER_TYPE_DESC);
}
//后置处理查询
postProcessPageQuery(pageQuery);

PageHelper.startPage(pageQuery.getPageNum(), pageQuery.getPageSize(),
orderParams.length == 1 ? pageQuery.getOrderBy() :
StringUtils.toUnderlineCase(pageQuery.getOrderBy()) + " "
+ pageQuery.getOrderType());
}

private static void postProcessPageQuery(PageQuery pageQuery) {
if (StringUtils.equalsAny(pageQuery.getOrderType(), FONT_ORDER_TYPE_DESC,
FONT_ORDER_TYPE_ASC)) {
pageQuery.setOrderType(
StringUtils.subBefore(pageQuery.getOrderType(), FONT_ORDER_TYPE_SUFFIX, false));
}
}

/**
* 将分页的dto列表转为分页vo列表
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
+ "<if test=\"fromName != null and fromName != ''\">"
+ "and fromName like concat('%', #{fromName}, '%') "
+ "</if>"
+ "<if test=\"toName != null and toName != ''\">"
+ "and toName like concat('%', #{toName}, '%') "
+ "</if>"
+ "<if test=\"content != null and content != ''\">"
+ "and content like concat('%', #{content}, '%') "
+ "</if>"
+ "</where>"
+ "</script>")
List<ChatMessageDTO> selectChatMessageList(ChatMessagePageQuery chatMessagePageQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public interface NotificationMessageMapper extends BaseMapper<NotificationMessag
+ "<if test=\"title != null and title != ''\">"
+ "and title like concat('%', #{title}, '%') "
+ "</if>"
+ "<if test=\"content != null and content != ''\">"
+ "and content like concat('%', #{content}, '%') "
+ "</if>"
+ "</where>"
+ "</script>")
List<NotificationMessageDTO> selectNotificationMessageList(NotificationMessageQuery query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public class ChatMessagePageQuery extends PageQuery {

private String toName;

private String content;

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class NotificationMessageServiceImpl extends
@Override
public PageSerializable<NotificationMessageVO> pageNotificationMessage(
NotificationMessageQuery notificationMessageQuery) {
PageHelperUtils.startPage(notificationMessageQuery, Consts.CREATE_TIME_FIELD);
PageHelperUtils.startPage(notificationMessageQuery);
return PageHelperUtils.convertPageDto2Vo(
baseMapper.selectNotificationMessageList(notificationMessageQuery),
NotificationMessageMapping.INSTANCE::toNotificationMessageVOList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public interface CodeItemMapper extends BaseMapper<CodeItem> {
+ "<if test=\"itemText != null and itemText != ''\">"
+ "and item_text like concat('%', #{itemText}, '%') "
+ "</if>"
+ "<if test=\"itemValue != null and itemValue != ''\">"
+ "and item_value like concat('%', #{itemValue}, '%') "
+ "</if>"
+ "<if test=\"description != null and description != ''\">"
+ "and description like concat('%', #{description}, '%') "
+ "</if>"
+ "</where>"
+ "</script>")
List<CodeItemDTO> selectCodeItemList(CodeItemQuery systemConfigQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public interface CodeMainMapper extends BaseMapper<CodeMain> {
+ "<if test=\"codeName != null and codeName != ''\">"
+ "and code_name like concat('%', #{codeName}, '%') "
+ "</if>"
+ "<if test=\"description != null and description != ''\">"
+ "and description like concat('%', #{description}, '%') "
+ "</if>"
+ "</where>"
+ "</script>")
List<CodeMainDTO> selectCodeMainList(CodeMainQuery systemConfigQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public interface SystemConfigMapper extends BaseMapper<SystemConfig> {
+ "<if test=\"configName != null and configName != ''\">"
+ "and config_name like concat('%', #{configName}, '%') "
+ "</if>"
+ "<if test=\"configValue != null and configValue != ''\">"
+ "and config_value like concat('%', #{configValue}, '%') "
+ "</if>"
+ "<if test=\"description != null and description != ''\">"
+ "and description like concat('%', #{description}, '%') "
+ "</if>"
+ "</where>"
+ "</script>")
List<SystemConfigDTO> selectSystemConfigList(SystemConfigQuery systemConfigQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public interface LoginLogMapper extends BaseMapper<LoginLog> {
+ "<if test=\"nickname != null and nickname != ''\">"
+ "and nickname like concat('%', #{nickname}, '%') "
+ "</if>"
+ "<if test=\"location != null and location != ''\">"
+ "and location like concat('%', #{location}, '%') "
+ "</if>"
+ "<if test=\"userId != null and userId != ''\">"
+ "and user_id = #{userId}"
+ "</if>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public interface OperateLogMapper extends BaseMapper<OperateLog> {
+ "<if test=\"nickname != null and nickname != ''\">"
+ "and nickname like concat('%', #{nickname}, '%') "
+ "</if>"
+ "<if test=\"operation != null and operation != ''\">"
+ "and operation like concat('%', #{operation}, '%') "
+ "</if>"
+ "<if test=\"userId != null and userId != ''\">"
+ "and user_id = #{userId}"
+ "</if>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void run(int port) {
.childHandler(webSocketChatServerInitializer)
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);

ChannelFuture f = b.bind(port).sync();
f.addListener(future -> {
if (future.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketFrameDecoder;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
Expand All @@ -35,15 +42,24 @@ public class WebSocketServerInitializer extends ChannelInitializer<Channel> {

@Override
protected void initChannel(Channel channel) {
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(64 * 1024));
pipeline.addLast(new ChunkedWriteHandler());
// pipeline.addLast(new HttpRequestHandler("/ws"));
pipeline.addLast(authFilterHandler);
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
pipeline.addLast(textToMessageHandler);
pipeline.addLast(webSocketMessageHandler);
channel.pipeline()
.addLast(new LoggingHandler(LogLevel.TRACE))
// HttpRequestDecoder和HttpResponseEncoder的一个组合,针对http协议进行编解码
.addLast(new HttpServerCodec())
// 分块向客户端写数据,防止发送大文件时导致内存溢出, channel.write(new ChunkedFile(new File("bigFile.mkv")))
.addLast(new ChunkedWriteHandler())
// 将HttpMessage和HttpContents聚合到一个完成的 FullHttpRequest或FullHttpResponse中,具体是FullHttpRequest对象还是FullHttpResponse对象取决于是请求还是响应
// 需要放到HttpServerCodec这个处理器后面
.addLast(new HttpObjectAggregator(10240))
// webSocket 数据压缩扩展,当添加这个的时候WebSocketServerProtocolHandler的第三个参数需要设置成true
.addLast(new WebSocketServerCompressionHandler())
.addLast(authFilterHandler)
// 服务器端向外暴露的 web socket 端点,当客户端传递比较大的对象时,maxFrameSize参数的值需要调大
.addLast(new WebSocketServerProtocolHandler("/ws", null, true, 2 << 20))
// 自定义处理器 - 处理 web socket 文本消息
.addLast(textToMessageHandler)
// 自定义处理器 - 处理 web socket 二进制消息
.addLast(webSocketMessageHandler);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.simple.keen.server.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig;
import com.simple.keen.server.message.Message;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public interface DeptMapper extends BaseMapper<Dept> {
+ "<if test=\"deptName != null and deptName != ''\">"
+ "and dept_name like concat('%', #{deptName}, '%') "
+ "</if>"
+ "<if test=\"deptShortName != null and deptShortName != ''\">"
+ "and dept_short_name like concat('%', #{deptShortName}, '%') "
+ "</if>"
+ "</script>")
@Results(id = "BaseResultMap", value = {
@Result(column = "id", property = "id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public interface MenuMapper extends BaseMapper<Menu> {
+ "<if test = \" title != null and title !='' \">"
+ " and title like concat('%', #{title}, '%')"
+ "</if>"
+ "<if test = \" component != null and component !='' \">"
+ " and component like concat('%', #{component}, '%')"
+ "</if>"
+ "<if test = \" path != null and path !='' \">"
+ " and path like concat('%', #{path}, '%')"
+ "</if>"
+ "</script>")
@Results(id = "BaseResultMap", value = {
@Result(column = "id", property = "id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public interface RoleMapper extends BaseMapper<Role> {
+ "<if test=\"roleName != null and roleName != ''\">"
+ "and role_name like concat('%', #{roleName}, '%') "
+ "</if>"
+ "<if test=\"roleTag != null and roleTag != ''\">"
+ "and role_tag like concat('%', #{roleTag}, '%') "
+ "</if>"
+ "<if test=\"description != null and description != ''\">"
+ "and description like concat('%', #{description}, '%') "
+ "</if>"
+ "</script>")
List<RoleDTO> selectRoleList(RoleQuery roleQuery);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public interface UserMapper extends BaseMapper<User> {
+ "<if test=\"nickname != null and nickname != ''\">"
+ "and nickname like concat('%', #{nickname}, '%') "
+ "</if>"
+ "<if test=\"username != null and username != ''\">"
+ "and username like concat('%', #{username}, '%') "
+ "</if>"
+ "<if test=\"deptId != null\">"
+ "and dept_id = #{deptId} "
+ "</if>"
+ "<if test=\"status != null\">"
+ "and status = #{status}"
+ "</if>"
+ "order by order_num desc"
+ "</script>")
List<UserDTO> selectUserList(UserQuery userQuery);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<aliyun-oss.version>3.10.2</aliyun-oss.version>
<sa-token.version>1.34.0</sa-token.version>
<ip2region.version>1.7.2</ip2region.version>
<fastjson.version>1.2.47</fastjson.version>
<fastjson.version>1.2.83</fastjson.version>
<thumbnailator.version>0.4.8</thumbnailator.version>

</properties>
Expand Down

0 comments on commit 58f179c

Please sign in to comment.