浏览代码

快分销-刷新token

yumeng 2 年之前
父节点
当前提交
278ef257af

+ 11 - 95
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -140,7 +140,6 @@ public class TestController {
 //        System.err.println(itemMap);
 
 
-
         String cookie = ikuaishouSupplyChainService.getCookie();
         if (Check.isNull(cookie)) {
             log.error("cookie数据为空");
@@ -164,107 +163,23 @@ public class TestController {
                 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                 Long orderCreateTimeStart = sdf.parse(start).getTime();
                 Long orderCreateTimeEnd = sdf.parse(end).getTime();
-                ikuaishouSupplyChainService.getOrderList(cookie, 0, orderCreateTimeStart, orderCreateTimeEnd,itemMap);
+                ikuaishouSupplyChainService.getOrderList(cookie, 0, orderCreateTimeStart, orderCreateTimeEnd, itemMap);
 
             }
         }
+    }
 
 
-        //   List<JSONObject>  = activityItemListService.getItemMap();
-     //   System.err.println(map);
-
-//        String cookie = ikuaishouSupplyChainService.getCookie();
-//        if (Check.isNull(cookie)) {
-//            log.error("cookie数据为空");
-//            return;
-//        }
-//
-//        List<Long> activityIdList = activityInfoService.getActivityIdList();
-//        if (!Check.isNull(activityIdList)) {
-//            for (int i = 0; i < activityIdList.size(); i++) {
-//                Long activityId = activityIdList.get(i);
-//                activityItemListService.getActivityItemList(cookie, 0, activityId);
-//            }
-//
-//        }
-
-        /*log.info("-------------------------获取快分销订单昨日数据开始数据开始--------------------------");
+    @GetMapping(value = "/getSettlementData")
+    public void getsettlementData(String startDay, String endDay) throws Exception {
+        List<String> days = DateUtils.getDays(startDay, endDay);
         String cookie = ikuaishouSupplyChainService.getCookie();
-        if (Check.isNull(cookie)) {
-            log.error("cookie数据为空");
-            return;
-        }
-
-
-        List<String> dateList = new ArrayList<>();
-        dateList.add("2022-11-01");
-        dateList.add("2022-11-02");
-        dateList.add("2022-11-03");
-        dateList.add("2022-11-04");
-        dateList.add("2022-11-05");
-        dateList.add("2022-11-06");
-        dateList.add("2022-11-07");
-        dateList.add("2022-11-08");
-        dateList.add("2022-11-09");
-        dateList.add("2022-11-10");
-        dateList.add("2022-11-11");
-        dateList.add("2022-11-12");
-        dateList.add("2022-11-13");
-        dateList.add("2022-11-14");
-        dateList.add("2022-11-15");
-        dateList.add("2022-11-16");
-        dateList.add("2022-11-17");
-        dateList.add("2022-11-18");
-        dateList.add("2022-11-19");
-        dateList.add("2022-11-20");
-        dateList.add("2022-11-21");
-        dateList.add("2022-11-22");
-        dateList.add("2022-11-23");
-        dateList.add("2022-11-24");
-        dateList.add("2022-11-25");
-        dateList.add("2022-11-26");
-        dateList.add("2022-11-27");
-        dateList.add("2022-11-28");
-        dateList.add("2022-11-29");
-        dateList.add("2022-11-30");
-        dateList.add("2022-12-01");
-        dateList.add("2022-12-02");
-        dateList.add("2022-12-03");
-        dateList.add("2022-12-04");
-        dateList.add("2022-12-05");
-        dateList.add("2022-12-06");
-        dateList.add("2022-12-07");
-        dateList.add("2022-12-08");
-        dateList.add("2022-12-09");
-        dateList.add("2022-12-10");
-        dateList.add("2022-12-11");
-        dateList.add("2022-12-12");
-        dateList.add("2022-12-13");
-        dateList.add("2022-12-14");
-        dateList.add("2022-12-15");
-        dateList.add("2022-12-16");
-        dateList.add("2022-12-17");
-        dateList.add("2022-12-18");
-        dateList.add("2022-12-19");
-        dateList.add("2022-12-20");
-        dateList.add("2022-12-21");
-        dateList.add("2022-12-22");
-        dateList.add("2022-12-23");
-        dateList.add("2022-12-24");
-        dateList.add("2022-12-25");
-        dateList.add("2022-12-26");
-        dateList.add("2022-12-27");
-        dateList.add("2022-12-28");
-        dateList.add("2022-12-29");
-        dateList.add("2022-12-30");
-        dateList.add("2022-12-31");
-
         JSONArray hourList = KuaishouHourEnum.getHourList();
         JSONArray minSecList = KuaishouMinSecEnum.getMinSecList();
-        for (int z = 0; z < dateList.size(); z++) {
-            String date = dateList.get(z);
+        for (int z = 0; z < days.size(); z++) {
+            String date = days.get(z);
             for (int i = 0; i < hourList.size(); i++) {
-                String hour = hourList.getString(i);
+                String hour = hourList.getString(i);    
                 for (int j = 0; j < minSecList.size(); j++) {
                     JSONObject minSecJson = minSecList.getJSONObject(j);
                     String startTime = minSecJson.getString("startTime");
@@ -276,11 +191,12 @@ public class TestController {
                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                     Long orderCreateTimeStart = sdf.parse(start).getTime();
                     Long orderCreateTimeEnd = sdf.parse(end).getTime();
-                    ikuaishouSupplyChainService.getOrderList(cookie, 0, orderCreateTimeStart, orderCreateTimeEnd);
+                    ikuaishouSupplyChainService.getSettlementData(cookie, 0, orderCreateTimeStart, orderCreateTimeEnd);
 
                 }
             }
-        }*/
+
+        }
 
 
     }

