Explorar el Código

亿道次元EIS 接口GetFeeReason 增加查询返回值:ct_varchar2000_2 附件ID,并且增加接口,根据附件ID下载附件

xiaost hace 9 meses
padre
commit
5b51ffcf8a

+ 35 - 0
src/main/java/com/uas/eis/controller/MESHelperController.java

@@ -1,13 +1,19 @@
 package com.uas.eis.controller;
 
+import com.uas.eis.core.support.FileUtil;
 import com.uas.eis.sdk.entity.ApiResult;
 import com.uas.eis.sdk.resp.ApiResponse;
 import com.uas.eis.service.MESHelperService;
+import net.sf.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 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;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -31,4 +37,33 @@ public class MESHelperController {
         return ApiResponse.successRsp(requestId,map);
     }
 
+    /**
+     * 附件下载
+    */
+    @RequestMapping("/downloadbyId.action")
+    public void downloadById(HttpServletResponse response, HttpServletRequest request) throws IOException, KeyManagementException, NoSuchAlgorithmException {
+        String id = request.getParameter("id");
+        String accessKey = request.getHeader("AccessKey");
+        String requestId = request.getHeader("RequestId");
+        JSONObject obj = mesHelperService.getFiles(accessKey,requestId,id).getJSONObject(0);
+        String path = obj.getString("fp_path");
+        String size = "0";
+        InputStream in = null;
+        File file = new File(path);
+        in = new FileInputStream(file);
+        size = String.valueOf(file.length());
+        OutputStream os = response.getOutputStream();
+        String fileName = obj.getString("fp_name");
+        response.addHeader("Content-Disposition", "attachment;filename=\""
+                + new String(fileName.getBytes("utf-8"), "iso-8859-1")+"\"");
+        response.addHeader("Content-Length", size);
+        response.setCharacterEncoding("utf-8");
+        response.setContentType(FileUtil.getContentType(fileName));
+        int data = 0;
+        while ((data = in.read()) != -1) {
+            os.write(data);
+        }
+        in.close();
+        os.close();
+    }
 }

+ 80 - 0
src/main/java/com/uas/eis/core/support/FileUtil.java

@@ -0,0 +1,80 @@
+package com.uas.eis.core.support;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+import java.util.Map;
+import java.util.UUID;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+public class FileUtil {
+
+
+    public static String getContentType(String fileName) {
+        if (null == fileName || "".equals(fileName)) {
+            return "application/octec-stream";
+        }
+        String ext = FilenameUtils.getExtension(fileName).toLowerCase();
+        String contentType = null;
+        switch (ext) {
+            case "pdf":
+                contentType = "application/pdf";
+                break;
+            case "xls":
+                contentType = "application/vnd.ms-excel";
+                break;
+            case "xlsx":
+                contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+                break;
+            case "doc":
+            case "dot":
+                contentType = "application/msword";
+                break;
+            case "docx":
+                contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+                break;
+            case "dotx":
+                contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
+                break;
+            case "ppt":
+            case "pot":
+            case "pps":
+            case "ppa":
+                contentType = "application/vnd.ms-powerpoint";
+                break;
+            case "pptx":
+                contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
+                break;
+            case "potx":
+                contentType = "application/vnd.openxmlformats-officedocument.presentationml.template";
+                break;
+            case "ppsx":
+                contentType = "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
+                break;
+            case "jpg":
+            case "png":
+            case "gif":
+                contentType = "image/*";
+                break;
+            case "avi":
+            case "mpg":
+            case "mpeg":
+            case "mp4":
+                contentType = "video/*";
+                break;
+            case "mp3":
+            case "wav":
+                contentType = "audio/*";
+                break;
+            default:
+                contentType = "application/octec-stream";
+                break;
+        }
+        return contentType;
+    }
+}

+ 5 - 0
src/main/java/com/uas/eis/service/MESHelperService.java

@@ -1,9 +1,14 @@
 package com.uas.eis.service;
 
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
 import java.util.List;
 import java.util.Map;
 
 public interface MESHelperService {
 
 	Map<Object, Object> DLLMain(String accessKey, String requestId, String data);
+
+	JSONArray getFiles(String accessKey, String requestId, String id);
 }

+ 28 - 1
src/main/java/com/uas/eis/serviceImpl/MESHelperServiceImpl.java

