提交 73ad44f5 authored 作者: zjm's avatar zjm

fix(PDF模块): 修改了自查核查单据模版

修改了自查核查单据模版
上级 58a106f7
...@@ -59,6 +59,18 @@ public class FileController { ...@@ -59,6 +59,18 @@ public class FileController {
return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(content,url,preview,"documents/")); return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(content,url,preview,"documents/"));
} }
/**
* 生成单据签字配发单据
*/
@ApiOperation(value = "生成单据签字配发单据")
@PostMapping("/printDocuments/Signature")
public ResponseEntity printDocumentsSignature(@RequestBody Documents documents) throws IOException, DocumentException {
String[] content = JavaToPdfHtmlFreeMarker.freeMarkerRenderNew(documents,url+"htmlModel/");
log.info("[file] 调用了生成出入单据对接口 出入库单据");
return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(content,url,preview,"documents/"));
}
/** /**
* 生成维修单据 * 生成维修单据
*/ */
...@@ -204,13 +216,13 @@ public class FileController { ...@@ -204,13 +216,13 @@ public class FileController {
public ResponseEntity printDocuments(HttpServletResponse response,HttpServletRequest request) throws IOException, DocumentException { public ResponseEntity printDocuments(HttpServletResponse response,HttpServletRequest request) throws IOException, DocumentException {
int interval = request.getSession().getMaxInactiveInterval(); int interval = request.getSession().getMaxInactiveInterval();
System.out.println("-------"+interval); System.out.println("-------"+interval);
List<Documents> documentsList=new ArrayList<>();
Documents documents=new Documents(); Documents documents=new Documents();
documents.setNumber("NO:第221321134号"); documents.setNumber("NO:第221321134号");
documents.setReceiveUnit("杭州机要"); documents.setReceiveUnit("杭州机要");
documents.setReplyNum("123123123131"); documents.setReplyNum("123123123131");
documents.setSenderUnit("浙江省"); documents.setSenderUnit("浙江省");
documents.setTitle("密码装备清退单"); documents.setTitle("密码装备清退单");
documents.setId(1);
List<DocumentDevice> documentDevices=new ArrayList<>(); List<DocumentDevice> documentDevices=new ArrayList<>();
for (int i=0;i<20;i++){ for (int i=0;i<20;i++){
DocumentDevice documentDevice=new DocumentDevice(); DocumentDevice documentDevice=new DocumentDevice();
...@@ -226,14 +238,11 @@ public class FileController { ...@@ -226,14 +238,11 @@ public class FileController {
documentDevices.add(documentDevice); documentDevices.add(documentDevice);
} }
documents.setDocumentDevices(documentDevices); documents.setDocumentDevices(documentDevices);
documentsList.add(documents); String[] content = JavaToPdfHtmlFreeMarker.freeMarkerRender(documents,url+"htmlModel/");
List<String> list=new ArrayList<>();
documentsList.forEach(
documents1 -> list.addAll(Objects.requireNonNull(JavaToPdfHtmlFreeMarker.freeMarkerRenderList(documents1, url + "htmlModel/")))
);
log.info("[file] 调用了生成出入单据对接口 documents"); log.info("[file] 调用了生成出入单据对接口 documents");
return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(list.toArray(new String[0]),url,preview,"documents/")); return ResponseEntity.ok(JavaToPdfHtmlFreeMarker.createPdf(content,url,preview,"documents/"));
} }
......
...@@ -72,6 +72,9 @@ public class DocumentDevice { ...@@ -72,6 +72,9 @@ public class DocumentDevice {
@ApiModelProperty(value = "设备类型 装备、配件") @ApiModelProperty(value = "设备类型 装备、配件")
private Integer isPart; private Integer isPart;
@ApiModelProperty(value = "是否异常")
private Integer abnormal;
public Integer getLen(){ public Integer getLen(){
return deviceSerialNumber.length(); return deviceSerialNumber.length();
} }
......
...@@ -64,6 +64,18 @@ public class Documents { ...@@ -64,6 +64,18 @@ public class Documents {
@ApiModelProperty(value = "后端转换使用") @ApiModelProperty(value = "后端转换使用")
private List<ScriptSaveVo> scriptSaveVos; private List<ScriptSaveVo> scriptSaveVos;
@ApiModelProperty(value = "发送方人员签字base64")
private String userSrcA1;
@ApiModelProperty(value = "发送方人员签字base64")
private String userSrcA2;
@ApiModelProperty(value = "接收方人员签字base64")
private String userSrcB1;
@ApiModelProperty(value = "接收方人员签字base64")
private String userSrcB2;
public Documents(String number, String title, String receiveUnit, String replyNum, String senderUnit, String srcA, String srcB, String nameA, String nameA1, String nameB, String nameB1, List<ScriptSaveVo> scriptSaveVos) { public Documents(String number, String title, String receiveUnit, String replyNum, String senderUnit, String srcA, String srcB, String nameA, String nameA1, String nameB, String nameB1, List<ScriptSaveVo> scriptSaveVos) {
this.number = number; this.number = number;
this.title = title; this.title = title;
......
...@@ -2271,4 +2271,219 @@ public class JavaToPdfHtmlFreeMarker { ...@@ -2271,4 +2271,219 @@ public class JavaToPdfHtmlFreeMarker {
} }
return null; return null;
} }
//有异常的分类
/**
* 工作交接计算每一页数据
* @param deviceList
* @return
* @throws UnsupportedEncodingException
*/
public static List<List<DocumentDevice>> toWorkHandoverDeviceList2(List<DocumentDevice> deviceList) throws UnsupportedEncodingException {
List<List<DocumentDevice>> lists=new ArrayList<>();
List<DocumentDevice> documentDevices=new ArrayList<>();
deviceList=deviceList.stream().sorted(Comparator.comparing(DocumentDevice::getModel).thenComparing(DocumentDevice::getParts)).collect(Collectors.toList());
Integer code=0;
int i=0;
for (int j=0;j< deviceList.size();j++){
DocumentDevice documentDevice=deviceList.get(j);
int max= toWorkHandoverMax(documentDevice);
if (i+max==15){
String s=String.join("",toListString(documentDevice.getDeviceSerialNumber(),56));
documentDevice.setOneCount(max);
documentDevice.setModel(String.join("",toListString(documentDevice.getModel(),17)));
documentDevice.setParts(String.join("",toListString(documentDevice.getParts(),17)));
documentDevice.setRemark(String.join("",toListString(documentDevice.getRemark(),15)));
documentDevice.setDeviceSerialNumber(isAddUnderline(s,documentDevice.getAbnormal()));
code++;
documentDevice.setCode(code);
documentDevices.add(documentDevice);
lists.add(documentDevices);
documentDevices=new ArrayList<>();
i=0;
}else if (i+max>15){
//当前页面少了多少行
int differ=15-i;
List<String> modelList= toListString(documentDevice.getModel(),17);
List<String> seqList=toListString(documentDevice.getDeviceSerialNumber(),56);
List<String> pasList=toListString(documentDevice.getParts(),17);
List<String> remarkList=toListString(documentDevice.getRemark(),15);
DocumentDevice documentDevice1=new DocumentDevice();
if (modelList.size()>differ){
documentDevice.setModel(String.join("",modelList.subList(0,differ)));
documentDevice1.setModel(String.join("",modelList.subList(differ,modelList.size())));
}else {
documentDevice.setModel(String.join("",modelList.subList(0,modelList.size())));
}
if (seqList.size()>differ){
documentDevice.setDeviceSerialNumber(isAddUnderline(String.join("",seqList.subList(0,differ)),documentDevice.getAbnormal()));
documentDevice1.setDeviceSerialNumber(isAddUnderline(String.join("",seqList.subList(differ,seqList.size())),documentDevice.getAbnormal()));
}else {
documentDevice.setDeviceSerialNumber(isAddUnderline(String.join("",seqList.subList(0,seqList.size())),documentDevice.getAbnormal()));
}
if (pasList.size()>differ){
documentDevice.setParts(String.join("",pasList.subList(0,differ)));
documentDevice1.setParts(String.join("",pasList.subList(differ,pasList.size())));
}else {
documentDevice.setParts(String.join("",pasList.subList(0,pasList.size())));
}
if (remarkList.size()>differ){
documentDevice.setRemark(String.join("",remarkList.subList(0,differ)));
documentDevice1.setRemark(String.join("",remarkList.subList(differ,remarkList.size())));
}else {
documentDevice.setRemark(String.join("",remarkList));
}
code++;
documentDevice.setCode(code);
documentDevice.setOneCount(differ);
documentDevices.add(documentDevice);
lists.add(documentDevices);
documentDevices=new ArrayList<>();
code++;
documentDevice1.setCode(code);
documentDevice1.setOneCount(max-differ);
documentDevices.add(documentDevice1);
i=max-differ;
}else {
String s=String.join("",toListString(documentDevice.getDeviceSerialNumber(),56));
code++;
documentDevice.setModel(String.join("",toListString(documentDevice.getModel(),17)));
documentDevice.setParts(String.join("",toListString(documentDevice.getParts(),17)));
documentDevice.setRemark(String.join("",toListString(documentDevice.getRemark(),15)));
documentDevice.setCode(code);
documentDevice.setOneCount(max);
documentDevice.setDeviceSerialNumber(isAddUnderline(s,documentDevice.getAbnormal()));
documentDevices.add(documentDevice);
i=i+max;
}
}
if (documentDevices.size()!=0){
lists.add(documentDevices);
}
return lists;
}
private static String isAddUnderline(String seq,Integer isNot){
if (isNot!=null && isNot==1) {
return "<span class=\"decorationLine\">"+seq+"</span>";
}else {
return seq;
}
}
/**
* freemarker渲染html 签字图片
*/
public static String[] freeMarkerRenderNew(Documents documents,String htmlPath) {
Writer out = new StringWriter();
String [] strings=new String[100000];
int index=0;
try {
String QRCode= ZXingUtil.encode(documents.getId());
// 获取模板,并设置编码方式
Template template = freemarkerCfg.getTemplate("billSignature.html");
template.setEncoding("UTF-8");
List<DocumentDevice> list=documents.getDocumentDevices();
List<List<DocumentDevice>> listList=toDocList(list);
int count=listList.size();
for (int i=1; i<=3; i++){
Integer page=1;
for (List<DocumentDevice> list1:listList) {
String htmlname=htmlPath+ UUID.randomUUID().toString()+".html";
// 合并数据模型与模板
FileWriter fileWriter = new FileWriter(new File(htmlname));
template.process(toMapNew(documents,list1,MAP.get(i),page,count,QRCode),fileWriter);
out.flush();
strings[index]=htmlname;
index++;
page++;
}
}
return strings;
} catch (Exception e) {
log.error("[freeMarkerRender] 方法找不到地址:{}",htmlPath);
} finally {
try {
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return null;
}
private static Map<String,Object> toMapNew(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()+"\"");
}
if (documents.getUserSrcA1()==null||documents.getUserSrcA1().equals("")){
data.put("userSrcA1","\""+1+"\"");
}else {
data.put("userSrcA1","\""+documents.getUserSrcA1()+"\"");
}
if (documents.getUserSrcA2()==null||documents.getUserSrcA2().equals("")){
data.put("userSrcA2","\""+1+"\"");
}else {
data.put("userSrcA2","\""+documents.getUserSrcA2()+"\"");
}
if (documents.getUserSrcB1()==null||documents.getUserSrcB1().equals("")){
data.put("userSrcB1","\""+1+"\"");
}else {
data.put("userSrcB1","\""+documents.getUserSrcB1()+"\"");
}
if (documents.getUserSrcB2()==null||documents.getUserSrcB2().equals("")){
data.put("userSrcB2","\""+1+"\"");
}else {
data.put("userSrcB2","\""+documents.getUserSrcB2()+"\"");
}
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",list);
return data;
}
} }
...@@ -304,8 +304,14 @@ ...@@ -304,8 +304,14 @@
</div> </div>
</p> </p>
<div style="height: 853px;overflow: hidden"> <div style="height: 853px;overflow: hidden">
<#list checks as dev>
<table class="altrowstable" border="0" id="alternatecolor"> <table class="altrowstable" border="0" id="alternatecolor">
<tr>
<th>型号</th>
<th>名称</th>
<th>数量</th>
</tr>
<#list checks as dev>
<#if (dev.model)??> <#if (dev.model)??>
<#if dev.isPart == 0> <#if dev.isPart == 0>
<tr> <tr>
...@@ -394,8 +400,8 @@ ...@@ -394,8 +400,8 @@
<td colspan="3" class="td30" style="text-align: left;padding: 0 2em;color: #555;">${dev.seqStirng!}</td> <td colspan="3" class="td30" style="text-align: left;padding: 0 2em;color: #555;">${dev.seqStirng!}</td>
</#if> </#if>
</tr> </tr>
</#list>
</table> </table>
</#list>
</div> </div>
</div> </div>
<p class="person" style="margin-top: 10px;font-size: 15px;width: 100%;text-align: left;"> <p class="person" style="margin-top: 10px;font-size: 15px;width: 100%;text-align: left;">
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论