Просмотр исходного кода

feature: 消费请求增加了消费卡类判断

luo.yibo@datuai.com 1 год назад
Родитель
Сommit
79d7c61058

+ 66 - 16
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/CheckBusiness.java

@@ -17,6 +17,7 @@ import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
 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;
+import org.dromara.common.core.enums.UserAccountStatusEnum;
 import org.dromara.common.core.utils.RecordIdUtils;
 import org.dromara.common.core.utils.RecordIdUtils;
 import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
 import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
 import org.dromara.server.consume.domain.vo.PtBagVo;
 import org.dromara.server.consume.domain.vo.PtBagVo;
@@ -89,7 +90,7 @@ public class CheckBusiness {
     }
     }
 
 
     /**
     /**
-     * 消费记录人员、卡片检查,一切通过后获取到消费账户、卡片及设备的视图信息
+     * 消费记录人员、卡片检查,全部通过后获取到消费账户、卡片及设备的视图信息
      *
      *
      * @param bo            消费记录
      * @param bo            消费记录
      * @param userAccountVo 消费账户
      * @param userAccountVo 消费账户
@@ -104,6 +105,7 @@ public class CheckBusiness {
         long factoryId = ObjectUtil.isEmpty(bo.getFactoryId()) ? 0 : bo.getFactoryId();
         long factoryId = ObjectUtil.isEmpty(bo.getFactoryId()) ? 0 : bo.getFactoryId();
         long userNo = ObjectUtil.isEmpty(bo.getUserNo()) ? 0 : bo.getUserNo();
         long userNo = ObjectUtil.isEmpty(bo.getUserNo()) ? 0 : bo.getUserNo();
         String userNumb = bo.getUserNumb() == null ? null : bo.getUserNumb();
         String userNumb = bo.getUserNumb() == null ? null : bo.getUserNumb();
+        // 获取设备信息
         if (termNo > 0) {
         if (termNo > 0) {
             R<ErrorInfo> result = checkTerm(bo, useTermVo);
             R<ErrorInfo> result = checkTerm(bo, useTermVo);
             if (R.isError(result)) {
             if (R.isError(result)) {
@@ -158,14 +160,37 @@ public class CheckBusiness {
      * @param useTermVo     消费设备
      * @param useTermVo     消费设备
      * @return 验证结果
      * @return 验证结果
      */
      */
-    public R<ErrorInfo> checkConsume(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo,
-                                     XfTermVo useTermVo) {
-        // TODO 2024-11-03 14:36:42 luoyibo 1.获取传入的参数
-        // TODO 2024-11-03 14:36:42 luoyibo 2.卡有效性验证
-        // TODO 2024-11-03 14:39:21 luoyibo 3.消费账户状态验证
-        // TODO 2024-11-03 14:39:49 luoyibo 4.餐类验证
-        // TODO 2024-11-03 14:41:28 luoyibo 5.折扣\限额\限次验证
-        // TODO 2024-11-03 14:45:18 luoyibo 6.根据消费机的消费模式验证余额
+    public R<ErrorInfo> checkConsume(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo, XfTermVo useTermVo) {
+        R<ErrorInfo> result;
+        // 1.消费账户状态验证,验证账户是否已开户、是否冻结、状态是否正常、是否过有效期
+        if ("Y".equals(userAccountVo.getFreezeStatus())) {
+            return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户已被冻结", "账户已被冻结"));
+        }
+        if ("N".equals(userAccountVo.getStatus())) {
+            return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户状态不正常", "账户状态不正常"));
+        }
+        if (!ObjectUtil.equal(userAccountVo.getAccountStatus(), UserAccountStatusEnum.IS_OPEN.code().toString())) {
+            return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户尚未开户", "账户尚未开户"));
+        }
+        if (userAccountVo.getLifespan() != null && bo.getConsumeDate().getTime() > userAccountVo.getLifespan().getTime()) {
+            return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户已过有效期", "账户已过有效期"));
+        }
+        // 2.餐类验证
+        RemoteMealTypeVo mealType = remoteMealTypeService.queryMealTypeVoByTime(bo.getConsumeDate());
+        if (ObjectUtil.isEmpty(mealType)) {
+            return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "不在交易时段", "不在交易时段"));
+        }
+        // 3.折扣\限额\限次验证
+        Boolean b = checkLimitDeal(bo, userAccountVo, useTermVo, userCardVo, mealType);
+        if (!b) {
+            return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "消费限制判断存在问题", "消费限制判断存在问题"));
+        }
+        // 4.根据消费机的消费模式验证余额,如果余额不足则返回
+        List<PtBagVo> bagVos = new ArrayList<>();
+        result = checkDeductionBag(bo, userAccountVo, useTermVo, bagVos);
+        if (R.isError(result)) {
+            return result;
+        }
         return R.ok();
         return R.ok();
     }
     }
 
 
