fix:优化header和title生成
This commit is contained in:
parent
5eb536c21d
commit
f7e8a4ed02
|
@ -3,6 +3,7 @@ package org.jeecg.common.util;
|
|||
import cn.hutool.core.lang.Console;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.modules.base.bizVo.AttributeItemVo;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -121,13 +122,7 @@ public class MyLogFormatUtil {
|
|||
data.put("Acquisition Start", "2023/09/13 01:25:45");
|
||||
data.put("Acquisition Stop", "2023/09/14 01:05:17");
|
||||
data.put("Acquisition Time[s]", 85435);
|
||||
|
||||
int keyWidth = 20;
|
||||
int valueWidth = 25;
|
||||
|
||||
getBlockContext(data);
|
||||
Console.log(getTitleFormat("title","."));
|
||||
Console.log(getHeaderFormat("header","."));
|
||||
|
||||
|
||||
List<String> channels = Arrays.asList("59.541", "88.034", "122.061", "165.857", "391.698", "661.657", "834.838", "898.036", "1115.540", "1173.230", "1332.490", "1836.050");
|
||||
|
@ -147,36 +142,11 @@ public class MyLogFormatUtil {
|
|||
attributeItemVo.setAttribute("Error");
|
||||
attributeItemVo.setContext(errors);
|
||||
energys.add(attributeItemVo);
|
||||
MyLogFormatUtil.getBlock(MyLogFormatUtil.SetSampleGEnergyChannel, "sampleId", energys);
|
||||
// MyLogFormatUtil.getBlock(MyLogFormatUtil.SetSampleGEnergyChannel, "sampleId", energys);
|
||||
|
||||
|
||||
// 报告
|
||||
List<List<String>> report = Lists.newLinkedList();
|
||||
report.add(channels);
|
||||
report.add(energies);
|
||||
report.add(errors);
|
||||
getBlockVerticalContext(energys);
|
||||
|
||||
// List<AttributeItem> data = new ArrayList<>();
|
||||
// AttributeItem attributeItem = new AttributeItem();
|
||||
// attributeItem.setAttribute("channel");
|
||||
// attributeItem.setUnit(" ");
|
||||
// attributeItem.setContext(channels);
|
||||
//
|
||||
// AttributeItem attributeItem1 = new AttributeItem();
|
||||
// attributeItem1.setAttribute("energies");
|
||||
// attributeItem1.setUnit(" dev");
|
||||
// attributeItem1.setContext(energies);
|
||||
//
|
||||
// AttributeItem attributeItem2 = new AttributeItem();
|
||||
// attributeItem2.setAttribute("errors");
|
||||
// attributeItem2.setUnit(" ");
|
||||
// attributeItem2.setContext(errors);
|
||||
//
|
||||
// data.add(attributeItem);
|
||||
// data.add(attributeItem1);
|
||||
// data.add(attributeItem2);
|
||||
// setBlock(new GammaArrLog().totalEfficiencyChannel, "abc", data);
|
||||
Console.log(getTitleFormat("Read calibration finished","."));
|
||||
Console.log(getHeaderFormat("header","."));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,7 +158,9 @@ public class MyLogFormatUtil {
|
|||
*/
|
||||
public static String getTitleFormat(String title, String flag) {
|
||||
int padding = (CONTEXT_TITLE_SIZE - title.length()) / 2;
|
||||
return String.format("%" + padding + "s%s%" + padding + "s", flag, title, flag).replace(" ",flag);
|
||||
// 两边填充flag
|
||||
flag = StringUtils.repeat(flag, padding);
|
||||
return String.format("%" + padding + "s%s%" + padding + "s", flag, " "+ title + " " , flag, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,8 +171,9 @@ public class MyLogFormatUtil {
|
|||
*/
|
||||
public static String getTitleFormat(String title) {
|
||||
int padding = (CONTEXT_TITLE_SIZE - title.length()) / 2;
|
||||
return String.format("%" + padding + "s%s%" + padding + "s", CONTEXT_TITLE_FLAG, title, CONTEXT_TITLE_FLAG)
|
||||
.replace(" ",CONTEXT_TITLE_FLAG);
|
||||
// 两边填充flag
|
||||
String flag = StringUtils.repeat(CONTEXT_TITLE_FLAG, padding);
|
||||
return String.format("%" + padding + "s%s%" + padding + "s", flag, " "+ title + " ", flag, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,7 +184,9 @@ public class MyLogFormatUtil {
|
|||
* @return
|
||||
*/
|
||||
public static String getHeaderFormat(String title, String flag) {
|
||||
return String.format("%s%" + CONTEXT_HEADER_SIZE + "s", title, flag, "\n").replace(" ",flag);
|
||||
// 两边填充flag
|
||||
flag = StringUtils.repeat(flag, CONTEXT_HEADER_SIZE);
|
||||
return String.format("%s%" + CONTEXT_HEADER_SIZE + "s", title, flag, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,29 +196,11 @@ public class MyLogFormatUtil {
|
|||
* @return
|
||||
*/
|
||||
public static String getHeaderFormat(String title) {
|
||||
return String.format("%s%" + CONTEXT_HEADER_SIZE + "s", title, FILE_TITLE_FLAG, "\n")
|
||||
.replace(" ", FILE_TITLE_FLAG);
|
||||
// 两边填充flag
|
||||
String flag = StringUtils.repeat(CONTEXT_TITLE_FLAG, CONTEXT_HEADER_SIZE);
|
||||
return String.format("%s%" + CONTEXT_HEADER_SIZE + "s", title, flag, "\n");
|
||||
}
|
||||
|
||||
// public void getBlockFormatData(List<Object> data) {
|
||||
// if(data.get(0) instanceof AttributeItemVo){
|
||||
//
|
||||
// }
|
||||
// if(data.get(0) instanceof List){
|
||||
// List<List<String>> tempData = new LinkedList<>();
|
||||
// for(int row = 0; row < data.get(0).size(); row++) {
|
||||
// List<String> 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 内容
|
||||
|
@ -255,15 +212,16 @@ public class MyLogFormatUtil {
|
|||
int valueWidth = 0;
|
||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||
keyWidth = Math.max(entry.getKey().length(), keyWidth);
|
||||
valueWidth = Math.max(entry.getValue().toString().length(), valueWidth);
|
||||
String val = Objects.isNull(entry.getValue()) ? "" : entry.getValue().toString();
|
||||
valueWidth = Math.max(val.length(), valueWidth);
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String key = entry.getKey() + " :";
|
||||
Object value = entry.getValue();
|
||||
String formattedKey = String.format("%-"+ (keyWidth + 4) + "s", key);
|
||||
String formattedValue = String.format("%-"+ (valueWidth + 4) + "s", value);
|
||||
System.out.println(formattedKey + " : " + formattedValue);
|
||||
result.add(formattedKey + " : " + formattedValue);
|
||||
result.add(formattedKey + formattedValue + "\n");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -332,6 +290,9 @@ public class MyLogFormatUtil {
|
|||
*/
|
||||
public static List<String> formatData(List<List<String>> data) {
|
||||
List<String> result = new LinkedList<>();
|
||||
if (data.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
// 计算每列数据中最长的字符串长度
|
||||
int[] columnWidths = new int[data.get(0).size()];
|
||||
for (List<String> row : data) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user