提交 d6f71b75 authored 作者: 133's avatar 133

[模版 字体] 上传了字体以及模版

上级 a1f15bad
...@@ -114,6 +114,18 @@ public class FileController { ...@@ -114,6 +114,18 @@ public class FileController {
return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(content,url,preview,"confirm/")); return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(content,url,preview,"confirm/"));
} }
/**
* 生成单据 核查确认单据
* @return
*/
@ApiOperation(value = "生成单据 核查确认单据")
@PostMapping("/printVerification")
public ResponseEntity printVerification(@RequestBody Confirm confirm) {
String[] content = JavaToPdfHtmlFreeMarker.freeMarkerRenderVerification(confirm,url+"htmlModel/");
log.info("[file] 调用了生成核查确认单据对接口 confirm");
return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(content,url,preview,"confirm/"));
}
/** /**
* 生成单据 销毁单据 * 生成单据 销毁单据
* @return * @return
......
...@@ -52,6 +52,9 @@ public class DocumentDevice { ...@@ -52,6 +52,9 @@ public class DocumentDevice {
@ApiModelProperty(value = "校对") @ApiModelProperty(value = "校对")
private String proofreading; private String proofreading;
@ApiModelProperty(value = "状态")
private String status;
private Integer oneCount; private Integer oneCount;
public Integer getLen(){ public Integer getLen(){
......
...@@ -37,7 +37,7 @@ public class PdfServiceImpl implements PdfService { ...@@ -37,7 +37,7 @@ public class PdfServiceImpl implements PdfService {
} }
private DocumentDevice toDocDev(ScriptSaveVo scriptSaveVo){ private DocumentDevice toDocDev(ScriptSaveVo scriptSaveVo){
return new DocumentDevice(null,scriptSaveVo.getModel(),null,scriptSaveVo.getType(),scriptSaveVo.getSecretLevel(),scriptSaveVo.getInvisibleRange(),scriptSaveVo.getNum(),scriptSaveVo.getSeqNumber(),null,scriptSaveVo.getRemark(),null,null); return new DocumentDevice(null,scriptSaveVo.getModel(),null,scriptSaveVo.getType(),scriptSaveVo.getSecretLevel(),scriptSaveVo.getInvisibleRange(),scriptSaveVo.getNum(),scriptSaveVo.getSeqNumber(),null,scriptSaveVo.getRemark(),null,null,null);
} }
} }
...@@ -115,7 +115,8 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -115,7 +115,8 @@ public class JavaToPdfHtmlFreeMarker {
renderer.setDocument(htmlFile); renderer.setDocument(htmlFile);
// 解决中文不显示问题 // 解决中文不显示问题
ITextFontResolver fontResolver = renderer.getFontResolver(); ITextFontResolver fontResolver = renderer.getFontResolver();
fontResolver.addFont(path+"fond/"+"simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); fontResolver.addFont("simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
fontResolver.addFont("simhei2.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
renderer.layout(); renderer.layout();
renderer.createPDF(os); renderer.createPDF(os);
PdfReader pdfReader = new PdfReader(os.toByteArray()); PdfReader pdfReader = new PdfReader(os.toByteArray());
...@@ -511,6 +512,45 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -511,6 +512,45 @@ public class JavaToPdfHtmlFreeMarker {
return null; return null;
} }
/**
* freemarker渲染html 核查确认单据
*/
public static String[] freeMarkerRenderVerification(Confirm confirm,String htmlPath) {
Writer out = new StringWriter();
String [] strings=new String[100000];
int index=0;
try {
Template template = freemarkerCfg.getTemplate("bill5.html");
template.setEncoding("UTF-8");
List<DocumentDevice> list=confirm.getConfirmDevices();
List<List<DocumentDevice>> listList=toVerificationList(list);
int count=listList.size();
Integer page=1;
for (List<DocumentDevice> list1:listList) {
String htmlname=htmlPath+ UUID.randomUUID().toString()+".html";
// 合并数据模型与模板
FileWriter fileWriter = new FileWriter(new File(htmlname));
template.process(toConfirmMap(confirm,list1,page,count),fileWriter);
out.flush();
strings[index]=htmlname;
index++;
page++;
}
return strings;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return null;
}
// /** // /**
// * 确认单据页面调用接口 // * 确认单据页面调用接口
// */ // */
...@@ -742,6 +782,64 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -742,6 +782,64 @@ public class JavaToPdfHtmlFreeMarker {
// return new FileRet(); // return new FileRet();
// } // }
/**
* 核查清单
* @param deviceList
* @return
*/
private static List<List<DocumentDevice>> toVerificationList(List<DocumentDevice> deviceList){
List<List<DocumentDevice>> lists=new ArrayList<>();
List<DocumentDevice> documentDevices=new ArrayList<>();
int i=0;
for (DocumentDevice documentDevice : deviceList) {
int max = toVerificationMax(documentDevice);
if (i + max == 34) {
documentDevices.add(documentDevice);
lists.add(documentDevices);
documentDevices = new ArrayList<>();
i = 0;
} else if (i + max > 34) {
lists.add(documentDevices);
documentDevices = new ArrayList<>();
documentDevices.add(documentDevice);
i = max;
} else {
documentDevices.add(documentDevice);
i = i + max;
}
}
if (documentDevices.size()!=0){
lists.add(documentDevices);
}
return lists;
}
private static Integer toVerificationMax(DocumentDevice documentDevice){
int partsCount=String_length(documentDevice.getParts());
int deviceSerialNumberCount=String_length(documentDevice.getDeviceSerialNumber());
int modelCount=String_length(documentDevice.getModel());
int parts = (partsCount%17>0) ? partsCount/17 + 1 : partsCount/17;
int deviceSerialNumber=(deviceSerialNumberCount%22>0) ? deviceSerialNumberCount/22 + 1 : deviceSerialNumberCount/22;
int model=(modelCount%17>0) ? modelCount/17 + 1 : modelCount/17;
int max=parts;
//求最大
if(max<deviceSerialNumber){
max=deviceSerialNumber;
}
if(max<model) {
max = model;
}
return max;
}
/**
* 自查确认单据
* @param deviceList
* @return
*/
private static List<List<DocumentDevice>> toConfirmList(List<DocumentDevice> deviceList){ private static List<List<DocumentDevice>> toConfirmList(List<DocumentDevice> deviceList){
List<List<DocumentDevice>> lists=new ArrayList<>(); List<List<DocumentDevice>> lists=new ArrayList<>();
List<DocumentDevice> documentDevices=new ArrayList<>(); List<DocumentDevice> documentDevices=new ArrayList<>();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<style> <style>
body,span,p,tr,td { body,span,p,tr,td {
font-size: 15px; font-size: 15px;
font-family: SimHei; font-family: FangSong_GB2312;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
......
...@@ -186,7 +186,7 @@ ...@@ -186,7 +186,7 @@
<tr> <tr>
<th width="30px">序号</th> <th width="30px">序号</th>
<th style="width: 150px;">型号</th> <th style="width: 150px;">型号</th>
<th style="width: 150px">部件</th> <th style="width: 150px">名称</th>
<th width="80px">应用领域</th> <th width="80px">应用领域</th>
<th width="150">装备序列号</th> <th width="150">装备序列号</th>
<th width="80px">检查结果</th> <th width="80px">检查结果</th>
......
<!DOCTYPE html>
<html lang="en">
<!--核查确认-->
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style>
body,span,p,tr,td {
font-size: 15px;
font-family: SimHei;
margin: 0;
padding: 0;
}
.bottomTxt {
text-align: center;
font-size: 15px;
color: #000;
height: 15px;
line-height: 10px;
}
/*@page{size:297mm 210mm;}<!-- 设置PDF页面大小,此配置只对生成PDF文件有效,不会对页面显示生效 -->*/
@page {
size: 210mm 297mm;
/*margin: 0.25in;*/
/*-fs-flow-bottom: "footer";*/
/*-fs-flow-left: "left";*/
/*-fs-flow-right: "right";*/
/*border: thin solid black;*/
/*padding: 1em;*/
}
.returnTablePrint {
width: 100%;
height: 100%;
overflow: hidden;
color: #000;
cursor: default;
}
.returnTablePrint .content {
width: 100%;
height: 100%;
/* background: url("../../../assets/img/detailsBg.png") no-repeat; */
/*background-size: 100% 100%;*/
/*padding: 30px;*/
/*box-sizing: border-box;*/
}
.returnTablePrint .content>div {
width: 100%;
height: 100%;
background: #fff;
/* padding: 30px; */
box-sizing: border-box;
}
.returnTablePrint .content>p {
width: 100%;
text-align: center;
font-size: 22px;
font-weight: bold;
color: #4a475d;
}
.returnTablePrint .listWrapper {
/* width: 92%; */
margin: 0 auto;
/* padding: 0px 20px 20px 20px; */
height: calc(100% - 70px);
/*padding: 10px 30px;*/
box-sizing: border-box;
}
.returnTablePrint .list {
/* width: 92%; */
margin: 0 auto;
/* padding: 0px 20px 20px 20px; */
/* height: calc(100% - 75px); */
height: calc(100% - 12px)
}
.returnTablePrint .title {
width: 100%;
font-size: 20px;
text-align: center;
position: relative;
margin: 0;
padding: 0;
box-sizing: border-box;
margin-top: 9px;
}
.returnTablePrint .title span:nth-child(2) {
font-size: 28px;
color: #000000;
}
.returnTablePrint .title span:nth-child(2) span {
font-size: 20px;
color: #000;
}
.returnTablePrint .main-title span{
font-size: 22px;
color: #333;
font-weight: bold;
}
.returnTablePrint .main-title {
font-size: 17px;
color: #000000;
text-align: center;
}
table.altrowstable {
width: 100%;
font-size: 15px;
color: #000;
border-width: 0px;
border-color: #a9c6c9;
border-collapse: collapse;
text-align: center;
table-layout: fixed;
word-break: break-all;
}
table.altrowstable th {
background-color: #dedede;
border: 1px solid #bebebe;
height: 24px;
line-height: 24px;
font-size: 15px;
}
table.altrowstable td {
word-break: break-all;
/*border: 1px solid #bebebe;*/
word-wrap: break-word;
height: 24px;
line-height: 24px;
font-size: 15px;
width: 100%;
}
.oddrowcolor {
background-color: #fff;
}
.evenrowcolor {
background-color: #fafafa;
}
.person {
color: #000;
text-align: right;
font-size: 15px;
}
.person>span {
display: inline-block;
margin-right: 30pt;
}
tr:nth-child(odd) {
background: #fafafa;
}
</style>
</head>
<body>
<div class="returnTablePrint">
<div class="content">
<div>
<div class="listWrapper">
<div class="list">
<p class="title" style="margin-bottom:20px">
<div class="main-title">
<span>
${title!}
</span>
</div>
</p>
<div style="height: 900px;">
<table class="altrowstable" id="alternatecolor">
<tr>
<th width="30px">序号</th>
<th style="width: 130px;">型号</th>
<th style="width: 130px">名称</th>
<th width="60px">应用领域</th>
<th width="150">装备序列号</th>
<th width="100px">状态</th>
<th width="80px">检查结果</th>
</tr>
<#list documentDevices as dev>
<tr>
<td>
${dev.code!}
</td>
<td>${dev.model!}</td>
<td>${dev.parts!}</td>
<td>${dev.applicationField!}</td>
<td>${dev.deviceSerialNumber!}</td>
<td>${dev.status!}</td>
<td>${dev.proofreading!}</td>
</tr>
</#list>
</table>
</div>
</div>
<p class="person" style="margin-top: 20px;font-size: 10px;">
<span style="width: 200px;text-align: left">经办人:</span>
<span style="width: 200px;text-align: left">审核人:</span>
</p>
</div>
</div>
</div>
<p class="bottomTxt" style="margin-top: 20px;">第${page}页/共${count}页</p>
</div>
<!--<script type="text/javascript">-->
<!--function altRows(id){-->
<!--if(document.getElementsByTagName){-->
<!--var table = document.getElementById(id);-->
<!--var rows = table.getElementsByTagName("tr");-->
<!--for(i = 0; i < rows.length; i++){-->
<!--if(i % 2 == 0){-->
<!--rows[i].className = "evenrowcolor";-->
<!--}else{-->
<!--rows[i].className = "oddrowcolor";-->
<!--}-->
<!--}-->
<!--}-->
<!--}-->
<!--window.onload=function(){-->
<!--altRows('alternatecolor');-->
<!--}-->
<!--</script>-->
</body>
</html>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论