|
|
|
|
@ -1,12 +1,18 @@
|
|
|
|
|
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
|
|
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
|
|
|
|
import cn.hutool.core.lang.tree.TreeUtil;
|
|
|
|
|
import cn.hutool.core.text.StrFormatter;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.electromagnetic.industry.software.common.cons.ElectromagneticConstants;
|
|
|
|
|
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
|
|
|
|
import com.electromagnetic.industry.software.common.enums.EleDataSaveStatusEnum;
|
|
|
|
|
import com.electromagnetic.industry.software.common.enums.EleDataStatusEnum;
|
|
|
|
|
@ -16,9 +22,9 @@ import com.electromagnetic.industry.software.common.util.*;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.pojo.req.FolderResortDTO;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.pojo.resp.ProjectVO;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@ -33,6 +39,8 @@ import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
|
|
|
|
|
|
|
|
|
@ -63,6 +71,14 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public ElectromagneticResult<?> createNewPrj(String prjName) {
|
|
|
|
|
|
|
|
|
|
Assert.isTrue(EleCommonUtil.isFileNameValid(prjName), "文件名不符合规范,只能包含中文字符、下划线、连字符、加号、数字和英文字符且长度小于32。");
|
|
|
|
|
if (!EleCommonUtil.isFileNameValid(prjName)) {
|
|
|
|
|
String info = StrFormatter.format("工程名称{}不符合要求", prjName);
|
|
|
|
|
log.error(info);
|
|
|
|
|
return ElectromagneticResultUtil.fail("-1", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 首先检查工程是否存在
|
|
|
|
|
// TODO 一个项目如果被废除了,然后又新建了一个同名工程,这种情况怎么处理,需要产品确认。当前这里先按照同名如果存在则抛出异常处理。
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> existPrjWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
@ -85,7 +101,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
|
|
|
|
|
EdFileInfo fileInfo = new EdFileInfo();
|
|
|
|
|
fileInfo.setId(newPrjId)
|
|
|
|
|
.setFileId(IdWorker.getSnowFlakeIdString())
|
|
|
|
|
.setFileId(newPrjId)
|
|
|
|
|
.setFileName(prjName)
|
|
|
|
|
.setFileVersion(100)
|
|
|
|
|
.setFileTime(EleCommonUtil.getNowTimeStr())
|
|
|
|
|
@ -153,7 +169,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
ids.add(prjId);
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.select(EdFileInfo::getId)
|
|
|
|
|
.likeRight(EdFileInfo::getFilePath, prjId + ElectromagneticConstants.MYSQL_FILE_PATH_SPLIT);
|
|
|
|
|
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT);
|
|
|
|
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(queryWrapper);
|
|
|
|
|
edFileInfos.forEach(e -> ids.add(e.getId()));
|
|
|
|
|
Wrappers.lambdaUpdate(EdFileInfo.class).set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code).in(EdFileInfo::getId, ids);
|
|
|
|
|
@ -171,18 +187,27 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public ElectromagneticResult<?> addFolder(String parentId, String folderName) {
|
|
|
|
|
|
|
|
|
|
// 验证名称是否合法
|
|
|
|
|
Assert.isTrue(EleCommonUtil.isFileNameValid(folderName), "文件名不符合规范,只能包含中文字符、下划线、连字符、加号、数字和英文字符且长度小于32。");
|
|
|
|
|
|
|
|
|
|
if (!EleCommonUtil.isFileNameValid(folderName)) {
|
|
|
|
|
String info = StrFormatter.format("子集名称{}不符合要求", folderName);
|
|
|
|
|
log.error(info);
|
|
|
|
|
return ElectromagneticResultUtil.fail("-1", info);
|
|
|
|
|
}
|
|
|
|
|
// 首先判断判断当前深度是否已经达到6层
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.select(EdFileInfo::getId, EdFileInfo::getFilePath)
|
|
|
|
|
.eq(EdFileInfo::getId, parentId);
|
|
|
|
|
EdFileInfo edFileInfo = this.baseMapper.selectOne(queryWrapper);
|
|
|
|
|
String currentPath = edFileInfo.getFilePath();
|
|
|
|
|
List<String> paths = CollUtil.newArrayList(edFileInfo.getFilePath().split(ElectromagneticConstants.MYSQL_FILE_PATH_SPLIT));
|
|
|
|
|
List<String> paths = CollUtil.newArrayList(edFileInfo.getFilePath().split(MYSQL_FILE_PATH_SPLIT));
|
|
|
|
|
if (paths.size() >= prjFolderMaxLength) {
|
|
|
|
|
String info = "当前子集已达到最大层级,禁止创建子集。";
|
|
|
|
|
log.error(info);
|
|
|
|
|
return ElectromagneticResultUtil.fail("-1", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断文件夹名称是否存在
|
|
|
|
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.select(EdFileInfo::getId, EdFileInfo::getFileName)
|
|
|
|
|
@ -194,31 +219,32 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
return ElectromagneticResultUtil.fail("-1", info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// int id = Integer.parseInt(this.baseMapper.maxPrjId());
|
|
|
|
|
// Date now = new Date();
|
|
|
|
|
// String currentUserId = UserThreadLocal.getUserId();
|
|
|
|
|
// String newPrjId = String.valueOf(id + 1);
|
|
|
|
|
// EdFileInfo fileInfo = EdFileInfo.builder()
|
|
|
|
|
// .id(newPrjId)
|
|
|
|
|
// .fileId(IdWorker.getSnowFlakeIdString())
|
|
|
|
|
// .fileName(folderName)
|
|
|
|
|
// .fileVersion(100)
|
|
|
|
|
// .fileTime(EleCommonUtil.getNowTimeStr())
|
|
|
|
|
// .dataType(EleDataTypeEnum.FOLDER.code)
|
|
|
|
|
// .dataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
|
|
|
|
// .effectFlag(EffectFlagEnum.EFFECT.code)
|
|
|
|
|
// .saveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
|
|
|
// .filePath(newPrjId)
|
|
|
|
|
// .sort(1)
|
|
|
|
|
// .createdTime(now)
|
|
|
|
|
// .updateTime(now)
|
|
|
|
|
// .createdBy(currentUserId)
|
|
|
|
|
// .updatedBy(currentUserId)
|
|
|
|
|
// .build();
|
|
|
|
|
// this.save(fileInfo);
|
|
|
|
|
// // 保存到文件系统
|
|
|
|
|
// fileSystemService.createDirectory(eleDataPath);
|
|
|
|
|
return null;
|
|
|
|
|
int id = Integer.parseInt(this.baseMapper.maxPrjId());
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
String currentUserId = UserThreadLocal.getUserId();
|
|
|
|
|
String newFolderId = String.valueOf(id + 1);
|
|
|
|
|
String path = currentPath + MYSQL_FILE_PATH_SPLIT + newFolderId;
|
|
|
|
|
EdFileInfo fileInfo = new EdFileInfo();
|
|
|
|
|
fileInfo.setId(newFolderId)
|
|
|
|
|
.setFileId(newFolderId)
|
|
|
|
|
.setFileName(folderName)
|
|
|
|
|
.setFileVersion(100)
|
|
|
|
|
.setParentId(parentId)
|
|
|
|
|
.setFileTime(EleCommonUtil.getNowTimeStr())
|
|
|
|
|
.setDataType(EleDataTypeEnum.FOLDER.code)
|
|
|
|
|
.setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
|
|
|
|
.setEffectFlag(EffectFlagEnum.EFFECT.code)
|
|
|
|
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
|
|
|
.setFilePath(path)
|
|
|
|
|
.setSort(names.size() + 1)
|
|
|
|
|
.setCreatedTime(now)
|
|
|
|
|
.setUpdateTime(now)
|
|
|
|
|
.setCreatedBy(currentUserId)
|
|
|
|
|
.setUpdatedBy(currentUserId);
|
|
|
|
|
// 保存到文件系统
|
|
|
|
|
String targetFilePath = getPath(paths) + File.separator + folderName;
|
|
|
|
|
fileSystemService.createDirectory(targetFilePath);
|
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -228,7 +254,38 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ElectromagneticResult<?> queryAllPrjInfo() {
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.select(EdFileInfo::getId)
|
|
|
|
|
.eq(EdFileInfo::getParentId, 0)
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
|
|
|
|
|
List<String> ids = this.baseMapper.selectList(queryWrapper).stream().map(EdFileInfo::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<ProjectVO> projectVOS = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (String id : ids) {
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> queryWrapper1 = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.select(EdFileInfo::getId, EdFileInfo::getFileName, EdFileInfo::getParentId, EdFileInfo::getSort)
|
|
|
|
|
.like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT);
|
|
|
|
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(queryWrapper1);
|
|
|
|
|
// 转换为树
|
|
|
|
|
TreeNodeConfig config = new TreeNodeConfig();
|
|
|
|
|
config.setIdKey(EdFileInfo.Fields.id);
|
|
|
|
|
config.setParentIdKey(EdFileInfo.Fields.parentId);
|
|
|
|
|
config.setWeightKey(EdFileInfo.Fields.sort);
|
|
|
|
|
|
|
|
|
|
List<Tree<String>> trees = TreeUtil.build(edFileInfos, "0", config, ((obj, treeNode) -> {
|
|
|
|
|
treeNode.putExtra(EdFileInfo.Fields.id, obj.getId());
|
|
|
|
|
treeNode.putExtra(EdFileInfo.Fields.parentId, obj.getParentId());
|
|
|
|
|
treeNode.putExtra(EdFileInfo.Fields.sort, obj.getSort());
|
|
|
|
|
treeNode.putExtra(EdFileInfo.Fields.fileName, obj.getFileName());
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
String jsonStr = JSONUtil.toJsonStr(trees);
|
|
|
|
|
ProjectVO projectVO = JSONUtil.toList(jsonStr, ProjectVO.class).get(0);
|
|
|
|
|
projectVOS.add(projectVO);
|
|
|
|
|
}
|
|
|
|
|
return ElectromagneticResultUtil.success(projectVOS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -265,6 +322,149 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除子集
|
|
|
|
|
*
|
|
|
|
|
* @param fileId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ElectromagneticResult<?> deleteFolder(String fileId) {
|
|
|
|
|
// TODO是否需要判断文件夹是否为空
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.select(EdFileInfo::getId, EdFileInfo::getFilePath)
|
|
|
|
|
.like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + fileId + MYSQL_FILE_PATH_SPLIT)
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
|
|
|
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(queryWrapper);
|
|
|
|
|
List<String> ids = edFileInfos.stream().map(EdFileInfo::getId).collect(Collectors.toList());
|
|
|
|
|
ids.add(fileId);
|
|
|
|
|
LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class)
|
|
|
|
|
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
|
|
|
|
.set(EdFileInfo::getSort, -1)
|
|
|
|
|
.in(EdFileInfo::getId, ids);
|
|
|
|
|
this.baseMapper.update(null, updateWrapper);
|
|
|
|
|
|
|
|
|
|
String[] tmpFileIds = edFileInfos.get(0).getFilePath().split(MYSQL_FILE_PATH_SPLIT);
|
|
|
|
|
String parentId = tmpFileIds[0];
|
|
|
|
|
for (String tmpPathId : tmpFileIds) {
|
|
|
|
|
parentId = this.baseMapper.maxPrjId();
|
|
|
|
|
if (fileId.equals(tmpPathId)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 同层级的resort
|
|
|
|
|
List<EdFileInfo> edFileInfos1 = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.select(EdFileInfo::getId, EdFileInfo::getSort)
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
|
|
|
|
.eq(EdFileInfo::getParentId, parentId)
|
|
|
|
|
.orderByAsc(EdFileInfo::getSort));
|
|
|
|
|
for (int i = 1; i <= edFileInfos1.size(); i++) {
|
|
|
|
|
String id = edFileInfos1.get(i).getId();
|
|
|
|
|
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
|
|
|
|
.set(EdFileInfo::getSort, i)
|
|
|
|
|
.eq(EdFileInfo::getId, id));
|
|
|
|
|
}
|
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 层级沿用
|
|
|
|
|
*
|
|
|
|
|
* @param sourceId
|
|
|
|
|
* @param targetId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ElectromagneticResult<?> follow(String sourceId, String targetId) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String currentUserId = UserThreadLocal.getUserId();
|
|
|
|
|
// 把source工程的层级结构copy到目标工程
|
|
|
|
|
// 查找source的全部目录
|
|
|
|
|
List<EdFileInfo> sourceEdFileInfos = this.baseMapper.selectAllAdminFolder(sourceId);
|
|
|
|
|
List<EdFileInfo> targetEdFileInfos = this.baseMapper.selectAllAdminFolder(targetId);
|
|
|
|
|
// 确定层级最大为prjFolderMaxLength层,现在逐层来处理。
|
|
|
|
|
for (int i = 1; i <= prjFolderMaxLength; ++i) {
|
|
|
|
|
// 先查找source第i层下有那些子集
|
|
|
|
|
final int count = i;
|
|
|
|
|
EdFileInfo targetParentFile = targetEdFileInfos.stream()
|
|
|
|
|
.filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == count - 1)
|
|
|
|
|
.collect(Collectors.toList()).get(0);
|
|
|
|
|
List<EdFileInfo> sourceTmpEdFiles = sourceEdFileInfos.stream()
|
|
|
|
|
.filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == count)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
List<EdFileInfo> targetTmpEdFiles = targetEdFileInfos.stream()
|
|
|
|
|
.filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == count)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
Map<String, EdFileInfo> sourceFileNameMap= sourceTmpEdFiles.stream().collect(Collectors.toMap(EdFileInfo::getFileName, e -> e));
|
|
|
|
|
List<String> targetFileNames = targetTmpEdFiles.stream().map(EdFileInfo::getFileName).collect(Collectors.toList());
|
|
|
|
|
for (EdFileInfo edFileInfo : sourceTmpEdFiles) {
|
|
|
|
|
String sourceFileName = edFileInfo.getFileName();
|
|
|
|
|
if (!targetFileNames.contains(sourceFileName)) {
|
|
|
|
|
EdFileInfo sourceFile = sourceFileNameMap.get(sourceFileName);
|
|
|
|
|
EdFileInfo targetFile = new EdFileInfo();
|
|
|
|
|
int maxFolderId = Integer.parseInt(this.baseMapper.maxPrjId());
|
|
|
|
|
String newFolderId = String.valueOf(maxFolderId + 1);
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
targetFile.setId(newFolderId)
|
|
|
|
|
.setFileId(newFolderId)
|
|
|
|
|
.setFileName(sourceFile.getFileName())
|
|
|
|
|
.setFileVersion(100)
|
|
|
|
|
.setParentId(targetParentFile.getParentId())
|
|
|
|
|
.setFileTime(EleCommonUtil.getNowTimeStr())
|
|
|
|
|
.setDataType(EleDataTypeEnum.FOLDER.code)
|
|
|
|
|
.setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
|
|
|
|
.setEffectFlag(EffectFlagEnum.EFFECT.code)
|
|
|
|
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
|
|
|
|
.setFilePath(targetParentFile.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFolderId)
|
|
|
|
|
.setSort(targetTmpEdFiles.size() + 1)
|
|
|
|
|
.setCreatedTime(now)
|
|
|
|
|
.setUpdateTime(now)
|
|
|
|
|
.setCreatedBy(currentUserId)
|
|
|
|
|
.setUpdatedBy(currentUserId);
|
|
|
|
|
this.save(targetFile);
|
|
|
|
|
String targetSysFilePath = getSysFilePathByDbPath(targetFile.getFilePath()) + File.separator + sourceFileName;
|
|
|
|
|
FileUtil.mkdir(targetSysFilePath);
|
|
|
|
|
targetEdFileInfos = this.baseMapper.selectAllAdminFolder(targetId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
String info = StrFormatter.format("层级沿用失败");
|
|
|
|
|
log.error(info, e);
|
|
|
|
|
return ElectromagneticResultUtil.fail("-1", info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改子集名称
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @param newFolderName
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ElectromagneticResult<?> modifyFolder(String id, String newFolderName) {
|
|
|
|
|
try {
|
|
|
|
|
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.eq(EdFileInfo::getId, id));
|
|
|
|
|
String sysFilePath = getSysFilePathByDbPath(fileInfo.getFilePath());
|
|
|
|
|
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
|
|
|
|
.set(EdFileInfo::getFileName, newFolderName));
|
|
|
|
|
FileUtil.rename(new File(sysFilePath), newFolderName, true);
|
|
|
|
|
return ElectromagneticResultUtil.success(true);
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
String info = StrFormatter.format("修改子集名称为{}失败", newFolderName);
|
|
|
|
|
log.error(info, e);
|
|
|
|
|
return ElectromagneticResultUtil.fail("-1", info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getSysFilePathByDbPath(String dbPath) {
|
|
|
|
|
ArrayList<String> paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT));
|
|
|
|
|
return getPath(paths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getPath(List<String> ids) {
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
|