1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-01 22:53:29 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

后端获取文件列表 Api 完成

This commit is contained in:
2022-04-10 16:09:35 +08:00
parent 8cfdf78eaf
commit dc1e8ee810
11 changed files with 205 additions and 171 deletions

View File

@@ -11,7 +11,7 @@
Target Server Version : 50726
File Encoding : 65001
Date: 08/04/2022 18:21:08
Date: 10/04/2022 15:44:26
*/
SET NAMES utf8mb4;
@@ -144,14 +144,12 @@ CREATE TABLE `file_info` (
`number_of_pages` int(11) NOT NULL DEFAULT 0,
`watermark` tinyint(1) NOT NULL DEFAULT 0,
`advertising` tinyint(1) NOT NULL DEFAULT 0 COMMENT '1为已删除项',
`book_origin` tinyint(4) NOT NULL,
`book_origin` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`thumbnail` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`file_create_at` datetime NOT NULL,
`file_modified_at` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
`file_size` int(18) NOT NULL DEFAULT 0,
`hash_md5` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`file_size` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
`hash_sha1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`hash_sha256` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC;
@@ -178,6 +176,28 @@ CREATE TABLE `file_object_info` (
-- Records of file_object_info
-- ----------------------------
-- ----------------------------
-- Table structure for schedule_task
-- ----------------------------
DROP TABLE IF EXISTS `schedule_task`;
CREATE TABLE `schedule_task` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '插入时间',
`schedule_time` datetime NOT NULL COMMENT '更新时间',
`action` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '任务名称',
`data` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '数据字段',
`task_guid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'GUID唯一标识',
`associated_user_id` int(11) NOT NULL COMMENT '和此任务关联的用户',
`fail_time` tinyint(4) NOT NULL DEFAULT 0 COMMENT '失败次数',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `task_guid`(`task_guid`) USING BTREE,
INDEX `schedule_time`(`schedule_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of schedule_task
-- ----------------------------
-- ----------------------------
-- Table structure for third_party_user_auth_relation
-- ----------------------------

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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
*

View File

@@ -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;
}

View File

@@ -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();
}
}

View File

@@ -52,4 +52,11 @@ public interface FileDOMapper {
* @mbg.generated
*/
int updateByPrimaryKey(FileDO record);
/**
* 查询系统中的所有文件
*
* @return
*/
FileDO[] selectAll();
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -14,14 +14,12 @@
<result column="number_of_pages" jdbcType="INTEGER" property="numberOfPages" />
<result column="watermark" jdbcType="BIT" property="watermark" />
<result column="advertising" jdbcType="BIT" property="advertising" />
<result column="book_origin" jdbcType="TINYINT" property="bookOrigin" />
<result column="book_origin" jdbcType="VARCHAR" property="bookOrigin" />
<result column="thumbnail" jdbcType="VARCHAR" property="thumbnail" />
<result column="file_create_at" jdbcType="TIMESTAMP" property="fileCreateAt" />
<result column="file_modified_at" jdbcType="TIMESTAMP" property="fileModifiedAt" />
<result column="file_size" jdbcType="INTEGER" property="fileSize" />
<result column="hash_md5" jdbcType="VARCHAR" property="hashMd5" />
<result column="file_size" jdbcType="BIGINT" property="fileSize" />
<result column="hash_sha1" jdbcType="VARCHAR" property="hashSha1" />
<result column="hash_sha256" jdbcType="VARCHAR" property="hashSha256" />
</resultMap>
<sql id="Base_Column_List">
<!--
@@ -30,7 +28,7 @@
-->
id, book_id, file_display_name, file_name, file_format, number_of_pages, watermark,
advertising, book_origin, thumbnail, file_create_at, file_modified_at, file_size,
hash_md5, hash_sha1, hash_sha256
hash_sha1
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--
@@ -59,14 +57,12 @@
file_name, file_format, number_of_pages,
watermark, advertising, book_origin,
thumbnail, file_create_at, file_modified_at,
file_size, hash_md5, hash_sha1,
hash_sha256)
file_size, hash_sha1)
values (#{id,jdbcType=INTEGER}, #{bookId,jdbcType=INTEGER}, #{fileDisplayName,jdbcType=VARCHAR},
#{fileName,jdbcType=VARCHAR}, #{fileFormat,jdbcType=VARCHAR}, #{numberOfPages,jdbcType=INTEGER},
#{watermark,jdbcType=BIT}, #{advertising,jdbcType=BIT}, #{bookOrigin,jdbcType=TINYINT},
#{watermark,jdbcType=BIT}, #{advertising,jdbcType=BIT}, #{bookOrigin,jdbcType=VARCHAR},
#{thumbnail,jdbcType=VARCHAR}, #{fileCreateAt,jdbcType=TIMESTAMP}, #{fileModifiedAt,jdbcType=TIMESTAMP},
#{fileSize,jdbcType=INTEGER}, #{hashMd5,jdbcType=VARCHAR}, #{hashSha1,jdbcType=VARCHAR},
#{hashSha256,jdbcType=VARCHAR})
#{fileSize,jdbcType=BIGINT}, #{hashSha1,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="plus.bookshelf.Dao.DO.FileDO">
<!--
@@ -114,15 +110,9 @@
<if test="fileSize != null">
file_size,
</if>
<if test="hashMd5 != null">
hash_md5,
</if>
<if test="hashSha1 != null">
hash_sha1,
</if>
<if test="hashSha256 != null">
hash_sha256,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@@ -150,7 +140,7 @@
#{advertising,jdbcType=BIT},
</if>
<if test="bookOrigin != null">
#{bookOrigin,jdbcType=TINYINT},
#{bookOrigin,jdbcType=VARCHAR},
</if>
<if test="thumbnail != null">
#{thumbnail,jdbcType=VARCHAR},
@@ -162,17 +152,11 @@
#{fileModifiedAt,jdbcType=TIMESTAMP},
</if>
<if test="fileSize != null">
#{fileSize,jdbcType=INTEGER},
</if>
<if test="hashMd5 != null">
#{hashMd5,jdbcType=VARCHAR},
#{fileSize,jdbcType=BIGINT},
</if>
<if test="hashSha1 != null">
#{hashSha1,jdbcType=VARCHAR},
</if>
<if test="hashSha256 != null">
#{hashSha256,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="plus.bookshelf.Dao.DO.FileDO">
@@ -204,7 +188,7 @@
advertising = #{advertising,jdbcType=BIT},
</if>
<if test="bookOrigin != null">
book_origin = #{bookOrigin,jdbcType=TINYINT},
book_origin = #{bookOrigin,jdbcType=VARCHAR},
</if>
<if test="thumbnail != null">
thumbnail = #{thumbnail,jdbcType=VARCHAR},
@@ -216,17 +200,11 @@
file_modified_at = #{fileModifiedAt,jdbcType=TIMESTAMP},
</if>
<if test="fileSize != null">
file_size = #{fileSize,jdbcType=INTEGER},
</if>
<if test="hashMd5 != null">
hash_md5 = #{hashMd5,jdbcType=VARCHAR},
file_size = #{fileSize,jdbcType=BIGINT},
</if>
<if test="hashSha1 != null">
hash_sha1 = #{hashSha1,jdbcType=VARCHAR},
</if>
<if test="hashSha256 != null">
hash_sha256 = #{hashSha256,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
@@ -243,14 +221,17 @@
number_of_pages = #{numberOfPages,jdbcType=INTEGER},
watermark = #{watermark,jdbcType=BIT},
advertising = #{advertising,jdbcType=BIT},
book_origin = #{bookOrigin,jdbcType=TINYINT},
book_origin = #{bookOrigin,jdbcType=VARCHAR},
thumbnail = #{thumbnail,jdbcType=VARCHAR},
file_create_at = #{fileCreateAt,jdbcType=TIMESTAMP},
file_modified_at = #{fileModifiedAt,jdbcType=TIMESTAMP},
file_size = #{fileSize,jdbcType=INTEGER},
hash_md5 = #{hashMd5,jdbcType=VARCHAR},
hash_sha1 = #{hashSha1,jdbcType=VARCHAR},
hash_sha256 = #{hashSha256,jdbcType=VARCHAR}
file_size = #{fileSize,jdbcType=BIGINT},
hash_sha1 = #{hashSha1,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from file_info
</select>
</mapper>