Browse Source

fix: 消费服务
1.消费业务前检查缓存中是否存在客户的公钥与私钥
2.对账循环处理加了try...catch,跳过出错的记录继续处理

luo.yibo@datuai.com 1 year ago
parent
commit
e14e508868

+ 16 - 0
ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteRegisterInfoService.java

@@ -0,0 +1,16 @@
+package org.dromara.system.api;
+
+/**
+ * 注册信息服务
+ *
+ * @author Michelle.Chung
+ */
+public interface RemoteRegisterInfoService {
+
+
+    /**
+     * 查询注册信息
+     */
+    void  queryRegisterInfo();
+
+}

+ 1 - 2
ruoyi-modules/ruoyi-hotel/src/main/java/org/dromara/hotel/service/impl/KfOrderServiceImpl.java

@@ -590,8 +590,7 @@ public class KfOrderServiceImpl implements IKfOrderService {
                 TenantHelper.ignore(() -> this.updateByBo(bo));
             } else {
                 TenantHelper.ignore(() -> this.insertByBo(bo));
-            }
-            // 设置团客报到状态
+            }            // 设置团客报到状态
             guestTeamService.setGuestCheckInStatus(bo.getGuestId(), bo.getTeamId());
             // 设置房间状态
             roomService.updateGuestRoomStatus(bo.getRoomCode(), bo.getTenantId(), HotelRoomStatusEnum.YZ.code());

+ 25 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteRegisterInfoServiceImpl.java

@@ -0,0 +1,25 @@
+package org.dromara.system.dubbo;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.dromara.system.api.RemoteRegisterInfoService;
+import org.dromara.system.service.ISysRegisterInfoService;
+import org.springframework.stereotype.Service;
+
+/**
+ * 注册服务实现
+ *
+ * @author Michelle.Chung
+ */
+@RequiredArgsConstructor
+@Service
+@DubboService
+public class RemoteRegisterInfoServiceImpl implements RemoteRegisterInfoService {
+
+    private final ISysRegisterInfoService registerInfoService;
+
+    @Override
+    public void queryRegisterInfo() {
+        registerInfoService.queryRegisterInfo();
+    }
+}

+ 5 - 4
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRegisterInfoServiceImpl.java

@@ -1,7 +1,5 @@
 package org.dromara.system.service.impl;
 
-import cn.hutool.core.util.StrUtil;
-import cn.hutool.crypto.SecureUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -25,7 +23,10 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
 
 /**
@@ -193,7 +194,7 @@ public class SysRegisterInfoServiceImpl implements ISysRegisterInfoService {
             tempVo.setCustomerId(customerId);
             tempVo.setDealerNo(dealerNo);
             vo.set(tempVo);
-            // todo 获取不到租户id,无法设置缓存 使用默认租户id
+
             RedisUtils.setCacheObject(CacheNames.CUSTOM_PUB_KEY,customerPublicKey);
             RedisUtils.setCacheObject(CacheNames.CUSTOM_PRI_KEY,customerPrivateKey);
         });

+ 13 - 2
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/BaseBusiness.java

@@ -7,12 +7,12 @@ import cn.hutool.core.util.ObjectUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
-import org.dromara.backstage.api.RemotePtParameterService;
 import org.dromara.backstage.api.domain.vo.RemoteCardVo;
 import org.dromara.backstage.api.domain.vo.RemoteMealTypeVo;
 import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
 import org.dromara.common.core.config.DefaultConfig;
 import org.dromara.common.core.constant.ApiErrorTypeConstants;
+import org.dromara.common.core.constant.CacheNames;
 import org.dromara.common.core.constant.DefaultConstants;
 import org.dromara.common.core.domain.R;
 import org.dromara.common.core.domain.model.ErrorInfo;
@@ -24,12 +24,14 @@ import org.dromara.common.message.kafka.constant.EventTypeConstants;
 import org.dromara.common.message.kafka.constant.KafkaTopicConstants;
 import org.dromara.common.message.kafka.enums.EventSenderEnum;
 import org.dromara.common.message.kafka.producer.KafkaCommonProducer;
+import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.common.tenant.helper.TenantHelper;
 import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
 import org.dromara.server.common.domain.vo.yc.YcPushConsumeInfoVo;
 import org.dromara.server.consume.domain.bo.*;
 import org.dromara.server.consume.domain.vo.*;
 import org.dromara.server.consume.service.*;
+import org.dromara.system.api.RemoteRegisterInfoService;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -63,7 +65,7 @@ public class BaseBusiness {
     private final DefaultConfig defaultConfig;
 
     @DubboReference
-    private final RemotePtParameterService remotePtParameterService;
+    private final RemoteRegisterInfoService remoteRegisterInfoService;
 
     /**
      * 生成原始消费记录
@@ -324,6 +326,15 @@ public class BaseBusiness {
     public List<ConsumptionBo> selectOriginalReconciliation(Date consumeDate){
         return TenantHelper.ignore(() -> originalService.selectReconciliationData(consumeDate));
     }
+
+    /**
+     * 查询注册信息,用来检查客户的公钥和么钥
+     */
+    public void getRegisterInfo(){
+        if (ObjectUtil.isEmpty(RedisUtils.getCacheObject(CacheNames.CUSTOM_PUB_KEY)) || ObjectUtil.isEmpty(RedisUtils.getCacheObject(CacheNames.CUSTOM_PRI_KEY))) {
+            remoteRegisterInfoService.queryRegisterInfo();
+        }
+    }
     /**
      * 将消费信息发送到kafka,教务消费此消息实现就餐打卡
      * @param consumeList 消费记录列表

+ 15 - 6
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/ConsumeBusiness.java

@@ -57,6 +57,8 @@ public class ConsumeBusiness {
      */
     public R<ErrorInfo> createOrder(ConsumptionBo bo, String mac, String xfPwd) {
         // baseBusiness.sendCloudConsume(bo);
+        //检查下客户的公钥与么钥
+        baseBusiness.getRegisterInfo();
 
         log.info("[请求交易]-[开始参数验证]-[{}]", JSONUtil.toJsonStr(bo));
         R<ErrorInfo> result = checkBusiness.checkParam(bo);
@@ -171,6 +173,7 @@ public class ConsumeBusiness {
         }
         return R.ok();
     }
