REQ-3345: 即刻生成聊天消息的history

This commit is contained in:
yanglin 2025-02-25 17:09:47 +08:00
parent 0b15bcd3a2
commit 8be8cc4dae
4 changed files with 27 additions and 14 deletions

View File

@ -39,7 +39,6 @@ import cn.axzo.im.service.MessageTaskService;
import cn.axzo.im.service.RobotMsgTemplateService; import cn.axzo.im.service.RobotMsgTemplateService;
import cn.axzo.im.updatable.UpdatableMessageManager; import cn.axzo.im.updatable.UpdatableMessageManager;
import cn.axzo.im.updatable.UpdatableMessageQueryService; import cn.axzo.im.updatable.UpdatableMessageQueryService;
import cn.axzo.im.updatable.UpdateSupport;
import cn.axzo.im.utils.BizAssertions; import cn.axzo.im.utils.BizAssertions;
import cn.axzo.pokonyan.exception.Aassert; import cn.axzo.pokonyan.exception.Aassert;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
@ -56,6 +55,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -99,9 +99,9 @@ public class MessageController implements MessageApi {
@Autowired @Autowired
private UpdatableMessageManager updatableMessageManager; private UpdatableMessageManager updatableMessageManager;
@Autowired @Autowired
private UpdateSupport updateSupport;
@Autowired
private UpdatableMessageQueryService updatableMessageQueryService; private UpdatableMessageQueryService updatableMessageQueryService;
@Autowired
private TransactionTemplate transactionTemplate;
@Override @Override
@ -247,6 +247,7 @@ public class MessageController implements MessageApi {
MessageTask.BizData bizData = MessageTask.BizData.builder() MessageTask.BizData bizData = MessageTask.BizData.builder()
.messageBody(JSON.toJSONString(request.getMessageBody())) .messageBody(JSON.toJSONString(request.getMessageBody()))
.isSenderRobot(false) .isSenderRobot(false)
.isChatMessage(true)
.senderPersonId(request.determineSenderPersonId()) .senderPersonId(request.determineSenderPersonId())
.nimMessageType(request.getMessageType()) .nimMessageType(request.getMessageType())
.build(); .build();
@ -262,7 +263,8 @@ public class MessageController implements MessageApi {
.build()); .build());
} }
} }
MessageTask messageTask = messageTaskService.create(MessageTask.builder() MessageTask messageTask = transactionTemplate.execute(unused -> {
MessageTask task = messageTaskService.create(MessageTask.builder()
.bizId(request.getBizId()) .bizId(request.getBizId())
.sendImAccount(sendImAccount) .sendImAccount(sendImAccount)
.receivePersons(receivePersons) .receivePersons(receivePersons)
@ -273,6 +275,11 @@ public class MessageController implements MessageApi {
.sendPriority(SendPriority.CHAT_MESSAGE.getPriority()) .sendPriority(SendPriority.CHAT_MESSAGE.getPriority())
.apiChannel(ApiChannel.COMMON_MESSAGE) .apiChannel(ApiChannel.COMMON_MESSAGE)
.build()); .build());
task = messageTaskService.getById(task.getId());
messageTaskService.createMessageHistory(task);
return task;
});
//noinspection DataFlowIssue
return ApiResult.ok(messageTask.getId()); return ApiResult.ok(messageTask.getId());
} }

View File

@ -170,6 +170,8 @@ public class MessageTask {
private NimMessageType nimMessageType; private NimMessageType nimMessageType;
private boolean isChatMessage;
public boolean determineIsSenderRobot() { public boolean determineIsSenderRobot() {
return isSenderRobot != null && isSenderRobot; return isSenderRobot != null && isSenderRobot;
} }

View File

@ -59,6 +59,9 @@ public class CreateMessageHistoryJob extends IJobHandler {
Page<MessageTask> page = messageTaskService.page(req); Page<MessageTask> page = messageTaskService.page(req);
if (CollectionUtils.isNotEmpty(page.getRecords())) { if (CollectionUtils.isNotEmpty(page.getRecords())) {
page.getRecords().forEach(messageTask -> { page.getRecords().forEach(messageTask -> {
MessageTask.BizData bizData = messageTask.getBizData();
if (bizData != null && bizData.isChatMessage())
return;
count.set(count.get() + 1); count.set(count.get() + 1);
try { try {
messageTaskService.createMessageHistory(messageTask); messageTaskService.createMessageHistory(messageTask);

View File

@ -45,6 +45,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;