REQ-3201: 重新发送消息
This commit is contained in:
parent
58065f60b1
commit
c7497ee7cd
@ -22,6 +22,7 @@ import cn.axzo.msg.center.inside.notices.service.impl.TingyunService;
|
||||
import cn.axzo.msg.center.inside.notices.service.impl.TodoSearchService;
|
||||
import cn.axzo.msg.center.inside.notices.service.impl.v3.MessageRecordServiceV3;
|
||||
import cn.axzo.msg.center.message.domain.param.PendingMessagePushParam;
|
||||
import cn.axzo.msg.center.message.service.card.CardManager;
|
||||
import cn.axzo.msg.center.message.service.group.GroupTemplateService;
|
||||
import cn.axzo.msg.center.message.service.impl.person.PersonService;
|
||||
import cn.axzo.msg.center.message.service.todo.manage.TodoManager;
|
||||
@ -34,6 +35,7 @@ import cn.axzo.msg.center.notices.manager.api.dto.request.plat.CreateTemplateReq
|
||||
import cn.axzo.msg.center.notices.manager.api.dto.request.plat.TingyunInterfaceListRequest;
|
||||
import cn.axzo.msg.center.notices.service.api.PlatService;
|
||||
import cn.axzo.msg.center.service.enums.MqMessageType;
|
||||
import cn.axzo.msg.center.service.pending.request.CardUpdateRequest;
|
||||
import cn.axzo.msg.center.service.pending.request.RevokeByTemplateCodeRequest;
|
||||
import cn.axzo.trade.web.annotation.EnableResponseAdvice;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -81,6 +83,7 @@ public class PrivateMessageController {
|
||||
private final MNSMessageTemplateDao mnsMessageTemplateDao;
|
||||
private final TingyunService tingyunService;
|
||||
private final MqProducer mqProducer;
|
||||
private final CardManager cardManager;
|
||||
|
||||
@PostMapping("/sendPendingMessage")
|
||||
@EnableResponseAdvice(enable = false)
|
||||
@ -248,4 +251,11 @@ public class PrivateMessageController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@PostMapping("/sendTestMessage")
|
||||
@EnableResponseAdvice(enable = false)
|
||||
public Object resendCards(@RequestBody @Valid CardUpdateRequest request) {
|
||||
cardManager.resend(request);
|
||||
return "done...";
|
||||
}
|
||||
|
||||
}
|
||||
@ -207,6 +207,15 @@ public class CardManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void resend(CardUpdateRequest request) {
|
||||
TemplateModelV3 templateModel = cardSupport.ensureImChannelPresent(request.getTemplateCode());
|
||||
BizAssertions.assertNotNull(templateModel, "找不到对应的模板, templateCode={}", request.getTemplateCode());
|
||||
for (List<Card> cards : cardsCursor(request)) {
|
||||
rebuildCardContent(templateModel, cards);
|
||||
updateMessages(cards);
|
||||
}
|
||||
}
|
||||
|
||||
RecordCursor<Card> cardsCursor(CardUpdateRequest request) {
|
||||
final int batchSize = cardProps.getUpdateCardBatchSize();
|
||||
return new RecordCursor<>(batchSize, Card::getId, () -> cardDao.lambdaQuery()
|
||||
@ -224,6 +233,43 @@ public class CardManager {
|
||||
}));
|
||||
}
|
||||
|
||||
void rebuildCardContent(TemplateModelV3 templateModel, List<Card> cards) {
|
||||
ArrayList<Card> updates = new ArrayList<>();
|
||||
for (Card card : cardDao.reloadCards(cards)) {
|
||||
Card update = new Card();
|
||||
update.setId(card.getId());
|
||||
// 每个消息独立解析, 因为每个卡片的状态和按钮可能已经存在差异了
|
||||
CardTemplate cardTemplate = cardSupport.parseCardTemplate(templateModel, card);
|
||||
BizAssertions.assertTrue(cardTemplate.isUpdatable(),
|
||||
"模板不支持更新, templateCode={}", card.getTemplateCode());
|
||||
GeneralMessagePushVO cardContent = cardParser.parseCardContent(cardTemplate, card);
|
||||
// 保留原来的title和content, 避免模版变了但缺少bizParam导致数据不完整
|
||||
cardContent.setCardTitle(card.getTitle());
|
||||
cardContent.setCardContent(card.getContent());
|
||||
cardContent.addDebugInfo("bizCode", card.getBizCode());
|
||||
cardContent.addDebugInfo("subBizCode", card.getSubBizCode());
|
||||
update.setCardContent(cardContent);
|
||||
updates.add(update);
|
||||
}
|
||||
cardDao.updateBatchById(updates);
|
||||
}
|
||||
|
||||
void updateMessages(List<Card> cards) {
|
||||
if (CollectionUtils.isEmpty(cards))
|
||||
return;
|
||||
UpdateMessageRequest imRequest = new UpdateMessageRequest();
|
||||
for (Card card : cardDao.reloadCards(cards)) {
|
||||
UpdateMessageRequest.Update update = new UpdateMessageRequest.Update();
|
||||
update.setBizMessageId(card.getBizMessageId());
|
||||
Object cardContent = card.getCardContent();
|
||||
update.setMsgTemplateContent(cardContent instanceof String ?
|
||||
(String) cardContent : JSON.toJSONString(cardContent));
|
||||
imRequest.addUpdate(update);
|
||||
}
|
||||
MessageUpdateResponse response = BizAssertions.assertResponse(messageApi.updateMessage(imRequest));
|
||||
log.info("更新IM消息, request={}, response={}", imRequest, response);
|
||||
}
|
||||
|
||||
private void execTransactional(Runnable runnable) {
|
||||
transactionTemplate.executeWithoutResult(unused -> runnable.run());
|
||||
}
|
||||
@ -259,9 +305,10 @@ public class CardManager {
|
||||
if (CollectionUtils.isEmpty(updates))
|
||||
return UpdateStateResult.NO_UPDATE;
|
||||
cardDao.updateBatchById(updates);
|
||||
rebuildCardContent();
|
||||
CardManager.this.rebuildCardContent(templateModel, updatedCards);
|
||||
updateCardLogger.reloadAndLogCards(String.format("%s:enqueue", operation));
|
||||
updateMessages();
|
||||
CardManager.this.updateMessages(updatedCards);
|
||||
updateCardLogger.reloadAndLogCards(String.format("%s:updateMessage:success", operation));
|
||||
return UpdateStateResult.UPDATED;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
@ -279,44 +326,6 @@ public class CardManager {
|
||||
return update;
|
||||
}
|
||||
|
||||
void rebuildCardContent() {
|
||||
ArrayList<Card> updates = new ArrayList<>();
|
||||
for (Card card : cardDao.reloadCards(updatedCards)) {
|
||||
Card update = new Card();
|
||||
update.setId(card.getId());
|
||||
// 每个消息独立解析, 因为每个卡片的状态和按钮可能已经存在差异了
|
||||
CardTemplate cardTemplate = cardSupport.parseCardTemplate(templateModel, card);
|
||||
BizAssertions.assertTrue(cardTemplate.isUpdatable(),
|
||||
"模板不支持更新, templateCode={}", card.getTemplateCode());
|
||||
GeneralMessagePushVO cardContent = cardParser.parseCardContent(cardTemplate, card);
|
||||
// 保留原来的title和content, 避免模版变了但缺少bizParam导致数据不完整
|
||||
cardContent.setCardTitle(card.getTitle());
|
||||
cardContent.setCardContent(card.getContent());
|
||||
cardContent.addDebugInfo("bizCode", card.getBizCode());
|
||||
cardContent.addDebugInfo("subBizCode", card.getSubBizCode());
|
||||
update.setCardContent(cardContent);
|
||||
updates.add(update);
|
||||
}
|
||||
cardDao.updateBatchById(updates);
|
||||
}
|
||||
|
||||
void updateMessages() {
|
||||
if (CollectionUtils.isEmpty(updatedCards))
|
||||
return;
|
||||
UpdateMessageRequest imRequest = new UpdateMessageRequest();
|
||||
for (Card card : cardDao.reloadCards(updatedCards)) {
|
||||
UpdateMessageRequest.Update update = new UpdateMessageRequest.Update();
|
||||
update.setBizMessageId(card.getBizMessageId());
|
||||
Object cardContent = card.getCardContent();
|
||||
update.setMsgTemplateContent(cardContent instanceof String ?
|
||||
(String) cardContent : JSON.toJSONString(cardContent));
|
||||
imRequest.addUpdate(update);
|
||||
}
|
||||
log.info("更新IM消息, operation={}, request={}", operation, imRequest);
|
||||
MessageUpdateResponse imResponse = BizAssertions.assertResponse(messageApi.updateMessage(imRequest));
|
||||
log.info("更新IM消息, operation={}, request={}, response={}", operation, imRequest, imResponse);
|
||||
updateCardLogger.reloadAndLogCards(String.format("%s:updateMessage:success", operation));
|
||||
}
|
||||
}
|
||||
|
||||
private enum UpdateStateResult {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user