fix: 优化导入逻辑
This commit is contained in:
parent
eadea5945c
commit
c068d0fa02
@ -7,6 +7,7 @@ import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.data.domain.FishDraftData;
|
||||
import com.yfd.platform.data.domain.FishImportRequest;
|
||||
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.BatchApproveRequest;
|
||||
import com.yfd.platform.data.domain.BatchRejectRequest;
|
||||
@ -404,18 +405,11 @@ public class FishDraftDataController {
|
||||
}
|
||||
|
||||
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("excelFileName", importResult.getExcelFileName() != null ?
|
||||
importResult.getExcelFileName() : "");
|
||||
map.put("failedRowDetails", importResult.getFailedRows() != null ?
|
||||
importResult.getFailedRows() : new ArrayList<>());
|
||||
|
||||
map.put("successRowDetails", importResult.getSuccessRows() != null ?
|
||||
importResult.getSuccessRows() : new ArrayList<>());
|
||||
map.put("rows", importResult.getRows() != null ?
|
||||
importResult.getRows() : new ArrayList<>());
|
||||
return map;
|
||||
}
|
||||
|
||||
@ -443,4 +437,5 @@ public class FishDraftDataController {
|
||||
return ResponseResult.error("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -12,8 +12,10 @@ import java.util.Map;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class FishImportResult {
|
||||
|
||||
private List<FishImportRow> successRows;
|
||||
private List<FishImportRow> failedRows;
|
||||
public static final String STATUS_SUCCESS = "SUCCESS";
|
||||
public static final String STATUS_FAILED = "FAILED";
|
||||
|
||||
private List<FishImportRow> rows;
|
||||
private List<String> unrecognizedFields;
|
||||
private Map<String, String> imageFiles;
|
||||
private Map<String, String> videoFiles;
|
||||
@ -29,13 +31,24 @@ public class FishImportResult {
|
||||
private String taskId;
|
||||
|
||||
public FishImportResult() {
|
||||
this.successRows = new ArrayList<>();
|
||||
this.failedRows = new ArrayList<>();
|
||||
this.rows = new ArrayList<>();
|
||||
this.unrecognizedFields = new ArrayList<>();
|
||||
this.imageFiles = 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
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class FishImportRow {
|
||||
@ -47,6 +60,8 @@ public class FishImportResult {
|
||||
private List<Map<String, String>> picpthList;
|
||||
private List<String> vdpthsWarnings;
|
||||
private List<String> picpthsWarnings;
|
||||
private String status;
|
||||
|
||||
public FishImportRow() {
|
||||
this.unrecognizedFields = new ArrayList<>();
|
||||
this.warnings = new ArrayList<>();
|
||||
@ -57,13 +72,16 @@ public class FishImportResult {
|
||||
}
|
||||
|
||||
public FishImportRow(int rowIndex) {
|
||||
this();
|
||||
this.rowIndex = rowIndex;
|
||||
this.unrecognizedFields = new ArrayList<>();
|
||||
this.warnings = new ArrayList<>();
|
||||
this.vdpthsWarnings = new ArrayList<>();
|
||||
this.picpthsWarnings = new ArrayList<>();
|
||||
this.vdpthList = new ArrayList<>();
|
||||
this.picpthList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return STATUS_SUCCESS.equals(status);
|
||||
}
|
||||
|
||||
public boolean isFailed() {
|
||||
return STATUS_FAILED.equals(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -161,10 +161,10 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
FishImportResult.FishImportRow importRow = parseRow(row, columnIndexMap, i);
|
||||
result.setTotalCount(result.getTotalCount() + 1);
|
||||
if (importRow.getData() != null && importRow.getWarnings().isEmpty()) {
|
||||
result.getSuccessRows().add(importRow);
|
||||
result.addSuccessRow(importRow);
|
||||
result.setSuccessCount(result.getSuccessCount() + 1);
|
||||
} else {
|
||||
result.getFailedRows().add(importRow);
|
||||
result.addFailedRow(importRow);
|
||||
result.setFailedCount(result.getFailedCount() + 1);
|
||||
}
|
||||
}
|
||||
@ -763,8 +763,8 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
processAttachments(result, zipContent);
|
||||
|
||||
log.info("ZIP文件处理完成");
|
||||
result.setSummary(result.getSummary() + String.format("\nZIP内容: 发现%d张图片, %d个视频, 临时目录: %s",
|
||||
zipContent.images.size(), zipContent.videos.size(), zipContent.tempDir));
|
||||
result.setSummary(result.getSummary() + String.format("\nZIP内容: 发现%d张图片, %d个视频",
|
||||
zipContent.images.size(), zipContent.videos.size()));
|
||||
|
||||
return result;
|
||||
|
||||
@ -777,27 +777,7 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
}
|
||||
|
||||
private void processAttachments(FishImportResult result, ZipFileUtil.ZipContent zipContent) {
|
||||
for (FishImportResult.FishImportRow importRow : result.getFailedRows()) {
|
||||
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()) {
|
||||
for (FishImportResult.FishImportRow importRow : result.getRows()) {
|
||||
FishDraftData data = importRow.getData();
|
||||
if (data == null) {
|
||||
continue;
|
||||
|
||||
@ -185,7 +185,7 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
|
||||
if (importTask.getResultJson() != null && !importTask.getResultJson().isEmpty()) {
|
||||
try {
|
||||
FishImportResult importResult = objectMapper.readValue(importTask.getResultJson(), FishImportResult.class);
|
||||
for (FishImportResult.FishImportRow successRow : importResult.getSuccessRows()) {
|
||||
for (FishImportResult.FishImportRow successRow : importResult.getRows()) {
|
||||
if (successRow.getData()==null) {
|
||||
continue;
|
||||
}
|
||||
@ -200,22 +200,6 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
// ignore parse error
|
||||
|
||||
Loading…
Reference in New Issue
Block a user