靓号校验处理
This commit is contained in:
parent
efedad7ebc
commit
fc60be306b
@ -0,0 +1,59 @@
|
|||||||
|
package com.red.circle.other.inner.asserts.user;
|
||||||
|
|
||||||
|
import com.red.circle.framework.dto.IResponseErrorCode;
|
||||||
|
import com.red.circle.framework.dto.ResErrorCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户靓号相关错误码, 范围: 4200 ~ 4300.
|
||||||
|
*/
|
||||||
|
@ResErrorCode(describe = "用户靓号相关", minCode = 4200, maxCode = 4300)
|
||||||
|
public enum UserSpecialErrorCode implements IResponseErrorCode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 财富等级不足10级.
|
||||||
|
*/
|
||||||
|
WEALTH_LEVEL_NOT_ENOUGH(4200, "You must reach wealth level 10 to apply for an exclusive ID."),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID格式不正确.
|
||||||
|
*/
|
||||||
|
ID_FORMAT_INVALID(4201, "Please enter an ID in the correct format."),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请已提交,待审核.
|
||||||
|
*/
|
||||||
|
APPLICATION_PENDING(4202, "Your application has been successfully submitted, please wait for review!"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前财富等级已申请过ID.
|
||||||
|
*/
|
||||||
|
ALREADY_APPLIED_AT_LEVEL(4203, "You've already applied for an exclusive ID at the current wealth level."),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID已被使用.
|
||||||
|
*/
|
||||||
|
ID_ALREADY_USED(4204, "ID has already been used by another user.");
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
UserSpecialErrorCode(Integer code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getErrorCodeName() {
|
||||||
|
return this.name();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,17 +1,15 @@
|
|||||||
package com.red.circle.other.app.command.user;
|
package com.red.circle.other.app.command.user;
|
||||||
|
|
||||||
import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
|
||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
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.app.dto.cmd.user.user.UserSpecialIdApplyCmd;
|
||||||
import com.red.circle.other.infra.database.mongo.entity.user.profile.UserSpecialId;
|
import com.red.circle.other.domain.model.user.UserConsumptionLevel;
|
||||||
import com.red.circle.other.infra.database.mongo.service.user.profile.UserSpecialIdService;
|
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.tool.core.sequence.IdWorkerUtils;
|
||||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||||
import com.red.circle.other.infra.database.rds.entity.user.user.UserBeautifulNumberApply;
|
import com.red.circle.other.infra.database.rds.entity.user.user.UserBeautifulNumberApply;
|
||||||
import com.red.circle.other.infra.database.rds.service.user.user.UserBeautifulNumberApplyService;
|
import com.red.circle.other.infra.database.rds.service.user.user.UserBeautifulNumberApplyService;
|
||||||
import com.red.circle.other.inner.asserts.user.UserErrorCode;
|
import com.red.circle.other.inner.asserts.user.UserSpecialErrorCode;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -29,42 +27,54 @@ public class UserBeautifulNumberApplyCmdExe {
|
|||||||
private final UserSpecialIdService userSpecialIdService;
|
private final UserSpecialIdService userSpecialIdService;
|
||||||
|
|
||||||
public void execute(UserSpecialIdApplyCmd cmd) {
|
public void execute(UserSpecialIdApplyCmd cmd) {
|
||||||
|
String account = cmd.getAccount();
|
||||||
|
Long userId = cmd.getUserId();
|
||||||
|
|
||||||
// 验证账号是否符合当前等级的靓号规则
|
UserConsumptionLevel consumptionLevel = userProfileGateway.getUserConsumptionLevel(SysOriginPlatformEnum.LIKEI, userId);
|
||||||
boolean isValidForLevel = SpecialIdPatternEnum.isValidForLevel(
|
Integer wealthLevel = consumptionLevel.getWealthLevel();
|
||||||
cmd.getAccount(),
|
|
||||||
cmd.getWealthLevel()
|
// (1) 财富等级>=10级校验
|
||||||
|
ResponseAssert.isTrue(
|
||||||
|
UserSpecialErrorCode.WEALTH_LEVEL_NOT_ENOUGH,
|
||||||
|
wealthLevel != null && wealthLevel >= 10
|
||||||
);
|
);
|
||||||
ResponseAssert.isTrue(CommonErrorCode.SAVE_FAILURE,"The account does not meet the current wealth level rules", isValidForLevel);
|
|
||||||
|
|
||||||
// 检查靓号是否已存在
|
// (2) ID格式校验:8位数字或2位数字
|
||||||
boolean exists = userSpecialIdService.exists(cmd.getReqSysOrigin().getOrigin(), cmd.getAccount());
|
ResponseAssert.isTrue(
|
||||||
ResponseAssert.isFalse(CommonErrorCode.SAVE_FAILURE, "The beautiful number already exists",exists);
|
UserSpecialErrorCode.ID_FORMAT_INVALID,
|
||||||
|
account != null && (account.matches("^\\d{8}$") || account.matches("^\\d{2}$"))
|
||||||
|
);
|
||||||
|
|
||||||
ResponseAssert.isFalse(CommonErrorCode.REPEATED_SUBMISSION, isExistPending(cmd));
|
// (3) 用户在当前财富等级已申请过ID(待审核)
|
||||||
|
Boolean hasPendingApply = userBeautifulNumberApplyService.hasPendingApplyAtLevel(userId, wealthLevel);
|
||||||
|
ResponseAssert.isFalse(
|
||||||
|
UserSpecialErrorCode.APPLICATION_PENDING,
|
||||||
|
Boolean.TRUE.equals(hasPendingApply)
|
||||||
|
);
|
||||||
|
|
||||||
// 检查用户是否已有靓号,如果有则删除
|
// (4) 用户在当前财富等级已经申请过ID(申请失败)- 通过数据库判断
|
||||||
UserSpecialId oldSpecialId = userSpecialIdService.getByUserId(cmd.getUserId());
|
Boolean hasAppliedFailed = userBeautifulNumberApplyService.hasAppliedAtLevelWithFailure(userId, wealthLevel);
|
||||||
if (oldSpecialId != null) {
|
ResponseAssert.isFalse(
|
||||||
userSpecialIdService.remove(oldSpecialId.getId());
|
UserSpecialErrorCode.ALREADY_APPLIED_AT_LEVEL,
|
||||||
}
|
Boolean.TRUE.equals(hasAppliedFailed)
|
||||||
|
);
|
||||||
|
|
||||||
|
// (5) 检查靓号是否已被使用
|
||||||
|
boolean exists = userSpecialIdService.exists(cmd.getReqSysOrigin().getOrigin(), account);
|
||||||
|
ResponseAssert.isFalse(
|
||||||
|
UserSpecialErrorCode.ID_ALREADY_USED,
|
||||||
|
exists
|
||||||
|
);
|
||||||
|
|
||||||
|
// 保存申请记录
|
||||||
userBeautifulNumberApplyService.save(new UserBeautifulNumberApply()
|
userBeautifulNumberApplyService.save(new UserBeautifulNumberApply()
|
||||||
.setId(IdWorkerUtils.getId())
|
.setId(IdWorkerUtils.getId())
|
||||||
.setApplyUser(cmd.requiredReqUserId())
|
.setApplyUser(cmd.requiredReqUserId())
|
||||||
|
.setApplyAccount(account)
|
||||||
|
.setWealthLevel(wealthLevel)
|
||||||
.setState(0)
|
.setState(0)
|
||||||
.setSysOrigin(cmd.requireReqSysOrigin())
|
.setSysOrigin(cmd.requireReqSysOrigin())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean isExistPending(AppExtCommand cmd) {
|
|
||||||
return userBeautifulNumberApplyService.isExistPending(cmd.requiredReqUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Integer getUserLevelExperience(AppExtCommand cmd) {
|
|
||||||
return userProfileGateway.getUserConsumptionLevel(cmd.requireReqSysOriginEnum(),
|
|
||||||
cmd.requiredReqUserId())
|
|
||||||
.getWealthLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,4 +51,16 @@ public class UserBeautifulNumberApply extends TimestampBaseEntity {
|
|||||||
@TableField("state")
|
@TableField("state")
|
||||||
private Integer state;
|
private Integer state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请的账号.
|
||||||
|
*/
|
||||||
|
@TableField("apply_account")
|
||||||
|
private String applyAccount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请时的财富等级.
|
||||||
|
*/
|
||||||
|
@TableField("wealth_level")
|
||||||
|
private Integer wealthLevel;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,4 +21,8 @@ public interface UserBeautifulNumberApplyService extends BaseService<UserBeautif
|
|||||||
PageResult<UserBeautifulNumberApply> page(UserBeautifulNumberApplyQryCmd query);
|
PageResult<UserBeautifulNumberApply> page(UserBeautifulNumberApplyQryCmd query);
|
||||||
|
|
||||||
void handleApply(Long id, Integer state);
|
void handleApply(Long id, Integer state);
|
||||||
|
|
||||||
|
Boolean hasAppliedAtLevelWithFailure(Long userId, Integer wealthLevel);
|
||||||
|
|
||||||
|
Boolean hasPendingApplyAtLevel(Long userId, Integer wealthLevel);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,4 +66,22 @@ public class UserBeautifulNumberApplyServiceImpl extends
|
|||||||
private boolean checkState(Integer state) {
|
private boolean checkState(Integer state) {
|
||||||
return Objects.equals(state, 1) || Objects.equals(state, 2);
|
return Objects.equals(state, 1) || Objects.equals(state, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean hasAppliedAtLevelWithFailure(Long userId, Integer wealthLevel) {
|
||||||
|
return Optional.ofNullable(query()
|
||||||
|
.eq(UserBeautifulNumberApply::getApplyUser, userId)
|
||||||
|
.eq(UserBeautifulNumberApply::getWealthLevel, wealthLevel)
|
||||||
|
.eq(UserBeautifulNumberApply::getState, 2)
|
||||||
|
.list()).map(CollectionUtil::isNotEmpty).orElse(Boolean.FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean hasPendingApplyAtLevel(Long userId, Integer wealthLevel) {
|
||||||
|
return Optional.ofNullable(query()
|
||||||
|
.eq(UserBeautifulNumberApply::getApplyUser, userId)
|
||||||
|
.eq(UserBeautifulNumberApply::getWealthLevel, wealthLevel)
|
||||||
|
.eq(UserBeautifulNumberApply::getState, 0)
|
||||||
|
.list()).map(CollectionUtil::isNotEmpty).orElse(Boolean.FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user