CP关系解绑需要金币
This commit is contained in:
parent
40a8f90e01
commit
a0461ce68c
@ -217,15 +217,30 @@ public enum EnumConfigKey {
|
|||||||
*/
|
*/
|
||||||
YAHLLA_GIFT_GOLD_RATIO_SELF,
|
YAHLLA_GIFT_GOLD_RATIO_SELF,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cp价格.
|
* cp价格.
|
||||||
*/
|
*/
|
||||||
CP_PRICE,
|
CP_PRICE,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aswat 超级管理员ID.
|
* CP 关系解绑金币.
|
||||||
*/
|
*/
|
||||||
ASWAT_ADMINS,
|
CP_DISMISS_CONSUME_GOLD,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brother 关系解绑金币.
|
||||||
|
*/
|
||||||
|
BROTHER_DISMISS_CONSUME_GOLD,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sisters 关系解绑金币.
|
||||||
|
*/
|
||||||
|
SISTERS_DISMISS_CONSUME_GOLD,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aswat 超级管理员ID.
|
||||||
|
*/
|
||||||
|
ASWAT_ADMINS,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* boos位置起步金额.
|
* boos位置起步金额.
|
||||||
|
|||||||
@ -750,15 +750,20 @@ public enum GoldOrigin {
|
|||||||
*/
|
*/
|
||||||
USER_RED_PACKET("User red packet"),
|
USER_RED_PACKET("User red packet"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CP告白信封
|
* CP告白信封
|
||||||
*/
|
*/
|
||||||
CP_LOVE_LETTER("CP love letter"),
|
CP_LOVE_LETTER("CP love letter"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cp榜单(周榜和季度榜)
|
* 解除 CP/Brother/Sisters 关系.
|
||||||
*/
|
*/
|
||||||
CP_RANKING_REWARD("CP ranking reward"),
|
CP_DISMISS("CP dismiss"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cp榜单(周榜和季度榜)
|
||||||
|
*/
|
||||||
|
CP_RANKING_REWARD("CP ranking reward"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 签到付费
|
* 签到付费
|
||||||
|
|||||||
@ -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.ResidentCpConfigSaveCmd;
|
||||||
import com.red.circle.console.app.dto.cmd.app.activity.cp.ResidentCpLevelConfigSaveCmd;
|
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.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.asserts.ResponseAssert;
|
||||||
import com.red.circle.framework.core.response.ResponseErrorCode;
|
import com.red.circle.framework.core.response.ResponseErrorCode;
|
||||||
import com.red.circle.framework.dto.PageQuery;
|
import com.red.circle.framework.dto.PageQuery;
|
||||||
import com.red.circle.framework.dto.PageResult;
|
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.cmd.sys.SysCpCabinConfigQryCmd;
|
||||||
|
import com.red.circle.other.inner.model.dto.sys.EnumConfigDTO;
|
||||||
import com.red.circle.other.inner.model.dto.sys.SysCpCabinConfigDTO;
|
import com.red.circle.other.inner.model.dto.sys.SysCpCabinConfigDTO;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
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 CP_LEVEL_COUNT = 5;
|
||||||
private static final int QUERY_LIMIT = 50;
|
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 CpCabinConfigService cpCabinConfigService;
|
||||||
|
private final SysEnumConfigService sysEnumConfigService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResidentCpConfigCO getConfig(String sysOrigin) {
|
public ResidentCpConfigCO getConfig(String sysOrigin) {
|
||||||
@ -49,6 +60,7 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService
|
|||||||
return new ResidentCpConfigCO()
|
return new ResidentCpConfigCO()
|
||||||
.setConfigured(!configs.isEmpty())
|
.setConfigured(!configs.isEmpty())
|
||||||
.setSysOrigin(normalizedSysOrigin)
|
.setSysOrigin(normalizedSysOrigin)
|
||||||
|
.setDismissConsumeGolds(getDismissConsumeGolds(normalizedSysOrigin))
|
||||||
.setLevels(levels);
|
.setLevels(levels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +94,7 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService
|
|||||||
cpCabinConfigService.addCpCabin(config);
|
cpCabinConfigService.addCpCabin(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
saveDismissConsumeGolds(normalizedSysOrigin, cmd.getDismissConsumeGolds());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SysCpCabinConfigDTO> listCpCabinConfigs(String sysOrigin) {
|
private List<SysCpCabinConfigDTO> listCpCabinConfigs(String sysOrigin) {
|
||||||
@ -136,6 +149,95 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService
|
|||||||
requiredValue >= previousRequiredValue);
|
requiredValue >= previousRequiredValue);
|
||||||
previousRequiredValue = requiredValue;
|
previousRequiredValue = requiredValue;
|
||||||
}
|
}
|
||||||
|
validateDismissConsumeGolds(cmd.getDismissConsumeGolds());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Long> getDismissConsumeGolds(String sysOrigin) {
|
||||||
|
Map<String, Long> result = defaultDismissConsumeGolds();
|
||||||
|
dismissConsumeGoldKeys().forEach((relationType, key) -> result.put(relationType,
|
||||||
|
enumConfigGoldValue(sysEnumConfigService.getByCode(key.name(), sysOrigin))));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveDismissConsumeGolds(String sysOrigin, Map<String, Long> 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<String, Long> 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<String, Long> defaultDismissConsumeGolds() {
|
||||||
|
Map<String, Long> result = new LinkedHashMap<>();
|
||||||
|
dismissConsumeGoldKeys().keySet().forEach(relationType -> result.put(relationType, 0L));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, EnumConfigKey> dismissConsumeGoldKeys() {
|
||||||
|
Map<String, EnumConfigKey> 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<ResidentCpLevelConfigSaveCmd> sortedLevels(
|
private List<ResidentCpLevelConfigSaveCmd> sortedLevels(
|
||||||
@ -158,6 +260,24 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService
|
|||||||
return requiredValue == null ? 0L : requiredValue;
|
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) {
|
private String defaultLevelName(Integer level, String levelName) {
|
||||||
if (StringUtils.isNotBlank(levelName)) {
|
if (StringUtils.isNotBlank(levelName)) {
|
||||||
return levelName.trim();
|
return levelName.trim();
|
||||||
|
|||||||
@ -33,14 +33,19 @@ public class SysEnumConfigServiceImpl implements SysEnumConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getViolationAvatar(EnumConfigKey violationPicture) {
|
public String getViolationAvatar(EnumConfigKey violationPicture) {
|
||||||
return ResponseAssert.requiredSuccess(enumConfigClient.getViolationAvatar(violationPicture));
|
return ResponseAssert.requiredSuccess(enumConfigClient.getViolationAvatar(violationPicture));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveSysEnumConfig(EnumConfigDTO sysEnumConfig) {
|
public EnumConfigDTO getByCode(String name, String sysOrigin) {
|
||||||
ResponseAssert.requiredSuccess(enumConfigClient.saveSysEnumConfig(sysEnumConfig));
|
return ResponseAssert.requiredSuccess(enumConfigClient.getByCode(name, sysOrigin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveSysEnumConfig(EnumConfigDTO sysEnumConfig) {
|
||||||
|
ResponseAssert.requiredSuccess(enumConfigClient.saveSysEnumConfig(sysEnumConfig));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSysEnumConfig(EnumConfigDTO sysEnumConfig) {
|
public void updateSysEnumConfig(EnumConfigDTO sysEnumConfig) {
|
||||||
|
|||||||
@ -3,7 +3,9 @@ package com.red.circle.console.app.dto.clienobject.app.activity.cp;
|
|||||||
import com.red.circle.framework.dto.ClientObject;
|
import com.red.circle.framework.dto.ClientObject;
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
@ -24,4 +26,9 @@ public class ResidentCpConfigCO extends ClientObject {
|
|||||||
private String sysOrigin;
|
private String sysOrigin;
|
||||||
|
|
||||||
private List<ResidentCpLevelConfigCO> levels = new ArrayList<>();
|
private List<ResidentCpLevelConfigCO> levels = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relation dismiss gold config. Key: CP/BROTHER/SISTERS.
|
||||||
|
*/
|
||||||
|
private Map<String, Long> dismissConsumeGolds = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import jakarta.validation.constraints.NotEmpty;
|
|||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
@ -25,4 +26,9 @@ public class ResidentCpConfigSaveCmd implements Serializable {
|
|||||||
@Valid
|
@Valid
|
||||||
@NotEmpty(message = "levels required.")
|
@NotEmpty(message = "levels required.")
|
||||||
private List<ResidentCpLevelConfigSaveCmd> levels;
|
private List<ResidentCpLevelConfigSaveCmd> levels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relation dismiss gold config. Key: CP/BROTHER/SISTERS.
|
||||||
|
*/
|
||||||
|
private Map<String, Long> dismissConsumeGolds;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,9 +18,11 @@ public interface SysEnumConfigService {
|
|||||||
|
|
||||||
List<EnumConfigDTO> sysEnumConfigList(String groupName);
|
List<EnumConfigDTO> sysEnumConfigList(String groupName);
|
||||||
|
|
||||||
String getViolationAvatar(EnumConfigKey violationPicture);
|
String getViolationAvatar(EnumConfigKey violationPicture);
|
||||||
|
|
||||||
void saveSysEnumConfig(EnumConfigDTO sysEnumConfig);
|
EnumConfigDTO getByCode(String name, String sysOrigin);
|
||||||
|
|
||||||
|
void saveSysEnumConfig(EnumConfigDTO sysEnumConfig);
|
||||||
|
|
||||||
void updateSysEnumConfig(EnumConfigDTO sysEnumConfig);
|
void updateSysEnumConfig(EnumConfigDTO sysEnumConfig);
|
||||||
|
|
||||||
|
|||||||
@ -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.external.inner.model.enums.message.OfficialNoticeTypeEnum;
|
||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||||
import com.red.circle.framework.core.response.CommonErrorCode;
|
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.clientobject.user.relation.cp.CpDismissApplyCO;
|
||||||
import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd;
|
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.gateway.user.UserProfileGateway;
|
||||||
import com.red.circle.other.domain.model.user.UserProfile;
|
import com.red.circle.other.domain.model.user.UserProfile;
|
||||||
import com.red.circle.other.infra.common.user.UserGiftBackpackCommon;
|
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.other.EnumConfigCacheService;
|
||||||
import com.red.circle.other.infra.database.cache.service.user.UserCpValueCacheService;
|
import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService;
|
||||||
import com.red.circle.other.infra.database.mongo.service.user.count.WeekCpValueCountService;
|
import com.red.circle.other.infra.database.cache.service.user.UserCpValueCacheService;
|
||||||
import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship;
|
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.CpApplyService;
|
||||||
import com.red.circle.other.infra.database.rds.service.user.user.CpBlessRecordService;
|
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.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.other.infra.enums.user.user.CpRelationshipType;
|
||||||
import com.red.circle.tool.core.collection.MapBuilder;
|
import com.red.circle.tool.core.collection.MapBuilder;
|
||||||
import com.red.circle.tool.core.date.TimestampUtils;
|
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.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取消CP申请.
|
* 取消CP申请.
|
||||||
@ -48,10 +55,12 @@ public class DismissCpApplyCmdExe {
|
|||||||
private final WeekCpValueCountService weekCpValueCountService;
|
private final WeekCpValueCountService weekCpValueCountService;
|
||||||
private final UserCpValueCacheService userCpValueCacheService;
|
private final UserCpValueCacheService userCpValueCacheService;
|
||||||
private final CpBlessRecordService cpBlessRecordService;
|
private final CpBlessRecordService cpBlessRecordService;
|
||||||
private final CpCabinAchieveService cpCabinAchieveService;
|
private final CpCabinAchieveService cpCabinAchieveService;
|
||||||
private final UserProfileGateway userProfileGateway;
|
private final UserProfileGateway userProfileGateway;
|
||||||
private final CpRelationshipCacheService cpRelationshipCacheService;
|
private final CpRelationshipCacheService cpRelationshipCacheService;
|
||||||
|
private final WalletGoldClient walletGoldClient;
|
||||||
|
private final EnumConfigCacheService enumConfigCacheService;
|
||||||
|
|
||||||
public CpDismissApplyCO execute(CpApplyDismissCmd cmd) {
|
public CpDismissApplyCO execute(CpApplyDismissCmd cmd) {
|
||||||
String relationType = parseRelationType(cmd.getRelationType());
|
String relationType = parseRelationType(cmd.getRelationType());
|
||||||
|
|
||||||
@ -66,6 +75,11 @@ public class DismissCpApplyCmdExe {
|
|||||||
return buildDismissedResult(cmd.getCpUserId(), relationType, TimestampUtils.now().getTime());
|
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);
|
cpApplyService.dismiss(cmd.requiredReqUserId(), relationType);
|
||||||
|
|
||||||
@ -118,6 +132,49 @@ public class DismissCpApplyCmdExe {
|
|||||||
Arrays.asList(relationship.getUserId(), relationship.getCpUserId()));
|
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,
|
private CpDismissApplyCO buildDismissedResult(Long cpUserId, String relationType,
|
||||||
Long dismissEndTime) {
|
Long dismissEndTime) {
|
||||||
return new CpDismissApplyCO()
|
return new CpDismissApplyCO()
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package com.red.circle.other.app.command.user.query;
|
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.clientobject.user.relation.cp.CpRightsConfigCO;
|
||||||
import com.red.circle.other.app.dto.cmd.user.relation.cp.CpRightsConfigQueryCmd;
|
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.CpCabinConfig;
|
||||||
import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship;
|
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.entity.user.user.CpValue;
|
||||||
@ -32,6 +34,7 @@ public class UserCpRightsConfigQueryExe {
|
|||||||
private final CpCabinConfigService cpCabinConfigService;
|
private final CpCabinConfigService cpCabinConfigService;
|
||||||
private final CpRelationshipService cpRelationshipService;
|
private final CpRelationshipService cpRelationshipService;
|
||||||
private final CpValueService cpValueService;
|
private final CpValueService cpValueService;
|
||||||
|
private final EnumConfigCacheService enumConfigCacheService;
|
||||||
|
|
||||||
public CpRightsConfigCO execute(CpRightsConfigQueryCmd cmd) {
|
public CpRightsConfigCO execute(CpRightsConfigQueryCmd cmd) {
|
||||||
String relationType = CpRelationshipType.normalize(cmd.getRelationType());
|
String relationType = CpRelationshipType.normalize(cmd.getRelationType());
|
||||||
@ -47,10 +50,16 @@ public class UserCpRightsConfigQueryExe {
|
|||||||
.relationshipStatus(Objects.isNull(relationship) ? RELATIONSHIP_STATUS_NONE
|
.relationshipStatus(Objects.isNull(relationship) ? RELATIONSHIP_STATUS_NONE
|
||||||
: relationship.getStatus())
|
: relationship.getStatus())
|
||||||
.intimacyValue(intimacyValue)
|
.intimacyValue(intimacyValue)
|
||||||
|
.dismissConsumeGold(dismissConsumeGold(relationType, cmd.requireReqSysOrigin()))
|
||||||
.levels(toLevels(relationType, configs, Objects.nonNull(relationship), intimacyValue))
|
.levels(toLevels(relationType, configs, Objects.nonNull(relationship), intimacyValue))
|
||||||
.build();
|
.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) {
|
private CpRelationship findRelationship(Long reqUserId, Long cpUserId, String relationType) {
|
||||||
if (Objects.isNull(reqUserId)) {
|
if (Objects.isNull(reqUserId)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
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.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.clientobject.user.relation.cp.CpDismissApplyCO;
|
||||||
import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyDismissCmd;
|
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.gateway.user.UserProfileGateway;
|
||||||
import com.red.circle.other.domain.model.user.UserProfile;
|
import com.red.circle.other.domain.model.user.UserProfile;
|
||||||
import com.red.circle.other.infra.common.user.UserGiftBackpackCommon;
|
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.cp.CpRelationshipCacheService;
|
||||||
import com.red.circle.other.infra.database.cache.service.user.UserCpValueCacheService;
|
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.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.CpRelationshipService;
|
||||||
import com.red.circle.other.infra.database.rds.service.user.user.CpValueService;
|
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.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 java.util.Arrays;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -56,6 +65,7 @@ class DismissCpApplyCmdExeTest {
|
|||||||
verify(fixture.cpCabinAchieveService).deleteByCpValId(3001L);
|
verify(fixture.cpCabinAchieveService).deleteByCpValId(3001L);
|
||||||
verify(fixture.cpBlessRecordService).deleteByCpValId(3001L);
|
verify(fixture.cpBlessRecordService).deleteByCpValId(3001L);
|
||||||
verify(fixture.cpRelationshipCacheService).remove(Arrays.asList(1001L, 2001L));
|
verify(fixture.cpRelationshipCacheService).remove(Arrays.asList(1001L, 2001L));
|
||||||
|
verify(fixture.walletGoldClient).changeBalance(any(GoldReceiptCmd.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -75,13 +85,16 @@ class DismissCpApplyCmdExeTest {
|
|||||||
assertEquals("NONE", result.getStatus());
|
assertEquals("NONE", result.getStatus());
|
||||||
assertEquals(0L, result.getDismissRemainSeconds());
|
assertEquals(0L, result.getDismissRemainSeconds());
|
||||||
verify(fixture.cpRelationshipService).deleteByUserPair(1001L, 2001L, "CP");
|
verify(fixture.cpRelationshipService).deleteByUserPair(1001L, 2001L, "CP");
|
||||||
|
verify(fixture.walletGoldClient, never()).changeBalance(any(GoldReceiptCmd.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CpRelationship relationship() {
|
private static CpRelationship relationship() {
|
||||||
return new CpRelationship()
|
return new CpRelationship()
|
||||||
|
.setId(4001L)
|
||||||
.setUserId(1001L)
|
.setUserId(1001L)
|
||||||
.setCpUserId(2001L)
|
.setCpUserId(2001L)
|
||||||
.setCpValId(3001L)
|
.setCpValId(3001L)
|
||||||
|
.setSysOrigin("LIKEI")
|
||||||
.setRelationType("CP")
|
.setRelationType("CP")
|
||||||
.setStatus(CpRelationshipStatus.NORMAL.name());
|
.setStatus(CpRelationshipStatus.NORMAL.name());
|
||||||
}
|
}
|
||||||
@ -110,6 +123,8 @@ class DismissCpApplyCmdExeTest {
|
|||||||
private final CpCabinAchieveService cpCabinAchieveService = mock(CpCabinAchieveService.class);
|
private final CpCabinAchieveService cpCabinAchieveService = mock(CpCabinAchieveService.class);
|
||||||
private final CpRelationshipCacheService cpRelationshipCacheService = mock(
|
private final CpRelationshipCacheService cpRelationshipCacheService = mock(
|
||||||
CpRelationshipCacheService.class);
|
CpRelationshipCacheService.class);
|
||||||
|
private final WalletGoldClient walletGoldClient = mock(WalletGoldClient.class);
|
||||||
|
private final EnumConfigCacheService enumConfigCacheService = mock(EnumConfigCacheService.class);
|
||||||
private final DismissCpApplyCmdExe exe;
|
private final DismissCpApplyCmdExe exe;
|
||||||
|
|
||||||
private Fixture() {
|
private Fixture() {
|
||||||
@ -117,6 +132,11 @@ class DismissCpApplyCmdExeTest {
|
|||||||
UserGiftBackpackCommon userGiftBackpackCommon = mock(UserGiftBackpackCommon.class);
|
UserGiftBackpackCommon userGiftBackpackCommon = mock(UserGiftBackpackCommon.class);
|
||||||
UserProfileGateway userProfileGateway = mock(UserProfileGateway.class);
|
UserProfileGateway userProfileGateway = mock(UserProfileGateway.class);
|
||||||
when(userProfileGateway.getByUserId(1001L)).thenReturn(userProfile());
|
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(
|
exe = new DismissCpApplyCmdExe(
|
||||||
cpValueService,
|
cpValueService,
|
||||||
@ -129,7 +149,9 @@ class DismissCpApplyCmdExeTest {
|
|||||||
cpBlessRecordService,
|
cpBlessRecordService,
|
||||||
cpCabinAchieveService,
|
cpCabinAchieveService,
|
||||||
userProfileGateway,
|
userProfileGateway,
|
||||||
cpRelationshipCacheService);
|
cpRelationshipCacheService,
|
||||||
|
walletGoldClient,
|
||||||
|
enumConfigCacheService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,11 @@ public class CpRightsConfigCO extends ClientObject {
|
|||||||
*/
|
*/
|
||||||
private Long intimacyValue;
|
private Long intimacyValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gold required to dismiss this relationship type.
|
||||||
|
*/
|
||||||
|
private Long dismissConsumeGold;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Level rights config.
|
* Level rights config.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -102,15 +102,30 @@ public enum OtherConfigEnum implements SysConfigEnum {
|
|||||||
* SERVER_NOTICE_ACCOUNT("Server Notice account"),
|
* SERVER_NOTICE_ACCOUNT("Server Notice account"),
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cp价格.
|
* cp价格.
|
||||||
*/
|
*/
|
||||||
CP_PRICE("cp price"),
|
CP_PRICE("cp price"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aswat 超级管理员ID.
|
* CP 关系解绑金币.
|
||||||
*/
|
*/
|
||||||
ASWAT_ADMINS("Aswat Super administrator ids"),
|
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位置起步金额.
|
* boos位置起步金额.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user