...
|
...
|
@@ -4,11 +4,12 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import com.aukey.example.constant.DwApi;
|
|
|
import com.aukey.example.entity.CurrencySet;
|
|
|
import com.aukey.example.entity.FbaFulfillmentCurrentInventoryView;
|
|
|
import com.aukey.example.entity.FulfillmentCurrentInventory;
|
|
|
import com.aukey.example.util.DwHelperUtil;
|
|
|
import com.aukey.example.vo.DwParamVo;
|
|
|
import com.aukey.example.vo.DwResultVo;
|
|
|
import com.aukey.example.vo.PageVo;
|
|
|
import com.aukey.example.vo.ObjVo;
|
|
|
import com.aukey.example.vo.SlVo;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -51,9 +52,9 @@ public class TestApiController { |
|
|
private String appId;
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "小批量读取 DEMO")
|
|
|
@GetMapping("/query_all")
|
|
|
public void queryAll() {
|
|
|
@ApiOperation(value = "小批量读取 OBJ 方式")
|
|
|
@GetMapping("/query_all_obj")
|
|
|
public void queryAllObj() {
|
|
|
|
|
|
// 构造请求参数
|
|
|
DwParamVo paramVo = new DwParamVo(this.appId, TokenController.getCurrentToken());
|
...
|
...
|
@@ -62,6 +63,7 @@ public class TestApiController { |
|
|
paramVo.setQueryCondition("WHERE currency_code = 'USD'");
|
|
|
// 每页数据条数 dw服务端有限制 取值[1, 3000]
|
|
|
paramVo.setPageSize(3000);
|
|
|
paramVo.setDataStructure(DwParamVo.OBJ);
|
|
|
|
|
|
// 调用API
|
|
|
String result = DwHelperUtil.doGet(dwDataApi, DwApi.CURRENCY_SET_API, paramVo.toMap());
|
...
|
...
|
@@ -70,13 +72,46 @@ public class TestApiController { |
|
|
throw new RuntimeException(String.format("API %s 调用失败", DwApi.CURRENCY_SET_API));
|
|
|
}
|
|
|
// json解析为对象
|
|
|
DwResultVo<PageVo<CurrencySet>> resultVo = JSON.parseObject(result, new TypeReference<DwResultVo<PageVo<CurrencySet>>>() {
|
|
|
DwResultVo<ObjVo<CurrencySet>> resultVo = JSON.parseObject(result, new TypeReference<DwResultVo<ObjVo<CurrencySet>>>() {
|
|
|
});
|
|
|
|
|
|
log.info("");
|
|
|
log.info("API请求状态:{}", resultVo.getMessage());
|
|
|
log.info("API返回数据:{}", JSON.toJSONString(resultVo.getData().getData()));
|
|
|
log.info("API返回数据两:{}", resultVo.getData().getData().size());
|
|
|
log.info("API返回数据量:{}", resultVo.getData().getTotal());
|
|
|
log.info("");
|
|
|
}
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "小批量读取 SL 方式")
|
|
|
@GetMapping("/query_all_sl")
|
|
|
public void queryAllSl() {
|
|
|
|
|
|
// 构造请求参数
|
|
|
DwParamVo paramVo = new DwParamVo(this.appId, TokenController.getCurrentToken());
|
|
|
|
|
|
// 添加查询条件
|
|
|
paramVo.setQueryCondition("WHERE currency_code = 'USD'");
|
|
|
// 每页数据条数 dw服务端有限制 取值[1, 3000]
|
|
|
paramVo.setPageSize(3000);
|
|
|
paramVo.setDataStructure(DwParamVo.SL);
|
|
|
|
|
|
// 调用API
|
|
|
String result = DwHelperUtil.doGet(dwDataApi, DwApi.CURRENCY_SET_API, paramVo.toMap());
|
|
|
|
|
|
if (StringUtils.isEmpty(result)) {
|
|
|
throw new RuntimeException(String.format("API %s 调用失败", DwApi.CURRENCY_SET_API));
|
|
|
}
|
|
|
|
|
|
// json解析为对象
|
|
|
DwResultVo<SlVo> resultVo = JSON.parseObject(result, new TypeReference<DwResultVo<SlVo>>() {
|
|
|
});
|
|
|
|
|
|
log.info("");
|
|
|
log.info("API请求状态:{}", resultVo.getMessage());
|
|
|
log.info("API返回数据字段:{}", JSON.toJSONString(resultVo.getData().getData().getHeadData()));
|
|
|
log.info("API返回数据数组:{}", JSON.toJSONString(resultVo.getData().getData().getColumnDataList()));
|
|
|
log.info("API返回数据量:{}", resultVo.getData().getTotal());
|
|
|
log.info("");
|
|
|
}
|
|
|
|
...
|
...
|
@@ -85,22 +120,23 @@ public class TestApiController { |
|
|
* 适合获取 百万级别的表,大表用分页读取会非常慢
|
|
|
* 大表建议使用流式读取
|
|
|
*/
|
|
|
@ApiOperation(value = "分页读取 DEMO")
|
|
|
@GetMapping("/query_page")
|
|
|
public void queryPage() {
|
|
|
@ApiOperation(value = "分页读取 OBJ 方式")
|
|
|
@GetMapping("/query_page_obj")
|
|
|
public void queryPageObj() {
|
|
|
|
|
|
// 构造请求参数
|
|
|
DwParamVo paramVo = new DwParamVo(this.appId, TokenController.getCurrentToken());
|
|
|
// 每页数据条数 dw服务端有限制 取值[1, 3000]
|
|
|
paramVo.setPageSize(1000);
|
|
|
paramVo.setDataStructure(DwParamVo.OBJ);
|
|
|
// TODO 自定义查询条件
|
|
|
|
|
|
// json字符串转实体引用类型
|
|
|
TypeReference typeReference = new TypeReference<DwResultVo<PageVo<CurrencySet>>>() {
|
|
|
TypeReference typeReference = new TypeReference<DwResultVo<ObjVo<CurrencySet>>>() {
|
|
|
};
|
|
|
|
|
|
// 回调函数
|
|
|
Function<DwResultVo<PageVo<CurrencySet>>, Integer> callback = (DwResultVo<PageVo<CurrencySet>> resultVo) -> {
|
|
|
Function<DwResultVo<ObjVo<CurrencySet>>, Integer> callback = (DwResultVo<ObjVo<CurrencySet>> resultVo) -> {
|
|
|
List<CurrencySet> dataList = resultVo.getData().getData();
|
|
|
System.out.println(dataList.size());
|
|
|
// TODO 业务逻辑在这里实现
|
...
|
...
|
@@ -121,13 +157,53 @@ public class TestApiController { |
|
|
|
|
|
|
|
|
/**
|
|
|
* 流式读取适合百/千万级别的表内网数据同步,本机测试
|
|
|
* 适合获取 百万级别的表,大表用分页读取会非常慢
|
|
|
* 大表建议使用流式读取
|
|
|
*/
|
|
|
@ApiOperation(value = "分页读取 SL 方式")
|
|
|
@GetMapping("/query_page_sl")
|
|
|
public void queryPageSl() {
|
|
|
|
|
|
// 构造请求参数
|
|
|
DwParamVo paramVo = new DwParamVo(this.appId, TokenController.getCurrentToken());
|
|
|
// 每页数据条数 dw服务端有限制 取值[1, 3000]
|
|
|
paramVo.setPageSize(1000);
|
|
|
paramVo.setDataStructure(DwParamVo.SL);
|
|
|
// TODO 自定义查询条件
|
|
|
|
|
|
// json字符串转实体引用类型
|
|
|
TypeReference typeReference = new TypeReference<DwResultVo<SlVo>>() {
|
|
|
};
|
|
|
|
|
|
// 回调函数
|
|
|
Function<DwResultVo<SlVo>, Integer> callback = (DwResultVo<SlVo> resultVo) -> {
|
|
|
log.info("字段字段:{}", resultVo.getData().getData().getHeadData());
|
|
|
log.info("数据数组:{}", resultVo.getData().getData().getColumnDataList());
|
|
|
// TODO 业务逻辑在这里实现
|
|
|
// ... more
|
|
|
// mapper.insertList(dataList)
|
|
|
|
|
|
// 需要返回总页数
|
|
|
return resultVo.getData().getTotal();
|
|
|
};
|
|
|
|
|
|
// 使用分页API
|
|
|
DwHelperUtil.pageReader(callback,
|
|
|
dwDataApi,
|
|
|
DwApi.CURRENCY_SET_API,
|
|
|
paramVo,
|
|
|
typeReference);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 流式读取适合百级别的表内网数据同步,每次数据读取建议在[100000, 1000000],本机测试
|
|
|
* <p>
|
|
|
* 网络环境:局域网
|
|
|
* 数据源 :华为dws
|
|
|
* cpu : 4核3.2GHz
|
|
|
* 内存 :16GB DDR3
|
|
|
* 测试数据:1000W条
|
|
|
* 测试数据:100W条
|
|
|
* 回调函数不做持久化操作
|
|
|
* <p>
|
|
|
* <p>
|
...
|
...
|
@@ -154,24 +230,24 @@ public class TestApiController { |
|
|
// TODO 自定义查询条件
|
|
|
|
|
|
// 定义实体构造函数
|
|
|
Supplier<FbaFulfillmentCurrentInventoryView> constructor = FbaFulfillmentCurrentInventoryView::new;
|
|
|
Supplier<FulfillmentCurrentInventory> constructor = FulfillmentCurrentInventory::new;
|
|
|
|
|
|
// 流式读取回调函数
|
|
|
Consumer<List<FbaFulfillmentCurrentInventoryView>> callBack = (List<FbaFulfillmentCurrentInventoryView> list) -> {
|
|
|
Consumer<List<FulfillmentCurrentInventory>> callBack = (List<FulfillmentCurrentInventory> list) -> {
|
|
|
System.out.println(list.size());
|
|
|
// TODO 业务逻辑在这里实现
|
|
|
// ... more
|
|
|
// mapper.insertList(list)
|
|
|
};
|
|
|
|
|
|
// 指定回调函数数据大小,取值[500, 5000].
|
|
|
// 指定回调函数数据大小,取值[1000, 5000]. 建议2000
|
|
|
// 取值越大,数据读取占用的堆内存越高
|
|
|
int batchSize = 5000;
|
|
|
int batchSize = 1000;
|
|
|
|
|
|
// 使用 StreamAPI
|
|
|
DwHelperUtil.streamReader(
|
|
|
dwDataApi,
|
|
|
DwApi.FBA_FULFILLMENT_CURRENT_INVENTORY_VIEW_API,
|
|
|
DwApi.FULFILLMENT_CURRENT_INVENTORY,
|
|
|
paramVo.toMap(),
|
|
|
callBack,
|
|
|
batchSize,
|
...
|
...
|
|