From a1a573ad87aaaf4fe0014631c26a28cbea6477d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AF=9B=E6=AF=9B=E8=99=AB?= <1421374934@qq.com> Date: Thu, 13 Jan 2022 23:45:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:bug:=20=E9=80=9A=E8=BF=87md5=E5=80=BC?= =?UTF-8?q?=E5=92=8C=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7id=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=96=87=E4=BB=B6url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rymcu/forest/mapper/ForestFileMapper.java | 5 +++-- .../rymcu/forest/service/ForestFileService.java | 5 +++-- .../service/impl/ForestFileServiceImpl.java | 7 ++++--- .../forest/web/api/common/UploadController.java | 17 +++++++---------- src/main/java/mapper/ForestFileMapper.xml | 1 + 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java b/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java index 339fdaf..327f217 100644 --- a/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java @@ -13,10 +13,11 @@ public interface ForestFileMapper extends Mapper { /** * 通过md5获取文件访问链接 * - * @param md5Value md5值 + * @param md5Value md5值 + * @param createdBy 创建人 * @return */ - String getFileUrlByMd5(@Param("md5Value") String md5Value); + String getFileUrlByMd5(@Param("md5Value") String md5Value, @Param("createdBy") long createdBy); /** * 插入文件对象 diff --git a/src/main/java/com/rymcu/forest/service/ForestFileService.java b/src/main/java/com/rymcu/forest/service/ForestFileService.java index 78f7bac..5459d86 100644 --- a/src/main/java/com/rymcu/forest/service/ForestFileService.java +++ b/src/main/java/com/rymcu/forest/service/ForestFileService.java @@ -15,10 +15,11 @@ public interface ForestFileService extends Service { /** * 通过md5获取文件访问链接 * - * @param md5Value md5值 + * @param md5Value md5值 + * @param createdBy 用户id * @return */ - String getFileUrlByMd5(String md5Value); + String getFileUrlByMd5(String md5Value, long createdBy); /** * 插入文件对象 diff --git a/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java index 65b1a2a..4f178f9 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java @@ -22,12 +22,13 @@ public class ForestFileServiceImpl extends AbstractService implement /** * 通过md5获取文件访问链接 * - * @param md5Value md5值 + * @param md5Value md5值 + * @param createdBy 用户id * @return */ @Override - public String getFileUrlByMd5(String md5Value) { - return forestFileMapper.getFileUrlByMd5(md5Value); + public String getFileUrlByMd5(String md5Value, long createdBy) { + return forestFileMapper.getFileUrlByMd5(md5Value, createdBy); } /** diff --git a/src/main/java/com/rymcu/forest/web/api/common/UploadController.java b/src/main/java/com/rymcu/forest/web/api/common/UploadController.java index 5ea38c9..2495184 100644 --- a/src/main/java/com/rymcu/forest/web/api/common/UploadController.java +++ b/src/main/java/com/rymcu/forest/web/api/common/UploadController.java @@ -121,7 +121,7 @@ public class UploadController { TokenUser tokenUser = getTokenUser(request); Map data = new HashMap(2); String md5 = DigestUtils.md5DigestAsHex(multipartFile.getInputStream()); - String fileUrl = forestFileService.getFileUrlByMd5(md5); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); if (StringUtils.isNotEmpty(fileUrl)) { data.put("url", fileUrl); return GlobalResultGenerator.genSuccessResult(data); @@ -180,7 +180,7 @@ public class UploadController { try (InputStream in = multipartFiles[i].getInputStream(); OutputStream out = Files.newOutputStream(saveFile.toPath())) { String md5 = DigestUtils.md5DigestAsHex(in); - String fileUrl = forestFileService.getFileUrlByMd5(md5); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); if (StringUtils.isNotEmpty(fileUrl)) { successMap.put(orgName, fileUrl); continue; @@ -235,12 +235,9 @@ public class UploadController { @PostMapping("/file/link") @Transactional(rollbackFor = Exception.class) - public GlobalResult linkToImageUrl(@RequestBody LinkToImageUrlDTO linkToImageUrlDTO) throws IOException, BaseApiException { - //todo 无法获取当前登录用户 -// User user = UserUtils.getCurrentUserByToken(); -// if (Objects.isNull(user)) { -// throw new BaseApiException(ErrorCode.INVALID_TOKEN); -// } + public GlobalResult linkToImageUrl(@RequestBody LinkToImageUrlDTO linkToImageUrlDTO, HttpServletRequest request) throws IOException, BaseApiException { + + TokenUser tokenUser = getTokenUser(request); String url = linkToImageUrlDTO.getUrl(); URL link = new URL(url); HttpURLConnection conn = (HttpURLConnection) link.openConnection(); @@ -255,7 +252,7 @@ public class UploadController { // 获取文件md5值 String md5 = DigestUtils.md5DigestAsHex(inputStream); - String fileUrl = forestFileService.getFileUrlByMd5(md5); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); Map data = new HashMap(2); data.put("originalURL", url); @@ -289,7 +286,7 @@ public class UploadController { //获取自己数组 byte[] getData = readInputStream(inputStream); FileCopyUtils.copy(getData, saveFile); - forestFileService.insertForestFile(fileUrl, savePath, md5, 1); + forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser()); data.put("originalURL", url); data.put("url", fileUrl); } catch (IOException e) { diff --git a/src/main/java/mapper/ForestFileMapper.xml b/src/main/java/mapper/ForestFileMapper.xml index 8b37b3c..d9dcd7a 100644 --- a/src/main/java/mapper/ForestFileMapper.xml +++ b/src/main/java/mapper/ForestFileMapper.xml @@ -20,6 +20,7 @@ select file_url from forest_file where md5_value = #{md5Value} + and created_by = #{createdBy} \ No newline at end of file From 487d436b0cb4b4e1c268a74607a484ad2df88962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AF=9B=E6=AF=9B=E8=99=AB?= <1421374934@qq.com> Date: Fri, 14 Jan 2022 11:55:15 +0800 Subject: [PATCH 2/3] :bug: fixed uploadService error token --- .../com/rymcu/forest/entity/ForestFile.java | 11 ++ .../rymcu/forest/mapper/ForestFileMapper.java | 9 +- .../forest/service/ForestFileService.java | 7 +- .../service/impl/ForestFileServiceImpl.java | 11 +- .../java/com/rymcu/forest/util/FileUtils.java | 5 +- .../web/api/common/UploadController.java | 120 ++++++++++-------- src/main/java/mapper/ForestFileMapper.xml | 7 +- 7 files changed, 104 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/rymcu/forest/entity/ForestFile.java b/src/main/java/com/rymcu/forest/entity/ForestFile.java index d2c3f4d..58a8dfa 100644 --- a/src/main/java/com/rymcu/forest/entity/ForestFile.java +++ b/src/main/java/com/rymcu/forest/entity/ForestFile.java @@ -23,6 +23,17 @@ public class ForestFile { @Column(name = "id") private Long id; + /** + * 文件大小 + */ + @Column(name = "file_size") + private long fileSize; + + /** + * 文件类型-文件后缀 + */ + @Column(name = "file_type") + private String fileType; /** * 访问路径 */ diff --git a/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java b/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java index 327f217..96810cd 100644 --- a/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/ForestFileMapper.java @@ -15,9 +15,10 @@ public interface ForestFileMapper extends Mapper { * * @param md5Value md5值 * @param createdBy 创建人 - * @return + * @param createdBy 创建人 + * @param fileType 文件类型 */ - String getFileUrlByMd5(@Param("md5Value") String md5Value, @Param("createdBy") long createdBy); + String getFileUrlByMd5(@Param("md5Value") String md5Value, @Param("createdBy") long createdBy, @Param("fileType") String fileType); /** * 插入文件对象 @@ -26,8 +27,10 @@ public interface ForestFileMapper extends Mapper { * @param filePath 上传路径 * @param md5Value md5值 * @param createdBy 创建人 + * @param fileSize 文件大小 + * @param fileType 文件类型 * @return */ - int insertForestFile(@Param("fileUrl") String fileUrl, @Param("filePath") String filePath, @Param("md5Value") String md5Value, @Param("createdBy") long createdBy); + int insertForestFile(@Param("fileUrl") String fileUrl, @Param("filePath") String filePath, @Param("md5Value") String md5Value, @Param("createdBy") long createdBy, @Param("fileSize") long fileSize, @Param("fileType") String fileType); } diff --git a/src/main/java/com/rymcu/forest/service/ForestFileService.java b/src/main/java/com/rymcu/forest/service/ForestFileService.java index 5459d86..ba48900 100644 --- a/src/main/java/com/rymcu/forest/service/ForestFileService.java +++ b/src/main/java/com/rymcu/forest/service/ForestFileService.java @@ -17,9 +17,10 @@ public interface ForestFileService extends Service { * * @param md5Value md5值 * @param createdBy 用户id + * @param fileType 文件类型 * @return */ - String getFileUrlByMd5(String md5Value, long createdBy); + String getFileUrlByMd5(String md5Value, long createdBy, String fileType); /** * 插入文件对象 @@ -28,7 +29,9 @@ public interface ForestFileService extends Service { * @param filePath 上传路径 * @param md5Value md5值 * @param createdBy 创建人 + * @param fileSize 文件大小 + * @param fileType 文件类型 * @return */ - int insertForestFile(String fileUrl, String filePath, String md5Value, long createdBy); + int insertForestFile(String fileUrl, String filePath, String md5Value, long createdBy, long fileSize, String fileType); } diff --git a/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java index 4f178f9..9354b19 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ForestFileServiceImpl.java @@ -24,11 +24,12 @@ public class ForestFileServiceImpl extends AbstractService implement * * @param md5Value md5值 * @param createdBy 用户id + * @param fileType 文件类型 * @return */ @Override - public String getFileUrlByMd5(String md5Value, long createdBy) { - return forestFileMapper.getFileUrlByMd5(md5Value, createdBy); + public String getFileUrlByMd5(String md5Value, long createdBy, String fileType) { + return forestFileMapper.getFileUrlByMd5(md5Value, createdBy, fileType); } /** @@ -38,10 +39,12 @@ public class ForestFileServiceImpl extends AbstractService implement * @param filePath 上传路径 * @param md5Value md5值 * @param createdBy 创建人 + * @param fileSize 文件大小 + * @param fileType 文件类型 * @return */ @Override - public int insertForestFile(String fileUrl, String filePath, String md5Value, long createdBy) { - return forestFileMapper.insertForestFile(fileUrl, filePath, md5Value, createdBy); + public int insertForestFile(String fileUrl, String filePath, String md5Value, long createdBy, long fileSize, String fileType) { + return forestFileMapper.insertForestFile(fileUrl, filePath, md5Value, createdBy, fileSize, fileType); } } diff --git a/src/main/java/com/rymcu/forest/util/FileUtils.java b/src/main/java/com/rymcu/forest/util/FileUtils.java index 61ee8ab..696c30b 100644 --- a/src/main/java/com/rymcu/forest/util/FileUtils.java +++ b/src/main/java/com/rymcu/forest/util/FileUtils.java @@ -18,7 +18,7 @@ public class FileUtils { private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); /** - * 获取文件扩展名 + * 获取文件扩展名,带. * * @param filename * @return @@ -31,6 +31,7 @@ public class FileUtils { * 获取文件扩展名 * * @param filename + * @param defExt 默认文件后缀名, 带. * @return */ public static String getExtend(String filename, String defExt) { @@ -41,7 +42,7 @@ public class FileUtils { int i = filename.lastIndexOf('.'); if ((i > 0) && (i < (filename.length() - 1))) { - String result = filename.substring(i + 1).toLowerCase(); + String result = filename.substring(i).toLowerCase(); if (result.contains("?")) { return result.split("\\?")[0]; } diff --git a/src/main/java/com/rymcu/forest/web/api/common/UploadController.java b/src/main/java/com/rymcu/forest/web/api/common/UploadController.java index 2495184..437ff25 100644 --- a/src/main/java/com/rymcu/forest/web/api/common/UploadController.java +++ b/src/main/java/com/rymcu/forest/web/api/common/UploadController.java @@ -42,8 +42,7 @@ public class UploadController { private final static String UPLOAD_URL = "/api/upload/file/batch"; private final static String LINK_TO_IMAGE_URL = "/api/upload/file/link"; - private static Environment env = SpringContextHolder.getBean(Environment.class); - + private static final Environment env = SpringContextHolder.getBean(Environment.class); @Resource private ForestFileService forestFileService; @@ -120,8 +119,15 @@ public class UploadController { } TokenUser tokenUser = getTokenUser(request); Map data = new HashMap(2); + + if (multipartFile.getSize() == 0) { + data.put("message", "上传失败!"); + return GlobalResultGenerator.genSuccessResult(data); + } String md5 = DigestUtils.md5DigestAsHex(multipartFile.getInputStream()); - String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); + String orgName = multipartFile.getOriginalFilename(); + String fileType = FileUtils.getExtend(orgName); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser(), fileType); if (StringUtils.isNotEmpty(fileUrl)) { data.put("url", fileUrl); return GlobalResultGenerator.genSuccessResult(data); @@ -137,15 +143,15 @@ public class UploadController { String localPath = Utils.getProperty("resource.file-path") + "/" + typePath + "/"; - String orgName = multipartFile.getOriginalFilename(); - String fileName = System.currentTimeMillis() + "." + FileUtils.getExtend(orgName).toLowerCase(); + + String fileName = System.currentTimeMillis() + fileType; String savePath = file.getPath() + File.separator + fileName; fileUrl = localPath + fileName; File saveFile = new File(savePath); try { FileCopyUtils.copy(multipartFile.getBytes(), saveFile); - forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser()); + forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser(), multipartFile.getSize(), fileType); data.put("url", fileUrl); } catch (IOException e) { data.put("message", "上传失败!"); @@ -174,21 +180,25 @@ public class UploadController { for (int i = 0, len = multipartFiles.length; i < len; i++) { MultipartFile multipartFile = multipartFiles[i]; String orgName = multipartFile.getOriginalFilename(); - String fileName = System.currentTimeMillis() + "." + FileUtils.getExtend(orgName).toLowerCase(); + + if (multipartFile.getSize() == 0) { + errFiles.add(orgName); + continue; + } + String fileType = FileUtils.getExtend(orgName); + String fileName = System.currentTimeMillis() + fileType; String savePath = file.getPath() + File.separator + fileName; File saveFile = new File(savePath); - try (InputStream in = multipartFiles[i].getInputStream(); - OutputStream out = Files.newOutputStream(saveFile.toPath())) { + try (InputStream in = multipartFiles[i].getInputStream(); OutputStream out = Files.newOutputStream(saveFile.toPath())) { String md5 = DigestUtils.md5DigestAsHex(in); - String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser(), fileType); if (StringUtils.isNotEmpty(fileUrl)) { successMap.put(orgName, fileUrl); continue; } - fileUrl = localPath + fileName; FileCopyUtils.copy(in, out); - forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser()); + forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser(), multipartFile.getSize(), fileType); successMap.put(orgName, localPath + fileName); } catch (IOException e) { errFiles.add(orgName); @@ -246,53 +256,57 @@ public class UploadController { //防止屏蔽程序抓取而返回403错误 conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"); conn.setRequestProperty("referer", ""); - - //得到输入流 - InputStream inputStream = conn.getInputStream(); - - // 获取文件md5值 - String md5 = DigestUtils.md5DigestAsHex(inputStream); - String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser()); - Map data = new HashMap(2); - data.put("originalURL", url); + //得到输入流 + try (InputStream inputStream = conn.getInputStream()) { + //获取自己数组 + byte[] getData = readInputStream(inputStream); + if (getData.length == 0) { + data.put("message", "文件为空!"); + return GlobalResultGenerator.genSuccessResult(data); + } - if (StringUtils.isNotEmpty(fileUrl)) { + // 获取文件md5值 + String md5 = DigestUtils.md5DigestAsHex(inputStream); + String fileType = FileUtils.getExtend(url); + String fileUrl = forestFileService.getFileUrlByMd5(md5, tokenUser.getIdUser(), fileType); + + data.put("originalURL", url); + + if (StringUtils.isNotEmpty(fileUrl)) { + data.put("url", fileUrl); + return GlobalResultGenerator.genSuccessResult(data); + } + + Integer type = linkToImageUrlDTO.getType(); + if (Objects.isNull(type)) { + type = 1; + } + String typePath = getTypePath(type); + //图片存储路径 + String ctxHeadPicPath = env.getProperty("resource.pic-path"); + String dir = ctxHeadPicPath + "/" + typePath; + File file = new File(dir); + if (!file.exists()) { + file.mkdirs();// 创建文件根目录 + } + + String fileName = System.currentTimeMillis() + fileType; + fileUrl = Utils.getProperty("resource.file-path") + "/" + typePath + "/" + fileName; + + String savePath = file.getPath() + File.separator + fileName; + File saveFile = new File(savePath); + + FileCopyUtils.copy(getData, saveFile); + forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser(), getData.length, fileType); + data.put("originalURL", url); data.put("url", fileUrl); return GlobalResultGenerator.genSuccessResult(data); + } catch (IOException e) { + data.put("message", "上传失败"); + return GlobalResultGenerator.genSuccessResult(data); } - Integer type = linkToImageUrlDTO.getType(); - if (Objects.isNull(type)) { - type = 1; - } - String typePath = getTypePath(type); - //图片存储路径 - String ctxHeadPicPath = env.getProperty("resource.pic-path"); - String dir = ctxHeadPicPath + "/" + typePath; - File file = new File(dir); - if (!file.exists()) { - file.mkdirs();// 创建文件根目录 - } - - - String fileName = System.currentTimeMillis() + "." + FileUtils.getExtend(url); - fileUrl = Utils.getProperty("resource.file-path") + "/" + typePath + "/" + fileName; - - String savePath = file.getPath() + File.separator + fileName; - - File saveFile = new File(savePath); - try { - //获取自己数组 - byte[] getData = readInputStream(inputStream); - FileCopyUtils.copy(getData, saveFile); - forestFileService.insertForestFile(fileUrl, savePath, md5, tokenUser.getIdUser()); - data.put("originalURL", url); - data.put("url", fileUrl); - } catch (IOException e) { - data.put("message", "上传失败!"); - } - return GlobalResultGenerator.genSuccessResult(data); } diff --git a/src/main/java/mapper/ForestFileMapper.xml b/src/main/java/mapper/ForestFileMapper.xml index d9dcd7a..7047c34 100644 --- a/src/main/java/mapper/ForestFileMapper.xml +++ b/src/main/java/mapper/ForestFileMapper.xml @@ -3,6 +3,8 @@ + + @@ -12,8 +14,8 @@ - insert into forest_file (md5_value, file_path, file_url, created_time, created_by) - values (#{md5Value}, #{filePath}, #{fileUrl}, sysdate(), #{createdBy}) + insert into forest_file (md5_value, file_path, file_url, created_time, created_by, file_size, file_type) + values (#{md5Value}, #{filePath}, #{fileUrl}, sysdate(), #{createdBy}, #{fileSize}, #{fileType}) \ No newline at end of file From e137a6267be38e6670f5a56cd66c288aa6cee772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AF=9B=E6=AF=9B=E8=99=AB?= <1421374934@qq.com> Date: Fri, 14 Jan 2022 11:56:30 +0800 Subject: [PATCH 3/3] :bug: forest_file.sql --- src/main/resources/static/forest.sql | 343 +++++++++++++-------------- 1 file changed, 163 insertions(+), 180 deletions(-) diff --git a/src/main/resources/static/forest.sql b/src/main/resources/static/forest.sql index b227878..a0e4b18 100644 --- a/src/main/resources/static/forest.sql +++ b/src/main/resources/static/forest.sql @@ -1,39 +1,39 @@ -create database forest default character set utf8mb4 collate utf8mb4_unicode_ci; +create +database forest default character set utf8mb4 collate utf8mb4_unicode_ci; -use forest; +use +forest; create table forest_article ( id bigint auto_increment comment '主键' primary key, - article_title varchar(128) null comment '文章标题', - article_thumbnail_url varchar(128) null comment '文章缩略图', - article_author_id bigint null comment '文章作者id', + article_title varchar(128) null comment '文章标题', + article_thumbnail_url varchar(128) null comment '文章缩略图', + article_author_id bigint null comment '文章作者id', article_type char default '0' null comment '文章类型', - article_tags varchar(128) null comment '文章标签', - article_view_count int default 1 null comment '浏览总数', - article_preview_content varchar(256) null comment '预览内容', - article_comment_count int default 0 null comment '评论总数', - article_permalink varchar(128) null comment '文章永久链接', - article_link varchar(32) null comment '站内链接', - created_time datetime null comment '创建时间', - updated_time datetime null comment '更新时间', + article_tags varchar(128) null comment '文章标签', + article_view_count int default 1 null comment '浏览总数', + article_preview_content varchar(256) null comment '预览内容', + article_comment_count int default 0 null comment '评论总数', + article_permalink varchar(128) null comment '文章永久链接', + article_link varchar(32) null comment '站内链接', + created_time datetime null comment '创建时间', + updated_time datetime null comment '更新时间', article_perfect char default '0' null comment '0:非优选1:优选', article_status char default '0' null comment '文章状态', - article_thumbs_up_count int default 0 null comment '点赞总数', - article_sponsor_count int default 0 null comment '赞赏总数' -) - comment ' ' collate = utf8mb4_unicode_ci; + article_thumbs_up_count int default 0 null comment '点赞总数', + article_sponsor_count int default 0 null comment '赞赏总数' +) comment ' ' collate = utf8mb4_unicode_ci; create table forest_article_content ( - id_article bigint not null comment '主键', - article_content text null comment '文章内容原文', - article_content_html text null comment '文章内容Html', + id_article bigint not null comment '主键', + article_content text null comment '文章内容原文', + article_content_html text null comment '文章内容Html', created_time datetime null comment '创建时间', updated_time datetime null comment '更新时间' -) - comment ' ' collate = utf8mb4_unicode_ci; +) comment ' ' collate = utf8mb4_unicode_ci; create index forest_article_content_id_article_index on forest_article_content (id_article); @@ -42,80 +42,74 @@ create table forest_article_thumbs_up ( id bigint auto_increment comment '主键' primary key, - id_article bigint null comment '文章表主键', - id_user bigint null comment '用户表主键', + id_article bigint null comment '文章表主键', + id_user bigint null comment '用户表主键', thumbs_up_time datetime null comment '点赞时间' -) - comment '文章点赞表 '; +) comment '文章点赞表 '; create table forest_bank ( id bigint auto_increment comment '主键' primary key, - bank_name varchar(64) null comment '银行名称', - bank_owner bigint null comment '银行负责人', + bank_name varchar(64) null comment '银行名称', + bank_owner bigint null comment '银行负责人', bank_description varchar(512) null comment '银行描述', - created_by bigint null comment '创建人', - created_time datetime null comment '创建时间' -) - comment '银行表 '; + created_by bigint null comment '创建人', + created_time datetime null comment '创建时间' +) comment '银行表 '; create table forest_bank_account ( id bigint auto_increment comment '主键' primary key, - id_bank bigint null comment '所属银行', - bank_account varchar(32) null comment '银行账户', - account_balance decimal(32, 8) null comment '账户余额', - account_owner bigint null comment '账户所有者', - created_time datetime null comment '创建时间', + id_bank bigint null comment '所属银行', + bank_account varchar(32) null comment '银行账户', + account_balance decimal(32, 8) null comment '账户余额', + account_owner bigint null comment '账户所有者', + created_time datetime null comment '创建时间', account_type char default '0' null comment '0: 普通账户 1: 银行账户' -) - comment '银行账户表 '; +) comment '银行账户表 '; create table forest_comment ( id bigint auto_increment comment '主键' primary key, - comment_content text null comment '评论内容', - comment_author_id bigint null comment '作者 id', - comment_article_id bigint null comment '文章 id', - comment_sharp_url varchar(256) null comment '锚点 url', - comment_original_comment_id bigint null comment '父评论 id', + comment_content text null comment '评论内容', + comment_author_id bigint null comment '作者 id', + comment_article_id bigint null comment '文章 id', + comment_sharp_url varchar(256) null comment '锚点 url', + comment_original_comment_id bigint null comment '父评论 id', comment_status char default '0' null comment '状态', - comment_ip varchar(128) null comment '评论 IP', - comment_ua varchar(512) null comment 'User-Agent', - comment_anonymous char null comment '0:公开回帖,1:匿名回帖', - comment_reply_count int null comment '回帖计数', - comment_visible char null comment '0:所有人可见,1:仅楼主和自己可见', - created_time datetime null comment '创建时间' -) - comment '评论表 ' collate = utf8mb4_unicode_ci; + comment_ip varchar(128) null comment '评论 IP', + comment_ua varchar(512) null comment 'User-Agent', + comment_anonymous char null comment '0:公开回帖,1:匿名回帖', + comment_reply_count int null comment '回帖计数', + comment_visible char null comment '0:所有人可见,1:仅楼主和自己可见', + created_time datetime null comment '创建时间' +) comment '评论表 ' collate = utf8mb4_unicode_ci; create table forest_currency_issue ( id bigint auto_increment comment '主键' primary key, issue_value decimal(32, 8) null comment '发行数额', - created_by bigint null comment '发行人', - created_time datetime null comment '发行时间' -) - comment '货币发行表 '; + created_by bigint null comment '发行人', + created_time datetime null comment '发行时间' +) comment '货币发行表 '; create table forest_currency_rule ( id bigint auto_increment comment '主键' primary key, - rule_name varchar(128) null comment '规则名称', - rule_sign varchar(64) null comment '规则标志(与枚举变量对应)', - rule_description varchar(1024) null comment '规则描述', - money decimal(32, 8) null comment '金额', + rule_name varchar(128) null comment '规则名称', + rule_sign varchar(64) null comment '规则标志(与枚举变量对应)', + rule_description varchar(1024) null comment '规则描述', + money decimal(32, 8) null comment '金额', award_status char default '0' null comment '奖励(0)/消耗(1)状态', - maximum_money decimal(32, 8) null comment '上限金额', - repeat_days int default 0 null comment '重复(0: 不重复,单位:天)', + maximum_money decimal(32, 8) null comment '上限金额', + repeat_days int default 0 null comment '重复(0: 不重复,单位:天)', status char default '0' null comment '状态' -) - comment '货币规则表 '; +) comment '货币规则表 '; create table forest_follow ( @@ -123,36 +117,33 @@ create table forest_follow primary key, follower_id bigint null comment '关注者 id', following_id bigint null comment '关注数据 id', - following_type char null comment '0:用户,1:标签,2:帖子收藏,3:帖子关注' -) - comment '关注表 ' collate = utf8mb4_unicode_ci; + following_type char null comment '0:用户,1:标签,2:帖子收藏,3:帖子关注' +) comment '关注表 ' collate = utf8mb4_unicode_ci; create table forest_notification ( id bigint auto_increment comment '主键' primary key, - id_user bigint null comment '用户id', - data_type char null comment '数据类型', - data_id bigint null comment '数据id', + id_user bigint null comment '用户id', + data_type char null comment '数据类型', + data_id bigint null comment '数据id', has_read char default '0' null comment '是否已读', - data_summary varchar(256) null comment '数据摘要', - created_time datetime null comment '创建时间' -) - comment '通知表 ' collate = utf8mb4_unicode_ci; + data_summary varchar(256) null comment '数据摘要', + created_time datetime null comment '创建时间' +) comment '通知表 ' collate = utf8mb4_unicode_ci; create table forest_portfolio ( id bigint auto_increment comment '主键' primary key, - portfolio_head_img_url varchar(500) null comment '作品集头像', - portfolio_title varchar(32) null comment '作品集名称', - portfolio_author_id bigint null comment '作品集作者', + portfolio_head_img_url varchar(500) null comment '作品集头像', + portfolio_title varchar(32) null comment '作品集名称', + portfolio_author_id bigint null comment '作品集作者', portfolio_description varchar(1024) null comment '作品集介绍', - created_time datetime null comment '创建时间', - updated_time datetime null comment '更新时间', + created_time datetime null comment '创建时间', + updated_time datetime null comment '更新时间', portfolio_description_html varchar(1024) null comment ' 作品集介绍HTML' -) - comment '作品集表' collate = utf8mb4_unicode_ci; +) comment '作品集表' collate = utf8mb4_unicode_ci; create table forest_portfolio_article ( @@ -160,67 +151,62 @@ create table forest_portfolio_article primary key, id_portfolio bigint null comment '作品集表主键', id_article bigint null comment '文章表主键', - sort_no int null comment '排序号' -) - comment '作品集与文章关系表' collate = utf8mb4_unicode_ci; + sort_no int null comment '排序号' +) comment '作品集与文章关系表' collate = utf8mb4_unicode_ci; create table forest_role ( id bigint auto_increment comment '主键' primary key, - name varchar(32) null comment '名称', - input_code varchar(32) null comment '拼音码', + name varchar(32) null comment '名称', + input_code varchar(32) null comment '拼音码', status char default '0' null comment '状态', - created_time datetime null comment '创建时间', - updated_time datetime null comment '更新时间', - weights tinyint default 0 null comment '权重,数值越小权限越大;0:无权限' -) - comment ' ' collate = utf8mb4_unicode_ci; + created_time datetime null comment '创建时间', + updated_time datetime null comment '更新时间', + weights tinyint default 0 null comment '权重,数值越小权限越大;0:无权限' +) comment ' ' collate = utf8mb4_unicode_ci; create table forest_sponsor ( id bigint auto_increment comment '主键' primary key, - data_type char null comment '数据类型', - data_id bigint null comment '数据主键', - sponsor bigint null comment '赞赏人', - sponsorship_time datetime null comment '赞赏日期', + data_type char null comment '数据类型', + data_id bigint null comment '数据主键', + sponsor bigint null comment '赞赏人', + sponsorship_time datetime null comment '赞赏日期', sponsorship_money decimal(32, 8) null comment '赞赏金额' -) - comment '赞赏表 '; +) comment '赞赏表 '; create table forest_tag ( id bigint auto_increment comment '主键' primary key, - tag_title varchar(32) null comment '标签名', - tag_icon_path varchar(512) null comment '标签图标', - tag_uri varchar(128) null comment '标签uri', - tag_description text null comment '描述', - tag_view_count int default 0 null comment '浏览量', - tag_article_count int default 0 null comment '关联文章总数', - tag_ad char null comment '标签广告', - tag_show_side_ad char null comment '是否显示全站侧边栏广告', - created_time datetime null comment '创建时间', - updated_time datetime null comment '更新时间', + tag_title varchar(32) null comment '标签名', + tag_icon_path varchar(512) null comment '标签图标', + tag_uri varchar(128) null comment '标签uri', + tag_description text null comment '描述', + tag_view_count int default 0 null comment '浏览量', + tag_article_count int default 0 null comment '关联文章总数', + tag_ad char null comment '标签广告', + tag_show_side_ad char null comment '是否显示全站侧边栏广告', + created_time datetime null comment '创建时间', + updated_time datetime null comment '更新时间', tag_status char default '0' null comment '标签状态', tag_reservation char default '0' null comment '保留标签', - tag_description_html text null -) - comment '标签表 ' collate = utf8mb4_unicode_ci; + tag_description_html text null +) comment '标签表 ' collate = utf8mb4_unicode_ci; create table forest_tag_article ( id bigint auto_increment comment '主键' primary key, - id_tag bigint null comment '标签 id', - id_article varchar(32) null comment '帖子 id', + id_tag bigint null comment '标签 id', + id_article varchar(32) null comment '帖子 id', article_comment_count int default 0 null comment '帖子评论计数 0', article_perfect int default 0 null comment '0:非优选1:优选 0', - created_time datetime null comment '创建时间', - updated_time datetime null comment '更新时间' -) - comment '标签 - 帖子关联表 ' collate = utf8mb4_unicode_ci; + created_time datetime null comment '创建时间', + updated_time datetime null comment '更新时间' +) comment '标签 - 帖子关联表 ' collate = utf8mb4_unicode_ci; create index forest_tag_article_id_tag_index on forest_tag_article (id_tag); @@ -229,31 +215,29 @@ create table forest_topic ( id bigint auto_increment comment '主键' primary key, - topic_title varchar(32) null comment '专题标题', - topic_uri varchar(32) null comment '专题路径', - topic_description text null comment '专题描述', - topic_type varchar(32) null comment '专题类型', - topic_sort int default 10 null comment '专题序号 10', - topic_icon_path varchar(128) null comment '专题图片路径', + topic_title varchar(32) null comment '专题标题', + topic_uri varchar(32) null comment '专题路径', + topic_description text null comment '专题描述', + topic_type varchar(32) null comment '专题类型', + topic_sort int default 10 null comment '专题序号 10', + topic_icon_path varchar(128) null comment '专题图片路径', topic_nva char default '0' null comment '0:作为导航1:不作为导航 0', - topic_tag_count int default 0 null comment '专题下标签总数 0', + topic_tag_count int default 0 null comment '专题下标签总数 0', topic_status char default '0' null comment '0:正常1:禁用 0', - created_time datetime null comment '创建时间', - updated_time datetime null comment '更新时间', - topic_description_html text null comment '专题描述 Html' -) - comment '主题表' collate = utf8mb4_unicode_ci; + created_time datetime null comment '创建时间', + updated_time datetime null comment '更新时间', + topic_description_html text null comment '专题描述 Html' +) comment '主题表' collate = utf8mb4_unicode_ci; create table forest_topic_tag ( id bigint auto_increment comment '主键' primary key, - id_topic bigint null comment '专题id', - id_tag bigint null comment '标签id', + id_topic bigint null comment '专题id', + id_tag bigint null comment '标签id', created_time datetime null comment '创建时间', updated_time datetime null comment '更新时间' -) - comment '专题- 标签关联表 ' collate = utf8mb4_unicode_ci; +) comment '专题- 标签关联表 ' collate = utf8mb4_unicode_ci; create index forest_topic_tag_id_topic_index on forest_topic_tag (id_topic); @@ -262,67 +246,62 @@ create table forest_transaction_record ( id bigint auto_increment comment '交易主键' primary key, - transaction_no varchar(32) null comment '交易流水号', - funds varchar(32) null comment '款项', - form_bank_account varchar(32) null comment '交易发起方', - to_bank_account varchar(32) null comment '交易收款方', - money decimal(32, 8) null comment '交易金额', + transaction_no varchar(32) null comment '交易流水号', + funds varchar(32) null comment '款项', + form_bank_account varchar(32) null comment '交易发起方', + to_bank_account varchar(32) null comment '交易收款方', + money decimal(32, 8) null comment '交易金额', transaction_type char default '0' null comment '交易类型', - transaction_time datetime null comment '交易时间' -) - comment '交易记录表 '; + transaction_time datetime null comment '交易时间' +) comment '交易记录表 '; create table forest_user ( id bigint auto_increment comment '用户ID' primary key, - account varchar(32) null comment '账号', - password varchar(64) not null comment '密码', - nickname varchar(128) null comment '昵称', - real_name varchar(32) null comment '真实姓名', + account varchar(32) null comment '账号', + password varchar(64) not null comment '密码', + nickname varchar(128) null comment '昵称', + real_name varchar(32) null comment '真实姓名', sex char default '0' null comment '性别', avatar_type char default '0' null comment '头像类型', - avatar_url varchar(512) null comment '头像路径', - email varchar(64) null comment '邮箱', - phone varchar(11) null comment '电话', + avatar_url varchar(512) null comment '头像路径', + email varchar(64) null comment '邮箱', + phone varchar(11) null comment '电话', status char default '0' null comment '状态', - created_time datetime null comment '创建时间', - updated_time datetime null comment '更新时间', - last_login_time datetime null comment '最后登录时间', - signature varchar(128) null comment '签名' -) - comment ' ' collate = utf8mb4_unicode_ci; + created_time datetime null comment '创建时间', + updated_time datetime null comment '更新时间', + last_login_time datetime null comment '最后登录时间', + signature varchar(128) null comment '签名' +) comment ' ' collate = utf8mb4_unicode_ci; create table forest_user_extend ( - id_user bigint not null comment '用户表主键', - github varchar(64) null comment 'github', - weibo varchar(32) null comment '微博', - weixin varchar(32) null comment '微信', - qq varchar(32) null comment 'qq', + id_user bigint not null comment '用户表主键', + github varchar(64) null comment 'github', + weibo varchar(32) null comment '微博', + weixin varchar(32) null comment '微信', + qq varchar(32) null comment 'qq', blog varchar(500) null comment '博客' -) - comment '用户扩展表 '; +) comment '用户扩展表 '; create table forest_user_role ( - id_user bigint not null comment '用户表主键', - id_role bigint not null comment '角色表主键', + id_user bigint not null comment '用户表主键', + id_role bigint not null comment '角色表主键', created_time datetime null comment '创建时间' -) - comment ' ' collate = utf8mb4_unicode_ci; +) comment ' ' collate = utf8mb4_unicode_ci; create table forest_user_tag ( id bigint auto_increment comment '主键' primary key, - id_user bigint null comment '用户 id', + id_user bigint null comment '用户 id', id_tag varchar(32) null comment '标签 id', - type char null comment '0:创建者,1:帖子使用,2:用户自评标签', - created_time datetime null comment '创建时间', - updated_time datetime null comment '更新时间' -) - comment '用户 - 标签关联表 ' collate = utf8mb4_unicode_ci; + type char null comment '0:创建者,1:帖子使用,2:用户自评标签', + created_time datetime null comment '创建时间', + updated_time datetime null comment '更新时间' +) comment '用户 - 标签关联表 ' collate = utf8mb4_unicode_ci; create table forest_visit ( @@ -331,14 +310,13 @@ create table forest_visit visit_url varchar(256) null comment '浏览链接', visit_ip varchar(128) null comment 'IP', visit_ua varchar(512) null comment 'User-Agent', - visit_city varchar(32) null comment '城市', + visit_city varchar(32) null comment '城市', visit_device_id varchar(256) null comment '设备唯一标识', - visit_user_id bigint null comment '浏览者 id', + visit_user_id bigint null comment '浏览者 id', visit_referer_url varchar(256) null comment '上游链接', - created_time datetime null comment '创建时间', - expired_time datetime null comment '过期时间' -) - comment '浏览表' collate = utf8mb4_unicode_ci; + created_time datetime null comment '创建时间', + expired_time datetime null comment '过期时间' +) comment '浏览表' collate = utf8mb4_unicode_ci; create table forest_lucene_user_dic ( @@ -375,9 +353,14 @@ CREATE TABLE `forest_file` `md5_value` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '文件md5值', `file_path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '文件上传路径', `file_url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '网络访问路径', - `created_time` datetime DEFAULT NULL COMMENT '创建时间', - `updated_time` datetime DEFAULT NULL COMMENT '更新时间', + `created_time` datetime DEFAULT NULL COMMENT '创建时间', + `updated_time` datetime DEFAULT NULL COMMENT '更新时间', `created_by` int(11) DEFAULT NULL COMMENT '创建人', + `file_size` int(11) DEFAULT NULL COMMENT '文件大小', + `file_type` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '文件类型', PRIMARY KEY (`id`), - UNIQUE KEY `index_md5_value` (`md5_value`) -) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci comment '文件上传记录表'; \ No newline at end of file + KEY `index_md5_value` (`md5_value`) USING BTREE, + KEY `index_created_by` (`created_by`), + KEY `inddex_md5_value_created_by` (`md5_value`,`created_by`), + KEY `index_file_type` (`file_type`) +) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='文件上传记录表'; \ No newline at end of file