Commit e0939393 by 杨林龙

分批保存数据

1 parent 6be13039
...@@ -23,6 +23,9 @@ public class MySimpleJobService { ...@@ -23,6 +23,9 @@ public class MySimpleJobService {
@Autowired @Autowired
private StatisticsDriveClient statisticsDriveClient; private StatisticsDriveClient statisticsDriveClient;
// 分批处理流程
private static final int BATCH_COUNT = 100;
public void statisticsDriveDataEveryDay() { public void statisticsDriveDataEveryDay() {
log.info("开始统计数据==="); log.info("开始统计数据===");
R statisticsDriveR = statisticsDriveClient.statisticsDriveDataEveryDay(); R statisticsDriveR = statisticsDriveClient.statisticsDriveDataEveryDay();
...@@ -41,6 +44,18 @@ public class MySimpleJobService { ...@@ -41,6 +44,18 @@ public class MySimpleJobService {
} }
log.info("开始保存数据===,数据集合的大小为" + statisticsDriveDtoList.size()); log.info("开始保存数据===,数据集合的大小为" + statisticsDriveDtoList.size());
statisticsDriveClient.insertStatisticsDriveList(statisticsDriveDtoList);
// 分批保存数据
int fragSize = statisticsDriveDtoList.size() / BATCH_COUNT;
log.info("开始分批保存,有" + fragSize + "个分片===");
for (int i = 0; i < fragSize; i++) {
List<StatisticsDriveDto> fragStatisticsDriveDtoList;
if (i != fragSize - 1) {
fragStatisticsDriveDtoList = statisticsDriveDtoList.subList(i * BATCH_COUNT, (i + 1) * BATCH_COUNT);
} else {
fragStatisticsDriveDtoList = statisticsDriveDtoList.subList(i * BATCH_COUNT, statisticsDriveDtoList.size());
}
statisticsDriveClient.insertStatisticsDriveList(fragStatisticsDriveDtoList);
}
} }
} }
...@@ -34,4 +34,10 @@ class MySimpleJobServiceTest { ...@@ -34,4 +34,10 @@ class MySimpleJobServiceTest {
System.out.println("statisticsDriveR = " + JSON.toJSONString(statisticsDriveR)); System.out.println("statisticsDriveR = " + JSON.toJSONString(statisticsDriveR));
} }
@Test
public void test02(){
int size = 623 / 100;
System.out.println("size = " + size);
}
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!