diff --git a/README.md b/README.md index ccd4120a..a63c1053 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ curl --location --request POST 'localhost:8080/base/cloud/spi' \ --data-raw '{ "appId":"7264840234423027259", "authId":"4463798", -"method":"testSpi", -"data":"{\"productIds\":[682805686164],\"pageSize\":\"20\"}" +"method":"getShopCloudHotProducts", +"data":"{\"sourceChannelCode\":\"query_none_less\",\"pageSize\":20,\"pageNo\":1}" }' diff --git a/ms-api/src/main/java/com/ms/api/dto/move/GetShopCloudHotProductsRequestDTO.java b/ms-api/src/main/java/com/ms/api/dto/move/GetShopCloudHotProductsRequestDTO.java index 80363b24..3ddb0321 100644 --- a/ms-api/src/main/java/com/ms/api/dto/move/GetShopCloudHotProductsRequestDTO.java +++ b/ms-api/src/main/java/com/ms/api/dto/move/GetShopCloudHotProductsRequestDTO.java @@ -11,12 +11,13 @@ public class GetShopCloudHotProductsRequestDTO { /** * 类目ID */ - private int cid; + private Long cid; /** * 页号 */ - private int pageNo; + private Long pageNo; + private Long pageSize; /** * 关键字 diff --git a/ms-biz/src/main/java/com/ms/api/spi/move/GetShopCloudHotProductsService.java b/ms-biz/src/main/java/com/ms/api/spi/move/GetShopCloudHotProductsService.java index 9c3cfa13..5ecf5227 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/move/GetShopCloudHotProductsService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/move/GetShopCloudHotProductsService.java @@ -2,52 +2,55 @@ package com.ms.api.spi.move; import com.doudian.open.api.product_isv_getClueList.ProductIsvGetClueListRequest; import com.doudian.open.api.product_isv_getClueList.ProductIsvGetClueListResponse; +import com.doudian.open.api.product_isv_getClueList.data.ProductIsvGetClueListData; import com.doudian.open.api.product_isv_getClueList.param.ProductIsvGetClueListParam; 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.common.R; +import com.ms.api.common.Ret; import com.ms.api.common.SPIBaseService; import com.ms.api.dto.move.GetShopCloudHotProductsRequestDTO; import com.ms.api.tool.DsJsonRequestTemplate; +import com.ms.api.util.DdRequestUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import java.util.HashMap; +import java.util.Map; + /** * 获取抖店精选爆款的商品列表数据(蓝海商机) */ @ExtensionService("getShopCloudHotProducts") @Slf4j -public class GetShopCloudHotProductsService extends SPIBaseService implements ExtensionServiceHandler { +public class GetShopCloudHotProductsService extends SPIBaseService implements ExtensionServiceHandler { @Autowired private DsJsonRequestTemplate dsJsonRequestTemplate; @Override - public BaseResponse handle(BaseRequest req) { + public BaseResponse handle(BaseRequest req) { initHandle(req); // ----参数校验---- GetShopCloudHotProductsRequestDTO fields = req.getData(); - ProductIsvGetClueListRequest request = new ProductIsvGetClueListRequest(); - ProductIsvGetClueListParam param = request.getParam(); - param.setSourceChannelCode("competitive"); - param.setFirstCid(20005L); - param.setSecondCid(20224L); - param.setClueInfo("线索名称"); - param.setCurrent(1L); - param.setPageSize(100L); - param.setCompetitiveClueType(0); - ProductIsvGetClueListResponse response = request.execute(); - // ----逻辑校验---- // ----业务处理---- - - // 1688暂时没提供,要确认下是否有接口,可能要从抖店云api获取 + ProductIsvGetClueListParam param = new ProductIsvGetClueListParam(); + param.setSourceChannelCode(fields.getSourceChannelCode()); + param.setFirstCid(fields.getCid()); + param.setClueInfo(fields.getKeyword()); + param.setCurrent(fields.getPageNo()); + param.setPageSize(fields.getPageSize()); + ProductIsvGetClueListData data = DdRequestUtil.ProductIsvGetClueListRequest(param); + Map result = new HashMap<>(); + result.put("data", data.getData()); + result.put("total", data.getTotal()); // ----结果返回---- - return R.ok(); + return R.ok(Ret.success(result)); } } diff --git a/ms-biz/src/main/java/com/ms/api/util/DdRequestUtil.java b/ms-biz/src/main/java/com/ms/api/util/DdRequestUtil.java index ee02134b..6636cd9c 100644 --- a/ms-biz/src/main/java/com/ms/api/util/DdRequestUtil.java +++ b/ms-biz/src/main/java/com/ms/api/util/DdRequestUtil.java @@ -33,6 +33,10 @@ import com.doudian.open.api.product_detail.ProductDetailRequest; import com.doudian.open.api.product_detail.ProductDetailResponse; import com.doudian.open.api.product_detail.data.ProductDetailData; import com.doudian.open.api.product_detail.param.ProductDetailParam; +import com.doudian.open.api.product_isv_getClueList.ProductIsvGetClueListRequest; +import com.doudian.open.api.product_isv_getClueList.ProductIsvGetClueListResponse; +import com.doudian.open.api.product_isv_getClueList.data.ProductIsvGetClueListData; +import com.doudian.open.api.product_isv_getClueList.param.ProductIsvGetClueListParam; import com.jinritemai.cloud.base.core.util.AuthThreadLocalUtil; import com.ms.api.common.ApiResult; import com.ms.api.consts.AppConst; @@ -179,4 +183,21 @@ public class DdRequestUtil { } throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); } + + public static ProductIsvGetClueListData ProductIsvGetClueListRequest(ProductIsvGetClueListParam param) { + String activeProfile= System.getenv("sys-deploy-env"); + if (!"Prod".equals(activeProfile)){ + AuthThreadLocalUtil.set(AppConst.TEST_SHOP_ID); + } + ProductIsvGetClueListRequest request = new ProductIsvGetClueListRequest(); + request.setParam(param); + log.info("=============Dd请求餐素:{}===================", JSONObject.toJSONString(param)); + ProductIsvGetClueListResponse response = request.execute(); + log.info("=============Dd请求返回:{}===================", JSONObject.toJSONString(response)); + boolean success = CommonTool.checkDdApiRequestIsSuccess(response); + if (success && ObjectUtil.isNotEmpty(response.getData())) { + return response.getData(); + } + throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + } }