commit
0f867d3149
6
pom.xml
6
pom.xml
@ -122,6 +122,12 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mpatric</groupId>
|
||||
<artifactId>mp3agic</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -2,14 +2,15 @@ package com.qiwenshare.file.api;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qiwenshare.file.domain.FileBean;
|
||||
import com.qiwenshare.file.vo.file.FileDetailVO;
|
||||
|
||||
public interface IFileService extends IService<FileBean> {
|
||||
|
||||
Long getFilePointCount(String fileId);
|
||||
void unzipFile(String userFileId, int unzipMode, String filePath);
|
||||
|
||||
public void updateFileDetail(String userFileId, String identifier, long fileSize, long modifyUserId);
|
||||
|
||||
void updateFileDetail(String userFileId, String identifier, long fileSize, long modifyUserId);
|
||||
|
||||
FileDetailVO getFileDetail(String userFileId);
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -17,8 +18,9 @@ public interface IUserFileService extends IService<UserFile> {
|
||||
|
||||
IPage<FileListVo> getFileByFileType(Integer fileTypeId, Long currentPage, Long pageCount, long userId);
|
||||
List<UserFile> selectUserFileListByPath(String filePath, Long userId);
|
||||
List<UserFile> selectFileListLikeRightFilePath(String filePath, long userId);
|
||||
List<UserFile> selectFilePathTreeByUserId(Long userId);
|
||||
void deleteUserFile(String userFileId, Long sessionUserId);
|
||||
|
||||
List<UserFile> selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") long userId);
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import com.qiwenshare.file.dto.file.*;
|
||||
import com.qiwenshare.file.io.QiwenFile;
|
||||
import com.qiwenshare.file.util.QiwenFileUtil;
|
||||
import com.qiwenshare.file.util.TreeNode;
|
||||
import com.qiwenshare.file.vo.file.FileDetailVO;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import com.qiwenshare.file.vo.file.SearchFileVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -165,10 +166,11 @@ public class FileController {
|
||||
.eq(UserFile::getUserFileId, renameFileDto.getUserFileId());
|
||||
userFileService.update(lambdaUpdateWrapper);
|
||||
if (1 == userFile.getIsDir()) {
|
||||
List<UserFile> list = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName() + "/", sessionUserBean.getUserId());
|
||||
List<UserFile> list = userFileService.selectUserFileByLikeRightFilePath(new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath(), sessionUserBean.getUserId());
|
||||
|
||||
for (UserFile newUserFile : list) {
|
||||
newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(userFile.getFilePath() + userFile.getFileName() + "/", userFile.getFilePath() + renameFileDto.getFileName() + "/"));
|
||||
newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(new QiwenFile(userFile.getFilePath(), userFile.getFileName(), userFile.getIsDir() == 1).getPath(),
|
||||
new QiwenFile(userFile.getFilePath(), renameFileDto.getFileName(), userFile.getIsDir() == 1).getPath()));
|
||||
userFileService.updateById(newUserFile);
|
||||
}
|
||||
}
|
||||
@ -429,6 +431,15 @@ public class FileController {
|
||||
return RestResult.success().message("修改文件成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "查询文件详情", description = "查询文件详情", tags = {"file"})
|
||||
@RequestMapping(value = "/detail", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public RestResult<FileDetailVO> queryFileDetail(
|
||||
@Parameter(description = "用户文件Id", required = true) String userFileId){
|
||||
FileDetailVO vo = fileService.getFileDetail(userFileId);
|
||||
return RestResult.success().data(vo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -155,11 +155,8 @@ public class FiletransferController {
|
||||
if (userFile.getIsDir() == 0) {
|
||||
userFileIds.add(userFileId);
|
||||
} else {
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.likeRight(UserFile::getFilePath, userFile.getFilePath() + QiwenFile.separator + userFile.getFileName())
|
||||
.eq(UserFile::getUserId, userFile.getUserId())
|
||||
.eq(UserFile::getDeleteFlag, 0);
|
||||
List<UserFile> userFileList = userFileService.list(lambdaQueryWrapper);
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true);
|
||||
List<UserFile> userFileList = userFileService.selectUserFileByLikeRightFilePath(qiwenFile.getPath(), userFile.getUserId());
|
||||
List<String> userFileIds1 = userFileList.stream().map(UserFile::getUserFileId).collect(Collectors.toList());
|
||||
userFileIds.add(userFile.getUserFileId());
|
||||
userFileIds.addAll(userFileIds1);
|
||||
|
@ -81,7 +81,7 @@ public class ShareController {
|
||||
}
|
||||
if (userFile.getIsDir() == 1) {
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true);
|
||||
List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(qiwenFile.getPath(), sessionUserBean.getUserId());
|
||||
List<UserFile> userfileList = userFileService.selectUserFileByLikeRightFilePath(qiwenFile.getPath(), sessionUserBean.getUserId());
|
||||
for (UserFile userFile1 : userfileList) {
|
||||
ShareFile shareFile1 = new ShareFile();
|
||||
shareFile1.setUserFileId(userFile1.getUserFileId());
|
||||
@ -121,7 +121,7 @@ public class ShareController {
|
||||
String savefileName = fileDealComp.getRepeatFileName(userFile, savefilePath);
|
||||
|
||||
if (userFile.getIsDir() == 1) {
|
||||
List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName(), userFile.getUserId());
|
||||
List<UserFile> userfileList = userFileService.selectUserFileByLikeRightFilePath(new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath(), userFile.getUserId());
|
||||
log.info("查询文件列表:" + JSON.toJSONString(userfileList));
|
||||
String filePath = userFile.getFilePath();
|
||||
userfileList.forEach(p->{
|
||||
|
59
src/main/java/com/qiwenshare/file/domain/Music.java
Normal file
59
src/main/java/com/qiwenshare/file/domain/Music.java
Normal file
@ -0,0 +1,59 @@
|
||||
package com.qiwenshare.file.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* @author MAC
|
||||
* @version 1.0
|
||||
* @description: TODO
|
||||
* @date 2022/4/27 23:44
|
||||
*/
|
||||
@Data
|
||||
@Table(name = "music")
|
||||
@Entity
|
||||
@TableName("music")
|
||||
public class Music {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@TableId(type = IdType.AUTO)
|
||||
@Column(columnDefinition="bigint(20)")
|
||||
private String musicId;
|
||||
@Column(columnDefinition = "bigint(20) comment '文件id'")
|
||||
private String fileId;
|
||||
private String track;
|
||||
@Column
|
||||
private String artist;
|
||||
@Column
|
||||
private String title;
|
||||
@Column
|
||||
private String album;
|
||||
@Column
|
||||
private String year;
|
||||
@Column
|
||||
private String genre;
|
||||
@Column
|
||||
private String comment;
|
||||
@Column
|
||||
private String lyrics;
|
||||
@Column
|
||||
private String composer;
|
||||
@Column
|
||||
private String publicer;
|
||||
@Column
|
||||
private String originalArtist;
|
||||
@Column
|
||||
private String albumArtist;
|
||||
@Column
|
||||
private String copyright;
|
||||
@Column
|
||||
private String url;
|
||||
@Column
|
||||
private String encoder;
|
||||
@Column(columnDefinition = "mediumblob")
|
||||
private String albumImage;
|
||||
}
|
13
src/main/java/com/qiwenshare/file/mapper/MusicMapper.java
Normal file
13
src/main/java/com/qiwenshare/file/mapper/MusicMapper.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.qiwenshare.file.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qiwenshare.file.domain.Image;
|
||||
import com.qiwenshare.file.domain.Music;
|
||||
|
||||
public interface MusicMapper extends BaseMapper<Music> {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -7,6 +7,8 @@ import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||
|
||||
void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName, long userId);
|
||||
@ -22,6 +24,8 @@ public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||
@Param("newFilePath") String newfilePath,
|
||||
@Param("userId") long userId);
|
||||
|
||||
List<UserFile> selectUserFileByLikeRightFilePath(@Param("filePath") String filePath, @Param("userId") long userId);
|
||||
|
||||
IPage<FileListVo> selectPageVo(Page<?> page, @Param("userFile") UserFile userFile, @Param("fileTypeId") Integer fileTypeId);
|
||||
Long selectStorageSizeByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.qiwenshare.file.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.qiwenshare.common.exception.QiwenException;
|
||||
@ -10,10 +12,15 @@ import com.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.file.api.IFileService;
|
||||
import com.qiwenshare.file.component.AsyncTaskComp;
|
||||
import com.qiwenshare.file.domain.FileBean;
|
||||
import com.qiwenshare.file.domain.Image;
|
||||
import com.qiwenshare.file.domain.Music;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.mapper.FileMapper;
|
||||
import com.qiwenshare.file.mapper.ImageMapper;
|
||||
import com.qiwenshare.file.mapper.MusicMapper;
|
||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||
import com.qiwenshare.file.util.QiwenFileUtil;
|
||||
import com.qiwenshare.file.vo.file.FileDetailVO;
|
||||
import com.qiwenshare.ufop.factory.UFOPFactory;
|
||||
import com.qiwenshare.ufop.operation.download.Downloader;
|
||||
import com.qiwenshare.ufop.operation.download.domain.DownloadFile;
|
||||
@ -50,6 +57,10 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
||||
|
||||
@Resource
|
||||
AsyncTaskComp asyncTaskComp;
|
||||
@Resource
|
||||
MusicMapper musicMapper;
|
||||
@Resource
|
||||
ImageMapper imageMapper;
|
||||
|
||||
@Override
|
||||
public Long getFilePointCount(String fileId) {
|
||||
@ -107,7 +118,7 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateFileDetail(String userFileId, String identifier, long fileSize, long modifyUserId) {
|
||||
UserFile userFile = userFileMapper.selectById(userFileId);
|
||||
|
||||
@ -120,4 +131,18 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
||||
fileMapper.updateById(fileBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileDetailVO getFileDetail(String userFileId) {
|
||||
UserFile userFile = userFileMapper.selectById(userFileId);
|
||||
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
|
||||
Music music = musicMapper.selectOne(new QueryWrapper<Music>().eq("fileId", userFile.getFileId()));
|
||||
Image image = imageMapper.selectOne(new QueryWrapper<Image>().eq("fileId", userFile.getFileId()));
|
||||
FileDetailVO fileDetailVO = new FileDetailVO();
|
||||
BeanUtil.copyProperties(userFile, fileDetailVO);
|
||||
BeanUtil.copyProperties(fileBean, fileDetailVO);
|
||||
fileDetailVO.setMusic(music);
|
||||
fileDetailVO.setImage(image);
|
||||
return fileDetailVO;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package com.qiwenshare.file.service;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.mpatric.mp3agic.ID3v1;
|
||||
import com.mpatric.mp3agic.ID3v2;
|
||||
import com.mpatric.mp3agic.Mp3File;
|
||||
import com.qiwenshare.common.util.DateUtil;
|
||||
import com.qiwenshare.common.util.MimeUtils;
|
||||
import com.qiwenshare.common.util.security.JwtUser;
|
||||
@ -22,6 +26,8 @@ import com.qiwenshare.ufop.constant.UploadFileStatusEnum;
|
||||
import com.qiwenshare.ufop.exception.operation.DownloadException;
|
||||
import com.qiwenshare.ufop.exception.operation.UploadException;
|
||||
import com.qiwenshare.ufop.factory.UFOPFactory;
|
||||
import com.qiwenshare.ufop.operation.copy.Copier;
|
||||
import com.qiwenshare.ufop.operation.copy.domain.CopyFile;
|
||||
import com.qiwenshare.ufop.operation.delete.Deleter;
|
||||
import com.qiwenshare.ufop.operation.delete.domain.DeleteFile;
|
||||
import com.qiwenshare.ufop.operation.download.Downloader;
|
||||
@ -34,14 +40,18 @@ import com.qiwenshare.ufop.operation.upload.domain.UploadFileResult;
|
||||
import com.qiwenshare.ufop.util.UFOPUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import sun.nio.cs.ext.GBK;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -73,6 +83,8 @@ public class FiletransferService implements IFiletransferService {
|
||||
UploadTaskMapper uploadTaskMapper;
|
||||
@Resource
|
||||
ImageMapper imageMapper;
|
||||
@Resource
|
||||
MusicMapper musicMapper;
|
||||
|
||||
@Resource
|
||||
PictureFileMapper pictureFileMapper;
|
||||
@ -214,8 +226,89 @@ public class FiletransferService implements IFiletransferService {
|
||||
image.setFileId(fileBean.getFileId());
|
||||
imageMapper.insert(image);
|
||||
}
|
||||
if ("mp3".equalsIgnoreCase(uploadFileResult.getExtendName())) {
|
||||
Downloader downloader = ufopFactory.getDownloader(uploadFileResult.getStorageType().getCode());
|
||||
DownloadFile downloadFile = new DownloadFile();
|
||||
downloadFile.setFileUrl(uploadFileResult.getFileUrl());
|
||||
InputStream inputStream = downloader.getInputStream(downloadFile);
|
||||
File outFile = UFOPUtils.getTempFile(uploadFileResult.getFileUrl());
|
||||
if (!outFile.exists()) {
|
||||
outFile.createNewFile();
|
||||
}
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(outFile);
|
||||
IOUtils.copy(inputStream, fileOutputStream);
|
||||
fileOutputStream.close();
|
||||
Mp3File mp3file = new Mp3File(outFile);
|
||||
Music music = new Music();
|
||||
music.setMusicId(IdUtil.getSnowflakeNextIdStr());
|
||||
music.setFileId(fileBean.getFileId());
|
||||
if (mp3file.hasId3v1Tag()) {
|
||||
ID3v1 id3v1Tag = mp3file.getId3v1Tag();
|
||||
music.setTrack(formatChatset(id3v1Tag.getTrack()));
|
||||
music.setArtist(formatChatset(id3v1Tag.getTrack()));
|
||||
music.setTitle(formatChatset(id3v1Tag.getTitle()));
|
||||
music.setAlbum(formatChatset(id3v1Tag.getAlbum()));
|
||||
music.setYear(formatChatset(id3v1Tag.getYear()));
|
||||
music.setGenre(formatChatset(id3v1Tag.getGenre() + " (" + id3v1Tag.getGenreDescription() + ")"));
|
||||
music.setComment(formatChatset(id3v1Tag.getComment()));
|
||||
}
|
||||
Mp3File mp3file2 = new Mp3File(outFile);
|
||||
if (mp3file2.hasId3v2Tag()) {
|
||||
ID3v2 id3v2Tag = mp3file2.getId3v2Tag();
|
||||
if (StringUtils.isEmpty(music.getTrack())) {
|
||||
music.setTrack(formatChatset(id3v2Tag.getTrack()));
|
||||
}
|
||||
if (StringUtils.isEmpty(music.getArtist())) {
|
||||
music.setArtist(formatChatset(id3v2Tag.getArtist()));
|
||||
}
|
||||
if (StringUtils.isEmpty(music.getTitle())) {
|
||||
music.setTitle(formatChatset(id3v2Tag.getTitle()));
|
||||
}
|
||||
if (StringUtils.isEmpty(music.getAlbum())) {
|
||||
music.setAlbum(formatChatset(id3v2Tag.getAlbum()));
|
||||
}
|
||||
if (StringUtils.isEmpty(music.getYear())) {
|
||||
music.setYear(formatChatset(id3v2Tag.getYear()));
|
||||
}
|
||||
if (StringUtils.isEmpty(music.getGenre())) {
|
||||
music.setGenre(formatChatset(id3v2Tag.getGenre() + " (" + id3v2Tag.getGenreDescription() + ")"));
|
||||
}
|
||||
if (StringUtils.isEmpty(music.getComment())) {
|
||||
music.setComment(formatChatset(id3v2Tag.getComment()));
|
||||
}
|
||||
music.setLyrics(formatChatset(id3v2Tag.getLyrics()));
|
||||
music.setComposer(formatChatset(id3v2Tag.getComposer()));
|
||||
music.setPublicer(formatChatset(id3v2Tag.getPublisher()));
|
||||
music.setOriginalArtist(formatChatset(id3v2Tag.getOriginalArtist()));
|
||||
music.setAlbumArtist(formatChatset(id3v2Tag.getAlbumArtist()));
|
||||
music.setCopyright(formatChatset(id3v2Tag.getCopyright()));
|
||||
music.setUrl(formatChatset(id3v2Tag.getUrl()));
|
||||
music.setEncoder(formatChatset(id3v2Tag.getEncoder()));
|
||||
|
||||
byte[] albumImageData = id3v2Tag.getAlbumImage();
|
||||
|
||||
if (albumImageData != null) {
|
||||
File outFile1 = UFOPUtils.getTempFile(uploadFileResult.getFileName() + ".png");
|
||||
if (!outFile1.exists()) {
|
||||
outFile1.createNewFile();
|
||||
}
|
||||
music.setAlbumImage(Base64.getEncoder().encodeToString(albumImageData));
|
||||
// FileOutputStream fileOutputStream1 = new FileOutputStream(outFile1);
|
||||
// IOUtils.write(albumImageData, fileOutputStream1);
|
||||
// Copier copier = ufopFactory.getCopier();
|
||||
// CopyFile copyFile = new CopyFile();
|
||||
// copyFile.setExtendName("png");
|
||||
// String fileUrl = copier.copy(new FileInputStream(outFile1), copyFile);
|
||||
// music.setAlbumImageUrl(fileUrl);
|
||||
|
||||
System.out.println("Have album image data, length: " + albumImageData.length + " bytes");
|
||||
System.out.println("Album image mime type: " + id3v2Tag.getAlbumImageMimeType());
|
||||
}
|
||||
}
|
||||
musicMapper.insert(music);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("生成图片缩略图失败!");
|
||||
log.error("生成图片缩略图失败!", e);
|
||||
}
|
||||
|
||||
} else if (UploadFileStatusEnum.UNCOMPLATE.equals(uploadFileResult.getStatus())) {
|
||||
@ -244,6 +337,17 @@ public class FiletransferService implements IFiletransferService {
|
||||
|
||||
}
|
||||
|
||||
private String formatChatset(String str) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
if (java.nio.charset.Charset.forName("ISO-8859-1").newEncoder().canEncode(str)) {
|
||||
byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1);
|
||||
return new String(bytes, Charset.forName("GBK"));
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadFile(HttpServletResponse httpServletResponse, DownloadFileDTO downloadFileDTO) {
|
||||
UserFile userFile = userFileMapper.selectById(downloadFileDTO.getUserFileId());
|
||||
@ -307,7 +411,8 @@ public class FiletransferService implements IFiletransferService {
|
||||
InputStream inputStream = downloader.getInputStream(downloadFile);
|
||||
BufferedInputStream bis = new BufferedInputStream(inputStream);
|
||||
try {
|
||||
zos.putNextEntry(new ZipEntry(userFile1.getFilePath().replaceFirst(filePath, "") + "/" + userFile1.getFileName() + "." + userFile1.getExtendName()));
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile1.getFilePath().replaceFirst(filePath, ""), userFile1.getFileName() + "." + userFile1.getExtendName(), false);
|
||||
zos.putNextEntry(new ZipEntry(qiwenFile.getPath()));
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int i = bis.read(buffer);
|
||||
@ -327,8 +432,9 @@ public class FiletransferService implements IFiletransferService {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QiwenFile qiwenFile = new QiwenFile(userFile1.getFilePath(), userFile1.getFileName(), true);
|
||||
// 空文件夹的处理
|
||||
zos.putNextEntry(new ZipEntry(userFile1.getFilePath() + userFile1.getFileName() + "/"));
|
||||
zos.putNextEntry(new ZipEntry(qiwenFile.getPath() + QiwenFile.separator));
|
||||
// 没有文件,不需要文件的copy
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import com.qiwenshare.common.util.security.SessionUtil;
|
||||
import com.qiwenshare.file.api.IUserFileService;
|
||||
import com.qiwenshare.file.domain.RecoveryFile;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.io.QiwenFile;
|
||||
import com.qiwenshare.file.mapper.FileMapper;
|
||||
import com.qiwenshare.file.mapper.FileTypeMapper;
|
||||
import com.qiwenshare.file.mapper.RecoveryFileMapper;
|
||||
@ -100,11 +101,11 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
userFileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName, userId);
|
||||
|
||||
//移动子目录
|
||||
oldfilePath = oldfilePath + "/" + fileName;
|
||||
newfilePath = newfilePath + "/" + fileName;
|
||||
oldfilePath = new QiwenFile(oldfilePath, fileName, true).getPath();
|
||||
newfilePath = new QiwenFile(newfilePath, fileName, true).getPath();
|
||||
|
||||
if (StringUtils.isEmpty(extendName)) { //为空说明是目录,则需要移动子目录
|
||||
List<UserFile> list = selectFileListLikeRightFilePath(oldfilePath, userId);
|
||||
List<UserFile> list = selectUserFileByLikeRightFilePath(oldfilePath, userId);
|
||||
|
||||
for (UserFile newUserFile : list) {
|
||||
newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(oldfilePath, newfilePath));
|
||||
@ -127,8 +128,8 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
|
||||
|
||||
//移动子目录
|
||||
oldfilePath = oldfilePath + "/" + fileName;
|
||||
newfilePath = newfilePath + "/" + fileName;
|
||||
oldfilePath = new QiwenFile(oldfilePath, fileName, true).getPath();
|
||||
newfilePath = new QiwenFile(newfilePath, fileName, true).getPath();
|
||||
|
||||
oldfilePath = oldfilePath.replace("\\", "\\\\\\\\");
|
||||
oldfilePath = oldfilePath.replace("'", "\\'");
|
||||
@ -161,23 +162,6 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
return userFileMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserFile> selectFileListLikeRightFilePath(String filePath, long userId) {
|
||||
filePath = filePath.replace("\\", "\\\\\\\\");
|
||||
filePath = filePath.replace("'", "\\'");
|
||||
filePath = filePath.replace("%", "\\%");
|
||||
filePath = filePath.replace("_", "\\_");
|
||||
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
log.info("查询文件路径:" + filePath);
|
||||
|
||||
lambdaQueryWrapper.eq(UserFile::getUserId, userId)
|
||||
.likeRight(UserFile::getFilePath, filePath)
|
||||
.eq(UserFile::getDeleteFlag, 0);
|
||||
return userFileMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserFile> selectFilePathTreeByUserId(Long userId) {
|
||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
@ -200,7 +184,7 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
.eq(UserFile::getUserFileId, userFileId);
|
||||
userFileMapper.update(null, userFileLambdaUpdateWrapper);
|
||||
|
||||
String filePath = userFile.getFilePath() + "/" + userFile.getFileName();
|
||||
String filePath = new QiwenFile(userFile.getFilePath(), userFile.getFileName(), true).getPath();
|
||||
updateFileDeleteStateByFilePath(filePath, uuid, sessionUserId);
|
||||
|
||||
}else{
|
||||
@ -222,9 +206,14 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserFile> selectUserFileByLikeRightFilePath(String filePath, long userId) {
|
||||
return userFileMapper.selectUserFileByLikeRightFilePath(filePath, userId);
|
||||
}
|
||||
|
||||
private void updateFileDeleteStateByFilePath(String filePath, String deleteBatchNum, Long userId) {
|
||||
executor.execute(() -> {
|
||||
List<UserFile> fileList = selectFileListLikeRightFilePath(filePath, userId);
|
||||
List<UserFile> fileList = selectUserFileByLikeRightFilePath(filePath, userId);
|
||||
for (int i = 0; i < fileList.size(); i++){
|
||||
UserFile userFileTemp = fileList.get(i);
|
||||
//标记删除标志
|
||||
|
53
src/main/java/com/qiwenshare/file/vo/file/FileDetailVO.java
Normal file
53
src/main/java/com/qiwenshare/file/vo/file/FileDetailVO.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.qiwenshare.file.vo.file;
|
||||
|
||||
import com.qiwenshare.file.domain.Image;
|
||||
import com.qiwenshare.file.domain.Music;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author MAC
|
||||
* @version 1.0
|
||||
* @description: TODO
|
||||
* @date 2022/4/28 23:45
|
||||
*/
|
||||
@Data
|
||||
public class FileDetailVO {
|
||||
private String fileId;
|
||||
|
||||
private String timeStampName;
|
||||
|
||||
private String fileUrl;
|
||||
|
||||
private Long fileSize;
|
||||
|
||||
private Integer storageType;
|
||||
|
||||
private Integer pointCount;
|
||||
|
||||
private String identifier;
|
||||
|
||||
private String userFileId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
|
||||
private String fileName;
|
||||
|
||||
private String filePath;
|
||||
|
||||
private String extendName;
|
||||
|
||||
private Integer isDir;
|
||||
|
||||
private String uploadTime;
|
||||
|
||||
private Integer deleteFlag;
|
||||
|
||||
private String deleteTime;
|
||||
|
||||
private String deleteBatchNum;
|
||||
|
||||
private Image image;
|
||||
|
||||
private Music music;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.qiwenshare.file.vo.file;
|
||||
|
||||
import com.qiwenshare.file.domain.Music;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ -41,4 +42,5 @@ public class FileListVo {
|
||||
|
||||
private Integer imageWidth;
|
||||
private Integer imageHeight;
|
||||
|
||||
}
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
<mapper namespace="com.qiwenshare.file.mapper.UserFileMapper">
|
||||
|
||||
|
||||
|
||||
<select id="selectPageVo" parameterType="com.qiwenshare.file.domain.UserFile" resultType="com.qiwenshare.file.vo.file.FileListVo">
|
||||
select * from userfile a
|
||||
left join image on a.fileId = image.fileId
|
||||
@ -44,6 +42,11 @@
|
||||
ORDER BY isDir desc
|
||||
</select>
|
||||
|
||||
<select id="selectUserFileByLikeRightFilePath" resultType="com.qiwenshare.file.domain.UserFile">
|
||||
select * from userfile
|
||||
where (filePath = #{filePath} or filePath like concat(#{filePath},'/%')) and userId = #{userId} and deleteFlag = 0
|
||||
</select>
|
||||
|
||||
|
||||
<update id="updateFilepathByFilepath">
|
||||
UPDATE userfile SET filePath=REPLACE(filePath, #{param1}, #{param2})
|
||||
|
Loading…
Reference in New Issue
Block a user