fix: 优化json存储数据改成数据库表存储
This commit is contained in:
parent
33cea1fd1e
commit
aa7f4ac0a0
@ -146,12 +146,6 @@ public class FishDraftDataController {
|
||||
String taskId = request.getTaskId();
|
||||
ImportTask importTask = importTaskService.getById(taskId);
|
||||
FishImportResult importResult = importTaskService.buildImportResult(taskId);
|
||||
Map<String, String> imageFiles = null;
|
||||
Map<String, String> videoFiles = null;
|
||||
if (importResult != null) {
|
||||
imageFiles = importResult.getImageFiles();
|
||||
videoFiles = importResult.getVideoFiles();
|
||||
}
|
||||
|
||||
if (importResult == null || importResult.getRows() == null) {
|
||||
return ResponseResult.error("导入数据不存在");
|
||||
@ -166,10 +160,12 @@ public class FishDraftDataController {
|
||||
data.setDeletedFlag(0);
|
||||
data.setLockFlag(0);
|
||||
data.setTm(date);
|
||||
data.setVdpthList(row.getVdpthList());
|
||||
data.setPicpthList(row.getPicpthList());
|
||||
fishDraftDataList.add(data);
|
||||
}
|
||||
boolean result = fishDraftDataService.saveBatch(fishDraftDataList);
|
||||
fishImportService.processAttachmentsAsync(fishDraftDataList, imageFiles, videoFiles,importTask.getTempDir());
|
||||
fishImportService.processAttachmentsAsync(fishDraftDataList,importTask.getTempDir());
|
||||
importTaskService.markSuccess(taskId);
|
||||
return result ? ResponseResult.success("保存成功") : ResponseResult.error("保存失败");
|
||||
}
|
||||
|
||||
@ -8,6 +8,8 @@ import lombok.EqualsAndHashCode;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -266,4 +268,10 @@ public class FishDraftData implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private String ftpName;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Map<String, String>> vdpthList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Map<String, String>> picpthList;
|
||||
|
||||
}
|
||||
@ -21,8 +21,6 @@ public class FishImportResult {
|
||||
private List<String> unrecognizedFields;
|
||||
private Map<String, String> imageFiles;
|
||||
private Map<String, String> videoFiles;
|
||||
// public Map<String, String> images;
|
||||
// public Map<String, String> videos;
|
||||
private String tempDir;
|
||||
private String excelFileName;
|
||||
private String excelFilePath;
|
||||
|
||||
@ -115,15 +115,15 @@ public class ImportTask implements Serializable {
|
||||
*/
|
||||
private String unrecognizedFields;
|
||||
|
||||
/**
|
||||
* 图片文件映射JSON
|
||||
*/
|
||||
private String imageFilesJson;
|
||||
|
||||
/**
|
||||
* 视频文件映射JSON
|
||||
*/
|
||||
private String videoFilesJson;
|
||||
// /**
|
||||
// * 图片文件映射JSON
|
||||
// */
|
||||
// private String imageFilesJson;
|
||||
//
|
||||
// /**
|
||||
// * 视频文件映射JSON
|
||||
// */
|
||||
// private String videoFilesJson;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.yfd.platform.data.service;
|
||||
|
||||
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.utils.ZipFileUtil;
|
||||
@ -7,6 +8,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -52,8 +55,6 @@ public interface IFishImportService {
|
||||
|
||||
void processAttachments(FishImportResult result, ZipFileUtil.ZipContent zipContent);
|
||||
|
||||
void processAttachmentsAsync(java.util.List<com.yfd.platform.data.domain.FishDraftData> dataList,
|
||||
java.util.Map<String, String> imageFiles,
|
||||
java.util.Map<String, String> videoFiles,
|
||||
void processAttachmentsAsync(List<FishDraftData> dataList,
|
||||
String tempDir);
|
||||
}
|
||||
@ -1494,8 +1494,6 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
|
||||
@Override
|
||||
public void processAttachmentsAsync(List<FishDraftData> dataList,
|
||||
Map<String, String> imageFiles,
|
||||
Map<String, String> videoFiles,
|
||||
String tempDir) {
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
return;
|
||||
@ -1513,6 +1511,12 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
log.error("数据不完整, 忽略处理");
|
||||
return;
|
||||
}
|
||||
List<Map<String, String>> vdpthList = data.getVdpthList();
|
||||
List<Map<String, String>> picpthList = data.getPicpthList();
|
||||
|
||||
Map<String, String> videoFiles = buildFileMap(vdpthList, tempDir, "videos");
|
||||
Map<String, String> imageFiles = buildFileMap(picpthList, tempDir, "images");
|
||||
|
||||
if (StringUtils.hasText(vdpth) && videoFiles != null && !videoFiles.isEmpty()) {
|
||||
String uploadedVdpth = uploadVideoFilesAsync(vdpth, videoFiles);
|
||||
if (uploadedVdpth != null) {
|
||||
@ -1554,6 +1558,27 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> buildFileMap(List<Map<String, String>> fileList, String tempDir, String subDir) {
|
||||
if (fileList == null || fileList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, String> fileMap = new HashMap<>();
|
||||
String baseDir = tempDir + File.separator + subDir + File.separator;
|
||||
|
||||
for (Map<String, String> item : fileList) {
|
||||
String name = item.get("name");
|
||||
String value = item.get("value");
|
||||
if (name != null && value != null) {
|
||||
fileMap.put(name, baseDir + value);
|
||||
}
|
||||
}
|
||||
|
||||
return fileMap.isEmpty() ? null : fileMap;
|
||||
}
|
||||
|
||||
|
||||
private String uploadVideoFilesAsync(String videoNames, Map<String, String> videoMap) {
|
||||
String[] fileNames = videoNames.split(";");
|
||||
List<String> attachmentIds = new ArrayList<>();
|
||||
|
||||
@ -186,19 +186,25 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
|
||||
return false;
|
||||
}
|
||||
String temp = importTask.getTempDir();
|
||||
if (StrUtil.isNotBlank( temp)) {
|
||||
FileUtil.del(temp);
|
||||
}else{
|
||||
FishImportResult importResult = buildImportResult(taskId);
|
||||
if (importResult != null && importResult.getTempDir() != null) {
|
||||
FileUtil.del(importResult.getTempDir());
|
||||
}
|
||||
}
|
||||
|
||||
importTask.setStatus("CANCELLED");
|
||||
importTask.setErrorMsg("用户取消: " + operatorId);
|
||||
importTask.setUpdatedAt(new Date());
|
||||
importTaskRowMapper.deleteByTaskId(taskId);
|
||||
return this.updateById(importTask);
|
||||
boolean result = this.updateById(importTask);
|
||||
|
||||
if (result && StrUtil.isNotBlank(temp)) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
FileUtil.del(temp);
|
||||
log.info("异步删除临时目录成功: {}", temp);
|
||||
} catch (Exception e) {
|
||||
log.error("异步删除临时目录失败: {}", temp, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -230,12 +236,12 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
|
||||
if (importResult.getUnrecognizedFields() != null && !importResult.getUnrecognizedFields().isEmpty()) {
|
||||
importTask.setUnrecognizedFields(String.join(",", importResult.getUnrecognizedFields()));
|
||||
}
|
||||
if (importResult.getImageFiles() != null && !importResult.getImageFiles().isEmpty()) {
|
||||
importTask.setImageFilesJson(objectMapper.writeValueAsString(importResult.getImageFiles()));
|
||||
}
|
||||
if (importResult.getVideoFiles() != null && !importResult.getVideoFiles().isEmpty()) {
|
||||
importTask.setVideoFilesJson(objectMapper.writeValueAsString(importResult.getVideoFiles()));
|
||||
}
|
||||
// if (importResult.getImageFiles() != null && !importResult.getImageFiles().isEmpty()) {
|
||||
// importTask.setImageFilesJson(objectMapper.writeValueAsString(importResult.getImageFiles()));
|
||||
// }
|
||||
// if (importResult.getVideoFiles() != null && !importResult.getVideoFiles().isEmpty()) {
|
||||
// importTask.setVideoFilesJson(objectMapper.writeValueAsString(importResult.getVideoFiles()));
|
||||
// }
|
||||
|
||||
this.updateById(importTask);
|
||||
|
||||
@ -349,20 +355,6 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
|
||||
result.setUnrecognizedFields(Arrays.asList(importTask.getUnrecognizedFields().split(",")));
|
||||
}
|
||||
|
||||
try {
|
||||
if (importTask.getImageFilesJson() != null && !importTask.getImageFilesJson().isEmpty()) {
|
||||
Map<String, String> imageFiles = objectMapper.readValue(
|
||||
importTask.getImageFilesJson(), new TypeReference<Map<String, String>>() {});
|
||||
result.setImageFiles(imageFiles);
|
||||
}
|
||||
if (importTask.getVideoFilesJson() != null && !importTask.getVideoFilesJson().isEmpty()) {
|
||||
Map<String, String> videoFiles = objectMapper.readValue(
|
||||
importTask.getVideoFilesJson(), new TypeReference<Map<String, String>>() {});
|
||||
result.setVideoFiles(videoFiles);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("解析文件映射JSON失败, taskId: {}", taskId, e);
|
||||
}
|
||||
|
||||
List<ImportTaskRow> rows = importTaskRowMapper.selectByTaskId(taskId);
|
||||
if (rows != null && !rows.isEmpty()) {
|
||||
@ -409,7 +401,8 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
|
||||
if (row.getVdpthListJson() != null && !row.getVdpthListJson().isEmpty()) {
|
||||
try {
|
||||
List<Map<String, String>> vdpthList = objectMapper.readValue(
|
||||
row.getVdpthListJson(), new TypeReference<List<Map<String, String>>>() {});
|
||||
row.getVdpthListJson(), new TypeReference<>() {
|
||||
});
|
||||
importRow.setVdpthList(vdpthList);
|
||||
} catch (Exception e) {
|
||||
log.error("解析视频列表JSON失败, rowId: {}", row.getId(), e);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user