|
@@ -39,6 +39,9 @@ import org.springframework.stereotype.Service;
|
|
|
public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
@Autowired
|
|
|
private KuaishouItemListMapper kuaishouItemListMapper;
|
|
|
+ private static List<JSONObject> categoryIds;
|
|
|
+ @Autowired
|
|
|
+ private SupplyChainMapper supplyChainMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -74,18 +77,16 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
}
|
|
|
JSONObject itemJson = data.getJSONObject(0);
|
|
|
Long categoryId = itemJson.getLong("categoryId");
|
|
|
- String categoryInfo = getCategoryInfo(categoryId);
|
|
|
+ JSONObject categoryInfo = getCategoryInfo(categoryId);
|
|
|
if (!Check.isNull(categoryInfo)) {
|
|
|
- itemJson.put("categoryName", categoryInfo);
|
|
|
+ itemJson.put("categoryName", categoryInfo.getString("categoryName"));
|
|
|
+ itemJson.put("categoryId", categoryInfo.getString("categoryId"));
|
|
|
}
|
|
|
itemJson.put("detailUrl", "https://app.kwaixiaodian.com/merchant/shop/detail?id=" + itemId);
|
|
|
-
|
|
|
returnJson.put("judgeStatus", 1);
|
|
|
returnJson.put("itemJson", itemJson);
|
|
|
returnJson.put("code", 0);
|
|
|
returnJson.put("message", "查询成功");
|
|
|
-
|
|
|
-
|
|
|
} else if (code == 807000 && (subCode == 24101 || subCode == 24214)) { // 商品下线
|
|
|
returnJson = getInvaliItemDetail(activityId, itemId, accessToken);
|
|
|
} else {
|
|
@@ -96,37 +97,109 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
return returnJson;
|
|
|
}
|
|
|
|
|
|
- private String getCategoryInfo(Long categoryId) {
|
|
|
+
|
|
|
+ private JSONObject getInvaliItemDetail(Long activityId, Long itemId, String accessToken) throws Exception {
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ String cookie = supplyChainMapper.getCookie();
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("limit", 20);
|
|
|
+ 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);
|
|
|
+ JSONObject result = JSONObject.parseObject(resultStr);
|
|
|
+ if (Check.isNull(result)) {
|
|
|
+ log.error("快分销招商商品数据返回为空");
|
|
|
+ returnJson.put("code", -1);
|
|
|
+ returnJson.put("message", "获取商品信息为空");
|
|
|
+ return returnJson;
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ JSONArray dataArray = result.getJSONArray("data");
|
|
|
+ if (Check.isNull(dataArray)) {
|
|
|
+ log.error("快分销招商商品数据返回为data数据为空");
|
|
|
+ returnJson.put("code", -1);
|
|
|
+ returnJson.put("message", "快分销招商商品数据返回为data数据为空");
|
|
|
+ return returnJson;
|
|
|
+ }
|
|
|
+ JSONObject itemJson = dataArray.getJSONObject(0);
|
|
|
+ itemJson.put("detailUrl", "https://app.kwaixiaodian.com/merchant/shop/detail?id=" + itemId);
|
|
|
+ String itemCategoryName = itemJson.getString("itemCategoryName");
|
|
|
+ if (!Check.isNull(itemCategoryName)) {
|
|
|
+ String[] split = itemCategoryName.split(">");
|
|
|
+ if (!Check.isNull(split)) {
|
|
|
+ String categoryName = split[0];
|
|
|
+ Long categoryId = kuaishouItemListMapper.getIdByName(categoryName);
|
|
|
+ if (!Check.isNull(categoryId)) {
|
|
|
+ itemJson.put("categoryId", categoryId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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 getCategoryInfo(Long categoryId) {
|
|
|
if (Check.isNull(categoryId)) {
|
|
|
return null;
|
|
|
}
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
StringBuffer stringBuffer = new StringBuffer();
|
|
|
-
|
|
|
KuaishouItemCategory category = kuaishouItemListMapper.getCategoryInfo(categoryId);
|
|
|
-
|
|
|
if (Check.isNull(category)) {
|
|
|
return null;
|
|
|
}
|
|
|
KuaishouItemCategory secondCategory = new KuaishouItemCategory();
|
|
|
KuaishouItemCategory thirdCategory = new KuaishouItemCategory();
|
|
|
KuaishouItemCategory fourthCategory = new KuaishouItemCategory();
|
|
|
+ Long id = null;
|
|
|
if (category.getCategorySort() == 1) {
|
|
|
+ id = categoryId;
|
|
|
stringBuffer.append(category.getCategoryName());
|
|
|
} else if (category.getCategorySort() == 2) {
|
|
|
secondCategory = kuaishouItemListMapper.getCategoryInfo(category.getParentId());
|
|
|
stringBuffer.append(secondCategory.getCategoryName()).append(">").append(category.getCategoryName());
|
|
|
+ id = secondCategory.getCategoryId();
|
|
|
} else if (category.getCategorySort() == 3) {
|
|
|
secondCategory = kuaishouItemListMapper.getCategoryInfo(category.getParentId());
|
|
|
thirdCategory = kuaishouItemListMapper.getCategoryInfo(secondCategory.getParentId());
|
|
|
stringBuffer.append(thirdCategory.getCategoryName()).append(">").append(secondCategory.getCategoryName()).append(">").append(category.getCategoryName());
|
|
|
+ id = thirdCategory.getCategoryId();
|
|
|
} else if (category.getCategorySort() == 4) {
|
|
|
secondCategory = kuaishouItemListMapper.getCategoryInfo(category.getParentId());
|
|
|
thirdCategory = kuaishouItemListMapper.getCategoryInfo(secondCategory.getParentId());
|
|
|
fourthCategory = kuaishouItemListMapper.getCategoryInfo(thirdCategory.getParentId());
|
|
|
stringBuffer.append(fourthCategory.getCategoryName()).append(">").append(thirdCategory.getCategoryName()).append(">").append(secondCategory.getCategoryName()).append(">").append(category.getCategoryName());
|
|
|
+ id = fourthCategory.getCategoryId();
|
|
|
}
|
|
|
|
|
|
- return stringBuffer.toString();
|
|
|
+ returnJson.put("categoryName", stringBuffer.toString());
|
|
|
+ returnJson.put("categoryId", id);
|
|
|
+ return returnJson;
|
|
|
|
|
|
|
|
|
}
|
|
@@ -219,59 +292,23 @@ public class KuaishouItemListServiceImpl implements IKuaishouItemListService {
|
|
|
|
|
|
}
|
|
|
kuaishouItemListMapper.batchCategory(adds);
|
|
|
-
|
|
|
System.err.println(jsonObject);
|
|
|
-
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- private SupplyChainMapper supplyChainMapper;
|
|
|
-
|
|
|
- private JSONObject getInvaliItemDetail(Long activityId, Long itemId, String accessToken) throws Exception {
|
|
|
- JSONObject returnJson = new JSONObject();
|
|
|
- String cookie = supplyChainMapper.getCookie();
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
- params.put("limit", 20);
|
|
|
- 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);
|
|
|
- JSONObject result = JSONObject.parseObject(resultStr);
|
|
|
- if (Check.isNull(result)) {
|
|
|
- log.error("快分销招商商品数据返回为空");
|
|
|
- returnJson.put("code", -1);
|
|
|
- returnJson.put("message", "获取商品信息为空");
|
|
|
- return returnJson;
|
|
|
- }
|
|
|
- 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;
|
|
|
- }
|
|
|
- JSONArray dataArray = result.getJSONArray("data");
|
|
|
- if (Check.isNull(dataArray)) {
|
|
|
- log.error("快分销招商商品数据返回为data数据为空");
|
|
|
- returnJson.put("code", -1);
|
|
|
- returnJson.put("message", "快分销招商商品数据返回为data数据为空");
|
|
|
- return returnJson;
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getCategoryIds() {
|
|
|
+ if (Check.isNull(categoryIds)) {
|
|
|
+ categoryIds = kuaishouItemListMapper.getCategoryIds();
|
|
|
}
|
|
|
- JSONObject itemJson = dataArray.getJSONObject(0);
|
|
|
- itemJson.put("detailUrl", "https://app.kwaixiaodian.com/merchant/shop/detail?id=" + itemId);
|
|
|
- returnJson.put("judgeStatus", 2);
|
|
|
- returnJson.put("itemJson", itemJson);
|
|
|
- returnJson.put("code", 0);
|
|
|
- returnJson.put("message", "查询成功");
|
|
|
+ return categoryIds;
|
|
|
+ }
|
|
|
|
|
|
- return returnJson;
|
|
|
+ @Override
|
|
|
+ public void updateCount(Long itemId, Integer sampleCount, Integer userCount) {
|
|
|
+ kuaishouItemListMapper.updateCount(itemId, sampleCount, userCount);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|