From b957576aa2547bdb52ddf9b9ad1efc7789a255c4 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Wed, 10 Dec 2025 14:47:09 +0800 Subject: [PATCH] =?UTF-8?q?cp=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=842?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inner/asserts/user/UserRelationErrorCode.java | 9 ++++++++- .../other/app/command/user/ProcessCpApplyCmd.java | 9 +-------- .../other/app/command/user/SendCpApplyCmdExe.java | 10 +++------- .../user/query/UserCpPairUserProfileQryExe.java | 6 +++++- .../user/relation/UserCpRelationServiceImpl.java | 12 ++++++++++-- .../user/relation/cp/CpPairUserProfileCO.java | 6 ++++++ 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserRelationErrorCode.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserRelationErrorCode.java index a98e1db1..e1f1180d 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserRelationErrorCode.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserRelationErrorCode.java @@ -50,7 +50,14 @@ public enum UserRelationErrorCode implements IResponseErrorCode { /** * 不可用操作自己. */ - UNAVAILABLE_OPS_YOURSELF(4309, "Unavailable to operate yourself"); + UNAVAILABLE_OPS_YOURSELF(4309, "Unavailable to operate yourself"), + + /** + * 不支持同性别用户. + */ + UNAVAILABLE_SAME_GENDER(4310, "Couples of the same gender cannot be created."), + + ; private final Integer code; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/ProcessCpApplyCmd.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/ProcessCpApplyCmd.java index 0cb34fee..4172c074 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/ProcessCpApplyCmd.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/ProcessCpApplyCmd.java @@ -36,7 +36,6 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class ProcessCpApplyCmd { - private final RedisService redisService; private final CpApplyService cpApplyService; private final CpValueService cpValueService; private final ImMessageClient imMessageClient; @@ -45,13 +44,7 @@ public class ProcessCpApplyCmd { private final CpRelationshipService cpRelationshipService; public void execute(ProcessApplyCmd cmd) { - String key = "CProcess_" + cmd.getApplyId(); - try { - ResponseAssert.isTrue(CommonErrorCode.REQUEST_LIMITING, redisService.lock(key, 60)); - process(cmd); - } finally { - redisService.unlock(key); - } + process(cmd); } private void process(ProcessApplyCmd cmd) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/SendCpApplyCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/SendCpApplyCmdExe.java index ce96093b..5e34255c 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/SendCpApplyCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/SendCpApplyCmdExe.java @@ -43,7 +43,6 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class SendCpApplyCmdExe { - private final RedisService redisService; private final CpApplyService cpApplyService; private final OfficialNoticeClient officialNoticeClient; private final WalletGoldClient walletGoldClient; @@ -72,10 +71,9 @@ public class SendCpApplyCmdExe { ResponseAssert.isFalse(UserRelationErrorCode.OTHER_SIDE_ALREADY_APPLIED, cpApplyService.exists(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId())); - // 防止重复触发 - ResponseAssert.isTrue(CommonErrorCode.REPEATED_SUBMISSION, redisService.setIfAbsent( - "SEND_CP_APPLY:" + cmd.requiredReqUserId() + "_" + cmd.getAcceptApplyUserId(), 10, - TimeUnit.SECONDS)); + UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.requiredReqUserId())); + UserProfileDTO acceptUserProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.getAcceptApplyUserId())); + ResponseAssert.isFalse(UserRelationErrorCode.UNAVAILABLE_SAME_GENDER, Objects.equals(userProfile.getUserSex(), acceptUserProfile.getUserSex())); WalletReceiptResDTO receipt = ResponseAssert.requiredSuccess( walletGoldClient.changeBalance(GoldReceiptCmd.builder() @@ -89,8 +87,6 @@ public class SendCpApplyCmdExe { .build()) ); - UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.requiredReqUserId())); - String applyText = "User " + userProfile.getUserNickname() + " confessed the feeling to you; if you accept, you will become a couple."; CpApply cpApply = new CpApply() diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java index 7aa3d309..6813698a 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpPairUserProfileQryExe.java @@ -13,6 +13,8 @@ import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; import com.red.circle.other.inner.asserts.user.UserErrorCode; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; + +import java.time.ZoneId; import java.util.Objects; import com.red.circle.tool.core.date.LocalDateTimeUtils; @@ -47,7 +49,9 @@ public class UserCpPairUserProfileQryExe { return new CpPairUserProfileCO() .setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser))) .setCpUserProfile(getUserProfile(cpRelationship.getCpUserId())) - .setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now())); + .setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now())) + .setFirstDay(cpRelationship.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString()) + ; } private UserProfileDTO getUserProfile(Long cpUserId) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java index 4a05a744..f1a5687d 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationServiceImpl.java @@ -16,6 +16,7 @@ import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileC import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd; +import com.red.circle.other.app.util.DistributedLockUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -35,6 +36,7 @@ public class UserCpRelationServiceImpl implements UserCpRelationService { private final UserCpRelationQryExe userCpRelationQryExe; private final UserCpPairUserProfileQryExe userCpPairUserProfileQryExe; private final UserCpRelationQueryV4Exe userCpRelationQueryV4Exe; + private final DistributedLockUtil distributedLockUtil; @Override public CpUserProfileCO getCpUser(UserIdCmd cmd) { @@ -48,12 +50,18 @@ public class UserCpRelationServiceImpl implements UserCpRelationService { @Override public void sendApply(CpApplyCmd cmd) { - sendCpApplyCmdExe.execute(cmd); + String key = "SEND_CP_APPLY:" + cmd.getReqUserId() + "_" + cmd.getAcceptApplyUserId(); + distributedLockUtil.executeWithLock(key, () -> { + sendCpApplyCmdExe.execute(cmd); + }); } @Override public void processApply(ProcessApplyCmd cmd) { - processCpApplyCmd.execute(cmd); + String key = "PROCESS_CP_APPLY:" + cmd.getApplyId(); + distributedLockUtil.executeWithLock(key, () -> { + processCpApplyCmd.execute(cmd); + }); } @Override diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpPairUserProfileCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpPairUserProfileCO.java index 0c33783f..7e91f9ee 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpPairUserProfileCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpPairUserProfileCO.java @@ -36,4 +36,10 @@ public class CpPairUserProfileCO extends ClientObject { @JsonSerialize(using = ToStringSerializer.class) private Long days; + /** + * 开始组件的日期 + */ + private String firstDay; + + }