|  | @@ -2,18 +2,25 @@ package com.ruixuan.isc.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | +import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  |  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.OpenDistributionInvestmentActivityItemDetailRequest;
 | 
	
		
			
				|  |  |  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.OpenDistributionInvestmentActivityItemDetailResponse;
 | 
	
		
			
				|  |  |  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.*;
 | 
	
		
			
				|  |  | +import com.ruixuan.isc.entity.ItemCheck;
 | 
	
		
			
				|  |  | +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;
 | 
	
		
			
				|  |  |  import com.ruixuan.isc.mapper.SupplyChainMapper;
 | 
	
		
			
				|  |  |  import com.ruixuan.isc.service.IAccessTokenService;
 | 
	
	
		
			
				|  | @@ -918,26 +925,25 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
 | 
	
		
			
				|  |  |          List<KuaishouAccessToken> mgsTokens = accessTokenService.getMgsTokenInfos();
 | 
	
		
			
				|  |  |          for (KuaishouAccessToken mgsToken : mgsTokens) {
 | 
	
		
			
				|  |  |              for (Long activityId : mgsActivityIds) {
 | 
	
		
			
				|  |  | -                getMgsKuaishouActivityOpenItemList(mgsToken, url, activityId, 1);
 | 
	
		
			
				|  |  | +                getKuaishouActivityOpenItemList(mgsToken, url, activityId, 1, "miaogousi");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        Thread.sleep(300000);
 | 
	
		
			
				|  |  | +        Thread.sleep(30000);
 | 
	
		
			
				|  |  |          List<Long> rocketActivityIds = supplyChainMapper.getRocketKuaishouActivityInfoList();
 | 
	
		
			
				|  |  | -        Thread.sleep(600000);
 | 
	
		
			
				|  |  |          List<KuaishouAccessToken> rocketTokens = accessTokenService.getRocketTokenInfos();
 | 
	
		
			
				|  |  |          for (KuaishouAccessToken token : rocketTokens) {
 | 
	
		
			
				|  |  |              for (Long activityId : rocketActivityIds) {
 | 
	
		
			
				|  |  | -                getRocketKuaishouActivityOpenItemList(token, url, activityId, 1);
 | 
	
		
			
				|  |  | +                getKuaishouActivityOpenItemList(token, url, activityId, 1, "rocket");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        Thread.sleep(300000);
 | 
	
		
			
				|  |  | +        Thread.sleep(30000);
 | 
	
		
			
				|  |  |          List<Long> activityIds = supplyChainMapper.getKuaishouActivityInfoList();
 | 
	
		
			
				|  |  |          List<KuaishouAccessToken> tokens = accessTokenService.getTokenInfos();
 | 
	
		
			
				|  |  |          for (KuaishouAccessToken accessToken : tokens) {
 | 
	
		
			
				|  |  |              for (Long activityId : activityIds) {
 | 
	
		
			
				|  |  | -                getKuaishouActivityOpenItemList(accessToken, url, activityId, 1);
 | 
	
		
			
				|  |  | +                getKuaishouActivityOpenItemList(accessToken, url, activityId, 1, "ruixuan");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1025,8 +1031,7 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private void getKuaishouActivityOpenItemList(KuaishouAccessToken accessToken, String url, Long activityId, Integer page) {
 | 
	
		
			
				|  |  | -        List<KuaiShouActivityOpenItemList> list = new ArrayList<>();
 | 
	
		
			
				|  |  | +    private void getKuaishouActivityOpenItemList(KuaishouAccessToken accessToken, String url, Long activityId, Integer page, String dbtype) {
 | 
	
		
			
				|  |  |          String appKey = accessToken.getAppKey();
 | 
	
		
			
				|  |  |          String signSecret = accessToken.getSignSecret();
 | 
	
		
			
				|  |  |          if (Check.isNull(signSecret) || Check.isNull(appKey)) {
 | 
	
	
		
			
				|  | @@ -1055,26 +1060,45 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
 | 
	
		
			
				|  |  |              JSONObject data = obj.getJSONObject("data");
 | 
	
		
			
				|  |  |              JSONArray result = data.getJSONArray("activityItemDataList");
 | 
	
		
			
				|  |  |              total = data.getInteger("total");
 | 
	
		
			
				|  |  | +            List<Long> itemIds = new ArrayList<>();
 | 
	
		
			
				|  |  | +            List<KuaiShouActivityOpenItemList> list = new ArrayList<>();
 | 
	
		
			
				|  |  |              for (int i = 0; i < result.size(); i++) {
 | 
	
		
			
				|  |  |                  JSONObject info = result.getJSONObject(i);
 | 
	
		
			
				|  |  | -                KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
 | 
	
		
			
				|  |  | -                list.add(activityInfo);
 | 
	
		
			
				|  |  | +                //商品活动审核状态:1-待审核,2-审核通过,3-审核拒绝,5-已失效
 | 
	
		
			
				|  |  | +                if (info.getLong("itemAuditStatus") == 1 || info.getLong("itemAuditStatus") == 2) {
 | 
	
		
			
				|  |  | +                    KuaiShouActivityOpenItemList activityInfo = new KuaiShouActivityOpenItemList(info);
 | 
	
		
			
				|  |  | +                    list.add(activityInfo);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                //2-审核通过
 | 
	
		
			
				|  |  | +                if (info.getLong("itemAuditStatus") == 2) {
 | 
	
		
			
				|  |  | +                    itemIds.add(info.getLong("itemId"));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (Check.isNotNull(list) && list.size() > 0) {
 | 
	
		
			
				|  |  | +                if ("ruixuan".equals(dbtype)) {
 | 
	
		
			
				|  |  | +                    supplyChainMapper.replaceKuaiShouActivityOpenItemList(list);
 | 
	
		
			
				|  |  | +                } else if ("miaogousi".equals(dbtype)) {
 | 
	
		
			
				|  |  | +                    supplyChainMapper.replaceMgsKuaiShouActivityOpenItemList(list);
 | 
	
		
			
				|  |  | +                } else if ("rocket".equals(dbtype)) {
 | 
	
		
			
				|  |  | +                    supplyChainMapper.replaceRocketKuaiShouActivityOpenItemList(list);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<List<Long>> splits = Lists.newArrayList(Lists.partition(itemIds, 10));
 | 
	
		
			
				|  |  | +            for (List<Long> itIds : splits) {
 | 
	
		
			
				|  |  | +                getActivityItemDetail(accessToken, url, activityId, itIds, dbtype);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          } 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);
 | 
	
		
			
				|  |  | +            getKuaishouActivityOpenItemList(accessToken, url, activityId, page + 1, dbtype);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private void getMgsKuaishouActivityOpenItemList(KuaishouAccessToken accessToken, String url, Long activityId, Integer page) {
 | 
	
		
			
				|  |  | +    private void getActivityItemDetail(KuaishouAccessToken accessToken, String url, Long activityId, List<Long> itemIds, String dbtype) {
 | 
	
		
			
				|  |  |          List<KuaiShouActivityOpenItemList> list = new ArrayList<>();
 | 
	
		
			
				|  |  |          String appKey = accessToken.getAppKey();
 | 
	
		
			
				|  |  |          String signSecret = accessToken.getSignSecret();
 | 
	
	
		
			
				|  | @@ -1082,94 +1106,49 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
 | 
	
		
			
				|  |  | -        OpenDistributionInvestmentActivityOpenItemListRequest request = new OpenDistributionInvestmentActivityOpenItemListRequest();
 | 
	
		
			
				|  |  | +        OpenDistributionInvestmentActivityItemDetailRequest request = new OpenDistributionInvestmentActivityItemDetailRequest();
 | 
	
		
			
				|  |  |          request.setAccessToken(accessToken.getAccessToken());
 | 
	
		
			
				|  |  |          request.setApiMethodVersion(1L);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        //每页活动数量
 | 
	
		
			
				|  |  | -        request.setLimit(200);
 | 
	
		
			
				|  |  | -        Integer offset = (page - 1) * 200;
 | 
	
		
			
				|  |  | -        request.setOffset(offset);
 | 
	
		
			
				|  |  |          request.setActivityId(activityId);
 | 
	
		
			
				|  |  | -        OpenDistributionInvestmentActivityOpenItemListResponse response = null;
 | 
	
		
			
				|  |  | +        request.setItemId(itemIds);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        OpenDistributionInvestmentActivityItemDetailResponse 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);
 | 
	
		
			
				|  |  | +            JSONArray data = obj.getJSONArray("data");
 | 
	
		
			
				|  |  | +            for (int i = 0; i < data.size(); i++) {
 | 
	
		
			
				|  |  | +                JSONObject info = data.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);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +            if (Check.isNotNull(list) && list.size() > 0) {
 | 
	
		
			
				|  |  | +                if ("ruixuan".equals(dbtype)) {
 | 
	
		
			
				|  |  | +                for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
 | 
	
		
			
				|  |  | +                    supplyChainMapper.updateKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                } else if ("miaogousi".equals(dbtype)) {
 | 
	
		
			
				|  |  | +                    for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
 | 
	
		
			
				|  |  | +                        supplyChainMapper.updateMgsKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                } else if ("rocket".equals(dbtype)) {
 | 
	
		
			
				|  |  | +                    for (KuaiShouActivityOpenItemList kuaiShouActivityOpenItemList : list) {
 | 
	
		
			
				|  |  | +                        supplyChainMapper.updateRocketKuaiShouActivityOpenItemList(kuaiShouActivityOpenItemList);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    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"));
 | 
	
		
			
				|  |  | +            log.error("===招商活动商品详情接口(open.distribution.investment.activity.item.detail)失败,信息:{}", 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) {
 |