修改消息已读规则

master
胡锐 1 month ago
parent e26f98089e
commit 2d4866c6fa
  1. 12
      cweb/src/main/java/com/hfkj/controller/MessageController.java
  2. 1
      service/src/main/java/com/hfkj/dao/BsMessageMapperExt.java
  3. 8
      service/src/main/java/com/hfkj/service/message/BsMessageReadService.java
  4. 31
      service/src/main/java/com/hfkj/service/message/impl/BsMessageReadServiceImpl.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) {

@ -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" +
" <if test='param.msgStatus != null'> and a.`status` = #{param.msgStatus} </if>" +
" <if test='param.msgStatus != null'> and a.`status` = #{param.msgStatus} </if>" +
" <if test='param.type != null'> and a.type = #{param.type} </if>" +
" GROUP BY a.id" +
" ORDER BY a.create_time desc) a where 1 = 1" +

@ -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);
}

@ -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<String,Object> param = new HashMap<>();
param.put("userId", userId);
param.put("type", messageType.getType());
param.put("status", MessageStatusEnum.status2.getStatus());
// 未读
param.put("readStatus", 0);
// 查询数据
List<Map<String, Object>> list = messageService.getUserMsgList(param);
for (Map<String,Object> map : list) {
if (MapUtils.getLong(map, "id") != null) {
// 已读
BsMessageRead messageRead = new BsMessageRead();
messageRead.setMessageId(MapUtils.getLong(map, "id"));
messageRead.setUserId(userId);
messageRead.setStatus(1);
editData(messageRead);
}
}
}
}

Loading…
Cancel
Save