开发了一部分的文件相关接口。
This commit is contained in:
parent
877fc5f557
commit
926f0ae96e
|
|
@ -1,11 +1,88 @@
|
||||||
package com.electromagnetic.industry.software.manage.controller;
|
package com.electromagnetic.industry.software.manage.controller;
|
||||||
|
|
||||||
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.req.FileInfoQueryDTO;
|
||||||
|
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/data/ed/file")
|
@RequestMapping("/data/ed/file")
|
||||||
public class EdFileInfoController {
|
public class EdFileInfoController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private EdFileInfoService edFileInfoService;
|
||||||
|
|
||||||
|
@RequestMapping("tree")
|
||||||
|
public ElectromagneticResult<?> tree() {
|
||||||
|
return edFileInfoService.tree();
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("createFolder")
|
||||||
|
public ElectromagneticResult<?> createFolder(@RequestParam String parentId, @RequestParam String newFolderName) {
|
||||||
|
return edFileInfoService.createFolder(parentId, newFolderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("deleteFolder")
|
||||||
|
public ElectromagneticResult<?> deleteFolder(@RequestParam String id, @RequestParam Integer dataType) {
|
||||||
|
return edFileInfoService.deleteFolder(id, dataType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("info")
|
||||||
|
public ElectromagneticResult<?> info(@RequestBody FileInfoQueryDTO fileInfoQueryDTO) {
|
||||||
|
return edFileInfoService.queryEdFileInfo(fileInfoQueryDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("upload")
|
||||||
|
public ElectromagneticResult<?> upload() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("download")
|
||||||
|
public ResponseEntity<InputStreamResource> download(@RequestParam String id, HttpServletResponse response) {
|
||||||
|
return edFileInfoService.download(id, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("updateFileInfo")
|
||||||
|
public ElectromagneticResult<?> updateFileInfo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("deleteFile")
|
||||||
|
public ElectromagneticResult<?> deleteFile() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("moveFile")
|
||||||
|
public ElectromagneticResult<?> moveFile() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("copyFile")
|
||||||
|
public ElectromagneticResult<?> copyFile() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("versionView")
|
||||||
|
public ElectromagneticResult<?> versionView() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("versionBack")
|
||||||
|
public ElectromagneticResult<?> versionBack() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("batchExport")
|
||||||
|
public ElectromagneticResult<?> batchExport() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ public class ProjectController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("modifyFolder")
|
@RequestMapping("modifyFolder")
|
||||||
public ElectromagneticResult<?> modifyFolder(@RequestParam String newFolderName, @RequestParam String id) {
|
public ElectromagneticResult<?> modifyFolder(@RequestParam String newFolderName, @RequestParam String id, @RequestParam String parentId) {
|
||||||
return edPrjService.modifyFolder(id, newFolderName);
|
return edPrjService.modifyFolder(id, newFolderName, parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("deleteFolder")
|
@RequestMapping("deleteFolder")
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,4 @@ public interface EdFileInfoMapper extends BaseMapper<EdFileInfo> {
|
||||||
|
|
||||||
String maxPrjId();
|
String maxPrjId();
|
||||||
|
|
||||||
List<EdFileInfo> selectAllAdminFolder(String prjId);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,12 @@ public class EdFileInfo extends BaseModel {
|
||||||
@TableField(value = "file_id")
|
@TableField(value = "file_id")
|
||||||
private String fileId;
|
private String fileId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父目录id
|
||||||
|
*/
|
||||||
|
@TableField(value = "parent_id")
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件类型
|
* 文件类型
|
||||||
*/
|
*/
|
||||||
|
|
@ -68,12 +74,6 @@ public class EdFileInfo extends BaseModel {
|
||||||
@TableField(value = "file_path")
|
@TableField(value = "file_path")
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
|
||||||
/**
|
|
||||||
* 父目录id
|
|
||||||
*/
|
|
||||||
@TableField(value = "parent_id")
|
|
||||||
private String parentId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据类型,0-文件夹 1-文件
|
* 数据类型,0-文件夹 1-文件
|
||||||
*/
|
*/
|
||||||
|
|
@ -113,6 +113,18 @@ public class EdFileInfo extends BaseModel {
|
||||||
/**
|
/**
|
||||||
* 文件夹顺序
|
* 文件夹顺序
|
||||||
*/
|
*/
|
||||||
@TableField("sort")
|
@TableField(value = "sort")
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件编码
|
||||||
|
*/
|
||||||
|
@TableField(value = "file_code")
|
||||||
|
private String fileCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是管理员定义的系统层级目录
|
||||||
|
*/
|
||||||
|
@TableField(value = "prj_dir")
|
||||||
|
private Boolean prjDir;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.pojo.other;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FileInfoDTO {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String fileId;
|
||||||
|
|
||||||
|
private String fileType;
|
||||||
|
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
private String fileNote;
|
||||||
|
|
||||||
|
private Integer fileVersion;
|
||||||
|
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
private Integer dataType;
|
||||||
|
|
||||||
|
private Integer dataStatus;
|
||||||
|
|
||||||
|
private Integer saveStatus;
|
||||||
|
|
||||||
|
private String fileSize;
|
||||||
|
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
private String fileCode;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.pojo.req;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FileInfoQueryDTO {
|
||||||
|
|
||||||
|
/** 父文件夹id */
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
/** 当前页码 */
|
||||||
|
private Integer pageNum;
|
||||||
|
|
||||||
|
/** 每页的数量 */
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
/** 搜索关键词 */
|
||||||
|
private String keyword;
|
||||||
|
|
||||||
|
/** 文件类型 (0-文件夹 1-文件)*/
|
||||||
|
private Integer fileType;
|
||||||
|
|
||||||
|
/** 上传时间(0-升序,1-降序)*/
|
||||||
|
private Integer createdTime;
|
||||||
|
|
||||||
|
/** 版本号(0-升序,1-降序 */
|
||||||
|
private Integer fileVersion;
|
||||||
|
|
||||||
|
/** 文件大小0-升序,1-降序) */
|
||||||
|
private Integer fileSize;
|
||||||
|
|
||||||
|
/** 状态(0-未发布 1-已发布 2-占用) */
|
||||||
|
private Integer dataStatus;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.pojo.resp;
|
||||||
|
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoDTO;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class FileInfoQueryPageVO {
|
||||||
|
|
||||||
|
private long total;
|
||||||
|
|
||||||
|
private List<FileInfoDTO> records = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.service;
|
||||||
|
|
||||||
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.req.FileInfoQueryDTO;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface EdFileInfoService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询文件列表
|
||||||
|
* @param fileInfoQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ElectromagneticResult<?> queryEdFileInfo(FileInfoQueryDTO fileInfoQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建文件夹
|
||||||
|
* @param parentId
|
||||||
|
* @param newFolderName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ElectromagneticResult<?> createFolder(String parentId, String newFolderName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目层级结构查询
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ElectromagneticResult<?> tree();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除目录
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param dataType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ElectromagneticResult<?> deleteFolder(String id, Integer dataType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载文件
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ResponseEntity<InputStreamResource> download(String id, HttpServletResponse response);
|
||||||
|
}
|
||||||
|
|
@ -88,5 +88,5 @@ public interface EdPrjService {
|
||||||
* @param newFolderName
|
* @param newFolderName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ElectromagneticResult<?> modifyFolder(String id, String newFolderName);
|
ElectromagneticResult<?> modifyFolder(String id, String newFolderName, String parentId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,297 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
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.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.EffectFlagEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.EleDataSaveStatusEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.EleDataStatusEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.EleDataTypeEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
|
import com.electromagnetic.industry.software.common.util.EleLog;
|
||||||
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
|
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.resp.ProjectVO;
|
||||||
|
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CommonService {
|
||||||
|
|
||||||
|
private final EleLog log = new EleLog(CommonService.class);
|
||||||
|
private static final Map<String, String> FILE_TYPE_ENUM = new HashMap<>();
|
||||||
|
@Value("${prj.folder.max.length}")
|
||||||
|
private int prjFolderMaxLength;
|
||||||
|
|
||||||
|
static {
|
||||||
|
FILE_TYPE_ENUM.put(EleDataTypeEnum.FOLDER.desc, "01");
|
||||||
|
FILE_TYPE_ENUM.put("py", "02");
|
||||||
|
FILE_TYPE_ENUM.put("zip", "03");
|
||||||
|
FILE_TYPE_ENUM.put("jpg", "04");
|
||||||
|
FILE_TYPE_ENUM.put("jpeg", "05");
|
||||||
|
FILE_TYPE_ENUM.put("png", "06");
|
||||||
|
FILE_TYPE_ENUM.put("gif", "07");
|
||||||
|
FILE_TYPE_ENUM.put("bmp", "08");
|
||||||
|
FILE_TYPE_ENUM.put("tif", "09");
|
||||||
|
FILE_TYPE_ENUM.put("tiff", "10");
|
||||||
|
FILE_TYPE_ENUM.put("svg", "11");
|
||||||
|
FILE_TYPE_ENUM.put("psd", "12");
|
||||||
|
FILE_TYPE_ENUM.put("pdf", "13");
|
||||||
|
FILE_TYPE_ENUM.put("doc", "14");
|
||||||
|
FILE_TYPE_ENUM.put("docx", "15");
|
||||||
|
FILE_TYPE_ENUM.put("xls", "16");
|
||||||
|
FILE_TYPE_ENUM.put("xlsx", "17");
|
||||||
|
FILE_TYPE_ENUM.put("ppt", "18");
|
||||||
|
FILE_TYPE_ENUM.put("pptx", "19");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private String eleDataPath;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private EdFileInfoMapper edFileInfoMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FileSystemService fileSystemService;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
String osName = System.getProperty("os.name").toLowerCase();
|
||||||
|
eleDataPath = osName.startsWith("win") ? environment.getProperty("data.windows.path") : environment.getProperty("data.linux.path");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查同层级是否有同名的文件夹
|
||||||
|
*/
|
||||||
|
public boolean checkSameFolder(String parentId, String newFolderName) {
|
||||||
|
Long count = edFileInfoMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getParentId, parentId)
|
||||||
|
.eq(EdFileInfo::getFileName, newFolderName));
|
||||||
|
|
||||||
|
return count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileSysPath(String dbPath) {
|
||||||
|
ArrayList<String> paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT));
|
||||||
|
String path = getPath(paths);
|
||||||
|
return eleDataPath + File.separator + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath(List<String> ids) {
|
||||||
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo::getId, EdFileInfo::getFileName)
|
||||||
|
.in(EdFileInfo::getId, ids);
|
||||||
|
List<EdFileInfo> edFileInfos = edFileInfoMapper.selectList(queryWrapper);
|
||||||
|
Map<String, String> map = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, EdFileInfo::getFileName));
|
||||||
|
StringBuilder path = new StringBuilder();
|
||||||
|
for (String id : ids) {
|
||||||
|
String tmp = map.get(id) + File.separator;
|
||||||
|
path.append(tmp);
|
||||||
|
}
|
||||||
|
return path.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String createFileCode(String parentId, String fileType, int version, String timeStr) {
|
||||||
|
return parentId + FILE_TYPE_ENUM.get(fileType) + version + timeStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EdFileInfo> selectAllAdminFolder(String id) {
|
||||||
|
return edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code)
|
||||||
|
.eq(EdFileInfo::getPrjDir, true)
|
||||||
|
.likeRight(EdFileInfo::getFilePath, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ElectromagneticResult<?> addFolder(String parentId, String folderName, boolean maxLengthCheck, boolean isPrjDir) {
|
||||||
|
|
||||||
|
// 验证名称是否合法
|
||||||
|
Assert.isTrue(EleCommonUtil.isFileNameValid(folderName), "文件名不符合规范,只能包含中文字符、下划线、连字符、加号、数字和英文字符且长度小于32。");
|
||||||
|
|
||||||
|
if (!EleCommonUtil.isFileNameValid(folderName)) {
|
||||||
|
String info = StrFormatter.format("子集名称{}不符合要求", folderName);
|
||||||
|
log.error(info);
|
||||||
|
return ElectromagneticResultUtil.fail("-1", info);
|
||||||
|
}
|
||||||
|
|
||||||
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo::getId, EdFileInfo::getFilePath)
|
||||||
|
.eq(EdFileInfo::getId, parentId);
|
||||||
|
EdFileInfo edFileInfo = edFileInfoMapper.selectOne(queryWrapper);
|
||||||
|
String currentPath = edFileInfo.getFilePath();
|
||||||
|
List<String> paths = CollUtil.newArrayList(edFileInfo.getFilePath().split(MYSQL_FILE_PATH_SPLIT));
|
||||||
|
if (maxLengthCheck) {
|
||||||
|
if (paths.size() >= prjFolderMaxLength) {
|
||||||
|
String info = "当前子集已达到最大层级,禁止创建子集。";
|
||||||
|
log.error(info);
|
||||||
|
return ElectromagneticResultUtil.fail("-1", info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断文件夹名称是否存在
|
||||||
|
List<EdFileInfo> edFileInfos = edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo::getId, EdFileInfo::getFileName)
|
||||||
|
.eq(EdFileInfo::getParentId, parentId));
|
||||||
|
List<String> names = edFileInfos.stream().map(EdFileInfo::getFileName).collect(Collectors.toList());
|
||||||
|
if (names.contains(folderName)) {
|
||||||
|
String info = "该子集名称已存在";
|
||||||
|
log.error(info);
|
||||||
|
return ElectromagneticResultUtil.fail("-1", info);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int id = Integer.parseInt(edFileInfoMapper.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();
|
||||||
|
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||||
|
fileInfo.setId(newFolderId)
|
||||||
|
.setFileId(newFolderId)
|
||||||
|
.setFileName(folderName)
|
||||||
|
.setFileVersion(FILE_START_VERSION)
|
||||||
|
.setParentId(parentId)
|
||||||
|
.setFileCode(createFileCode(parentId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr))
|
||||||
|
.setFileTime(nowTimeStr)
|
||||||
|
.setPrjDir(isPrjDir)
|
||||||
|
.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);
|
||||||
|
edFileInfoMapper.insert(fileInfo);
|
||||||
|
// 保存到文件系统
|
||||||
|
String targetFilePath = getEleDataPath() + File.separator + getPath(paths) + File.separator + folderName;
|
||||||
|
fileSystemService.createDirectory(targetFilePath);
|
||||||
|
return ElectromagneticResultUtil.success(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String info = "添加子集失败";
|
||||||
|
log.error(info, e);
|
||||||
|
throw new BizException(-1, info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ElectromagneticResult<?> queryAllPrjInfo() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo::getId)
|
||||||
|
.eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
||||||
|
List<String> ids = edFileInfoMapper.selectList(queryWrapper).stream().map(EdFileInfo::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<ProjectVO> projectVOS = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String id : ids) {
|
||||||
|
List<EdFileInfo> edFileInfos = selectAllAdminFolder(id);
|
||||||
|
|
||||||
|
// 转换为树
|
||||||
|
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, PRJ_PARENT_ID, 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);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String info = "查询项目失败";
|
||||||
|
log.error(info, e);
|
||||||
|
throw new BizException(-1, info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ElectromagneticResult<?> deleteFolder(String fileId, String parentId, boolean needResort) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// TODO 如果文件夹下存在文件(不包括文件夹,包括已经删除的文件),则不允许删除
|
||||||
|
Long count = edFileInfoMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + fileId + MYSQL_FILE_PATH_SPLIT)
|
||||||
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code));
|
||||||
|
if (count > 0) {
|
||||||
|
String info = "禁止删除非空文件夹";
|
||||||
|
log.info(info);
|
||||||
|
throw new BizException(-1, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = edFileInfoMapper.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)
|
||||||
|
.set(EdFileInfo::getUpdateTime, new Date())
|
||||||
|
.set(EdFileInfo::getUpdatedBy, UserThreadLocal.getUserId())
|
||||||
|
.in(EdFileInfo::getId, ids);
|
||||||
|
edFileInfoMapper.update(null, updateWrapper);
|
||||||
|
if (!needResort) {
|
||||||
|
return ElectromagneticResultUtil.success(true);
|
||||||
|
}
|
||||||
|
// 同层级的resort
|
||||||
|
List<EdFileInfo> edFileInfos1 = edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo::getId, EdFileInfo::getSort)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
.eq(EdFileInfo::getParentId, parentId)
|
||||||
|
.orderByAsc(EdFileInfo::getSort));
|
||||||
|
Date now = new Date();
|
||||||
|
String currentUserId = UserThreadLocal.getUserId();
|
||||||
|
for (int i = 0; i < edFileInfos1.size(); i++) {
|
||||||
|
String id = edFileInfos1.get(i).getId();
|
||||||
|
edFileInfoMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||||
|
.set(EdFileInfo::getSort, i + 1)
|
||||||
|
.set(EdFileInfo::getUpdatedBy, currentUserId)
|
||||||
|
.set(EdFileInfo::getUpdateTime, now)
|
||||||
|
.eq(EdFileInfo::getId, id));
|
||||||
|
}
|
||||||
|
return ElectromagneticResultUtil.success(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
String info = "删除子集异常";
|
||||||
|
log.error(info, e);
|
||||||
|
throw new BizException(-1, info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,155 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
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.exception.BizException;
|
||||||
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
|
import com.electromagnetic.industry.software.common.util.EleLog;
|
||||||
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
|
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoDTO;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.req.FileInfoQueryDTO;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.resp.FileInfoQueryPageVO;
|
||||||
|
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||||
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.BindException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CommonService commonService;
|
||||||
|
|
||||||
|
private EleLog log = new EleLog(EdFileInfoServiceImpl.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询文件列表
|
||||||
|
* @param fileInfoQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ElectromagneticResult<?> queryEdFileInfo(FileInfoQueryDTO fileInfoQueryDTO) {
|
||||||
|
|
||||||
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select()
|
||||||
|
.eq(EdFileInfo::getParentId, fileInfoQueryDTO.getParentId())
|
||||||
|
.like(StrUtil.isNotEmpty(fileInfoQueryDTO.getKeyword()), EdFileInfo::getFileName, fileInfoQueryDTO.getKeyword())
|
||||||
|
.like(StrUtil.isNotEmpty(fileInfoQueryDTO.getKeyword()), EdFileInfo::getFileNote, fileInfoQueryDTO.getKeyword())
|
||||||
|
.eq(Objects.equals(fileInfoQueryDTO.getFileType(), 0), EdFileInfo::getFileType, 0)
|
||||||
|
.eq(Objects.equals(fileInfoQueryDTO.getFileType(), 1), EdFileInfo::getFileType, 1)
|
||||||
|
|
||||||
|
.eq(Objects.equals(fileInfoQueryDTO.getDataStatus(), 0), EdFileInfo::getDataStatus, 0)
|
||||||
|
.eq(Objects.equals(fileInfoQueryDTO.getDataStatus(), 1), EdFileInfo::getDataStatus, 1)
|
||||||
|
.eq(Objects.equals(fileInfoQueryDTO.getDataStatus(), 2), EdFileInfo::getDataStatus, 2)
|
||||||
|
|
||||||
|
.orderByAsc(Objects.equals(fileInfoQueryDTO.getCreatedTime(), 0), EdFileInfo::getCreatedTime)
|
||||||
|
.orderByDesc(Objects.equals(fileInfoQueryDTO.getCreatedTime(), 1), EdFileInfo::getCreatedTime)
|
||||||
|
|
||||||
|
.orderByAsc(Objects.equals(fileInfoQueryDTO.getFileVersion(), 0), EdFileInfo::getFileVersion)
|
||||||
|
.orderByDesc(Objects.equals(fileInfoQueryDTO.getFileVersion(), 1), EdFileInfo::getFileVersion)
|
||||||
|
|
||||||
|
.orderByAsc(Objects.equals(fileInfoQueryDTO.getFileSize(), 0), EdFileInfo::getFileSize)
|
||||||
|
.orderByDesc(Objects.equals(fileInfoQueryDTO.getFileSize(), 1), EdFileInfo::getFileSize)
|
||||||
|
|
||||||
|
.orderByAsc(Objects.equals(fileInfoQueryDTO.getCreatedTime(), 0), EdFileInfo::getCreatedTime)
|
||||||
|
.orderByDesc(Objects.equals(fileInfoQueryDTO.getCreatedTime(), 1), EdFileInfo::getCreatedTime);
|
||||||
|
Page<EdFileInfo> edFileInfoPage = this.baseMapper.selectPage(new Page<>(fileInfoQueryDTO.getPageNum(), fileInfoQueryDTO.getPageSize()), queryWrapper);
|
||||||
|
long total = edFileInfoPage.getTotal();
|
||||||
|
List<FileInfoDTO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileInfoDTO.class);
|
||||||
|
return ElectromagneticResultUtil.success(new FileInfoQueryPageVO(total, records));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建文件夹
|
||||||
|
* @param parentId
|
||||||
|
* @param newFolderName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ElectromagneticResult<?> createFolder(String parentId, String newFolderName) {
|
||||||
|
return commonService.addFolder(parentId, newFolderName, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目层级结构查询
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ElectromagneticResult<?> tree() {
|
||||||
|
return commonService.queryAllPrjInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除目录
|
||||||
|
* @param id
|
||||||
|
* @param dataType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ElectromagneticResult<?> deleteFolder(String id, Integer dataType) {
|
||||||
|
|
||||||
|
Assert.isTrue(dataType == 0 || dataType == 1, "参数错误");
|
||||||
|
if (dataType == 0) {
|
||||||
|
return commonService.deleteFolder(id, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||||
|
.set(EdFileInfo::getEffectFlag, false)
|
||||||
|
.eq(EdFileInfo::getId, id));
|
||||||
|
return ElectromagneticResultUtil.success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载文件
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<InputStreamResource> download(String id, HttpServletResponse response) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.<EdFileInfo>lambdaQuery().eq(EdFileInfo::getId, id));
|
||||||
|
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath());
|
||||||
|
Assert.isTrue(FileUtil.exist(fileSysPath), "下载文件不存在。");
|
||||||
|
FileSystemResource fileSystemResource = new FileSystemResource(fileSysPath);
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
|
headers.add("Pragma", "no-cache");
|
||||||
|
headers.add("Expires", "0");
|
||||||
|
String fileName = Base64.encode(fileSystemResource.getFilename());
|
||||||
|
response.setHeader("content-disposition","attachment;filename=" + fileName);
|
||||||
|
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||||
|
return ResponseEntity
|
||||||
|
.ok()
|
||||||
|
.headers(headers)
|
||||||
|
.contentLength(fileSystemResource.contentLength())
|
||||||
|
.contentType(MediaType.parseMediaType("application/octet-stream;charset=UTF-8"))
|
||||||
|
.body(new InputStreamResource(fileSystemResource.getInputStream()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
String info = "下载文件异常";
|
||||||
|
log.error(info, e);
|
||||||
|
throw new BizException(-1, info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,8 @@
|
||||||
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.lang.Assert;
|
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.text.StrFormatter;
|
||||||
import cn.hutool.core.util.StrUtil;
|
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.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
|
@ -25,15 +20,12 @@ import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
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.req.FolderResortDTO;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.resp.ProjectVO;
|
|
||||||
import com.electromagnetic.industry.software.manage.service.EdPrjService;
|
import com.electromagnetic.industry.software.manage.service.EdPrjService;
|
||||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -42,15 +34,12 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.MYSQL_FILE_PATH_SPLIT;
|
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdPrjService {
|
public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdPrjService {
|
||||||
|
|
||||||
private static final String PRJ_PARENT_ID = "0";
|
|
||||||
private final EleLog log = new EleLog(EdPrjServiceImpl.class);
|
private final EleLog log = new EleLog(EdPrjServiceImpl.class);
|
||||||
@Resource
|
|
||||||
private Environment environment;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FileSystemService fileSystemService;
|
private FileSystemService fileSystemService;
|
||||||
|
|
@ -58,14 +47,8 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
@Value("${prj.folder.max.length}")
|
@Value("${prj.folder.max.length}")
|
||||||
private int prjFolderMaxLength;
|
private int prjFolderMaxLength;
|
||||||
|
|
||||||
private String eleDataPath;
|
@Resource
|
||||||
|
private CommonService commonService;
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
String osName = System.getProperty("os.name").toLowerCase();
|
|
||||||
eleDataPath = osName.startsWith("win") ? environment.getProperty("data.windows.path") : environment.getProperty("data.linux.path");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新的工程
|
* 创建一个新的工程
|
||||||
|
|
@ -85,12 +68,11 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
|
|
||||||
// 首先检查工程是否存在
|
// 首先检查工程是否存在
|
||||||
// TODO 一个项目如果被废除了,然后又新建了一个同名工程,这种情况怎么处理,需要产品确认。当前这里先按照同名如果存在则抛出异常处理。
|
// TODO 一个项目如果被废除了,然后又新建了一个同名工程,这种情况怎么处理,需要产品确认。当前这里先按照同名如果存在则抛出异常处理。
|
||||||
LambdaQueryWrapper<EdFileInfo> existPrjWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
Long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.eq(EdFileInfo::getParentId, "")
|
.eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
|
||||||
.isNull(EdFileInfo::getParentId);
|
.eq(EdFileInfo::getFileName, prjName));
|
||||||
|
|
||||||
List<EdFileInfo> existEdFileInfos = this.baseMapper.selectList(existPrjWrapper);
|
if (count > 0) {
|
||||||
if (CollUtil.isNotEmpty(existEdFileInfos)) {
|
|
||||||
String info = StrFormatter.format("{} 已经存在", prjName);
|
String info = StrFormatter.format("{} 已经存在", prjName);
|
||||||
log.info(info);
|
log.info(info);
|
||||||
ElectromagneticResultUtil.fail("-1", "该项目名称已经存在。");
|
ElectromagneticResultUtil.fail("-1", "该项目名称已经存在。");
|
||||||
|
|
@ -105,25 +87,28 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
String newPrjId = String.valueOf(id + 1);
|
String newPrjId = String.valueOf(id + 1);
|
||||||
|
|
||||||
EdFileInfo fileInfo = new EdFileInfo();
|
EdFileInfo fileInfo = new EdFileInfo();
|
||||||
|
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||||
fileInfo.setId(newPrjId)
|
fileInfo.setId(newPrjId)
|
||||||
.setFileId(newPrjId)
|
.setFileId(newPrjId)
|
||||||
.setFileName(prjName)
|
.setFileName(prjName)
|
||||||
.setFileVersion(100)
|
.setFileVersion(FILE_START_VERSION)
|
||||||
.setParentId(PRJ_PARENT_ID)
|
.setParentId(PRJ_PARENT_ID)
|
||||||
.setFileTime(EleCommonUtil.getNowTimeStr())
|
.setFileTime(nowTimeStr)
|
||||||
|
.setPrjDir(true)
|
||||||
.setDataType(EleDataTypeEnum.FOLDER.code)
|
.setDataType(EleDataTypeEnum.FOLDER.code)
|
||||||
.setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
.setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code)
|
||||||
.setEffectFlag(EffectFlagEnum.EFFECT.code)
|
.setEffectFlag(EffectFlagEnum.EFFECT.code)
|
||||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||||
.setFilePath(newPrjId)
|
.setFilePath(newPrjId)
|
||||||
.setSort(1)
|
.setSort(1)
|
||||||
|
.setFileCode(commonService.createFileCode(newPrjId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr))
|
||||||
.setCreatedTime(now)
|
.setCreatedTime(now)
|
||||||
.setUpdateTime(now)
|
.setUpdateTime(now)
|
||||||
.setCreatedBy(currentUserId)
|
.setCreatedBy(currentUserId)
|
||||||
.setUpdatedBy(currentUserId);
|
.setUpdatedBy(currentUserId);
|
||||||
this.save(fileInfo);
|
this.save(fileInfo);
|
||||||
// 保存到文件系统
|
// 保存到文件系统
|
||||||
fileSystemService.createDirectory(eleDataPath + File.separator + prjName);
|
fileSystemService.createDirectory(commonService.getEleDataPath() + File.separator + prjName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String info = StrFormatter.format("文件创建失败,具体为--->{}", e.getMessage());
|
String info = StrFormatter.format("文件创建失败,具体为--->{}", e.getMessage());
|
||||||
log.error(info, e);
|
log.error(info, e);
|
||||||
|
|
@ -134,7 +119,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改项目名称
|
* 修改项目名称
|
||||||
*
|
|
||||||
* @param prjId
|
* @param prjId
|
||||||
* @param newPrjName
|
* @param newPrjName
|
||||||
* @return
|
* @return
|
||||||
|
|
@ -143,18 +127,32 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ElectromagneticResult<?> modifyPrjName(String prjId, String newPrjName) {
|
public ElectromagneticResult<?> modifyPrjName(String prjId, String newPrjName) {
|
||||||
try {
|
try {
|
||||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getId, prjId);
|
Long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
EdFileInfo fileInfo = this.baseMapper.selectOne(queryWrapper);
|
.eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
|
||||||
|
.eq(EdFileInfo::getFileName, newPrjName));
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
String info = StrFormatter.format("{} 已经存在", newPrjName);
|
||||||
|
log.info(info);
|
||||||
|
ElectromagneticResultUtil.fail("-1", "该项目名称已经存在。");
|
||||||
|
}
|
||||||
|
|
||||||
|
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.select(EdFileInfo::getFileName)
|
||||||
|
.eq(EdFileInfo::getId, prjId));
|
||||||
String oldPrjName = fileInfo.getFileName();
|
String oldPrjName = fileInfo.getFileName();
|
||||||
String newPath = eleDataPath + File.separator + newPrjName;
|
String newPath = commonService.getEleDataPath();
|
||||||
if (fileSystemService.checkFolderExist(newPath)) {
|
if (fileSystemService.checkFolderExist(newPath)) {
|
||||||
String info = StrFormatter.format("工程名{}已经存在", newPrjName);
|
String info = StrFormatter.format("工程名{}已经存在", newPrjName);
|
||||||
log.error(info);
|
log.error(info);
|
||||||
return ElectromagneticResultUtil.fail("-1", info);
|
return ElectromagneticResultUtil.fail("-1", info);
|
||||||
}
|
}
|
||||||
fileInfo.setFileName(newPrjName);
|
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||||
this.baseMapper.updateById(fileInfo);
|
.eq(EdFileInfo::getId, prjId)
|
||||||
fileSystemService.renameFile(eleDataPath, oldPrjName, newPrjName);
|
.set(EdFileInfo::getFileName, newPrjName)
|
||||||
|
.set(EdFileInfo::getUpdatedBy, UserThreadLocal.getUserId())
|
||||||
|
.set(EdFileInfo::getUpdateTime, new Date()));
|
||||||
|
fileSystemService.renameFile(commonService.getEleDataPath(), oldPrjName, newPrjName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String info = StrFormatter.format("修改工程名异常--->{},{}", newPrjName, e.getMessage());
|
String info = StrFormatter.format("修改工程名异常--->{},{}", newPrjName, e.getMessage());
|
||||||
log.error(info, e);
|
log.error(info, e);
|
||||||
|
|
@ -165,7 +163,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除一个项目,做逻辑删除
|
* 删除一个项目,做逻辑删除
|
||||||
*
|
|
||||||
* @param prjId
|
* @param prjId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
@ -173,6 +170,16 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ElectromagneticResult<?> delete(String prjId) {
|
public ElectromagneticResult<?> delete(String prjId) {
|
||||||
try {
|
try {
|
||||||
|
Long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code)
|
||||||
|
.likeRight(EdFileInfo::getFilePath, prjId));
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
String info = StrFormatter.format("禁止删除非空项目");
|
||||||
|
log.info(info);
|
||||||
|
ElectromagneticResultUtil.fail("-1", info);
|
||||||
|
}
|
||||||
|
|
||||||
List<String> ids = new ArrayList<>();
|
List<String> ids = new ArrayList<>();
|
||||||
ids.add(prjId);
|
ids.add(prjId);
|
||||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
|
@ -199,72 +206,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ElectromagneticResult<?> addFolder(String parentId, String folderName) {
|
public ElectromagneticResult<?> addFolder(String parentId, String folderName) {
|
||||||
|
return commonService.addFolder(parentId, folderName, true, true);
|
||||||
// 验证名称是否合法
|
|
||||||
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(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)
|
|
||||||
.eq(EdFileInfo::getParentId, parentId));
|
|
||||||
List<String> names = edFileInfos.stream().map(EdFileInfo::getFileName).collect(Collectors.toList());
|
|
||||||
if (names.contains(folderName)) {
|
|
||||||
String info = "该子集名称已存在";
|
|
||||||
log.error(info);
|
|
||||||
return ElectromagneticResultUtil.fail("-1", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
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);
|
|
||||||
this.save(fileInfo);
|
|
||||||
// 保存到文件系统
|
|
||||||
String targetFilePath = eleDataPath + File.separator + getPath(paths) + File.separator + folderName;
|
|
||||||
fileSystemService.createDirectory(targetFilePath);
|
|
||||||
return ElectromagneticResultUtil.success(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String info = "添加子集失败";
|
|
||||||
log.error(info, e);
|
|
||||||
throw new BizException(-1, info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -274,41 +216,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<?> queryAllPrjInfo() {
|
public ElectromagneticResult<?> queryAllPrjInfo() {
|
||||||
|
return commonService.queryAllPrjInfo();
|
||||||
try {
|
|
||||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
||||||
.select(EdFileInfo::getId)
|
|
||||||
.eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
|
|
||||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
|
||||||
List<String> ids = this.baseMapper.selectList(queryWrapper).stream().map(EdFileInfo::getId).collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<ProjectVO> projectVOS = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String id : ids) {
|
|
||||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectAllAdminFolder(id);
|
|
||||||
// 转换为树
|
|
||||||
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, PRJ_PARENT_ID, 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);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String info = "查询项目失败";
|
|
||||||
log.error(info, e);
|
|
||||||
throw new BizException(-1, info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -367,43 +275,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ElectromagneticResult<?> deleteFolder(String fileId, String parentId) {
|
public ElectromagneticResult<?> deleteFolder(String fileId, String parentId) {
|
||||||
|
return commonService.deleteFolder(fileId, parentId, true);
|
||||||
try {
|
|
||||||
// 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);
|
|
||||||
// 同层级的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));
|
|
||||||
Date now = new Date();
|
|
||||||
String currentUserId = UserThreadLocal.getUserId();
|
|
||||||
for (int i = 0; i < edFileInfos1.size(); i++) {
|
|
||||||
String id = edFileInfos1.get(i).getId();
|
|
||||||
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
|
||||||
.set(EdFileInfo::getSort, i + 1)
|
|
||||||
.set(EdFileInfo::getUpdatedBy, currentUserId)
|
|
||||||
.set(EdFileInfo::getUpdateTime, now)
|
|
||||||
.eq(EdFileInfo::getId, id));
|
|
||||||
}
|
|
||||||
return ElectromagneticResultUtil.success(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
String info = "删除子集异常";
|
|
||||||
log.error(info, e);
|
|
||||||
throw new BizException(-1, info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -420,8 +292,8 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
String currentUserId = UserThreadLocal.getUserId();
|
String currentUserId = UserThreadLocal.getUserId();
|
||||||
// 把source工程的层级结构copy到目标工程
|
// 把source工程的层级结构copy到目标工程
|
||||||
// 查找source的全部目录
|
// 查找source的全部目录
|
||||||
List<EdFileInfo> sourceEdFileInfos = this.baseMapper.selectAllAdminFolder(sourceId);
|
List<EdFileInfo> sourceEdFileInfos = commonService.selectAllAdminFolder(sourceId);
|
||||||
List<EdFileInfo> targetEdFileInfos = this.baseMapper.selectAllAdminFolder(targetId);
|
List<EdFileInfo> targetEdFileInfos = commonService.selectAllAdminFolder(targetId);
|
||||||
// 确定层级最大为prjFolderMaxLength层,现在逐层来处理。
|
// 确定层级最大为prjFolderMaxLength层,现在逐层来处理。
|
||||||
for (int i = 1; i <= prjFolderMaxLength; ++i) {
|
for (int i = 1; i <= prjFolderMaxLength; ++i) {
|
||||||
// 先查找source第i层下有那些子集
|
// 先查找source第i层下有那些子集
|
||||||
|
|
@ -448,7 +320,8 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
targetFile.setId(newFolderId)
|
targetFile.setId(newFolderId)
|
||||||
.setFileId(newFolderId)
|
.setFileId(newFolderId)
|
||||||
.setFileName(sourceFile.getFileName())
|
.setFileName(sourceFile.getFileName())
|
||||||
.setFileVersion(100)
|
.setFileVersion(FILE_START_VERSION)
|
||||||
|
.setPrjDir(true)
|
||||||
.setParentId(targetParentFile.getParentId())
|
.setParentId(targetParentFile.getParentId())
|
||||||
.setFileTime(EleCommonUtil.getNowTimeStr())
|
.setFileTime(EleCommonUtil.getNowTimeStr())
|
||||||
.setDataType(EleDataTypeEnum.FOLDER.code)
|
.setDataType(EleDataTypeEnum.FOLDER.code)
|
||||||
|
|
@ -462,9 +335,9 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
.setCreatedBy(currentUserId)
|
.setCreatedBy(currentUserId)
|
||||||
.setUpdatedBy(currentUserId);
|
.setUpdatedBy(currentUserId);
|
||||||
this.save(targetFile);
|
this.save(targetFile);
|
||||||
String targetSysFilePath = getFileSysPath(targetFile.getFilePath()) + File.separator + sourceFileName;
|
String targetSysFilePath = commonService.getFileSysPath(targetFile.getFilePath()) + File.separator + sourceFileName;
|
||||||
fileSystemService.createDirectory(targetSysFilePath);
|
fileSystemService.createDirectory(targetSysFilePath);
|
||||||
targetEdFileInfos = this.baseMapper.selectAllAdminFolder(targetId);
|
targetEdFileInfos = commonService.selectAllAdminFolder(targetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -478,20 +351,25 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改子集名称
|
* 修改子集名称
|
||||||
*
|
|
||||||
* @param id
|
* @param id
|
||||||
* @param newFolderName
|
* @param newFolderName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ElectromagneticResult<?> modifyFolder(String id, String newFolderName) {
|
public ElectromagneticResult<?> modifyFolder(String id, String newFolderName, String parentId) {
|
||||||
try {
|
try {
|
||||||
|
// 首先检查同层是否有同名目录
|
||||||
|
if (commonService.checkSameFolder(parentId, newFolderName)) {
|
||||||
|
String info = "存在同名子集,禁止修改";
|
||||||
|
log.error(info);
|
||||||
|
throw new BizException(-1, info);
|
||||||
|
}
|
||||||
String currentUserId = UserThreadLocal.getUserId();
|
String currentUserId = UserThreadLocal.getUserId();
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.eq(EdFileInfo::getId, id));
|
.eq(EdFileInfo::getId, id));
|
||||||
String sysFilePath = getFileSysPath(fileInfo.getFilePath());
|
String sysFilePath = commonService.getFileSysPath(fileInfo.getFilePath());
|
||||||
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||||
.set(EdFileInfo::getUpdateTime, now)
|
.set(EdFileInfo::getUpdateTime, now)
|
||||||
.set(EdFileInfo::getUpdatedBy, currentUserId)
|
.set(EdFileInfo::getUpdatedBy, currentUserId)
|
||||||
|
|
@ -506,24 +384,4 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFileSysPath(String dbPath) {
|
|
||||||
ArrayList<String> paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT));
|
|
||||||
String path = getPath(paths);
|
|
||||||
return eleDataPath + File.separator + path;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPath(List<String> ids) {
|
|
||||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
||||||
.select(EdFileInfo::getId, EdFileInfo::getFileName)
|
|
||||||
.in(EdFileInfo::getId, ids);
|
|
||||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(queryWrapper);
|
|
||||||
Map<String, String> map = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, EdFileInfo::getFileName));
|
|
||||||
StringBuilder path = new StringBuilder();
|
|
||||||
for (String id : ids) {
|
|
||||||
String tmp = map.get(id) + File.separator;
|
|
||||||
path.append(tmp);
|
|
||||||
}
|
|
||||||
return path.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,4 @@
|
||||||
from ed_file_info
|
from ed_file_info
|
||||||
where length(id) = 6
|
where length(id) = 6
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<select id="selectAllAdminFolder"
|
|
||||||
resultType="com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo">
|
|
||||||
select id, file_name, parent_id, sort, file_path
|
|
||||||
from ed_file_info
|
|
||||||
where length(id) = 6
|
|
||||||
and effect_flag = 1
|
|
||||||
and data_type = 0
|
|
||||||
and file_path like concat(#{prjId}, '%')
|
|
||||||
</select>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
@ -6,4 +6,7 @@ public interface ElectromagneticConstants {
|
||||||
|
|
||||||
String MYSQL_FILE_PATH_SPLIT = "_";
|
String MYSQL_FILE_PATH_SPLIT = "_";
|
||||||
|
|
||||||
|
int FILE_START_VERSION = 100;
|
||||||
|
|
||||||
|
String PRJ_PARENT_ID = "0";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ public enum EffectFlagEnum {
|
||||||
* 无效
|
* 无效
|
||||||
*/
|
*/
|
||||||
NOT_EFFECTIVE(0, "无效");
|
NOT_EFFECTIVE(0, "无效");
|
||||||
public Integer code;
|
|
||||||
public String desc;
|
public final Integer code;
|
||||||
|
public final String desc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ public enum EleDataSaveStatusEnum {
|
||||||
SUCCESS(1, "上传成功"),
|
SUCCESS(1, "上传成功"),
|
||||||
FAIL(2, "上传失败");
|
FAIL(2, "上传失败");
|
||||||
|
|
||||||
public int code;
|
public final int code;
|
||||||
public String des;
|
public final String des;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ public enum EleDataStatusEnum {
|
||||||
PUBLISHED(1, "已发布"),
|
PUBLISHED(1, "已发布"),
|
||||||
OCCUPY(2, "占用");
|
OCCUPY(2, "占用");
|
||||||
|
|
||||||
public int code;
|
public final int code;
|
||||||
public String desc;
|
public final String desc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import lombok.AllArgsConstructor;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum EleDataTypeEnum {
|
public enum EleDataTypeEnum {
|
||||||
|
|
||||||
FOLDER(0, "文件夹"),
|
FOLDER(0, "folder"),
|
||||||
FILE(1, "普通文件");
|
FILE(1, "file");
|
||||||
|
|
||||||
public int code;
|
public final int code;
|
||||||
public String desc;
|
public final String desc;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ public enum PublishEnum {
|
||||||
*/
|
*/
|
||||||
UNPUBLISHED(0, "未发布"),
|
UNPUBLISHED(0, "未发布"),
|
||||||
;
|
;
|
||||||
private Integer code;
|
private final Integer code;
|
||||||
private String desc;
|
private final String desc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue