Merge branch 'dev-beihang' into develop

This commit is contained in:
chenxudong 2025-05-12 10:40:10 +08:00
commit ab1c8215bf
5 changed files with 342 additions and 126 deletions

View File

@ -201,4 +201,17 @@ public class SysEdFileInfoController {
String userId = UserThreadLocal.getUserId();
return ElectromagneticResultUtil.success(edFileInfoService.findFavorite(userId, fileInfoQueryDTO));
}
/**
* 从收藏夹移除
*
* @param
* @return
*/
@GetMapping("/importPrj")
@UserOperation(value = "导入工程", modelName = UserOperationModuleEnum.USER_PRJ)
public ElectromagneticResult<?> importPrj(@RequestParam("file") MultipartFile file) {
return edFileInfoService.importPrj(file);
}
}

View File

@ -243,4 +243,9 @@ public interface EdFileInfoService {
* @return
*/
ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode);
/**
* 导入工程
*/
ElectromagneticResult<?> importPrj(MultipartFile file);
}

View File

@ -1,6 +1,7 @@
package com.electromagnetic.industry.software.manage.service.serviceimpl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert;
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.json.JSONUtil;
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.electromagnetic.industry.software.common.enums.*;
import com.electromagnetic.industry.software.common.exception.BizException;
@ -235,7 +237,8 @@ public class CommonService {
case REPO_PRJ, REPO_FILE -> queryWrapper.eq(EdFileInfo::getDataOwn, DataOwnEnum.REPO_PRJ.code);
default -> throw new BizException("参数错误");
}
return edFileInfoMapper.selectList(queryWrapper);
List<EdFileInfo> edFileInfos = edFileInfoMapper.selectList(queryWrapper);
return edFileInfos;
}
@Transactional(rollbackFor = Exception.class)
@ -751,4 +754,137 @@ public class CommonService {
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, "层级沿用成功源工程id {}目标工程id {}", sourceId, 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, "项目 {} 发布成功, 项目id {}", fileInfo.getFileName(), prjId);
return ElectromagneticResultUtil.success(true);
} catch (Exception e) {
String info = StrFormatter.format("项目 {} 发布异常", fileInfo.getFileName());
log.error(info, e);
throw new BizException(info, e);
}
}
}

View File

