Search in sources :

Example 1 with FileImportResult

use of com.varsql.web.dto.file.FileImportResult in project varsql by varsqlinfo.

the class FileImportExportServiceImpl method importFile.

/**
 * @Method Name  : importFile
 * @Method 설명 : import file
 * @작성자   : ytkim
 * @작성일   : 2020. 11. 22.
 * @변경이력  :
 */
public ResponseResult importFile(FileImportInfo fii) {
    String conuid = fii.getConuid();
    String importType = fii.getImportType();
    List<FileInfoEntity> importFileList = fileInfoEntityRepository.findAllById(Arrays.asList(CommUtils.getFileIds(fii.getFileIds())));
    ResponseResult result = new ResponseResult();
    List<FileImportResult> resultInfo = new ArrayList<>();
    importFileList.forEach(fileInfo -> {
        FileImportResult fileImportResult = new FileImportResult();
        try {
            fileImportResult.setFileName(fileInfo.getFileName());
            SQLExecuteResult ser = null;
            if ("sql".equals(importType)) {
                ser = sqlImport(fileInfo, conuid);
            } else if ("xml".equals(importType)) {
                ser = xmlImport(fileInfo, conuid);
            } else if ("json".equals(importType)) {
                ser = jsonImport(fileInfo, conuid);
            } else if ("csv".equals(importType)) {
                ser = csvImport(fileInfo, conuid);
            }
            if (ser.getResultCode() != null) {
                fileImportResult.setResultCode(ser.getResultCode());
            }
            fileImportResult.setResultCount(ser.getExecuteCount());
            fileImportResult.setMessage(ser.getMessage());
        } catch (IOException | SQLException e) {
            fileImportResult.setResultCode(VarsqlAppCode.ERROR);
            fileImportResult.setMessage(e.getMessage());
            logger.error("file import error importType : {} , conuid : {} , fileInfo :{} ", importType, fileInfo);
            logger.error("error message : {}", e.getMessage(), e);
        }
        resultInfo.add(fileImportResult);
    });
    result.setItemList(resultInfo);
    return result;
}
Also used : SQLException(java.sql.SQLException) ResponseResult(com.vartech.common.app.beans.ResponseResult) ArrayList(java.util.ArrayList) SQLExecuteResult(com.varsql.core.sql.executor.SQLExecuteResult) FileInfoEntity(com.varsql.web.model.entity.app.FileInfoEntity) FileImportResult(com.varsql.web.dto.file.FileImportResult) IOException(java.io.IOException)

Aggregations

SQLExecuteResult (com.varsql.core.sql.executor.SQLExecuteResult)1 FileImportResult (com.varsql.web.dto.file.FileImportResult)1 FileInfoEntity (com.varsql.web.model.entity.app.FileInfoEntity)1 ResponseResult (com.vartech.common.app.beans.ResponseResult)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1