咨询服务名片消息已读接口

This commit is contained in:
feng
2025-12-10 15:02:14 +08:00
parent fe5ca6619c
commit 569e23322f
6 changed files with 231 additions and 0 deletions
@@ -0,0 +1,65 @@
package com.renkang.consultation.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: Im消息已读日志 , 目前用于新疆项目中医生名片点击次数限制 且此表中暂时只存储了医生名片类型的消息
* @Author: feng
* @Date: 2025-12-10
* @Version: V1.0
*/
@Data
@TableName("im_msg_read_log")
@EqualsAndHashCode(callSuper = false)
@Schema(title = "Im消息已读日志", description = "Im消息已读日志")
public class ImMsgReadLog implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(title = "id")
private String id;
/**
* 群组ID
*/
@Schema(title = "群组ID")
private String groupId;
/**
* 发送者账号
*/
@Schema(title = "发送者账号")
private String fromAccount;
/**
* 接受者账号(消息已读人员账号)
*/
@Schema(title = "接受者账号")
private String toAccount;
/**
* 消息ID (腾讯IM平台生成的消息ID 并非im_msg_record_all表的ID)
*/
@Schema(title = "消息ID(腾讯IM平台生成的消息ID)")
private String msgId;
/**
* 读取次数(点击次数)
*/
@Schema(title = "读取次数(点击次数)")
private Integer readCount;
/**
* 发送时间
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Schema(title = "读取时间")
private Date readTime;
}
@@ -0,0 +1,35 @@
package com.renkang.consultation.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
@Schema(title = "Im消息已读日志vo", description = "Im消息已读日志vo")
public class ImMsgReadLogVO {
/**
* 群组ID
*/
@Schema(title = "群组ID")
@NotNull(message = "缺少必填参数:groupid")
private String groupId;
/**
* 发送者账号
*/
@Schema(title = "发送者账号")
@NotNull(message = "缺少必填参数:fromAccount")
private String fromAccount;
/**
* 接受者账号(消息已读人员账号)
*/
@Schema(title = "接受者账号")
@NotNull(message = "缺少必填参数:toAccount")
private String toAccount;
/**
* 消息ID (腾讯IM平台生成的消息ID 并非im_msg_record_all表的ID)
*/
@Schema(title = "消息ID(腾讯IM平台生成的消息ID)")
@NotNull(message = "缺少必填参数:msgId")
private String msgId;
}
@@ -0,0 +1,38 @@
package com.renkang.consultation.controller;
import com.renkang.consultation.service.ImMsgReadLogService;
import com.renkang.consultation.vo.ImMsgReadLogVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
@Slf4j
@Tag(name = "咨询消息已读管理")
@RestController
@RequestMapping("/con-message")
@RequiredArgsConstructor
public class ImMsgReadLogController {
private final ImMsgReadLogService imMsgReadLogService;
@PostMapping("/saveReadLog")
@Operation(summary = "记录消息已读日志", description = "记录消息已读日志")
public Result<String> saveReadLog(@RequestBody @Valid ImMsgReadLogVO imMsgReadLogVO) {
return Result.OK(imMsgReadLogService.saveReadLog(imMsgReadLogVO));
}
@PostMapping("/findReadStatus")
@Operation(summary = "查询消息是否已读", description = "查询消息是否已读(暂时只支持查询自定义消息类型的已读记录-医生名片)")
public Result<Map<String,Integer>> findReadStatus(List<String> msgIdList) {
return Result.OK(imMsgReadLogService.findReadStatus(msgIdList));
}
}
@@ -0,0 +1,9 @@
package com.renkang.consultation.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.renkang.consultation.entity.ImMsgReadLog;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ImMsgReadLogMapper extends MPJBaseMapper<ImMsgReadLog> {
}
@@ -0,0 +1,22 @@
package com.renkang.consultation.service;
import com.renkang.consultation.vo.ImMsgReadLogVO;
import java.util.List;
import java.util.Map;
public interface ImMsgReadLogService {
/**
* 记录消息已读日志
* @param imMsgReadLogVO
* @return
*/
String saveReadLog(ImMsgReadLogVO imMsgReadLogVO);
/**
* 查询消息是否已读
* @param msgIdList
* @return
*/
Map<String,Integer> findReadStatus(List<String> msgIdList);
}
@@ -0,0 +1,62 @@
package com.renkang.consultation.service.impl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.renkang.consultation.entity.ImMsgReadLog;
import com.renkang.consultation.mapper.ImMsgReadLogMapper;
import com.renkang.consultation.service.ImMsgReadLogService;
import com.renkang.consultation.vo.ImMsgReadLogVO;
import lombok.RequiredArgsConstructor;
import org.jeecg.common.exception.ExceptionAssertsUtil;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class ImMsgReadLogServiceImpl implements ImMsgReadLogService {
private final ImMsgReadLogMapper imMsgReadLogMapper;
@Override
public String saveReadLog(ImMsgReadLogVO imMsgReadLogVO) {
MPJLambdaWrapper<ImMsgReadLog> wrapper = new MPJLambdaWrapper<>();
wrapper.eq(ImMsgReadLog::getMsgId, imMsgReadLogVO.getMsgId());
wrapper.eq(ImMsgReadLog::getGroupId, imMsgReadLogVO.getGroupId());
ImMsgReadLog msgReadLog = imMsgReadLogMapper.selectOne(wrapper);
if(msgReadLog == null) {
msgReadLog = new ImMsgReadLog();
msgReadLog.setGroupId(imMsgReadLogVO.getGroupId());
msgReadLog.setMsgId(imMsgReadLogVO.getMsgId());
msgReadLog.setReadTime(new Date());
msgReadLog.setToAccount(imMsgReadLogVO.getToAccount());
msgReadLog.setFromAccount(imMsgReadLogVO.getFromAccount());
msgReadLog.setReadCount(1);
imMsgReadLogMapper.insert(msgReadLog);
}else {
//因为目前用于医生名片的已读且只能点一次,暂时这样提示
ExceptionAssertsUtil.fail("名片已过期");
}
return "操作成功";
}
@Override
public Map<String,Integer> findReadStatus(List<String> msgIdList) {
Map<String,Integer> map = new HashMap<>();
MPJLambdaWrapper<ImMsgReadLog> wrapper = new MPJLambdaWrapper<>();
wrapper.in(ImMsgReadLog::getMsgId, msgIdList);
Map<String,ImMsgReadLog> logMap = imMsgReadLogMapper.selectList(wrapper).stream()
.collect(Collectors.toMap(ImMsgReadLog::getMsgId, x -> x));
for (String msgId : msgIdList) {
ImMsgReadLog log = logMap.get(msgId);
if(log == null) {
map.put(msgId, 0);
}else {
map.put(msgId, log.getReadCount());
}
}
return map;
}
}