This commit is contained in:
hy001 2026-05-23 19:07:47 +08:00
parent 5359be337d
commit 32543b958c
6 changed files with 37 additions and 75 deletions

View File

@ -106,7 +106,7 @@ public class ProcessCpApplyCmd {
cmd.requireReqSysOrigin(), relationType);
}
sendAutoRejectedNotices(autoRefuseWaitAppliesAfterAgree(cpApply, relationType));
autoRefuseWaitAppliesAfterAgree(cpApply, relationType);
cpRelationshipCacheService.remove(Arrays.asList(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId()));
cpRelationBroadcastMqClient.publish(cmd.requireReqSysOrigin(), cpApply.getId(),
@ -126,24 +126,12 @@ public class ProcessCpApplyCmd {
imMessageClient.sendCustomMessage(agree
? CpRelationC2cNoticeUtils.buildAccepted(cpApply, senderProfile, acceptProfile)
: CpRelationC2cNoticeUtils.buildRejected(cpApply, senderProfile, acceptProfile));
imMessageClient.sendCustomMessage(agree
? CpRelationC2cNoticeUtils.buildAcceptedToAcceptUser(cpApply, senderProfile,
acceptProfile)
: CpRelationC2cNoticeUtils.buildRejectedToAcceptUser(cpApply, senderProfile,
acceptProfile));
} catch (Exception ex) {
log.warn("[CP] send process c2c notice failed, applyId={}, agree={}, reason={}",
cpApply.getId(), agree, ex.getMessage(), ex);
}
}
private void sendAutoRejectedNotices(List<CpApply> refusedApplies) {
if (Objects.isNull(refusedApplies) || refusedApplies.isEmpty()) {
return;
}
refusedApplies.forEach(apply -> sendProcessNotice(apply, false));
}
private List<CpApply> autoRefuseWaitAppliesAfterAgree(CpApply cpApply, String relationType) {
Map<Long, CpApply> refusedApplyMap = new LinkedHashMap<>();
addRefusedApplies(refusedApplyMap,

View File

@ -185,6 +185,9 @@ public class SendCpApplyCmdExe {
CpRelationshipType relationType, String title) {
imMessageClient.sendCustomMessage(CpRelationC2cNoticeUtils.buildInvitePending(sendUserId,
acceptUserId, applyId, userProfile, acceptUserProfile, isReconcile, relationType, title));
imMessageClient.sendCustomMessage(CpRelationC2cNoticeUtils.buildInvitePendingToSendUser(
sendUserId, acceptUserId, applyId, userProfile, acceptUserProfile, isReconcile, relationType,
title));
}
private BigDecimal normalizeApplyConsumeGold(BigDecimal applyConsumeGold) {

View File

@ -25,6 +25,20 @@ public final class CpRelationC2cNoticeUtils {
public static CustomC2cMsgBodyCmd buildInvitePending(Long fromUserId, Long toUserId,
Long applyId, UserProfileDTO senderProfile, UserProfileDTO acceptProfile,
boolean isReconcile, CpRelationshipType relationType, String title) {
return buildInvitePendingMessage(fromUserId, toUserId, applyId, senderProfile, acceptProfile,
isReconcile, relationType, title);
}
public static CustomC2cMsgBodyCmd buildInvitePendingToSendUser(Long sendUserId, Long acceptUserId,
Long applyId, UserProfileDTO senderProfile, UserProfileDTO acceptProfile,
boolean isReconcile, CpRelationshipType relationType, String title) {
return buildInvitePendingMessage(acceptUserId, sendUserId, applyId, senderProfile,
acceptProfile, isReconcile, relationType, title);
}
private static CustomC2cMsgBodyCmd buildInvitePendingMessage(Long fromUserId, Long toUserId,
Long applyId, UserProfileDTO senderProfile, UserProfileDTO acceptProfile,
boolean isReconcile, CpRelationshipType relationType, String title) {
Map<String, Object> content = senderContent(senderProfile);
content.put("applyType", isReconcile ? "RECONCILE" : "APPLY");
content.put("relationType", relationType.name());

View File

@ -76,8 +76,6 @@ public class CpApplyListener implements MessageListener {
}
imMessageClient.sendCustomMessage(
CpRelationC2cNoticeUtils.buildExpiredToAcceptUser(cpApply, senderProfile, acceptProfile));
imMessageClient.sendCustomMessage(
CpRelationC2cNoticeUtils.buildExpiredToSendUser(cpApply, senderProfile, acceptProfile));
} catch (Exception ex) {
log.warn("[CP] send expired c2c notice failed, applyId={}, reason={}", cpApply.getId(),
ex.getMessage(), ex);

View File

@ -40,8 +40,8 @@ class ProcessCpApplyCmdTest {
nullable(Long.class), eq("LIKEI"), eq("BROTHER"));
verify(fixture.cpRelationBroadcastMqClient).publish("LIKEI", 3001L, 1001L, 2001L,
"BROTHER");
assertProcessMessagesToBothUsers(fixture.sentCustomMessages(2), 0,
"RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER", 3001L, 1001L, 2001L);
assertProcessMessage(fixture.sentCustomMessage(),
"RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER");
}
@Test
@ -54,8 +54,8 @@ class ProcessCpApplyCmdTest {
nullable(Long.class), eq("LIKEI"), eq("SISTERS"));
verify(fixture.cpRelationBroadcastMqClient).publish("LIKEI", 3001L, 1001L, 2001L,
"SISTERS");
assertProcessMessagesToBothUsers(fixture.sentCustomMessages(2), 0,
"RELATION_ESTABLISHED", "ACCEPTED", true, "SISTERS", 3001L, 1001L, 2001L);
assertProcessMessage(fixture.sentCustomMessage(),
"RELATION_ESTABLISHED", "ACCEPTED", true, "SISTERS");
}
@Test
@ -64,8 +64,8 @@ class ProcessCpApplyCmdTest {
fixture.exe.execute(processCmd(false));
assertProcessMessagesToBothUsers(fixture.sentCustomMessages(2), 0,
"RELATION_REJECTED", "REJECTED", false, "CP", 3001L, 1001L, 2001L);
assertProcessMessage(fixture.sentCustomMessage(),
"RELATION_REJECTED", "REJECTED", false, "CP");
}
@Test
@ -85,7 +85,7 @@ class ProcessCpApplyCmdTest {
}
@Test
void agreeApplyShouldRejectOtherWaitAppliesBetweenSameUsers() {
void agreeApplyShouldAutoRefuseOtherWaitAppliesBetweenSameUsersWithoutRejectedIm() {
Fixture fixture = new Fixture("CP");
when(fixture.cpApplyService.refuseOtherWaitAppliesBetweenUsers(3001L, 1001L, 2001L))
.thenReturn(List.of(apply(3002L, "BROTHER"), apply(3003L, "SISTERS")));
@ -93,13 +93,8 @@ class ProcessCpApplyCmdTest {
fixture.exe.execute(processCmd(true));
verify(fixture.cpApplyService).refuseOtherWaitAppliesBetweenUsers(3001L, 1001L, 2001L);
List<CustomC2cMsgBodyCmd> messages = fixture.sentCustomMessages(6);
assertProcessMessagesToBothUsers(messages, 0, "RELATION_REJECTED", "REJECTED", false,
"BROTHER", 3002L, 1001L, 2001L);
assertProcessMessagesToBothUsers(messages, 2, "RELATION_REJECTED", "REJECTED", false,
"SISTERS", 3003L, 1001L, 2001L);
assertProcessMessagesToBothUsers(messages, 4, "RELATION_ESTABLISHED", "ACCEPTED", true,
"CP", 3001L, 1001L, 2001L);
assertProcessMessage(fixture.sentCustomMessage(),
"RELATION_ESTABLISHED", "ACCEPTED", true, "CP");
}
@Test
@ -118,17 +113,8 @@ class ProcessCpApplyCmdTest {
fixture.exe.execute(processCmd(true));
List<CustomC2cMsgBodyCmd> messages = fixture.sentCustomMessages(10);
assertProcessMessagesToBothUsers(messages, 0, "RELATION_REJECTED", "REJECTED", false,
"BROTHER", 3002L, 1001L, 2001L);
assertProcessMessagesToBothUsers(messages, 2, "RELATION_REJECTED", "REJECTED", false,
"SISTERS", 3003L, 1001L, 2001L);
assertProcessMessagesToBothUsers(messages, 4, "RELATION_REJECTED", "REJECTED", false,
"CP", 3004L, 1001L, 4001L);
assertProcessMessagesToBothUsers(messages, 6, "RELATION_REJECTED", "REJECTED", false,
"CP", 3005L, 1001L, 4002L);
assertProcessMessagesToBothUsers(messages, 8, "RELATION_ESTABLISHED", "ACCEPTED", true,
"CP", 3001L, 1001L, 2001L);
assertProcessMessage(fixture.sentCustomMessage(),
"RELATION_ESTABLISHED", "ACCEPTED", true, "CP");
}
@Test
@ -145,13 +131,8 @@ class ProcessCpApplyCmdTest {
fixture.exe.execute(processCmd(true));
List<CustomC2cMsgBodyCmd> messages = fixture.sentCustomMessages(6);
assertProcessMessagesToBothUsers(messages, 0, "RELATION_REJECTED", "REJECTED", false,
"CP", 3002L, 1001L, 4001L);
assertProcessMessagesToBothUsers(messages, 2, "RELATION_REJECTED", "REJECTED", false,
"CP", 3003L, 1001L, 4002L);
assertProcessMessagesToBothUsers(messages, 4, "RELATION_ESTABLISHED", "ACCEPTED", true,
"CP", 3001L, 1001L, 2001L);
assertProcessMessage(fixture.sentCustomMessage(),
"RELATION_ESTABLISHED", "ACCEPTED", true, "CP");
}
@Test
@ -164,8 +145,8 @@ class ProcessCpApplyCmdTest {
verify(fixture.cpApplyService, never()).refuseWaitAppliesByUserAndRelation(
any(Long.class), eq(1001L), eq("BROTHER"));
assertProcessMessagesToBothUsers(fixture.sentCustomMessages(2), 0,
"RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER", 3001L, 1001L, 2001L);
assertProcessMessage(fixture.sentCustomMessage(),
"RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER");
}
@Test
@ -182,13 +163,8 @@ class ProcessCpApplyCmdTest {
fixture.exe.execute(processCmd(true));
List<CustomC2cMsgBodyCmd> messages = fixture.sentCustomMessages(6);
assertProcessMessagesToBothUsers(messages, 0, "RELATION_REJECTED", "REJECTED", false,
"BROTHER", 3002L, 1001L, 4001L);
assertProcessMessagesToBothUsers(messages, 2, "RELATION_REJECTED", "REJECTED", false,
"BROTHER", 3003L, 1001L, 4002L);
assertProcessMessagesToBothUsers(messages, 4, "RELATION_ESTABLISHED", "ACCEPTED", true,
"BROTHER", 3001L, 1001L, 2001L);
assertProcessMessage(fixture.sentCustomMessage(),
"RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER");
}
private static ProcessApplyCmd processCmd(boolean agree) {
@ -251,15 +227,6 @@ class ProcessCpApplyCmdTest {
.contains("\"relationType\":\"" + relationType + "\""));
}
private static void assertProcessMessagesToBothUsers(List<CustomC2cMsgBodyCmd> messages,
int startIndex, String action, String status, Boolean agree, String relationType,
Long applyId, Long sendUserId, Long acceptUserId) {
assertProcessMessage(messages.get(startIndex), action, status, agree, relationType, applyId,
String.valueOf(acceptUserId), String.valueOf(sendUserId));
assertProcessMessage(messages.get(startIndex + 1), action, status, agree, relationType,
applyId, String.valueOf(sendUserId), String.valueOf(acceptUserId));
}
private static class Fixture {
private final CpApplyService cpApplyService = mock(CpApplyService.class);
@ -306,13 +273,6 @@ class ProcessCpApplyCmdTest {
return captor.getValue();
}
private List<CustomC2cMsgBodyCmd> sentCustomMessages(int count) {
ArgumentCaptor<CustomC2cMsgBodyCmd> captor = ArgumentCaptor.forClass(
CustomC2cMsgBodyCmd.class);
verify(imMessageClient, org.mockito.Mockito.times(count)).sendCustomMessage(captor.capture());
return captor.getAllValues();
}
private static UserProfile profile(Long userId) {
UserProfile userProfile = new UserProfile();
userProfile.setId(userId);

View File

@ -31,7 +31,7 @@ import org.mockito.ArgumentCaptor;
class CpApplyListenerTest {
@Test
void waitApplyExpiredShouldSendC2cMessageToBothUsers() {
void waitApplyExpiredShouldSendOneC2cMessageToConversation() {
CpApplyService cpApplyService = mock(CpApplyService.class);
ImMessageClient imMessageClient = mock(ImMessageClient.class);
UserProfileGateway userProfileGateway = mock(UserProfileGateway.class);
@ -66,10 +66,9 @@ class CpApplyListenerTest {
ArgumentCaptor<CustomC2cMsgBodyCmd> captor = ArgumentCaptor.forClass(
CustomC2cMsgBodyCmd.class);
verify(imMessageClient, org.mockito.Mockito.times(2)).sendCustomMessage(captor.capture());
verify(imMessageClient).sendCustomMessage(captor.capture());
List<CustomC2cMsgBodyCmd> messages = captor.getAllValues();
assertExpiredMessage(messages.get(0), "1001", "2001");
assertExpiredMessage(messages.get(1), "2001", "1001");
verify(cpApplyService).changeStatusById(3001L, CpApplyStatus.EXPIRE);
}