Commit 9b93723e authored by 廖旭伟's avatar 廖旭伟

证照目录是否转pdf设置功能

parent e71379ab
......@@ -184,17 +184,6 @@
<artifactId>javase</artifactId>
<version>3.4.1</version>
</dependency>
<!-- documents4j word转pdf -->
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-local</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-transformer-msoffice-word</artifactId>
<version>1.1.5</version>
</dependency>
</dependencies>
<build>
......
package com.mortals.xhx.common.utils;
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
public class PdfUtil {
protected static Log log = LogFactory.getLog(PdfUtil.class);
/**
  * word转pdf
* @param wordFilePath word文件路径
* @param pdfFilePath pdf文件路径
* @return 成功或失败
*/
public static boolean docxToPdf(String wordFilePath, String pdfFilePath) throws Exception {
boolean result = false;
InputStream inputStream = null;
OutputStream outputStream = null;
File inputFile = new File(wordFilePath);
File outputFile = new File(pdfFilePath);
try {
inputStream = new FileInputStream(inputFile);
outputStream = new FileOutputStream(outputFile);
//IConverter converter = LocalConverter.builder().build();
IConverter converter = SingletonLocalConverter.getInstance().getConverter();
converter.convert(inputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
outputStream.close();
inputStream.close();
result = true;
} catch (Exception e) {
log.error("[documents4J] word转pdf失败:",e);
e.printStackTrace();
}finally {
if (outputStream != null) {
outputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
}
return result;
}
public static void main(String[] args) {
String filepath= "D:\\mortals\\app\\data\\test\\12a.docx";
String outpath= "D:\\mortals\\app\\data\\test\\12aa.pdf";
try{
long old = System.currentTimeMillis();
docxToPdf(filepath, outpath);
long now = System.currentTimeMillis();
System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); // 转化用时
}catch(Exception e) {
e.printStackTrace();
}
}
}
package com.mortals.xhx.common.utils;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;
public class SingletonLocalConverter {
private IConverter converter;
public IConverter getConverter() {
return converter;
}
private SingletonLocalConverter() {
converter = LocalConverter.builder().build();
}
private static SingletonLocalConverter single = null;
public static SingletonLocalConverter getInstance(){
if (single == null) {
single = new SingletonLocalConverter();
}
return single;
}
}
......@@ -264,8 +264,8 @@ public class WordUtil {
public static void main(String[] args){
String wordp = "D:\\mortals\\app\\data\\test\\12a.docx";
String pdfP = "D:\\mortals\\app\\data\\test\\12a.pdf";
String wordp = "D:\\mortals\\app\\data\\test\\222.docx";
String pdfP = "D:\\mortals\\app\\data\\test\\222a.pdf";
//convertWordToPDF(wordp,pdfP);
try {
wordToPdf(wordp,pdfP);
......
......@@ -89,6 +89,8 @@ public class CertificateCatalogEntity extends CertificateCatalogVo {
*/
private String excelFile;
private Integer isPdf;
public CertificateCatalogEntity(){}
......@@ -345,8 +347,13 @@ public class CertificateCatalogEntity extends CertificateCatalogVo {
this.excelFile = excelFile;
}
public Integer getIsPdf() {
return isPdf;
}
public void setIsPdf(Integer isPdf) {
this.isPdf = isPdf;
}
@Override
public int hashCode() {
......
......@@ -208,7 +208,11 @@ public class ApplyLogServiceImpl extends AbstractCRUDServiceImpl<ApplyLogDao, Ap
applyLogEntity.setCatalogName(catalog.getCatalogName());
//applyLogEntity.setFormTemplate(catalog.getFormContent());
DocTemplateVO docTemplate = new DocTemplateVO(catalog.getTemplateUrl(),applyLogEntity.getFormContent());
String paths = preview(docTemplate, context,true);
boolean hasPDF = false;
if(catalog.getIsPdf()!=null && catalog.getIsPdf()==1){
hasPDF = true;
}
String paths = preview(docTemplate, context,hasPDF);
String[] vals = paths.split(";");
if(vals.length==3) {
applyLogEntity.setCertificateUrl(vals[2]);
......@@ -358,8 +362,8 @@ public class ApplyLogServiceImpl extends AbstractCRUDServiceImpl<ApplyLogDao, Ap
if(hasPDF) {
String pdfName = mergedocPath.substring(0,mergedocPath.indexOf(".")) + ".pdf";
String pdfPath = rootPath + pdfName;
//WordUtil.convertWordToPDF(mergedoc, pdfPath);
PdfUtil.docxToPdf(mergedoc, pdfPath);
WordUtil.convertWordToPDF(mergedoc, pdfPath);
//PdfUtil.docxToPdf(mergedoc, pdfPath);
//下载地址拼装
String returnStr = mergedocPath + ";" + "/preview/" + fileName + ";" + pdfName;
return returnStr;
......@@ -563,5 +567,4 @@ public class ApplyLogServiceImpl extends AbstractCRUDServiceImpl<ApplyLogDao, Ap
}
}
}
\ No newline at end of file
......@@ -28,7 +28,7 @@
<result property="updateTime" column="updateTime" />
<result property="deviceId" column="deviceId" />
<result property="excelFile" column="excelFile" />
<result property="isPdf" column="isPdf" />
</resultMap>
......@@ -104,23 +104,26 @@
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('excelFile') or colPickMode == 1 and data.containsKey('excelFile')))">
a.excelFile,
</if>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('isPdf') or colPickMode == 1 and data.containsKey('isPdf')))">
a.isPdf,
</if>
</trim>
</sql>
<!-- 新增 区分主键自增加还是业务插入 -->
<insert id="insert" parameterType="CertificateCatalogEntity" useGeneratedKeys="true" keyProperty="id">
insert into mortals_xhx_certificate_catalog
(catalogName,catalogCode,holderType,industryId,classifyId,transverse,portrait,inspect,templateName,templateUrl,formContent,exampleUrl,status,printerName,printerIp,paperSource,createUserId,createTime,updateUserId,updateTime,deviceId,excelFile)
(catalogName,catalogCode,holderType,industryId,classifyId,transverse,portrait,inspect,templateName,templateUrl,formContent,exampleUrl,status,printerName,printerIp,paperSource,createUserId,createTime,updateUserId,updateTime,deviceId,excelFile,isPdf)
VALUES
(#{catalogName},#{catalogCode},#{holderType},#{industryId},#{classifyId},#{transverse},#{portrait},#{inspect},#{templateName},#{templateUrl},#{formContent},#{exampleUrl},#{status},#{printerName},#{printerIp},#{paperSource},#{createUserId},#{createTime},#{updateUserId},#{updateTime},#{deviceId},#{excelFile})
(#{catalogName},#{catalogCode},#{holderType},#{industryId},#{classifyId},#{transverse},#{portrait},#{inspect},#{templateName},#{templateUrl},#{formContent},#{exampleUrl},#{status},#{printerName},#{printerIp},#{paperSource},#{createUserId},#{createTime},#{updateUserId},#{updateTime},#{deviceId},#{excelFile},#{isPdf})
</insert>
<!-- 批量新增 -->
<insert id="insertBatch" parameterType="paramDto">
insert into mortals_xhx_certificate_catalog
(catalogName,catalogCode,holderType,industryId,classifyId,transverse,portrait,inspect,templateName,templateUrl,formContent,exampleUrl,status,printerName,printerIp,paperSource,createUserId,createTime,updateUserId,updateTime,deviceId,excelFile)
(catalogName,catalogCode,holderType,industryId,classifyId,transverse,portrait,inspect,templateName,templateUrl,formContent,exampleUrl,status,printerName,printerIp,paperSource,createUserId,createTime,updateUserId,updateTime,deviceId,excelFile,isPdf)
VALUES
<foreach collection="data.dataList" item="item" index="index" separator="," >
(#{item.catalogName},#{item.catalogCode},#{item.holderType},#{item.industryId},#{item.classifyId},#{item.transverse},#{item.portrait},#{item.inspect},#{item.templateName},#{item.templateUrl},#{item.formContent},#{item.exampleUrl},#{item.status},#{item.printerName},#{item.printerIp},#{item.paperSource},#{item.createUserId},#{item.createTime},#{item.updateUserId},#{item.updateTime},#{item.deviceId},#{item.excelFile})
(#{item.catalogName},#{item.catalogCode},#{item.holderType},#{item.industryId},#{item.classifyId},#{item.transverse},#{item.portrait},#{item.inspect},#{item.templateName},#{item.templateUrl},#{item.formContent},#{item.exampleUrl},#{item.status},#{item.printerName},#{item.printerIp},#{item.paperSource},#{item.createUserId},#{item.createTime},#{item.updateUserId},#{item.updateTime},#{item.deviceId},#{item.excelFile},#{item.isPdf})
</foreach>
</insert>
......@@ -226,6 +229,9 @@
<if test="(colPickMode==0 and data.containsKey('excelFile')) or (colPickMode==1 and !data.containsKey('excelFile'))">
a.excelFile=#{data.excelFile},
</if>
<if test="(colPickMode==0 and data.containsKey('isPdf')) or (colPickMode==1 and !data.containsKey('isPdf'))">
a.isPdf=#{data.isPdf},
</if>
</trim>
<trim suffixOverrides="where" suffix="">
where
......@@ -442,6 +448,18 @@
</if>
</foreach>
</trim>
<trim prefix="isPdf=(case" suffix="ELSE isPdf end),">
<foreach collection="data.dataList" item="item" index="index" separator="" >
<choose>
<when test="(colPickMode==0 and item.containsKey('isPdf')) or (colPickMode==1 and !item.containsKey('isPdf'))">
when a.id=#{item.id} then #{item.isPdf}
</when>
<when test="(colPickMode==0 and item.containsKey('isPdfIncrement')) or (colPickMode==1 and !item.containsKey('isPdfIncrement'))">
when a.id=#{item.id} then ifnull(a.isPdf,0) + #{item.isPdfIncrement}
</when>
</choose>
</foreach>
</trim>
</trim>
where id in
<foreach collection="data.dataList" item="item" index="index" open="(" separator="," close=")">
......@@ -954,6 +972,15 @@
#{item}
</foreach>
</if>
<if test="conditionParamRef.containsKey('isPdf')">
<if test="conditionParamRef.isPdf != null ">
${_conditionType_} a.isPdf = #{${_conditionParam_}.isPdf}
</if>
<if test="conditionParamRef.isPdf == null">
${_conditionType_} a.isPdf is null
</if>
</if>
</sql>
<sql id="_orderCols_">
<if test="orderColList != null and !orderColList.isEmpty()">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment