Browse Source

2025/7/23

java8
Aoi_Tori 6 months ago
parent
commit
2f53b21024
  1. 9
      src/main/java/com/xujie/sys/modules/reader/service/impl/GetInformationForExcelServiceImpl.java

9
src/main/java/com/xujie/sys/modules/reader/service/impl/GetInformationForExcelServiceImpl.java

@ -53,6 +53,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
@Override
@Transactional(rollbackFor = Exception.class)
public void saveByExcel() {
log.info("saveByExcel方法执行");
List<EquipmentFolderLocation> locationList = equipmentFolderLocationService
.lambdaQuery()
.ne(EquipmentFolderLocation::getSuffix, "RS232/RS485")
@ -107,6 +108,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
}
private void saveInformation(EquipmentFolderLocation equipmentFolderLocation) throws Exception {
log.info("saveInformation方法执行");
String folderFiler = equipmentFolderLocation.getFolderPath();
//获取文件夹下所有文件
//创建本地文件夹路径
@ -242,8 +244,10 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
String timestamp1 = String.valueOf(System.currentTimeMillis());
//excel(csv)不为空就做新增
if (CollectionUtils.isNotEmpty(excelName)) {
log.info("excelName isNotEmpty");
List<EquipmentDataDetail> equipmentDataDetails = saveExcel(excelName, equipmentFolderLocation, batchNo, timestamp1);
if (CollectionUtils.isNotEmpty(equipmentDataDetails)) {
log.info("equipmentDataDetails isNotEmpty");
//批量新增
saveInformation(equipmentDataDetails);
for (String s : excelName) {
@ -278,6 +282,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
//新增完之后把原路径的文件复制到另一个文件并删除原路径的下的文件
//endPath本地文件名 suffixName复制到文件夹路径
private static void deleteBypath(String endPath, String suffixName, String newFileName) throws Exception {
log.info("deleteBypath方法执行");
// 创建源文件对象和目标文件夹对象
File sourceFile = new File(endPath);
@ -315,6 +320,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
//对excel(csv)文件进行操作
public List<EquipmentDataDetail> saveExcel(List<String> fileName, EquipmentFolderLocation equipmentFolderLocation, Integer batchNo, String timestamp1) {
log.info("saveExcel方法执行");
List<EquipmentDataDetail> equipmentDataDetails = new ArrayList<>();
//获取每个excel下的所有关于Test的两个值并保存
int index = 1;
@ -349,7 +355,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
if (CollectionUtils.isEmpty(list)) {
log.info("读取的文件为空,或不是excel格式的");
new File(s).delete();
// return new ArrayList<>();
return new ArrayList<>();
}
//获取复制之后的文件路径
//找到\\的最后索引
@ -820,6 +826,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
//超过一百条数据做线程池新增新增
private void saveInformation(List<EquipmentDataDetail> equipmentDataDetails) {
log.info("saveInformation(List<EquipmentDataDetail>)执行");
//如果需要新增的数量小于一百就直接新增,大于一百就做线程池新增
if (equipmentDataDetails.size() < 80) {
//批量新增

Loading…
Cancel
Save