|
|
|
@ -1,11 +1,14 @@
|
|
|
|
|
package com.dsideal.QingLong.MaxKB.Controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
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.Service.Impl.MaxKbImpl;
|
|
|
|
|
import com.dsideal.QingLong.MaxKB.Service.MaxKbService;
|
|
|
|
|
import com.dsideal.QingLong.MaxKB.Util.ExportExcelUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.AsposeUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.CommonUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.SessionKit;
|
|
|
|
|
import com.jfinal.aop.Before;
|
|
|
|
@ -16,8 +19,15 @@ import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.jfinal.ext.interceptor.GET;
|
|
|
|
|
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.IOException;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
@ -108,19 +118,43 @@ public class MaxKbController extends Controller {
|
|
|
|
|
*
|
|
|
|
|
* @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)
|
|
|
|
|
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);
|
|
|
|
|
ExportExcelUtil exporter = new ExportExcelUtil();
|
|
|
|
|
String fileName = UUID.randomUUID() + ".xlsx";
|
|
|
|
|
String tmpFile = CommonUtil.basePath+File.separator + fileName;
|
|
|
|
|
exporter.exportToExcel(tmpFile, list);
|
|
|
|
|
//提供文件路径
|
|
|
|
|
Kv kv = Kv.create();
|
|
|
|
|
kv.set("success", true);
|
|
|
|
|
kv.set("message", "生成成功!");
|
|
|
|
|
kv.set("url", CommonUtil.getServerUrl(getRequest())+ "/Excel/" + fileName);
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
String excelPath = CommonUtil.basePath + File.separator + fileName;
|
|
|
|
|
exporter.exportToExcel(excelPath, list);
|
|
|
|
|
|
|
|
|
|
//2、提供EXCEL
|
|
|
|
|
//文件名称
|
|
|
|
|
String excel_filename = "按区域、学校统计课程建设情况.xlsx";
|
|
|
|
|
String pdfName = "按区域、学校统计课程建设情况.pdf";
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|