|
|
|
@ -84,7 +84,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
//图片 |
|
|
|
List<String> imageFiles = new ArrayList<>(); |
|
|
|
|
|
|
|
// List<String> deleteFile =new ArrayList<>(); |
|
|
|
List<String> deleteFile =new ArrayList<>(); |
|
|
|
|
|
|
|
if (fileInfo != null && files != null) { |
|
|
|
Path folderPath = Paths.get(folderFiler); |
|
|
|
@ -96,15 +96,18 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
// 处理图片文件的逻辑 |
|
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
|
// 指定新的文件名(这里示例加上前缀) |
|
|
|
Path newFilePath = folderPath.resolve(timestamp+"$" + file.getFileName()); |
|
|
|
Path newFilePath = folderPath.resolve(timestamp + "$" + file.getFileName()); |
|
|
|
// 重命名文件 |
|
|
|
Files.move(file, newFilePath, StandardCopyOption.REPLACE_EXISTING); |
|
|
|
imageFiles.add(newFilePath.toString()); |
|
|
|
//保存的图片路径 |
|
|
|
String s = file.getFileName().toString(); |
|
|
|
imageFiles.add(excel.getBackupPhotoPath()+"\\"+timestamp + "$"+s); |
|
|
|
deleteFile.add(newFilePath.toString()); |
|
|
|
|
|
|
|
}else { |
|
|
|
} else { |
|
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
|
// 指定新的文件名(这里示例加上前缀) |
|
|
|
Path newFilePath = folderPath.resolve(timestamp+"$" + file.getFileName()); |
|
|
|
Path newFilePath = folderPath.resolve(timestamp + "$" + file.getFileName()); |
|
|
|
// 重命名文件 |
|
|
|
Files.move(file, newFilePath, StandardCopyOption.REPLACE_EXISTING); |
|
|
|
excelFiles.add(newFilePath.toString()); |
|
|
|
@ -115,7 +118,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(excelFiles) && CollectionUtils.isEmpty(imageFiles) ) { |
|
|
|
if (CollectionUtils.isEmpty(excelFiles) && CollectionUtils.isEmpty(imageFiles)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
//判断这个批次号应该是多少 |
|
|
|
@ -131,22 +134,22 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
} else { |
|
|
|
Date createDate = equipments.get(equipments.size() - 1).getCreateDate();//获取最近新增一条信息的时间 |
|
|
|
Date date = new Date(); |
|
|
|
if (StringUtils.isEmpty(excel.getBatchDate())){ |
|
|
|
if (StringUtils.isEmpty(excel.getBatchDate())) { |
|
|
|
excel.setBatchDate("1"); |
|
|
|
} |
|
|
|
int time = Integer.parseInt(excel.getBatchDate()); |
|
|
|
Long finalTime= date.getTime()- createDate.getTime(); |
|
|
|
if (finalTime/1000>time){ |
|
|
|
batchNo = equipments.get(equipments.size() - 1).getBatchNo()+ 1; |
|
|
|
}else { |
|
|
|
Long finalTime = date.getTime() - createDate.getTime(); |
|
|
|
if (finalTime / 1000 > time) { |
|
|
|
batchNo = equipments.get(equipments.size() - 1).getBatchNo() + 1; |
|
|
|
} else { |
|
|
|
batchNo = equipments.get(equipments.size() - 1).getBatchNo(); |
|
|
|
} |
|
|
|
} |
|
|
|
//对图片保存 |
|
|
|
if (CollectionUtils.isNotEmpty(imageFiles)){ |
|
|
|
if (CollectionUtils.isNotEmpty(imageFiles)) { |
|
|
|
List<EquipmentDataDetail> equipmentDataDetails = saveImage(imageFiles, excel, batchNo); |
|
|
|
getInformationForExcelMapper.saveByExcels(equipmentDataDetails); |
|
|
|
for (String s : imageFiles) { |
|
|
|
for (String s : deleteFile) { |
|
|
|
// 创建源文件对象和目标文件夹对象 |
|
|
|
deleteBypath(s, excel.getBackupPhotoPath()); |
|
|
|
} |
|
|
|
@ -163,7 +166,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
int dotIndex = file.lastIndexOf("."); |
|
|
|
String s = file.substring(dotIndex + 1); |
|
|
|
|
|
|
|
if (s.equals("csv") ||s.equals("xls")) { |
|
|
|
if (s.equals("csv") || s.equals("xls")) { |
|
|
|
fileName.add(file); |
|
|
|
} |
|
|
|
if (s.equals("tff")) { |
|
|
|
@ -400,7 +403,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
} |
|
|
|
|
|
|
|
//对图片进行保存 |
|
|
|
private static List<EquipmentDataDetail> saveImage(List<String> fileName,EquipmentFolderLocation excel,Integer batchNo){ |
|
|
|
private static List<EquipmentDataDetail> saveImage(List<String> fileName, EquipmentFolderLocation excel, Integer batchNo) { |
|
|
|
List<EquipmentDataDetail> detailList = new ArrayList<>(); |
|
|
|
for (String s : fileName) { |
|
|
|
EquipmentDataDetail equipmentDataDetail = new EquipmentDataDetail(); |
|
|
|
@ -449,7 +452,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
String folderFile = "E:\\file"; |
|
|
|
Path folderPath = Paths.get(folderFile); |
|
|
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(folderPath)) { |
|
|
|
@ -460,15 +463,17 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
// 处理图片文件的逻辑 |
|
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
|
// 指定新的文件名(这里示例加上前缀) |
|
|
|
Path newFilePath = folderPath.resolve(timestamp+"$" + file.getFileName()); |
|
|
|
Path newFilePath = folderPath.resolve(timestamp + "$" + file.getFileName()); |
|
|
|
// 重命名文件 |
|
|
|
Files.move(file, newFilePath, StandardCopyOption.REPLACE_EXISTING); |
|
|
|
String s = newFilePath.toString(); |
|
|
|
System.out.println("图片名: " + s); |
|
|
|
}else { |
|
|
|
System.out.println("新图片名: " + s); |
|
|
|
String s1 = file.getFileName().toString(); |
|
|
|
System.out.println("旧图片名"+timestamp + "$" +s1); |
|
|
|
} else { |
|
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
|
// 指定新的文件名(这里示例加上前缀) |
|
|
|
Path newFilePath = folderPath.resolve(timestamp+"$" + file.getFileName()); |
|
|
|
Path newFilePath = folderPath.resolve(timestamp + "$" + file.getFileName()); |
|
|
|
// 重命名文件 |
|
|
|
Files.move(file, newFilePath, StandardCopyOption.REPLACE_EXISTING); |
|
|
|
String s = newFilePath.toString(); |
|
|
|
@ -480,3 +485,4 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|