Skip to content

Commit

Permalink
3.3.0-SNAPSHOT
Browse files Browse the repository at this point in the history
Great Change

Signed-off-by: sinri <[email protected]>
  • Loading branch information
sinri committed Aug 14, 2024
1 parent 6b1ea73 commit 6728bb4
Show file tree
Hide file tree
Showing 29 changed files with 162 additions and 121 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.sinri</groupId>
<artifactId>Keel</artifactId>
<version>3.2.16-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
<!-- <version>3.2.15</version>-->

<name>Keel</name>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/github/sinri/keel/poi/excel/KeelSheets.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.github.sinri.keel.poi.excel;

import io.github.sinri.keel.core.ValueBox;
import io.github.sinri.keel.poi.excel.reader.KeelSheetReader;
import io.github.sinri.keel.poi.excel.reader.options.SheetReadOptions;
import io.github.sinri.keel.poi.excel.writer.KeelSheetWriter;
import io.vertx.core.Handler;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
Expand Down

This file was deleted.

32 changes: 0 additions & 32 deletions src/main/java/io/github/sinri/keel/poi/excel/entity/Column.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.github.sinri.keel.poi.excel;
package io.github.sinri.keel.poi.excel.reader;

import io.github.sinri.keel.core.TechnicalPreview;
import io.github.sinri.keel.facade.async.KeelAsyncKit;
import io.github.sinri.keel.poi.excel.entity.*;
import io.github.sinri.keel.poi.excel.KeelSheet;
import io.github.sinri.keel.poi.excel.reader.entity.*;
import io.github.sinri.keel.poi.excel.reader.options.ColumnReadOptions;
import io.github.sinri.keel.poi.excel.reader.options.SheetReadOptions;
import io.vertx.core.Future;
import org.apache.poi.ss.usermodel.*;

