From 1343fa4631d73e85b9d5fe96f6ab874ebe4e9ccd Mon Sep 17 00:00:00 2001 From: hy001 Date: Thu, 21 May 2026 11:18:31 +0800 Subject: [PATCH] =?UTF-8?q?CP=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/i18n/messages.properties | 6 +- .../resources/i18n/messages_id.properties | 10 +- .../resources/i18n/messages_tr.properties | 8 +- .../resources/i18n/messages_zh_TW.properties | 8 +- .../asserts/user/UserRelationErrorCode.java | 11 +- .../model/dto/user/CpSimpleUserProfileCO.java | 13 +- .../CpRelationshipRestController.java | 33 +- .../user/user/UserCpCabinRestController.java | 28 +- .../user/user/UserCpRightsRestController.java | 30 ++ .../command/user/DismissCpApplyCmdExe.java | 116 +++-- .../app/command/user/ProcessCpApplyCmd.java | 67 +-- .../app/command/user/SendCpApplyCmdExe.java | 265 ++++++----- .../command/user/query/CpApplyIdQryExe.java | 16 +- .../user/query/UserCpBlessRecordQueryExe.java | 12 +- .../user/query/UserCpCabinQueryExe.java | 104 +++-- .../user/query/UserCpCabinValueQueryExe.java | 20 +- .../command/user/query/UserCpLightCmdExe.java | 133 +++--- .../query/UserCpPairUserProfileQryExe.java | 113 +++-- .../user/query/UserCpRelationQryExe.java | 41 +- .../user/query/UserCpRelationQueryV4Exe.java | 12 +- .../query/UserCpRightsConfigQueryExe.java | 141 ++++++ .../gift/strategy/GiftCountStrategy.java | 109 +++-- .../app/listener/user/CpApplyListener.java | 9 +- .../ActivityCorrectionDataManager.java | 2 +- .../relation/UserCpRelationServiceImpl.java | 51 +- .../user/user/CpBlessRecordAndUpReadExe.java | 22 +- .../user/user/UserCpCabinServiceImpl.java | 69 +-- .../relation/cp/CpCabinUserProfileCO.java | 11 +- .../user/relation/cp/CpPairUserProfileCO.java | 38 +- .../user/relation/cp/CpRightsConfigCO.java | 116 +++++ .../user/relation/cp/CpUserProfileCO.java | 13 +- .../dto/cmd/user/relation/cp/CpApplyCmd.java | 14 +- .../user/relation/cp/CpApplyDismissCmd.java | 13 +- .../user/relation/cp/CpApplyIdQueryCmd.java | 18 + .../relation/cp/CpRelationshipQueryCmd.java | 20 + .../relation/cp/CpRightsConfigQueryCmd.java | 26 ++ .../cmd/user/relation/cp/UserCpLightCmd.java | 13 +- .../user/user/UserCpBlessRecordQueryCmd.java | 9 +- .../cmd/user/user/UserCpCabinQueryCmd.java | 18 + .../user/relation/UserCpRelationService.java | 23 +- .../service/user/user/UserCpCabinService.java | 34 +- .../impl/CpRelationshipCacheServiceImpl.java | 44 +- .../rds/entity/user/user/CpApply.java | 26 +- .../rds/entity/user/user/CpRelationship.java | 18 +- .../rds/service/user/user/CpApplyService.java | 43 +- .../user/user/CpRelationshipService.java | 80 +++- .../user/user/impl/CpApplyServiceImpl.java | 106 +++-- .../user/impl/CpRelationshipServiceImpl.java | 241 ++++++---- .../enums/user/user/CpRelationshipType.java | 63 +++ .../dao/user/user/CpRelationshipDAO.xml | 14 +- .../rc-service-other/other-start/pom.xml | 38 +- .../src/test/java/CpLocalFlowSmokeTest.java | 441 ++++++++++++++++++ .../src/test/java/RocketMqLocalSmokeTest.java | 131 ++++++ sql/20260520_cp_relationship_type.sql | 13 + 54 files changed, 2303 insertions(+), 770 deletions(-) create mode 100644 rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCpRightsRestController.java create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRightsConfigQueryExe.java create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpRightsConfigCO.java create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyIdQueryCmd.java create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpRelationshipQueryCmd.java create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpRightsConfigQueryCmd.java create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserCpCabinQueryCmd.java create mode 100644 rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/enums/user/user/CpRelationshipType.java create mode 100644 rc-service/rc-service-other/other-start/src/test/java/CpLocalFlowSmokeTest.java create mode 100644 rc-service/rc-service-other/other-start/src/test/java/RocketMqLocalSmokeTest.java create mode 100644 sql/20260520_cp_relationship_type.sql diff --git a/rc-common-business/common-business-core/src/main/resources/i18n/messages.properties b/rc-common-business/common-business-core/src/main/resources/i18n/messages.properties index 6977da65..d4b7054c 100644 --- a/rc-common-business/common-business-core/src/main/resources/i18n/messages.properties +++ b/rc-common-business/common-business-core/src/main/resources/i18n/messages.properties @@ -62,8 +62,10 @@ ROOM_THEME_NOT_PASS.body=\u3010Room Custom Theme\u3011 The review failed. BADGE_ACTIVATION.title=Badge activation BADGE_ACTIVATION.body=You have received a new achievement badge, go check it out~ # cp\u5173\u7CFB\u89E3\u9664 -CP_DISMISS.title=CP Dismiss -CP_DISMISS.body=${nickname} Dissolved the CP relationship with you +CP_DISMISS.title=CP Dismiss +CP_DISMISS.body=${nickname} Dissolved the CP relationship with you +CP_BLESS.title=Cp bless +CP_BLESS.body=${nickname} has sent you CP blessing gifts # \u63A5\u6536\u8D35\u65CFvip ACCEPT_NOBLE_VIP.title=Receiving nobles ACCEPT_NOBLE_VIP.body=${nickname} gives you ${days} days of noble status~ diff --git a/rc-common-business/common-business-core/src/main/resources/i18n/messages_id.properties b/rc-common-business/common-business-core/src/main/resources/i18n/messages_id.properties index b202d7c1..1a01399b 100644 --- a/rc-common-business/common-business-core/src/main/resources/i18n/messages_id.properties +++ b/rc-common-business/common-business-core/src/main/resources/i18n/messages_id.properties @@ -80,9 +80,11 @@ AGREE_BD_LEADER_INVITE_AGENT.body=${userProfile} menerima undangan BD Anda # BD leader\u53D1\u9001\u6210\u4E3ABD\u9080\u8BF7 BD_LEADER_SEND_INVITE_BD.title=Undangan BD BD_LEADER_SEND_INVITE_BD.body=${userProfile}mengundang Anda untuk menjadi BD -# CP祝福通知 -CP_BLESS.title=Cp memberkati -CP_BLESS.body=${nickname} Saya memberi Anda hadiah berkah ruang CP +# CP祝福通知 +CP_DISMISS.title=CP Dismiss +CP_DISMISS.body=${nickname} Dissolved the CP relationship with you +CP_BLESS.title=Cp memberkati +CP_BLESS.body=${nickname} Saya memberi Anda hadiah berkah ruang CP # 告白通知 USER_CONFESSION.title=Pengakuan pengguna -USER_CONFESSION.body=${nickname} mengaku padamu di dinding pengakuan \ No newline at end of file +USER_CONFESSION.body=${nickname} mengaku padamu di dinding pengakuan diff --git a/rc-common-business/common-business-core/src/main/resources/i18n/messages_tr.properties b/rc-common-business/common-business-core/src/main/resources/i18n/messages_tr.properties index ff37338b..a6c8006d 100644 --- a/rc-common-business/common-business-core/src/main/resources/i18n/messages_tr.properties +++ b/rc-common-business/common-business-core/src/main/resources/i18n/messages_tr.properties @@ -58,8 +58,10 @@ ROOM_THEME_NOT_PASS.body=[Oda \u00F6zel temas\u0131] incelemede ba\u015Far\u0131 BADGE_ACTIVATION.title=Rozet aktivasyonu BADGE_ACTIVATION.body=Yeni bir ba\u015Far\u0131 rozeti ald\u0131n\u0131z, gidip bir g\u00F6z at\u0131n ~ # cp\u5173\u7CFB\u89E3\u9664 -CP_DISMISS.title=CP s\u00FCr\u00FCm\u00FC -CP_DISMISS.body= ${nickname} sizinle CP ili\u015Fkisini bozdu +CP_DISMISS.title=CP s\u00FCr\u00FCm\u00FC +CP_DISMISS.body= ${nickname} sizinle CP ili\u015Fkisini bozdu +CP_BLESS.title=Cp bless +CP_BLESS.body=${nickname} has sent you CP blessing gifts # \u63A5\u6536\u8D35\u65CFvip ACCEPT_NOBLE_VIP.title=Soylular al\u0131r ACCEPT_NOBLE_VIP.body =${nickname} size ${days} g\u00FCnl\u00FCk asil stat\u00FCs\u00FC verir ~ @@ -117,4 +119,4 @@ AGREE_BD_LEADER_INVITE_AGENT.title=Daveti kabul etmek AGREE_BD_LEADER_INVITE_AGENT.body=${userProfile}, BD davetinizi kabul etti # BD leader\u53D1\u9001\u6210\u4E3ABD\u9080\u8BF7 BD_LEADER_SEND_INVITE_BD.title=BD Davetiyesi -BD_LEADER_SEND_INVITE_BD.body=${userProfile} sizi BD olmaya davet ediyor \ No newline at end of file +BD_LEADER_SEND_INVITE_BD.body=${userProfile} sizi BD olmaya davet ediyor diff --git a/rc-common-business/common-business-core/src/main/resources/i18n/messages_zh_TW.properties b/rc-common-business/common-business-core/src/main/resources/i18n/messages_zh_TW.properties index 8d1bded1..bf36096f 100644 --- a/rc-common-business/common-business-core/src/main/resources/i18n/messages_zh_TW.properties +++ b/rc-common-business/common-business-core/src/main/resources/i18n/messages_zh_TW.properties @@ -61,8 +61,10 @@ ROOM_THEME_NOT_PASS.body=\u3010\u623F\u9593\u81EA\u5B9A\u7FA9\u4E3B\u984C\u3011\ BADGE_ACTIVATION.title=\u5FBD\u7AE0\u6FC0\u6D3B BADGE_ACTIVATION.body=\u60A8\u5DF2\u7372\u5F97\u65B0\u7684\u6210\u5C31\u5FBD\u7AE0\uFF0C\u5FEB\u53BB\u770B\u770B\u5427~ # cp\u5173\u7CFB\u89E3\u9664 -CP_DISMISS.title=CP \u89E3\u9664 -CP_DISMISS.body= ${nickname} \u8207\u60A8\u89E3\u9664\u4E86 CP \u95DC\u4FC2 +CP_DISMISS.title=CP \u89E3\u9664 +CP_DISMISS.body= ${nickname} \u8207\u60A8\u89E3\u9664\u4E86 CP \u95DC\u4FC2 +CP_BLESS.title=Cp \u795D\u798F +CP_BLESS.body=${nickname} \u7D66\u4F60\u5011\u9001\u4E86cp\u7A7A\u9593\u795D\u798F\u79AE\u7269 # \u63A5\u6536\u8D35\u65CFvip ACCEPT_NOBLE_VIP.title=\u8CB4\u65CF\u63A5\u6536 ACCEPT_NOBLE_VIP.body =${nickname} \u8D08\u9001\u60A8 ${days} \u5929\u7684\u8CB4\u65CF\u8EAB\u4EFD~ @@ -134,4 +136,4 @@ AGREE_BD_LEADER_INVITE_AGENT.title=\u63A5\u53D7\u9080\u8BF7 AGREE_BD_LEADER_INVITE_AGENT.body=${userProfile} \u63A5\u53D7BD\u9080\u8BF7 # BD leader\u53D1\u9001\u6210\u4E3ABD\u9080\u8BF7 BD_LEADER_SEND_INVITE_BD.title=BD\u9080\u8BF7 -BD_LEADER_SEND_INVITE_BD.body=${userProfile} \u9080\u8BF7\u6210\u4E3ABD \ No newline at end of file +BD_LEADER_SEND_INVITE_BD.body=${userProfile} \u9080\u8BF7\u6210\u4E3ABD 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 cb031caf..77c2369f 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 @@ -70,9 +70,14 @@ public enum UserRelationErrorCode implements IResponseErrorCode { /** * CP关系不存在. */ - CP_RELATIONSHIP_NOT_EXISTS(4313, "CP relationship does not exist"), - - ; + CP_RELATIONSHIP_NOT_EXISTS(4313, "CP relationship does not exist"), + + /** + * 关系类型与用户性别不匹配. + */ + RELATION_TYPE_GENDER_NOT_MATCH(4314, "Relationship type does not match user gender"), + + ; private final Integer code; diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpSimpleUserProfileCO.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpSimpleUserProfileCO.java index e6b896cc..5004a841 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpSimpleUserProfileCO.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/user/CpSimpleUserProfileCO.java @@ -41,10 +41,15 @@ public class CpSimpleUserProfileCO implements Serializable { */ private String meUserNickname; - /** - * CP用户ID - */ - @JsonSerialize(using = ToStringSerializer.class) + /** + * 关系类型:CP/BROTHER/SISTERS. + */ + private String relationType; + + /** + * CP用户ID + */ + @JsonSerialize(using = ToStringSerializer.class) private Long cpUserId; /** diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java index 6b46921c..649e168d 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/relation/CpRelationshipRestController.java @@ -1,15 +1,16 @@ package com.red.circle.other.adapter.app.user.relation; -import com.red.circle.common.business.dto.cmd.AppExtCommand; -import com.red.circle.common.business.dto.cmd.UserIdCmd; -import com.red.circle.framework.web.controller.BaseController; -import com.red.circle.other.app.command.user.LoveLetterQueryCmdExe; -import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; -import com.red.circle.other.domain.model.cp.loveletter.LoveLetterDetailCO; -import com.red.circle.other.domain.model.cp.loveletter.LoveLetterWallCO; -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.common.business.dto.cmd.AppExtCommand; +import com.red.circle.framework.web.controller.BaseController; +import com.red.circle.other.app.command.user.LoveLetterQueryCmdExe; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; +import com.red.circle.other.domain.model.cp.loveletter.LoveLetterDetailCO; +import com.red.circle.other.domain.model.cp.loveletter.LoveLetterWallCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyIdQueryCmd; +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.CpRelationshipQueryCmd; +import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.loveletter.SendLoveLetterCmd; import com.red.circle.other.app.service.user.relation.UserCpRelationService; import lombok.RequiredArgsConstructor; @@ -51,9 +52,9 @@ public class CpRelationshipRestController extends BaseController { * @eo.request-type formdata */ @GetMapping("/pair") - public List getCpPairUserProfileCO(AppExtCommand cmd) { - return userCpRelationService.getCpPairUserProfileCO(cmd); - } + public List getCpPairUserProfileCO(CpRelationshipQueryCmd cmd) { + return userCpRelationService.getCpPairUserProfileCO(cmd); + } /** * CP申请. @@ -103,9 +104,9 @@ public class CpRelationshipRestController extends BaseController { * @eo.request-type formdata */ @GetMapping("/apply-id") - public String getCpApplyId(@Validated UserIdCmd cmd) { - return userCpRelationService.getCpApplyId(cmd); - } + public String getCpApplyId(@Validated CpApplyIdQueryCmd cmd) { + return userCpRelationService.getCpApplyId(cmd); + } /** * 发送CP告白信封. diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCpCabinRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCpCabinRestController.java index b7b51273..248ff6fe 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCpCabinRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCpCabinRestController.java @@ -1,13 +1,13 @@ package com.red.circle.other.adapter.app.user.user; -import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; -import com.red.circle.framework.web.controller.BaseController; +import com.red.circle.framework.web.controller.BaseController; import com.red.circle.other.app.dto.clientobject.user.user.CpBlessRecordCO; import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinCO; import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinUnreadCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinValueCO; -import com.red.circle.other.app.dto.cmd.user.user.UserCpBlessRecordQueryCmd; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinValueCO; +import com.red.circle.other.app.dto.cmd.user.user.UserCpBlessRecordQueryCmd; +import com.red.circle.other.app.dto.cmd.user.user.UserCpCabinQueryCmd; import com.red.circle.other.app.service.user.user.UserCpCabinService; import java.util.List; import lombok.AllArgsConstructor; @@ -34,25 +34,25 @@ public class UserCpCabinRestController extends BaseController { * cp小屋相关信息 */ @GetMapping - public UserCpCabinCO getCpCabinInfo(UserIdCommonCmd cmd) { - return userCpCabinService.getCpCabinInfo(cmd); - } + public UserCpCabinCO getCpCabinInfo(UserCpCabinQueryCmd cmd) { + return userCpCabinService.getCpCabinInfo(cmd); + } /** * cp value. */ @GetMapping("/value") - public UserCpCabinValueCO getCpCabinValue(UserIdCommonCmd cmd) { - return userCpCabinService.getCpCabinValue(cmd); - } + public UserCpCabinValueCO getCpCabinValue(UserCpCabinQueryCmd cmd) { + return userCpCabinService.getCpCabinValue(cmd); + } /** * 获得最近两百条祝福记录,并标记为已读. */ @GetMapping("/list") - public UserCpCabinUnreadCO getCpBlessRecordAndUpRead(UserIdCommonCmd cmd) { - return userCpCabinService.getCpBlessRecordAndUpRead(cmd); - } + public UserCpCabinUnreadCO getCpBlessRecordAndUpRead(UserCpCabinQueryCmd cmd) { + return userCpCabinService.getCpBlessRecordAndUpRead(cmd); + } /** * cp小屋祝福列表分页列表 @@ -62,4 +62,4 @@ public class UserCpCabinRestController extends BaseController { return userCpCabinService.pageCpBlessRecord(cmd); } -} \ No newline at end of file +} diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCpRightsRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCpRightsRestController.java new file mode 100644 index 00000000..a595ee3f --- /dev/null +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserCpRightsRestController.java @@ -0,0 +1,30 @@ +package com.red.circle.other.adapter.app.user.user; + +import com.red.circle.framework.web.controller.BaseController; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpRightsConfigCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpRightsConfigQueryCmd; +import com.red.circle.other.app.service.user.user.UserCpCabinService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * CP rights. + */ +@RestController +@RequiredArgsConstructor +@RequestMapping(value = "/user/cp/rights", produces = MediaType.APPLICATION_JSON_VALUE) +public class UserCpRightsRestController extends BaseController { + + private final UserCpCabinService userCpCabinService; + + /** + * CP rights config. + */ + @GetMapping("/config") + public CpRightsConfigCO getCpRightsConfig(CpRightsConfigQueryCmd cmd) { + return userCpCabinService.getCpRightsConfig(cmd); + } +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/DismissCpApplyCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/DismissCpApplyCmdExe.java index 25ad3bd8..87908ae0 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/DismissCpApplyCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/DismissCpApplyCmdExe.java @@ -1,24 +1,32 @@ package com.red.circle.other.app.command.user; -import com.google.common.collect.Sets; -import com.red.circle.external.inner.endpoint.message.ImMessageClient; -import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd; -import com.red.circle.other.app.service.user.user.UserProfileService; -import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.google.common.collect.Sets; +import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient; +import com.red.circle.external.inner.model.cmd.message.notice.official.NoticeExtTemplateTypeCmd; +import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum; +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.framework.core.response.CommonErrorCode; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd; +import com.red.circle.other.app.service.user.user.UserProfileService; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.infra.common.user.UserGiftBackpackCommon; import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService; import com.red.circle.other.infra.database.cache.service.user.UserCpValueCacheService; import com.red.circle.other.infra.database.mongo.service.user.count.WeekCpValueCountService; import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; -import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService; -import com.red.circle.other.infra.database.rds.service.user.user.CpCabinAchieveService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; -import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService; +import com.red.circle.other.infra.database.rds.service.user.user.CpCabinAchieveService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; +import com.red.circle.tool.core.collection.MapBuilder; +import com.red.circle.tool.core.date.TimestampUtils; + +import java.util.Arrays; +import java.util.List; +import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -31,10 +39,10 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class DismissCpApplyCmdExe { - private final CpValueService cpValueService; - private final CpApplyService cpApplyService; - private final ImMessageClient imMessageClient; - private final CpRelationshipService cpRelationshipService; + private final CpValueService cpValueService; + private final CpApplyService cpApplyService; + private final OfficialNoticeClient officialNoticeClient; + private final CpRelationshipService cpRelationshipService; private final UserGiftBackpackCommon userGiftBackpackCommon; private final WeekCpValueCountService weekCpValueCountService; private final UserCpValueCacheService userCpValueCacheService; @@ -43,20 +51,24 @@ public class DismissCpApplyCmdExe { private final UserProfileGateway userProfileGateway; private final CpRelationshipCacheService cpRelationshipCacheService; - public void execute(CpApplyDismissCmd cmd) { - - var cpRelationship = cpRelationshipService.getByUserId(cmd.requiredReqUserId()); - if (Objects.isNull(cpRelationship)) { - return; - } - - // 更新申请状态为解散 - cpApplyService.dismiss(cmd.requiredReqUserId()); - - // 更新CP关系为分手中,不删除数据 - cpRelationshipService.updateToDismissing(cmd.requiredReqUserId(), cmd.getCpUserId()); - - cpRelationshipCacheService.remove(Arrays.asList(cmd.requiredReqUserId(), cmd.getCpUserId())); + public void execute(CpApplyDismissCmd cmd) { + String relationType = parseRelationType(cmd.getRelationType()); + + var cpRelationship = cpRelationshipService.getByUserId( + cmd.requiredReqUserId(), cmd.getCpUserId(), relationType); + if (Objects.isNull(cpRelationship)) { + return; + } + + // 更新申请状态为解散 + cpApplyService.dismiss(cmd.requiredReqUserId(), relationType); + + // 更新CP关系为分手中,不删除数据 + cpRelationshipService.updateToDismissing(cmd.requiredReqUserId(), cmd.getCpUserId(), relationType); + + cpRelationshipCacheService.remove(Arrays.asList(cmd.requiredReqUserId(), cmd.getCpUserId())); + + sendDismissNotice(cmd, relationType); // 以下数据不删除,7天后由定时任务清理 // weekCpValueCountService.removeThisWeek(...) @@ -68,8 +80,40 @@ public class DismissCpApplyCmdExe { } - private String getSendApplyUserId(CpApplyDismissCmd cmd) { - return cmd.requiredReqUserId().toString(); - } - -} + private String getSendApplyUserId(CpApplyDismissCmd cmd) { + return cmd.requiredReqUserId().toString(); + } + + private void sendDismissNotice(CpApplyDismissCmd cmd, String relationType) { + UserProfile userProfile = userProfileGateway.getByUserId(cmd.requiredReqUserId()); + if (Objects.isNull(userProfile)) { + return; + } + long dismissEndTime = TimestampUtils.now().getTime() + (7 * 24 * 60 * 60 * 1000L); + officialNoticeClient.send(NoticeExtTemplateTypeCmd.builder() + .toAccount(cmd.getCpUserId()) + .noticeType(OfficialNoticeTypeEnum.CP_DISMISS) + .templateParam(MapBuilder.builder() + .put("nickname", userProfile.getUserNickname()) + .put("userNickname", userProfile.getUserNickname()) + .put("account", userProfile.getAccount()) + .put("userAvatar", userProfile.getUserAvatar()) + .put("countryCode", userProfile.getCountryCode()) + .put("countryName", userProfile.getCountryName()) + .put("relationType", relationType) + .put("dismissEndTime", dismissEndTime) + .build()) + .expand(cmd.requiredReqUserId()) + .build()); + } + + private String parseRelationType(String relationType) { + try { + return CpRelationshipType.normalize(relationType); + } catch (IllegalArgumentException ex) { + ResponseAssert.failure(CommonErrorCode.TYPE_IS_NOT_IN_SCOPE, "relationType is not supported."); + return CpRelationshipType.CP.name(); + } + } + +} 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 01d1a781..63b256ef 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 @@ -13,10 +13,11 @@ import com.red.circle.other.infra.database.rds.entity.user.user.CpApply; import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; import com.red.circle.other.infra.database.rds.entity.user.user.CpValue; import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; -import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; -import com.red.circle.other.infra.enums.user.user.CpApplyStatus; -import com.red.circle.tool.core.date.TimestampUtils; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.enums.user.user.CpApplyStatus; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; +import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.other.inner.asserts.user.UserRelationErrorCode; import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient; import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd; @@ -53,25 +54,27 @@ public class ProcessCpApplyCmd { private void process(ProcessApplyCmd cmd) { CpApply cpApply = cpApplyService.getById(cmd.getApplyId()); - // 没有找到映射信息 - ResponseAssert.notNull(CommonErrorCode.NOT_FOUND_MAPPING_INFO, cpApply); - - // 状态错误 + // 没有找到映射信息 + ResponseAssert.notNull(CommonErrorCode.NOT_FOUND_MAPPING_INFO, cpApply); + String relationType = CpRelationshipType.normalize(cpApply.getRelationType()); + + // 状态错误 ResponseAssert.isTrue(CommonErrorCode.STATE_ERROR, Objects.equals(cpApply.getStatus(), CpApplyStatus.WAIT.name())); - // 检查是否是复合申请 - CpRelationship dismissingCp = cpRelationshipService.getDismissingCp( - cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId()); + // 检查是否是复合申请 + CpRelationship dismissingCp = cpRelationshipService.getDismissingCp( + cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(), relationType); boolean isReconcile = Objects.nonNull(dismissingCp); if (!isReconcile) { - // 非复合申请:CP已存在 - ResponseAssert.isFalse(UserRelationErrorCode.ME_OR_YOU_CP_EXISTED, - cpRelationshipService.existsCp(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId())); + // 非复合申请:CP已存在 + ResponseAssert.isFalse(UserRelationErrorCode.ME_OR_YOU_CP_EXISTED, + cpRelationshipService.existsCp(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(), + relationType)); // 检查CP数量限制(最多4个) - int senderCpCount = cpRelationshipService.countCp(cmd.requiredReqUserId()); + int senderCpCount = cpRelationshipService.countCp(cpApply.getSendApplyUserId()); int receiverCpCount = cpRelationshipService.countCp(cpApply.getAcceptApplyUserId()); ResponseAssert.isFalse(UserRelationErrorCode.CP_LIMIT_EXCEEDED, senderCpCount >= 4); ResponseAssert.isFalse(UserRelationErrorCode.CP_LIMIT_EXCEEDED, receiverCpCount >= 4); @@ -86,23 +89,24 @@ public class ProcessCpApplyCmd { return; } - refuseStatusWait(cmd, cpApply); - - if (isReconcile) { - // 复合:更新状态为NORMAL - cpRelationshipService.reconcile(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId()); - } else { - // 新建关系 - cpRelationshipService - .addCp(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(), createCpValue(), - cmd.requireReqSysOrigin()); + refuseStatusWait(cmd, cpApply, relationType); + + if (isReconcile) { + // 复合:更新状态为NORMAL + cpRelationshipService.reconcile(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(), + relationType); + } else { + // 新建关系 + cpRelationshipService + .addCp(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(), createCpValue(), + cmd.requireReqSysOrigin(), relationType); } cpRelationshipCacheService.remove(Arrays.asList(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId())); } - private void refuseStatusWait(ProcessApplyCmd cmd, CpApply cpApply) { - cpApplyService.refuseStatusWait(cmd.requiredReqUserId()); + private void refuseStatusWait(ProcessApplyCmd cmd, CpApply cpApply, String relationType) { + cpApplyService.refuseStatusWait(cmd.requiredReqUserId(), relationType); userMqMessageService.cpApplyDelayed( new CpApplyEvent() .setId(cpApply.getId()) @@ -110,8 +114,13 @@ public class ProcessCpApplyCmd { TimestampUtils.nowPlusMinutes(1)); } - private void returnGoldCoins(ProcessApplyCmd cmd, CpApply cpApply) { - walletGoldClient.changeBalance(GoldReceiptCmd.builder() + private void returnGoldCoins(ProcessApplyCmd cmd, CpApply cpApply) { + if (Objects.isNull(cpApply.getApplyConsumeGold()) + || cpApply.getApplyConsumeGold().compareTo(BigDecimal.ZERO) <= 0) { + cpApplyService.changeStatusById(cmd.getApplyId(), CpApplyStatus.REIMBURSE); + return; + } + walletGoldClient.changeBalance(GoldReceiptCmd.builder() .appIncome() .userId(cpApply.getSendApplyUserId()) .eventId(cpApply.getId()) 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 cc9c2f9c..599bf23d 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 @@ -1,13 +1,14 @@ package com.red.circle.other.app.command.user; import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; -import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient; -import com.red.circle.external.inner.model.cmd.message.notice.official.NoticeExtTemplateTypeCmd; -import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum; -import com.red.circle.framework.core.asserts.ResponseAssert; -import com.red.circle.mq.business.model.event.user.CpApplyEvent; -import com.red.circle.mq.rocket.business.producer.UserMqMessageService; -import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; +import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient; +import com.red.circle.external.inner.model.cmd.message.notice.official.NoticeExtTemplateTypeCmd; +import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum; +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.framework.core.response.CommonErrorCode; +import com.red.circle.mq.business.model.event.user.CpApplyEvent; +import com.red.circle.mq.rocket.business.producer.UserMqMessageService; +import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd; import com.red.circle.other.app.util.OfficialNoticeUtils; import com.red.circle.other.domain.gateway.user.UserProfileGateway; @@ -15,32 +16,36 @@ import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService; import com.red.circle.other.infra.database.rds.entity.user.user.CpApply; import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; -import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; -import com.red.circle.other.infra.enums.user.user.CpApplyStatus; -import com.red.circle.other.inner.enums.config.EnumConfigKey; -import com.red.circle.other.inner.model.dto.user.UserProfileDTO; -import com.red.circle.tool.core.date.TimestampUtils; -import com.red.circle.other.inner.asserts.user.UserRelationErrorCode; +import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.enums.user.user.CpApplyStatus; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; +import com.red.circle.other.inner.enums.config.EnumConfigKey; +import com.red.circle.other.inner.model.dto.user.UserProfileDTO; +import com.red.circle.tool.core.date.TimestampUtils; +import com.red.circle.other.inner.asserts.user.UserRelationErrorCode; import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient; import com.red.circle.wallet.inner.model.cmd.GoldReceiptCmd; -import com.red.circle.wallet.inner.model.dto.WalletReceiptResDTO; -import com.red.circle.wallet.inner.model.enums.GoldOrigin; - -import java.util.Map; -import java.util.Objects; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; +import com.red.circle.wallet.inner.model.dto.WalletReceiptResDTO; +import com.red.circle.wallet.inner.model.enums.GoldOrigin; + +import java.math.BigDecimal; +import java.util.Map; +import java.util.Objects; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; /** * 发送cp申请. * * @author pengliang on 2021/7/13 */ -@Component -@RequiredArgsConstructor -public class SendCpApplyCmdExe { +@Component +@RequiredArgsConstructor +@Slf4j +public class SendCpApplyCmdExe { private final CpApplyService cpApplyService; private final OfficialNoticeClient officialNoticeClient; @@ -50,87 +55,135 @@ public class SendCpApplyCmdExe { private final EnumConfigCacheService enumConfigCacheService; private final UserProfileGateway userProfileGateway; private final UserProfileAppConvertor userProfileAppConvertor; - private final UserRegionGateway userRegionGateway; - - public void execute(CpApplyCmd cmd) { - - // 不可用操作自己 - ResponseAssert.isFalse(UserRelationErrorCode.UNAVAILABLE_OPS_YOURSELF, - Objects.equals(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId())); - - boolean eqRegion = userRegionGateway.checkEqRegion(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId()); - ResponseAssert.isTrue(UserRelationErrorCode.UNAVAILABLE_NOT_REGION, eqRegion); - - // 检查是否是复合申请 - CpRelationship dismissingCp = cpRelationshipService.getDismissingCp( - cmd.requiredReqUserId(), cmd.getAcceptApplyUserId()); - boolean isReconcile = Objects.nonNull(dismissingCp); - - if (!isReconcile) { - // 非复合申请:检查CP是否已存在 - ResponseAssert.isFalse(UserRelationErrorCode.ME_OR_YOU_CP_EXISTED, - cpRelationshipService - .existsCp(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId())); - - // 检查CP数量限制(最多4个) - int senderCpCount = cpRelationshipService.countCp(cmd.requiredReqUserId()); - int receiverCpCount = cpRelationshipService.countCp(cmd.getAcceptApplyUserId()); - ResponseAssert.isFalse(UserRelationErrorCode.CP_LIMIT_EXCEEDED, senderCpCount >= 4); - ResponseAssert.isFalse(UserRelationErrorCode.CP_LIMIT_EXCEEDED, receiverCpCount >= 4); - } - - // 您已发送申请 - ResponseAssert.isFalse(UserRelationErrorCode.YOU_HAVE_SENT_AN_APPLICATION, - cpApplyService.existsNotProcessSendApply(cmd.requiredReqUserId())); - - // 对方已向你发送申请 - ResponseAssert.isFalse(UserRelationErrorCode.OTHER_SIDE_ALREADY_APPLIED, - cpApplyService.exists(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId())); - - 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() - .appExpenditure() - .userId(cmd.requiredReqUserId()) - .eventId(cmd.getAcceptApplyUserIdString()) - .sysOrigin(cmd.requireReqSysOrigin()) - .origin(GoldOrigin.CP_BUILD) - .amount(enumConfigCacheService.getValueBigDecimal(EnumConfigKey.CP_PRICE, - cmd.requireReqSysOrigin())) - .build()) - ); - - String applyText = isReconcile - ? "User " + userProfile.getUserNickname() + " wants to reconcile with you; if you accept, you will be a couple again." - : "User " + userProfile.getUserNickname() + " confessed the feeling to you; if you accept, you will become a couple."; - - CpApply cpApply = new CpApply() - .setSendApplyUserId(cmd.requiredReqUserId()) - .setAcceptApplyUserId(cmd.getAcceptApplyUserId()) - .setApplyText(applyText) - .setStatus(CpApplyStatus.WAIT.name()) - .setApplyConsumeGold(receipt.getOpAmount().getDollarAmount()); - - cpApplyService.save(cpApply); - - Map map = OfficialNoticeUtils.buildUserProfile(userProfile); - map.put("applyType", isReconcile ? "RECONCILE" : "APPLY"); - officialNoticeClient.send(NoticeExtTemplateTypeCmd.builder() - .toAccount(cmd.getAcceptApplyUserId()) - .noticeType(OfficialNoticeTypeEnum.CP_BUILD) - .templateParam(map) - .expand(cpApply.getId()) + private final UserRegionGateway userRegionGateway; + + public void execute(CpApplyCmd cmd) { + process(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId(), cmd.requireReqSysOrigin(), + cmd.getRelationType(), true); + } + + public boolean autoCreateFromCpGift(Long sendUserId, Long acceptUserId, String sysOrigin) { + try { + process(sendUserId, acceptUserId, sysOrigin, CpRelationshipType.CP.name(), false); + return true; + } catch (Exception ex) { + log.info("[CP] skip auto create cp apply from gift, sendUserId={}, acceptUserId={}, reason={}", + sendUserId, acceptUserId, ex.getMessage()); + return false; + } + } + + private void process(Long sendUserId, Long acceptUserId, String sysOrigin, String relationTypeValue, + boolean chargeGold) { + CpRelationshipType relationType = parseRelationType(relationTypeValue); + + // 不可用操作自己 + ResponseAssert.isFalse(UserRelationErrorCode.UNAVAILABLE_OPS_YOURSELF, + Objects.equals(sendUserId, acceptUserId)); + + boolean eqRegion = userRegionGateway.checkEqRegion(sendUserId, acceptUserId); + ResponseAssert.isTrue(UserRelationErrorCode.UNAVAILABLE_NOT_REGION, eqRegion); + + UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO( + userProfileGateway.getByUserId(sendUserId)); + UserProfileDTO acceptUserProfile = userProfileAppConvertor.toUserProfileDTO( + userProfileGateway.getByUserId(acceptUserId)); + validateRelationTypeGender(relationType, userProfile, acceptUserProfile); + + // 检查是否是复合申请 + CpRelationship dismissingCp = cpRelationshipService.getDismissingCp( + sendUserId, acceptUserId, relationType.name()); + boolean isReconcile = Objects.nonNull(dismissingCp); + + if (!isReconcile) { + // 非复合申请:检查CP是否已存在 + ResponseAssert.isFalse(UserRelationErrorCode.ME_OR_YOU_CP_EXISTED, + cpRelationshipService + .existsCp(sendUserId, acceptUserId, relationType.name())); + + // 检查CP数量限制(最多4个) + int senderCpCount = cpRelationshipService.countCp(sendUserId); + int receiverCpCount = cpRelationshipService.countCp(acceptUserId); + ResponseAssert.isFalse(UserRelationErrorCode.CP_LIMIT_EXCEEDED, senderCpCount >= 4); + ResponseAssert.isFalse(UserRelationErrorCode.CP_LIMIT_EXCEEDED, receiverCpCount >= 4); + } + + // 您已发送申请 + ResponseAssert.isFalse(UserRelationErrorCode.YOU_HAVE_SENT_AN_APPLICATION, + cpApplyService.existsNotProcessSendApply(sendUserId, relationType.name())); + + // 对方已向你发送申请 + ResponseAssert.isFalse(UserRelationErrorCode.OTHER_SIDE_ALREADY_APPLIED, + cpApplyService.exists(sendUserId, acceptUserId, relationType.name())); + + BigDecimal applyConsumeGold = BigDecimal.ZERO; + if (chargeGold) { + WalletReceiptResDTO receipt = ResponseAssert.requiredSuccess( + walletGoldClient.changeBalance(GoldReceiptCmd.builder() + .appExpenditure() + .userId(sendUserId) + .eventId(acceptUserId.toString()) + .sysOrigin(sysOrigin) + .origin(GoldOrigin.CP_BUILD) + .amount(enumConfigCacheService.getValueBigDecimal(EnumConfigKey.CP_PRICE, + sysOrigin)) + .build()) + ); + applyConsumeGold = receipt.getOpAmount().getDollarAmount(); + } + + String applyText = isReconcile + ? "User " + userProfile.getUserNickname() + " wants to reconcile with you; if you accept, you will be " + + relationType.applyTargetText() + " again." + : "User " + userProfile.getUserNickname() + " invited you; if you accept, you will become " + + relationType.applyTargetText() + "."; + + CpApply cpApply = new CpApply() + .setSendApplyUserId(sendUserId) + .setAcceptApplyUserId(acceptUserId) + .setRelationType(relationType.name()) + .setApplyText(applyText) + .setStatus(CpApplyStatus.WAIT.name()) + .setApplyConsumeGold(applyConsumeGold); + + cpApplyService.save(cpApply); + + Map map = OfficialNoticeUtils.buildUserProfile(userProfile); + map.put("applyType", isReconcile ? "RECONCILE" : "APPLY"); + map.put("relationType", relationType.name()); + officialNoticeClient.send(NoticeExtTemplateTypeCmd.builder() + .toAccount(acceptUserId) + .noticeType(OfficialNoticeTypeEnum.CP_BUILD) + .templateParam(map) + .expand(cpApply.getId()) .build() ); - userMqMessageService.cpApplyDelayed( - new CpApplyEvent() - .setId(cpApply.getId()) - .setSysOrigin(SysOriginPlatformEnum.valueOf(cmd.requireReqSysOrigin())), - TimestampUtils.nowPlusDays(1)); - } - -} + userMqMessageService.cpApplyDelayed( + new CpApplyEvent() + .setId(cpApply.getId()) + .setSysOrigin(SysOriginPlatformEnum.valueOf(sysOrigin)), + TimestampUtils.nowPlusDays(1)); + } + + private CpRelationshipType parseRelationType(String relationTypeValue) { + try { + return CpRelationshipType.of(relationTypeValue); + } catch (IllegalArgumentException ex) { + ResponseAssert.failure(CommonErrorCode.TYPE_IS_NOT_IN_SCOPE, "relationType is not supported."); + return CpRelationshipType.CP; + } + } + + private void validateRelationTypeGender(CpRelationshipType relationType, UserProfileDTO userProfile, + UserProfileDTO acceptUserProfile) { + if (Objects.equals(relationType, CpRelationshipType.CP)) { + ResponseAssert.isFalse(UserRelationErrorCode.UNAVAILABLE_SAME_GENDER, + Objects.equals(userProfile.getUserSex(), acceptUserProfile.getUserSex())); + return; + } + ResponseAssert.isTrue(UserRelationErrorCode.RELATION_TYPE_GENDER_NOT_MATCH, + relationType.genderMatched(userProfile.getUserSex(), acceptUserProfile.getUserSex())); + } + +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/CpApplyIdQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/CpApplyIdQryExe.java index 10c6bdc6..a0e19a98 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/CpApplyIdQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/CpApplyIdQryExe.java @@ -1,7 +1,8 @@ package com.red.circle.other.app.command.user.query; -import com.red.circle.common.business.dto.cmd.UserIdCmd; -import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyIdQueryCmd; +import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -17,10 +18,11 @@ public class CpApplyIdQryExe { private final CpApplyService cpApplyService; - public String execute(UserIdCmd cmd) { - return Optional.ofNullable(cpApplyService.getId(cmd.requiredReqUserId(), cmd.getUserId())) - .map(String::valueOf) - .orElse(null); - } + public String execute(CpApplyIdQueryCmd cmd) { + return Optional.ofNullable(cpApplyService.getId(cmd.requiredReqUserId(), cmd.getUserId(), + CpRelationshipType.normalize(cmd.getRelationType()))) + .map(String::valueOf) + .orElse(null); + } } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpBlessRecordQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpBlessRecordQueryExe.java index 7b3d6163..2523662b 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpBlessRecordQueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpBlessRecordQueryExe.java @@ -8,10 +8,11 @@ import com.red.circle.other.app.dto.clientobject.user.user.CpBlessRecordCO; import com.red.circle.other.app.dto.cmd.user.user.UserCpBlessRecordQueryCmd; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.model.user.UserProfile; -import com.red.circle.other.infra.database.rds.entity.user.user.CpBlessRecord; -import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; -import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.entity.user.user.CpBlessRecord; +import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; +import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import com.red.circle.tool.core.collection.CollectionUtils; import java.util.List; import java.util.Map; @@ -37,7 +38,8 @@ public class UserCpBlessRecordQueryExe { public List execute(UserCpBlessRecordQueryCmd cmd) { - CpRelationship relationship = cpRelationshipService.getByUserIdOrCpUserId(cmd.getUserId()); + CpRelationship relationship = cpRelationshipService.getByUserIdOrCpUserId( + cmd.getUserId(), CpRelationshipType.normalize(cmd.getRelationType())); if (Objects.isNull(relationship)) { return Lists.newArrayList(); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpCabinQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpCabinQueryExe.java index 7770671d..9898c295 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpCabinQueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpCabinQueryExe.java @@ -1,18 +1,16 @@ package com.red.circle.other.app.command.user.query; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.red.circle.common.business.core.enums.CommonErrorEnum; -import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; -import com.red.circle.framework.core.asserts.ResponseAssert; -import com.red.circle.other.app.convertor.user.UserCpCabinConvertor; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import com.red.circle.other.app.convertor.user.UserCpCabinConvertor; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpCabinConfigCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; import com.red.circle.other.app.dto.clientobject.user.relation.cp.UserCpCabinSpecialMemberCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinSpecialCO; -import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinCO; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinSpecialCO; +import com.red.circle.other.app.dto.cmd.user.user.UserCpCabinQueryCmd; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.infra.database.rds.entity.user.user.CpBlessRecord; import com.red.circle.other.infra.database.rds.entity.user.user.CpCabinConfig; @@ -20,17 +18,19 @@ import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; import com.red.circle.other.infra.database.rds.entity.user.user.CpValue; import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService; import com.red.circle.other.infra.database.rds.service.user.user.CpCabinAchieveService; -import com.red.circle.other.infra.database.rds.service.user.user.CpCabinConfigService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; -import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.database.rds.service.user.user.CpCabinConfigService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.TimestampUtils; -import com.red.circle.tool.core.num.NumUtils; -import java.math.BigDecimal; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import com.red.circle.tool.core.num.NumUtils; +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import lombok.AllArgsConstructor; @@ -55,32 +55,28 @@ public class UserCpCabinQueryExe { private final CpCabinAchieveService cpCabinAchieveService; private final CpRelationshipService cpRelationshipService; - public UserCpCabinCO execute(UserIdCommonCmd cmd) { - - List cpCabinConfig = cpCabinConfigService.getCpCabinConfig( - cmd.getReqSysOrigin().getOrigin()); - ResponseAssert.notEmpty(CommonErrorEnum.NOT_FOUND_MAPPING_INFO, cpCabinConfig); - - List cpCabinConfigList = userCpCabinConvertor.toCpCabinConfigCO(cpCabinConfig); - CpRelationship relationship = cpRelationshipService.getByUserIdOrCpUserId(cmd.getUserId()); - Boolean selfCabin = Objects.equals(cmd.getUserId(), cmd.getReqUserId()); - - if (Objects.isNull(relationship)) { - UserCpCabinCO userCpCabinCO = new UserCpCabinCO(); - CpPairUserProfileCO cpPairUserProfileCO = new CpPairUserProfileCO(); - cpPairUserProfileCO.setMeUserProfile(userProfileAppConvertor.toUserProfileDTO( - userProfileGateway.getByUserId(cmd.getReqUserId()))); - userCpCabinCO.setCpPairUserProfileCO(cpPairUserProfileCO); - userCpCabinCO.setCpCabinConfigCO(cpCabinConfigList); - userCpCabinCO.setCheckSelfCabin(selfCabin); - userCpCabinCO.setCpValLastMonth(0L); - return userCpCabinCO; - } - - CpValue cpValue = cpValueService.getById(relationship.getCpValId()); - CpPairUserProfileCO cpPairUserProfileCO = new CpPairUserProfileCO(); - cpPairUserProfileCO.setCpUserProfile(userProfileAppConvertor.toUserProfileDTO( - userProfileGateway.getByUserId(relationship.getCpUserId()))); + public UserCpCabinCO execute(UserCpCabinQueryCmd cmd) { + String relationType = CpRelationshipType.normalize(cmd.getRelationType()); + CpRelationship relationship = cpRelationshipService.getByUserIdOrCpUserId( + cmd.getUserId(), relationType); + Boolean selfCabin = Objects.equals(cmd.getUserId(), cmd.getReqUserId()); + + if (Objects.isNull(relationship)) { + return emptyCabin(selfCabin); + } + + List cpCabinConfig = cpCabinConfigService.getCpCabinConfig( + cmd.getReqSysOrigin().getOrigin()); + + List cpCabinConfigList = CollectionUtils.isEmpty(cpCabinConfig) + ? Collections.emptyList() + : userCpCabinConvertor.toCpCabinConfigCO(cpCabinConfig); + + CpValue cpValue = cpValueService.getById(relationship.getCpValId()); + CpPairUserProfileCO cpPairUserProfileCO = new CpPairUserProfileCO(); + cpPairUserProfileCO.setRelationType(CpRelationshipType.normalize(relationship.getRelationType())); + cpPairUserProfileCO.setCpUserProfile(userProfileAppConvertor.toUserProfileDTO( + userProfileGateway.getByUserId(relationship.getCpUserId()))); cpPairUserProfileCO.setMeUserProfile(userProfileAppConvertor.toUserProfileDTO( userProfileGateway.getByUserId(relationship.getUserId()))); cpPairUserProfileCO.setDays(TimestampUtils.durationNowDays(relationship.getCreateTime())); @@ -101,10 +97,22 @@ public class UserCpCabinQueryExe { .currentCpCabinConfigCO(currentCpCabin) .checkSelfCabin(selfCabin) .userCpCabinSpecial(specialCO) - .build(); - } - - private UserCpCabinSpecialCO getUserCpCabinSpecialCO( + .build(); + } + + private static UserCpCabinCO emptyCabin(Boolean selfCabin) { + return UserCpCabinCO.builder() + .cpVal("0") + .blessVal(0L) + .cpPairUserProfileCO(null) + .cpCabinConfigCO(Collections.emptyList()) + .currentCpCabinConfigCO(null) + .userCpCabinSpecial(null) + .checkSelfCabin(Boolean.TRUE.equals(selfCabin)) + .build(); + } + + private UserCpCabinSpecialCO getUserCpCabinSpecialCO( CpRelationship relationship, CpPairUserProfileCO cpPairUserProfileCO, CpCabinConfigCO currentCpCabin) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpCabinValueQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpCabinValueQueryExe.java index 4403f9aa..ad0c0e01 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpCabinValueQueryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpCabinValueQueryExe.java @@ -1,12 +1,13 @@ package com.red.circle.other.app.command.user.query; -import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinValueCO; -import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; -import com.red.circle.other.infra.database.rds.entity.user.user.CpValue; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; -import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinValueCO; +import com.red.circle.other.app.dto.cmd.user.user.UserCpCabinQueryCmd; +import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; +import com.red.circle.other.infra.database.rds.entity.user.user.CpValue; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import com.red.circle.tool.core.num.NumUtils; import java.math.BigDecimal; import java.util.Objects; @@ -27,9 +28,10 @@ public class UserCpCabinValueQueryExe { private final CpValueService cpValueService; private final CpRelationshipService cpRelationshipService; - public UserCpCabinValueCO execute(UserIdCommonCmd cmd) { - - CpRelationship relationship = cpRelationshipService.getByUserIdOrCpUserId(cmd.getUserId()); + public UserCpCabinValueCO execute(UserCpCabinQueryCmd cmd) { + + CpRelationship relationship = cpRelationshipService.getByUserIdOrCpUserId( + cmd.getUserId(), CpRelationshipType.normalize(cmd.getRelationType())); if (Objects.isNull(relationship)) { return UserCpCabinValueCO.builder() .blessVal(0L) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpLightCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpLightCmdExe.java index eea74b01..f7c81dad 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpLightCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpLightCmdExe.java @@ -1,16 +1,16 @@ package com.red.circle.other.app.command.user.query; -import com.red.circle.common.business.core.enums.CommonErrorEnum; -import com.red.circle.common.business.dto.cmd.UserIdCmd; -import com.red.circle.framework.core.asserts.ResponseAssert; -import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileCO; -import com.red.circle.other.app.dto.cmd.user.relation.cp.UserCpLightCmd; -import com.red.circle.other.app.service.user.relation.UserCpLightCacheService; -import java.util.Objects; - -import com.red.circle.other.app.service.user.relation.UserCpRelationService; -import lombok.AllArgsConstructor; +import com.red.circle.common.business.core.enums.CommonErrorEnum; +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.other.app.dto.cmd.user.relation.cp.UserCpLightCmd; +import com.red.circle.other.app.service.user.relation.UserCpLightCacheService; +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.infra.enums.user.user.CpRelationshipType; +import java.util.Objects; + +import lombok.AllArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,43 +25,44 @@ import org.springframework.stereotype.Component; @AllArgsConstructor public class UserCpLightCmdExe { - private final UserCpLightCacheService userCpLightCacheService; - private final UserCpRelationService userCpRelationService; + private final UserCpLightCacheService userCpLightCacheService; + private final CpRelationshipService cpRelationshipService; public void execute(UserCpLightCmd cmd) { if (StringUtils.isBlank(cmd.getNearUserId()) || Objects.equals(cmd.getNearUserId(), "null")) { ResponseAssert.failure(CommonErrorEnum.DATA_PARSING_ERROR); } - UserIdCmd userIdCmd = new UserIdCmd(); - userIdCmd.setUserId(cmd.getReqUserId()); - CpUserProfileCO cpUserProfileCO = userCpRelationService.getCpUser(userIdCmd); - - // 如果cp用户是空,不点亮 - if (Objects.isNull(cpUserProfileCO)) { - return; - } - - // 如果cp不是旁边用户,不点亮 - if (Objects.nonNull(cpUserProfileCO.getUserProfile().getId()) && !Objects.equals(cpUserProfileCO.getUserProfile().getId().toString(), cmd.getNearUserId())) { - return; - } - - if (Objects.nonNull(cmd.getType()) && Objects.equals(cmd.getType(), "APPOINT")) { - userCpLightCacheService.lightCpUserAppoint(cmd.getReqUserId(), - Long.parseLong(cmd.getNearUserId()), - cmd.getReqSysOrigin().getOrigin()); - userCpLightCacheService.lightCpUserAppoint( - Long.parseLong(cmd.getNearUserId()), - cmd.getReqUserId(), - cmd.getReqSysOrigin().getOrigin()); - } else { - userCpLightCacheService.lightCpUser(cmd.getReqUserId(), - Long.parseLong(cmd.getNearUserId()), - cmd.getReqSysOrigin().getOrigin()); - userCpLightCacheService.lightCpUser( - Long.parseLong(cmd.getNearUserId()), - cmd.getReqUserId(), - cmd.getReqSysOrigin().getOrigin()); + Long nearUserId = Long.parseLong(cmd.getNearUserId()); + CpRelationship cpRelationship = cpRelationshipService.getByUserId( + cmd.getReqUserId(), nearUserId, CpRelationshipType.normalize(cmd.getRelationType())); + + // 如果cp用户是空,不点亮 + if (Objects.isNull(cpRelationship)) { + return; + } + + // 如果cp不是旁边用户,不点亮 + if (Objects.nonNull(cpRelationship.getCpUserId()) && !Objects.equals( + cpRelationship.getCpUserId(), nearUserId)) { + return; + } + + if (Objects.nonNull(cmd.getType()) && Objects.equals(cmd.getType(), "APPOINT")) { + userCpLightCacheService.lightCpUserAppoint(cmd.getReqUserId(), + nearUserId, + cmd.getReqSysOrigin().getOrigin()); + userCpLightCacheService.lightCpUserAppoint( + nearUserId, + cmd.getReqUserId(), + cmd.getReqSysOrigin().getOrigin()); + } else { + userCpLightCacheService.lightCpUser(cmd.getReqUserId(), + nearUserId, + cmd.getReqSysOrigin().getOrigin()); + userCpLightCacheService.lightCpUser( + nearUserId, + cmd.getReqUserId(), + cmd.getReqSysOrigin().getOrigin()); } } @@ -69,36 +70,36 @@ public class UserCpLightCmdExe { if (StringUtils.isBlank(cmd.getNearUserId()) || Objects.equals(cmd.getNearUserId(), "null")) { ResponseAssert.failure(CommonErrorEnum.DATA_PARSING_ERROR); } - UserIdCmd userIdCmd = new UserIdCmd(); - userIdCmd.setUserId(cmd.getReqUserId()); - CpUserProfileCO cpUserProfileCO = userCpRelationService.getCpUser(userIdCmd); - - // 如果cp用户是空,不点亮 - if (Objects.isNull(cpUserProfileCO)) { - return; - } + Long nearUserId = Long.parseLong(cmd.getNearUserId()); + CpRelationship cpRelationship = cpRelationshipService.getByUserId( + cmd.getReqUserId(), nearUserId, CpRelationshipType.normalize(cmd.getRelationType())); + + // 如果cp用户是空,不点亮 + if (Objects.isNull(cpRelationship)) { + return; + } // 如果cp不是旁边用户,不点亮 /*if (Objects.nonNull(cpUserProfileCO.getUserProfile().getId()) && !Objects.equals(cpUserProfileCO.getUserProfile().getId().toString(), cmd.getNearUserId())) { return; }*/ - if (Objects.nonNull(cmd.getType()) && Objects.equals(cmd.getType(), "APPOINT")) { - userCpLightCacheService.cancelCpUserAppoint(cmd.getReqUserId(), - cpUserProfileCO.getUserProfile().getId(), - cmd.getReqSysOrigin().getOrigin()); - userCpLightCacheService.cancelCpUserAppoint( - cpUserProfileCO.getUserProfile().getId(), - cmd.getReqUserId(), - cmd.getReqSysOrigin().getOrigin()); - } else { - userCpLightCacheService.cancelCpUser(cmd.getReqUserId(), - cpUserProfileCO.getUserProfile().getId(), - cmd.getReqSysOrigin().getOrigin()); - userCpLightCacheService.cancelCpUser( - cpUserProfileCO.getUserProfile().getId(), - cmd.getReqUserId(), - cmd.getReqSysOrigin().getOrigin()); + if (Objects.nonNull(cmd.getType()) && Objects.equals(cmd.getType(), "APPOINT")) { + userCpLightCacheService.cancelCpUserAppoint(cmd.getReqUserId(), + cpRelationship.getCpUserId(), + cmd.getReqSysOrigin().getOrigin()); + userCpLightCacheService.cancelCpUserAppoint( + cpRelationship.getCpUserId(), + cmd.getReqUserId(), + cmd.getReqSysOrigin().getOrigin()); + } else { + userCpLightCacheService.cancelCpUser(cmd.getReqUserId(), + cpRelationship.getCpUserId(), + cmd.getReqSysOrigin().getOrigin()); + userCpLightCacheService.cancelCpUser( + cpRelationship.getCpUserId(), + cmd.getReqUserId(), + cmd.getReqSysOrigin().getOrigin()); } } } 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 e088836d..f22452fc 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 @@ -1,25 +1,27 @@ package com.red.circle.other.app.command.user.query; -import com.red.circle.common.business.dto.cmd.AppExtCommand; -import com.red.circle.framework.core.asserts.ResponseAssert; -import com.red.circle.mq.business.model.event.task.TaskApprovalEvent; -import com.red.circle.mq.rocket.business.producer.TaskMqMessage; -import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.mq.business.model.event.task.TaskApprovalEvent; +import com.red.circle.mq.rocket.business.producer.TaskMqMessage; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; import com.red.circle.tool.core.date.DateUtils; -import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; -import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; -import com.red.circle.other.domain.model.user.UserProfile; -import com.red.circle.other.domain.gateway.user.UserProfileGateway; -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.app.convertor.user.UserProfileAppConvertor; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpRelationshipQueryCmd; +import com.red.circle.other.domain.model.user.UserProfile; +import com.red.circle.other.domain.gateway.user.UserProfileGateway; +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.infra.enums.user.user.CpRelationshipType; 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.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; +import java.time.ZoneId; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Objects; import com.red.circle.tool.core.date.LocalDateTimeUtils; import lombok.RequiredArgsConstructor; @@ -32,7 +34,9 @@ import org.springframework.stereotype.Component; */ @Component @RequiredArgsConstructor -public class UserCpPairUserProfileQryExe { +public class UserCpPairUserProfileQryExe { + + private static final long DISMISS_DURATION_MS = 7 * 24 * 60 * 60 * 1000L; private final CpRelationshipService cpRelationshipService; private final UserProfileGateway userProfileGateway; @@ -40,13 +44,16 @@ public class UserCpPairUserProfileQryExe { private final CpValueService cpValueService; private final TaskMqMessage taskMqMessage; - public List execute(AppExtCommand cmd) { - - UserProfile meUser = userProfileGateway.getByUserId(cmd.requiredReqUserId()); - ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, meUser); - - List cpRelationshipList = cpRelationshipService.getByUserId(cmd.requiredReqUserId()); - List dismissing = cpRelationshipService.getDismissingByUserId(cmd.requiredReqUserId()); + public List execute(CpRelationshipQueryCmd cmd) { + String relationType = CpRelationshipType.normalize(cmd.getRelationType()); + + UserProfile meUser = userProfileGateway.getByUserId(cmd.requiredReqUserId()); + ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, meUser); + + List cpRelationshipList = cpRelationshipService.getByUserId( + cmd.requiredReqUserId(), relationType); + List dismissing = cpRelationshipService.getDismissingByUserId( + cmd.requiredReqUserId(), relationType); cpRelationshipList.addAll(dismissing); if (cpRelationshipList.isEmpty()) { return Collections.emptyList(); @@ -54,18 +61,48 @@ public class UserCpPairUserProfileQryExe { return cpRelationshipList.stream() .map(cpRelationship -> new CpPairUserProfileCO() - .setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser))) - .setCpUserProfile(getUserProfile(cpRelationship.getCpUserId())) - .setStatus(cpRelationship.getStatus()) - .setCpValue(cpValueService.getCpVal(cpRelationship.getCpValId())) - .setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now())) - .setFirstDay(cpRelationship.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString())) - .sorted(Comparator.comparing(CpPairUserProfileCO::getCpValue).reversed()) - .toList(); - } + .setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser))) + .setCpUserProfile(getUserProfile(cpRelationship.getCpUserId())) + .setRelationType(relationType(cpRelationship)) + .setStatus(cpRelationship.getStatus()) + .setCpValue(cpValueService.getCpVal(cpRelationship.getCpValId())) + .setDays(relationshipDays(cpRelationship.getCreateTime())) + .setFirstDay(cpRelationship.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString()) + .setDismissEndTime(dismissEndTime(cpRelationship)) + .setDismissRemainSeconds(dismissRemainSeconds(cpRelationship))) + .sorted(Comparator.comparing(CpPairUserProfileCO::getCpValue).reversed()) + .toList(); + } - private UserProfileDTO getUserProfile(Long cpUserId) { - return userProfileAppConvertor.toUserProfileDTO(userProfileGateway - .getByUserId(cpUserId)); - } -} + private UserProfileDTO getUserProfile(Long cpUserId) { + return userProfileAppConvertor.toUserProfileDTO(userProfileGateway + .getByUserId(cpUserId)); + } + + private static long relationshipDays(Date createTime) { + Date now = DateUtils.now(); + if (!createTime.before(now)) { + return 0L; + } + return DateUtils.toDurationDays(createTime, now); + } + + private static String relationType(CpRelationship cpRelationship) { + return CpRelationshipType.normalize(cpRelationship.getRelationType()); + } + + private static Long dismissEndTime(CpRelationship cpRelationship) { + if (Objects.isNull(cpRelationship.getDismissTime())) { + return null; + } + return cpRelationship.getDismissTime() + DISMISS_DURATION_MS; + } + + private static Long dismissRemainSeconds(CpRelationship cpRelationship) { + Long dismissEndTime = dismissEndTime(cpRelationship); + if (Objects.isNull(dismissEndTime)) { + return null; + } + return Math.max(0L, (dismissEndTime - System.currentTimeMillis()) / 1000); + } +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQryExe.java index 59414126..26acfe4e 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQryExe.java @@ -6,13 +6,15 @@ import com.red.circle.tool.core.date.DateUtils; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileCO; import com.red.circle.other.domain.gateway.user.UserProfileGateway; -import com.red.circle.other.infra.database.cache.service.user.UserCpValueCacheService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.cache.service.user.UserCpValueCacheService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; -import com.red.circle.other.inner.enums.user.UserCpLevelEnum; - -import java.time.ZoneId; -import java.util.Optional; +import com.red.circle.other.inner.enums.user.UserCpLevelEnum; + +import java.time.ZoneId; +import java.util.Date; +import java.util.Optional; import com.red.circle.tool.core.date.LocalDateTimeUtils; import com.red.circle.tool.core.date.ZonedId; @@ -35,20 +37,29 @@ public class UserCpRelationQryExe { public CpUserProfileCO execute(UserIdCmd cmd) { return Optional.ofNullable(cpRelationshipService.getByUserId(cmd.getReqUserId(), cmd.getUserId())) - .map(cpRelationship -> new CpUserProfileCO() - .setUserProfile(getUserProfile(cpRelationship.getCpUserId())) - .setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now())) + .map(cpRelationship -> new CpUserProfileCO() + .setUserProfile(getUserProfile(cpRelationship.getCpUserId())) + .setRelationType(CpRelationshipType.normalize(cpRelationship.getRelationType())) + .setDays(relationshipDays(cpRelationship.getCreateTime())) .setFirstDay(cpRelationship.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString()) ) .orElse(null); } - private UserProfileDTO getUserProfile(Long cpUserId) { - return userProfileAppConvertor.toUserProfileDTO(userProfileGateway - .getByUserId(cpUserId)); - } - - private UserCpLevelEnum getLevel(Long userId1, Long userId2) { + private UserProfileDTO getUserProfile(Long cpUserId) { + return userProfileAppConvertor.toUserProfileDTO(userProfileGateway + .getByUserId(cpUserId)); + } + + private static long relationshipDays(Date createTime) { + Date now = DateUtils.now(); + if (!createTime.before(now)) { + return 0L; + } + return DateUtils.toDurationDays(createTime, now); + } + + private UserCpLevelEnum getLevel(Long userId1, Long userId2) { Long val = userCpValueCacheService.getValue(userId1, userId2); if (val > 350000) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQueryV4Exe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQueryV4Exe.java index d9967189..e906d122 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQueryV4Exe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRelationQueryV4Exe.java @@ -19,8 +19,9 @@ import com.red.circle.other.infra.database.rds.entity.user.user.CpValue; import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService; import com.red.circle.other.infra.database.rds.service.user.user.CpCabinAchieveService; import com.red.circle.other.infra.database.rds.service.user.user.CpCabinConfigService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; -import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import com.red.circle.other.inner.enums.user.UserCpLevelEnum; import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.tool.core.collection.CollectionUtils; @@ -76,9 +77,10 @@ public class UserCpRelationQueryV4Exe { cpCabinAchieveService.lastMonthCpVal(cpValue.getId())); } - return buildUserCpCabinSpecialCO(CpCabinUserProfileCO.builder() - .userProfile(getUserProfile(cpRelationship.getCpUserId())) - .days(TimestampUtils.durationNowDays(cpRelationship.getCreateTime())) + return buildUserCpCabinSpecialCO(CpCabinUserProfileCO.builder() + .userProfile(getUserProfile(cpRelationship.getCpUserId())) + .relationType(CpRelationshipType.normalize(cpRelationship.getRelationType())) + .days(TimestampUtils.durationNowDays(cpRelationship.getCreateTime())) .level(getLevel(cpRelationship.getUserId(), cpRelationship.getCpUserId())) .currentCpCabinConfigCO(currentCpCabinConfigCO) .cpCabinConfigCO(cpCabinConfigList) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRightsConfigQueryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRightsConfigQueryExe.java new file mode 100644 index 00000000..6f70c14f --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UserCpRightsConfigQueryExe.java @@ -0,0 +1,141 @@ +package com.red.circle.other.app.command.user.query; + +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpRightsConfigCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpRightsConfigQueryCmd; +import com.red.circle.other.infra.database.rds.entity.user.user.CpCabinConfig; +import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; +import com.red.circle.other.infra.database.rds.entity.user.user.CpValue; +import com.red.circle.other.infra.database.rds.service.user.user.CpCabinConfigService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.IntStream; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +/** + * CP rights config query. + */ +@Component +@RequiredArgsConstructor +public class UserCpRightsConfigQueryExe { + + private static final String RELATIONSHIP_STATUS_NONE = "NONE"; + + private final CpCabinConfigService cpCabinConfigService; + private final CpRelationshipService cpRelationshipService; + private final CpValueService cpValueService; + + public CpRightsConfigCO execute(CpRightsConfigQueryCmd cmd) { + String relationType = CpRelationshipType.normalize(cmd.getRelationType()); + CpRelationship relationship = findRelationship(cmd.getReqUserId(), cmd.getCpUserId(), + relationType); + Long intimacyValue = getIntimacyValue(relationship); + List configs = cpCabinConfigService.getCpCabinConfig( + cmd.getReqSysOrigin().getOrigin()); + + return CpRightsConfigCO.builder() + .relationType(relationType) + .cpUserId(resolveCpUserId(cmd.getReqUserId(), cmd.getCpUserId(), relationship)) + .relationshipStatus(Objects.isNull(relationship) ? RELATIONSHIP_STATUS_NONE + : relationship.getStatus()) + .intimacyValue(intimacyValue) + .levels(toLevels(relationType, configs, Objects.nonNull(relationship), intimacyValue)) + .build(); + } + + private CpRelationship findRelationship(Long reqUserId, Long cpUserId, String relationType) { + if (Objects.isNull(reqUserId)) { + return null; + } + if (Objects.nonNull(cpUserId)) { + CpRelationship normal = cpRelationshipService.getByUserId(reqUserId, cpUserId, + relationType); + if (Objects.nonNull(normal)) { + return normal; + } + return cpRelationshipService.getDismissingCp(reqUserId, cpUserId, relationType); + } + return cpRelationshipService.getByUserIdOrCpUserId(reqUserId, relationType); + } + + private Long getIntimacyValue(CpRelationship relationship) { + if (Objects.isNull(relationship)) { + return 0L; + } + CpValue cpValue = cpValueService.getById(relationship.getCpValId()); + return Optional.ofNullable(cpValue) + .map(CpValue::getCpVal) + .map(BigDecimal::longValue) + .orElse(0L); + } + + private Long resolveCpUserId(Long reqUserId, Long requestCpUserId, CpRelationship relationship) { + if (Objects.nonNull(requestCpUserId) || Objects.isNull(relationship)) { + return requestCpUserId; + } + if (Objects.equals(relationship.getUserId(), reqUserId)) { + return relationship.getCpUserId(); + } + if (Objects.equals(relationship.getCpUserId(), reqUserId)) { + return relationship.getUserId(); + } + return relationship.getCpUserId(); + } + + private List toLevels(String relationType, List configs, + boolean hasRelationship, Long intimacyValue) { + if (Objects.isNull(configs) || configs.isEmpty()) { + return Collections.emptyList(); + } + return IntStream.range(0, configs.size()) + .mapToObj(index -> toLevel(relationType, configs.get(index), index + 1, hasRelationship, + intimacyValue)) + .toList(); + } + + private CpRightsConfigCO.LevelCO toLevel(String relationType, CpCabinConfig config, int level, + boolean hasRelationship, Long intimacyValue) { + Long requiredIntimacyValue = Optional.ofNullable(config.getCabinUnlockValue()).orElse(0L); + boolean unlocked = hasRelationship && Optional.ofNullable(intimacyValue).orElse(0L) + >= requiredIntimacyValue; + String levelName = StringUtils.defaultIfBlank(config.getName(), relationType + " Level " + + level); + + return CpRightsConfigCO.LevelCO.builder() + .level(level) + .levelName(levelName) + .requiredIntimacyValue(requiredIntimacyValue) + .unlocked(unlocked) + .rights(Collections.singletonList(toRight(relationType, config, level, levelName, + requiredIntimacyValue, unlocked))) + .build(); + } + + private CpRightsConfigCO.RightCO toRight(String relationType, CpCabinConfig config, int level, + String title, Long requiredIntimacyValue, boolean unlocked) { + return CpRightsConfigCO.RightCO.builder() + .rightKey(relationType + "_CABIN_LEVEL_" + level) + .icon(firstNotBlank(config.getCover(), config.getPersonCover(), config.getCardCover(), + config.getBackgroundCover(), config.getSourceMiniUrl(), config.getSourceUrl())) + .title(title) + .desc("Unlock when intimacy reaches " + requiredIntimacyValue) + .unlocked(unlocked) + .build(); + } + + private String firstNotBlank(String... values) { + for (String value : values) { + if (StringUtils.isNotBlank(value)) { + return value; + } + } + return null; + } +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftCountStrategy.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftCountStrategy.java index 13f224f0..a2adf6ea 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftCountStrategy.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftCountStrategy.java @@ -5,20 +5,23 @@ import com.google.common.collect.Lists; import com.red.circle.common.business.core.enums.GameStateEnum; import com.red.circle.common.business.core.enums.SysOriginPlatformEnum; import com.red.circle.common.business.enums.DynamicMessageEnum; -import com.red.circle.component.redis.service.RedisService; -import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient; -import com.red.circle.mq.business.model.event.gift.OfflineProcessGiftEvent; +import com.red.circle.component.redis.service.RedisService; +import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient; +import com.red.circle.external.inner.model.cmd.message.notice.official.NoticeExtTemplateTypeCmd; +import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum; +import com.red.circle.mq.business.model.event.gift.OfflineProcessGiftEvent; import com.red.circle.mq.rocket.business.producer.TaskMqMessage; import com.red.circle.mq.rocket.business.producer.UserMqMessageService; -import com.red.circle.other.app.common.game.GameIndoorTeamPkCommon; -import com.red.circle.other.app.common.gift.GameLuckyGiftCommon; -import com.red.circle.other.app.dto.clientobject.dynamic.MessageItemCO; +import com.red.circle.other.app.common.game.GameIndoorTeamPkCommon; +import com.red.circle.other.app.common.gift.GameLuckyGiftCommon; +import com.red.circle.other.app.command.user.SendCpApplyCmdExe; +import com.red.circle.other.app.dto.clientobject.dynamic.MessageItemCO; import com.red.circle.other.app.dto.clientobject.game.GameRoomPkUserCO; import com.red.circle.other.app.dto.cmd.SpinsTaskProgressUpdateCmd; import com.red.circle.other.app.dto.cmd.task.RoomDailyTaskProgressUpdateCmd; import com.red.circle.other.app.service.SpinsUserTaskProgressService; -import com.red.circle.other.app.service.task.RoomDailyTaskProgressService; -import com.red.circle.other.app.service.user.user.UserProfileService; +import com.red.circle.other.app.service.task.RoomDailyTaskProgressService; +import com.red.circle.other.app.service.user.user.UserProfileService; import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils; import com.red.circle.other.domain.enums.VipBenefitType; import com.red.circle.other.domain.gateway.user.UserProfileGateway; @@ -76,7 +79,8 @@ import com.red.circle.other.inner.enums.material.GiftSpecialEnum; import com.red.circle.other.inner.enums.material.GiftTabEnum; import com.red.circle.other.inner.enums.task.RoomDailyTaskCode; import com.red.circle.other.inner.model.dto.material.GiftConfigDTO; -import com.red.circle.tool.core.collection.CollectionUtils; +import com.red.circle.tool.core.collection.CollectionUtils; +import com.red.circle.tool.core.collection.MapBuilder; import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.json.JacksonUtils; @@ -145,8 +149,9 @@ public class GiftCountStrategy implements GiftStrategy { private final DynamicGiftService dynamicGiftService; private final DynamicMessageService dynamicMessageService; private static final List inRegionCodes = List.of("IN", "PK", "BD"); - private final UserRegionCacheService userRegionCacheService; - private final UserProfileGateway userProfileGateway; + private final UserRegionCacheService userRegionCacheService; + private final UserProfileGateway userProfileGateway; + private final SendCpApplyCmdExe sendCpApplyCmdExe; @Override @@ -184,9 +189,12 @@ public class GiftCountStrategy implements GiftStrategy { } } - // 动态礼物处理 - processDynamicGift(runningWater); - + // 动态礼物处理 + processDynamicGift(runningWater); + + autoCreateCpApplyFromCpGift(runningWater); + saveBlessingsRecord(runningWater); + boolean isHighPriceGift = checkHighPriceGift(runningWater); BigDecimal giftValueCount = BigDecimal.valueOf(getActualAmount(giftValue, giftValue.getGiftValue())); @@ -312,7 +320,7 @@ public class GiftCountStrategy implements GiftStrategy { } - private void saveBlessingsRecord(GiftGiveRunningWater runningWater) { + private void saveBlessingsRecord(GiftGiveRunningWater runningWater) { //log.warn("cptesttest saveBlessingsRecord:{},{}",Boolean.FALSE.equals(runningWater.getCheckBlessingsGift()),JacksonUtils.toJson(runningWater)); if (Boolean.FALSE.equals(runningWater.getCheckBlessingsGift())) { return; @@ -357,17 +365,66 @@ public class GiftCountStrategy implements GiftStrategy { cpValueService.incrBlessValue(cpValue.getId(), runningWater.getGiftValue().getGiftValue()); - UserProfile userProfile = userProfileRepository.getByUserId(runningWater.getUserId()); - // 发送祝福通知 - /* officialService.send(NoticeExtTemplateTypeCmd.builder() - .toAccount(runningWater.getAcceptUsers().get(0).getAcceptUserId()) - .noticeType(OfficialNoticeTypeEnum.CP_BLESS) - .templateParam(MapBuilder.builder() - .put("nickname", userProfile.getUserNickname()) - .build()) - .build());*/ - - } + sendCpBlessNotice(runningWater, cpRelationship, cache); + + } + + private void autoCreateCpApplyFromCpGift(GiftGiveRunningWater runningWater) { + try { + if (Objects.isNull(runningWater) || Objects.isNull(runningWater.getGiftValue()) + || !isCpGift(runningWater.getGiftValue())) { + return; + } + if (CollectionUtils.isEmpty(runningWater.getAcceptUsers())) { + return; + } + runningWater.getAcceptUsers().forEach(accept -> { + if (Objects.equals(runningWater.getUserId(), accept.getAcceptUserId())) { + return; + } + sendCpApplyCmdExe.autoCreateFromCpGift( + runningWater.getUserId(), accept.getAcceptUserId(), runningWater.getSysOrigin()); + }); + } catch (Exception ex) { + log.warn("[CP] skip auto create cp apply from gift, runningWaterId={}, giftId={}, sendUserId={}, reason={}", + Objects.nonNull(runningWater) ? runningWater.getId() : null, + Objects.nonNull(runningWater) ? runningWater.getGiftId() : null, + Objects.nonNull(runningWater) ? runningWater.getUserId() : null, + ex.getMessage()); + } + } + + private void sendCpBlessNotice(GiftGiveRunningWater runningWater, CpRelationship cpRelationship, + GiftConfigDTO giftConfig) { + UserProfile userProfile = userProfileRepository.getByUserId(runningWater.getUserId()); + if (Objects.isNull(userProfile)) { + return; + } + List toAccounts = Lists.newArrayList(cpRelationship.getUserId(), cpRelationship.getCpUserId()) + .stream() + .filter(Objects::nonNull) + .distinct() + .toList(); + if (CollectionUtils.isEmpty(toAccounts)) { + return; + } + officialService.send(NoticeExtTemplateTypeCmd.builder() + .toAccounts(toAccounts) + .noticeType(OfficialNoticeTypeEnum.CP_BLESS) + .templateParam(MapBuilder.builder() + .put("nickname", userProfile.getUserNickname()) + .put("userNickname", userProfile.getUserNickname()) + .put("account", userProfile.getAccount()) + .put("userAvatar", userProfile.getUserAvatar()) + .put("countryCode", userProfile.getCountryCode()) + .put("countryName", userProfile.getCountryName()) + .put("giftCover", giftConfig.getGiftPhoto()) + .put("giftCount", runningWater.getGiftValue().getQuantity()) + .put("relationType", cpRelationship.getRelationType()) + .build()) + .expand(cpRelationship.getCpValId()) + .build()); + } /** diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java index a8b10759..4916a221 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java @@ -74,8 +74,13 @@ public class CpApplyListener implements MessageListener { cpApplies.forEach(apply -> reimburse(param, apply)); } - private void reimburse(CpApplyEvent param, CpApply cpApply) { - walletGoldClient.changeBalance(GoldReceiptCmd.builder() + private void reimburse(CpApplyEvent param, CpApply cpApply) { + if (Objects.isNull(cpApply.getApplyConsumeGold()) + || cpApply.getApplyConsumeGold().signum() <= 0) { + cpApplyService.changeStatusById(cpApply.getId(), CpApplyStatus.REIMBURSE); + return; + } + walletGoldClient.changeBalance(GoldReceiptCmd.builder() .appIncome() .userId(cpApply.getSendApplyUserId()) .eventId(cpApply.getId()) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/ActivityCorrectionDataManager.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/ActivityCorrectionDataManager.java index 2b8cd9e6..cf3f1010 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/ActivityCorrectionDataManager.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/manager/activity/ActivityCorrectionDataManager.java @@ -79,7 +79,7 @@ public class ActivityCorrectionDataManager { log.warn("correctionActivityData:CHARM_RANK_MONTH-完成"); // cp - CpRelationship cpRelationship = cpRelationshipService.getByUserId(userId, null); + CpRelationship cpRelationship = cpRelationshipService.getByUserId(userId, (Long) null); if (Objects.nonNull(cpRelationship)) { BigDecimal cpVal = cpValueService.getCpVal(cpRelationship.getCpValId()); 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 9f775222..ab2f5347 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 @@ -1,8 +1,7 @@ package com.red.circle.other.app.service.user.relation; -import com.red.circle.common.business.dto.cmd.AppExtCommand; -import com.red.circle.common.business.dto.cmd.UserIdCmd; -import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; +import com.red.circle.common.business.dto.cmd.UserIdCmd; +import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; import com.red.circle.other.app.command.user.DismissCpApplyCmdExe; import com.red.circle.other.app.command.user.LoveLetterQueryCmdExe; import com.red.circle.other.app.command.user.ProcessCpApplyCmd; @@ -13,19 +12,22 @@ import com.red.circle.other.app.command.user.query.UserCpPairUserProfileQryExe; import com.red.circle.other.app.command.user.query.UserCpRelationQryExe; import com.red.circle.other.app.command.user.query.UserCpRelationQueryV4Exe; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpCabinUserProfileCO; -import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; -import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileCO; -import com.red.circle.other.domain.model.cp.loveletter.LoveLetterDetailCO; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyIdQueryCmd; +import com.red.circle.other.domain.model.cp.loveletter.LoveLetterDetailCO; import com.red.circle.other.domain.model.cp.loveletter.LoveLetterWallCO; -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.dto.cmd.user.relation.cp.loveletter.SendLoveLetterCmd; -import com.red.circle.other.app.util.DistributedLockUtil; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.List; +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.CpRelationshipQueryCmd; +import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd; +import com.red.circle.other.app.dto.cmd.user.relation.cp.loveletter.SendLoveLetterCmd; +import com.red.circle.other.app.util.DistributedLockUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Objects; /** * 用户cp关系实现. @@ -53,13 +55,14 @@ public class UserCpRelationServiceImpl implements UserCpRelationService { } @Override - public List getCpPairUserProfileCO(AppExtCommand cmd) { - return userCpPairUserProfileQryExe.execute(cmd); - } + public List getCpPairUserProfileCO(CpRelationshipQueryCmd cmd) { + return userCpPairUserProfileQryExe.execute(cmd); + } - @Override - public void sendApply(CpApplyCmd cmd) { - String key = "SEND_CP_APPLY:" + cmd.getReqUserId() + "_" + cmd.getAcceptApplyUserId(); + @Override + public void sendApply(CpApplyCmd cmd) { + String key = "SEND_CP_APPLY:" + Objects.toString(cmd.getRelationType(), "CP") + + "_" + cmd.getReqUserId() + "_" + cmd.getAcceptApplyUserId(); distributedLockUtil.executeWithLock(key, () -> { sendCpApplyCmdExe.execute(cmd); }); @@ -79,9 +82,9 @@ public class UserCpRelationServiceImpl implements UserCpRelationService { } @Override - public String getCpApplyId(UserIdCmd cmd) { - return cpApplyIdQryExe.execute(cmd); - } + public String getCpApplyId(CpApplyIdQueryCmd cmd) { + return cpApplyIdQryExe.execute(cmd); + } @Override public CpCabinUserProfileCO getCpUserV4(UserIdCommonCmd cmd) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/CpBlessRecordAndUpReadExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/CpBlessRecordAndUpReadExe.java index 0c0ae418..fe8f3d6d 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/CpBlessRecordAndUpReadExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/CpBlessRecordAndUpReadExe.java @@ -1,17 +1,18 @@ package com.red.circle.other.app.service.user.user; import com.google.common.collect.Lists; -import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; -import com.red.circle.other.app.convertor.user.CpBlessRecordConvert; -import com.red.circle.other.app.convertor.user.UserCpCabinConvertor; -import com.red.circle.other.app.dto.clientobject.user.user.CpBlessRecordCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinUnreadCO; +import com.red.circle.other.app.convertor.user.CpBlessRecordConvert; +import com.red.circle.other.app.convertor.user.UserCpCabinConvertor; +import com.red.circle.other.app.dto.clientobject.user.user.CpBlessRecordCO; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinUnreadCO; +import com.red.circle.other.app.dto.cmd.user.user.UserCpCabinQueryCmd; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.domain.model.user.UserProfile; import com.red.circle.other.infra.database.rds.entity.user.user.CpBlessRecord; -import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; -import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; +import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import com.red.circle.tool.core.collection.CollectionUtils; import java.util.List; import java.util.Map; @@ -36,7 +37,7 @@ public class CpBlessRecordAndUpReadExe { private final CpRelationshipService cpRelationshipService; private final CpBlessRecordConvert cpBlessRecordConvert; - public UserCpCabinUnreadCO execute(UserIdCommonCmd cmd) { + public UserCpCabinUnreadCO execute(UserCpCabinQueryCmd cmd) { if (!Objects.equals(cmd.getReqUserId(), cmd.getUserId())) { return UserCpCabinUnreadCO.builder() @@ -45,7 +46,8 @@ public class CpBlessRecordAndUpReadExe { .build(); } - CpRelationship relationship = cpRelationshipService.getByUserId(cmd.getReqUserId(), cmd.getUserId()); + CpRelationship relationship = cpRelationshipService.getByUserIdOrCpUserId( + cmd.getUserId(), CpRelationshipType.normalize(cmd.getRelationType())); if (Objects.isNull(relationship)) { return UserCpCabinUnreadCO.builder() .topClassRecords(Lists.newArrayList()) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/UserCpCabinServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/UserCpCabinServiceImpl.java index f00795d4..737c6170 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/UserCpCabinServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/UserCpCabinServiceImpl.java @@ -1,16 +1,19 @@ package com.red.circle.other.app.service.user.user; -import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; -import com.red.circle.other.app.command.user.query.UserCpBlessRecordQueryExe; -import com.red.circle.other.app.command.user.query.UserCpCabinQueryExe; -import com.red.circle.other.app.command.user.query.UserCpCabinValueQueryExe; -import com.red.circle.other.app.dto.clientobject.user.user.CpBlessRecordCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinUnreadCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinValueCO; -import com.red.circle.other.app.dto.cmd.user.user.UserCpBlessRecordQueryCmd; -import java.util.List; +import com.red.circle.other.app.command.user.query.UserCpBlessRecordQueryExe; +import com.red.circle.other.app.command.user.query.UserCpCabinQueryExe; +import com.red.circle.other.app.command.user.query.UserCpCabinValueQueryExe; +import com.red.circle.other.app.command.user.query.UserCpRightsConfigQueryExe; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpRightsConfigCO; +import com.red.circle.other.app.dto.clientobject.user.user.CpBlessRecordCO; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinCO; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinUnreadCO; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinValueCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpRightsConfigQueryCmd; +import com.red.circle.other.app.dto.cmd.user.user.UserCpBlessRecordQueryCmd; +import com.red.circle.other.app.dto.cmd.user.user.UserCpCabinQueryCmd; +import java.util.List; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; @@ -23,27 +26,33 @@ import org.springframework.stereotype.Service; public class UserCpCabinServiceImpl implements UserCpCabinService { private final UserCpCabinQueryExe userCpCabinQueryExe; - private final UserCpCabinValueQueryExe userCpCabinValueQueryExe; - private final CpBlessRecordAndUpReadExe cpBlessRecordAndUpReadExe; - private final UserCpBlessRecordQueryExe userCpBlessRecordQueryExe; + private final UserCpCabinValueQueryExe userCpCabinValueQueryExe; + private final CpBlessRecordAndUpReadExe cpBlessRecordAndUpReadExe; + private final UserCpBlessRecordQueryExe userCpBlessRecordQueryExe; + private final UserCpRightsConfigQueryExe userCpRightsConfigQueryExe; @Override - public UserCpCabinCO getCpCabinInfo(UserIdCommonCmd cmd) { - return userCpCabinQueryExe.execute(cmd); - } + public UserCpCabinCO getCpCabinInfo(UserCpCabinQueryCmd cmd) { + return userCpCabinQueryExe.execute(cmd); + } + + @Override + public UserCpCabinValueCO getCpCabinValue(UserCpCabinQueryCmd cmd) { + return userCpCabinValueQueryExe.execute(cmd); + } + + @Override + public UserCpCabinUnreadCO getCpBlessRecordAndUpRead(UserCpCabinQueryCmd cmd) { + return cpBlessRecordAndUpReadExe.execute(cmd); + } @Override - public UserCpCabinValueCO getCpCabinValue(UserIdCommonCmd cmd) { - return userCpCabinValueQueryExe.execute(cmd); - } - - @Override - public UserCpCabinUnreadCO getCpBlessRecordAndUpRead(UserIdCommonCmd cmd) { - return cpBlessRecordAndUpReadExe.execute(cmd); - } - - @Override - public List pageCpBlessRecord(UserCpBlessRecordQueryCmd cmd) { - return userCpBlessRecordQueryExe.execute(cmd); - } -} + public List pageCpBlessRecord(UserCpBlessRecordQueryCmd cmd) { + return userCpBlessRecordQueryExe.execute(cmd); + } + + @Override + public CpRightsConfigCO getCpRightsConfig(CpRightsConfigQueryCmd cmd) { + return userCpRightsConfigQueryExe.execute(cmd); + } +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpCabinUserProfileCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpCabinUserProfileCO.java index 59c1f7ba..6df9a9d1 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpCabinUserProfileCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpCabinUserProfileCO.java @@ -31,9 +31,14 @@ public class CpCabinUserProfileCO extends ClientObject { */ private UserProfileDTO userProfile; - /** - * 组建天数. - */ + /** + * 关系类型:CP/BROTHER/SISTERS. + */ + private String relationType; + + /** + * 组建天数. + */ @JsonSerialize(using = ToStringSerializer.class) private Long days; 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 c0968e70..dce543d9 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 @@ -33,10 +33,15 @@ public class CpPairUserProfileCO extends ClientObject { private UserProfileDTO cpUserProfile; - /** - * CP关系状态(NORMAL-正常, DISMISSING-分手中) - */ - private String status; + /** + * 关系类型:CP/BROTHER/SISTERS. + */ + private String relationType; + + /** + * CP关系状态(NORMAL-正常, DISMISSING-分手中) + */ + private String status; /** * 心动值 @@ -49,10 +54,21 @@ public class CpPairUserProfileCO extends ClientObject { @JsonSerialize(using = ToStringSerializer.class) private Long days; - /** - * 开始组件的日期 - */ - private String firstDay; - - -} + /** + * 开始组件的日期 + */ + private String firstDay; + + /** + * 解除冷静期结束时间戳. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long dismissEndTime; + + /** + * 解除冷静期剩余秒数. + */ + private Long dismissRemainSeconds; + + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpRightsConfigCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpRightsConfigCO.java new file mode 100644 index 00000000..19cf6412 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpRightsConfigCO.java @@ -0,0 +1,116 @@ +package com.red.circle.other.app.dto.clientobject.user.relation.cp; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.red.circle.framework.dto.ClientObject; +import java.io.Serial; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * CP rights config. + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class CpRightsConfigCO extends ClientObject { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * Relationship type: CP/BROTHER/SISTERS. + */ + private String relationType; + + /** + * Relationship user id. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long cpUserId; + + /** + * NORMAL/DISMISSING/NONE. + */ + private String relationshipStatus; + + /** + * Current intimacy value. + */ + private Long intimacyValue; + + /** + * Level rights config. + */ + private List levels; + + @Data + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class LevelCO { + + /** + * Level number. + */ + private Integer level; + + /** + * Level display name. + */ + private String levelName; + + /** + * Required intimacy value. + */ + private Long requiredIntimacyValue; + + /** + * Whether current relationship has unlocked this level. + */ + private Boolean unlocked; + + /** + * Rights under this level. + */ + private List rights; + } + + @Data + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class RightCO { + + /** + * Stable right key. + */ + private String rightKey; + + /** + * Right icon. + */ + private String icon; + + /** + * Right title. + */ + private String title; + + /** + * Right description. + */ + private String desc; + + /** + * Whether current relationship has unlocked this right. + */ + private Boolean unlocked; + } +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpUserProfileCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpUserProfileCO.java index babada43..b98ede6a 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpUserProfileCO.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/user/relation/cp/CpUserProfileCO.java @@ -26,10 +26,15 @@ public class CpUserProfileCO extends ClientObject { */ private UserProfileDTO userProfile; - /** - * 组建天数. - */ - @JsonSerialize(using = ToStringSerializer.class) + /** + * 关系类型:CP/BROTHER/SISTERS. + */ + private String relationType; + + /** + * 组建天数. + */ + @JsonSerialize(using = ToStringSerializer.class) private Long days; /** diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyCmd.java index 81af4428..229496af 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyCmd.java @@ -23,11 +23,15 @@ public class CpApplyCmd extends AppExtCommand { * * @eo.required */ - @NotNull(message = "acceptApplyUserId required.") - private Long acceptApplyUserId; - - - public String getAcceptApplyUserIdString() { + @NotNull(message = "acceptApplyUserId required.") + private Long acceptApplyUserId; + + /** + * 关系类型:CP/BROTHER/SISTERS,默认 CP. + */ + private String relationType; + + public String getAcceptApplyUserIdString() { return getAcceptApplyUserId().toString(); } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyDismissCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyDismissCmd.java index 7223e5b0..08969641 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyDismissCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyDismissCmd.java @@ -22,7 +22,12 @@ public class CpApplyDismissCmd extends AppExtCommand { /** * cp用户id */ - @NotNull - private Long cpUserId; - -} + @NotNull + private Long cpUserId; + + /** + * 关系类型:CP/BROTHER/SISTERS,默认 CP. + */ + private String relationType; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyIdQueryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyIdQueryCmd.java new file mode 100644 index 00000000..bcbdf9d2 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpApplyIdQueryCmd.java @@ -0,0 +1,18 @@ +package com.red.circle.other.app.dto.cmd.user.relation.cp; + +import com.red.circle.common.business.dto.cmd.UserIdCmd; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * CP apply id query. + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CpApplyIdQueryCmd extends UserIdCmd { + + /** + * 关系类型:CP/BROTHER/SISTERS,默认 CP. + */ + private String relationType; +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpRelationshipQueryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpRelationshipQueryCmd.java new file mode 100644 index 00000000..1f3e5355 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpRelationshipQueryCmd.java @@ -0,0 +1,20 @@ +package com.red.circle.other.app.dto.cmd.user.relation.cp; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * CP relationship query. + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +public class CpRelationshipQueryCmd extends AppExtCommand { + + /** + * 关系类型:CP/BROTHER/SISTERS,默认 CP. + */ + private String relationType; +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpRightsConfigQueryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpRightsConfigQueryCmd.java new file mode 100644 index 00000000..fa2d52c2 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/CpRightsConfigQueryCmd.java @@ -0,0 +1,26 @@ +package com.red.circle.other.app.dto.cmd.user.relation.cp; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.red.circle.framework.core.dto.AppCommand; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * CP rights config query. + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class CpRightsConfigQueryCmd extends AppCommand { + + /** + * Relationship type: CP/BROTHER/SISTERS, defaults to CP. + */ + private String relationType; + + /** + * Optional relationship user id. If absent, only config can be returned safely. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long cpUserId; +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/UserCpLightCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/UserCpLightCmd.java index a129961f..70b6eeee 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/UserCpLightCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/relation/cp/UserCpLightCmd.java @@ -26,7 +26,12 @@ public class UserCpLightCmd extends AppCommand { /** * 点亮类型.APPOINT指定礼物,SPECIAL特效礼物 */ - @NotNull(message = "type required.") - private String type; - -} + @NotNull(message = "type required.") + private String type; + + /** + * 关系类型:CP/BROTHER/SISTERS,默认 CP. + */ + private String relationType; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserCpBlessRecordQueryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserCpBlessRecordQueryCmd.java index 1293d46d..146014a4 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserCpBlessRecordQueryCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserCpBlessRecordQueryCmd.java @@ -20,5 +20,10 @@ public class UserCpBlessRecordQueryCmd extends AppCommand { /** * 最后一条记录id. */ - private Long lastId; -} + private Long lastId; + + /** + * 关系类型:CP/BROTHER/SISTERS,默认 CP. + */ + private String relationType; +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserCpCabinQueryCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserCpCabinQueryCmd.java new file mode 100644 index 00000000..88e1a9d5 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserCpCabinQueryCmd.java @@ -0,0 +1,18 @@ +package com.red.circle.other.app.dto.cmd.user.user; + +import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * CP cabin query. + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class UserCpCabinQueryCmd extends UserIdCommonCmd { + + /** + * 关系类型:CP/BROTHER/SISTERS,默认 CP. + */ + private String relationType; +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java index 5d6b6ca3..fd2d7453 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/relation/UserCpRelationService.java @@ -1,14 +1,15 @@ package com.red.circle.other.app.service.user.relation; -import com.red.circle.common.business.dto.cmd.AppExtCommand; -import com.red.circle.common.business.dto.cmd.UserIdCmd; -import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; -import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpCabinUserProfileCO; -import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; -import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileCO; -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.common.business.dto.cmd.UserIdCmd; +import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpCabinUserProfileCO; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpPairUserProfileCO; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyIdQueryCmd; +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.CpRelationshipQueryCmd; +import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.loveletter.SendLoveLetterCmd; import java.util.List; @@ -22,7 +23,7 @@ public interface UserCpRelationService { CpUserProfileCO getCpUser(UserIdCmd cmd); - List getCpPairUserProfileCO(AppExtCommand cmd); + List getCpPairUserProfileCO(CpRelationshipQueryCmd cmd); void sendApply(CpApplyCmd cmd); @@ -30,7 +31,7 @@ public interface UserCpRelationService { void dismissApply(CpApplyDismissCmd cmd); - String getCpApplyId(UserIdCmd cmd); + String getCpApplyId(CpApplyIdQueryCmd cmd); CpCabinUserProfileCO getCpUserV4(UserIdCommonCmd cmd); diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/user/UserCpCabinService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/user/UserCpCabinService.java index d1c8e8f1..d74cca78 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/user/UserCpCabinService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/user/UserCpCabinService.java @@ -1,13 +1,15 @@ package com.red.circle.other.app.service.user.user; -import com.red.circle.common.business.dto.cmd.UserIdCommonCmd; -import com.red.circle.other.app.dto.clientobject.user.user.CpBlessRecordCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinUnreadCO; -import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinValueCO; -import com.red.circle.other.app.dto.cmd.user.user.UserCpBlessRecordQueryCmd; -import java.util.List; +import com.red.circle.other.app.dto.clientobject.user.user.CpBlessRecordCO; +import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpRightsConfigCO; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinCO; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinUnreadCO; +import com.red.circle.other.app.dto.clientobject.user.user.UserCpCabinValueCO; +import com.red.circle.other.app.dto.cmd.user.relation.cp.CpRightsConfigQueryCmd; +import com.red.circle.other.app.dto.cmd.user.user.UserCpBlessRecordQueryCmd; +import com.red.circle.other.app.dto.cmd.user.user.UserCpCabinQueryCmd; +import java.util.List; /** * CP(小屋、祝福)相关 @@ -15,11 +17,13 @@ import java.util.List; */ public interface UserCpCabinService { - UserCpCabinCO getCpCabinInfo(UserIdCommonCmd cmd); - - UserCpCabinValueCO getCpCabinValue(UserIdCommonCmd cmd); - - UserCpCabinUnreadCO getCpBlessRecordAndUpRead(UserIdCommonCmd cmd); - - List pageCpBlessRecord(UserCpBlessRecordQueryCmd cmd); -} + UserCpCabinCO getCpCabinInfo(UserCpCabinQueryCmd cmd); + + UserCpCabinValueCO getCpCabinValue(UserCpCabinQueryCmd cmd); + + UserCpCabinUnreadCO getCpBlessRecordAndUpRead(UserCpCabinQueryCmd cmd); + + List pageCpBlessRecord(UserCpBlessRecordQueryCmd cmd); + + CpRightsConfigCO getCpRightsConfig(CpRightsConfigQueryCmd cmd); +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/cp/impl/CpRelationshipCacheServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/cp/impl/CpRelationshipCacheServiceImpl.java index a108fed1..724dc9e5 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/cp/impl/CpRelationshipCacheServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/cache/service/cp/impl/CpRelationshipCacheServiceImpl.java @@ -5,11 +5,12 @@ import com.red.circle.component.redis.service.RedisService; import com.red.circle.other.infra.database.cache.key.user.UserKey; import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService; import com.red.circle.other.infra.database.rds.entity.user.user.BaseInfo; -import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; -import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService; -import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; -import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; -import com.red.circle.other.inner.model.dto.user.CpSimpleUserProfileCO; +import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship; +import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService; +import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; +import com.red.circle.other.infra.database.rds.service.user.user.CpValueService; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; +import com.red.circle.other.inner.model.dto.user.CpSimpleUserProfileCO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.DateUtils; import lombok.RequiredArgsConstructor; @@ -80,16 +81,17 @@ public class CpRelationshipCacheServiceImpl implements CpRelationshipCacheServic } BigDecimal cpValue = cpValueMap.getOrDefault(cpRelationship.getCpValId(), BigDecimal.ZERO); - Long days = DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now()); + Long days = relationshipDays(cpRelationship.getCreateTime()); String firstDay = cpRelationship.getCreateTime().toInstant() .atZone(ZoneId.systemDefault()).toLocalDate().toString(); return new CpSimpleUserProfileCO() - .setMeUserId(baseInfo.getId()) - .setMeAccount(baseInfo.getAccount()) - .setMeUserAvatar(baseInfo.getUserAvatar()) - .setMeUserNickname(baseInfo.getUserNickname()) - .setCpUserId(cpUser.getId()) + .setMeUserId(baseInfo.getId()) + .setMeAccount(baseInfo.getAccount()) + .setMeUserAvatar(baseInfo.getUserAvatar()) + .setMeUserNickname(baseInfo.getUserNickname()) + .setRelationType(CpRelationshipType.normalize(cpRelationship.getRelationType())) + .setCpUserId(cpUser.getId()) .setCpAccount(cpUser.getAccount()) .setCpUserAvatar(cpUser.getUserAvatar()) .setCpUserNickname(cpUser.getUserNickname()) @@ -113,12 +115,20 @@ public class CpRelationshipCacheServiceImpl implements CpRelationshipCacheServic return Collections.emptyList(); } - private static String getKey(Long userId) { - return UserKey.CP.getKey(userId); - } - - @Override - public void remove(List userIds) { + private static String getKey(Long userId) { + return UserKey.CP.getKey(userId); + } + + private static long relationshipDays(Date createTime) { + Date now = DateUtils.now(); + if (!createTime.before(now)) { + return 0L; + } + return DateUtils.toDurationDays(createTime, now); + } + + @Override + public void remove(List userIds) { userIds.forEach(userId -> { redisService.delete(getKey(userId)); }); diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/user/user/CpApply.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/user/user/CpApply.java index ce0d894f..711226cc 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/user/user/CpApply.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/user/user/CpApply.java @@ -40,16 +40,22 @@ public class CpApply extends TimestampBaseEntity { @TableField("send_apply_user_id") private Long sendApplyUserId; - /** - * 接收申请用户. - */ - @TableField("accept_apply_user_id") - private Long acceptApplyUserId; - - /** - * 申请消费金币. - */ - @TableField("apply_consume_gold") + /** + * 接收申请用户. + */ + @TableField("accept_apply_user_id") + private Long acceptApplyUserId; + + /** + * 关系类型:CP/BROTHER/SISTERS. + */ + @TableField("relation_type") + private String relationType; + + /** + * 申请消费金币. + */ + @TableField("apply_consume_gold") private BigDecimal applyConsumeGold; /** diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/user/user/CpRelationship.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/user/user/CpRelationship.java index 4521f9cf..82be24b6 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/user/user/CpRelationship.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/user/user/CpRelationship.java @@ -55,12 +55,18 @@ public class CpRelationship extends TimestampBaseEntity { /** * cp用户id. */ - @TableField("cp_user_id") - private Long cpUserId; - - /** - * 0.发起人 1.接收人 - */ + @TableField("cp_user_id") + private Long cpUserId; + + /** + * 关系类型:CP/BROTHER/SISTERS. + */ + @TableField("relation_type") + private String relationType; + + /** + * 0.发起人 1.接收人 + */ @TableField("is_initiate") private Integer initiate; diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpApplyService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpApplyService.java index ffdc213e..6c528fa2 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpApplyService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpApplyService.java @@ -18,11 +18,16 @@ import java.util.List; */ public interface CpApplyService extends BaseService { - /** - * 解散cp. - */ - void dismiss(Long requestUserId); - + /** + * 解散cp. + */ + void dismiss(Long requestUserId); + + /** + * 解散指定类型关系申请. + */ + void dismiss(Long requestUserId, String relationType); + /** * 获取申请记录. * @@ -30,7 +35,12 @@ public interface CpApplyService extends BaseService { * @param sendApplyUserId 发送人 * @return 申请记录ID. */ - Long getId(Long acceptApplyUserId, Long sendApplyUserId); + Long getId(Long acceptApplyUserId, Long sendApplyUserId); + + /** + * 获取指定类型申请记录. + */ + Long getId(Long acceptApplyUserId, Long sendApplyUserId, String relationType); /** * 申请记录是否存在. @@ -39,7 +49,12 @@ public interface CpApplyService extends BaseService { * @param sendApplyUserId 发送人 * @return true 存在,false 不存在 */ - boolean exists(Long acceptApplyUserId, Long sendApplyUserId); + boolean exists(Long acceptApplyUserId, Long sendApplyUserId); + + /** + * 指定类型申请记录是否存在. + */ + boolean exists(Long acceptApplyUserId, Long sendApplyUserId, String relationType); /** * 是否存在发送记录. @@ -47,7 +62,12 @@ public interface CpApplyService extends BaseService { * @param sendApplyUserId 发送人 * @return true 存在,false 不存在 */ - boolean existsNotProcessSendApply(Long sendApplyUserId); + boolean existsNotProcessSendApply(Long sendApplyUserId); + + /** + * 是否存在指定类型发送记录. + */ + boolean existsNotProcessSendApply(Long sendApplyUserId, String relationType); /** * 改变状态同意. @@ -63,7 +83,12 @@ public interface CpApplyService extends BaseService { * * @param acceptApplyUserId 接收用户 */ - void refuseStatusWait(Long acceptApplyUserId); + void refuseStatusWait(Long acceptApplyUserId); + + /** + * 拒绝指定类型所有等待状态. + */ + void refuseStatusWait(Long acceptApplyUserId, String relationType); /** * 获取我拒绝都信息. diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpRelationshipService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpRelationshipService.java index 605296c2..c4083450 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpRelationshipService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/CpRelationshipService.java @@ -26,16 +26,26 @@ public interface CpRelationshipService extends BaseService { */ List listLatestCp(String sysOrigin, Set excludeUserId, Integer size); - /** - * 是否互为cp. - */ - boolean existsCp(Long userId, Long cpUserId); - + /** + * 是否互为cp. + */ + boolean existsCp(Long userId, Long cpUserId); + + /** + * 是否存在指定类型关系. + */ + boolean existsCp(Long userId, Long cpUserId, String relationType); + /** * 获取分手中的cp信息集合 */ - List getDismissingByUserId(Long userId); - + List getDismissingByUserId(Long userId); + + /** + * 获取指定类型分手中的cp信息集合. + */ + List getDismissingByUserId(Long userId, String relationType); + /** * 获取cp用户id. * @@ -47,13 +57,23 @@ public interface CpRelationshipService extends BaseService { /** * 获取cp信息集合 */ - List getByUserId(Long userId); - + List getByUserId(Long userId); + + /** + * 获取指定类型cp信息集合. + */ + List getByUserId(Long userId, String relationType); + /** * 获取cp信息. */ - CpRelationship getByUserId(Long userId, Long cpUserId); - + CpRelationship getByUserId(Long userId, Long cpUserId); + + /** + * 获取指定类型cp信息. + */ + CpRelationship getByUserId(Long userId, Long cpUserId, String relationType); + /** * 获取cpValId * @@ -75,7 +95,13 @@ public interface CpRelationshipService extends BaseService { * @param bindCpValId cp值id * @param sysOrigin 系统 */ - void addCp(Long sendApplyUserId, Long acceptApplyUserId, Long bindCpValId, String sysOrigin); + void addCp(Long sendApplyUserId, Long acceptApplyUserId, Long bindCpValId, String sysOrigin); + + /** + * 组建指定类型关系. + */ + void addCp(Long sendApplyUserId, Long acceptApplyUserId, Long bindCpValId, String sysOrigin, + String relationType); /** * 获取cp信息. @@ -90,7 +116,12 @@ public interface CpRelationshipService extends BaseService { * @param userId 用户id * @return */ - CpRelationship getByUserIdOrCpUserId(Long userId); + CpRelationship getByUserIdOrCpUserId(Long userId); + + /** + * 按关系类型获取任一用户关联关系. + */ + CpRelationship getByUserIdOrCpUserId(Long userId, String relationType); /** * 获取用户正常CP数量. @@ -107,14 +138,24 @@ public interface CpRelationshipService extends BaseService { * @param cpUserId cp用户id * @return CP关系 */ - CpRelationship getDismissingCp(Long userId, Long cpUserId); - + CpRelationship getDismissingCp(Long userId, Long cpUserId); + + /** + * 获取指定类型分手中的关系. + */ + CpRelationship getDismissingCp(Long userId, Long cpUserId, String relationType); + /** * 更新CP关系为分手中. * * @param userId 用户id */ - void updateToDismissing(Long userId, Long cpUserId); + void updateToDismissing(Long userId, Long cpUserId); + + /** + * 更新指定类型关系为分手中. + */ + void updateToDismissing(Long userId, Long cpUserId, String relationType); /** * 复合CP(更新为正常状态). @@ -122,7 +163,12 @@ public interface CpRelationshipService extends BaseService { * @param userId 用户id * @param cpUserId cp用户id */ - void reconcile(Long userId, Long cpUserId); + void reconcile(Long userId, Long cpUserId); + + /** + * 复合指定类型关系. + */ + void reconcile(Long userId, Long cpUserId, String relationType); /** * 获取7天前分手中的CP关系列表. diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpApplyServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpApplyServiceImpl.java index ac0f5510..a793fa43 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpApplyServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpApplyServiceImpl.java @@ -6,9 +6,10 @@ import com.red.circle.framework.mybatis.constant.PageConstant; import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl; import com.red.circle.tool.core.text.StringUtils; import com.red.circle.other.infra.database.rds.dao.user.user.CpApplyDAO; -import com.red.circle.other.infra.database.rds.entity.user.user.CpApply; -import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; -import com.red.circle.other.infra.enums.user.user.CpApplyStatus; +import com.red.circle.other.infra.database.rds.entity.user.user.CpApply; +import com.red.circle.other.infra.database.rds.service.user.user.CpApplyService; +import com.red.circle.other.infra.enums.user.user.CpApplyStatus; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import com.red.circle.other.inner.model.cmd.user.CpApplyQryCmd; import java.time.LocalDateTime; import java.util.List; @@ -28,44 +29,67 @@ import org.springframework.stereotype.Service; public class CpApplyServiceImpl extends BaseServiceImpl implements CpApplyService { - @Override - public void dismiss(Long requestUserId) { - update() - .set(CpApply::getStatus, CpApplyStatus.DISMISS) - .set(CpApply::getUpdateTime, LocalDateTime.now()) - .set(CpApply::getUpdateUser, requestUserId) - .eq(CpApply::getStatus, CpApplyStatus.AGREE) - .and(where -> where.eq(CpApply::getSendApplyUserId, requestUserId) + @Override + public void dismiss(Long requestUserId) { + dismiss(requestUserId, CpRelationshipType.CP.name()); + } + + @Override + public void dismiss(Long requestUserId, String relationType) { + update() + .set(CpApply::getStatus, CpApplyStatus.DISMISS) + .set(CpApply::getUpdateTime, LocalDateTime.now()) + .set(CpApply::getUpdateUser, requestUserId) + .eq(CpApply::getRelationType, CpRelationshipType.normalize(relationType)) + .eq(CpApply::getStatus, CpApplyStatus.AGREE) + .and(where -> where.eq(CpApply::getSendApplyUserId, requestUserId) .or().eq(CpApply::getAcceptApplyUserId, requestUserId)) .last(PageConstant.LIMIT_ONE) .execute(); } - @Override - public Long getId(Long acceptApplyUserId, Long sendApplyUserId) { - return Optional.ofNullable( - query() - .select(CpApply::getId) - .eq(CpApply::getStatus, CpApplyStatus.WAIT) - .eq(CpApply::getAcceptApplyUserId, acceptApplyUserId) - .eq(CpApply::getSendApplyUserId, sendApplyUserId) + @Override + public Long getId(Long acceptApplyUserId, Long sendApplyUserId) { + return getId(acceptApplyUserId, sendApplyUserId, CpRelationshipType.CP.name()); + } + + @Override + public Long getId(Long acceptApplyUserId, Long sendApplyUserId, String relationType) { + return Optional.ofNullable( + query() + .select(CpApply::getId) + .eq(CpApply::getStatus, CpApplyStatus.WAIT) + .eq(CpApply::getRelationType, CpRelationshipType.normalize(relationType)) + .eq(CpApply::getAcceptApplyUserId, acceptApplyUserId) + .eq(CpApply::getSendApplyUserId, sendApplyUserId) .last(PageConstant.LIMIT_ONE) .getOne() ).map(CpApply::getId).orElse(null); } - @Override - public boolean exists(Long acceptApplyUserId, Long sendApplyUserId) { - return Optional.ofNullable(getId(acceptApplyUserId, sendApplyUserId)).isPresent(); - } - - @Override - public boolean existsNotProcessSendApply(Long sendApplyUserId) { - return Optional.ofNullable(query() - .select(CpApply::getId) - .eq(CpApply::getSendApplyUserId, sendApplyUserId) - .eq(CpApply::getStatus, CpApplyStatus.WAIT) - .getOne()) + @Override + public boolean exists(Long acceptApplyUserId, Long sendApplyUserId) { + return exists(acceptApplyUserId, sendApplyUserId, CpRelationshipType.CP.name()); + } + + @Override + public boolean exists(Long acceptApplyUserId, Long sendApplyUserId, String relationType) { + return Optional.ofNullable(getId(acceptApplyUserId, sendApplyUserId, relationType)).isPresent(); + } + + @Override + public boolean existsNotProcessSendApply(Long sendApplyUserId) { + return existsNotProcessSendApply(sendApplyUserId, CpRelationshipType.CP.name()); + } + + @Override + public boolean existsNotProcessSendApply(Long sendApplyUserId, String relationType) { + return Optional.ofNullable(query() + .select(CpApply::getId) + .eq(CpApply::getSendApplyUserId, sendApplyUserId) + .eq(CpApply::getRelationType, CpRelationshipType.normalize(relationType)) + .eq(CpApply::getStatus, CpApplyStatus.WAIT) + .getOne()) .map(cpApply -> Objects.nonNull(cpApply.getId())) .orElse(Boolean.FALSE); } @@ -78,13 +102,19 @@ public class CpApplyServiceImpl extends BaseServiceImpl imp .execute(); } - @Override - public void refuseStatusWait(Long acceptApplyUserId) { - update() - .set(CpApply::getStatus, CpApplyStatus.REFUSE) - .eq(CpApply::getStatus, CpApplyStatus.WAIT) - .eq(CpApply::getAcceptApplyUserId, acceptApplyUserId) - .execute(); + @Override + public void refuseStatusWait(Long acceptApplyUserId) { + refuseStatusWait(acceptApplyUserId, CpRelationshipType.CP.name()); + } + + @Override + public void refuseStatusWait(Long acceptApplyUserId, String relationType) { + update() + .set(CpApply::getStatus, CpApplyStatus.REFUSE) + .eq(CpApply::getStatus, CpApplyStatus.WAIT) + .eq(CpApply::getRelationType, CpRelationshipType.normalize(relationType)) + .eq(CpApply::getAcceptApplyUserId, acceptApplyUserId) + .execute(); } @Override diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java index 42541ac6..7056b63b 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/user/user/impl/CpRelationshipServiceImpl.java @@ -7,9 +7,10 @@ import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.LocalDateUtils; import com.red.circle.other.infra.database.rds.dao.user.user.CpRelationshipDAO; -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.infra.enums.user.user.CpRelationshipStatus; +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.infra.enums.user.user.CpRelationshipStatus; +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; import java.math.BigDecimal; import java.sql.Timestamp; import java.util.*; @@ -45,14 +46,20 @@ public class CpRelationshipServiceImpl extends } - @Override - public boolean existsCp(Long userId, Long cpUserId) { - return Optional.ofNullable( - query().select(CpRelationship::getId) - .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) - .and(where -> where - .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) - .or() + @Override + public boolean existsCp(Long userId, Long cpUserId) { + return existsCp(userId, cpUserId, CpRelationshipType.CP.name()); + } + + @Override + public boolean existsCp(Long userId, Long cpUserId, String relationType) { + return Optional.ofNullable( + query().select(CpRelationship::getId) + .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) + .eq(CpRelationship::getRelationType, CpRelationshipType.normalize(relationType)) + .and(where -> where + .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) + .or() .nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId)) ) .last(PageConstant.LIMIT_ONE) @@ -60,41 +67,61 @@ public class CpRelationshipServiceImpl extends ).map(cpRelationship -> Objects.nonNull(cpRelationship.getId())).orElse(Boolean.FALSE); } - @Override - public List getDismissingByUserId(Long userId) { - return query() - .eq(CpRelationship::getUserId, userId) - .eq(CpRelationship::getStatus, CpRelationshipStatus.DISMISSING.name()) - .list(); - } + @Override + public List getDismissingByUserId(Long userId) { + return getDismissingByUserId(userId, CpRelationshipType.CP.name()); + } + + @Override + public List getDismissingByUserId(Long userId, String relationType) { + return query() + .eq(CpRelationship::getUserId, userId) + .eq(CpRelationship::getStatus, CpRelationshipStatus.DISMISSING.name()) + .eq(CpRelationship::getRelationType, CpRelationshipType.normalize(relationType)) + .list(); + } - @Override - public List getCpUserId(Long userId) { - return query().select(CpRelationship::getCpUserId, TimestampBaseEntity::getCreateTime) - .eq(CpRelationship::getUserId, userId) - .list() + @Override + public List getCpUserId(Long userId) { + return query().select(CpRelationship::getCpUserId, TimestampBaseEntity::getCreateTime) + .eq(CpRelationship::getUserId, userId) + .eq(CpRelationship::getRelationType, CpRelationshipType.CP.name()) + .list() .stream() .sorted(Comparator.comparing(CpRelationship::getCreateTime).reversed()) .map(CpRelationship::getCpUserId) .toList(); } - @Override - public List getByUserId(Long userId) { - return query() - .eq(CpRelationship::getUserId, userId) - .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) - .orderByAsc(TimestampBaseEntity::getCreateTime) - .list(); - } - - @Override - public CpRelationship getByUserId(Long userId, Long cpUserId) { - return query() - .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) - .and(where -> where - .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) - .or() + @Override + public List getByUserId(Long userId) { + return getByUserId(userId, CpRelationshipType.CP.name()); + } + + @Override + public List getByUserId(Long userId, String relationType) { + return query() + .eq(CpRelationship::getUserId, userId) + .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) + .eq(Objects.nonNull(relationType), CpRelationship::getRelationType, + Objects.nonNull(relationType) ? CpRelationshipType.normalize(relationType) : null) + .orderByAsc(TimestampBaseEntity::getCreateTime) + .list(); + } + + @Override + public CpRelationship getByUserId(Long userId, Long cpUserId) { + return getByUserId(userId, cpUserId, CpRelationshipType.CP.name()); + } + + @Override + public CpRelationship getByUserId(Long userId, Long cpUserId, String relationType) { + return query() + .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) + .eq(CpRelationship::getRelationType, CpRelationshipType.normalize(relationType)) + .and(where -> where + .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) + .or() .nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId)) ) .last(PageConstant.LIMIT_ONE) @@ -116,15 +143,21 @@ public class CpRelationshipServiceImpl extends removeById(id); } - @Override - public void addCp(Long sendApplyUserId, Long acceptApplyUserId, Long bindCpValId, - String sysOrigin) { - CpRelationship sendUser = createCpRelationshipBean(sendApplyUserId, acceptApplyUserId, - bindCpValId, 0, sysOrigin); - CpRelationship cpUser = createCpRelationshipBean(acceptApplyUserId, sendApplyUserId, - bindCpValId, 1, sysOrigin); - saveBatch(Arrays.asList(sendUser, cpUser)); - } + @Override + public void addCp(Long sendApplyUserId, Long acceptApplyUserId, Long bindCpValId, + String sysOrigin) { + addCp(sendApplyUserId, acceptApplyUserId, bindCpValId, sysOrigin, CpRelationshipType.CP.name()); + } + + @Override + public void addCp(Long sendApplyUserId, Long acceptApplyUserId, Long bindCpValId, + String sysOrigin, String relationType) { + CpRelationship sendUser = createCpRelationshipBean(sendApplyUserId, acceptApplyUserId, + bindCpValId, 0, sysOrigin, relationType); + CpRelationship cpUser = createCpRelationshipBean(acceptApplyUserId, sendApplyUserId, + bindCpValId, 1, sysOrigin, relationType); + saveBatch(Arrays.asList(sendUser, cpUser)); + } @Override public void updateAccountByUserId(Long userId, BigDecimal account) { @@ -134,24 +167,32 @@ public class CpRelationshipServiceImpl extends } - @Override - public CpRelationship getByUserIdOrCpUserId(Long userId) { - return Optional.ofNullable(query() - .and(where -> where.eq(CpRelationship::getUserId, userId) - .or().eq(CpRelationship::getCpUserId, userId)) - .last(PageConstant.LIMIT_ONE) + @Override + public CpRelationship getByUserIdOrCpUserId(Long userId) { + return getByUserIdOrCpUserId(userId, CpRelationshipType.CP.name()); + } + + @Override + public CpRelationship getByUserIdOrCpUserId(Long userId, String relationType) { + return Optional.ofNullable(query() + .eq(Objects.nonNull(relationType), CpRelationship::getRelationType, + Objects.nonNull(relationType) ? CpRelationshipType.normalize(relationType) : null) + .and(where -> where.eq(CpRelationship::getUserId, userId) + .or().eq(CpRelationship::getCpUserId, userId)) + .last(PageConstant.LIMIT_ONE) .getOne() ).orElse(null); } - private CpRelationship createCpRelationshipBean(Long userId, Long cpUserId, Long bindCpValId, - Integer initiate, String sysOrigin) { - CpRelationship cpUser = new CpRelationship() - .setUserId(userId) - .setCpUserId(cpUserId) - .setCpValId(bindCpValId) - .setInitiate(initiate) - .setSysOrigin(sysOrigin) + private CpRelationship createCpRelationshipBean(Long userId, Long cpUserId, Long bindCpValId, + Integer initiate, String sysOrigin, String relationType) { + CpRelationship cpUser = new CpRelationship() + .setUserId(userId) + .setCpUserId(cpUserId) + .setCpValId(bindCpValId) + .setRelationType(CpRelationshipType.normalize(relationType)) + .setInitiate(initiate) + .setSysOrigin(sysOrigin) .setAmount(BigDecimal.ZERO) .setStatus(CpRelationshipStatus.NORMAL.name()) .setDismissTime(null); @@ -167,41 +208,59 @@ public class CpRelationshipServiceImpl extends .count()); } - @Override - public CpRelationship getDismissingCp(Long userId, Long cpUserId) { - return query() - .and(where -> where - .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) - .or() - .nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId)) - ) - .eq(CpRelationship::getStatus, CpRelationshipStatus.DISMISSING.name()) - .last(PageConstant.LIMIT_ONE) - .getOne(); - } - - @Override - public void updateToDismissing(Long userId, Long cpUserId) { - update() - .set(CpRelationship::getStatus, CpRelationshipStatus.DISMISSING.name()) - .set(CpRelationship::getDismissTime, TimestampUtils.now().getTime()) - .set(CpRelationship::getUpdateTime, TimestampUtils.now()) - .and(where -> where - .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) - .or() + @Override + public CpRelationship getDismissingCp(Long userId, Long cpUserId) { + return getDismissingCp(userId, cpUserId, CpRelationshipType.CP.name()); + } + + @Override + public CpRelationship getDismissingCp(Long userId, Long cpUserId, String relationType) { + return query() + .and(where -> where + .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) + .or() + .nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId)) + ) + .eq(CpRelationship::getStatus, CpRelationshipStatus.DISMISSING.name()) + .eq(CpRelationship::getRelationType, CpRelationshipType.normalize(relationType)) + .last(PageConstant.LIMIT_ONE) + .getOne(); + } + + @Override + public void updateToDismissing(Long userId, Long cpUserId) { + updateToDismissing(userId, cpUserId, CpRelationshipType.CP.name()); + } + + @Override + public void updateToDismissing(Long userId, Long cpUserId, String relationType) { + update() + .set(CpRelationship::getStatus, CpRelationshipStatus.DISMISSING.name()) + .set(CpRelationship::getDismissTime, TimestampUtils.now().getTime()) + .set(CpRelationship::getUpdateTime, TimestampUtils.now()) + .eq(CpRelationship::getRelationType, CpRelationshipType.normalize(relationType)) + .and(where -> where + .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) + .or() .nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId)) ) .eq(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) .execute(); } - @Override - public void reconcile(Long userId, Long cpUserId) { - update() - .set(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) - .set(CpRelationship::getDismissTime, null) - .set(CpRelationship::getUpdateTime, TimestampUtils.now()) - .and(where -> where + @Override + public void reconcile(Long userId, Long cpUserId) { + reconcile(userId, cpUserId, CpRelationshipType.CP.name()); + } + + @Override + public void reconcile(Long userId, Long cpUserId, String relationType) { + update() + .set(CpRelationship::getStatus, CpRelationshipStatus.NORMAL.name()) + .set(CpRelationship::getDismissTime, null) + .set(CpRelationship::getUpdateTime, TimestampUtils.now()) + .eq(CpRelationship::getRelationType, CpRelationshipType.normalize(relationType)) + .and(where -> where .nested(w -> w.eq(CpRelationship::getUserId, userId).eq(CpRelationship::getCpUserId, cpUserId)) .or() .nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId)) diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/enums/user/user/CpRelationshipType.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/enums/user/user/CpRelationshipType.java new file mode 100644 index 00000000..822a24f5 --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/enums/user/user/CpRelationshipType.java @@ -0,0 +1,63 @@ +package com.red.circle.other.infra.enums.user.user; + +import java.util.Locale; +import java.util.Objects; +import org.apache.commons.lang3.StringUtils; + +/** + * CP family relationship type. + */ +public enum CpRelationshipType { + + /** + * Couple, requires different genders. + */ + CP, + + /** + * Brothers, requires both users to be male. + */ + BROTHER, + + /** + * Sisters, requires both users to be female. + */ + SISTERS; + + private static final int FEMALE = 0; + private static final int MALE = 1; + + public static CpRelationshipType of(String value) { + if (StringUtils.isBlank(value)) { + return CP; + } + String normalized = value.trim().toUpperCase(Locale.ROOT); + if (Objects.equals(normalized, "BROTHERS")) { + return BROTHER; + } + if (Objects.equals(normalized, "SISTER")) { + return SISTERS; + } + return CpRelationshipType.valueOf(normalized); + } + + public static String normalize(String value) { + return of(value).name(); + } + + public boolean genderMatched(Integer sendUserSex, Integer acceptUserSex) { + return switch (this) { + case CP -> !Objects.equals(sendUserSex, acceptUserSex); + case BROTHER -> Objects.equals(sendUserSex, MALE) && Objects.equals(acceptUserSex, MALE); + case SISTERS -> Objects.equals(sendUserSex, FEMALE) && Objects.equals(acceptUserSex, FEMALE); + }; + } + + public String applyTargetText() { + return switch (this) { + case CP -> "a couple"; + case BROTHER -> "brothers"; + case SISTERS -> "sisters"; + }; + } +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/user/user/CpRelationshipDAO.xml b/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/user/user/CpRelationshipDAO.xml index 672d7413..63ff5256 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/user/user/CpRelationshipDAO.xml +++ b/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/user/user/CpRelationshipDAO.xml @@ -9,10 +9,11 @@ FROM `user_cp_relationship` WHERE `cp_val_id` IN (SELECT vId FROM (SELECT DISTINCT(`cp_val_id`) vId - FROM `user_cp_relationship` - WHERE `sys_origin` = #{sysOrigin} - ORDER BY id DESC - LIMIT #{size}) tmp) + FROM `user_cp_relationship` + WHERE `sys_origin` = #{sysOrigin} + AND `relation_type` = 'CP' + ORDER BY id DESC + LIMIT #{size}) tmp)