From a0461ce68c6069f81e6b47a3a1c5962854b894f6 Mon Sep 17 00:00:00 2001 From: hy001 Date: Fri, 22 May 2026 19:17:41 +0800 Subject: [PATCH] =?UTF-8?q?CP=E5=85=B3=E7=B3=BB=E8=A7=A3=E7=BB=91=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E9=87=91=E5=B8=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inner/enums/config/EnumConfigKey.java | 33 +++-- .../wallet/inner/model/enums/GoldOrigin.java | 23 ++-- .../ResidentCpActivityServiceImpl.java | 120 ++++++++++++++++++ .../app/sys/SysEnumConfigServiceImpl.java | 21 +-- .../app/activity/cp/ResidentCpConfigCO.java | 7 + .../activity/cp/ResidentCpConfigSaveCmd.java | 6 + .../service/app/sys/SysEnumConfigService.java | 8 +- .../command/user/DismissCpApplyCmdExe.java | 79 ++++++++++-- .../query/UserCpRightsConfigQueryExe.java | 9 ++ .../app/common/cp/CpRelationGoldConfig.java | 32 +++++ .../user/DismissCpApplyCmdExeTest.java | 24 +++- .../user/relation/cp/CpRightsConfigCO.java | 5 + .../database/rds/enums/OtherConfigEnum.java | 33 +++-- 13 files changed, 350 insertions(+), 50 deletions(-) create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/cp/CpRelationGoldConfig.java diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/config/EnumConfigKey.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/config/EnumConfigKey.java index 71e48afa..f22e5942 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/config/EnumConfigKey.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/config/EnumConfigKey.java @@ -217,15 +217,30 @@ public enum EnumConfigKey { */ YAHLLA_GIFT_GOLD_RATIO_SELF, - /** - * cp价格. - */ - CP_PRICE, - - /** - * Aswat 超级管理员ID. - */ - ASWAT_ADMINS, + /** + * cp价格. + */ + CP_PRICE, + + /** + * CP 关系解绑金币. + */ + CP_DISMISS_CONSUME_GOLD, + + /** + * Brother 关系解绑金币. + */ + BROTHER_DISMISS_CONSUME_GOLD, + + /** + * Sisters 关系解绑金币. + */ + SISTERS_DISMISS_CONSUME_GOLD, + + /** + * Aswat 超级管理员ID. + */ + ASWAT_ADMINS, /** * boos位置起步金额. diff --git a/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/GoldOrigin.java b/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/GoldOrigin.java index b4d26628..ed431e6d 100644 --- a/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/GoldOrigin.java +++ b/rc-service/rc-inner-api/wallet-inner/wallet-inner-model/src/main/java/com/red/circle/wallet/inner/model/enums/GoldOrigin.java @@ -750,15 +750,20 @@ public enum GoldOrigin { */ USER_RED_PACKET("User red packet"), - /** - * CP告白信封 - */ - CP_LOVE_LETTER("CP love letter"), - - /** - * cp榜单(周榜和季度榜) - */ - CP_RANKING_REWARD("CP ranking reward"), + /** + * CP告白信封 + */ + CP_LOVE_LETTER("CP love letter"), + + /** + * 解除 CP/Brother/Sisters 关系. + */ + CP_DISMISS("CP dismiss"), + + /** + * cp榜单(周榜和季度榜) + */ + CP_RANKING_REWARD("CP ranking reward"), /** * 签到付费 diff --git a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/activity/ResidentCpActivityServiceImpl.java b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/activity/ResidentCpActivityServiceImpl.java index 47895830..7e9c6cd0 100644 --- a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/activity/ResidentCpActivityServiceImpl.java +++ b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/activity/ResidentCpActivityServiceImpl.java @@ -5,15 +5,20 @@ import com.red.circle.console.app.dto.clienobject.app.activity.cp.ResidentCpLeve import com.red.circle.console.app.dto.cmd.app.activity.cp.ResidentCpConfigSaveCmd; import com.red.circle.console.app.dto.cmd.app.activity.cp.ResidentCpLevelConfigSaveCmd; import com.red.circle.console.app.service.app.sys.CpCabinConfigService; +import com.red.circle.console.app.service.app.sys.SysEnumConfigService; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.ResponseErrorCode; import com.red.circle.framework.dto.PageQuery; import com.red.circle.framework.dto.PageResult; +import com.red.circle.other.inner.enums.config.EnumConfigKey; import com.red.circle.other.inner.model.cmd.sys.SysCpCabinConfigQryCmd; +import com.red.circle.other.inner.model.dto.sys.EnumConfigDTO; import com.red.circle.other.inner.model.dto.sys.SysCpCabinConfigDTO; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -34,8 +39,14 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService private static final int CP_LEVEL_COUNT = 5; private static final int QUERY_LIMIT = 50; + private static final String CONFIG_GROUP_NAME = "CP"; + private static final String CONFIG_DATA_TYPE = "int"; + private static final String RELATION_TYPE_CP = "CP"; + private static final String RELATION_TYPE_BROTHER = "BROTHER"; + private static final String RELATION_TYPE_SISTERS = "SISTERS"; private final CpCabinConfigService cpCabinConfigService; + private final SysEnumConfigService sysEnumConfigService; @Override public ResidentCpConfigCO getConfig(String sysOrigin) { @@ -49,6 +60,7 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService return new ResidentCpConfigCO() .setConfigured(!configs.isEmpty()) .setSysOrigin(normalizedSysOrigin) + .setDismissConsumeGolds(getDismissConsumeGolds(normalizedSysOrigin)) .setLevels(levels); } @@ -82,6 +94,7 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService cpCabinConfigService.addCpCabin(config); } } + saveDismissConsumeGolds(normalizedSysOrigin, cmd.getDismissConsumeGolds()); } private List listCpCabinConfigs(String sysOrigin) { @@ -136,6 +149,95 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService requiredValue >= previousRequiredValue); previousRequiredValue = requiredValue; } + validateDismissConsumeGolds(cmd.getDismissConsumeGolds()); + } + + private Map getDismissConsumeGolds(String sysOrigin) { + Map result = defaultDismissConsumeGolds(); + dismissConsumeGoldKeys().forEach((relationType, key) -> result.put(relationType, + enumConfigGoldValue(sysEnumConfigService.getByCode(key.name(), sysOrigin)))); + return result; + } + + private void saveDismissConsumeGolds(String sysOrigin, Map dismissConsumeGolds) { + if (Objects.isNull(dismissConsumeGolds)) { + return; + } + dismissConsumeGoldKeys().forEach((relationType, key) -> { + if (dismissConsumeGolds.containsKey(relationType)) { + saveDismissConsumeGold(sysOrigin, key, dismissConsumeGolds.get(relationType)); + } + }); + } + + private void saveDismissConsumeGold(String sysOrigin, EnumConfigKey key, Long value) { + Long normalizedValue = defaultGold(value); + EnumConfigDTO enumConfig = sysEnumConfigService.getByCode(key.name(), sysOrigin); + boolean exists = Objects.nonNull(enumConfig) && Objects.nonNull(enumConfig.getId()); + if (!exists) { + enumConfig = new EnumConfigDTO(); + } + enumConfig.setSysOrigin(sysOrigin) + .setName(key.name()) + .setTitle(dismissConsumeGoldTitle(key)) + .setVal(String.valueOf(normalizedValue)) + .setDescription(dismissConsumeGoldTitle(key)) + .setDataType(CONFIG_DATA_TYPE) + .setReturnApp(Boolean.FALSE) + .setGroupName(CONFIG_GROUP_NAME); + if (exists) { + sysEnumConfigService.updateSysEnumConfig(enumConfig); + } else { + sysEnumConfigService.saveSysEnumConfig(enumConfig); + } + } + + private void validateDismissConsumeGolds(Map dismissConsumeGolds) { + if (Objects.isNull(dismissConsumeGolds)) { + return; + } + dismissConsumeGolds.forEach((relationType, gold) -> { + ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR, + "relationType is not supported.", + dismissConsumeGoldKeys().containsKey(normalizeRelationType(relationType))); + ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR, + "dismissConsumeGold must be greater than or equal to zero.", + defaultGold(gold) >= 0); + }); + } + + private Long enumConfigGoldValue(EnumConfigDTO enumConfig) { + if (Objects.isNull(enumConfig) || StringUtils.isBlank(enumConfig.getVal())) { + return 0L; + } + try { + return new BigDecimal(enumConfig.getVal()).longValue(); + } catch (NumberFormatException ex) { + return 0L; + } + } + + private Map defaultDismissConsumeGolds() { + Map result = new LinkedHashMap<>(); + dismissConsumeGoldKeys().keySet().forEach(relationType -> result.put(relationType, 0L)); + return result; + } + + private Map dismissConsumeGoldKeys() { + Map result = new LinkedHashMap<>(); + result.put(RELATION_TYPE_CP, EnumConfigKey.CP_DISMISS_CONSUME_GOLD); + result.put(RELATION_TYPE_BROTHER, EnumConfigKey.BROTHER_DISMISS_CONSUME_GOLD); + result.put(RELATION_TYPE_SISTERS, EnumConfigKey.SISTERS_DISMISS_CONSUME_GOLD); + return result; + } + + private String dismissConsumeGoldTitle(EnumConfigKey key) { + return switch (key) { + case CP_DISMISS_CONSUME_GOLD -> "CP 解绑金币"; + case BROTHER_DISMISS_CONSUME_GOLD -> "Brother 解绑金币"; + case SISTERS_DISMISS_CONSUME_GOLD -> "Sisters 解绑金币"; + default -> "关系解绑金币"; + }; } private List sortedLevels( @@ -158,6 +260,24 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService return requiredValue == null ? 0L : requiredValue; } + private Long defaultGold(Long gold) { + return gold == null ? 0L : gold; + } + + private String normalizeRelationType(String relationType) { + if (StringUtils.isBlank(relationType)) { + return ""; + } + String normalized = relationType.trim().toUpperCase(); + if (Objects.equals(normalized, "BROTHERS")) { + return RELATION_TYPE_BROTHER; + } + if (Objects.equals(normalized, "SISTER")) { + return RELATION_TYPE_SISTERS; + } + return normalized; + } + private String defaultLevelName(Integer level, String levelName) { if (StringUtils.isNotBlank(levelName)) { return levelName.trim(); diff --git a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/sys/SysEnumConfigServiceImpl.java b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/sys/SysEnumConfigServiceImpl.java index 162b10a3..f447f37d 100644 --- a/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/sys/SysEnumConfigServiceImpl.java +++ b/rc-service/rc-service-console/console-application/src/main/java/com/red/circle/console/app/service/app/sys/SysEnumConfigServiceImpl.java @@ -33,14 +33,19 @@ public class SysEnumConfigServiceImpl implements SysEnumConfigService { } @Override - public String getViolationAvatar(EnumConfigKey violationPicture) { - return ResponseAssert.requiredSuccess(enumConfigClient.getViolationAvatar(violationPicture)); - } - - @Override - public void saveSysEnumConfig(EnumConfigDTO sysEnumConfig) { - ResponseAssert.requiredSuccess(enumConfigClient.saveSysEnumConfig(sysEnumConfig)); - } + public String getViolationAvatar(EnumConfigKey violationPicture) { + return ResponseAssert.requiredSuccess(enumConfigClient.getViolationAvatar(violationPicture)); + } + + @Override + public EnumConfigDTO getByCode(String name, String sysOrigin) { + return ResponseAssert.requiredSuccess(enumConfigClient.getByCode(name, sysOrigin)); + } + + @Override + public void saveSysEnumConfig(EnumConfigDTO sysEnumConfig) { + ResponseAssert.requiredSuccess(enumConfigClient.saveSysEnumConfig(sysEnumConfig)); + } @Override public void updateSysEnumConfig(EnumConfigDTO sysEnumConfig) { diff --git a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clienobject/app/activity/cp/ResidentCpConfigCO.java b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clienobject/app/activity/cp/ResidentCpConfigCO.java index c86a9735..12c37eb4 100644 --- a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clienobject/app/activity/cp/ResidentCpConfigCO.java +++ b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/clienobject/app/activity/cp/ResidentCpConfigCO.java @@ -3,7 +3,9 @@ package com.red.circle.console.app.dto.clienobject.app.activity.cp; import com.red.circle.framework.dto.ClientObject; import java.io.Serial; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -24,4 +26,9 @@ public class ResidentCpConfigCO extends ClientObject { private String sysOrigin; private List levels = new ArrayList<>(); + + /** + * Relation dismiss gold config. Key: CP/BROTHER/SISTERS. + */ + private Map dismissConsumeGolds = new LinkedHashMap<>(); } diff --git a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/cmd/app/activity/cp/ResidentCpConfigSaveCmd.java b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/cmd/app/activity/cp/ResidentCpConfigSaveCmd.java index ef3c2c33..25a276f2 100644 --- a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/cmd/app/activity/cp/ResidentCpConfigSaveCmd.java +++ b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/dto/cmd/app/activity/cp/ResidentCpConfigSaveCmd.java @@ -6,6 +6,7 @@ import jakarta.validation.constraints.NotEmpty; import java.io.Serial; import java.io.Serializable; import java.util.List; +import java.util.Map; import lombok.Data; import lombok.experimental.Accessors; @@ -25,4 +26,9 @@ public class ResidentCpConfigSaveCmd implements Serializable { @Valid @NotEmpty(message = "levels required.") private List levels; + + /** + * Relation dismiss gold config. Key: CP/BROTHER/SISTERS. + */ + private Map dismissConsumeGolds; } diff --git a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/sys/SysEnumConfigService.java b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/sys/SysEnumConfigService.java index 0560315a..54bbd38b 100644 --- a/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/sys/SysEnumConfigService.java +++ b/rc-service/rc-service-console/console-client/src/main/java/com/red/circle/console/app/service/app/sys/SysEnumConfigService.java @@ -18,9 +18,11 @@ public interface SysEnumConfigService { List sysEnumConfigList(String groupName); - String getViolationAvatar(EnumConfigKey violationPicture); - - void saveSysEnumConfig(EnumConfigDTO sysEnumConfig); + String getViolationAvatar(EnumConfigKey violationPicture); + + EnumConfigDTO getByCode(String name, String sysOrigin); + + void saveSysEnumConfig(EnumConfigDTO sysEnumConfig); void updateSysEnumConfig(EnumConfigDTO sysEnumConfig); 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 cfd30df1..543d2e65 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 @@ -6,15 +6,17 @@ import com.red.circle.external.inner.model.cmd.message.notice.official.NoticeExt 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.common.cp.CpRelationGoldConfig; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpDismissApplyCO; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd; 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.common.user.UserGiftBackpackCommon; +import com.red.circle.other.infra.database.cache.service.other.EnumConfigCacheService; +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; @@ -23,11 +25,16 @@ 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 com.red.circle.tool.core.tuple.PennyAmount; +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.enums.GoldOrigin; +import java.math.BigDecimal; import java.util.Arrays; import java.util.Objects; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; /** * 取消CP申请. @@ -48,10 +55,12 @@ public class DismissCpApplyCmdExe { private final WeekCpValueCountService weekCpValueCountService; private final UserCpValueCacheService userCpValueCacheService; private final CpBlessRecordService cpBlessRecordService; - private final CpCabinAchieveService cpCabinAchieveService; - private final UserProfileGateway userProfileGateway; - private final CpRelationshipCacheService cpRelationshipCacheService; - + private final CpCabinAchieveService cpCabinAchieveService; + private final UserProfileGateway userProfileGateway; + private final CpRelationshipCacheService cpRelationshipCacheService; + private final WalletGoldClient walletGoldClient; + private final EnumConfigCacheService enumConfigCacheService; + public CpDismissApplyCO execute(CpApplyDismissCmd cmd) { String relationType = parseRelationType(cmd.getRelationType()); @@ -66,6 +75,11 @@ public class DismissCpApplyCmdExe { return buildDismissedResult(cmd.getCpUserId(), relationType, TimestampUtils.now().getTime()); } + String sysOrigin = resolveSysOrigin(cmd, cpRelationship); + BigDecimal dismissConsumeGold = dismissConsumeGold(relationType, sysOrigin); + deductDismissGold(cmd.requiredReqUserId(), cpRelationship, relationType, + dismissConsumeGold, sysOrigin); + // 更新申请状态为解散 cpApplyService.dismiss(cmd.requiredReqUserId(), relationType); @@ -118,6 +132,49 @@ public class DismissCpApplyCmdExe { Arrays.asList(relationship.getUserId(), relationship.getCpUserId())); } + private BigDecimal dismissConsumeGold(String relationType, String sysOrigin) { + return CpRelationGoldConfig.defaultGold(enumConfigCacheService.getValueBigDecimal( + CpRelationGoldConfig.dismissConsumeGoldKey(relationType), sysOrigin)); + } + + private void deductDismissGold(Long userId, CpRelationship relationship, String relationType, + BigDecimal dismissConsumeGold, String sysOrigin) { + if (dismissConsumeGold.compareTo(BigDecimal.ZERO) <= 0) { + return; + } + ResponseAssert.requiredSuccess(walletGoldClient.changeBalance(GoldReceiptCmd.builder() + .appExpenditure() + .userId(userId) + .sysOrigin(sysOrigin) + .eventId(dismissEventId(relationship, relationType)) + .origin(GoldOrigin.CP_DISMISS) + .amount(PennyAmount.ofDollar(dismissConsumeGold)) + .build())); + } + + private String dismissEventId(CpRelationship relationship, String relationType) { + if (Objects.nonNull(relationship.getId())) { + return "CP_DISMISS:" + relationship.getId(); + } + if (Objects.nonNull(relationship.getCpValId())) { + return "CP_DISMISS:" + relationship.getCpValId(); + } + return "CP_DISMISS:" + relationType + ":" + relationship.getUserId() + ":" + + relationship.getCpUserId(); + } + + private String resolveSysOrigin(CpApplyDismissCmd cmd, CpRelationship relationship) { + try { + return cmd.requireReqSysOrigin(); + } catch (Exception ignored) { + return resolveRelationshipSysOrigin(relationship); + } + } + + private String resolveRelationshipSysOrigin(CpRelationship relationship) { + return Objects.toString(relationship.getSysOrigin(), ""); + } + private CpDismissApplyCO buildDismissedResult(Long cpUserId, String relationType, Long dismissEndTime) { return new CpDismissApplyCO() 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 index 2432eb99..0ab5ea73 100644 --- 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 @@ -1,7 +1,9 @@ package com.red.circle.other.app.command.user.query; +import com.red.circle.other.app.common.cp.CpRelationGoldConfig; 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.cache.service.other.EnumConfigCacheService; 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; @@ -32,6 +34,7 @@ public class UserCpRightsConfigQueryExe { private final CpCabinConfigService cpCabinConfigService; private final CpRelationshipService cpRelationshipService; private final CpValueService cpValueService; + private final EnumConfigCacheService enumConfigCacheService; public CpRightsConfigCO execute(CpRightsConfigQueryCmd cmd) { String relationType = CpRelationshipType.normalize(cmd.getRelationType()); @@ -47,10 +50,16 @@ public class UserCpRightsConfigQueryExe { .relationshipStatus(Objects.isNull(relationship) ? RELATIONSHIP_STATUS_NONE : relationship.getStatus()) .intimacyValue(intimacyValue) + .dismissConsumeGold(dismissConsumeGold(relationType, cmd.requireReqSysOrigin())) .levels(toLevels(relationType, configs, Objects.nonNull(relationship), intimacyValue)) .build(); } + private Long dismissConsumeGold(String relationType, String sysOrigin) { + return CpRelationGoldConfig.defaultGoldLong(enumConfigCacheService.getValueBigDecimal( + CpRelationGoldConfig.dismissConsumeGoldKey(relationType), sysOrigin)); + } + private CpRelationship findRelationship(Long reqUserId, Long cpUserId, String relationType) { if (Objects.isNull(reqUserId)) { return null; diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/cp/CpRelationGoldConfig.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/cp/CpRelationGoldConfig.java new file mode 100644 index 00000000..fa8a2cec --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/cp/CpRelationGoldConfig.java @@ -0,0 +1,32 @@ +package com.red.circle.other.app.common.cp; + +import com.red.circle.other.infra.enums.user.user.CpRelationshipType; +import com.red.circle.other.inner.enums.config.EnumConfigKey; +import java.math.BigDecimal; +import java.util.Objects; + +/** + * Relation gold config helpers. + */ +public final class CpRelationGoldConfig { + + private CpRelationGoldConfig() { + } + + public static EnumConfigKey dismissConsumeGoldKey(String relationType) { + CpRelationshipType normalizedType = CpRelationshipType.of(relationType); + return switch (normalizedType) { + case BROTHER -> EnumConfigKey.BROTHER_DISMISS_CONSUME_GOLD; + case SISTERS -> EnumConfigKey.SISTERS_DISMISS_CONSUME_GOLD; + case CP -> EnumConfigKey.CP_DISMISS_CONSUME_GOLD; + }; + } + + public static BigDecimal defaultGold(BigDecimal gold) { + return Objects.isNull(gold) ? BigDecimal.ZERO : gold; + } + + public static Long defaultGoldLong(BigDecimal gold) { + return defaultGold(gold).longValue(); + } +} diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/DismissCpApplyCmdExeTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/DismissCpApplyCmdExeTest.java index c0c75ded..7965d84c 100644 --- a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/DismissCpApplyCmdExeTest.java +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/DismissCpApplyCmdExeTest.java @@ -3,15 +3,19 @@ package com.red.circle.other.app.command.user; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.any; import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient; +import com.red.circle.framework.dto.ResultResponse; import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpDismissApplyCO; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd; 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.other.EnumConfigCacheService; 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; @@ -22,6 +26,11 @@ import com.red.circle.other.infra.database.rds.service.user.user.CpCabinAchieveS 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.CpRelationshipStatus; +import com.red.circle.other.inner.enums.config.EnumConfigKey; +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 java.math.BigDecimal; import java.util.Arrays; import org.junit.jupiter.api.Test; @@ -56,6 +65,7 @@ class DismissCpApplyCmdExeTest { verify(fixture.cpCabinAchieveService).deleteByCpValId(3001L); verify(fixture.cpBlessRecordService).deleteByCpValId(3001L); verify(fixture.cpRelationshipCacheService).remove(Arrays.asList(1001L, 2001L)); + verify(fixture.walletGoldClient).changeBalance(any(GoldReceiptCmd.class)); } @Test @@ -75,13 +85,16 @@ class DismissCpApplyCmdExeTest { assertEquals("NONE", result.getStatus()); assertEquals(0L, result.getDismissRemainSeconds()); verify(fixture.cpRelationshipService).deleteByUserPair(1001L, 2001L, "CP"); + verify(fixture.walletGoldClient, never()).changeBalance(any(GoldReceiptCmd.class)); } private static CpRelationship relationship() { return new CpRelationship() + .setId(4001L) .setUserId(1001L) .setCpUserId(2001L) .setCpValId(3001L) + .setSysOrigin("LIKEI") .setRelationType("CP") .setStatus(CpRelationshipStatus.NORMAL.name()); } @@ -110,6 +123,8 @@ class DismissCpApplyCmdExeTest { private final CpCabinAchieveService cpCabinAchieveService = mock(CpCabinAchieveService.class); private final CpRelationshipCacheService cpRelationshipCacheService = mock( CpRelationshipCacheService.class); + private final WalletGoldClient walletGoldClient = mock(WalletGoldClient.class); + private final EnumConfigCacheService enumConfigCacheService = mock(EnumConfigCacheService.class); private final DismissCpApplyCmdExe exe; private Fixture() { @@ -117,6 +132,11 @@ class DismissCpApplyCmdExeTest { UserGiftBackpackCommon userGiftBackpackCommon = mock(UserGiftBackpackCommon.class); UserProfileGateway userProfileGateway = mock(UserProfileGateway.class); when(userProfileGateway.getByUserId(1001L)).thenReturn(userProfile()); + when(enumConfigCacheService.getValueBigDecimal( + EnumConfigKey.CP_DISMISS_CONSUME_GOLD, "LIKEI")) + .thenReturn(BigDecimal.valueOf(100)); + when(walletGoldClient.changeBalance(any(GoldReceiptCmd.class))) + .thenReturn(ResultResponse.success(new WalletReceiptResDTO())); exe = new DismissCpApplyCmdExe( cpValueService, @@ -129,7 +149,9 @@ class DismissCpApplyCmdExeTest { cpBlessRecordService, cpCabinAchieveService, userProfileGateway, - cpRelationshipCacheService); + cpRelationshipCacheService, + walletGoldClient, + enumConfigCacheService); } } } 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 index 19cf6412..2113e6d7 100644 --- 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 @@ -45,6 +45,11 @@ public class CpRightsConfigCO extends ClientObject { */ private Long intimacyValue; + /** + * Gold required to dismiss this relationship type. + */ + private Long dismissConsumeGold; + /** * Level rights config. */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/enums/OtherConfigEnum.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/enums/OtherConfigEnum.java index 2c508c29..f064face 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/enums/OtherConfigEnum.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/enums/OtherConfigEnum.java @@ -102,15 +102,30 @@ public enum OtherConfigEnum implements SysConfigEnum { * SERVER_NOTICE_ACCOUNT("Server Notice account"), */ - /** - * cp价格. - */ - CP_PRICE("cp price"), - - /** - * Aswat 超级管理员ID. - */ - ASWAT_ADMINS("Aswat Super administrator ids"), + /** + * cp价格. + */ + CP_PRICE("cp price"), + + /** + * CP 关系解绑金币. + */ + CP_DISMISS_CONSUME_GOLD("CP dismiss consume gold"), + + /** + * Brother 关系解绑金币. + */ + BROTHER_DISMISS_CONSUME_GOLD("Brother dismiss consume gold"), + + /** + * Sisters 关系解绑金币. + */ + SISTERS_DISMISS_CONSUME_GOLD("Sisters dismiss consume gold"), + + /** + * Aswat 超级管理员ID. + */ + ASWAT_ADMINS("Aswat Super administrator ids"), /** * boos位置起步金额.