fix: 优化导入逻辑

This commit is contained in:
tangwei 2026-04-29 18:11:38 +08:00
parent eadea5945c
commit c068d0fa02
4 changed files with 38 additions and 61 deletions

View File

@ -7,6 +7,7 @@ import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.data.domain.FishDraftData; import com.yfd.platform.data.domain.FishDraftData;
import com.yfd.platform.data.domain.FishImportRequest; import com.yfd.platform.data.domain.FishImportRequest;
import com.yfd.platform.data.domain.FishImportResult; import com.yfd.platform.data.domain.FishImportResult;
import com.yfd.platform.data.domain.FishImportRowRequest;
import com.yfd.platform.data.domain.ImportTask; import com.yfd.platform.data.domain.ImportTask;
import com.yfd.platform.data.domain.BatchApproveRequest; import com.yfd.platform.data.domain.BatchApproveRequest;
import com.yfd.platform.data.domain.BatchRejectRequest; import com.yfd.platform.data.domain.BatchRejectRequest;
@ -404,18 +405,11 @@ public class FishDraftDataController {
} }
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("successRows", importResult.getSuccessRows() != null ? importResult.getSuccessRows().size() : 0);
map.put("failedRows", importResult.getFailedRows() != null ? importResult.getFailedRows().size() : 0);
map.put("unrecognizedFields", importResult.getUnrecognizedFields() != null ?
importResult.getUnrecognizedFields() : new ArrayList<>());
map.put("tempDir", importResult.getTempDir() != null ? importResult.getTempDir() : ""); map.put("tempDir", importResult.getTempDir() != null ? importResult.getTempDir() : "");
map.put("excelFileName", importResult.getExcelFileName() != null ? map.put("excelFileName", importResult.getExcelFileName() != null ?
importResult.getExcelFileName() : ""); importResult.getExcelFileName() : "");
map.put("failedRowDetails", importResult.getFailedRows() != null ? map.put("rows", importResult.getRows() != null ?
importResult.getFailedRows() : new ArrayList<>()); importResult.getRows() : new ArrayList<>());
map.put("successRowDetails", importResult.getSuccessRows() != null ?
importResult.getSuccessRows() : new ArrayList<>());
return map; return map;
} }
@ -443,4 +437,5 @@ public class FishDraftDataController {
return ResponseResult.error("删除失败"); return ResponseResult.error("删除失败");
} }
} }
} }

View File

