Commit f79cddf9 by wenyang Committed by hongzhong

经纪人签署联合销售接口2(多人联合签名,数据动态展示PDF中)

parent d76f1994
......@@ -48,7 +48,10 @@ import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.PageHelper;
import com.google.common.base.Strings;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
......@@ -58,6 +61,7 @@ import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.draw.LineSeparator;
import com.libs.pdf.PDFTemplate;
import com.yd.api.customer.service.CustomerService;
import com.yd.api.customer.vo.register.RegisterRequestVO;
......@@ -4484,11 +4488,10 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
byte[] imgBytes = Base64.getDecoder().decode(imgStr);
String templatePDF = PDFConfiguration.getProperty("unionSales.pdf.template");
String logoPath = PDFConfiguration.getProperty("unionSales.pdf.template");
//模板文件生成临时文件目录
String tmpPathPDF = PDFConfiguration.getProperty("unionSales.pdf.temp.path");
//PDF模板输出临时文件
String templateResultPDF = tmpPathPDF + "signedUnionSalesTemp.pdf";
//PDF模板输出结果文件
String savePath = tmpPathPDF + "signedUnionSales.pdf";
......@@ -4497,7 +4500,7 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
String signPicture = this.getImgStrFilePath(tmpPathPDF, "signUnionSales.png", inputStream);
//生成最终版本的pdf
Map<String,Object> retMap = generateFinalPdf(templatePDF, templateResultPDF, savePath, signPicture, unionSalesPractitioners);
Map<String,Object> retMap = generateFinalPdf(logoPath, savePath, signPicture, unionSalesPractitioners,unionSalesPractitionerInfo);
//上传至oss ossService
String ossPath = this.putContractFileToOSS("unionSales", savePath, unionSalesId);
......@@ -4530,28 +4533,32 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
/**
* 生成最终版本的pdf
* @param filePath 模板路径
* @param finalPathTemp 临时文件路径
* @param logoPaht logo图片路径
* @param savePath 最终版本的pdf生成路径
* @param signPicture 签名图片
* @param unionSalesPractitioners 业务数据
* @param unionSalesPractitioners 动态组拼PDF数据集合对象
* @param unionSalesPractitioner
* @param void
* @author Yan Wenyang
*/
public static Map<String,Object> generateFinalPdf(String filePath,String filePathTemp,String savePath,String signPicture, List<UnionSalesPractitionerInfo> unionSalesPractitioners) {
public static Map<String,Object> generateFinalPdf(String logoPath,String savePath,String signPicture, List<UnionSalesPractitionerInfo> unionSalesPractitioners,UnionSalesPractitionerInfo unionSalesPractitioner) {
Document document = new Document();
PdfWriter writer = null;
Map<String,Object> retMap = new HashMap<String,Object>();
FileOutputStream out = null;
try {
out = new FileOutputStream(filePathTemp);
out = new FileOutputStream(savePath);
writer = PdfWriter.getInstance(document, out);
document.open();
generatePdfChunk(document, logoPath, unionSalesPractitioners, "1", unionSalesPractitioner);
//动态生成PDF表格
Paragraph paragraph = generatePdfTable(unionSalesPractitioners);
document.add(paragraph);
generatePdfChunk(document, logoPath, unionSalesPractitioners, "2", unionSalesPractitioner);
//动态把图片插入PDF中
if(unionSalesPractitioners != null && unionSalesPractitioners.size() > 0){
String salesSignUlr = unionSalesPractitioners.get(0).getSalesSignUlr();
......@@ -4580,7 +4587,7 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
baos.flush();
com.itextpdf.text.Image jpg = com.itextpdf.text.Image.getInstance(baos.toByteArray());
jpg.scaleToFit(70, 90);
jpg.scaleToFit(100, 100);
jpg.setAbsolutePosition(unionSalesPractitionerInfo.getSignX(), unionSalesPractitionerInfo.getSignY());
jpg.setAlignment(com.itextpdf.text.Image.ALIGN_CENTER);
document.add(jpg);
......@@ -4599,18 +4606,20 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
}
int signCount = unionSalesPractitioners.get(0).getSignCount();
int x = 100;
if((signCount+1)%3 == 2){
x = 275;
}else if((signCount+1)%3 == 0){
x = 450;
int count = unionSalesPractitioners.size();
int x = 150;
int y = 405;
if(count > 1){
y = y - 10*count;
if(count/3 >= 1){
y = y - count/3*15;
}
}
int y = 600;
if(signCount/3 > 0){
y = (signCount/3+1)*600;
if(signCount > 0){
y = y - signCount*70;
}
com.itextpdf.text.Image jpg = com.itextpdf.text.Image.getInstance(signPicture);
jpg.scaleToFit(70, 90);
jpg.scaleToFit(100, 100);
jpg.setAbsolutePosition(x, y);
jpg.setAlignment(com.itextpdf.text.Image.ALIGN_CENTER);
document.add(jpg);
......@@ -4643,10 +4652,10 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
}
}
//多个PDF合并功能
String[] filePaths = {filePath,filePathTemp};
if(!mergePdfFiles(filePaths, savePath, -1)){
retMap.put("signStatus", "1");
}
// String[] filePaths = {filePath,filePathTemp};
// if(!mergePdfFiles(filePaths, savePath, -1)){
// retMap.put("signStatus", "1");
// }
return retMap;
}
......@@ -4660,11 +4669,13 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
*/
public static boolean mergePdfFiles(String[] filePaths,String savePath,int pages){
Document retDocument = null;
PdfReader pdfReader = null;
PdfCopy copy = null;
boolean boole = true;
try {
if(filePaths != null && filePaths.length > 0){
retDocument = new Document(new PdfReader(filePaths[0]).getPageSize(1));
pdfReader = new PdfReader(filePaths[0]);
retDocument = new Document(pdfReader.getPageSize(1));
copy = new PdfCopy(retDocument, new FileOutputStream(savePath));
retDocument.open();
PdfImportedPage page;
......@@ -4699,6 +4710,9 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
if(retDocument != null){
retDocument.close();
}
if(pdfReader != null){
pdfReader.close();
}
} catch (Exception e) {
boole = false;
e.printStackTrace();
......@@ -4708,6 +4722,162 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
}
/**
* 动态生成PDF
* @param document Document对象
* @param logoPath logo图片路径
* @param object 动态组拼PDF数据集合对象
* @param type 操作对象
* @param unionSalesPractitioner 当前经纪人签署信息
* @return void
* @author Yan Wenyang
*/
@SuppressWarnings("unchecked")
public static void generatePdfChunk(Document document,String logoPath, Object object,String type,UnionSalesPractitionerInfo unionSalesPractitioner) throws Exception {
//添加段落
Paragraph preface = new Paragraph();
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
com.itextpdf.text.Font fontChinese = new com.itextpdf.text.Font(bfChinese, 15.5F, com.itextpdf.text.Font.NORMAL);
if(object != null){
List<UnionSalesPractitionerInfo> unionSalesPractitioners = (List<UnionSalesPractitionerInfo>)object;
UnionSalesPractitionerInfo unionSalesPractitionerInfo = unionSalesPractitioners.get(0);
if("1".equals(type)){
//1. 生成logo图片
com.itextpdf.text.Image jpgLogo = com.itextpdf.text.Image.getInstance(logoPath);
jpgLogo.scaleToFit(150, 150);
jpgLogo.setAbsolutePosition(90, 800);
jpgLogo.setAlignment(com.itextpdf.text.Image.ALIGN_CENTER);
document.add(jpgLogo);
//2. 横线
LineSeparator line = new LineSeparator(0.5f,80,BaseColor.BLACK,Element.ALIGN_CENTER,-10f);
Paragraph paragraphLine = new Paragraph();
paragraphLine.add(new Chunk(line));
document.add(line);
//3. 正文
preface = new Paragraph();
preface.add(new Phrase("银盾经纪人联合销售确认书", fontChinese));
preface.setAlignment(Element.ALIGN_CENTER);
preface.setSpacingBefore(20f); //设置段落上空白
preface.setSpacingAfter(10f); //设置段落下空白
document.add(preface);
fontChinese = new com.itextpdf.text.Font(bfChinese, 10.5F, com.itextpdf.text.Font.NORMAL);
preface = new Paragraph();
preface.add(new Phrase("以下保单经纪人同意进行联合销售,并对佣金分配比例和业绩分配比例约定如下:", fontChinese));
preface.setAlignment(Element.ALIGN_CENTER);
preface.setSpacingBefore(10f); //设置段落上空白
preface.setSpacingAfter(10f); //设置段落下空白
document.add(preface);
preface = new Paragraph();
preface.add(new Phrase("保单信息", fontChinese));
preface.setAlignment(Element.ALIGN_CENTER);
preface.setSpacingBefore(10f); //设置段落上空白
preface.setSpacingAfter(10f); //设置段落下空白
document.add(preface);
preface = new Paragraph();
preface.add(new Phrase("保险公司:", fontChinese));
preface.add(new Phrase(unionSalesPractitionerInfo.getInsurerName(), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
preface = new Paragraph();
preface.add(new Phrase("产品名称:", fontChinese));
preface.add(new Phrase(unionSalesPractitionerInfo.getProductName(), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
preface = new Paragraph();
preface.add(new Phrase("投保单号: ", fontChinese));
preface.add(new Phrase(unionSalesPractitionerInfo.getProposalNo(), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
preface = new Paragraph();
preface.add(new Phrase("保单号: ", fontChinese));
preface.add(new Phrase(unionSalesPractitionerInfo.getPolicyNo(), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
preface = new Paragraph();
preface.add(new Phrase("投保人: ", fontChinese));
preface.add(new Phrase(unionSalesPractitionerInfo.getPolicyholderName(), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setSpacingAfter(10f); //设置段落下空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
}else{
fontChinese = new com.itextpdf.text.Font(bfChinese, 10.5F, com.itextpdf.text.Font.NORMAL);
preface = new Paragraph();
preface.add(new Phrase("※本人已详细阅读以上联合销售的内容,同意上述约定并承诺执行。", fontChinese));
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
//5. 动态已签经纪人信息
for (int i= 0; i< unionSalesPractitioners.size(); i++) {
unionSalesPractitionerInfo = unionSalesPractitioners.get(i);
if(unionSalesPractitionerInfo != null && !StringUtils.isBlank(unionSalesPractitionerInfo.getSignUlr())
&& "3".equals(unionSalesPractitionerInfo.getSignStatus())){
preface = new Paragraph();
preface.add(new Phrase("经纪人: ", fontChinese));
preface.add(new Phrase(unionSalesPractitionerInfo.getPractitionerName(), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setSpacingAfter(10f); //设置段落下空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
preface = new Paragraph();
preface.add(new Phrase("经纪人亲签: ", fontChinese));
preface.add(new Phrase(" 日期:", fontChinese));
preface.add(new Phrase(unionSalesPractitionerInfo.getSignDate(), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setSpacingAfter(10f); //设置段落下空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
}
}
//6. 当前签署经纪人信息
if(unionSalesPractitioner != null){
preface = new Paragraph();
preface.add(new Phrase("经纪人: ", fontChinese));
preface.add(new Phrase(unionSalesPractitioner.getPractitionerName(), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setSpacingAfter(10f); //设置段落下空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
preface = new Paragraph();
preface.add(new Phrase("经纪人亲签: ", fontChinese));
preface.add(new Phrase(" 日期:", fontChinese));
preface.add(new Phrase(CommonUtil.dateParseString(new Date(), "yyyy-MM-dd HH:mm:ss"), fontChinese));
preface.setSpacingBefore(10f); //设置段落上空白
preface.setSpacingAfter(10f); //设置段落下空白
preface.setIndentationLeft(50);
preface.setIndentationRight(50);
document.add(preface);
}
}
}
}
/**
* 动态生成PDF表格
* @param object 动态组排PDF数据集合对象
* @return Paragraph
......@@ -4716,16 +4886,15 @@ public class PractitionerServiceImpl implements com.yd.api.practitioner.service.
@SuppressWarnings("unchecked")
public static Paragraph generatePdfTable(Object object) throws Exception {
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
com.itextpdf.text.Font fontChinese = new com.itextpdf.text.Font(bfChinese, 10.5F, com.itextpdf.text.Font.NORMAL);
com.itextpdf.text.Font fontChinese = new com.itextpdf.text.Font(bfChinese, 10F, com.itextpdf.text.Font.NORMAL);
Paragraph ret = new Paragraph();
PdfPTable tableBox = new PdfPTable(3);
tableBox.setWidths(new float[] { 0.4f, 0.3f, 0.3f});//每个单元格占多宽
tableBox.setWidthPercentage(80f);
//创建表格格式及内容
tableBox.addCell(getCell(new Phrase("联合销售人信息", fontChinese), 3, 1));
tableBox.addCell(getCell(new Phrase("经纪人", fontChinese), 1, 1));
tableBox.addCell(getCell(new Phrase("分佣比例", fontChinese), 1, 1));
tableBox.addCell(getCell(new Phrase("业绩比例", fontChinese), 1, 1));
tableBox.addCell(getCell(new Phrase("分佣分配比例", fontChinese), 1, 1));
tableBox.addCell(getCell(new Phrase("业绩分配比例", fontChinese), 1, 1));
if(object != null){
//遍历查询出的结果
List<UnionSalesPractitionerInfo> unionSalesPractitioners = (List<UnionSalesPractitionerInfo>)object;
......
......@@ -18,6 +18,11 @@ public class UnionSalesPractitionerInfo {
private Integer isActive;//是否启用(0=No, 1=Yes)
private int signCount;//已签署总数
private String salesSignUlr;//签署文件URl
private String insurerName;//保险公司名称
private String productName;//产品名称
private String proposalNo;//投保单号
private String policyNo;//保单号
private String policyholderName;//投保人姓名
/**
* @return the id
......@@ -211,5 +216,65 @@ public class UnionSalesPractitionerInfo {
public void setSignY(int signY) {
this.signY = signY;
}
/**
* @return the insurerName
*/
public String getInsurerName() {
return insurerName;
}
/**
* @param insurerName the insurerName to set
*/
public void setInsurerName(String insurerName) {
this.insurerName = insurerName;
}
/**
* @return the productName
*/
public String getProductName() {
return productName;
}
/**
* @param productName the productName to set
*/
public void setProductName(String productName) {
this.productName = productName;
}
/**
* @return the proposalNo
*/
public String getProposalNo() {
return proposalNo;
}
/**
* @param proposalNo the proposalNo to set
*/
public void setProposalNo(String proposalNo) {
this.proposalNo = proposalNo;
}
/**
* @return the policyNo
*/
public String getPolicyNo() {
return policyNo;
}
/**
* @param policyNo the policyNo to set
*/
public void setPolicyNo(String policyNo) {
this.policyNo = policyNo;
}
/**
* @return the policyholderName
*/
public String getPolicyholderName() {
return policyholderName;
}
/**
* @param policyholderName the policyholderName to set
*/
public void setPolicyholderName(String policyholderName) {
this.policyholderName = policyholderName;
}
}
......@@ -2026,15 +2026,21 @@
t.commission_rate as commissionRate,
t.achievements_rate as achievementsRate,
t.sign_status as signStatus,
t.sign_date as signDate,
date_format(t.sign_date,'%Y-%m-%d %H:%i:%s') as signDate,
t.sign_url as signUlr,
t.signX as signX,
t.signY as signY,
t.flag as flag,
t.is_active as isActive,
(select count(a.id) from ag_acl_union_sales_practitioner a where a.is_active = 1 and a.sign_status ='3' and a.union_sales_id = t.union_sales_id) as signCount,
(SELECT us.sign_url FROM ag_acl_union_sales us WHERE us.is_active = 1 AND us.id = t.union_sales_id) AS salesSignUlr
from ag_acl_union_sales_practitioner t where t.is_active = 1 and t.union_sales_id= #{unionSalesId}
(SELECT COUNT(a.id) FROM ag_acl_union_sales_practitioner a WHERE a.is_active = 1 AND a.sign_status ='3' AND a.union_sales_id = t.union_sales_id) as signCount,
us.sign_url as salesSignUlr,
us.insurer_name as insurerName,
us.product_name as productName,
us.proposal_no as proposalNo,
us.policy_no as policyNo,
us.policyholder_name as policyholderName
from ag_acl_union_sales_practitioner t,ag_acl_union_sales us
where us.id = t.union_sales_id and us.is_active = 1 and t.is_active = 1 and t.union_sales_id= #{unionSalesId} order by t.id
</select>
<update id="updateUnionSalesPractitioner">
......
......@@ -25,5 +25,5 @@ informed.pdf.temp.path=/opt/tomcat8/conf/ydpdf/informed
commitment.pdf.template=/opt/tomcat8/conf/ydpdf/commitment/templateCommitment.pdf
commitment.pdf.temp.path=/opt/tomcat8/conf/ydpdf/commitment
unionSales.pdf.template=/opt/tomcat8/conf/ydpdf/unionSales/templateUnionSalest.pdf
unionSales.pdf.template=/opt/tomcat8/conf/ydpdf/unionSales/ydLogo.jpg
unionSales.pdf.temp.path=/opt/tomcat8/conf/ydpdf/unionSales/
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