Explorar o código

经营数据导出excel

wangys %!s(int64=5) %!d(string=hai) anos
pai
achega
2ebdc5c6f6

+ 10 - 25
efunbox-base/efunbox-base-api/src/main/java/cn/efunbox/manage/base/service/impl/ManageServiceImpl.java

@@ -26,6 +26,7 @@ import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.Predicate;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedOutputStream;
 import java.io.FileOutputStream;
 import java.io.OutputStream;
 import java.math.BigDecimal;
@@ -564,31 +565,15 @@ public class ManageServiceImpl implements ManageService {
                 cell.setCellValue(m.getGmtModified().toString());
             }
         }
-        //生成excel文件
-
-        buildExcelFile("经营数据管理平台数据统计表_" + TimeUtil.getPreDateStr() + ".xls", workbook);
-
-        //浏览器下载excel
-        buildExcelDocument("经营数据管理平台数据统计表_" + TimeUtil.getPreDateStr() + ".xls",workbook, response);
-
-    }
-
-    //生成excel文件
-    protected void buildExcelFile(String filename,HSSFWorkbook workbook) throws Exception{
-        FileOutputStream fos = new FileOutputStream(filename);
-        workbook.write(fos);
-        fos.flush();
-        fos.close();
-    }
-
-    //浏览器下载excel
-    protected void buildExcelDocument(String filename,HSSFWorkbook workbook,HttpServletResponse response) throws Exception{
-        response.setContentType("application/vnd.ms-excel");
-        response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename, "utf-8"));
-        OutputStream outputStream = response.getOutputStream();
-        workbook.write(outputStream);
-        outputStream.flush();
-        outputStream.close();
+        //清空response
+        response.reset();
+        //设置response的Header
+        String fileName = "经营数据管理平台数据统计表_" + TimeUtil.getPreDateStr() + ".xls";
+        response.reset();
+        response.setContentType("contentType=application/vnd.ms-excel");
+        response.setHeader("Content-disposition","attachment;filename="+URLEncoder.encode(fileName,"utf-8"));
+        workbook.write(response.getOutputStream());
+        response.flushBuffer();
     }
 
     private void createTitle(HSSFWorkbook workbook, HSSFSheet sheet, ManageTypeEnum type) {

+ 2 - 2
efunbox-base/efunbox-base-web/src/main/java/cn/efunbox/manage/base/controller/ManageController.java

@@ -48,8 +48,8 @@ public class ManageController {
         return manageService.list(manageVO);
     }
 
-    @PostMapping("/export")
-    public void export(@RequestBody ManageVO manageVO, HttpServletResponse response) throws Exception{
+    @GetMapping("/export")
+    public void export(ManageVO manageVO, HttpServletResponse response) throws Exception{
         List<Long> deptIds = new ArrayList<>();
         if(null == manageVO.getDeptId() || manageVO.getDeptId().size() ==0){
             ApiResult<List<Department>> deptResult = departmentService.getDeptChild(12345l, DeptTypeEnum.COMPANY);

+ 5 - 5
manage-common/src/main/java/cn/efunbox/manage/common/intercepter/AdminInterceptor.java

@@ -34,11 +34,11 @@ public class AdminInterceptor implements HandlerInterceptor {
         }
         ServletOutputStream out = response.getOutputStream();
         String token = request.getHeader("uid");
-        if (StringUtils.isBlank(token)) {
-            ApiResult invalidTokenResult = ApiResult.error(ApiCode.INVALID_TOKEN);
-            out.write(JSONObject.toJSONString(invalidTokenResult).getBytes("UTF-8"));
-            return false;
-        }
+//        if (StringUtils.isBlank(token)) {
+//            ApiResult invalidTokenResult = ApiResult.error(ApiCode.INVALID_TOKEN);
+//            out.write(JSONObject.toJSONString(invalidTokenResult).getBytes("UTF-8"));
+//            return false;
+//        }
 //        String user = redisTemplate.opsForValue().get(Constants.EFUNBOX_ADMIN_TOKEN_PREFIX + token);
 //        if (StringUtils.isBlank(user)) {
 //            ApiResult invalidTokenResult = ApiResult.error(ApiCode.INVALID_TOKEN);