|
@@ -2,28 +2,22 @@ package com.uas.platform.b2b.controller;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.dfs.service.FileClient;
|
|
import com.uas.dfs.service.FileClient;
|
|
|
-import com.uas.platform.b2b.dao.AttachDao;
|
|
|
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
|
import com.uas.platform.b2b.model.Attach;
|
|
import com.uas.platform.b2b.model.Attach;
|
|
|
-import com.uas.platform.b2b.model.PurchaseOrder;
|
|
|
|
|
import com.uas.platform.b2b.model.PurchaseOrderAll;
|
|
import com.uas.platform.b2b.model.PurchaseOrderAll;
|
|
|
-import com.uas.platform.b2b.model.PurchaseOrderAllItem;
|
|
|
|
|
import com.uas.platform.b2b.service.AttachService;
|
|
import com.uas.platform.b2b.service.AttachService;
|
|
|
import com.uas.platform.b2b.service.PurchaseOrderService;
|
|
import com.uas.platform.b2b.service.PurchaseOrderService;
|
|
|
-import com.uas.platform.b2b.support.HttpUtils;
|
|
|
|
|
-import com.uas.platform.b2b.temporary.model.FileUrl;
|
|
|
|
|
|
|
+import com.uas.platform.b2b.support.UsageBufferedLogger;
|
|
|
import com.uas.platform.core.exception.NotFoundException;
|
|
import com.uas.platform.core.exception.NotFoundException;
|
|
|
|
|
+import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.ui.ModelMap;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -48,24 +42,31 @@ public class FileController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private CommonDao commonDao;
|
|
private CommonDao commonDao;
|
|
|
|
|
|
|
|
|
|
+ private final static UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 文件下载
|
|
* 文件下载
|
|
|
*
|
|
*
|
|
|
- * @param fileId
|
|
|
|
|
- * @param response
|
|
|
|
|
|
|
+ * @param fileId attach中的文件id
|
|
|
|
|
+ * @param response http 返回值
|
|
|
* @throws IOException
|
|
* @throws IOException
|
|
|
*/
|
|
*/
|
|
|
@RequestMapping("/{fileId}")
|
|
@RequestMapping("/{fileId}")
|
|
|
public void download(@PathVariable("fileId") long fileId, HttpServletResponse response) throws IOException {
|
|
public void download(@PathVariable("fileId") long fileId, HttpServletResponse response) throws IOException {
|
|
|
Attach attach = attachService.getAttach(fileId);
|
|
Attach attach = attachService.getAttach(fileId);
|
|
|
- if(attach == null) throw new IllegalArgumentException("附件不存在");
|
|
|
|
|
- response.addHeader("Content-Disposition", "attachment;filename=" + new String(attach.getName().getBytes("utf-8"), "iso-8859-1"));
|
|
|
|
|
|
|
+ if(attach == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("附件不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ logger.log("附件下载", 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.setCharacterEncoding("utf-8");
|
|
|
response.setContentType("application/octec-stream");
|
|
response.setContentType("application/octec-stream");
|
|
|
String path = attach.getPath();
|
|
String path = attach.getPath();
|
|
|
if(path.startsWith("http://dfs.ubtob.com")) {// 存储在dfs存储服务器,去dfs存储服务器下载
|
|
if(path.startsWith("http://dfs.ubtob.com")) {// 存储在dfs存储服务器,去dfs存储服务器下载
|
|
|
byte[] fileBytes = fileClient.download(attach.getPath());
|
|
byte[] fileBytes = fileClient.download(attach.getPath());
|
|
|
- if (fileBytes.length <= 0) throw new IllegalArgumentException("附件不存在");
|
|
|
|
|
|
|
+ if (fileBytes.length <= 0) {
|
|
|
|
|
+ throw new IllegalArgumentException("附件不存在");
|
|
|
|
|
+ }
|
|
|
response.addHeader("Content-Length", String.valueOf(fileBytes.length));
|
|
response.addHeader("Content-Length", String.valueOf(fileBytes.length));
|
|
|
OutputStream os = response.getOutputStream();
|
|
OutputStream os = response.getOutputStream();
|
|
|
os.write(fileBytes);
|
|
os.write(fileBytes);
|
|
@@ -94,7 +95,11 @@ public class FileController {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 文件批量下载
|
|
* 文件批量下载
|
|
|
|
|
+ *
|
|
|
* @param id id是采购单的id,因为这里需要进行处理
|
|
* @param id id是采购单的id,因为这里需要进行处理
|
|
|
|
|
+ * @modify-author hejq
|
|
|
|
|
+ * @modify-date 2018-01-11 20:29
|
|
|
|
|
+ * @modify-desc 增加日志记录
|
|
|
*/
|
|
*/
|
|
|
@RequestMapping("/batch/{id}")
|
|
@RequestMapping("/batch/{id}")
|
|
|
public void batchDownload(@PathVariable("id") long id, HttpServletResponse response) throws IOException {
|
|
public void batchDownload(@PathVariable("id") long id, HttpServletResponse response) throws IOException {
|
|
@@ -105,6 +110,7 @@ public class FileController {
|
|
|
StringBuffer idString = null;
|
|
StringBuffer idString = null;
|
|
|
String url = null;
|
|
String url = null;
|
|
|
if (!CollectionUtils.isEmpty(attaches)) {
|
|
if (!CollectionUtils.isEmpty(attaches)) {
|
|
|
|
|
+ logger.log("附件下载", "采购单附件批量下载", "关联订单id: " + id);
|
|
|
for (Attach attach : attaches) {
|
|
for (Attach attach : attaches) {
|
|
|
if (attach.getPath().startsWith("http://dfs.ubtob.com")) {// 存储在dfs存储服务器,去dfs存储服务器下载
|
|
if (attach.getPath().startsWith("http://dfs.ubtob.com")) {// 存储在dfs存储服务器,去dfs存储服务器下载
|
|
|
// TODO dfs服务器上打包下载
|
|
// TODO dfs服务器上打包下载
|