|
@@ -5,7 +5,6 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.kuaishou.merchant.open.api.KsMerchantApiException;
|
|
@@ -51,6 +50,8 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
|
|
|
@Override
|
|
|
public JSONObject getItemDetail(Long activityId, Long itemId, String accessToken) throws Exception {
|
|
|
+ // 调用爬虫信息
|
|
|
+ JSONObject invaliItemDetail = getInvaliItemDetail(activityId, itemId);
|
|
|
JSONObject returnJson = new JSONObject();
|
|
|
AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(KuaiShouConstants.KFX_URL, KuaiShouConstants.APP_KEY, KuaiShouConstants.SIGN_SECRET);
|
|
|
OpenDistributionInvestmentActivityItemDetailRequest request = new OpenDistributionInvestmentActivityItemDetailRequest();
|
|
@@ -62,7 +63,6 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
request.setItemId(item);
|
|
|
OpenDistributionInvestmentActivityItemDetailResponse response = client.execute(request);
|
|
|
JSONObject json = JSONObject.parseObject(GsonUtils.toJSON(response));
|
|
|
-
|
|
|
if (Check.isNull(json)) {
|
|
|
throw new Exception("获取商品信息出错,请重新提交");
|
|
|
}
|
|
@@ -83,12 +83,21 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
itemJson.put("categoryId", categoryInfo.getString("categoryId"));
|
|
|
}
|
|
|
itemJson.put("detailUrl", "https://app.kwaixiaodian.com/merchant/shop/detail?id=" + itemId);
|
|
|
+ if (!Check.isNull(invaliItemDetail)) {
|
|
|
+ JSONObject invaliJSon = invaliItemDetail.getJSONObject("itemJson");
|
|
|
+ if (!Check.isNull(invaliJSon)) {
|
|
|
+ itemJson.put("postArea", invaliJSon.getString("postArea"));
|
|
|
+ itemJson.put("deliveryRate", invaliJSon.getString("deliveryRate"));
|
|
|
+ itemJson.put("regimentalPromotionRate", invaliJSon.getLong("regimentalPromotionRate"));
|
|
|
+ itemJson.put("commissionRate", invaliJSon.getLong("commissionRate"));
|
|
|
+ }
|
|
|
+ }
|
|
|
returnJson.put("judgeStatus", 1);
|
|
|
returnJson.put("itemJson", itemJson);
|
|
|
returnJson.put("code", 0);
|
|
|
returnJson.put("message", "查询成功");
|
|
|
- } else if (code != 1 ) { // 商品下线
|
|
|
- returnJson = getInvaliItemDetail(activityId, itemId, accessToken);
|
|
|
+ } else if (code != 1) { // 商品下线
|
|
|
+ return invaliItemDetail;
|
|
|
} else {
|
|
|
returnJson.put("code", -1);
|
|
|
returnJson.put("message", "数据查询失败");
|
|
@@ -98,7 +107,7 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private JSONObject getInvaliItemDetail(Long activityId, Long itemId, String accessToken) throws Exception {
|
|
|
+ private JSONObject getInvaliItemDetail(Long activityId, Long itemId) throws Exception {
|
|
|
JSONObject returnJson = new JSONObject();
|
|
|
String cookie = supplyChainMapper.getCookie();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
@@ -106,7 +115,6 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
params.put("offset", 0);
|
|
|
params.put("activityId", activityId);
|
|
|
params.put("itemId", itemId);
|
|
|
-
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Cookie", cookie);
|
|
|
String resultStr = KsHttpUtils.KuaiShouttpGetRequest("https://cps.kwaixiaodian.com/distribute/pc/investment/activity/item/list", params, headers);
|
|
@@ -120,7 +128,6 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
Integer code = result.getInteger("result");
|
|
|
if (code != 1) {
|
|
|
log.info("快分销招商商品数据返回异常:", resultStr);
|
|
|
- // sendMessageService.sendMessage("113dee46c7df464da78c07a985e92cd1", "快手供应链cookie失效,请及时更新。媒体返回信息:" + resultStr);
|
|
|
returnJson.put("code", -1);
|
|
|
returnJson.put("message", "增加快手商品信息抓取失败,请联系技术人员");
|
|
|
return returnJson;
|
|
@@ -145,22 +152,62 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ itemJson.put("commissionRate", itemJson.getLong("itemCommissionRate"));
|
|
|
+ itemJson.put("regimentalPromotionRate", itemJson.getLong("investmentPromotionRate"));
|
|
|
+ JSONObject otherInfo = getOtherInfo(itemId, cookie);
|
|
|
+ if (!Check.isNull(otherInfo)) {
|
|
|
+ itemJson.put("postArea", otherInfo.getString("postArea"));
|
|
|
+ itemJson.put("deliveryRate", otherInfo.getString("deliveryRate"));
|
|
|
+ itemJson.put("itemDescUrls", otherInfo.getJSONArray("itemDescUrls"));
|
|
|
+ itemJson.put("itemGalleryUrls", otherInfo.getJSONArray("itemGalleryUrls"));
|
|
|
+ }
|
|
|
returnJson.put("judgeStatus", 2);
|
|
|
returnJson.put("itemJson", itemJson);
|
|
|
returnJson.put("code", 0);
|
|
|
returnJson.put("message", "查询成功");
|
|
|
-
|
|
|
return returnJson;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- String a = "家居生活>厨具/杯具>刀剪菜板>菜刀";
|
|
|
- String[] split = a.split(">");
|
|
|
- String b = split[0];
|
|
|
- System.err.println(b);
|
|
|
+ private JSONObject getOtherInfo(Long itemId, String cookie) throws Exception {
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("itemId", itemId);
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Cookie", cookie);
|
|
|
+ String resultStr = KsHttpUtils.KuaiShouttpGetRequest("https://app.kwaixiaodian.com/rest/app/grocery/product/self/detail", params, headers);
|
|
|
+ JSONObject result = JSONObject.parseObject(resultStr);
|
|
|
+ if (!Check.isNull(result)) {
|
|
|
+ JSONObject productDetail = result.getJSONObject("productDetail");
|
|
|
+ if (!Check.isNull(productDetail)) {
|
|
|
+ JSONObject expressTemplate = productDetail.getJSONObject("expressTemplate");
|
|
|
+ if (!Check.isNull(expressTemplate)) {
|
|
|
+ String sendProvinceName = expressTemplate.getString("sendProvinceName");
|
|
|
+ String sendCityName = expressTemplate.getString("sendCityName");
|
|
|
+ if (Check.isNull(sendCityName)) {
|
|
|
+ returnJson.put("postArea", sendProvinceName);
|
|
|
+ } else {
|
|
|
+ returnJson.put("postArea", sendProvinceName + "-" + sendCityName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject expressInfo = productDetail.getJSONObject("expressInfo");
|
|
|
+ if (!Check.isNull(expressInfo)) {
|
|
|
+ String deliveryDesc = expressInfo.getString("deliveryDesc");
|
|
|
+ returnJson.put("deliveryRate", deliveryDesc);
|
|
|
+ }
|
|
|
+ // itemDescUrls 商品详情图
|
|
|
+ JSONArray itemDescUrls = productDetail.getJSONArray("detailImageUrls");
|
|
|
+ if (!Check.isNull(itemDescUrls)) {
|
|
|
+ returnJson.put("itemDescUrls", itemDescUrls);
|
|
|
+ }
|
|
|
+ // 轮播图
|
|
|
+ JSONArray itemGalleryUrls = productDetail.getJSONArray("imageUrls");
|
|
|
+ if (!Check.isNull(itemGalleryUrls)) {
|
|
|
+ returnJson.put("itemGalleryUrls", itemGalleryUrls);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return returnJson;
|
|
|
}
|
|
|
|
|
|
private JSONObject getCategoryInfo(Long categoryId) {
|
|
@@ -309,6 +356,11 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
kuaishouItemListMapper.updateCount(itemId, sampleCount, userCount);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Long> getActivityIds(Long userId) {
|
|
|
+ return kuaishouItemListMapper.getActivityIds(userId);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|