Commit bf6b4e71 by 刘宇峰

同步商品信息-优化代码

1 parent ad3fe834
...@@ -100,7 +100,7 @@ public interface ShopmallGoodsApiService { ...@@ -100,7 +100,7 @@ public interface ShopmallGoodsApiService {
public List<QueryGoodsSaleLimitListResponse> queryGoodsSaleLimitList(@RequestParam("goodsSkuCodes") List<String> goodsSkuCodes); public List<QueryGoodsSaleLimitListResponse> queryGoodsSaleLimitList(@RequestParam("goodsSkuCodes") List<String> goodsSkuCodes);
@GetMapping(value = "/syncGoodsListData", produces = MediaType.APPLICATION_JSON_VALUE) @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) @PostMapping(value = "/syncGoodsInfoData", produces = MediaType.APPLICATION_JSON_VALUE)
public Integer syncGoodsInfoData(@RequestBody List<String> goodsSkuCodes); public Integer syncGoodsInfoData(@RequestBody List<String> goodsSkuCodes);
......
...@@ -80,8 +80,8 @@ public class GoodsApiController implements ShopmallGoodsApiService { ...@@ -80,8 +80,8 @@ public class GoodsApiController implements ShopmallGoodsApiService {
@Operation(summary = "同步全部商品数据接口") @Operation(summary = "同步全部商品数据接口")
@Override @Override
public Integer syncGoodsListData() { public Integer syncGoodsListData(List<String> goodsSkuCodes) {
return goodsService.syncGoodsListData(); return goodsService.syncGoodsListData(goodsSkuCodes);
} }
@Operation(summary = "同步特定商品数据接口") @Operation(summary = "同步特定商品数据接口")
......
...@@ -194,13 +194,17 @@ public class GoodsService implements InitializingBean { ...@@ -194,13 +194,17 @@ public class GoodsService implements InitializingBean {
* *
* @return * @return
*/ */
public Integer syncGoodsListData() { public Integer syncGoodsListData(List<String> goodsSkuCodes) {
log.info("开始同步商品数据"); log.info("开始同步全部商品数据");
QueryGoodsListResponse totalListResponse = cloudCraneService.queryGoodsList(new QueryGoodsListRequest(1, 100)); QueryGoodsListByConditionRequest conditionRequest = new QueryGoodsListByConditionRequest();
conditionRequest.setPageNum(1);
conditionRequest.setPageSize(100);
QueryGoodsListByConditionResponse totalListResponse = cloudCraneService.queryGoodsListByCondition(conditionRequest);
Integer totalCount = totalListResponse.getTotalCount(); Integer totalCount = totalListResponse.getTotalCount();
Integer totalPage = totalListResponse.getTotalPage(); Integer totalPage = totalListResponse.getTotalPage();
log.info("商品数据{}条,{}页", totalCount, totalPage); log.info("商品数据{}条,{}页", totalCount, totalPage);
if (CollectionUtils.isNotEmpty(totalListResponse.getGoodsSkuList())) {
List<String> goodsSkuCodeList = totalListResponse.getGoodsSkuList().stream().map(GoodsSkuListItem::getGoodsSkuCode).collect(Collectors.toList()); List<String> goodsSkuCodeList = totalListResponse.getGoodsSkuList().stream().map(GoodsSkuListItem::getGoodsSkuCode).collect(Collectors.toList());
//同步第一页 //同步第一页
Integer syncCnt = syncGoodsInfoData(goodsSkuCodeList, false); Integer syncCnt = syncGoodsInfoData(goodsSkuCodeList, false);
...@@ -215,6 +219,8 @@ public class GoodsService implements InitializingBean { ...@@ -215,6 +219,8 @@ public class GoodsService implements InitializingBean {
} }
return syncCnt; return syncCnt;
} }
return 0;
}
/** /**
* 同步特定商品(供本系统、定时任务调用) * 同步特定商品(供本系统、定时任务调用)
......
...@@ -52,7 +52,7 @@ public class GoodsServiceTest { ...@@ -52,7 +52,7 @@ public class GoodsServiceTest {
@Test @Test
public void testSyncAllGoods() { 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!