|
@@ -238,8 +238,6 @@ public class CheckBusiness {
|
|
|
public R<ErrorInfo> checkConsume(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo, XfTermVo useTermVo) {
|
|
public R<ErrorInfo> checkConsume(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo, XfTermVo useTermVo) {
|
|
|
ErrorInfo errorInfo;
|
|
ErrorInfo errorInfo;
|
|
|
R<ErrorInfo> result;
|
|
R<ErrorInfo> result;
|
|
|
- // 如果折扣验证,消费金额会更新成折扣金额,所以先保存
|
|
|
|
|
- BigDecimal consumeMoney = bo.getConsumeMoney();
|
|
|
|
|
// 1.消费账户状态验证,验证账户是否已开户、是否冻结、状态是否正常、是否过有效期
|
|
// 1.消费账户状态验证,验证账户是否已开户、是否冻结、状态是否正常、是否过有效期
|
|
|
if ("Y".equals(userAccountVo.getFreezeStatus())) {
|
|
if ("Y".equals(userAccountVo.getFreezeStatus())) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户已被冻结",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户已被冻结",
|
|
@@ -263,24 +261,28 @@ public class CheckBusiness {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 2.餐类验证
|
|
// 2.餐类验证
|
|
|
|
|
+ long startTime=System.currentTimeMillis();
|
|
|
RemoteMealTypeVo mealType = remoteMealTypeService.queryMealTypeVoByTime(bo.getConsumeDate());
|
|
RemoteMealTypeVo mealType = remoteMealTypeService.queryMealTypeVoByTime(bo.getConsumeDate());
|
|
|
if (ObjectUtil.isEmpty(mealType)) {
|
|
if (ObjectUtil.isEmpty(mealType)) {
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "不在交易时段", "不在交易时段"));
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "不在交易时段", "不在交易时段"));
|
|
|
}
|
|
}
|
|
|
- // 3.根据消费机的消费模式验证余额,如果余额不足则返回
|
|
|
|
|
- result = checkOrigDeductionBag(bo, userAccountVo, useTermVo);
|
|
|
|
|
- if (R.isError(result)) {
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // 4.设备限制验证,只有消费机上传时会会进行验证,在手工补扣、错扣补款时不进行验证
|
|
|
|
|
|
|
+ // 3.设备限制验证,只有消费机上传时会会进行验证,在手工补扣、错扣补款时不进行验证
|
|
|
|
|
+ startTime=System.currentTimeMillis();
|
|
|
if (bo.getStatusFlag() == 1 || bo.getStatusFlag() == 4) {
|
|
if (bo.getStatusFlag() == 1 || bo.getStatusFlag() == 4) {
|
|
|
result = checkTermLimitDeal(bo, useTermVo, userCardVo, mealType);
|
|
result = checkTermLimitDeal(bo, useTermVo, userCardVo, mealType);
|
|
|
if (R.isError(result)) {
|
|
if (R.isError(result)) {
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "消费限制判断存在问题", JSONUtil.toJsonStr(result.getData())));
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "消费限制判断存在问题", JSONUtil.toJsonStr(result.getData())));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ log.info("折扣验证耗时:{}毫秒", System.currentTimeMillis()-startTime);
|
|
|
|
|
+ // 4.根据消费机的消费模式验证余额,如果余额不足则返回
|
|
|
|
|
+ startTime=System.currentTimeMillis();
|
|
|
|
|
+ result = checkOrigDeductionBag(bo, userAccountVo, useTermVo);
|
|
|
|
|
+ if (R.isError(result)) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("卡余验证耗时:{}毫秒", System.currentTimeMillis()-startTime);
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -732,9 +734,9 @@ public class CheckBusiness {
|
|
|
// 计算扣费钱包的总金额
|
|
// 计算扣费钱包的总金额
|
|
|
for (String bagCode : bagCodes) {
|
|
for (String bagCode : bagCodes) {
|
|
|
PtBagVo bagVo = bagService.queryByUserBagCode(userId, bagCode);
|
|
PtBagVo bagVo = bagService.queryByUserBagCode(userId, bagCode);
|
|
|
- if (ObjectUtil.isNotEmpty(bagVo)) {
|
|
|
|
|
|
|
+ // if (ObjectUtil.isNotEmpty(bagVo)) {
|
|
|
totalBalance = totalBalance.add(bagVo.getBalance());
|
|
totalBalance = totalBalance.add(bagVo.getBalance());
|
|
|
- }
|
|
|
|
|
|
|
+ // }
|
|
|
}
|
|
}
|
|
|
// 如果扣费钱包总余额<消费金额,则不允许消费
|
|
// 如果扣费钱包总余额<消费金额,则不允许消费
|
|
|
if (consumeMoney.compareTo(totalBalance) > 0) {
|
|
if (consumeMoney.compareTo(totalBalance) > 0) {
|
|
@@ -788,8 +790,8 @@ public class CheckBusiness {
|
|
|
|
|
|
|
|
// 设备消费间隔验证
|
|
// 设备消费间隔验证
|
|
|
if ((currentLocalDt.toEpochSecond(ZoneOffset.of("+8"))
|
|
if ((currentLocalDt.toEpochSecond(ZoneOffset.of("+8"))
|
|
|
- - lastPayLocalDt.toEpochSecond(ZoneOffset.of("+8"))) / 60 < termSwipeInterval && termSwipeInterval > 0) {// 消费间隔
|
|
|
|
|
- return R.fail(new ErrorInfo(400, TradeStatusEnum.TimeInterval.toString(), "超过设备单次限额", TradeStatusEnum.TimeInterval.getName()));
|
|
|
|
|
|
|
+ - lastPayLocalDt.toEpochSecond(ZoneOffset.of("+8"))) / 60 < termSwipeInterval && termSwipeInterval > 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.TimeInterval.toString(), "消费间隔过短", TradeStatusEnum.TimeInterval.getName()));
|
|
|
}
|
|
}
|
|
|
// 设备单次限额验证
|
|
// 设备单次限额验证
|
|
|
if (termSingleMoney.compareTo(consumeValue) < 0 && termSingleMoney.compareTo(BigDecimal.ZERO) > 0) {// 限制金额
|
|
if (termSingleMoney.compareTo(consumeValue) < 0 && termSingleMoney.compareTo(BigDecimal.ZERO) > 0) {// 限制金额
|
|
@@ -849,15 +851,18 @@ public class CheckBusiness {
|
|
|
* @return 检查结果
|
|
* @return 检查结果
|
|
|
*/
|
|
*/
|
|
|
public R<ErrorInfo> checkCardLimitDeal(ConsumptionBo bo, XfTermVo termVo, RemoteCardVo userCardVo, RemoteMealTypeVo mealTypeVo) {
|
|
public R<ErrorInfo> checkCardLimitDeal(ConsumptionBo bo, XfTermVo termVo, RemoteCardVo userCardVo, RemoteMealTypeVo mealTypeVo) {
|
|
|
|
|
+ long startTime=System.currentTimeMillis();
|
|
|
LocalDateTime currentLocalDt = LocalDateTime.now();
|
|
LocalDateTime currentLocalDt = LocalDateTime.now();
|
|
|
Long cardNo = userCardVo.getCardNo();
|
|
Long cardNo = userCardVo.getCardNo();
|
|
|
Long mealTypeId = Long.valueOf(mealTypeVo.getTypeId());
|
|
Long mealTypeId = Long.valueOf(mealTypeVo.getTypeId());
|
|
|
Date lastPayDate = userCardVo.getLastPay();
|
|
Date lastPayDate = userCardVo.getLastPay();
|
|
|
// 获取卡片的限制信息
|
|
// 获取卡片的限制信息
|
|
|
XfCardLimitedVo cardLimitedVo = cardLimitedService.queryByCardNo(cardNo);
|
|
XfCardLimitedVo cardLimitedVo = cardLimitedService.queryByCardNo(cardNo);
|
|
|
|
|
+ log.info("卡类限额、限次与折扣初始化耗时1:{}", System.currentTimeMillis()-startTime);
|
|
|
if (ObjectUtil.isEmpty(cardLimitedVo)) {
|
|
if (ObjectUtil.isEmpty(cardLimitedVo)) {
|
|
|
cardLimitedVo = initXfCardLimited(cardNo, mealTypeVo.getMealId(), lastPayDate);
|
|
cardLimitedVo = initXfCardLimited(cardNo, mealTypeVo.getMealId(), lastPayDate);
|
|
|
}
|
|
}
|
|
|
|
|
+ log.info("卡类限额、限次与折扣初始化耗时:{}", System.currentTimeMillis()-startTime);
|
|
|
// 最后交易时间
|
|
// 最后交易时间
|
|
|
LocalDateTime lastPayLimitLocalDt = LocalDateTime.ofInstant(cardLimitedVo.getLastPay().toInstant(), ZoneOffset.of("+8"));
|
|
LocalDateTime lastPayLimitLocalDt = LocalDateTime.ofInstant(cardLimitedVo.getLastPay().toInstant(), ZoneOffset.of("+8"));
|
|
|
// 最后交易餐类
|
|
// 最后交易餐类
|
|
@@ -870,21 +875,29 @@ public class CheckBusiness {
|
|
|
if (!Objects.equals(lastPayLimitMealType, mealTypeId)) {
|
|
if (!Objects.equals(lastPayLimitMealType, mealTypeId)) {
|
|
|
cardLimitedVo = cardLimitedService.resetMealCardLimitedData(cardNo, mealTypeId.toString());
|
|
cardLimitedVo = cardLimitedService.resetMealCardLimitedData(cardNo, mealTypeId.toString());
|
|
|
}
|
|
}
|
|
|
|
|
+ log.info("卡类限额、限次与折扣初始化耗时2:{}", System.currentTimeMillis()-startTime);
|
|
|
|
|
+
|
|
|
// 卡类折扣检查
|
|
// 卡类折扣检查
|
|
|
|
|
+ startTime=System.currentTimeMillis();
|
|
|
R<ErrorInfo> result = checkCardDisCount(termVo, userCardVo, cardLimitedVo, mealTypeVo, bo);
|
|
R<ErrorInfo> result = checkCardDisCount(termVo, userCardVo, cardLimitedVo, mealTypeVo, bo);
|
|
|
if (R.isError(result)) {
|
|
if (R.isError(result)) {
|
|
|
return R.fail(result.getData());
|
|
return R.fail(result.getData());
|
|
|
}
|
|
}
|
|
|
|
|
+ log.info("卡类折扣检查耗时:{}", System.currentTimeMillis()-startTime);
|
|
|
// 卡类限额检查
|
|
// 卡类限额检查
|
|
|
|
|
+ startTime=System.currentTimeMillis();
|
|
|
result = checkCardQuota(termVo, userCardVo, cardLimitedVo, mealTypeVo, bo.getConsumeMoney());
|
|
result = checkCardQuota(termVo, userCardVo, cardLimitedVo, mealTypeVo, bo.getConsumeMoney());
|
|
|
if (R.isError(result)) {
|
|
if (R.isError(result)) {
|
|
|
return R.fail(result.getData());
|
|
return R.fail(result.getData());
|
|
|
}
|
|
}
|
|
|
|
|
+ log.info("卡类限额检查耗时:{}", System.currentTimeMillis()-startTime);
|
|
|
// 卡类限次检
|
|
// 卡类限次检
|
|
|
|
|
+ startTime=System.currentTimeMillis();
|
|
|
result = checkCardLimited(termVo, userCardVo, cardLimitedVo, mealTypeVo);
|
|
result = checkCardLimited(termVo, userCardVo, cardLimitedVo, mealTypeVo);
|
|
|
if (R.isError(result)) {
|
|
if (R.isError(result)) {
|
|
|
return R.fail(result.getData());
|
|
return R.fail(result.getData());
|
|
|
}
|
|
}
|
|
|
|
|
+ log.info("卡类限次检查耗时:{}", System.currentTimeMillis()-startTime);
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|