diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/BeautifulNumberApplyRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/BeautifulNumberApplyRestController.java index 5d46bbc4..5e71740b 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/BeautifulNumberApplyRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/BeautifulNumberApplyRestController.java @@ -2,6 +2,7 @@ package com.red.circle.other.adapter.app.user.user; import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.framework.web.controller.BaseController; +import com.red.circle.other.app.dto.cmd.user.user.UserSpecialIdApplyCmd; import com.red.circle.other.app.service.user.user.BeautifulNumberApplyService; import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; @@ -34,7 +35,7 @@ public class BeautifulNumberApplyRestController extends BaseController { * @eo.request-type formdata */ @PostMapping - public void apply(AppExtCommand cmd) { + public void apply(UserSpecialIdApplyCmd cmd) { beautifulNumberApplyService.apply(cmd); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserBeautifulNumberApplyCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserBeautifulNumberApplyCmdExe.java index a50bba5a..30602267 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserBeautifulNumberApplyCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserBeautifulNumberApplyCmdExe.java @@ -3,6 +3,10 @@ package com.red.circle.other.app.command.user; import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; +import com.red.circle.other.app.dto.cmd.user.user.UserSpecialIdApplyCmd; +import com.red.circle.other.infra.database.mongo.entity.user.profile.UserSpecialId; +import com.red.circle.other.infra.database.mongo.service.user.profile.UserSpecialIdService; +import com.red.circle.other.infra.enums.user.user.SpecialIdPatternEnum; import com.red.circle.tool.core.sequence.IdWorkerUtils; import com.red.circle.other.domain.gateway.user.UserProfileGateway; import com.red.circle.other.infra.database.rds.entity.user.user.UserBeautifulNumberApply; @@ -22,14 +26,29 @@ public class UserBeautifulNumberApplyCmdExe { private final UserProfileGateway userProfileGateway; private final UserBeautifulNumberApplyService userBeautifulNumberApplyService; + private final UserSpecialIdService userSpecialIdService; - public void execute(AppExtCommand cmd) { + public void execute(UserSpecialIdApplyCmd cmd) { - ResponseAssert.isTrue( - UserErrorCode.INSUFFICIENT_LEVEL_30_ERROR, getUserLevelExperience(cmd) >= 30); + // 验证账号是否符合当前等级的靓号规则 + boolean isValidForLevel = SpecialIdPatternEnum.isValidForLevel( + cmd.getAccount(), + cmd.getWealthLevel() + ); + ResponseAssert.isTrue(CommonErrorCode.SAVE_FAILURE,"The account does not meet the current wealth level rules", isValidForLevel); + + // 检查靓号是否已存在 + boolean exists = userSpecialIdService.exists(cmd.getReqSysOrigin().getOrigin(), cmd.getAccount()); + ResponseAssert.isFalse(CommonErrorCode.SAVE_FAILURE, "The beautiful number already exists",exists); ResponseAssert.isFalse(CommonErrorCode.REPEATED_SUBMISSION, isExistPending(cmd)); + // 检查用户是否已有靓号,如果有则删除 + UserSpecialId oldSpecialId = userSpecialIdService.getByUserId(cmd.getUserId()); + if (oldSpecialId != null) { + userSpecialIdService.remove(oldSpecialId.getId()); + } + userBeautifulNumberApplyService.save(new UserBeautifulNumberApply() .setId(IdWorkerUtils.getId()) .setApplyUser(cmd.requiredReqUserId()) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/BeautifulNumberApplyServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/BeautifulNumberApplyServiceImpl.java index 8eb84329..e56f9de1 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/BeautifulNumberApplyServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/user/BeautifulNumberApplyServiceImpl.java @@ -3,6 +3,7 @@ package com.red.circle.other.app.service.user.user; import com.red.circle.common.business.dto.cmd.AppExtCommand; import com.red.circle.other.app.command.user.UserBeautifulNumberApplyCmdExe; import com.red.circle.other.app.command.user.query.ExistUserBeautifulNumberQryExe; +import com.red.circle.other.app.dto.cmd.user.user.UserSpecialIdApplyCmd; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,7 +20,7 @@ public class BeautifulNumberApplyServiceImpl implements BeautifulNumberApplyServ private final ExistUserBeautifulNumberQryExe existUserBeautifulNumberQryExe; @Override - public void apply(AppExtCommand cmd) { + public void apply(UserSpecialIdApplyCmd cmd) { userBeautifulNumberApplyCmdExe.execute(cmd); } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserSpecialIdApplyCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserSpecialIdApplyCmd.java new file mode 100644 index 00000000..9c25d768 --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/UserSpecialIdApplyCmd.java @@ -0,0 +1,17 @@ +package com.red.circle.other.app.dto.cmd.user.user; + +import com.red.circle.common.business.dto.cmd.AppExtCommand; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class UserSpecialIdApplyCmd extends AppExtCommand { + + private String account; + + private Long userId; + + private Integer wealthLevel; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/user/BeautifulNumberApplyService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/user/BeautifulNumberApplyService.java index 014451e3..b59ca056 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/user/BeautifulNumberApplyService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/user/BeautifulNumberApplyService.java @@ -1,6 +1,7 @@ package com.red.circle.other.app.service.user.user; import com.red.circle.common.business.dto.cmd.AppExtCommand; +import com.red.circle.other.app.dto.cmd.user.user.UserSpecialIdApplyCmd; /** * 用户注册登录等相关服务. @@ -9,7 +10,7 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand; */ public interface BeautifulNumberApplyService { - void apply(AppExtCommand cmd); + void apply(UserSpecialIdApplyCmd cmd); Boolean existRecord(AppExtCommand cmd);