deason 3 år sedan
förälder
incheckning
00c7629f84

+ 20 - 20
examcloud-commons/src/main/java/cn/com/qmth/examcloud/commons/util/Calculator.java

@@ -11,31 +11,31 @@ import java.math.BigDecimal;
  */
 public class Calculator {
 
-	public static double add(double v1, double v2) {
-		BigDecimal b1 = new BigDecimal(Double.toString(v1));
-		BigDecimal b2 = new BigDecimal(Double.toString(v2));
-		return b1.add(b2).doubleValue();
+    public static double add(double v1, double v2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
+        return b1.add(b2).doubleValue();
 
-	}
+    }
 
-	public static double subtract(double v1, double v2) {
-		BigDecimal b1 = new BigDecimal(Double.toString(v1));
-		BigDecimal b2 = new BigDecimal(Double.toString(v2));
-		return b1.subtract(b2).doubleValue();
+    public static double subtract(double v1, double v2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(v1));
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
+        return b1.subtract(b2).doubleValue();
 
-	}
+    }
 
-	public static double multiply(double v1, double v2) {
-		BigDecimal b1 = new BigDecimal(v1);
-		BigDecimal b2 = new BigDecimal(v2);
-		return b1.multiply(b2).doubleValue();
+    public static double multiply(double v1, double v2) {
+        BigDecimal b1 = BigDecimal.valueOf(v1);
+        BigDecimal b2 = BigDecimal.valueOf(v2);
+        return b1.multiply(b2).doubleValue();
 
-	}
+    }
 
-	public static double divide(double v1, double v2, int len) {
-		BigDecimal b1 = new BigDecimal(v1);
-		BigDecimal b2 = new BigDecimal(v2);
-		return b1.divide(b2, len, BigDecimal.ROUND_HALF_UP).doubleValue();
-	}
+    public static double divide(double v1, double v2, int len) {
+        BigDecimal b1 = BigDecimal.valueOf(v1);
+        BigDecimal b2 = BigDecimal.valueOf(v2);
+        return b1.divide(b2, len, BigDecimal.ROUND_HALF_UP).doubleValue();
+    }
 
 }

+ 294 - 291
examcloud-commons/src/main/java/cn/com/qmth/examcloud/commons/util/OKHttpUtil.java

@@ -1,25 +1,18 @@
 package cn.com.qmth.examcloud.commons.util;
 
+import cn.com.qmth.examcloud.commons.helpers.FormFilePart;
+import okhttp3.*;
+import okhttp3.Request.Builder;
+import org.apache.commons.collections.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.commons.collections.CollectionUtils;
-
-import cn.com.qmth.examcloud.commons.helpers.FormFilePart;
-import okhttp3.FormBody;
-import okhttp3.MediaType;
-import okhttp3.MultipartBody;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Request.Builder;
-import okhttp3.RequestBody;
-import okhttp3.Response;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * OKHttp
  *
