|
|
@@ -53,6 +53,7 @@ public class CommonCheck {
|
|
|
// 用户校验模式 0-userId 1- userNo
|
|
|
private static final Integer userIdMode = 0;
|
|
|
private static final Integer userNoMode = 1;
|
|
|
+ private static final Integer userNumbMode = 2;
|
|
|
// 卡片校验模式 0-userId 1- cardNo
|
|
|
private static final Integer cardIdMode = 0;
|
|
|
private static final Integer cardNoMode = 1;
|
|
|
@@ -91,6 +92,8 @@ public class CommonCheck {
|
|
|
AllowConsumeValidationContext termCtx = AllowConsumeValidationContext.create(ctx.getBo());
|
|
|
AllowConsumeValidationContext userAccountCtx = AllowConsumeValidationContext.create(ctx.getBo());
|
|
|
|
|
|
+ // checkUserAccount(userAccountCtx);
|
|
|
+
|
|
|
validationTasks.add(() -> checkParam(ctx));
|
|
|
validationTasks.add(() -> checkTerm(termCtx));
|
|
|
validationTasks.add(() -> checkUserAccount(userAccountCtx));
|
|
|
@@ -362,6 +365,7 @@ public class CommonCheck {
|
|
|
try {
|
|
|
long cardNo = ObjectUtil.isEmpty(ctx.getCardNo()) ? 0 : ctx.getCardNo();
|
|
|
long userNo = ObjectUtil.isEmpty(ctx.getUserNo()) ? 0 : ctx.getUserNo();
|
|
|
+ String userNumb = ObjectUtil.isEmpty(ctx.getUserNumb()) ? null : ctx.getUserNumb();
|
|
|
|
|
|
// 如果卡流水号>0验证卡信息
|
|
|
if (cardNo > 0) {
|
|
|
@@ -370,6 +374,9 @@ public class CommonCheck {
|
|
|
if (userNo > 0) {
|
|
|
return checkUserNo(ctx);
|
|
|
}
|
|
|
+ if (ObjectUtil.isNotEmpty(userNumb)) {
|
|
|
+ return checkUserNumb(ctx);
|
|
|
+ }
|
|
|
return R.ok();
|
|
|
} catch (Exception e) {
|
|
|
Thread.currentThread().interrupt();
|
|
|
@@ -403,7 +410,7 @@ public class CommonCheck {
|
|
|
|
|
|
}
|
|
|
// 获取消费账户信息
|
|
|
- Long userId = ctx.getUserCardVo().getUserId();
|
|
|
+ String userId = String.valueOf(ctx.getUserCardVo().getUserId());
|
|
|
result = checkUser(userId, userIdMode, ctx);
|
|
|
if (R.isError(result)) {
|
|
|
return result;
|
|
|
@@ -422,7 +429,7 @@ public class CommonCheck {
|
|
|
*/
|
|
|
private R<ErrorInfo> checkUserNo(AllowConsumeValidationContext ctx) {
|
|
|
// 校验账户信息
|
|
|
- Long userNo = ctx.getUserNo();
|
|
|
+ String userNo = String.valueOf(ctx.getUserNo());
|
|
|
R<ErrorInfo> result = checkUser(userNo, userNoMode, ctx);
|
|
|
if (R.isError(result)) {
|
|
|
return result;
|
|
|
@@ -439,6 +446,30 @@ public class CommonCheck {
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据用户编号校验账户是否可以消费。
|
|
|
+ *
|
|
|
+ * @param ctx 消费有效性校验上下文,包含消费相关的基础信息(如用户流水号、消费金额等)
|
|
|
+ * @return 如果校验失败,则返回包含错误信息的 R 对象;如果校验成功,则返回表示成功的 R 对象
|
|
|
+ */
|
|
|
+ private R<ErrorInfo> checkUserNumb(AllowConsumeValidationContext ctx) {
|
|
|
+ // 校验账户信息
|
|
|
+ String userNumb = ctx.getUserNumb();
|
|
|
+ R<ErrorInfo> result = checkUser(userNumb, userNumbMode, ctx);
|
|
|
+ if (R.isError(result)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 校验卡片信息
|
|
|
+ Long userId = ctx.getUserAccountVo().getUserId();
|
|
|
+ result = checkCard(userId, cardIdMode, ctx);
|
|
|
+ if (R.isError(result)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 更新bo中部分值息
|
|
|
+ setCheckAfterAccountData(ctx);
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
/**
|
|
|
* 校验用户账户信息是否符合交易条件。
|
|
|
* 该方法会检查账户是否存在、是否被冻结、状态是否正常、是否已开户以及是否过期。
|
|
|
@@ -449,7 +480,7 @@ public class CommonCheck {
|
|
|
* @param ctx 消费有效性校验上下文 *
|
|
|
* @return 包含错误信息的响应对象,如果校验失败则返回错误详情;如果校验成功则返回成功响应
|
|
|
*/
|
|
|
- private R<ErrorInfo> checkUser(Long checkParam, Integer checkMode, AllowConsumeValidationContext ctx) {
|
|
|
+ private R<ErrorInfo> checkUser(String checkParam, Integer checkMode, AllowConsumeValidationContext ctx) {
|
|
|
// 1. 从缓存获取账户信息
|
|
|
RemoteUserAccountVo accountVo = getAccountFromCache(checkParam, checkMode);
|
|
|
// 账户不存在,不允许交易
|
|
|
@@ -526,11 +557,20 @@ public class CommonCheck {
|
|
|
* @param checkMode 校验模式
|
|
|
* @return 账户信息对象
|
|
|
*/
|
|
|
- private RemoteUserAccountVo getAccountFromCache(Long checkParam, Integer checkMode) {
|
|
|
- String cacheKey = checkParam.toString();
|
|
|
- return checkMode.equals(userIdMode) ?
|
|
|
- RedisUtils.getCacheMapValue(CacheNames.PT_USER_ACCOUNT_ID, cacheKey) :
|
|
|
- RedisUtils.getCacheMapValue(CacheNames.PT_USER_ACCOUNT_NO, cacheKey);
|
|
|
+ private RemoteUserAccountVo getAccountFromCache(String checkParam, Integer checkMode) {
|
|
|
+ List<RemoteUserAccountVo> list = RedisUtils.getCacheList(CacheNames.PT_USER_ACCOUNT_List);
|
|
|
+ if (CollectionUtil.isEmpty(list)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Long tempValue = Long.valueOf(checkParam);
|
|
|
+ if (checkMode.equals(userIdMode)) {
|
|
|
+ return list.parallelStream().filter(p -> tempValue.equals(p.getUserId())).findFirst().orElse(null);
|
|
|
+ } else if (checkMode.equals(userNoMode)) {
|
|
|
+ return list.parallelStream().filter(p -> tempValue.equals(p.getUserNo())).findFirst().orElse(null);
|
|
|
+ } else if (checkMode.equals(userNumbMode)) {
|
|
|
+ return list.parallelStream().filter(p -> checkParam.equals(p.getUserNumb())).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|