|
|
@@ -18,6 +18,7 @@ import org.dromara.common.core.domain.model.ErrorInfo;
|
|
|
import org.dromara.common.core.enums.CardStatusEnum;
|
|
|
import org.dromara.common.core.enums.TradeStatusEnum;
|
|
|
import org.dromara.common.core.enums.UserAccountStatusEnum;
|
|
|
+import org.dromara.common.json.utils.JsonUtils;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
|
|
|
import org.dromara.server.consume.business.BaseBusiness;
|
|
|
@@ -100,7 +101,7 @@ public class CommonCheck {
|
|
|
R<ErrorInfo> result = task.get();
|
|
|
// 如果发现错误且尚未设置错误结果
|
|
|
if (result != null && R.isError(result) &&
|
|
|
- firstError.compareAndSet(null, result)) {
|
|
|
+ firstError.compareAndSet(null, result)) {
|
|
|
// 取消其他任务(通过中断)
|
|
|
taskExecutor.getThreadPoolExecutor().getQueue().clear();
|
|
|
}
|
|
|
@@ -124,6 +125,7 @@ public class CommonCheck {
|
|
|
return firstError.get() != null ? firstError.get() : R.ok();
|
|
|
} catch (InterruptedException e) {
|
|
|
Thread.currentThread().interrupt();
|
|
|
+ log.error("error:{}", e.getMessage(), e);
|
|
|
return createError(TradeStatusEnum.SysError);
|
|
|
}
|
|
|
}
|
|
|
@@ -142,14 +144,14 @@ public class CommonCheck {
|
|
|
// 1. 校验设备标识参数
|
|
|
if (isTerminalInvalid(ctx)) {
|
|
|
return createErrorResponse(1, ApiErrorTypeConstants.PARAM_ERROR,
|
|
|
- "设备机号不正确", "设备机号必须大于零或MAC地址不能为空!");
|
|
|
+ "设备机号不正确", "设备机号必须大于零或MAC地址不能为空!");
|
|
|
}
|
|
|
|
|
|
// 2. 校验用户标识参数
|
|
|
if (isUserIdentifierInvalid(ctx)) {
|
|
|
return createErrorResponse(1, ApiErrorTypeConstants.PARAM_ERROR,
|
|
|
- "交易人员标识不满足",
|
|
|
- "必须提供 [CardNo | FactoryId | userNo | userNumb] 中至少1项来标识交易用户");
|
|
|
+ "交易人员标识不满足",
|
|
|
+ "必须提供 [CardNo | FactoryId | userNo | userNumb] 中至少1项来标识交易用户");
|
|
|
}
|
|
|
|
|
|
// 3. 所有参数校验通过
|
|
|
@@ -165,7 +167,7 @@ public class CommonCheck {
|
|
|
private boolean isTerminalInvalid(AllowConsumeValidationContext ctx) {
|
|
|
// 终端号为空或为0 且 MAC地址为空
|
|
|
return (ObjectUtil.isEmpty(ctx.getTermNo()) || ctx.getTermNo() == 0)
|
|
|
- && ObjectUtil.isEmpty(ctx.getTermMac());
|
|
|
+ && ObjectUtil.isEmpty(ctx.getTermMac());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -177,9 +179,9 @@ public class CommonCheck {
|
|
|
private boolean isUserIdentifierInvalid(AllowConsumeValidationContext ctx) {
|
|
|
// 所有用户标识字段均为空或无效值
|
|
|
return ctx.getCardNo() <= 0L
|
|
|
- && ctx.getFactoryId() == 0L
|
|
|
- && ctx.getUserNo() <= 0L
|
|
|
- && StrUtil.isEmpty(ctx.getUserNumb());
|
|
|
+ && ctx.getFactoryId() == 0L
|
|
|
+ && ctx.getUserNo() <= 0L
|
|
|
+ && StrUtil.isEmpty(ctx.getUserNumb());
|
|
|
}
|
|
|
// endregion
|
|
|
|
|
|
@@ -197,8 +199,8 @@ public class CommonCheck {
|
|
|
List<XfTermVo> list = RedisUtils.getCacheList(CacheNames.PT_TERM_LIST);
|
|
|
if (CollectionUtil.isEmpty(list)) {
|
|
|
return createErrorResponse(1, ApiErrorTypeConstants.OBJECT_NOT_EXISTS,
|
|
|
- "未获取到设备数据",
|
|
|
- "获取消费设备失败");
|
|
|
+ "未获取到设备数据",
|
|
|
+ "获取消费设备失败");
|
|
|
}
|
|
|
XfTermVo termVo;
|
|
|
String mac = ctx.getTermMac();
|
|
|
@@ -210,8 +212,8 @@ public class CommonCheck {
|
|
|
}
|
|
|
if (ObjectUtil.isEmpty(termVo)) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.OBJECT_NOT_EXISTS,
|
|
|
- "设备不存在",
|
|
|
- MessageFormat.format("机号或MAC为[{0}]的设备不存在,不允许交易", msgInfo));
|
|
|
+ "设备不存在",
|
|
|
+ MessageFormat.format("机号或MAC为[{0}]的设备不存在,不允许交易", msgInfo));
|
|
|
}
|
|
|
// 因为后续处理都是用的机号,如果消费机上传的是mac地址,则将termNo更新到消费业务对象
|
|
|
if (termVo != null) {
|
|
|
@@ -265,9 +267,9 @@ public class CommonCheck {
|
|
|
Long cardFactoryId = ctx.getUserCardVo().getFactoryId();
|
|
|
if (factoryId.compareTo(0L) > 0 && !cardFactoryId.equals(factoryId)) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.PARAM_ERROR,
|
|
|
- "卡片不正确",
|
|
|
- MessageFormat.format("物理卡号不一致,不允许交易。传入值[{0}],系统值[{1}]", factoryId,
|
|
|
- cardFactoryId));
|
|
|
+ "卡片不正确",
|
|
|
+ MessageFormat.format("物理卡号不一致,不允许交易。传入值[{0}],系统值[{1}]", factoryId,
|
|
|
+ cardFactoryId));
|
|
|
|
|
|
}
|
|
|
// 获取消费账户信息
|
|
|
@@ -323,32 +325,32 @@ public class CommonCheck {
|
|
|
// 账户不存在,不允许交易
|
|
|
if (ObjectUtil.isEmpty(accountVo)) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.NOT_FOUND,
|
|
|
- "账户不存在",
|
|
|
- MessageFormat.format("流水号或Id为[{0}]的账户不存在,不允许交易", checkParam));
|
|
|
+ "账户不存在",
|
|
|
+ MessageFormat.format("流水号或Id为[{0}]的账户不存在,不允许交易", checkParam));
|
|
|
}
|
|
|
// 账户被冻结,不允许交易
|
|
|
if (ObjectUtil.equals(accountVo.getFreezeStatus(), Constants.SYS_YES)) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.BAD_REQUEST,
|
|
|
- "账户被冻结",
|
|
|
- MessageFormat.format("流水号或Id为[{0}]的账户被冻结,不允许交易", checkParam));
|
|
|
+ "账户被冻结",
|
|
|
+ MessageFormat.format("流水号或Id为[{0}]的账户被冻结,不允许交易", checkParam));
|
|
|
}
|
|
|
// 账户状态不正常,不允许交易
|
|
|
if (ObjectUtil.equals(accountVo.getStatus(), Constants.SYS_NO)) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.NOT_FOUND,
|
|
|
- "账户状态不正常",
|
|
|
- MessageFormat.format("流水号或Id为[{0}]的账户状态不正常,不允许交易", checkParam));
|
|
|
+ "账户状态不正常",
|
|
|
+ MessageFormat.format("流水号或Id为[{0}]的账户状态不正常,不允许交易", checkParam));
|
|
|
}
|
|
|
// 未开户,不允许交易
|
|
|
if (!ObjectUtil.equals(accountVo.getAccountStatus(), UserAccountStatusEnum.IS_OPEN.code().toString())) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.NOT_FOUND,
|
|
|
- "账户尚未开户",
|
|
|
- MessageFormat.format("流水号或Id为[{0}]的账户尚未开户,不允许交易", checkParam));
|
|
|
+ "账户尚未开户",
|
|
|
+ MessageFormat.format("流水号或Id为[{0}]的账户尚未开户,不允许交易", checkParam));
|
|
|
}
|
|
|
// 账户已过有效期,不允许消费
|
|
|
if (accountVo.getLifespan().getTime() < System.currentTimeMillis()) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.BAD_REQUEST,
|
|
|
- "账户过期",
|
|
|
- MessageFormat.format("流水号或Id为[{0}]的账户已过期,不允许交易", checkParam));
|
|
|
+ "账户过期",
|
|
|
+ MessageFormat.format("流水号或Id为[{0}]的账户已过期,不允许交易", checkParam));
|
|
|
}
|
|
|
// 全部检查通过,复制账户信息
|
|
|
ctx.setUserAccountVo(accountVo);
|
|
|
@@ -371,14 +373,14 @@ public class CommonCheck {
|
|
|
// 卡片不存在,不允许消费
|
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.CARD_NOT_EXISTS,
|
|
|
- "卡片不存在",
|
|
|
- MessageFormat.format("流水号或用户Id或物理卡号为[{0}]的卡片不存在,不允许交易", checkParam));
|
|
|
+ "卡片不存在",
|
|
|
+ MessageFormat.format("流水号或用户Id或物理卡号为[{0}]的卡片不存在,不允许交易", checkParam));
|
|
|
}
|
|
|
// 卡片状态不正常,不允许消费
|
|
|
if (!String.valueOf(CardStatusEnum.NORMAL.code()).equals(cardVo.getStatus())) {
|
|
|
return createErrorResponse(400, ApiErrorTypeConstants.CARD_STATUS_NOT_NORMAL,
|
|
|
- "卡片状态不正确",
|
|
|
- MessageFormat.format("流水号或用户Id或物理卡号为[{0}]的卡片状态不正确,不允许交易", checkParam));
|
|
|
+ "卡片状态不正确",
|
|
|
+ MessageFormat.format("流水号或用户Id或物理卡号为[{0}]的卡片状态不正确,不允许交易", checkParam));
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -397,8 +399,8 @@ public class CommonCheck {
|
|
|
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);
|
|
|
+ RedisUtils.getCacheMapValue(CacheNames.PT_USER_ACCOUNT_ID, cacheKey) :
|
|
|
+ RedisUtils.getCacheMapValue(CacheNames.PT_USER_ACCOUNT_NO, cacheKey);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -411,8 +413,9 @@ public class CommonCheck {
|
|
|
private RemoteCardVo getCardFromCache(Long checkParam, Integer checkMode) {
|
|
|
String cacheKey = checkParam.toString();
|
|
|
return checkMode.equals(cardIdMode) ?
|
|
|
- RedisUtils.getCacheMapValue(CacheNames.PT_USER_CARD_USER_ID, cacheKey) :
|
|
|
- RedisUtils.getCacheMapValue(CacheNames.PT_USER_CARD_NO, cacheKey);
|
|
|
+ JsonUtils.parseObject(String.valueOf(RedisUtils.getCacheMapValue(CacheNames.PT_USER_CARD_USER_ID, cacheKey)), RemoteCardVo.class) :
|
|
|
+ JsonUtils.parseObject(String.valueOf(RedisUtils.getCacheMapValue(CacheNames.PT_USER_CARD_NO, cacheKey)), RemoteCardVo.class);
|
|
|
+ // RedisUtils.getCacheMapValue(CacheNames.PT_USER_CARD_NO, cacheKey);
|
|
|
}
|
|
|
// endregion
|
|
|
|
|
|
@@ -472,8 +475,8 @@ public class CommonCheck {
|
|
|
}
|
|
|
String mealTime = DateUtil.format(consumeDate, "HH:mm:ss");
|
|
|
return list.stream().filter(p -> mealTime
|
|
|
- .compareTo(p.getBeginTime()) >= 0 && mealTime.compareTo(p.getEndTime()) < 0)
|
|
|
- .findFirst().orElse(null);
|
|
|
+ .compareTo(p.getBeginTime()) >= 0 && mealTime.compareTo(p.getEndTime()) < 0)
|
|
|
+ .findFirst().orElse(null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -508,12 +511,12 @@ public class CommonCheck {
|
|
|
RedisUtils.expire(CacheNames.XF_ORIGINAL_ID, Duration.ofHours(20));
|
|
|
|
|
|
// if (ObjectUtil.equals(currentDateStr, consumeDateStr)) {
|
|
|
- // 重置卡天当日消费数据
|
|
|
- taskExecutor.submit(() -> baseBusiness.resetCardConsumeInfo(userCardVo, mealType, consumeMoney, consumeDate));
|
|
|
- // 重置卡片当日限制数据
|
|
|
- taskExecutor.submit(() -> baseBusiness.restCardLimitedInfo(mapCardLimited, cardLimitedVo, consumeMoney));
|
|
|
- // 重置人员当日总卡余
|
|
|
- taskExecutor.submit(() -> baseBusiness.resetUserBalance(userId, balance));
|
|
|
+ // 重置卡天当日消费数据
|
|
|
+ taskExecutor.submit(() -> baseBusiness.resetCardConsumeInfo(userCardVo, mealType, consumeMoney, consumeDate));
|
|
|
+ // 重置卡片当日限制数据
|
|
|
+ taskExecutor.submit(() -> baseBusiness.restCardLimitedInfo(mapCardLimited, cardLimitedVo, consumeMoney));
|
|
|
+ // 重置人员当日总卡余
|
|
|
+ taskExecutor.submit(() -> baseBusiness.resetUserBalance(userId, balance));
|
|
|
// }
|
|
|
}
|
|
|
|