|
|
|
@ -33,6 +33,7 @@ import org.apache.commons.csv.CSVParser; |
|
|
|
import org.apache.commons.csv.CSVRecord; |
|
|
|
import org.apache.commons.net.ftp.FTP; |
|
|
|
import org.apache.commons.net.ftp.FTPClient; |
|
|
|
import org.apache.commons.net.ftp.FTPFile; |
|
|
|
import org.apache.commons.net.ftp.FTPSClient; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
@ -93,6 +94,7 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
// @Value("${file.ftpUrlPort:10000}") |
|
|
|
private Integer ftpUrlPort = 10012; |
|
|
|
|
|
|
|
|
|
|
|
// @Value("${file.produceEnvironment:true}") |
|
|
|
private Boolean produceEnvironment = true; |
|
|
|
|
|
|
|
@ -1164,6 +1166,8 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
return inputStream; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//异常处理返回本地csv |
|
|
|
private float[][] exceptionHandling() throws IOException { |
|
|
|
//i.csv文件存放到resources下 |
|
|
|
@ -1443,10 +1447,11 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public InputStream downloadCsv(String filePath) { |
|
|
|
log.info("解析csv图片地址"+filePath); |
|
|
|
String updatePath = truncateFileName(filePath); |
|
|
|
String updatePath = truncateFileNameToCsv(filePath); |
|
|
|
InputStream inputStream = downloadFtp(updatePath); |
|
|
|
if(inputStream==null){ |
|
|
|
log.info("图片地址"+updatePath+"无返回"); |
|
|
|
@ -1495,30 +1500,42 @@ public class HikVisionServiceImpl implements HikVisionService { |
|
|
|
return inputStream; |
|
|
|
} |
|
|
|
|
|
|
|
public static String truncateFileName(String originalPath) { |
|
|
|
|
|
|
|
public static String truncateFileNameToCsv(String originalPath) { |
|
|
|
// 获取文件名部分(最后一个 '/' 之后的内容) |
|
|
|
int lastSlashIndex = originalPath.lastIndexOf('/'); |
|
|
|
if (lastSlashIndex == -1) { |
|
|
|
return originalPath; // 如果没有路径分隔符,直接返回原路径 |
|
|
|
// 如果没有路径分隔符,直接处理整个字符串 |
|
|
|
return processFileNameToCsv(originalPath); |
|
|
|
} |
|
|
|
|
|
|
|
// 分离路径和文件名 |
|
|
|
String path = originalPath.substring(0, lastSlashIndex + 1); |
|
|
|
String fileName = originalPath.substring(lastSlashIndex + 1); |
|
|
|
String fileExtension = ""; // 存储文件扩展名(如 .jpg) |
|
|
|
|
|
|
|
// 分离文件名和扩展名(如果有) |
|
|
|
// 处理文件名部分并强制改为.csv |
|
|
|
String processedFileName = processFileNameToCsv(fileName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return path + processedFileName; |
|
|
|
} |
|
|
|
|
|
|
|
private static String processFileNameToCsv(String fileName) { |
|
|
|
// 去掉文件扩展名(如果有) |
|
|
|
int lastDotIndex = fileName.lastIndexOf('.'); |
|
|
|
if (lastDotIndex != -1) { |
|
|
|
fileExtension = fileName.substring(lastDotIndex); |
|
|
|
fileName = fileName.substring(0, lastDotIndex); |
|
|
|
} |
|
|
|
|
|
|
|
// 去掉最后一个 '_' 及其后面的部分 |
|
|
|
int lastUnderscoreIndex = fileName.lastIndexOf('_'); |
|
|
|
if (lastUnderscoreIndex != -1) { |
|
|
|
fileName = fileName.substring(0, lastUnderscoreIndex); |
|
|
|
} |
|
|
|
// 拼接修改后的文件名和扩展名 |
|
|
|
String newFileName = fileName + fileExtension; |
|
|
|
// 拼接回原路径 |
|
|
|
return originalPath.substring(0, lastSlashIndex + 1) + newFileName; |
|
|
|
|
|
|
|
// 强制添加.csv后缀 |
|
|
|
return fileName + ".csv"; |
|
|
|
} |
|
|
|
|
|
|
|
//解析获取csv文件温度--返回流文件 |
|
|
|
|