42 Commits

Author SHA1 Message Date
5b54e739d4 Merge github.com:201206030/novel 2022-08-04 23:58:33 +08:00
00acb47ec0 build: 3.3.0 发布 2022-08-04 23:57:51 +08:00
xxy
ada179053c Update README.md 2022-08-04 12:36:29 +08:00
xxy
1614e79106 Update README.md 2022-08-03 19:11:04 +08:00
xxy
8b43851955 Update README.md 2022-07-22 21:16:54 +08:00
xxy
8ba670cebb Update README.md 2022-07-21 22:03:36 +08:00
xxy
657c8a2286 Update README.md 2022-07-15 06:25:44 +08:00
cf4c6b77db Update README.md 2022-07-12 20:03:23 +08:00
6f6183af21 chore: 增加阿里云Maven中央仓库下载源 2022-07-09 20:32:09 +08:00
c3105c5b33 Update README.md 2022-07-08 14:33:23 +08:00
4f7a4f964a build: 依赖版本管理 2022-07-08 08:00:46 +08:00
fd9ce3cb49 docs: Java 样式文件修改 2022-07-08 07:59:24 +08:00
ae7267b605 Update README.md 2022-07-06 00:17:49 +08:00
9600f9c7e6 docs: 优化注释 2022-07-06 00:08:21 +08:00
eea6682870 docs: 优化注释 2022-07-05 23:58:09 +08:00
0890a3295d Merge github.com:201206030/novel 2022-07-02 09:58:19 +08:00
b0294a5b90 chore: git 忽略 .shardingsphere 目录 2022-07-02 09:55:47 +08:00
97b0e40534 Update README.md 2022-07-02 08:59:57 +08:00
5852cc6d26 style: 代码格式化 2022-07-01 06:30:11 +08:00
9b93d90270 style: 代码格式化 2022-06-30 21:34:54 +08:00
6d2fa74237 docs: 修改接口文档 2022-06-30 19:11:02 +08:00
76677ea8b8 Update README.md 2022-06-27 18:51:24 +08:00
e795d26aa5 docs: 接口文档修改 2022-06-27 18:33:44 +08:00
80480bc026 Update README.md 2022-06-27 12:41:13 +08:00
dec50ab0a0 feat: 集成 springdoc-openapi 自动生成 API 文档 2022-06-27 11:17:49 +08:00
c572650107 refactor: 使用类型推断 var 2022-06-23 20:58:38 +08:00
d9202c76fa Update README.md 2022-06-21 08:08:04 +08:00
fdc74bb7da Update README.md 2022-06-21 08:04:16 +08:00
5dceb7ac96 Update README.md 2022-06-21 07:51:29 +08:00
154b009c05 Update README.md 2022-06-21 07:48:12 +08:00
d7a9416c57 perf: LockAspect 优化 2022-06-21 07:33:25 +08:00
57793c4444 Update README.md 2022-06-21 06:44:49 +08:00
9bd95d3f28 feat: Spring AOP + Redisson 实现分布式锁 2022-06-20 13:20:00 +08:00
ac1628aa2a refactor: 使用 @ConfigurationProperties record 2022-06-19 09:53:58 +08:00
8e9f31a240 chore: 增加数据库脚本文件说明 2022-06-10 18:12:21 +08:00
37811bf173 chore: 修改 ShardingSphere-JDBC 的数据迁移脚本名,开启 ShardingSphere-JDBC 功能才需要执行 2022-06-10 17:33:58 +08:00
cfafc6450b chore: 增加 xxl_job 的脚本,开启 xxl-job 功能才需要执行 2022-06-10 17:31:22 +08:00
8199b3d4af docs: update README.md 2022-06-09 11:52:47 +08:00
fc0f3bee1d perf: 增加 Spring Boot Admin 的 SBA Client 配置 2022-06-07 20:57:06 +08:00
925da99d0b perf: Actuator Endpoints 保护 2022-06-07 18:17:08 +08:00
7012b7b8ea docs: update README.md 2022-06-07 08:24:40 +08:00
0a8808b418 build: 集成 Spring Boot Admin,实现应用管理和监控功能 2022-06-06 21:43:31 +08:00
101 changed files with 1560 additions and 706 deletions

1
.gitignore vendored
View File

@ -33,3 +33,4 @@ build/
.vscode/
/logs/
/.shardingsphere/

View File

