Przeglądaj źródła

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 5 lat temu
rodzic
commit
fda61154ac

+ 17 - 4
mec-web/src/main/java/com/ym/mec/web/controller/ExportController.java

@@ -16,8 +16,10 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.excel.POIUtil;
+
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,7 +30,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletResponse;
+
 import java.io.IOException;
+import java.io.OutputStream;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -288,6 +292,7 @@ public class ExportController extends BaseController {
             }
         }
         List<CourseScheduleEndDto> rows = scheduleService.endFindCourseSchedules(queryInfo).getRows();
+        OutputStream ouputStream = null;
         try {
             HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"分部名称", "课程编号", "开始时间", "结束时间",
                     "班级名称", "班级声部", "课程名称", "课程类型", "教学模式",
@@ -297,12 +302,20 @@ public class ExportController extends BaseController {
                     "signOutTime","signInStatusEnum.msg","signOutStatusEnum.msg", "remark"}, rows);
             response.setContentType("application/octet-stream");
             response.setHeader("Content-Disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
-            response.flushBuffer();
-            workbook.write(response.getOutputStream());
-            workbook.close();
+            ouputStream = response.getOutputStream();
+			workbook.write(ouputStream);
+			ouputStream.flush();
         } catch (Exception e) {
             e.printStackTrace();
-        }
+        } finally {
+			if (ouputStream != null) {
+				try {
+					ouputStream.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
     }