diff --git a/src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java b/src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java index 298073f..2c13715 100644 --- a/src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java +++ b/src/main/java/com/inspect/simulator/service/impl/HikVisionServiceImpl.java @@ -1445,54 +1445,82 @@ public class HikVisionServiceImpl implements HikVisionService { @Override public InputStream downloadCsv(String filePath) { - InputStream inputStream; - InputStream inputStreamPath = downloadFtp(filePath); - if (inputStreamPath == null) { - return null; + log.info("解析csv图片地址"+filePath); + String updatePath = truncateFileName(filePath); + InputStream inputStream = downloadFtp(updatePath); + if(inputStream==null){ + log.info("图片地址"+updatePath+"无返回"); } - if (!produceEnvironment) { - //调用华软接口 - String protocol = hrFtpUrl.substring(0, 6); // "ftp://" - String withoutProtocol = hrFtpUrl.substring(6); // "zthr02:zthr02@123.184.14.138:50021/" - String[] userAndHost = withoutProtocol.split("@"); - if (userAndHost.length != 2) { - throw new IllegalArgumentException("URL 格式错误,缺少 @ 分隔符"); - } - String[] userPass = userAndHost[0].split(":"); - String username = userPass[0]; - String password = userPass[1]; - String hostPort = userAndHost[1].replace("/", ""); // 移除末尾的 "/" - String[] hostAndPort = hostPort.split(":"); - String host = hostAndPort[0]; - int port = Integer.parseInt(hostAndPort[1]); - String imageName = Paths.get(filePath).getFileName().toString(); - //将图片上传到华软 - boolean isLoginHr = pic2Ftp(imageName, inputStreamPath, host, port, username, password); - String ftpUrlName = "[\"" + hrFtpUrl + imageName + "\"]"; - if (isLoginHr) { - //可以登陆华软ftp - inputStream = UploadFtpImageStream(hrUavUrl, ftpUrlName); - if (inputStream != null) { - return inputStream; - } - } else { - log.error("调用华软接口失败,使用本地1.csv文件!"); - inputStream = getClass().getClassLoader().getResourceAsStream("1.csv"); - return inputStream; - } - } else { - //共用同一ftp - String imageName = Paths.get(filePath).getFileName().toString(); - String ftpUrlName = "[\"ftp://" + ftpUrlAccount + ":" + ftpUrlPwd + "@" + ftpUrlAddress + ":" + ftpUrlPort + "/" + imageName + "\"]"; - inputStream = UploadFtpImageStream(hrUavUrl, ftpUrlName); - if (inputStream != null) { - return inputStream; - } - } +// if (!produceEnvironment) { +// //调用华软接口 +// String protocol = hrFtpUrl.substring(0, 6); // "ftp://" +// String withoutProtocol = hrFtpUrl.substring(6); // "zthr02:zthr02@123.184.14.138:50021/" +// String[] userAndHost = withoutProtocol.split("@"); +// if (userAndHost.length != 2) { +// throw new IllegalArgumentException("URL 格式错误,缺少 @ 分隔符"); +// } +// String[] userPass = userAndHost[0].split(":"); +// String username = userPass[0]; +// String password = userPass[1]; +// String hostPort = userAndHost[1].replace("/", ""); // 移除末尾的 "/" +// String[] hostAndPort = hostPort.split(":"); +// String host = hostAndPort[0]; +// int port = Integer.parseInt(hostAndPort[1]); +// String imageName = Paths.get(filePath).getFileName().toString(); +// //将图片上传到华软 +// boolean isLoginHr = pic2Ftp(imageName, inputStreamPath, host, port, username, password); +// String ftpUrlName = "[\"" + hrFtpUrl + imageName + "\"]"; +// if (isLoginHr) { +// //可以登陆华软ftp +// inputStream = UploadFtpImageStream(hrUavUrl, ftpUrlName); +// if (inputStream != null) { +// return inputStream; +// } +// } else { +// log.error("调用华软接口失败,使用本地1.csv文件!"); +// inputStream = getClass().getClassLoader().getResourceAsStream("1.csv"); +// return inputStream; +// } +// } else { +// //共用同一ftp +// String imageName = Paths.get(filePath).getFileName().toString(); +// String ftpUrlName = "[\"ftp://" + ftpUrlAccount + ":" + ftpUrlPwd + "@" + ftpUrlAddress + ":" + ftpUrlPort + "/" + imageName + "\"]"; +// inputStream = UploadFtpImageStream(hrUavUrl, ftpUrlName); +// if (inputStream != null) { +// +// return inputStream; +// } +// } return inputStream; } + public static String truncateFileName(String originalPath) { + // 获取文件名部分(最后一个 '/' 之后的内容) + int lastSlashIndex = originalPath.lastIndexOf('/'); + if (lastSlashIndex == -1) { + return originalPath; // 如果没有路径分隔符,直接返回原路径 + } + String fileName = originalPath.substring(lastSlashIndex + 1); + String fileExtension = ""; // 存储文件扩展名(如 .jpg) + + // 分离文件名和扩展名(如果有) + 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文件温度--返回流文件 private InputStream getFtpFileAsStream(String csvUrl) throws IOException { diff --git a/src/main/resources/mapper/PatrolResultMapper.xml b/src/main/resources/mapper/PatrolResultMapper.xml index c8e6939..d7bb533 100644 --- a/src/main/resources/mapper/PatrolResultMapper.xml +++ b/src/main/resources/mapper/PatrolResultMapper.xml @@ -766,7 +766,7 @@