|
|
|
@ -120,24 +120,31 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
//txt(tff)不为空就做新增 |
|
|
|
if (CollectionUtils.isNotEmpty(txtName)) { |
|
|
|
List<EquipmentDataDetail> equipmentDataDetails = saveTxt(txtName, excel, batchNo); |
|
|
|
// 创建一个固定大小的线程池,这里假设有10个线程 |
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(equipmentDataDetails.size()/100); |
|
|
|
int startList =0; |
|
|
|
int endList=100; |
|
|
|
for (int i = startList; i < equipmentDataDetails.size(); i= startList) { |
|
|
|
if (endList>equipmentDataDetails.size()){ |
|
|
|
endList = equipmentDataDetails.size(); |
|
|
|
//如果需要新增的数量小于一百就直接新增,大于一百就做线程池新增 |
|
|
|
if (equipmentDataDetails.size()<100){ |
|
|
|
//批量新增 |
|
|
|
getInformationForExcelMapper.saveByExcels(equipmentDataDetails); |
|
|
|
}else { |
|
|
|
// 创建一个固定大小的线程池,这里假设有10个线程 |
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(equipmentDataDetails.size()/100); |
|
|
|
int startList =0; |
|
|
|
int endList=100; |
|
|
|
|
|
|
|
for (int i = startList; i < equipmentDataDetails.size(); i= startList) { |
|
|
|
if (endList>equipmentDataDetails.size()){ |
|
|
|
endList = equipmentDataDetails.size(); |
|
|
|
} |
|
|
|
List<EquipmentDataDetail> details = equipmentDataDetails.subList(startList, endList); |
|
|
|
startList=startList+endList; |
|
|
|
endList=endList+endList; |
|
|
|
executor.execute(()->{ |
|
|
|
//批量新增 |
|
|
|
getInformationForExcelMapper.saveByExcels(details); |
|
|
|
}); |
|
|
|
} |
|
|
|
List<EquipmentDataDetail> details = equipmentDataDetails.subList(startList, endList); |
|
|
|
startList=startList+endList; |
|
|
|
endList=endList+endList; |
|
|
|
executor.execute(()->{ |
|
|
|
//批量新增 |
|
|
|
getInformationForExcelMapper.saveByExcels(details); |
|
|
|
}); |
|
|
|
// 关闭线程池 |
|
|
|
executor.shutdown(); |
|
|
|
} |
|
|
|
// 关闭线程池 |
|
|
|
executor.shutdown(); |
|
|
|
for (String s : txtName) { |
|
|
|
deleteBypath( s, excel.getBackupFolderPath()); |
|
|
|
} |
|
|
|
@ -164,19 +171,18 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
try { |
|
|
|
// 复制文件到目标文件夹 |
|
|
|
Files.copy(sourceFile.toPath(), destinationFile.toPath()); |
|
|
|
System.out.println("文件复制成功!"); |
|
|
|
log.info("文件复制成功!"); |
|
|
|
|
|
|
|
// 删除源文件 |
|
|
|
if (sourceFile.delete()) { |
|
|
|
System.out.println("源文件删除成功!"); |
|
|
|
log.info("源文件删除成功!"); |
|
|
|
} else { |
|
|
|
System.out.println("源文件删除失败!"); |
|
|
|
log.info("源文件删除失败!"); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
System.out.println("文件操作出错:" + e.getMessage()); |
|
|
|
log.info("文件操作出错:" + e.getMessage()); |
|
|
|
} |
|
|
|
} else { |
|
|
|
System.out.println("源文件不存在或不是文件。"); |
|
|
|
log.info("源文件不存在或已删除。"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|