提交 0fcb2724 authored 作者: 133's avatar 133

[模版] 添加二维码信息

上级 f6b5cb4a
...@@ -58,6 +58,11 @@ ...@@ -58,6 +58,11 @@
<groupId>com.tykj</groupId> <groupId>com.tykj</groupId>
<artifactId>dev-library</artifactId> <artifactId>dev-library</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.tykj</groupId>
<artifactId>dev-zxing</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.xhtmlrenderer</groupId> <groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf-itext5</artifactId> <artifactId>flying-saucer-pdf-itext5</artifactId>
......
...@@ -21,6 +21,10 @@ import java.util.List; ...@@ -21,6 +21,10 @@ import java.util.List;
@Data @Data
@ApiModel(value = "出库入库单据样式", description = "出库入库单据属性实体") @ApiModel(value = "出库入库单据样式", description = "出库入库单据属性实体")
public class Documents { public class Documents {
@ApiModelProperty
private Integer id;
@ApiModelProperty(value = "单据号") @ApiModelProperty(value = "单据号")
private String number; private String number;
......
...@@ -4,6 +4,7 @@ import com.itextpdf.text.Document; ...@@ -4,6 +4,7 @@ import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException; import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.*; import com.itextpdf.text.pdf.*;
import com.tykj.dev.device.file.entity.*; import com.tykj.dev.device.file.entity.*;
import com.tykj.dev.device.zxing.util.ZXingUtil;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -193,7 +194,10 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -193,7 +194,10 @@ public class JavaToPdfHtmlFreeMarker {
Writer out = new StringWriter(); Writer out = new StringWriter();
String [] strings=new String[100000]; String [] strings=new String[100000];
int index=0; int index=0;
try { try {
String QRCode= ZXingUtil.encode(documents.getId());
System.out.println(QRCode);
// 获取模板,并设置编码方式 // 获取模板,并设置编码方式
Template template = freemarkerCfg.getTemplate("bill.html"); Template template = freemarkerCfg.getTemplate("bill.html");
template.setEncoding("UTF-8"); template.setEncoding("UTF-8");
...@@ -207,7 +211,7 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -207,7 +211,7 @@ public class JavaToPdfHtmlFreeMarker {
String htmlname=htmlPath+ UUID.randomUUID().toString()+".html"; String htmlname=htmlPath+ UUID.randomUUID().toString()+".html";
// 合并数据模型与模板 // 合并数据模型与模板
FileWriter fileWriter = new FileWriter(new File(htmlname)); FileWriter fileWriter = new FileWriter(new File(htmlname));
template.process(toMap(documents,list1,MAP.get(i),page,count),fileWriter); template.process(toMap(documents,list1,MAP.get(i),page,count,QRCode),fileWriter);
out.flush(); out.flush();
strings[index]=htmlname; strings[index]=htmlname;
index++; index++;
...@@ -470,6 +474,47 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -470,6 +474,47 @@ public class JavaToPdfHtmlFreeMarker {
} }
private static Map<String,Object> toMap(Documents documents,List<DocumentDevice> list,String test,Integer page,Integer count,String QRCode){
Map<String,Object> data = new HashMap();
data.put("ul",test);
data.put("number",documents.getNumber());
data.put("title",documents.getTitle());
data.put("receiveUnit",documents.getReceiveUnit());
data.put("replyNum",documents.getReplyNum());
data.put("senderUnit",documents.getSenderUnit());
data.put("page",page);
data.put("count",count);
data.put("QRCode","\""+"data:image/png;base64,"+QRCode+"\"");
if (documents.getSrcA()==null||documents.getSrcA().equals("")){
data.put("srcA","\""+1+"\"");
}else {
data.put("srcA","\""+documents.getSrcA()+"\"");
}
data.put("nameA",documents.getNameA());
data.put("nameA1",documents.getNameA1());
data.put("nameB",documents.getNameB());
data.put("nameB1",documents.getNameB1());
if (documents.getSrcB()==null||documents.getSrcB().equals("")){
data.put("srcB","\""+1+"\"");
}else {
data.put("srcB","\""+documents.getSrcB()+"\"");
}
List<DocumentDevice> list1=new ArrayList<>();
AtomicInteger i= new AtomicInteger(1);
list.forEach(
documentDevice -> {
documentDevice.setCode(i.get());
i.set(i.get() + 1);
list1.add(documentDevice);
}
);
data.put("documentDevices",list1);
return data;
}
private static Map<String,Object> toConfirmMap(Confirm confirm, List<DocumentDevice> list,Integer page,Integer count){ private static Map<String,Object> toConfirmMap(Confirm confirm, List<DocumentDevice> list,Integer page,Integer count){
......
...@@ -16,7 +16,13 @@ ...@@ -16,7 +16,13 @@
@page { @page {
size: 297mm 210mm; size: 297mm 210mm;
} }
.erwei{
width: 43px;
height: 43px;
position: fixed;
left: 150px;
top: 0px;
}
.bottomTxt { .bottomTxt {
text-align: center; text-align: center;
font-size: 15px; font-size: 15px;
...@@ -415,6 +421,7 @@ border:1px solid #bebebe; ...@@ -415,6 +421,7 @@ border:1px solid #bebebe;
<div class="returnTablePrint"> <div class="returnTablePrint">
<img class="erwei" src=${QRCode} />
<div class="content"> <div class="content">
<div> <div>
<div class="listWrapper"> <div class="listWrapper">
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论