Merge branch 'operator_20240221' into pre

This commit is contained in:
yanglin 2024-02-22 19:21:21 +08:00
commit 933acd8f81
3 changed files with 55 additions and 8 deletions

View File

@ -4,12 +4,12 @@ import cn.axzo.im.center.api.vo.resp.MessageDispatchResp;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toSet;
/**
@ -18,7 +18,7 @@ import static java.util.stream.Collectors.toSet;
public class BatchSendResult {
private final Set<Long> requestPersonIds;
private final Map<Long, MessageDispatchResp> personId2SendResult;
private final Map<Long, List<MessageDispatchResp>> personId2SendResult;
BatchSendResult(Set<String> requestPersonIds) {
this(requestPersonIds, Collections.emptyList());
@ -31,10 +31,10 @@ public class BatchSendResult {
this.personId2SendResult = respList.stream()
// [2024.1.16]: im端在处理逐条发送和批量发送时的逻辑不一致, 批量发送时没有返回msgId -_-
.filter(r -> r.getPersonId() != null)
.collect(toMap(r -> Long.valueOf(r.getPersonId()), identity()));
.collect(groupingBy(r -> Long.valueOf(r.getPersonId())));
}
public Optional<MessageDispatchResp> findSendResult(Long personId) {
public Optional<List<MessageDispatchResp>> findSendResult(Long personId) {
return Optional.ofNullable(personId2SendResult.get(personId));
}

View File

@ -14,14 +14,19 @@ import cn.axzo.msg.center.inside.notices.utils.FunctionalTransactionTemplate;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toMap;
/**
@ -87,10 +92,17 @@ public class MessageMappingProcessor implements EventMappingProcessor {
continue;
}
String imMessageId = batchResult.findSendResult(personId)
.orElse(new ArrayList<>())
.stream()
.map(MessageDispatchResp::getMsgid)
.orElse(null);
// 把im端的id也存起来
messageRecordV3Dao.setSendSuccess(message.getId(), imMessageId);
.filter(Objects::nonNull)
.collect(joining(","));
if (StringUtils.isBlank(imMessageId)) {
messageRecordV3Dao.batchSetSendFailed(Collections.singletonList(message.getId()), "云信没有返回message_id");
} else {
// 把im端的id也存起来
messageRecordV3Dao.setSendSuccess(message.getId(), imMessageId);
}
}
}

View File

@ -0,0 +1,35 @@
package cn.axzo.msg.center.api;
import cn.axzo.msg.center.MsgCenterApplication;
import cn.axzo.msg.center.api.request.v3.MessageSendReqV3;
import cn.axzo.msg.center.service.dto.PersonV3DTO;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author yanglin
*/
@SpringBootTest(classes = MsgCenterApplication.class)
@RequiredArgsConstructor(onConstructor_ = @Autowired)
class MessageAPIV3Test {
private final MessageAPIV3 messageAPIV3;
@Test
void foo() throws Exception {
MessageSendReqV3 req = new MessageSendReqV3();
req.setSender(new PersonV3DTO(-99L));
req.setReceivers(Arrays.asList(new PersonV3DTO(2810L)));
req.setBizEventMappingCode("operator_news");
req.setBizCode("operator_news");
messageAPIV3.send(req);
Thread.sleep(100000L);
}
}