update 会员信息表-下载会员批复文件pdf
This commit is contained in:
+3
-1
@@ -268,7 +268,9 @@ public class approvalDocumentNumberController extends JeroController<ApprovalDoc
|
|||||||
|
|
||||||
outputStream = response.getOutputStream();
|
outputStream = response.getOutputStream();
|
||||||
outputStream.write(bos.toByteArray());
|
outputStream.write(bos.toByteArray());
|
||||||
} catch (Exception e) {
|
} catch (JeroBootException e) {
|
||||||
|
throw new JeroBootException(e.getMessage());
|
||||||
|
}catch (Exception e) {
|
||||||
log.error("报错:",e);
|
log.error("报错:",e);
|
||||||
} finally {
|
} finally {
|
||||||
if (bos != null) {
|
if (bos != null) {
|
||||||
|
|||||||
+38
-24
@@ -1,13 +1,17 @@
|
|||||||
package com.jero.approvalDocumentNumber.service;
|
package com.jero.approvalDocumentNumber.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DatePattern;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.itextpdf.text.DocumentException;
|
||||||
import com.itextpdf.text.pdf.AcroFields;
|
import com.itextpdf.text.pdf.AcroFields;
|
||||||
import com.itextpdf.text.pdf.BaseFont;
|
import com.itextpdf.text.pdf.BaseFont;
|
||||||
import com.itextpdf.text.pdf.PdfReader;
|
import com.itextpdf.text.pdf.PdfReader;
|
||||||
import com.itextpdf.text.pdf.PdfStamper;
|
import com.itextpdf.text.pdf.PdfStamper;
|
||||||
import com.jero.approvalDocumentNumber.entity.ApprovalDocumentNumber;
|
import com.jero.approvalDocumentNumber.entity.ApprovalDocumentNumber;
|
||||||
import com.jero.approvalDocumentNumber.mapper.ApprovalDocumentNumberMapper;
|
import com.jero.approvalDocumentNumber.mapper.ApprovalDocumentNumberMapper;
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
import com.jero.standards.memberinfo.entity.MemberInfo;
|
import com.jero.standards.memberinfo.entity.MemberInfo;
|
||||||
import com.jero.standards.memberinfo.mapper.MemberInfoMapper;
|
import com.jero.standards.memberinfo.mapper.MemberInfoMapper;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -15,7 +19,9 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +59,13 @@ public class ApprovalDocumentNumberService extends ServiceImpl<ApprovalDocumentN
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void downloadApprovalPdf(String companyName, String year,
|
public void downloadApprovalPdf(String companyName, String year,
|
||||||
String effectiveDate, PdfStamper pdfStamper, ByteArrayOutputStream bos) throws Exception {
|
String effectiveDate, PdfStamper pdfStamper, ByteArrayOutputStream bos) {
|
||||||
|
LambdaQueryWrapper<ApprovalDocumentNumber> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(ApprovalDocumentNumber::getDateYear,year);
|
||||||
|
ApprovalDocumentNumber approval = approvalMapper.selectOne(wrapper);
|
||||||
|
if (approval == null){
|
||||||
|
throw new JeroBootException(year+"年批复文号为空");
|
||||||
|
}
|
||||||
ClassLoader classLoader = ApprovalDocumentNumberService.class.getClassLoader();
|
ClassLoader classLoader = ApprovalDocumentNumberService.class.getClassLoader();
|
||||||
String fontPath = classLoader.getResource("template/simfang.ttf").getPath();
|
String fontPath = classLoader.getResource("template/simfang.ttf").getPath();
|
||||||
if (fontPath.startsWith("/")){
|
if (fontPath.startsWith("/")){
|
||||||
@@ -64,31 +76,33 @@ public class ApprovalDocumentNumberService extends ServiceImpl<ApprovalDocumentN
|
|||||||
templatePath = templatePath.substring(1);
|
templatePath = templatePath.substring(1);
|
||||||
}
|
}
|
||||||
/* 使用中文字体 */
|
/* 使用中文字体 */
|
||||||
BaseFont baseFont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
BaseFont baseFont = null;
|
||||||
|
try {
|
||||||
|
baseFont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
||||||
|
//模板路径
|
||||||
|
if (templatePath == null) {
|
||||||
|
log.error("会员批复文件pdf模板为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PdfReader pdfReader = new PdfReader(templatePath);
|
||||||
|
|
||||||
//模板路径
|
pdfStamper = new PdfStamper(pdfReader, bos);
|
||||||
if (templatePath == null) {
|
|
||||||
log.error("会员批复文件pdf模板为空");
|
AcroFields form = pdfStamper.getAcroFields();
|
||||||
return;
|
form.addSubstitutionFont(baseFont);
|
||||||
|
|
||||||
|
form.setField("companyName", companyName + ":");
|
||||||
|
form.setField("dateYear", year);
|
||||||
|
form.setField("approvalDocumentNumber", approval.getApprovalDocumentNumber());
|
||||||
|
String date = DateUtil.parseDate(effectiveDate).toString(DatePattern.CHINESE_DATE_PATTERN);
|
||||||
|
form.setField("createTime", date);
|
||||||
|
//设置不可编辑
|
||||||
|
pdfStamper.setFormFlattening(true);
|
||||||
|
pdfStamper.close();
|
||||||
|
pdfReader.close();
|
||||||
|
} catch (DocumentException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
PdfReader pdfReader = new PdfReader(templatePath);
|
|
||||||
|
|
||||||
pdfStamper = new PdfStamper(pdfReader, bos);
|
|
||||||
|
|
||||||
AcroFields form = pdfStamper.getAcroFields();
|
|
||||||
form.addSubstitutionFont(baseFont);
|
|
||||||
LambdaQueryWrapper<ApprovalDocumentNumber> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.eq(ApprovalDocumentNumber::getDateYear,year);
|
|
||||||
ApprovalDocumentNumber approval = approvalMapper.selectOne(wrapper);
|
|
||||||
form.setField("companyName", companyName + ":");
|
|
||||||
form.setField("dateYear", year);
|
|
||||||
form.setField("approvalDocumentNumber", approval.getApprovalDocumentNumber());
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
||||||
form.setField("createTime", effectiveDate);
|
|
||||||
//设置不可编辑
|
|
||||||
pdfStamper.setFormFlattening(true);
|
|
||||||
pdfStamper.close();
|
|
||||||
pdfReader.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user