提交 db947bd1 作者: han

查询列表时增加分页

上级 20936c81
package com.mmc.iuav.user.model.qo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @Author han
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MessageQO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "页码", required = true, example = "1")
@NotNull(message = "页码不能为空", groups = Page.class)
@Min(value = 1, groups = Page.class)
private Integer pageNo;
@ApiModelProperty(value = "每页显示数", required = true, example = "10")
@NotNull(message = "每页显示数不能为空", groups = Page.class)
@Min(value = 1, groups = Page.class)
private Integer pageSize;
public void buildCurrentPage() {
this.pageNo = (pageNo - 1) * pageSize;
}
}
package com.mmc.iuav.user.controller; package com.mmc.iuav.user.controller;
import com.mmc.iuav.response.ResultBody; import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.model.qo.MessageQO;
import com.mmc.iuav.user.model.vo.SystemMessageVO; import com.mmc.iuav.user.model.vo.SystemMessageVO;
import com.mmc.iuav.user.service.MessageService; import com.mmc.iuav.user.service.MessageService;
import io.swagger.annotations.*; import io.swagger.annotations.*;
...@@ -32,9 +33,9 @@ public class MessageController extends BaseController{ ...@@ -32,9 +33,9 @@ public class MessageController extends BaseController{
} }
@ApiOperation(value = "后台——系统消息列表") @ApiOperation(value = "后台——系统消息列表")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)}) @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@GetMapping("/selectAllSystemMessage") @PostMapping("/selectAllSystemMessage")
public ResultBody selectAllSystemMessage(){ public ResultBody selectAllSystemMessage(@RequestBody MessageQO messageQO){
return messageService.selectAllSystemMessage(); return ResultBody.success(messageService.selectAllSystemMessage(messageQO));
} }
@ApiOperation(value = "后台——删除消息") @ApiOperation(value = "后台——删除消息")
...@@ -46,10 +47,10 @@ public class MessageController extends BaseController{ ...@@ -46,10 +47,10 @@ public class MessageController extends BaseController{
@ApiOperation(value = "用户——系统消息列表") @ApiOperation(value = "用户——系统消息列表")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)}) @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
@GetMapping("/systemMessageListByUser") @PostMapping("/systemMessageListByUser")
public ResultBody selectAllSystemMessageByUser(HttpServletRequest request){ public ResultBody selectAllSystemMessageByUser(HttpServletRequest request,@RequestBody MessageQO messageQO){
Integer userId = this.getUserLoginInfoFromRedis(request).getUserAccountId(); Integer userId = this.getUserLoginInfoFromRedis(request).getUserAccountId();
return messageService.selectAllSystemMessageByReceive(userId); return ResultBody.success(messageService.selectAllSystemMessageByReceive(userId,messageQO));
} }
@ApiOperation(value = "用户查看——系统消息详情") @ApiOperation(value = "用户查看——系统消息详情")
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)}) @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ResultBody.class)})
......
package com.mmc.iuav.user.dao; package com.mmc.iuav.user.dao;
import com.mmc.iuav.user.entity.SystemMessageDO; import com.mmc.iuav.user.entity.SystemMessageDO;
import com.mmc.iuav.user.model.qo.MessageQO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -31,7 +32,9 @@ public interface MessageDao { ...@@ -31,7 +32,9 @@ public interface MessageDao {
* 查询所有的系统消息 * 查询所有的系统消息
* @return * @return
*/ */
List<SystemMessageDO> selectAllSystemMessage(); List<SystemMessageDO> selectAllSystemMessage(MessageQO messageQO);
int countSystemMessage();
/** /**
* 删除消息 * 删除消息
......
package com.mmc.iuav.user.service; package com.mmc.iuav.user.service;
import com.mmc.iuav.page.PageResult;
import com.mmc.iuav.response.ResultBody; import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.entity.SystemMessageDO; import com.mmc.iuav.user.entity.SystemMessageDO;
import com.mmc.iuav.user.model.qo.MessageQO;
import com.mmc.iuav.user.model.vo.SystemMessageVO; import com.mmc.iuav.user.model.vo.SystemMessageVO;
import java.util.List; import java.util.List;
...@@ -26,7 +28,7 @@ public interface MessageService { ...@@ -26,7 +28,7 @@ public interface MessageService {
* 查询所有的系统消息 * 查询所有的系统消息
* @return * @return
*/ */
ResultBody selectAllSystemMessage(); PageResult selectAllSystemMessage(MessageQO messageQO);
/** /**
* 删除消息 * 删除消息
...@@ -40,7 +42,7 @@ public interface MessageService { ...@@ -40,7 +42,7 @@ public interface MessageService {
* 查询所有的系统消息 * 查询所有的系统消息
* @return * @return
*/ */
ResultBody selectAllSystemMessageByReceive(Integer userId); PageResult selectAllSystemMessageByReceive(Integer userId, MessageQO messageQO);
/** /**
* 用户查看——系统消息详情 * 用户查看——系统消息详情
......
package com.mmc.iuav.user.service.impl; package com.mmc.iuav.user.service.impl;
import com.mmc.iuav.page.PageResult;
import com.mmc.iuav.response.ResultBody; import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.user.dao.MessageDao; import com.mmc.iuav.user.dao.MessageDao;
import com.mmc.iuav.user.entity.SystemMessageDO; import com.mmc.iuav.user.entity.SystemMessageDO;
import com.mmc.iuav.user.model.qo.MessageQO;
import com.mmc.iuav.user.model.vo.SystemMessageVO; import com.mmc.iuav.user.model.vo.SystemMessageVO;
import com.mmc.iuav.user.service.MessageService; import com.mmc.iuav.user.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -31,8 +33,15 @@ public class MessageServiceImpl implements MessageService { ...@@ -31,8 +33,15 @@ public class MessageServiceImpl implements MessageService {
} }
@Override @Override
public ResultBody selectAllSystemMessage() { public PageResult selectAllSystemMessage(MessageQO messageQO) {
return ResultBody.success(messageDao.selectAllSystemMessage()); int count = messageDao.countSystemMessage();
if (count == 0) {
return PageResult.buildPage(messageQO.getPageNo(), messageQO.getPageSize(), count);
}
Integer pageNo = messageQO.getPageNo();
messageQO.buildCurrentPage();
List<SystemMessageDO> messageList = messageDao.selectAllSystemMessage(messageQO);
return PageResult.buildPage(pageNo, messageQO.getPageSize(), count, messageList);
} }
@Override @Override
public ResultBody removeMessage(Integer id) { public ResultBody removeMessage(Integer id) {
...@@ -43,12 +52,18 @@ public class MessageServiceImpl implements MessageService { ...@@ -43,12 +52,18 @@ public class MessageServiceImpl implements MessageService {
return ResultBody.error("删除失败"); return ResultBody.error("删除失败");
} }
@Override @Override
public ResultBody selectAllSystemMessageByReceive(Integer userId) { public PageResult selectAllSystemMessageByReceive(Integer userId, MessageQO messageQO) {
if(userId == null){ if(userId == null){
ResultBody.error("未登录"); ResultBody.error("未登录");
} }
int count = messageDao.countSystemMessage();
if (count == 0) {
return PageResult.buildPage(messageQO.getPageNo(), messageQO.getPageSize(), count);
}
Integer pageNo = messageQO.getPageNo();
messageQO.buildCurrentPage();
List<SystemMessageDO> messagesDO = new ArrayList<>(); List<SystemMessageDO> messagesDO = new ArrayList<>();
List<SystemMessageDO> messages = messageDao.selectAllSystemMessage(); List<SystemMessageDO> messages = messageDao.selectAllSystemMessage(messageQO);
for (SystemMessageDO message : messages) { for (SystemMessageDO message : messages) {
if(messageDao.selectReceiverMessage(userId, message.getId()) != 0){ if(messageDao.selectReceiverMessage(userId, message.getId()) != 0){
// 已读 // 已读
...@@ -60,7 +75,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -60,7 +75,7 @@ public class MessageServiceImpl implements MessageService {
} }
messagesDO.add(message); messagesDO.add(message);
} }
return ResultBody.success(messagesDO); return PageResult.buildPage(pageNo, messageQO.getPageSize(), count, messagesDO);
} }
@Override @Override
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
id, subject, content, type, create_time id, subject, content, type, create_time
from message from message
where type = 0 and is_deleted = 0 where type = 0 and is_deleted = 0
order by create_time desc
LIMIT #{pageNo},#{pageSize}
</select> </select>
<select id="selectReceiverMessage" resultType="java.lang.Integer"> <select id="selectReceiverMessage" resultType="java.lang.Integer">
select count(*) select count(*)
...@@ -27,6 +29,12 @@ ...@@ -27,6 +29,12 @@
from receiver_message from receiver_message
where user_id = #{userId} and message_id = #{messageId} and is_deleted = 1 where user_id = #{userId} and message_id = #{messageId} and is_deleted = 1
</select> </select>
<select id="countSystemMessage" resultType="java.lang.Integer">
SELECT
count(*)
FROM message
where is_deleted = 0
</select>
<insert id="insertSystemMessage"> <insert id="insertSystemMessage">
insert into message insert into message
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论