@@ -10,6 +10,7 @@ import com.uas.eis.sdk.entity.ApiResult;
 import com.uas.eis.service.MESDataService;
 import com.uas.eis.service.MESHelperService;
 import com.uas.eis.utils.*;
+import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import net.sf.json.JsonConfig;
 import org.apache.commons.lang.StringUtils;
@@ -144,6 +145,32 @@ public class MESHelperServiceImpl implements MESHelperService {
 		return remap;
 	}
 
+	@Override
+	public JSONArray getFiles(String accessKey, String requestId, String id) {
+		String AE_MASTER = checkAccessKey(accessKey, requestId);
+		accessKey1=accessKey;
+		SpObserver.putSp(AE_MASTER);
+		Master=AE_MASTER;
+		JSONArray arr = new JSONArray();
+		JSONObject obj = null;
+		for (String i : id.split(";")) {
+			if (i != null && !i.trim().equals("")) {
+				SqlRowList rs = baseDao.queryForRowSet("SELECT * FROM "+Master+".FilePath WHERE fp_id=" + i);
+				if(rs.next()){
+					JSONObject o = new JSONObject();
+					o.put("fp_id", i);
+					o.put("fp_path", rs.getString("fp_path"));
+					o.put("fp_size", rs.getInt("fp_size"));
+					o.put("fp_name", rs.getString("fp_name"));
+					o.put("fp_date", rs.getGeneralTimestamp("fp_date"));
+					o.put("fp_man", rs.getString("fp_man"));
+					arr.add(obj);
+				}
+			}
+		}
+		return arr;
+	}
+
 	private Map<Object,Object> GetMakeInfo(JSONObject map){
 		Map<Object, Object> rmap = new HashMap<Object, Object>();
 		String iSN=null;
@@ -251,7 +278,7 @@ public class MESHelperServiceImpl implements MESHelperService {
 			rmap.put("oErrMessage",oErrMessage);
 			return rmap;
 		}
-		SqlRowList rs=baseDao.queryForRowSet("select ct_code,ct_number_3,ct_varchar50_18,ct_varchar500_1,ct_varchar500_2,ct_varchar500_3,ct_varchar500_4,ct_varchar500_5,ct_number_2,ct_varchar50_27,ct_number_19,ct_varchar50_30,ct_varchar50_25,ct_number_12,ct_number_23,ct_varchar50_34,ct_varchar50_39,ct_varchar50_22,ct_statuscode,ct_date_1,ct_status,ct_recorder,ct_varchar50_10,ct_date_2,ct_id,ct_varchar50_1,ct_varchar50_2,ct_varchar50_3,ct_varchar50_4,ct_varchar50_5,ct_varchar50_6,ct_varchar50_7,ct_varchar50_8,ct_varchar50_11,ct_number_1,ct_varchar50_9,ct_varchar50_12,ct_varchar50_13,ct_varchar50_14,ct_varchar50_15,ct_varchar50_16,ct_caller,ct_date_3,ct_varchar50_17" +
+		SqlRowList rs=baseDao.queryForRowSet("select ct_code,ct_number_3,ct_varchar50_18,ct_varchar500_1,ct_varchar500_2,ct_varchar500_3,ct_varchar500_4,ct_varchar500_5,ct_number_2,ct_varchar50_27,ct_number_19,ct_varchar50_30,ct_varchar50_25,ct_number_12,ct_number_23,ct_varchar50_34,ct_varchar50_39,ct_varchar50_22,ct_statuscode,ct_date_1,ct_status,ct_recorder,ct_varchar50_10,ct_date_2,ct_id,ct_varchar50_1,ct_varchar50_2,ct_varchar50_3,ct_varchar50_4,ct_varchar50_5,ct_varchar50_6,ct_varchar50_7,ct_varchar50_8,ct_varchar50_11,ct_number_1,ct_varchar50_9,ct_varchar50_12,ct_varchar50_13,ct_varchar50_14,ct_varchar50_15,ct_varchar50_16,ct_caller,ct_date_3,ct_varchar50_17,ct_varchar2000_2" +
 				" from "+Master+".CUSTOMTABLE where ct_id="+map.get("CT_ID") +" and ct_caller='MakeFee'");
 		if(rs.next()){
 			for(String key:rs.getCurrentMap().keySet()){