+
     /**
      * 原始消费对账,将有原始消费记录但没有消费明细的消费记录写入消费明细
      * @return 对账结果
@@ -189,13 +192,19 @@ public class ConsumeBusiness {
         list.forEach(p->{
             p.setUseType(SystemUseTypeEnum.CONSUME);
             p.setCreditType(CreditTypeEnum.TERM_CONSUME);
-            R<ErrorInfo> result = fullOrder(p, "", "");
-            if (R.isSuccess(result)) {
-                doMessage.add(MessageFormat.format("[入账成功]-[{0}]", JsonUtils.toJsonString(p)));
-                success.getAndIncrement();
-            } else {
-                doMessage.add(MessageFormat.format("[入账失败]-[{0}]-[{1}]", JsonUtils.toJsonString(p),JSONUtil.toJsonStr(result.getData())));
+            try {
+                R<ErrorInfo> result = fullOrder(p, "", "");
+                if (R.isSuccess(result)) {
+                    doMessage.add(MessageFormat.format("[入账成功]-[{0}]", JsonUtils.toJsonString(p)));
+                    success.getAndIncrement();
+                } else {
+                    doMessage.add(MessageFormat.format("[入账失败]-[{0}]-[{1}]", JsonUtils.toJsonString(p),JSONUtil.toJsonStr(result.getData())));
+                    fail.getAndIncrement();
+                }
+            } catch (Exception e) {
+                doMessage.add(MessageFormat.format("[入账失败]-[{}]=[{}]", JsonUtils.toJsonString(p),e.getStackTrace()));
                 fail.getAndIncrement();
+                log.error("[对账失败]-[{}]", JSONUtil.toJsonStr(p), e);
             }
         });
         doMessage.forEach(System.out::println);

+ 3 - 3
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/impl/PtBagServiceImpl.java

@@ -269,13 +269,13 @@ public class PtBagServiceImpl implements IPtBagService {
 
         //解密余额密文,得到加密的余额
         //加密余额默认=明文余额
-        BigDecimal entryptValue = entity.getBalance();
+        BigDecimal encryptValue = entity.getBalance();
         if (StrUtil.isNotBlank(entity.getEncryptBalance())) {
             String decryptValue = YcEncryptUtil.decryptBagBalanceByPublicKey(entity.getEncryptBalance(), entity.getUserId().toString());
-            entryptValue = new BigDecimal(decryptValue);
+            encryptValue = new BigDecimal(decryptValue);
         }
         //如果明文余额与解密后余额不一致则验证不通过
-        if (entryptValue.compareTo(entity.getBalance()) != 0) {
+        if (encryptValue.compareTo(entity.getBalance()) != 0) {
             throw new BagException("bag.balance.valid", JSONUtil.parse(bo));
         }
         return entity;