Ver Fonte

feature: 增加了消费交易状态枚举定义

luo.yibo@datuai.com há 1 ano atrás
pai
commit
4ab4a25767

+ 50 - 0
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/TradeStatusEnum.java

@@ -0,0 +1,50 @@
+package org.dromara.common.core.enums;
+
+import lombok.Getter;
+
+/**
+ * @ClassName TradeStatusEnum
+ * @Description 消费交易状态枚举
+ * @Author luoyibo
+ * @Date 2024-11-06 10:55
+ * @Version 1.0
+ * @since jdk17
+ */
+@Getter
+public enum TradeStatusEnum {
+    ReqSuccess("成功", (byte)0x00),
+    InitCardFail("初始化卡片失败", (byte)0x04),
+    ReqTrade("应答", (byte)0x51),
+    Blacklist("黑名单卡", (byte)0x52),
+    NOMoney("余额不足", (byte)0x53),
+    DayLimitTimes("日限次", (byte)0x54),
+    DayLimitMoney("日限额", (byte)0x55),
+    TimeInterval("消费间隔时间", (byte)0x56),
+    OnceBigMoney("单次消费限额", (byte)0x57),
+    InvalidCard("非本系统卡", (byte)0x58),
+    MealLimitTimes("餐限次", (byte)0x59),
+    CardValidDate("超过卡片有效期", (byte)0x5A),
+    CardTypeLimit("卡类限制", (byte)0x5B),
+    NoByCardDeal("副卡不允许在线交易", (byte)0x5C),
+    MealLimitMoney("餐限额", (byte)0x60),
+    NotInTradeTime("不在交易时间段", (byte)0x61),
+    NonScanCode("没有扫码数据", (byte)0x62),
+    SysError("系统错误", (byte)0x63),
+    MidasApiError("米大师接口调用失败", (byte)0x64),
+    NoDish("无订餐数据", (byte)0x70);
+
+    private String name; // 名称
+    private Byte value; // 值
+
+    /**
+     * 私有构造,防止被外部调用
+     *
+     */
+    TradeStatusEnum(){}
+
+    TradeStatusEnum(String name, Byte value) {
+        this.name = name;
+        this.value = value;
+    }
+
+}

+ 15 - 8
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/CheckBusiness.java

@@ -3,6 +3,7 @@ package org.dromara.server.consume.business;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
@@ -181,9 +182,9 @@ public class CheckBusiness {
             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, "消费限制判断存在问题", "消费限制判断存在问题"));
+        result = checkLimitDeal(bo, userAccountVo, useTermVo, userCardVo, mealType);
+        if (R.isError(result)) {
+            return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "消费限制判断存在问题", JSONUtil.toJsonStr(result.getData())));
         }
         // 4.根据消费机的消费模式验证余额,如果余额不足则返回
         List<PtBagVo> bagVos = new ArrayList<>();
@@ -424,15 +425,17 @@ public class CheckBusiness {
         return R.ok();
     }
 
-    public Boolean checkLimitDeal(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, RemoteCardVo userCardVo,
-                                  RemoteMealTypeVo mealTypeVo) {
+    public R<ErrorInfo> 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;
+            return R.ok();
         }
+        // 当前卡片类型
+        int cardTypeId = userCardVo.getCardType().intValue();
         // 设备允许卡类
-        Integer termCardTypeId = termVo.getCardType() == null ? 0 : termVo.getCardType();
+        int termCardTypeId = termVo.getCardType() == null ? 0 : termVo.getCardType();
         // 设备每天最大消费次数
         Integer termDayCount = termVo.getDayCount() == null ? 0 : termVo.getDayCount();
         // 每天最大消费金额
@@ -446,7 +449,11 @@ public class CheckBusiness {
         // 设备是否启用了卡有效
         Boolean termUseValidity = Objects.equals(termVo.getTermValidity(), "0") ? Boolean.FALSE : Boolean.TRUE;
 
-        return false;
+        int offsetTypeId = (int) Math.pow(2, (cardTypeId - 1));
+        if ((offsetTypeId & termCardTypeId) != offsetTypeId) {
+            return R.fail(new ErrorInfo(400, type, "卡类限制", ""));
+        }
+        return R.ok();
     }
 
     private RemoteOperatorVo getOperatorVo(ConsumptionBo bo) {