package com.qianwen.smartman.modules.dnc.service.impl; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.base.BaseServiceImpl; import com.qianwen.core.mp.support.Condition; import com.qianwen.core.mp.support.Query; import com.qianwen.core.oss.model.OssFile; import com.qianwen.core.secure.BladeUser; import com.qianwen.core.secure.utils.AuthUtil; import com.qianwen.core.tool.node.ForestNodeMerger; import com.qianwen.core.tool.utils.FileUtil; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.common.cache.ParamCache; import com.qianwen.smartman.common.cache.UserCache; import com.qianwen.smartman.common.constant.CommonConstant; import com.qianwen.smartman.common.constant.DncConstant; import com.qianwen.smartman.common.utils.Lambda; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.smartman.modules.cps.service.IWorkstationService; import com.qianwen.smartman.modules.cps.vo.WorkstationVO; import com.qianwen.smartman.modules.dnc.convert.FileConvert; import com.qianwen.smartman.modules.dnc.dto.DncOperationLogDto; import com.qianwen.smartman.modules.dnc.dto.PathDto; import com.qianwen.smartman.modules.dnc.entity.File; import com.qianwen.smartman.modules.dnc.entity.TransferDirectoryFile; import com.qianwen.smartman.modules.dnc.enums.DncEnums; import com.qianwen.smartman.modules.dnc.enums.FileType; import com.qianwen.smartman.modules.dnc.mapper.FileMapper; import com.qianwen.smartman.modules.dnc.service.IDncOperationLogService; import com.qianwen.smartman.modules.dnc.service.IFileService; import com.qianwen.smartman.modules.dnc.service.IObsFileService; import com.qianwen.smartman.modules.dnc.service.ITransferDirectoryFileService; import com.qianwen.smartman.modules.dnc.util.FileUtils; import com.qianwen.smartman.modules.dnc.vo.ChangeFileParentVO; import com.qianwen.smartman.modules.dnc.vo.CreateFileVO; import com.qianwen.smartman.modules.dnc.vo.DeleteFileVO; import com.qianwen.smartman.modules.dnc.vo.FileHistoryVO; import com.qianwen.smartman.modules.dnc.vo.FileSourcePathVO; import com.qianwen.smartman.modules.dnc.vo.FileVO; import com.qianwen.smartman.modules.dnc.vo.FolderListVO; import com.qianwen.smartman.modules.dnc.vo.FolderTreeVO; import com.qianwen.smartman.modules.dnc.vo.FolderVO; import com.qianwen.smartman.modules.dnc.vo.NewFolderVO; import com.qianwen.smartman.modules.dnc.vo.RenameVO; import com.qianwen.smartman.modules.dnc.vo.UpdateFileVO; import com.qianwen.smartman.modules.dnc.vo.UploadFileOssVO; import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder; import com.qianwen.smartman.modules.system.entity.User; import lombok.NonNull; @Service /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/dnc/service/impl/FileServiceImpl.class */ public class FileServiceImpl extends BaseServiceImpl implements IFileService { @Autowired private FileMapper fileMapper; @Autowired private IDncOperationLogService dncOperationLogService; @Autowired @Lazy private ITransferDirectoryFileService transferDirectoryFileService; @Autowired private IWorkstationService workstationService; @Autowired private OssBuilder ossBuilder; @Autowired private IObsFileService obsFileService; @Override // org.springblade.modules.dnc.service.IFileService @Transactional(rollbackFor = {Exception.class}) public List batchSave(BladeUser user, List list, Integer operationType, Integer sourceType) { return (List) list.stream().peek(createFileDto -> { String hash; OssFile fileDto = createFileDto.getOssFile(); if (Func.isNotBlank(fileDto.getName())) { OssFile ossFile = this.ossBuilder.template().statFile(fileDto.getName()); fileDto.setContentType(ossFile.getContentType()); hash = ossFile.getHash(); fileDto.setHash(hash); fileDto.setLength(ossFile.getLength()); } else { fileDto.setContentType(fileDto.getContentType()); hash = fileDto.getHash(); fileDto.setHash(hash); fileDto.setLength(fileDto.getLength()); } Long userId = user.getUserId(); File file = File.builder().fileType(Integer.valueOf(FileType.FILE.getValue())).owner(userId).objectKey(fileDto.getName()).contentMd5(fileDto.getHash()).displayName(createFileDto.getName()).contentType(fileDto.getContentType()).contentLength(Long.valueOf(fileDto.getLength())).suffix(FileUtil.getFileExtension(createFileDto.getName())).isCurrent(true).link(createFileDto.getOssFile().getLink()).build(); File latestFile = getOne(Lambda.create().eq(File::getParentId, createFileDto.getTargetId()) .eq(File::getOwner, userId).eq(File::getFileType, Integer.valueOf(FileType.FILE.getValue())) .eq(File::getDisplayName, createFileDto.getName()).limit(Integer.valueOf(1)).orderByDesc(File::getVersion)); /* File latestFile = (File) getOne((Wrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) Lambda.create().eq((v0) -> { return v0.getParentId(); }, createFileDto.getTargetId())).eq((v0) -> { return v0.getOwner(); }, userId)).eq((v0) -> { return v0.getFileType(); }, Integer.valueOf(FileType.FILE.getValue()))).eq((v0) -> { return v0.getDisplayName(); }, createFileDto.getName())).limit(1).orderByDesc((v0) -> { return v0.getVersion(); }));*/ if (Func.isEmpty(latestFile)) { file.setVersion(DncConstant.DEFAULT_VERSION); createFile(sourceType, createFileDto, file, userId, operationType); } else if (!hash.equals(latestFile.getContentMd5())) { file.setVersion(Integer.valueOf(latestFile.getVersion().intValue() + 1)); createFile(sourceType, createFileDto, file, userId, operationType); } }).collect(Collectors.toList()); } private void createFile(Integer sourceType, UploadFileOssVO createFileDto, File file, Long userId, Integer operationType) { String sourcePathId = null; String sourcePathName = null; if (DncEnums.LogFileSourceType.STATION_FILE.getCode().equals(sourceType) || DncEnums.LogFileSourceType.PROCESSING_PROGRAM.getCode().equals(sourceType)) { TransferDirectoryFile transferDirectoryFile = (TransferDirectoryFile) this.transferDirectoryFileService.getById(createFileDto.getSourceId()); if (Func.isNotEmpty(transferDirectoryFile)) { Long workstationId = transferDirectoryFile.getWorkstationId(); WorkstationVO workstationVO = this.workstationService.getDetail(workstationId); sourcePathId = workstationVO.getGroupId() + "/" + workstationId + "/" + file.getId(); sourcePathName = workstationVO.getGroupName() + "/" + workstationVO.getName() + "/" + file.getDisplayName(); } } Long id = saveFile(userId, createFileDto.getTargetId(), file, operationType, sourceType, sourcePathId, sourcePathName); createFileDto.setId(id); } @Override public List lazyFolderList(Long userId, String id) { List folderList = findFolderList(userId, id); return folderList.stream().map(f -> { FolderVO vo = FileConvert.INSTANCE.convertToFolderVO(f); ((FolderVO) Objects.requireNonNull(vo)).setName(f.getDisplayName()); return vo; }).collect(Collectors.toList()); } @Override // org.springblade.modules.dnc.service.IFileService public List folderTreeList(final Long userId) { List list = list(Lambda.eq(File::getOwner, userId).eq(File::getFileType, Integer.valueOf(FileType.FOLDER.getValue()))); return ForestNodeMerger.merge(list.stream().map(FileConvert.INSTANCE::convertToFolderTreeVO) .peek(vo -> vo.setGroup((vo.getParentId().longValue() == 0L || vo.getId().longValue() == 0L))) .collect(Collectors.toList())); /* List list = list((Wrapper) Lambda.eq((v0) -> { return v0.getOwner(); }, userId).eq((v0) -> { return v0.getFileType(); }, Integer.valueOf(FileType.FOLDER.getValue()))); Stream stream = list.stream(); FileConvert fileConvert = FileConvert.INSTANCE; fileConvert.getClass(); return ForestNodeMerger.merge((List) stream.map(this::convertToFolderTreeVO).peek(vo -> { vo.setGroup(vo.getParentId().longValue() == 0 || vo.getId().longValue() == 0); }).collect(Collectors.toList()));*/ } @Override // org.springblade.modules.dnc.service.IFileService public List findFolderList(Long userId, String id) { LambdaQueryWrapper query = Wrappers.query().lambda().eq(File::getOwner, userId).eq(File::getParentId, id).eq(File::getFileType, Integer.valueOf(FileType.FOLDER.getValue())); return this.baseMapper.selectList(query); } @Override // org.springblade.modules.dnc.service.IFileService @Transactional(rollbackFor = {Exception.class}) public Long createFolder(BladeUser user, NewFolderVO vo) { vo.setFileType(FileType.FOLDER); checkDisplayName(vo.getParent(), vo.getName(), user.getUserId(), Integer.valueOf(vo.getFileType().getValue())); File folder = File.newFolder(user.getUserId(), vo.getParent(), vo.getName()); folder.setVersion(DncConstant.DEFAULT_VERSION); save(folder); updateAllPath(folder, vo.getParent()); saveOperationLog(AuthUtil.getUser(), folder, DncEnums.LogOperationType.UPLOAD.getCode(), DncEnums.LogFileSourceType.MY_DOCUMENTS.getCode(), null, null); Optional fileOptional = Optional.of(folder); return (Long) fileOptional.map((v0) -> { return v0.getId(); }).orElse(null); } @Override // org.springblade.modules.dnc.service.IFileService public FolderListVO list(Long userId, Long parent, String searchKey) { String parentName = getParentName(parent); Collection fileList = findFiles(userId, parent, searchKey); Collection folderDtoList = (Collection) fileList.stream().filter(f -> { return f.getFileType().intValue() == FileType.FOLDER.getValue(); }).map(f2 -> { FolderVO dto = FileConvert.INSTANCE.convertToFolderVO(f2); ((FolderVO) Objects.requireNonNull(dto)).setName(f2.getDisplayName()); dto.setUpdateTime((Date) Optional.ofNullable(f2.getUpdateTime()).orElse(f2.getCreateTime())); User creatUser = UserCache.getUser(Long.valueOf(dto.getCreateUser())); dto.setCreateUserName(Func.isNotEmpty(creatUser) ? creatUser.getAccount() : ""); User updateUser = UserCache.getUser(Long.valueOf(dto.getUpdateUser())); dto.setCreateUserName(Func.isNotEmpty(updateUser) ? updateUser.getAccount() : ""); return dto; }).collect(Collectors.toList()); Collection fileVOList = (Collection) fileList.stream().filter(f3 -> { return f3.getFileType().intValue() == FileType.FILE.getValue(); }).map(f4 -> { FileVO dto = FileConvert.INSTANCE.convert(f4); String allPathName = parentName + "/" + f4.getDisplayName(); ((FileVO) Objects.requireNonNull(dto)).setAllPathName(allPathName); dto.setName(f4.getDisplayName()); dto.setUpdateTime((Date) Optional.ofNullable(f4.getUpdateTime()).orElse(f4.getCreateTime())); dto.setFileType(f4.getFileType()); User creatUser = UserCache.getUser(Long.valueOf(dto.getCreateUser())); dto.setCreateUserName(Func.isNotEmpty(creatUser) ? creatUser.getAccount() : ""); User updateUser = UserCache.getUser(Long.valueOf(dto.getCreateUser())); dto.setUpdateUserName(Func.isNotEmpty(updateUser) ? updateUser.getAccount() : ""); dto.setVersionDesc(dto.getVersion() != null ? dto.getVersion() + CommonConstant.FILE_SUFFIX : ""); return dto; }).collect(Collectors.toList()); return new FolderListVO(folderDtoList, fileVOList); } public String getParentName(Long parentId) { String[] split = (String[]) Optional.ofNullable(getById(parentId)).map(file -> { return ((String) Optional.ofNullable(file.getAllPath()).orElse("")).split("/"); }).orElse(new String[]{"0"}); List fileIs = Arrays.asList(split); String pathName = this.fileMapper.getPathName(fileIs); return Func.isEmpty(pathName) ? "" : pathName; } public Collection findFiles(Long userId, Long parentId, String searchKey) { LambdaQueryWrapper query = Wrappers.query().lambda().eq(File::getOwner, userId).eq(File::getIsCurrent, Boolean.valueOf(true)) .likeRight(StringUtils.isNoneBlank(searchKey), File::getDisplayName, searchKey) .orderByAsc(File::getFileType).orderByDesc(File::getUpdateTime); if (parentId != null) { query = (LambdaQueryWrapper)query.eq(File::getParentId, parentId); } else { query = (LambdaQueryWrapper)query.isNull(File::getParentId); } return this.baseMapper.selectList(query); } private void checkDisplayName(Long parentId, String name, Long userId, Integer fileType) { if (FileUtils.hasSpecial(name)) { throw new ServiceException(MessageUtils.message("dnc.filename.cannot.contains", new Object[0])); } if (FileType.FOLDER.getValue() == fileType.intValue()) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(File::getDisplayName, name) .eq(File::getOwner, userId) .eq(File::getParentId, parentId); /* QueryWrapper queryWrapper = new QueryWrapper<>(); ((LambdaQueryWrapper) ((LambdaQueryWrapper) queryWrapper.lambda().eq((v0) -> { return v0.getDisplayName(); }, name)).eq((v0) -> { return v0.getOwner(); }, userId)).eq((v0) -> { return v0.getParentId(); }, parentId);*/ List files = list(queryWrapper); if (Func.isNotEmpty(files)) { throw new ServiceException(MessageUtils.message("dnc.file.name.exist", new Object[0])); } } } @Override // org.springblade.modules.dnc.service.IFileService public void updateAllPath(File file, Long parentId) { Optional parentFile = (parentId == null || parentId.longValue() == -1) ? Optional.empty() : Optional.of(getById(parentId)); String parentPath = (String) parentFile.map((v0) -> { return v0.getAllPath(); }).orElse(null); file.setIsDeleted(0); file.joinPath(parentPath); updateById(file); } @Override // org.springblade.modules.dnc.service.IFileService public Long createFile(Long userId, CreateFileVO createFileVO) { OssFile ossFile = createFileVO.getOssFile(); File file = File.builder().fileType(Integer.valueOf(FileType.FILE.getValue())).owner(userId).objectKey(ossFile.getName()).parentId(createFileVO.getTargetId()).contentMd5(ossFile.getHash()).displayName(createFileVO.getOriginalName()).contentType(ossFile.getContentType()).contentLength(Long.valueOf(ossFile.getLength())).suffix(DncConstant.SUFFIX).isCurrent(true).link(createFileVO.getOssFile().getLink()).build(); return saveFile(userId, createFileVO.getTargetId(), file, DncEnums.LogOperationType.UPLOAD.getCode(), DncEnums.FileSource.MY_DOCUMENTS.getCode(), null, null); } @Override // org.springblade.modules.dnc.service.IFileService public Long saveFile(Long userId, Long parentId, File file, Integer operationType, Integer sourceType, String sourcePathId, String sourcePathName) { file.setParentId(parentId); file.changeParent(parentId); checkDisplayName(parentId, file.getDisplayName(), userId, file.getFileType()); save(file); updateAllPath(file, parentId); changeCurrent(parentId, file); saveOperationLog(AuthUtil.getUser(), file, operationType, sourceType, sourcePathId, sourcePathName); return file.getId(); } private void saveOperationLog(BladeUser user, File file, Integer operationType, Integer sourceType, String sourcePathId, String sourcePathName) { DncOperationLogDto dncOperationLogDto = FileConvert.INSTANCE.convertToDncOperationLogDto(file); dncOperationLogDto.setFileId(file.getId()).setFileName(file.getDisplayName()).setOperationTime(new Date()).setOperatorName(user.getAccount()).setOperatorId(user.getUserId()).setOperationResponse(DncConstant.OPERATE_SUCCEED).setOperationType(operationType).setSourcePathId(sourcePathId).setSourcePathName(sourcePathName).setSourceType(sourceType).setTargetType(DncEnums.LogFileSourceType.MY_DOCUMENTS.getCode()).setFileType(file.getFileType()).setVersion(file.getVersion()); if (!DncEnums.LogOperationType.DELETE.getCode().equals(operationType)) { dncOperationLogDto.setTargetPathId(file.getAllPath()).setTargetPathName(getParentName(file.getParentId()).concat("/").concat(file.getDisplayName())); } this.dncOperationLogService.insertLog(dncOperationLogDto); } private void changeCurrent(Long parentId, File file) { List list = list(Wrappers.lambdaQuery().ne(File::getId, file.getId()) .eq(File::getDisplayName, file.getDisplayName()) .eq(File::getParentId, parentId) .eq(File::getIsCurrent, Boolean.valueOf(true)) .eq(File::getFileType, Integer.valueOf(FileType.FILE.getValue()))); /* List list = list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().ne((v0) -> { return v0.getId(); }, file.getId())).eq((v0) -> { return v0.getDisplayName(); }, file.getDisplayName())).eq((v0) -> { return v0.getParentId(); }, parentId)).eq((v0) -> { return v0.getIsCurrent(); }, true)).eq((v0) -> { return v0.getFileType(); }, Integer.valueOf(FileType.FILE.getValue())));*/ list.forEach(f -> { f.setIsCurrent(false); f.setCoverTime(new Date()); updateById(f); }); } @Override // org.springblade.modules.dnc.service.IFileService @Transactional(rollbackFor = {Exception.class}) public void updateFile(UpdateFileVO updateFileVO) { File file = (File) getById(updateFileVO.getFileId()); OssFile ossFile = updateFileVO.getOssFile(); File newFile = File.builder().objectKey(ossFile.getName()).contentMd5(ossFile.getHash()).contentLength(Long.valueOf(ossFile.getLength())).parentId(file.getParentId()).build(); newFile.setId(file.getId()); updateById(newFile); saveOperationLog(AuthUtil.getUser(), file, DncEnums.LogOperationType.TO_UPDATE.getCode(), DncEnums.FileSource.MY_DOCUMENTS.getCode(), null, null); } @Override // org.springblade.modules.dnc.service.IFileService @Transactional(rollbackFor = {Exception.class}) public void delete(DeleteFileVO deleteFileVO) { deleteFileVO.getSourceIdList().forEach(id -> { File file = (File) this.baseMapper.selectById(id); PathDto pathDto = getPathDto(file); LambdaQueryWrapper deleteWrapper = Wrappers.query().lambda().like(Func.isNotBlank(file.getAllPath()), File::getAllPath, file.getAllPath() + "%"); this.baseMapper.delete(deleteWrapper); /* this.baseMapper.delete((LambdaQueryWrapper) Wrappers.query().lambda().like(Func.isNotBlank(file.getAllPath()), (v0) -> { return v0.getAllPath(); }, file.getAllPath() + "%"));*/ saveOperationLog(AuthUtil.getUser(), file, DncEnums.LogOperationType.DELETE.getCode(), DncEnums.LogFileSourceType.MY_DOCUMENTS.getCode(), pathDto.getAllPathId(), pathDto.getAllPathName()); }); } private PathDto getPathDto(File file) { String allPath = file.getAllPath(); String[] split = allPath.split("/"); String allPathName = (String) Arrays.stream(split).map((v1) -> { return getById(v1); }).map((v0) -> { return v0.getDisplayName(); }).reduce((a, b) -> { return a + "/" + b; }).orElse(""); return new PathDto(allPath, allPathName); } @Override // org.springblade.modules.dnc.service.IFileService @Transactional(rollbackFor = {Exception.class}) public void move(ChangeFileParentVO changeFileParentVO) { changeFileParentVO.getSourceIdList().forEach(source -> { Long target = changeFileParentVO.getParentId(); check(source, target); File sourceFile = (File) this.baseMapper.selectById(source); sourceFile.setCreateTime(new Date()); PathDto pathDto = getPathDto(sourceFile); List files = findFile(Lists.newArrayList(changeFileParentVO.getSourceIdList()), target, sourceFile.getDisplayName(), AuthUtil.getUserId(), sourceFile.getFileType()); if (Func.isNotEmpty(files)) { throw new ServiceException(MessageUtils.message("dnc.file.already.exist", new Object[0])); } String sourcePath = sourceFile.getAllPath(); Optional parentFile = (target == null || target.equals(0L)) ? Optional.empty() : Optional.of(getById(target)); List targetPath = parentFile.map((v0) -> { return v0.pathList(); }).orElse(new ArrayList<>()); sourceFile.changeParent(target); sourceFile.joinPath(targetPath, source.toString()); LambdaQueryWrapper wrapper = Wrappers.query().lambda().like(File::getAllPath, sourcePath + "%") .eq(File::getIsCurrent, DncConstant.IS_CURRENT).ne(File::getId, source); List subFileList = list(wrapper); /* List subFileList = list((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().like((v0) -> { return v0.getAllPath(); }, sourcePath + "%")).eq((v0) -> { return v0.getIsCurrent(); }, DncConstant.IS_CURRENT)).ne((v0) -> { return v0.getId(); }, source));*/ updateById(sourceFile); saveOperationLog(AuthUtil.getUser(), sourceFile, DncEnums.LogOperationType.MOVE.getCode(), DncEnums.LogFileSourceType.MY_DOCUMENTS.getCode(), pathDto.getAllPathId(), pathDto.getAllPathName()); if (!subFileList.isEmpty()) { for (File file : subFileList) { file.setCreateTime(new Date()); PathDto childrenPathDto = getPathDto(file); file.joinPath(parentFile.map((v0) -> { return v0.pathList(); }).orElse(new ArrayList<>()), source.toString()); updateById(file); saveOperationLog(AuthUtil.getUser(), file, DncEnums.LogOperationType.MOVE.getCode(), DncEnums.LogFileSourceType.MY_DOCUMENTS.getCode(), childrenPathDto.getAllPathId(), childrenPathDto.getAllPathName()); } } }); } private List findFile(List fileId, Long parentId, String newName, Long userId, Integer fileType) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda() .eq((fileType.intValue() == FileType.FOLDER.getValue()), File::getDisplayName, newName) .eq((fileType.intValue() == FileType.FILE.getValue()), File::getDisplayName, newName) .eq(File::getParentId, parentId) .eq(File::getFileType, fileType) .eq(File::getOwner, userId) .eq(File::getIsCurrent, DncConstant.IS_CURRENT); /* Wrapper queryWrapper = new QueryWrapper(); ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) queryWrapper.lambda().eq(fileType.intValue() == FileType.FOLDER.getValue(), (v0) -> { return v0.getDisplayName(); }, newName).eq(fileType.intValue() == FileType.FILE.getValue(), (v0) -> { return v0.getDisplayName(); }, newName).eq((v0) -> { return v0.getParentId(); }, parentId)).eq((v0) -> { return v0.getFileType(); }, fileType)).eq((v0) -> { return v0.getOwner(); }, userId)).eq((v0) -> { return v0.getIsCurrent(); }, DncConstant.IS_CURRENT);*/ return this.baseMapper.selectList(queryWrapper); } private List renameFindFile(Long fileId, Long parentId, String newName, Integer fileType) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda() .eq((fileType.intValue() == FileType.FOLDER.getValue()), File::getDisplayName, newName) .eq((fileType.intValue() == FileType.FILE.getValue()), File::getDisplayName, newName) .eq(File::getParentId, parentId) .eq(File::getFileType, fileType) .eq(File::getOwner, AuthUtil.getUserId()) .eq(File::getIsCurrent, Boolean.valueOf(true)) .ne(File::getId, fileId); /* ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) queryWrapper.lambda().eq(fileType.intValue() == FileType.FOLDER.getValue(), (v0) -> { return v0.getDisplayName(); }, newName).eq(fileType.intValue() == FileType.FILE.getValue(), (v0) -> { return v0.getDisplayName(); }, newName).eq((v0) -> { return v0.getParentId(); }, parentId)).eq((v0) -> { return v0.getFileType(); }, fileType)).eq((v0) -> { return v0.getOwner(); }, AuthUtil.getUserId())).eq((v0) -> { return v0.getIsCurrent(); }, true)).ne((v0) -> { return v0.getId(); }, fileId);*/ return this.baseMapper.selectList(queryWrapper); } private void check(@NonNull Long source, Long target) { if (source == null) { throw new NullPointerException("source is marked non-null but is null"); } if (target == null || target.equals(0L)) { return; } File sourceFile = (File) this.baseMapper.selectById(source); File targetFile = (File) this.baseMapper.selectById(target); String targetPath = targetFile.getAllPath(); String sourcePath = sourceFile.getAllPath(); if (targetPath.startsWith(sourcePath)) { throw new ServiceException(MessageUtils.message("dnc.file.not.self", new Object[0])); } } @Override // org.springblade.modules.dnc.service.IFileService @Transactional(rollbackFor = {Exception.class}) public void copy(ChangeFileParentVO changeFileParentVO) { changeFileParentVO.getSourceIdList().forEach(source -> { Long target = changeFileParentVO.getParentId(); check(source, target); File sourceFile = (File) getById(source); Optional parentFile = (target == null || target.equals(0L)) ? Optional.empty() : Optional.of(getById(target)); String targetPath = (String) parentFile.map((v0) -> { return v0.getAllPath(); }).orElse(null); LambdaQueryWrapper wrapper = Wrappers.query().lambda().eq(File::getIsCurrent, DncConstant.IS_CURRENT) .like(File::getAllPath, sourceFile.getAllPath() + "%"); List subFileList = list(wrapper); /* List subFileList = list((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getIsCurrent(); }, DncConstant.IS_CURRENT)).like((v0) -> { return v0.getAllPath(); }, sourceFile.getAllPath() + "%"));*/ subFileList.forEach(file -> { file.setMark(Long.valueOf(IdWorker.getId())); }); Map keyToPath = subFileList.stream().collect(Collectors.toMap((v0) -> { return v0.getMark(); }, this::getPathDto)); List ids = subFileList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); List files = findFile(ids, target, sourceFile.getDisplayName(), AuthUtil.getUserId(), sourceFile.getFileType()); if (Func.isNotEmpty(files)) { throw new ServiceException(MessageUtils.message("dnc.file.already.exist", new Object[0])); } List newFileList = subFileList.stream().map((v0) -> { return v0.copy(); }).map(c -> { c.joinPath(new ArrayList<>(), source.toString()); return c; }).collect(Collectors.toList()); saveBatch(newFileList); Map idMap = newFileList.stream().collect(Collectors.toMap((v0) -> { return v0.lastPathId(); }, c2 -> { return c2.getId().toString(); })); for (File item : newFileList) { item.changeParent(idMap, target); item.changeChildPath(idMap); item.joinPath(targetPath); } saveOrUpdateBatch(newFileList); for (File file2 : newFileList) { PathDto pathDto = keyToPath.get(file2.getMark()); saveOperationLog(AuthUtil.getUser(), file2, DncEnums.LogOperationType.COPY.getCode(), DncEnums.LogFileSourceType.MY_DOCUMENTS.getCode(), pathDto.getAllPathId(), pathDto.getAllPathName()); } }); } @Override // org.springblade.modules.dnc.service.IFileService @Transactional(rollbackFor = {Exception.class}) public void rename(Long id, RenameVO renameVO) { String newName = renameVO.getNewName(); List files = renameFindFile(id, renameVO.getParentId(), newName, renameVO.getFileType()); if (Func.isNotEmpty(files)) { throw new ServiceException(MessageUtils.message("dnc.file.name.exist", new Object[0])); } File file = (File) this.baseMapper.selectById(id); PathDto pathDto = getPathDto(file); file.rename(newName); updateById(file); saveOperationLog(AuthUtil.getUser(), file, DncEnums.LogOperationType.TO_UPDATE.getCode(), DncEnums.LogFileSourceType.MY_DOCUMENTS.getCode(), pathDto.getAllPathId(), pathDto.getAllPathName()); } @Override // org.springblade.modules.dnc.service.IFileService public List duplicateName(List uploadFileOssVOList) { List collect = new ArrayList<>(); uploadFileOssVOList.forEach(file -> { File one = getOne(Wrappers.lambdaQuery().eq(File::getFileType, Integer.valueOf(FileType.FILE.getValue())) .eq(File::getIsCurrent, Boolean.valueOf(true)) .eq(File::getDisplayName, file.getName()) .eq(File::getOwner, AuthUtil.getUser().getUserId()) .eq(File::getParentId, file.getTargetId())); /* File one = (File) getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getFileType(); }, Integer.valueOf(FileType.FILE.getValue()))).eq((v0) -> { return v0.getIsCurrent(); }, true)).eq((v0) -> { return v0.getDisplayName(); }, file.getName())).eq((v0) -> { return v0.getOwner(); }, AuthUtil.getUser().getUserId())).eq((v0) -> { return v0.getParentId(); }, file.getTargetId()));*/ if (one != null) { String objectKey = file.getOssFile().getName(); String contentMd5 = one.getContentMd5(); if (Func.isNotBlank(objectKey)) { boolean result = this.obsFileService.verifyFileContent(objectKey, contentMd5); if (result) { collect.add(file.getName()); } } else if (!one.getContentMd5().equals(file.getOssFile().getHash())) { collect.add(file.getName()); } } }); return collect; } @Override // org.springblade.modules.dnc.service.IFileService public List history(Long pid, String name) { List fileList = list(Wrappers.lambdaQuery().eq(File::getParentId, pid) .eq(File::getDisplayName, name).eq(File::getOwner, AuthUtil.getUser().getUserId()).orderByDesc(File::getIsCurrent).orderByDesc(File::getVersion)); /* List fileList = list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getParentId(); }, pid)).eq((v0) -> { return v0.getDisplayName(); }, name)).eq((v0) -> { return v0.getOwner(); }, AuthUtil.getUser().getUserId())).orderByDesc((v0) -> { return v0.getIsCurrent(); })).orderByDesc((v0) -> { return v0.getVersion(); }));*/ List fileHistoryVOList = FileConvert.INSTANCE.convertHistory(fileList); fileHistoryVOList.forEach(fileHistoryVO -> { User createUser = UserCache.getUser(Long.valueOf(fileHistoryVO.getCreateUser())); if (Func.isNotEmpty(createUser)) { fileHistoryVO.setCreateUserName(createUser.getAccount()); } else { fileHistoryVO.setCreateUserName(""); } User updateUser = UserCache.getUser(Long.valueOf(fileHistoryVO.getUpdateUser())); if (Func.isNotEmpty(updateUser)) { fileHistoryVO.setUpdateUserName(updateUser.getAccount()); } else { fileHistoryVO.setUpdateUserName(""); } fileHistoryVO.setVersionDesc(Func.isNotEmpty(fileHistoryVO.getVersion()) ? fileHistoryVO.getVersion() + CommonConstant.FILE_SUFFIX : ""); }); return fileHistoryVOList; } @Override // org.springblade.modules.dnc.service.IFileService @Transactional(rollbackFor = {Exception.class}) public Boolean changeVersion(Long oldId, Long newId) { File oldFile = (File) getById(oldId); oldFile.setIsCurrent(false); updateById(oldFile); File newFile = (File) getById(newId); newFile.setIsCurrent(true); updateById(newFile); return true; } @Override // org.springblade.modules.dnc.service.IFileService public IPage page(Long userId, Long parent, Integer fileType, String searchKey, Query query) { // Wrapper wrapper; List suffix = new ArrayList<>(); if (DncEnums.FileType.PROCESSING_PROGRAM.getCode().equals(fileType)) { suffix = getSuffix(); } String parentName = getParentName(parent); LambdaQueryWrapper wrapper = Wrappers.query().lambda().eq(File::getOwner, userId) .eq(File::getIsCurrent, Boolean.valueOf(true)) .in(Func.isNotEmpty(suffix), File::getSuffix, suffix) .likeRight(StringUtils.isNoneBlank(new CharSequence[] { searchKey }), File::getDisplayName, searchKey) .orderByAsc(File::getFileType).orderByDesc(File::getUpdateTime); if (parent != null) { wrapper = (LambdaQueryWrapper)wrapper.eq(File::getParentId, parent); } else { wrapper = (LambdaQueryWrapper)wrapper.isNull(File::getParentId); } /* LambdaQueryWrapper wrapper2 = (LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getOwner(); }, userId)).eq((v0) -> { return v0.getIsCurrent(); }, true)).in(Func.isNotEmpty(suffix), (v0) -> { return v0.getSuffix(); }, suffix).likeRight(StringUtils.isNoneBlank(new CharSequence[]{searchKey}), (v0) -> { return v0.getDisplayName(); }, searchKey).orderByAsc((v0) -> { return v0.getFileType(); })).orderByDesc((v0) -> { return v0.getUpdateTime(); }); if (parent != null) { wrapper = (LambdaQueryWrapper) wrapper2.eq((v0) -> { return v0.getParentId(); }, parent); } else { wrapper = (LambdaQueryWrapper) wrapper2.isNull((v0) -> { return v0.getParentId(); }); }*/ IPage page = page(Condition.getPage(query), wrapper); IPage fileVOIPage = FileConvert.INSTANCE.pageConvert(page); fileVOIPage.getRecords().forEach(f -> { if (FileType.FILE.getValue() == f.getFileType().intValue()) { String allPathName = parentName + "/" + f.getName(); ((FileVO) Objects.requireNonNull(f)).setAllPathName(allPathName); } f.setUpdateTime((Date) Optional.ofNullable(f.getUpdateTime()).orElse(f.getCreateTime())); f.setVersion(Func.isNotBlank(f.getVersion()) ? f.getVersion() + CommonConstant.FILE_SUFFIX : ""); }); List collect = fileVOIPage.getRecords().stream().sorted(Comparator.comparing(FileVO::getFileType).thenComparing(Comparator.comparing(FileVO::getUpdateTime).reversed())).collect(Collectors.toList()); /* List collect1 = fileVOIPage.getRecords().stream().sorted(Comparator.comparing((v0) -> { return v0.getFileType(); }).thenComparing(Comparator.comparing((v0) -> { return v0.getUpdateTime(); }).reversed())).collect(Collectors.toList());*/ fileVOIPage.setRecords(collect); return fileVOIPage; } @Override // org.springblade.modules.dnc.service.IFileService public List getSuffix() { String value = ParamCache.getValue(CommonConstant.FILE_SUFFIX_KEY); List suffixList = new ArrayList<>(); if (Func.isNotBlank(value)) { String value1 = value.replace(DncConstant.POINT, ""); String[] suffix = value1.split(","); for (String s : suffix) { suffixList.add(s.toUpperCase()); suffixList.add(s.toLowerCase()); } return suffixList.stream().distinct().collect(Collectors.toList()); } return suffixList; } /* JADX WARN: Multi-variable type inference failed */ @Override // org.springblade.modules.dnc.service.IFileService public IPage filePage(Long userId, Long parent, Integer fileType, String searchKey, Query query) { List suffix = new ArrayList<>(); boolean result = false; String noSuffix = ""; if (DncEnums.FileType.PROCESSING_PROGRAM.getCode().equals(fileType)) { suffix = getSuffix(); result = true; List collect = suffix.stream().filter(CommonConstant.NOT_SUFFIX::equals).collect(Collectors.toList()); /* List collect = (List) suffix2.stream().filter((v1) -> { return r1.equals(v1); }).collect(Collectors.toList());*/ if (collect.size() > 0) { noSuffix = CommonConstant.NOT_SUFFIX; } suffix = suffix.stream().filter(s -> !CommonConstant.NOT_SUFFIX.equals(s)).collect(Collectors.toList()); /* suffix = suffix2.stream().filter(s -> { return !CommonConstant.NOT_SUFFIX.equals(s); }).collect(Collectors.toList());*/ } String parentName = getParentName(parent); List finalSuffix = suffix; String finalNoSuffix = noSuffix; LambdaQueryWrapper wrapper = Wrappers.query().lambda() .eq(File::getOwner, userId).eq(File::getIsCurrent, Boolean.valueOf(true)) .eq(File::getFileType, Integer.valueOf(FileType.FILE.getValue())) .and(result, i -> i.in(File::getSuffix, finalSuffix).or().eq(Func.isNotBlank(finalNoSuffix), File::getSuffix, "")) .and(Func.isNotBlank(searchKey), s -> s.likeRight(File::getDisplayName, searchKey).or().likeRight(File::getSuffix, searchKey)) .orderByDesc(File::getUpdateTime); /* Wrapper wrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getOwner(); }, userId)).eq((v0) -> { return v0.getIsCurrent(); }, true)).eq((v0) -> { return v0.getFileType(); }, Integer.valueOf(FileType.FILE.getValue()))).and(result, i -> { ((LambdaQueryWrapper) ((LambdaQueryWrapper) i.in((v0) -> { return v0.getSuffix(); }, finalSuffix)).or()).eq(Func.isNotBlank(finalNoSuffix), (v0) -> { return v0.getSuffix(); }, ""); }).and(Func.isNotBlank(searchKey), s2 -> { ((LambdaQueryWrapper) ((LambdaQueryWrapper) s2.likeRight((v0) -> { return v0.getDisplayName(); }, searchKey)).or()).likeRight((v0) -> { return v0.getSuffix(); }, searchKey); }).orderByDesc((v0) -> { return v0.getUpdateTime(); });*/ if (parent != null) { wrapper.eq(File::getParentId, parent); /* wrapper = (LambdaQueryWrapper) wrapper.eq((v0) -> { return v0.getParentId(); }, parent);*/ } IPage page = page(Condition.getPage(query), wrapper); IPage fileVOIPage = FileConvert.INSTANCE.pageConvert(page); fileVOIPage.getRecords().forEach(f -> { if (FileType.FILE.getValue() == f.getFileType().intValue()) { String allPathName = parentName + "/" + f.getName(); ((FileVO) Objects.requireNonNull(f)).setAllPathName(allPathName); } f.setUpdateTime((Date) Optional.ofNullable(f.getUpdateTime()).orElse(f.getCreateTime())); f.setVersion(Func.isNotBlank(f.getVersion()) ? f.getVersion() + CommonConstant.FILE_SUFFIX : ""); }); return fileVOIPage; } @Override // org.springblade.modules.dnc.service.IFileService public FileSourcePathVO getFileSourcePath(String fileId) { FileSourcePathVO fileSourcePathVO = new FileSourcePathVO(); if (Func.isNotBlank(fileId)) { File file = (File) getById(fileId); List ids = new ArrayList<>(); String allPath = ""; if (file != null) { allPath = file.getAllPath(); String[] fileIds = allPath.split("/"); for (String s : fileIds) { ids.add(Long.valueOf(Long.parseLong(s))); } } String fromPath = ""; if (Func.isNotEmpty(ids)) { fromPath = list(Wrappers.lambdaQuery().in(File::getId, ids)).stream().map(File::getDisplayName).collect(Collectors.joining("/")); /* fromPath = (String) list((Wrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getId(); }, ids)).stream().map((v0) -> { return v0.getDisplayName(); }).collect(Collectors.joining("/")); */ } fileSourcePathVO.setAllPathId(allPath); fileSourcePathVO.setAllPathName(fromPath); } return fileSourcePathVO; } @Override // org.springblade.modules.dnc.service.IFileService public Boolean existsFile(DeleteFileVO deleteFileVO) { List fileList = new ArrayList<>(); deleteFileVO.getSourceIdList().forEach(id -> { File directory = (File) getById(id); List list = list(Wrappers.lambdaQuery().likeRight(File::getAllPath, directory.getAllPath()) .eq(File::getFileType, Integer.valueOf(FileType.FILE.getValue())) .eq(File::getIsCurrent, Boolean.TRUE)); /* List list = list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().likeRight((v0) -> { return v0.getAllPath(); }, directory.getAllPath())).eq((v0) -> { return v0.getFileType(); }, Integer.valueOf(FileType.FILE.getValue()))).eq((v0) -> { return v0.getIsCurrent(); }, Boolean.TRUE));*/ if (Func.isNotEmpty(list)) { fileList.addAll(list); } }); return Boolean.valueOf(Func.isNotEmpty(fileList)); } }