瀏覽代碼

Merge remote-tracking branch 'origin/master'

yumeng 1 年之前
父節點
當前提交
8584b211cd

+ 17 - 8
ruixuan-live/src/main/java/com/ruixuan/isc/controller/SupplyChainController.java

@@ -2,7 +2,6 @@ package com.ruixuan.isc.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.kuaishou.merchant.open.api.KsMerchantApiException;
-import com.kuaishou.merchant.open.api.common.utils.KsStringUtils;
 import com.kuaishou.merchant.open.api.common.utils.PlatformEventSecurityUtil;
 import com.ruixuan.common.core.controller.BaseController;
 import com.ruixuan.common.core.page.TableDataInfo;
@@ -14,14 +13,16 @@ import com.ruixuan.isc.service.ISupplyChainService;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.SneakyThrows;
-import org.apache.commons.codec.binary.Base64;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
 
-import javax.crypto.Cipher;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
@@ -1879,11 +1880,15 @@ public class SupplyChainController extends BaseController {
     }
 
 
+    /**
+     *接口链接:
+     * https://open.kwaixiaodian.com/zone/new/docs/api?name=open.distribution.investment.activity.open.close&version=1
+     */
     @GetMapping("/addList")
     @ApiOperation(value = "分销团长订单列表(游标方式)")
     public void addList(String beginDate, String endDate) {
         try {
-            supplyChainService.addList(beginDate, endDate, null);
+            supplyChainService.addList(beginDate, endDate, "");
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
@@ -1930,7 +1935,11 @@ public class SupplyChainController extends BaseController {
     @GetMapping("/addListKuaishouActivityInfo")
     @ApiOperation(value = "团长查询招商活动列表")
     public void addListKuaishouActivityInfo() {
-        supplyChainService.addListKuaishouActivityInfo();
+        try {
+            supplyChainService.addListKuaishouActivityInfo();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
     }
 
 }

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

@@ -14,4 +14,6 @@ public interface AccessTokenMapper {
     List<KuaishouAccessToken> getByteDanceTokenInfos();
 
     void updateBytedance(KuaishouAccessToken update);
+
+    List<KuaishouAccessToken> getMgsTokenInfos();
 }

+ 5 - 1
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/SupplyChainMapper.java

@@ -155,5 +155,9 @@ public interface SupplyChainMapper {
 
     void replaceKuaishouActivityInfo(@Param("list") List<KuaiShouActivityInfo> list);
 
-    void updateKuaishouSupplyChain( @Param("list") List<Long> list);
+    void updateKuaishouSupplyChain(@Param("list") List<Long> list);
+
+    void replaceMgsKuaishouActivityInfo(@Param("list") List<KuaiShouActivityInfo> list);
+
+    void updateMgsKuaishouSupplyChain(@Param("list") List<Long> list);
 }

+ 2 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/IAccessTokenService.java

@@ -13,4 +13,6 @@ public interface IAccessTokenService {
      void refreshByteDanceAccessToken();
 
     List<KuaishouAccessToken> getTokenInfos();
+
+    List<KuaishouAccessToken> getMgsTokenInfos();
 }

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

@@ -182,6 +182,6 @@ public interface ISupplyChainService {
      *团长查询招商活动列表
      * open.distribution.investment.activity.open.list
      */
-    void addListKuaishouActivityInfo();
+    void addListKuaishouActivityInfo() throws InterruptedException;
 
 }

+ 5 - 1
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/AccessTokenServiceImpl.java

@@ -6,7 +6,6 @@ import com.doudian.open.api.token_refresh.TokenRefreshRequest;
 import com.doudian.open.api.token_refresh.TokenRefreshResponse;
 import com.doudian.open.api.token_refresh.param.TokenRefreshParam;
 import com.doudian.open.core.AccessToken;
-import com.doudian.open.core.AccessTokenBuilder;
 import com.kuaishou.merchant.open.api.KsMerchantApiException;
 import com.kuaishou.merchant.open.api.client.oauth.OauthAccessTokenKsClient;
 import com.kuaishou.merchant.open.api.response.oauth.KsAccessTokenResponse;
@@ -112,4 +111,9 @@ public class AccessTokenServiceImpl implements IAccessTokenService {
     public List<KuaishouAccessToken> getTokenInfos() {
         return accessTokenMapper.getTokenInfos();
     }
+
+    @Override
+    public List<KuaishouAccessToken> getMgsTokenInfos() {
+        return accessTokenMapper.getMgsTokenInfos();
+    }
 }

+ 119 - 6
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/SupplyChainServiceImpl.java

@@ -445,14 +445,20 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
         String url = "https://openapi.kwaixiaodian.com";
         Long beginTime = DateUtils.getStartLongTime(beginDate);
         Long endTime = DateUtils.getEndLongTime(endDate);
-        Map<Long, Long> itemMap = getItemMap();
+//        Map<Long, Long> itemMap = getItemMap();
         List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
         for (KuaishouAccessToken accessToken : tokens) {
-            getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap, 1);
+            getInfo(accessToken, beginTime, endTime, url, pcursor, 1);
         }
+        Thread.sleep(600000);
+        List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
+        for (KuaishouAccessToken accessToken : mgsTokens) {
+            getMgsInfo(accessToken, beginTime, endTime, url, pcursor, 1);
+        }
+
     }
 
-    private void getInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Map<Long, Long> itemMap, Integer counts) throws InterruptedException {
+    private void getInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
         List<Long> list = new ArrayList<>();
         String appKey = accessToken.getAppKey();
         String signSecret = accessToken.getSignSecret();
@@ -500,7 +506,7 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
             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);
