use of cn.devezhao.commons.excel.Cell in project rebuild by getrebuild.
the class DataImporter method exec.
@Override
protected Integer exec() {
final List<Cell[]> rows = new DataFileParser(rule.getSourceFile()).parse();
this.setTotal(rows.size() - 1);
owningUser = rule.getDefaultOwningUser() != null ? rule.getDefaultOwningUser() : getUser();
GeneralEntityServiceContextHolder.setSkipSeriesValue();
for (final Cell[] row : rows) {
if (isInterrupt()) {
this.setInterrupted();
break;
}
Cell fc = row == null || row.length == 0 ? null : row[0];
if (fc == null || fc.getRowNo() == 0) {
continue;
}
try {
Record record = checkoutRecord(row);
if (record == null) {
traceLogs.add(new Object[] { fc.getRowNo(), "SKIP" });
} else {
boolean isNew = record.getPrimary() == null;
record = Application.getEntityService(rule.getToEntity().getEntityCode()).createOrUpdate(record);
this.addSucceeded();
traceLogs.add(new Object[] { fc.getRowNo(), isNew ? "CREATED" : "UPDATED", record.getPrimary(), cellTraces });
}
} catch (Exception ex) {
traceLogs.add(new Object[] { fc.getRowNo(), "ERROR", ex.getLocalizedMessage() });
log.error("ROW#{} > {}", fc.getRowNo(), ex.getLocalizedMessage());
}
this.addCompleted();
}
return this.getSucceeded();
}
use of cn.devezhao.commons.excel.Cell in project rebuild by getrebuild.
the class RecordCheckout method checkoutN2NReferenceValue.
protected ID[] checkoutN2NReferenceValue(Field field, Cell cell) {
final String val = cell.asString();
Set<ID> ids = new LinkedHashSet<>();
for (String s : val.split("[,,;;]")) {
ID id = checkoutReferenceValue(field, new Cell(s, cell.getRowNo(), cell.getColumnNo()));
if (id != null)
ids.add(id);
}
return ids.toArray(new ID[0]);
}
use of cn.devezhao.commons.excel.Cell in project rebuild by getrebuild.
the class RecordCheckout method checkout.
/**
* @param record
* @param row
* @return
*/
public Record checkout(Record record, Cell[] row) {
for (Map.Entry<Field, Integer> e : this.fieldsMapping.entrySet()) {
int cellIndex = e.getValue();
if (cellIndex >= row.length)
continue;
Cell cellValue = row[cellIndex];
if (cellValue == Cell.NULL || cellValue.isEmpty()) {
continue;
}
Field field = e.getKey();
Object value = checkoutFieldValue(field, cellValue, true);
if (value != null) {
record.setObjectValue(field.getName(), value);
} else {
putTraceLog(cellValue, Language.L(EasyMetaFactory.getDisplayType(field)));
}
}
return record;
}
use of cn.devezhao.commons.excel.Cell in project rebuild by getrebuild.
the class ClassificationFileImporter method exec.
@Override
protected Integer exec() throws Exception {
List<Cell[]> rows = new DataFileParser(file).parse();
this.setTotal(rows.size() - 1);
boolean first = true;
for (Cell[] row : rows) {
if (first) {
first = false;
continue;
}
if (row.length == 0) {
continue;
}
this.addCompleted();
String L1 = row[0].asString();
if (StringUtils.isBlank(L1)) {
continue;
}
ID L1Id = findOrCreate(L1, null, null, LEVEL_BEGIN);
String L2 = row.length > 1 ? row[1].asString() : null;
if (StringUtils.isBlank(L2)) {
continue;
}
ID L2Id = findOrCreate(L2, null, L1Id, LEVEL_BEGIN + 1);
String L3 = row.length > 2 ? row[2].asString() : null;
if (StringUtils.isBlank(L3)) {
continue;
}
ID L3Id = findOrCreate(L3, null, L2Id, LEVEL_BEGIN + 2);
String L4 = row.length > 3 ? row[3].asString() : null;
if (StringUtils.isBlank(L4)) {
continue;
}
findOrCreate(L4, null, L3Id, LEVEL_BEGIN + 3);
}
return this.getSucceeded();
}
use of cn.devezhao.commons.excel.Cell in project rebuild by getrebuild.
the class RecordCheckoutTest method checkoutMultiSelectValue.
@Test
void checkoutMultiSelectValue() {
RecordCheckout checkout = new RecordCheckout(null);
Field MULTISELECT = MetadataHelper.getEntity(TestAllFields).getField("MULTISELECT");
checkout.checkoutMultiSelectValue(MULTISELECT, new Cell("1哈哈; 3"));
}
Aggregations