@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.electromagnetic.industry.software.common.enums.*;
import com.electromagnetic.industry.software.common.enums.FilePermission;
import com.electromagnetic.industry.software.common.exception.BizException;
import com.electromagnetic.industry.software.common.exception.PermissionDeniedException;
import com.electromagnetic.industry.software.common.pojo.RespPageVO;
@ -28,6 +29,8 @@ import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
import com.electromagnetic.industry.software.common.util.*;
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
import com.electromagnetic.industry.software.manage.mapper.RoleMapper;
import com.electromagnetic.industry.software.manage.mapper.RolePermissionMapper;
import com.electromagnetic.industry.software.manage.mapper.UserMapper;
import com.electromagnetic.industry.software.manage.pojo.models.*;
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoVO;
@ -52,6 +55,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
@ -85,6 +89,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
private EdFileRelationService edFileRelationService;
@Resource
private RolePermissionService rolePermissionService;
@Resource
private RoleMapper roleMapper;
/**
* 查询文件列表
@ -1505,6 +1511,185 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
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);
// 添加所有权限
addRoleAndPermission(prjId);
} catch (Exception e) {
String info = "导入失败,原因 " + e.getMessage();
log.error(info, e);
throw new BizException(info, e);
}
return ElectromagneticResultUtil.success(true);
}
private void addRoleAndPermission(String prjId) {
// 首先添加角色这里先假设只有北航角色名称为936c586c88e44df7a262f0ebb4dbe3ab
Role role = roleMapper.selectOne(Wrappers.lambdaQuery(Role.class)
.eq(Role::getEffectFlag, EffectFlagEnum.EFFECT.code)
.eq(Role::getRoleName, "936c586c88e44df7a262f0ebb4dbe3ab"));
if (Objects.isNull(role)) {
role = new Role();
role.newInit();
role.setRoleName("936c586c88e44df7a262f0ebb4dbe3ab");
role.setRoleDesc("针对北航内定的角色");
roleMapper.insert(role);
}
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code)
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT));
Set<String> ids = edFileInfos.stream().map(e -> e.getId()).collect(Collectors.toSet());
ids.add(prjId);
for (String id : ids) {
for (FilePermission permission : FilePermission.values()) {
RolePermission rolePermission = new RolePermission();
rolePermission.newInit();
rolePermission.setRoleId(role.getId());
rolePermission.setFileId(id);
rolePermission.setPermissionCode(permission.getCode());
rolePermissionService.save(rolePermission);
}
}
}
private void updateImportPrj2FileSystem(MultipartFile file, String prjId) throws IOException {
String orgName = file.getOriginalFilename();
String tmpZipFile = elePropertyConfig.getEleTmpPath() + File.separator + orgName;
String mainName = FileUtil.mainName(orgName);
FileUtil.del(tmpZipFile);
FileUtil.writeFromStream(file.getInputStream(), tmpZipFile);
String destDir = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID();
try {
ZipUtil.unzip(tmpZipFile, destDir, StandardCharsets.UTF_8);
} catch (Exception e) {
ZipUtil.unzip(tmpZipFile, destDir, Charset.forName("GBK"));
}
File file1 = Objects.requireNonNull(new File(destDir).listFiles())[0];
FileUtil.rename(file1, mainName, true);
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, String> idNameMap = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, EdFileInfo::getFileName));
idNameMap.put(prjId, mainName);
Map<String, EdFileInfo> filePathMap = new HashMap<>();
for (EdFileInfo edFileInfo : edFileInfos) {
StringBuilder names = new StringBuilder();
for (String id : edFileInfo.getFilePath().split(MYSQL_FILE_PATH_SPLIT)) {
String name = idNameMap.get(id);
names.append(MYSQL_FILE_PATH_SPLIT).append(name);
}
filePathMap.put(names.substring(1), edFileInfo);
}
List<File> files = FileUtil.loopFiles(destDir);
String tmpPath = FileUtil.normalize(destDir);
for (File importFile : files) {
String parentDir = FileUtil.normalize(importFile.getParent());
String relativeFilePath = parentDir.replace(tmpPath, "");
String fileType = FileUtil.getSuffix(importFile.getName());
relativeFilePath = relativeFilePath.startsWith("/") ? relativeFilePath.substring(1) : relativeFilePath;
relativeFilePath = relativeFilePath.replace("/", MYSQL_FILE_PATH_SPLIT);
EdFileInfo edFileInfo = filePathMap.get(relativeFilePath);
Assert.notNull(edFileInfo, "导入的工程与定义的层级结构不一致");
String id = edFileInfo.getId();
EdFileInfo newEdFileInfo = new EdFileInfo();
newEdFileInfo.newInit();
String fileCode = commonService.createFileCode(edFileInfo.getFilePath(), fileType, FILE_START_VERSION, newEdFileInfo.getFileTime());
newEdFileInfo.setParentId(id)
.setFileCode(fileCode)
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
.setDataOwn(DataOwnEnum.SYS_FILE.code)
.setFileName(FileUtil.mainName(importFile))
.setFileContent(EleCommonUtil.parse(FileUtil.getInputStream(importFile), fileType))
.setFileType(fileType)
.setFileVersion(FILE_START_VERSION)
.setFileSize(file.getSize())
.setFilePath(edFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId())
.setDataType(EleDataTypeEnum.FILE.code)
.setDataStatus(PublishEnum.PUBLISHED.getCode())
.setEffectFlag(EffectFlagEnum.EFFECT.code);
this.baseMapper.insert(newEdFileInfo);
String destPath = commonService.getPrjRootPath1(DataOwnEnum.SYS_FILE.code) + File.separator + newEdFileInfo.getId();
FileUtil.move(importFile, new File(destPath), false);
EleCommonUtil.encryptFile(destPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
UserThreadLocal.setSuccessInfo(newEdFileInfo.getParentId(), newEdFileInfo.getId(), "解析导入的工程文件成功,导入的工程名为 {},文件名为 {}", orgName, importFile.getName());
}
}
private String updateImportPrj2Db(MultipartFile file) {
String originalFilename = file.getOriginalFilename();
String suffix = FileUtil.getSuffix(originalFilename);
String mainName = FileUtil.mainName(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 newPrjId;
}
/**
* 统一废除文件相关数据
*

View File

@ -303,35 +303,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
@Override
@Transactional(rollbackFor = Exception.class)
public ElectromagneticResult<?> publish(String prjId, int dataOwnCode) {
EdFileInfo fileInfo = this.baseMapper.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 = 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);
}
return commonService.publish(prjId, dataOwnCode);
}
/**
@ -356,102 +328,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
@Override
@Transactional(rollbackFor = Exception.class)
public ElectromagneticResult<?> follow(String sourceId, String targetId, int 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);
}
return commonService.follow(sourceId, targetId, dataOwnCode);
}
/**