|
@@ -1,6 +1,11 @@
|
|
|
package com.ssj.sys.controller;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.util.MapUtils;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ssj.bean.common.framework.core.domain.Response;
|
|
|
import com.ssj.bean.sys.sort.domain.Sort;
|
|
|
import com.ssj.bean.weixin.libmy.domain.TbLibJoin;
|
|
@@ -13,10 +18,17 @@ import com.ssj.framework.core.util.SystemResourceLocator;
|
|
|
import com.ssj.service.sys.sort.service.SortService;
|
|
|
import com.ssj.service.weixin.library.service.ILibJoinService;
|
|
|
import com.ssj.service.weixin.zuoyb.service.*;
|
|
|
+import com.ssj.sys.model.HowDetailExportVO;
|
|
|
+import com.ssj.sys.model.HowExportVO;
|
|
|
+import com.ssj.sys.model.HowKdlExportVO;
|
|
|
+import com.ssj.sys.model.RowRangeDto;
|
|
|
+import com.ssj.sys.utils.BizMergeStrategy;
|
|
|
+import com.ssj.sys.utils.ExcelMergeUtil;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
|
import org.apache.poi.hssf.util.HSSFColor;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
@@ -26,12 +38,10 @@ import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
|
@@ -41,6 +51,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -769,7 +780,7 @@ public class SysZuoybController extends BaseController {
|
|
|
@RequestParam(required = false, defaultValue = "10") int pageSize,
|
|
|
@RequestParam(required = false, defaultValue = "1") int pageNo,
|
|
|
@RequestParam(required = false, defaultValue = "SSJ") String EQ_libId)
|
|
|
- throws Exception {
|
|
|
+ {
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
params.put("EQ_libId", EQ_libId);
|
|
|
params.put("LIKE_name",request.getParameter("LIKE_name")==null?"":request.getParameter("LIKE_name"));
|
|
@@ -786,7 +797,7 @@ public class SysZuoybController extends BaseController {
|
|
|
|
|
|
Page<Map<String, Object>> page= zuoybKnowHowService.getZuoybKnowHow(params, initPage(pageNo,pageSize));
|
|
|
SplitPage sp = new SplitPage();
|
|
|
- sp.setAction(request.getRequestURI().toString());
|
|
|
+ sp.setAction(request.getRequestURI());
|
|
|
sp.setPageNo(pageNo);
|
|
|
sp.setPageSize(pageSize);
|
|
|
sp.setParams(params);
|
|
@@ -1362,7 +1373,8 @@ public class SysZuoybController extends BaseController {
|
|
|
});
|
|
|
}else{
|
|
|
//修改sort表的alias
|
|
|
- zuoybKnowHowDetailsSortService.updateAliasByStatAndNameAndDetailId(how.getId(),2,how.getName());
|
|
|
+ zuoybKnowHowDetailsSortService.updateAliasByStatAndNameAndDetailId(
|
|
|
+ how.getId(),2,how.getName(),how.getModule(),how.getTwoModule(),how.getJxmb(),how.getYdsl(),how.getMemorize(),how.getUnderstanding(),how.getApply());
|
|
|
}
|
|
|
|
|
|
}else{
|
|
@@ -2267,16 +2279,14 @@ public class SysZuoybController extends BaseController {
|
|
|
@RequestMapping(value = "/exportHowExcel", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
public void exportHowExcel(HttpServletRequest request, HttpServletResponse response,
|
|
|
- @RequestParam(required = false, defaultValue = "SSJ") String EQ_libId,
|
|
|
- String EQ_courseName,
|
|
|
- String LIKE_name,
|
|
|
- String EQ_grade,
|
|
|
- Integer semester,
|
|
|
- Integer banben
|
|
|
+ @RequestParam(required = false, defaultValue = "SSJ") String EQ_libId
|
|
|
|
|
|
- ) throws Exception {
|
|
|
- Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ ) throws IOException{
|
|
|
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ String EQ_courseName = request.getParameter("EQ_courseName")==null?"":request.getParameter("EQ_courseName");
|
|
|
+ String EQ_grade = request.getParameter("EQ_grade")==null?"":request.getParameter("EQ_grade");
|
|
|
+ String semester = request.getParameter("semester")==null?"":request.getParameter("semester");
|
|
|
StringBuffer fileName =new StringBuffer("单元");
|
|
|
if(EQ_courseName != null){
|
|
|
fileName.append(EQ_courseName);
|
|
@@ -2285,108 +2295,78 @@ public class SysZuoybController extends BaseController {
|
|
|
fileName.append(EQ_grade+"年级");
|
|
|
}
|
|
|
if(semester != null && !"".equals(semester)){
|
|
|
- fileName.append(semester==1?"上学期":"下学期");
|
|
|
+ fileName.append(semester.equals("1")?"上学期":"下学期");
|
|
|
}
|
|
|
-
|
|
|
+ request.getSession().removeAttribute("endFlag");//每次导入前,清除结束标记
|
|
|
params.put("EQ_libId", EQ_libId);
|
|
|
- params.put("LIKE_name", LIKE_name);
|
|
|
- params.put("banben", banben);
|
|
|
- ServletOutputStream os = null;
|
|
|
- try {
|
|
|
- os = response.getOutputStream(); // 获得输出流
|
|
|
- response.reset(); // 清空输出流
|
|
|
-
|
|
|
- String filesName = new String(fileName.toString().getBytes("gb2312"), "ISO8859-1") +".xlsx";
|
|
|
- int rownum = 1; // 添加的起始行
|
|
|
-
|
|
|
-
|
|
|
+ params.put("LIKE_name",request.getParameter("LIKE_name")==null?"":request.getParameter("LIKE_name"));
|
|
|
+ params.put("EQ_grade",request.getParameter("EQ_grade")==null?"":request.getParameter("EQ_grade"));//年级
|
|
|
+ params.put("EQ_courseName",request.getParameter("EQ_courseName")==null?"":request.getParameter("EQ_courseName"));
|
|
|
+ params.put("semester",request.getParameter("semester")==null?"":request.getParameter("semester"));//学期
|
|
|
+ params.put("banben",request.getParameter("banben")==null?"":request.getParameter("banben"));//版本
|
|
|
+ params.put("beginDate", request.getParameter("beginDate")==null? "":request.getParameter("beginDate"));
|
|
|
+ params.put("endDate", request.getParameter("endDate")==null? "":request.getParameter("endDate"));
|
|
|
+ params.put("LIKE_id", request.getParameter("LIKE_id")==null?"":request.getParameter("LIKE_id"));
|
|
|
+ params.put("isZt", request.getParameter("isZt")==null?"":request.getParameter("isZt"));
|
|
|
|
|
|
- ClassPathResource classPathResource = new ClassPathResource("/excel/report/report13.xlsx");
|
|
|
- XSSFWorkbook workbook = new XSSFWorkbook(classPathResource.getInputStream());
|
|
|
- response.setHeader("Content-disposition", "attachment; filename=" + filesName); // 设定输出文件头
|
|
|
- // response.setContentType("application/msexcel"); //定义输出类型
|
|
|
- response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
+ // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
+ try {
|
|
|
+ int pageSize = 100;
|
|
|
+ int pageNo = 10000;
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
- XSSFSheet sheet = workbook.getSheetAt(0); // 读取第一个工作簿
|
|
|
- XSSFRow row;
|
|
|
- XSSFCell cell = null;
|
|
|
- XSSFCellStyle style = this.getxStyle(workbook);
|
|
|
- List<Map<String, Object>> list=zuoybKnowHowDetailsSortService.getKonwVersion(EQ_libId, EQ_courseName, EQ_grade, banben, semester, LIKE_name);
|
|
|
- int endRow = rownum;
|
|
|
- int startRow = rownum;
|
|
|
-
|
|
|
- int idnum =6;
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- row = sheet.createRow(rownum);
|
|
|
- int j = 0;
|
|
|
- myCreateCellx(j++, list.get(i).get("course_name")!=null?list.get(i).get("course_name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("name")!=null?list.get(i).get("name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("id").toString(), row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("num")!=null?list.get(i).get("num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("module")!=null?list.get(i).get("module").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("create_time")!=null?list.get(i).get("create_time").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("s_id")!=null?list.get(i).get("s_id").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("alias")!=null?list.get(i).get("alias").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("semester")!=null?list.get(i).get("semester").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_num")!=null?list.get(i).get("s_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("grade_num")!=null?list.get(i).get("grade_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_type")!=null?list.get(i).get("s_type").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_create_time")!=null?list.get(i).get("s_create_time").toString():"", row, cell, style); // 列1
|
|
|
- if (i > 0) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (list.get(i).get("id").toString().equals(list.get(i - 1).get("id").toString())) {
|
|
|
- endRow++;// 则合并结束行号+1
|
|
|
- if (i == list.size() - 1) {
|
|
|
- for (int a = 0; a < idnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(startRow, // first
|
|
|
- endRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- if (startRow != endRow) {
|
|
|
- for (int a = 0; a < idnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(startRow, // first
|
|
|
- endRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
- startRow = rownum;// 为下次合并做准备,把合并开始行号赋值为下一行开始号
|
|
|
- endRow = rownum;// 合并结束行同合并开始行
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- rownum++;
|
|
|
- }
|
|
|
- workbook.write(os);
|
|
|
+ // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
|
|
+
|
|
|
+ String filesName = URLEncoder.encode(fileName.toString(), "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + filesName + ".xlsx");
|
|
|
+ Page<HowExportVO> page= zuoybKnowHowDetailsSortService.getZuoybKnowHowPage(params,initPage(1,100000));
|
|
|
+ //合并策略map
|
|
|
+ Map<String, List<RowRangeDto>> strategyMap = ExcelMergeUtil.addMerStrategy(page.getContent());
|
|
|
+ EasyExcel.write(response.getOutputStream(), HowExportVO.class)
|
|
|
+ //注册合并策略
|
|
|
+ .registerWriteHandler(new BizMergeStrategy(strategyMap))
|
|
|
+ .sheet("单元版本").doWrite(page.getContent());
|
|
|
+
|
|
|
+// // 这里需要设置不关闭流
|
|
|
+// excelWriter = EasyExcel.write(response.getOutputStream(), HowExportVO.class).build();
|
|
|
+// WriteSheet writeSheet = EasyExcel.writerSheet("单元版本").build();
|
|
|
+// for(int i=1;i<pageNo;i++){
|
|
|
+// Page<HowExportVO> page= zuoybKnowHowDetailsSortService.getZuoybKnowHowPage(params,initPage(i,pageSize));
|
|
|
+// if(!page.hasContent()){
|
|
|
+// break;
|
|
|
+//
|
|
|
+// }
|
|
|
+// excelWriter.write(page.getContent(),writeSheet);
|
|
|
+// }
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }finally{
|
|
|
- if(os != null){
|
|
|
- try {
|
|
|
- os.flush();
|
|
|
- os.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/json");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ Map<String, String> map = MapUtils.newHashMap();
|
|
|
+ map.put("status", "failure");
|
|
|
+ map.put("message", "下载文件失败" + e.getMessage());
|
|
|
+ response.getWriter().println(JSON.toJSONString(map));
|
|
|
+ }finally {
|
|
|
+ // 千万别忘记finish 会帮忙关闭流
|
|
|
+ if (excelWriter != null) {
|
|
|
+ excelWriter.finish();
|
|
|
}
|
|
|
+ //设置结束标记
|
|
|
+ request.getSession().setAttribute("endFlag", "1");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private List<HowDetailExportVO> howExportData(List<Map<String,Object>> list){
|
|
|
+ List<HowDetailExportVO> reList = new ArrayList<>();
|
|
|
+ if(!list.isEmpty()){
|
|
|
+ list.forEach(m->{
|
|
|
+ String jsonStr = JSONObject.toJSONString(m);
|
|
|
+ reList.add(JSONObject.parseObject(jsonStr, HowDetailExportVO.class));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return reList;
|
|
|
+ }
|
|
|
@RequestMapping(value = "/exportHowDetailsExcel", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
public void exportHowDetailsExcel(HttpServletRequest request, HttpServletResponse response,
|
|
@@ -2399,7 +2379,7 @@ public class SysZuoybController extends BaseController {
|
|
|
|
|
|
) throws Exception {
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
-
|
|
|
+ request.getSession().removeAttribute("endFlag");//每次导入前,清除结束标记
|
|
|
StringBuffer fileName =new StringBuffer("知识点");
|
|
|
if(EQ_courseName != null){
|
|
|
fileName.append(EQ_courseName);
|
|
@@ -2414,164 +2394,64 @@ public class SysZuoybController extends BaseController {
|
|
|
params.put("EQ_libId", EQ_libId);
|
|
|
params.put("LIKE_name", LIKE_name);
|
|
|
params.put("banben", banben);
|
|
|
- ServletOutputStream os = null;
|
|
|
- try {
|
|
|
- os = response.getOutputStream(); // 获得输出流
|
|
|
- response.reset(); // 清空输出流
|
|
|
-
|
|
|
- String filesName = new String(fileName.toString().getBytes("gb2312"), "ISO8859-1") +".xlsx";
|
|
|
- int rownum = 1; // 添加的起始行
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- ClassPathResource classPathResource = new ClassPathResource("/excel/report/report14.xlsx");
|
|
|
- XSSFWorkbook workbook = new XSSFWorkbook(classPathResource.getInputStream());
|
|
|
-
|
|
|
- response.setHeader("Content-disposition", "attachment; filename=" + filesName); // 设定输出文件头
|
|
|
- // response.setContentType("application/msexcel"); //定义输出类型
|
|
|
- response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
- XSSFSheet sheet = workbook.getSheetAt(0); // 读取第一个工作簿
|
|
|
- XSSFRow row;
|
|
|
- XSSFCell cell = null;
|
|
|
- XSSFCellStyle style = this.getxStyle(workbook);
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
|
|
+
|
|
|
+ String filesName = URLEncoder.encode(fileName.toString(), "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + filesName + ".xlsx");
|
|
|
List<Map<String, Object>> list=zuoybKnowHowDetailsSortService.getKonwDetailVersion(EQ_libId, EQ_courseName, EQ_grade, banben, semester, LIKE_name);
|
|
|
- int endRow = rownum;
|
|
|
- int startRow = rownum;
|
|
|
-
|
|
|
- int idnum =6;
|
|
|
- int detailnum =23;
|
|
|
- int detailStartRow =rownum ;
|
|
|
- int detailEndRow = rownum;
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- row = sheet.createRow(rownum);
|
|
|
- int j = 0;
|
|
|
- myCreateCellx(j++, list.get(i).get("course_name")!=null?list.get(i).get("course_name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("name")!=null?list.get(i).get("name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("id").toString(), row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("num")!=null?list.get(i).get("num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("module")!=null?list.get(i).get("module").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("t_create_time")!=null?list.get(i).get("t_create_time").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("detail_name")!=null?list.get(i).get("detail_name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("detail_id")!=null?list.get(i).get("detail_id").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("t11_module")!=null?list.get(i).get("t11_module").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("jxmb")!=null?list.get(i).get("jxmb").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("zdbx")!=null?list.get(i).get("zdbx").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("ydsl")!=null?list.get(i).get("ydsl").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("img")!=null?list.get(i).get("img").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("two_module")!=null?list.get(i).get("two_module").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("before_name")!=null?list.get(i).get("before_name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("after_name")!=null?list.get(i).get("after_name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("type")!=null?list.get(i).get("type").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("is_hot")!=null?list.get(i).get("is_hot").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("memorize")!=null?list.get(i).get("memorize").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("understanding")!=null?list.get(i).get("understanding").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("apply")!=null?list.get(i).get("apply").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("duration")!=null?list.get(i).get("duration").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("attr_type")!=null?list.get(i).get("attr_type").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("detail_num")!=null?list.get(i).get("detail_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("detail_create_time")!=null?list.get(i).get("detail_create_time").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("s_id")!=null?list.get(i).get("s_id").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("alias")!=null?list.get(i).get("alias").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("semester")!=null?list.get(i).get("semester").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_num")!=null?list.get(i).get("s_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("grade_num")!=null?list.get(i).get("grade_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_type")!=null?list.get(i).get("s_type").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("s_module")!=null?list.get(i).get("s_module").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_two_module")!=null?list.get(i).get("s_two_module").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_jxmb")!=null?list.get(i).get("s_jxmb").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_zdbx")!=null?list.get(i).get("s_zdbx").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_ydsl")!=null?list.get(i).get("s_ydsl").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_memorize")!=null?list.get(i).get("s_memorize").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_understanding")!=null?list.get(i).get("s_understanding").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_apply")!=null?list.get(i).get("s_apply").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("s_attr_type")!=null?list.get(i).get("s_attr_type").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_create_time")!=null?list.get(i).get("s_create_time").toString():"", row, cell, style); // 列1
|
|
|
- if (i > 0) {
|
|
|
-
|
|
|
- if (list.get(i).get("detail_id")!=null&&list.get(i).get("detail_id").toString().equals(list.get(i - 1).get("detail_id").toString())) {
|
|
|
- detailEndRow++;// 则合并结束行号+1
|
|
|
- if (i == list.size() - 1) {
|
|
|
- for (int a = idnum; a < detailnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(detailStartRow, // first
|
|
|
- detailEndRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- if (detailStartRow != detailEndRow) {
|
|
|
- for (int a = idnum; a < detailnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(detailStartRow, // first
|
|
|
- detailEndRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- detailStartRow = rownum;// 为下次合并做准备,把合并开始行号赋值为下一行开始号
|
|
|
- detailEndRow = rownum;// 合并结束行同合并开始行
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (list.get(i).get("id").toString().equals(list.get(i - 1).get("id").toString())) {
|
|
|
- endRow++;// 则合并结束行号+1
|
|
|
- if (i == list.size() - 1) {
|
|
|
- for (int a = 0; a < idnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(startRow, // first
|
|
|
- endRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- if (startRow != endRow) {
|
|
|
- for (int a = 0; a < idnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(startRow, // first
|
|
|
- endRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
- startRow = rownum;// 为下次合并做准备,把合并开始行号赋值为下一行开始号
|
|
|
- endRow = rownum;// 合并结束行同合并开始行
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
-
|
|
|
- }
|
|
|
- rownum++;
|
|
|
- }
|
|
|
- workbook.write(os);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }finally{
|
|
|
- if(os != null){
|
|
|
- try {
|
|
|
- os.flush();
|
|
|
- os.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+ List<HowDetailExportVO> dataList = howExportData(list);
|
|
|
+ //合并策略map
|
|
|
+ Map<String, List<RowRangeDto>> strategyMap = ExcelMergeUtil.addDetailMerStrategy(dataList);
|
|
|
+ EasyExcel.write(response.getOutputStream(), HowDetailExportVO.class)
|
|
|
+ //注册合并策略
|
|
|
+ .registerWriteHandler(new BizMergeStrategy(strategyMap))
|
|
|
+ .sheet("单元版本").doWrite(dataList);
|
|
|
+
|
|
|
+// // 这里需要设置不关闭流
|
|
|
+// excelWriter = EasyExcel.write(response.getOutputStream(), HowExportVO.class).build();
|
|
|
+// WriteSheet writeSheet = EasyExcel.writerSheet("单元版本").build();
|
|
|
+// for(int i=1;i<pageNo;i++){
|
|
|
+// Page<HowExportVO> page= zuoybKnowHowDetailsSortService.getZuoybKnowHowPage(params,initPage(i,pageSize));
|
|
|
+// if(!page.hasContent()){
|
|
|
+// break;
|
|
|
+//
|
|
|
+// }
|
|
|
+// excelWriter.write(page.getContent(),writeSheet);
|
|
|
+// }
|
|
|
+ } catch (Exception e) {
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/json");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ Map<String, String> map = MapUtils.newHashMap();
|
|
|
+ map.put("status", "failure");
|
|
|
+ map.put("message", "下载文件失败" + e.getMessage());
|
|
|
+ response.getWriter().println(JSON.toJSONString(map));
|
|
|
+ }finally {
|
|
|
+ // 千万别忘记finish 会帮忙关闭流
|
|
|
+ if (excelWriter != null) {
|
|
|
+ excelWriter.finish();
|
|
|
+ }
|
|
|
+ //设置结束标记
|
|
|
+ request.getSession().setAttribute("endFlag", "1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<HowKdlExportVO> kdExportData(List<Map<String,Object>> list){
|
|
|
+ List<HowKdlExportVO> reList = new ArrayList<>();
|
|
|
+ if(!list.isEmpty()){
|
|
|
+ list.forEach(m->{
|
|
|
+ String jsonStr = JSONObject.toJSONString(m);
|
|
|
+ reList.add(JSONObject.parseObject(jsonStr, HowKdlExportVO.class));
|
|
|
+ });
|
|
|
}
|
|
|
+ return reList;
|
|
|
}
|
|
|
+
|
|
|
@RequestMapping(value = "/exportHowDetailsKdExcel", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
public void exportHowDetailsKdExcel(HttpServletRequest request, HttpServletResponse response,
|
|
@@ -2584,7 +2464,7 @@ public class SysZuoybController extends BaseController {
|
|
|
|
|
|
) throws Exception {
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
-
|
|
|
+ request.getSession().removeAttribute("endFlag");//每次导入前,清除结束标记
|
|
|
StringBuffer fileName =new StringBuffer("考点");
|
|
|
if(EQ_courseName != null){
|
|
|
fileName.append(EQ_courseName);
|
|
@@ -2599,174 +2479,40 @@ public class SysZuoybController extends BaseController {
|
|
|
params.put("EQ_libId", EQ_libId);
|
|
|
params.put("LIKE_name", LIKE_name);
|
|
|
params.put("banben", banben);
|
|
|
- ServletOutputStream os = null;
|
|
|
- try {
|
|
|
- os = response.getOutputStream(); // 获得输出流
|
|
|
- response.reset(); // 清空输出流
|
|
|
-
|
|
|
- String filesName = new String(fileName.toString().getBytes("gb2312"), "ISO8859-1") +".xlsx";
|
|
|
- int rownum = 1; // 添加的起始行
|
|
|
|
|
|
- ClassPathResource classPathResource = new ClassPathResource("/excel/report/report15.xlsx");
|
|
|
- XSSFWorkbook workbook = new XSSFWorkbook(classPathResource.getInputStream());
|
|
|
- response.setHeader("Content-disposition", "attachment; filename=" + filesName); // 设定输出文件头
|
|
|
- // response.setContentType("application/msexcel"); //定义输出类型
|
|
|
- response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
- XSSFSheet sheet = workbook.getSheetAt(0); // 读取第一个工作簿
|
|
|
- XSSFRow row;
|
|
|
- XSSFCell cell = null;
|
|
|
- XSSFCellStyle style = this.getxStyle(workbook);
|
|
|
- List<Map<String, Object>> list=zuoybKnowHowDetailsSortService.getKonwDetailKdVersion(EQ_libId, EQ_courseName, EQ_grade, banben, semester, LIKE_name);
|
|
|
- int endRow = rownum;
|
|
|
- int startRow = rownum;
|
|
|
-
|
|
|
- int idnum =5;
|
|
|
- int detailStartRow =rownum ;
|
|
|
- int detailEndRow = rownum;
|
|
|
- int detailnum =12;
|
|
|
- int kdnum =19;
|
|
|
- int kdStartRow =rownum ;
|
|
|
- int kdEndRow = rownum;
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- row = sheet.createRow(rownum);
|
|
|
- int j = 0;
|
|
|
- myCreateCellx(j++, list.get(i).get("course_name")!=null?list.get(i).get("course_name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("name")!=null?list.get(i).get("name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("id").toString(), row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("num")!=null?list.get(i).get("num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("t_create_time")!=null?list.get(i).get("t_create_time").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("detail_name")!=null?list.get(i).get("detail_name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("detail_id")!=null?list.get(i).get("detail_id").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("t11_module")!=null?list.get(i).get("t11_module").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("jxmb")!=null?list.get(i).get("jxmb").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("zdbx")!=null?list.get(i).get("zdbx").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("ydsl")!=null?list.get(i).get("ydsl").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("detail_num")!=null?list.get(i).get("detail_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("detail_create_time")!=null?list.get(i).get("detail_create_time").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("d_id")!=null?list.get(i).get("d_id").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("d_name")!=null?list.get(i).get("d_name").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("d_ydsl")!=null?list.get(i).get("d_ydsl").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("d_img")!=null?list.get(i).get("d_img").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("d_num")!=null?list.get(i).get("d_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("d_label")!=null?list.get(i).get("d_label").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("d_level")!=null?list.get(i).get("d_level").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("d_create_time")!=null?list.get(i).get("d_create_time").toString():"", row, cell, style); // 列1
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- myCreateCellx(j++, list.get(i).get("s_id")!=null?list.get(i).get("s_id").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("alias")!=null?list.get(i).get("alias").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("semester")!=null?list.get(i).get("semester").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_num")!=null?list.get(i).get("s_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("grade_num")!=null?list.get(i).get("grade_num").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_type")!=null?list.get(i).get("s_type").toString():"", row, cell, style); // 列1
|
|
|
- myCreateCellx(j++, list.get(i).get("s_create_time")!=null?list.get(i).get("s_create_time").toString():"", row, cell, style); // 列1
|
|
|
- if (i > 0) {
|
|
|
-
|
|
|
- if (list.get(i).get("detail_id")!=null&&list.get(i).get("detail_id").toString().equals(list.get(i - 1).get("detail_id").toString())) {
|
|
|
- detailEndRow++;// 则合并结束行号+1
|
|
|
- if (i == list.size() - 1) {
|
|
|
- for (int a = idnum; a < detailnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(detailStartRow, // first
|
|
|
- detailEndRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- if (detailStartRow != detailEndRow) {
|
|
|
- for (int a = idnum; a < detailnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(detailStartRow, // first
|
|
|
- detailEndRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- detailStartRow = rownum;// 为下次合并做准备,把合并开始行号赋值为下一行开始号
|
|
|
- detailEndRow = rownum;// 合并结束行同合并开始行
|
|
|
- }
|
|
|
- if (list.get(i).get("d_id")!=null&&list.get(i).get("d_id").toString().equals(list.get(i - 1).get("d_id").toString())) {
|
|
|
- kdEndRow++;// 则合并结束行号+1
|
|
|
- if (i == list.size() - 1) {
|
|
|
- for (int a = detailnum; a < kdnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(kdStartRow, // first
|
|
|
- kdEndRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- if (kdStartRow != kdEndRow) {
|
|
|
- for (int a = detailnum; a < kdnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(kdStartRow, // first
|
|
|
- kdEndRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- kdStartRow = rownum;// 为下次合并做准备,把合并开始行号赋值为下一行开始号
|
|
|
- kdEndRow = rownum;// 合并结束行同合并开始行
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (list.get(i).get("id").toString().equals(list.get(i - 1).get("id").toString())) {
|
|
|
- endRow++;// 则合并结束行号+1
|
|
|
- if (i == list.size() - 1) {
|
|
|
- for (int a = 0; a < idnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(startRow, // first
|
|
|
- endRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- if (startRow != endRow) {
|
|
|
- for (int a = 0; a < idnum; a++) {
|
|
|
- sheet.addMergedRegion(new CellRangeAddress(startRow, // first
|
|
|
- endRow, // last row (0-based)
|
|
|
- a, // first column (0-based)
|
|
|
- a // last column (0-based)
|
|
|
- ));// 合并单元格
|
|
|
- }
|
|
|
- }
|
|
|
- startRow = rownum;// 为下次合并做准备,把合并开始行号赋值为下一行开始号
|
|
|
- endRow = rownum;// 合并结束行同合并开始行
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
|
|
|
|
|
+ String filesName = URLEncoder.encode(fileName.toString(), "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + filesName + ".xlsx");
|
|
|
+ List<Map<String, Object>> list=zuoybKnowHowDetailsSortService.getKonwDetailKdVersion(EQ_libId, EQ_courseName, EQ_grade, banben, semester, LIKE_name);
|
|
|
|
|
|
- }
|
|
|
- rownum++;
|
|
|
- }
|
|
|
- workbook.write(os);
|
|
|
+ List<HowKdlExportVO> dataList = kdExportData(list);
|
|
|
+ //合并策略map
|
|
|
+ Map<String, List<RowRangeDto>> strategyMap = ExcelMergeUtil.addKdMerStrategy(dataList);
|
|
|
+ EasyExcel.write(response.getOutputStream(), HowKdlExportVO.class)
|
|
|
+ //注册合并策略
|
|
|
+ .registerWriteHandler(new BizMergeStrategy(strategyMap))
|
|
|
+ .sheet("单元版本").doWrite(dataList);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- }finally{
|
|
|
- if(os != null){
|
|
|
- try {
|
|
|
- os.flush();
|
|
|
- os.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/json");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ Map<String, String> map = MapUtils.newHashMap();
|
|
|
+ map.put("status", "failure");
|
|
|
+ map.put("message", "下载文件失败" + e.getMessage());
|
|
|
+ response.getWriter().println(JSON.toJSONString(map));
|
|
|
+ }finally {
|
|
|
+ // 千万别忘记finish 会帮忙关闭流
|
|
|
+ if (excelWriter != null) {
|
|
|
+ excelWriter.finish();
|
|
|
}
|
|
|
+ //设置结束标记
|
|
|
+ request.getSession().setAttribute("endFlag", "1");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2813,4 +2559,16 @@ public class SysZuoybController extends BaseController {
|
|
|
cell.setCellValue(new XSSFRichTextString(value));
|
|
|
cell.setCellStyle(style);
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/getEndFlag", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ private Response getEndFlag(HttpServletRequest request, HttpServletResponse response){
|
|
|
+ Response responseEntity = new Response();
|
|
|
+ //获取结束标记*/
|
|
|
+ Object flag = request.getSession().getAttribute("endFlag");
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ data.put("flag",flag);
|
|
|
+ responseEntity.success(data);
|
|
|
+ return responseEntity;
|
|
|
+ }
|
|
|
}
|