+ 15 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KFXAccessTokenJob.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.job.kuaishou.handler;
+import cn.com.ctop.common.module.utils.HttpUtils2;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.stereotype.Component;
+
+@Component
+public class KFXAccessTokenJob {
+
+    @XxlJob("refreshAccessToken")
+    public void refreshAccessToken() {
+        String url = "http://ruixuan.api.tjyourong.com.cn/item/accessToken";
+        HttpUtils2.httpGet(url, null, null);
+    }
+
+}

+ 33 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouSupplyChainSettlement.java

@@ -0,0 +1,33 @@
+package cn.com.ctop.kuaishou.modules.batch.entity;
+
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import io.swagger.annotations.ApiModel;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+
+/**
+ * 快手电商-供应链订单信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2022-12-01
+ */
+@Data
+@TableName("kuaishou_supply_chain_settlement")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "kuaishou_supply_chain_settlement对象", description = "快手电商-供应链订单信息")
+public class KuaishouSupplyChainSettlement {
+
+
+    private Long oid;
+    private Long settlementAmount;
+    private Long settlementTime;
+
+
+}

+ 3 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouSupplyChainMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.batch.mapper;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouSupplyChain;
 
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouSupplyChainSettlement;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -18,4 +19,6 @@ public interface KuaishouSupplyChainMapper extends BaseMapper<KuaishouSupplyChai
     void replace(@Param(value = "adds") List<KuaishouSupplyChain> supplyChains);
 
     String getCookie();
+
+    void replaceSettlement(@Param(value = "adds") List<KuaishouSupplyChainSettlement> supplyChains);
 }

+ 16 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouSupplyChainMapper.xml

@@ -65,6 +65,22 @@
             )
         </foreach>
     </insert>
+    <insert id="replaceSettlement">
+        replace into ruixuan.kuaishou_supply_chain_settlement(
+        oid,
+        settlement_amount,
+        settlement_time
+
+        )
+        values
+        <foreach collection="adds" item="add" separator=",">
+            (
+            #{add.oid},
+            #{add.settlementAmount},
+            #{add.settlementTime}
+            )
+        </foreach>
+    </insert>
     <select id="getCookie" resultType="java.lang.String">
         select  cookie  from ruixuan.kuaishou_supply_chain_cookie limit 1
     </select>

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouSupplyChainService.java