Expand Down Expand Up @@ -67,7 +70,7 @@ public static int autoDetectNonBlankColumnCountInOneRow(Row row) {
private static String dumpCellToString(
@Nullable Cell cell,
@Nonnull SheetReadOptions readOptions,
@Nullable SheetColumnReadOptions columnReadOptions
@Nullable ColumnReadOptions columnReadOptions
) {
if (cell == null) return "";

Expand Down Expand Up @@ -138,7 +141,7 @@ private static String dumpCellToString(

for (int i = 0; i < maxColumns; i++) {
@Nullable Cell cell = row.getCell(i, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
SheetColumnReadOptions columnReadOptions = readOptions.getColumnReadOptions(i);
ColumnReadOptions columnReadOptions = readOptions.getColumnReadOptions(i);
String s = dumpCellToString(cell, readOptions, columnReadOptions);
rowDatum.add(s);
}
Expand Down Expand Up @@ -464,4 +467,20 @@ public KeelSheetMatrixTemplatedRow next() {
}
};
}

public List<ColumnReadOptions> buildColumnListDefinition() {
Optional<Integer> max = this.readOptions.getColumnReadOptionsMap().keySet().stream().max(Comparator.comparingInt(o -> o));
if (max.isPresent()) {
List<ColumnReadOptions> list = new ArrayList<>(max.get());
for (int i = 0; i < max.get() - 1; i++) {
ColumnReadOptions sheetColumnReadOptions = this.readOptions.getColumnReadOptionsMap().get(i);
if (sheetColumnReadOptions == null) {
sheetColumnReadOptions = this.readOptions.getDefaultColumnReadOptions();
}
list.set(i, ColumnReadOptions.build(sheetColumnReadOptions.getColumnName(), sheetColumnReadOptions.getColumnType()));
}
return list;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sinri.keel.poi.excel;
package io.github.sinri.keel.poi.excel.reader;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.entity;

import io.github.sinri.keel.poi.excel.reader.options.ColumnReadOptions;

import javax.annotation.Nonnull;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -113,4 +116,21 @@ public R next() {
return this.rawRow2row.apply(rawRow);
}
}

/**
* Convert and merge each content row into entities.
*
* @see <a href="https://github.com/FasterXML/jackson-databind">Jackson Databind</a>
* @since 3.2.16
*/
public <T> List<T> toBoundDataEntities(@Nonnull List<ColumnReadOptions> columns, Class<T> tClass) {
List<T> list = new ArrayList<>();
Iterator<KeelSheetMatrixRow> rowIterator = getRowIterator();
while (rowIterator.hasNext()) {
KeelSheetMatrixRow row = rowIterator.next();
T t = row.toJsonObject(columns).mapTo(tClass);
list.add(t);
}
return list;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.entity;

import io.github.sinri.keel.poi.excel.reader.options.ColumnReadOptions;
import io.vertx.core.json.JsonObject;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -47,8 +48,6 @@ public Integer readValueToInteger(int i) {
} catch (ArithmeticException arithmeticException) {
return null;
}
// double v = readValueToDouble(i);
// return (int) v;
}

@Nullable
Expand All @@ -58,24 +57,21 @@ public Long readValueToLong(int i) {
} catch (ArithmeticException arithmeticException) {
return null;
}
// double v = readValueToDouble(i);
// return (long) v;
}

public double readValueToDouble(int i) {
return readValueToBigDecimal(i).doubleValue();
// return Double.parseDouble(readValue(i));
}

/**
* @param columns definitions of columns as list
* @return a json object with each column in defined type
* @since 3.2.16
*/
public JsonObject toJsonObject(@Nonnull List<Column> columns) {
public JsonObject toJsonObject(@Nonnull List<ColumnReadOptions> columns) {
JsonObject jsonObject = new JsonObject();
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i);
ColumnReadOptions column = columns.get(i);
Object value;
switch (column.getColumnType()) {
case Long:
Expand All @@ -95,15 +91,17 @@ public JsonObject toJsonObject(@Nonnull List<Column> columns) {
value = readValue(i);
break;
}
jsonObject.put(column.getName(), value);
jsonObject.put(column.getColumnName(), value);
}
return jsonObject;
}

/**
* @since 3.2.16
* Use Jackson to map Json Object to a java class.
* @see <a href="https://github.com/FasterXML/jackson-databind">Jackson Databind</a>
*/
public <T> T toBoundDataEntity(@Nonnull List<Column> columns, Class<T> tClass) {
public <T> T toBoundDataEntity(@Nonnull List<ColumnReadOptions> columns, Class<T> tClass) {
return toJsonObject(columns).mapTo(tClass);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.entity;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.entity;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.entity;

import io.vertx.core.json.JsonObject;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.entity;

import io.vertx.core.json.JsonObject;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.entity;

import javax.annotation.Nonnull;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.entity;

import javax.annotation.Nonnull;
import java.util.ArrayList;
Expand All @@ -11,12 +11,10 @@
public class KeelSheetTemplatedMatrixImpl implements KeelSheetTemplatedMatrix {
private final KeelSheetMatrixRowTemplate template;
private final List<List<String>> rawRows;
//private final List<KeelSheetMatrixTemplatedRow> templatedRows;

KeelSheetTemplatedMatrixImpl(@Nonnull KeelSheetMatrixRowTemplate template) {
this.template = template;
this.rawRows = new ArrayList<>();
// this.templatedRows = new ArrayList<>();
}

@Override
Expand Down Expand Up @@ -47,7 +45,6 @@ public List<KeelSheetMatrixTemplatedRow> getRows() {
@Override
public KeelSheetTemplatedMatrix addRawRow(@Nonnull List<String> rawRow) {
this.rawRows.add(rawRow);
//this.templatedRows.add(KeelSheetMatrixTemplatedRow.create(getTemplate(), rawRow));
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package io.github.sinri.keel.poi.excel.reader.entity;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.github.sinri.keel.poi.excel.reader.options;

import javax.annotation.Nullable;
import java.text.SimpleDateFormat;

public class ColumnReadOptions {
private boolean formatDateTime = true;
private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private ColumnType columnType = ColumnType.String;
@Nullable
private String columnName;

public static ColumnReadOptions build(String columnName, ColumnType columnType) {
return new ColumnReadOptions().setColumnType(columnType).setColumnName(columnName);
}

public ColumnType getColumnType() {
return columnType;
}

public ColumnReadOptions setColumnType(ColumnType columnType) {
this.columnType = columnType;
return this;
}

@Nullable
public String getColumnName() {
return columnName;
}

public ColumnReadOptions setColumnName(@Nullable String columnName) {
this.columnName = columnName;
return this;
}

public boolean isFormatDateTime() {
return formatDateTime;
}

public ColumnReadOptions setFormatDateTime(boolean formatDateTime) {
this.formatDateTime = formatDateTime;
return this;
}

public SimpleDateFormat getDateTimeFormat() {
return dateTimeFormat;
}

public ColumnReadOptions setDateTimeFormat(SimpleDateFormat dateTimeFormat) {
this.dateTimeFormat = dateTimeFormat;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.sinri.keel.poi.excel.entity;
package io.github.sinri.keel.poi.excel.reader.options;

/**
* @since 3.2.16
Expand Down
Loading

0 comments on commit 6728bb4

Please sign in to comment.