|
@@ -32,6 +32,8 @@ import java.util.*;
|
|
@Service
|
|
@Service
|
|
public class SampleScanServiceImpl implements ISampleScanService {
|
|
public class SampleScanServiceImpl implements ISampleScanService {
|
|
|
|
|
|
|
|
+ final int BATCH_INSERT_LIMITS = 100;
|
|
|
|
+
|
|
@Value("${file.upload-path}")
|
|
@Value("${file.upload-path}")
|
|
private String uploadDir;
|
|
private String uploadDir;
|
|
@Resource
|
|
@Resource
|
|
@@ -243,7 +245,14 @@ public class SampleScanServiceImpl implements ISampleScanService {
|
|
sampleScanMapper.addMainData(sampleScan);
|
|
sampleScanMapper.addMainData(sampleScan);
|
|
|
|
|
|
if (sampleScanDetails !=null && sampleScanDetails.size() > 0) {
|
|
if (sampleScanDetails !=null && sampleScanDetails.size() > 0) {
|
|
- sampleScanMapper.addDetailData(sampleScanDetails);
|
|
|
|
|
|
+ if (sampleScanDetails.size() >= BATCH_INSERT_LIMITS) {
|
|
|
|
+ List<List<SampleScanDetail>> lists = splitList(sampleScanDetails, BATCH_INSERT_LIMITS);
|
|
|
|
+ for (int i = 0; i < lists.size(); i++) {
|
|
|
|
+ sampleScanMapper.addDetailData(lists.get(i));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ sampleScanMapper.addDetailData(sampleScanDetails);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -282,4 +291,29 @@ public class SampleScanServiceImpl implements ISampleScanService {
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 将列表按指定大小分割
|
|
|
|
+ * @param list 原始列表
|
|
|
|
+ * @param size 每个子列表的大小
|
|
|
|
+ * @return 分割后的子列表集合
|
|
|
|
+ */
|
|
|
|
+ public static <T> List<List<T>> splitList(List<T> list, int size) {
|
|
|
|
+ List<List<T>> result = new ArrayList<>();
|
|
|
|
+ if (list == null || list.size() == 0 || size <= 0) {
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int fullChunks = list.size() / size;
|
|
|
|
+ for (int i = 0; i < fullChunks; i++) {
|
|
|
|
+ result.add(new ArrayList<>(list.subList(i * size, (i + 1) * size)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 处理剩余的元素
|
|
|
|
+ if (fullChunks * size < list.size()) {
|
|
|
|
+ result.add(new ArrayList<>(list.subList(fullChunks * size, list.size())));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|