@ -1,9 +1,15 @@
[![index]( https://s1.ax1x.com/2022/05/17/O5tgbR.png )]( https://curl.qcloud.com/kgMaOjoq )
[![index]( https://youdoc.github.io/img/tencent.jpg )]( https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=736e609d66e0ac4e57813316cec6fd0b&from=console )
<p align="center">
<a href='https://docs.oracle.com/en/java/javase/17'><img alt="Java 17" src="https://img.shields.io/badge/Java%2017-%234479A1.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAABNVBMVEUAAABkmP9ml/9mmf9mmf9lmv9nmf9mmf9mmf9nmP9mmf9mmf9mmv9mmf9mmf9mmf9mmf9mmP9llv9mmf9mmf9mmv9mmf9mmf9mmf9mmf//AABlmf9mmf9km/9mmf9mmf9lmf9mmf9mmf//AABmmf9mmf9mmf9lmv9mmf//AABmmf9mmP9mmf9mmf//AABgl/9mmf//AABmmP//AABmmf//AAD/AABmmf9mmv9mmf//AABnmf//AAD/AAD/AABmmf//AAD/AABlmf9mmf//AABmmf9mmv9mmf//AAD/AAD/AABmmf//AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AABmmf//AAD/AAD/AABsof9mmf//AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AAD/AABmmf//AAB37HanAAAAZXRSTlMAP4CLnb8dtpUP2plK78zEpyoKrGbVbxj334BjRzL7sVA168C8hXlEIwvJYJBXQQahWC8k5M6nW1Q6Myb2ya5yY0gT0rp9dWpSEerm35JtH5l7Xhjnzo2EdATz2dOfiDst8AW1KD5Fo/kAAAl3SURBVHja3Ny7ruIwEAbg/zloU9FEiqJQoCQiEsUh4k4ESNw56H//R1gHlsQk8TnbrcdfS8OIsT2escB/MoEjlnDEfAQ3ZMUDTlgwhRvIIZyQcAcneDzc4QKPDOACj3TjLPHICC7wSMIFR5JOFFxUXDjcQyoXyJeRbpzteyoLyOdR6UO8kMoN8u2pjCGfR+UM8b5IOlE0jlkKId2aigt33YQl+X2UPUu3DYTzqThwrZokLMVXCLfk0xbC9fiUSy8Ye3zpQbYRXyLhha9P0oXqpIpjANGqOGLZd1yfdGKlB3QjsVZ8SyDZiW+55GnCxmMlxE/sPl/8gpULzL52X7DZiDUfBv0g5dnu3+P8exyT9SDmt92t4E36axzDWU4Wc1jtEv0WR5BSOVneUlnffo5jsTpSiexe5MCOmhBN/jKmYvsix2TAWjFBw/D1se2LHBgmrI3v+LQ582UPy2UFa0s0zKd8Omaw3IiabTPIMV8G1nfpVtT08GEx418r2G5Lzbw7q3iwPq1woiaAblJ9ltrf2vpmLQ+huySC7rsD1o74MLrxJbb9LFfmrHndfUbmPqy3/oc4pgKuu196HHfoepLaD48pK8nG8HvAfvcxK8W1ddTLGfHMWFtDd81JihmCBub6KpXUZ+xHrIwNtVcuIbF6rA2hu7Ik5gFKwsqp684r5dXcwtho6E+piHnaFLCStm9ZgqbSO9PWizHfBNSKevUe9xs5JysQz5RZGUkpPZPPQALjtnyCAN+mPbZHWXO3Hd8WxkBiCQ/7A7712/WJpDcPG77dW8eIrNl0tdo3rV1L1gZcrYWHuXZhJGCVLG6G0W1EUlSVMjMce1sKS65hdxsIGaUl18AwZjvwRcxL2cwwL5jxwxrWW/Jp2siex426qeXDaGUSdS/3FUlZx6LPp0O/3WDRWf7OobTv/qYZPxwtH63XO1dkmCrKGR8iPHQnT0rdAfbLYipF2AxwSp39k1Bg1H2rDaRtXMCuu6Y6U3OEBMvul/xj1nKIkHY2rK8FKzFk8Kj4HatH0gCuukwl7eSS1RiqSvcZGkYSX/oXHd2fkCVp/5Nw6yjYj+IyqxS3z72ZoEbdn3bu/HVpMI4D+Gf37S63uXRebSoeKCKoGQl+UyMpouiEIIhP//+fULoOc1/LdFsuev0ssrfu+Tx7ru15HHnmevUpmyeO7x6OTN6HvWH2Xony5OA9Wh+zMmiPuHP/RaSxP4Eserp/2fcys7R7i+d7Jfh1Zv+PrUd7cxCZ6tIj7n1vMNnO8SPQ/cdZrFdRD+9mYSvK7716kIHZrBM8ewOn8myKNn0p78EV+vACTmKQFQW/q6yHkBZ9QvKabxXaVFWAizVzBWYQ8JU6fiMJkDi9Q1u4xdkexGJCEm9hpyrhV7kmJEm3NRd3mJUOMRFgj0fjVxNICkGqGFIbQ0hMNdkkNUrEkELWIFEr/IqAuBkdDr+hdUgaiSEO4uVRLn7DlSBOswnpQES/jaE5xIks4HddiIs+DiruhnR+2UwsiI/Txj02XKqvV+c8J+IWz8IRGwzNYr1f962GcB5Bl/PBgBnhd0wJjhpgqAix4fHAhiNLApzCcGa1ZrVjL/nKjYIH6vNTfj4S4pPDWyiiakrkukfsaVZ7RbtBUvzA5JiXYr2ARyk+NYO0g0A+h3Gy6GLtLYTSCxKazjmMgctRnZoBpzCTqL8hLy/l8CwFV9UoexJGOJGVWN8ecjy5+KXptt0y/pZi+XSQlz0H/pyOobIASVsMm/JkXFyvlgHF01qFYziN7gYNu9iTiZrOCn24QIAhFbLNEDE0hmyzMVSBbGttIk09YQIkQsJQAOmQIRkTDHUhDbWgA8mYpFixFnMGSUiGjl9B8joWIgMJwZALiZtp+AUPiWhhyIfk+bj1Es5jEHMDjpIxJEHyKAyRLfhDrR7lK4jos7/pCN01pIDBr95JHQ9O05+upXYZv3nZhNs4NO50WUgDg3sKucqgS86LVcJrCZHaphPVfIMacBYe4lmIqIYfqxCQjhIeVX6n1EeuaL1sq6pYx1+pSwdR3lK4pRYhNaSCMVB8aj+KrOIXZhXS1OpeGqKyai5gz1DbtbkppE0nLTyTqNnDw4rMIyITVsH0TXi1gH9mZDaaAkTYCmrFFvxFfS/Pq8pJEXzJlh24FUk338I1YEur7oBru4eJynUx55t0l+x5BhznwPUxFuxsWCOmwxnrCH3477//dmT4F3gVFv4BXeThHzB+iSJk39RERAYyz8Md0oDTOQRcHUPFkEtNT8jSkle0qiDSLbgyxE/DXXpVrBK604dDwrBUJLWbMn5TJq+syhF4m3duzucq2kDiqSAYMGIBo5TuEK6Jieejp3A9HLyEWYKrwb7EsyldHa4IKZ6XYnB1T2f9jo9/SKTHBlyjaXCDJ+PsGlyDxWzKQlSJ4jb4OyOOkv/+4LdPLBlrU/5FvWFlcqCO8BYFkeHzUwEi0p6OEJpLroBflP1GpzRc/DLwrCn3Ouv5kgwV5S+fP0OHgLiVpDpuuVKqbVQbQJxmqzbuMHkBUtXDBsSmqZVxh25C2tZ4AzFheQypMqROt2IL0nH/4jYjwsK4bi0av2lC6sj41r67+B0J6SJ2JwlsiEUH91hrFlIyLPJt/ELyYI8Q25jp3aAKSRPkgNsgRmPAFM5H4aFRZUlAMgxdtmkLv8o19IMeWYbzzRi8RZmhGz1PgLiwRIfU1M1PK9YlOFDNvYVLkBYeU29rQYdw4DyOTkzyy67mi2X8mX/LfvsFhV24zNsxV8ejwnW1NqfxwXbPw5AV4FBfWLAzvTYNt9TOG4Fkqtaxr8xRX0JE5UVUDbjY21p+cFPAhI3MFdE/viHfifFOLlJmInmUnEn1WLidt8wlssk0zJMblTEG7rZq1BZw1GzOhHWfgMQIOtGzA5r7kumcAGSHYOHXpiSDoRwBqTAcvdacdOwlRZuc2s7dWKK7qSuF8v4eIcakqUa+V6q1BDhBlXbxq1wesunnQx3tLMYQagcHUxSpBEnqCxAztmTzzAZ/Vlk7kLQW/1JbVmcxHD2Ri6T2soAR5tiBVDjFShnR9TWeXPeaHmvAyQxWn05sSgtXTaJErSG/hRS1xpT/41IKoxumsqtMTWJPSa72xsW8PV8tKUnj2mK9jEe9U/l8zYDUhY8vtIUXU244mqz+9WXFfosYN/hKro5/aNQ2u6sx0bq6afldoqArbc+Dtm/EUeREaGET3n/rbc+4gP+iPgNo04Ue6Gbq9gAAAABJRU5ErkJggg=="></a>
<a href='https://docs.spring.io/spring-boot/docs/3.0.0-SNAPSHOT/reference/html'><img alt="Spring Boot 3" src="https://img.shields.io/badge/Spring%20Boot%203-%23000000.svg?logo=springboot"></a>
<a href='https://staging-cn.vuejs.org'><img alt="Vue 3" src="https://img.shields.io/badge/Vue%203%20-%232b3847.svg?logo=vue.js"></a><br/>
<a href='https://github.com/201206030/novel'><img alt="Github stars" src="https://img.shields.io/github/stars/201206030/novel?logo=github"></a>
<a href='https://github.com/201206030/novel'><img alt="Github forks" src="https://img.shields.io/github/forks/201206030/novel?logo=github"></a>
<a href='https://gitee.com/novel_dev_team/novel'><img alt="Gitee stars" src="https://gitee.com/novel_dev_team/novel/badge/star.svg?theme=gitee"></a>
<a href='https://gitee.com/novel_dev_team/novel'><img alt="Gitee forks" src="https://gitee.com/novel_dev_team/novel/badge/fork.svg?theme=gitee"></a>
<a href="https://github.com/201206030/novel"><img src="https://visitor-badge.glitch.me/badge?page_id=201206030.novel" alt="visitors"></a>
</p>
[![Github stars](https://img.shields.io/github/stars/201206030/novel?logo=github)](https://github.com/201206030/novel)
[![Github forks](https://img.shields.io/github/forks/201206030/novel?logo=github)](https://github.com/201206030/novel)
[![Gitee star](https://gitee.com/novel_dev_team/novel/badge/star.svg?theme=gitee)](https://gitee.com/novel_dev_team/novel)
[![Gitee fork](https://gitee.com/novel_dev_team/novel/badge/fork.svg?theme=gitee)](https://gitee.com/novel_dev_team/novel)
## 项目简介
novel 是一套基于时下**最新** Java 技术栈 Spring Boot 3 + Vue 3 开发的前后端分离的**学习型**小说项目,配备详细的项目教程手把手教你**从零开始**开发上线一个生产级别的 Java 系统,由小说门户系统、作家后台管理系统、平台后台管理系统、爬虫管理系统等多个子系统构成。包括小说推荐、作品检索、小说排行榜、小说阅读、小说评论、充值订阅、新闻发布等功能。
@ -12,7 +18,7 @@ novel 是一套基于时下**最新** Java 技术栈 Spring Boot 3 + Vue 3 开
- 后端项目(更新中):[GitHub](https://github.com/201206030/novel) [码云](https://gitee.com/novel_dev_team/novel)
- 前端项目(更新中):[GitHub](https://github.com/201206030/novel-front-web) [码云](https://gitee.com/novel_dev_team/novel-front-web)
- 线上应用版:[GitHub](https://github.com/201206030/novel-plus) [码云](https://gitee.com/novel_dev_team/novel-plus) [演示地址](http://47.106.243.172:8888/)
- 线上应用版:[GitHub](https://github.com/201206030/novel-plus) [码云](https://gitee.com/novel_dev_team/novel-plus) [演示站点](http://47.106.243.172:8888/)
- 微服务版:[GitHub](https://github.com/201206030/novel-cloud) [码云](https://gitee.com/novel_dev_team/novel-cloud)
## 开发环境
@ -32,7 +38,7 @@ novel 是一套基于时下**最新** Java 技术栈 Spring Boot 3 + Vue 3 开
## 后端技术选型
| 技术 | 版本 | 说明 | 官网 | 学习 |
|:-------------------------------|:--------------:|---------------------| --------------------------------------- |:----------------------------------------------------------------------------------------:|
|---------------------|:--------------:|---------------------| --------------------------------------- |:---------------------------------------------------------------------------------------:|
| Spring Boot | 3.0.0-SNAPSHOT | 容器 + MVC 框架 | https://spring.io/projects/spring-boot | [进入](https://youdoc.github.io/course/novel/11.html) |
| MyBatis | 3.5.9 | ORM 框架 | http://www.mybatis.org | [进入](https://mybatis.org/mybatis-3/zh/index.html) |
| MyBatis-Plus | 3.5.1 | MyBatis 增强工具 | https://baomidou.com/ | [进入](https://baomidou.com/pages/24112f/) |
@ -40,12 +46,15 @@ novel 是一套基于时下**最新** Java 技术栈 Spring Boot 3 + Vue 3 开
| Lombok | 1.18.24 | 简化对象封装工具 | https://github.com/projectlombok/lombok | [进入](https://projectlombok.org/features/all) |
| Caffeine | 3.1.0 | 本地缓存支持 | https://github.com/ben-manes/caffeine | [进入](https://github.com/ben-manes/caffeine/wiki/Home-zh-CN) |
| Redis | 7.0 | 分布式缓存支持 | https://redis.io | [进入](https://redis.io/docs) |
| Redisson | 3.17.4 | 分布式锁实现 | https://github.com/redisson/redisson | [进入](https://github.com/redisson/redisson/wiki/%E7%9B%AE%E5%BD%95) |
| MySQL | 8.0 | 数据库服务 | https://www.mysql.com | [进入](https://docs.oracle.com/en-us/iaas/mysql-database/doc/getting-started.html) |
| ShardingSphere-JDBC | 5.1.1 | 数据库分库分表支持 | https://shardingsphere.apache.org | [进入](https://shardingsphere.apache.org/document/5.1.1/cn/overview) |
| Elasticsearch | 8.2.0 | 搜索引擎服务 | https://www.elastic.co | [进入](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html) |
| RabbitMQ | 3.10.2 | 开源消息中间件 | https://www.rabbitmq.com | [进入](https://www.rabbitmq.com/tutorials/tutorial-one-java.html) |
| XXL-JOB | 2.3.1 | 分布式任务调度平台 | https://www.xuxueli.com/xxl-job | [进入](https://www.xuxueli.com/xxl-job) |
| Sentinel | 1.8.4 | 流量控制组件 | https://github.com/alibaba/Sentinel | [进入](https://github.com/alibaba/Sentinel/wiki/%E4%B8%BB%E9%A1%B5) |
| Springdoc-openapi | 2.0.0-M4-SNAPSHOT | Swagger 3 接口文档自动生成 | https://github.com/springdoc/springdoc-openapi | [进入](https://springdoc.org/) |
| Spring Boot Admin | 3.0.0-M1 | 应用管理和监控 | https://github.com/codecentric/spring-boot-admin | [进入](https://codecentric.github.io/spring-boot-admin/3.0.0-M1) |
| Undertow | 2.2.17.Final | Java 开发的高性能 Web 服务器 | https://undertow.io | [进入](https://undertow.io/documentation.html) |
| Docker | - | 应用容器引擎 | https://www.docker.com/ | - |
| Jenkins | - | 自动化部署工具 | https://github.com/jenkinsci/jenkins | - |
@ -56,10 +65,10 @@ novel 是一套基于时下**最新** Java 技术栈 Spring Boot 3 + Vue 3 开
| 技术 | 版本 | 说明 | 官网 | 学习 |
| :----------------- | :-----: | -------------------------- | --------------------------------------- | :-------------------------------------------------: |
| Vue.js | 3.2.13 | 渐进式 JavaScript 框架 | https://v3.cn.vuejs.org | [进入](https://v3.cn.vuejs.org/guide/introduction.html) |
| Vue Router | 4.0.15 | Vue.js 的官方路由 | https://router.vuejs.org/zh/index.html | [进入](https://router.vuejs.org/zh/guide/) |
| axios | 0.27.2 | 基于 promise 的网络请求库 | https://axios-http.com/zh | [进入](https://axios-http.com/zh/docs/intro) |
| element-plus | 2.2.0 | 基于 Vue 3面向设计师和开发者的组件库 | https://element-plus.org/zh-CN/ | [进入](https://element-plus.org/zh-CN/guide/design.html) |
| Vue.js | 3.2.13 | 渐进式 JavaScript 框架 | https://vuejs.org | [进入](https://staging-cn.vuejs.org/guide/introduction.html) |
| Vue Router | 4.0.15 | Vue.js 的官方路由 | https://router.vuejs.org | [进入](https://router.vuejs.org/zh/guide/) |
| axios | 0.27.2 | 基于 promise 的网络请求库 | https://axios-http.com | [进入](https://axios-http.com/zh/docs/intro) |
| element-plus | 2.2.0 | 基于 Vue 3面向设计师和开发者的组件库 | https://element-plus.org | [进入](https://element-plus.org/zh-CN/guide/design.html) |
## 编码规范
@ -88,6 +97,8 @@ io
| | +- resp -- 接口响应工具及响应数据格式封装
| | +- util -- 通用工具
| |
| +- annotation -- 自定义注解类
| +- aspect -- Spring AOP 切面
| +- auth -- 用户认证授权相关
| +- config -- 业务相关配置
| +- constant -- 业务相关常量
@ -168,6 +179,10 @@ io
![img](https://oscimg.oschina.net/oscnet/up-f849960f4c1303fea77d26e64fc505a7180.png)
11. 接口文档
![img](https://youdoc.github.io/img/novel/SwaggerUI.png)
## 安装步骤
@ -175,7 +190,7 @@ io
- 下载后端源码
```
```bash
git clone https://gitee.com/novel_dev_team/novel.git
```
@ -193,7 +208,7 @@ git clone https://gitee.com/novel_dev_team/novel.git
1. 修改`src/resources/application.yml`配置文件中的数据源配置
```
```yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/novel_test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
@ -201,9 +216,9 @@ git clone https://gitee.com/novel_dev_team/novel.git
password: test123456
```
2. 修改`src/resources/application.yml`配置文件中的`redis`连接配置
2. 修改`src/resources/application.yml` 和 `src/resources/redisson.yml` 配置文件中的`redis`连接配置
```
```yaml
spring:
redis:
host: 127.0.0.1
@ -211,17 +226,25 @@ git clone https://gitee.com/novel_dev_team/novel.git
password: 123456
```
3. 项目根目录下运行如下命令来启动后端服务(有安装 IDE 的可以导入源码到 IDE 中运行)
```yaml
singleServerConfig:
address: "redis://127.0.0.1:6379"
password: 123456
```
3. 根据前后端的实际部署情况,修改`application.yml`中的跨域配置(默认情况可忽略此步骤)
4. 项目根目录下运行如下命令来启动后端服务(有安装 IDE 的可以导入源码到 IDE 中运行)
```bash
mvn spring-boot:run
```
5. 接口文档访问地址:`http://server:port/swagger-ui/index.html`
4. 根据前后端的实际部署情况,修改`application.yml`中的跨域配置(默认情况可忽略此步骤)
- 下载前端前台门户系统源码
```
```bash
git clone https://gitee.com/novel_dev_team/novel-front-web.git
```
@ -231,25 +254,25 @@ git clone https://gitee.com/novel_dev_team/novel-front-web.git
2. `yarn`安装
```
```bash
npm install -g yarn
```
3. 项目根目录下运行如下命令来安装项目依赖
```
```bash
yarn install
```
4. 项目根目录下运行如下命令启动
```
```bash
yarn serve
```
5. 浏览器通过`http://localhost:1024`来访问
## 项目教程
[手把手教你从零开始开发上线一个生产级别的小说系统](https://youdoc.github.io/course/novel/3.html)
[手把手教你从零开始开发上线一个生产级别的小说系统](https://docs.xxyopen.com/course/novel/3.html)
## 公众号
@ -261,7 +284,7 @@ git clone https://gitee.com/novel_dev_team/novel-front-web.git
- 回复「**笔记**」获取`Spring Boot 3 学习笔记`
![xxyopen](https://youdoc.gitee.io/img/qrcode_for_gh.jpg)
![xxyopen](https://youdoc.github.io/img/qrcode_for_gh.jpg)
## 赞赏支持

6
doc/sql/README.md Normal file
View File

@ -0,0 +1,6 @@
1. 初始状态下MySQL 只需要执行 `novel.sql` 文件即可正常运行本系统
2. 代码更新后再执行以日期命名的增量 SQL 文件
3. 只有开启 XXL-JOB 的功能,才需要执行 `xxl-job.sql` 和以 xxl-job 开头日期结尾的增量 SQL 文件
4. 只有开启 ShardingSphere-JDBC 的功能,才需要执行 `shardingsphere-jdbc.sql` 和以 shardingsphere-jdbc 开头日期结尾的增量 SQL
文件

190
doc/sql/xxl-job.sql Normal file
View File

@ -0,0 +1,190 @@
#
# XXL-JOB v2.4.0-SNAPSHOT
# Copyright (c) 2015-present, xuxueli.
CREATE database if NOT EXISTS `xxl_job` default character set utf8mb4 collate utf8mb4_unicode_ci;
use `xxl_job`;
SET NAMES utf8mb4;
CREATE TABLE `xxl_job_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`job_group` int(11) NOT NULL COMMENT '执行器主键ID',
`job_desc` varchar(255) NOT NULL,
`add_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`author` varchar(64) DEFAULT NULL COMMENT '作者',
`alarm_email` varchar(255) DEFAULT NULL COMMENT '报警邮件',
`schedule_type` varchar(50) NOT NULL DEFAULT 'NONE' COMMENT '调度类型',
`schedule_conf` varchar(128) DEFAULT NULL COMMENT '调度配置,值含义取决于调度类型',
`misfire_strategy` varchar(50) NOT NULL DEFAULT 'DO_NOTHING' COMMENT '调度过期策略',
`executor_route_strategy` varchar(50) DEFAULT NULL COMMENT '执行器路由策略',
`executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
`executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
`executor_block_strategy` varchar(50) DEFAULT NULL COMMENT '阻塞处理策略',
`executor_timeout` int(11) NOT NULL DEFAULT '0' COMMENT '任务执行超时时间,单位秒',
`executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
`glue_type` varchar(50) NOT NULL COMMENT 'GLUE类型',
`glue_source` mediumtext COMMENT 'GLUE源代码',
`glue_remark` varchar(128) DEFAULT NULL COMMENT 'GLUE备注',
`glue_updatetime` datetime DEFAULT NULL COMMENT 'GLUE更新时间',
`child_jobid` varchar(255) DEFAULT NULL COMMENT '子任务ID多个逗号分隔',
`trigger_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '调度状态0-停止1-运行',
`trigger_last_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '上次调度时间',
`trigger_next_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '下次调度时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`job_group` int(11) NOT NULL COMMENT '执行器主键ID',
`job_id` int(11) NOT NULL COMMENT '任务主键ID',
`executor_address` varchar(255) DEFAULT NULL COMMENT '执行器地址,本次执行的地址',
`executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
`executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
`executor_sharding_param` varchar(20) DEFAULT NULL COMMENT '执行器任务分片参数,格式如 1/2',
`executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
`trigger_time` datetime DEFAULT NULL COMMENT '调度-时间',
`trigger_code` int(11) NOT NULL COMMENT '调度-结果',
`trigger_msg` text COMMENT '调度-日志',
`handle_time` datetime DEFAULT NULL COMMENT '执行-时间',
`handle_code` int(11) NOT NULL COMMENT '执行-状态',
`handle_msg` text COMMENT '执行-日志',
`alarm_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '告警状态0-默认、1-无需告警、2-告警成功、3-告警失败',
PRIMARY KEY (`id`),
KEY `I_trigger_time` (`trigger_time`),
KEY `I_handle_code` (`handle_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_log_report` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`trigger_day` datetime DEFAULT NULL COMMENT '调度-时间',
`running_count` int(11) NOT NULL DEFAULT '0' COMMENT '运行中-日志数量',
`suc_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行成功-日志数量',
`fail_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行失败-日志数量',
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `i_trigger_day` (`trigger_day`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_logglue` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`job_id` int(11) NOT NULL COMMENT '任务主键ID',
`glue_type` varchar(50) DEFAULT NULL COMMENT 'GLUE类型',
`glue_source` mediumtext COMMENT 'GLUE源代码',
`glue_remark` varchar(128) NOT NULL COMMENT 'GLUE备注',
`add_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_registry` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`registry_group` varchar(50) NOT NULL,
`registry_key` varchar(255) NOT NULL,
`registry_value` varchar(255) NOT NULL,
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_group` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`app_name` varchar(64) NOT NULL COMMENT '执行器AppName',
`title` varchar(12) NOT NULL COMMENT '执行器名称',
`address_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '执行器地址类型0=自动注册、1=手动录入',
`address_list` text COMMENT '执行器地址列表,多地址逗号分隔',
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL COMMENT '账号',
`password` varchar(50) NOT NULL COMMENT '密码',
`role` tinyint(4) NOT NULL COMMENT '角色0-普通用户、1-管理员',
`permission` varchar(255) DEFAULT NULL COMMENT '权限执行器ID列表多个逗号分割',
PRIMARY KEY (`id`),
UNIQUE KEY `i_username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `xxl_job_lock` (
`lock_name` varchar(50) NOT NULL COMMENT '锁名称',
PRIMARY KEY (`lock_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `address_type`, `address_list`, `update_time`) VALUES (1, 'xxl-job-executor-sample', '示例执行器', 0, NULL, '2018-11-03 22:21:31' );
INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1, 1, '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');
INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');
commit;
-- 增加 novel 任务执行器和同步小说数据到 Elasticsearch 的任务
-- 增加 novel 任务执行器和同步小说数据到 Elasticsearch 的任务
INSERT INTO `xxl_job`.`xxl_job_group` ( `app_name`, `title`, `address_type`, `address_list`, `update_time` )
VALUES
(
'xxl-job-executor-novel',
'novel 任务执行器',
0,
NULL,
now()
);
INSERT INTO `xxl_job`.`xxl_job_info` (
`job_group`,
`job_desc`,
`add_time`,
`update_time`,
`author`,
`alarm_email`,
`schedule_type`,
`schedule_conf`,
`misfire_strategy`,
`executor_route_strategy`,
`executor_handler`,
`executor_param`,
`executor_block_strategy`,
`executor_timeout`,
`executor_fail_retry_count`,
`glue_type`,
`glue_source`,
`glue_remark`,
`glue_updatetime`,
`child_jobid`,
`trigger_status`,
`trigger_last_time`,
`trigger_next_time`
)
VALUES
(
(SELECT
id
FROM
xxl_job_group
WHERE
app_name = 'xxl-job-executor-novel'),
'同步小说数据到 Elasticsearch',
now(),
now(),
'xxyopen',
'',
'CRON',
'0 0 0 1 * ?',
'DO_NOTHING',
'FIRST',
'saveToEsJobHandler',
'',
'SERIAL_EXECUTION',
0,
0,
'BEAN',
'',
'GLUE代码初始化',
now(),
'',
0,
0,
0
);

3
doc/style/README.md Normal file
View File

@ -0,0 +1,3 @@
IntelliJ IDEA 中导入 `intellij-java-google-style.xml` 文件:
`Preferences` => `Editor` => `Code Style` => `Java` => `Schema` => `Import Schema`

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<code_scheme name="GoogleStyle">
<codeStyleSettings language="JAVA">
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false"/>
<option name="KEEP_BLANK_LINES_IN_CODE" value="1"/>
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1"/>
<option name="ALIGN_MULTILINE_PARAMETERS" value="false"/>
<option name="ALIGN_MULTILINE_RESOURCES" value="false"/>
<option name="ALIGN_MULTILINE_FOR" value="false"/>
<option name="CALL_PARAMETERS_WRAP" value="1"/>
<option name="METHOD_PARAMETERS_WRAP" value="1"/>
<option name="EXTENDS_LIST_WRAP" value="1"/>
<option name="THROWS_KEYWORD_WRAP" value="1"/>
<option name="METHOD_CALL_CHAIN_WRAP" value="1"/>
<option name="BINARY_OPERATION_WRAP" value="1"/>
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true"/>
<option name="TERNARY_OPERATION_WRAP" value="1"/>
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true"/>
<option name="FOR_STATEMENT_WRAP" value="1"/>
<option name="ARRAY_INITIALIZER_WRAP" value="1"/>
<option name="WRAP_COMMENTS" value="true"/>
<option name="IF_BRACE_FORCE" value="3"/>
<option name="DOWHILE_BRACE_FORCE" value="3"/>
<option name="WHILE_BRACE_FORCE" value="3"/>
<option name="FOR_BRACE_FORCE" value="3"/>
<option name="PARENT_SETTINGS_INSTALLED" value="true"/>
<indentOptions>
<option name="INDENT_SIZE" value="4"/>
<option name="CONTINUATION_INDENT_SIZE" value="4"/>
<option name="TAB_SIZE" value="4"/>
</indentOptions>
</codeStyleSettings>
</code_scheme>

86
pom.xml
View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -10,7 +11,7 @@
</parent>
<groupId>io.github.xxyopen</groupId>
<artifactId>novel</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<name>novel</name>
<description>Spring Boot 3 + Vue 3 构建的前后端分离小说系统</description>
<properties>
@ -22,7 +23,11 @@
<xxl-job.version>2.3.1</xxl-job.version>
<sentinel.version>1.8.4</sentinel.version>
<shardingsphere-jdbc.version>5.1.1</shardingsphere-jdbc.version>
<redisson.version>3.17.4</redisson.version>
<spring-boot-admin.version>3.0.0-M1</spring-boot-admin.version>
<springdoc-openapi.version>2.0.0-M4-SNAPSHOT</springdoc-openapi.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -145,6 +150,41 @@
<version>${shardingsphere-jdbc.version}</version>
</dependency>
<!-- Spring Boot 管理和监控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Redisson 相关 -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson.version}</version>
</dependency>
<!-- Aop 相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- OpenAPI 3 -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
@ -184,6 +224,16 @@
</plugins>
</build>
<repositories>
<repository>
<id>ali</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
@ -200,8 +250,40 @@
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>sonatype-nexus-snapshots-2</id>
<name>Sonatype Nexus Snapshots 2</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>ali</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>

View File

@ -1,18 +1,29 @@
package io.github.xxyopen.novel;
import io.github.xxyopen.novel.core.constant.SystemConfigConsts;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import java.util.Map;
@OpenAPIDefinition(info = @Info(title = "novel 项目接口文档", version = "v3.2.0", license = @License(name = "Apache 2.0", url = "https://www.apache.org/licenses/LICENSE-2.0")))
@SecurityScheme(type = SecuritySchemeType.APIKEY, in = SecuritySchemeIn.HEADER, name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME, description = "登录 token")
@SpringBootApplication
@MapperScan("io.github.xxyopen.novel.dao.mapper")
@EnableCaching
@ -37,4 +48,13 @@ public class NovelApplication {
};
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.csrf().disable()
.requestMatcher(EndpointRequest.toAnyEndpoint())
.authorizeRequests(requests -> requests.anyRequest().hasRole("ENDPOINT_ADMIN"));
http.httpBasic();
return http.build();
}
}

View File

@ -5,6 +5,7 @@ import io.github.xxyopen.novel.core.common.req.PageReqDto;
import io.github.xxyopen.novel.core.common.resp.PageRespDto;
import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.core.constant.SystemConfigConsts;
import io.github.xxyopen.novel.dto.req.AuthorRegisterReqDto;
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
import io.github.xxyopen.novel.dto.req.ChapterAddReqDto;
@ -12,9 +13,19 @@ import io.github.xxyopen.novel.dto.resp.BookChapterRespDto;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import io.github.xxyopen.novel.service.AuthorService;
import io.github.xxyopen.novel.service.BookService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 作家后台-作家模块 API 控制器
@ -22,6 +33,8 @@ import org.springframework.web.bind.annotation.*;
* @author xiongxiaoyang
* @date 2022/5/23
*/
@Tag(name = "AuthorController", description = "作家后台-作者模块")
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@RestController
@RequestMapping(ApiRouterConsts.API_AUTHOR_URL_PREFIX)
@RequiredArgsConstructor
@ -34,6 +47,7 @@ public class AuthorController {
/**
* 作家注册接口
*/
@Operation(summary = "作家注册接口")
@PostMapping("register")
public RestResp<Void> register(@Valid @RequestBody AuthorRegisterReqDto dto) {
dto.setUserId(UserHolder.getUserId());
@ -43,6 +57,7 @@ public class AuthorController {
/**
* 查询作家状态接口
*/
@Operation(summary = "作家状态查询接口")
@GetMapping("status")
public RestResp<Integer> getStatus() {
return authorService.getStatus(UserHolder.getUserId());
@ -51,6 +66,7 @@ public class AuthorController {
/**
* 小说发布接口
*/
@Operation(summary = "小说发布接口")
@PostMapping("book")
public RestResp<Void> publishBook(@Valid @RequestBody BookAddReqDto dto) {
return bookService.saveBook(dto);
@ -59,16 +75,20 @@ public class AuthorController {
/**
* 小说发布列表查询接口
*/
@Operation(summary = "小说发布列表查询接口")
@GetMapping("books")
public RestResp<PageRespDto<BookInfoRespDto>> listBooks(PageReqDto dto) {
public RestResp<PageRespDto<BookInfoRespDto>> listBooks(@ParameterObject PageReqDto dto) {
return bookService.listAuthorBooks(dto);
}
/**
* 小说章节发布接口
*/
@Operation(summary = "小说章节发布接口")
@PostMapping("book/chapter/{bookId}")
public RestResp<Void> publishBookChapter(@PathVariable("bookId") Long bookId, @Valid @RequestBody ChapterAddReqDto dto) {
public RestResp<Void> publishBookChapter(
@Parameter(description = "小说ID") @PathVariable("bookId") Long bookId,
@Valid @RequestBody ChapterAddReqDto dto) {
dto.setBookId(bookId);
return bookService.saveBookChapter(dto);
}
@ -76,8 +96,11 @@ public class AuthorController {
/**
* 小说章节发布列表查询接口
*/
@Operation(summary = "小说章节发布列表查询接口")
@GetMapping("book/chapters/{bookId}")
public RestResp<PageRespDto<BookChapterRespDto>> listBookChapters(@PathVariable("bookId") Long bookId, PageReqDto dto) {
public RestResp<PageRespDto<BookChapterRespDto>> listBookChapters(
@Parameter(description = "小说ID") @PathVariable("bookId") Long bookId,
@ParameterObject PageReqDto dto) {
return bookService.listBookChapters(bookId, dto);
}

View File

@ -2,13 +2,25 @@ package io.github.xxyopen.novel.controller.front;
import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.dto.resp.*;
import io.github.xxyopen.novel.dto.resp.BookCategoryRespDto;
import io.github.xxyopen.novel.dto.resp.BookChapterAboutRespDto;
import io.github.xxyopen.novel.dto.resp.BookChapterRespDto;
import io.github.xxyopen.novel.dto.resp.BookCommentRespDto;
import io.github.xxyopen.novel.dto.resp.BookContentAboutRespDto;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import io.github.xxyopen.novel.dto.resp.BookRankRespDto;
import io.github.xxyopen.novel.service.BookService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 前台门户-小说模块 API 控制器
@ -16,6 +28,7 @@ import java.util.List;
* @author xiongxiaoyang
* @date 2022/5/14
*/
@Tag(name = "BookController", description = "前台门户-小说模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_BOOK_URL_PREFIX)
@RequiredArgsConstructor
@ -26,78 +39,96 @@ public class BookController {
/**
* 小说分类列表查询接口
*/
@Operation(summary = "小说分类列表查询接口")
@GetMapping("category/list")
public RestResp<List<BookCategoryRespDto>> listCategory(Integer workDirection) {
public RestResp<List<BookCategoryRespDto>> listCategory(
@Parameter(description = "作品方向", required = true) Integer workDirection) {
return bookService.listCategory(workDirection);
}
/**
* 小说信息查询接口
*/
@Operation(summary = "小说信息查询接口")
@GetMapping("{id}")
public RestResp<BookInfoRespDto> getBookById(@PathVariable("id") Long bookId) {
public RestResp<BookInfoRespDto> getBookById(
@Parameter(description = "小说 ID") @PathVariable("id") Long bookId) {
return bookService.getBookById(bookId);
}
/**
* 增加小说点击量接口
*/
@Operation(summary = "增加小说点击量接口")
@PostMapping("visit")
public RestResp<Void> addVisitCount(Long bookId) {
public RestResp<Void> addVisitCount(@Parameter(description = "小说ID") Long bookId) {
return bookService.addVisitCount(bookId);
}
/**
* 小说最新章节相关信息查询接口
*/
@Operation(summary = "小说最新章节相关信息查询接口")
@GetMapping("last_chapter/about")
public RestResp<BookChapterAboutRespDto> getLastChapterAbout(Long bookId) {
public RestResp<BookChapterAboutRespDto> getLastChapterAbout(
@Parameter(description = "小说ID") Long bookId) {
return bookService.getLastChapterAbout(bookId);
}
/**
* 小说推荐列表查询接口
*/
@Operation(summary = "小说推荐列表查询接口")
@GetMapping("rec_list")
public RestResp<List<BookInfoRespDto>> listRecBooks(Long bookId) throws NoSuchAlgorithmException {
public RestResp<List<BookInfoRespDto>> listRecBooks(
@Parameter(description = "小说ID") Long bookId) throws NoSuchAlgorithmException {
return bookService.listRecBooks(bookId);
}
/**
* 小说章节列表查询接口
*/
@Operation(summary = "小说章节列表查询接口")
@GetMapping("chapter/list")
public RestResp<List<BookChapterRespDto>> listChapters(Long bookId) {
public RestResp<List<BookChapterRespDto>> listChapters(
@Parameter(description = "小说ID") Long bookId) {
return bookService.listChapters(bookId);
}
/**
* 小说内容相关信息查询接口
*/
@Operation(summary = "小说内容相关信息查询接口")
@GetMapping("content/{chapterId}")
public RestResp<BookContentAboutRespDto> getBookContentAbout(@PathVariable("chapterId") Long chapterId) {
public RestResp<BookContentAboutRespDto> getBookContentAbout(
@Parameter(description = "章节ID") @PathVariable("chapterId") Long chapterId) {
return bookService.getBookContentAbout(chapterId);
}
/**
* 获取上一章节ID接口
*/
@Operation(summary = "获取上一章节ID接口")
@GetMapping("pre_chapter_id/{chapterId}")
public RestResp<Long> getPreChapterId(@PathVariable("chapterId") Long chapterId) {
public RestResp<Long> getPreChapterId(
@Parameter(description = "章节ID") @PathVariable("chapterId") Long chapterId) {
return bookService.getPreChapterId(chapterId);
}
/**
* 获取下一章节ID接口
*/
@Operation(summary = "获取下一章节ID接口")
@GetMapping("next_chapter_id/{chapterId}")
public RestResp<Long> getNextChapterId(@PathVariable("chapterId") Long chapterId) {
public RestResp<Long> getNextChapterId(
@Parameter(description = "章节ID") @PathVariable("chapterId") Long chapterId) {
return bookService.getNextChapterId(chapterId);
}
/**
* 小说点击榜查询接口
*/
@Operation(summary = "小说点击榜查询接口")
@GetMapping("visit_rank")
public RestResp<List<BookRankRespDto>> listVisitRankBooks() {
return bookService.listVisitRankBooks();
@ -106,6 +137,7 @@ public class BookController {
/**
* 小说新书榜查询接口
*/
@Operation(summary = "小说新书榜查询接口")
@GetMapping("newest_rank")
public RestResp<List<BookRankRespDto>> listNewestRankBooks() {
return bookService.listNewestRankBooks();
@ -114,6 +146,7 @@ public class BookController {
/**
* 小说更新榜查询接口
*/
@Operation(summary = "小说更新榜查询接口")
@GetMapping("update_rank")
public RestResp<List<BookRankRespDto>> listUpdateRankBooks() {
return bookService.listUpdateRankBooks();
@ -122,8 +155,10 @@ public class BookController {
/**
* 小说最新评论查询接口
*/
@Operation(summary = "小说最新评论查询接口")
@GetMapping("comment/newest_list")
public RestResp<BookCommentRespDto> listNewestComments(Long bookId) {
public RestResp<BookCommentRespDto> listNewestComments(
@Parameter(description = "小说ID") Long bookId) {
return bookService.listNewestComments(bookId);
}

View File

@ -5,6 +5,8 @@ import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.dto.resp.HomeBookRespDto;
import io.github.xxyopen.novel.dto.resp.HomeFriendLinkRespDto;
import io.github.xxyopen.novel.service.HomeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -18,6 +20,7 @@ import java.util.List;
* @author xiongxiaoyang
* @date 2022/5/12
*/
@Tag(name = "HomeController", description = "前台门户-首页模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_HOME_URL_PREFIX)
@RequiredArgsConstructor
@ -28,6 +31,7 @@ public class HomeController {
/**
* 首页小说推荐查询接口
*/
@Operation(summary = "首页小说推荐查询接口")
@GetMapping("books")
public RestResp<List<HomeBookRespDto>> listHomeBooks() {
return homeService.listHomeBooks();
@ -36,6 +40,7 @@ public class HomeController {
/**
* 首页友情链接列表查询接口
*/
@Operation(summary = "首页友情链接列表查询接口")
@GetMapping("friend_Link/list")
public RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks() {
return homeService.listHomeFriendLinks();

View File

@ -1,23 +1,26 @@
package io.github.xxyopen.novel.controller.front;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.dto.resp.NewsInfoRespDto;
import io.github.xxyopen.novel.service.NewsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 前台门户-新闻模块 API 控制器
*
* @author xiongxiaoyang
* @date 2022/5/12
*/
@Tag(name = "NewsController", description = "前台门户-新闻模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_NEWS_URL_PREFIX)
@RequiredArgsConstructor
@ -28,6 +31,7 @@ public class NewsController {
/**
* 最新新闻列表查询接口
*/
@Operation(summary = "最新新闻列表查询接口")
@GetMapping("latest_list")
public RestResp<List<NewsInfoRespDto>> listLatestNews() {
return newsService.listLatestNews();
@ -36,8 +40,10 @@ public class NewsController {
/**
* 新闻信息查询接口
*/
@Operation(summary = "新闻信息查询接口")
@GetMapping("{id}")
public RestResp<NewsInfoRespDto> getNews(@PathVariable Long id) {
public RestResp<NewsInfoRespDto> getNews(
@Parameter(description = "新闻ID") @PathVariable Long id) {
return newsService.getNews(id);
}
}

View File

@ -4,11 +4,17 @@ import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.dto.resp.ImgVerifyCodeRespDto;
import io.github.xxyopen.novel.service.ResourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
* 前台门户-资源(图片/视频/文档)模块 API 控制器
@ -16,6 +22,7 @@ import java.io.IOException;
* @author xiongxiaoyang
* @date 2022/5/17
*/
@Tag(name = "ResourceController", description = "前台门户-资源模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_RESOURCE_URL_PREFIX)
@RequiredArgsConstructor
@ -26,6 +33,7 @@ public class ResourceController {
/**
* 获取图片验证码接口
*/
@Operation(summary = "获取图片验证码接口")
@GetMapping("img_verify_code")
public RestResp<ImgVerifyCodeRespDto> getImgVerifyCode() throws IOException {
return resourceService.getImgVerifyCode();
@ -33,9 +41,11 @@ public class ResourceController {
/**
* 图片上传接口
* */
*/
@Operation(summary = "图片上传接口")
@PostMapping("/image")
RestResp<String> uploadImage(@RequestParam("file") MultipartFile file) {
RestResp<String> uploadImage(
@Parameter(description = "上传文件") @RequestParam("file") MultipartFile file) {
return resourceService.uploadImage(file);
}

View File

@ -6,7 +6,10 @@ import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import io.github.xxyopen.novel.service.SearchService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -17,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
* @author xiongxiaoyang
* @date 2022/5/27
*/
@Tag(name = "SearchController", description = "前台门户-搜索模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_SEARCH_URL_PREFIX)
@RequiredArgsConstructor
@ -27,8 +31,10 @@ public class SearchController {
/**
* 小说搜索接口
*/
@Operation(summary = "小说搜索接口")
@GetMapping("books")
public RestResp<PageRespDto<BookInfoRespDto>> searchBooks(BookSearchReqDto condition) {
public RestResp<PageRespDto<BookInfoRespDto>> searchBooks(
@ParameterObject BookSearchReqDto condition) {
return searchService.searchBooks(condition);
}

View File

@ -3,6 +3,7 @@ package io.github.xxyopen.novel.controller.front;
import io.github.xxyopen.novel.core.auth.UserHolder;
import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.core.constant.SystemConfigConsts;
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
import io.github.xxyopen.novel.dto.req.UserInfoUptReqDto;
import io.github.xxyopen.novel.dto.req.UserLoginReqDto;
@ -12,9 +13,20 @@ import io.github.xxyopen.novel.dto.resp.UserLoginRespDto;
import io.github.xxyopen.novel.dto.resp.UserRegisterRespDto;
import io.github.xxyopen.novel.service.BookService;
import io.github.xxyopen.novel.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 前台门户-会员模块 API 控制器
@ -22,6 +34,8 @@ import org.springframework.web.bind.annotation.*;
* @author xiongxiaoyang
* @date 2022/5/17
*/
@Tag(name = "UserController", description = "前台门户-会员模块")
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_USER_URL_PREFIX)
@RequiredArgsConstructor
@ -34,6 +48,7 @@ public class UserController {
/**
* 用户注册接口
*/
@Operation(summary = "用户注册接口")
@PostMapping("register")
public RestResp<UserRegisterRespDto> register(@Valid @RequestBody UserRegisterReqDto dto) {
return userService.register(dto);
@ -42,6 +57,7 @@ public class UserController {
/**
* 用户登录接口
*/
@Operation(summary = "用户登录接口")
@PostMapping("login")
public RestResp<UserLoginRespDto> login(@Valid @RequestBody UserLoginReqDto dto) {
return userService.login(dto);
@ -50,6 +66,7 @@ public class UserController {
/**
* 用户信息查询接口
*/
@Operation(summary = "用户信息查询接口")
@GetMapping
public RestResp<UserInfoRespDto> getUserInfo() {
return userService.getUserInfo(UserHolder.getUserId());
@ -58,6 +75,7 @@ public class UserController {
/**
* 用户信息修改接口
*/
@Operation(summary = "用户信息修改接口")
@PutMapping
public RestResp<Void> updateUserInfo(@Valid @RequestBody UserInfoUptReqDto dto) {
dto.setUserId(UserHolder.getUserId());
@ -67,6 +85,7 @@ public class UserController {
/**
* 用户反馈提交接口
*/
@Operation(summary = "用户反馈提交接口")
@PostMapping("feedback")
public RestResp<Void> submitFeedback(@RequestBody String content) {
return userService.saveFeedback(UserHolder.getUserId(), content);
@ -75,14 +94,16 @@ public class UserController {
/**
* 用户反馈删除接口
*/
@Operation(summary = "用户反馈删除接口")
@DeleteMapping("feedback/{id}")
public RestResp<Void> deleteFeedback(@PathVariable Long id) {
public RestResp<Void> deleteFeedback(@Parameter(description = "反馈ID") @PathVariable Long id) {
return userService.deleteFeedback(UserHolder.getUserId(), id);
}
/**
* 发表评论接口
*/
@Operation(summary = "发表评论接口")
@PostMapping("comment")
public RestResp<Void> comment(@Valid @RequestBody UserCommentReqDto dto) {
dto.setUserId(UserHolder.getUserId());
@ -92,26 +113,28 @@ public class UserController {
/**
* 修改评论接口
*/
@Operation(summary = "修改评论接口")
@PutMapping("comment/{id}")
public RestResp<Void> updateComment(@PathVariable Long id, String content) {
public RestResp<Void> updateComment(@Parameter(description = "评论ID") @PathVariable Long id,
String content) {
return bookService.updateComment(UserHolder.getUserId(), id, content);
}
/**
* 删除评论接口
*/
@Operation(summary = "删除评论接口")
@DeleteMapping("comment/{id}")
public RestResp<Void> deleteComment(@PathVariable Long id) {
public RestResp<Void> deleteComment(@Parameter(description = "评论ID") @PathVariable Long id) {
return bookService.deleteComment(UserHolder.getUserId(), id);
}
/**
* 查询书架状态接口
* 0-不在书架
* 1-已在书架
* 查询书架状态接口 0-不在书架 1-已在书架
*/
@Operation(summary = "查询书架状态接口")
@GetMapping("bookshelf_status")
public RestResp<Integer> getBookshelfStatus(@RequestBody String bookId) {
public RestResp<Integer> getBookshelfStatus(@Parameter(description = "小说ID") String bookId) {
return userService.getBookshelfStatus(UserHolder.getUserId(), bookId);
}

View File

@ -0,0 +1,23 @@
package io.github.xxyopen.novel.core.annotation;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* 分布式锁-Key 注解
*
* @author xiongxiaoyang
* @date 2022/6/20
*/
@Documented
@Retention(RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
public @interface Key {
String expr() default "";
}

View File

@ -0,0 +1,31 @@
package io.github.xxyopen.novel.core.annotation;
import io.github.xxyopen.novel.core.common.constant.ErrorCodeEnum;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* 分布式锁 注解
*
* @author xiongxiaoyang
* @date 2022/6/20
*/
@Documented
@Retention(RUNTIME)
@Target(METHOD)
public @interface Lock {
String prefix();
boolean isWait() default false;
long waitTime() default 3L;
ErrorCodeEnum failCode() default ErrorCodeEnum.OK;
}

View File

@ -0,0 +1,81 @@
package io.github.xxyopen.novel.core.aspect;
import io.github.xxyopen.novel.core.annotation.Key;
import io.github.xxyopen.novel.core.annotation.Lock;
import io.github.xxyopen.novel.core.common.exception.BusinessException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.concurrent.TimeUnit;
import lombok.SneakyThrows;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.common.TemplateParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
/**
* 分布式锁 切面
*
* @author xiongxiaoyang
* @date 2022/6/20
*/
@Aspect
@Component
public record LockAspect(RedissonClient redissonClient) {
private static final String KEY_PREFIX = "Lock";
private static final String KEY_SEPARATOR = "::";
@Around(value = "@annotation(io.github.xxyopen.novel.core.annotation.Lock)")
@SneakyThrows
public Object doAround(ProceedingJoinPoint joinPoint) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method targetMethod = methodSignature.getMethod();
Lock lock = targetMethod.getAnnotation(Lock.class);
String lockKey = KEY_PREFIX + buildLockKey(lock.prefix(), targetMethod,
joinPoint.getArgs());
RLock rLock = redissonClient.getLock(lockKey);
if (lock.isWait() ? rLock.tryLock(lock.waitTime(), TimeUnit.SECONDS) : rLock.tryLock()) {
try {
return joinPoint.proceed();
} finally {
rLock.unlock();
}
}
throw new BusinessException(lock.failCode());
}
private String buildLockKey(String prefix, Method method, Object[] args) {
StringBuilder builder = new StringBuilder();
if (StringUtils.hasText(prefix)) {
builder.append(KEY_SEPARATOR).append(prefix);
}
Parameter[] parameters = method.getParameters();
for (int i = 0; i < parameters.length; i++) {
builder.append(KEY_SEPARATOR);
if (parameters[i].isAnnotationPresent(Key.class)) {
Key key = parameters[i].getAnnotation(Key.class);
builder.append(parseKeyExpr(key.expr(), args[i]));
}
}
return builder.toString();
}
private String parseKeyExpr(String expr, Object arg) {
if (!StringUtils.hasText(expr)) {
return arg.toString();
}
ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression(expr, new TemplateParserContext());
return expression.getValue(arg, String.class);
}
}

View File

@ -5,7 +5,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* 平台后台管理系统 认证策略
* 平台后台管理系统 认证授权策略
*
* @author xiongxiaoyang
* @date 2022/5/18
@ -18,4 +18,5 @@ public class AdminAuthStrategy implements AuthStrategy {
public void auth(String token, String requestUri) throws BusinessException {
// TODO 平台后台 token 校验
}
}

View File

@ -6,9 +6,8 @@ import io.github.xxyopen.novel.core.constant.SystemConfigConsts;
import io.github.xxyopen.novel.core.util.JwtUtils;
import io.github.xxyopen.novel.dto.UserInfoDto;
import io.github.xxyopen.novel.manager.cache.UserInfoCacheManager;
import org.springframework.util.StringUtils;
import java.util.Objects;
import org.springframework.util.StringUtils;
/**
* 策略模式实现用户认证授权功能
@ -19,7 +18,7 @@ import java.util.Objects;
public interface AuthStrategy {
/**
* 请求用户认证
* 用户认证授权
*
* @param token 登录 token
* @param requestUri 请求的 URI
@ -28,14 +27,15 @@ public interface AuthStrategy {
void auth(String token, String requestUri) throws BusinessException;
/**
* 前台多系统单点登录统一账号认证(门户系统、作家系统以及后面会扩展的漫画系统和视频系统等)
* 前台多系统单点登录统一账号认证授权(门户系统、作家系统以及后面会扩展的漫画系统和视频系统等)
*
* @param jwtUtils jwt 工具
* @param userInfoCacheManager 用户缓存管理对象
* @param token token 登录 token
* @return 用户ID
*/
default Long authSSO(JwtUtils jwtUtils, UserInfoCacheManager userInfoCacheManager, String token) {
default Long authSSO(JwtUtils jwtUtils, UserInfoCacheManager userInfoCacheManager,
String token) {
if (!StringUtils.hasText(token)) {
// token 为空
throw new BusinessException(ErrorCodeEnum.USER_LOGIN_EXPIRED);
@ -55,4 +55,5 @@ public interface AuthStrategy {
// 返回 userId
return userId;
}
}

View File

@ -7,14 +7,13 @@ import io.github.xxyopen.novel.core.util.JwtUtils;
import io.github.xxyopen.novel.dto.AuthorInfoDto;
import io.github.xxyopen.novel.manager.cache.AuthorInfoCacheManager;
import io.github.xxyopen.novel.manager.cache.UserInfoCacheManager;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
/**
* 作家后台管理系统 认证策略
* 作家后台管理系统 认证授权策略
*
* @author xiongxiaoyang
* @date 2022/5/18
@ -31,7 +30,7 @@ public class AuthorAuthStrategy implements AuthStrategy {
/**
* 不需要进行作家权限认证的 URI
* */
*/
private static final List<String> EXCLUDE_URI = List.of(
ApiRouterConsts.API_AUTHOR_URL_PREFIX + "/register",
ApiRouterConsts.API_AUTHOR_URL_PREFIX + "/status"
@ -55,4 +54,5 @@ public class AuthorAuthStrategy implements AuthStrategy {
// 设置作家ID到当前线程
UserHolder.setAuthorId(authorInfo.getId());
}
}

View File

@ -7,7 +7,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* 前台门户系统 认证策略
* 前台门户系统 认证授权策略
*
* @author xiongxiaoyang
* @date 2022/5/18
@ -25,4 +25,5 @@ public class FrontAuthStrategy implements AuthStrategy {
// 统一账号认证
authSSO(jwtUtils, userInfoCacheManager, token);
}
}

View File

@ -13,12 +13,12 @@ public class UserHolder {
/**
* 当前线程用户ID
* */
*/
private static final ThreadLocal<Long> userIdTL = new ThreadLocal<>();
/**
* 当前线程作家ID
* */
*/
private static final ThreadLocal<Long> authorIdTL = new ThreadLocal<>();
public void setUserId(Long userId) {

View File

@ -11,30 +11,30 @@ public class CommonConsts {
/**
* 是
* */
*/
public static final Integer YES = 1;
public static final String TRUE = "true";
/**
* 否
* */
*/
public static final Integer NO = 0;
public static final String FALSE = "false";
/**
* 性别常量
* */
*/
public enum SexEnum {
/**
* 男
* */
*/
MALE(0, ""),
/**
* 女
* */
*/
FEMALE(1, "");
SexEnum(int code, String desc) {

View File

@ -5,15 +5,12 @@ import lombok.Getter;
/**
* 错误码枚举类。
*
* 错误码为字符串类型,共 5 位,分成两个部分:错误产生来源+四位数字编号。
* 错误产生来源分为 A/B/C A 表示错误来源于用户,比如参数错误,用户安装版本过低,用户支付
* 超时等问题; B 表示错误来源于当前系统,往往是业务逻辑出错,或程序健壮性差等问题; C 表示错误来源
* 于第三方服务,比如 CDN 服务出错,消息投递超时等问题;四位数字编号从 0001 到 9999大类之间的
* <p>
* 错误码为字符串类型,共 5 位,分成两个部分:错误产生来源+四位数字编号。 错误产生来源分为 A/B/C A 表示错误来源于用户,比如参数错误,用户安装版本过低,用户支付 超时等问题; B
* 表示错误来源于当前系统,往往是业务逻辑出错,或程序健壮性差等问题; C 表示错误来源 于第三方服务,比如 CDN 服务出错,消息投递超时等问题;四位数字编号从 0001 到 9999大类之间的
* 步长间距预留 100。
*
* 错误码分为一级宏观错误码、二级宏观错误码、三级宏观错误码。
* 在无法更加具体确定的错误场景中,可以直接使用一级宏观错误码。
* <p>
* 错误码分为一级宏观错误码、二级宏观错误码、三级宏观错误码。 在无法更加具体确定的错误场景中,可以直接使用一级宏观错误码。
*
* @author xiongxiaoyang
* @date 2022/5/11
@ -24,134 +21,132 @@ public enum ErrorCodeEnum {
/**
* 正确执行后的返回
* */
*/
OK("00000", "一切 ok"),
/**
* 一级宏观错误码,用户端错误
* */
*/
USER_ERROR("A0001", "用户端错误"),
/**
* 二级宏观错误码,用户注册错误
* */
*/
USER_REGISTER_ERROR("A0100", "用户注册错误"),
/**
* 用户未同意隐私协议
* */
*/
USER_NO_AGREE_PRIVATE_ERROR("A0101", "用户未同意隐私协议"),
/**
* 注册国家或地区受限
* */
*/
USER_REGISTER_AREA_LIMIT_ERROR("A0102", "注册国家或地区受限"),
/**
* 用户验证码错误
* */
*/
USER_VERIFY_CODE_ERROR("A0240", "用户验证码错误"),
/**
* 用户名已存在
* */
*/
USER_NAME_EXIST("A0111", "用户名已存在"),
/**
* 用户账号不存在
* */
*/
USER_ACCOUNT_NOT_EXIST("A0201", "用户账号不存在"),
/**
* 用户密码错误
* */
*/
USER_PASSWORD_ERROR("A0210", "用户密码错误"),
/**
* 二级宏观错误码,用户请求参数错误
* */
*/
USER_REQUEST_PARAM_ERROR("A0400", "用户请求参数错误"),
/**
* 用户登录已过期
* */
*/
USER_LOGIN_EXPIRED("A0230", "用户登录已过期"),
/**
* 访问未授权
* */
*/
USER_UN_AUTH("A0301", "访问未授权"),
/**
* 用户请求服务异常
* */
*/
USER_REQ_EXCEPTION("A0500", "用户请求服务异常"),
/**
* 请求超出限制
* */
*/
USER_REQ_MANY("A0501", "请求超出限制"),
/**
* 用户评论异常
* */
*/
USER_COMMENT("A2000", "用户评论异常"),
/**
* 用户评论异常
* */
*/
USER_COMMENTED("A2001", "用户已发表评论"),
/**
* 作家发布异常
* */
*/
AUTHOR_PUBLISH("A3000", "作家发布异常"),
/**
* 小说名已存在
* */
*/
AUTHOR_BOOK_NAME_EXIST("A3001", "小说名已存在"),
/**
* 用户上传文件异常
* */
*/
USER_UPLOAD_FILE_ERROR("A0700", "用户上传文件异常"),
/**
* 用户上传文件类型不匹配
* */
*/
USER_UPLOAD_FILE_TYPE_NOT_MATCH("A0701", "用户上传文件类型不匹配"),
/**
* 一级宏观错误码,系统执行出错
* */
*/
SYSTEM_ERROR("B0001", "系统执行出错"),
/**
* 二级宏观错误码,系统执行超时
* */
*/
SYSTEM_TIMEOUT_ERROR("B0100", "系统执行超时"),
/**
* 一级宏观错误码,调用第三方服务出错
* */
*/
THIRD_SERVICE_ERROR("C0001", "调用第三方服务出错"),
/**
* 一级宏观错误码,中间件服务出错
* */
MIDDLEWARE_SERVICE_ERROR("C0100","中间件服务出错")
;
*/
MIDDLEWARE_SERVICE_ERROR("C0100", "中间件服务出错");
/**
* 错误码
* */
*/
private final String code;
/**
* 中文描述
* */
*/
private final String message;
}

View File

@ -19,7 +19,7 @@ public class CommonExceptionHandler {
/**
* 处理数据校验异常
* */
*/
@ExceptionHandler(BindException.class)
public RestResp<Void> handlerBindException(BindException e) {
log.error(e.getMessage(), e);
@ -28,7 +28,7 @@ public class CommonExceptionHandler {
/**
* 处理业务异常
* */
*/
@ExceptionHandler(BusinessException.class)
public RestResp<Void> handlerBusinessException(BusinessException e) {
log.error(e.getMessage(), e);
@ -37,7 +37,7 @@ public class CommonExceptionHandler {
/**
* 处理系统异常
* */
*/
@ExceptionHandler(Exception.class)
public RestResp<Void> handlerException(Exception e) {
log.error(e.getMessage(), e);

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.core.common.req;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.Data;
/**
@ -13,18 +14,20 @@ public class PageReqDto {
/**
* 请求页码,默认第 1 页
* */
*/
@Parameter(description = "请求页码,默认第 1 页")
private int pageNum = 1;
/**
* 每页大小,默认每页 10 条
* */
*/
@Parameter(description = "每页大小,默认每页 10 条")
private int pageSize = 10;
/**
* 是否查询所有,默认不查所有
* 为 true 时pageNum 和 pageSize 无效
* */
* 是否查询所有,默认不查所有 为 true 时pageNum 和 pageSize 无效
*/
@Parameter(hidden = true)
private boolean fetchAll = false;
}

View File

@ -1,8 +1,7 @@
package io.github.xxyopen.novel.core.common.resp;
import lombok.Getter;
import java.util.List;
import lombok.Getter;
/**
* 分页响应数据格式封装
@ -34,8 +33,7 @@ public class PageRespDto<T> {
private final List<? extends T> list;
/**
* 该构造函数用于通用分页查询的场景
* 接收普通分页数据和普通集合
* 该构造函数用于通用分页查询的场景 接收普通分页数据和普通集合
*/
public PageRespDto(long pageNum, long pageSize, long total, List<T> list) {
this.pageNum = pageNum;
@ -50,7 +48,7 @@ public class PageRespDto<T> {
/**
* 获取分页数
* */
*/
public long getPages() {
if (this.pageSize == 0L) {
return 0L;
@ -59,7 +57,6 @@ public class PageRespDto<T> {
if (this.total % this.pageSize != 0L) {
++pages;
}
return pages;
}
}

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.core.common.resp;
import io.github.xxyopen.novel.core.common.constant.ErrorCodeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import java.util.Objects;
@ -17,16 +18,19 @@ public class RestResp<T> {
/**
* 响应码
*/
@Schema(description = "错误码00000-没有错误")
private String code;
/**
* 响应消息
*/
@Schema(description = "响应消息")
private String message;
/**
* 响应数据
*/
@Schema(description = "响应数据")
private T data;
private RestResp() {

View File

@ -1,14 +1,15 @@
package io.github.xxyopen.novel.core.common.util;
import lombok.experimental.UtilityClass;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Base64;
import java.util.Random;
import javax.imageio.ImageIO;
import lombok.experimental.UtilityClass;
/**
* 图片验证码工具类

View File

@ -16,6 +16,7 @@ public class IpUtils {
/**
* 获取真实IP
*
* @return 真实IP
*/
public String getRealIp(HttpServletRequest request) {

View File

@ -2,6 +2,11 @@ package io.github.xxyopen.novel.core.config;
import com.github.benmanes.caffeine.cache.Caffeine;
import io.github.xxyopen.novel.core.constant.CacheConsts;
import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.support.SimpleCacheManager;
@ -13,12 +18,6 @@ import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 缓存配置类
*
@ -37,9 +36,11 @@ public class CacheConfig {
SimpleCacheManager cacheManager = new SimpleCacheManager();
List<CaffeineCache> caches = new ArrayList<>(CacheConsts.CacheEnum.values().length);
for (CacheConsts.CacheEnum c : CacheConsts.CacheEnum.values()) {
// 类型推断 var 非常适合 for 循环JDK 10 引入JDK 11 改进
for (var c : CacheConsts.CacheEnum.values()) {
if (c.isLocal()) {
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().recordStats().maximumSize(c.getMaxSize());
Caffeine<Object, Object> caffeine = Caffeine.newBuilder().recordStats()
.maximumSize(c.getMaxSize());
if (c.getTtl() > 0) {
caffeine.expireAfterWrite(Duration.ofSeconds(c.getTtl()));
}
@ -56,25 +57,32 @@ public class CacheConfig {
*/
@Bean
public CacheManager redisCacheManager(RedisConnectionFactory connectionFactory) {
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(
connectionFactory);
RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig()
.disableCachingNullValues().prefixCacheNameWith(CacheConsts.REDIS_CACHE_PREFIX);
Map<String, RedisCacheConfiguration> cacheMap = new LinkedHashMap<>(CacheConsts.CacheEnum.values().length);
for (CacheConsts.CacheEnum c : CacheConsts.CacheEnum.values()) {
Map<String, RedisCacheConfiguration> cacheMap = new LinkedHashMap<>(
CacheConsts.CacheEnum.values().length);
// 类型推断 var 非常适合 for 循环JDK 10 引入JDK 11 改进
for (var c : CacheConsts.CacheEnum.values()) {
if (c.isRemote()) {
if (c.getTtl() > 0) {
cacheMap.put(c.getName(), RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues()
.prefixCacheNameWith(CacheConsts.REDIS_CACHE_PREFIX).entryTtl(Duration.ofSeconds(c.getTtl())));
cacheMap.put(c.getName(),
RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues()
.prefixCacheNameWith(CacheConsts.REDIS_CACHE_PREFIX)
.entryTtl(Duration.ofSeconds(c.getTtl())));
} else {
cacheMap.put(c.getName(), RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues()
cacheMap.put(c.getName(),
RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues()
.prefixCacheNameWith(CacheConsts.REDIS_CACHE_PREFIX));
}
}
}
RedisCacheManager redisCacheManager = new RedisCacheManager(redisCacheWriter, defaultCacheConfig, cacheMap);
RedisCacheManager redisCacheManager = new RedisCacheManager(redisCacheWriter,
defaultCacheConfig, cacheMap);
redisCacheManager.setTransactionAware(true);
redisCacheManager.initializeCaches();
return redisCacheManager;

View File

@ -25,7 +25,7 @@ public class CorsConfig {
public CorsFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
// 允许的域,不要写*否则cookie就无法使用了
for (String allowOrigin : corsProperties.getAllowOrigins()) {
for (String allowOrigin : corsProperties.allowOrigins()) {
config.addAllowedOrigin(allowOrigin);
}
// 允许的头信息

View File

@ -1,6 +1,5 @@
package io.github.xxyopen.novel.core.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;
@ -12,11 +11,6 @@ import java.util.List;
* @date 2022/5/17
*/
@ConfigurationProperties(prefix = "novel.cors")
@Data
public class CorsProperties {
public record CorsProperties(List<String> allowOrigins) {
/**
* 允许跨域的域名
* */
private List<String> allowOrigins;
}

View File

@ -0,0 +1,26 @@
package io.github.xxyopen.novel.core.config;
import lombok.SneakyThrows;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Redisson 配置类
*
* @author xiongxiaoyang
* @date 2022/6/20
*/
@Configuration
public class RedissonConfig {
@Bean
@SneakyThrows
public RedissonClient redissonClient() {
Config config = Config.fromYAML(getClass().getResource("/redisson.yml"));
return Redisson.create(config);
}
}

View File

@ -12,9 +12,8 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Spring Web Mvc 相关配置
* 不要加 @EnableWebMvc 注解,否则会导致 jackson 的全局配置失效
* 类上添加 @EnableWebMvc 会导致 WebMvcAutoConfiguration 中的自动配置全部失效
* Spring Web Mvc 相关配置不要加 @EnableWebMvc 注解,否则会导致 jackson 的全局配置失效。因为 @EnableWebMvc 注解会导致
* WebMvcAutoConfiguration 自动配置失效
*
* @author xiongxiaoyang
* @date 2022/5/18

View File

@ -1,9 +1,7 @@
package io.github.xxyopen.novel.core.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Xss 过滤配置属性
@ -12,17 +10,6 @@ import java.util.List;
* @date 2022/5/17
*/
@ConfigurationProperties(prefix = "novel.xss")
@Data
public class XssProperties {
/**
* 过滤开关
* */
private Boolean enabled;
/**
* 排除链接
* */
private List<String> excludes;
public record XssProperties(Boolean enabled, List<String> excludes) {
}

View File

@ -10,22 +10,22 @@ public class AmqpConsts {
/**
* 小说信息改变 MQ
* */
*/
public static class BookChangeMq {
/**
* 小说信息改变交换机
* */
*/
public static final String EXCHANGE_NAME = "EXCHANGE-BOOK-CHANGE";
/**
* Elasticsearch book 索引更新的队列
* */
*/
public static final String QUEUE_ES_UPDATE = "QUEUE-ES-BOOK-UPDATE";
/**
* Redis book 缓存更新的队列
* */
*/
public static final String QUEUE_REDIS_UPDATE = "QUEUE-REDIS-BOOK-UPDATE";
}

View File

@ -34,32 +34,32 @@ public class ApiRouterConsts {
/**
* 首页模块请求路径前缀
* */
*/
public static final String HOME_URL_PREFIX = "/home";
/**
* 首页模块请求路径前缀
* */
*/
public static final String NEWS_URL_PREFIX = "/news";
/**
* 小说模块请求路径前缀
* */
*/
public static final String BOOK_URL_PREFIX = "/book";
/**
* 会员模块请求路径前缀
* */
*/
public static final String USER_URL_PREFIX = "/user";
/**
* 资源(图片/视频/文档)模块请求路径前缀
* */
*/
public static final String RESOURCE_URL_PREFIX = "/resource";
/**
* 搜索模块请求路径前缀
* */
*/
public static final String SEARCH_URL_PREFIX = "/search";
/**
@ -85,11 +85,13 @@ public class ApiRouterConsts {
/**
* 前台门户资源(图片/视频/文档相关API请求路径前缀
*/
public static final String API_FRONT_RESOURCE_URL_PREFIX = API_FRONT_URL_PREFIX + RESOURCE_URL_PREFIX;
public static final String API_FRONT_RESOURCE_URL_PREFIX =
API_FRONT_URL_PREFIX + RESOURCE_URL_PREFIX;
/**
* 前台门户搜索相关API请求路径前缀
* */
public static final String API_FRONT_SEARCH_URL_PREFIX = API_FRONT_URL_PREFIX + SEARCH_URL_PREFIX;
*/
public static final String API_FRONT_SEARCH_URL_PREFIX =
API_FRONT_URL_PREFIX + SEARCH_URL_PREFIX;
}

View File

@ -56,7 +56,7 @@ public class CacheConsts {
/**
* 小说分类列表缓存
* */
*/
public static final String BOOK_CATEGORY_LIST_CACHE_NAME = "bookCategoryListCache";
/**
@ -76,13 +76,14 @@ public class CacheConsts {
/**
* 最近更新小说ID列表缓存
* */
*/
public static final String LAST_UPDATE_BOOK_ID_LIST_CACHE_NAME = "lastUpdateBookIdListCache";
/**
* 图片验证码缓存 KEY
* */
public static final String IMG_VERIFY_CODE_CACHE_KEY = REDIS_CACHE_PREFIX + "imgVerifyCodeCache::";
*/
public static final String IMG_VERIFY_CODE_CACHE_KEY =
REDIS_CACHE_PREFIX + "imgVerifyCodeCache::";
/**
* 用户信息缓存

View File

@ -10,7 +10,6 @@ import lombok.Getter;
*/
public class DatabaseConsts {
/**
* 用户信息表
*/

View File

@ -14,7 +14,7 @@ public class EsConsts {
/**
* 小说索引
* */
*/
public static class BookIndex {
private BookIndex() {
@ -23,7 +23,7 @@ public class EsConsts {
/**
* 索引名
* */
*/
public static final String INDEX_NAME = "book";
/**

View File

@ -14,32 +14,32 @@ public class SystemConfigConsts {
/**
* Http 请求认证 Header
* */
*/
public static final String HTTP_AUTH_HEADER_NAME = "Authorization";
/**
* 前台门户系统标识
* */
*/
public static final String NOVEL_FRONT_KEY = "front";
/**
* 作家管理系统标识
* */
*/
public static final String NOVEL_AUTHOR_KEY = "author";
/**
* 后台管理系统标识
* */
*/
public static final String NOVEL_ADMIN_KEY = "admin";
/**
* 图片上传目录
* */
*/
public static final String IMAGE_UPLOAD_DIRECTORY = "/image/";
/**
* 常量类实例化异常信息
* */
*/
public static final String CONST_INSTANCE_EXCEPTION_MSG = "Constant class";
}

View File

@ -3,18 +3,22 @@ package io.github.xxyopen.novel.core.filter;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import io.github.xxyopen.novel.core.config.XssProperties;
import io.github.xxyopen.novel.core.wrapper.XssHttpServletRequestWrapper;
import jakarta.servlet.*;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 防止 XSS 攻击的过滤器
*
@ -28,7 +32,6 @@ import java.util.regex.Pattern;
@RequiredArgsConstructor
public class XssFilter implements Filter {
private final XssProperties xssProperties;
@Override
@ -37,22 +40,24 @@ public class XssFilter implements Filter {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletRequest;
if (handleExcludeUrl(req)) {
filterChain.doFilter(servletRequest, servletResponse);
return;
}
XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) servletRequest);
XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper(
(HttpServletRequest) servletRequest);
filterChain.doFilter(xssRequest, servletResponse);
}
private boolean handleExcludeUrl(HttpServletRequest request) {
if (CollectionUtils.isEmpty(xssProperties.getExcludes())) {
if (CollectionUtils.isEmpty(xssProperties.excludes())) {
return false;
}
String url = request.getServletPath();
for (String pattern : xssProperties.getExcludes()) {
for (String pattern : xssProperties.excludes()) {
Pattern p = Pattern.compile("^" + pattern);
Matcher m = p.matcher(url);
if (m.find()) {

View File

@ -9,18 +9,16 @@ import io.github.xxyopen.novel.core.constant.ApiRouterConsts;
import io.github.xxyopen.novel.core.constant.SystemConfigConsts;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* 认证 拦截器
* 为了注入其它的 Spring beans需要通过 @Component 注解将该拦截器注册到 Spring 上下文
* 认证授权 拦截器:为了注入其它的 Spring beans需要通过 @Component 注解将该拦截器注册到 Spring 上下文
*
* @author xiongxiaoyang
* @date 2022/5/18
@ -35,7 +33,8 @@ public class AuthInterceptor implements HandlerInterceptor {
@SuppressWarnings("NullableProblems")
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
// 获取登录 JWT
String token = request.getHeader(SystemConfigConsts.HTTP_AUTH_HEADER_NAME);
@ -55,14 +54,16 @@ public class AuthInterceptor implements HandlerInterceptor {
// 认证失败
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.getWriter().write(objectMapper.writeValueAsString(RestResp.fail(exception.getErrorCodeEnum())));
response.getWriter().write(
objectMapper.writeValueAsString(RestResp.fail(exception.getErrorCodeEnum())));
return false;
}
}
@SuppressWarnings("NullableProblems")
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// 清理当前线程保存的用户数据
UserHolder.clear();
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);

View File

@ -2,15 +2,14 @@ package io.github.xxyopen.novel.core.interceptor;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
/**
* 文件 拦截器
*
@ -26,12 +25,14 @@ public class FileInterceptor implements HandlerInterceptor {
@SuppressWarnings("NullableProblems")
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
// 获取请求的 URI
String requestUri = request.getRequestURI();
// 缓存10天
response.setDateHeader("expires", System.currentTimeMillis() + 60 * 60 * 24 * 10 * 1000);
try (OutputStream out = response.getOutputStream(); InputStream input = new FileInputStream(fileUploadPath + requestUri)) {
try (OutputStream out = response.getOutputStream(); InputStream input = new FileInputStream(
fileUploadPath + requestUri)) {
byte[] b = new byte[4096];
for (int n; (n = input.read(b)) != -1; ) {
out.write(b, 0, n);

View File

@ -15,20 +15,18 @@ import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.common.util.IpUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 流量限制 拦截器
* 实现接口防刷和限流
* 流量限制 拦截器:实现接口防刷和限流
*
* @author xiongxiaoyang
* @date 2022/6/1
@ -70,7 +68,8 @@ public class FlowLimitInterceptor implements HandlerInterceptor {
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
String ip = IpUtils.getRealIp(request);
Entry entry = null;
try {
@ -85,7 +84,8 @@ public class FlowLimitInterceptor implements HandlerInterceptor {
log.info("IP:{}被限流了!", ip);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.getWriter().write(objectMapper.writeValueAsString(RestResp.fail(ErrorCodeEnum.USER_REQ_MANY)));
response.getWriter()
.write(objectMapper.writeValueAsString(RestResp.fail(ErrorCodeEnum.USER_REQ_MANY)));
} finally {
// 注意exit 的时候也一定要带上对应的参数,否则可能会有统计错误。
if (entry != null) {

View File

@ -24,7 +24,8 @@ public class TokenParseInterceptor implements HandlerInterceptor {
private final JwtUtils jwtUtils;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
// 获取登录 JWT
String token = request.getHeader(SystemConfigConsts.HTTP_AUTH_HEADER_NAME);
if (StringUtils.hasText(token)) {
@ -35,7 +36,8 @@ public class TokenParseInterceptor implements HandlerInterceptor {
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// 清理当前线程保存的用户数据
UserHolder.clear();
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);

View File

@ -3,9 +3,8 @@ package io.github.xxyopen.novel.core.json.deserializer;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.boot.jackson.JsonComponent;
import java.io.IOException;
import org.springframework.boot.jackson.JsonComponent;
/**
@ -18,13 +17,13 @@ import java.io.IOException;
public class GlobalJsonDeserializer {
/**
* 字符串反序列化器
* 过滤特殊字符,解决 XSS 攻击
* 字符串反序列化器:过滤特殊字符,解决 XSS 攻击
*/
public static class StringDeserializer extends JsonDeserializer<String> {
@Override
public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
public String deserialize(JsonParser jsonParser,
DeserializationContext deserializationContext) throws IOException {
return jsonParser.getValueAsString()
.replace("<", "&lt;")
.replace(">", "&gt;");

View File

@ -3,7 +3,6 @@ package io.github.xxyopen.novel.core.json.serializer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
/**
@ -15,7 +14,8 @@ import java.io.IOException;
public class UsernameSerializer extends JsonSerializer<String> {
@Override
public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
public void serialize(String s, JsonGenerator jsonGenerator,
SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeString(s.substring(0, 4) + "****" + s.substring(8));
}

View File

@ -21,7 +21,8 @@ import org.springframework.stereotype.Component;
* @date 2022/5/25
*/
@Component
@ConditionalOnProperty(prefix = "spring", name = {"elasticsearch.enable","amqp.enable"}, havingValue = "true")
@ConditionalOnProperty(prefix = "spring", name = {"elasticsearch.enable",
"amqp.enable"}, havingValue = "true")
@RequiredArgsConstructor
@Slf4j
public class RabbitQueueListener {
@ -32,7 +33,7 @@ public class RabbitQueueListener {
/**
* 监听小说信息改变的 ES 更新队列,更新最新小说信息到 ES
* */
*/
@RabbitListener(queues = AmqpConsts.BookChangeMq.QUEUE_ES_UPDATE)
@SneakyThrows
public void updateEsBook(Long bookId) {

View File

@ -13,14 +13,13 @@ import io.github.xxyopen.novel.core.constant.EsConsts;
import io.github.xxyopen.novel.dao.entity.BookInfo;
import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
import io.github.xxyopen.novel.dto.es.EsBookDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 小说数据同步到 elasticsearch 任务
*

View File

@ -5,14 +5,13 @@ import io.jsonwebtoken.Jws;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
/**
* JWT 工具类
*
@ -37,6 +36,7 @@ public class JwtUtils {
/**
* 根据用户ID生成JWT
*
* @param uid 用户ID
* @param systemKey 系统标识
* @return JWT
@ -51,6 +51,7 @@ public class JwtUtils {
/**
* 解析JWT返回用户ID
*
* @param token JWT
* @param systemKey 系统标识
* @return 用户ID

View File

@ -2,7 +2,6 @@ package io.github.xxyopen.novel.core.wrapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;
import java.util.HashMap;
import java.util.Map;
@ -34,7 +33,8 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
for (int i = 0; i < length; i++) {
escapeValues[i] = values[i];
int index = i;
REPLACE_RULE.forEach((k, v)-> escapeValues[index] = escapeValues[index].replaceAll(k, v));
REPLACE_RULE.forEach(
(k, v) -> escapeValues[index] = escapeValues[index].replaceAll(k, v));
}
return escapeValues;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.Data;
@ -12,17 +13,20 @@ import lombok.Data;
@Data
public class AuthorRegisterReqDto {
@Schema(hidden = true)
private Long userId;
/**
* 笔名
*/
@Schema(description = "笔名", required = true)
@NotBlank(message = "笔名不能为空!")
private String penName;
/**
* 手机号码
*/
@Schema(description = "手机号码", required = true)
@NotBlank(message = "手机号不能为空!")
@Pattern(regexp = "^1[3|4|5|6|7|8|9][0-9]{9}$", message = "手机号格式不正确!")
private String telPhone;
@ -30,12 +34,14 @@ public class AuthorRegisterReqDto {
/**
* QQ或微信账号
*/
@Schema(description = "QQ或微信账号", required = true)
@NotBlank(message = "QQ或微信账号不能为空")
private String chatAccount;
/**
* 电子邮箱
*/
@Schema(description = "电子邮箱", required = true)
@NotBlank(message = "电子邮箱不能为空!")
@Email(message = "邮箱格式不正确!")
private String email;
@ -43,6 +49,7 @@ public class AuthorRegisterReqDto {
/**
* 作品方向;0-男频 1-女频
*/
@Schema(description = "作品方向;0-男频 1-女频", required = true)
@NotNull(message = "作品方向不能为空!")
@Min(0)
@Max(1)

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -16,42 +17,49 @@ public class BookAddReqDto {
/**
* 作品方向;0-男频 1-女频
*/
@Schema(description = "作品方向;0-男频 1-女频", required = true)
@NotNull
private Integer workDirection;
/**
* 类别ID
*/
@Schema(description = "类别ID", required = true)
@NotNull
private Long categoryId;
/**
* 类别名
*/
@Schema(description = "类别名", required = true)
@NotBlank
private String categoryName;
/**
* 小说封面地址
*/
@Schema(description = "小说封面地址", required = true)
@NotBlank
private String picUrl;
/**
* 小说名
*/
@Schema(description = "小说名", required = true)
@NotBlank
private String bookName;
/**
* 书籍描述
*/
@Schema(description = "书籍描述", required = true)
@NotBlank
private String bookDesc;
/**
* 是否收费;1-收费 0-免费
*/
@Schema(description = "是否收费;1-收费 0-免费", required = true)
@NotNull
private Integer isVip;
}

View File

@ -2,6 +2,7 @@ package io.github.xxyopen.novel.dto.req;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.github.xxyopen.novel.core.common.req.PageReqDto;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -19,36 +20,43 @@ public class BookSearchReqDto extends PageReqDto {
/**
* 搜索关键字
*/
@Parameter(description = "搜索关键字")
private String keyword;
/**
* 作品方向
*/
@Parameter(description = "作品方向")
private Integer workDirection;
/**
* 分类ID
*/
@Parameter(description = "分类ID")
private Integer categoryId;
/**
* 是否收费1收费0免费
*/
@Parameter(description = "是否收费1收费0免费")
private Integer isVip;
/**
* 小说更新状态0连载中1已完结
*/
@Parameter(description = "小说更新状态0连载中1已完结")
private Integer bookStatus;
/**
* 字数最小值
*/
@Parameter(description = "字数最小值")
private Integer wordCountMin;
/**
* 字数最大值
*/
@Parameter(description = "字数最大值")
private Integer wordCountMax;
/**
@ -57,6 +65,7 @@ public class BookSearchReqDto extends PageReqDto {
* 如果使用Post请求@RequestBody接收请求体参数默认解析日期格式为yyyy-MM-dd HH:mm:ss ,
* 如果需要接收其他格式的参数,则可以使用@JsonFormat注解
* */
@Parameter(description = "最小更新时间")
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date updateTimeMin;
@ -64,5 +73,6 @@ public class BookSearchReqDto extends PageReqDto {
/**
* 排序字段
*/
@Parameter(description = "排序字段")
private String sort;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -17,17 +18,20 @@ public class ChapterAddReqDto {
/**
* 小说ID
*/
@Schema(description = "小说ID", required = true)
private Long bookId;
/**
* 章节名
*/
@NotBlank
@Schema(description = "章节名", required = true)
private String chapterName;
/**
* 章节内容
*/
@Schema(description = "章节内容", required = true)
@NotBlank
@Length(min = 50)
private String chapterContent;
@ -35,6 +39,7 @@ public class ChapterAddReqDto {
/**
* 是否收费;1-收费 0-免费
*/
@Schema(description = "是否收费;1-收费 0-免费", required = true)
@NotNull
private Integer isVip;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -15,9 +16,11 @@ public class UserCommentReqDto {
private Long userId;
@Schema(description = "小说ID", required = true)
@NotNull(message="小说ID不能为空")
private Long bookId;
@Schema(description = "评论内容", required = true)
@NotBlank(message="评论不能为空!")
@Length(min = 10,max = 512)
private String commentContent;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Pattern;
@ -16,12 +17,15 @@ public class UserInfoUptReqDto {
private Long userId;
@Schema(description = "昵称")
@Length(min = 2,max = 10)
private String nickName;
@Schema(description = "头像地址")
@Pattern(regexp="^/[^\s]{10,}\\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF|bpm|BPM)$")
private String userPhoto;
@Schema(description = "性别")
@Min(value = 0)
@Max(value = 1)
private Integer userSex;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
@ -13,10 +14,12 @@ import lombok.Data;
@Data
public class UserLoginReqDto {
@Schema(description = "手机号", required = true, example = "18888888888")
@NotBlank(message = "手机号不能为空!")
@Pattern(regexp = "^1[3|4|5|6|7|8|9][0-9]{9}$", message = "手机号格式不正确!")
private String username;
@Schema(description = "密码", required = true, example = "123456")
@NotBlank(message = "密码不能为空!")
private String password;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
@ -14,13 +15,16 @@ import org.hibernate.validator.constraints.Length;
@Data
public class UserRegisterReqDto {
@Schema(description = "手机号", required = true)
@NotBlank(message="手机号不能为空!")
@Pattern(regexp="^1[3|4|5|6|7|8|9][0-9]{9}$",message="手机号格式不正确!")
private String username;
@Schema(description = "密码", required = true)
@NotBlank(message="密码不能为空!")
private String password;
@Schema(description = "验证码", required = true)
@NotBlank(message="验证码不能为空!")
@Pattern(regexp="^\\d{4}$",message="验证码格式不正确!")
private String velCode;
@ -28,6 +32,7 @@ public class UserRegisterReqDto {
/**
* 请求会话标识,用来标识图形验证码属于哪个会话
* */
@Schema(description = "sessionId", required = true)
@NotBlank
@Length(min = 32,max = 32)
private String sessionId;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -16,11 +17,13 @@ public class BookCategoryRespDto {
/**
* 类别ID
*/
@Schema(description = "类别ID")
private Long id;
/**
* 类别名
*/
@Schema(description = "类别名")
private String name;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -18,11 +19,13 @@ public class BookChapterAboutRespDto {
/**
* 章节总数
*/
@Schema(description = "章节总数")
private Long chapterTotal;
/**
* 内容概要30字
*/
@Schema(description = " 内容概要30字")
private String contentSummary;
}

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -24,37 +25,44 @@ public class BookChapterRespDto implements Serializable {
/**
* 章节ID
* */
@Schema(description = "章节ID")
private Long id;
/**
* 小说ID
*/
@Schema(description = "小说ID")
private Long bookId;
/**
* 章节号
*/
@Schema(description = "章节号")
private Integer chapterNum;
/**
* 章节名
*/
@Schema(description = "章节名")
private String chapterName;
/**
* 章节字数
*/
@Schema(description = "章节字数")
private Integer chapterWordCount;
/**
* 章节更新时间
*/
@Schema(description = "章节更新时间")
@JsonFormat(pattern = "yyyy/MM/dd HH:dd")
private LocalDateTime chapterUpdateTime;
/**
* 是否收费;1-收费 0-免费
*/
@Schema(description = "是否收费;1-收费 0-免费")
private Integer isVip;
}

View File

@ -3,6 +3,7 @@ package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.github.xxyopen.novel.core.json.serializer.UsernameSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -18,25 +19,33 @@ import java.util.List;
@Builder
public class BookCommentRespDto {
@Schema(description = "评论总数")
private Long commentTotal;
@Schema(description = "评论列表")
private List<CommentInfo> comments;
@Data
@Builder
public static class CommentInfo {
@Schema(description = "评论ID")
private Long id;
@Schema(description = "评论内容")
private String commentContent;
@Schema(description = "评论用户")
@JsonSerialize(using = UsernameSerializer.class)
private String commentUser;
@Schema(description = "评论用户ID")
private Long commentUserId;
@Schema(description = "评论用户头像")
private String commentUserPhoto;
@Schema(description = "评论时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime commentTime;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -16,16 +17,19 @@ public class BookContentAboutRespDto {
/**
* 小说信息
*/
@Schema(description = "小说信息")
private BookInfoRespDto bookInfo;
/**
* 章节信息
*/
@Schema(description = "章节信息")
private BookChapterRespDto chapterInfo;
/**
* 章节内容
*/
@Schema(description = "章节内容")
private String bookContent;
}

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@ -20,81 +21,97 @@ public class BookInfoRespDto {
/**
* ID
*/
@Schema(description = "小说ID")
private Long id;
/**
* 类别ID
*/
@Schema(description = "类别ID")
private Long categoryId;
/**
* 类别名
*/
@Schema(description = "类别名")
private String categoryName;
/**
* 小说封面地址
*/
@Schema(description = "小说封面地址")
private String picUrl;
/**
* 小说名
*/
@Schema(description = "小说名")
private String bookName;
/**
* 作家id
*/
@Schema(description = "作家id")
private Long authorId;
/**
* 作家名
*/
@Schema(description = "作家名")
private String authorName;
/**
* 书籍描述
*/
@Schema(description = "书籍描述")
private String bookDesc;
/**
* 书籍状态;0-连载中 1-已完结
*/
@Schema(description = "书籍状态;0-连载中 1-已完结")
private Integer bookStatus;
/**
* 点击量
*/
@Schema(description = "点击量")
private Long visitCount;
/**
* 总字数
*/
@Schema(description = "总字数")
private Integer wordCount;
/**
* 评论数
*/
@Schema(description = "评论数")
private Integer commentCount;
/**
* 首章节ID
*/
@Schema(description = "首章节ID")
private Long firstChapterId;
/**
* 最新章节ID
*/
@Schema(description = "最新章节ID")
private Long lastChapterId;
/**
* 最新章节名
*/
@Schema(description = "最新章节名")
private String lastChapterName;
/**
* 最新章节更新时间
*/
@Schema(description = "最新章节更新时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime updateTime;

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
@ -22,51 +23,61 @@ public class BookRankRespDto implements Serializable {
/**
* ID
*/
@Schema(description = "小说ID")
private Long id;
/**
* 类别ID
*/
@Schema(description = "类别ID")
private Long categoryId;
/**
* 类别名
*/
@Schema(description = "类别名")
private String categoryName;
/**
* 小说封面地址
*/
@Schema(description = "小说封面地址")
private String picUrl;
/**
* 小说名
*/
@Schema(description = "小说名")
private String bookName;
/**
* 作家名
*/
@Schema(description = "作家名")
private String authorName;
/**
* 书籍描述
*/
@Schema(description = "书籍描述")
private String bookDesc;
/**
* 总字数
*/
@Schema(description = "总字数")
private Integer wordCount;
/**
* 最新章节名
*/
@Schema(description = "最新章节名")
private String lastChapterName;
/**
* 最新章节更新时间
*/
@Schema(description = "最新章节更新时间")
@JsonFormat(pattern = "MM/dd HH:mm")
private LocalDateTime lastChapterUpdateTime;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
@ -14,31 +15,37 @@ public class HomeBookRespDto {
/**
* 类型;0-轮播图 1-顶部栏 2-本周强推 3-热门推荐 4-精品推荐
*/
@Schema(description = "类型;0-轮播图 1-顶部栏 2-本周强推 3-热门推荐 4-精品推荐")
private Integer type;
/**
* 推荐小说ID
*/
@Schema(description = "小说ID")
private Long bookId;
/**
* 小说封面地址
*/
@Schema(description = "小说封面地址")
private String picUrl;
/**
* 小说名
*/
@Schema(description = "小说名")
private String bookName;
/**
* 作家名
*/
@Schema(description = "作家名")
private String authorName;
/**
* 书籍描述
*/
@Schema(description = "书籍描述")
private String bookDesc;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
@ -20,10 +21,12 @@ public class HomeFriendLinkRespDto implements Serializable {
/**
* 链接名
*/
@Schema(description = "链接名")
private String linkName;
/**
* 链接url
*/
@Schema(description = "链接url")
private String linkUrl;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -15,11 +16,13 @@ public class ImgVerifyCodeRespDto {
/**
* 当前会话ID用于标识改图形验证码属于哪个会话
* */
@Schema(description = "sessionId")
private String sessionId;
/**
* Base64 编码的验证码图片
* */
@Schema(description = "Base64 编码的验证码图片")
private String img;
}

View File

@ -1,6 +1,7 @@
package io.github.xxyopen.novel.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -19,37 +20,44 @@ public class NewsInfoRespDto {
/**
* ID
*/
@Schema(description = "新闻ID")
private Long id;
/**
* 类别ID
*/
@Schema(description = "类别ID")
private Long categoryId;
/**
* 类别名
*/
@Schema(description = "类别名")
private String categoryName;
/**
* 新闻来源
*/
@Schema(description = "新闻来源")
private String sourceName;
/**
* 新闻标题
*/
@Schema(description = "新闻标题")
private String title;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDateTime updateTime;
/**
* 新闻内容
* */
@Schema(description = "新闻内容")
private String content;

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -16,15 +17,18 @@ public class UserInfoRespDto {
/**
* 昵称
* */
@Schema(description = "昵称")
private String nickName;
/**
* 用户头像
* */
@Schema(description = "用户头像")
private String userPhoto;
/**
* 用户性别
* */
@Schema(description = "用户性别")
private Integer userSex;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -12,9 +13,12 @@ import lombok.Data;
@Builder
public class UserLoginRespDto {
@Schema(description = "用户ID")
private Long uid;
@Schema(description = "用户昵称")
private String nickName;
@Schema(description = "用户token")
private String token;
}

View File

@ -1,5 +1,6 @@
package io.github.xxyopen.novel.dto.resp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
@ -12,7 +13,9 @@ import lombok.Data;
@Builder
public class UserRegisterRespDto {
@Schema(description = "用户ID")
private Long uid;
@Schema(description = "用户token")
private String token;
}

View File

@ -6,13 +6,12 @@ import io.github.xxyopen.novel.core.constant.DatabaseConsts;
import io.github.xxyopen.novel.dao.entity.AuthorInfo;
import io.github.xxyopen.novel.dao.mapper.AuthorInfoMapper;
import io.github.xxyopen.novel.dto.AuthorInfoDto;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* 作家信息 缓存管理类
*

View File

@ -6,12 +6,11 @@ import io.github.xxyopen.novel.core.constant.DatabaseConsts;
import io.github.xxyopen.novel.dao.entity.BookCategory;
import io.github.xxyopen.novel.dao.mapper.BookCategoryMapper;
import io.github.xxyopen.novel.dto.resp.BookCategoryRespDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 小说分类 缓存管理类
*

View File

@ -8,14 +8,13 @@ import io.github.xxyopen.novel.dao.entity.BookInfo;
import io.github.xxyopen.novel.dao.mapper.BookChapterMapper;
import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 小说信息 缓存管理类
*

View File

@ -6,12 +6,11 @@ import io.github.xxyopen.novel.core.constant.DatabaseConsts;
import io.github.xxyopen.novel.dao.entity.BookInfo;
import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
import io.github.xxyopen.novel.dto.resp.BookRankRespDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 小说排行榜 缓存管理类
*

View File

@ -6,12 +6,11 @@ import io.github.xxyopen.novel.core.constant.DatabaseConsts;
import io.github.xxyopen.novel.dao.entity.HomeFriendLink;
import io.github.xxyopen.novel.dao.mapper.HomeFriendLinkMapper;
import io.github.xxyopen.novel.dto.resp.HomeFriendLinkRespDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 友情链接 缓存管理类
*

View File

@ -8,16 +8,15 @@ import io.github.xxyopen.novel.dao.entity.HomeBook;
import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
import io.github.xxyopen.novel.dao.mapper.HomeBookMapper;
import io.github.xxyopen.novel.dto.resp.HomeBookRespDto;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
/**
* 首页推荐小说 缓存管理类

View File

@ -6,12 +6,11 @@ import io.github.xxyopen.novel.core.constant.DatabaseConsts;
import io.github.xxyopen.novel.dao.entity.NewsInfo;
import io.github.xxyopen.novel.dao.mapper.NewsInfoMapper;
import io.github.xxyopen.novel.dto.resp.NewsInfoRespDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 新闻 缓存管理类
*

View File

@ -4,12 +4,11 @@ import io.github.xxyopen.novel.core.constant.CacheConsts;
import io.github.xxyopen.novel.dao.entity.UserInfo;
import io.github.xxyopen.novel.dao.mapper.UserInfoMapper;
import io.github.xxyopen.novel.dto.UserInfoDto;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* 用户信息 缓存管理类
*

View File

@ -4,13 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.github.xxyopen.novel.core.constant.DatabaseConsts;
import io.github.xxyopen.novel.dao.entity.UserInfo;
import io.github.xxyopen.novel.dao.mapper.UserInfoMapper;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 用户模块 DAO管理类
*
* @author xiongxiaoyang
* @date 2022/5/20
*/
@ -22,9 +22,10 @@ public class UserDaoManager {
/**
* 根据用户ID集合批量查询用户信息列表
*
* @param userIds 需要查询的用户ID集合
* @return 满足条件的用户信息列表
* */
*/
public List<UserInfo> listUsers(List<Long> userIds) {
QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.in(DatabaseConsts.CommonColumnEnum.ID.getName(), userIds);

View File

@ -2,6 +2,7 @@ package io.github.xxyopen.novel.manager.mq;
import io.github.xxyopen.novel.core.common.constant.CommonConsts;
import io.github.xxyopen.novel.core.constant.AmqpConsts;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Value;
@ -9,8 +10,6 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import java.util.Objects;
/**
* AMQP 消息管理类
*
@ -35,10 +34,12 @@ public class AmqpMsgManager {
}
}
private void sendAmqpMessage(AmqpTemplate amqpTemplate, String exchange, String routingKey, Object message) {
private void sendAmqpMessage(AmqpTemplate amqpTemplate, String exchange, String routingKey,
Object message) {
// 如果在事务中则在事务执行完成后再发送,否则可以直接发送
if (TransactionSynchronizationManager.isActualTransactionActive()) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
TransactionSynchronizationManager.registerSynchronization(
new TransactionSynchronization() {
@Override
public void afterCommit() {
amqpTemplate.convertAndSend(exchange, routingKey, message);

View File

@ -2,15 +2,14 @@ package io.github.xxyopen.novel.manager.redis;
import io.github.xxyopen.novel.core.common.util.ImgVerifyCodeUtils;
import io.github.xxyopen.novel.core.constant.CacheConsts;
import java.io.IOException;
import java.time.Duration;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.Duration;
import java.util.Objects;
/**
* 验证码 管理类
*
@ -39,7 +38,8 @@ public class VerifyCodeManager {
* 校验图形验证码
*/
public boolean imgVerifyCodeOk(String sessionId, String verifyCode) {
return Objects.equals(stringRedisTemplate.opsForValue().get(CacheConsts.IMG_VERIFY_CODE_CACHE_KEY + sessionId), verifyCode);
return Objects.equals(stringRedisTemplate.opsForValue()
.get(CacheConsts.IMG_VERIFY_CODE_CACHE_KEY + sessionId), verifyCode);
}
/**

View File

@ -21,8 +21,9 @@ public interface AuthorService {
/**
* 查询作家状态
*
* @param userId 用户ID
* @return 作家状态
* */
*/
RestResp<Integer> getStatus(Long userId);
}

View File

@ -3,13 +3,19 @@ package io.github.xxyopen.novel.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.xxyopen.novel.core.annotation.Key;
import io.github.xxyopen.novel.core.annotation.Lock;
import io.github.xxyopen.novel.core.auth.UserHolder;
import io.github.xxyopen.novel.core.common.constant.ErrorCodeEnum;
import io.github.xxyopen.novel.core.common.req.PageReqDto;
import io.github.xxyopen.novel.core.common.resp.PageRespDto;
import io.github.xxyopen.novel.core.common.resp.RestResp;
import io.github.xxyopen.novel.core.constant.DatabaseConsts;
import io.github.xxyopen.novel.dao.entity.*;
import io.github.xxyopen.novel.dao.entity.BookChapter;
import io.github.xxyopen.novel.dao.entity.BookComment;
import io.github.xxyopen.novel.dao.entity.BookContent;
import io.github.xxyopen.novel.dao.entity.BookInfo;
import io.github.xxyopen.novel.dao.entity.UserInfo;
import io.github.xxyopen.novel.dao.mapper.BookChapterMapper;
import io.github.xxyopen.novel.dao.mapper.BookCommentMapper;
import io.github.xxyopen.novel.dao.mapper.BookContentMapper;
@ -18,23 +24,39 @@ import io.github.xxyopen.novel.dto.AuthorInfoDto;
import io.github.xxyopen.novel.dto.req.BookAddReqDto;
import io.github.xxyopen.novel.dto.req.ChapterAddReqDto;
import io.github.xxyopen.novel.dto.req.UserCommentReqDto;
import io.github.xxyopen.novel.dto.resp.*;
import io.github.xxyopen.novel.manager.cache.*;
import io.github.xxyopen.novel.dto.resp.BookCategoryRespDto;
import io.github.xxyopen.novel.dto.resp.BookChapterAboutRespDto;
import io.github.xxyopen.novel.dto.resp.BookChapterRespDto;
import io.github.xxyopen.novel.dto.resp.BookCommentRespDto;
import io.github.xxyopen.novel.dto.resp.BookContentAboutRespDto;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import io.github.xxyopen.novel.dto.resp.BookRankRespDto;
import io.github.xxyopen.novel.manager.cache.AuthorInfoCacheManager;
import io.github.xxyopen.novel.manager.cache.BookCategoryCacheManager;
import io.github.xxyopen.novel.manager.cache.BookChapterCacheManager;
import io.github.xxyopen.novel.manager.cache.BookContentCacheManager;
import io.github.xxyopen.novel.manager.cache.BookInfoCacheManager;
import io.github.xxyopen.novel.manager.cache.BookRankCacheManager;
import io.github.xxyopen.novel.manager.dao.UserDaoManager;
import io.github.xxyopen.novel.manager.mq.AmqpMsgManager;
import io.github.xxyopen.novel.service.BookService;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 小说模块 服务实现类
*
@ -98,7 +120,8 @@ public class BookServiceImpl implements BookService {
BookInfoRespDto bookInfo = bookInfoCacheManager.getBookInfo(bookId);
// 查询最新章节信息
BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(bookInfo.getLastChapterId());
BookChapterRespDto bookChapter = bookChapterCacheManager.getChapter(
bookInfo.getLastChapterId());
// 查询章节内容
String content = bookContentCacheManager.getBookContent(bookInfo.getLastChapterId());
@ -117,7 +140,8 @@ public class BookServiceImpl implements BookService {
}
@Override
public RestResp<List<BookInfoRespDto>> listRecBooks(Long bookId) throws NoSuchAlgorithmException {
public RestResp<List<BookInfoRespDto>> listRecBooks(Long bookId)
throws NoSuchAlgorithmException {
Long categoryId = bookInfoCacheManager.getBookInfo(bookId).getCategoryId();
List<Long> lastUpdateIdList = bookInfoCacheManager.getLastUpdateIdList(categoryId);
List<BookInfoRespDto> respDtoList = new ArrayList<>();
@ -188,7 +212,8 @@ public class BookServiceImpl implements BookService {
QueryWrapper<BookChapter> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(DatabaseConsts.BookChapterTable.COLUMN_BOOK_ID, bookId)
.orderByAsc(DatabaseConsts.BookChapterTable.COLUMN_CHAPTER_NUM);
return RestResp.ok(bookChapterMapper.selectList(queryWrapper).stream().map(v -> BookChapterRespDto.builder()
return RestResp.ok(bookChapterMapper.selectList(queryWrapper).stream()
.map(v -> BookChapterRespDto.builder()
.id(v.getId())
.chapterName(v.getChapterName())
.isVip(v.getIsVip())
@ -200,8 +225,10 @@ public class BookServiceImpl implements BookService {
return RestResp.ok(bookCategoryCacheManager.listCategory(workDirection));
}
@Lock(prefix = "userComment")
@Override
public RestResp<Void> saveComment(UserCommentReqDto dto) {
public RestResp<Void> saveComment(
@Key(expr = "#{userId + '::' + bookId}") UserCommentReqDto dto) {
// 校验用户是否已发表评论
QueryWrapper<BookComment> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(DatabaseConsts.BookCommentTable.COLUMN_USER_ID, dto.getUserId())
@ -226,7 +253,8 @@ public class BookServiceImpl implements BookService {
QueryWrapper<BookComment> commentCountQueryWrapper = new QueryWrapper<>();
commentCountQueryWrapper.eq(DatabaseConsts.BookCommentTable.COLUMN_BOOK_ID, bookId);
Long commentTotal = bookCommentMapper.selectCount(commentCountQueryWrapper);
BookCommentRespDto bookCommentRespDto = BookCommentRespDto.builder().commentTotal(commentTotal).build();
BookCommentRespDto bookCommentRespDto = BookCommentRespDto.builder()
.commentTotal(commentTotal).build();
if (commentTotal > 0) {
// 查询最新的评论列表
@ -239,7 +267,8 @@ public class BookServiceImpl implements BookService {
// 查询评论用户信息,并设置需要返回的评论用户名
List<Long> userIds = bookComments.stream().map(BookComment::getUserId).toList();
List<UserInfo> userInfos = userDaoManager.listUsers(userIds);
Map<Long, UserInfo> userInfoMap = userInfos.stream().collect(Collectors.toMap(UserInfo::getId, Function.identity()));
Map<Long, UserInfo> userInfoMap = userInfos.stream()
.collect(Collectors.toMap(UserInfo::getId, Function.identity()));
List<BookCommentRespDto.CommentInfo> commentInfos = bookComments.stream()
.map(v -> BookCommentRespDto.CommentInfo.builder()
.id(v.getId())

View File

@ -8,13 +8,12 @@ import io.github.xxyopen.novel.dao.mapper.BookInfoMapper;
import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import io.github.xxyopen.novel.service.SearchService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 数据库搜索 服务实现类
*
@ -35,7 +34,8 @@ public class DbSearchServiceImpl implements SearchService {
page.setCurrent(condition.getPageNum());
page.setSize(condition.getPageSize());
List<BookInfo> bookInfos = bookInfoMapper.searchBooks(page, condition);
return RestResp.ok(PageRespDto.of(condition.getPageNum(), condition.getPageSize(), page.getTotal(),
return RestResp.ok(
PageRespDto.of(condition.getPageNum(), condition.getPageSize(), page.getTotal(),
bookInfos.stream().map(v -> BookInfoRespDto.builder()
.id(v.getId())
.bookName(v.getBookName())

View File

@ -19,16 +19,15 @@ import io.github.xxyopen.novel.dto.es.EsBookDto;
import io.github.xxyopen.novel.dto.req.BookSearchReqDto;
import io.github.xxyopen.novel.dto.resp.BookInfoRespDto;
import io.github.xxyopen.novel.service.SearchService;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Elasticsearch 搜索 服务实现类
*
@ -77,14 +76,17 @@ public class EsSearchServiceImpl implements SearchService {
List<BookInfoRespDto> list = new ArrayList<>();
List<Hit<EsBookDto>> hits = response.hits().hits();
for (Hit<EsBookDto> hit : hits) {
// 类型推断 var 非常适合 for 循环JDK 10 引入JDK 11 改进
for (var hit : hits) {
EsBookDto book = hit.source();
assert book != null;
if (!CollectionUtils.isEmpty(hit.highlight().get(EsConsts.BookIndex.FIELD_BOOK_NAME))) {
book.setBookName(hit.highlight().get(EsConsts.BookIndex.FIELD_BOOK_NAME).get(0));
}
if (!CollectionUtils.isEmpty(hit.highlight().get(EsConsts.BookIndex.FIELD_AUTHOR_NAME))) {
book.setAuthorName(hit.highlight().get(EsConsts.BookIndex.FIELD_AUTHOR_NAME).get(0));
if (!CollectionUtils.isEmpty(
hit.highlight().get(EsConsts.BookIndex.FIELD_AUTHOR_NAME))) {
book.setAuthorName(
hit.highlight().get(EsConsts.BookIndex.FIELD_AUTHOR_NAME).get(0));
}
list.add(BookInfoRespDto.builder()
.id(book.getId())
@ -98,14 +100,16 @@ public class EsSearchServiceImpl implements SearchService {
.build());
}
assert total != null;
return RestResp.ok(PageRespDto.of(condition.getPageNum(), condition.getPageSize(), total.value(), list));
return RestResp.ok(
PageRespDto.of(condition.getPageNum(), condition.getPageSize(), total.value(), list));
}
/**
* 构建检索条件
*/
private void buildSearchCondition(BookSearchReqDto condition, SearchRequest.Builder searchBuilder) {
private void buildSearchCondition(BookSearchReqDto condition,
SearchRequest.Builder searchBuilder) {
BoolQuery boolQuery = BoolQuery.of(b -> {

View File

@ -10,11 +10,10 @@ import io.github.xxyopen.novel.dao.mapper.NewsInfoMapper;
import io.github.xxyopen.novel.dto.resp.NewsInfoRespDto;
import io.github.xxyopen.novel.manager.cache.NewsCacheManager;
import io.github.xxyopen.novel.service.NewsService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 新闻模块 服务实现类
*

View File

@ -8,20 +8,19 @@ import io.github.xxyopen.novel.core.constant.SystemConfigConsts;
import io.github.xxyopen.novel.dto.resp.ImgVerifyCodeRespDto;
import io.github.xxyopen.novel.manager.redis.VerifyCodeManager;
import io.github.xxyopen.novel.service.ResourceService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import javax.imageio.ImageIO;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
* 资源(图片/视频/文档)相关服务实现类

View File

@ -22,13 +22,12 @@ import io.github.xxyopen.novel.dto.resp.UserLoginRespDto;
import io.github.xxyopen.novel.dto.resp.UserRegisterRespDto;
import io.github.xxyopen.novel.manager.redis.VerifyCodeManager;
import io.github.xxyopen.novel.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
/**
* 会员模块 服务实现类
@ -69,7 +68,8 @@ public class UserServiceImpl implements UserService {
// 注册成功,保存用户信息
UserInfo userInfo = new UserInfo();
userInfo.setPassword(DigestUtils.md5DigestAsHex(dto.getPassword().getBytes(StandardCharsets.UTF_8)));
userInfo.setPassword(
DigestUtils.md5DigestAsHex(dto.getPassword().getBytes(StandardCharsets.UTF_8)));
userInfo.setUsername(dto.getUsername());
userInfo.setNickName(dto.getUsername());
userInfo.setCreateTime(LocalDateTime.now());

View File

@ -1,7 +1,6 @@
spring:
profiles:
active: dev
# 将所有数字转为 String 类型返回,避免前端数据精度丢失的问题
jackson:
generator:
@ -10,6 +9,8 @@ spring:
# 上传文件最大大小
multipart:
max-file-size: 5MB
application:
name: novel
server:
port: 8888
@ -129,6 +130,66 @@ xxl:
accessToken: 123
---
spring:
config:
activate:
on-profile: dev
# Spring Boot 应用管理和监控
boot:
admin:
client:
# 是否开启 Spring Boot Admin 客户端
enabled: false
# Spring Boot Admin 服务端注册地址
url: http://localhost:8080
# Spring Boot Admin 服务端认证用户名
username: novel
# Spring Boot Admin 服务端认证密码
password: novel
instance:
metadata:
# SBA Client
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
security:
user:
name: ENDPOINT_ADMIN
password: ENDPOINT_ADMIN
roles: ENDPOINT_ADMIN
# Actuator 端点管理
management:
# 端点公开配置
endpoints:
# 通过 HTTP 公开的 Web 端点
web:
exposure:
# 公开所有的 Web 端点
include: "*"
# 端点启用配置
endpoint:
logfile:
# 启用返回日志文件内容的端点
enabled: true
# 外部日志文件路径
external-file: logs/novel.log
info:
env:
# 公开所有以 info. 开头的环境属性
enabled: true
health:
rabbit:
# 关闭 rabbitmq 的健康检查
enabled: false
elasticsearch:
# 关闭 elasticsearch 的健康检查
enabled: false
---
spring:
config:

View File

@ -53,26 +53,26 @@
<!-- ROOT 日志级别 -->
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
<!-- com.maijinjie.springboot 为根包也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
<!-- 级别依次为【从高到低】FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
<logger name="io.github.xxyopen" level="DEBUG" additivity="false">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</logger>
</springProfile>
<springProfile name="prod">
<!-- ROOT 日志级别 -->
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
<!-- com.maijinjie.springboot 为根包也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
<!-- 级别依次为【从高到低】FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
<logger name="io.github.xxyopen" level="ERROR" additivity="false">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</logger>
</springProfile>

View File

@ -0,0 +1,3 @@
singleServerConfig:
address: "redis://127.0.0.1:6379"
password: 123456