Search in sources :

Example 1 with DataFileParser

use of com.rebuild.core.service.dataimport.DataFileParser 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();
}
Also used : DataFileParser(com.rebuild.core.service.dataimport.DataFileParser) ID(cn.devezhao.persist4j.engine.ID) Cell(cn.devezhao.commons.excel.Cell)

Example 2 with DataFileParser

use of com.rebuild.core.service.dataimport.DataFileParser in project rebuild by getrebuild.

the class DataImportController method checkFile.

// 检查导入文件
@RequestMapping("/data-imports/check-file")
public RespBody checkFile(HttpServletRequest request) {
    String file = getParameterNotNull(request, "file");
    File tmp = getFileOfImport(file);
    if (tmp == null) {
        return RespBody.error(Language.L("数据文件无效"));
    }
    DataFileParser parser;
    int count = -1;
    List<Cell[]> preview;
    try {
        parser = new DataFileParser(tmp);
        preview = parser.parse(11);
    } catch (Exception ex) {
        log.error("Parse excel error : " + file, ex);
        return RespBody.error(Language.L("无法解析数据,请检查数据文件格式"));
    }
    return RespBody.ok(JSONUtils.toJSONObject(new String[] { "count", "preview" }, new Object[] { count, preview }));
}
Also used : DataFileParser(com.rebuild.core.service.dataimport.DataFileParser) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataFileParser (com.rebuild.core.service.dataimport.DataFileParser)2 Cell (cn.devezhao.commons.excel.Cell)1 ID (cn.devezhao.persist4j.engine.ID)1 JSONObject (com.alibaba.fastjson.JSONObject)1 File (java.io.File)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1