From 6991ca63b0f5286abc13b56e64012ccf459fca01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cxxxxxxx=E8=AF=A6?= <286460656@qq.com> Date: Mon, 18 Sep 2023 20:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E7=B1=BB=E7=9B=AE=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spi/move/GetProductInfoByProductId.java | 63 ++++++++++++++++++- .../api/spi/move/GetProductInfoService.java | 63 ++++++++++++++++++- 2 files changed, 122 insertions(+), 4 deletions(-) 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");