|
|
@ -131,6 +131,8 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
List<String> txtName = new ArrayList<>(); |
|
|
List<String> txtName = new ArrayList<>(); |
|
|
|
|
|
|
|
|
for (File file : files) { |
|
|
for (File file : files) { |
|
|
|
|
|
log.info("file: {}", file.getName()); |
|
|
|
|
|
|
|
|
String fileName = file.getName(); |
|
|
String fileName = file.getName(); |
|
|
int dotIndex = fileName.lastIndexOf("."); |
|
|
int dotIndex = fileName.lastIndexOf("."); |
|
|
String s = fileName.substring(dotIndex + 1); |
|
|
String s = fileName.substring(dotIndex + 1); |
|
|
@ -138,6 +140,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
//获取每个文件夹后缀与数据库里面的规定后缀名是否一样 |
|
|
//获取每个文件夹后缀与数据库里面的规定后缀名是否一样 |
|
|
String suffix = equipmentFolderLocation.getSuffix(); |
|
|
String suffix = equipmentFolderLocation.getSuffix(); |
|
|
String[] fileTypes = suffix.split("/");//文件类型,可能有多种 |
|
|
String[] fileTypes = suffix.split("/");//文件类型,可能有多种 |
|
|
|
|
|
log.info("fileTypes: {}", Arrays.toString(fileTypes)); |
|
|
for (String type : fileTypes) { |
|
|
for (String type : fileTypes) { |
|
|
if (s.equals(type)) { |
|
|
if (s.equals(type)) { |
|
|
if (s.equals("jpg") || s.equals("png") || s.equals("gif")) { |
|
|
if (s.equals("jpg") || s.equals("png") || s.equals("gif")) { |
|
|
@ -146,6 +149,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
} |
|
|
} |
|
|
if (s.equals("csv") || s.equals("xls") || s.equals("xlsx")) { |
|
|
if (s.equals("csv") || s.equals("xls") || s.equals("xlsx")) { |
|
|
excelName.add(equipmentFolderLocation.getFolderPath() + File.separator + fileName); |
|
|
excelName.add(equipmentFolderLocation.getFolderPath() + File.separator + fileName); |
|
|
|
|
|
log.info("excelName新增:{}", fileName); |
|
|
map.get("excel").add(file); |
|
|
map.get("excel").add(file); |
|
|
} |
|
|
} |
|
|
if (s.equals("txt") || s.equals("tff")) { |
|
|
if (s.equals("txt") || s.equals("tff")) { |
|
|
@ -209,7 +213,6 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
batchNo = (Integer)resultList.get(0).get("batchNo")-1; |
|
|
batchNo = (Integer)resultList.get(0).get("batchNo")-1; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//对图片保存 |
|
|
//对图片保存 |
|
|
if (CollectionUtils.isNotEmpty(imageFiles)) { |
|
|
if (CollectionUtils.isNotEmpty(imageFiles)) { |
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
@ -243,6 +246,9 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
//用一个统一的时间搓保证新增和复制删除的文件名是一样的 |
|
|
//用一个统一的时间搓保证新增和复制删除的文件名是一样的 |
|
|
String timestamp1 = String.valueOf(System.currentTimeMillis()); |
|
|
String timestamp1 = String.valueOf(System.currentTimeMillis()); |
|
|
//excel(csv)不为空就做新增 |
|
|
//excel(csv)不为空就做新增 |
|
|
|
|
|
if (!excelName.isEmpty()){ |
|
|
|
|
|
log.info("excelName: {}", excelName); |
|
|
|
|
|
} |
|
|
if (CollectionUtils.isNotEmpty(excelName)) { |
|
|
if (CollectionUtils.isNotEmpty(excelName)) { |
|
|
log.info("excelName isNotEmpty"); |
|
|
log.info("excelName isNotEmpty"); |
|
|
List<EquipmentDataDetail> equipmentDataDetails = saveExcel(excelName, equipmentFolderLocation, batchNo, timestamp1); |
|
|
List<EquipmentDataDetail> equipmentDataDetails = saveExcel(excelName, equipmentFolderLocation, batchNo, timestamp1); |
|
|
@ -301,16 +307,16 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
try { |
|
|
try { |
|
|
// 复制文件到目标文件夹 |
|
|
// 复制文件到目标文件夹 |
|
|
Files.copy(sourceFile.toPath(), destinationFile.toPath()); |
|
|
Files.copy(sourceFile.toPath(), destinationFile.toPath()); |
|
|
log.info("文件复制成功!" + sourceFile.toPath()); |
|
|
|
|
|
|
|
|
log.info("文件复制成功!{}", sourceFile.toPath()); |
|
|
// 删除源文件 |
|
|
// 删除源文件 |
|
|
if (sourceFile.delete()) { |
|
|
if (sourceFile.delete()) { |
|
|
log.info("源文件删除成功 :" + sourceFile.toPath()); |
|
|
|
|
|
|
|
|
log.info("源文件删除成功 :{}", sourceFile.toPath()); |
|
|
} else { |
|
|
} else { |
|
|
log.info("源文件删除失败 :" + sourceFile.toPath()); |
|
|
|
|
|
|
|
|
log.info("源文件删除失败 :{}", sourceFile.toPath()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
log.info("文件操作出错:" + e.getMessage()); |
|
|
|
|
|
|
|
|
log.info("文件操作出错:{}", e.getMessage()); |
|
|
} |
|
|
} |
|
|
//存在就删除 |
|
|
//存在就删除 |
|
|
|
|
|
|
|
|
@ -350,7 +356,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
log.info("读取文件失败,文件为:" + s + "失败日志:" + e.getMessage()); |
|
|
|
|
|
|
|
|
log.info("读取文件失败,文件为:{}失败日志:{}", s, e.getMessage()); |
|
|
} |
|
|
} |
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
log.info("读取的文件为空,或不是excel格式的"); |
|
|
log.info("读取的文件为空,或不是excel格式的"); |
|
|
|