临时上传
This commit is contained in:
parent
4f0e7c883d
commit
adb64e25c1
|
|
@ -176,4 +176,17 @@ public class UserEdFileInfoController {
|
||||||
return ElectromagneticResultUtil.success(edFileInfoService.removeFavorite(userId, id));
|
return ElectromagneticResultUtil.success(edFileInfoService.removeFavorite(userId, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从收藏夹移除
|
||||||
|
*
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/importPrj")
|
||||||
|
@UserOperation(value = "导入工程", modelName = UserOperationModuleEnum.USER_PRJ)
|
||||||
|
public ElectromagneticResult<?> importPrj(@RequestParam("file") MultipartFile file) {
|
||||||
|
return ElectromagneticResultUtil.success(edFileInfoService.importPrj(file));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -243,4 +243,9 @@ public interface EdFileInfoService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode);
|
ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入工程
|
||||||
|
*/
|
||||||
|
ElectromagneticResult<?> importPrj(MultipartFile file);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.lang.tree.Tree;
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
|
|
@ -11,6 +12,7 @@ import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.electromagnetic.industry.software.common.enums.*;
|
import com.electromagnetic.industry.software.common.enums.*;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
|
|
@ -751,4 +753,137 @@ public class CommonService {
|
||||||
return newEdFileInfo;
|
return newEdFileInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ElectromagneticResult<?> follow(String sourceId, String targetId, int dataOwnCode) {
|
||||||
|
try {
|
||||||
|
// 把source工程的层级结构copy到目标工程
|
||||||
|
// 查找source的全部目录
|
||||||
|
List<EdFileInfo> sourceEdFileInfos = selectAllPrjFolder(sourceId, dataOwnCode);
|
||||||
|
List<EdFileInfo> targetEdFileInfos = selectAllPrjFolder(targetId, dataOwnCode);
|
||||||
|
Set<String> sourceNames = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).map(EdFileInfo::getFileName).collect(Collectors.toSet());
|
||||||
|
Set<String> targetNames = targetEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).map(EdFileInfo::getFileName).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
Collection<String> intersection = CollectionUtil.intersection(sourceNames, targetNames);
|
||||||
|
if (CollUtil.isNotEmpty(intersection)) {
|
||||||
|
String info = StrFormatter.format("层级沿用失败,源工程 {},目标工程 {},原因 存在相同子集", sourceId, targetId);
|
||||||
|
log.error(info);
|
||||||
|
return ElectromagneticResultUtil.fail("-1", info);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> idMaps = new HashMap<>();
|
||||||
|
idMaps.put(sourceId, targetId);
|
||||||
|
for (int i = 1; i <= elePropertyConfig.getPrjFolderMaxLength(); ++i) {
|
||||||
|
int layerIndex = i;
|
||||||
|
List<EdFileInfo> currentSourceLayerDirs = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == layerIndex).toList();
|
||||||
|
if (layerIndex == 1) {
|
||||||
|
targetEdFileInfos = selectAllPrjFolder(targetId, dataOwnCode);
|
||||||
|
EdFileInfo prjFileInfo = targetEdFileInfos.stream().filter(e -> e.getParentId().equals(PRJ_PARENT_ID)).findFirst().get();
|
||||||
|
List<EdFileInfo> targetChildLayerDirs = targetEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).toList();
|
||||||
|
int size = targetChildLayerDirs.size();
|
||||||
|
for (EdFileInfo edFileInfo : currentSourceLayerDirs) {
|
||||||
|
int maxFolderId = Integer.parseInt(edFileInfoMapper.maxPrjId());
|
||||||
|
String newFolderId = String.valueOf(maxFolderId + 1);
|
||||||
|
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||||
|
String fileCode = createFileCode(targetId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr);
|
||||||
|
EdFileInfo targetFile = new EdFileInfo();
|
||||||
|
targetFile.newInit();
|
||||||
|
targetFile.setId(newFolderId)
|
||||||
|
.setFileId(newFolderId)
|
||||||
|
.setFileName(edFileInfo.getFileName())
|
||||||
|
.setFileVersion(FILE_START_VERSION)
|
||||||
|
.setDataOwn(dataOwnCode)
|
||||||
|
.setParentId(idMaps.get(edFileInfo.getParentId()))
|
||||||
|
.setFileTime(nowTimeStr)
|
||||||
|
.setDataType(EleDataTypeEnum.FOLDER.code)
|
||||||
|
.setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
||||||
|
.setFileCode(fileCode)
|
||||||
|
.setFileType("文件夹")
|
||||||
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||||
|
.setFilePath(prjFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFolderId)
|
||||||
|
.setSort(++size)
|
||||||
|
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||||
|
edFileInfoMapper.insert(targetFile);
|
||||||
|
targetEdFileInfos.add(targetFile);
|
||||||
|
idMaps.put(edFileInfo.getFileId(), newFolderId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
List<EdFileInfo> edFileInfos = edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
|
||||||
|
.in(EdFileInfo::getId, idMaps.values()));
|
||||||
|
Map<String, EdFileInfo> map = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||||
|
for (EdFileInfo edFileInfo : currentSourceLayerDirs) {
|
||||||
|
String targetDirParentId = idMaps.get(edFileInfo.getParentId());
|
||||||
|
EdFileInfo parentFileInfo = map.get(targetDirParentId);
|
||||||
|
|
||||||
|
int maxFolderId = Integer.parseInt(edFileInfoMapper.maxPrjId());
|
||||||
|
String newFolderId = String.valueOf(maxFolderId + 1);
|
||||||
|
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||||
|
|
||||||
|
String fileCode = createFileCode(targetId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr);
|
||||||
|
EdFileInfo targetFile = new EdFileInfo();
|
||||||
|
targetFile.newInit();
|
||||||
|
targetFile.setId(newFolderId)
|
||||||
|
.setFileId(newFolderId)
|
||||||
|
.setFileName(edFileInfo.getFileName())
|
||||||
|
.setFileVersion(FILE_START_VERSION)
|
||||||
|
.setDataOwn(dataOwnCode)
|
||||||
|
.setParentId(targetDirParentId)
|
||||||
|
.setFileTime(nowTimeStr)
|
||||||
|
.setDataType(EleDataTypeEnum.FOLDER.code)
|
||||||
|
.setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
||||||
|
.setFileCode(fileCode)
|
||||||
|
.setFileType("文件夹")
|
||||||
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||||
|
.setFilePath(parentFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFolderId)
|
||||||
|
.setSort(edFileInfo.getSort())
|
||||||
|
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||||
|
edFileInfoMapper.insert(targetFile);
|
||||||
|
targetEdFileInfos.add(targetFile);
|
||||||
|
idMaps.put(edFileInfo.getFileId(), newFolderId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UserThreadLocal.setSuccessInfo("", targetId, "层级沿用成功");
|
||||||
|
return ElectromagneticResultUtil.success(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String info = StrFormatter.format("层级沿用失败,源工程 {},目标工程 {},原因 {}", sourceId, targetId, e.getMessage());
|
||||||
|
log.error(info, e);
|
||||||
|
throw new BizException(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ElectromagneticResult<?> publish(String prjId, int dataOwnCode) {
|
||||||
|
EdFileInfo fileInfo = edFileInfoMapper.selectById(prjId);
|
||||||
|
try {
|
||||||
|
// 将已经处于删除状态设置成逻辑删除
|
||||||
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo::getId, EdFileInfo::getFilePath, EdFileInfo::getFileName)
|
||||||
|
.eq(EdFileInfo::getDataOwn, dataOwnCode)
|
||||||
|
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.WAIT_DELETED.code)
|
||||||
|
.likeRight(EdFileInfo::getFilePath, prjId);
|
||||||
|
List<EdFileInfo> edFileInfos = edFileInfoMapper.selectList(queryWrapper);
|
||||||
|
for (EdFileInfo edFileInfo : edFileInfos) {
|
||||||
|
edFileInfoMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getId, edFileInfo.getId())
|
||||||
|
.set(EdFileInfo::getAllDeleted, true)
|
||||||
|
.set(EdFileInfo::getPermanentDeleted, true)
|
||||||
|
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
|
||||||
|
}
|
||||||
|
// 其余置为发布状态
|
||||||
|
LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||||
|
.set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code)
|
||||||
|
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.NOT_PUBLISHED.code)
|
||||||
|
.likeRight(EdFileInfo::getFilePath, prjId);
|
||||||
|
edFileInfoMapper.update(new EdFileInfo(), updateWrapper);
|
||||||
|
UserThreadLocal.setSuccessInfo("", prjId, "项目 {} 发布成功", fileInfo.getFileName());
|
||||||
|
return ElectromagneticResultUtil.success(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String info = StrFormatter.format("项目 {} 发布异常", fileInfo.getFileName());
|
||||||
|
log.error(info, e);
|
||||||
|
throw new BizException(info, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1505,6 +1505,101 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
return ElectromagneticResultUtil.success(true);
|
return ElectromagneticResultUtil.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入工程
|
||||||
|
* @param file
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ElectromagneticResult<?> importPrj(MultipartFile file) {
|
||||||
|
try {
|
||||||
|
// 创建工程
|
||||||
|
String prjId = updateImportPrj2Db(file);
|
||||||
|
// 层级沿用
|
||||||
|
commonService.follow("100001", prjId, DataOwnEnum.SYS_PRJ.code);
|
||||||
|
// 工程发布
|
||||||
|
commonService.publish(prjId, DataOwnEnum.SYS_PRJ.code);
|
||||||
|
// 将文件存入到数据库和文件系统
|
||||||
|
updateImportPrj2FileSystem(file, prjId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateImportPrj2FileSystem(MultipartFile file, String prjId) throws IOException {
|
||||||
|
String tmpFile = elePropertyConfig.getEleTmpPath() + File.separator + file.getOriginalFilename();
|
||||||
|
String mainName = FileUtil.mainName(tmpFile);
|
||||||
|
FileUtil.del(tmpFile);
|
||||||
|
FileUtil.writeFromStream(file.getInputStream(), tmpFile);
|
||||||
|
ZipUtil.unzip(tmpFile);
|
||||||
|
List<File> files = FileUtil.loopFiles(elePropertyConfig.getEleTmpPath() + File.separator + mainName);
|
||||||
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
|
||||||
|
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code));
|
||||||
|
Map<String, EdFileInfo> fileIdMap = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String updateImportPrj2Db(MultipartFile file) {
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
String suffix = FileUtil.getSuffix(originalFilename);
|
||||||
|
String mainName = FileUtil.getName(originalFilename);
|
||||||
|
Assert.isTrue(StrUtil.equals(suffix, "zip"), "不支持 {} 格式的工程文件", suffix);
|
||||||
|
// 检查工程是否存在
|
||||||
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getFileName, mainName)
|
||||||
|
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
.eq(EdFileInfo::getParentId, PRJ_PARENT_ID));
|
||||||
|
|
||||||
|
if (!edFileInfos.isEmpty()) {
|
||||||
|
// 废除工程及其下面的所有文件
|
||||||
|
Set<String> ids = edFileInfos.stream().map(EdFileInfo::getId).collect(Collectors.toSet());
|
||||||
|
for (EdFileInfo edFileInfo : edFileInfos) {
|
||||||
|
String id = edFileInfo.getId();
|
||||||
|
List<EdFileInfo> edFileInfos1 = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo::getId)
|
||||||
|
.eq(EdFileInfo::getFileId, id)
|
||||||
|
.likeRight(EdFileInfo::getFilePath, id + MYSQL_FILE_PATH_SPLIT));
|
||||||
|
ids.addAll(edFileInfos1.stream().map(EdFileInfo::getId).collect(Collectors.toSet()));
|
||||||
|
}
|
||||||
|
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||||
|
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||||
|
.in(EdFileInfo::getId, ids));
|
||||||
|
UserThreadLocal.setSuccessInfo("", "", "导入工程时,发现了同名工程 {},删除了同名工程,ids是 {}", mainName, ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存信息到MySQL
|
||||||
|
String maxPrjId = this.baseMapper.maxPrjId();
|
||||||
|
LambdaQueryWrapper<EdFileInfo> qw = Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID);
|
||||||
|
Long prjCount = this.baseMapper.selectCount(qw.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code));
|
||||||
|
int id = Integer.parseInt(StrUtil.isEmpty(maxPrjId) ? "100000" : maxPrjId);
|
||||||
|
String newPrjId = String.valueOf(id + 1);
|
||||||
|
EdFileInfo fileInfo = new EdFileInfo();
|
||||||
|
fileInfo.newInit();
|
||||||
|
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||||
|
fileInfo.setId(newPrjId)
|
||||||
|
.setFileType("文件夹")
|
||||||
|
.setFileId(newPrjId)
|
||||||
|
.setFileName(mainName)
|
||||||
|
.setFileVersion(FILE_START_VERSION)
|
||||||
|
.setParentId(PRJ_PARENT_ID)
|
||||||
|
.setFileTime(nowTimeStr)
|
||||||
|
.setDataType(EleDataTypeEnum.FOLDER.code)
|
||||||
|
.setDataStatus(EleDataStatusEnum.PUBLISHED.code)
|
||||||
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||||
|
.setFilePath(newPrjId)
|
||||||
|
.setSort(prjCount.intValue() + 1)
|
||||||
|
.setFileCode(commonService.createFileCode(newPrjId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr))
|
||||||
|
.setDataOwn(DataOwnEnum.SYS_PRJ.code)
|
||||||
|
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||||
|
this.baseMapper.insert(fileInfo);
|
||||||
|
UserThreadLocal.setSuccessInfo("", newPrjId, "创建 {} 项目成功。", mainName);
|
||||||
|
return maxPrjId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一废除文件相关数据
|
* 统一废除文件相关数据
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -303,35 +303,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ElectromagneticResult<?> publish(String prjId, int dataOwnCode) {
|
public ElectromagneticResult<?> publish(String prjId, int dataOwnCode) {
|
||||||
EdFileInfo fileInfo = this.baseMapper.selectById(prjId);
|
return commonService.publish(prjId, dataOwnCode);
|
||||||
try {
|
|
||||||
// 将已经处于删除状态设置成逻辑删除
|
|
||||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
||||||
.select(EdFileInfo::getId, EdFileInfo::getFilePath, EdFileInfo::getFileName)
|
|
||||||
.eq(EdFileInfo::getDataOwn, dataOwnCode)
|
|
||||||
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.WAIT_DELETED.code)
|
|
||||||
.likeRight(EdFileInfo::getFilePath, prjId);
|
|
||||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(queryWrapper);
|
|
||||||
for (EdFileInfo edFileInfo : edFileInfos) {
|
|
||||||
this.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
|
|
||||||
.eq(EdFileInfo::getId, edFileInfo.getId())
|
|
||||||
.set(EdFileInfo::getAllDeleted, true)
|
|
||||||
.set(EdFileInfo::getPermanentDeleted, true)
|
|
||||||
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
|
|
||||||
}
|
|
||||||
// 其余置为发布状态
|
|
||||||
LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class)
|
|
||||||
.set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code)
|
|
||||||
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.NOT_PUBLISHED.code)
|
|
||||||
.likeRight(EdFileInfo::getFilePath, prjId);
|
|
||||||
this.update(new EdFileInfo(), updateWrapper);
|
|
||||||
UserThreadLocal.setSuccessInfo("", prjId, "项目 {} 发布成功", fileInfo.getFileName());
|
|
||||||
return ElectromagneticResultUtil.success(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String info = StrFormatter.format("项目 {} 发布异常", fileInfo.getFileName());
|
|
||||||
log.error(info, e);
|
|
||||||
throw new BizException(info, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -356,102 +328,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ElectromagneticResult<?> follow(String sourceId, String targetId, int dataOwnCode) {
|
public ElectromagneticResult<?> follow(String sourceId, String targetId, int dataOwnCode) {
|
||||||
|
return commonService.follow(sourceId, targetId, dataOwnCode);
|
||||||
try {
|
|
||||||
// 把source工程的层级结构copy到目标工程
|
|
||||||
// 查找source的全部目录
|
|
||||||
List<EdFileInfo> sourceEdFileInfos = commonService.selectAllPrjFolder(sourceId, dataOwnCode);
|
|
||||||
List<EdFileInfo> targetEdFileInfos = commonService.selectAllPrjFolder(targetId, dataOwnCode);
|
|
||||||
Set<String> sourceNames = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).map(EdFileInfo::getFileName).collect(Collectors.toSet());
|
|
||||||
Set<String> targetNames = targetEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).map(EdFileInfo::getFileName).collect(Collectors.toSet());
|
|
||||||
|
|
||||||
Collection<String> intersection = CollectionUtil.intersection(sourceNames, targetNames);
|
|
||||||
if (CollUtil.isNotEmpty(intersection)) {
|
|
||||||
String info = StrFormatter.format("层级沿用失败,源工程 {},目标工程 {},原因 存在相同子集", sourceId, targetId);
|
|
||||||
log.error(info);
|
|
||||||
return ElectromagneticResultUtil.fail("-1", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, String> idMaps = new HashMap<>();
|
|
||||||
idMaps.put(sourceId, targetId);
|
|
||||||
for (int i = 1; i <= elePropertyConfig.getPrjFolderMaxLength(); ++i) {
|
|
||||||
int layerIndex = i;
|
|
||||||
List<EdFileInfo> currentSourceLayerDirs = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == layerIndex).toList();
|
|
||||||
if (layerIndex == 1) {
|
|
||||||
targetEdFileInfos = commonService.selectAllPrjFolder(targetId, dataOwnCode);
|
|
||||||
EdFileInfo prjFileInfo = targetEdFileInfos.stream().filter(e -> e.getParentId().equals(PRJ_PARENT_ID)).findFirst().get();
|
|
||||||
List<EdFileInfo> targetChildLayerDirs = targetEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).toList();
|
|
||||||
int size = targetChildLayerDirs.size();
|
|
||||||
for (EdFileInfo edFileInfo : currentSourceLayerDirs) {
|
|
||||||
int maxFolderId = Integer.parseInt(this.baseMapper.maxPrjId());
|
|
||||||
String newFolderId = String.valueOf(maxFolderId + 1);
|
|
||||||
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
|
||||||
String fileCode = commonService.createFileCode(targetId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr);
|
|
||||||
EdFileInfo targetFile = new EdFileInfo();
|
|
||||||
targetFile.newInit();
|
|
||||||
targetFile.setId(newFolderId)
|
|
||||||
.setFileId(newFolderId)
|
|
||||||
.setFileName(edFileInfo.getFileName())
|
|
||||||
.setFileVersion(FILE_START_VERSION)
|
|
||||||
.setDataOwn(dataOwnCode)
|
|
||||||
.setParentId(idMaps.get(edFileInfo.getParentId()))
|
|
||||||
.setFileTime(nowTimeStr)
|
|
||||||
.setDataType(EleDataTypeEnum.FOLDER.code)
|
|
||||||
.setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
|
||||||
.setFileCode(fileCode)
|
|
||||||
.setFileType("文件夹")
|
|
||||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
||||||
.setFilePath(prjFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFolderId)
|
|
||||||
.setSort(++size)
|
|
||||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
|
||||||
this.save(targetFile);
|
|
||||||
targetEdFileInfos.add(targetFile);
|
|
||||||
idMaps.put(edFileInfo.getFileId(), newFolderId);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
||||||
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
|
|
||||||
.in(EdFileInfo::getId, idMaps.values()));
|
|
||||||
Map<String, EdFileInfo> map = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
|
||||||
for (EdFileInfo edFileInfo : currentSourceLayerDirs) {
|
|
||||||
String targetDirParentId = idMaps.get(edFileInfo.getParentId());
|
|
||||||
EdFileInfo parentFileInfo = map.get(targetDirParentId);
|
|
||||||
|
|
||||||
int maxFolderId = Integer.parseInt(this.baseMapper.maxPrjId());
|
|
||||||
String newFolderId = String.valueOf(maxFolderId + 1);
|
|
||||||
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
|
||||||
|
|
||||||
String fileCode = commonService.createFileCode(targetId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr);
|
|
||||||
EdFileInfo targetFile = new EdFileInfo();
|
|
||||||
targetFile.newInit();
|
|
||||||
targetFile.setId(newFolderId)
|
|
||||||
.setFileId(newFolderId)
|
|
||||||
.setFileName(edFileInfo.getFileName())
|
|
||||||
.setFileVersion(FILE_START_VERSION)
|
|
||||||
.setDataOwn(dataOwnCode)
|
|
||||||
.setParentId(targetDirParentId)
|
|
||||||
.setFileTime(nowTimeStr)
|
|
||||||
.setDataType(EleDataTypeEnum.FOLDER.code)
|
|
||||||
.setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
|
||||||
.setFileCode(fileCode)
|
|
||||||
.setFileType("文件夹")
|
|
||||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
||||||
.setFilePath(parentFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFolderId)
|
|
||||||
.setSort(edFileInfo.getSort())
|
|
||||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
|
||||||
this.save(targetFile);
|
|
||||||
targetEdFileInfos.add(targetFile);
|
|
||||||
idMaps.put(edFileInfo.getFileId(), newFolderId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
UserThreadLocal.setSuccessInfo("", targetId, "层级沿用成功");
|
|
||||||
return ElectromagneticResultUtil.success(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String info = StrFormatter.format("层级沿用失败,源工程 {},目标工程 {},原因 {}", sourceId, targetId, e.getMessage());
|
|
||||||
log.error(info, e);
|
|
||||||
throw new BizException(info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue