main
黄海 7 months ago
parent bfae1f94fa
commit 6de5e3b763

@ -1,11 +1,14 @@
package com.dsideal.QingLong.MaxKB.Controller; package com.dsideal.QingLong.MaxKB.Controller;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.dsideal.QingLong.Base.Model.BaseModel; import com.dsideal.QingLong.Base.Model.BaseModel;
import com.dsideal.QingLong.Interceptor.IsNumericInterface;
import com.dsideal.QingLong.MaxKB.Model.MaxKbModel; import com.dsideal.QingLong.MaxKB.Model.MaxKbModel;
import com.dsideal.QingLong.MaxKB.Service.Impl.MaxKbImpl; import com.dsideal.QingLong.MaxKB.Service.Impl.MaxKbImpl;
import com.dsideal.QingLong.MaxKB.Service.MaxKbService; import com.dsideal.QingLong.MaxKB.Service.MaxKbService;
import com.dsideal.QingLong.MaxKB.Util.ExportExcelUtil; import com.dsideal.QingLong.MaxKB.Util.ExportExcelUtil;
import com.dsideal.QingLong.Util.AsposeUtil;
import com.dsideal.QingLong.Util.CommonUtil; import com.dsideal.QingLong.Util.CommonUtil;
import com.dsideal.QingLong.Util.SessionKit; import com.dsideal.QingLong.Util.SessionKit;
import com.jfinal.aop.Before; import com.jfinal.aop.Before;
@ -16,8 +19,15 @@ import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import com.jfinal.ext.interceptor.GET; import com.jfinal.ext.interceptor.GET;
import com.jfinal.kit.StrKit; import com.jfinal.kit.StrKit;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -108,19 +118,43 @@ public class MaxKbController extends Controller {
* *
* @param gather_regionc * @param gather_regionc
*/ */
// http://10.10.21.20:9000/QingLong/maxkb/exportExcel?gather_regionc=直属代管 // http://10.10.21.20:9000/QingLong/maxkb/exportExcel?gather_regionc=直属代管&type_id=1
// http://10.10.21.20:9000/QingLong/maxkb/exportExcel?gather_regionc=直属代管&type_id=2
@Before(GET.class) @Before(GET.class)
public void exportExcel(String gather_regionc) { @IsNumericInterface({"type_id"})
public void exportExcel(String gather_regionc, int type_id) throws Exception {
List<Record> list = mkm.SchoolClassStudentTeacherList(gather_regionc); List<Record> list = mkm.SchoolClassStudentTeacherList(gather_regionc);
ExportExcelUtil exporter = new ExportExcelUtil(); ExportExcelUtil exporter = new ExportExcelUtil();
String fileName = UUID.randomUUID() + ".xlsx"; String fileName = UUID.randomUUID() + ".xlsx";
String tmpFile = CommonUtil.basePath+File.separator + fileName; String excelPath = CommonUtil.basePath + File.separator + fileName;
exporter.exportToExcel(tmpFile, list); exporter.exportToExcel(excelPath, list);
//提供文件路径
Kv kv = Kv.create(); //2、提供EXCEL
kv.set("success", true); //文件名称
kv.set("message", "生成成功!"); String excel_filename = "按区域、学校统计课程建设情况.xlsx";
kv.set("url", CommonUtil.getServerUrl(getRequest())+ "/Excel/" + fileName); String pdfName = "按区域、学校统计课程建设情况.pdf";
renderJson(kv); if (type_id < 2) {
renderFile(new File(excelPath), excel_filename);
return;
}
//3、提供pdf预览
String pdfPath = excelPath.replace(".xlsx", ".pdf");
AsposeUtil.xls2pdf(excelPath, pdfPath);
//提供带中文文件名的pdf流
HttpServletResponse response = getResponse();
response.reset();
response.setContentType("application/pdf;charset=UTF-8");
response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(pdfName, "UTF-8"));//这里的名字并不起作用
OutputStream out = response.getOutputStream();
PDDocument document = Loader.loadPDF(FileUtil.readBytes(pdfPath)); //加载pdf
PDDocumentInformation info = document.getDocumentInformation(); //获得文档属性对象
//对比原来的代码就是在文件流写入响应体之前经过一下pdfbox修改标题属性然后pdfbox的save方法可以直接写入到响应体中。
info.setTitle(pdfName); //修改标题属性 这个标题会被展示
document.setDocumentInformation(info);
document.save(out); //修改完直接输出到响应体中
document.close();
out.close();
renderNull();
} }
} }

