Compare commits

...

5 Commits

Author SHA1 Message Date
hy001
3588d0aeee Merge branch 'main' into test 2026-05-23 13:18:30 +08:00
hy001
dfb71f55a8 Merge branch 'main' into test 2026-05-23 12:20:10 +08:00
hy001
3168637944 已有关系拒绝其他关系 2026-05-22 21:23:19 +08:00
hy001
dca9f12cb5 新增发IM C2c 2026-05-22 20:11:20 +08:00
hy001
a0461ce68c CP关系解绑需要金币 2026-05-22 19:17:41 +08:00
32 changed files with 1463 additions and 234 deletions

View File

@ -1,8 +1,12 @@
package com.red.circle.external.inner.endpoint.message.api;
import com.red.circle.framework.dto.ResultResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.external.inner.model.cmd.message.CustomC2cMsgBodyCmd;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
* im 消息服务.
@ -24,9 +28,15 @@ public interface ImMessageClientApi {
/**
* 发送文本消息.
*/
@GetMapping("/sendMessageText/long")
ResultResponse<Void> sendMessageText(@RequestParam("fromAccount") Long fromAccount,
@RequestParam("toAccount") Long toAccount,
@RequestParam("text") String text);
}
@GetMapping("/sendMessageText/long")
ResultResponse<Void> sendMessageText(@RequestParam("fromAccount") Long fromAccount,
@RequestParam("toAccount") Long toAccount,
@RequestParam("text") String text);
/**
* 发送 C2C 自定义消息.
*/
@PostMapping("/sendCustomMessage")
ResultResponse<Void> sendCustomMessage(@RequestBody @Valid CustomC2cMsgBodyCmd cmd);
}

View File

@ -0,0 +1,82 @@
package com.red.circle.external.inner.model.cmd.message;
import com.red.circle.framework.dto.Command;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.Serial;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* C2C custom IM message.
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CustomC2cMsgBodyCmd extends Command {
@Serial
private static final long serialVersionUID = 1L;
@NotBlank(message = "fromAccount required.")
private String fromAccount;
@NotBlank(message = "toAccount required.")
private String toAccount;
@NotBlank(message = "desc required.")
private String desc;
@NotNull(message = "data required.")
private Object data;
public static CustomC2cMsgBodyBuilder builder() {
return new CustomC2cMsgBodyBuilder();
}
public static class CustomC2cMsgBodyBuilder {
private String fromAccount;
private String toAccount;
private String desc;
private Object data;
public CustomC2cMsgBodyBuilder fromAccount(String fromAccount) {
this.fromAccount = fromAccount;
return this;
}
public CustomC2cMsgBodyBuilder fromAccount(Long fromAccount) {
this.fromAccount = String.valueOf(fromAccount);
return this;
}
public CustomC2cMsgBodyBuilder toAccount(String toAccount) {
this.toAccount = toAccount;
return this;
}
public CustomC2cMsgBodyBuilder toAccount(Long toAccount) {
this.toAccount = String.valueOf(toAccount);
return this;
}
public CustomC2cMsgBodyBuilder desc(String desc) {
this.desc = desc;
return this;
}
public CustomC2cMsgBodyBuilder data(Object data) {
this.data = data;
return this;
}
public CustomC2cMsgBodyCmd build() {
CustomC2cMsgBodyCmd cmd = new CustomC2cMsgBodyCmd();
cmd.setFromAccount(this.fromAccount);
cmd.setToAccount(this.toAccount);
cmd.setDesc(this.desc);
cmd.setData(this.data);
return cmd;
}
}
}

View File

@ -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位置起步金额.

View File

@ -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"),
/**
* 签到付费

View File

@ -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;
@ -35,8 +40,14 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService
private static final int CP_LEVEL_COUNT = 6;
private static final int CP_MIN_LEVEL = 0;
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) {
@ -50,6 +61,7 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService
return new ResidentCpConfigCO()
.setConfigured(!configs.isEmpty())
.setSysOrigin(normalizedSysOrigin)
.setDismissConsumeGolds(getDismissConsumeGolds(normalizedSysOrigin))
.setLevels(levels);
}
@ -83,6 +95,7 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService
cpCabinConfigService.addCpCabin(config);
}
}
saveDismissConsumeGolds(normalizedSysOrigin, cmd.getDismissConsumeGolds());
}
private List<SysCpCabinConfigDTO> listCpCabinConfigs(String sysOrigin) {
@ -135,6 +148,95 @@ public class ResidentCpActivityServiceImpl implements ResidentCpActivityService
requiredValue >= previousRequiredValue);
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(
@ -157,6 +259,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();

View File

@ -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) {

View File

@ -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<ResidentCpLevelConfigCO> levels = new ArrayList<>();
/**
* Relation dismiss gold config. Key: CP/BROTHER/SISTERS.
*/
private Map<String, Long> dismissConsumeGolds = new LinkedHashMap<>();
}

View File

@ -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<ResidentCpLevelConfigSaveCmd> levels;
/**
* Relation dismiss gold config. Key: CP/BROTHER/SISTERS.
*/
private Map<String, Long> dismissConsumeGolds;
}

View File

@ -18,9 +18,11 @@ public interface SysEnumConfigService {
List<EnumConfigDTO> 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);

View File

@ -1,8 +1,9 @@
package com.red.circle.external.inner.endpoint.message;
import com.red.circle.external.inner.endpoint.message.api.ImMessageClientApi;
import com.red.circle.external.inner.service.message.ImMessageClientService;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.external.inner.endpoint.message.api.ImMessageClientApi;
import com.red.circle.external.inner.model.cmd.message.CustomC2cMsgBodyCmd;
import com.red.circle.external.inner.service.message.ImMessageClientService;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.tool.core.parse.DataTypeUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
@ -30,10 +31,16 @@ public class ImMessageClientEndpoint implements ImMessageClientApi {
}
@Override
public ResultResponse<Void> sendMessageText(Long fromAccount, Long toAccount, String text) {
imMessageClientService.sendMessageText(DataTypeUtils.toString(fromAccount),
DataTypeUtils.toString(toAccount), text);
return ResultResponse.success();
}
}
public ResultResponse<Void> sendMessageText(Long fromAccount, Long toAccount, String text) {
imMessageClientService.sendMessageText(DataTypeUtils.toString(fromAccount),
DataTypeUtils.toString(toAccount), text);
return ResultResponse.success();
}
@Override
public ResultResponse<Void> sendCustomMessage(CustomC2cMsgBodyCmd cmd) {
imMessageClientService.sendCustomMessage(cmd);
return ResultResponse.success();
}
}

View File

@ -1,7 +1,9 @@
package com.red.circle.external.inner.service.message;
/**
* im 消息服务.
package com.red.circle.external.inner.service.message;
import com.red.circle.external.inner.model.cmd.message.CustomC2cMsgBodyCmd;
/**
* im 消息服务.
*
* @author pengliang on 2023/7/12
*/
@ -9,7 +11,12 @@ public interface ImMessageClientService {
/**
* 发送文本消息.
*/
void sendMessageText(String fromAccount, String toAccount, String text);
}
*/
void sendMessageText(String fromAccount, String toAccount, String text);
/**
* 发送 C2C 自定义消息.
*/
void sendCustomMessage(CustomC2cMsgBodyCmd cmd);
}

View File

