Commit bf6b4e71 by 刘宇峰

同步商品信息-优化代码

1 parent ad3fe834
......@@ -100,7 +100,7 @@ public interface ShopmallGoodsApiService {
public List<QueryGoodsSaleLimitListResponse> queryGoodsSaleLimitList(@RequestParam("goodsSkuCodes") List<String> goodsSkuCodes);
@GetMapping(value = "/syncGoodsListData", produces = MediaType.APPLICATION_JSON_VALUE)
public Integer syncGoodsListData();
public Integer syncGoodsListData(@RequestBody List<String> goodsSkuCodes);
@PostMapping(value = "/syncGoodsInfoData", produces = MediaType.APPLICATION_JSON_VALUE)
public Integer syncGoodsInfoData(@RequestBody List<String> goodsSkuCodes);
......
......@@ -80,8 +80,8 @@ public class GoodsApiController implements ShopmallGoodsApiService {
@Operation(summary = "同步全部商品数据接口")
@Override
public Integer syncGoodsListData() {
return goodsService.syncGoodsListData();
public Integer syncGoodsListData(List<String> goodsSkuCodes) {
return goodsService.syncGoodsListData(goodsSkuCodes);
}
@Operation(summary = "同步特定商品数据接口")
......
......@@ -194,26 +194,32 @@ public class GoodsService implements InitializingBean {
*
* @return
*/
public Integer syncGoodsListData() {
log.info("开始同步商品数据");
QueryGoodsListResponse totalListResponse = cloudCraneService.queryGoodsList(new QueryGoodsListRequest(1, 100));
public Integer syncGoodsListData(List<String> goodsSkuCodes) {
log.info("开始同步全部商品数据");
QueryGoodsListByConditionRequest conditionRequest = new QueryGoodsListByConditionRequest();
conditionRequest.setPageNum(1);
conditionRequest.setPageSize(100);
QueryGoodsListByConditionResponse totalListResponse = cloudCraneService.queryGoodsListByCondition(conditionRequest);
Integer totalCount = totalListResponse.getTotalCount();
Integer totalPage = totalListResponse.getTotalPage();
log.info("商品数据{}条,{}页", totalCount, totalPage);
List<String> goodsSkuCodeList = totalListResponse.getGoodsSkuList().stream().map(GoodsSkuListItem::getGoodsSkuCode).collect(Collectors.toList());
//同步第一页
Integer syncCnt = syncGoodsInfoData(goodsSkuCodeList, false);
if (CollectionUtils.isNotEmpty(totalListResponse.getGoodsSkuList())) {
List<String> goodsSkuCodeList = totalListResponse.getGoodsSkuList().stream().map(GoodsSkuListItem::getGoodsSkuCode).collect(Collectors.toList());
//同步第一页
Integer syncCnt = syncGoodsInfoData(goodsSkuCodeList, false);
for (int i = 2; i <= totalPage; i++) {
QueryGoodsListResponse goodsListPageResponse = cloudCraneService.queryGoodsList(new QueryGoodsListRequest(i, totalListResponse.getPageSize()));
for (int i = 2; i <= totalPage; i++) {
QueryGoodsListResponse goodsListPageResponse = cloudCraneService.queryGoodsList(new QueryGoodsListRequest(i, totalListResponse.getPageSize()));
goodsSkuCodeList = goodsListPageResponse.getGoodsSkuList().stream().map(GoodsSkuListItem::getGoodsSkuCode).collect(Collectors.toList());
goodsSkuCodeList = goodsListPageResponse.getGoodsSkuList().stream().map(GoodsSkuListItem::getGoodsSkuCode).collect(Collectors.toList());
log.info("开始同步{}页商品数据", i);
syncCnt += syncGoodsInfoData(goodsSkuCodeList, false);
log.info("开始同步{}页商品数据", i);
syncCnt += syncGoodsInfoData(goodsSkuCodeList, false);
}
return syncCnt;
}
return syncCnt;
return 0;
}
/**
......
......@@ -52,7 +52,7 @@ public class GoodsServiceTest {
@Test
public void testSyncAllGoods() {
goodsService.syncGoodsListData();
goodsService.syncGoodsListData(null);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!