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

[工作交接] 代码提交

上级 7e057efb
......@@ -81,7 +81,7 @@ public class FileController {
@ApiOperation(value = "生成工作交接的单据")
@PostMapping("/wordHandover")
public ResponseEntity wordHandover(@RequestBody WorkHandoverDoc workHandoverDoc) {
String[] content = JavaToPdfHtmlFreeMarker.freeMarkerRenderWorkHandover(workHandoverDoc,url+"htmlModel/");
String[] content = JavaToPdfHtmlFreeMarker.freeMarkerRenderWorkHandover2(workHandoverDoc,url+"htmlModel/");
log.info("[file] 生成工作交接的单据");
return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(content,url,preview,"workHandover/"));
}
......
......@@ -59,6 +59,8 @@ public class WorkHandoverDevice {
@ApiModelProperty(value = "序列号区间")
public String seqs;
public int oneCount;
public Integer getLen(){
return seqs.length();
}
......
......@@ -823,7 +823,6 @@ public class JavaToPdfHtmlFreeMarker {
}
List<String> endList = strings.subList((count - 1) * 6 * 30, strings.size());
Integer max4 = toMaxList(endList);
int count1 = (max4 % 30 > 0) ? max4 / 30 + 1 : max4 / 30;
if (max4 == 30) {
Check check1 = new Check();
check1.setSeqStirng(toALLSeqStirng(endList));
......@@ -1411,7 +1410,7 @@ public class JavaToPdfHtmlFreeMarker {
}
/**
* 计算每一页打印的内容
* 计算每一页打印的内容 (遗弃)
* 判断是否超过一页展示的最多的内容
* 如大于
* 直接生成一个页面的数据 放入到集合中 List<List<DocumentDevice>>
......@@ -2001,4 +2000,143 @@ public class JavaToPdfHtmlFreeMarker {
return allStirng.toString();
}
/**
* 工作交接计算每一页数据
* @param deviceList
* @return
* @throws UnsupportedEncodingException
*/
public static List<List<WorkHandoverDevice>> toWorkHandoverDeviceList(List<WorkHandoverDevice> deviceList) throws UnsupportedEncodingException {
List<List<WorkHandoverDevice>> lists=new ArrayList<>();
List<WorkHandoverDevice> revenues=new ArrayList<>();
deviceList=deviceList.stream().sorted(Comparator.comparing(WorkHandoverDevice::getModel).thenComparing(WorkHandoverDevice::getName)).collect(Collectors.toList());
Integer code=0;
int i=0;
for (int j=0;j< deviceList.size();j++){
WorkHandoverDevice workHandoverDevice=deviceList.get(j);
int max= toWorkHandoverMax(workHandoverDevice);
if (i+max==19){
workHandoverDevice.setModel(String.join("",toListString(workHandoverDevice.getModel(),16)));
workHandoverDevice.setName(String.join("",toListString(workHandoverDevice.getName(),16)));
workHandoverDevice.setSeqs(String.join("",toListString(workHandoverDevice.getSeqs(),32)));
workHandoverDevice.setOneCount(max);
code++;
workHandoverDevice.setCode(code);
revenues.add(workHandoverDevice);
lists.add(revenues);
revenues = new ArrayList<>();
i=0;
}else if (i+max>19){
//当前页面少了多少行
int differ=19-i;
List<String> modelList= toListString(workHandoverDevice.getModel(),16);
List<String> nameList=toListString(workHandoverDevice.getName(),16);
List<String> seqList=toListString(workHandoverDevice.getSeqs(),32);
WorkHandoverDevice workHandoverDevice1=new WorkHandoverDevice();
if (modelList.size()>differ){
workHandoverDevice.setModel(String.join("",modelList.subList(0,differ)));
workHandoverDevice1.setModel(String.join("",modelList.subList(differ,modelList.size())));
}else {
workHandoverDevice.setModel(String.join("",modelList));
}
if (nameList.size()>differ){
workHandoverDevice.setName(String.join("",nameList.subList(0,differ)));
workHandoverDevice1.setName(String.join("",nameList.subList(differ,nameList.size())));
}else {
workHandoverDevice.setName(String.join("",nameList));
}
if (seqList.size()>differ){
workHandoverDevice.setSeqs(String.join("",seqList.subList(0,differ)));
workHandoverDevice1.setSeqs(String.join("",seqList.subList(differ,seqList.size())));
}else {
workHandoverDevice.setSeqs(String.join("",seqList));
}
code++;
workHandoverDevice.setCode(code);
workHandoverDevice.setOneCount(differ);
revenues.add(workHandoverDevice);
lists.add(revenues);
revenues=new ArrayList<>();
workHandoverDevice1.setOneCount(max-differ);
code++;
workHandoverDevice1.setCode(code);
revenues.add(workHandoverDevice1);
i=max-differ;
}else {
code++;
workHandoverDevice.setModel(String.join("",toListString(workHandoverDevice.getModel(),16)));
workHandoverDevice.setName(String.join("",toListString(workHandoverDevice.getName(),16)));
workHandoverDevice.setSeqs(String.join("",toListString(workHandoverDevice.getSeqs(),32)));
workHandoverDevice.setCode(code);
workHandoverDevice.setOneCount(max);
revenues.add(workHandoverDevice);
i=i+max;
}
}
if (revenues.size()!=0){
lists.add(revenues);
}
return lists;
}
private static Integer toWorkHandoverMax(WorkHandoverDevice workHandoverDevice){
int nameCount=String_length(workHandoverDevice.getName());
int modelCount=String_length(workHandoverDevice.getModel());
int seqCount=String_length(workHandoverDevice.getSeqs());
int name = (nameCount%16>0) ? nameCount/16 + 1 : nameCount/16;
int model=(modelCount%16>0) ? modelCount/16 + 1 : modelCount/16;
int seq=(seqCount%32>0) ? seqCount/32 + 1 : seqCount/32;
int max=name;
//求最大
if(max<model){
max=model;
}
if (max<seq){
max=seq;
}
return max;
}
/**
* freemarker渲染html workHandoverDoc
*/
public static String[] freeMarkerRenderWorkHandover2(WorkHandoverDoc workHandoverDoc,String htmlPath) {
Writer out = new StringWriter();
String [] strings=new String[100000];
int index=0;
try {
// 获取模板,并设置编码方式
Template template = freemarkerCfg.getTemplate("bill13.html");
template.setEncoding("UTF-8");
List<WorkHandoverDevice> list = workHandoverDoc.getWorkHandoverDeviceList();
List<List<WorkHandoverDevice>> listList=toWorkHandoverDeviceList(list);
Integer count=listList.size();
for (int i=1; i<=3; i++){
Integer page=1;
for (List<WorkHandoverDevice> list1:listList) {
String htmlname=htmlPath+ UUID.randomUUID().toString()+".html";
// 合并数据模型与模板
FileWriter fileWriter = new FileWriter(new File(htmlname));
template.process(toMapWork(workHandoverDoc,list1,MAP1.get(i),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;
}
}
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论