From f9097fe38a555c5236001793d01b1661fc340abf Mon Sep 17 00:00:00 2001 From: zhangyanli Date: Wed, 15 May 2024 14:51:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A4=E9=80=9A=E7=B1=BB=E5=9E=8B=E4=B8=80?= =?UTF-8?q?=E6=9C=9F=E4=B8=80=E6=A1=A3=E6=A1=A3=E6=A1=88=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/archivesUtil/HomeAbsHandler.java | 87 +++++++++++++++++++ .../dsno3/eduArchives/ArchivesMapper.xml | 6 +- .../mybatis/dsno3/eduStudy/ClassMapper.xml | 3 +- 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/zcloud/util/archivesUtil/HomeAbsHandler.java diff --git a/src/main/java/com/zcloud/util/archivesUtil/HomeAbsHandler.java b/src/main/java/com/zcloud/util/archivesUtil/HomeAbsHandler.java new file mode 100644 index 0000000..190af8e --- /dev/null +++ b/src/main/java/com/zcloud/util/archivesUtil/HomeAbsHandler.java @@ -0,0 +1,87 @@ +package com.zcloud.util.archivesUtil; + +import com.zcloud.entity.PageData; +import com.zcloud.mapper.dsno3.eduArchives.ArchivesMapper; +import com.zcloud.mapper.dsno3.eduStudy.ClassMapper; +import com.zcloud.service.eduArchives.ArchivesService; +import com.zcloud.util.Const; +import com.zcloud.util.DateUtil; +import com.zcloud.util.WordToPdfUtil; +import fr.opensagres.xdocreport.document.IXDocReport; +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 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.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +/** + * 说明:安全培训教材会审表 + * 作者:wangxuan + * 官网:www.zcloudchina.com + * + * @author wangxuan + */ +@Component +public class HomeAbsHandler extends AbsHandlerBatchExport { + @Autowired + private ClassMapper classMapper; + + @Autowired + private ArchivesService archivesService; + + @Autowired + private ArchivesMapper archivesMapper; + + /** + * @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 { + String projectPath = pd.getString("projectPath"); + String now = DateUtil.getSdfTimesSSS(); + ArrayList files = new ArrayList<>(); //最外层 + PageData clazz = classMapper.findById(pd); + List studentList = archivesMapper.getStudents(pd); + + SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); //日期格式 + SimpleDateFormat dayformat = new SimpleDateFormat("yyyy年MM月"); //日期格式 + + File file = new File(projectPath + Const.FILEPATHWORDTEMPLATE + "traffic-records1.docx"); + InputStream mbwj = new FileInputStream(file); + //注册xdocreport实例并加载FreeMarker模板引擎 + IXDocReport report = XDocReportRegistry.getRegistry().loadReport(mbwj, TemplateEngineKind.Freemarker); + //创建xdocreport上下文对象 + IContext context = report.createContext(); + + context.put("value1", clazz.get("INDUSTRY_END_NAME") + "企业"); + context.put("value2", clazz.get("CORP_NAME")); + context.put("value3", dayformat.format(dateformat.parse(clazz.getString("START_TIME")))); + FieldsMetadata fm = report.createFieldsMetadata(); + //输出到本地目录 + FileOutputStream out = new FileOutputStream(new File(projectPath + Const.FILEPATHFILE + "首页-" + now + ".docx")); + report.process(context, out); + WordToPdfUtil.docToPdf(projectPath + Const.FILEPATHFILE + "首页-" + now + ".docx", projectPath + Const.FILEPATHFILE + "首页-" + now + ".pdf"); + //删除本地word pdf + File word = new File(projectPath + Const.FILEPATHFILE + "首页-" + now + ".docx"); + word.delete(); + return new File(projectPath + Const.FILEPATHFILE + "首页-" + now + ".pdf"); + } + + @Override + public void afterPropertiesSet() throws Exception { + BatchExportFactory.register("archives111", this); + } +} diff --git a/src/main/resources/mybatis/dsno3/eduArchives/ArchivesMapper.xml b/src/main/resources/mybatis/dsno3/eduArchives/ArchivesMapper.xml index e6c0b94..2d75c3a 100644 --- a/src/main/resources/mybatis/dsno3/eduArchives/ArchivesMapper.xml +++ b/src/main/resources/mybatis/dsno3/eduArchives/ArchivesMapper.xml @@ -323,6 +323,8 @@ corp.CORP_NAME, corp.CORP_TYPE_NAME, corp.CORP_TYPE4, + corp.INDUSTRY_TYPE as INDUSTRY_ALL_TYPE, + corp.INDUSTRY_NAME as INDUSTRY_ALL_NAME, us1.SIGN_PICTURE RECORDOR_SIGN, us2.SIGN_PICTURE ASSESSOR_SIGN, us3.SIGN_PICTURE SAFETYDEPTOR_SIGN @@ -424,14 +426,14 @@ BUS_STAGESTUDENTRELATION s ON s.STUDENT_ID = f.STUDENT_ID left join bus_class c on f.class_id = c.class_id LEFT JOIN BUS_POST_TYPE p on p.POSTTYPE_ID = c.POSTTYPE + LEFT JOIN BUS_CORP_INFO ci on ci.CORPINFO_ID = c.CORPINFO_ID LEFT JOIN BUS_TRAINING_TYPE t on t.TRAININGTYPE_ID = c.TRAINTYPE - LEFT JOIN BUS_INDUSTRY_TYPE iei on iei.INDUSTRYTYPE_ID = c.INDUSTRY_END_ID + LEFT JOIN BUS_INDUSTRY_TYPE iei on iei.INDUSTRYTYPE_ID = SUBSTRING_INDEX(ci.INDUSTRY_TYPE,',',-1) LEFT JOIN BUS_TRAIN_LEVEL_TYPE tlt on tlt.TRAINLEVEL_ID = c.TRAINLEVEL LEFT JOIN SYS_USERINFO ui on ui.USER_ID = f.USER_ID LEFT JOIN SYS_DICTIONARIES cl on cl.DICTIONARIES_ID = ui.DEGREE_OF_EDUCATION LEFT JOIN SYS_DICTIONARIES_CORP dd on dd.DICTIONARIES_ID = ui.DUTIES LEFT JOIN SYS_DICTIONARIES_CORP dt on dt.DICTIONARIES_ID = ui.TITLE - LEFT JOIN BUS_CORP_INFO ci on ci.CORPINFO_ID = c.CORPINFO_ID left join BUS_INDUSTRY_TYPE it on it.INDUSTRYTYPE_ID = ci.INDUSTRY_TYPE WHERE f.STUDENT_ID = #{STUDENT_ID} AND s.ISDELETE = '0' diff --git a/src/main/resources/mybatis/dsno3/eduStudy/ClassMapper.xml b/src/main/resources/mybatis/dsno3/eduStudy/ClassMapper.xml index 59c452d..560ec20 100644 --- a/src/main/resources/mybatis/dsno3/eduStudy/ClassMapper.xml +++ b/src/main/resources/mybatis/dsno3/eduStudy/ClassMapper.xml @@ -301,6 +301,7 @@ CONCAT_WS('-',IF( t.NAME= '',null ,t.NAME ),IF( lei.NAME= '',null , lei.NAME ),IF( p.NAME= '',null , p.NAME ),IF( tlt.NAME= '',null , tlt.NAME )) TYPENAME, tlt.NAME TRAINLEVEL_NAME, + lei.NAME as INDUSTRY_END_NAME, bci.CORP_NAME, bci.PLAN_DEPARTMENT, us.SIGN_PICTURE AS SAFETYDEPTOR_URL @@ -311,7 +312,7 @@ left join bus_corp_info bci on f.CORPINFO_ID = bci.CORPINFO_ID LEFT JOIN BUS_TRAINING_TYPE t on t.TRAININGTYPE_ID = f.TRAINTYPE LEFT JOIN BUS_TRAIN_LEVEL_TYPE tlt on tlt.TRAINLEVEL_ID = f.TRAINLEVEL - LEFT JOIN bus_industry_type lei ON lei.INDUSTRYTYPE_ID = f.INDUSTRY_END_ID + LEFT JOIN bus_industry_type lei ON lei.INDUSTRYTYPE_ID = SUBSTRING_INDEX(bci.INDUSTRY_TYPE,',',-1) left join sys_user_sign us on us.USERSIGNID = f.SAFETYDEPTOR WHERE f.CLASS_ID = #{CLASS_ID}