@@ -15,4 +15,6 @@ public interface IKuaishouSupplyChainService extends IService<KuaishouSupplyChai
     void getOrderList(String cookie, Integer offset, Long orderCreateTimeStart, Long orderCreateTimeEnd, Map<Long,Long> itemMap) throws Exception;
 
     String getCookie();
+
+    void getSettlementData(String cookie, Integer offset, Long orderCreateTimeStart, Long orderCreateTimeEnd) throws Exception;
 }

+ 60 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouSupplyChainServiceImpl.java

@@ -5,6 +5,7 @@ import cn.com.ctop.common.module.service.ISendMessageService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouSupplyChain;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouSupplyChainSettlement;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouSupplyChainMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouSupplyChainService;
 import com.alibaba.fastjson.JSONArray;
@@ -124,6 +125,65 @@ public class KuaishouSupplyChainServiceImpl extends ServiceImpl<KuaishouSupplyCh
         return supplyChainMapper.getCookie();
     }
 
+    @Override
+    public void getSettlementData(String cookie, Integer offset, Long orderCreateTimeStart, Long orderCreateTimeEnd) throws Exception {
+
+       String getUrl = "https://cps.kwaixiaodian.com/distribute/pc/investment/bill/list";
+        Map<String, Object> params = new HashMap<>();
+        if (!Check.isNull(orderCreateTimeStart)) {
+            params.put("settlementTimeStart", orderCreateTimeStart);
+        }
+        if (!Check.isNull(orderCreateTimeEnd)) {
+            params.put("settlementTimeEnd", orderCreateTimeEnd);
+        }
+
+        params.put("limit", 5000);
+        params.put("offset", offset);
+        params.put("activityUserType", 1);
+
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Cookie", cookie);
+
+        String resultStr = HttpUtils.KuaiShouttpGetRequest(getUrl, params, headers);
+        JSONObject result = JSONObject.parseObject(resultStr);
+        if (Check.isNull(result)) {
+            log.error("快分销数据返回为空");
+            return;
+        }
+        Integer code = result.getInteger("result");
+        if (code != 1) {
+            log.info("快分销数据返回异常:", resultStr);
+            sendMessageService.sendMessage("113dee46c7df464da78c07a985e92cd1", "快手供应链cookie失效,请及时更新。媒体返回信息:" + resultStr);
+            return;
+        }
+        JSONObject dataJson = result.getJSONObject("data");
+        if (Check.isNull(dataJson)) {
+            log.error("快分销数据返回为data数据为空");
+            return;
+        }
+        JSONArray list = dataJson.getJSONArray("list");
+        if (Check.isNull(list)) {
+            log.error("快分销数据返回为list数据为空");
+            return;
+        }
+        log.info("快分销当前数据条数:{}", list.size());
+        List<KuaishouSupplyChainSettlement> supplyChains = new ArrayList<>();
+        for (int i = 0; i < list.size(); i++) {
+            JSONObject jsonObject = list.getJSONObject(i);
+            KuaishouSupplyChainSettlement supplyChain = new KuaishouSupplyChainSettlement();
+            supplyChain.setOid(jsonObject.getLong("oid"));
+            supplyChain.setSettlementAmount(jsonObject.getLong("settlementAmount"));
+            supplyChain.setSettlementTime(jsonObject.getLong("settlementTime"));
+
+            supplyChains.add(supplyChain);
+        }
+        supplyChainMapper.replaceSettlement(supplyChains);
+        Thread.sleep(2000L);
+        if (list.size() >= 5000) {
+            getSettlementData(cookie, offset + 5000, orderCreateTimeStart, orderCreateTimeEnd);
+        }
+    }
+
     public static String filterSupplement(String content) {
         StringBuilder sb = new StringBuilder();
         for (char ch : content.toCharArray()) {