mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-13 00:15:24 +00:00
perf[storage]: 统一使用valueOf构造新对象
This commit is contained in:
1 parent
a62e007f42
commit
f4d94c23e5
3 files changed
+17
-14
No files matched your search
@@ -29,6 +29,14 @@ public class ResourceData {
|
||||
// 配置表数据
|
||||
private List<ResourceRow> rows = new ArrayList<>();
|
||||
|
||||
public static ResourceData valueOf(String name, List<ResourceHeader> headers, List<ResourceRow> rows) {
|
||||
var resourceData = new ResourceData();
|
||||
resourceData.name = name;
|
||||
resourceData.headers = headers;
|
||||
resourceData.rows = rows;
|
||||
return resourceData;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -25,13 +25,12 @@ public class ResourceHeader {
|
||||
//列
|
||||
private int index;
|
||||
|
||||
public ResourceHeader() {
|
||||
}
|
||||
|
||||
public ResourceHeader(String name, String type, int index) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
public static ResourceHeader valueOf(String name, String type, int index) {
|
||||
var resourceHeader = new ResourceHeader();
|
||||
resourceHeader.name = name;
|
||||
resourceHeader.type = type;
|
||||
resourceHeader.index = index;
|
||||
return resourceHeader;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -61,13 +61,10 @@ public class ExcelToJsonUtils {
|
||||
public static ResourceData readResourceDataFromExcel(InputStream inputStream, String fileName) {
|
||||
// 只读取代码里写的字段
|
||||
var wb = createWorkbook(inputStream, fileName);
|
||||
var resource = new ResourceData();
|
||||
resource.setName(fileName);
|
||||
// 默认取到第一个sheet页
|
||||
var sheet = wb.getSheetAt(0);
|
||||
//设置所有列
|
||||
var headers = getHeaders(sheet, fileName);
|
||||
resource.setHeaders(headers);
|
||||
|
||||
// 行数定位到有效数据行,默认是第四行为有效数据行
|
||||
var iterator = sheet.iterator();
|
||||
@@ -84,10 +81,9 @@ public class ExcelToJsonUtils {
|
||||
var content = CellUtils.getCellStringValue(cell);
|
||||
columns.add(content);
|
||||
}
|
||||
rows.add(ResourceRow.valueOf(row.getRowNum(), columns));
|
||||
rows.add(ResourceRow.valueOf(row.getRowNum() + 1, columns));
|
||||
}
|
||||
resource.setRows(rows);
|
||||
return resource;
|
||||
return ResourceData.valueOf(fileName, headers, rows);
|
||||
}
|
||||
|
||||
// 只读取代码里写的字段
|
||||
@@ -127,7 +123,7 @@ public class ExcelToJsonUtils {
|
||||
if (Objects.nonNull(previousValue)) {
|
||||
throw new RunException("资源[class:{}]的Excel文件出现重复的属性控制列[field:{}]", fileName, fieldName);
|
||||
}
|
||||
headerList.add(new ResourceHeader(fieldName, typeName, i));
|
||||
headerList.add(ResourceHeader.valueOf(fieldName, typeName, i));
|
||||
}
|
||||
return headerList;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user