mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-01 22:53:29 +08:00
后端获取文件列表 Api 完成
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
package plus.bookshelf.Common.Enum;
|
||||
|
||||
public enum BookOrigin {
|
||||
ORIGIN("原版电子书"),
|
||||
SCAN("扫描版"),
|
||||
WORD("文字版"), // 大部分是手机版的电子书重新制作成为PDF的
|
||||
HEELP_DOCUMENT("帮助文档"),
|
||||
OTHER("其他");
|
||||
|
||||
private BookOrigin(String intro) {
|
||||
this.intro = intro;
|
||||
}
|
||||
|
||||
private String intro;
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package plus.bookshelf.Common.Enum;
|
||||
|
||||
public enum FileFormatEnum {
|
||||
PDF("pdf", "PDF文件"),
|
||||
MOBI("mobi", "mobi文件"),
|
||||
EPUB("epub", "epub电子书文件"),
|
||||
TXT("txt", "文本文档"),
|
||||
CHM("chm", "CHM帮助文档"),
|
||||
AZW3("azw3", "azw3文件"),
|
||||
DOC("doc", "Word文档"),
|
||||
DOCX("docx", "Word文档");
|
||||
|
||||
private FileFormatEnum(String ext, String extIntro) {
|
||||
this.ext = ext;
|
||||
this.extIntro = extIntro;
|
||||
}
|
||||
|
||||
private String ext;
|
||||
private String extIntro;
|
||||
|
||||
public String getExt() {
|
||||
return ext;
|
||||
}
|
||||
|
||||
public String getExtIntro() {
|
||||
return extIntro;
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ package plus.bookshelf.Controller.Controller;
|
||||
import com.qcloud.cos.http.HttpMethodName;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -11,10 +12,17 @@ import plus.bookshelf.Common.Error.BusinessException;
|
||||
import plus.bookshelf.Common.FileManager.QCloudCosUtils;
|
||||
import plus.bookshelf.Common.Response.CommonReturnType;
|
||||
import plus.bookshelf.Config.QCloudCosConfig;
|
||||
import plus.bookshelf.Controller.VO.FileVO;
|
||||
import plus.bookshelf.Service.Impl.FileServiceImpl;
|
||||
import plus.bookshelf.Service.Impl.UserServiceImpl;
|
||||
import plus.bookshelf.Service.Model.FileModel;
|
||||
import plus.bookshelf.Service.Model.UserModel;
|
||||
import plus.bookshelf.Service.Service.CosPresignedUrlGenerateLogService;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = "文件管理")
|
||||
@Controller("file")
|
||||
@RequestMapping("/file")
|
||||
@@ -29,6 +37,27 @@ public class FileController extends BaseController {
|
||||
@Autowired
|
||||
CosPresignedUrlGenerateLogService cosPresignedUrlGenerateLogService;
|
||||
|
||||
@ApiOperation(value = "查询文件列表", notes = "查询文件列表")
|
||||
@RequestMapping(value = "list", method = {RequestMethod.GET})
|
||||
@ResponseBody
|
||||
public CommonReturnType list() throws InvocationTargetException, IllegalAccessException {
|
||||
List<FileModel> fileModels = fileService.list();
|
||||
List<FileVO> fileVOS = new ArrayList<>();
|
||||
for (FileModel fileModel : fileModels) {
|
||||
FileVO fileVO = convertFromModel(fileModel);
|
||||
fileVOS.add(fileVO);
|
||||
}
|
||||
return CommonReturnType.create(fileVOS);
|
||||
}
|
||||
|
||||
private FileVO convertFromModel(FileModel fileModel) {
|
||||
FileVO fileVO = new FileVO();
|
||||
BeanUtils.copyProperties(fileModel, fileVO);
|
||||
fileVO.setFileCreateAt(fileModel.getFileCreateAt().getTime());
|
||||
fileVO.setFileModifiedAt(fileModel.getFileModifiedAt().getTime());
|
||||
return fileVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件操作预授权URL
|
||||
*
|
||||
|
@@ -0,0 +1,51 @@
|
||||
package plus.bookshelf.Controller.VO;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class FileVO {
|
||||
|
||||
// 文件Id
|
||||
Integer id;
|
||||
|
||||
// 关联的书籍Id
|
||||
Integer bookId;
|
||||
|
||||
// 文件名 (用于展示给用户的文件名,不含扩展名)
|
||||
String fileDisplayName;
|
||||
|
||||
// 文件存储名称 (文件的实际文件名,含扩展名)
|
||||
String fileName;
|
||||
|
||||
// 文件格式
|
||||
String fileFormat;
|
||||
|
||||
// 总页数
|
||||
Integer numberOfPages;
|
||||
|
||||
// 是否含有水印
|
||||
Boolean watermark;
|
||||
|
||||
// 是否有广告
|
||||
Boolean advertising;
|
||||
|
||||
// 文件来源 电子版/扫描版
|
||||
String bookOrigin;
|
||||
|
||||
// 缩略图
|
||||
private String thumbnail;
|
||||
|
||||
// 文件创建时间
|
||||
long fileCreateAt;
|
||||
|
||||
// 文件修改时间
|
||||
long fileModifiedAt;
|
||||
|
||||
// 文件大小
|
||||
long fileSize;
|
||||
|
||||
// 文件哈希 - SHA1
|
||||
String hashSha1;
|
||||
}
|
@@ -82,7 +82,7 @@ public class FileDO {
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private Byte bookOrigin;
|
||||
private String bookOrigin;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -118,16 +118,7 @@ public class FileDO {
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private Integer fileSize;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.hash_md5
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String hashMd5;
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -138,15 +129,6 @@ public class FileDO {
|
||||
*/
|
||||
private String hashSha1;
|
||||
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column file_info.hash_sha256
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
private String hashSha256;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.id
|
||||
@@ -347,7 +329,7 @@ public class FileDO {
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Byte getBookOrigin() {
|
||||
public String getBookOrigin() {
|
||||
return bookOrigin;
|
||||
}
|
||||
|
||||
@@ -359,8 +341,8 @@ public class FileDO {
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setBookOrigin(Byte bookOrigin) {
|
||||
this.bookOrigin = bookOrigin;
|
||||
public void setBookOrigin(String bookOrigin) {
|
||||
this.bookOrigin = bookOrigin == null ? null : bookOrigin.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,7 +425,7 @@ public class FileDO {
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public Integer getFileSize() {
|
||||
public Long getFileSize() {
|
||||
return fileSize;
|
||||
}
|
||||
|
||||
@@ -455,34 +437,10 @@ public class FileDO {
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setFileSize(Integer fileSize) {
|
||||
public void setFileSize(Long fileSize) {
|
||||
this.fileSize = fileSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.hash_md5
|
||||
*
|
||||
* @return the value of file_info.hash_md5
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getHashMd5() {
|
||||
return hashMd5;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.hash_md5
|
||||
*
|
||||
* @param hashMd5 the value for file_info.hash_md5
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setHashMd5(String hashMd5) {
|
||||
this.hashMd5 = hashMd5 == null ? null : hashMd5.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.hash_sha1
|
||||
@@ -506,28 +464,4 @@ public class FileDO {
|
||||
public void setHashSha1(String hashSha1) {
|
||||
this.hashSha1 = hashSha1 == null ? null : hashSha1.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column file_info.hash_sha256
|
||||
*
|
||||
* @return the value of file_info.hash_sha256
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public String getHashSha256() {
|
||||
return hashSha256;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column file_info.hash_sha256
|
||||
*
|
||||
* @param hashSha256 the value for file_info.hash_sha256
|
||||
*
|
||||
* @mbg.generated
|
||||
*/
|
||||
public void setHashSha256(String hashSha256) {
|
||||
this.hashSha256 = hashSha256 == null ? null : hashSha256.trim();
|
||||
}
|
||||
}
|
@@ -52,4 +52,11 @@ public interface FileDOMapper {
|
||||
* @mbg.generated
|
||||
*/
|
||||
int updateByPrimaryKey(FileDO record);
|
||||
|
||||
/**
|
||||
* 查询系统中的所有文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
FileDO[] selectAll();
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package plus.bookshelf.Service.Impl;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import plus.bookshelf.Dao.DO.FileDO;
|
||||
import plus.bookshelf.Dao.Mapper.FileDOMapper;
|
||||
import plus.bookshelf.Service.Model.FileModel;
|
||||
import plus.bookshelf.Service.Service.FileService;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FileServiceImpl implements FileService {
|
||||
|
||||
@Autowired
|
||||
FileDOMapper fileDOMapper;
|
||||
|
||||
/**
|
||||
* 列出所有文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FileModel> list() throws InvocationTargetException, IllegalAccessException {
|
||||
FileDO[] fileDOS = fileDOMapper.selectAll();
|
||||
|
||||
List<FileModel> fileModels = new ArrayList<>();
|
||||
for (FileDO fileDO : fileDOS) {
|
||||
FileModel fileModel = convertFromDataObject(fileDO);
|
||||
fileModels.add(fileModel);
|
||||
}
|
||||
|
||||
return fileModels;
|
||||
}
|
||||
|
||||
private FileModel convertFromDataObject(FileDO fileDO) throws InvocationTargetException, IllegalAccessException {
|
||||
FileModel fileModel = new FileModel();
|
||||
BeanUtils.copyProperties(fileDO, fileModel);
|
||||
return fileModel;
|
||||
}
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
package plus.bookshelf.Service.Model;
|
||||
|
||||
import lombok.Data;
|
||||
import org.joda.time.DateTime;
|
||||
import plus.bookshelf.Common.Enum.BookOrigin;
|
||||
import plus.bookshelf.Common.Enum.FileFormatEnum;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class FileModel {
|
||||
@@ -21,7 +20,7 @@ public class FileModel {
|
||||
String fileName;
|
||||
|
||||
// 文件格式
|
||||
FileFormatEnum fileFormat;
|
||||
String fileFormat;
|
||||
|
||||
// 总页数
|
||||
Integer numberOfPages;
|
||||
@@ -33,23 +32,20 @@ public class FileModel {
|
||||
Boolean advertising;
|
||||
|
||||
// 文件来源 电子版/扫描版
|
||||
BookOrigin bookOrigin;
|
||||
String bookOrigin;
|
||||
|
||||
// 缩略图
|
||||
private String thumbnail;
|
||||
|
||||
// 文件创建时间
|
||||
DateTime fileCreateAt;
|
||||
Date fileCreateAt;
|
||||
|
||||
// 文件修改时间
|
||||
DateTime fileModifiedAt;
|
||||
Date fileModifiedAt;
|
||||
|
||||
// 文件大小
|
||||
long fileSize;
|
||||
|
||||
// 文件哈希 - MD5
|
||||
String hashMd5;
|
||||
|
||||
// 文件哈希 - SHA1
|
||||
String hashSha1;
|
||||
|
||||
// 文件哈希 - SHA256
|
||||
String hashSha256;
|
||||
}
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package plus.bookshelf.Service.Service;
|
||||
|
||||
import plus.bookshelf.Service.Model.FileModel;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
public interface FileService {
|
||||
/**
|
||||
* 列出所有文件
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<FileModel> list() throws InvocationTargetException, IllegalAccessException;
|
||||
}
|
Reference in New Issue
Block a user