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;

View File

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

View File

@ -43,7 +43,6 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor
public class SendCpApplyCmdExe {
private final RedisService redisService;
private final CpApplyService cpApplyService;
private final OfficialNoticeClient officialNoticeClient;
private final WalletGoldClient walletGoldClient;
@ -72,10 +71,9 @@ public class SendCpApplyCmdExe {
ResponseAssert.isFalse(UserRelationErrorCode.OTHER_SIDE_ALREADY_APPLIED,
cpApplyService.exists(cmd.requiredReqUserId(), cmd.getAcceptApplyUserId()));
// 防止重复触发
ResponseAssert.isTrue(CommonErrorCode.REPEATED_SUBMISSION, redisService.setIfAbsent(
"SEND_CP_APPLY:" + cmd.requiredReqUserId() + "_" + cmd.getAcceptApplyUserId(), 10,
TimeUnit.SECONDS));
UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.requiredReqUserId()));
UserProfileDTO acceptUserProfile = userProfileAppConvertor.toUserProfileDTO(userProfileGateway.getByUserId(cmd.getAcceptApplyUserId()));
ResponseAssert.isFalse(UserRelationErrorCode.UNAVAILABLE_SAME_GENDER, Objects.equals(userProfile.getUserSex(), acceptUserProfile.getUserSex()));
WalletReceiptResDTO receipt = ResponseAssert.requiredSuccess(
walletGoldClient.changeBalance(GoldReceiptCmd.builder()
@ -89,8 +87,6 @@ public class SendCpApplyCmdExe {
.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.";
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.inner.asserts.user.UserErrorCode;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import java.time.ZoneId;
import java.util.Objects;
import com.red.circle.tool.core.date.LocalDateTimeUtils;
@ -47,7 +49,9 @@ public class UserCpPairUserProfileQryExe {
return new CpPairUserProfileCO()
.setMeUserProfile(userProfileAppConvertor.toUserProfileDTO((meUser)))
.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) {

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

View File

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