|
@@ -20,10 +20,12 @@ import org.dromara.common.core.enums.TradeStatusEnum;
|
|
|
import org.dromara.common.core.enums.UserAccountStatusEnum;
|
|
import org.dromara.common.core.enums.UserAccountStatusEnum;
|
|
|
import org.dromara.common.json.utils.JsonUtils;
|
|
import org.dromara.common.json.utils.JsonUtils;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
|
|
+import org.dromara.server.common.constant.ConsumeConstants;
|
|
|
import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
|
|
import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
|
|
|
import org.dromara.server.common.util.CardDateUtils;
|
|
import org.dromara.server.common.util.CardDateUtils;
|
|
|
import org.dromara.server.consume.business.BaseBusiness;
|
|
import org.dromara.server.consume.business.BaseBusiness;
|
|
|
import org.dromara.server.consume.business.InitBusiness;
|
|
import org.dromara.server.consume.business.InitBusiness;
|
|
|
|
|
+import org.dromara.server.consume.cache.CardCacheManager;
|
|
|
import org.dromara.server.consume.domain.vo.XfCardLimitedVo;
|
|
import org.dromara.server.consume.domain.vo.XfCardLimitedVo;
|
|
|
import org.dromara.server.consume.domain.vo.XfTermVo;
|
|
import org.dromara.server.consume.domain.vo.XfTermVo;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
@@ -59,12 +61,14 @@ public class CommonCheck {
|
|
|
private static final Integer userNumbMode = 2;
|
|
private static final Integer userNumbMode = 2;
|
|
|
// 卡片校验模式 0-userId 1- cardNo
|
|
// 卡片校验模式 0-userId 1- cardNo
|
|
|
private static final Integer cardIdMode = 0;
|
|
private static final Integer cardIdMode = 0;
|
|
|
- private static final Integer cardNoMode = 1;
|
|
|
|
|
|
|
+ private static final int cardNoMode = 1;
|
|
|
|
|
+ private static final Integer cardFactoryMode = 2;
|
|
|
// 异步线程执行超时时间,以毫秒为单位
|
|
// 异步线程执行超时时间,以毫秒为单位
|
|
|
private static final long VALIDATION_TIMEOUT = 500;
|
|
private static final long VALIDATION_TIMEOUT = 500;
|
|
|
|
|
|
|
|
private final BaseBusiness baseBusiness;
|
|
private final BaseBusiness baseBusiness;
|
|
|
private final InitBusiness initBusiness;
|
|
private final InitBusiness initBusiness;
|
|
|
|
|
+ private final CardCacheManager cardCacheManager;
|
|
|
private final ThreadPoolTaskExecutor taskExecutor;
|
|
private final ThreadPoolTaskExecutor taskExecutor;
|
|
|
|
|
|
|
|
//region 账户、卡片与设备验证
|
|
//region 账户、卡片与设备验证
|
|
@@ -314,12 +318,16 @@ public class CommonCheck {
|
|
|
public R<ErrorInfo> checkUserAccount(AllowConsumeValidationContext ctx) {
|
|
public R<ErrorInfo> checkUserAccount(AllowConsumeValidationContext ctx) {
|
|
|
long cardNo = ObjectUtil.isEmpty(ctx.getCardNo()) ? 0 : ctx.getCardNo();
|
|
long cardNo = ObjectUtil.isEmpty(ctx.getCardNo()) ? 0 : ctx.getCardNo();
|
|
|
long userNo = ObjectUtil.isEmpty(ctx.getUserNo()) ? 0 : ctx.getUserNo();
|
|
long userNo = ObjectUtil.isEmpty(ctx.getUserNo()) ? 0 : ctx.getUserNo();
|
|
|
|
|
+ long factoryId = ObjectUtil.isEmpty(ctx.getFactoryId()) ? 0 : ctx.getFactoryId();
|
|
|
String userNumb = ObjectUtil.isEmpty(ctx.getUserNumb()) ? null : ctx.getUserNumb();
|
|
String userNumb = ObjectUtil.isEmpty(ctx.getUserNumb()) ? null : ctx.getUserNumb();
|
|
|
|
|
|
|
|
// 如果卡流水号>0验证卡信息
|
|
// 如果卡流水号>0验证卡信息
|
|
|
if (cardNo > 0) {
|
|
if (cardNo > 0) {
|
|
|
return checkCardNo(ctx);
|
|
return checkCardNo(ctx);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (factoryId > 0) {
|
|
|
|
|
+ return checkFactoryId(ctx);
|
|
|
|
|
+ }
|
|
|
if (userNo > 0) {
|
|
if (userNo > 0) {
|
|
|
return checkUserNo(ctx);
|
|
return checkUserNo(ctx);
|
|
|
}
|
|
}
|
|
@@ -364,6 +372,32 @@ public class CommonCheck {
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据物理卡号校验账户是否可以消费。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param ctx 消费有效性校验上下文,包含消费相关的基础信息(如用户流水号、消费金额等)
|
|
|
|
|
+ * @return 如果校验失败,则返回包含错误信息的 R 对象;如果校验成功,则返回表示成功的 R 对象
|
|
|
|
|
+ */
|
|
|
|
|
+ private R<ErrorInfo> checkFactoryId(AllowConsumeValidationContext ctx) {
|
|
|
|
|
+ // 检查卡片
|
|
|
|
|
+ long factoryId = ctx.getFactoryId();
|
|
|
|
|
+ R<ErrorInfo> result = checkCard(factoryId, cardFactoryMode, ctx);
|
|
|
|
|
+ if (R.isError(result)) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取消费账户信息
|
|
|
|
|
+ String strUserId = String.valueOf(ctx.getUserCardVo().getUserId());
|
|
|
|
|
+ result = checkUser(strUserId, userIdMode, ctx);
|
|
|
|
|
+ if (R.isError(result)) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 更新bo中部分值息
|
|
|
|
|
+ setCheckAfterAccountData(ctx);
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 根据用户流水号校验账户是否可以消费。
|
|
* 根据用户流水号校验账户是否可以消费。
|
|
|
*
|
|
*
|
|
@@ -491,7 +525,7 @@ public class CommonCheck {
|
|
|
Date lastPay = CardDateUtils.toDate(beforeTime, ZoneId.of("Asia/Shanghai"));
|
|
Date lastPay = CardDateUtils.toDate(beforeTime, ZoneId.of("Asia/Shanghai"));
|
|
|
cardVo.setLastPay(lastPay);
|
|
cardVo.setLastPay(lastPay);
|
|
|
}
|
|
}
|
|
|
- if(cardVo.getLastMeal() == null) {
|
|
|
|
|
|
|
+ if (cardVo.getLastMeal() == null) {
|
|
|
cardVo.setLastMeal(0L);
|
|
cardVo.setLastMeal(0L);
|
|
|
}
|
|
}
|
|
|
ctx.setUserCardVo(cardVo);
|
|
ctx.setUserCardVo(cardVo);
|
|
@@ -531,19 +565,18 @@ public class CommonCheck {
|
|
|
/**
|
|
/**
|
|
|
* 从缓存获取卡片信息
|
|
* 从缓存获取卡片信息
|
|
|
*
|
|
*
|
|
|
- * @param checkParam 用户标识
|
|
|
|
|
- * @param checkMode 校验模式
|
|
|
|
|
|
|
+ * @param checkParam 卡片标识
|
|
|
|
|
+ * @param checkMode 获取方式
|
|
|
* @return 账户信息对象
|
|
* @return 账户信息对象
|
|
|
*/
|
|
*/
|
|
|
private RemoteCardVo getCardFromCache(Long checkParam, Integer checkMode) {
|
|
private RemoteCardVo getCardFromCache(Long checkParam, Integer checkMode) {
|
|
|
- String cacheKey = checkParam.toString();
|
|
|
|
|
- Object cacheCard = checkMode.equals(cardIdMode) ?
|
|
|
|
|
- RedisUtils.getCacheMapValue(CacheNames.PT_USER_CARD_USER_ID, cacheKey) :
|
|
|
|
|
- RedisUtils.getCacheMapValue(CacheNames.PT_USER_CARD_NO, cacheKey);
|
|
|
|
|
- if (cacheCard == null) {
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ Object cacheCard = null;
|
|
|
|
|
+ switch (checkMode) {
|
|
|
|
|
+ case ConsumeConstants.CARD_NO -> cacheCard = cardCacheManager.getByCardNo(checkParam);
|
|
|
|
|
+ case ConsumeConstants.CARD_USER -> cacheCard = cardCacheManager.getByUserId(checkParam);
|
|
|
|
|
+ case ConsumeConstants.CARD_FACTORY -> cacheCard = cardCacheManager.getByFactoryId(checkParam);
|
|
|
}
|
|
}
|
|
|
- return JsonUtils.parseObject(cacheCard.toString(), RemoteCardVo.class);
|
|
|
|
|
|
|
+ return cacheCard == null ? null : JsonUtils.parseObject(cacheCard.toString(), RemoteCardVo.class);
|
|
|
}
|
|
}
|
|
|
// endregion
|
|
// endregion
|
|
|
|
|
|