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