@@ -223,11 +248,12 @@ public class CheckBusiness {
 
 
             return R.fail(errorInfo);
             return R.fail(errorInfo);
         }
         }
-        if (!Objects.equals(cardVo.getFactoryId(), bo.getFactoryId())) {
-            errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不正确",
-                                      "物理卡号不一致,不允许交易");
+        if (bo.getFactoryId() > 0) {
+            if (!Objects.equals(cardVo.getFactoryId(), bo.getFactoryId())) {
+                errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不正确", "物理卡号不一致,不允许交易");
 
 
-            return R.fail(errorInfo);
+                return R.fail(errorInfo);
+            }
         }
         }
         RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoById(cardVo.getUserId());
         RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoById(cardVo.getUserId());
         setUserInfo(bo, accountVo);
         setUserInfo(bo, accountVo);
@@ -349,9 +375,8 @@ public class CheckBusiness {
         return R.ok();
         return R.ok();
     }
     }
 
 
-    public R<ErrorInfo> checkDeductionBag(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo,
-                                          List<PtBagVo> bagVos) {
-        // 设备的扣费钱包串
+    public R<ErrorInfo> checkDeductionBag(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, List<PtBagVo> bagVos) {
+        // 设备的扣费钱包字符串
         String consumeType = termVo.getConsumeType();
         String consumeType = termVo.getConsumeType();
         // 分解扣费钱包
         // 分解扣费钱包
         List<String> bagCodes = StrUtil.split(consumeType, ",");
         List<String> bagCodes = StrUtil.split(consumeType, ",");
@@ -399,6 +424,31 @@ public class CheckBusiness {
         return R.ok();
         return R.ok();
     }
     }
 
 
+    public Boolean checkLimitDeal(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, RemoteCardVo userCardVo,
+                                  RemoteMealTypeVo mealTypeVo) {
+        Long termNo = termVo.getTermNo();
+        String mealTypeId = mealTypeVo.getTypeId();
+        if (termNo == 0 && ObjectUtil.equal("0", mealTypeId)) {
+            return Boolean.TRUE;
+        }
+        // 设备允许卡类
+        Integer termCardTypeId = termVo.getCardType() == null ? 0 : termVo.getCardType();
+        // 设备每天最大消费次数
+        Integer termDayCount = termVo.getDayCount() == null ? 0 : termVo.getDayCount();
+        // 每天最大消费金额
+        BigDecimal termDayMoney = termVo.getDayMoney() == null ? BigDecimal.ZERO : termVo.getDayMoney();
+        // 每餐最大消费次数
+        Integer termmealCount = termVo.getMealCount() == null ? 0 : termVo.getMealCount();
+        // 单次最大消费金额
+        BigDecimal termSignleMoney = termVo.getSingleMoney() == null ? BigDecimal.ZERO : termVo.getSingleMoney();
+        // 二次可用最大时间间隔
+        Integer termSwipeInterval = termVo.getSwipeInterval() == null ? 0 : termVo.getSwipeInterval();
+        // 设备是否启用了卡有效
+        Boolean termUseValidity = Objects.equals(termVo.getTermValidity(), "0") ? Boolean.FALSE : Boolean.TRUE;
+
+        return false;
+    }
+
     private RemoteOperatorVo getOperatorVo(ConsumptionBo bo) {
     private RemoteOperatorVo getOperatorVo(ConsumptionBo bo) {
         RemoteOperatorVo operatorVo = remoteOperatorService.getVoById(bo.getOperatorId());
         RemoteOperatorVo operatorVo = remoteOperatorService.getVoById(bo.getOperatorId());
         if (ObjectUtil.isEmpty(operatorVo)) {
         if (ObjectUtil.isEmpty(operatorVo)) {

+ 169 - 0
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/domain/vo/XfTermVo.java

@@ -7,6 +7,7 @@ import org.dromara.server.consume.domain.XfTerm;
 
 
 import java.io.Serial;
 import java.io.Serial;
 import java.io.Serializable;
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 
 
 
 /**
 /**
@@ -100,4 +101,172 @@ public class XfTermVo implements Serializable {
      */
      */
     private String tenantId;
     private String tenantId;
 
 
+    //region 以下为消费机的参数属性
+    private Integer cardType;
+
+    /**
+     * 消费工作模式,见XF_WorkMode字典类别
+     */
+    private String workMode;
+
+    /**
+     * 开机模式,0-不需要营业员开机,1-需要营业员开机
+     */
+    private String openMode;
+
+    /**
+     * 卡上最大金额
+     */
+    private BigDecimal maxCardMoney;
+
+    /**
+     * 定值消费金额
+     */
+    private BigDecimal constantValue;
+
+    /**
+     * 编号0代表的金额
+     */
+    private BigDecimal rationZero;
+
+    /**
+     * 编号1代表的金额
+     */
+    private BigDecimal rationOne;
+
+    /**
+     * 编号2代表的金额
+     */
+    private BigDecimal rationTwo;
+
+    /**
+     * 编号3代表的金额
+     */
+    private BigDecimal rationThree;
+
+    /**
+     * 编号4代表的金额
+     */
+    private BigDecimal rationFour;
+
+    /**
+     * 编号5代表的金额
+     */
+    private BigDecimal rationFive;
+
+    /**
+     * 编号6代表的金额
+     */
+    private BigDecimal rationSix;
+
+    /**
+     * 编号7代表的金额
+     */
+    private BigDecimal rationSeven;
+
+    /**
+     * 编号8代表的金额
+     */
+    private BigDecimal rationEight;
+
+    /**
+     * 编号9代表的金额
+     */
+    private BigDecimal rationNine;
+
+    /**
+     * 每天最大消费次数,0-不限
+     */
+    private Integer dayCount;
+
+    /**
+     * 每天最大消费金额
+     */
+    private BigDecimal dayMoney;
+
+    /**
+     * 每餐最大消费次数,0-不限
+     */
+    private Integer mealCount;
+
+    /**
+     * 单次最大消费金额
+     */
+    private BigDecimal singleMoney;
+
+    /**
+     * 早餐消费金额
+     */
+    private BigDecimal breakfastMoney;
+
+    /**
+     * 午餐消费金额
+     */
+    private BigDecimal lunchMoney;
+
+    /**
+     * 晚餐消费金额
+     */
+    private BigDecimal supperMoney;
+
+    /**
+     * 夜宵消费金额
+     */
+    private BigDecimal nightMoney;
+
+    /**
+     * 早餐开始时间
+     */
+    private Long breakfastBegin;
+
+    /**
+     * 早餐结束时间
+     */
+    private Long breakfastEnd;
+
+    /**
+     * 午餐开始时间
+     */
+    private Long lunchBegin;
+
+    /**
+     * 午餐结束时间
+     */
+    private Long lunchEnd;
+
+    /**
+     * 晚餐开始时间
+     */
+    private Long supperBegin;
+
+    /**
+     * 晚餐结束时间
+     */
+    private Long supperEnd;
+
+    /**
+     * 宵夜开始时间
+     */
+    private Long nightBegin;
+
+    /**
+     * 宵夜结束时间
+     */
+    private Long nightEnd;
+
+    /**
+     * 两次刷卡间隔,0-不限制
+     */
+    private Integer swipeInterval;
+
+    /**
+     * 是否启用卡片有效限制,0-禁用 1-启用
+     */
+    private String termValidity;
+
+    /**
+     * 重启时间
+     */
+    private String rebootTime;
+    //endregion
 }
 }