|
@@ -2,6 +2,7 @@ package com.om.utils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
import com.itextpdf.io.font.PdfEncodings;
|
|
import com.itextpdf.io.font.PdfEncodings;
|
|
import com.itextpdf.io.image.BmpImageData;
|
|
import com.itextpdf.io.image.BmpImageData;
|
|
import com.itextpdf.io.image.ImageData;
|
|
import com.itextpdf.io.image.ImageData;
|
|
@@ -24,8 +25,12 @@ import com.itextpdf.layout.element.*;
|
|
import com.itextpdf.layout.property.BorderRadius;
|
|
import com.itextpdf.layout.property.BorderRadius;
|
|
import com.itextpdf.layout.property.HorizontalAlignment;
|
|
import com.itextpdf.layout.property.HorizontalAlignment;
|
|
import com.itextpdf.layout.property.TextAlignment;
|
|
import com.itextpdf.layout.property.TextAlignment;
|
|
|
|
+import com.itextpdf.layout.property.UnitValue;
|
|
import com.om.entity.dto.ControlListMap;
|
|
import com.om.entity.dto.ControlListMap;
|
|
|
|
+import com.om.entity.po.FaultCode;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
@@ -51,7 +56,8 @@ import java.util.Map;
|
|
@Component
|
|
@Component
|
|
public class ITextPdfUtil {
|
|
public class ITextPdfUtil {
|
|
//字体,我这里使用系统自带的simhei黑体
|
|
//字体,我这里使用系统自带的simhei黑体
|
|
- //private static final String FONT = "C:/Windows/Fonts/simhei.ttf";
|
|
|
|
|
|
+ // private static final String FONT = "C:/Windows/Fonts/simhei.ttf";
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ITextPdfUtil.class);
|
|
private static final String FONT = "/usr/local/docker/opera/static/simhei.ttf";
|
|
private static final String FONT = "/usr/local/docker/opera/static/simhei.ttf";
|
|
|
|
|
|
@Value("${baseStatic}")
|
|
@Value("${baseStatic}")
|
|
@@ -166,11 +172,13 @@ public class ITextPdfUtil {
|
|
for (ControlListMap listMap : controlListMap) {
|
|
for (ControlListMap listMap : controlListMap) {
|
|
String name = listMap.getName();
|
|
String name = listMap.getName();
|
|
Map<String, String> versionMap = listMap.getVersionMap();
|
|
Map<String, String> versionMap = listMap.getVersionMap();
|
|
- Map<String, String> faultCodeMap = listMap.getFaultCodeMap();
|
|
|
|
|
|
+ Map<String, FaultCode> faultCodeMap = listMap.getFaultCodeMap();
|
|
|
|
+ log.debug("versionMap::{}",versionMap);
|
|
|
|
+ log.debug("faultCodeMap::{}",faultCodeMap);
|
|
|
|
|
|
- Table faultCodeTable = new Table(2);
|
|
|
|
|
|
+ Table faultCodeTable = new Table(3);
|
|
|
|
|
|
- mapToTable(faultCodeMap, faultCodeTable, red, red);
|
|
|
|
|
|
+ mapToTableFault(faultCodeMap, faultCodeTable, red, red);
|
|
|
|
|
|
Table versionTable = new Table(2);
|
|
Table versionTable = new Table(2);
|
|
|
|
|
|
@@ -257,7 +265,6 @@ public class ITextPdfUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private void mapToTable(Map<String, String> map, Table table, Color one, Color two) {
|
|
private void mapToTable(Map<String, String> map, Table table, Color one, Color two) {
|
|
table.setMargin(10);
|
|
table.setMargin(10);
|
|
table.setWidth(570);
|
|
table.setWidth(570);
|
|
@@ -266,9 +273,9 @@ public class ITextPdfUtil {
|
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
table.addCell(entry.getKey() + ": ")
|
|
table.addCell(entry.getKey() + ": ")
|
|
.setFontColor(one);
|
|
.setFontColor(one);
|
|
- String value = entry.getValue();
|
|
|
|
- if (StringUtils.isEmpty(value)) {
|
|
|
|
- value = " ";
|
|
|
|
|
|
+ String value = entry.getValue();
|
|
|
|
+ if (StringUtils.isBlank(value)) {
|
|
|
|
+ value = "";
|
|
}
|
|
}
|
|
table.addCell(new Cell()
|
|
table.addCell(new Cell()
|
|
.add(new Paragraph(value))
|
|
.add(new Paragraph(value))
|
|
@@ -277,6 +284,28 @@ public class ITextPdfUtil {
|
|
RemoveBorder(table);
|
|
RemoveBorder(table);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ private void mapToTableFault(Map<String, FaultCode> map, Table table, Color one, Color two) {
|
|
|
|
+ table.setMargin(10);
|
|
|
|
+ table.setWidth(570);
|
|
|
|
+ table.setFontSize(16);
|
|
|
|
+ table.setFontColor(new DeviceRgb(136, 136, 136));
|
|
|
|
+ table.setWidth(UnitValue.createPercentValue(100)); // 调整宽度以适应页面
|
|
|
|
+
|
|
|
|
+ for (Map.Entry<String, FaultCode> entry : map.entrySet()) {
|
|
|
|
+ String key = entry.getKey();
|
|
|
|
+ FaultCode faultCode = entry.getValue();
|
|
|
|
+
|
|
|
|
+ // 将键、描述和状态添加到同一行
|
|
|
|
+ table.addCell(new Cell().add(new Paragraph(key)).setFontColor(one));
|
|
|
|
+ table.addCell(new Cell().add(new Paragraph(faultCode.getDescription())).setFontColor(two));
|
|
|
|
+ table.addCell(new Cell().add(new Paragraph(faultCode.getStatus())).setFontColor(two));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ RemoveBorder(table);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private void RemoveBorder(Table table) {
|
|
private void RemoveBorder(Table table) {
|
|
for (IElement iElement : table.getChildren()) {
|
|
for (IElement iElement : table.getChildren()) {
|
|
((Cell) iElement).setBorder(Border.NO_BORDER);
|
|
((Cell) iElement).setBorder(Border.NO_BORDER);
|