|
@@ -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"));
|