Browse Source

【PDA--品质报告,获取图片流,新接口】

xiaost 4 days ago
parent
commit
cc3eea803a
1 changed files with 47 additions and 0 deletions
  1. 47 0
      src/com/uas/mes/api/pdashop/controller/QualityController.java

+ 47 - 0
src/com/uas/mes/api/pdashop/controller/QualityController.java

@@ -1,7 +1,9 @@
 package com.uas.mes.api.pdashop.controller;
 
 import com.uas.erp.core.BaseUtil;
+import com.uas.erp.core.HttpUtil;
 import com.uas.erp.core.exception.APIErrorException;
+import com.uas.erp.core.support.SystemSession;
 import com.uas.erp.model.Employee;
 import com.uas.mes.api.core.BaseApiController;
 import com.uas.mes.api.pdashop.service.QualityService;
@@ -13,6 +15,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
 
 /**
  * 品质检验,首件,巡检等
@@ -110,5 +116,46 @@ public class QualityController  extends BaseApiController {
         return success(qualityService.fuzzySearchSampleReport(condition,page,pageSize));
     }
 
+    @RequestMapping("/download.action")
+    public void download(HttpServletResponse response, HttpServletRequest request, String fileName) throws IOException, KeyManagementException, NoSuchAlgorithmException {
+        String path = request.getParameter("path");
+        String escape = request.getParameter("escape");
+        String size = request.getParameter("size");
+        if (!"1".equals(escape)) {
+            path = new String(path.getBytes("iso-8859-1"), "utf-8");
+        }
+        InputStream in = null;
+        File file = null;
+        if (path.startsWith("http:")||path.startsWith("https:")) {
+            in = HttpUtil.download(path);
+        }else if (path.startsWith("ftp:") || path.startsWith("sftp:")) {
+            // 存放在其他网络资源中,直接跳转至链接地址
+            response.sendRedirect(path);
+            return;
+        }else if (path.startsWith("B2B://")) {// 文件在云平台
+            path = SystemSession.getUser().getCurrentMaster().getMa_b2bwebsite() + "/" + path.substring(6);
+            in = HttpUtil.download(path);
+        } else {
+            file = new File(path);
+            in = new FileInputStream(file);
+        }
+        if (size==null) {
+            size = String.valueOf(file.length());
+        }
+        OutputStream os = response.getOutputStream();
+        if (fileName == null && file != null)
+            fileName = new String(file.getName().getBytes("utf-8"), "iso-8859-1");
+        fileName = fileName.replace(",", " ");
+        response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
+        response.addHeader("Content-Length", size);
+        response.setCharacterEncoding("iso-8859-1");
+        response.setContentType("application/octec-stream");
+        int data = 0;
+        while ((data = in.read()) != -1) {
+            os.write(data);
+        }
+        in.close();
+        os.close();
+    }
 
 }