提交 65c25e4b authored 作者: 133's avatar 133

[模版提交]

上级 9354a744
...@@ -314,41 +314,22 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -314,41 +314,22 @@ public class JavaToPdfHtmlFreeMarker {
String [] strings=new String[100000]; String [] strings=new String[100000];
int index=0; int index=0;
try { try {
// 获取模板,并设置编码方式
Template template = freemarkerCfg.getTemplate("bill2.html"); Template template = freemarkerCfg.getTemplate("bill2.html");
template.setEncoding("UTF-8"); template.setEncoding("UTF-8");
List<DocumentDevice> list=confirm.getConfirmDevices().stream().sorted(Comparator.comparing(DocumentDevice::getModel)).collect(Collectors.toList());
boolean falg=true;
Integer page=0;
int pageNum = page + 1;
int pageSize = 34;
Integer totalNum = list.size();
//默认从零分页,这里要考虑这种情况,下面要计算。
Integer totalPage = 0;
while (falg){
if (totalNum > 0) {
totalPage = totalNum % pageSize == 0 ? totalNum / pageSize : totalNum / pageSize + 1;
}
if (pageNum >= totalPage) {
pageNum = totalPage;
falg=false;
}
int startPoint = (pageNum - 1) * pageSize;
int endPoint = startPoint + pageSize;
if (totalNum <= endPoint) {
endPoint = totalNum;
}
String htmlname=htmlPath+ UUID.randomUUID().toString()+".html"; List<DocumentDevice> list=confirm.getConfirmDevices();
// 合并数据模型与模板 List<List<DocumentDevice>> listList=toConfirmList(list);
FileWriter fileWriter = new FileWriter(new File(htmlname)); int count=listList.size();
template.process(toConfirmMap(confirm,list.subList(startPoint, endPoint),pageNum,totalPage),fileWriter); Integer page=1;
out.flush(); for (List<DocumentDevice> list1:listList) {
strings[index]=htmlname; String htmlname=htmlPath+ UUID.randomUUID().toString()+".html";
index++; // 合并数据模型与模板
pageNum++; FileWriter fileWriter = new FileWriter(new File(htmlname));
template.process(toConfirmMap(confirm,list1,page,count),fileWriter);
out.flush();
strings[index]=htmlname;
index++;
page++;
} }
return strings; return strings;
} catch (Exception e) { } catch (Exception e) {
...@@ -594,6 +575,63 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -594,6 +575,63 @@ public class JavaToPdfHtmlFreeMarker {
// return new FileRet(); // return new FileRet();
// } // }
private static List<List<DocumentDevice>> toConfirmList(List<DocumentDevice> deviceList){
List<List<DocumentDevice>> lists=new ArrayList<>();
List<DocumentDevice> documentDevices=new ArrayList<>();
int i=0;
for (DocumentDevice documentDevice : deviceList) {
int max = toMax(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 int String_length(String value) {
int valueLength = 0;
String chinese = "[\u4e00-\u9fa5]";
for (int i = 0; i < value.length(); i++) {
String temp = value.substring(i, i + 1);
if (temp.matches(chinese)) {
valueLength += 2;
} else {
valueLength += 1;
}
}
return valueLength;
}
private static Integer toMax(DocumentDevice documentDevice){
int partsCount=String_length(documentDevice.getParts());
int deviceSerialNumberCount=String_length(documentDevice.getDeviceSerialNumber());
int modelCount=String_length(documentDevice.getModel());
int parts = (partsCount%20>0) ? partsCount/20 + 1 : partsCount/20;
int deviceSerialNumber=(deviceSerialNumberCount%22>0) ? deviceSerialNumberCount/22 + 1 : deviceSerialNumberCount/22;
int model=(modelCount%20>0) ? modelCount/20 + 1 : modelCount/20;
int max=parts;
//求最大
if(max<deviceSerialNumber){
max=deviceSerialNumber;
}
if(max<model) {
max = model;
}
return max;
}
/** /**
......
...@@ -372,8 +372,8 @@ border:1px solid #bebebe; ...@@ -372,8 +372,8 @@ border:1px solid #bebebe;
height: 24px; height: 24px;
line-height:24px; line-height:24px;
font-size: 15px; font-size: 15px;
word-break: break-all; word-break: normal;
word-wrap: break-word; word-wrap: normal;
border:1px solid #bebebe; border:1px solid #bebebe;
width: 100%; width: 100%;
} }
......
...@@ -184,13 +184,12 @@ ...@@ -184,13 +184,12 @@
<div style="height: 900px;"> <div style="height: 900px;">
<table class="altrowstable" id="alternatecolor"> <table class="altrowstable" id="alternatecolor">
<tr> <tr>
<th width="70px">序号</th> <th width="30px">序号</th>
<th style="width: 150px;">型号</th> <th style="width: 150px;">型号</th>
<th>部件</th> <th style="width: 150px">部件</th>
<th width="100px">密级</th> <th width="80px">应用领域</th>
<th width="100px">应用领域</th> <th width="150">装备序列号</th>
<th>装备序列号</th> <th width="80px">检查结果</th>
<th>检查结果</th>
</tr> </tr>
<#list documentDevices as dev> <#list documentDevices as dev>
<tr> <tr>
...@@ -199,7 +198,6 @@ ...@@ -199,7 +198,6 @@
</td> </td>
<td>${dev.model!}</td> <td>${dev.model!}</td>
<td>${dev.parts!}</td> <td>${dev.parts!}</td>
<td>${dev.securityClassification!}</td>
<td>${dev.applicationField!}</td> <td>${dev.applicationField!}</td>
<td>${dev.deviceSerialNumber!}</td> <td>${dev.deviceSerialNumber!}</td>
<td>${dev.proofreading!}</td> <td>${dev.proofreading!}</td>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论