调通了导出的相关功能。
This commit is contained in:
parent
d9525bc13b
commit
50040f2216
|
|
@ -1,15 +1,14 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.models;
|
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.util.Date;
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("ed_file_relation")
|
@TableName("ed_file_relation")
|
||||||
public class EdFileRelation {
|
public class EdFileRelation extends BaseModel {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
|
@ -30,21 +29,21 @@ public class EdFileRelation {
|
||||||
*/
|
*/
|
||||||
private String relationship;
|
private String relationship;
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 创建者 用户id
|
// * 创建者 用户id
|
||||||
*/
|
// */
|
||||||
@TableField(value = "created_by")
|
// @TableField(value = "created_by")
|
||||||
private String createdBy;
|
// private String createdBy;
|
||||||
|
//
|
||||||
@TableField(value = "created_at", fill = FieldFill.INSERT)
|
// @TableField(value = "created_at", fill = FieldFill.INSERT)
|
||||||
private Date createdAt;
|
// private Date createdAt;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 更新者 用户id
|
// * 更新者 用户id
|
||||||
*/
|
// */
|
||||||
@TableField(value = "updated_by")
|
// @TableField(value = "updated_by")
|
||||||
private String updatedBy;
|
// private String updatedBy;
|
||||||
|
//
|
||||||
@TableField(value = "updated_at", fill = FieldFill.UPDATE)
|
// @TableField(value = "updated_at", fill = FieldFill.UPDATE)
|
||||||
private Date updatedAt;
|
// private Date updatedAt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,31 @@ public class CommonService {
|
||||||
return count == 0;
|
return count == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetFileInfoName(EdFileInfo fileInfo) {
|
||||||
|
String fileName = fileInfo.getFileName();
|
||||||
|
String parentId = fileInfo.getParentId();
|
||||||
|
for (int i = 0; i < 1000; ++i) {
|
||||||
|
long count = edFileInfoMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getFileName, fileName)
|
||||||
|
.eq(EdFileInfo::getFileType, fileInfo.getFileType())
|
||||||
|
.eq(EdFileInfo::getParentId, parentId)
|
||||||
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||||
|
if (count > 0) {
|
||||||
|
fileName = fileName + APPEND_NEW_FILE_NAME;
|
||||||
|
} else {
|
||||||
|
fileInfo.setFileName(fileName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFolder(String id) {
|
||||||
|
EdFileInfo fileInfo = edFileInfoMapper.selectById(id);
|
||||||
|
Assert.notNull(fileInfo, StrFormatter.format("文件不存在,ID为{}", id));
|
||||||
|
return fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code);
|
||||||
|
}
|
||||||
|
|
||||||
public String getFileSysPath(String id) {
|
public String getFileSysPath(String id) {
|
||||||
EdFileInfo fileInfo = edFileInfoMapper.selectById(id);
|
EdFileInfo fileInfo = edFileInfoMapper.selectById(id);
|
||||||
int dataOwnCode = fileInfo.getDataOwn();
|
int dataOwnCode = fileInfo.getDataOwn();
|
||||||
|
|
|
||||||
|
|
@ -829,8 +829,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||||
maps.putAll(edFileInfos);
|
maps.putAll(edFileInfos);
|
||||||
}
|
}
|
||||||
List<EdFileInfo> resFiles = new ArrayList<>(maps.values());
|
Set<EdFileInfo> resFiles = new HashSet<>(maps.values());
|
||||||
String prjId = resFiles.get(0).getFilePath().split(MYSQL_FILE_PATH_SPLIT)[0];
|
String prjId = resFiles.stream().findFirst().get().getFilePath().split(MYSQL_FILE_PATH_SPLIT)[0];
|
||||||
List<EdFileInfo> prjFolders = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
List<EdFileInfo> prjFolders = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
|
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
|
||||||
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code)
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code)
|
||||||
|
|
@ -846,10 +846,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
List<EdFileInfo> files = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
|
List<EdFileInfo> files = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
|
||||||
for (EdFileInfo edFileInfo : files) {
|
for (EdFileInfo edFileInfo : files) {
|
||||||
String filePath = commonService.getFileSysPath(edFileInfo.getId()); // file
|
String filePath = commonService.getFileSysPath(edFileInfo.getId()); // file
|
||||||
String destPath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + commonService.getDbPath(edFileInfo.getFilePath());
|
String destPath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + EXPORT_PRJ_NAME + File.separator + edFileInfo.getId();
|
||||||
fileSystemService.copyFile(filePath, destPath);
|
fileSystemService.copyFile(filePath, destPath);
|
||||||
}
|
}
|
||||||
String json = JSONUtil.toJsonStr(files);
|
String json = JSONUtil.toJsonStr(resFiles);
|
||||||
String mysqlFilePath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + PRJ_INFO + ".json";
|
String mysqlFilePath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + PRJ_INFO + ".json";
|
||||||
fileSystemService.writeStringToFile(mysqlFilePath, json);
|
fileSystemService.writeStringToFile(mysqlFilePath, json);
|
||||||
return files.stream().map(EdFileInfo::getId).toList();
|
return files.stream().map(EdFileInfo::getId).toList();
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,6 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
@Resource
|
@Resource
|
||||||
EdFileInfoMapper edFileInfoMapper;
|
EdFileInfoMapper edFileInfoMapper;
|
||||||
@Resource
|
@Resource
|
||||||
EdFileInfoServiceImpl edFileInfoService;
|
|
||||||
@Resource
|
|
||||||
private CommonService commonService;
|
private CommonService commonService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -57,7 +55,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
String queryId1 = edFileRelation.getId1();
|
String queryId1 = edFileRelation.getId1();
|
||||||
String queryId2 = edFileRelation.getId2();
|
String queryId2 = edFileRelation.getId2();
|
||||||
|
|
||||||
if (edFileInfoService.isFolder(queryId1) || edFileInfoService.isFolder(queryId2)) {
|
if (commonService.isFolder(queryId1) || commonService.isFolder(queryId2)) {
|
||||||
throw new BizException("文件夹无法建立关系");
|
throw new BizException("文件夹无法建立关系");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,7 +163,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
newEdFileInfo.newInit();
|
newEdFileInfo.newInit();
|
||||||
// 首先检查是否是同名文件
|
// 首先检查是否是同名文件
|
||||||
Assert.isTrue(EleCommonUtil.isFileNameValid(mainName + "." + suffix), NAME_VALID_MSG);
|
Assert.isTrue(EleCommonUtil.isFileNameValid(mainName + "." + suffix), NAME_VALID_MSG);
|
||||||
long count = edFileInfoService.count(Wrappers.lambdaQuery(EdFileInfo.class)
|
long count = edFileInfoMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.eq(EdFileInfo::getParentId, parentId)
|
.eq(EdFileInfo::getParentId, parentId)
|
||||||
.eq(EdFileInfo::getFileName, mainName)
|
.eq(EdFileInfo::getFileName, mainName)
|
||||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
|
@ -209,7 +207,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
String suffix = FileUtil.getSuffix(fileName);
|
String suffix = FileUtil.getSuffix(fileName);
|
||||||
Assert.isTrue(StrUtil.isNotEmpty(suffix), "文件类型不能为空");
|
Assert.isTrue(StrUtil.isNotEmpty(suffix), "文件类型不能为空");
|
||||||
// 查找下一层,看是否存在顶级定义相关文件,如果存在,则该层属于管理员层级定义的,不允许上传文件
|
// 查找下一层,看是否存在顶级定义相关文件,如果存在,则该层属于管理员层级定义的,不允许上传文件
|
||||||
long dirCount = edFileInfoService.count(Wrappers.lambdaQuery(EdFileInfo.class)
|
long dirCount = edFileInfoMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.eq(EdFileInfo::getParentId, parentId)
|
.eq(EdFileInfo::getParentId, parentId)
|
||||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
.eq(EdFileInfo::getDataOwn, dataOwnCode)
|
.eq(EdFileInfo::getDataOwn, dataOwnCode)
|
||||||
|
|
@ -221,7 +219,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
newEdFileInfo.newInit();
|
newEdFileInfo.newInit();
|
||||||
try {
|
try {
|
||||||
Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), NAME_VALID_MSG);
|
Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), NAME_VALID_MSG);
|
||||||
Long count = edFileInfoService.count(Wrappers.lambdaQuery(EdFileInfo.class)
|
Long count = edFileInfoMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.eq(EdFileInfo::getParentId, parentId)
|
.eq(EdFileInfo::getParentId, parentId)
|
||||||
.eq(EdFileInfo::getFileName, mainName)
|
.eq(EdFileInfo::getFileName, mainName)
|
||||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
|
@ -250,10 +248,9 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
|
|
||||||
// 文件名加”_1“,存为新文件
|
// 文件名加”_1“,存为新文件
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
edFileInfoService.resetFileInfoName(newEdFileInfo);
|
commonService.resetFileInfoName(newEdFileInfo);
|
||||||
}
|
}
|
||||||
|
edFileInfoMapper.insertOrUpdate(newEdFileInfo);
|
||||||
edFileInfoService.saveOrUpdate(newEdFileInfo);
|
|
||||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
|
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
|
||||||
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
||||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||||
|
|
@ -275,7 +272,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
.setSaveStatus(EleDataSaveStatusEnum.FAIL.code)
|
.setSaveStatus(EleDataSaveStatusEnum.FAIL.code)
|
||||||
.setDataOwn(dataOwnCode)
|
.setDataOwn(dataOwnCode)
|
||||||
.setEffectFlag(EffectFlagEnum.NOT_EFFECTIVE.code);
|
.setEffectFlag(EffectFlagEnum.NOT_EFFECTIVE.code);
|
||||||
edFileInfoService.saveOrUpdate(newEdFileInfo);
|
edFileInfoMapper.insertOrUpdate(newEdFileInfo);
|
||||||
String info = "上传文件失败";
|
String info = "上传文件失败";
|
||||||
log.error(info, e);
|
log.error(info, e);
|
||||||
throw new BizException(info);
|
throw new BizException(info);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue