This commit is contained in:
s2042968 2025-01-02 17:26:28 +08:00
commit 7151243618
11 changed files with 81 additions and 24 deletions

View File

@ -109,4 +109,9 @@ public class EdFileInfoController {
public ElectromagneticResult<?> uploadRecord(@RequestParam int pageNum, @RequestParam int pageSize) {
return edFileInfoService.uploadRecord(pageNum, pageSize);
}
@RequestMapping(value = "/detail", method = RequestMethod.GET)
public ElectromagneticResult<?> detail(@RequestParam String id) {
return edFileInfoService.detail(id);
}
}

View File

@ -6,7 +6,7 @@ import lombok.Data;
import java.util.Date;
@Data
public class FileInfoDTO {
public class FileInfoVO {
private String id;

View File

@ -10,6 +10,7 @@ public class UploadRecordDTO {
private String id;
private String fileName;
private Integer saveStatus;
private String fileType;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createdTime;

View File

@ -1,6 +1,6 @@
package com.electromagnetic.industry.software.manage.pojo.resp;
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoDTO;
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoVO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -15,5 +15,5 @@ public class FileInfoQueryPageVO {
private long total;
private List<FileInfoDTO> records = new ArrayList<>();
private List<FileInfoVO> records = new ArrayList<>();
}

View File

@ -10,4 +10,5 @@ public class FileVersionViewVO {
private Integer preVersion;
private String fileCode;
private Integer effectFlag;
private String parentId;
}

View File

@ -1,10 +1,12 @@
package com.electromagnetic.industry.software.manage.pojo.resp;
import lombok.Data;
import lombok.experimental.FieldNameConstants;
import java.util.ArrayList;
import java.util.List;
@FieldNameConstants
@Data
public class ProjectVO {
@ -13,6 +15,7 @@ public class ProjectVO {
private String parentId;
private int sort;
private Integer dataStatus;
private String title;
private List<ProjectVO> children = new ArrayList<>();
}

View File

@ -143,4 +143,11 @@ public interface EdFileInfoService {
* @return
*/
ElectromagneticResult<?> uploadRecord(int pageNum, int pageSize);
/**
* 查询文件详情
* @param id
* @return
*/
ElectromagneticResult<?> detail(String id);
}

View File

@ -228,6 +228,8 @@ public class CommonService {
List<EdFileInfo> edFileInfos = selectAllAdminFolder(id);
if (!isAdminQuery) {
edFileInfos = edFileInfos.stream().filter(e -> e.getDataStatus().equals(EleDataStatusEnum.PUBLISHED.code)).collect(Collectors.toList());
} else {
edFileInfos = edFileInfos.stream().filter(e -> !e.getDataStatus().equals(EleDataStatusEnum.DELETED.code)).collect(Collectors.toList());
}
// 转换为树
if (isAdminQuery) {
@ -236,11 +238,12 @@ public class CommonService {
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("id", obj.getId());
treeNode.putExtra(EdFileInfo.Fields.parentId, obj.getParentId());
treeNode.putExtra(EdFileInfo.Fields.sort, obj.getSort());
treeNode.putExtra(EdFileInfo.Fields.fileName, obj.getFileName());
treeNode.putExtra(EdFileInfo.Fields.dataStatus, obj.getDataStatus());
treeNode.putExtra(ProjectVO.Fields.id, obj.getId());
treeNode.putExtra(ProjectVO.Fields.parentId, obj.getParentId());
treeNode.putExtra(ProjectVO.Fields.sort, obj.getSort());
treeNode.putExtra(ProjectVO.Fields.fileName, obj.getFileName());
treeNode.putExtra(ProjectVO.Fields.title, obj.getFileName());
treeNode.putExtra(ProjectVO.Fields.dataStatus, obj.getDataStatus());
}));
String jsonStr = JSONUtil.toJsonStr(trees);
ProjectVO projectVO = JSONUtil.toList(jsonStr, ProjectVO.class).get(0);
@ -272,6 +275,8 @@ public class CommonService {
public ElectromagneticResult<?> deleteFolder(String id) {
// 如果文件夹下存在文件包括文件夹和已经逻辑删除的文件则不允许删除后面管理员选择会有物理删除文件夹和文件的功能此时MySQL和文件系统则会进行物理删除该文件
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
try {
// 这里要分两种情况1是删除层级目录2是删除用户创建的文件夹
EdFileInfo fileInfo = edFileInfoMapper.selectOne(Wrappers.<EdFileInfo>lambdaQuery().eq(EdFileInfo::getId, id));
@ -290,6 +295,8 @@ public class CommonService {
edFileInfoMapper.update(null, Wrappers.<EdFileInfo>lambdaUpdate()
.eq(EdFileInfo::getId, id)
.set(EdFileInfo::getSort, -1)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.set(EdFileInfo::getDataStatus, EleDataStatusEnum.DELETED.code));
// 层级文件夹重排序
List<EdFileInfo> edFileInfos1 = edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
@ -297,9 +304,9 @@ public class CommonService {
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
.ne(EdFileInfo::getDataStatus, EleDataStatusEnum.DELETED.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 tmp = edFileInfos1.get(i).getId();
edFileInfoMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
@ -322,6 +329,8 @@ public class CommonService {
// 逻辑文件夹重排序
edFileInfoMapper.update(null, Wrappers.<EdFileInfo>lambdaUpdate()
.eq(EdFileInfo::getId, id)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
}
}

View File

@ -24,15 +24,15 @@ import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
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.other.FileInfoDTO;
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoVO;
import com.electromagnetic.industry.software.manage.pojo.other.UploadRecordDTO;
import com.electromagnetic.industry.software.manage.pojo.req.*;
import com.electromagnetic.industry.software.manage.pojo.resp.FileInfoQueryPageVO;
import com.electromagnetic.industry.software.manage.pojo.resp.FileVersionViewVO;
import com.electromagnetic.industry.software.manage.pojo.resp.ProjectVO;
import com.electromagnetic.industry.software.manage.pojo.resp.UploadRecordVO;
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
import com.electromagnetic.industry.software.manage.service.FileSystemService;
import com.electromagnetic.industry.software.manage.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
@ -62,11 +62,13 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
@Resource
private CommonService commonService;
private EleLog log = new EleLog(EdFileInfoServiceImpl.class);
@Autowired
private final EleLog log = new EleLog(EdFileInfoServiceImpl.class);
@Resource
private FileSystemService fileSystemService;
@Resource
private Environment environment;
@Resource
private PermissionService permissionService;
private String downloadDataDir = "";
private String uploadDataDir = "";
@ -126,13 +128,13 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.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);
List<FileInfoVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileInfoVO.class);
resetFileSize(records);
return ElectromagneticResultUtil.success(new FileInfoQueryPageVO(total, records));
}
private void resetFileSize(List<FileInfoDTO> records) {
for (FileInfoDTO fileInfoDTO : records) {
private void resetFileSize(List<FileInfoVO> records) {
for (FileInfoVO fileInfoDTO : records) {
if (fileInfoDTO.getFileSize() < 1024) {
fileInfoDTO.setFileSizeShow(fileInfoDTO.getFileSize() + "B");
} else if (fileInfoDTO.getFileSize() < 1024 * 1024) {
@ -179,8 +181,11 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
if (fileInfo.getDataType() == EleDataTypeEnum.FOLDER.code) {
return commonService.deleteFolder(id);
}
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.set(EdFileInfo::getEffectFlag, false)
.eq(EdFileInfo::getId, id));
return ElectromagneticResultUtil.success(true);
@ -196,7 +201,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
public ResponseEntity<InputStreamResource> download(String id, HttpServletResponse response) {
try {
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.<EdFileInfo>lambdaQuery().eq(EdFileInfo::getId, id));
EdFileInfo fileInfo = this.baseMapper.selectById(id);
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath());
Assert.isTrue(FileUtil.exist(fileSysPath), "下载文件不存在。");
FileSystemResource fileSystemResource = new FileSystemResource(fileSysPath);
@ -255,8 +260,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
Assert.isTrue(count == 0, "文件名已存在");
String srcFilePath = commonService.getFileSysPath(fileInfo.getFilePath());
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getId, updateFileInfoDTO.getId())
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.set(EdFileInfo::getFileName, updateFileInfoDTO.getFileName())
.set(EdFileInfo::getFileNote, updateFileInfoDTO.getFileNote()));
String newName = updateFileInfoDTO.getFileName() + "." + fileInfo.getFileType() + "." + fileInfo.getFileCode();
@ -687,7 +696,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
@Override
public ElectromagneticResult<?> versionView(String fileId) {
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
.select(EdFileInfo::getId, EdFileInfo::getFileId, EdFileInfo::getFileVersion, EdFileInfo::getPreVersion, EdFileInfo::getFileCode, EdFileInfo::getEffectFlag, EdFileInfo::getFileName)
.select(EdFileInfo::getParentId, EdFileInfo::getId, EdFileInfo::getFileId, EdFileInfo::getFileVersion, EdFileInfo::getPreVersion, EdFileInfo::getFileCode, EdFileInfo::getEffectFlag, EdFileInfo::getFileName)
.eq(EdFileInfo::getFileId, fileId));
List<FileVersionViewVO> fileVersionViewVOS = BeanUtil.copyToList(edFileInfos, FileVersionViewVO.class);
return ElectromagneticResultUtil.success(fileVersionViewVOS);
@ -848,9 +857,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
@Override
public ElectromagneticResult<?> uploadRecord(int pageNum, int pageSize) {
List<String> prjIds = ListUtil.list(false, "100001", "100002"); //TODO 从权限处获取该用户有哪些工程的权限这里先写静态方便调试
List<String> prjIds = permissionService.getAccessibleTree(); //TODO 从权限处获取该用户有哪些工程的权限这里先写静态方便调试
LambdaQueryWrapper<EdFileInfo> lambdaQuery = Wrappers.lambdaQuery(EdFileInfo.class)
.select(EdFileInfo::getId, EdFileInfo::getFileName, EdFileInfo::getSaveStatus, EdFileInfo::getCreatedTime)
.select(EdFileInfo::getId, EdFileInfo::getFileName, EdFileInfo::getSaveStatus, EdFileInfo::getCreatedTime, EdFileInfo::getFileType)
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code)
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
.likeRight(EdFileInfo::getFilePath, prjIds.get(0));
@ -863,6 +872,19 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
return ElectromagneticResultUtil.success(new UploadRecordVO(total, uploadRecordDTOS));
}
/**
* 查询文件详情
*
* @param id
* @return
*/
@Override
public ElectromagneticResult<?> detail(String id) {
EdFileInfo fileInfo = this.baseMapper.selectById(id);
FileInfoVO fileInfoVO = BeanUtil.copyProperties(fileInfo, FileInfoVO.class);
return ElectromagneticResultUtil.success(fileInfoVO);
}
private ElectromagneticResult<?> handCopyConflict(String targetFolderId, Integer strategy, EdFileInfo srcFileInfo, EdFileInfo destFolderInfo) {
// 禁止同目录下移动和复制
if (srcFileInfo.getParentId().equals(destFolderInfo.getId())) {

View File

@ -227,10 +227,14 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
@Override
@Transactional(rollbackFor = Exception.class)
public ElectromagneticResult<?> folderResort(List<FolderResortDTO> folderResortDTOList) {
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
try {
for (FolderResortDTO folderResortDTO : folderResortDTOList) {
LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getSort, folderResortDTO.getSort())
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.eq(EdFileInfo::getId, folderResortDTO.getId());
this.update(updateWrapper);
}
@ -252,16 +256,21 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
@Transactional(rollbackFor = Exception.class)
public ElectromagneticResult<?> publish(String prjId) {
try {
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
// 将已经处于删除状态设置成逻辑删除
this.update(Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.DELETED.code)
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.likeRight(EdFileInfo::getFilePath, prjId));
// 其余置为发布状态
LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code)
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.NOT_PUBLISHED.code)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.likeRight(EdFileInfo::getFilePath, prjId);
this.update(updateWrapper);
return ElectromagneticResultUtil.success(true);

View File

@ -15,7 +15,7 @@ public enum EffectFlagEnum {
*/
EFFECT(1, "有效"),
/**
* 无效
* 无效PermisionService
*/
NOT_EFFECTIVE(0, "无效");