diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java index e28091d..75a6fb8 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/service/impl/IdcServiceImpl.java @@ -86,6 +86,7 @@ public class IdcServiceImpl implements IdcService { private ScheduledDao scheduledDao; private String imagePath = "register/file/image2/"; + private String devImagePath = "register/file/device/"; /*获取拉取任务列表*/ @Override @@ -627,24 +628,45 @@ public class IdcServiceImpl implements IdcService { @Override public void downloadFile(String fileName, HttpServletResponse response) { - OutputStream os; + String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : fileName.substring(0, 1).equals("/") ? "" : "/"; String sourceFileName = filePath + filePathSlash + imagePath + fileName; -// String sourceFileName = fileName; - try { - if (FileUtils.isFileExist(sourceFileName)) { - byte[] bytes = FileUtils.readFileByBytes(sourceFileName); - os = response.getOutputStream(); - os.write(bytes); - os.flush(); - os.close(); + String sourceFileName2 = filePath + filePathSlash + devImagePath + fileName; + + try (OutputStream os = response.getOutputStream()) { + String targetFile = null; + + // 优先级检查文件列表(按优先级顺序) + String[] checkFiles = {sourceFileName2, sourceFileName}; + for (String file : checkFiles) { + if (FileUtils.isFileExist(file)) { + targetFile = file; + break; + } + } + + if (targetFile != null) { + // 读取文件并写入响应流 + byte[] bytes = FileUtils.readFileByBytes(targetFile); + + if (bytes != null) { + os.write(bytes); + os.flush(); // 强制刷新缓冲区 + } else { + response.setStatus(HttpServletResponse.SC_NOT_FOUND); // 404 + logger.error("文件内容为空: {}", targetFile); + } + } else { - logger.error("file not exists:" + sourceFileName); + // 处理文件不存在的情况(示例) + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + os.write("File not found".getBytes()); } } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); // 500 + logger.error("写入响应流失败: ", e); } + } private void saveUploadStatus(Map params) { diff --git a/api-admin/src/main/resources/application-dev.properties b/api-admin/src/main/resources/application-dev.properties index 42404d4..85c79a4 100644 --- a/api-admin/src/main/resources/application-dev.properties +++ b/api-admin/src/main/resources/application-dev.properties @@ -23,7 +23,7 @@ server.connectionTimeout=180000 # \u8F93\u51FA\u65E5\u5FD7\u5230\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u7684springboot.log\u6587\u4EF6\u4E2D // \u914D\u7F6E logback-spring.xml\u65F6 \u6B64\u65E5\u5FD7\u8F93\u51FA\u65B9\u5F0F\u4F1A\u88AB\u8986\u76D6\u3002 logging.file=D:/1s/udiwms/udiwms.log #logging.file=/www/glxpdata/spsyc/ -file_path=D:/share/udisps/ +file_path=D:/udi/udiwms/udiwmsfile/ #file_path=/share/order/sync back_file_path=D:/share/udisps/back/ #back_file_path=/share/order/sync_back