|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.dsideal.QingLong.YunXiao.Controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.dsideal.QingLong.Interceptor.EmptyInterface;
|
|
|
|
|
import com.dsideal.QingLong.Interceptor.IsLoginInterface;
|
|
|
|
|
import com.dsideal.QingLong.Render.ImageRender;
|
|
|
|
@ -15,9 +16,15 @@ import com.jfinal.ext.interceptor.POST;
|
|
|
|
|
import com.jfinal.kit.Kv;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Page;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import org.apache.pdfbox.Loader;
|
|
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
|
|
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
@ -108,26 +115,48 @@ public class YunXiaoController extends Controller {
|
|
|
|
|
/**
|
|
|
|
|
* 课程建设统计报表导出
|
|
|
|
|
*/
|
|
|
|
|
// http://10.10.21.20:9000/QingLong/yx/LessonConstructionExportExcel
|
|
|
|
|
// http://10.10.21.20:9000/QingLong/yx/LessonConstructionExportExcel?type_id=2
|
|
|
|
|
@Before(GET.class)
|
|
|
|
|
public void LessonConstructionExportExcel() {
|
|
|
|
|
public void LessonConstructionExportExcel(int type_id) throws Exception {
|
|
|
|
|
List<Record> list1 = ym.LessonConstructionInfoByStageSubject();
|
|
|
|
|
List<Record> list2 = ym.LessonConstructionInfoByStageSubjectBook();
|
|
|
|
|
List<Record> list3 = ym.previewRank();
|
|
|
|
|
|
|
|
|
|
//1、生成Excel
|
|
|
|
|
YunXiaoExportExcelUtil exporter = new YunXiaoExportExcelUtil();
|
|
|
|
|
//使用guid生成一个临时文件名,然后拼接到tmpDir后面,生成完整的临时文件路径
|
|
|
|
|
//文件上传路径
|
|
|
|
|
String fileName = UUID.randomUUID() + ".xlsx";
|
|
|
|
|
String tmpFile = CommonUtil.basePath + File.separator + fileName;
|
|
|
|
|
exporter.LessonConstructionExportExcel(tmpFile, list1, list2, list3);
|
|
|
|
|
String excelPath = CommonUtil.basePath + File.separator + fileName;
|
|
|
|
|
exporter.LessonConstructionExportExcel(excelPath, list1, list2, list3);
|
|
|
|
|
|
|
|
|
|
//提供文件路径
|
|
|
|
|
Kv kv = Kv.create();
|
|
|
|
|
kv.set("success", true);
|
|
|
|
|
kv.set("message", "生成成功!");
|
|
|
|
|
kv.set("url", CommonUtil.getServerUrl(getRequest()) + "/Excel/" + fileName);
|
|
|
|
|
renderJson(kv);
|
|
|
|
|
//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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|