From 2d4866c6facbaccf6abd8e0bb33e9be4cac33397 Mon Sep 17 00:00:00 2001
From: hu177768073 <177768073@qq.com>
Date: Tue, 15 Oct 2024 17:42:01 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B6=88=E6=81=AF=E5=B7=B2?=
=?UTF-8?q?=E8=AF=BB=E8=A7=84=E5=88=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../hfkj/controller/MessageController.java | 12 ++-----
.../java/com/hfkj/dao/BsMessageMapperExt.java | 1 -
.../service/message/BsMessageReadService.java | 8 +++++
.../impl/BsMessageReadServiceImpl.java | 31 +++++++++++++++++++
4 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/cweb/src/main/java/com/hfkj/controller/MessageController.java b/cweb/src/main/java/com/hfkj/controller/MessageController.java
index 9337774..4569034 100644
--- a/cweb/src/main/java/com/hfkj/controller/MessageController.java
+++ b/cweb/src/main/java/com/hfkj/controller/MessageController.java
@@ -108,19 +108,13 @@ public class MessageController {
@ApiOperation(value = "已读")
public ResponseData read(@RequestBody JSONObject body) {
try {
- if (body == null || body.getLong("id") == null) {
+ if (body == null || body.getInteger("type") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
// 是否存在记录
- BsMessageRead messageRead = messageReadService.getDetail(body.getLong("id"), userSession.getUser().getId());
- if (messageRead == null) {
- messageRead = new BsMessageRead();
- messageRead.setMessageId(body.getLong("id"));
- messageRead.setUserId(userSession.getUser().getId());
- messageRead.setStatus(1);
- messageReadService.editData(messageRead);
- }
+ messageReadService.read(userSession.getUser().getId(), MessageTypeEnum.getDataByType(body.getInteger("type")));
+
return ResponseMsgUtil.success("成功");
} catch (Exception e) {
diff --git a/service/src/main/java/com/hfkj/dao/BsMessageMapperExt.java b/service/src/main/java/com/hfkj/dao/BsMessageMapperExt.java
index 2e8c5af..dbac4c0 100644
--- a/service/src/main/java/com/hfkj/dao/BsMessageMapperExt.java
+++ b/service/src/main/java/com/hfkj/dao/BsMessageMapperExt.java
@@ -26,7 +26,6 @@ public interface BsMessageMapperExt {
" LEFT JOIN bs_message_read b on b.message_id = a.id and b.user_id = #{param.userId} and b.`status` = 1" +
" where 1 = 1 and a.user_id = #{param.userId} or a.user_id is null" +
" and a.`status` = #{param.msgStatus} " +
- " and a.`status` = #{param.msgStatus} " +
" and a.type = #{param.type} " +
" GROUP BY a.id" +
" ORDER BY a.create_time desc) a where 1 = 1" +
diff --git a/service/src/main/java/com/hfkj/service/message/BsMessageReadService.java b/service/src/main/java/com/hfkj/service/message/BsMessageReadService.java
index 1c7adcb..187b939 100644
--- a/service/src/main/java/com/hfkj/service/message/BsMessageReadService.java
+++ b/service/src/main/java/com/hfkj/service/message/BsMessageReadService.java
@@ -1,6 +1,7 @@
package com.hfkj.service.message;
import com.hfkj.entity.BsMessageRead;
+import com.hfkj.sysenum.message.MessageTypeEnum;
/**
* @className: BsMessageReadService
@@ -23,4 +24,11 @@ public interface BsMessageReadService {
*/
BsMessageRead getDetail(Long msgId,Long userId);
+ /**
+ * 已读
+ * @param userId
+ * @param messageType
+ */
+ void read(Long userId, MessageTypeEnum messageType);
+
}
diff --git a/service/src/main/java/com/hfkj/service/message/impl/BsMessageReadServiceImpl.java b/service/src/main/java/com/hfkj/service/message/impl/BsMessageReadServiceImpl.java
index 9326ae0..231e1dd 100644
--- a/service/src/main/java/com/hfkj/service/message/impl/BsMessageReadServiceImpl.java
+++ b/service/src/main/java/com/hfkj/service/message/impl/BsMessageReadServiceImpl.java
@@ -4,11 +4,17 @@ import com.hfkj.dao.BsMessageReadMapper;
import com.hfkj.entity.BsMessageRead;
import com.hfkj.entity.BsMessageReadExample;
import com.hfkj.service.message.BsMessageReadService;
+import com.hfkj.service.message.BsMessageService;
+import com.hfkj.sysenum.message.MessageStatusEnum;
+import com.hfkj.sysenum.message.MessageTypeEnum;
+import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @className: BsMessageReadServiceImpl
@@ -19,6 +25,8 @@ import java.util.List;
public class BsMessageReadServiceImpl implements BsMessageReadService {
@Resource
private BsMessageReadMapper messageReadMapper;
+ @Resource
+ private BsMessageService messageService;
@Override
public void editData(BsMessageRead data) {
@@ -40,4 +48,27 @@ public class BsMessageReadServiceImpl implements BsMessageReadService {
}
return null;
}
+
+ @Override
+ public void read(Long userId, MessageTypeEnum messageType) {
+ Map param = new HashMap<>();
+ param.put("userId", userId);
+ param.put("type", messageType.getType());
+ param.put("status", MessageStatusEnum.status2.getStatus());
+ // 未读
+ param.put("readStatus", 0);
+
+ // 查询数据
+ List