cp功能完善2

This commit is contained in:
tianfeng 2025-12-10 14:47:09 +08:00
parent 6852d82604
commit b957576aa2
6 changed files with 33 additions and 19 deletions

View File

@ -50,7 +50,14 @@ public enum UserRelationErrorCode implements IResponseErrorCode {
/** /**
* 不可用操作自己. * 不可用操作自己.
*/ */
UNAVAILABLE_OPS_YOURSELF(4309, "Unavailable to operate yourself"); UNAVAILABLE_OPS_YOURSELF(4309, "Unavailable to operate yourself"),
/**
* 不支持同性别用户.
*/
UNAVAILABLE_SAME_GENDER(4310, "Couples of the same gender cannot be created."),
;
private final Integer code; private final Integer code;

View File

@ -36,7 +36,6 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor @RequiredArgsConstructor
public class ProcessCpApplyCmd { public class ProcessCpApplyCmd {
private final RedisService redisService;
private final CpApplyService cpApplyService; private final CpApplyService cpApplyService;
private final CpValueService cpValueService; private final CpValueService cpValueService;
private final ImMessageClient imMessageClient; private final ImMessageClient imMessageClient;
@ -45,13 +44,7 @@ public class ProcessCpApplyCmd {
private final CpRelationshipService cpRelationshipService; private final CpRelationshipService cpRelationshipService;
public void execute(ProcessApplyCmd cmd) { public void execute(ProcessApplyCmd cmd) {
String key = "CProcess_" + cmd.getApplyId(); process(cmd);
try {
ResponseAssert.isTrue(CommonErrorCode.REQUEST_LIMITING, redisService.lock(key, 60));
process(cmd);
} finally {
redisService.unlock(key);
}
} }
private void process(ProcessApplyCmd cmd) { private void process(ProcessApplyCmd cmd) {

View File

@ -43,7 +43,6 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor @RequiredArgsConstructor
public class SendCpApplyCmdExe { public class SendCpApplyCmdExe {
private final RedisService redisService;
private final CpApplyService cpApplyService; private final CpApplyService cpApplyService;
private final OfficialNoticeClient officialNoticeClient; private final OfficialNoticeClient officialNoticeClient;
private final WalletGoldClient walletGoldClient; private final WalletGoldClient walletGoldClient;
@ -72,10 +71,9 @@ public class SendCpApplyCmdExe {
ResponseAssert.isFalse(UserRelationErrorCode.OTHER_SIDE_ALREADY_APPLIED, ResponseAssert.isFalse(UserRelationErrorCode.OTHER_SIDE_ALREADY_APPLIED,
cpApplyService.exists(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId())); cpApplyService.exists(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId()));
// 防止重复触发 UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.requiredReqUserId()));
ResponseAssert.isTrue(CommonErrorCode.REPEATED_SUBMISSION, redisService.setIfAbsent( UserProfileDTO acceptUserProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.getAcceptApplyUserId()));
"SEND_CP_APPLY:" + cmd.requiredReqUserId() + "_" + cmd.getAcceptApplyUserId(), 10, ResponseAssert.isFalse(UserRelationErrorCode.UNAVAILABLE_SAME_GENDER, Objects.equals(userProfile.getUserSex(), acceptUserProfile.getUserSex()));
TimeUnit.SECONDS));
WalletReceiptResDTO receipt = ResponseAssert.requiredSuccess( WalletReceiptResDTO receipt = ResponseAssert.requiredSuccess(
walletGoldClient.changeBalance(GoldReceiptCmd.builder() walletGoldClient.changeBalance(GoldReceiptCmd.builder()
@ -89,8 +87,6 @@ public class SendCpApplyCmdExe {
.build()) .build())
); );
UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.requiredReqUserId()));
String applyText = "User " + userProfile.getUserNickname() + " confessed the feeling to you; if you accept, you will become a couple."; String applyText = "User " + userProfile.getUserNickname() + " confessed the feeling to you; if you accept, you will become a couple.";
CpApply cpApply = new CpApply() CpApply cpApply = new CpApply()

View File

@ -13,6 +13,8 @@ import com.red.circle.other.infra.database.rds.entity.user.user.CpRelationship;
import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService; import com.red.circle.other.infra.database.rds.service.user.user.CpRelationshipService;
import com.red.circle.other.inner.asserts.user.UserErrorCode; import com.red.circle.other.inner.asserts.user.UserErrorCode;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO; import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import java.time.ZoneId;
import java.util.Objects; import java.util.Objects;
import com.red.circle.tool.core.date.LocalDateTimeUtils; import com.red.circle.tool.core.date.LocalDateTimeUtils;
@ -47,7 +49,9 @@ public class UserCpPairUserProfileQryExe {
return new CpPairUserProfileCO() return new CpPairUserProfileCO()
.setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser))) .setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser)))
.setCpUserProfile(getUserProfile(cpRelationship.getCpUserId())) .setCpUserProfile(getUserProfile(cpRelationship.getCpUserId()))
.setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now())); .setDays(DateUtils.toDurationDays(cpRelationship.getCreateTime(), DateUtils.now()))
.setFirstDay(cpRelationship.getCreateTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString())
;
} }
private UserProfileDTO getUserProfile(Long cpUserId) { private UserProfileDTO getUserProfile(Long cpUserId) {

View File

@ -16,6 +16,7 @@ import com.red.circle.other.app.dto.clientobject.user.relation.cp.CpUserProfileC
import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.CpApplyCmd;
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.app.dto.cmd.user.relation.cp.ProcessApplyCmd; import com.red.circle.other.app.dto.cmd.user.relation.cp.ProcessApplyCmd;
import com.red.circle.other.app.util.DistributedLockUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -35,6 +36,7 @@ public class UserCpRelationServiceImpl implements UserCpRelationService {
private final UserCpRelationQryExe userCpRelationQryExe; private final UserCpRelationQryExe userCpRelationQryExe;
private final UserCpPairUserProfileQryExe userCpPairUserProfileQryExe; private final UserCpPairUserProfileQryExe userCpPairUserProfileQryExe;
private final UserCpRelationQueryV4Exe userCpRelationQueryV4Exe; private final UserCpRelationQueryV4Exe userCpRelationQueryV4Exe;
private final DistributedLockUtil distributedLockUtil;
@Override @Override
public CpUserProfileCO getCpUser(UserIdCmd cmd) { public CpUserProfileCO getCpUser(UserIdCmd cmd) {
@ -48,12 +50,18 @@ public class UserCpRelationServiceImpl implements UserCpRelationService {
@Override @Override
public void sendApply(CpApplyCmd cmd) { public void sendApply(CpApplyCmd cmd) {
sendCpApplyCmdExe.execute(cmd); String key = "SEND_CP_APPLY:" + cmd.getReqUserId() + "_" + cmd.getAcceptApplyUserId();
distributedLockUtil.executeWithLock(key, () -> {
sendCpApplyCmdExe.execute(cmd);
});
} }
@Override @Override
public void processApply(ProcessApplyCmd cmd) { public void processApply(ProcessApplyCmd cmd) {
processCpApplyCmd.execute(cmd); String key = "PROCESS_CP_APPLY:" + cmd.getApplyId();
distributedLockUtil.executeWithLock(key, () -> {
processCpApplyCmd.execute(cmd);
});
} }
@Override @Override

View File

@ -36,4 +36,10 @@ public class CpPairUserProfileCO extends ClientObject {
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long days; private Long days;
/**
* 开始组件的日期
*/
private String firstDay;
} }