|
@@ -154,6 +154,7 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public CommonResult<Boolean> uploadDataInfo(MultipartFile file, Data dataInfo) {
|
|
|
//1.检测是否有重复的批次号
|
|
|
QueryWrapper query = query();
|
|
@@ -286,15 +287,15 @@ public class DataServiceImpl extends BaseServiceImpl<DataMapper, Data> implement
|
|
|
}
|
|
|
// TODO 李兆晏 确认逻辑是否正确 end
|
|
|
|
|
|
- int batchSize = 100; // 每批插入的数量
|
|
|
+ int batchSize = 100;
|
|
|
int totalSize = dataList.size();
|
|
|
- // 循环分批插入
|
|
|
- for (int i = 0; i < totalSize; i += batchSize) {
|
|
|
- // 获取当前批次的数据
|
|
|
- int end = Math.min(i + batchSize, totalSize);
|
|
|
- dataList = dataList.subList(i, end);
|
|
|
- // 插入当前批次的数据
|
|
|
- dataMapper.insertBatch(dataList);
|
|
|
+ int page = (int) Math.ceil((double) totalSize / batchSize); // 计算总批次数
|
|
|
+
|
|
|
+ for (int i = 0; i < page; i++) {
|
|
|
+ int fromIndex = i * batchSize;
|
|
|
+ int toIndex = Math.min(fromIndex + batchSize, totalSize); // 确保最后一批不越界
|
|
|
+ List<Data> batchList = new ArrayList<>(dataList.subList(fromIndex, toIndex)); // 生成子列表副本
|
|
|
+ dataMapper.insertBatch(batchList); // 批量插入
|
|
|
}
|
|
|
FileUtils.deleteFile(destZip);
|
|
|
} catch (Exception e) {
|