Преглед на файлове

为正在查询的订单添加工具类

lighter преди 4 години
родител
ревизия
0cf3db8044

+ 2 - 1
src/main/java/thyyxxk/wxservice_server/scheduled/QueryOrderStateTask.java

@@ -14,6 +14,7 @@ import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder;
 import thyyxxk.wxservice_server.service.WxApiService;
 import thyyxxk.wxservice_server.utils.PropertiesUtil;
 import thyyxxk.wxservice_server.utils.ResultVoUtil;
+import thyyxxk.wxservice_server.utils.TradeVectorUtil;
 
 import java.util.List;
 
@@ -55,7 +56,7 @@ public class QueryOrderStateTask {
             return;
         }
         for (WxPayOrder order : list) {
-            if (!service.tradeNoBetweenQuery(order.getTradeNo())) {
+            if (!TradeVectorUtil.tradeNoBetweenQuery(order.getTradeNo())) {
                 log.info("定时任务查询订单状态:{}", order.getTradeNo());
                 service.queryOrderState(order.getTradeNo());
             }

+ 4 - 9
src/main/java/thyyxxk/wxservice_server/service/WxApiService.java

@@ -48,7 +48,6 @@ import java.util.concurrent.TimeUnit;
 @Slf4j
 @Service
 public class WxApiService {
-    private static final Vector<String> TRADE_NOS_BETWEEN_QUERY = new Vector<>();
     private final WxApiDao dao;
     private final InpatientDao yjjDao;
     private final SpringRetryService retryService;
@@ -187,16 +186,12 @@ public class WxApiService {
         }
     }
 
-    public boolean tradeNoBetweenQuery(String tradeNo) {
-        return TRADE_NOS_BETWEEN_QUERY.contains(tradeNo);
-    }
-
     @Async("asyncTask")
     public CompletableFuture<ResultVo<String>> queryOrderState(String tradeNo) throws Exception {
-        while (tradeNoBetweenQuery(tradeNo)) {
+        while (TradeVectorUtil.tradeNoBetweenQuery(tradeNo)) {
             TimeUnit.SECONDS.sleep(1);
         }
-        TRADE_NOS_BETWEEN_QUERY.add(tradeNo);
+        TradeVectorUtil.add(tradeNo);
         JSONObject obj = retryService.queryOrderStateFromTencent(tradeNo);
         dao.incrementQueryTimesByTradeNo(tradeNo);
         String tradeState = obj.getString("trade_state");
@@ -221,11 +216,11 @@ public class WxApiService {
                     saveRet = ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未识别到的订单类型,请联系服务中心。");
                     break;
             }
-            TRADE_NOS_BETWEEN_QUERY.remove(tradeNo);
+            TradeVectorUtil.remove(tradeNo);
             return CompletableFuture.completedFuture(saveRet);
         }
         String message = updatePayStatusByTradeState(tradeState, tradeNo);
-        TRADE_NOS_BETWEEN_QUERY.remove(tradeNo);
+        TradeVectorUtil.remove(tradeNo);
         return CompletableFuture.completedFuture(ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, message));
     }
 

+ 33 - 0
src/main/java/thyyxxk/wxservice_server/utils/TradeVectorUtil.java

@@ -0,0 +1,33 @@
+package thyyxxk.wxservice_server.utils;
+
+import java.util.Vector;
+
+/**
+ * @description: 正在查询的订单的容器
+ * @author: DingJie
+ * @create: 2021-06-21 08:41:35
+ **/
+public class TradeVectorUtil {
+    private static Vector<String> tradeNosBetweenQuery;
+
+    public static void add(String tradeNo) {
+        if (null == tradeNosBetweenQuery) {
+            tradeNosBetweenQuery = new Vector<>();
+        }
+        tradeNosBetweenQuery.add(tradeNo);
+    }
+
+    public static void remove(String tradeNo) {
+        if (null != tradeNosBetweenQuery) {
+            tradeNosBetweenQuery.remove(tradeNo);
+        }
+    }
+
+    public static boolean tradeNoBetweenQuery(String tradeNo) {
+        if (null == tradeNosBetweenQuery) {
+            return false;
+        }
+        return tradeNosBetweenQuery.contains(tradeNo);
+    }
+
+}

+ 1 - 1
src/main/resources/application-prod.yml

@@ -1,5 +1,5 @@
 server:
-  port: 8083
+  port: 8085
   servlet:
     context-path: /wxserver
 spring: