From a794d8f357ad124fd04070a2a84dff04a134b6dc Mon Sep 17 00:00:00 2001 From: orgin Date: Mon, 18 Sep 2023 19:08:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=83=BD=E8=B0=B1log=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/util/MyLogFormatUtil.java | 113 ++++++++++++++---- 1 file changed, 87 insertions(+), 26 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyLogFormatUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyLogFormatUtil.java index 4541e506..ea298212 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyLogFormatUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/MyLogFormatUtil.java @@ -139,17 +139,23 @@ public class MyLogFormatUtil { attributeItemVo.setAttribute("Channel"); attributeItemVo.setContext(channels); energys.add(attributeItemVo); -// attributeItem = new AttributeItem(); -// attributeItem.setAttribute("Energy"); -// attributeItem.setContext(energies); -// energys.add(attributeItem); -// attributeItem = new AttributeItem(); -// attributeItem.setAttribute("Error"); -// attributeItem.setContext(errors); + attributeItemVo = new AttributeItemVo(); + attributeItemVo.setAttribute("Energy"); + attributeItemVo.setContext(energies); + energys.add(attributeItemVo); + attributeItemVo = new AttributeItemVo(); + attributeItemVo.setAttribute("Error"); + attributeItemVo.setContext(errors); energys.add(attributeItemVo); MyLogFormatUtil.getBlock(MyLogFormatUtil.SetSampleGEnergyChannel, "sampleId", energys); + // 报告 + List> report = Lists.newLinkedList(); + report.add(channels); + report.add(energies); + report.add(errors); + getBlockVerticalContext(energys); // List data = new ArrayList<>(); // AttributeItem attributeItem = new AttributeItem(); @@ -219,6 +225,25 @@ public class MyLogFormatUtil { .replace(" ", FILE_TITLE_FLAG); } +// public void getBlockFormatData(List data) { +// if(data.get(0) instanceof AttributeItemVo){ +// +// } +// if(data.get(0) instanceof List){ +// List> tempData = new LinkedList<>(); +// for(int row = 0; row < data.get(0).size(); row++) { +// List items = new LinkedList<>(); +// tempData.add(items); +// // 获取有多少列数据 +// for(int column = 0; column < data.size(); column++) { +// if(data.get(column).size() > row) { +// items.add(data.get(column).get(row)); +// } +// } +// } +// } +// } + /** * 获取内容正文 * @param data 内容 @@ -250,7 +275,7 @@ public class MyLogFormatUtil { */ public static List getBlockContext(List data) { List result = new LinkedList<>(); - List> tempData = new ArrayList<>(); + List> tempData = new LinkedList<>(); if(data.size() > 0) { // 初始化数据 for(int row = 0; row < data.get(0).getContext().size(); row++) { @@ -264,31 +289,67 @@ public class MyLogFormatUtil { } } } + result.addAll(formatData(tempData)); + } + return result; + } - // 计算每列数据中最长的字符串长度 - int[] columnWidths = new int[tempData.get(0).size()]; - for (List row : tempData) { - for (int i = 0; i < row.size(); i++) { - columnWidths[i] = Math.max(columnWidths[i], row.get(i).length()); + /** + * 获取竖排数据 + * @param data + * @return + */ + public static List getBlockVerticalContext(List data) { + List result = new LinkedList<>(); + if(data.size() > 0) { + List> tempData = new LinkedList<>(); + // 行 + for(int row = 0; row < data.get(0).getContext().size(); row++) { + List columns = new LinkedList<>(); + tempData.add(columns); + // 获取有多少列数据 + for(int column = 0; column < data.size(); column++) { + AttributeItemVo item = data.get(column); + if(item.getContext().size() > row) { + columns.add(item.getContext().get(row) + " " + item.getUnit()); + } } } - - // 构造格式化字符串 - StringBuilder formatBuilder = new StringBuilder(); - for (int i = 0; i < columnWidths.length; i++) { - formatBuilder.append("%-").append(columnWidths[i] + 4).append("s"); - } - String format = formatBuilder.toString(); - // 格式化输出日志 - for (List row : tempData) { - result.add(String.format(format, row.toArray())); - Console.log(String.format(format, row.toArray())); - } - result.add(STRING_END); + result.addAll(formatData(tempData)); } return result; } + /** + * 格式化数据 + * @param data + * @return + */ + public static List formatData(List> data) { + List result = new LinkedList<>(); + // 计算每列数据中最长的字符串长度 + int[] columnWidths = new int[data.get(0).size()]; + for (List row : data) { + for (int i = 0; i < row.size(); i++) { + columnWidths[i] = Math.max(columnWidths[i], row.get(i).length()); + } + } + + // 构造格式化字符串 + StringBuilder formatBuilder = new StringBuilder(); + for (int i = 0; i < columnWidths.length; i++) { + formatBuilder.append("%-").append(columnWidths[i] + 4).append("s"); + } + String format = formatBuilder.toString(); + // 格式化输出日志 + for (List row : data) { + result.add(String.format(format, row.toArray())); + Console.log(String.format(format, row.toArray())); + } + result.add(STRING_END); + return result; + } + /** * 求百分比 * @param one 被除数