diff --git a/ms-api/src/main/java/com/ms/api/dto/move/GetRecommendProductListRequestDTO.java b/ms-api/src/main/java/com/ms/api/dto/move/GetRecommendProductListRequestDTO.java new file mode 100644 index 00000000..d0c32653 --- /dev/null +++ b/ms-api/src/main/java/com/ms/api/dto/move/GetRecommendProductListRequestDTO.java @@ -0,0 +1,9 @@ +package com.ms.api.dto.move; + +import lombok.Data; + +@Data +public class GetRecommendProductListRequestDTO { + private Integer pageNo; + private Integer pageSize; +} diff --git a/ms-biz/src/main/java/com/ms/api/biz/DsCatService.java b/ms-biz/src/main/java/com/ms/api/biz/DsCatService.java new file mode 100644 index 00000000..b7e61e89 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/biz/DsCatService.java @@ -0,0 +1,65 @@ +package com.ms.api.biz; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.ms.api.common.Ret; +import com.ms.api.paas.StorageService; +import com.ms.api.tool.DsJsonRequestTemplate; +import com.ms.api.tool.MoveTool; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.HashMap; + +@Component +@Slf4j +public class DsCatService { + +// @Autowired +// private CategoryService categoryService; + + @Autowired + private DsJsonRequestTemplate dsJsonRequestTemplate; + + @Autowired + private StorageService storageService; + + public JSONArray getDSProductCatTree() { + HashMap params = new HashMap<>(); + String res = null; + JSONObject resObj = null; + String tosPath = MoveTool.getAllProductCatTreeOssPath(); + JSONArray arrayData = null; + try { + Ret getTosContentRet = storageService.getContent(tosPath); + if (getTosContentRet.getResult().equals("success")) { + arrayData = JSONObject.parseArray(getTosContentRet.getData().get("data").toString()); + } else { + try { + res = dsJsonRequestTemplate.execute("/move/search_ds_product_cat_tree", params); + log.info(res); + resObj = JSON.parseObject(res); + if (resObj.get("result").equals("success")) { + JSONObject cateTree = resObj.getJSONObject("cateTree"); + arrayData = new JSONArray(); + arrayData.add(cateTree.values()); + try { + storageService.uploadContent(tosPath, JSONObject.toJSONString(arrayData)); + } catch (Exception e) { + log.error("商品类目TOS写入操作过程异常:", e); + } + } + } catch (Exception e) { + e.printStackTrace(); + log.error("strerror2:", e); + } + } + } catch (Exception e) { + log.error("商品类目TOS读取操作过程异常:", e); + } + return arrayData; + } + +} diff --git a/ms-biz/src/main/java/com/ms/api/spi/move/GetRecommendProductListService.java b/ms-biz/src/main/java/com/ms/api/spi/move/GetRecommendProductListService.java new file mode 100644 index 00000000..b3a8c4b6 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/spi/move/GetRecommendProductListService.java @@ -0,0 +1,99 @@ +package com.ms.api.spi.move; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.jinritemai.cloud.base.api.BaseRequest; +import com.jinritemai.cloud.base.api.BaseResponse; +import com.jinritemai.cloud.base.api.ExtensionService; +import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.biz.DsCatService; +import com.ms.api.common.R; +import com.ms.api.common.Ret; +import com.ms.api.common.SPIBaseService; +import com.ms.api.dto.move.GetRecommendProductListRequestDTO; +import com.ms.api.service.CategoryService; +import com.ms.api.tool.DsJsonRequestTemplate; +import com.ms.dal.entity.Category; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +@ExtensionService("getRecommendProductList") +@Slf4j +public class GetRecommendProductListService extends SPIBaseService implements ExtensionServiceHandler { + + @Autowired + private DsJsonRequestTemplate dsJsonRequestTemplate; + + @Autowired + private DsCatService dsCatService; + + @Autowired + private CategoryService categoryService; + + @Override + public BaseResponse handle(BaseRequest req) { + initHandle(req); + getAuthCode(); + + GetRecommendProductListRequestDTO requestDTO = req.getData(); + + // 1688类目树 + JSONArray arrayData = dsCatService.getDSProductCatTree(); + + // 获取商家抖店类目列表 + List categoryList = categoryService.getAllLeafProductCatListFromTos(shopId.intValue(), false); + Collections.shuffle(categoryList); + + int productCnt = 0; + int categoryIndex = 0; + while (productCnt < requestDTO.getPageSize()) { + + + categoryIndex++; + } + + +// HashMap params = new HashMap<>(); +//// params.put("keyword",fields.getKeyword()); +//// params.put("topCid",fields.getTopCid()); +// params.put("cid",fields.getCid()); +// params.put("sort", "saleCntDesc"); +//// params.put("ruleIds", fields.getRuleIds()); +// params.put("isHideMoved", 1); +// params.put("pageNo",requestDTO.getPageNo()); +// params.put("pageSize",requestDTO.getPageSize()); +// params.put("authCode",authCode); +// log.info(params.toString()); +// JSONObject resObj = null; +// String res = null; +// List products = new LinkedList<>(); +// +// try { +// res = dsJsonRequestTemplate.execute("/move/search_choiceness_source_item", params); +// resObj = JSON.parseObject(res); +// if (resObj.get("result").equals("success")) { +// log.info("resObj::"+resObj.toString()); +// Map result = new HashMap(); +// List sourceItems = new ArrayList<>(); +// JSONArray sourceItemjson = resObj.getJSONArray("sourceItems"); +// if (!ObjectUtil.isEmpty(sourceItemjson)) { +// sourceItems = sourceItemjson; +// } +// result.put("result", resObj.getString("result")); +// result.put("sourceItems", sourceItems); +// result.put("total", resObj.getInteger("total")); +// res = JSON.toJSONString(result); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// log.error(e.getMessage()); +// } + + + return R.ok(Ret.success()); + } +} diff --git a/ms-biz/src/main/java/com/ms/api/spi/move/SearchDSProductCatTreeService.java b/ms-biz/src/main/java/com/ms/api/spi/move/SearchDSProductCatTreeService.java index 0f86e633..a573f4f8 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/move/SearchDSProductCatTreeService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/move/SearchDSProductCatTreeService.java @@ -1,29 +1,20 @@ package com.ms.api.spi.move; -import cn.hutool.core.util.ObjectUtil; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.ExtensionService; import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.biz.DsCatService; import com.ms.api.common.R; import com.ms.api.common.Ret; import com.ms.api.common.SPIBaseService; import com.ms.api.dto.move.SearchDSProductCatTreeRequestDTO; -import com.ms.api.paas.StorageService; -import com.ms.api.tool.DsJsonRequestTemplate; -import com.ms.api.common.UniqueKeyMultiValueMap; -import com.ms.api.tool.MoveTool; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.MultiValueMap; -import java.io.*; -import java.net.URL; -import java.sql.Array; -import java.util.*; +import java.util.HashMap; +import java.util.Map; /** * 获取搜索列表的类目过滤条件 @@ -35,10 +26,7 @@ import java.util.*; public class SearchDSProductCatTreeService extends SPIBaseService implements ExtensionServiceHandler { @Autowired - private DsJsonRequestTemplate dsJsonRequestTemplate; - - @Autowired - private StorageService storageService; + private DsCatService dsCatService; @Override public BaseResponse handle(BaseRequest req) { @@ -48,37 +36,7 @@ public class SearchDSProductCatTreeService extends SPIBaseService implements Ext // ----逻辑校验---- // ----业务处理---- - HashMap params = new HashMap<>(); - String res = null; - JSONObject resObj = null; - String tosPath = MoveTool.getAllProductCatTreeOssPath(); - List arrayData = null; - try { - Ret getTosContentRet = storageService.getContent(tosPath); - if (getTosContentRet.getResult().equals("success")) { - arrayData = JSONObject.parseArray(getTosContentRet.getData().get("data").toString()); - } else { - try { - res = dsJsonRequestTemplate.execute("/move/search_ds_product_cat_tree", params); - log.info(res); - resObj = JSON.parseObject(res); - if (resObj.get("result").equals("success")) { - JSONObject cateTree = resObj.getJSONObject("cateTree"); - arrayData = new ArrayList<>(cateTree.values()); - try { - storageService.uploadContent(tosPath, JSONObject.toJSONString(arrayData)); - } catch (Exception e) { - log.error("商品类目TOS写入操作过程异常:", e); - } - } - } catch (Exception e) { - e.printStackTrace(); - log.error("strerror2:" + e); - } - } - } catch (Exception e) { - log.error("商品类目TOS读取操作过程异常:", e); - } + JSONArray arrayData = dsCatService.getDSProductCatTree(); Map result = new HashMap<>(); result.put("data", arrayData.toString());