From 0639f7feede9614a98f64450792cc83f58f80a84 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 14 五月 2025 17:00:54 +0800
Subject: [PATCH] 与测控一体阀兼容
---
pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/download/DownloadFileCtrl.java | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 109 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/download/DownloadFileCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/download/DownloadFileCtrl.java
new file mode 100644
index 0000000..4eda17f
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/download/DownloadFileCtrl.java
@@ -0,0 +1,109 @@
+package com.dy.pipIrrWebFile.download;
+
+import com.dy.pipIrrGlobal.dyFile.FileOperate;
+import com.dy.pipIrrGlobal.dyFile.FileRestVo;
+import com.dy.pipIrrGlobal.pojoFi.WebFile;
+import jakarta.servlet.ServletOutputStream;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URLEncoder;
+
+/**
+ * web鏂囦欢涓嬭浇
+ */
+@Slf4j
+@RestController
+@RequestMapping(path="download")
+@SuppressWarnings("unchecked")//java鐗堟湰瓒婇珮锛屽娉涘瀷绾︽潫瓒婁弗锛屾墍浠ラ厤缃甋uppressWarnings("unchecked")
+public class DownloadFileCtrl {
+
+ @Autowired
+ private DownloadFileSv sv ;
+
+ @Autowired
+ private FileOperate fileOp ;
+
+ @Value("${dy.webFile.fmUrl}")
+ private String fmUrl ;
+
+
+ /**
+ * 閫氳繃web鏂囦欢鏁版嵁搴撳疄浣搃d涓嬭浇璇ユ枃浠�
+ * @param id
+ * @return
+ */
+ @GetMapping("/down")
+ public void down(String id, HttpServletRequest req, HttpServletResponse rep){
+ try{
+ WebFile fPo = sv.selectById(id) ;
+ if(fPo != null){
+ FileRestVo frVo = fileOp.parseHashcode(fmUrl, fPo.hash) ;
+ if(frVo.fileSysAbsolutePath != null){
+ if(!frVo.fileSysAbsolutePath.endsWith("\\\\") && !frVo.fileSysAbsolutePath.endsWith("/") ){
+ frVo.fileSysAbsolutePath = frVo.fileSysAbsolutePath + "/" ;
+ }
+ }
+ String filePath = frVo.fileSysAbsolutePath + fPo.filePath ;
+ File f = new File(filePath) ;
+ if(f.exists()){
+ String fileReName = fPo.orgName + "." + fPo.extName ;
+ //URLEncoder.encode鍙互闃叉涓枃涔辩爜
+ fileReName = URLEncoder.encode(fileReName, "UTF-8").replaceAll("\\+", "%20");
+ rep.addHeader("content-type", "application/octet-stream");
+ rep.addHeader("Content-Disposition", "attachment;fileName=" + fileReName);
+
+ ServletOutputStream out = null;
+ FileInputStream in = null ;
+ try {
+ out = rep.getOutputStream() ;
+ } catch (Exception ee) {
+ out = null ;
+ }finally{
+ if(out != null){
+ byte[] bs = new byte[1024] ;
+ int len = -1 ;
+ try {
+ in = new FileInputStream(f);
+ len = in.read(bs) ;
+ while(len != -1){
+ out.write(bs, 0, len);
+ len = in.read(bs) ;
+ }
+ } catch (Exception eee) {
+ } finally {
+ if(out != null){
+ try{
+ out.flush();
+ out.close();
+ }catch(Exception e){
+ }finally{
+ if(in != null){
+ try{
+ in.close();
+ }catch(Exception e){
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }else{
+ }
+ }else{
+ }
+ }catch (Exception e){
+ log.error("涓嬭浇鏂囦欢鏃跺紓甯�", e);
+ }
+
+ }
+}
--
Gitblit v1.8.0