@ -3,6 +3,7 @@ package com.dsideal.QingLong.YunXiao.Controller;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import com.dsideal.QingLong.Interceptor.EmptyInterface; import com.dsideal.QingLong.Interceptor.EmptyInterface;
import com.dsideal.QingLong.Interceptor.IsLoginInterface; import com.dsideal.QingLong.Interceptor.IsLoginInterface;
import com.dsideal.QingLong.Interceptor.IsNumericInterface;
import com.dsideal.QingLong.Render.ImageRender; import com.dsideal.QingLong.Render.ImageRender;
import com.dsideal.QingLong.Util.AsposeUtil; import com.dsideal.QingLong.Util.AsposeUtil;
import com.dsideal.QingLong.Util.CommonUtil; import com.dsideal.QingLong.Util.CommonUtil;
@ -115,8 +116,10 @@ public class YunXiaoController extends Controller {
/** /**
* *
*/ */
// http://10.10.21.20:9000/QingLong/yx/LessonConstructionExportExcel?type_id=1
// http://10.10.21.20:9000/QingLong/yx/LessonConstructionExportExcel?type_id=2 // http://10.10.21.20:9000/QingLong/yx/LessonConstructionExportExcel?type_id=2
@Before(GET.class) @Before(GET.class)
@IsNumericInterface({"type_id"})
public void LessonConstructionExportExcel(int type_id) throws Exception { public void LessonConstructionExportExcel(int type_id) throws Exception {
List<Record> list1 = ym.LessonConstructionInfoByStageSubject(); List<Record> list1 = ym.LessonConstructionInfoByStageSubject();
List<Record> list2 = ym.LessonConstructionInfoByStageSubjectBook(); List<Record> list2 = ym.LessonConstructionInfoByStageSubjectBook();
@ -162,24 +165,47 @@ public class YunXiaoController extends Controller {
/** /**
* *
*/ */
// http://10.10.21.20:9000/QingLong/yx/LessonConstructionInfoByXzqhSchool
// http://10.10.21.20:9000/QingLong/yx/LessonConstructionInfoByXzqhSchool?type_id=1 // http://10.10.21.20:9000/QingLong/yx/LessonConstructionInfoByXzqhSchool?type_id=1
// http://10.10.21.20:9000/QingLong/yx/LessonConstructionInfoByXzqhSchool?type_id=2
@Before(GET.class) @Before(GET.class)
public void LessonConstructionInfoByXzqhSchool(int type_id) { @IsNumericInterface({"type_id"})
public void LessonConstructionInfoByXzqhSchool(int type_id) throws Exception {
List<Record> list1 = ym.LessonConstructionInfoByXzqh(); List<Record> list1 = ym.LessonConstructionInfoByXzqh();
List<Record> list2 = ym.LessonConstructionInfoByXzqhStage(); List<Record> list2 = ym.LessonConstructionInfoByXzqhStage();
List<Record> list3 = ym.LessonConstructionInfoByXzqhSchool(); List<Record> list3 = ym.LessonConstructionInfoByXzqhSchool();
List<Record> list4 = ym.LessonConstructionInfo(); List<Record> list4 = ym.LessonConstructionInfo();
YunXiaoExportExcelUtil exporter = new YunXiaoExportExcelUtil(); YunXiaoExportExcelUtil exporter = new YunXiaoExportExcelUtil();
String fileName = UUID.randomUUID() + ".xlsx"; String fileName = UUID.randomUUID() + ".xlsx";
String tmpFile = CommonUtil.basePath + File.separator + fileName; String excelPath = CommonUtil.basePath + File.separator + fileName;
exporter.LessonConstructionInfoByXzqhSchool(tmpFile, list1, list2, list3, list4); exporter.LessonConstructionInfoByXzqhSchool(excelPath, list1, list2, list3, list4);
//提供文件路径
Kv kv = Kv.create(); //2、提供EXCEL
kv.set("success", true); //文件名称
kv.set("message", "生成成功!"); String excel_filename = "按区域、学校统计课程建设情况.xlsx";
kv.set("url", CommonUtil.getServerUrl(getRequest()) + "/Excel/" + fileName); String pdfName = "按区域、学校统计课程建设情况.pdf";
renderJson(kv); if (type_id < 2) {
renderFile(new File(excelPath), excel_filename);
return;
}
//3、提供pdf预览
String pdfPath = excelPath.replace(".xlsx", ".pdf");
AsposeUtil.xls2pdf(excelPath, pdfPath);
//提供带中文文件名的pdf流
HttpServletResponse response = getResponse();
response.reset();
response.setContentType("application/pdf;charset=UTF-8");
response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(pdfName, "UTF-8"));//这里的名字并不起作用
OutputStream out = response.getOutputStream();
PDDocument document = Loader.loadPDF(FileUtil.readBytes(pdfPath)); //加载pdf
PDDocumentInformation info = document.getDocumentInformation(); //获得文档属性对象
//对比原来的代码就是在文件流写入响应体之前经过一下pdfbox修改标题属性然后pdfbox的save方法可以直接写入到响应体中。
info.setTitle(pdfName); //修改标题属性 这个标题会被展示
document.setDocumentInformation(info);
document.save(out); //修改完直接输出到响应体中
document.close();
out.close();
renderNull();
} }
/** /**

Loading…
Cancel
Save