+                getInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
             }
         }
         if (Check.isNotNull(list) && list.size() > 0) {
@@ -508,7 +514,67 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
             Thread.sleep(200);
         }
         if (!"nomore".equals(pcursor)) {
-            getInfo(accessToken, beginTime, endTime, url, pcursor, itemMap, 1);
+            getInfo(accessToken, beginTime, endTime, url, pcursor, 1);
+        }
+    }
+
+    private void getMgsInfo(KuaishouAccessToken accessToken, Long beginTime, Long endTime, String url, String pcursor, Integer counts) throws InterruptedException {
+        List<Long> list = new ArrayList<>();
+        String appKey = accessToken.getAppKey();
+        String signSecret = accessToken.getSignSecret();
+        if (Check.isNull(signSecret) || Check.isNull(appKey)) {
+            return;
+        }
+        AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
+        OpenDistributionCpsLeaderOrderCursorListRequest request = new OpenDistributionCpsLeaderOrderCursorListRequest();
+        request.setAccessToken(accessToken.getAccessToken());
+        request.setApiMethodVersion(1L);
+
+        //排序类型 [1:按指定查询类型降序] [2:按指定查询类型升序]
+        request.setSortType(1);
+        //查询类型 [1:按分销订单创建时间查询] [2:按分销订单更新时间查询][4:按订单实际创建时间查询]
+        request.setQueryType(2);
+        //分销订单状态 [0:全部订单] [30:已付款] [50:已收货] [60:已结算] [80:已失效]
+        request.setCpsOrderStatus(0);
+        request.setDistributorId(0l);
+        request.setBeginTime(beginTime);
+        request.setEndTime(endTime);
+        request.setPcursor(pcursor);
+        request.setPageize(100);
+        request.setFundType(1);
+
+        OpenDistributionCpsLeaderOrderCursorListResponse response = null;
+        try {
+            response = client.execute(request);
+        } catch (KsMerchantApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
+        String code = obj.getString("code");
+        if ("1".equals(code)) {
+            JSONObject data = obj.getJSONObject("data");
+            pcursor = data.getString("pcursor");
+            JSONArray orderView = data.getJSONArray("orderView");
+            for (int i = 0; i < orderView.size(); i++) {
+                JSONObject info = orderView.getJSONObject(i);
+                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("error_msg"));
+            log.error("游标:{},执行次数:{}", pcursor, counts);
+            if (counts <= 3) {
+                getMgsInfo(accessToken, beginTime, endTime, url, pcursor, counts + 1);
+            }
+        }
+        if (Check.isNotNull(list) && list.size() > 0) {
+            supplyChainMapper.updateMgsKuaishouSupplyChain(list);
+            Thread.sleep(200);
+        }
+        if (!"nomore".equals(pcursor)) {
+            getMgsInfo(accessToken, beginTime, endTime, url, pcursor, 1);
         }
     }
 
@@ -567,12 +633,18 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
 
 
     @Override
-    public void addListKuaishouActivityInfo() {
+    public void addListKuaishouActivityInfo() throws InterruptedException {
         String url = "https://openapi.kwaixiaodian.com";
         List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
         for (KuaishouAccessToken accessToken : tokens) {
             getInfoKuaishouActivityInfo(accessToken, url);
         }
+        Thread.sleep(600000);
+        List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
+        for (KuaishouAccessToken mgsToken : mgsTokens) {
+            getMgsInfoKuaishouActivityInfo(mgsToken, url);
+        }
+
     }
 
     private void getInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
@@ -634,5 +706,46 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
         return activityInfo;
     }
 
+
+    private void getMgsInfoKuaishouActivityInfo(KuaishouAccessToken accessToken, String url) {
+        List<KuaiShouActivityInfo> list = new ArrayList<>();
+        String appKey = accessToken.getAppKey();
+        String signSecret = accessToken.getSignSecret();
+        if (Check.isNull(signSecret) || Check.isNull(appKey)) {
+            return;
+        }
+        AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
+        OpenDistributionInvestmentActivityOpenListRequest request = new OpenDistributionInvestmentActivityOpenListRequest();
+
+        request.setAccessToken(accessToken.getAccessToken());
+        request.setApiMethodVersion(1L);
+
+        //每页活动数量
+        request.setLimit(5000);
+        OpenDistributionInvestmentActivityOpenListResponse response = null;
+        try {
+            response = client.execute(request);
+        } catch (KsMerchantApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
+        String code = obj.getString("code");
+        if ("1".equals(code)) {
+            JSONObject data = obj.getJSONObject("data");
+            JSONArray result = data.getJSONArray("result");
+            for (int i = 0; i < result.size(); i++) {
+                JSONObject info = result.getJSONObject(i);
+                KuaiShouActivityInfo activityInfo = organizeKuaishouActivityInfo(info);
+                list.add(activityInfo);
+            }
+        } else {
+            log.error("===团长查询招商活动列表(open.distribution.investment.activity.open.list)失败,信息:{}" + obj.getString("msg"));
+            return;
+        }
+
+        if (Check.isNotNull(list) && list.size() > 0) {
+            supplyChainMapper.replaceMgsKuaishouActivityInfo(list);
+        }
+    }
 }
 

+ 24 - 6
ruixuan-live/src/main/resources/mapper/isc/AccessTokenMapper.xml

@@ -4,22 +4,40 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruixuan.isc.mapper.AccessTokenMapper">
     <update id="update" parameterType="com.ruixuan.isc.entity.KuaishouAccessToken">
- update kuaishou_access_token set access_token = #{accessToken},refresh_token = #{refreshToken}
- where id = #{id}
+        update kuaishou_access_token
+        set access_token  = #{accessToken},
+            refresh_token = #{refreshToken}
+        where id = #{id}
     </update>
+
     <update id="updateBytedance" parameterType="com.ruixuan.isc.entity.KuaishouAccessToken">
-         update bytedance_access_token set access_token = #{accessToken},refresh_token = #{refreshToken},update_time = #{updateTime}
+        update bytedance_access_token
+        set access_token  = #{accessToken},
+            refresh_token = #{refreshToken},
+            update_time   = #{updateTime}
         where id = #{id}
     </update>
 
 
     <select id="getAccessToken" resultType="com.ruixuan.isc.entity.KuaishouAccessToken">
-        select  * from kuaishou_access_token where id = #{regId} limit 1
+        select *
+        from kuaishou_access_token
+        where id = #{regId} limit 1
     </select>
+
     <select id="getTokenInfos" resultType="com.ruixuan.isc.entity.KuaishouAccessToken">
-        select *  from kuaishou_access_token
+        select *
+        from kuaishou_access_token
     </select>
+
+    <select id="getMgsTokenInfos" resultType="com.ruixuan.isc.entity.KuaishouAccessToken">
+        select *
+        from miaogousi.kuaishou_access_token
+    </select>
+
     <select id="getByteDanceTokenInfos" resultType="com.ruixuan.isc.entity.KuaishouAccessToken">
-         select *  from bytedance_access_token
+        select *
+        from bytedance_access_token
     </select>
+
 </mapper>

+ 43 - 4
ruixuan-live/src/main/resources/mapper/isc/SupplyChainMapper.xml

@@ -15,10 +15,10 @@
     </update>
 
     <update id="updateOrderRegimentalSettleAmount">
-    update kuaishou_supply_chain
-    set order_status = #{cpsOrderStatus},
-    total_regimental_settle_amount = regimental_promotion_amount
-    where oid = #{oid}
+        update kuaishou_supply_chain
+        set order_status                   = #{cpsOrderStatus},
+            total_regimental_settle_amount = regimental_promotion_amount
+        where oid = #{oid}
     </update>
 
     <update id="updateItem">
@@ -2555,6 +2555,36 @@
     </insert>
 
 
+    <insert id="replaceMgsKuaishouActivityInfo">
+        replace into miaogousi.kuaishou_activity_info(
+        activity_id,
+        regimental_id,
+        activity_title,
+        activity_type,
+        activity_begin_time,
+        activity_end_time,
+        activity_status,
+        apply_item_count,
+        wait_audit_item_count,
+        audit_pass_item_count
+        )
+        values
+        <foreach collection="list" item="add" separator=",">
+            (
+            #{add.activityId},
+            #{add.regimentalId},
+            #{add.activityTitle},
+            #{add.activityType},
+            #{add.activityBeginTime},
+            #{add.activityEndTime},
+            #{add.activityStatus},
+            #{add.applyItemCount},
+            #{add.waitAuditItemCount},
+            #{add.auditPassItemCount}
+            )
+        </foreach>
+    </insert>
+
     <update id="updateKuaishouSupplyChain">
         update kuaishou_supply_chain set send_status = 1
         where oid in
@@ -2564,5 +2594,14 @@
         </foreach>
     </update>
 
+    <update id="updateMgsKuaishouSupplyChain">
+        update miaogousi.kuaishou_supply_chain set send_status = 1
+        where oid in
+        <foreach collection="list" item="id" separator=","
+                 open="(" close=")">
+            #{id}
+        </foreach>
+    </update>
+
 
 </mapper>