Browse Source

增加访问公共域获取附件信息的方法

hejq 8 years ago
parent
commit
17dacbcb22

+ 7 - 7
src/main/java/com/uas/platform/b2b/controller/FileController.java

@@ -5,6 +5,7 @@ import com.uas.dfs.service.FileClient;
 import com.uas.platform.b2b.dao.CommonDao;
 import com.uas.platform.b2b.model.Attach;
 import com.uas.platform.b2b.model.PurchaseOrderAll;
+import com.uas.platform.b2b.ps.InquiryUtils;
 import com.uas.platform.b2b.service.AttachService;
 import com.uas.platform.b2b.service.PurchaseOrderService;
 import com.uas.platform.b2b.support.SystemSession;
@@ -43,8 +44,6 @@ public class FileController {
 	@Autowired
     private CommonDao commonDao;
 
-    private final static UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
-
 	/**
 	 * 文件下载
 	 * 
@@ -53,12 +52,14 @@ public class FileController {
 	 * @throws IOException
 	 */
 	@RequestMapping("/{fileId}")
-	public void download(@PathVariable("fileId") long fileId, HttpServletResponse response) throws IOException {
+	public void download(@PathVariable("fileId") long fileId, HttpServletResponse response) throws Exception {
 		Attach attach = attachService.getAttach(fileId);
-		if(attach == null) {
-            throw  new IllegalArgumentException("附件不存在");
+		if (attach == null) {
+		    attach = InquiryUtils.getAttach(fileId);
+		    if (attach == null) {
+                throw  new IllegalArgumentException("附件不存在");
+            }
         }
-        logger.log(SystemSession.getUser().getUserUU(), SystemSession.getUser().getEnterprise().getUu(), "附件下载", attach.getName() + "下载", "关联附件id: " + attach.getId());
         response.addHeader("Content-Disposition", "attachment;filename=" + new String(attach.getName().getBytes("utf-8"), "iso-8859-1"));
 		response.setCharacterEncoding("utf-8");
 		response.setContentType("application/octec-stream");
@@ -111,7 +112,6 @@ public class FileController {
         StringBuffer idString = null;
         String url = null;
         if (!CollectionUtils.isEmpty(attaches)) {
-            logger.log(SystemSession.getUser().getUserUU(), SystemSession.getUser().getEnterprise().getUu(),"附件下载", "采购单附件批量下载", "关联订单id: " + id);
            for (Attach attach : attaches) {
                if (attach.getPath().startsWith("http://dfs.ubtob.com")) {// 存储在dfs存储服务器,去dfs存储服务器下载
                 // TODO dfs服务器上打包下载

+ 19 - 0
src/main/java/com/uas/platform/b2b/ps/InquiryUtils.java

@@ -274,4 +274,23 @@ public class InquiryUtils {
         }
         return null;
     }
+
+    /**
+     * 获取存在公共域的附件
+     *
+     * @param id 获取的附件id
+     * @return
+     * @throws Exception
+     */
+    public static Attach getAttach(Long id) throws Exception {
+        HttpUtil.Response res = HttpUtil.sendGetRequest(url + "/inquiry/public/attachUrl?id=" + id, null);
+        if (res.getStatusCode() == 200) {
+            if (null != res.getResponseText()) {
+                return JSONObject.parseObject(res.getResponseText(), Attach.class);
+            }
+        } else {
+            throw new Exception("数据查询失败: " + res.getStatusCode());
+        }
+        return null;
+    }
 }