chore: checkpoint before switching to main

This commit is contained in:
2026-09-11 09:07:41 +08:00
parent c20301ffff
commit ac2327b499
17 changed files with 297 additions and 96 deletions
@@ -162,8 +162,12 @@ public class RelationshipService {
com.danyang.match.platform.relationship.entity.UserRelation r2 = relationMapper.findByRelation(targetUserId, userId, Constants.RELATION_TYPE_LIKED).orElse(null);
if (r2 != null) relationMapper.deleteById(r2.getId());
// 解除已有的Match
unmatch(userId, targetUserId);
// 仅解除已有 Match;没有 Match 不能导致拉黑事务回滚。
matchMapper.findActiveMatch(userId, targetUserId).ifPresent(match -> {
match.setStatus(Constants.MATCH_STATUS_UNMATCHED);
match.setUnmatchedAt(Instant.now());
matchMapper.updateById(match);
});
log.info("拉黑用户: userId={}, targetUserId={}", userId, targetUserId);
saveAuditLog(userId, "BLOCK", "user_relation", targetUserId, null, null);
@@ -187,33 +187,23 @@ public class RelationshipStatusService {
}
String reqStatus = request.getStatus();
if (Constants.SUCCESS_REQUEST_STATUS_CONFIRMED.equals(reqStatus)) {
throw new GlobalExceptionHandler.BusinessException(
ApiResponseCode.CONFLICT, "该成功牵手请求已确认");
}
if (Constants.SUCCESS_REQUEST_STATUS_DECLINED.equals(reqStatus)) {
throw new GlobalExceptionHandler.BusinessException(
ApiResponseCode.CONFLICT, "该成功牵手邀请已被拒绝");
}
// 3. 查找另一方的确认状态
// 发起方调用时: otherUserId = targetUserId(对方)
// 响应方调用时: otherUserId = initiatedBy(发起方)
boolean isInitiator = userId.equals(request.getInitiatedBy());
String otherUserId = isInitiator ? targetUserId : request.getInitiatedBy();
RelationshipSuccessRequest otherConfirm = successRequestMapper.selectOne(
new LambdaQueryWrapper<RelationshipSuccessRequest>()
.eq(RelationshipSuccessRequest::getMatchId, match.getId())
.eq(RelationshipSuccessRequest::getInitiatedBy, otherUserId)
.eq(RelationshipSuccessRequest::getStatus, Constants.SUCCESS_REQUEST_STATUS_CONFIRMED)
.isNull(RelationshipSuccessRequest::getDeletedAt)
.last("LIMIT 1"));
boolean secondConfirmation = Constants.SUCCESS_REQUEST_STATUS_CONFIRMED.equals(reqStatus);
if (secondConfirmation && userId.equals(request.getConfirmedBy())) {
throw new GlobalExceptionHandler.BusinessException(
ApiResponseCode.CONFLICT, "您已确认过该成功牵手请求");
}
String otherUserId = userId.equals(match.getUserAId()) ? match.getUserBId() : match.getUserAId();
// 5. 标记当前用户已确认
request.setConfirmedBy(userId);
request.setResolvedAt(Instant.now());
if (otherConfirm != null) {
if (secondConfirmation) {
// ===== 双方都已确认 → 执行成功牵手 =====
match.setStatus(Constants.MATCH_STATUS_SUCCESSFUL);
match.setSuccessfulAt(Instant.now());