|
@@ -0,0 +1,166 @@
|
|
|
+package com.wtkj.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.wtkj.dto.UploadFileDTO;
|
|
|
+import com.wtkj.entity.FileAndFolder;
|
|
|
+import com.wtkj.mapper.FileAndFolderMapper;
|
|
|
+import com.wtkj.service.IFileAndFolderService;
|
|
|
+import com.wutong.file.feign.IFileClient;
|
|
|
+import com.wutong.file.vo.FileVO;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+ * @author Blizzard
|
|
|
+ * @create at 2023-09-14 15:05
|
|
|
+ * @describe
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class FileAndFolderServiceImpl extends BaseServiceImpl<FileAndFolderMapper, FileAndFolder> implements IFileAndFolderService {
|
|
|
+
|
|
|
+ private final IFileClient fileClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isExistSameName(List<UploadFileDTO> files) {
|
|
|
+ boolean flag = false;
|
|
|
+ List<FileAndFolder> isExists = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(files)) {
|
|
|
+ files.forEach(f -> {
|
|
|
+ Long fileId = f.getBladeFileId();
|
|
|
+ R<FileVO> rpc = fileClient.findById(fileId);
|
|
|
+ if (rpc.isSuccess()) {
|
|
|
+ Long parentId = f.getParentId();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<FileAndFolder> lqw = new LambdaQueryWrapper<>();
|
|
|
+ lqw.eq(FileAndFolder::getStageId, f.getStageId());
|
|
|
+ lqw.eq(FileAndFolder::getParentId, parentId);
|
|
|
+ lqw.eq(FileAndFolder::getTitle, rpc.getData().getOriginalFileName());
|
|
|
+ List<FileAndFolder> list = this.list(lqw);
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ isExists.addAll(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(isExists)) {
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<FileAndFolder> pageByStageId(Long stageId, IPage<FileAndFolder> page) {
|
|
|
+ return page.setRecords(baseMapper.selectByStage(stageId, page));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer getFileAmountByFolderId(Long stageId, Long parentId) {
|
|
|
+
|
|
|
+ return getChildrenFileAmountByFolderId(0, stageId, parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<FileAndFolder> pageByParentId(Long parentId, IPage<FileAndFolder> page) {
|
|
|
+ return page.setRecords(baseMapper.selectByParent(parentId, page));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject getPageAndFileAmount(Long stageId, Long parentId) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+
|
|
|
+ Integer fileAmount = this.getFileAmountByFolderId(stageId, parentId);
|
|
|
+ result.put("amount", fileAmount);
|
|
|
+
|
|
|
+ int totalPage = 0;
|
|
|
+ int volume = 0;
|
|
|
+ List<FileAndFolder> files = this.getChildrenFilesByFolderId(stageId, parentId);
|
|
|
+ if (!CollectionUtils.isEmpty(files)) {
|
|
|
+ totalPage = files.stream().filter(f -> f.getBladeFileId() != null).map(f -> fileClient.findImageList(f.getBladeFileId())).filter(rpc -> rpc.isSuccess() && rpc.getData() != null).map(R::getData).mapToInt(List::size).sum();
|
|
|
+ volume = files.stream().filter(f -> f.getBladeFileId() != null).map(f -> fileClient.findById(f.getBladeFileId())).filter(rpc -> rpc.isSuccess() && rpc.getData() != null).map(R::getData).map(FileVO::getVolume).mapToInt(Integer::parseInt).sum();
|
|
|
+ }
|
|
|
+ result.put("totalPage", totalPage);
|
|
|
+ result.put("volume", volume);
|
|
|
+ int folderAmount = 0;
|
|
|
+ List<FileAndFolder> folders = this.getChildrenFolderByFolderId(stageId, parentId);
|
|
|
+ if (!CollectionUtils.isEmpty(folders)) {
|
|
|
+ folderAmount = folders.size();
|
|
|
+ }
|
|
|
+ result.put("folderAmount", folderAmount);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FileAndFolder> getChildrenFilesByFolderId(Long stageId, Long parentId) {
|
|
|
+ return getChildrenFileByFolderId(new ArrayList<>(), stageId, parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FileAndFolder> getChildrenFolderByFolderId(Long stageId, Long parentId) {
|
|
|
+ return baseMapper.getChildrenFolderList(stageId, parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FileAndFolder> getChildren(Long stageId, Long parentId) {
|
|
|
+ return getChildrenByFolderId(new ArrayList<>(), stageId, parentId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<FileAndFolder> getChildrenByFolderId(ArrayList<FileAndFolder> result, Long stageId, Long parentId) {
|
|
|
+
|
|
|
+ List<FileAndFolder> children = baseMapper.getChildren(stageId, parentId);
|
|
|
+ if (!org.springframework.util.CollectionUtils.isEmpty(children)) {
|
|
|
+ result.addAll(children);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FileAndFolder> childrenFolder = baseMapper.getChildrenFolderList(stageId, parentId);
|
|
|
+ if (!org.springframework.util.CollectionUtils.isEmpty(childrenFolder)) {
|
|
|
+ for (FileAndFolder folder : childrenFolder) {
|
|
|
+ getChildrenByFolderId(result, folder.getStageId(), folder.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<FileAndFolder> getChildrenFileByFolderId(ArrayList<FileAndFolder> result, Long stageId, Long parentId) {
|
|
|
+
|
|
|
+ List<FileAndFolder> files = baseMapper.getChildrenFileList(stageId, parentId);
|
|
|
+ if (!org.springframework.util.CollectionUtils.isEmpty(files)) {
|
|
|
+ result.addAll(files);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FileAndFolder> childrenFolder = baseMapper.getChildrenFolderList(stageId, parentId);
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(childrenFolder)) {
|
|
|
+ for (FileAndFolder folder : childrenFolder) {
|
|
|
+ getChildrenFileByFolderId(result, folder.getStageId(), folder.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Integer getChildrenFileAmountByFolderId(int count, Long stageId, Long folderId) {
|
|
|
+
|
|
|
+ count = count + baseMapper.getFileAmountByFolderId(stageId, folderId);
|
|
|
+
|
|
|
+ List<FileAndFolder> children = baseMapper.getChildrenFolderList(stageId, folderId);
|
|
|
+
|
|
|
+ if (children != null && !children.isEmpty()) {
|
|
|
+ for (FileAndFolder child : children) {
|
|
|
+ int cnt = getChildrenFileAmountByFolderId(0, child.getStageId(), child.getId());
|
|
|
+ count = cnt + count;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|