diff --git a/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoByProductId.java b/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoByProductId.java index 84d56633..8b5b0513 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoByProductId.java +++ b/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoByProductId.java @@ -4,6 +4,13 @@ import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.doudian.open.api.product_GetRecommendCategory.ProductGetRecommendCategoryRequest; +import com.doudian.open.api.product_GetRecommendCategory.ProductGetRecommendCategoryResponse; +import com.doudian.open.api.product_GetRecommendCategory.data.CategoryDetailsItem; +import com.doudian.open.api.product_GetRecommendCategory.param.ProductGetRecommendCategoryParam; +import com.doudian.open.api.shop_getShopCategory.ShopGetShopCategoryRequest; +import com.doudian.open.api.shop_getShopCategory.ShopGetShopCategoryResponse; +import com.doudian.open.api.shop_getShopCategory.param.ShopGetShopCategoryParam; import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.ExtensionService; @@ -32,6 +39,7 @@ import org.phprpc.util.AssocArray; import org.phprpc.util.PHPSerializer; import org.springframework.beans.factory.annotation.Autowired; +import java.lang.annotation.Retention; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -73,6 +81,9 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi getAuthCode(); GetProductInfoRequestDTO fields = req.getData(); List productIds = fields.getProductIds(); + if (productIds.size() > 20) { + return R.ok(Ret.fail("最多支持20个商品")); + } List productInfo = new ArrayList<>(); List fetchFailIds = new ArrayList<>(); for (int i = 0; i < productIds.size(); i++) { @@ -108,8 +119,56 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi product.put("ddCategoryList", pathArr); } } else { - product.put("ddCid", ""); - product.put("ddCategoryList", ""); + ProductGetRecommendCategoryRequest request = new ProductGetRecommendCategoryRequest(); + ProductGetRecommendCategoryParam param = request.getParam(); + param.setScene("category_infer"); + param.setName(product.getString("title")); + ProductGetRecommendCategoryResponse response = request.execute(); + List categoryDetails = response.getData().getCategoryDetails(); + if (!ObjectUtil.isEmpty(categoryDetails) && categoryDetails.size() > 0) { + log.info(categoryDetails.get(0).toString()); + CategoryDetailsItem categoryDetailsItem = categoryDetails.get(0); + List categoryIds = new ArrayList<>(); + List pathArr = new ArrayList<>(); + if (categoryDetailsItem.getCategoryDetail().getFirstCid() != 0) { + categoryIds.add(categoryDetailsItem.getCategoryDetail().getFirstCid()); + } + if (categoryDetailsItem.getCategoryDetail().getSecondCid() != 0) { + categoryIds.add(categoryDetailsItem.getCategoryDetail().getSecondCid()); + } + if (categoryDetailsItem.getCategoryDetail().getFirstCid() != 0) { + categoryIds.add(categoryDetailsItem.getCategoryDetail().getFirstCid()); + } + if (categoryDetailsItem.getCategoryDetail().getFourthCid() != 0) { + categoryIds.add(categoryDetailsItem.getCategoryDetail().getFourthCid()); + } + if (!categoryDetailsItem.getCategoryDetail().getFirstCname().isEmpty()) { + pathArr.add(categoryDetailsItem.getCategoryDetail().getFirstCname()); + } + if (!categoryDetailsItem.getCategoryDetail().getSecondCname().isEmpty()) { + pathArr.add(categoryDetailsItem.getCategoryDetail().getSecondCname()); + } + if (!categoryDetailsItem.getCategoryDetail().getThirdCname().isEmpty()) { + pathArr.add(categoryDetailsItem.getCategoryDetail().getThirdCname()); + } + if (!categoryDetailsItem.getCategoryDetail().getFourthCname().isEmpty()) { + pathArr.add(categoryDetailsItem.getCategoryDetail().getFourthCname()); + } + ShopGetShopCategoryRequest shopRequest = new ShopGetShopCategoryRequest(); + ShopGetShopCategoryParam shopParam = shopRequest.getParam(); + shopParam.setCid(categoryIds.get(categoryIds.size() - 2)); + ShopGetShopCategoryResponse shopReponse = shopRequest.execute(); + if (!ObjectUtil.isEmpty(shopReponse.getData())) { + product.put("ddCid", categoryIds); + product.put("ddCategoryList", pathArr); + } else { + product.put("ddCid", ""); + product.put("ddCategoryList", ""); + } + } else { + product.put("ddCid", ""); + product.put("ddCategoryList", ""); + } } // 处理价格 Double price = product.getDoubleValue("jd_price"); diff --git a/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoService.java b/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoService.java index 293034f1..6b6479f1 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/move/GetProductInfoService.java @@ -3,6 +3,14 @@ package com.ms.api.spi.move; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.doudian.open.api.product_GetRecommendCategory.ProductGetRecommendCategoryRequest; +import com.doudian.open.api.product_GetRecommendCategory.ProductGetRecommendCategoryResponse; +import com.doudian.open.api.product_GetRecommendCategory.data.CategoryDetail; +import com.doudian.open.api.product_GetRecommendCategory.data.CategoryDetailsItem; +import com.doudian.open.api.product_GetRecommendCategory.param.ProductGetRecommendCategoryParam; +import com.doudian.open.api.shop_getShopCategory.ShopGetShopCategoryRequest; +import com.doudian.open.api.shop_getShopCategory.ShopGetShopCategoryResponse; +import com.doudian.open.api.shop_getShopCategory.param.ShopGetShopCategoryParam; import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.ExtensionService; @@ -73,6 +81,9 @@ public class GetProductInfoService extends SPIBaseService implements ExtensionSe GetProductInfoRequestDTO fields = req.getData(); // List sourceItemUrls = new ArrayList<>(); List sourceItemUrls = fields.getSourceItemUrls(); + if (sourceItemUrls.size() > 20) { + return R.ok(Ret.fail("最多支持20个商品")); + } // sourceItemUrls.add("https://detail.1688.com/offer/682805686164.html?spm=a2638t.b_90254924.bangdan-list.3.3872436cl59VWf&cosite=baidujj_pz&tracelog=p4p&_p_isad=1&clickid=3906df8adbe74c3faba6eefc496fa074&sessionid=3fa85d5fd57096560a3cfa71088c6e4a"); // sourceItemUrls.add("https://detail.1688.com/offer/682805686164.html?spm=a2638t.b_90254924.bangdan-list.3.3872436cl59VWf&cosite=baidujj_pz&tracelog=p4p&_p_isad=1&clickid=3906df8adbe74c3faba6eefc496fa074&sessionid=3fa85d5fd57096560a3cfa71088c6e4a"); List productInfo = new ArrayList<>(); @@ -113,8 +124,56 @@ public class GetProductInfoService extends SPIBaseService implements ExtensionSe product.put("ddCategoryList", pathArr); } } else { - product.put("ddCid", ""); - product.put("ddCategoryList", ""); + ProductGetRecommendCategoryRequest request = new ProductGetRecommendCategoryRequest(); + ProductGetRecommendCategoryParam param = request.getParam(); + param.setScene("category_infer"); + param.setName(product.getString("title")); + ProductGetRecommendCategoryResponse response = request.execute(); + List categoryDetails = response.getData().getCategoryDetails(); + if (!ObjectUtil.isEmpty(categoryDetails) && categoryDetails.size() > 0) { + log.info(categoryDetails.get(0).toString()); + CategoryDetailsItem categoryDetailsItem = categoryDetails.get(0); + List categoryIds = new ArrayList<>(); + List pathArr = new ArrayList<>(); + if (categoryDetailsItem.getCategoryDetail().getFirstCid() != 0) { + categoryIds.add(categoryDetailsItem.getCategoryDetail().getFirstCid()); + } + if (categoryDetailsItem.getCategoryDetail().getSecondCid() != 0) { + categoryIds.add(categoryDetailsItem.getCategoryDetail().getSecondCid()); + } + if (categoryDetailsItem.getCategoryDetail().getFirstCid() != 0) { + categoryIds.add(categoryDetailsItem.getCategoryDetail().getFirstCid()); + } + if (categoryDetailsItem.getCategoryDetail().getFourthCid() != 0) { + categoryIds.add(categoryDetailsItem.getCategoryDetail().getFourthCid()); + } + if (!categoryDetailsItem.getCategoryDetail().getFirstCname().isEmpty()) { + pathArr.add(categoryDetailsItem.getCategoryDetail().getFirstCname()); + } + if (!categoryDetailsItem.getCategoryDetail().getSecondCname().isEmpty()) { + pathArr.add(categoryDetailsItem.getCategoryDetail().getSecondCname()); + } + if (!categoryDetailsItem.getCategoryDetail().getThirdCname().isEmpty()) { + pathArr.add(categoryDetailsItem.getCategoryDetail().getThirdCname()); + } + if (!categoryDetailsItem.getCategoryDetail().getFourthCname().isEmpty()) { + pathArr.add(categoryDetailsItem.getCategoryDetail().getFourthCname()); + } + ShopGetShopCategoryRequest shopRequest = new ShopGetShopCategoryRequest(); + ShopGetShopCategoryParam shopParam = shopRequest.getParam(); + shopParam.setCid(categoryIds.get(categoryIds.size() - 2)); + ShopGetShopCategoryResponse shopReponse = shopRequest.execute(); + if (!ObjectUtil.isEmpty(shopReponse.getData())) { + product.put("ddCid", categoryIds); + product.put("ddCategoryList", pathArr); + } else { + product.put("ddCid", ""); + product.put("ddCategoryList", ""); + } + } else { + product.put("ddCid", ""); + product.put("ddCategoryList", ""); + } } // 处理价格 JSONObject skuMap = product.getJSONObject("skuMap");