@ -12,8 +12,10 @@ import java.util.Map;
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class FishImportResult { public class FishImportResult {
private List<FishImportRow> successRows; public static final String STATUS_SUCCESS = "SUCCESS";
private List<FishImportRow> failedRows; public static final String STATUS_FAILED = "FAILED";
private List<FishImportRow> rows;
private List<String> unrecognizedFields; private List<String> unrecognizedFields;
private Map<String, String> imageFiles; private Map<String, String> imageFiles;
private Map<String, String> videoFiles; private Map<String, String> videoFiles;
@ -29,13 +31,24 @@ public class FishImportResult {
private String taskId; private String taskId;
public FishImportResult() { public FishImportResult() {
this.successRows = new ArrayList<>(); this.rows = new ArrayList<>();
this.failedRows = new ArrayList<>();
this.unrecognizedFields = new ArrayList<>(); this.unrecognizedFields = new ArrayList<>();
this.imageFiles = new LinkedHashMap<>(); this.imageFiles = new LinkedHashMap<>();
this.videoFiles = new LinkedHashMap<>(); this.videoFiles = new LinkedHashMap<>();
} }
public void addSuccessRow(FishImportRow row) {
if (rows == null) rows = new ArrayList<>();
row.setStatus(STATUS_SUCCESS);
rows.add(row);
}
public void addFailedRow(FishImportRow row) {
if (rows == null) rows = new ArrayList<>();
row.setStatus(STATUS_FAILED);
rows.add(row);
}
@Data @Data
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public static class FishImportRow { public static class FishImportRow {
@ -47,6 +60,8 @@ public class FishImportResult {
private List<Map<String, String>> picpthList; private List<Map<String, String>> picpthList;
private List<String> vdpthsWarnings; private List<String> vdpthsWarnings;
private List<String> picpthsWarnings; private List<String> picpthsWarnings;
private String status;
public FishImportRow() { public FishImportRow() {
this.unrecognizedFields = new ArrayList<>(); this.unrecognizedFields = new ArrayList<>();
this.warnings = new ArrayList<>(); this.warnings = new ArrayList<>();
@ -57,13 +72,16 @@ public class FishImportResult {
} }
public FishImportRow(int rowIndex) { public FishImportRow(int rowIndex) {
this();
this.rowIndex = rowIndex; this.rowIndex = rowIndex;
this.unrecognizedFields = new ArrayList<>(); }
this.warnings = new ArrayList<>();
this.vdpthsWarnings = new ArrayList<>(); public boolean isSuccess() {
this.picpthsWarnings = new ArrayList<>(); return STATUS_SUCCESS.equals(status);
this.vdpthList = new ArrayList<>(); }
this.picpthList = new ArrayList<>();
public boolean isFailed() {
return STATUS_FAILED.equals(status);
} }
} }
} }

View File

@ -161,10 +161,10 @@ public class FishImportServiceImpl implements IFishImportService {
FishImportResult.FishImportRow importRow = parseRow(row, columnIndexMap, i); FishImportResult.FishImportRow importRow = parseRow(row, columnIndexMap, i);
result.setTotalCount(result.getTotalCount() + 1); result.setTotalCount(result.getTotalCount() + 1);
if (importRow.getData() != null && importRow.getWarnings().isEmpty()) { if (importRow.getData() != null && importRow.getWarnings().isEmpty()) {
result.getSuccessRows().add(importRow); result.addSuccessRow(importRow);
result.setSuccessCount(result.getSuccessCount() + 1); result.setSuccessCount(result.getSuccessCount() + 1);
} else { } else {
result.getFailedRows().add(importRow); result.addFailedRow(importRow);
result.setFailedCount(result.getFailedCount() + 1); result.setFailedCount(result.getFailedCount() + 1);
} }
} }
@ -763,8 +763,8 @@ public class FishImportServiceImpl implements IFishImportService {
processAttachments(result, zipContent); processAttachments(result, zipContent);
log.info("ZIP文件处理完成"); log.info("ZIP文件处理完成");
result.setSummary(result.getSummary() + String.format("\nZIP内容: 发现%d张图片, %d个视频, 临时目录: %s", result.setSummary(result.getSummary() + String.format("\nZIP内容: 发现%d张图片, %d个视频",
zipContent.images.size(), zipContent.videos.size(), zipContent.tempDir)); zipContent.images.size(), zipContent.videos.size()));
return result; return result;
@ -777,27 +777,7 @@ public class FishImportServiceImpl implements IFishImportService {
} }
private void processAttachments(FishImportResult result, ZipFileUtil.ZipContent zipContent) { private void processAttachments(FishImportResult result, ZipFileUtil.ZipContent zipContent) {
for (FishImportResult.FishImportRow importRow : result.getFailedRows()) { for (FishImportResult.FishImportRow importRow : result.getRows()) {
FishDraftData data = importRow.getData();
if (data == null) {
continue;
}
String vdpth = data.getVdpth();
String picpth = data.getPicpth();
if (StringUtils.hasText(vdpth)) {
String uploadedVdpth = processVideoAttachments(importRow,vdpth, zipContent.videos);
data.setVdpth(uploadedVdpth);
}
if (StringUtils.hasText(picpth)) {
String uploadedPicpth = processImageAttachments(importRow,picpth, zipContent.images);
data.setPicpth(uploadedPicpth);
}
}
for (FishImportResult.FishImportRow importRow : result.getSuccessRows()) {
FishDraftData data = importRow.getData(); FishDraftData data = importRow.getData();
if (data == null) { if (data == null) {
continue; continue;

View File

@ -185,7 +185,7 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
if (importTask.getResultJson() != null && !importTask.getResultJson().isEmpty()) { if (importTask.getResultJson() != null && !importTask.getResultJson().isEmpty()) {
try { try {
FishImportResult importResult = objectMapper.readValue(importTask.getResultJson(), FishImportResult.class); FishImportResult importResult = objectMapper.readValue(importTask.getResultJson(), FishImportResult.class);
for (FishImportResult.FishImportRow successRow : importResult.getSuccessRows()) { for (FishImportResult.FishImportRow successRow : importResult.getRows()) {
if (successRow.getData()==null) { if (successRow.getData()==null) {
continue; continue;
} }
@ -200,22 +200,6 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
fileIds.forEach(fileId -> attachmentUploadService.deleteFile(fileId)); fileIds.forEach(fileId -> attachmentUploadService.deleteFile(fileId));
} }
} }
for (FishImportResult.FishImportRow failedRow : importResult.getFailedRows()) {
if (failedRow.getData()==null) {
continue;
}
String vdpth = failedRow.getData().getVdpth();
if (StringUtils.hasText(vdpth)) {
List<String> fileIds = StrUtil.split(vdpth, ",");
fileIds.forEach(fileId -> attachmentUploadService.deleteFile(fileId));
}
String picpth = failedRow.getData().getPicpth();
if (StringUtils.hasText(picpth)) {
List<String> fileIds = StrUtil.split(vdpth, ",");
fileIds.forEach(fileId -> attachmentUploadService.deleteFile(fileId));
}
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
// ignore parse error // ignore parse error