Browse Source

团长招商活动已报名商品列表

zhaoxian 1 year ago
parent
commit
b4e77242b2

+ 14 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/controller/SupplyChainController.java

@@ -2069,4 +2069,18 @@ public class SupplyChainController extends BaseController {
         }
     }
 
+    /**
+     * open.distribution.investment.activity.open.item.list
+     * 团长招商活动已报名商品列表
+     */
+    @GetMapping("/addKuaishouActivityOpenItemList")
+    @ApiOperation(value = "团长招商活动已报名商品列表")
+    public void addKuaishouActivityOpenItemList() {
+        try {
+            supplyChainService.addKuaishouActivityOpenItemList();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
 }

+ 68 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/entity/KuaiShouActivityOpenItemList.java

@@ -0,0 +1,68 @@
+package com.ruixuan.isc.entity;
+
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 团长招商活动已报名商品列表
+ * kuaishou_activity_open_item_list
+ */
+@Data
+@ApiModel(value = "kuaishou_activity_open_item_list对象", description = "团长招商活动已报名商品列表")
+public class KuaiShouActivityOpenItemList {
+
+    /**
+     * 商品ID
+     */
+    private Long itemId;
+    /**
+     * 商品类目名称
+     */
+    private String itemCategoryName;
+    /**
+     * 商品价格
+     */
+    private Long itemPrice;
+    /**
+     * 上级活动ID
+     */
+    private Long preActivityId;
+    /**
+     * 商品叶子类目id
+     */
+    private Long itemLeafCategoryId;
+    /**
+     * 商品佣金率
+     */
+    private Long itemCommissionRate;
+    /**
+     * 团长服务费率
+     */
+    private Long investmentPromotionRate;
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    private Date updateTime;
+
+    public KuaiShouActivityOpenItemList() {
+
+    }
+
+    public KuaiShouActivityOpenItemList(JSONObject info) {
+        this.setItemId(info.getLong("itemId"));
+        this.setItemCategoryName(info.getString("itemCategoryName"));
+        this.setItemPrice(info.getLong("itemPrice"));
+        this.setPreActivityId(info.getLong("preActivityId"));
+        this.setItemLeafCategoryId(info.getLong("itemLeafCategoryId"));
+        this.setItemCommissionRate(info.getLong("itemCommissionRate"));
+        this.setInvestmentPromotionRate(info.getLong("investmentPromotionRate"));
+    }
+
+}

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

@@ -2,6 +2,7 @@ package com.ruixuan.isc.mapper;
 
 import com.alibaba.fastjson.JSONObject;
 import com.ruixuan.isc.entity.KuaiShouActivityInfo;
+import com.ruixuan.isc.entity.KuaiShouActivityOpenItemList;
 import com.ruixuan.isc.entity.KuaishouSupplyChain;
 import org.apache.ibatis.annotations.Param;
 
@@ -171,4 +172,15 @@ public interface SupplyChainMapper {
 
     List<JSONObject> exportItemDetail(Map<String, Object> requestMap);
 
+    List<Long> getKuaishouActivityInfoList();
+
+    List<Long> getMgsKuaishouActivityInfoList();
+
+    List<Long> getRocketKuaishouActivityInfoList();
+
+    void replaceKuaiShouActivityOpenItemList(@Param("list") List<KuaiShouActivityOpenItemList> list);
+
+    void replaceMgsKuaiShouActivityOpenItemList(@Param("list") List<KuaiShouActivityOpenItemList> list);
+
+    void replaceRocketKuaiShouActivityOpenItemList(@Param("list") List<KuaiShouActivityOpenItemList> list);
 }

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

@@ -184,6 +184,8 @@ public interface ISupplyChainService {
      */
     void addListKuaishouActivityInfo() throws InterruptedException;
 
+    void addKuaishouActivityOpenItemList() throws InterruptedException;
+
     List<JSONObject> getBytedanceOrderHourDataList(Long today);
 
     List<JSONObject> getKuaishouOrderHourDataList(String today);
@@ -191,4 +193,6 @@ public interface ISupplyChainService {
     List<JSONObject> getTopOrders(Map<String, Object> requestMap);
 
     List<JSONObject> exportItemDetail(Map<String, Object> requestMap);
+
+
 }

+ 185 - 4
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/SupplyChainServiceImpl.java

@@ -6,12 +6,15 @@ import com.kuaishou.merchant.open.api.KsMerchantApiException;
 import com.kuaishou.merchant.open.api.client.AccessTokenKsMerchantClient;
 import com.kuaishou.merchant.open.api.common.utils.GsonUtils;
 import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionCpsLeaderOrderCursorListRequest;
+import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionInvestmentActivityOpenItemListRequest;
 import com.kuaishou.merchant.open.api.request.distribution.OpenDistributionInvestmentActivityOpenListRequest;
 import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionCpsLeaderOrderCursorListResponse;
+import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionInvestmentActivityOpenItemListResponse;
 import com.kuaishou.merchant.open.api.response.distribution.OpenDistributionInvestmentActivityOpenListResponse;
 import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.DateUtils;
 import com.ruixuan.isc.entity.KuaiShouActivityInfo;
+import com.ruixuan.isc.entity.KuaiShouActivityOpenItemList;
 import com.ruixuan.isc.entity.KuaishouAccessToken;
 import com.ruixuan.isc.entity.KuaishouSupplyChain;
 import com.ruixuan.isc.mapper.KuaishouItemListMapper;
@@ -679,19 +682,49 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
     @Override
     public void addListKuaishouActivityInfo() throws InterruptedException {
         String url = "https://openapi.kwaixiaodian.com";
+        List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
+        for (KuaishouAccessToken mgsToken : mgsTokens) {
+            getMgsInfoKuaishouActivityInfo(mgsToken, url);
+        }
+        Thread.sleep(600000);
+        List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
+        for (KuaishouAccessToken token : rocketTokens) {
+            getRocketInfoKuaishouActivityInfo(token, url);
+        }
+        Thread.sleep(600000);
         List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
         for (KuaishouAccessToken accessToken : tokens) {
             getInfoKuaishouActivityInfo(accessToken, url);
         }
-        Thread.sleep(600000);
+    }
+
+    @Override
+    public void addKuaishouActivityOpenItemList() throws InterruptedException {
+        String url = "https://openapi.kwaixiaodian.com";
+        List<Long> mgsActivityIds = supplyChainMapper.getMgsKuaishouActivityInfoList();
         List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
         for (KuaishouAccessToken mgsToken : mgsTokens) {
-            getMgsInfoKuaishouActivityInfo(mgsToken, url);
+            for (Long activityId : mgsActivityIds) {
+                getMgsKuaishouActivityOpenItemList(mgsToken, url, activityId, 1);
+            }
         }
-       Thread.sleep(600000);
+
+//        Thread.sleep(300000);
+        List<Long> rocketActivityIds = supplyChainMapper.getRocketKuaishouActivityInfoList();
         List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
         for (KuaishouAccessToken token : rocketTokens) {
-            getRocketInfoKuaishouActivityInfo(token, url);
+            for (Long activityId : rocketActivityIds) {
+                getRocketKuaishouActivityOpenItemList(token, url, activityId, 1);
+            }
+        }
+
+//        Thread.sleep(300000);
+        List<Long> activityIds = supplyChainMapper.getKuaishouActivityInfoList();
+        List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
+        for (KuaishouAccessToken accessToken : tokens) {
+            for (Long activityId : activityIds) {
+                getKuaishouActivityOpenItemList(accessToken, url, activityId, 1);
+            }
         }
 
     }
@@ -757,6 +790,154 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
         }
     }
 
