Переглянути джерело

分销团长订单列表(游标方式)

zhaoxian 1 рік тому
батько
коміт
00bb37b377

+ 10 - 6
ruixuan-live/src/main/java/com/ruixuan/isc/controller/SupplyChainController.java

@@ -1882,13 +1882,18 @@ public class SupplyChainController extends BaseController {
     @GetMapping("/addList")
     @ApiOperation(value = "分销团长订单列表(游标方式)")
     public void addList(String beginDate, String endDate) {
-        supplyChainService.addList(beginDate, endDate, null);
+        try {
+            supplyChainService.addList(beginDate, endDate, null);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
     }
 
     static ExecutorService fxNowService = Executors.newFixedThreadPool(3);
+
     @PostMapping(value = "/accept")
     public Map<String, Object> acceptEvent(@RequestBody String eventsEncoded) {
-       // System.err.println(eventsEncoded);
+        // System.err.println(eventsEncoded);
         try {
             String events = PlatformEventSecurityUtil.decode(eventsEncoded, "JRowMMndTkSlvVORNvtJbw==");
             JSONObject eventJSon = JSONObject.parseObject(events);
@@ -1896,11 +1901,11 @@ public class SupplyChainController extends BaseController {
                 @Override
                 public void run() {
                     try {
-                        if(!Check.isNull(eventJSon)){
+                        if (!Check.isNull(eventJSon)) {
                             String event = eventJSon.getString("event");
-                            if("kwaishop_distribute_order_change_notify".equals(event)){
+                            if ("kwaishop_distribute_order_change_notify".equals(event)) {
                                 supplyChainService.updateOrder(eventJSon);
-                            }else if("kwaishop_distribute_activity_item_change".equals(event)){
+                            } else if ("kwaishop_distribute_activity_item_change".equals(event)) {
                                 supplyChainService.updateItem(eventJSon);
                             }
                         }
@@ -1922,7 +1927,6 @@ public class SupplyChainController extends BaseController {
     }
 
 
-
     @GetMapping("/addListKuaishouActivityInfo")
     @ApiOperation(value = "团长查询招商活动列表")
     public void addListKuaishouActivityInfo() {

+ 2 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/SupplyChainMapper.java

@@ -152,4 +152,6 @@ public interface SupplyChainMapper {
     void updateItem(@Param("itemId") Long itemId, @Param("status") Integer status);
 
     void replaceKuaishouActivityInfo(@Param("list") List<KuaiShouActivityInfo> list);
+
+    void updateKuaishouSupplyChain( @Param("list") List<Long> list);
 }

+ 1 - 1
ruixuan-live/src/main/java/com/ruixuan/isc/service/ISupplyChainService.java

@@ -176,7 +176,7 @@ public interface ISupplyChainService {
      *分销团长订单列表(游标方式)
      * open.distribution.cps.leader.order.cursor.list
      */
-    void addList(String beginDate, String endDate, String pcursor);
+    void addList(String beginDate, String endDate, String pcursor) throws InterruptedException;
 
     /*
      *团长查询招商活动列表

+ 16 - 11
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/SupplyChainServiceImpl.java

@@ -436,19 +436,19 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
     }
 
     @Override
-    public void addList(String beginDate, String endDate, String pcursor) {
+    public void addList(String beginDate, String endDate, String pcursor) throws InterruptedException {
         String url = "https://openapi.kwaixiaodian.com";
         Long beginTime = DateUtils.getStartLongTime(beginDate);
         Long endTime = DateUtils.getEndLongTime(endDate);
         Map<Long, Long> itemMap = getItemMap();
         List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
         for (KuaishouAccessToken accessToken : tokens) {
-            getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap);
+            getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap, 1);
         }
     }
 
-    private void getInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Map<Long, Long> itemMap) {
-        List<KuaishouSupplyChain> list = new ArrayList<>();
+    private void getInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Map<Long, Long> itemMap, Integer counts) throws InterruptedException {
+        List<Long> list = new ArrayList<>();
         String appKey = accessToken.getAppKey();
         String signSecret = accessToken.getSignSecret();
         if (Check.isNull(signSecret) || Check.isNull(appKey)) {
@@ -486,19 +486,24 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
             JSONArray orderView = data.getJSONArray("orderView");
             for (int i = 0; i < orderView.size(); i++) {
                 JSONObject info = orderView.getJSONObject(i);
-                KuaishouSupplyChain chain = organizeData(info, itemMap);
-                list.add(chain);
+                Integer sendStatus = info.getInteger("sendStatus");
+                if (Check.isNotNull(sendStatus) && sendStatus == 1) {
+                    list.add(info.getLong("oid"));
+                }
             }
         } else {
-            log.error("===查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}" + obj.getString("msg"));
-            return;
+            log.error("===查询分销团长订单列表(open.distribution.cps.leader.order.cursor.list)失败,信息:{}", obj.getString("msg"));
+            log.error("游标:{},执行次数:{}", pcursor, counts);
+            if (counts <= 3) {
+                getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap, counts + 1);
+            }
         }
-
         if (Check.isNotNull(list) && list.size() > 0) {
-            supplyChainMapper.replaceAll(list);
+            supplyChainMapper.updateKuaishouSupplyChain(list);
+            Thread.sleep(200);
         }
         if (!"nomore".equals(pcursor)) {
-            getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap);
+            getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap, 1);
         }
     }
 

+ 17 - 3
ruixuan-live/src/main/resources/mapper/isc/SupplyChainMapper.xml

@@ -10,13 +10,16 @@
     </insert>
     <update id="updateOrder">
 
-    update kuaishou_supply_chain set order_status = #{cpsOrderStatus}
-    where oid = #{oid}
+        update kuaishou_supply_chain
+        set order_status = #{cpsOrderStatus}
+        where oid = #{oid}
 
 
     </update>
     <update id="updateItem">
-        update kuaishou_item_list set activity_item_status = #{status} where item_id = #{itemId}
+        update kuaishou_item_list
+        set activity_item_status = #{status}
+        where item_id = #{itemId}
 
     </update>
     <delete id="unbindUser" parameterType="java.lang.Long">
@@ -2545,4 +2548,15 @@
         </foreach>
     </insert>
 
+
+    <update id="updateKuaishouSupplyChain">
+        update kuaishou_supply_chain set send_status = 1
+        where oid in
+        <foreach collection="list" item="id" separator=","
+                 open="(" close=")">
+            #{id}
+        </foreach>
+    </update>
+
+
 </mapper>