2024-03-06 16:25:53 +08:00
|
|
|
|
package com.zcloud.util.archivesUtil;
|
|
|
|
|
|
|
|
|
|
import com.zcloud.service.eduArchives.ArchivesReviewRecordService;
|
|
|
|
|
import com.zcloud.service.eduArchives.ArchivesReviewService;
|
|
|
|
|
import com.zcloud.service.eduStudy.ClassCurriculumService;
|
|
|
|
|
import com.zcloud.service.eduStudy.ClassService;
|
|
|
|
|
import com.zcloud.service.eduStudy.CurriculumService;
|
|
|
|
|
import com.zcloud.entity.PageData;
|
|
|
|
|
import com.zcloud.entity.TrainingPlanDao;
|
|
|
|
|
import com.zcloud.service.corp.CorpInfoService;
|
|
|
|
|
import com.zcloud.util.*;
|
|
|
|
|
import fr.opensagres.xdocreport.document.IXDocReport;
|
|
|
|
|
import fr.opensagres.xdocreport.document.images.ByteArrayImageProvider;
|
|
|
|
|
import fr.opensagres.xdocreport.document.registry.XDocReportRegistry;
|
|
|
|
|
import fr.opensagres.xdocreport.template.IContext;
|
|
|
|
|
import fr.opensagres.xdocreport.template.TemplateEngineKind;
|
|
|
|
|
import fr.opensagres.xdocreport.template.formatter.FieldsMetadata;
|
|
|
|
|
import fr.opensagres.xdocreport.template.formatter.NullImageBehaviour;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 说明:安全培训教材会审表
|
|
|
|
|
* 作者:wangxuan
|
|
|
|
|
* 官网:www.zcloudchina.com
|
|
|
|
|
*
|
|
|
|
|
* @author wangxuan
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
public class HsAbsHandler extends AbsHandlerBatchExport {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ClassService classService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CorpInfoService corpInfoService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ArchivesReviewService archivesReviewService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ArchivesReviewRecordService archivesReviewRecordService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private CurriculumService curriculumService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ClassCurriculumService classCurriculumService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description: 返回pdf路径
|
|
|
|
|
* @Author: dearLin
|
|
|
|
|
* @Date: 2023/3/20/020 10:41
|
|
|
|
|
* @Param: [com.zcloud.entity.PageData] [pageData]
|
|
|
|
|
* @Return: java.lang.String
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public File batchExport(PageData pd, String nowZip) throws Exception {
|
|
|
|
|
ArrayList<File> outsideFiles = new ArrayList<>(); //最外层
|
|
|
|
|
List<PageData> varList = classCurriculumService.findByClassID(pd);
|
|
|
|
|
String projectPath = pd.getString("projectPath");
|
|
|
|
|
for (PageData pageData : varList) {
|
|
|
|
|
String now = DateUtil.getSdfTimesSSS();
|
|
|
|
|
pd.put("CURRICULUM_ID",pageData.getString("CURRICULUM_ID"));
|
|
|
|
|
// 公章
|
|
|
|
|
PageData corpinfo = corpInfoService.findById(pd);
|
|
|
|
|
String path = Const.HTTPFILEURL + corpinfo.getString("OFFICIAL_SEAL_PATH");
|
|
|
|
|
URL url = new URL(path);
|
|
|
|
|
ByteArrayImageProvider byteArrayImageProvider = new ByteArrayImageProvider(url.openStream());//照片 读取网络路径
|
|
|
|
|
// 表头
|
|
|
|
|
PageData classInfo = classService.findById(pd);
|
|
|
|
|
PageData archInfo = archivesReviewService.findById(pd);
|
|
|
|
|
PageData curriculumInfo = curriculumService.findById(pd);
|
|
|
|
|
|
2024-03-12 17:20:55 +08:00
|
|
|
|
File file = new File(projectPath + Const.FILEPATHWORDTEMPLATE + "hs.docx");
|
2024-03-06 16:25:53 +08:00
|
|
|
|
InputStream mbwj = new FileInputStream(file);
|
|
|
|
|
//注册xdocreport实例并加载FreeMarker模板引擎
|
|
|
|
|
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(mbwj, TemplateEngineKind.Freemarker);
|
|
|
|
|
//创建xdocreport上下文对象
|
|
|
|
|
IContext context = report.createContext();
|
|
|
|
|
SimpleDateFormat formatdate = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
context.put("var0", Tools.notEmpty(curriculumInfo.getString("CURRICULUMNAME")) ? curriculumInfo.getString("CURRICULUMNAME") : "");
|
|
|
|
|
|
|
|
|
|
if (archInfo != null && archInfo.getString("CORP_NAME") != null) {
|
|
|
|
|
context.put("var1", archInfo.getString("CORP_NAME"));
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var1", Tools.notEmpty(classInfo.getString("CORP_NAME")) ? classInfo.getString("CORP_NAME") : "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (archInfo != null && archInfo.getString("CREATTIME") != null) {
|
|
|
|
|
Date creattime = formatter.parse(archInfo.getString("CREATTIME"));
|
|
|
|
|
context.put("var2", formatdate.format(creattime));
|
|
|
|
|
} else {
|
|
|
|
|
if (Tools.notEmpty(classInfo.getString("CREATTIME"))) {
|
|
|
|
|
Date creattime = formatter.parse(classInfo.getString("CREATTIME"));
|
|
|
|
|
context.put("var2", formatdate.format(creattime));
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var2", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.put("POSTTYPE_NAME", Tools.notEmpty(classInfo.getString("POSTTYPE_NAME")) ? classInfo.getString("POSTTYPE_NAME") : "");
|
|
|
|
|
|
|
|
|
|
if (archInfo != null && archInfo.getString("CODE") != null) {
|
|
|
|
|
context.put("var4", archInfo.getString("CODE"));
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var4", Tools.notEmpty(classInfo.getString("CODE")) ? classInfo.getString("CODE") : "");
|
|
|
|
|
}
|
|
|
|
|
if (archInfo != null && archInfo.getString("END_TIME") != null) {
|
|
|
|
|
Date END_TIME = formatter.parse(archInfo.getString("END_TIME"));
|
|
|
|
|
context.put("var5", formatdate.format(END_TIME));
|
|
|
|
|
} else {
|
|
|
|
|
if (Tools.notEmpty(classInfo.getString("END_TIME"))) {
|
|
|
|
|
Date END_TIME = formatter.parse(classInfo.getString("END_TIME"));
|
|
|
|
|
context.put("var5", formatdate.format(END_TIME));
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var5", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.put("var6", Tools.notEmpty(curriculumInfo.getString("INDUSTRY_ALL_NAME")) ? curriculumInfo.getString("INDUSTRY_ALL_NAME") : "");
|
|
|
|
|
|
|
|
|
|
if (archInfo != null && StringUtils.isNotEmpty(archInfo.getString("REVIEW_PERSON"))) {
|
|
|
|
|
context.put("var7", archInfo.getString("REVIEW_PERSON"));
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var7", " "); // 经费
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (archInfo != null && StringUtils.isNotEmpty(archInfo.getString("REVIEW_TIME"))) {
|
|
|
|
|
Date REVIEW_TIME = formatter.parse(archInfo.getString("REVIEW_TIME") + " 00:00:00");
|
|
|
|
|
context.put("var8", formatdate.format(REVIEW_TIME));
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var8", " "); // 会审时间
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<TrainingPlanDao> list1 = new ArrayList<>(); //一共多少行
|
|
|
|
|
if (archInfo != null) {
|
|
|
|
|
PageData reviewersParameter = new PageData();
|
|
|
|
|
reviewersParameter.put("ARCHIVES_REVIEW_ID", archInfo.getString("ARCHIVES_REVIEW_ID"));
|
|
|
|
|
List<PageData> archlist = archivesReviewRecordService.listAll(reviewersParameter); //列出TrainingSchedule列表
|
|
|
|
|
for (int i = 0; i < archlist.size(); i++) {
|
|
|
|
|
TrainingPlanDao trainingPlanDao = new TrainingPlanDao(); //每行的内容实体类
|
|
|
|
|
trainingPlanDao.setValue1((String) archlist.get(i).get("NAME"));
|
|
|
|
|
trainingPlanDao.setValue2((String) archlist.get(i).get("DEPARTMENT_NAME"));
|
|
|
|
|
trainingPlanDao.setValue3((String) archlist.get(i).get("DUTIES"));
|
|
|
|
|
trainingPlanDao.setValue4((String) archlist.get(i).get("CHECK_OPINION"));
|
|
|
|
|
if (Tools.notEmpty(archlist.get(i).getString("SIGN_PICTURE"))) {
|
|
|
|
|
String SIGN_PATH = Const.HTTPFILEURL + (String) archlist.get(i).getString("SIGN_PICTURE");
|
|
|
|
|
URL SIGN_URL = new URL(SIGN_PATH);
|
|
|
|
|
trainingPlanDao.setPic2(new ByteArrayImageProvider(SIGN_URL.openStream())); //照片 读取网络路径
|
|
|
|
|
}
|
|
|
|
|
trainingPlanDao.setValue6(String.valueOf(i + 1));
|
|
|
|
|
list1.add(trainingPlanDao);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
context.put("item", list1);
|
|
|
|
|
if (archInfo != null && archInfo.getString("enterpriseName") != null) {
|
|
|
|
|
context.put("var11", archInfo.getString("enterpriseName"));
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var11", Tools.notEmpty(classInfo.getString("enterpriseName")) ? classInfo.getString("enterpriseName") : ""); //会审地点
|
|
|
|
|
}
|
|
|
|
|
if (archInfo != null) {
|
|
|
|
|
context.put("var9", Tools.notEmpty(archInfo.getString("BOOK_NUM")) ? archInfo.getString("BOOK_NUM") : ""); //初版书号
|
|
|
|
|
if (archInfo.getString("REVIEW_OPINIONS") == null) {
|
|
|
|
|
context.put("var10", Tools.notEmpty("此教材符合相关文件要求,同意使用。")); //会审意见
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var10", archInfo.getString("REVIEW_OPINIONS")); //会审意见
|
|
|
|
|
}
|
|
|
|
|
pd.put("ARCHIVES_REVIEW_ID", archInfo.getString("ARCHIVES_REVIEW_ID"));
|
|
|
|
|
// List<PageData> archlist = archivesReviewRecordService.listAll(pd);!!!!!!!
|
|
|
|
|
} else {
|
|
|
|
|
context.put("var9", " "); //初版书号
|
|
|
|
|
context.put("var10", "此教材符合相关文件要求,同意使用。"); //会审意见
|
|
|
|
|
// context.put("archlist", null);
|
|
|
|
|
}
|
|
|
|
|
if (byteArrayImageProvider != null) {
|
|
|
|
|
context.put("pic", byteArrayImageProvider); // 公章
|
|
|
|
|
} else {
|
|
|
|
|
context.put("pic", " "); // 公章
|
|
|
|
|
}
|
|
|
|
|
FieldsMetadata fm = report.createFieldsMetadata();
|
|
|
|
|
// word模板中图片标签对应关系 pic---word模板中图片标签 item-- word模板中图片列表的遍历项,即模板中«@before-row[#list list2 as item]» 的item item.pic中的pic 为 后台实体类的图片字段名
|
|
|
|
|
fm.addFieldAsImage("pic", "pic", NullImageBehaviour.RemoveImageTemplate);
|
|
|
|
|
fm.addFieldAsImage("pic2", "item.pic2", NullImageBehaviour.RemoveImageTemplate);
|
|
|
|
|
//Word模板中的表格数据对应的集合类型
|
|
|
|
|
fm.load("pic", IContext.class, false);
|
|
|
|
|
fm.load("item", TrainingPlanDao.class, true);
|
|
|
|
|
FileOutputStream out = new FileOutputStream(new File(projectPath + Const.FILEPATHFILE + pageData.getString("CURRICULUMNAME") + "-" + now + ".docx"));
|
|
|
|
|
report.process(context, out);
|
|
|
|
|
|
|
|
|
|
WordToPdfUtil.docToPdf(projectPath + Const.FILEPATHFILE + pageData.getString("CURRICULUMNAME") + "-" + now + ".docx",
|
|
|
|
|
projectPath + Const.FILEPATHFILE + pageData.getString("CURRICULUMNAME") + "-" + now + ".pdf");
|
|
|
|
|
//删除本地word pdf
|
|
|
|
|
File word = new File(projectPath + Const.FILEPATHFILE + pageData.getString("CURRICULUMNAME") + "-" + now + ".docx");
|
|
|
|
|
word.delete();
|
|
|
|
|
File pdf = new File(projectPath + Const.FILEPATHFILE + pageData.getString("CURRICULUMNAME") + "-" + now + ".pdf");
|
|
|
|
|
outsideFiles.add(pdf);
|
|
|
|
|
}
|
|
|
|
|
FileZip.zipList(projectPath + Const.TEMPZIPFILES + "安全培训教材会审表-" + nowZip + ".zip", outsideFiles);
|
|
|
|
|
for (File filepath : outsideFiles) {
|
|
|
|
|
filepath.delete(); //删除缓存文件
|
|
|
|
|
}
|
|
|
|
|
File file = new File(projectPath + Const.TEMPZIPFILES + "安全培训教材会审表-" + nowZip + ".zip");
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterPropertiesSet() throws Exception {
|
|
|
|
|
BatchExportFactory.register("archives100", this);
|
|
|
|
|
}
|
|
|
|
|
}
|