|
@@ -6,15 +6,10 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
-import org.dromara.backstage.api.RemoteCardService;
|
|
|
|
|
-import org.dromara.backstage.api.RemoteMealTypeService;
|
|
|
|
|
-import org.dromara.backstage.api.RemoteOperatorService;
|
|
|
|
|
-import org.dromara.backstage.api.RemoteUserAccountService;
|
|
|
|
|
-import org.dromara.backstage.api.domain.vo.RemoteCardVo;
|
|
|
|
|
-import org.dromara.backstage.api.domain.vo.RemoteMealTypeVo;
|
|
|
|
|
-import org.dromara.backstage.api.domain.vo.RemoteOperatorVo;
|
|
|
|
|
-import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
|
|
|
|
|
|
|
+import org.dromara.backstage.api.*;
|
|
|
|
|
+import org.dromara.backstage.api.domain.vo.*;
|
|
|
import org.dromara.common.core.constant.ApiErrorTypeConstants;
|
|
import org.dromara.common.core.constant.ApiErrorTypeConstants;
|
|
|
import org.dromara.common.core.domain.R;
|
|
import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.domain.model.ErrorInfo;
|
|
import org.dromara.common.core.domain.model.ErrorInfo;
|
|
@@ -32,6 +27,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.text.MessageFormat;
|
|
import java.text.MessageFormat;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -61,6 +57,14 @@ public class CheckBusiness {
|
|
|
private final RemoteMealTypeService remoteMealTypeService;
|
|
private final RemoteMealTypeService remoteMealTypeService;
|
|
|
@DubboReference
|
|
@DubboReference
|
|
|
private final RemoteOperatorService remoteOperatorService;
|
|
private final RemoteOperatorService remoteOperatorService;
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private final RemotePtParameterService remotePtParameterService;
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private final RemoteXfLimitedService remoteLimitedService;
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private final RemoteXfDiscountService remoteDisCountService;
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private final RemoteXfQuotaService remoteQuotaService;
|
|
|
|
|
|
|
|
private final IXfTermService termService;
|
|
private final IXfTermService termService;
|
|
|
private final IConsumeDetailOriginalService consumeDetailOriginalService;
|
|
private final IConsumeDetailOriginalService consumeDetailOriginalService;
|
|
@@ -87,7 +91,7 @@ public class CheckBusiness {
|
|
|
// 检查交易人员标识
|
|
// 检查交易人员标识
|
|
|
if (bo.getCardNo() <= 0 && bo.getFactoryId() == 0 && bo.getUserNo() <= 0 && StrUtil.isEmpty(bo.getUserNumb())) {
|
|
if (bo.getCardNo() <= 0 && bo.getFactoryId() == 0 && bo.getUserNo() <= 0 && StrUtil.isEmpty(bo.getUserNumb())) {
|
|
|
errorInfo = new ErrorInfo(1, ApiErrorTypeConstants.PARAM_ERROR, "交易人员标识不满足",
|
|
errorInfo = new ErrorInfo(1, ApiErrorTypeConstants.PARAM_ERROR, "交易人员标识不满足",
|
|
|
- "必须提供 [CardNo | FactoryId | userNo | userNumb] 中至少1项来标识交易用户");
|
|
|
|
|
|
|
+ "必须提供 [CardNo | FactoryId | userNo | userNumb] 中至少1项来标识交易用户");
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
return R.ok();
|
|
return R.ok();
|
|
@@ -106,7 +110,7 @@ public class CheckBusiness {
|
|
|
TermToken token = tokenManager.getTermToken().get(String.valueOf(termNo));
|
|
TermToken token = tokenManager.getTermToken().get(String.valueOf(termNo));
|
|
|
if (ObjectUtil.isEmpty(token)) {
|
|
if (ObjectUtil.isEmpty(token)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.INVALID_TOKEN, "Token不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.INVALID_TOKEN, "Token不存在",
|
|
|
- MessageFormat.format("没有找到机号为[{0}]的设备的Token!", termNo));
|
|
|
|
|
|
|
+ MessageFormat.format("没有找到机号为[{0}]的设备的Token!", termNo));
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
if (ObjectUtil.isNotEmpty(mac)) {
|
|
if (ObjectUtil.isNotEmpty(mac)) {
|
|
@@ -160,7 +164,7 @@ public class CheckBusiness {
|
|
|
XfTermVo termVo = termService.queryVoOneByNo(termNo);
|
|
XfTermVo termVo = termService.queryVoOneByNo(termNo);
|
|
|
if (ObjectUtil.isEmpty(termVo)) {
|
|
if (ObjectUtil.isEmpty(termVo)) {
|
|
|
ErrorInfo errorInfo = new ErrorInfo(400, "", "设备不存在",
|
|
ErrorInfo errorInfo = new ErrorInfo(400, "", "设备不存在",
|
|
|
- MessageFormat.format("机号为[{0}]的设备不存在,不允许交易", termNo));
|
|
|
|
|
|
|
+ MessageFormat.format("机号为[{0}]的设备不存在,不允许交易", termNo));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
@@ -239,6 +243,9 @@ public class CheckBusiness {
|
|
|
// 获取营业员信息
|
|
// 获取营业员信息
|
|
|
BeanUtil.copyProperties(getOperatorVo(bo), operatorVo);
|
|
BeanUtil.copyProperties(getOperatorVo(bo), operatorVo);
|
|
|
|
|
|
|
|
|
|
+ // 更新卡片的折扣、限额与限次信息
|
|
|
|
|
+ updateOtherConsumeInfo(bo, userCardVo, mealTypeVo, useTermVo);
|
|
|
|
|
+
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -255,13 +262,13 @@ public class CheckBusiness {
|
|
|
RemoteCardVo cardVo = remoteCardService.queryCardByCardNo(cardNo);
|
|
RemoteCardVo cardVo = remoteCardService.queryCardByCardNo(cardNo);
|
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
|
- MessageFormat.format("流水号为[{0}]的卡片不存在,不允许交易", cardNo));
|
|
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的卡片不存在,不允许交易", cardNo));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
if (!"1".equals(cardVo.getStatus())) {
|
|
if (!"1".equals(cardVo.getStatus())) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
|
- MessageFormat.format("流水号为[{0}]的卡片状态不正确,不允许交易", cardNo));
|
|
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的卡片状态不正确,不允许交易", cardNo));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
@@ -287,14 +294,14 @@ public class CheckBusiness {
|
|
|
RemoteCardVo cardVo = remoteCardService.queryCardByFactoryId(factoryId);
|
|
RemoteCardVo cardVo = remoteCardService.queryCardByFactoryId(factoryId);
|
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
|
- MessageFormat.format("物理卡号为[{0}]的卡片不存在,不允许交易", factoryId));
|
|
|
|
|
|
|
+ MessageFormat.format("物理卡号为[{0}]的卡片不存在,不允许交易", factoryId));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
if (!"1".equals(cardVo.getStatus())) {
|
|
if (!"1".equals(cardVo.getStatus())) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
|
- MessageFormat.format("物理卡号为[{0}]的卡片卡片状态不正确,不允许交易",
|
|
|
|
|
- factoryId));
|
|
|
|
|
|
|
+ MessageFormat.format("物理卡号为[{0}]的卡片卡片状态不正确,不允许交易",
|
|
|
|
|
+ factoryId));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
@@ -313,20 +320,20 @@ public class CheckBusiness {
|
|
|
RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoByUserNo(userNo);
|
|
RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoByUserNo(userNo);
|
|
|
if (ObjectUtil.isEmpty(accountVo)) {
|
|
if (ObjectUtil.isEmpty(accountVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "人员不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "人员不存在",
|
|
|
- MessageFormat.format("流水号为[{0}]的人员不存在,不允许交易", userNo));
|
|
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的人员不存在,不允许交易", userNo));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(accountVo.getUserId());
|
|
RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(accountVo.getUserId());
|
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
|
- MessageFormat.format("流水号为[{0}]的人员卡片不存在,不允许交易", userNo));
|
|
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的人员卡片不存在,不允许交易", userNo));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
if (!"1".equals(cardVo.getStatus())) {
|
|
if (!"1".equals(cardVo.getStatus())) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
|
- MessageFormat.format("流水号为[{0}]的人员卡片状态不正确,不允许交易", userNo));
|
|
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的人员卡片状态不正确,不允许交易", userNo));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
@@ -346,20 +353,20 @@ public class CheckBusiness {
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(accountVo)) {
|
|
if (ObjectUtil.isEmpty(accountVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "人员不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "人员不存在",
|
|
|
- MessageFormat.format("编号为[{0}]的人员不存在,不允许交易", userNumb));
|
|
|
|
|
|
|
+ MessageFormat.format("编号为[{0}]的人员不存在,不允许交易", userNumb));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(accountVo.getUserId());
|
|
RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(accountVo.getUserId());
|
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
|
- MessageFormat.format("编号为[{0}]的人员卡片不存在,不允许交易", userNumb));
|
|
|
|
|
|
|
+ MessageFormat.format("编号为[{0}]的人员卡片不存在,不允许交易", userNumb));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
if (!"1".equals(cardVo.getStatus())) {
|
|
if (!"1".equals(cardVo.getStatus())) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
|
- MessageFormat.format("编号为[{0}]的人员卡片状态不正确,不允许交易", userNumb));
|
|
|
|
|
|
|
+ MessageFormat.format("编号为[{0}]的人员卡片状态不正确,不允许交易", userNumb));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
@@ -375,18 +382,18 @@ public class CheckBusiness {
|
|
|
|
|
|
|
|
private R<ErrorInfo> checkOriginalRecord(ConsumptionBo bo) {
|
|
private R<ErrorInfo> checkOriginalRecord(ConsumptionBo bo) {
|
|
|
String originalId = RecordIdUtils.getRecordId(bo.getConsumeDate(), bo.getTermNo().shortValue(),
|
|
String originalId = RecordIdUtils.getRecordId(bo.getConsumeDate(), bo.getTermNo().shortValue(),
|
|
|
- bo.getTermRecordId().shortValue(), bo.getUserNo().intValue(), 0);
|
|
|
|
|
|
|
+ bo.getTermRecordId().shortValue(), bo.getUserNo().intValue(), 0);
|
|
|
XfConsumeDetailOriginalVo consumeDetailOriginalVo = consumeDetailOriginalService.queryById(originalId);
|
|
XfConsumeDetailOriginalVo consumeDetailOriginalVo = consumeDetailOriginalService.queryById(originalId);
|
|
|
if (ObjectUtil.isEmpty(consumeDetailOriginalVo)) {
|
|
if (ObjectUtil.isEmpty(consumeDetailOriginalVo)) {
|
|
|
// TODO 正常应该是进行记录类型和脱机消费的检查,此处先按错误处理
|
|
// TODO 正常应该是进行记录类型和脱机消费的检查,此处先按错误处理
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "原始消费记录不存在",
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "原始消费记录不存在",
|
|
|
- MessageFormat.format("标识为[{0}]的原始消费记录不存在", bo.getRecordId())));
|
|
|
|
|
|
|
+ MessageFormat.format("标识为[{0}]的原始消费记录不存在", bo.getRecordId())));
|
|
|
}
|
|
}
|
|
|
XfConsumeDetailVo consumeDetailVo = consumeDetailService.queryVoByOriginalId(originalId);
|
|
XfConsumeDetailVo consumeDetailVo = consumeDetailService.queryVoByOriginalId(originalId);
|
|
|
if (ObjectUtil.isNotEmpty(consumeDetailVo)) {
|
|
if (ObjectUtil.isNotEmpty(consumeDetailVo)) {
|
|
|
// 认为是重复上传,不再入账
|
|
// 认为是重复上传,不再入账
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.RECORD_IS_EXISTS, "原始消费记录已处理",
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.RECORD_IS_EXISTS, "原始消费记录已处理",
|
|
|
- MessageFormat.format("标识为[{0}]的原始消费记录已处理", bo.getRecordId())));
|
|
|
|
|
|
|
+ MessageFormat.format("标识为[{0}]的原始消费记录已处理", bo.getRecordId())));
|
|
|
}
|
|
}
|
|
|
bo.setOriginalId(originalId);
|
|
bo.setOriginalId(originalId);
|
|
|
return R.ok();
|
|
return R.ok();
|
|
@@ -434,15 +441,16 @@ public class CheckBusiness {
|
|
|
if (doMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
if (doMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
// 循环扣费后,如果还有未扣的金额,表示钱包余额不足,不允许交易
|
|
// 循环扣费后,如果还有未扣的金额,表示钱包余额不足,不允许交易
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.CONSUME_CHECK_FAIL, "钱包余额不足",
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.CONSUME_CHECK_FAIL, "钱包余额不足",
|
|
|
- MessageFormat.format("余额不足,余额[{0}],消费金额[{1}]", totalBalance,
|
|
|
|
|
- consumeMoney)));
|
|
|
|
|
|
|
+ MessageFormat.format("余额不足,余额[{0}],消费金额[{1}]", totalBalance,
|
|
|
|
|
+ consumeMoney)));
|
|
|
}
|
|
}
|
|
|
bo.setBalance(totalBalance.subtract(consumeMoney));
|
|
bo.setBalance(totalBalance.subtract(consumeMoney));
|
|
|
bagVos.addAll(doBagVos);
|
|
bagVos.addAll(doBagVos);
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public R<ErrorInfo> checkTermLimitDeal(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, RemoteCardVo userCardVo, RemoteMealTypeVo mealTypeVo) {
|
|
|
|
|
|
|
+ public R<ErrorInfo> checkTermLimitDeal(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, RemoteCardVo userCardVo,
|
|
|
|
|
+ RemoteMealTypeVo mealTypeVo) {
|
|
|
Long termNo = termVo.getTermNo();
|
|
Long termNo = termVo.getTermNo();
|
|
|
BigDecimal consumeValue = bo.getConsumeMoney();
|
|
BigDecimal consumeValue = bo.getConsumeMoney();
|
|
|
Long factoryFixId = userCardVo.getFactoryId();
|
|
Long factoryFixId = userCardVo.getFactoryId();
|
|
@@ -477,7 +485,7 @@ public class CheckBusiness {
|
|
|
|
|
|
|
|
// 设备消费间隔验证
|
|
// 设备消费间隔验证
|
|
|
if ((currentLocalDt.toEpochSecond(ZoneOffset.of("+8"))
|
|
if ((currentLocalDt.toEpochSecond(ZoneOffset.of("+8"))
|
|
|
- - lastPayLocalDt.toEpochSecond(ZoneOffset.of("+8"))) / 60 < termSwipeInterval && termSwipeInterval > 0) {// 消费间隔
|
|
|
|
|
|
|
+ - lastPayLocalDt.toEpochSecond(ZoneOffset.of("+8"))) / 60 < termSwipeInterval && termSwipeInterval > 0) {// 消费间隔
|
|
|
return R.fail(new ErrorInfo(400, TradeStatusEnum.TimeInterval.toString(), "超过设备单次限额", TradeStatusEnum.TimeInterval.getName()));
|
|
return R.fail(new ErrorInfo(400, TradeStatusEnum.TimeInterval.toString(), "超过设备单次限额", TradeStatusEnum.TimeInterval.getName()));
|
|
|
}
|
|
}
|
|
|
// 设备单次限额验证
|
|
// 设备单次限额验证
|
|
@@ -486,7 +494,8 @@ public class CheckBusiness {
|
|
|
}
|
|
}
|
|
|
// 设备启用了卡有效时进行卡有效期验证
|
|
// 设备启用了卡有效时进行卡有效期验证
|
|
|
if (factoryFixId != 0 && termUseValidity && currentLocalDt.isAfter(expiryLocalDt)) {
|
|
if (factoryFixId != 0 && termUseValidity && currentLocalDt.isAfter(expiryLocalDt)) {
|
|
|
- return R.fail(new ErrorInfo(400, TradeStatusEnum.CardValidDate.toString(), "卡片已超过失效日期", TradeStatusEnum.CardValidDate.getName()));
|
|
|
|
|
|
|
+ return R.fail(
|
|
|
|
|
+ new ErrorInfo(400, TradeStatusEnum.CardValidDate.toString(), "卡片已超过失效日期", TradeStatusEnum.CardValidDate.getName()));
|
|
|
}
|
|
}
|
|
|
// 消费卡类限制验证
|
|
// 消费卡类限制验证
|
|
|
int offsetTypeId = (int) Math.pow(2, (cardTypeId - 1));
|
|
int offsetTypeId = (int) Math.pow(2, (cardTypeId - 1));
|
|
@@ -494,12 +503,12 @@ public class CheckBusiness {
|
|
|
if (temp != offsetTypeId) {
|
|
if (temp != offsetTypeId) {
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "设备卡类限制", TradeStatusEnum.CardTypeLimit.getName()));
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "设备卡类限制", TradeStatusEnum.CardTypeLimit.getName()));
|
|
|
}
|
|
}
|
|
|
- //餐限次验证
|
|
|
|
|
|
|
+ // 餐限次验证
|
|
|
String lastMeal = userCardVo.getLastMeal().toString();
|
|
String lastMeal = userCardVo.getLastMeal().toString();
|
|
|
int mealCount = userCardVo.getMealCount().intValue();
|
|
int mealCount = userCardVo.getMealCount().intValue();
|
|
|
BigDecimal mealValue = userCardVo.getMealTotal();
|
|
BigDecimal mealValue = userCardVo.getMealTotal();
|
|
|
if (!ObjectUtil.equals(lastMeal, mealTypeId)
|
|
if (!ObjectUtil.equals(lastMeal, mealTypeId)
|
|
|
- || !currentLocalDt.toLocalDate().isEqual(lastPayLocalDt.toLocalDate())) {
|
|
|
|
|
|
|
+ || !currentLocalDt.toLocalDate().isEqual(lastPayLocalDt.toLocalDate())) {
|
|
|
remoteCardService.initCardMealData(userCardVo.getCardNo(), mealTypeId);
|
|
remoteCardService.initCardMealData(userCardVo.getCardNo(), mealTypeId);
|
|
|
lastMeal = mealTypeId;
|
|
lastMeal = mealTypeId;
|
|
|
mealCount = 0;
|
|
mealCount = 0;
|
|
@@ -513,6 +522,8 @@ public class CheckBusiness {
|
|
|
int dayCount = userCardVo.getDayCount().intValue();
|
|
int dayCount = userCardVo.getDayCount().intValue();
|
|
|
BigDecimal dayValue = userCardVo.getDayTotal();
|
|
BigDecimal dayValue = userCardVo.getDayTotal();
|
|
|
|
|
|
|
|
|
|
+ LocalDate t1 = currentLocalDt.toLocalDate();
|
|
|
|
|
+ LocalDate t2 = lastPayLocalDt.toLocalDate();
|
|
|
if (!currentLocalDt.toLocalDate().isEqual(lastPayLocalDt.toLocalDate())) {
|
|
if (!currentLocalDt.toLocalDate().isEqual(lastPayLocalDt.toLocalDate())) {
|
|
|
remoteCardService.initCardDayData(userCardVo.getCardNo());
|
|
remoteCardService.initCardDayData(userCardVo.getCardNo());
|
|
|
dayCount = 0;
|
|
dayCount = 0;
|
|
@@ -525,6 +536,10 @@ public class CheckBusiness {
|
|
|
return R.fail(new ErrorInfo(400, TradeStatusEnum.DayLimitMoney.toString(), "日限额", TradeStatusEnum.DayLimitMoney.getName()));
|
|
return R.fail(new ErrorInfo(400, TradeStatusEnum.DayLimitMoney.toString(), "日限额", TradeStatusEnum.DayLimitMoney.getName()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ R<ErrorInfo> result = checkCardLimitDeal(bo, termVo, userCardVo, mealTypeVo);
|
|
|
|
|
+ if (R.isError(result)) {
|
|
|
|
|
+ return R.fail(result.getData());
|
|
|
|
|
+ }
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -550,7 +565,7 @@ public class CheckBusiness {
|
|
|
Long zkMealCount = cardLimitedVo.getMealDiscountCount();
|
|
Long zkMealCount = cardLimitedVo.getMealDiscountCount();
|
|
|
// 最后交易时间
|
|
// 最后交易时间
|
|
|
LocalDateTime lastPayLimitLocalDt = LocalDateTime.ofInstant(cardLimitedVo.getLastPay().toInstant(),
|
|
LocalDateTime lastPayLimitLocalDt = LocalDateTime.ofInstant(cardLimitedVo.getLastPay().toInstant(),
|
|
|
- ZoneOffset.of("+8"));
|
|
|
|
|
|
|
+ ZoneOffset.of("+8"));
|
|
|
// 最后交易餐类
|
|
// 最后交易餐类
|
|
|
Long lastPayLimitMealType = cardLimitedVo.getLastMeal();
|
|
Long lastPayLimitMealType = cardLimitedVo.getLastMeal();
|
|
|
// 判断交易是否为新的一天(重置各项数据)
|
|
// 判断交易是否为新的一天(重置各项数据)
|
|
@@ -575,10 +590,160 @@ public class CheckBusiness {
|
|
|
zkMealCount = 0L;
|
|
zkMealCount = 0L;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 卡类限次检查
|
|
|
|
|
+ R<ErrorInfo> result = checkCardLimited(termVo, userCardVo, cardLimitedVo, mealTypeVo);
|
|
|
|
|
+ if (R.isError(result)) {
|
|
|
|
|
+ return R.fail(result.getData());
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private R<ErrorInfo> checkCardLimited(XfTermVo termVo, RemoteCardVo userCardVo, XfCardLimitedVo cardLimitedVo, RemoteMealTypeVo mealTypeVo) {
|
|
|
|
|
+ String useLimited = remotePtParameterService.getPtParameterByKey("XC_CONSUME");
|
|
|
|
|
+ String mealType = mealTypeVo.getTypeId();
|
|
|
|
|
+ if (StrUtil.isEmpty(useLimited) || ObjectUtil.notEqual(useLimited, "1")) {
|
|
|
|
|
+ // 如果没有启用限次,直接返回
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ Long limitedTermId = remoteLimitedService.queryLimitedTermIdByTermId(termVo.getTermId());
|
|
|
|
|
+ if (ObjectUtil.equals(limitedTermId, 0L)) {
|
|
|
|
|
+ // 当前设备没有设置限次
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ RemoteLimitedVo remoteLimitedVo = remoteLimitedService.queryLimitedByCardType(userCardVo.getCardType().intValue());
|
|
|
|
|
+ if (ObjectUtil.isEmpty(remoteLimitedVo)) {
|
|
|
|
|
+ // 当前卡类没有限次信息
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ String limitedStatus = remoteLimitedVo.getStatus();
|
|
|
|
|
+ if (ObjectUtil.isEmpty(limitedStatus) || ObjectUtil.equals(limitedStatus, "0")) {
|
|
|
|
|
+ // 卡类限次未启用
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 每日次数
|
|
|
|
|
+ Long dayCount = remoteLimitedVo.getDailyCount();
|
|
|
|
|
+ // 早餐次数
|
|
|
|
|
+ Long oneCount = remoteLimitedVo.getOneCount();
|
|
|
|
|
+ // 午餐次数
|
|
|
|
|
+ Long twoCount = remoteLimitedVo.getTwoCount();
|
|
|
|
|
+ // 晚餐次数
|
|
|
|
|
+ Long threeCount = remoteLimitedVo.getThreeCount();
|
|
|
|
|
+ // 宵夜次数
|
|
|
|
|
+ Long fourCount = remoteLimitedVo.getFourCount();
|
|
|
|
|
+
|
|
|
|
|
+ if (dayCount.compareTo(0L) > 0 || oneCount.compareTo(0L) > 0 || twoCount.compareTo(0L) > 0 || threeCount.compareTo(
|
|
|
|
|
+ 0L) > 0 || fourCount.compareTo(0L) > 0) {
|
|
|
|
|
+ if (dayCount.compareTo(0L) > 0) {
|
|
|
|
|
+ // 日限次
|
|
|
|
|
+ if (cardLimitedVo.getDayCount().compareTo(dayCount) > 0) {
|
|
|
|
|
+ return R.fail(
|
|
|
|
|
+ new ErrorInfo(400, TradeStatusEnum.DayLimitTimes.toString(), "卡类日限制次数", TradeStatusEnum.DayLimitTimes.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 早餐限次
|
|
|
|
|
+ if (ObjectUtil.equals(mealType, "1")) {
|
|
|
|
|
+ if (cardLimitedVo.getMealCount().compareTo(oneCount) > 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitTimes.toString(), "卡类早餐限制次数",
|
|
|
|
|
+ TradeStatusEnum.MealLimitTimes.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 午餐限次
|
|
|
|
|
+ if (ObjectUtil.equals(mealType, "2")) {
|
|
|
|
|
+ if (cardLimitedVo.getMealCount().compareTo(twoCount) > 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitTimes.toString(), "卡类午餐限制次数",
|
|
|
|
|
+ TradeStatusEnum.MealLimitTimes.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 晚餐限次
|
|
|
|
|
+ if (ObjectUtil.equals(mealType, "3")) {
|
|
|
|
|
+ if (cardLimitedVo.getMealCount().compareTo(threeCount) > 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitTimes.toString(), "卡类晚餐限制次数",
|
|
|
|
|
+ TradeStatusEnum.MealLimitTimes.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 宵夜限次
|
|
|
|
|
+ if (ObjectUtil.equals(mealType, "4")) {
|
|
|
|
|
+ if (cardLimitedVo.getMealCount().compareTo(fourCount) > 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitTimes.toString(), "卡类夜宵限制次数",
|
|
|
|
|
+ TradeStatusEnum.MealLimitTimes.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新其它消费信息
|
|
|
|
|
+ * 1.更新卡片交易信息
|
|
|
|
|
+ * @param bo 交易业务对象
|
|
|
|
|
+ * @param userCardVo 卡片视图对象
|
|
|
|
|
+ * @param mealTypeVo 餐类视图对象
|
|
|
|
|
+ * @param termVo 设备视图对象
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateOtherConsumeInfo(ConsumptionBo bo, RemoteCardVo userCardVo, RemoteMealTypeVo mealTypeVo,XfTermVo termVo) {
|
|
|
|
|
+ Long mealType = Long.parseLong(mealTypeVo.getTypeId());
|
|
|
|
|
+ Date consumeDate = bo.getConsumeDate();
|
|
|
|
|
+ String currentDateStr = DateFormatUtils.format(new Date(), "yyyy-MM-dd");
|
|
|
|
|
+ String consumeDateStr = DateFormatUtils.format(consumeDate, "yyyy-MM-dd");
|
|
|
|
|
+ if (ObjectUtil.equals(currentDateStr, consumeDateStr)) {
|
|
|
|
|
+ // 更新卡片交易信息
|
|
|
|
|
+ Boolean result = remoteCardService.updateCardDayData(userCardVo.getCardNo(), mealType, bo.getConsumeMoney(), consumeDate);
|
|
|
|
|
+
|
|
|
|
|
+ // 限次消费处理
|
|
|
|
|
+ String useLimited = remotePtParameterService.getPtParameterByKey("XC_CONSUME");
|
|
|
|
|
+ // 启用了限次
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(useLimited) && ObjectUtil.equals(useLimited, "1")) {
|
|
|
|
|
+ Long limitedTermId = remoteLimitedService.queryLimitedTermIdByTermId(termVo.getTermId());
|
|
|
|
|
+ // 当前设备也有限次
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(limitedTermId) && limitedTermId > 0) {
|
|
|
|
|
+ // 查询卡类的限次信息
|
|
|
|
|
+ RemoteLimitedVo remoteLimitedVo = remoteLimitedService.queryLimitedByCardType(userCardVo.getCardType().intValue());
|
|
|
|
|
+ // 有卡类的限次信息并已启用
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(remoteLimitedVo) && ObjectUtil.equals(remoteLimitedVo.getStatus(), "1")) {
|
|
|
|
|
+ // 更新卡类的限次信息
|
|
|
|
|
+ result = cardLimitedService.updateLimitedData(userCardVo.getCardNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 限额消费处理
|
|
|
|
|
+ String useQuota = remotePtParameterService.getPtParameterByKey("XE_CONSUME");
|
|
|
|
|
+ // 启用了限额
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(useQuota) && ObjectUtil.equals(useQuota, "1")) {
|
|
|
|
|
+ Long quotaId = remoteQuotaService.queryQuotaTermIdByTermId(termVo.getTermId());
|
|
|
|
|
+ // 当前设备也有限额
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(quotaId) && quotaId > 0) {
|
|
|
|
|
+ // 查询卡类的限额信息
|
|
|
|
|
+ RemoteQuotaVo remoteQuotaVo = remoteQuotaService.queryQuotaByCardType(userCardVo.getCardType().intValue());
|
|
|
|
|
+ // 有卡类的限额信息并已启用
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(remoteQuotaVo) && ObjectUtil.equals(remoteQuotaVo.getStatus(), "1")) {
|
|
|
|
|
+ // 更新卡类的限额信息
|
|
|
|
|
+ result = cardLimitedService.updateQuotaData(userCardVo.getCardNo(),bo.getConsumeMoney());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 折扣消费处理
|
|
|
|
|
+ String useDisCount = remotePtParameterService.getPtParameterByKey("RATE_CONSUME");
|
|
|
|
|
+ // 启用了折扣
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(useDisCount) && ObjectUtil.equals(useDisCount, "1")) {
|
|
|
|
|
+ Long disCountTermId = remoteDisCountService.queryDisCountTermIdByTermId(termVo.getTermId());
|
|
|
|
|
+ // 当前设备也有折扣
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(disCountTermId) && disCountTermId > 0) {
|
|
|
|
|
+ // 查询卡类的折扣信息
|
|
|
|
|
+ RemoteDiscountVo remoteDisCountVo = remoteDisCountService.queryDisCountByCardType(userCardVo.getCardType().intValue());
|
|
|
|
|
+ // 有卡类的折扣信息并已启用
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(remoteDisCountVo) && ObjectUtil.equals(remoteDisCountVo.getStatus(), "1")) {
|
|
|
|
|
+ // 更新卡类的折扣信息
|
|
|
|
|
+ result = cardLimitedService.updateDisCountData(userCardVo.getCardNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private XfCardLimitedVo initXfCardLimited(Long cardNo, Long mealType, RemoteCardVo userCardVo) {
|
|
private XfCardLimitedVo initXfCardLimited(Long cardNo, Long mealType, RemoteCardVo userCardVo) {
|
|
|
LocalDateTime lastPayLocalDt = LocalDateTime.ofInstant(userCardVo.getLastPay().toInstant(), ZoneOffset.of("+8"));
|
|
LocalDateTime lastPayLocalDt = LocalDateTime.ofInstant(userCardVo.getLastPay().toInstant(), ZoneOffset.of("+8"));
|
|
|
;
|
|
;
|