@ -1,10 +1,16 @@
package com.red.circle.external.inner.service.message.impl;
import com.red.circle.component.instant.msg.tencet.service.endpoint.api.im.account.ImMessageManagerService;
import com.red.circle.external.inner.service.message.ImMessageClientService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import com.red.circle.component.instant.msg.tencet.service.endpoint.api.im.account.ImMessageManagerService;
import com.red.circle.component.instant.msg.tencet.service.param.ImMessageParam;
import com.red.circle.component.instant.msg.tencet.service.param.MessageBody;
import com.red.circle.component.instant.msg.tencet.service.param.OfflinePushInfo;
import com.red.circle.external.inner.model.cmd.message.CustomC2cMsgBodyCmd;
import com.red.circle.external.inner.service.message.ImMessageClientService;
import com.red.circle.tool.core.num.NumUtils;
import com.red.circle.tool.core.parse.DataTypeUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
/**
* im 消息服务.
@ -19,8 +25,24 @@ public class ImMessageClientServiceImpl implements ImMessageClientService {
private final ImMessageManagerService imMessageManagerService;
@Override
public void sendMessageText(String fromAccount, String toAccount, String text) {
imMessageManagerService.sendMessageText(fromAccount, toAccount, text).subscribe();
}
}
public void sendMessageText(String fromAccount, String toAccount, String text) {
imMessageManagerService.sendMessageText(fromAccount, toAccount, text).subscribe();
}
@Override
public void sendCustomMessage(CustomC2cMsgBodyCmd cmd) {
ImMessageParam param = ImMessageParam.builder()
.fromAccount(cmd.getFromAccount())
.toAccount(cmd.getToAccount())
.offlinePushInfo(OfflinePushInfo.builder()
.pushFlag(0)
.build())
.msgRandom(DataTypeUtils.toInteger(NumUtils.getRandomNumberString(9)))
.build()
.addMsgBody(MessageBody.customBody(cmd.getDesc(), cmd.getData()));
imMessageManagerService.sendMessage(param)
.subscribe(res -> log.warn("sendCustomMessage response result:{}", res),
res -> log.error("sendCustomMessage error cmd={}, result={}", cmd, res));
}
}

View File

@ -186,10 +186,11 @@ public class BlessingsGiftGiveCmdExe {
giftConfig.setId(giftConfigCache.getId());
giftConfig.setGiftCandy(giftConfigCache.getGiftCandy());
giftConfig.setGiftIntegral(giftConfigCache.getGiftIntegral());
giftConfig.setSpecial(giftConfigCache.getSpecial());
giftConfig.setType(giftConfigCache.getType());
giftConfig.setGiftTab(giftConfigCache.getGiftTab());
return giftConfig;
}
}
giftConfig.setSpecial(giftConfigCache.getSpecial());
giftConfig.setType(giftConfigCache.getType());
giftConfig.setGiftTab(giftConfigCache.getGiftTab());
giftConfig.setCpRelationType(giftConfigCache.getCpRelationType());
return giftConfig;
}
}

View File

@ -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()

View File

@ -6,10 +6,12 @@ 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.common.cp.CpRelationC2cNoticeUtils;
import com.red.circle.other.app.common.cp.CpRelationBroadcastMqClient;
import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.infra.database.cache.service.cp.CpRelationshipCacheService;
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.cache.service.cp.CpRelationshipCacheService;
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;
@ -22,10 +24,11 @@ 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.enums.GoldOrigin;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Objects;
import com.red.circle.wallet.inner.model.enums.GoldOrigin;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -67,17 +70,22 @@ public class ProcessCpApplyCmd {
ResponseAssert.isTrue(CommonErrorCode.STATE_ERROR,
Objects.equals(cpApply.getStatus(), CpApplyStatus.WAIT.name()));
// 检查是否是复合申请
CpRelationship dismissingCp = cpRelationshipService.getDismissingCp(
cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(), relationType);
boolean isReconcile = Objects.nonNull(dismissingCp);
if (!isReconcile) {
// 非复合申请CP已存在
boolean agree = isAgree(cmd);
boolean isReconcile = false;
if (agree) {
// 检查是否是复合申请
CpRelationship dismissingCp = cpRelationshipService.getDismissingCp(
cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(), relationType);
isReconcile = Objects.nonNull(dismissingCp);
}
if (agree && !isReconcile) {
// 非复合申请两人之间只能存在一种正常关系
ResponseAssert.isFalse(UserRelationErrorCode.ME_OR_YOU_CP_EXISTED,
cpRelationshipService.existsCp(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(),
relationType));
cpRelationshipService.existsRelationship(cpApply.getSendApplyUserId(),
cpApply.getAcceptApplyUserId()));
int maxCount = relationMaxCount(relationType);
ResponseAssert.isFalse(UserRelationErrorCode.CP_LIMIT_EXCEEDED,
cpRelationshipService.countCp(cpApply.getSendApplyUserId(), relationType) >= maxCount);
@ -86,13 +94,14 @@ public class ProcessCpApplyCmd {
}
// 操作失败
ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE,
cpApplyService.changeStatusById(cmd.getApplyId(), getStatus(cmd)));
if (!isAgree(cmd)) {
returnGoldCoins(cmd, cpApply);
return;
}
ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE,
cpApplyService.changeStatusById(cmd.getApplyId(), getStatus(cmd)));
if (!agree) {
returnGoldCoins(cmd, cpApply);
sendProcessNotice(cpApply, false);
return;
}
if (isReconcile) {
// 复合更新状态为NORMAL
@ -105,24 +114,52 @@ public class ProcessCpApplyCmd {
cmd.requireReqSysOrigin(), relationType);
}
refuseStatusWaitIfLimitReached(cmd, cpApply, relationType);
List<Long> refusedApplyIds = cpApplyService.refuseOtherWaitBetweenUsers(cpApply.getId(),
cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId());
boolean refusedByLimit = refuseStatusWaitIfLimitReached(cmd, cpApply, relationType);
if (!refusedApplyIds.isEmpty() || refusedByLimit) {
scheduleReimburse(cmd, cpApply.getId());
}
cpRelationshipCacheService.remove(Arrays.asList(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId()));
cpRelationBroadcastMqClient.publish(cmd.requireReqSysOrigin(), cpApply.getId(),
cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId(), relationType);
sendProcessNotice(cpApply, true);
}
private void refuseStatusWaitIfLimitReached(ProcessApplyCmd cmd, CpApply cpApply,
private void sendProcessNotice(CpApply cpApply, boolean agree) {
try {
UserProfile senderProfile = userProfileGateway.getByUserId(cpApply.getSendApplyUserId());
UserProfile acceptProfile = userProfileGateway.getByUserId(cpApply.getAcceptApplyUserId());
if (Objects.isNull(senderProfile) || Objects.isNull(acceptProfile)) {
log.info("[CP] skip process c2c notice, applyId={}, senderProfile={}, acceptProfile={}",
cpApply.getId(), Objects.nonNull(senderProfile), Objects.nonNull(acceptProfile));
return;
}
imMessageClient.sendCustomMessage(agree
? CpRelationC2cNoticeUtils.buildAccepted(cpApply, senderProfile, acceptProfile)
: CpRelationC2cNoticeUtils.buildRejected(cpApply, senderProfile, acceptProfile));
} catch (Exception ex) {
log.warn("[CP] send process c2c notice failed, applyId={}, agree={}, reason={}",
cpApply.getId(), agree, ex.getMessage(), ex);
}
}
private boolean refuseStatusWaitIfLimitReached(ProcessApplyCmd cmd, CpApply cpApply,
String relationType) {
if (cpRelationshipService.countCp(cpApply.getAcceptApplyUserId(), relationType)
< relationMaxCount(relationType)) {
return;
return false;
}
cpApplyService.refuseStatusWait(cmd.requiredReqUserId(), relationType);
return true;
}
private void scheduleReimburse(ProcessApplyCmd cmd, Long applyId) {
userMqMessageService.cpApplyDelayed(
new CpApplyEvent()
.setId(cpApply.getId())
.setSysOrigin(SysOriginPlatformEnum.valueOf(cmd.requireReqSysOrigin())),
.setId(applyId)
.setSysOrigin(SysOriginPlatformEnum.valueOf(cmd.requireReqSysOrigin())),
TimestampUtils.nowPlusMinutes(1));
}

View File

@ -1,18 +1,16 @@
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.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.external.inner.endpoint.message.ImMessageClient;
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.common.cp.CpRelationC2cNoticeUtils;
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;
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
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;
@ -20,19 +18,16 @@ 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.asserts.user.UserRelationErrorCode;
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.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.math.BigDecimal;
import java.util.Map;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -51,8 +46,8 @@ public class SendCpApplyCmdExe {
private static final int FRIEND_MAX_COUNT = 3;
private final CpApplyService cpApplyService;
private final OfficialNoticeClient officialNoticeClient;
private final WalletGoldClient walletGoldClient;
private final ImMessageClient imMessageClient;
private final WalletGoldClient walletGoldClient;
private final UserMqMessageService userMqMessageService;
private final CpRelationshipService cpRelationshipService;
private final EnumConfigCacheService enumConfigCacheService;
@ -69,8 +64,20 @@ public class SendCpApplyCmdExe {
return autoCreateFromCpGift(sendUserId, acceptUserId, sysOrigin, CpRelationshipType.CP.name());
}
public boolean autoCreateFromCpGift(Long sendUserId, Long acceptUserId, String sysOrigin,
BigDecimal applyConsumeGold) {
return autoCreateFromCpGift(sendUserId, acceptUserId, sysOrigin, CpRelationshipType.CP.name(),
applyConsumeGold);
}
public boolean autoCreateFromCpGift(Long sendUserId, Long acceptUserId, String sysOrigin,
String relationTypeValue) {
return autoCreateFromCpGift(sendUserId, acceptUserId, sysOrigin, relationTypeValue,
BigDecimal.ZERO);
}
public boolean autoCreateFromCpGift(Long sendUserId, Long acceptUserId, String sysOrigin,
String relationTypeValue, BigDecimal applyConsumeGold) {
if (Objects.equals(sendUserId, acceptUserId)) {
log.info(
"[CP] skip auto create cp apply from self gift, sendUserId={}, relationType={}",
@ -78,7 +85,7 @@ public class SendCpApplyCmdExe {
return false;
}
try {
process(sendUserId, acceptUserId, sysOrigin, relationTypeValue, false);
process(sendUserId, acceptUserId, sysOrigin, relationTypeValue, false, applyConsumeGold);
return true;
} catch (Exception ex) {
log.info(
@ -90,6 +97,11 @@ public class SendCpApplyCmdExe {
private void process(Long sendUserId, Long acceptUserId, String sysOrigin, String relationTypeValue,
boolean chargeGold) {
process(sendUserId, acceptUserId, sysOrigin, relationTypeValue, chargeGold, BigDecimal.ZERO);
}
private void process(Long sendUserId, Long acceptUserId, String sysOrigin, String relationTypeValue,
boolean chargeGold, BigDecimal giftApplyConsumeGold) {
CpRelationshipType relationType = parseRelationType(relationTypeValue);
// 不可用操作自己
@ -111,10 +123,9 @@ public class SendCpApplyCmdExe {
boolean isReconcile = Objects.nonNull(dismissingCp);
if (!isReconcile) {
// 非复合申请检查CP是否已存在
// 非复合申请两人之间只能存在一种正常关系
ResponseAssert.isFalse(UserRelationErrorCode.ME_OR_YOU_CP_EXISTED,
cpRelationshipService
.existsCp(sendUserId, acceptUserId, relationType.name()));
cpRelationshipService.existsRelationship(sendUserId, acceptUserId));
validateRelationLimit(sendUserId, acceptUserId, relationType);
}
@ -127,7 +138,7 @@ public class SendCpApplyCmdExe {
ResponseAssert.isFalse(UserRelationErrorCode.OTHER_SIDE_ALREADY_APPLIED,
cpApplyService.exists(sendUserId, acceptUserId, relationType.name()));
BigDecimal applyConsumeGold = BigDecimal.ZERO;
BigDecimal applyConsumeGold = normalizeApplyConsumeGold(giftApplyConsumeGold);
if (chargeGold) {
WalletReceiptResDTO receipt = ResponseAssert.requiredSuccess(
walletGoldClient.changeBalance(GoldReceiptCmd.builder()
@ -159,22 +170,9 @@ public class SendCpApplyCmdExe {
cpApplyService.save(cpApply);
Map<Object, Object> map = OfficialNoticeUtils.buildUserProfile(userProfile);
map.put("applyType", isReconcile ? "RECONCILE" : "APPLY");
map.put("relationType", relationType.name());
map.put("acceptUserId", acceptUserProfile.getId());
map.put("acceptAccount", acceptUserProfile.getAccount());
map.put("acceptActualAccount", acceptUserProfile.actualAccount());
map.put("acceptNickname", acceptUserProfile.getUserNickname());
map.put("acceptUserAvatar", acceptUserProfile.getUserAvatar());
officialNoticeClient.send(NoticeExtTemplateTypeCmd.builder()
.toAccount(acceptUserId)
.noticeType(OfficialNoticeTypeEnum.CP_BUILD)
.templateParam(map)
.expand(cpApply.getId())
.build()
);
sendCpBuildIm(sendUserId, acceptUserId, cpApply.getId(), userProfile, acceptUserProfile,
isReconcile, relationType, applyText);
userMqMessageService.cpApplyDelayed(
new CpApplyEvent()
.setId(cpApply.getId())
@ -182,6 +180,20 @@ public class SendCpApplyCmdExe {
TimestampUtils.nowPlusDays(1));
}
private void sendCpBuildIm(Long sendUserId, Long acceptUserId, Long applyId,
UserProfileDTO userProfile, UserProfileDTO acceptUserProfile, boolean isReconcile,
CpRelationshipType relationType, String title) {
imMessageClient.sendCustomMessage(CpRelationC2cNoticeUtils.buildInvitePending(sendUserId,
acceptUserId, applyId, userProfile, acceptUserProfile, isReconcile, relationType, title));
}
private BigDecimal normalizeApplyConsumeGold(BigDecimal applyConsumeGold) {
if (Objects.isNull(applyConsumeGold) || applyConsumeGold.compareTo(BigDecimal.ZERO) <= 0) {
return BigDecimal.ZERO;
}
return applyConsumeGold;
}
private void validateRelationLimit(Long sendUserId, Long acceptUserId,
CpRelationshipType relationType) {
int maxCount = relationMaxCount(relationType);

View File

@ -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;

View File

@ -0,0 +1,205 @@
package com.red.circle.other.app.common.cp;
import com.red.circle.external.inner.model.cmd.message.CustomC2cMsgBodyCmd;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.other.infra.database.rds.entity.user.user.CpApply;
import com.red.circle.other.infra.enums.user.user.CpRelationshipType;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.json.JacksonUtils;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
public final class CpRelationC2cNoticeUtils {
public static final String NOTICE_TYPE = "CP_BUILD";
public static final String ACTION_INVITE_PENDING = "INVITE_PENDING";
public static final String ACTION_RELATION_ESTABLISHED = "RELATION_ESTABLISHED";
public static final String ACTION_RELATION_REJECTED = "RELATION_REJECTED";
public static final String ACTION_RELATION_EXPIRED = "RELATION_EXPIRED";
private CpRelationC2cNoticeUtils() {
}
public static CustomC2cMsgBodyCmd buildInvitePending(Long fromUserId, Long toUserId,
Long applyId, UserProfileDTO senderProfile, UserProfileDTO acceptProfile,
boolean isReconcile, CpRelationshipType relationType, String title) {
Map<String, Object> content = senderContent(senderProfile);
content.put("applyType", isReconcile ? "RECONCILE" : "APPLY");
content.put("relationType", relationType.name());
putAcceptProfile(content, acceptProfile);
Map<String, Object> payload = basePayload(applyId, relationType.name(), title,
ACTION_INVITE_PENDING, "PENDING", content);
putSenderProfile(payload, senderProfile);
putAcceptProfile(payload, acceptProfile);
return buildMessage(fromUserId, toUserId, payload);
}
public static CustomC2cMsgBodyCmd buildAccepted(CpApply cpApply, UserProfile senderProfile,
UserProfile acceptProfile) {
String relationType = CpRelationshipType.normalize(cpApply.getRelationType());
String title = "User " + displayName(acceptProfile) + " accepted your "
+ relationType.toLowerCase() + " invitation.";
Map<String, Object> content = senderContent(senderProfile);
content.put("applyType", "APPLY");
content.put("relationType", relationType);
putAcceptProfile(content, acceptProfile);
Map<String, Object> payload = basePayload(cpApply.getId(), relationType, title,
ACTION_RELATION_ESTABLISHED, "ACCEPTED", content);
payload.put("agree", true);
putSenderProfile(payload, senderProfile);
putAcceptProfile(payload, acceptProfile);
return buildMessage(cpApply.getAcceptApplyUserId(), cpApply.getSendApplyUserId(), payload);
}
public static CustomC2cMsgBodyCmd buildRejected(CpApply cpApply, UserProfile senderProfile,
UserProfile acceptProfile) {
String relationType = CpRelationshipType.normalize(cpApply.getRelationType());
String title = "User " + displayName(acceptProfile) + " declined your "
+ relationType.toLowerCase() + " invitation.";
Map<String, Object> content = senderContent(senderProfile);
content.put("applyType", "APPLY");
content.put("relationType", relationType);
putAcceptProfile(content, acceptProfile);
Map<String, Object> payload = basePayload(cpApply.getId(), relationType, title,
ACTION_RELATION_REJECTED, "REJECTED", content);
payload.put("agree", false);
putSenderProfile(payload, senderProfile);
putAcceptProfile(payload, acceptProfile);
return buildMessage(cpApply.getAcceptApplyUserId(), cpApply.getSendApplyUserId(), payload);
}
public static CustomC2cMsgBodyCmd buildExpiredToAcceptUser(CpApply cpApply,
UserProfile senderProfile, UserProfile acceptProfile) {
return buildExpired(cpApply, senderProfile, acceptProfile, cpApply.getSendApplyUserId(),
cpApply.getAcceptApplyUserId());
}
public static CustomC2cMsgBodyCmd buildExpiredToSendUser(CpApply cpApply,
UserProfile senderProfile, UserProfile acceptProfile) {
return buildExpired(cpApply, senderProfile, acceptProfile, cpApply.getAcceptApplyUserId(),
cpApply.getSendApplyUserId());
}
private static CustomC2cMsgBodyCmd buildExpired(CpApply cpApply, UserProfile senderProfile,
UserProfile acceptProfile, Long fromUserId, Long toUserId) {
String relationType = CpRelationshipType.normalize(cpApply.getRelationType());
String title = "Your " + relationType.toLowerCase() + " invitation expired.";
Map<String, Object> content = senderContent(senderProfile);
content.put("applyType", "APPLY");
content.put("relationType", relationType);
putAcceptProfile(content, acceptProfile);
Map<String, Object> payload = basePayload(cpApply.getId(), relationType, title,
ACTION_RELATION_EXPIRED, "EXPIRED", content);
payload.put("expired", true);
putSenderProfile(payload, senderProfile);
putAcceptProfile(payload, acceptProfile);
return buildMessage(fromUserId, toUserId, payload);
}
private static Map<String, Object> basePayload(Long applyId, String relationType, String title,
String action, String status, Map<String, Object> content) {
Map<String, Object> payload = new LinkedHashMap<>();
payload.put("noticeType", NOTICE_TYPE);
payload.put("type", NOTICE_TYPE);
payload.put("noticeAction", action);
payload.put("action", action);
payload.put("status", status);
payload.put("result", status);
payload.put("state", status);
payload.put("title", title);
payload.put("content", JacksonUtils.toJson(content));
payload.put("expand", applyId);
payload.put("applyId", applyId);
payload.put("relationType", relationType);
return payload;
}
private static CustomC2cMsgBodyCmd buildMessage(Long fromUserId, Long toUserId,
Map<String, Object> payload) {
return CustomC2cMsgBodyCmd.builder()
.fromAccount(fromUserId)
.toAccount(toUserId)
.desc(NOTICE_TYPE)
.data(payload)
.build();
}
private static Map<String, Object> senderContent(UserProfileDTO userProfile) {
Map<String, Object> content = new LinkedHashMap<>();
content.put("userNickname", userProfile.getUserNickname());
content.put("account", userProfile.getAccount());
content.put("actualAccount", userProfile.actualAccount());
content.put("userAvatar", userProfile.getUserAvatar());
content.put("countryCode", userProfile.getCountryCode());
content.put("countryName", userProfile.getCountryName());
return content;
}
private static Map<String, Object> senderContent(UserProfile userProfile) {
Map<String, Object> content = new LinkedHashMap<>();
content.put("userNickname", Objects.nonNull(userProfile) ? userProfile.getUserNickname() : null);
content.put("account", Objects.nonNull(userProfile) ? userProfile.getAccount() : null);
content.put("actualAccount", Objects.nonNull(userProfile) ? userProfile.getActualAccount() : null);
content.put("userAvatar", Objects.nonNull(userProfile) ? userProfile.getUserAvatar() : null);
content.put("countryCode", Objects.nonNull(userProfile) ? userProfile.getCountryCode() : null);
content.put("countryName", Objects.nonNull(userProfile) ? userProfile.getCountryName() : null);
return content;
}
private static void putSenderProfile(Map<String, Object> payload, UserProfileDTO userProfile) {
payload.put("account", userProfile.getAccount());
payload.put("actualAccount", userProfile.actualAccount());
payload.put("userNickname", userProfile.getUserNickname());
payload.put("userAvatar", userProfile.getUserAvatar());
}
private static void putSenderProfile(Map<String, Object> payload, UserProfile userProfile) {
if (Objects.isNull(userProfile)) {
return;
}
payload.put("account", userProfile.getAccount());
payload.put("actualAccount", userProfile.getActualAccount());
payload.put("userNickname", userProfile.getUserNickname());
payload.put("userAvatar", userProfile.getUserAvatar());
}
private static void putAcceptProfile(Map<String, Object> payload, UserProfileDTO userProfile) {
payload.put("acceptUserId", userProfile.getId());
payload.put("acceptAccount", userProfile.getAccount());
payload.put("acceptActualAccount", userProfile.actualAccount());
payload.put("acceptNickname", userProfile.getUserNickname());
payload.put("acceptUserNickname", userProfile.getUserNickname());
payload.put("acceptUserAvatar", userProfile.getUserAvatar());
}
private static void putAcceptProfile(Map<String, Object> payload, UserProfile userProfile) {
if (Objects.isNull(userProfile)) {
return;
}
payload.put("acceptUserId", userProfile.getId());
payload.put("acceptAccount", userProfile.getAccount());
payload.put("acceptActualAccount", userProfile.getActualAccount());
payload.put("acceptNickname", userProfile.getUserNickname());
payload.put("acceptUserNickname", userProfile.getUserNickname());
payload.put("acceptUserAvatar", userProfile.getUserAvatar());
}
private static String displayName(UserProfile userProfile) {
if (Objects.isNull(userProfile)) {
return "";
}
if (StringUtils.isNotBlank(userProfile.getUserNickname())) {
return userProfile.getUserNickname();
}
if (StringUtils.isNotBlank(userProfile.getAccount())) {
return userProfile.getAccount();
}
return Objects.toString(userProfile.getId(), "");
}
}

View File

@ -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();
}
}

View File

@ -379,15 +379,15 @@ public class GiftCountStrategy implements GiftStrategy {
if (CollectionUtils.isEmpty(runningWater.getAcceptUsers())) {
return;
}
String relationType = CpRelationshipType.normalize(
runningWater.getGiftValue().getCpRelationType());
String relationType = resolveCpGiftRelationType(runningWater);
BigDecimal applyConsumeGold = cpGiftApplyConsumeGold(runningWater.getGiftValue());
runningWater.getAcceptUsers().forEach(accept -> {
if (Objects.equals(runningWater.getUserId(), accept.getAcceptUserId())) {
return;
}
sendCpApplyCmdExe.autoCreateFromCpGift(
runningWater.getUserId(), accept.getAcceptUserId(), runningWater.getSysOrigin(),
relationType);
relationType, applyConsumeGold);
});
} catch (Exception ex) {
log.warn("[CP] skip auto create cp apply from gift, runningWaterId={}, giftId={}, sendUserId={}, reason={}",
@ -398,6 +398,44 @@ public class GiftCountStrategy implements GiftStrategy {
}
}
private String resolveCpGiftRelationType(GiftGiveRunningWater runningWater) {
String relationType = Objects.nonNull(runningWater.getGiftValue())
? runningWater.getGiftValue().getCpRelationType()
: null;
if (StringUtils.isNotBlank(relationType)) {
return CpRelationshipType.normalize(relationType);
}
String configuredRelationType = cpRelationTypeFromGiftConfig(runningWater);
return CpRelationshipType.normalize(configuredRelationType);
}
private String cpRelationTypeFromGiftConfig(GiftGiveRunningWater runningWater) {
if (Objects.isNull(runningWater) || Objects.isNull(runningWater.getGiftId())) {
log.warn("[CP] cp gift relation type missing and giftId missing, fallback CP. runningWaterId={}",
Objects.nonNull(runningWater) ? runningWater.getId() : null);
return CpRelationshipType.CP.name();
}
GiftConfigDTO giftConfig = cacheGiftConfigManagerService.getById(runningWater.getGiftId());
if (Objects.nonNull(giftConfig) && StringUtils.isNotBlank(giftConfig.getCpRelationType())) {
return giftConfig.getCpRelationType();
}
log.warn("[CP] cp gift relation type missing from running water and config, fallback CP. runningWaterId={}, giftId={}",
runningWater.getId(), runningWater.getGiftId());
return CpRelationshipType.CP.name();
}
private BigDecimal cpGiftApplyConsumeGold(GiftValue giftValue) {
if (Objects.isNull(giftValue) || !GiftCurrencyType.GOLD.eq(giftValue.getCurrencyType())
|| Objects.equals(giftValue.getBag(), Boolean.TRUE)) {
return BigDecimal.ZERO;
}
BigDecimal giftGold = giftValue.getGiftValue();
if (Objects.isNull(giftGold) || giftGold.compareTo(BigDecimal.ZERO) <= 0) {
return BigDecimal.ZERO;
}
return giftGold;
}
private void sendCpBlessNotice(GiftGiveRunningWater runningWater, CpRelationship cpRelationship,
GiftConfigDTO giftConfig) {
UserProfile userProfile = userProfileRepository.getByUserId(runningWater.getUserId());

View File

@ -1,23 +1,29 @@
package com.red.circle.other.app.listener.user;
import com.red.circle.component.mq.MessageEventProcess;
import com.red.circle.component.mq.MessageEventProcessDescribe;
import com.red.circle.component.mq.config.RocketMqMessageListener;
import com.red.circle.component.mq.service.Action;
import com.red.circle.component.mq.service.ConsumerMessage;
import com.red.circle.component.mq.service.MessageListener;
import com.red.circle.mq.business.model.event.user.CpApplyEvent;
import com.red.circle.mq.rocket.business.streams.CpApplySink;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.json.JacksonUtils;
import com.red.circle.other.infra.database.rds.entity.user.user.CpApply;
import com.red.circle.component.mq.MessageEventProcess;
import com.red.circle.component.mq.MessageEventProcessDescribe;
import com.red.circle.component.mq.config.RocketMqMessageListener;
import com.red.circle.component.mq.service.Action;
import com.red.circle.component.mq.service.ConsumerMessage;
import com.red.circle.component.mq.service.MessageListener;
import com.red.circle.external.inner.endpoint.message.ImMessageClient;
import com.red.circle.mq.business.model.event.user.CpApplyEvent;
import com.red.circle.mq.rocket.business.streams.CpApplySink;
import com.red.circle.other.app.common.cp.CpRelationC2cNoticeUtils;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.json.JacksonUtils;
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.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.util.List;
import java.util.Objects;
import com.red.circle.wallet.inner.model.enums.GoldOrigin;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -29,11 +35,13 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequiredArgsConstructor
@RocketMqMessageListener(topic = "${rocketmq.topics.RC_DEFAULT_APP_DELAYED}", groupId = CpApplySink.INPUT, tag = CpApplySink.TAG)
public class CpApplyListener implements MessageListener {
private final CpApplyService cpApplyService;
private final WalletGoldClient walletGoldClient;
private final MessageEventProcess messageEventProcess;
public class CpApplyListener implements MessageListener {
private final CpApplyService cpApplyService;
private final ImMessageClient imMessageClient;
private final UserProfileGateway userProfileGateway;
private final WalletGoldClient walletGoldClient;
private final MessageEventProcess messageEventProcess;
@Override
public Action consume(ConsumerMessage message) {
@ -59,22 +67,38 @@ public class CpApplyListener implements MessageListener {
return;
}
// 等待超时
if (Objects.equals(cpApply.getStatus(), CpApplyStatus.WAIT.name())) {
reimburse(eventBody, cpApply);
}
});
}
// 等待超时
if (Objects.equals(cpApply.getStatus(), CpApplyStatus.WAIT.name())) {
reimburse(eventBody, cpApply, true);
}
});
}
private void checkReimburse(CpApplyEvent param, CpApply cpApply) {
List<CpApply> cpApplies = cpApplyService.listRefuse(cpApply.getAcceptApplyUserId());
if (CollectionUtils.isEmpty(cpApplies)) {
return;
}
cpApplies.forEach(apply -> reimburse(param, apply));
}
private void reimburse(CpApplyEvent param, CpApply cpApply) {
private void checkReimburse(CpApplyEvent param, CpApply cpApply) {
Map<Long, CpApply> applyMap = new LinkedHashMap<>();
addReimburseApplies(applyMap, cpApplyService.listRefuse(cpApply.getAcceptApplyUserId()));
addReimburseApplies(applyMap, cpApplyService.listRefuseBetweenUsers(cpApply.getSendApplyUserId(),
cpApply.getAcceptApplyUserId()));
if (applyMap.isEmpty()) {
return;
}
applyMap.values().forEach(apply -> reimburse(param, apply, false));
}
private void addReimburseApplies(Map<Long, CpApply> applyMap, List<CpApply> cpApplies) {
if (CollectionUtils.isEmpty(cpApplies)) {
return;
}
cpApplies.stream()
.filter(Objects::nonNull)
.filter(apply -> Objects.nonNull(apply.getId()))
.forEach(apply -> applyMap.putIfAbsent(apply.getId(), apply));
}
private void reimburse(CpApplyEvent param, CpApply cpApply, boolean expired) {
if (expired) {
sendExpiredNotice(cpApply);
}
if (Objects.isNull(cpApply.getApplyConsumeGold())
|| cpApply.getApplyConsumeGold().signum() <= 0) {
cpApplyService.changeStatusById(cpApply.getId(), CpApplyStatus.REIMBURSE);
@ -88,7 +112,26 @@ public class CpApplyListener implements MessageListener {
.origin(GoldOrigin.CP_BUILD)
.amount(cpApply.getApplyConsumeGold())
.build());
cpApplyService.changeStatusById(cpApply.getId(), CpApplyStatus.REIMBURSE);
}
}
cpApplyService.changeStatusById(cpApply.getId(), CpApplyStatus.REIMBURSE);
}
private void sendExpiredNotice(CpApply cpApply) {
try {
UserProfile senderProfile = userProfileGateway.getByUserId(cpApply.getSendApplyUserId());
UserProfile acceptProfile = userProfileGateway.getByUserId(cpApply.getAcceptApplyUserId());
if (Objects.isNull(senderProfile) || Objects.isNull(acceptProfile)) {
log.info("[CP] skip expired c2c notice, applyId={}, senderProfile={}, acceptProfile={}",
cpApply.getId(), Objects.nonNull(senderProfile), Objects.nonNull(acceptProfile));
return;
}
imMessageClient.sendCustomMessage(
CpRelationC2cNoticeUtils.buildExpiredToAcceptUser(cpApply, senderProfile, acceptProfile));
imMessageClient.sendCustomMessage(
CpRelationC2cNoticeUtils.buildExpiredToSendUser(cpApply, senderProfile, acceptProfile));
} catch (Exception ex) {
log.warn("[CP] send expired c2c notice failed, applyId={}, reason={}", cpApply.getId(),
ex.getMessage(), ex);
}
}
}

View File

@ -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);
}
}
}

View File

@ -0,0 +1,201 @@
package com.red.circle.other.app.command.user;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.nullable;
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 com.red.circle.external.inner.endpoint.message.ImMessageClient;
import com.red.circle.external.inner.model.cmd.message.CustomC2cMsgBodyCmd;
import com.red.circle.framework.core.dto.ReqSysOrigin;
import com.red.circle.framework.dto.ResultResponse;
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.common.cp.CpRelationBroadcastMqClient;
import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd;
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.cache.service.cp.CpRelationshipCacheService;
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.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.wallet.inner.endpoint.wallet.WalletGoldClient;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
class ProcessCpApplyCmdTest {
@Test
void agreeBrotherApplyShouldCreateBrotherRelationship() {
Fixture fixture = new Fixture("BROTHER");
fixture.exe.execute(processCmd(true));
verify(fixture.cpRelationshipService).addCp(eq(1001L), eq(2001L),
nullable(Long.class), eq("LIKEI"), eq("BROTHER"));
verify(fixture.cpRelationBroadcastMqClient).publish("LIKEI", 3001L, 1001L, 2001L,
"BROTHER");
assertProcessMessage(fixture.sentCustomMessage(), "RELATION_ESTABLISHED", "ACCEPTED",
true, "BROTHER");
}
@Test
void agreeSistersApplyShouldCreateSistersRelationship() {
Fixture fixture = new Fixture("SISTERS");
fixture.exe.execute(processCmd(true));
verify(fixture.cpRelationshipService).addCp(eq(1001L), eq(2001L),
nullable(Long.class), eq("LIKEI"), eq("SISTERS"));
verify(fixture.cpRelationBroadcastMqClient).publish("LIKEI", 3001L, 1001L, 2001L,
"SISTERS");
assertProcessMessage(fixture.sentCustomMessage(), "RELATION_ESTABLISHED", "ACCEPTED",
true, "SISTERS");
}
@Test
void rejectApplyShouldSendRejectedC2cMessageToSender() {
Fixture fixture = new Fixture("CP");
fixture.exe.execute(processCmd(false));
assertProcessMessage(fixture.sentCustomMessage(), "RELATION_REJECTED", "REJECTED",
false, "CP");
}
@Test
void agreeApplyShouldFailWhenPairAlreadyHasAnyRelation() {
Fixture fixture = new Fixture("BROTHER");
when(fixture.cpRelationshipService.existsRelationship(1001L, 2001L)).thenReturn(true);
Assertions.assertThrows(RuntimeException.class, () -> fixture.exe.execute(processCmd(true)));
verify(fixture.cpApplyService, never()).changeStatusById(eq(3001L),
any(CpApplyStatus.class));
verify(fixture.cpRelationshipService, never()).addCp(any(Long.class), any(Long.class),
nullable(Long.class), any(String.class), any(String.class));
verify(fixture.cpRelationBroadcastMqClient, never()).publish(any(String.class),
any(Long.class), any(Long.class), any(Long.class), any(String.class));
verify(fixture.imMessageClient, never()).sendCustomMessage(any(CustomC2cMsgBodyCmd.class));
}
@Test
void agreeApplyShouldRejectOtherWaitAppliesBetweenSameUsers() {
Fixture fixture = new Fixture("CP");
when(fixture.cpApplyService.refuseOtherWaitBetweenUsers(3001L, 1001L, 2001L))
.thenReturn(List.of(3002L, 3003L));
fixture.exe.execute(processCmd(true));
verify(fixture.cpApplyService).refuseOtherWaitBetweenUsers(3001L, 1001L, 2001L);
ArgumentCaptor<CpApplyEvent> eventCaptor = ArgumentCaptor.forClass(CpApplyEvent.class);
verify(fixture.userMqMessageService).cpApplyDelayed(eventCaptor.capture(),
any(Timestamp.class));
Assertions.assertEquals(3001L, eventCaptor.getValue().getId());
}
private static ProcessApplyCmd processCmd(boolean agree) {
ProcessApplyCmd cmd = new ProcessApplyCmd()
.setApplyId(3001L)
.setAgree(agree);
cmd.setReqUserId(2001L);
cmd.setReqSysOrigin(ReqSysOrigin.of("LIKEI", "LIKEI"));
return cmd;
}
private static CpApply apply(String relationType) {
return new CpApply()
.setId(3001L)
.setSendApplyUserId(1001L)
.setAcceptApplyUserId(2001L)
.setRelationType(relationType)
.setStatus(CpApplyStatus.WAIT.name());
}
@SuppressWarnings("unchecked")
private static void assertProcessMessage(CustomC2cMsgBodyCmd message, String action,
String status, Boolean agree, String relationType) {
Assertions.assertEquals("2001", message.getFromAccount());
Assertions.assertEquals("1001", message.getToAccount());
Assertions.assertEquals("CP_BUILD", message.getDesc());
Map<String, Object> data = (Map<String, Object>) message.getData();
Assertions.assertEquals("CP_BUILD", data.get("noticeType"));
Assertions.assertEquals(action, data.get("noticeAction"));
Assertions.assertEquals(action, data.get("action"));
Assertions.assertEquals(status, data.get("status"));
Assertions.assertEquals(status, data.get("result"));
Assertions.assertEquals(status, data.get("state"));
Assertions.assertEquals(agree, data.get("agree"));
Assertions.assertEquals(3001L, data.get("applyId"));
Assertions.assertEquals(relationType, data.get("relationType"));
Assertions.assertTrue(data.get("content").toString()
.contains("\"relationType\":\"" + relationType + "\""));
}
private static class Fixture {
private final CpApplyService cpApplyService = mock(CpApplyService.class);
private final CpRelationshipService cpRelationshipService = mock(CpRelationshipService.class);
private final CpRelationBroadcastMqClient cpRelationBroadcastMqClient = mock(
CpRelationBroadcastMqClient.class);
private final ImMessageClient imMessageClient = mock(ImMessageClient.class);
private final UserMqMessageService userMqMessageService = mock(UserMqMessageService.class);
private final ProcessCpApplyCmd exe;
private Fixture(String relationType) {
CpValueService cpValueService = mock(CpValueService.class);
WalletGoldClient walletGoldClient = mock(WalletGoldClient.class);
UserProfileGateway userProfileGateway = mock(UserProfileGateway.class);
CpRelationshipCacheService cpRelationshipCacheService = mock(
CpRelationshipCacheService.class);
when(cpApplyService.getById(3001L)).thenReturn(apply(relationType));
when(cpApplyService.changeStatusById(3001L, CpApplyStatus.AGREE)).thenReturn(true);
when(cpApplyService.changeStatusById(3001L, CpApplyStatus.REFUSE)).thenReturn(true);
when(cpApplyService.changeStatusById(3001L, CpApplyStatus.REIMBURSE)).thenReturn(true);
when(cpApplyService.refuseOtherWaitBetweenUsers(3001L, 1001L, 2001L))
.thenReturn(List.of());
when(userProfileGateway.getByUserId(1001L)).thenReturn(profile(1001L));
when(userProfileGateway.getByUserId(2001L)).thenReturn(profile(2001L));
when(imMessageClient.sendCustomMessage(any(CustomC2cMsgBodyCmd.class)))
.thenReturn(ResultResponse.success());
exe = new ProcessCpApplyCmd(
cpApplyService,
cpValueService,
imMessageClient,
walletGoldClient,
userMqMessageService,
cpRelationshipService,
userProfileGateway,
cpRelationshipCacheService,
cpRelationBroadcastMqClient);
}
private CustomC2cMsgBodyCmd sentCustomMessage() {
ArgumentCaptor<CustomC2cMsgBodyCmd> captor = ArgumentCaptor.forClass(
CustomC2cMsgBodyCmd.class);
verify(imMessageClient).sendCustomMessage(captor.capture());
return captor.getValue();
}
private static UserProfile profile(Long userId) {
UserProfile userProfile = new UserProfile();
userProfile.setId(userId);
userProfile.setAccount(userId.toString());
userProfile.setUserNickname("user-" + userId);
userProfile.setCountryCode("SA");
userProfile.setCountryName("Saudi Arabia");
return userProfile;
}
}
}

View File

@ -4,14 +4,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
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 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.endpoint.message.ImMessageClient;
import com.red.circle.external.inner.model.cmd.message.CustomC2cMsgBodyCmd;
import com.red.circle.framework.dto.ResultResponse;
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.domain.gateway.user.UserProfileGateway;
@ -23,6 +25,9 @@ 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.inner.model.dto.user.UserProfileDTO;
import com.red.circle.wallet.inner.endpoint.wallet.WalletGoldClient;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@ -49,6 +54,61 @@ class SendCpApplyCmdExeTest {
verify(fixture.cpApplyService, never()).save(any(CpApply.class));
}
@Test
void autoCreateFromCpGiftShouldSkipWhenAnyRelationAlreadyExistsInEitherDirection() {
Fixture fixture = new Fixture(1, 0);
when(fixture.cpRelationshipService.existsRelationship(1001L, 2001L)).thenReturn(true);
assertFalse(fixture.exe.autoCreateFromCpGift(1001L, 2001L, "LIKEI", "BROTHER"));
verify(fixture.cpApplyService, never()).save(any(CpApply.class));
verify(fixture.imMessageClient, never()).sendCustomMessage(any(CustomC2cMsgBodyCmd.class));
verify(fixture.userMqMessageService, never()).cpApplyDelayed(any(CpApplyEvent.class),
any(Timestamp.class));
Fixture reverseFixture = new Fixture(1, 0);
when(reverseFixture.cpRelationshipService.existsRelationship(2001L, 1001L)).thenReturn(true);
assertFalse(reverseFixture.exe.autoCreateFromCpGift(2001L, 1001L, "LIKEI", "SISTERS"));
verify(reverseFixture.cpApplyService, never()).save(any(CpApply.class));
verify(reverseFixture.imMessageClient, never()).sendCustomMessage(any(CustomC2cMsgBodyCmd.class));
verify(reverseFixture.userMqMessageService, never()).cpApplyDelayed(any(CpApplyEvent.class),
any(Timestamp.class));
}
@Test
void autoCreateFromCpGiftShouldCreateIndependentAppliesForDifferentRelationTypes() {
Fixture fixture = new Fixture(1, 0);
assertTrue(fixture.exe.autoCreateFromCpGift(1001L, 2001L, "LIKEI", "CP"));
assertTrue(fixture.exe.autoCreateFromCpGift(1001L, 2001L, "LIKEI", "BROTHER"));
assertTrue(fixture.exe.autoCreateFromCpGift(1001L, 2001L, "LIKEI", "SISTERS"));
List<CpApply> applies = fixture.savedApplies(3);
assertEquals("CP", applies.get(0).getRelationType());
assertEquals("BROTHER", applies.get(1).getRelationType());
assertEquals("SISTERS", applies.get(2).getRelationType());
List<CustomC2cMsgBodyCmd> messages = fixture.sentCustomMessages(3);
assertEquals("1001", messages.get(0).getFromAccount());
assertEquals("2001", messages.get(0).getToAccount());
assertCpBuildMessage(messages.get(0), "CP", 3001L);
assertCpBuildMessage(messages.get(1), "BROTHER", 3002L);
assertCpBuildMessage(messages.get(2), "SISTERS", 3003L);
}
@SuppressWarnings("unchecked")
private static void assertCpBuildMessage(CustomC2cMsgBodyCmd message, String relationType,
Long applyId) {
assertEquals("CP_BUILD", message.getDesc());
Map<String, Object> data = (Map<String, Object>) message.getData();
assertEquals("CP_BUILD", data.get("noticeType"));
assertEquals("CP_BUILD", data.get("type"));
assertEquals(applyId, data.get("expand"));
assertEquals(applyId, data.get("applyId"));
assertEquals(relationType, data.get("relationType"));
assertTrue(data.get("content").toString().contains("\"relationType\":\"" + relationType + "\""));
}
@Test
void autoCreateFromCpGiftShouldSkipSelfGift() {
Fixture fixture = new Fixture(1, 1);
@ -61,33 +121,42 @@ class SendCpApplyCmdExeTest {
private static class Fixture {
private final CpApplyService cpApplyService = mock(CpApplyService.class);
private final ImMessageClient imMessageClient = mock(ImMessageClient.class);
private final UserMqMessageService userMqMessageService = mock(UserMqMessageService.class);
private final CpRelationshipService cpRelationshipService = mock(CpRelationshipService.class);
private final UserRegionGateway userRegionGateway = mock(UserRegionGateway.class);
private final SendCpApplyCmdExe exe;
private long nextApplyId = 3001L;
private Fixture(Integer sendSex, Integer acceptSex) {
OfficialNoticeClient officialNoticeClient = mock(OfficialNoticeClient.class);
WalletGoldClient walletGoldClient = mock(WalletGoldClient.class);
UserMqMessageService userMqMessageService = mock(UserMqMessageService.class);
CpRelationshipService cpRelationshipService = mock(CpRelationshipService.class);
EnumConfigCacheService enumConfigCacheService = mock(EnumConfigCacheService.class);
UserProfileGateway userProfileGateway = mock(UserProfileGateway.class);
UserProfileAppConvertor userProfileAppConvertor = mock(UserProfileAppConvertor.class);
UserProfile sendProfile = new UserProfile();
sendProfile.setId(1001L);
UserProfile acceptProfile = new UserProfile();
acceptProfile.setId(2001L);
UserProfileDTO sendProfileDTO = profile(1001L, sendSex);
UserProfileDTO acceptProfileDTO = profile(2001L, acceptSex);
when(userRegionGateway.checkEqRegion(1001L, 2001L)).thenReturn(true);
when(userRegionGateway.checkEqRegion(2001L, 1001L)).thenReturn(true);
when(userProfileGateway.getByUserId(1001L)).thenReturn(sendProfile);
when(userProfileGateway.getByUserId(2001L)).thenReturn(acceptProfile);
when(userProfileAppConvertor.toUserProfileDTO(sendProfile)).thenReturn(sendProfileDTO);
when(userProfileAppConvertor.toUserProfileDTO(acceptProfile)).thenReturn(acceptProfileDTO);
when(officialNoticeClient.send(any(NoticeExtTemplateTypeCmd.class)))
when(imMessageClient.sendCustomMessage(any(CustomC2cMsgBodyCmd.class)))
.thenReturn(ResultResponse.success());
when(cpApplyService.save(any(CpApply.class))).thenAnswer(invocation -> {
CpApply apply = invocation.getArgument(0);
apply.setId(nextApplyId++);
return true;
});
exe = new SendCpApplyCmdExe(
cpApplyService,
officialNoticeClient,
imMessageClient,
walletGoldClient,
userMqMessageService,
cpRelationshipService,
@ -99,9 +168,19 @@ class SendCpApplyCmdExeTest {
}
private CpApply savedApply() {
return savedApplies(1).get(0);
}
private List<CpApply> savedApplies(int count) {
ArgumentCaptor<CpApply> captor = ArgumentCaptor.forClass(CpApply.class);
verify(cpApplyService).save(captor.capture());
return captor.getValue();
verify(cpApplyService, times(count)).save(captor.capture());
return captor.getAllValues();
}
private List<CustomC2cMsgBodyCmd> sentCustomMessages(int count) {
ArgumentCaptor<CustomC2cMsgBodyCmd> captor = ArgumentCaptor.forClass(CustomC2cMsgBodyCmd.class);
verify(imMessageClient, times(count)).sendCustomMessage(captor.capture());
return captor.getAllValues();
}
private static UserProfileDTO profile(Long userId, Integer sex) {

View File

@ -0,0 +1,103 @@
package com.red.circle.other.app.listener.user;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.component.mq.MessageEventProcess;
import com.red.circle.component.mq.MessageEventProcessDescribe;
import com.red.circle.component.mq.service.Action;
import com.red.circle.component.mq.service.ConsumerMessage;
import com.red.circle.external.inner.endpoint.message.ImMessageClient;
import com.red.circle.external.inner.model.cmd.message.CustomC2cMsgBodyCmd;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.mq.business.model.event.user.CpApplyEvent;
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.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.wallet.inner.endpoint.wallet.WalletGoldClient;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
class CpApplyListenerTest {
@Test
void waitApplyExpiredShouldSendC2cMessageToBothUsers() {
CpApplyService cpApplyService = mock(CpApplyService.class);
ImMessageClient imMessageClient = mock(ImMessageClient.class);
UserProfileGateway userProfileGateway = mock(UserProfileGateway.class);
WalletGoldClient walletGoldClient = mock(WalletGoldClient.class);
MessageEventProcess messageEventProcess = mock(MessageEventProcess.class);
CpApply apply = new CpApply()
.setId(3001L)
.setSendApplyUserId(1001L)
.setAcceptApplyUserId(2001L)
.setRelationType("SISTERS")
.setStatus(CpApplyStatus.WAIT.name());
when(cpApplyService.getById(3001L)).thenReturn(apply);
when(cpApplyService.changeStatusById(3001L, CpApplyStatus.REIMBURSE)).thenReturn(true);
when(userProfileGateway.getByUserId(1001L)).thenReturn(profile(1001L));
when(userProfileGateway.getByUserId(2001L)).thenReturn(profile(2001L));
when(imMessageClient.sendCustomMessage(any(CustomC2cMsgBodyCmd.class)))
.thenReturn(ResultResponse.success());
when(messageEventProcess.consume(any(MessageEventProcessDescribe.class),
eq(CpApplyEvent.class), any())).thenAnswer(invocation -> {
@SuppressWarnings("unchecked")
Consumer<CpApplyEvent> consumer = invocation.getArgument(2, Consumer.class);
consumer.accept(new CpApplyEvent()
.setId(3001L)
.setSysOrigin(SysOriginPlatformEnum.LIKEI));
return Action.SUCCESS;
});
CpApplyListener listener = new CpApplyListener(cpApplyService, imMessageClient,
userProfileGateway, walletGoldClient, messageEventProcess);
assertEquals(Action.SUCCESS, listener.consume(new ConsumerMessage()));
ArgumentCaptor<CustomC2cMsgBodyCmd> captor = ArgumentCaptor.forClass(
CustomC2cMsgBodyCmd.class);
verify(imMessageClient, org.mockito.Mockito.times(2)).sendCustomMessage(captor.capture());
List<CustomC2cMsgBodyCmd> messages = captor.getAllValues();
assertExpiredMessage(messages.get(0), "1001", "2001");
assertExpiredMessage(messages.get(1), "2001", "1001");
}
@SuppressWarnings("unchecked")
private static void assertExpiredMessage(CustomC2cMsgBodyCmd message, String fromAccount,
String toAccount) {
assertEquals(fromAccount, message.getFromAccount());
assertEquals(toAccount, message.getToAccount());
assertEquals("CP_BUILD", message.getDesc());
Map<String, Object> data = (Map<String, Object>) message.getData();
assertEquals("RELATION_EXPIRED", data.get("noticeAction"));
assertEquals("RELATION_EXPIRED", data.get("action"));
assertEquals("EXPIRED", data.get("status"));
assertEquals("EXPIRED", data.get("result"));
assertEquals("EXPIRED", data.get("state"));
assertEquals(Boolean.TRUE, data.get("expired"));
assertEquals("SISTERS", data.get("relationType"));
assertTrue(data.get("content").toString().contains("\"relationType\":\"SISTERS\""));
}
private static UserProfile profile(Long userId) {
UserProfile userProfile = new UserProfile();
userProfile.setId(userId);
userProfile.setAccount(userId.toString());
userProfile.setUserNickname("user-" + userId);
userProfile.setCountryCode("SA");
userProfile.setCountryName("Saudi Arabia");
return userProfile;
}
}

View File

@ -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.
*/

