Browse Source

2025-12-10

过站采集sop预览优化
master
fengyuan_yang 1 month ago
parent
commit
9a91087f18
  1. 60
      src/main/java/com/gaotao/modules/pms/controller/QcController.java

60
src/main/java/com/gaotao/modules/pms/controller/QcController.java

@ -21,6 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
@RestController
@ -1807,6 +1809,64 @@ public class QcController {
return R.ok().put("page", page);
}
/**
* SOP文件预览/下载
* 根据文件路径读取文件内容并返回
**/
@PostMapping("/downloadSopFile")
public void downloadSopFile(@RequestParam("sopUrl") String sopUrl, HttpServletResponse response) {
if (sopUrl == null || sopUrl.isEmpty()) {
throw new RuntimeException("文件路径不能为空");
}
File file = new File(sopUrl);
if (!file.exists()) {
throw new RuntimeException("文件不存在: " + sopUrl);
}
// 获取文件后缀
String fileName = file.getName();
String fileSuffix = "";
if (fileName.contains(".")) {
fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
}
// 设置响应类型
String contentType = "application/octet-stream";
if ("pdf".equals(fileSuffix)) {
contentType = "application/pdf";
} else if ("jpg".equals(fileSuffix) || "jpeg".equals(fileSuffix)) {
contentType = "image/jpeg";
} else if ("png".equals(fileSuffix)) {
contentType = "image/png";
} else if ("gif".equals(fileSuffix)) {
contentType = "image/gif";
} else if ("bmp".equals(fileSuffix)) {
contentType = "image/bmp";
} else if ("mp4".equals(fileSuffix)) {
contentType = "video/mp4";
} else if ("txt".equals(fileSuffix)) {
contentType = "text/plain";
}
response.setContentType(contentType);
response.setHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
OutputStream os = response.getOutputStream()) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = bis.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.flush();
} catch (IOException e) {
throw new RuntimeException("文件读取失败: " + e.getMessage());
}
}
/**
* 查询可用的SOP文件
**/

Loading…
Cancel
Save