+
+    private void getKuaishouActivityOpenItemList(KuaishouAccessToken accessToken, String url, Long activityId, Integer page) {
+        List<KuaiShouActivityOpenItemList> 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);
+        OpenDistributionInvestmentActivityOpenItemListRequest request = new OpenDistributionInvestmentActivityOpenItemListRequest();
+        request.setAccessToken(accessToken.getAccessToken());
+        request.setApiMethodVersion(1L);
+
+        //每页活动数量
+        request.setLimit(200);
+        Integer offset = (page - 1) * 200;
+        request.setOffset(offset);
+        request.setActivityId(activityId);
+        OpenDistributionInvestmentActivityOpenItemListResponse response = null;
+        try {
+            response = client.execute(request);
+        } catch (KsMerchantApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
+        Integer total = null;
+        String code = obj.getString("code");
+        if ("1".equals(code)) {
+            JSONObject data = obj.getJSONObject("data");
+            JSONArray result = data.getJSONArray("activityItemDataList");
+            total = data.getInteger("total");
+            for (int i = 0; i < result.size(); i++) {
+                JSONObject info = result.getJSONObject(i);
+                KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
+                list.add(activityInfo);
+            }
+        } else {
+            log.error("===团长招商活动已报名商品列表(open.distribution.investment.activity.open.item.list)失败,信息:{}" + obj.getString("error_msg"));
+            return;
+        }
+
+        if (Check.isNotNull(list) && list.size() > 0) {
+            supplyChainMapper.replaceKuaiShouActivityOpenItemList(list);
+        }
+
+        if (total - page * 200 > 0) {
+            getKuaishouActivityOpenItemList(accessToken, url, activityId, page + 1);
+        }
+    }
+
+    private void getMgsKuaishouActivityOpenItemList(KuaishouAccessToken accessToken, String url, Long activityId, Integer page) {
+        List<KuaiShouActivityOpenItemList> 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);
+        OpenDistributionInvestmentActivityOpenItemListRequest request = new OpenDistributionInvestmentActivityOpenItemListRequest();
+        request.setAccessToken(accessToken.getAccessToken());
+        request.setApiMethodVersion(1L);
+
+        //每页活动数量
+        request.setLimit(200);
+        Integer offset = (page - 1) * 200;
+        request.setOffset(offset);
+        request.setActivityId(activityId);
+        OpenDistributionInvestmentActivityOpenItemListResponse response = null;
+        try {
+            response = client.execute(request);
+        } catch (KsMerchantApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
+        Integer total = null;
+        String code = obj.getString("code");
+        if ("1".equals(code)) {
+            JSONObject data = obj.getJSONObject("data");
+            JSONArray result = data.getJSONArray("activityItemDataList");
+            total = data.getInteger("total");
+            for (int i = 0; i < result.size(); i++) {
+                JSONObject info = result.getJSONObject(i);
+                KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
+                list.add(activityInfo);
+            }
+        } else {
+            log.error("===MGS团长招商活动已报名商品列表(open.distribution.investment.activity.open.item.list)失败,信息:{}" + obj.getString("error_msg"));
+            return;
+        }
+
+        if (Check.isNotNull(list) && list.size() > 0) {
+            supplyChainMapper.replaceMgsKuaiShouActivityOpenItemList(list);
+        }
+
+        if (total - page * 200 > 0) {
+            getMgsKuaishouActivityOpenItemList(accessToken, url, activityId, page + 1);
+        }
+    }
+
+    private void getRocketKuaishouActivityOpenItemList(KuaishouAccessToken accessToken, String url, Long activityId, Integer page) {
+        List<KuaiShouActivityOpenItemList> 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);
+        OpenDistributionInvestmentActivityOpenItemListRequest request = new OpenDistributionInvestmentActivityOpenItemListRequest();
+        request.setAccessToken(accessToken.getAccessToken());
+        request.setApiMethodVersion(1L);
+
+        //每页活动数量
+        request.setLimit(200);
+        Integer offset = (page - 1) * 200;
+        request.setOffset(offset);
+        request.setActivityId(activityId);
+        OpenDistributionInvestmentActivityOpenItemListResponse response = null;
+        try {
+            response = client.execute(request);
+        } catch (KsMerchantApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject obj = JSONObject.parseObject(GsonUtils.toJSON(response));
+        Integer total = null;
+        String code = obj.getString("code");
+        if ("1".equals(code)) {
+            JSONObject data = obj.getJSONObject("data");
+            JSONArray result = data.getJSONArray("activityItemDataList");
+            total = data.getInteger("total");
+            for (int i = 0; i < result.size(); i++) {
+                JSONObject info = result.getJSONObject(i);
+                KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
+                list.add(activityInfo);
+            }
+        } else {
+            log.error("===Rocket团长招商活动已报名商品列表(open.distribution.investment.activity.open.item.list)失败,信息:{}" + obj.getString("error_msg"));
+            return;
+        }
+
+        if (Check.isNotNull(list) && list.size() > 0) {
+            supplyChainMapper.replaceRocketKuaiShouActivityOpenItemList(list);
+        }
+
+        if (total - page * 200 > 0) {
+            getRocketKuaishouActivityOpenItemList(accessToken, url, activityId, page + 1);
+        }
+    }
+
     private KuaiShouActivityInfo organizeKuaishouActivityInfo(JSONObject jsonObject) {
         KuaiShouActivityInfo activityInfo = new KuaiShouActivityInfo();
         activityInfo.setActivityId(jsonObject.getLong("activityId"));

+ 97 - 1
ruixuan-live/src/main/resources/mapper/isc/SupplyChainMapper.xml

@@ -230,7 +230,7 @@
         (case
         when tt.ccr_value = '-' or tt.ccr_value is null
         then 0
-        else  replace(tt.ccr_value, '%', '')
+        else replace(tt.ccr_value, '%', '')
         end
         ) as 'ccrInt',
         tt.ccr_value as 'ccrValue'
@@ -2740,6 +2740,7 @@
         GROUP BY stat_hour
         ORDER BY stat_hour
     </select>
+
     <select id="exportItemDetail" resultType="com.alibaba.fastjson.JSONObject">
         select t.*,tt.userName
         from (
@@ -2787,4 +2788,99 @@
 
     </select>
 
+    <insert id="replaceKuaiShouActivityOpenItemList">
+        replace into kuaishou_activity_open_item_list(
+        item_id,
+        item_category_name,
+        item_price,
+        pre_activity_id,
+        item_leaf_category_id,
+        item_commission_rate,
+        investment_promotion_rate
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.itemId},
+            #{li.itemCategoryName},
+            #{li.itemPrice},
+            #{li.preActivityId},
+            #{li.itemLeafCategoryId},
+            #{li.itemCommissionRate},
+            #{li.investmentPromotionRate}
+            )
+        </foreach>
+    </insert>
+
+    <insert id="replaceMgsKuaiShouActivityOpenItemList">
+        replace into miaogousi.kuaishou_activity_open_item_list(
+        item_id,
+        item_category_name,
+        item_price,
+        pre_activity_id,
+        item_leaf_category_id,
+        item_commission_rate,
+        investment_promotion_rate
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.itemId},
+            #{li.itemCategoryName},
+            #{li.itemPrice},
+            #{li.preActivityId},
+            #{li.itemLeafCategoryId},
+            #{li.itemCommissionRate},
+            #{li.investmentPromotionRate}
+            )
+        </foreach>
+    </insert>
+
+
+    <insert id="replaceRocketKuaiShouActivityOpenItemList">
+        replace into rocket.kuaishou_activity_open_item_list(
+        item_id,
+        item_category_name,
+        item_price,
+        pre_activity_id,
+        item_leaf_category_id,
+        item_commission_rate,
+        investment_promotion_rate
+        )
+        values
+        <foreach collection="list" item="li" separator=",">
+            (
+            #{li.itemId},
+            #{li.itemCategoryName},
+            #{li.itemPrice},
+            #{li.preActivityId},
+            #{li.itemLeafCategoryId},
+            #{li.itemCommissionRate},
+            #{li.investmentPromotionRate}
+            )
+        </foreach>
+    </insert>
+
+
+    <select id="getKuaishouActivityInfoList" resultType="Long">
+        SELECT DISTINCT activity_id
+        FROM kuaishou_activity_info
+        WHERE activity_status = 2
+           OR activity_status = 3
+    </select>
+
+    <select id="getMgsKuaishouActivityInfoList" resultType="Long">
+        SELECT DISTINCT activity_id
+        FROM miaogousi.kuaishou_activity_info
+        WHERE activity_status = 2
+           OR activity_status = 3
+    </select>
+
+    <select id="getRocketKuaishouActivityInfoList" resultType="Long">
+        SELECT DISTINCT activity_id
+        FROM rocket.kuaishou_activity_info
+        WHERE activity_status = 2
+           OR activity_status = 3
+    </select>
+
 </mapper>