View File

@ -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位置起步金额.

View File

@ -89,9 +89,19 @@ public interface CpApplyService extends BaseService<CpApply> {
* 拒绝指定类型所有等待状态.
*/
void refuseStatusWait(Long acceptApplyUserId, String relationType);
/**
* 获取我拒绝都信息.
/**
* 拒绝两个用户之间除指定申请外的其他等待申请.
*/
List<Long> refuseOtherWaitBetweenUsers(Long excludeApplyId, Long userId, Long cpUserId);
/**
* 获取两个用户之间已拒绝的申请.
*/
List<CpApply> listRefuseBetweenUsers(Long userId, Long cpUserId);
/**
* 获取我拒绝都信息.
*/
List<CpApply> listRefuse(Long userId);

View File

@ -36,9 +36,14 @@ public interface CpRelationshipService extends BaseService<CpRelationship> {
*/
boolean existsCp(Long userId, Long cpUserId, String relationType);
/**
* 获取分手中的cp信息集合
*/
/**
* 两个用户之间是否存在任意正常关系.
*/
boolean existsRelationship(Long userId, Long cpUserId);
/**
* 获取分手中的cp信息集合
*/
List<CpRelationship> getDismissingByUserId(Long userId);
/**

View File

@ -115,19 +115,61 @@ public class CpApplyServiceImpl extends BaseServiceImpl<CpApplyDAO, CpApply> imp
.eq(CpApply::getRelationType, CpRelationshipType.normalize(relationType))
.eq(CpApply::getAcceptApplyUserId, acceptApplyUserId)
.execute();
}
@Override
public List<CpApply> listRefuse(Long userId) {
return query()
.eq(CpApply::getStatus, CpApplyStatus.REFUSE)
}
@Override
public List<Long> refuseOtherWaitBetweenUsers(Long excludeApplyId, Long userId, Long cpUserId) {
List<Long> applyIds = query()
.select(CpApply::getId)
.eq(CpApply::getStatus, CpApplyStatus.WAIT)
.ne(Objects.nonNull(excludeApplyId), CpApply::getId, excludeApplyId)
.and(where -> where
.nested(w -> w.eq(CpApply::getSendApplyUserId, userId)
.eq(CpApply::getAcceptApplyUserId, cpUserId))
.or()
.nested(w -> w.eq(CpApply::getSendApplyUserId, cpUserId)
.eq(CpApply::getAcceptApplyUserId, userId)))
.list()
.stream()
.map(CpApply::getId)
.filter(Objects::nonNull)
.toList();
if (applyIds.isEmpty()) {
return applyIds;
}
update()
.set(CpApply::getStatus, CpApplyStatus.REFUSE)
.set(CpApply::getUpdateTime, LocalDateTime.now())
.in(CpApply::getId, applyIds)
.execute();
return applyIds;
}
@Override
public List<CpApply> listRefuse(Long userId) {
return query()
.eq(CpApply::getStatus, CpApplyStatus.REFUSE)
.eq(CpApply::getAcceptApplyUserId, userId)
.last(PageConstant.MAX_LIMIT)
.list();
}
@Override
public PageResult<CpApply> pageCpApply(CpApplyQryCmd query) {
.last(PageConstant.MAX_LIMIT)
.list();
}
@Override
public List<CpApply> listRefuseBetweenUsers(Long userId, Long cpUserId) {
return query()
.eq(CpApply::getStatus, CpApplyStatus.REFUSE)
.and(where -> where
.nested(w -> w.eq(CpApply::getSendApplyUserId, userId)
.eq(CpApply::getAcceptApplyUserId, cpUserId))
.or()
.nested(w -> w.eq(CpApply::getSendApplyUserId, cpUserId)
.eq(CpApply::getAcceptApplyUserId, userId)))
.last(PageConstant.MAX_LIMIT)
.list();
}
@Override
public PageResult<CpApply> pageCpApply(CpApplyQryCmd query) {
return query()
.eq(Objects.nonNull(query.getSendApplyUserId()), CpApply::getSendApplyUserId,
query.getSendApplyUserId())

View File

@ -66,10 +66,25 @@ public class CpRelationshipServiceImpl extends
.nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId))
)
.last(PageConstant.LIMIT_ONE)
.getOne()
).map(cpRelationship -> Objects.nonNull(cpRelationship.getId())).orElse(Boolean.FALSE);
}
.getOne()
).map(cpRelationship -> Objects.nonNull(cpRelationship.getId())).orElse(Boolean.FALSE);
}
@Override
public boolean existsRelationship(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()
.nested(w -> w.eq(CpRelationship::getUserId, cpUserId).eq(CpRelationship::getCpUserId, userId))
)
.last(PageConstant.LIMIT_ONE)
.getOne()
).map(cpRelationship -> Objects.nonNull(cpRelationship.getId())).orElse(Boolean.FALSE);
}
@Override
public List<CpRelationship> getDismissingByUserId(Long userId) {
return getDismissingByUserId(userId, CpRelationshipType.CP.name());

View File

@ -215,8 +215,9 @@ public class CpLocalFlowSmokeTest {
}
private void assertGiftAutoApplyRelationType(UserPair pair, String relationType) {
BigDecimal giftConsumeGold = BigDecimal.valueOf(66);
boolean created = sendCpApplyCmdExe.autoCreateFromCpGift(pair.sendUserId,
pair.acceptUserId, SYS_ORIGIN, relationType);
pair.acceptUserId, SYS_ORIGIN, relationType, giftConsumeGold);
assertTrue(relationType + " gift should auto create apply", created);
Long applyId = cpApplyService.getId(pair.acceptUserId, pair.sendUserId, relationType);
@ -225,12 +226,21 @@ public class CpLocalFlowSmokeTest {
CpApply apply = cpApplyService.getById(applyId);
assertEquals(relationType, apply.getRelationType());
assertEquals(0, BigDecimal.ZERO.compareTo(apply.getApplyConsumeGold()));
assertEquals(0, giftConsumeGold.compareTo(apply.getApplyConsumeGold()));
agree(applyId, pair.acceptUserId);
CpRelationship relationship = cpRelationshipService.getByUserId(pair.sendUserId,
pair.acceptUserId, relationType);
assertNotNull(relationType + " relationship after gift auto apply agree", relationship);
assertEquals(relationType, relationship.getRelationType());
createdPairs.add(new RelationPair(pair.sendUserId, pair.acceptUserId, relationType));
createdCpValIds.add(relationship.getCpValId());
}
private void runCpGiftApplyBlessDismissFlow(UserPair pair) throws Exception {
BigDecimal giftConsumeGold = BigDecimal.valueOf(88);
boolean created = sendCpApplyCmdExe.autoCreateFromCpGift(pair.sendUserId, pair.acceptUserId,
SYS_ORIGIN);
SYS_ORIGIN, giftConsumeGold);
Long pendingApplyId = cpApplyService.getId(pair.acceptUserId, pair.sendUserId, "CP");
if (pendingApplyId != null && !createdApplyIds.contains(pendingApplyId)) {
createdApplyIds.add(pendingApplyId);
@ -243,7 +253,7 @@ public class CpLocalFlowSmokeTest {
CpApply apply = cpApplyService.getById(applyId);
assertEquals("CP", apply.getRelationType());
assertEquals(0, BigDecimal.ZERO.compareTo(apply.getApplyConsumeGold()));
assertEquals(0, giftConsumeGold.compareTo(apply.getApplyConsumeGold()));
agree(applyId, pair.acceptUserId);
CpRelationship relationship = cpRelationshipService.getByUserId(pair.sendUserId,