Commit 3b97cf3f authored by 雍欢's avatar 雍欢

CommonController - 添加文件输出拦截器

parent 7d579520
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-common</artifactId> <artifactId>huigou-common</artifactId>
<name>huigou-common</name> <name>huigou-common</name>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-core-api</artifactId> <artifactId>huigou-core-api</artifactId>
<name>huigou-core-api</name> <name>huigou-core-api</name>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-core-impl</artifactId> <artifactId>huigou-core-impl</artifactId>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-core-proxy</artifactId> <artifactId>huigou-core-proxy</artifactId>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-data</artifactId> <artifactId>huigou-data</artifactId>
<name>huigou-data</name> <name>huigou-data</name>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-loader</artifactId> <artifactId>huigou-loader</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-system-common</artifactId> <artifactId>huigou-system-common</artifactId>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-uasp</artifactId> <artifactId>huigou-uasp</artifactId>
......
...@@ -24,6 +24,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; ...@@ -24,6 +24,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import com.huigou.cache.SystemCache; import com.huigou.cache.SystemCache;
...@@ -76,6 +77,8 @@ public class CommonController extends ControllerBase { ...@@ -76,6 +77,8 @@ public class CommonController extends ControllerBase {
protected final static String BIZ_CODE_KEY_NAME = "bizCode"; protected final static String BIZ_CODE_KEY_NAME = "bizCode";
protected final static String DATA_KEY_NAME = Constants.DATA; protected final static String DATA_KEY_NAME = Constants.DATA;
@Autowired(required = false)
private OutputFileInterceptor outputFileInterceptor;
protected enum Status { protected enum Status {
SUCCESS, SUCCESS_TIPS, ERROR, ERROR_DIALOG; SUCCESS, SUCCESS_TIPS, ERROR, ERROR_DIALOG;
...@@ -206,8 +209,7 @@ public class CommonController extends ControllerBase { ...@@ -206,8 +209,7 @@ public class CommonController extends ControllerBase {
* 跳转到页面,无需配置struts的result * 跳转到页面,无需配置struts的result
* *
* @param page * @param page
* @param obj * @param obj Map SDO POJO
* Map SDO POJO
* @return String * @return String
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -446,6 +448,7 @@ public class CommonController extends ControllerBase { ...@@ -446,6 +448,7 @@ public class CommonController extends ControllerBase {
* *
* @return String * @return String
* @author * @author
* @see OutputFileInterceptor
*/ */
protected String outputFile(File file, String type) throws Exception { protected String outputFile(File file, String type) throws Exception {
HttpServletResponse res = this.getResponse(); HttpServletResponse res = this.getResponse();
...@@ -458,6 +461,9 @@ public class CommonController extends ControllerBase { ...@@ -458,6 +461,9 @@ public class CommonController extends ControllerBase {
try { try {
out = res.getOutputStream(); out = res.getOutputStream();
bis = new BufferedInputStream(new FileInputStream(file)); bis = new BufferedInputStream(new FileInputStream(file));
if (outputFileInterceptor != null) {
bis = new BufferedInputStream(outputFileInterceptor.intercept(bis, type, this));
}
bos = new BufferedOutputStream(out); bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048]; byte[] buff = new byte[2048];
int bytesRead; int bytesRead;
...@@ -485,7 +491,7 @@ public class CommonController extends ControllerBase { ...@@ -485,7 +491,7 @@ public class CommonController extends ControllerBase {
*/ */
protected String outputPDF(String template, Map<String, Object> variables) { protected String outputPDF(String template, Map<String, Object> variables) {
String imgHttpUrl = this.getRequest().getScheme() + "://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort() String imgHttpUrl = this.getRequest().getScheme() + "://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort()
+ SystemCache.getContextPath(); + SystemCache.getContextPath();
variables.put("imgHttpUrl", imgHttpUrl); variables.put("imgHttpUrl", imgHttpUrl);
String path = PDFCreater.createByFreemarker(template, variables); String path = PDFCreater.createByFreemarker(template, variables);
File file = new File(FileHelper.getTmpdir(), path); File file = new File(FileHelper.getTmpdir(), path);
...@@ -503,18 +509,15 @@ public class CommonController extends ControllerBase { ...@@ -503,18 +509,15 @@ public class CommonController extends ControllerBase {
/** /**
* Freemarker模板生成PDF显示在网页上(包含审批流程) * Freemarker模板生成PDF显示在网页上(包含审批流程)
* *
* @param template * @param template Freemarker 模板
* Freemarker 模板 * @param bizId 业务单据ID
* @param bizId * @param variables 参数
* 业务单据ID
* @param variables
* 参数
* @return * @return
*/ */
public String outputAndProcUnitHandlerPDF(String template, String bizId, Map<String, Object> variables) { public String outputAndProcUnitHandlerPDF(String template, String bizId, Map<String, Object> variables) {
ProcUnitHandlerApplication application = SpringBeanFactory.getBean(this.getServletContext(), "procUnitHandlerApplication", ProcUnitHandlerApplication application = SpringBeanFactory.getBean(this.getServletContext(), "procUnitHandlerApplication",
ProcUnitHandlerApplication.class); ProcUnitHandlerApplication.class);
if (application != null && bizId != null) { if (application != null && bizId != null) {
List<Map<String, Object>> group = application.groupProcUnitHandlers(bizId, "Approve", "", "", "-1"); List<Map<String, Object>> group = application.groupProcUnitHandlers(bizId, "Approve", "", "", "-1");
Map<String, Object> a = new HashMap<String, Object>(2); Map<String, Object> a = new HashMap<String, Object>(2);
...@@ -535,7 +538,7 @@ public class CommonController extends ControllerBase { ...@@ -535,7 +538,7 @@ public class CommonController extends ControllerBase {
*/ */
protected String outputWord(String template, Map<String, Object> variables) { protected String outputWord(String template, Map<String, Object> variables) {
String imgHttpUrl = this.getRequest().getScheme() + "://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort() String imgHttpUrl = this.getRequest().getScheme() + "://" + this.getRequest().getServerName() + ":" + this.getRequest().getServerPort()
+ SystemCache.getContextPath(); + SystemCache.getContextPath();
variables.put("imgHttpUrl", imgHttpUrl); variables.put("imgHttpUrl", imgHttpUrl);
String path = PDFCreater.createWord(template, variables); String path = PDFCreater.createWord(template, variables);
File file = new File(FileHelper.getTmpdir(), path); File file = new File(FileHelper.getTmpdir(), path);
......
package com.huigou.uasp.client;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* 文件输出拦截器。
*
* @author yonghuan
* @see CommonController#outputFile(File, String)
* @since 1.1.1
*/
public interface OutputFileInterceptor {
/**
* 对文件输出进行拦截处理。
*
* @param is 文件内容
* @param type 文件类型
* @param target 被拦截的对象
* @return 拦截处理结果
* @throws IOException
*/
InputStream intercept(InputStream is, String type, Object target) throws IOException;
}
package com.huigou.uasp.client;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
/**
* @author yonghuan
* @since 1.1.1
*/
public class OutputFileInterceptorComposite implements OutputFileInterceptor {
private List<OutputFileInterceptor> delegationInterceptors;
public OutputFileInterceptorComposite(List<OutputFileInterceptor> delegationInterceptors) {
this.delegationInterceptors = Collections.unmodifiableList(delegationInterceptors);
}
@Override
public InputStream intercept(InputStream is, String type, Object target) throws IOException {
for (OutputFileInterceptor interceptor : delegationInterceptors) {
is = interceptor.intercept(is, type, target);
}
return is;
}
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<parent> <parent>
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
</parent> </parent>
<artifactId>huigou-xt</artifactId> <artifactId>huigou-xt</artifactId>
<name>统一应用支撑平台</name> <name>统一应用支撑平台</name>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<groupId>com.huigou</groupId> <groupId>com.huigou</groupId>
<artifactId>root</artifactId> <artifactId>root</artifactId>
<version>1.1.0</version> <version>1.1.1</version>
<packaging>pom</packaging> <packaging>pom</packaging>
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
<!-- test --> <!-- test -->
<junit.version>4.9</junit.version> <junit.version>4.9</junit.version>
<spring-data-mongodb.version>1.9.3.RELEASE</spring-data-mongodb.version> <spring-data-mongodb.version>1.9.3.RELEASE</spring-data-mongodb.version>
<huigou.uasp.version>1.1.0</huigou.uasp.version> <huigou.uasp.version>1.1.1</huigou.uasp.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment