1.修改创建文件夹和上传文件的bug。
This commit is contained in:
parent
143389f52b
commit
9ed6a64a9e
|
|
@ -38,3 +38,7 @@ data.export.cache.dir=export
|
||||||
#导入数据时文件的缓存文件夹名称
|
#导入数据时文件的缓存文件夹名称
|
||||||
data.import.cache.dir=import
|
data.import.cache.dir=import
|
||||||
file.encode.passwd=adknfhkj87654knd
|
file.encode.passwd=adknfhkj87654knd
|
||||||
|
#数据类型中的文件类型为file
|
||||||
|
data.type.file=file
|
||||||
|
#数据类型中的文件夹类型为folder
|
||||||
|
data.type.folder=folder
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ public interface EDDataService {
|
||||||
* @param edDataInfo
|
* @param edDataInfo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Boolean createDataInfo(EDDataInfo edDataInfo);
|
Boolean createDataInfo(EDDataInfo edDataInfo) throws FileNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件信息列表
|
* 获取文件信息列表
|
||||||
|
|
@ -69,7 +69,7 @@ public interface EDDataService {
|
||||||
* @param parames
|
* @param parames
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Boolean uploadFile(EDDataParams parames);
|
Boolean uploadFile(EDDataParams parames) throws FileNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件下载
|
* 文件下载
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,11 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
private String exportCacheDir;
|
private String exportCacheDir;
|
||||||
@Value("${file.encode.passwd}")
|
@Value("${file.encode.passwd}")
|
||||||
private String encodePasswd;
|
private String encodePasswd;
|
||||||
|
@Value("${data.type.file}")
|
||||||
|
private String dataTypeFile;
|
||||||
|
@Value("${data.type.folder}")
|
||||||
|
private String dataTypeFolder;
|
||||||
|
|
||||||
|
|
||||||
// 文件夹名称分隔符
|
// 文件夹名称分隔符
|
||||||
private static final String FOLDER_NAME_SEPARATOR = "_";
|
private static final String FOLDER_NAME_SEPARATOR = "_";
|
||||||
|
|
@ -140,15 +145,14 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
* @param edDataInfo
|
* @param edDataInfo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Boolean createDataInfo(EDDataInfo edDataInfo)
|
public Boolean createDataInfo(EDDataInfo edDataInfo) throws FileNotFoundException
|
||||||
{
|
{
|
||||||
// 获取上级目录的名称
|
// 获取上级目录的名称
|
||||||
Category categoryParent = new Category();
|
Category categoryParent = new Category();
|
||||||
categoryParent.setCategoryId(edDataInfo.getCategoryId());
|
categoryParent.setCategoryId(edDataInfo.getCategoryId());
|
||||||
List<Category> categoryParentList = categoryRepository.selectCategories(categoryParent);
|
List<Category> categoryParentList = categoryRepository.selectCategories(categoryParent);
|
||||||
if(categoryParentList.size() < 1)
|
if(categoryParentList.size() < 1) {
|
||||||
{
|
throw new FileNotFoundException("上级文件夹不存在");
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -165,8 +169,8 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
List<EDDataInfo> childFileInfoList = edDataRepository.getDataInfoList(folderParames);
|
List<EDDataInfo> childFileInfoList = edDataRepository.getDataInfoList(folderParames);
|
||||||
for(EDDataInfo fileInfo : childFileInfoList)
|
for(EDDataInfo fileInfo : childFileInfoList)
|
||||||
{
|
{
|
||||||
if(fileInfo.getDataName() == edDataInfo.getDataName()){
|
if(fileInfo.getDataName().equals(edDataInfo.getDataName())){
|
||||||
return Boolean.FALSE;
|
throw new FileNotFoundException("文件夹已存在");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,7 +247,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
// 修改文件夹
|
// 修改文件夹
|
||||||
edDataRepository.updateFileInfo(parames);
|
edDataRepository.updateFileInfo(parames);
|
||||||
// 修改文件夹中的文件
|
// 修改文件夹中的文件
|
||||||
if(edDataInfo.getDataType().equals("folder") && parames.getEffectFlag() != null) {
|
if(edDataInfo.getDataType().equals(dataTypeFolder) && parames.getEffectFlag() != null) {
|
||||||
EDDataParams paramesChild = new EDDataParams();
|
EDDataParams paramesChild = new EDDataParams();
|
||||||
paramesChild.setParentId(edDataInfo.getDataId());
|
paramesChild.setParentId(edDataInfo.getDataId());
|
||||||
paramesChild.setEffectFlag(parames.getEffectFlag());
|
paramesChild.setEffectFlag(parames.getEffectFlag());
|
||||||
|
|
@ -265,12 +269,12 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
List<EDDataInfo> edDataInfoList = edDataRepository.getDataInfoList(parames);
|
List<EDDataInfo> edDataInfoList = edDataRepository.getDataInfoList(parames);
|
||||||
parames.setDataId(null);
|
parames.setDataId(null);
|
||||||
for (EDDataInfo edDataInfo : edDataInfoList) {
|
for (EDDataInfo edDataInfo : edDataInfoList) {
|
||||||
if(edDataInfo.getDataType().equals("folder"))
|
if(edDataInfo.getDataType().equals(dataTypeFolder))
|
||||||
{
|
{
|
||||||
parames.setParentId(edDataInfo.getDataId());
|
parames.setParentId(edDataInfo.getDataId());
|
||||||
childFileCount += getChildFileCount(parames);
|
childFileCount += getChildFileCount(parames);
|
||||||
}
|
}
|
||||||
else if(edDataInfo.getDataType().equals("file"))
|
else if(edDataInfo.getDataType().equals(dataTypeFile))
|
||||||
{
|
{
|
||||||
++childFileCount;
|
++childFileCount;
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +288,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
* @param parames
|
* @param parames
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Boolean uploadFile(EDDataParams parames)
|
public Boolean uploadFile(EDDataParams parames) throws FileNotFoundException
|
||||||
{
|
{
|
||||||
|
|
||||||
// 获取目录编码ID
|
// 获取目录编码ID
|
||||||
|
|
@ -295,7 +299,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
|
|
||||||
// 检查文件是否为空
|
// 检查文件是否为空
|
||||||
if (fileInput == null || fileInput.isEmpty()) {
|
if (fileInput == null || fileInput.isEmpty()) {
|
||||||
return Boolean.FALSE;
|
throw new FileNotFoundException("上传的文件为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取文件名
|
// 获取文件名
|
||||||
|
|
@ -309,6 +313,17 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
fileName = fileFullName.substring(fileFullName.lastIndexOf("."));
|
fileName = fileFullName.substring(fileFullName.lastIndexOf("."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断文件名称是否存在
|
||||||
|
EDDataParams folderParames = new EDDataParams();
|
||||||
|
folderParames.setParentId(categoryId);
|
||||||
|
List<EDDataInfo> childFileInfoList = edDataRepository.getDataInfoList(folderParames);
|
||||||
|
for(EDDataInfo fileInfo : childFileInfoList)
|
||||||
|
{
|
||||||
|
if(fileInfo.getDataName().equals(fileFullName)){
|
||||||
|
throw new FileNotFoundException("上传的文件已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String dataStoragePath = getDataStoragePath();
|
String dataStoragePath = getDataStoragePath();
|
||||||
if (!FileUtil.exist(dataStoragePath)){
|
if (!FileUtil.exist(dataStoragePath)){
|
||||||
FileUtil.mkdir(dataStoragePath);
|
FileUtil.mkdir(dataStoragePath);
|
||||||
|
|
@ -319,12 +334,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
|
|
||||||
// 将文件数据信息写到数据库
|
// 将文件数据信息写到数据库
|
||||||
EDDataInfo edDataInfo = new EDDataInfo();
|
EDDataInfo edDataInfo = new EDDataInfo();
|
||||||
{
|
|
||||||
// 临时数据设置
|
|
||||||
if (Boolean.TRUE) {
|
|
||||||
if (parames.getUserId() == null || parames.getUserId().isEmpty()) parames.setUserId(IdWorker.getSnowFlakeIdString());
|
|
||||||
if (parames.getUserName() == null || parames.getUserName().isEmpty()) parames.setUserName("user");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建新文件数据
|
// 创建新文件数据
|
||||||
edDataInfo.setCreator(parames.getUserId());
|
edDataInfo.setCreator(parames.getUserId());
|
||||||
|
|
@ -339,16 +349,16 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
|
|
||||||
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
||||||
edDataInfo.setDataNo(edDataInfo.getDataId());
|
edDataInfo.setDataNo(edDataInfo.getDataId());
|
||||||
edDataInfo.setDataType("file");
|
edDataInfo.setDataType(dataTypeFile);
|
||||||
edDataInfo.setVersion("1.0.0");
|
edDataInfo.setVersion("1.0.0");
|
||||||
edDataInfo.setDataStatus("publish");
|
edDataInfo.setDataStatus("publish");
|
||||||
edDataInfo.setSaveStatus("saving");
|
edDataInfo.setSaveStatus("saving");
|
||||||
|
|
||||||
boolean isSuccess = edDataRepository.createDataInfo(edDataInfo);
|
boolean isSuccess = edDataRepository.createDataInfo(edDataInfo);
|
||||||
}
|
log.info("文件开始保存.");
|
||||||
|
|
||||||
// 保存文件数据 到 文件存储目录
|
// 保存文件数据 到 文件存储目录
|
||||||
{
|
|
||||||
|
|
||||||
// 文件保存目录路径
|
// 文件保存目录路径
|
||||||
String fileSavePath = dataStoragePath + File.separator + filePathOfFolder;
|
String fileSavePath = dataStoragePath + File.separator + filePathOfFolder;
|
||||||
|
|
@ -372,10 +382,11 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
File saveFile = new File(fileCacheFullPath);
|
File saveFile = new File(fileCacheFullPath);
|
||||||
|
|
||||||
// 将文件保存到硬盘
|
// 将文件保存到硬盘
|
||||||
|
EDDataParams fileParames = new EDDataParams();
|
||||||
try {
|
try {
|
||||||
fileInput.transferTo(saveFile);
|
fileInput.transferTo(saveFile);
|
||||||
|
|
||||||
EDDataParams fileParames = new EDDataParams();
|
|
||||||
fileParames.setDataId(edDataInfo.getDataId());
|
fileParames.setDataId(edDataInfo.getDataId());
|
||||||
if(fileInput.getSize() == saveFile.length())
|
if(fileInput.getSize() == saveFile.length())
|
||||||
{
|
{
|
||||||
|
|
@ -390,7 +401,7 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
fileParames.setSaveStatus("failure");
|
fileParames.setSaveStatus("failure");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isSuccess = edDataRepository.updateFileInfo(fileParames);
|
isSuccess = edDataRepository.updateFileInfo(fileParames);
|
||||||
|
|
||||||
FileUtil.del(uploadFileCachePath);//删除临时目录
|
FileUtil.del(uploadFileCachePath);//删除临时目录
|
||||||
|
|
||||||
|
|
@ -399,11 +410,12 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
fileParames.setSaveStatus("failure");
|
||||||
}
|
edDataRepository.updateFileInfo(fileParames);
|
||||||
|
log.info("文件保存失败: " + fileSaveFullPath);
|
||||||
|
throw new FileNotFoundException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -659,11 +671,11 @@ public class EDDataServiceImpl implements EDDataService {
|
||||||
&& !FileUtil.exist(fileStorageFullPath)
|
&& !FileUtil.exist(fileStorageFullPath)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if(fileInfo.getDataType().equals("folder")) {
|
if(fileInfo.getDataType().equals(dataTypeFolder)) {
|
||||||
if (!FileUtil.exist(fileStorageFullPath)) {
|
if (!FileUtil.exist(fileStorageFullPath)) {
|
||||||
FileUtil.mkdir(fileStorageFullPath);
|
FileUtil.mkdir(fileStorageFullPath);
|
||||||
}
|
}
|
||||||
} else if(fileInfo.getDataType().equals("file")) {
|
} else if(fileInfo.getDataType().equals(dataTypeFile)) {
|
||||||
Path source = Paths.get(importFileCacheFullPath);
|
Path source = Paths.get(importFileCacheFullPath);
|
||||||
Path target = Paths.get(fileStorageFullPath);
|
Path target = Paths.get(fileStorageFullPath);
|
||||||
FileUtil.move(source,target,true);
|
FileUtil.move(source,target,true);
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@ import electromagnetic.data.framework.share.model.BaseRequest;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class EDDataRequest extends BaseRequest {
|
public class EDDataRequest extends BaseRequest implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前页
|
* 当前页
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,9 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
@Value("${file.encode.passwd}")
|
@Value("${file.encode.passwd}")
|
||||||
private String encodePasswd;
|
private String encodePasswd;
|
||||||
|
|
||||||
|
@Value("${data.type.folder}")
|
||||||
|
private String dataTypeFolder;
|
||||||
|
|
||||||
private static final String UPLOAD_FILE_CHUNK_SUFFIX = ".part";
|
private static final String UPLOAD_FILE_CHUNK_SUFFIX = ".part";
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,12 +73,6 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
public ElectromagneticResult<Boolean> createFolder(EDDataRequest request) {
|
public ElectromagneticResult<Boolean> createFolder(EDDataRequest request) {
|
||||||
EDDataInfo edDataInfo = EDDataMappers.INSTANCE.getEDDataInfo(request);
|
EDDataInfo edDataInfo = EDDataMappers.INSTANCE.getEDDataInfo(request);
|
||||||
|
|
||||||
// 临时数据设置
|
|
||||||
if(Boolean.TRUE) {
|
|
||||||
if (request.getUserId() == null || request.getUserId().isEmpty()) request.setUserId(IdWorker.getSnowFlakeIdString());
|
|
||||||
if (request.getUserName() == null || request.getUserName().isEmpty()) request.setUserName("user");
|
|
||||||
}
|
|
||||||
|
|
||||||
edDataInfo.setCreator(request.getUserId());
|
edDataInfo.setCreator(request.getUserId());
|
||||||
edDataInfo.setCreatorName(request.getUserName());
|
edDataInfo.setCreatorName(request.getUserName());
|
||||||
edDataInfo.setModifier(request.getUserId());
|
edDataInfo.setModifier(request.getUserId());
|
||||||
|
|
@ -87,13 +84,17 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
|
|
||||||
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
||||||
edDataInfo.setDataNo(edDataInfo.getDataId());
|
edDataInfo.setDataNo(edDataInfo.getDataId());
|
||||||
edDataInfo.setDataType("folder");
|
edDataInfo.setDataType(dataTypeFolder);
|
||||||
edDataInfo.setVersion("1.0.0");
|
edDataInfo.setVersion("1.0.0");
|
||||||
edDataInfo.setDataStatus("publish");
|
edDataInfo.setDataStatus("publish");
|
||||||
edDataInfo.setSaveStatus("success");
|
edDataInfo.setSaveStatus("success");
|
||||||
|
|
||||||
Boolean isSuccess = edDataService.createDataInfo(edDataInfo);
|
try {
|
||||||
return ElectromagneticResultUtil.success(isSuccess);
|
return ElectromagneticResultUtil.success(edDataService.createDataInfo(edDataInfo));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
log.error("创建文件夹失败。。。", e);
|
||||||
|
return ElectromagneticResultUtil.fail("500", e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -125,8 +126,8 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
*/
|
*/
|
||||||
public ElectromagneticResult<Boolean> updateFileInfo(EDDataRequest request)
|
public ElectromagneticResult<Boolean> updateFileInfo(EDDataRequest request)
|
||||||
{
|
{
|
||||||
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
|
||||||
try {
|
try {
|
||||||
|
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
||||||
return ElectromagneticResultUtil.success(edDataService.updateFileInfo(parames));
|
return ElectromagneticResultUtil.success(edDataService.updateFileInfo(parames));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
log.error("文件信息更新失败。。。", e);
|
log.error("文件信息更新失败。。。", e);
|
||||||
|
|
@ -159,9 +160,13 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
||||||
*/
|
*/
|
||||||
public ElectromagneticResult<Boolean> uploadFile(EDDataRequest request)
|
public ElectromagneticResult<Boolean> uploadFile(EDDataRequest request)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
||||||
Boolean isSuccess = edDataService.uploadFile(parames);
|
return ElectromagneticResultUtil.success(edDataService.uploadFile(parames));
|
||||||
return ElectromagneticResultUtil.success(isSuccess);
|
} catch (FileNotFoundException e) {
|
||||||
|
log.error("上传文件失败。。。", e);
|
||||||
|
return ElectromagneticResultUtil.fail("500", e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue