|
@@ -1,6 +1,8 @@
|
|
|
package org.eco.als.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import jakarta.annotation.Resource;
|
|
@@ -29,6 +31,7 @@ import org.eco.common.core.constant.Constants;
|
|
|
import org.eco.common.core.exception.BusinessException;
|
|
|
import org.eco.common.core.utils.HttpUtils;
|
|
|
import org.eco.common.core.utils.StringUtils;
|
|
|
+import org.eco.common.core.utils.file.FileUtils;
|
|
|
import org.eco.system.domain.vo.SysOssVo;
|
|
|
import org.eco.system.service.ISysOssService;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -233,16 +236,21 @@ public class AlgorithmService implements IAlgorithmService {
|
|
|
}
|
|
|
|
|
|
private SysOssVo getSysOssVo(AlgorithmBo algorithmBo) {
|
|
|
- File file = null;
|
|
|
- try (InputStream inputStream = ossService.getFileStream(algorithmBo.getOssId())) {
|
|
|
- file = CsvUtils.excelToFileCsvByColumns(inputStream, algorithmBo.getColumnData());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("文件转换异常:{}", e.getMessage());
|
|
|
+ SysOssVo sysOss = ossService.getById(algorithmBo.getOssId());
|
|
|
+ if (ObjectUtil.isNull(sysOss)) {
|
|
|
+ throw new BusinessException("文件数据不存在!");
|
|
|
}
|
|
|
- if (ObjectUtil.isNull(file)) {
|
|
|
- return null;
|
|
|
+ String path = StringUtils.substringAfter(sysOss.getFileName(), Constants.RESOURCE_PREFIX);
|
|
|
+ String tempPathCsv = EcoConfig.getTempPath() + "/" + CsvUtils.getName(FileUtils.getNameNotSuffix(sysOss.getOriginalName()));
|
|
|
+
|
|
|
+ JSONArray jsonArray =CsvUtils.getCsvDataByHeaders(path, Arrays.asList(algorithmBo.getColumnData()), null);
|
|
|
+ File file = CsvUtils.jsonToFileCsvByJsonArray(jsonArray, tempPathCsv);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotNull(file)) {
|
|
|
+ sysOss = ossService.upload(file);
|
|
|
}
|
|
|
- return ossService.upload(file);
|
|
|
+ FileUtil.del(tempPathCsv);
|
|
|
+ return sysOss;
|
|
|
}
|
|
|
|
|
|
@Override
|