@@ -29,282 +22,292 @@ import org.slf4j.LoggerFactory;
  */
 public class OKHttpUtil {
 
-	private static final Logger LOG = LoggerFactory.getLogger(OKHttpUtil.class);
-
-	public static final class MediaTypes {
-
-		public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
-	}
-
-	/**
-	 * 请求体构建器
-	 *
-	 * @author WANGWEI
-	 * @date 2019年4月10日
-	 * @Copyright (c) 2018-2020 http://www.qmth.com.cn/ All Rights Reserved.
-	 */
-	public static interface RequestBodyBuilder {
-		RequestBody build();
-	}
-
-	/**
-	 * json请求体构建器
-	 *
-	 * @author WANGWEI
-	 * @date 2019年4月10日
-	 * @Copyright (c) 2018-2020 http://www.qmth.com.cn/ All Rights Reserved.
-	 */
-	public static final class JsonBodyBuilder implements RequestBodyBuilder {
-
-		private String json;
-
-		public JsonBodyBuilder(String json) {
-			super();
-			this.json = json;
-		}
-
-		@Override
-		public RequestBody build() {
-			return RequestBody.create(MediaTypes.JSON, json);
-		}
-
-		@Override
-		public String toString() {
-			return json;
-		}
-	}
-
-	private static OkHttpClient okHttpClient;
-
-	static {
-		okHttpClient = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS)
-				.readTimeout(20, TimeUnit.SECONDS).build();
-	}
-
-	public static OkHttpClient getOkHttpClient() {
-		return okHttpClient;
-	}
-
-	/**
-	 * 发送请求 (带json请求体)
-	 *
-	 * @author WANGWEI
-	 * @param httpMethod
-	 * @param url
-	 * @param headers
-	 * @param jsonBody
-	 * @return
-	 */
-	public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
-								String jsonBody) {
-		return call(httpMethod, url, headers, new JsonBodyBuilder(jsonBody));
-	}
-
-	/**
-	 * 发送请求 (带请求体)
-	 *
-	 * @author WANGWEI
-	 * @param httpMethod
-	 * @param url
-	 * @param headers
-	 * @param requestBodyBuilder
-	 * @return
-	 */
-	public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
-								RequestBodyBuilder requestBodyBuilder) {
-
-		LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
-		LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
-		LOG.info("[okhttp3] body: " + requestBodyBuilder);
-
-		Builder builder = null;
-		if (httpMethod.equals(HttpMethod.GET)) {
-			builder = new Request.Builder().url(url).get();
-		} else if (httpMethod.equals(HttpMethod.POST)) {
-			builder = new Request.Builder().url(url).post(requestBodyBuilder.build());
-		} else if (httpMethod.equals(HttpMethod.PUT)) {
-			builder = new Request.Builder().url(url).put(requestBodyBuilder.build());
-		} else if (httpMethod.equals(HttpMethod.DELETE)) {
-			builder = new Request.Builder().url(url).delete(requestBodyBuilder.build());
-		}
-
-		if (null != headers && 0 != headers.size()) {
-			for (Entry<String, String> entry : headers.entrySet()) {
-				builder.addHeader(entry.getKey(), entry.getValue());
-			}
-		}
-
-		Request request = builder.build();
-
-		Response response = null;
-		try {
-			response = okHttpClient.newCall(request).execute();
-			return response;
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	/**
-	 * 发送请求
-	 *
-	 * @author WANGWEI
-	 * @param httpMethod
-	 * @param url
-	 * @return
-	 */
-	public static Response call(HttpMethod httpMethod, String url) {
-		return call(httpMethod, url, null);
-	}
-
-	/**
-	 * 发送请求
-	 *
-	 * @author WANGWEI
-	 * @param httpMethod
-	 * @param url
-	 * @param headers
-	 * @return
-	 */
-	public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers) {
-
-		LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
-		LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
-
-		Builder builder = null;
-		if (httpMethod.equals(HttpMethod.GET)) {
-			builder = new Request.Builder().url(url).get();
-		} else if (httpMethod.equals(HttpMethod.POST)) {
-			builder = new Request.Builder().url(url).post(new FormBody.Builder().build());
-		} else if (httpMethod.equals(HttpMethod.PUT)) {
-			builder = new Request.Builder().url(url).put(new FormBody.Builder().build());
-		} else if (httpMethod.equals(HttpMethod.DELETE)) {
-			builder = new Request.Builder().url(url).delete(new FormBody.Builder().build());
-		}
-
-		if (null != headers && 0 != headers.size()) {
-			for (Entry<String, String> entry : headers.entrySet()) {
-				builder.addHeader(entry.getKey(), entry.getValue());
-			}
-		}
-
-		Request request = builder.build();
-
-		Response response = null;
-		try {
-			response = okHttpClient.newCall(request).execute();
-			return response;
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	/**
-	 * 发送请求 (表单)
-	 *
-	 * @author WANGWEI
-	 * @param httpMethod
-	 * @param url
-	 * @param headers
-	 * @param params
-	 * @return
-	 */
-	public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
-								Map<String, String> params) {
-
-		LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
-		LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
-		LOG.info("[okhttp3] params: " + JsonUtil.toJson(params));
-
-		Builder builder = null;
-		if (httpMethod.equals(HttpMethod.GET)) {
-			url = UrlUtil.joinParams(url, params);
-			builder = new Request.Builder().url(url).get();
-		} else {
-			okhttp3.FormBody.Builder formBody = new FormBody.Builder();
-			if (null != params && 0 != params.size()) {
-				for (Entry<String, String> entry : params.entrySet()) {
-					formBody.add(entry.getKey(), entry.getValue());
-				}
-			}
-			if (httpMethod.equals(HttpMethod.POST)) {
-				builder = new Request.Builder().url(url).post(formBody.build());
-			} else if (httpMethod.equals(HttpMethod.PUT)) {
-				builder = new Request.Builder().url(url).put(formBody.build());
-			} else if (httpMethod.equals(HttpMethod.DELETE)) {
-				builder = new Request.Builder().url(url).delete(formBody.build());
-			}
-		}
-
-		if (null != headers && 0 != headers.size()) {
-			for (Entry<String, String> entry : headers.entrySet()) {
-				builder.addHeader(entry.getKey(), entry.getValue());
-			}
-		}
-
-		Request request = builder.build();
-
-		Response response = null;
-		try {
-			response = okHttpClient.newCall(request).execute();
-			return response;
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	/**
-	 * 发送请求 (包含文件表单)
-	 *
-	 * @author WANGWEI
-	 * @param httpMethod
-	 * @param url
-	 * @param headers
-	 * @param params
-	 * @param formFilePartList
-	 * @return
-	 */
-	public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
-								Map<String, String> params, List<FormFilePart> formFilePartList) {
-
-		LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
-		LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
-		LOG.info("[okhttp3] params: " + JsonUtil.toJson(params));
-
-		okhttp3.MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder()
-				.setType(MultipartBody.ALTERNATIVE);
-
-		if (null != params) {
-			for (Entry<String, String> entry : params.entrySet()) {
-				multipartBodyBuilder.addFormDataPart(entry.getKey(), entry.getValue());
-			}
-		}
-
-		if (CollectionUtils.isNotEmpty(formFilePartList)) {
-			MediaType type = MediaType.parse("application/octet-stream");
-			for (FormFilePart part : formFilePartList) {
-				RequestBody fileBody = RequestBody.create(type, part.getFile());
-				multipartBodyBuilder.addFormDataPart(part.getParamName(), part.getFilename(),
-						fileBody);
-			}
-		}
-
-		Builder builder = new Request.Builder().url(url).post(multipartBodyBuilder.build());
-		if (null != headers && 0 != headers.size()) {
-			for (Entry<String, String> entry : headers.entrySet()) {
-				builder.addHeader(entry.getKey(), entry.getValue());
-			}
-		}
-
-		Request request = builder.build();
-
-		Response response = null;
-		try {
-			response = okHttpClient.newCall(request).execute();
-			return response;
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-	}
+    private static final Logger LOG = LoggerFactory.getLogger(OKHttpUtil.class);
+
+    public static final class MediaTypes {
+
+        public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
+
+    }
+
+    /**
+     * 请求体构建器
+     *
+     * @author WANGWEI
+     * @date 2019年4月10日
+     * @Copyright (c) 2018-2020 http://www.qmth.com.cn/ All Rights Reserved.
+     */
+    public static interface RequestBodyBuilder {
+
+        RequestBody build();
+
+    }
+
+    /**
+     * json请求体构建器
+     *
+     * @author WANGWEI
+     * @date 2019年4月10日
+     * @Copyright (c) 2018-2020 http://www.qmth.com.cn/ All Rights Reserved.
+     */
+    public static final class JsonBodyBuilder implements RequestBodyBuilder {
+
+        private String json;
+
+        public JsonBodyBuilder(String json) {
+            super();
+            this.json = json;
+        }
+
+        @Override
+        public RequestBody build() {
+            return RequestBody.create(MediaTypes.JSON, json);
+        }
+
+        @Override
+        public String toString() {
+            return json;
+        }
+
+    }
+
+    private static OkHttpClient okHttpClient;
+
+    static {
+        okHttpClient = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS)
+                .readTimeout(20, TimeUnit.SECONDS).build();
+    }
+
+    public static OkHttpClient getOkHttpClient() {
+        return okHttpClient;
+    }
+
+    /**
+     * 发送请求 (带json请求体)
+     *
+     * @param httpMethod
+     * @param url
+     * @param headers
+     * @param jsonBody
+     * @return
+     * @author WANGWEI
+     */
+    public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
+                                String jsonBody) {
+        return call(httpMethod, url, headers, new JsonBodyBuilder(jsonBody));
+    }
+
+    /**
+     * 发送请求 (带请求体)
+     *
+     * @param httpMethod
+     * @param url
+     * @param headers
+     * @param requestBodyBuilder
+     * @return
+     * @author WANGWEI
+     */
+    public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
+                                RequestBodyBuilder requestBodyBuilder) {
+
+        LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
+        LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
+        LOG.info("[okhttp3] body: " + requestBodyBuilder);
+
+        Builder builder;
+        if (httpMethod.equals(HttpMethod.GET)) {
+            builder = new Request.Builder().url(url).get();
+        } else if (httpMethod.equals(HttpMethod.POST)) {
+            builder = new Request.Builder().url(url).post(requestBodyBuilder.build());
+        } else if (httpMethod.equals(HttpMethod.PUT)) {
+            builder = new Request.Builder().url(url).put(requestBodyBuilder.build());
+        } else if (httpMethod.equals(HttpMethod.DELETE)) {
+            builder = new Request.Builder().url(url).delete(requestBodyBuilder.build());
+        } else {
+            builder = new Request.Builder().url(url);
+        }
+
+        if (null != headers && 0 != headers.size()) {
+            for (Entry<String, String> entry : headers.entrySet()) {
+                builder.addHeader(entry.getKey(), entry.getValue());
+            }
+        }
+
+        Request request = builder.build();
+
+        Response response = null;
+        try {
+            response = okHttpClient.newCall(request).execute();
+            return response;
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * 发送请求
+     *
+     * @param httpMethod
+     * @param url
+     * @return
+     * @author WANGWEI
+     */
+    public static Response call(HttpMethod httpMethod, String url) {
+        return call(httpMethod, url, null);
+    }
+
+    /**
+     * 发送请求
+     *
+     * @param httpMethod
+     * @param url
+     * @param headers
+     * @return
+     * @author WANGWEI
+     */
+    public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers) {
+
+        LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
+        LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
+
+        Builder builder;
+        if (httpMethod.equals(HttpMethod.GET)) {
+            builder = new Request.Builder().url(url).get();
+        } else if (httpMethod.equals(HttpMethod.POST)) {
+            builder = new Request.Builder().url(url).post(new FormBody.Builder().build());
+        } else if (httpMethod.equals(HttpMethod.PUT)) {
+            builder = new Request.Builder().url(url).put(new FormBody.Builder().build());
+        } else if (httpMethod.equals(HttpMethod.DELETE)) {
+            builder = new Request.Builder().url(url).delete(new FormBody.Builder().build());
+        } else {
+            builder = new Request.Builder().url(url);
+        }
+
+        if (null != headers && 0 != headers.size()) {
+            for (Entry<String, String> entry : headers.entrySet()) {
+                builder.addHeader(entry.getKey(), entry.getValue());
+            }
+        }
+
+        Request request = builder.build();
+
+        Response response = null;
+        try {
+            response = okHttpClient.newCall(request).execute();
+            return response;
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * 发送请求 (表单)
+     *
+     * @param httpMethod
+     * @param url
+     * @param headers
+     * @param params
+     * @return
+     * @author WANGWEI
+     */
+    public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
+                                Map<String, String> params) {
+
+        LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
+        LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
+        LOG.info("[okhttp3] params: " + JsonUtil.toJson(params));
+
+        Builder builder;
+        if (httpMethod.equals(HttpMethod.GET)) {
+            url = UrlUtil.joinParams(url, params);
+            builder = new Request.Builder().url(url).get();
+        } else {
+            okhttp3.FormBody.Builder formBody = new FormBody.Builder();
+            if (null != params && 0 != params.size()) {
+                for (Entry<String, String> entry : params.entrySet()) {
+                    formBody.add(entry.getKey(), entry.getValue());
+                }
+            }
+            if (httpMethod.equals(HttpMethod.POST)) {
+                builder = new Request.Builder().url(url).post(formBody.build());
+            } else if (httpMethod.equals(HttpMethod.PUT)) {
+                builder = new Request.Builder().url(url).put(formBody.build());
+            } else if (httpMethod.equals(HttpMethod.DELETE)) {
+                builder = new Request.Builder().url(url).delete(formBody.build());
+            } else {
+                builder = new Request.Builder().url(url);
+            }
+        }
+
+        if (null != headers && 0 != headers.size()) {
+            for (Entry<String, String> entry : headers.entrySet()) {
+                builder.addHeader(entry.getKey(), entry.getValue());
+            }
+        }
+
+        Request request = builder.build();
+
+        Response response = null;
+        try {
+            response = okHttpClient.newCall(request).execute();
+            return response;
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * 发送请求 (包含文件表单)
+     *
+     * @param httpMethod
+     * @param url
+     * @param headers
+     * @param params
+     * @param formFilePartList
+     * @return
+     * @author WANGWEI
+     */
+    public static Response call(HttpMethod httpMethod, String url, Map<String, String> headers,
+                                Map<String, String> params, List<FormFilePart> formFilePartList) {
+
+        LOG.info("[okhttp3] new call: " + httpMethod + " " + url);
+        LOG.info("[okhttp3] headers: " + JsonUtil.toJson(headers));
+        LOG.info("[okhttp3] params: " + JsonUtil.toJson(params));
+
+        okhttp3.MultipartBody.Builder multipartBodyBuilder = new MultipartBody.Builder()
+                .setType(MultipartBody.ALTERNATIVE);
+
+        if (null != params) {
+            for (Entry<String, String> entry : params.entrySet()) {
+                multipartBodyBuilder.addFormDataPart(entry.getKey(), entry.getValue());
+            }
+        }
+
+        if (CollectionUtils.isNotEmpty(formFilePartList)) {
+            MediaType type = MediaType.parse("application/octet-stream");
+            for (FormFilePart part : formFilePartList) {
+                RequestBody fileBody = RequestBody.create(type, part.getFile());
+                multipartBodyBuilder.addFormDataPart(part.getParamName(), part.getFilename(),
+                        fileBody);
+            }
+        }
+
+        Builder builder = new Request.Builder().url(url).post(multipartBodyBuilder.build());
+        if (null != headers && 0 != headers.size()) {
+            for (Entry<String, String> entry : headers.entrySet()) {
+                builder.addHeader(entry.getKey(), entry.getValue());
+            }
+        }
+
+        Request request = builder.build();
+
+        Response response = null;
+        try {
+            response = okHttpClient.newCall(request).execute();
+            return response;
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
 
 }

+ 251 - 250
examcloud-support/src/main/java/cn/com/qmth/examcloud/support/excel/ExcelExportUtil.java

@@ -1,339 +1,340 @@
 package cn.com.qmth.examcloud.support.excel;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
+import cn.com.qmth.examcloud.commons.util.UUID;
+import cn.com.qmth.examcloud.support.util.FileDisposeUtil;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringEscapeUtils;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringEscapeUtils;
-
-import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
-import cn.com.qmth.examcloud.commons.util.UUID;
-import cn.com.qmth.examcloud.support.util.FileDisposeUtil;
+import java.util.*;
 
 /*
  * excel导出工具
  */
 public class ExcelExportUtil {
-	
 
-	private static final String TEMP_FILE_EXP = "excelExport/";
-	
-	private static final String DEFALUT_CONTENT_TYPE = "application/vnd.ms-excel";
 
-	private static final String DEFALUT_EXT = ".xlsx";
+    private static final String TEMP_FILE_EXP = "excelExport/";
 
-	private static final String ZIP_SUFFIX = ".zip";
+    private static final String DEFALUT_CONTENT_TYPE = "application/vnd.ms-excel";
 
+    private static final String DEFALUT_EXT = ".xlsx";
 
-	public static void exportExcel(String fileName, Class<?> dataClass, List<?> dataset,
-			HttpServletResponse response) throws Exception {
-		File directory = new File(TEMP_FILE_EXP + File.separator + UUID.randomUUID());
-		ServletOutputStream outputStream = null;
-		InputStream in=null;
-		try {
-			response.setHeader("Content-Disposition",
-					"inline;filename=" + URLEncoder.encode(fileName, "UTF-8") + DEFALUT_EXT);
-			response.setContentType(DEFALUT_CONTENT_TYPE);
-			outputStream=response.getOutputStream();
-			File file=createExcelFile(UUID.randomUUID(), dataClass, dataset, directory);
-			in=new FileInputStream(file);
-			int len=0;
-			byte[] buffer=new byte[1024];
-			while((len=in.read(buffer))>0){
-				outputStream.write(buffer,0,len);
-			}
-		}finally {
-			if(in!=null)in.close();
-			if(outputStream!=null)outputStream.close();
-			FileUtils.deleteDirectory(directory);
-		}
-	}
-	
-	public static void exportExcel(Class<?> dataClass, List<?> dataset,OutputStream outputStream) throws Exception {
-		File directory = new File(TEMP_FILE_EXP + File.separator + UUID.randomUUID());
-		InputStream in=null;
-		try {
-			File file=createExcelFile(UUID.randomUUID(), dataClass, dataset, directory);
-			in=new FileInputStream(file);
-			int len=0;
-			byte[] buffer=new byte[1024];
-			while((len=in.read(buffer))>0){
-				outputStream.write(buffer,0,len);
-			}
-		}finally {
-			if(in!=null)in.close();
-			if(outputStream!=null)outputStream.close();
-			FileUtils.deleteDirectory(directory);
-		}
-	}
+    private static final String ZIP_SUFFIX = ".zip";
 
 
-	private static File createExcelFile(String fileName,Class<?> dataClass, List<?> dataset, File directory) throws Exception{
-		File excelTargetDir = new File(directory.getAbsolutePath() + "/excel/");
-		File exceloriginalZip=new File(directory.getAbsolutePath() + "/excel/exceloriginal.zip");
-		File excelfile=null;
-		try {
-			excelTargetDir.mkdirs();
-			exceloriginalZip.createNewFile();
-			InputStream is=ExcelExportUtil.class.getClass().getResourceAsStream("/exceloriginal/exceloriginal.zip");
-			FileUtils.copyInputStreamToFile(is, exceloriginalZip);
-			FileDisposeUtil.unZip(excelTargetDir, exceloriginalZip);
-			exceloriginalZip.delete();
-			dispose(excelTargetDir, dataClass,dataset);
-			File zipfile = new File(
-					excelTargetDir.getParentFile().getAbsolutePath() + File.separator + fileName + ZIP_SUFFIX);
-			FileDisposeUtil.createZip(excelTargetDir.getAbsolutePath(), zipfile.getAbsolutePath());
-			excelfile = new File(
-					excelTargetDir.getParentFile().getAbsolutePath() + File.separator + fileName + DEFALUT_EXT);
-			zipfile.renameTo(excelfile);
-		}finally {
-//			try {
-//				FileUtils.deleteDirectory(excelTargetDir);
-//			} catch (IOException e) {
-//			}
-		}
-		return excelfile;
+    public static void exportExcel(String fileName, Class<?> dataClass, List<?> dataset,
+                                   HttpServletResponse response) throws Exception {
+        File directory = new File(TEMP_FILE_EXP + File.separator + UUID.randomUUID());
+        ServletOutputStream outputStream = null;
+        InputStream in = null;
+        try {
+            response.setHeader("Content-Disposition",
+                    "inline;filename=" + URLEncoder.encode(fileName, "UTF-8") + DEFALUT_EXT);
+            response.setContentType(DEFALUT_CONTENT_TYPE);
+            outputStream = response.getOutputStream();
+            File file = createExcelFile(UUID.randomUUID(), dataClass, dataset, directory);
+            in = new FileInputStream(file);
+            int len = 0;
+            byte[] buffer = new byte[1024];
+            while ((len = in.read(buffer)) > 0) {
+                outputStream.write(buffer, 0, len);
+            }
+        } finally {
+            if (in != null) in.close();
+            if (outputStream != null) outputStream.close();
+            FileUtils.deleteDirectory(directory);
+        }
+    }
 
-	}
+    public static void exportExcel(Class<?> dataClass, List<?> dataset, OutputStream outputStream) throws Exception {
+        File directory = new File(TEMP_FILE_EXP + File.separator + UUID.randomUUID());
+        InputStream in = null;
+        try {
+            File file = createExcelFile(UUID.randomUUID(), dataClass, dataset, directory);
+            in = new FileInputStream(file);
+            int len = 0;
+            byte[] buffer = new byte[1024];
+            while ((len = in.read(buffer)) > 0) {
+                outputStream.write(buffer, 0, len);
+            }
+        } finally {
+            if (in != null) in.close();
+            if (outputStream != null) outputStream.close();
+            FileUtils.deleteDirectory(directory);
+        }
+    }
 
-	private static void dispose(File excelTargetDir, Class<?> dataClass, List<?> dataset)
-			throws IOException, NoSuchMethodException, SecurityException,
-			IllegalAccessException, IllegalArgumentException, InvocationTargetException {
-		//excel列名A B C AA AB
-		List<String> colName=new ArrayList<String>();
-		//单元格值
-		Map<String,Integer> vmap=new LinkedHashMap<String, Integer>();
-		int vmapSize=0;
-		ExcelSheet sheet=new ExcelSheet();
-		int index = 1;//第一行开始
-		//处理头
-		List<ColumnSetting> columnSettings = getColumnSettings(dataClass);
-		ExcelRow headrow=new ExcelRow();
-		headrow.setR(String.valueOf(index));
-		for(int i=0;i<columnSettings.size();i++) {
-			colName.add(getExcelColumnName(i));
-			ExcelCell cell=new ExcelCell();
-			cell.setR(colName.get(i)+index);
-			cell.setS("1");
-			Integer cellV=vmap.get(columnSettings.get(i).getHeader());
-			if(cellV==null) {
-				vmapSize++;
-				cellV=vmapSize;
-				vmap.put(columnSettings.get(i).getHeader(), cellV);
-			}
-			cell.setV(cellV.toString());
-			headrow.addCell(cell);
-		}
-		colName.add(getExcelColumnName(colName.size()));
-		sheet.addRow(headrow);
-		sheet.setDimension(colName.get(0)+1+":"+colName.get(colName.size()-1)+(dataset.size()+1));
-		File sheetFile=writeSheetHead(excelTargetDir, sheet, columnSettings);
-		//处理数据
-		for(int k=0;k<dataset.size();k++) {
-			index++;
-        	Object obj=dataset.get(k);
-            ExcelRow row=new ExcelRow();
+
+    private static File createExcelFile(String fileName, Class<?> dataClass, List<?> dataset, File directory) throws Exception {
+        File excelTargetDir = new File(directory.getAbsolutePath() + "/excel/");
+        File exceloriginalZip = new File(directory.getAbsolutePath() + "/excel/exceloriginal.zip");
+        File excelfile = null;
+        try {
+            excelTargetDir.mkdirs();
+            exceloriginalZip.createNewFile();
+            InputStream is = ExcelExportUtil.class.getClass().getResourceAsStream("/exceloriginal/exceloriginal.zip");
+            FileUtils.copyInputStreamToFile(is, exceloriginalZip);
+            FileDisposeUtil.unZip(excelTargetDir, exceloriginalZip);
+            exceloriginalZip.delete();
+            dispose(excelTargetDir, dataClass, dataset);
+            File zipfile = new File(
+                    excelTargetDir.getParentFile().getAbsolutePath() + File.separator + fileName + ZIP_SUFFIX);
+            FileDisposeUtil.createZip(excelTargetDir.getAbsolutePath(), zipfile.getAbsolutePath());
+            excelfile = new File(
+                    excelTargetDir.getParentFile().getAbsolutePath() + File.separator + fileName + DEFALUT_EXT);
+            zipfile.renameTo(excelfile);
+        } finally {
+            //			try {
+            //				FileUtils.deleteDirectory(excelTargetDir);
+            //			} catch (IOException e) {
+            //			}
+        }
+        return excelfile;
+
+    }
+
+    private static void dispose(File excelTargetDir, Class<?> dataClass, List<?> dataset)
+            throws IOException, NoSuchMethodException, SecurityException,
+            IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+        //excel列名A B C AA AB
+        List<String> colName = new ArrayList<String>();
+        //单元格值
+        Map<String, Integer> vmap = new LinkedHashMap<String, Integer>();
+        int vmapSize = 0;
+        ExcelSheet sheet = new ExcelSheet();
+        int index = 1;//第一行开始
+        //处理头
+        List<ColumnSetting> columnSettings = getColumnSettings(dataClass);
+        ExcelRow headrow = new ExcelRow();
+        headrow.setR(String.valueOf(index));
+        for (int i = 0; i < columnSettings.size(); i++) {
+            colName.add(getExcelColumnName(i));
+            ExcelCell cell = new ExcelCell();
+            cell.setR(colName.get(i) + index);
+            cell.setS("1");
+            Integer cellV = vmap.get(columnSettings.get(i).getHeader());
+            if (cellV == null) {
+                vmapSize++;
+                cellV = vmapSize;
+                vmap.put(columnSettings.get(i).getHeader(), cellV);
+            }
+            cell.setV(cellV.toString());
+            headrow.addCell(cell);
+        }
+        colName.add(getExcelColumnName(colName.size()));
+        sheet.addRow(headrow);
+        sheet.setDimension(colName.get(0) + 1 + ":" + colName.get(colName.size() - 1) + (dataset.size() + 1));
+        File sheetFile = writeSheetHead(excelTargetDir, sheet, columnSettings);
+        //处理数据
+        for (int k = 0; k < dataset.size(); k++) {
+            index++;
+            Object obj = dataset.get(k);
+            ExcelRow row = new ExcelRow();
             row.setR(String.valueOf(index));
             // 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
             for (short i = 0; i < columnSettings.size(); i++) {
                 String methodName = columnSettings.get(i).getGetMethodName();
                 Method method = dataClass.getMethod(methodName, new Class[]{});
-                Object value = method.invoke(obj, new Object[] {});
-                ExcelCell cell=new ExcelCell();
-                cell.setR(colName.get(i)+index);
+                Object value = method.invoke(obj, new Object[]{});
+                ExcelCell cell = new ExcelCell();
+                cell.setR(colName.get(i) + index);
                 cell.setS("0");
-                if(value!=null) {
-                	String encodeValue=StringEscapeUtils.escapeXml(value.toString());
-	    			Integer cellV=vmap.get(encodeValue);
-	    			if(cellV==null) {
-	    				vmapSize++;
-	    				cellV=vmapSize;
-	    				vmap.put(encodeValue, cellV);
-	    			}
-	    			cell.setV(cellV.toString());
-                }else {
-                	cell.setV(String.valueOf(0));
+                if (value != null) {
+                    String encodeValue = StringEscapeUtils.escapeXml(value.toString());
+                    Integer cellV = vmap.get(encodeValue);
+                    if (cellV == null) {
+                        vmapSize++;
+                        cellV = vmapSize;
+                        vmap.put(encodeValue, cellV);
+                    }
+                    cell.setV(cellV.toString());
+                } else {
+                    cell.setV(String.valueOf(0));
                 }
                 row.addCell(cell);
             }
             sheet.addRow(row);
             //早点回收内存
             dataset.set(k, null);
-            if(sheet.getRowCount()>=10000) {
-            	writeSheetBody(sheetFile, sheet);
-            	sheet.clearRows();
+            if (sheet.getRowCount() >= 10000) {
+                writeSheetBody(sheetFile, sheet);
+                sheet.clearRows();
             }
         }
-		if(sheet.getRowCount()>0) {
-        	writeSheetBody(sheetFile, sheet);
-        	sheet.clearRows();
+        if (sheet.getRowCount() > 0) {
+            writeSheetBody(sheetFile, sheet);
+            sheet.clearRows();
         }
-		writeSheetTail(sheetFile);
-        
-        writeSharedStrings(excelTargetDir, vmap,index*(colName.size()-1));
-        vmap=null;
-	}
+        writeSheetTail(sheetFile);
+
+        writeSharedStrings(excelTargetDir, vmap, index * (colName.size() - 1));
+        vmap = null;
+    }
 
-	private static void writeSharedStrings(File excelTargetDir, Map<String,Integer> vmap,Integer count) throws IOException {
-		File file = new File(excelTargetDir.getAbsolutePath() + "/xl/sharedStrings.xml");
-		FileOutputStream outputStream = null;
+    private static void writeSharedStrings(File excelTargetDir, Map<String, Integer> vmap, Integer count) throws IOException {
+        File file = new File(excelTargetDir.getAbsolutePath() + "/xl/sharedStrings.xml");
+        FileOutputStream outputStream = null;
         try {
             file.createNewFile();//创建文件
-            outputStream = new FileOutputStream(file,true);
+            outputStream = new FileOutputStream(file, true);
             String data1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
             outputStream.write(data1.getBytes("utf-8"));
-            String data2 = "<sst count=\""+count+"\" uniqueCount=\""+(vmap.size()+1)+"\"\n";
+            String data2 = "<sst count=\"" + count + "\" uniqueCount=\"" + (vmap.size() + 1) + "\"\n";
             outputStream.write(data2.getBytes("utf-8"));
-            String data3="xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"><si><t/></si>\n";
+            String data3 = "xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"><si><t/></si>\n";
             outputStream.write(data3.getBytes("utf-8"));
-            for(String k:vmap.keySet()) {
-            	String data4="<si><t>"+k+"</t></si>\n";
-            	outputStream.write(data4.getBytes("utf-8"));
+            for (String k : vmap.keySet()) {
+                String data4 = "<si><t>" + k + "</t></si>\n";
+                outputStream.write(data4.getBytes("utf-8"));
             }
-            String data5="</sst>";
-        	outputStream.write(data5.getBytes("utf-8"));
-        	outputStream.flush();
+            String data5 = "</sst>";
+            outputStream.write(data5.getBytes("utf-8"));
+            outputStream.flush();
         } catch (Exception e) {
-        	throw new ExamCloudRuntimeException(e);
+            throw new ExamCloudRuntimeException(e);
         } finally {
-            outputStream.close();
+            if (outputStream != null) {
+                outputStream.close();
+            }
         }
-	}
-	private static File writeSheetHead(File excelTargetDir, ExcelSheet sheet,List<ColumnSetting> columnSettings) throws IOException {
-		File file = new File(excelTargetDir.getAbsolutePath() + "/xl/worksheets/sheet1.xml");
-		FileOutputStream outputStream = null;
+    }
+
+    private static File writeSheetHead(File excelTargetDir, ExcelSheet sheet, List<ColumnSetting> columnSettings) throws IOException {
+        File file = new File(excelTargetDir.getAbsolutePath() + "/xl/worksheets/sheet1.xml");
+        FileOutputStream outputStream = null;
         try {
-            outputStream = new FileOutputStream(file,true);
+            outputStream = new FileOutputStream(file, true);
             String data1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
             outputStream.write(data1.getBytes("utf-8"));
             String data2 = "<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">\n";
             outputStream.write(data2.getBytes("utf-8"));
-            String data3="<dimension ref=\""+sheet.getDimension()+"\"/>\n";
+            String data3 = "<dimension ref=\"" + sheet.getDimension() + "\"/>\n";
             outputStream.write(data3.getBytes("utf-8"));
-            String data4="<sheetViews><sheetView workbookViewId=\"0\" tabSelected=\"true\"/></sheetViews><sheetFormatPr defaultRowHeight=\"15.0\" baseColWidth=\"15\"/><cols>\n";
+            String data4 = "<sheetViews><sheetView workbookViewId=\"0\" tabSelected=\"true\"/></sheetViews><sheetFormatPr defaultRowHeight=\"15.0\" baseColWidth=\"15\"/><cols>\n";
             outputStream.write(data4.getBytes("utf-8"));
-            int index=0;
-            for(ColumnSetting col:columnSettings) {
-            	index++;
-            	if(col.getWidth()!=0) {
-            		String data10 = "<col min=\""+index+"\" max=\""+index+"\" width=\""+col.getWidth()+"\" customWidth=\"true\"/>\n";
+            int index = 0;
+            for (ColumnSetting col : columnSettings) {
+                index++;
+                if (col.getWidth() != 0) {
+                    String data10 = "<col min=\"" + index + "\" max=\"" + index + "\" width=\"" + col.getWidth() + "\" customWidth=\"true\"/>\n";
+                    outputStream.write(data10.getBytes("utf-8"));
+                } else {
+                    String data10 = "<col min=\"" + index + "\" max=\"" + index + "\" width=\"" + 15 + "\" customWidth=\"true\"/>\n";
                     outputStream.write(data10.getBytes("utf-8"));
-            	}else {
-            		String data10 = "<col min=\""+index+"\" max=\""+index+"\" width=\""+15+"\" customWidth=\"true\"/>\n";
-	                outputStream.write(data10.getBytes("utf-8"));
-            	}
+                }
             }
             String data11 = "</cols><sheetData>\n";
             outputStream.write(data11.getBytes("utf-8"));
-        	outputStream.flush();
-        	return file;
+            outputStream.flush();
+            return file;
         } catch (Exception e) {
-        	throw new ExamCloudRuntimeException(e);
+            throw new ExamCloudRuntimeException(e);
         } finally {
-            outputStream.close();
+            if (outputStream != null) {
+                outputStream.close();
+            }
         }
-	}
-	private static void writeSheetBody(File file, ExcelSheet sheet) throws IOException {
-		FileOutputStream outputStream = null;
+    }
+
+    private static void writeSheetBody(File file, ExcelSheet sheet) throws IOException {
+        FileOutputStream outputStream = null;
         try {
-            outputStream = new FileOutputStream(file,true);
-            for(ExcelRow row:sheet.getRows()) {
-            	String data5="<row r=\""+row.getR()+"\">\n";
-            	outputStream.write(data5.getBytes("utf-8"));
-	            for(ExcelCell cell:row.getCells()) {
-	            	String data6="<c r=\""+cell.getR()+"\" s=\""+cell.getS()+"\" t=\"s\"><v>"+cell.getV()+"</v></c>\n";
-	            	outputStream.write(data6.getBytes("utf-8"));
-	            }
-	            String data7="</row>\n";
-            	outputStream.write(data7.getBytes("utf-8"));
-            	row=null;
+            outputStream = new FileOutputStream(file, true);
+            for (ExcelRow row : sheet.getRows()) {
+                String data5 = "<row r=\"" + row.getR() + "\">\n";
+                outputStream.write(data5.getBytes("utf-8"));
+                for (ExcelCell cell : row.getCells()) {
+                    String data6 = "<c r=\"" + cell.getR() + "\" s=\"" + cell.getS() + "\" t=\"s\"><v>" + cell.getV() + "</v></c>\n";
+                    outputStream.write(data6.getBytes("utf-8"));
+                }
+                String data7 = "</row>\n";
+                outputStream.write(data7.getBytes("utf-8"));
+                row = null;
             }
-        	outputStream.flush();
+            outputStream.flush();
         } catch (Exception e) {
-        	throw new ExamCloudRuntimeException(e);
+            throw new ExamCloudRuntimeException(e);
         } finally {
-            outputStream.close();
+            if (outputStream != null) {
+                outputStream.close();
+            }
         }
-	}
-	
-	private static void writeSheetTail(File file) throws IOException {
-		FileOutputStream outputStream = null;
+    }
+
+    private static void writeSheetTail(File file) throws IOException {
+        FileOutputStream outputStream = null;
         try {
-            outputStream = new FileOutputStream(file,true);
-            String data7="</sheetData><pageMargins bottom=\"0.75\" footer=\"0.3\" header=\"0.3\" left=\"0.7\" right=\"0.7\" top=\"0.75\"/></worksheet>";
-        	outputStream.write(data7.getBytes("utf-8"));
-        	outputStream.flush();
+            outputStream = new FileOutputStream(file, true);
+            String data7 = "</sheetData><pageMargins bottom=\"0.75\" footer=\"0.3\" header=\"0.3\" left=\"0.7\" right=\"0.7\" top=\"0.75\"/></worksheet>";
+            outputStream.write(data7.getBytes("utf-8"));
+            outputStream.flush();
         } catch (Exception e) {
-        	throw new ExamCloudRuntimeException(e);
+            throw new ExamCloudRuntimeException(e);
         } finally {
-            outputStream.close();
+            if (outputStream != null) {
+                outputStream.close();
+            }
         }
-	}
-	
-	 /**
+    }
+
+    /**
      * 提取ExcelProperty注解类的字段信息
+     *
      * @param dataClass 需要解析 写入excel的数据类型
      * @return
      */
-    private static List<ColumnSetting> getColumnSettings(Class<?> dataClass){
+    private static List<ColumnSetting> getColumnSettings(Class<?> dataClass) {
         List<ColumnSetting> columnSettings = new ArrayList<>();
         //先在方法上找ExcelProperty注解
         Method[] methods = dataClass.getDeclaredMethods();
-        for(Method method : methods){
+        for (Method method : methods) {
             ExcelProperty exportProperty = method.getAnnotation(ExcelProperty.class);
-            if(exportProperty != null && exportProperty.name().trim().length() > 0){
-                ColumnSetting columnSetting = new ColumnSetting(StringEscapeUtils.escapeXml(exportProperty.name()),method.getName(),
-                        exportProperty.width(),exportProperty.index());
+            if (exportProperty != null && exportProperty.name().trim().length() > 0) {
+                ColumnSetting columnSetting = new ColumnSetting(StringEscapeUtils.escapeXml(exportProperty.name()), method.getName(),
+                        exportProperty.width(), exportProperty.index());
                 columnSettings.add(columnSetting);
             }
         }
         //如果方法上找不到注解,再到属性上找 
-        if(columnSettings.size() == 0){
-        	Field[] fields = dataClass.getDeclaredFields();
-        	for(Field field:fields){
-        		ExcelProperty exportProperty = field.getAnnotation(ExcelProperty.class);
-        		if(exportProperty != null && exportProperty.name().trim().length() > 0){
-                    ColumnSetting columnSetting = new ColumnSetting(StringEscapeUtils.escapeXml(exportProperty.name()),"get"+toUpperCaseFirstOne(field.getName()),
-                            exportProperty.width(),exportProperty.index());
+        if (columnSettings.size() == 0) {
+            Field[] fields = dataClass.getDeclaredFields();
+            for (Field field : fields) {
+                ExcelProperty exportProperty = field.getAnnotation(ExcelProperty.class);
+                if (exportProperty != null && exportProperty.name().trim().length() > 0) {
+                    ColumnSetting columnSetting = new ColumnSetting(StringEscapeUtils.escapeXml(exportProperty.name()), "get" + toUpperCaseFirstOne(field.getName()),
+                            exportProperty.width(), exportProperty.index());
                     columnSettings.add(columnSetting);
                 }
-        	}
+            }
         }
         Collections.sort(columnSettings);
         return columnSettings;
     }
-    
-    private static String toUpperCaseFirstOne(String s){
-	  if(Character.isUpperCase(s.charAt(0)))
-	    return s;
-	  else
-	    return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
-	}
-    
+
+    private static String toUpperCaseFirstOne(String s) {
+        if (Character.isUpperCase(s.charAt(0)))
+            return s;
+        else
+            return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
+    }
+
     private static String getExcelColumnName(int celNum) {
-		int num = celNum+1;//celNum是从0算起
-		String tem = "";
-		while(num > 0) {
-			int lo = (num - 1) % 26;//取余,A到Z是26进制,
-			tem = (char)(lo + 'A') + tem;
-			num = (num - 1) / 26;//取模
-		}
-		return tem;
-	}
+        int num = celNum + 1;//celNum是从0算起
+        String tem = "";
+        while (num > 0) {
+            int lo = (num - 1) % 26;//取余,A到Z是26进制,
+            tem = (char) (lo + 'A') + tem;
+            num = (num - 1) / 26;//取模
+        }
+        return tem;
+    }
+
 }