feat: update api of openai
This commit is contained in:
commit
84b3f54afa
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
HELP.md
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
src/main/resources/application-prod.yml
|
||||||
|
/jmh-result.json
|
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
|
||||||
|
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
|
201
LICENSE
Normal file
201
LICENSE
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
842
README.md
Normal file
842
README.md
Normal file
@ -0,0 +1,842 @@
|
|||||||
|
# 智能图书馆开源文档
|
||||||
|
|
||||||
|
>作者:[程序员小白条](https://luoye6.github.io/)
|
||||||
|
>
|
||||||
|
>[Gitee 主页](https://gitee.com/falle22222n-leaves)
|
||||||
|
>
|
||||||
|
>[GitHub 主页](https://github.com/luoye6)
|
||||||
|
|
||||||
|
Language:**[English](README_en.md)**| **[中文](README.md).**
|
||||||
|
|
||||||
|
## ☀️新手必读
|
||||||
|
|
||||||
|
+ 本项目拥有完整的API后台接口文档(文尾)(重点⭐)
|
||||||
|
+ 未经本人允许擅自将本项目作于商用、竞赛、贩卖源码、毕设擅自改动作者等违法行为,将依法追究法律责任,后果自负,项目已申请软件著作权。
|
||||||
|
+ 拥有典型的大学生思维、狂妄、自大的人请不要加我,谢谢合作!
|
||||||
|
+ 如果项目对您有所帮助,可以Star⭐一下,受到鼓励的我会继续加油。
|
||||||
|
+ [项目在线演示地址](https://www.xiaobaitiao.top)
|
||||||
|
+ [项目前端地址](https://gitee.com/falle22222n-leaves/vue_-book-manage-system)
|
||||||
|
+ [项目后端地址](https://gitee.com/falle22222n-leaves/vue_-book-manage-system_backend)
|
||||||
|
+ [项目部署视频](https://www.bilibili.com/video/BV1Zh4y1z7QE/?spm_id_from=333.999.0.0)
|
||||||
|
|
||||||
|
[](https://gitee.com/falle22222n-leaves/vue_-book-manage-system) [](https://gitee.com/falle22222n-leaves) [](https://github.com/luoye6)
|
||||||
|
|
||||||
|
## 黑马程序员推荐作品(doge)
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️个人介绍
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐼新项目上线(开新坑)
|
||||||
|
智能 AI 旅游推荐平台上线!欢迎收藏和 Fork,技术栈 Vue3+SpringBoot2+TypeScript,UI 设计更加美观,且可以自定义主题颜色,支持讯飞星火 AI 大模型和可添加协同过滤算法。
|
||||||
|
+ [项目在线演示地址](https://www.xiaobaitiao.icu)
|
||||||
|
+ [项目前端地址](https://gitee.com/falle22222n-leaves/vue3_tourism_frontend)
|
||||||
|
+ [项目后端地址](https://gitee.com/falle22222n-leaves/vue3_tourism_backend)
|
||||||
|
|
||||||
|
## ☀️项目介绍
|
||||||
|
|
||||||
|
**AI 智能图书馆**(AI Intelligent Library)是一个利用 AI 模型和数据分析对用户所喜欢的图书进行精准推荐的系统,并且提供了 AIGC 的在线生成借阅量分析的 BI 图表功能,能够起到一个数据分析师的作用。其主要有三大使用者:用户(借阅人)、图书管理员、系统管理员。
|
||||||
|
|
||||||
|
> Ps:如果你想要简易和新颖,那么这个项目将会是不错的选择~
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️功能和特性
|
||||||
|
|
||||||
|
### 用户功能
|
||||||
|
|
||||||
|
1)图书查询功能:分页构造器缓解数据过大压力,后端可设置请求数防止爬虫请求数过大,服务器负载过大。模糊查询进行字段搜索。表格均**可导出 PDF 和 EXCEL**。
|
||||||
|
|
||||||
|
2)读者规则功能:查询现有的借阅规则,借阅规则包括:借阅编号,可借阅图书数量,可借阅天数,可借阅图书馆,过期扣费/天。
|
||||||
|
|
||||||
|
3)查看公告: 可以查询图书管理员发布的公告列表,**文字滑动效果**。
|
||||||
|
|
||||||
|
4)个人信息: 可以查看个人的借阅证编号,借阅证姓名,规则编号,状态,可以修改个人账户的密码。
|
||||||
|
|
||||||
|
5)借阅信息: 可以查看自身借阅过的图书记录和归还情况。
|
||||||
|
|
||||||
|
6)违章信息: 可以查询自身归还的图书是否有违章信息。
|
||||||
|
|
||||||
|
7)读者留言: 实现留言功能并以**弹幕形式**显示。
|
||||||
|
|
||||||
|
8)**智能推荐**用户输入自己的偏好,AI 根据数据库书籍列表和用户偏好,给用户推荐书籍。
|
||||||
|
|
||||||
|
### 图书管理员功能
|
||||||
|
|
||||||
|
1)借阅图书: 图书管理员输入借阅证号(用户)和要借的图书编号和当前的时间,点击借阅。
|
||||||
|
|
||||||
|
2)归还图书: 输入图书编号查看图书是否逾期,并且可以设置违规信息,然后选择是否归还图书。
|
||||||
|
|
||||||
|
3)借书报表: 用于查询已经借阅并归还的书籍列表,同样使用分页构造器和模糊查询字段,显示借阅证编号,图书编号,借阅日期,截止日期,归还日期,违章信息,处理人。
|
||||||
|
|
||||||
|
4)还书报表: 用于查询已经借阅但是还未归还的书籍列表,显示借阅证编号,图书编号,借阅日期,截止日期。
|
||||||
|
|
||||||
|
5)发布公告: 可以查询当前发布的公告列表,并进行删除,修改,增加功能,分页构造器用于缓解数据量大的情况。
|
||||||
|
|
||||||
|
### 系统管理员功能
|
||||||
|
|
||||||
|
1)书籍管理: 可以查询当前的所有图书,显示图书编号,图书昵称,作者,图书馆,分类,位置,状态,描述。可以进行添加,修改,删除图书。利用分页构造器实现批量查询。利用模糊查询实现图书搜索功能。**利用插件实现 PDF 和 EXCEL 导出**。
|
||||||
|
|
||||||
|
2)书籍类型: 显示查询当前的所有图书类型,可以进行添加,修改,删除图书类型,利用分页构造器实现批量查询,缓解数据压力。
|
||||||
|
|
||||||
|
3)借阅证管理: 可以查询当前的所有借阅证列表,也就是用户数量,可以进行添加,修改,删除操作。同样实现分页。
|
||||||
|
|
||||||
|
4)借阅信息查询: 可以查询当前已经完成借阅和归还的记录,显示借阅证号,书籍编号,借阅日期,截止日期,归还日期,违章信息,处理人。分页功能,PDF 和 EXCEL 导出。
|
||||||
|
|
||||||
|
5)借阅规则管理: 可以查询当前所有的借阅规则,显示限制借阅天数,限制本数,限制图书馆,逾期费用,可以进行添加、删除、修改操作。
|
||||||
|
|
||||||
|
6)图书管理员管理: 显示当前的图书管理员列表,显示账号,姓名,邮箱,可以进行添加、删除、修改操作。
|
||||||
|
|
||||||
|
7)系统管理: 可以查询一个月内的借阅量,以一周为时间间隔,计算借阅量,**用 Echarts 实现各种图表的展示**。
|
||||||
|
|
||||||
|
8)系统分析:可以上传某个时间段的借阅量和日期,并且输入分析目标和想要生成的图表类型,等待一段时间后,**AI 将会给出分析结论和可视化图表**。
|
||||||
|
|
||||||
|
### 特性(亮点)
|
||||||
|
|
||||||
|
1)本项目采用前后端分离的模式,前端构建页面,后端作数据接口,前端调用后端数据接口得到数据,重新渲染页面。
|
||||||
|
|
||||||
|
2)前端在 Authorization 字段提供 Token 令牌,API 认证使用 Token 认证,使用 HTTP Status Code 表示状态,数据返回格式使用 JSON。
|
||||||
|
|
||||||
|
3)后端已开启 CORS 跨域支持,采用权限拦截器进行权限校验,并检查登录情况。
|
||||||
|
|
||||||
|
4)添加全局异常处理机制,捕获异常,增强系统健壮性。
|
||||||
|
|
||||||
|
5)前端用 Echarts 可视化库实现了图书借阅的分析图标(折线图、饼图),并通过 Loading 配置提高加载体验。
|
||||||
|
|
||||||
|
6)留言组件采用弹幕形式,贴合用户的喜好。
|
||||||
|
|
||||||
|
7)引入 knife4j 依赖,使用 Swagger + Knife4j 自动生成 OpenAPI 规范的接口文档,前端可以在此基础上使用插件自动生成接口请求代码,降低前后端协作成本
|
||||||
|
|
||||||
|
8)使用 ElementUI 组件库进行前端界面搭建,快速实现页面生成,并实现了前后端统一权限管理,多环境切换等能力。
|
||||||
|
|
||||||
|
9)基于 MyBatis Plus 框架的 QueryWrapper 实现对 MySQL 数据库的灵活查询,并配合 MyBatisX 插件自动生成后端 CRUD 基础代码,减少重复工作。
|
||||||
|
|
||||||
|
10)前端路由懒加载、CDN 静态资源缓存优化、图片懒加载效果。
|
||||||
|
|
||||||
|
## ☀️运行方式
|
||||||
|
|
||||||
|
### 2 分钟快速上手使用项目
|
||||||
|
|
||||||
|
1)找到 SpringBoot 启动类,点击运行
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2)打开 Knife4J 注册用户,或者可以直接找我拿数据库模拟数据(简易)。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
3)前端输入表单内容后点击登录即可成功,开始愉快使用功能~
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️部署方式
|
||||||
|
|
||||||
|
### 前置条件
|
||||||
|
|
||||||
|
**前端**
|
||||||
|
|
||||||
|
软件:Vscode 或者 Webstorm(推荐)
|
||||||
|
|
||||||
|
环境:Node 版本 16 或者 18(推荐) **注:千万别选 18 以上的版本!**
|
||||||
|
|
||||||
|
**后端**
|
||||||
|
|
||||||
|
软件:Eclipse 或者 IDEA(推荐)
|
||||||
|
|
||||||
|
环境:MySQL 5.7 或者 8.0(推荐)Redis(可选)
|
||||||
|
|
||||||
|
### 前端部署
|
||||||
|
|
||||||
|
1)点击克隆/下载项目,会使用 Git 进行版本控制的,推荐 Git Clone,不会的小伙伴可以选择下载一个 Zip 压缩包,然后解压到自己电脑的 D 盘,推荐直接 Star,后续直接向我拿数据库模拟文件和 API 接口文档。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2)利用 Vscode 或者 Webstorm 打开前端页面,配置 Configuration。配置 Node 环境和包管理工具即可,我这边选择的包管理工具是 Npm,其他包管理工具如:Yarn、Cnpm、Pnpm 皆可。 **注:注意更改 Npm 的镜像地址为淘宝的新镜像地址,否则会出现 Npm Install 一直卡进度条的情况。**
|
||||||
|
|
||||||
|
3)直接点击 dev 的运行,或者打开控制台,输入 npm run serve 即可成功启动前端项目。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
npm config set registry https://registry.npmmirror.com/
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
4)将图片链接进行自定义切换,可以切换为你自己的图床的图片链接,比如七牛云、GitHub 等,也可以寻找在线图片,复制百度文库图片链接(多试几次,有些图片有防盗链)。**更换背景后,可以看到右下角的权限切换小图标。**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 后端部署
|
||||||
|
|
||||||
|
1)点击克隆/下载项目,会使用 Git 进行版本控制的,推荐 Git Clone,不会的小伙伴可以选择下载一个 Zip 压缩包,然后解压到自己电脑的 D 盘,推荐直接 Star,后续直接向我拿数据库模拟文件和 API 接口文档。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2)领取数据库模拟文件后,利用 Navicat 或者 SQLYog 等软件导入数据库文件,记得先建立一个名为 bms_boot 的数据库,然后右键点击运行 SQL 文件即可,运行成功,无报错后,重新打开数据库,检查是否有数据,如果有数据,表明导入成功。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
3)用 IDEA 打开后端项目,找到 application-dev.yml 文件,修改其中的 MySQL 配置,保证用户名和密码正确,注:密码不能以数字 0 开头。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
4)导入 Maven 依赖,注意看自己的 Maven 版本是否正确,建议选择跟我一样的,3.8以上的版本,发现依赖导入很慢,是因为没有配置国内镜像,默认连接的是国外服务器,因此阿里云镜像配置可以看这篇博客。[CSDN Maven 配置教程](https://blog.csdn.net/lianghecai52171314/article/details/102625184?ops_request_misc=&request_id=&biz_id=102&utm_term=Maven)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
5)找到 SpringBoot 启动类,我建议用 Debug 模式启动项目,更好排查错误。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
6)如果遇到错误,大概率可能是 JDK 版本问题,我项目用的是 JDK 8,建议选择与我相同版本。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
7)成功启动项目效果展示如下
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 前后端联调
|
||||||
|
|
||||||
|
1)如果需要修改端口和前缀(比如/api),需要同时修改前端和后端。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️技术选型
|
||||||
|
|
||||||
|
### 前端
|
||||||
|
|
||||||
|
| **技术** | **作用** | **版本** |
|
||||||
|
| ---------------------------- | ------------------------------------------------------------ | ---------------------------------------------------- |
|
||||||
|
| Vue | 提供前端交互 | 2.6.14 |
|
||||||
|
| Vue-Router | 路由式编程导航 | 3.5.1 |
|
||||||
|
| Element-UI | 模块组件库,绘制界面 | 2.4.5 |
|
||||||
|
| Axios | 发送ajax请求给后端请求数据 | 1.2.1 |
|
||||||
|
| core-js | 兼容性更强,浏览器适配 | 3.8.3 |
|
||||||
|
| swiper | 轮播图插件(快速实现) | 3.4.2 |
|
||||||
|
| vue-baberrage | vue弹幕插件(实现留言功能) | 3.2.4 |
|
||||||
|
| vue-json-excel | 表格导出Excel | 0.3.0 |
|
||||||
|
| html2canvas+jspdf | 表格导出PDF | 1.4.1 2.5.1 |
|
||||||
|
| node-polyfill-webpack-plugin | webpack5中移除了nodejs核心模块的polyfill自动引入 | 2.0.1 |
|
||||||
|
| default-passive-events | **Chrome** 增加了新的事件捕获机制 **Passive Event Listeners**(被动事件侦听器) | 让页面滑动更加流畅,主要用于提升移动端滑动行为的性能 |
|
||||||
|
| nprogress | 发送请求显示进度条(人机交互友好) | 0.2.0 |
|
||||||
|
| echarts | 数据转图标的好工具(功能强大) | 5.4.1 |
|
||||||
|
| less lessloader | 方便样式开发 | 4.1.3 11.1.0 |
|
||||||
|
|
||||||
|
### 后端
|
||||||
|
|
||||||
|
| **技术及版本** | **作用** | **版本** |
|
||||||
|
| ------------------------------------ | ------------------------------------------------------------ | --------------------------------- |
|
||||||
|
| SpringBoot | 应用开发框架 | 2.7.8 |
|
||||||
|
| JDK | Java 开发包 | 1.8 |
|
||||||
|
| MySQL | 提供后端数据库 | 8.0.23 |
|
||||||
|
| MyBatisPlus | 提供连接数据库和快捷的增删改查 | 3.5.1 |
|
||||||
|
| SpringBoot-Configuration-processor | 配置处理器 定义的类和配置文件绑定一般没有提示,因此可以添加配置处理器,产生相对应的提示. | |
|
||||||
|
| SpringBoot-Starter-Web | 后端集成Tomcat MVC | 用于和前端连接 |
|
||||||
|
| SpringBoot-starter-test | Junit4单元测试前端在调用接口前,后端先调用单元测试进行增删改查,注意Junit4和5的问题,注解@RunWith是否添加 | |
|
||||||
|
| Lombok | 实体类方法的快速生成 简化代码 | |
|
||||||
|
| mybatis-plus-generator | 代码生成器 | 3.5.1 |
|
||||||
|
| MyBatisX | MyBatisPlus插件直接生成mapper,实体类,service | |
|
||||||
|
| jjwt | token工具包 | 0.9.0 |
|
||||||
|
| fastjson | 阿里巴巴的 JSON 工具类 | 1.2.83 |
|
||||||
|
| hutool | hutool工具包(简化开发工具类) | [文档](https://hutool.cn/docs/#/) |
|
||||||
|
| knife4j-openapi2-spring-boot-starter | Knife4j 在线接口文档测试工具 | 4.0.0 |
|
||||||
|
| gson | 谷歌的 JSON 工具类 | 2.8.5 |
|
||||||
|
| Java-WebSocket | 讯飞星火 AI 配置 | 1.3.8 |
|
||||||
|
| okhttp | 讯飞星火 AI 配置 | 4.10.0 |
|
||||||
|
| okio | 讯飞星火 AI 配置 | 2.10.0 |
|
||||||
|
| jsoup | 简易爬虫工具 | 1.15.3 |
|
||||||
|
| guava | 谷歌工具类 | 30.1-jre |
|
||||||
|
| spring-boot-starter-data-redis | Redis 的 Starter | |
|
||||||
|
| broadscope-bailian-sdk-java | 阿里云 AI 模型 | 1.1.7 |
|
||||||
|
| spring-boot-starter-websocket | WebSocket 的 Starter | |
|
||||||
|
|
||||||
|
## ☀️架构
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️核心设计
|
||||||
|
|
||||||
|
### 智能推荐功能
|
||||||
|
|
||||||
|
1)用户输入自己的图书偏爱信息。
|
||||||
|
|
||||||
|
2)前端发送 Axios 请求。
|
||||||
|
|
||||||
|
3)后端先判断文本是否违法(为空或者文本字数过长)。
|
||||||
|
|
||||||
|
4)查看接口是否存在。
|
||||||
|
|
||||||
|
5)查看 AI 接口调用次数是否充足。
|
||||||
|
|
||||||
|
6)GuavaRateLimiter 进行单体限流,判断请求次数是否超出正常业务频次。
|
||||||
|
|
||||||
|
7)给 AI 模型人工预设,并且查询数据库中的书籍列表进行拼接。
|
||||||
|
|
||||||
|
8)查询 AI 模型与该用户最近的五条历史记录,用于上下文关联。
|
||||||
|
|
||||||
|
9)FutureTask 同步调用获取 AI 结果,并设置超时时间(超时抛出异常)
|
||||||
|
|
||||||
|
10)获取 AI 模型推荐信息后进行持久化,并且减少接口调用次数(判断是否成功)
|
||||||
|
|
||||||
|
11)返回处理好的 AI 推荐信息给前端,并设置响应状态码为 200 即可。
|
||||||
|
|
||||||
|
### 智能分析功能
|
||||||
|
|
||||||
|
1)用户输入分析目标、图标名称、选择图标类型、上传 Excel 文件,点击提交,发送 Axios 请求至后端。
|
||||||
|
|
||||||
|
2)校验文件是否为空、名称是否过长、文件大小检验、文件后缀校验
|
||||||
|
|
||||||
|
3)获取管理员 ID,从接口信息表查询管理员 ID 拥有的接口,接口判空。
|
||||||
|
|
||||||
|
4)判断 AI 接口调用次数是否足够
|
||||||
|
|
||||||
|
5)GuavaRateLimiter 进行单体限流,判断请求次数是否超出正常业务频次。
|
||||||
|
|
||||||
|
6)构造 AI 模型的提示词和角色
|
||||||
|
|
||||||
|
7)构造用户输入,拼接用户输入信息,并用工具类将 Excel 转为 CSV 字符串数据。
|
||||||
|
|
||||||
|
8)利用讯飞星火 AI 模型,传入调用者 ID 和输入参数,利用 FutureTask 同步获取,并设置超时时间(超时抛出异常)
|
||||||
|
|
||||||
|
9)对 AI 生成结果进行判断,格式错误就返回前端错误信息,并提示重新调用(后续考虑 RabbitMQ 进行重试和补偿机制)
|
||||||
|
|
||||||
|
10)将 AI 生成结果持久化到数据库,并更新接口调用次数(判断是否成功),动态给前端返回图标和数据结论。
|
||||||
|
|
||||||
|
## ☀️学完这个项目你能得到什么
|
||||||
|
|
||||||
|
1)简单地调用 AI 模型(讯飞星火 | 阿里百炼)获取自定义文本内容。
|
||||||
|
|
||||||
|
2)简单的 JWT 权限校验 ,利用后端拦截器进行登录校验。
|
||||||
|
|
||||||
|
3)上传 Excel 文件,Excel 文件转换为 CSV 数据,AIGC 在线生成可视化图表。
|
||||||
|
|
||||||
|
4)Jousp 批量爬取图书列表,可结合 SpringSchedule 定时任务执行。
|
||||||
|
|
||||||
|
5)简单的增删改查系统,前后端是如何联调协作的。
|
||||||
|
|
||||||
|
6)前端路由懒加载、CDN 静态资源缓存优化、图片懒加载是如何实现的
|
||||||
|
|
||||||
|
7)利用 Lodash 进行节流控制,尽量降低无效的恶意刷留言情况。
|
||||||
|
|
||||||
|
8)利用自定义线程池和 FutureTask 进行超时请求处理。
|
||||||
|
|
||||||
|
9)利用Google 的 GuavaRateLimiter 进行单体限流控制。
|
||||||
|
|
||||||
|
10)定时任务结合 Redis 做一个缓存预热,加快查询效率,提高用户体验。
|
||||||
|
|
||||||
|
## ☀️项目简介
|
||||||
|
|
||||||
|
+ 主要使用Vue2和SpringBoot2实现
|
||||||
|
+ 项目权限控制分别为:用户借阅,图书管理员,系统管理员
|
||||||
|
+ 开发工具:IDEA2022.1.3(真不推荐用eclipse开发,IDEA项目可以导出为eclipse项目,二者不影响,但需要自己学教程)
|
||||||
|
+ [IDEA->Eclipse](https://blog.csdn.net/HD202202/article/details/128076400)
|
||||||
|
+ [Eclipse->IDEA](https://blog.csdn.net/q20010619/article/details/125096051)
|
||||||
|
|
||||||
|
+ 学校老师硬性要求软件的话,还是按要求来。可以先问一下是否可以选择其他软件开发。
|
||||||
|
+ 用户账号密码: 相思断红肠 123456
|
||||||
|
+ 图书管理员账号密码: admin 123456
|
||||||
|
+ 系统管理员账号密码: root 123456
|
||||||
|
+ [前端样式参考](https://gitee.com/mingyuefusu/tushuguanlixitong) 感谢原作者**明月复苏**
|
||||||
|
|
||||||
|
+ 遇到交互功能错误,或者页面无法打开,请用开发者工具F12查看请求和响应状态码情况,当然可能小白不懂,那也没关系,可以加我**QQ:909088445**。白天上课,晚上有空才能回答,感谢体谅!⭐⭐⭐
|
||||||
|
|
||||||
|
## ☀️项目详细介绍(亮点)
|
||||||
|
|
||||||
|
+ 本项目采用前后端分离的模式,前端构建页面,后端作数据接口,前端调用后端数据接口得到数据,重新渲染页面。
|
||||||
|
+ 后端已开启 CORS 跨域支持
|
||||||
|
+ API 认证使用 Token 认证
|
||||||
|
+ 前端在 Authorization 字段提供 Token 令牌
|
||||||
|
+ 使用 HTTP Status Code 表示状态
|
||||||
|
+ 数据返回格式使用 JSON
|
||||||
|
+ 后端采用权限拦截器进行权限校验,并检查登录情况
|
||||||
|
+ 添加全局异常处理机制,捕获异常,增强系统健壮性
|
||||||
|
+ 前端用 Echarts 可视化库实现了图书借阅的分析图标(折线图、饼图),并通过 Loading 配置提高加载体验。
|
||||||
|
+ 留言组件采用弹幕形式,贴合用户的喜好。
|
||||||
|
+ 引入 knife4j 依赖,使用 Swagger + Knife4j 自动生成 OpenAPI 规范的接口文档,前端可以在此基础上使用插件自动生成接口请求代码,降低前后端协作成本
|
||||||
|
+ 使用 ElementUI 组件库进行前端界面搭建,快速实现页面生成,并实现了前后端统一权限管理,多环境切换等能力。
|
||||||
|
+ 基于 MyBatis Plus 框架的 QueryWrapper 实现对 MySQL 数据库的灵活查询,并配合 MyBatisX 插件自动生成后端 CRUD 基础代码,减少重复工作。
|
||||||
|
+ 前端路由懒加载、CDN 静态资源缓存优化、图片懒加载效果。
|
||||||
|
|
||||||
|
### ⭐用户模块功能介绍
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ 图书查询功能:分页构造器缓解数据过大压力,后端可设置请求数防止爬虫请求数过大,服务器负载过大。模糊查询进行字段搜索。表格均可导出PDF和EXCEL。
|
||||||
|
+ 读者规则功能:查询现有的借阅规则,借阅规则包括:借阅编号,可借阅图书数量,可借阅天数,可借阅图书馆,过期扣费/天。
|
||||||
|
+ 查看公告: 可以查询图书管理员发布的公告列表,文字滑动效果。
|
||||||
|
|
||||||
|
+ 个人信息: 可以查看个人的借阅证编号,借阅证姓名,规则编号,状态,可以修改个人账户的密码。
|
||||||
|
|
||||||
|
+ 借阅信息: 可以查看自身借阅过的图书记录和归还情况。
|
||||||
|
+ 违章信息: 可以查询自身归还的图书是否有违章信息。
|
||||||
|
+ 读者留言: 实现留言功能并以弹幕形式显示。
|
||||||
|
|
||||||
|
### ⭐图书管理员模块功能介绍
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ 借阅图书: 图书管理员输入借阅证号(用户)和要借的图书编号和当前的时间,点击借阅。
|
||||||
|
+ 归还图书: 输入图书编号查看图书是否逾期,并且可以设置违规信息,然后选择是否归还图书
|
||||||
|
+ 借书报表: 用于查询已经借阅并归还的书籍列表,同样使用分页构造器和模糊查询字段,显示借阅证编号,图书编号,借阅日期,截止日期,归还日期,违章信息,处理人。
|
||||||
|
+ 还书报表: 用于查询已经借阅但是还未归还的书籍列表,显示借阅证编号,图书编号,借阅日期,截止日期。
|
||||||
|
|
||||||
|
+ 发布公告: 可以查询当前发布的公告列表,并进行删除,修改,增加功能,分页构造器用于缓解数据量大的情况。
|
||||||
|
|
||||||
|
### ⭐系统管理员模块功能介绍
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ 书籍管理: 可以查询当前的所有图书,显示图书编号,图书昵称,作者,图书馆,分类,位置,状态,描述。可以进行添加,修改,删除图书。利用分页构造器实现批量查询。利用模糊查询实现图书搜索功能。利用插件实现PDF和EXCEL导出。
|
||||||
|
+ 书籍类型: 显示查询当前的所有图书类型,可以进行添加,修改,删除图书类型,利用分页构造器实现批量查询,缓解数据压力。
|
||||||
|
+ 借阅证管理: 可以查询当前的所有借阅证列表,也就是用户数量,可以进行添加,修改,删除操作。同样实现分页。
|
||||||
|
+ 借阅信息查询: 可以查询当前已经完成借阅和归还的记录,显示借阅证号,书籍编号,借阅日期,截止日期,归还日期,违章信息,处理人。分页功能,PDF和EXCEL导出。
|
||||||
|
+ 借阅规则管理: 可以查询当前所有的借阅规则,显示限制借阅天数,限制本数,限制图书馆,逾期费用,可以进行添加、删除、修改操作。
|
||||||
|
+ 图书管理员管理: 显示当前的图书管理员列表,显示账号,姓名,邮箱,可以进行添加、删除、修改操作。
|
||||||
|
+ 系统管理: 可以查询一个月内的借阅量,以一周为时间间隔,计算借阅量,用Echarts实现折线图的展示。
|
||||||
|
|
||||||
|
## ☀️数据库表设计
|
||||||
|
|
||||||
|
### t_users表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ----------- | ---------------- | ------------------------------------------------- |
|
||||||
|
| user_id | int(11) | 主键 非空 自增 用户表的唯一标识 |
|
||||||
|
| username | varchar(32) | 用户名 非空 |
|
||||||
|
| password | varchar(32) | 密码(MD5加密) 非空 |
|
||||||
|
| card_name | varchar(10) | 真实姓名 非空 |
|
||||||
|
| card_number | Bigint(11) | 借阅证编号 固定 11位随机生成 非空(后文都改BigInt) |
|
||||||
|
| rule_number | int(11) | 规则编号 可以自定义 也就是权限功能 |
|
||||||
|
| status | int(1) | 1表示可用 0表示禁用 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_admins表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ----------- | ---------------- | --------------------------------- |
|
||||||
|
| admin_id | int(11) | 主键 非空 自增 管理员表的唯一标识 |
|
||||||
|
| username | varchar(32) | 用户名 非空 |
|
||||||
|
| password | varchar(32) | 密码(MD5加密) 非空 |
|
||||||
|
| admin_name | varchar(10) | 管理员真实姓名 非空 |
|
||||||
|
| status | int(1) | 1表示可用 0表示禁用 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_book_admins表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| --------------- | ---------------- | ------------------------------- |
|
||||||
|
| book_admin_id | int(11) | 主键 非空 自增 管理表的唯一标识 |
|
||||||
|
| username | varchar(32) | 用户名 非空 |
|
||||||
|
| password | varchar(32) | 密码(MD5加密)非空 |
|
||||||
|
| book_admin_name | varchar(10) | 图书管理员真实姓名 非空 |
|
||||||
|
| status | int(1) | 1表示可用 0表示禁用 |
|
||||||
|
| email | varchar(255) | 电子邮箱 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_books表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ---------------- | ---------------- | ------------------------------- |
|
||||||
|
| book_id | int(11) | 主键 自增 非空 图书表的唯一标识 |
|
||||||
|
| book_number | int(11) | 图书编号 非空 图书的唯一标识 |
|
||||||
|
| book_name | varchar(32) | 图书名称 非空 |
|
||||||
|
| book_author | varchar(32) | 图书作者 非空 |
|
||||||
|
| book_library | varchar(32) | 图书所在图书馆的名称 非空 |
|
||||||
|
| book_type | varchar(32) | 图书类别 非空 |
|
||||||
|
| book_location | varchar(32) | 图书位置 非空 |
|
||||||
|
| book_status | varchar(32) | 图书状态(未借出/已借出) |
|
||||||
|
| book_description | varchar(100) | 图书描述 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_books_borrow表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ----------- | ---------------- | ------------------------------------------------------------ |
|
||||||
|
| borrow_id | int(11) | 主键 自增 非空 借阅表的唯一标识 |
|
||||||
|
| card_number | int(11) | 借阅证编号 固定 11位随机生成 非空 用户与图书关联的的唯一标识 |
|
||||||
|
| book_number | int(11) | 图书编号 非空 图书的唯一标识 |
|
||||||
|
| borrow_date | datetime | 借阅日期 Java注解 JsonFormatter |
|
||||||
|
| close_date | datetime | 截止日期 Java注解 JsonFormatter |
|
||||||
|
| return_date | datetime | 归还日期 Java注解 JsonFormatter |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_notice表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| --------------- | ---------------- | ----------------------------------- |
|
||||||
|
| notice_id | int(11) | 主键 非空 自增 公告表记录的唯一标识 |
|
||||||
|
| notice_title | varchar(32) | 公告的题目 非空 |
|
||||||
|
| notice_content | varchar(255) | 公告的内容 非空 |
|
||||||
|
| notice_admin_id | int(11) | 发布公告的管理员的id |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_violation表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ------------------ | ---------------- | ----------------------------------- |
|
||||||
|
| violation_id | int(11) | 主键 非空 自增 违章表记录的唯一标识 |
|
||||||
|
| card_number | int(11) | 借阅证编号 固定 11位随机生成 非空 |
|
||||||
|
| book_number | int(11) | 图书编号 非空 图书的唯一标识 |
|
||||||
|
| borrow_date | datetime | 借阅日期 Java注解 JsonFormatter |
|
||||||
|
| close_date | datetime | 截止日期 Java注解 JsonFormatter |
|
||||||
|
| return_date | datetime | 归还日期 Java注解 JsonFormatter |
|
||||||
|
| violation_message | varchar(100) | 违章信息 非空 |
|
||||||
|
| violation_admin_id | int(11) | 违章信息管理员的id |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_comment表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| --------------------- | ---------------- | ----------------------------------- |
|
||||||
|
| comment_id | int(11) | 主键 非空 自增 留言表记录的唯一标识 |
|
||||||
|
| comment_avatar | varchar(255) | 留言的头像 |
|
||||||
|
| comment_barrage_style | varchar(32) | 弹幕的高度 |
|
||||||
|
| comment_message | varchar(255) | 留言的内容 |
|
||||||
|
| comment_time | int(11) | 留言的时间(控制速度) |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_book_rule表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ------------------ | ---------------- | ------------------------------------- |
|
||||||
|
| rule_id | int(11) | 主键 非空 自增 借阅规则记录的唯一标识 |
|
||||||
|
| book_rule_id | int(11) | 借阅规则编号 非空 |
|
||||||
|
| book_days | int(11) | 借阅天数 非空 |
|
||||||
|
| book_limit_number | int(11) | 限制借阅的本数 非空 |
|
||||||
|
| book_limit_library | varchar(255) | 限制的图书馆 非空 |
|
||||||
|
| book_overdue_fee | double | 图书借阅逾期后每天费用 非空 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_book_type表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ------------ | ---------------- | ------------------------------------- |
|
||||||
|
| type_id | int(11) | 主键 非空 自增 图书类别记录的唯一标识 |
|
||||||
|
| type_name | varchar(32) | 借阅类别的昵称 非空 |
|
||||||
|
| type_content | varchar(255) | 借阅类别的描述 非空 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
## 🐼功能演示图
|
||||||
|
|
||||||
|
### 用户模块功能图
|
||||||
|
|
||||||
|
**首页轮播图演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**图书查询演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**读者规则演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**查看公告演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**个人信息演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**借阅信息演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**违章信息演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**读者留言演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**智能推荐演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 图书管理员功能图
|
||||||
|
|
||||||
|
**借阅图书演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**归还图书演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**借书报表演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**还书报表演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**发布公告演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 系统管理员功能图
|
||||||
|
|
||||||
|
+ 由于篇幅受限,系统功能展示主要功能。
|
||||||
|
|
||||||
|
**系统管理演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**智能分析演示**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐼部署项目
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ 可以下载ZIP压缩包或者使用克隆(Git clone)
|
||||||
|
+ 复制http或者ssh的链接(github建议ssh,gittee都可以)
|
||||||
|
+ 在D盘新建一个文件夹,点击进入该文件夹,右键Git Bash Here
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ 还没有下载Git或者不会Git的建议先看基础教程(30分钟左右)
|
||||||
|
|
||||||
|
+ 输入git init 初始化git项目 然后出现一个.git文件夹
|
||||||
|
+ 输入git remote add origin xxxxxx(xxx为刚刚复制的http或者ssh链接)
|
||||||
|
|
||||||
|
+ 输入git pull origin master 从远程代码托管仓库拉取代码
|
||||||
|
+ 成功拉取项目(前端后端都是如此)
|
||||||
|
+ 前端项目注意依赖下载使用npm install 或者 yarn install (Vscode或者Webstorm)
|
||||||
|
+ 后端项目注意maven依赖下载(IDEA(推荐)或者Ecplise)
|
||||||
|
+ 前端npm 镜像源建议淘宝镜像源,后端maven镜像源推荐阿里云镜像源(非必选,但更换后下载快速)
|
||||||
|
|
||||||
|
## 🐼部署项目问题
|
||||||
|
|
||||||
|
⭐
|
||||||
|
|
||||||
|
+ 乱码问题 项目采用的UFT-8
|
||||||
|
+ 一般出现乱码就是UTF-8和GBK二者相反
|
||||||
|
+ 请百度IDEA乱码和Eclipse乱码问题(描述清楚即可)
|
||||||
|
|
||||||
|
⭐
|
||||||
|
|
||||||
|
+ 点击交互按钮,没有发生反应。
|
||||||
|
+ 很明显,请求失败,浏览器打开开发者工具,Edge浏览器直接ctrl+shift+i,其他浏览器按F12
|
||||||
|
+ 查看红色的请求和响应状态码问题
|
||||||
|
|
||||||
|
⭐
|
||||||
|
|
||||||
|
+ 先阅读文档再进行问题的查询或者提问
|
||||||
|
+ 提问有技巧,模糊的发言,让高级架构师找BUG也无从下手
|
||||||
|
|
||||||
|
⭐
|
||||||
|
|
||||||
|
+ **QQ:909088445**
|
||||||
|
+ 一般晚上在线,建议先自己寻找问题!!!
|
||||||
|
+ 开源免费, 定制化和调试项目付费。
|
||||||
|
|
||||||
|
## 🐼需求分析和设计
|
||||||
|
|
||||||
|
需求分析和设计文档,有(**付费**)需求的可以加 QQ:909088445,适合走毕设和课设的小伙伴,图省事的可以找我。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐼项目API接口文档
|
||||||
|
|
||||||
|
+ 接口文档篇幅过大
|
||||||
|
+ 本来想完全采用RESTFUL风格,做到一半忘记了
|
||||||
|
+ 看清楚文档的基准地址
|
||||||
|
+ 要API后端接口文档详细内容和数据库结构(**由于服务器、域名、 AI 模型的成本问题,现数据库文件已收费**)+内容一起的,将前后端**star**⭐的截图加我QQ:**909088445**发我即可领取~感谢支持
|
||||||
|
|
||||||
|
#### **数据库领取截图示例(Gitee&GitHub):**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐼(重点)远程部署和项目讲解服务
|
||||||
|
|
||||||
|
远程部署服务需自己先下载向日葵远程控制软件,然后加 WX 或者 QQ 即可(**付费服务**),远程部署用于给完全不懂的小白,项目讲解服务用于**课设、实训、毕设语音答辩服务**,想减省时间,提高通过率,直接加我即可,可以**定制背景图片和整体的样式功能**,**降重服务**也可私我!新增定制协同过滤算法和数据可视化功能!有需求的小伙伴,请先编写一份具体的需求文档!
|
||||||
|
|
||||||
|
|
||||||
|
## 🐷其他
|
||||||
|
|
||||||
|
+ 个人博客地址: https://luoye6.github.io/
|
||||||
|
+ 个人博客采用Hexo+Github托管
|
||||||
|
+ 采用butterfly主题可以实现定制化
|
||||||
|
+ 推荐有空闲时间的,可以花1-2天搭建个人博客用于记录笔记。
|
||||||
|
|
||||||
|
## ☕请我喝咖啡
|
||||||
|
|
||||||
|
如果本项目对您有所帮助,不妨请作者我喝杯咖啡 :)
|
||||||
|
|
||||||
|
<div><img src="https://pic.yupi.icu/5563/202312191854931.png" style="height:300px;width:300px"></img> <img src="https://pic.yupi.icu/5563/202312191859536.png" style="height:300px;width:300px"></img></div>
|
||||||
|
|
||||||
|
## **版本迭代**
|
||||||
|
|
||||||
|
### 2023-3-19
|
||||||
|
|
||||||
|
1.引入knife4j依赖,使用 Swagger + Knife4j 自动生成 OpenAPI 规范的接口文档,前端可以在此基础上使用插件自动生成接口请求代码,降低前后端协作成本。
|
||||||
|
|
||||||
|
2.引入jsoup依赖可以自定义添加爬虫功能,可以批量添加图书并且是比较真实的数据。
|
||||||
|
|
||||||
|
3.添加事务管理器,可以进行用@Transactional指定异常类型回滚和事务传播行为。
|
||||||
|
|
||||||
|
### 2023-4-13
|
||||||
|
|
||||||
|
1.手动在增加和删除逻辑较为复杂的数据库操作上,添加了@Transactional注解,遇到运行时异常直接回滚数据库,防止借书和还书出现逻辑错误。
|
||||||
|
|
||||||
|
2.修复11位图书编号无法借书的Bug,其原因是因为11位超出了Integer的2147483647(10位)。解决方法:数据库改为BigInt,Java改为Long。
|
||||||
|
|
||||||
|
3.**注意**:不要随便删除用户和公告!!!会导致其他人体验的时候出现逻辑错误!!!请明白了项目逻辑再去做删除操作!!!感谢配合!!!
|
||||||
|
|
||||||
|
4.下一期准备优化图表的展示,逾期图书后告警通知之类的功能,感谢大家的支持,我会继续维护和优化功能,有Bug可以加我QQ或者提出issue,勿要恶意利用bug,再次鸣谢。
|
||||||
|
|
||||||
|
5.劳动节准备录一期部署项目的视频会发到b站,到时候会将部署讲清楚,方便大家课设或者毕设的完成,此项目有数据库表设计、API接口文档、内容功能介绍、亮点介绍,唯一缺少的可能是数据流图、ER图之类的,star的人多了,我会添加上去。
|
||||||
|
|
||||||
|
### 2023-5-1
|
||||||
|
|
||||||
|
1.添加“系统管理员”权限的系统管理功能,**添加借书类型分析统计图(饼图)**采用Echarts。
|
||||||
|
|
||||||
|
2.优化请求在没有收到数据时的显示卡顿的情况,添加“加载中”状态,**使用v-loading**(ElementUI组件库),**优化用户人机交互体验**,在服务器调用接口缓慢的情况下,给予**良好的交互**。
|
||||||
|
|
||||||
|
3.轮播图优化:**压缩图片体积**,另外使用Swiper的**懒加载**,实现图片加载中状态,然后图片完全加载完成后才显示图片,**优化用户体验过程**。
|
||||||
|
|
||||||
|
4.后端**新增自定义错误码枚举类**,可以自定义状态码进行返回,保留原有枚举类。
|
||||||
|
|
||||||
|
5.前端优化部分表格内容展示,当纵向内容过长,**设置了表格最大高度**,超出就会显示滑动窗口。优化表格列宽度,**提高表格美观度**。
|
||||||
|
|
||||||
|
6.**添加**书籍管理组件的**批量删除图书**功能,优化管理员体验,不用单个删除图书,**提高效率**。
|
||||||
|
|
||||||
|
7.Jmeter进行压力测试,服务器接口在**100个用户并发**发送请求的情况下,**QPS达到50**以上。
|
||||||
|
|
||||||
|
### 2023-5-20
|
||||||
|
|
||||||
|
**后端更新情况**
|
||||||
|
|
||||||
|
1.~~防止前端抓包被获取明文密码,前端输入密码,进行md5加密(混合盐值,防止碰撞),后端直接与数据库加密后的密码比较,相等代表登录成功。提高系统**安全性**!~~。
|
||||||
|
|
||||||
|
2.整改Controller层,**将业务代码全部放入Service层**,由Controller调用Service服务,并修改了@Transactional注解位置到业务层,减少耦合度,让Controller减少臃肿。做到对扩展开放,对修改关闭。后续考虑运用**设计模式**进行优化代码和**多线程**知识提高在**高并发**下接口响应的速度。
|
||||||
|
|
||||||
|
3.对照阿里巴巴手册进行代码修改,将警告进行减少,代码更加**优雅、规范**。
|
||||||
|
|
||||||
|
4.**修复BUG**: 借阅时间为空,造成服务器被击穿。归还日期为空,仍然显示借书成功。(解决方法:时间参数进行校验,判断是否为空)
|
||||||
|
|
||||||
|
5.**工具类增加情况**:SQLUtils(防止SQL注入),NetUtils(网络工具类)
|
||||||
|
|
||||||
|
**前端更新情况**
|
||||||
|
|
||||||
|
1.将路由加载方式,改为懒加载,利用懒加载可以有效分担首页加载压力,**减少首页加载用时**。
|
||||||
|
|
||||||
|
2.添加404页面,当用户访问请求地址不存在的页面,直接跳转到404页面,**提高用户体验度**。
|
||||||
|
|
||||||
|
3.添加按钮的加载中状态,**优化人机交互**,提升用户体验度。修改按钮:登录按钮,其他按钮如果有需要可以自定义去修改,增加:loading="loading"即可。
|
||||||
|
|
||||||
|
**Bug修复情况**
|
||||||
|
|
||||||
|
1.11位图书编号可以借,但却**无法进行逾期检查**,发现方法参数还是Integer,上次把借书和还书的改成Long了,逾期查看还没改成Long,因此出现问题,现在已经修复。
|
||||||
|
|
||||||
|
### 2023-6-10
|
||||||
|
|
||||||
|
**前端更新情况**
|
||||||
|
|
||||||
|
1.在某些页面添加全屏功能按钮,**方便用户放大查看表格数据**。
|
||||||
|
|
||||||
|
2.增加了GitHub和Gitee的地址图标,**方便进行项目拉取和克隆**。
|
||||||
|
|
||||||
|
3.读者留言组件,留言功能进行强化,防止无意义的数字、字母、空格出现在数据,后续考虑
|
||||||
|
|
||||||
|
4.读者留言组件,**利用lodash进行节流**,5秒内只可发送一次网络请求,防止恶意刷无效留言。
|
||||||
|
|
||||||
|
**后端更新情况**
|
||||||
|
|
||||||
|
1.后端添加利用EasyExcel进行图书的**批量导入功能**,实现与实际生活中利用Excel存储一些图书数据的交互功能,**提高导入效率**,和爬虫功能效果相同,都可以实现大数据量情况下的导入,推荐利用EasyExcel进行批量导入,时间会比爬虫会更快。
|
||||||
|
|
||||||
|
**Bug修复情况**
|
||||||
|
|
||||||
|
1.修改用户页面的修改密码功能,因为上次更新已经加了盐值,但是后端代码逻辑没有进行更改,本次修复"在修改密码后无法登录的情况",原因是因为后端没有加盐值,已修复。
|
||||||
|
|
||||||
|
2.修复系统管理员修改借阅证的密码然后就登录不上了,原因跟第一条Bug是一样的,因为后端的盐值没有进行添加,已修复。
|
||||||
|
|
||||||
|
3.修复系统管理员在书籍管理功能时候,直接点击修改书籍,发现书籍的分类是错误的,因为前端只在添加书籍的对话框发了获取分类的请求,修改对话框的时候忘记添加了获取分类的请求,已修复。
|
||||||
|
|
||||||
|
### 2023-9
|
||||||
|
|
||||||
|
**前端更新情况**
|
||||||
|
|
||||||
|
1.增加**智能推荐页面**,能够与AI进行交流,**用户输入自己喜欢xxx类的书籍,AI能够在现有数据库中进行分析**,然后给用户作出推荐,调用的是国内AI模型,底层是OpenAI。
|
||||||
|
|
||||||
|
2.增加**智能分析页面**,输入分析目标和图标类型和Excel文件,AI生成分析结论和可视化图标,大大提高效率,**减少人力分析成本**。
|
||||||
|
|
||||||
|
3.增加系统管理员可以利用在前端**利用Excel文件批量上传图书**的功能(测试中),仅供参考。
|
||||||
|
|
||||||
|
**后端更新情况**
|
||||||
|
|
||||||
|
1.增加智能分析的接口和获取最近5条聊天记录的接口,利用**线程池**和**Future**进行**超时请求处理**,如果接口调用超过40秒直接返回错误信息。
|
||||||
|
|
||||||
|
2.利用Google的Guava中的RateLimiter进行限流控制,**每秒钟只允许一个请求通过**,防止刷量行为。
|
||||||
|
|
||||||
|
### 2023-11
|
||||||
|
|
||||||
|
**后端更新情况**
|
||||||
|
|
||||||
|
1.将用户聊天的AI模型切换为阿里的通义千问Plus模型,并且**支持多轮会话的历史记录**,**不再使用讯飞星火的AI模型**,但仍保留工具类。主要是为了可以更快的得到响应,而且阿里的**文档更加详细**,可以**定制话术**,在用户输入无关图书推荐的内容时候,直接**拒绝回答**。
|
||||||
|
|
||||||
|
2.添加一个 IncSyncDeleteAIMessage **定时任务**,每天将会**删除由于系统错误等原因AI回复失败**,导致内容为空的记录,并且会为这些用户**恢复接口的次数**,**后续可能会选择 RabbitMQ**,将失败的消息放入消息队列,然后**确保失败的消息被消费**。
|
||||||
|
|
||||||
|
3.登录加密由前端改到后端,由于前端可以被撞库,因此加密依然放到后端。**方案:**前端传输,用 HTTPS 进行密文加密,后端采用盐值+算法进行加密,数据库存密文。
|
||||||
|
|
||||||
|
4.将留言页面存放在 Redis 中,**减少数据库的 IO 查询**,QPS 是原来的数百倍!
|
||||||
|
|
||||||
|
**前端更新情况**
|
||||||
|
|
||||||
|
1.将三个登录页面的背景图和头像改为存储在 assets 文件夹的 images 中,**主要是为使用项目的人考虑**,很多人不懂图床技术,我这边暂时将登录页面改成静态图。
|
||||||
|
|
||||||
|
2.权限切换的提示优化,**在图标上面现在有登录权限切换的文字样式**,提示用户有多个登录页面可以切换。
|
||||||
|
|
||||||
|
3.登录加密由前端改到后端,由于前端可以被撞库,因此加密依然放到后端。**方案**:前端传输,用 HTTPS 进行密文加密,后端采用盐值+算法进行加密,数据库存密文。
|
||||||
|
|
||||||
|
### 2024-3
|
||||||
|
|
||||||
|
**后端更新情况**
|
||||||
|
|
||||||
|
1)为 Knife4J 添加 @ ApiOperation 注解,标注每个接口的作用,**方便开发者阅读和测试接口**。
|
881
README_en.md
Normal file
881
README_en.md
Normal file
@ -0,0 +1,881 @@
|
|||||||
|
# OpenSource DocumentationForSmart Libraries
|
||||||
|
|
||||||
|
>作者:[Programmer's Little White Bar](https://luoye6.github.io/)
|
||||||
|
>
|
||||||
|
>[Gitee Homepage](https://gitee.com/falle22222n-leaves)
|
||||||
|
>
|
||||||
|
>[Github Homepage](https://github.com/luoye6)
|
||||||
|
|
||||||
|
Language:**[English](README_en.md)**| **[中文](README.md).**
|
||||||
|
|
||||||
|
## ☀️Must Read For Beginners
|
||||||
|
|
||||||
|
+ This project has a complete API backend interface document (at the end of the text) (key points⭐)
|
||||||
|
+ The project deployment video has been recorded
|
||||||
|
+ If the project is helpful to you, Star ⭐ Once encouraged, I will continue to work hard.
|
||||||
|
+ [Project online demonstration address](https://www.xiaobaitiao.top)
|
||||||
|
+ [Project front-end address](https://gitee.com/falle22222n-leaves/vue_-book-manage-system)
|
||||||
|
+ [Project backend address](https://gitee.com/falle22222n-leaves/vue_-book-manage-system_backend)
|
||||||
|
+ [Project deployment video](https://www.bilibili.com/video/BV1Zh4y1z7QE/?spm_id_from=333.999.0.0)
|
||||||
|
|
||||||
|
[](https://gitee.com/falle22222n-leaves/vue_-book-manage-system) [](https://gitee.com/falle22222n-leaves) [](https://github.com/luoye6)
|
||||||
|
|
||||||
|
## ☀️Personal Introduction
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️Introduction
|
||||||
|
|
||||||
|
**AI Intelligent Library** is a system that uses AI models and data analysis to accurately recommend books that users like, and provides AIGC's online generation of BI charts for borrowing volume analysis, which can serve as a data analyst. It mainly has three major users: users (borrowers), librarians, and system administrators.
|
||||||
|
|
||||||
|
> Ps: If you want simplicity and novelty, then this project will be a good choice~
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️Function And Features
|
||||||
|
|
||||||
|
### User functions
|
||||||
|
|
||||||
|
1)Book query function: The pagination constructor alleviates the pressure of excessive data, and the backend can set the number of requests to prevent excessive crawler requests and server load. Fuzzy query for field search. The tables can be exported to both PDF and Excel.
|
||||||
|
|
||||||
|
2)Reader rule function: Query existing borrowing rules, borrowing rules include: borrowing number, number of books that can be borrowed, number of days that can be borrowed, library that can be borrowed, overdue fee deduction/day.
|
||||||
|
|
||||||
|
3)View announcements: You can check the list of announcements published by the librarian, with a text scrolling effect.
|
||||||
|
|
||||||
|
4)Personal information: You can view an individual's borrowing card number, borrowing card name, rule number, status, and modify the password of your personal account.
|
||||||
|
|
||||||
|
5)Borrowing information: You can view the records and return status of books you have borrowed.
|
||||||
|
|
||||||
|
6)Violation information: You can check whether the returned books contain any violation information.
|
||||||
|
|
||||||
|
7)Reader's message: Implement the message function and display it in the form of a bullet screen.
|
||||||
|
|
||||||
|
8)**Intelligent recommendation** Users input their preferences, and AI recommends books to users based on the database book list and user preferences.
|
||||||
|
|
||||||
|
### Library Administrator Function
|
||||||
|
|
||||||
|
1)Borrowing Books: The librarian enters the borrowing card number (user), the book number to be borrowed, and the current time, and clicks to borrow.
|
||||||
|
|
||||||
|
2)Returning books: Enter the book number to check if the book is overdue, and set violation information, then choose whether to return the book.
|
||||||
|
|
||||||
|
3)Book Borrowing Report: Used to query the list of books that have been borrowed and returned. It also uses a pagination constructor and fuzzy query fields to display the borrowing card number, book number, borrowing date, deadline, return date, violation information, and handler.
|
||||||
|
|
||||||
|
4)Book Return Report: Used to query the list of books that have been borrowed but not yet returned, displaying the borrowing card number, book number, borrowing date, and deadline.
|
||||||
|
|
||||||
|
5)Announcement: You can query the current list of announcements and delete, modify, and add features. The pagination constructor is used to alleviate the situation of large data volume.
|
||||||
|
|
||||||
|
### System Administrator Function
|
||||||
|
|
||||||
|
1)Book management: It can query all current books, display book numbers, book nicknames, authors, libraries, classifications, locations, status, and descriptions. You can add, modify, and delete books. Implement batch queries using a paging constructor. Utilize fuzzy queries to achieve book search functionality **Utilize plugins to export PDF and Excel**.
|
||||||
|
|
||||||
|
2)Book Types: Display and query all current book types, which can be added, modified, or deleted. Use a pagination constructor to achieve batch queries and alleviate data pressure.
|
||||||
|
|
||||||
|
3)Borrowing Card Management: It is possible to query the current list of all borrowing cards, that is, the number of users, and perform operations such as adding, modifying, and deleting. Implement pagination as well.
|
||||||
|
|
||||||
|
4)Borrowing information query: can query the current completed borrowing and returning records, display the borrowing card number, book number, borrowing date, deadline, return date, violation information, and handler. Paging function, PDF and Excel export.
|
||||||
|
|
||||||
|
5)Borrowing Rule Management: You can query all current borrowing rules, display restricted borrowing days, restricted book count, restricted library, overdue fees, and perform add, delete, and modify operations.
|
||||||
|
|
||||||
|
6)Librarian Management: Display the current list of librarians, including accounts, names, and email addresses, allowing for adding, deleting, and modifying operations.
|
||||||
|
|
||||||
|
7)System management: It is possible to query the borrowing volume within a month, calculate the borrowing volume at a weekly interval, and use Echarts to display various charts.
|
||||||
|
|
||||||
|
8)System analysis: You can upload the borrowing volume and date for a certain time period, and input the analysis target and the type of chart you want to generate. After waiting for a period of time, **AI will provide analysis conclusions and visual charts**.
|
||||||
|
|
||||||
|
### Features (highlights)
|
||||||
|
|
||||||
|
1)This project adopts a front-end and back-end separation mode, with the front-end building the page and the back-end serving as the data interface. The front-end calls the back-end data interface to obtain data and re render the page.
|
||||||
|
|
||||||
|
2)The front-end provides a Token token in the Authorization field, API authentication uses Token authentication, HTTP Status Code represents status, and data return format uses JSON.
|
||||||
|
|
||||||
|
3)The backend has enabled CORS cross domain support, using permission interceptors for permission verification and checking login status.
|
||||||
|
|
||||||
|
4)Add a global exception handling mechanism to capture exceptions and enhance system robustness.
|
||||||
|
|
||||||
|
5)The front-end uses the Echarts visualization library to implement analysis icons (line charts, pie charts) for book borrowing, and improves the loading experience through loading configuration.
|
||||||
|
|
||||||
|
6)The message component adopts bullet screen format, which is in line with user preferences.
|
||||||
|
|
||||||
|
7)Introduce the knife4j dependency and use Swagger+Knife4j to automatically generate interface documents for the OpenAPI specification. The front-end can use plugins to automatically generate interface request codes based on this, reducing the cost of front-end and back-end collaboration
|
||||||
|
|
||||||
|
8)By using the ElementUI component library for front-end interface construction, we can quickly generate pages and achieve unified permission management and multi environment switching capabilities for both front-end and back-end.
|
||||||
|
|
||||||
|
9)The QueryWrapper based on the MyBatis Plus framework enables flexible querying of MySQL databases and, in conjunction with the MyBatisX plugin, automatically generates backend CRUD basic code to reduce repetitive work.
|
||||||
|
|
||||||
|
10)Front end routing lazy loading, CDN static resource cache optimization, and image lazy loading effect.
|
||||||
|
|
||||||
|
## ☀️Operation Mode
|
||||||
|
|
||||||
|
### 2 Minutes To Quickly Get Started Using The Project
|
||||||
|
|
||||||
|
1)Find the SpringBoot startup class, click on Run
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2)Open Knife4J to register as a user, or you can directly contact me to obtain database simulation data (simple).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
3)After entering the form content in the front-end, click on login to successfully start using the function happily~
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️Deployment Method
|
||||||
|
|
||||||
|
### Preconditions
|
||||||
|
|
||||||
|
**Front end**
|
||||||
|
|
||||||
|
Software: Vscore or Webstorm (recommended)
|
||||||
|
|
||||||
|
Environment: Node version 16 or 18 (recommended) **Note: Do not choose versions above 18**
|
||||||
|
|
||||||
|
**Backend**
|
||||||
|
|
||||||
|
Software: Eclipse or IDEA (recommended)
|
||||||
|
|
||||||
|
Environment: MySQL 5.7 or 8.0 (recommended) Redis (optional)
|
||||||
|
|
||||||
|
### Front End Deployment
|
||||||
|
|
||||||
|
1)Clicking on Clone/Download Project will use Git for version control. It is recommended to use Git Clone. If you do not know how to do so, you can choose to download a Zip compressed file and extract it to your computer's D drive. It is recommended to use Star directly, and then directly obtain the database simulation file and API interface documentation from me.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2)Open the front-end page using Vscode or Webstorm and configure the Configuration. Configure the Node environment and package management tools. The package management tool I have chosen is Npm, while other package management tools such as Yarn, Cnpm, and Pnpm are all available**Note: Please change the image address of Npm to the new image address on Taobao, otherwise Npm Install will keep getting stuck in the progress bar**.
|
||||||
|
|
||||||
|
3)Simply click on the run of dev or open the console and enter npm run serve to successfully launch the front-end project.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
npm config set registry https://registry.npmmirror.com/
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
4)Customize and switch image links to your own image bed, such as Qiniuyun, GitHub, etc. You can also search for online images and copy Baidu Wenku image links (try multiple times, some images have anti-theft links) **After changing the background, you can see the permission switch icon in the bottom right corner**.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Backend Deployment
|
||||||
|
|
||||||
|
1)Clicking on Clone/Download Project will use Git for version control. It is recommended to use Git Clone. If you do not know how to do so, you can choose to download a Zip compressed file and extract it to your computer's D drive. It is recommended to use Star directly, and then directly obtain the database simulation file and API interface documentation from me.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2)After receiving the database simulation file, use software such as Navicat or SQLYog to import the database file. Remember to first create a database named bms_boot, and then right-click to run the SQL file. After running successfully without any errors, reopen the database and check for data. If there is data, it indicates successful import.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
3) Open the backend project using IDEA, locate the application dev.yml file, modify the MySQL configuration, and ensure that the username and password are correct. Note: Passwords cannot start with the number 0.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
4)mporting Maven dependencies, pay attention to checking if your Maven version is correct. It is recommended to choose the same version as mine, version 3.8 or above. I found that importing dependencies is slow because there is no configuration for domestic images, and the default connection is to foreign servers. Therefore, Alibaba Cloud image configuration can be found in this blog post.[CSDN Maven 配置教程](https://blog.csdn.net/lianghecai52171314/article/details/102625184?ops_request_misc=&request_id=&biz_id=102&utm_term=Maven)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
5)Find the SpringBoot startup class, and I suggest using Debug mode to start the project for better troubleshooting.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
6)If you encounter an error, it is most likely a JDK version issue. My project is using JDK 8, so it is recommended to choose the same version as me.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
7)The successful launch of the project results are shown below
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Front And Rear End Joint Debugging
|
||||||
|
|
||||||
|
1)If you need to modify the port and prefix (such as/API), you need to modify both the front-end and back-end.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️Technical Selection
|
||||||
|
|
||||||
|
### Front End
|
||||||
|
|
||||||
|
| **技术** | **作用** | **版本** |
|
||||||
|
| ---------------------------- | ------------------------------------------------------------ | ---------------------------------------------------- |
|
||||||
|
| Vue | 提供前端交互 | 2.6.14 |
|
||||||
|
| Vue-Router | 路由式编程导航 | 3.5.1 |
|
||||||
|
| Element-UI | 模块组件库,绘制界面 | 2.4.5 |
|
||||||
|
| Axios | 发送ajax请求给后端请求数据 | 1.2.1 |
|
||||||
|
| core-js | 兼容性更强,浏览器适配 | 3.8.3 |
|
||||||
|
| swiper | 轮播图插件(快速实现) | 3.4.2 |
|
||||||
|
| vue-baberrage | vue弹幕插件(实现留言功能) | 3.2.4 |
|
||||||
|
| vue-json-excel | 表格导出Excel | 0.3.0 |
|
||||||
|
| html2canvas+jspdf | 表格导出PDF | 1.4.1 2.5.1 |
|
||||||
|
| node-polyfill-webpack-plugin | webpack5中移除了nodejs核心模块的polyfill自动引入 | 2.0.1 |
|
||||||
|
| default-passive-events | **Chrome** 增加了新的事件捕获机制 **Passive Event Listeners**(被动事件侦听器) | 让页面滑动更加流畅,主要用于提升移动端滑动行为的性能 |
|
||||||
|
| nprogress | 发送请求显示进度条(人机交互友好) | 0.2.0 |
|
||||||
|
| echarts | 数据转图标的好工具(功能强大) | 5.4.1 |
|
||||||
|
| less lessloader | 方便样式开发 | 4.1.3 11.1.0 |
|
||||||
|
|
||||||
|
### 后端
|
||||||
|
|
||||||
|
| **技术及版本** | **作用** | **版本** |
|
||||||
|
| ------------------------------------ | ------------------------------------------------------------ | --------------------------------- |
|
||||||
|
| SpringBoot | 应用开发框架 | 2.7.8 |
|
||||||
|
| JDK | Java 开发包 | 1.8 |
|
||||||
|
| MySQL | 提供后端数据库 | 8.0.23 |
|
||||||
|
| MyBatisPlus | 提供连接数据库和快捷的增删改查 | 3.5.1 |
|
||||||
|
| SpringBoot-Configuration-processor | 配置处理器 定义的类和配置文件绑定一般没有提示,因此可以添加配置处理器,产生相对应的提示. | |
|
||||||
|
| SpringBoot-Starter-Web | 后端集成Tomcat MVC | 用于和前端连接 |
|
||||||
|
| SpringBoot-starter-test | Junit4单元测试前端在调用接口前,后端先调用单元测试进行增删改查,注意Junit4和5的问题,注解@RunWith是否添加 | |
|
||||||
|
| Lombok | 实体类方法的快速生成 简化代码 | |
|
||||||
|
| mybatis-plus-generator | 代码生成器 | 3.5.1 |
|
||||||
|
| MyBatisX | MyBatisPlus插件直接生成mapper,实体类,service | |
|
||||||
|
| jjwt | token工具包 | 0.9.0 |
|
||||||
|
| fastjson | 阿里巴巴的 JSON 工具类 | 1.2.83 |
|
||||||
|
| hutool | hutool工具包(简化开发工具类) | [文档](https://hutool.cn/docs/#/) |
|
||||||
|
| knife4j-openapi2-spring-boot-starter | Knife4j 在线接口文档测试工具 | 4.0.0 |
|
||||||
|
| gson | 谷歌的 JSON 工具类 | 2.8.5 |
|
||||||
|
| Java-WebSocket | 讯飞星火 AI 配置 | 1.3.8 |
|
||||||
|
| okhttp | 讯飞星火 AI 配置 | 4.10.0 |
|
||||||
|
| okio | 讯飞星火 AI 配置 | 2.10.0 |
|
||||||
|
| jsoup | 简易爬虫工具 | 1.15.3 |
|
||||||
|
| guava | 谷歌工具类 | 30.1-jre |
|
||||||
|
| spring-boot-starter-data-redis | Redis 的 Starter | |
|
||||||
|
| broadscope-bailian-sdk-java | 阿里云 AI 模型 | 1.1.7 |
|
||||||
|
| spring-boot-starter-websocket | WebSocket 的 Starter | |
|
||||||
|
|
||||||
|
## ☀️Architecture
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## ☀️Core Design
|
||||||
|
|
||||||
|
### Intelligent Recommendation Function
|
||||||
|
|
||||||
|
1)Users input their book preference information.
|
||||||
|
|
||||||
|
2)The front-end sends Axios requests.
|
||||||
|
|
||||||
|
3)The backend first checks whether the text is illegal (empty or too long).
|
||||||
|
|
||||||
|
4)Check if the interface exists.
|
||||||
|
|
||||||
|
5)Check if the number of AI interface calls is sufficient.
|
||||||
|
|
||||||
|
6)GuavaRateLimiter performs individual flow limiting to determine if the number of requests exceeds the normal business frequency.
|
||||||
|
|
||||||
|
7)Manually preset the AI model and query the list of books in the database for concatenation.
|
||||||
|
|
||||||
|
8)Query the AI model and the user's latest five historical records for context association.
|
||||||
|
|
||||||
|
9)FutureTask synchronously calls to obtain AI results and sets a timeout (timeout throws an exception)
|
||||||
|
|
||||||
|
10)Persist after obtaining AI model recommendation information and reduce the number of interface calls (to determine if successful)
|
||||||
|
|
||||||
|
12)Return the processed AI recommendation information to the front-end and set the response status code to 200.
|
||||||
|
|
||||||
|
### Intelligent Analysis Function
|
||||||
|
|
||||||
|
1)Users input analysis targets, icon names, select icon types, upload Excel files, click submit, and send Axios requests to the backend.
|
||||||
|
|
||||||
|
2)Verify whether the file is empty, the name is too long, the file size is checked, and the file suffix is checked
|
||||||
|
|
||||||
|
3)Obtain the administrator ID and query the interface owned by the administrator ID from the interface information table. The interface is found to be empty.
|
||||||
|
|
||||||
|
4)Determine if the number of AI interface calls is sufficient
|
||||||
|
|
||||||
|
5)GuavaRateLimiter performs individual flow limiting to determine if the number of requests exceeds the normal business frequency.
|
||||||
|
|
||||||
|
6)Hint words and roles for constructing AI models
|
||||||
|
|
||||||
|
7)Construct user input, concatenate user input information, and use tool classes to convert Excel into CSV string data.
|
||||||
|
|
||||||
|
8)Using the iFlytek Starfire AI model, input the caller ID and input parameters, use FutureTask to synchronously obtain them, and set a timeout time (timeout throws an exception)
|
||||||
|
|
||||||
|
10)Judging the AI generated results, if there is a formatting error, return the front-end error message and prompt for re calling (consider RabbitMQ for retry and compensation mechanisms in the future)
|
||||||
|
|
||||||
|
11)Persist the AI generated results to the database, update the number of interface calls (to determine if successful), and dynamically return icons and data conclusions to the front-end.
|
||||||
|
|
||||||
|
## ☀️What Will You Get After Completing This Project
|
||||||
|
|
||||||
|
1)Simply call the AI model (iFlytek Starfire | Alibaba Bailian) to obtain custom text content.
|
||||||
|
|
||||||
|
2)Simple JWT permission verification, using backend interceptors for login verification.
|
||||||
|
|
||||||
|
3)Upload an Excel file, convert the Excel file to CSV data, and generate visual charts online by AIGC.
|
||||||
|
|
||||||
|
4)Jousp can batch crawl book lists and execute them in conjunction with SpringSchedule scheduled tasks.
|
||||||
|
|
||||||
|
5)How does the front-end and back-end of a simple system for adding, deleting, modifying, and querying work together.
|
||||||
|
|
||||||
|
6)How are front-end routing lazy loading, CDN static resource caching optimization, and image lazy loading implemented
|
||||||
|
|
||||||
|
7)Use Lodash for throttling control to minimize ineffective malicious message brushing.
|
||||||
|
|
||||||
|
8)Use custom thread pools and FutureTasks for timeout request processing.
|
||||||
|
|
||||||
|
9)Utilize Google's GuavaRateLimited for individual flow limiting control.
|
||||||
|
|
||||||
|
10)Combining scheduled tasks with Redis for cache preheating to accelerate query efficiency and improve user experience.
|
||||||
|
|
||||||
|
## ☀️Project Introduction
|
||||||
|
|
||||||
|
+ Mainly implemented using Vue2 and SpringBoot2
|
||||||
|
|
||||||
|
+ The project permission controls are: user borrowing, librarian, and system administrator
|
||||||
|
|
||||||
|
+ Development tool: IDEA2022.1.3 (I really don't recommend using Eclipse for development. IDEA projects can be exported as Eclipse projects, and they don't affect each other, but you need to learn the tutorial yourself)
|
||||||
|
|
||||||
|
+ [IDEA ->Eclipse]( https://blog.csdn.net/HD202202/article/details/128076400 )
|
||||||
|
|
||||||
|
+ [Eclipse ->IDEA]( https://blog.csdn.net/q20010619/article/details/125096051 )
|
||||||
|
|
||||||
|
+ If the school teachers insist on software, they should still follow the requirements. Can you first ask if it is possible to choose other software development options.
|
||||||
|
|
||||||
|
+ User account password: Xiangsi Duan Hongchang 123456
|
||||||
|
|
||||||
|
+ Librarian account password: admin 123456
|
||||||
|
|
||||||
|
+ System administrator account password: root 123456
|
||||||
|
|
||||||
|
+ [Front end style reference]( https://gitee.com/mingyuefusu/tushuguanlixitong )Thank you to the original author **Mingyue Resurrection**
|
||||||
|
|
||||||
|
+ Encountered an interaction function error or the page cannot be opened. Please use the developer tool F12 to check the status code of the request and response. Of course, the novice may not understand, so it's okay. You can add me **QQ: 909088445**. Class during the day, I can only answer when I have time at night. Thank you for your understanding! ⭐⭐⭐
|
||||||
|
|
||||||
|
## ☀️Project Detailed Introduction (HighLights)
|
||||||
|
|
||||||
|
+ This project adopts a front-end and back-end separation mode, with the front-end building the page and the back-end serving as the data interface. The front-end calls the back-end data interface to obtain data and re render the page.
|
||||||
|
|
||||||
|
+ The backend has enabled CORS cross domain support
|
||||||
|
|
||||||
|
+ API authentication using Token authentication
|
||||||
|
|
||||||
|
+ The front-end provides a Token token in the Authorization field
|
||||||
|
|
||||||
|
+ Using HTTP Status Code to represent status
|
||||||
|
|
||||||
|
+ Use JSON for data return format
|
||||||
|
|
||||||
|
+ The backend uses permission interceptors for permission verification and checks login status
|
||||||
|
|
||||||
|
+ Add a global exception handling mechanism to capture exceptions and enhance system robustness
|
||||||
|
|
||||||
|
+ The front-end uses the Echarts visualization library to implement analysis icons (line charts, pie charts) for book borrowing, and improves the loading experience through loading configuration.
|
||||||
|
|
||||||
|
+ The message component adopts bullet screen format, which is in line with user preferences.
|
||||||
|
|
||||||
|
+ Introduce the knife4j dependency and use Swagger+Knife4j to automatically generate interface documents for the OpenAPI specification. The front-end can use plugins to automatically generate interface request codes based on this, reducing the cost of front-end and back-end collaboration
|
||||||
|
|
||||||
|
+ By using the ElementUI component library for front-end interface construction, we can quickly generate pages and achieve unified permission management and multi environment switching capabilities for both front-end and back-end.
|
||||||
|
|
||||||
|
+ The QueryWrapper based on the MyBatis Plus framework enables flexible querying of MySQL databases and, in conjunction with the MyBatisX plugin, automatically generates backend CRUD basic code to reduce repetitive work.
|
||||||
|
|
||||||
|
+ Front end routing lazy loading, CDN static resource cache optimization, and image lazy loading effect.
|
||||||
|
|
||||||
|
### ⭐Introduction To User Module Functions
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ Book query function: The pagination constructor alleviates the pressure of excessive data, and the backend can set the number of requests to prevent excessive crawler requests and server load. Fuzzy query for field search. Tables can be exported to both PDF and Excel.
|
||||||
|
|
||||||
|
+ Reader rule function: Query existing borrowing rules, borrowing rules include: borrowing number, number of books that can be borrowed, number of days that can be borrowed, library that can be borrowed, overdue fee deduction/day.
|
||||||
|
|
||||||
|
+ View announcements: You can check the list of announcements published by the librarian, with text scrolling effect.
|
||||||
|
|
||||||
|
+ Personal information: You can view an individual's borrowing card number, borrowing card name, rule number, status, and modify the password of your personal account.
|
||||||
|
|
||||||
|
+ Borrowing information: You can view the records and return status of books you have borrowed.
|
||||||
|
|
||||||
|
+ Violation information: You can check whether the returned books contain any violation information.
|
||||||
|
|
||||||
|
+ Reader's message: Implement the message function and display it in bullet screen format.
|
||||||
|
|
||||||
|
### ⭐Introduction To The Functions Of The Librarian Module
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ Borrowing Books: The librarian enters the borrowing card number (user), the book number to be borrowed, and the current time, and clicks to borrow.
|
||||||
|
|
||||||
|
+ Returning books: Enter the book number to check if the book is overdue, and set violation information, then choose whether to return the book
|
||||||
|
|
||||||
|
+ Book Borrowing Report: Used to query the list of books that have been borrowed and returned. It also uses a pagination constructor and fuzzy query fields to display the borrowing card number, book number, borrowing date, deadline, return date, violation information, and handler.
|
||||||
|
|
||||||
|
+ Book Return Report: Used to query the list of books that have been borrowed but not yet returned, displaying the borrowing card number, book number, borrowing date, and deadline.
|
||||||
|
|
||||||
|
+ Announcement: You can query the current list of announcements and delete, modify, and add features. The pagination constructor is used to alleviate the situation of large data volume.
|
||||||
|
|
||||||
|
### ⭐Introduction To The Functions Of The System Administrator Module
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ Book management: It can query all current books, display book numbers, book nicknames, authors, libraries, classifications, locations, status, and descriptions. You can add, modify, and delete books. Implement batch queries using a paging constructor. Utilize fuzzy queries to achieve book search functionality. Use plugins to export PDF and Excel.
|
||||||
|
|
||||||
|
+ Book Types: Display and query all current book types, which can be added, modified, or deleted. Use a pagination constructor to achieve batch queries and alleviate data pressure.
|
||||||
|
|
||||||
|
+ Borrowing Card Management: It is possible to query the current list of all borrowing cards, that is, the number of users, and perform operations such as adding, modifying, and deleting. Implement pagination as well.
|
||||||
|
|
||||||
|
+ Borrowing information query: can query the current completed borrowing and returning records, display the borrowing card number, book number, borrowing date, deadline, return date, violation information, and handler. Paging function, PDF and Excel export.
|
||||||
|
|
||||||
|
+ Borrowing Rule Management: You can query all current borrowing rules, display restricted borrowing days, restricted book count, restricted library, overdue fees, and perform add, delete, and modify operations.
|
||||||
|
|
||||||
|
+ Librarian Management: Display the current list of librarians, including accounts, names, and email addresses, allowing for adding, deleting, and modifying operations.
|
||||||
|
|
||||||
|
+ System management: It is possible to query the borrowing volume within a month, calculate the borrowing volume at a weekly interval, and use Echarts to display a line chart.
|
||||||
|
|
||||||
|
## ☀️Database Table Design
|
||||||
|
|
||||||
|
### t_users表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ----------- | ---------------- | ------------------------------------------------- |
|
||||||
|
| user_id | int(11) | 主键 非空 自增 用户表的唯一标识 |
|
||||||
|
| username | varchar(32) | 用户名 非空 |
|
||||||
|
| password | varchar(32) | 密码(MD5加密) 非空 |
|
||||||
|
| card_name | varchar(10) | 真实姓名 非空 |
|
||||||
|
| card_number | Bigint(11) | 借阅证编号 固定 11位随机生成 非空(后文都改BigInt) |
|
||||||
|
| rule_number | int(11) | 规则编号 可以自定义 也就是权限功能 |
|
||||||
|
| status | int(1) | 1表示可用 0表示禁用 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_admins表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ----------- | ---------------- | --------------------------------- |
|
||||||
|
| admin_id | int(11) | 主键 非空 自增 管理员表的唯一标识 |
|
||||||
|
| username | varchar(32) | 用户名 非空 |
|
||||||
|
| password | varchar(32) | 密码(MD5加密) 非空 |
|
||||||
|
| admin_name | varchar(10) | 管理员真实姓名 非空 |
|
||||||
|
| status | int(1) | 1表示可用 0表示禁用 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_book_admins表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| --------------- | ---------------- | ------------------------------- |
|
||||||
|
| book_admin_id | int(11) | 主键 非空 自增 管理表的唯一标识 |
|
||||||
|
| username | varchar(32) | 用户名 非空 |
|
||||||
|
| password | varchar(32) | 密码(MD5加密)非空 |
|
||||||
|
| book_admin_name | varchar(10) | 图书管理员真实姓名 非空 |
|
||||||
|
| status | int(1) | 1表示可用 0表示禁用 |
|
||||||
|
| email | varchar(255) | 电子邮箱 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_books表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ---------------- | ---------------- | ------------------------------- |
|
||||||
|
| book_id | int(11) | 主键 自增 非空 图书表的唯一标识 |
|
||||||
|
| book_number | int(11) | 图书编号 非空 图书的唯一标识 |
|
||||||
|
| book_name | varchar(32) | 图书名称 非空 |
|
||||||
|
| book_author | varchar(32) | 图书作者 非空 |
|
||||||
|
| book_library | varchar(32) | 图书所在图书馆的名称 非空 |
|
||||||
|
| book_type | varchar(32) | 图书类别 非空 |
|
||||||
|
| book_location | varchar(32) | 图书位置 非空 |
|
||||||
|
| book_status | varchar(32) | 图书状态(未借出/已借出) |
|
||||||
|
| book_description | varchar(100) | 图书描述 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_books_borrow表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ----------- | ---------------- | ------------------------------------------------------------ |
|
||||||
|
| borrow_id | int(11) | 主键 自增 非空 借阅表的唯一标识 |
|
||||||
|
| card_number | int(11) | 借阅证编号 固定 11位随机生成 非空 用户与图书关联的的唯一标识 |
|
||||||
|
| book_number | int(11) | 图书编号 非空 图书的唯一标识 |
|
||||||
|
| borrow_date | datetime | 借阅日期 Java注解 JsonFormatter |
|
||||||
|
| close_date | datetime | 截止日期 Java注解 JsonFormatter |
|
||||||
|
| return_date | datetime | 归还日期 Java注解 JsonFormatter |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_notice表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| --------------- | ---------------- | ----------------------------------- |
|
||||||
|
| notice_id | int(11) | 主键 非空 自增 公告表记录的唯一标识 |
|
||||||
|
| notice_title | varchar(32) | 公告的题目 非空 |
|
||||||
|
| notice_content | varchar(255) | 公告的内容 非空 |
|
||||||
|
| notice_admin_id | int(11) | 发布公告的管理员的id |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_violation表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ------------------ | ---------------- | ----------------------------------- |
|
||||||
|
| violation_id | int(11) | 主键 非空 自增 违章表记录的唯一标识 |
|
||||||
|
| card_number | int(11) | 借阅证编号 固定 11位随机生成 非空 |
|
||||||
|
| book_number | int(11) | 图书编号 非空 图书的唯一标识 |
|
||||||
|
| borrow_date | datetime | 借阅日期 Java注解 JsonFormatter |
|
||||||
|
| close_date | datetime | 截止日期 Java注解 JsonFormatter |
|
||||||
|
| return_date | datetime | 归还日期 Java注解 JsonFormatter |
|
||||||
|
| violation_message | varchar(100) | 违章信息 非空 |
|
||||||
|
| violation_admin_id | int(11) | 违章信息管理员的id |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_comment表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| --------------------- | ---------------- | ----------------------------------- |
|
||||||
|
| comment_id | int(11) | 主键 非空 自增 留言表记录的唯一标识 |
|
||||||
|
| comment_avatar | varchar(255) | 留言的头像 |
|
||||||
|
| comment_barrage_style | varchar(32) | 弹幕的高度 |
|
||||||
|
| comment_message | varchar(255) | 留言的内容 |
|
||||||
|
| comment_time | int(11) | 留言的时间(控制速度) |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_book_rule表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ------------------ | ---------------- | ------------------------------------- |
|
||||||
|
| rule_id | int(11) | 主键 非空 自增 借阅规则记录的唯一标识 |
|
||||||
|
| book_rule_id | int(11) | 借阅规则编号 非空 |
|
||||||
|
| book_days | int(11) | 借阅天数 非空 |
|
||||||
|
| book_limit_number | int(11) | 限制借阅的本数 非空 |
|
||||||
|
| book_limit_library | varchar(255) | 限制的图书馆 非空 |
|
||||||
|
| book_overdue_fee | double | 图书借阅逾期后每天费用 非空 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
### t_book_type表
|
||||||
|
|
||||||
|
| 列名 | 数据类型以及长度 | 备注 |
|
||||||
|
| ------------ | ---------------- | ------------------------------------- |
|
||||||
|
| type_id | int(11) | 主键 非空 自增 图书类别记录的唯一标识 |
|
||||||
|
| type_name | varchar(32) | 借阅类别的昵称 非空 |
|
||||||
|
| type_content | varchar(255) | 借阅类别的描述 非空 |
|
||||||
|
| create_time | datetime | 创建时间 Java注解 JsonFormatter |
|
||||||
|
| update_time | datetime | 更新时间 Java注解 JsonFormatter |
|
||||||
|
|
||||||
|
## 🐼Functional Demonstration Diagram
|
||||||
|
|
||||||
|
### User Module Function Diagram
|
||||||
|
|
||||||
|
**Homepage carousel demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Book search demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Reader Rule Demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**View announcement demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Personal information demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Presentation of Borrowing Information**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Violation information demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Reader's message demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Intelligent recommendation demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Library Administrator Function Diagram
|
||||||
|
|
||||||
|
**Borrowing book demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Demo on returning books**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Presentation of borrowing report**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Presentation of return report**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Announcement demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### System Administrator Function Diagram
|
||||||
|
|
||||||
|
+ Due to space limitations, the main functions of the system are displayed.
|
||||||
|
|
||||||
|
**System Management Demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Intelligent analysis demonstration**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐼Deployment Projects
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ You can download ZIP compressed packages or use clones (Git clone)
|
||||||
|
|
||||||
|
+ Copy HTTP or SSH links (Github suggests SSH, Gittee can do both)
|
||||||
|
|
||||||
|
+ Create a new folder on drive D, click to enter the folder, right-click on Git Bash Here
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
+ If you haven't downloaded Git yet or don't know Git, it is recommended to read the basic tutorial first (about 30 minutes)
|
||||||
|
|
||||||
|
+ Enter git init to initialize the git project and a. git folder will appear
|
||||||
|
|
||||||
|
+ Enter git remote add origin xxxxxx (xxx is the HTTP or SSH link just copied)
|
||||||
|
|
||||||
|
+ Enter git pull origin master to pull code from a remote code hosting repository
|
||||||
|
|
||||||
|
+ Successfully pulled the project (both front-end and back-end are like this)
|
||||||
|
|
||||||
|
+ Front end projects should pay attention to relying on downloading and using npm install or yarn install (Vscode or Webstorm)
|
||||||
|
|
||||||
|
+ Backend projects should pay attention to Maven dependency downloads (IDEA (recommended) or Ecplise)
|
||||||
|
|
||||||
|
+ Suggest Taobao image source for front-end NPM image source, and Alibaba Cloud image source for back-end Maven image source (optional, but quick download after replacement)
|
||||||
|
|
||||||
|
## 🐼Deployment Project Issues
|
||||||
|
|
||||||
|
⭐
|
||||||
|
|
||||||
|
+ The UFT-8 used in the garbled code problem project
|
||||||
|
|
||||||
|
+ Generally, garbled characters are the opposite of UTF-8 and GBK
|
||||||
|
|
||||||
|
+ Please provide a clear description of Baidu IDEA garbled code and Eclipse garbled code issues
|
||||||
|
|
||||||
|
⭐
|
||||||
|
|
||||||
|
+ Clicking the interaction button did not result in any response.
|
||||||
|
|
||||||
|
+ It is obvious that the request has failed. The browser opens the developer tool, and Edge browser directly uses Ctrl+shift+i, while other browsers press F12
|
||||||
|
|
||||||
|
+ View red request and response status code issues
|
||||||
|
|
||||||
|
⭐
|
||||||
|
|
||||||
|
+ Read the document first before querying or asking questions
|
||||||
|
|
||||||
|
+ Skilled questioning and vague statements make it difficult for senior architects to identify bugs
|
||||||
|
|
||||||
|
⭐
|
||||||
|
|
||||||
|
+ **QQ: 909088445**
|
||||||
|
|
||||||
|
+ Usually online at night, it is recommended to find the problem yourself first!!!
|
||||||
|
|
||||||
|
+ Open source is free, customized and debugging projects are paid for.
|
||||||
|
|
||||||
|
## 🐼Requirement Analysis And Design
|
||||||
|
|
||||||
|
Requirement analysis and design documents. For those with (**paid**) requirements, you can add QQ: 909088445. It is suitable for those who have completed the design and course design. For those who want to save time, please feel free to contact me.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐼Project API Interface Document
|
||||||
|
|
||||||
|
+ The interface document is too lengthy
|
||||||
|
|
||||||
|
+ I originally intended to completely adopt the RESTFUL style, but forgot halfway through it
|
||||||
|
|
||||||
|
+ Read the reference address of the document clearly
|
||||||
|
|
||||||
|
+ To combine the detailed content of the API backend interface document with the database structure and content, the front-end and back-end **star will be added** ⭐ Take a screenshot of it and add it to my QQ: **909088445** Send it to me to collect it~Thank you for your support
|
||||||
|
|
||||||
|
#### **Sample Screenshot Of Database Retrieval (Gitee&GitHub):**
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 🐷 Other
|
||||||
|
|
||||||
|
+ Personal blog address: https://luoye6.github.io/
|
||||||
|
|
||||||
|
+ Personal blog is hosted on Hexo+Github
|
||||||
|
|
||||||
|
+ Using the butterfly theme can achieve customization
|
||||||
|
|
||||||
|
+ It is recommended that those who have free time can spend 1-2 days building a personal blog to take notes.
|
||||||
|
|
||||||
|
## ☕Please Treat Me To coffee
|
||||||
|
|
||||||
|
If this project is helpful to you, may I have a cup of coffee with the author :)
|
||||||
|
|
||||||
|
<div><img src="https://pic.yupi.icu/5563/202312191854931.png" style="height:300px;width:300px"></img> <img src="https://pic.yupi.icu/5563/202312191859536.png" style="height:300px;width:300px"></img></div>
|
||||||
|
|
||||||
|
## **Version Iteration**
|
||||||
|
|
||||||
|
### March 19, 2023
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1)Introduce the knife4j dependency and use Swagger+Knife4j to automatically generate interface documentation for the OpenAPI specification. The front-end can use plugins to automatically generate interface request code on this basis, reducing the cost of front-end and back-end collaboration.
|
||||||
|
|
||||||
|
2)Introducing JSOUP dependencies allows for custom addition of crawler functionality, allowing for batch addition of books with relatively real data.
|
||||||
|
|
||||||
|
3)Add a transaction manager to enable @ Transactional to specify exception types for rollback and transaction propagation behavior.
|
||||||
|
|
||||||
|
### April 13, 2023
|
||||||
|
|
||||||
|
1)In manually adding and deleting database operations with complex logic, @ Transactional annotations have been added. When encountering runtime exceptions, the database can be rolled back directly to prevent logical errors in borrowing and returning books.
|
||||||
|
|
||||||
|
2)Fix the bug where the 11 digit book number cannot be borrowed, as it exceeds the integer's 2147483647 (10 digits). Solution: Change the database to BigInt and Java to Long.
|
||||||
|
|
||||||
|
3)**Note**: Do not delete users and announcements casually!!! It can cause logical errors when others experience it!!! Please understand the project logic before proceeding with the deletion operation!!! Thank you for your cooperation!!!
|
||||||
|
|
||||||
|
4)In the next issue, we are preparing to optimize the display of charts and functions such as alarm notifications after overdue books. Thank you for your support. I will continue to maintain and optimize the functions. If there are any bugs, you can add me on QQ or raise an issue. Do not maliciously exploit the bugs. Thank you again.
|
||||||
|
|
||||||
|
5)A video of a deployment project for Labor Day will be posted on Bilibili, and the deployment will be explained clearly to facilitate the completion of course or final projects. This project includes database table design, API interface documentation, content and function introduction, and highlight introduction. The only missing ones may be data flow diagrams, ER diagrams, and so on. As there are many people on Star, I will add them.
|
||||||
|
|
||||||
|
### May 1st, 2023
|
||||||
|
|
||||||
|
1)Add the system management function with "System Administrator" permissions, and **add a borrowing type analysis and statistical chart (pie chart)** using Echarts.
|
||||||
|
|
||||||
|
2)Optimize the display lag when no data is received, add a "loading" status, **use v-loading** (ElementUI component library), **optimize user human-machine interaction experience**, and provide **good interaction** when the server calls the interface slowly.
|
||||||
|
|
||||||
|
3)Rotation image optimization: **Compress image volume**, and also use Swiper's **Lazy loading** to achieve image loading status, and then display the image only after it is fully loaded, **optimizing the user experience process**.
|
||||||
|
|
||||||
|
4)Add a custom error code enumeration class to the backend, which allows for custom status codes to be returned while retaining the original enumeration class.
|
||||||
|
|
||||||
|
5)The front-end optimization section displays table content. When the vertical content is too long and the maximum height of the table is set, a sliding window will be displayed if it exceeds the limit. Optimize table column width and improve table aesthetics.
|
||||||
|
|
||||||
|
6)Add the **Batch Delete Books** function of the Book Management component to optimize the administrator experience, eliminating the need for individual book deletions and improving efficiency.
|
||||||
|
|
||||||
|
7)Jmeter conducted stress testing, and the server interface achieved a QPS of 50 or above when **100 users simultaneously sent requests**.
|
||||||
|
|
||||||
|
### May 20th, 2023
|
||||||
|
|
||||||
|
**Backend updates**
|
||||||
|
|
||||||
|
1)To prevent the front-end from capturing packets and obtaining plaintext passwords, the front-end inputs the password and performs MD5 encryption (mixed salt values to prevent collisions). The back-end directly compares the encrypted password with the database, and equality represents successful login. Improve system security.
|
||||||
|
|
||||||
|
2)Rectify the Controller layer by placing all business code into the Service layer, where the Controller calls the Service service and modifies the @ Transactional annotation position to the Business layer, reducing coupling and reducing bloating for the Controller. Be open to extensions and closed to modifications. In the future, we will consider using **design patterns** to optimize code and **multi threading** knowledge to improve interface response speed under **high concurrency**.
|
||||||
|
|
||||||
|
3)Modify the code according to the Alibaba manual, reduce warnings, and make the code more elegant and standardized.
|
||||||
|
|
||||||
|
4)**Fix bug**: Borrowing time is empty, causing server breakdown. If the return date is empty, it still shows that the borrowing was successful. (Solution: Verify the time parameter to determine if it is empty)
|
||||||
|
|
||||||
|
5)**Tool class increase**: SQLUtils (preventing SQL injection), NetUtils (network tool class)
|
||||||
|
|
||||||
|
**Front end update status**
|
||||||
|
|
||||||
|
1)Change the route loading method to lazy loading, which can effectively alleviate the pressure of homepage loading and reduce the time required for homepage loading.
|
||||||
|
|
||||||
|
2)Add a 404 page, and when the user visits a page with a request address that does not exist, they will be redirected directly to the 404 page to improve the user experience.
|
||||||
|
|
||||||
|
3)Add the loading status of the button, **optimize human-computer interaction**, and improve user experience. Modify button: Login button, other buttons can be customized and modified if needed. Add: loading="loading".
|
||||||
|
|
||||||
|
**Bug fixing status**
|
||||||
|
|
||||||
|
The 1.11 digit book number can be borrowed, but **cannot be checked for overdue payment**. It was found that the method parameter is still Integer. Last time, the borrowing and returning books were changed to Long, but the overdue payment check has not been changed to Long, resulting in a problem. It has now been fixed.
|
||||||
|
|
||||||
|
### June 10, 2023
|
||||||
|
|
||||||
|
**Front end update status**
|
||||||
|
|
||||||
|
1)Add full screen function buttons on certain pages to facilitate users to zoom in and view table data.
|
||||||
|
|
||||||
|
2)Added address icons for GitHub and Gitee to facilitate project pulling and cloning.
|
||||||
|
|
||||||
|
3)The reader's comment component and comment function will be strengthened to prevent meaningless numbers, letters, and spaces from appearing in the data. Further considerations will be made in the future
|
||||||
|
|
||||||
|
4)Reader message component, **using lodash for throttling **, can only send network requests once within 5 seconds to prevent malicious brushing of invalid messages.
|
||||||
|
|
||||||
|
**Backend updates**
|
||||||
|
|
||||||
|
1)Add a batch import function for books using EasyExcel on the backend to achieve interaction with storing some book data using Excel in real life, improve import efficiency, and achieve the same effect as the crawler function. It can also import large amounts of data. It is recommended to use EasyExcel for batch import, which will take faster time than the crawler function.
|
||||||
|
|
||||||
|
**Bug fixing status**
|
||||||
|
|
||||||
|
1)Modify the password modification function on the user page, as the last update already added salt values, but the backend code logic has not been changed. This fix "inability to log in after password modification" is due to the backend not adding salt values, which has been fixed.
|
||||||
|
|
||||||
|
2)Fixed the issue where the system administrator changed the password for the borrowing certificate and was unable to log in. The reason is the same as the first bug, as the backend's salt value was not added and has been fixed.
|
||||||
|
|
||||||
|
3)Fixed the issue where the system administrator directly clicked on "modify book" in the book management function and found that the classification of the book was incorrect. This was because the front-end only sent a request to obtain the classification in the "add book" dialog box, and forgot to add a request to obtain the classification when modifying the dialog box. This issue has been fixed.
|
||||||
|
|
||||||
|
### September 2023
|
||||||
|
|
||||||
|
**Front end update status**
|
||||||
|
|
||||||
|
1)Add an intelligent recommendation page that can communicate with AI. Users can input their favorite xxx books, and AI can analyze them in existing databases to make recommendations. The domestic AI model is called, and the underlying layer is OpenAI.
|
||||||
|
|
||||||
|
2)Add an intelligent analysis page, input analysis objectives, icon types, and Excel files, generate analysis conclusions and visual icons through AI, greatly improving efficiency and reducing labor analysis costs.
|
||||||
|
|
||||||
|
3)Add the function of system administrators to upload books in bulk using Excel files on the front-end (under testing), for reference only.
|
||||||
|
|
||||||
|
**Backend updates**
|
||||||
|
|
||||||
|
1)Add interfaces for intelligent analysis and obtaining the last 5 chat records, and use **Thread Pool** and **Future** for timeout request processing. If the interface call exceeds 40 seconds, an error message will be returned directly.
|
||||||
|
|
||||||
|
2)Utilize RateLimiter in Google's Guava for flow limiting control, allowing only one request per second to pass through, to prevent brushing behavior.
|
||||||
|
|
||||||
|
### November 2023
|
||||||
|
|
||||||
|
**Backend updates**
|
||||||
|
|
||||||
|
1)Switch the AI model for user chat to Alibaba's Tongyi Qianwen Plus model, and **support multi round session history**, no longer use iFlytek Starfire's AI model, but still retain the tool class. The main purpose is to receive a faster response, and Alibaba's documents are more detailed, allowing for customized scripts . When users input irrelevant book recommendations, they can directly **refuse to answer **.
|
||||||
|
|
||||||
|
2)Add an IncSyncDeleteAIMessage **scheduled task**, which will delete records with empty content due to system errors and other reasons every day. The number of times the interface will be restored for these users will also be. In the future, RabbitMQ may be selected to put the failed messages into the message queue, and then ensure that the failed messages are consumed .
|
||||||
|
|
||||||
|
3)Login encryption has been changed from the front-end to the back-end. As the front-end can be compromised, encryption will still be placed in the back-end Solution: Frontend transmission, encrypted with HTTPS for ciphertext, backend encrypted with salt value+algorithm, and database storing ciphertext.
|
||||||
|
|
||||||
|
4)Store the message page in Redis, **reduce database IO queries**, and increase QPS by hundreds of times!
|
||||||
|
|
||||||
|
**Front end update status**
|
||||||
|
|
||||||
|
1)Change the background images and avatars of the three login pages to be stored in the images folder of the assets folder, mainly for the sake of users of the project. Many people do not understand graphic bed technology, so I will temporarily change the login pages to static images.
|
||||||
|
|
||||||
|
2)Optimization of permission switching prompt, There is now a text style for login permission switching on the icon , indicating that users have multiple login pages to switch between.
|
||||||
|
|
||||||
|
3)Login encryption has been changed from the front-end to the back-end. As the front-end can be compromised, encryption will still be placed in the back-end **Solution**: Frontend transmission, encrypted with HTTPS for ciphertext, backend encrypted with salt value+algorithm, and database storing ciphertext.
|
||||||
|
|
||||||
|
### March 2024
|
||||||
|
|
||||||
|
**Backend updates**
|
||||||
|
|
||||||
|
1)Add @ ApiOperation annotations to Knife4J to indicate the purpose of each interface, making it easier for developers to read and test the interfaces.
|
BIN
doc/swagger.png
Normal file
BIN
doc/swagger.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 KiB |
316
mvnw
vendored
Normal file
316
mvnw
vendored
Normal file
@ -0,0 +1,316 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing,
|
||||||
|
# software distributed under the License is distributed on an
|
||||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
# KIND, either express or implied. See the License for the
|
||||||
|
# specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Maven Start Up Batch script
|
||||||
|
#
|
||||||
|
# Required ENV vars:
|
||||||
|
# ------------------
|
||||||
|
# JAVA_HOME - location of a JDK home dir
|
||||||
|
#
|
||||||
|
# Optional ENV vars
|
||||||
|
# -----------------
|
||||||
|
# M2_HOME - location of maven2's installed home dir
|
||||||
|
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||||
|
# e.g. to debug Maven itself, use
|
||||||
|
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||||
|
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||||
|
|
||||||
|
if [ -f /usr/local/etc/mavenrc ] ; then
|
||||||
|
. /usr/local/etc/mavenrc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f /etc/mavenrc ] ; then
|
||||||
|
. /etc/mavenrc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$HOME/.mavenrc" ] ; then
|
||||||
|
. "$HOME/.mavenrc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
# OS specific support. $var _must_ be set to either true or false.
|
||||||
|
cygwin=false;
|
||||||
|
darwin=false;
|
||||||
|
mingw=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN*) cygwin=true ;;
|
||||||
|
MINGW*) mingw=true;;
|
||||||
|
Darwin*) darwin=true
|
||||||
|
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||||
|
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||||
|
if [ -z "$JAVA_HOME" ]; then
|
||||||
|
if [ -x "/usr/libexec/java_home" ]; then
|
||||||
|
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||||
|
else
|
||||||
|
export JAVA_HOME="/Library/Java/Home"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ] ; then
|
||||||
|
if [ -r /etc/gentoo-release ] ; then
|
||||||
|
JAVA_HOME=`java-config --jre-home`
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$M2_HOME" ] ; then
|
||||||
|
## resolve links - $0 may be a link to maven's home
|
||||||
|
PRG="$0"
|
||||||
|
|
||||||
|
# need this for relative symlinks
|
||||||
|
while [ -h "$PRG" ] ; do
|
||||||
|
ls=`ls -ld "$PRG"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG="`dirname "$PRG"`/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
saveddir=`pwd`
|
||||||
|
|
||||||
|
M2_HOME=`dirname "$PRG"`/..
|
||||||
|
|
||||||
|
# make it fully qualified
|
||||||
|
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||||
|
|
||||||
|
cd "$saveddir"
|
||||||
|
# echo Using m2 at $M2_HOME
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||||
|
if $cygwin ; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||||
|
[ -n "$CLASSPATH" ] &&
|
||||||
|
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||||
|
if $mingw ; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ]; then
|
||||||
|
javaExecutable="`which javac`"
|
||||||
|
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
||||||
|
# readlink(1) is not available as standard on Solaris 10.
|
||||||
|
readLink=`which readlink`
|
||||||
|
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
||||||
|
if $darwin ; then
|
||||||
|
javaHome="`dirname \"$javaExecutable\"`"
|
||||||
|
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
||||||
|
else
|
||||||
|
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
||||||
|
fi
|
||||||
|
javaHome="`dirname \"$javaExecutable\"`"
|
||||||
|
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
||||||
|
JAVA_HOME="$javaHome"
|
||||||
|
export JAVA_HOME
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVACMD" ] ; then
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="`\\unset -f command; \\command -v java`"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||||
|
echo " We cannot execute $JAVACMD" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ] ; then
|
||||||
|
echo "Warning: JAVA_HOME environment variable is not set."
|
||||||
|
fi
|
||||||
|
|
||||||
|
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||||
|
|
||||||
|
# traverses directory structure from process work directory to filesystem root
|
||||||
|
# first directory with .mvn subdirectory is considered project base directory
|
||||||
|
find_maven_basedir() {
|
||||||
|
|
||||||
|
if [ -z "$1" ]
|
||||||
|
then
|
||||||
|
echo "Path not specified to find_maven_basedir"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
basedir="$1"
|
||||||
|
wdir="$1"
|
||||||
|
while [ "$wdir" != '/' ] ; do
|
||||||
|
if [ -d "$wdir"/.mvn ] ; then
|
||||||
|
basedir=$wdir
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||||
|
if [ -d "${wdir}" ]; then
|
||||||
|
wdir=`cd "$wdir/.."; pwd`
|
||||||
|
fi
|
||||||
|
# end of workaround
|
||||||
|
done
|
||||||
|
echo "${basedir}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# concatenates all lines of a file
|
||||||
|
concat_lines() {
|
||||||
|
if [ -f "$1" ]; then
|
||||||
|
echo "$(tr -s '\n' ' ' < "$1")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||||
|
if [ -z "$BASE_DIR" ]; then
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
##########################################################################################
|
||||||
|
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||||
|
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||||
|
##########################################################################################
|
||||||
|
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo "Found .mvn/wrapper/maven-wrapper.jar"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
||||||
|
fi
|
||||||
|
if [ -n "$MVNW_REPOURL" ]; then
|
||||||
|
jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
|
||||||
|
else
|
||||||
|
jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
|
||||||
|
fi
|
||||||
|
while IFS="=" read key value; do
|
||||||
|
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
|
||||||
|
esac
|
||||||
|
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo "Downloading from: $jarUrl"
|
||||||
|
fi
|
||||||
|
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
||||||
|
if $cygwin; then
|
||||||
|
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v wget > /dev/null; then
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo "Found wget ... using wget"
|
||||||
|
fi
|
||||||
|
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||||
|
wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
|
||||||
|
else
|
||||||
|
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
|
||||||
|
fi
|
||||||
|
elif command -v curl > /dev/null; then
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo "Found curl ... using curl"
|
||||||
|
fi
|
||||||
|
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||||
|
curl -o "$wrapperJarPath" "$jarUrl" -f
|
||||||
|
else
|
||||||
|
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo "Falling back to using Java to download"
|
||||||
|
fi
|
||||||
|
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||||
|
# For Cygwin, switch paths to Windows format before running javac
|
||||||
|
if $cygwin; then
|
||||||
|
javaClass=`cygpath --path --windows "$javaClass"`
|
||||||
|
fi
|
||||||
|
if [ -e "$javaClass" ]; then
|
||||||
|
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo " - Compiling MavenWrapperDownloader.java ..."
|
||||||
|
fi
|
||||||
|
# Compiling the Java class
|
||||||
|
("$JAVA_HOME/bin/javac" "$javaClass")
|
||||||
|
fi
|
||||||
|
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||||
|
# Running the downloader
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo " - Running MavenWrapperDownloader.java ..."
|
||||||
|
fi
|
||||||
|
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
##########################################################################################
|
||||||
|
# End of extension
|
||||||
|
##########################################################################################
|
||||||
|
|
||||||
|
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo $MAVEN_PROJECTBASEDIR
|
||||||
|
fi
|
||||||
|
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
|
if $cygwin; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||||
|
[ -n "$CLASSPATH" ] &&
|
||||||
|
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||||
|
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||||
|
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Provide a "standardized" way to retrieve the CLI args that will
|
||||||
|
# work with both Windows and non-Windows executions.
|
||||||
|
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
|
||||||
|
export MAVEN_CMD_LINE_ARGS
|
||||||
|
|
||||||
|
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||||
|
|
||||||
|
exec "$JAVACMD" \
|
||||||
|
$MAVEN_OPTS \
|
||||||
|
$MAVEN_DEBUG_OPTS \
|
||||||
|
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||||
|
"-Dmaven.home=${M2_HOME}" \
|
||||||
|
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||||
|
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
188
mvnw.cmd
vendored
Normal file
188
mvnw.cmd
vendored
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
@REM or more contributor license agreements. See the NOTICE file
|
||||||
|
@REM distributed with this work for additional information
|
||||||
|
@REM regarding copyright ownership. The ASF licenses this file
|
||||||
|
@REM to you under the Apache License, Version 2.0 (the
|
||||||
|
@REM "License"); you may not use this file except in compliance
|
||||||
|
@REM with the License. You may obtain a copy of the License at
|
||||||
|
@REM
|
||||||
|
@REM https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@REM
|
||||||
|
@REM Unless required by applicable law or agreed to in writing,
|
||||||
|
@REM software distributed under the License is distributed on an
|
||||||
|
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@REM KIND, either express or implied. See the License for the
|
||||||
|
@REM specific language governing permissions and limitations
|
||||||
|
@REM under the License.
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
@REM Maven Start Up Batch script
|
||||||
|
@REM
|
||||||
|
@REM Required ENV vars:
|
||||||
|
@REM JAVA_HOME - location of a JDK home dir
|
||||||
|
@REM
|
||||||
|
@REM Optional ENV vars
|
||||||
|
@REM M2_HOME - location of maven2's installed home dir
|
||||||
|
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||||
|
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
|
||||||
|
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||||
|
@REM e.g. to debug Maven itself, use
|
||||||
|
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||||
|
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||||
|
@echo off
|
||||||
|
@REM set title of command window
|
||||||
|
title %0
|
||||||
|
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
|
||||||
|
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||||
|
|
||||||
|
@REM set %HOME% to equivalent of $HOME
|
||||||
|
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||||
|
|
||||||
|
@REM Execute a user defined script before this one
|
||||||
|
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||||
|
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||||
|
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
|
||||||
|
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
|
||||||
|
:skipRcPre
|
||||||
|
|
||||||
|
@setlocal
|
||||||
|
|
||||||
|
set ERROR_CODE=0
|
||||||
|
|
||||||
|
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||||
|
@setlocal
|
||||||
|
|
||||||
|
@REM ==== START VALIDATION ====
|
||||||
|
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Error: JAVA_HOME not found in your environment. >&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||||
|
echo location of your Java installation. >&2
|
||||||
|
echo.
|
||||||
|
goto error
|
||||||
|
|
||||||
|
:OkJHome
|
||||||
|
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||||
|
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||||
|
echo location of your Java installation. >&2
|
||||||
|
echo.
|
||||||
|
goto error
|
||||||
|
|
||||||
|
@REM ==== END VALIDATION ====
|
||||||
|
|
||||||
|
:init
|
||||||
|
|
||||||
|
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||||
|
@REM Fallback to current working directory if not found.
|
||||||
|
|
||||||
|
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||||
|
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||||
|
|
||||||
|
set EXEC_DIR=%CD%
|
||||||
|
set WDIR=%EXEC_DIR%
|
||||||
|
:findBaseDir
|
||||||
|
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||||
|
cd ..
|
||||||
|
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||||
|
set WDIR=%CD%
|
||||||
|
goto findBaseDir
|
||||||
|
|
||||||
|
:baseDirFound
|
||||||
|
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||||
|
cd "%EXEC_DIR%"
|
||||||
|
goto endDetectBaseDir
|
||||||
|
|
||||||
|
:baseDirNotFound
|
||||||
|
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||||
|
cd "%EXEC_DIR%"
|
||||||
|
|
||||||
|
:endDetectBaseDir
|
||||||
|
|
||||||
|
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||||
|
|
||||||
|
@setlocal EnableExtensions EnableDelayedExpansion
|
||||||
|
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||||
|
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||||
|
|
||||||
|
:endReadAdditionalConfig
|
||||||
|
|
||||||
|
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||||
|
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||||
|
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||||
|
|
||||||
|
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
|
||||||
|
|
||||||
|
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
||||||
|
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
|
||||||
|
)
|
||||||
|
|
||||||
|
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||||
|
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||||
|
if exist %WRAPPER_JAR% (
|
||||||
|
if "%MVNW_VERBOSE%" == "true" (
|
||||||
|
echo Found %WRAPPER_JAR%
|
||||||
|
)
|
||||||
|
) else (
|
||||||
|
if not "%MVNW_REPOURL%" == "" (
|
||||||
|
SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
|
||||||
|
)
|
||||||
|
if "%MVNW_VERBOSE%" == "true" (
|
||||||
|
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||||
|
echo Downloading from: %DOWNLOAD_URL%
|
||||||
|
)
|
||||||
|
|
||||||
|
powershell -Command "&{"^
|
||||||
|
"$webclient = new-object System.Net.WebClient;"^
|
||||||
|
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
|
||||||
|
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
|
||||||
|
"}"^
|
||||||
|
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
|
||||||
|
"}"
|
||||||
|
if "%MVNW_VERBOSE%" == "true" (
|
||||||
|
echo Finished downloading %WRAPPER_JAR%
|
||||||
|
)
|
||||||
|
)
|
||||||
|
@REM End of extension
|
||||||
|
|
||||||
|
@REM Provide a "standardized" way to retrieve the CLI args that will
|
||||||
|
@REM work with both Windows and non-Windows executions.
|
||||||
|
set MAVEN_CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
|
%MAVEN_JAVA_EXE% ^
|
||||||
|
%JVM_CONFIG_MAVEN_PROPS% ^
|
||||||
|
%MAVEN_OPTS% ^
|
||||||
|
%MAVEN_DEBUG_OPTS% ^
|
||||||
|
-classpath %WRAPPER_JAR% ^
|
||||||
|
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
|
||||||
|
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||||
|
if ERRORLEVEL 1 goto error
|
||||||
|
goto end
|
||||||
|
|
||||||
|
:error
|
||||||
|
set ERROR_CODE=1
|
||||||
|
|
||||||
|
:end
|
||||||
|
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||||
|
|
||||||
|
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
|
||||||
|
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||||
|
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
|
||||||
|
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
|
||||||
|
:skipRcPost
|
||||||
|
|
||||||
|
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||||
|
if "%MAVEN_BATCH_PAUSE%"=="on" pause
|
||||||
|
|
||||||
|
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
|
||||||
|
|
||||||
|
cmd /C exit /B %ERROR_CODE%
|
197
pom.xml
Normal file
197
pom.xml
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
<?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"
|
||||||
|
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>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.7.8</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.book.backend</groupId>
|
||||||
|
<artifactId>vue_book_backend</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>vue_book_backend</name>
|
||||||
|
<description>vue_book_backend</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.23</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-generator</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt</artifactId>
|
||||||
|
<version>0.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.67</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.8.5</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.java-websocket/Java-WebSocket -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.java-websocket</groupId>
|
||||||
|
<artifactId>Java-WebSocket</artifactId>
|
||||||
|
<version>1.3.8</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp</artifactId>
|
||||||
|
<version>4.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.squareup.okio/okio -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okio</groupId>
|
||||||
|
<artifactId>okio</artifactId>
|
||||||
|
<version>2.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- hutool工具包-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.11</version>
|
||||||
|
</dependency>
|
||||||
|
<!--knife4j依赖导入-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
|
||||||
|
<version>4.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup Java爬虫-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jsoup</groupId>
|
||||||
|
<artifactId>jsoup</artifactId>
|
||||||
|
<version>1.15.3</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://github.com/alibaba/easyexcel -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>easyexcel</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yucongming</groupId>
|
||||||
|
<artifactId>yucongming-java-sdk</artifactId>
|
||||||
|
<version>0.0.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>30.1-jre</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://github.com/redisson/redisson#quick-start -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.redisson</groupId>
|
||||||
|
<artifactId>redisson</artifactId>
|
||||||
|
<version>3.21.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.15.2</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 阿里云AI模型-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>broadscope-bailian-sdk-java</artifactId>
|
||||||
|
<version>1.1.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-core</artifactId>
|
||||||
|
<version>1.23</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
|
<version>1.23</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.7.4</version>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<finalName>my-app</finalName> <!-- 设置打包后的JAR文件名 -->
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
</project>
|
247
sql/bms_boot_structure.sql
Normal file
247
sql/bms_boot_structure.sql
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
/*
|
||||||
|
Navicat Premium Data Transfer
|
||||||
|
|
||||||
|
Source Server : localhost
|
||||||
|
Source Server Type : MySQL
|
||||||
|
Source Server Version : 50716
|
||||||
|
Source Host : localhost:3306
|
||||||
|
Source Schema : bms_boot
|
||||||
|
|
||||||
|
Target Server Type : MySQL
|
||||||
|
Target Server Version : 50716
|
||||||
|
File Encoding : 65001
|
||||||
|
|
||||||
|
Date: 18/03/2024 14:11:45
|
||||||
|
*/
|
||||||
|
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_admins
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_admins`;
|
||||||
|
CREATE TABLE `t_admins` (
|
||||||
|
`admin_id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '管理员表的唯一标识',
|
||||||
|
`username` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
|
||||||
|
`password` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码(MD5加密)',
|
||||||
|
`admin_name` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '管理员真实姓名',
|
||||||
|
`status` int(1) NOT NULL COMMENT '1表示可用 0表示禁用',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`admin_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 1624 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_ai_intelligent
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_ai_intelligent`;
|
||||||
|
CREATE TABLE `t_ai_intelligent` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`input_message` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户输入信息',
|
||||||
|
`ai_result` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT 'AI生成结果',
|
||||||
|
`user_id` bigint(20) NULL DEFAULT NULL,
|
||||||
|
`create_time` datetime NULL DEFAULT NULL,
|
||||||
|
`update_time` datetime NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 1736624313104711683 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_book_admins
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_book_admins`;
|
||||||
|
CREATE TABLE `t_book_admins` (
|
||||||
|
`book_admin_id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '图书管理员表的唯一标识',
|
||||||
|
`username` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
|
||||||
|
`password` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码md5加密',
|
||||||
|
`book_admin_name` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书管理员真实姓名',
|
||||||
|
`status` int(1) NOT NULL COMMENT '1表示可用 0表示禁用',
|
||||||
|
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '电子邮箱',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`book_admin_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 1548 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_book_rule
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_book_rule`;
|
||||||
|
CREATE TABLE `t_book_rule` (
|
||||||
|
`rule_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '借阅规则记录的唯一标识',
|
||||||
|
`book_rule_id` int(11) NOT NULL COMMENT '借阅规则编号',
|
||||||
|
`book_days` int(11) NOT NULL COMMENT '借阅天数',
|
||||||
|
`book_limit_number` int(11) NOT NULL COMMENT '限制借阅的本数',
|
||||||
|
`book_limit_library` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '限制的图书馆',
|
||||||
|
`book_overdue_fee` double NOT NULL COMMENT '图书借阅后每天逾期费用',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`rule_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_book_type
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_book_type`;
|
||||||
|
CREATE TABLE `t_book_type` (
|
||||||
|
`type_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '图书类别唯一标识',
|
||||||
|
`type_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '借阅类别的昵称',
|
||||||
|
`type_content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '借阅类别的描述',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`type_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_books
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_books`;
|
||||||
|
CREATE TABLE `t_books` (
|
||||||
|
`book_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '图书表唯一标识',
|
||||||
|
`book_number` bigint(11) NOT NULL COMMENT '图书编号 图书的唯一标识',
|
||||||
|
`book_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书名称',
|
||||||
|
`book_author` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书作者',
|
||||||
|
`book_library` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书所在图书馆名称',
|
||||||
|
`book_type` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书类别',
|
||||||
|
`book_location` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书位置',
|
||||||
|
`book_status` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书状态',
|
||||||
|
`book_description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '图书描述',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`book_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 122 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_books_borrow
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_books_borrow`;
|
||||||
|
CREATE TABLE `t_books_borrow` (
|
||||||
|
`borrow_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '借阅表唯一标识',
|
||||||
|
`card_number` bigint(11) NOT NULL COMMENT '借阅证编号 固定11位随机生成 用户和图书关联的唯一标识',
|
||||||
|
`book_number` bigint(11) NOT NULL COMMENT '图书编号 图书唯一标识',
|
||||||
|
`borrow_date` datetime NOT NULL COMMENT '借阅日期',
|
||||||
|
`close_date` datetime NOT NULL COMMENT '截止日期',
|
||||||
|
`return_date` datetime NULL DEFAULT NULL COMMENT '归还日期',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`borrow_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 45 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_chart
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_chart`;
|
||||||
|
CREATE TABLE `t_chart` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||||
|
`name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '图标名称',
|
||||||
|
`goal` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '分析目标',
|
||||||
|
`chart_data` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '图标数据',
|
||||||
|
`chart_type` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '图标类型',
|
||||||
|
`gen_chart` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '生成的图标数据',
|
||||||
|
`gen_result` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '生成的分析结论',
|
||||||
|
`status` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'wait' COMMENT 'wait,running,succeed,failed',
|
||||||
|
`exec_message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '执行信息',
|
||||||
|
`admin_id` bigint(20) NULL DEFAULT NULL COMMENT '创建管理员 id',
|
||||||
|
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`isDelete` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 1736624602977255426 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '图表信息表' ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_chat
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_chat`;
|
||||||
|
CREATE TABLE `t_chat` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '聊天记录id\r\n',
|
||||||
|
`from_id` bigint(20) NOT NULL COMMENT '发送消息者id\r\n',
|
||||||
|
`to_id` bigint(20) NULL DEFAULT NULL COMMENT '接受消息者id,可以为空',
|
||||||
|
`text` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '消息内容',
|
||||||
|
`chat_type` tinyint(4) NOT NULL COMMENT '聊天类型 1-私聊 2-群聊',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`message_type` int(1) NOT NULL COMMENT '消息类型 1 文本 2 撤回消息 3 图片 4 语音 5 视频',
|
||||||
|
`role` int(11) NOT NULL COMMENT '消息发送者身份 1 用户 2 图书管理员',
|
||||||
|
`reply_message` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '回复的消息内容',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_comment
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_comment`;
|
||||||
|
CREATE TABLE `t_comment` (
|
||||||
|
`comment_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '留言表唯一标识',
|
||||||
|
`comment_avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '留言的头像 链接',
|
||||||
|
`comment_barrage_style` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '弹幕的高度(样式)',
|
||||||
|
`comment_message` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '弹幕的内容',
|
||||||
|
`comment_time` int(11) NOT NULL COMMENT '留言的时间(控制速度)',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`comment_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 65 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_notice
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_notice`;
|
||||||
|
CREATE TABLE `t_notice` (
|
||||||
|
`notice_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '公告表唯一标识',
|
||||||
|
`notice_title` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '公告题目',
|
||||||
|
`notice_content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '公告内容',
|
||||||
|
`notice_admin_id` int(11) NOT NULL COMMENT '发布公告的管理员id',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`notice_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_user_interface_info
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_user_interface_info`;
|
||||||
|
CREATE TABLE `t_user_interface_info` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`user_id` bigint(20) NOT NULL COMMENT '用户id或管理员id',
|
||||||
|
`interface_id` bigint(20) NOT NULL COMMENT '1 表示AI聊天接口 2表示智能分析接口 ',
|
||||||
|
`total_num` int(11) NOT NULL DEFAULT 0 COMMENT '总共调用接口次数\r\n',
|
||||||
|
`left_num` int(11) NOT NULL DEFAULT 0 COMMENT '剩余接口可用次数',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_users
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_users`;
|
||||||
|
CREATE TABLE `t_users` (
|
||||||
|
`user_id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '用户表的唯一标识',
|
||||||
|
`username` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
|
||||||
|
`password` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码 MD5加密',
|
||||||
|
`card_name` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '真实姓名',
|
||||||
|
`card_number` bigint(11) NOT NULL COMMENT '借阅证编号 固定11位随机生成 非空',
|
||||||
|
`rule_number` int(11) NOT NULL COMMENT '规则编号 可以自定义也就是权限功能',
|
||||||
|
`status` int(1) NOT NULL COMMENT '1表示可用 0表示禁用',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`user_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 2546 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for t_violation
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `t_violation`;
|
||||||
|
CREATE TABLE `t_violation` (
|
||||||
|
`violation_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '违章表唯一标识',
|
||||||
|
`card_number` bigint(11) NOT NULL COMMENT '借阅证编号 11位 随机生成',
|
||||||
|
`book_number` bigint(11) NOT NULL COMMENT '图书编号 图书唯一标识',
|
||||||
|
`borrow_date` datetime NOT NULL COMMENT '借阅日期',
|
||||||
|
`close_date` datetime NOT NULL COMMENT '截止日期',
|
||||||
|
`return_date` datetime NULL DEFAULT NULL COMMENT '归还日期',
|
||||||
|
`violation_message` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '违章信息',
|
||||||
|
`violation_admin_id` int(11) NOT NULL COMMENT '违章信息管理员的id',
|
||||||
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
`update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`violation_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB AUTO_INCREMENT = 32 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.book.backend;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
// @SpringBootApplication(exclude = {RedisAutoConfiguration.class})
|
||||||
|
// todo 如需关闭 Redis,须添加 exclude 中的内容
|
||||||
|
@SpringBootApplication()
|
||||||
|
@MapperScan("com.book.backend.mapper")
|
||||||
|
@EnableTransactionManagement
|
||||||
|
public class VueBookBackendApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(VueBookBackendApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
src/main/java/com/book/backend/common/BaseContext.java
Normal file
25
src/main/java/com/book/backend/common/BaseContext.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package com.book.backend.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于ThreadLocal封装工具类,用于保存和获取当前登录用户id
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
public class BaseContext {
|
||||||
|
private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置值
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
public static void setCurrentId(Long id){
|
||||||
|
threadLocal.set(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Long getCurrentId(){
|
||||||
|
return threadLocal.get();
|
||||||
|
}
|
||||||
|
}
|
30
src/main/java/com/book/backend/common/BasePage.java
Normal file
30
src/main/java/com/book/backend/common/BasePage.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.book.backend.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BasePage {
|
||||||
|
/**
|
||||||
|
* 分页参数 当前页
|
||||||
|
*/
|
||||||
|
private int pageNum = 1;
|
||||||
|
/**
|
||||||
|
* 分页参数每页条数
|
||||||
|
*/
|
||||||
|
private int pageSize = 3;
|
||||||
|
/**
|
||||||
|
* 查询的内容
|
||||||
|
*/
|
||||||
|
private String query;
|
||||||
|
/**
|
||||||
|
* 查询的条件
|
||||||
|
*/
|
||||||
|
private String condition;
|
||||||
|
/**
|
||||||
|
* 借阅证编号
|
||||||
|
*/
|
||||||
|
private String cardNumber;
|
||||||
|
}
|
11
src/main/java/com/book/backend/common/CustomException.java
Normal file
11
src/main/java/com/book/backend/common/CustomException.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.book.backend.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义业务异常类
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
public class CustomException extends RuntimeException{
|
||||||
|
public CustomException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
46
src/main/java/com/book/backend/common/JwtProperties.java
Normal file
46
src/main/java/com/book/backend/common/JwtProperties.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package com.book.backend.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT配置类,读取Application.yml中的配置
|
||||||
|
*
|
||||||
|
* @author AdminMall
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Data
|
||||||
|
public class JwtProperties {
|
||||||
|
/**
|
||||||
|
* JWT存储的请求头
|
||||||
|
*/
|
||||||
|
@Value("${jwt.tokenHeader}")
|
||||||
|
private String tokenHeader;
|
||||||
|
/**
|
||||||
|
* jwt加解密使用的密钥
|
||||||
|
*/
|
||||||
|
@Value("${jwt.secret}")
|
||||||
|
private String secret;
|
||||||
|
/**
|
||||||
|
* JWT的超时时间
|
||||||
|
*/
|
||||||
|
@Value("${jwt.expiration}")
|
||||||
|
private long expiration;
|
||||||
|
|
||||||
|
public JwtProperties() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JWT负载中拿到的开头
|
||||||
|
*/
|
||||||
|
@Value("${jwt.tokenHead}")
|
||||||
|
private String tokenHead;
|
||||||
|
|
||||||
|
public JwtProperties(String tokenHeader, String secret, long expiration, String tokenHead) {
|
||||||
|
this.tokenHeader = tokenHeader;
|
||||||
|
this.secret = secret;
|
||||||
|
this.expiration = expiration;
|
||||||
|
this.tokenHead = tokenHead;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.book.backend.common;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.ibatis.reflection.MetaObject;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义元数据对象处理器
|
||||||
|
* 公共填充功能
|
||||||
|
* MyBatisPlus
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||||
|
/**
|
||||||
|
* 插入操作自动填充
|
||||||
|
* @param metaObject
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void insertFill(MetaObject metaObject) {
|
||||||
|
|
||||||
|
// metaObject.setValue("createTime", LocalDateTime.now());
|
||||||
|
// metaObject.setValue("updateTime",LocalDateTime.now());
|
||||||
|
// MyBatisPlus3.3.0版本后推荐使用strictInsertFill,当字段值为null时,不进行填充
|
||||||
|
this.strictInsertFill(metaObject,"createTime",String.class,
|
||||||
|
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
|
this.strictInsertFill(metaObject,"updateTime",String.class,
|
||||||
|
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新操作自动填充
|
||||||
|
* @param metaObject
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateFill(MetaObject metaObject) {
|
||||||
|
// MyBatisPlus3.3.0版本后推荐使用strictUpdateFill,当字段值为null时,不进行更新
|
||||||
|
// metaObject.setValue("updateTime",LocalDateTime.now());
|
||||||
|
this.strictUpdateFill(metaObject,"updateTime",
|
||||||
|
String.class,LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
|
}
|
||||||
|
}
|
72
src/main/java/com/book/backend/common/R.java
Normal file
72
src/main/java/com/book/backend/common/R.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package com.book.backend.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用返回结果,服务端响应的数据最终都会封装成此对象
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class R<T> {
|
||||||
|
/**
|
||||||
|
* 响应状态码
|
||||||
|
* | 200 | OK | 请求成功
|
||||||
|
* | ---- | --------------------- | ---------------------------------------------------
|
||||||
|
* | 201 | CREATED | 创建成功
|
||||||
|
* | 204 | DELETED | 删除成功
|
||||||
|
* | 400 | BAD REQUEST | 请求的地址不存在或者包含不支持的参数
|
||||||
|
* | 401 | UNAUTHORIZED | 未授权
|
||||||
|
* | 403 | FORBIDDEN | 被禁止访问
|
||||||
|
* | 404 | NOT FOUND | 请求的资源不存在
|
||||||
|
* | 422 | Unprocesable entity | [POST/PUT/PATCH] 当创建一个对象时,发生一个验证错误
|
||||||
|
* | 500 | INTERNAL SERVER ERROR | 内部错误
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 返回给前端的自定义信息
|
||||||
|
*/
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前端发送请求所需要接受到的真实数据
|
||||||
|
*/
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态数据
|
||||||
|
*/
|
||||||
|
private HashMap<String,Object> map = new HashMap<>();
|
||||||
|
|
||||||
|
public static <T> R<T> success(T object,String message) {
|
||||||
|
R<T> r = new R<T>();
|
||||||
|
r.data = object;
|
||||||
|
r.status = 200;
|
||||||
|
r.msg = message;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> R<T> error(String msg) {
|
||||||
|
R<T> r = new R<T>();
|
||||||
|
r.msg = msg;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
public static <T> R<T> error(String msg,int code) {
|
||||||
|
R<T> r = new R<T>();
|
||||||
|
r.msg = msg;
|
||||||
|
r.status = code;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 自定义类型的添加 加入到动态数据HashMap中
|
||||||
|
* @param key string
|
||||||
|
* @param value Object
|
||||||
|
* @return R<T>
|
||||||
|
*/
|
||||||
|
public R<T> add(String key, Object value) {
|
||||||
|
this.map.put(key, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.book.backend.common.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义异常类
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/luoye6">程序员小白条</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BusinessException extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码
|
||||||
|
*/
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
public BusinessException(int code, String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(ErrorCode errorCode) {
|
||||||
|
super(errorCode.getMessage());
|
||||||
|
this.code = errorCode.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BusinessException(ErrorCode errorCode, String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = errorCode.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.book.backend.common.exception;
|
||||||
|
|
||||||
|
public enum CommonError {
|
||||||
|
UNKOWN_ERROR("系统内部错误"),
|
||||||
|
PARAMS_ERROR("非法参数"),
|
||||||
|
OBJECT_NULL("对象为空"),
|
||||||
|
QUERY_NULL("查询结果为空或图书已借出"),
|
||||||
|
REQUEST_NULL("请求参数为空"),
|
||||||
|
USER_NULL("用户为空");
|
||||||
|
private String errMessage;
|
||||||
|
|
||||||
|
public String getErrMessage() {
|
||||||
|
return errMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CommonError( String errMessage) {
|
||||||
|
this.errMessage = errMessage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.book.backend.common.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义错误码
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public enum ErrorCode {
|
||||||
|
|
||||||
|
SUCCESS(0, "ok"),
|
||||||
|
PARAMS_ERROR(40000, "请求参数错误"),
|
||||||
|
NOT_LOGIN_ERROR(40100, "未登录"),
|
||||||
|
NO_AUTH_ERROR(40101, "无权限"),
|
||||||
|
NOT_FOUND_ERROR(40400, "请求数据不存在"),
|
||||||
|
TOO_MANY_REQUEST(42900, "请求过于频繁"),
|
||||||
|
FORBIDDEN_ERROR(40300, "禁止访问"),
|
||||||
|
SYSTEM_ERROR(50000, "系统内部异常"),
|
||||||
|
OPERATION_ERROR(50001, "操作失败");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态码
|
||||||
|
*/
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 信息
|
||||||
|
*/
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
ErrorCode(int code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.book.backend.common.exception;
|
||||||
|
|
||||||
|
import com.book.backend.common.R;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@ExceptionHandler(VueBookException.class)
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public R businessExceptionHandler(VueBookException e) {
|
||||||
|
return R.error(e.getErrMessage(),e.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ResponseBody
|
||||||
|
// @ExceptionHandler(Exception.class)
|
||||||
|
// @ResponseStatus(HttpStatus.OK)
|
||||||
|
// public R runtimeExceptionHandler(Exception e) {
|
||||||
|
// return R.error(CommonError.UNKOWN_ERROR.getErrMessage());
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.book.backend.common.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抛异常工具类
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/luoye6">程序员小白条</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ThrowUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件成立则抛异常
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param runtimeException
|
||||||
|
*/
|
||||||
|
public static void throwIf(boolean condition, RuntimeException runtimeException) {
|
||||||
|
if (condition) {
|
||||||
|
throw runtimeException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件成立则抛异常
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param errorCode
|
||||||
|
*/
|
||||||
|
public static void throwIf(boolean condition, ErrorCode errorCode) {
|
||||||
|
throwIf(condition, new BusinessException(errorCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件成立则抛异常
|
||||||
|
*
|
||||||
|
* @param condition
|
||||||
|
* @param errorCode
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
|
||||||
|
throwIf(condition, new BusinessException(errorCode, message));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.book.backend.common.exception;
|
||||||
|
|
||||||
|
public class VueBookException extends RuntimeException{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 5565760508056698922L;
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
*/
|
||||||
|
private String errMessage;
|
||||||
|
/**
|
||||||
|
* 错误码
|
||||||
|
*/
|
||||||
|
private int code;
|
||||||
|
public VueBookException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public VueBookException(String errMessage) {
|
||||||
|
super(errMessage);
|
||||||
|
this.errMessage = errMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrMessage() {
|
||||||
|
return errMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrMessage(String errMessage) {
|
||||||
|
this.errMessage = errMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
* @param errorCode
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
public VueBookException(ErrorCode errorCode,String message){
|
||||||
|
super(message);
|
||||||
|
this.code = errorCode.getCode();
|
||||||
|
}
|
||||||
|
public VueBookException(ErrorCode errorCode){
|
||||||
|
this.code = errorCode.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cast(CommonError commonError){
|
||||||
|
throw new VueBookException(commonError.getErrMessage());
|
||||||
|
}
|
||||||
|
public static void cast(String errMessage){
|
||||||
|
throw new VueBookException(errMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.book.backend.config;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.ServletRequestEvent;
|
||||||
|
import javax.servlet.ServletRequestListener;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import javax.websocket.HandshakeResponse;
|
||||||
|
import javax.websocket.server.HandshakeRequest;
|
||||||
|
import javax.websocket.server.ServerEndpointConfig;
|
||||||
|
import javax.websocket.server.ServerEndpointConfig.Configurator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从websocket中获取用户session
|
||||||
|
*
|
||||||
|
* @author qimu
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class HttpSessionConfigurator extends Configurator implements ServletRequestListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestInitialized(ServletRequestEvent sre) {
|
||||||
|
HttpSession session = ((HttpServletRequest) sre.getServletRequest()).getSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
|
||||||
|
HttpSession httpSession = (HttpSession) request.getHttpSession();
|
||||||
|
if (httpSession != null) {
|
||||||
|
sec.getUserProperties().put(HttpSession.class.getName(), httpSession);
|
||||||
|
}
|
||||||
|
super.modifyHandshake(sec, request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestDestroyed(ServletRequestEvent arg0) {
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/com/book/backend/config/JsonConfig.java
Normal file
31
src/main/java/com/book/backend/config/JsonConfig.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.book.backend.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import org.springframework.boot.jackson.JsonComponent;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spring MVC Json 配置
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/luoye6">程序员小白条</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@JsonComponent
|
||||||
|
public class JsonConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加 Long 转 json 精度丢失的配置
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||||
|
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
||||||
|
SimpleModule module = new SimpleModule();
|
||||||
|
module.addSerializer(Long.class, ToStringSerializer.instance);
|
||||||
|
module.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
return objectMapper;
|
||||||
|
}
|
||||||
|
}
|
27
src/main/java/com/book/backend/config/MyBatisConfig.java
Normal file
27
src/main/java/com/book/backend/config/MyBatisConfig.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package com.book.backend.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@MapperScan("com.blog.backend.mapper")
|
||||||
|
public class MyBatisConfig {
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor(){
|
||||||
|
//配置分页插件
|
||||||
|
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
|
||||||
|
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
|
||||||
|
return mybatisPlusInterceptor;
|
||||||
|
}
|
||||||
|
// @Bean
|
||||||
|
// public StrategyConfig strategyConfig(){
|
||||||
|
// return new StrategyConfig.Builder().entityBuilder().enableTableFieldAnnotation().build();
|
||||||
|
// }
|
||||||
|
}
|
31
src/main/java/com/book/backend/config/RedisConfig.java
Normal file
31
src/main/java/com/book/backend/config/RedisConfig.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.book.backend.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig {
|
||||||
|
// 因为用到了jsonRedisSerializer,所以要导入jackson依赖
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory){
|
||||||
|
// 创建RedisTemplate对象
|
||||||
|
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||||
|
// 设置连接工厂
|
||||||
|
template.setConnectionFactory(connectionFactory);
|
||||||
|
// 创建JSON序列化工具
|
||||||
|
GenericJackson2JsonRedisSerializer jsonRedisSerializer =
|
||||||
|
new GenericJackson2JsonRedisSerializer();
|
||||||
|
// 设置Key的序列化
|
||||||
|
template.setKeySerializer(RedisSerializer.string());
|
||||||
|
template.setHashKeySerializer(RedisSerializer.string());
|
||||||
|
// 设置Value的序列化
|
||||||
|
template.setValueSerializer(jsonRedisSerializer);
|
||||||
|
template.setHashValueSerializer(jsonRedisSerializer);
|
||||||
|
// 返回
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
}
|
37
src/main/java/com/book/backend/config/RedissonConfig.java
Normal file
37
src/main/java/com/book/backend/config/RedissonConfig.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package com.book.backend.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="https://github.com/luoye6">小白条
|
||||||
|
* @from <a href="https://luoye6.github.io/"> 个人博客
|
||||||
|
*/
|
||||||
|
import lombok.Data;
|
||||||
|
import org.redisson.Redisson;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.redisson.config.Config;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
//@Configuration
|
||||||
|
//@ConfigurationProperties(prefix = "spring.redis")
|
||||||
|
@Data
|
||||||
|
public class RedissonConfig {
|
||||||
|
|
||||||
|
private Integer database;
|
||||||
|
|
||||||
|
private String host;
|
||||||
|
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedissonClient redissonClient() {
|
||||||
|
Config config = new Config();
|
||||||
|
config.useSingleServer()
|
||||||
|
.setDatabase(database)
|
||||||
|
.setAddress("redis://" + host + ":" + port)
|
||||||
|
.setPassword(password);
|
||||||
|
return Redisson.create(config);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.book.backend.config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="https://github.com/luoye6">小白条
|
||||||
|
* @from <a href="https://luoye6.github.io/"> 个人博客
|
||||||
|
*/
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ThreadPoolExecutorConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ThreadPoolExecutor threadPoolExecutor() {
|
||||||
|
ThreadFactory threadFactory = new ThreadFactory() {
|
||||||
|
private int count = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Thread newThread( Runnable r) {
|
||||||
|
Thread thread = new Thread(r);
|
||||||
|
thread.setName("线程" + count);
|
||||||
|
count++;
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new ThreadPoolExecutor(2, 4, 100, TimeUnit.SECONDS,
|
||||||
|
new ArrayBlockingQueue<>(4), threadFactory);
|
||||||
|
}
|
||||||
|
}
|
30
src/main/java/com/book/backend/config/WebMvcConfig.java
Normal file
30
src/main/java/com/book/backend/config/WebMvcConfig.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.book.backend.config;
|
||||||
|
|
||||||
|
import com.book.backend.interceptor.AuthInterceptorHandler;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
//跨域配置
|
||||||
|
registry.addMapping("/**").allowedOriginPatterns("*").allowedMethods("POST","GET","PUT","OPTIONS","DELETE").allowCredentials(true).allowedHeaders("*").maxAge(3600);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
registry.addInterceptor(authInterceptorHandler()).excludePathPatterns("/**/login").excludePathPatterns("/doc.html").excludePathPatterns("/**/websocket");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AuthInterceptorHandler authInterceptorHandler(){
|
||||||
|
return new AuthInterceptorHandler();
|
||||||
|
}
|
||||||
|
}
|
20
src/main/java/com/book/backend/config/WebSocketConfig.java
Normal file
20
src/main/java/com/book/backend/config/WebSocketConfig.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.book.backend.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class WebSocketConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ServerEndpointExporter类的作用是,会扫描所有的服务器端点,
|
||||||
|
* 把带有@ServerEndpoint 注解的所有类都添加进来
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ServerEndpointExporter serverEndpointExporter(){
|
||||||
|
return new ServerEndpointExporter();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/book/backend/constant/ChatConstant.java
Normal file
16
src/main/java/com/book/backend/constant/ChatConstant.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.book.backend.constant;
|
||||||
|
|
||||||
|
|
||||||
|
public interface ChatConstant {
|
||||||
|
/**
|
||||||
|
* 私聊
|
||||||
|
*/
|
||||||
|
int PRIVATE_CHAT = 1;
|
||||||
|
/**
|
||||||
|
* 群聊
|
||||||
|
*/
|
||||||
|
int HALL_CHAT = 2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
58
src/main/java/com/book/backend/constant/Constant.java
Normal file
58
src/main/java/com/book/backend/constant/Constant.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package com.book.backend.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* 常量类
|
||||||
|
* 防止魔法值
|
||||||
|
*/
|
||||||
|
public class Constant {
|
||||||
|
/**
|
||||||
|
* 字符串NULL判断
|
||||||
|
*/
|
||||||
|
public static final String NULL = "null";
|
||||||
|
/**
|
||||||
|
* 预检请求
|
||||||
|
*/
|
||||||
|
public static final String OPTIONS = "OPTIONS";
|
||||||
|
/**
|
||||||
|
* 账号为可用状态
|
||||||
|
*/
|
||||||
|
public static final Integer AVAILABLE = 1;
|
||||||
|
/**
|
||||||
|
* 账号为禁用状态
|
||||||
|
*/
|
||||||
|
public static final Integer DISABLE = 0;
|
||||||
|
/**
|
||||||
|
* 图书已借出状态
|
||||||
|
*/
|
||||||
|
public static final String BOOKDISABLE = "已借出";
|
||||||
|
/**
|
||||||
|
* 图书未借出状态
|
||||||
|
*/
|
||||||
|
public static final String BOOKAVAILABLE = "未借出";
|
||||||
|
/**
|
||||||
|
* 用户可用状态 字符串
|
||||||
|
*/
|
||||||
|
public static final String USERAVAILABLE = "可用";
|
||||||
|
/**
|
||||||
|
* 用户禁用状态 字符串
|
||||||
|
*/
|
||||||
|
public static final String USERDISABLE = "禁用";
|
||||||
|
/**
|
||||||
|
* 密码超过30,判定为md5加密字符
|
||||||
|
*/
|
||||||
|
public static final Integer MD5PASSWORD = 30;
|
||||||
|
/**
|
||||||
|
* 升序
|
||||||
|
*/
|
||||||
|
public static final String SORT_ORDER_ASC = "ascend";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 降序
|
||||||
|
*/
|
||||||
|
public static final String SORT_ORDER_DESC = " descend";
|
||||||
|
/**
|
||||||
|
* BI 模型 id
|
||||||
|
*/
|
||||||
|
public static final long BI_MODEL_ID = 1659171950288818178L;
|
||||||
|
}
|
@ -0,0 +1,414 @@
|
|||||||
|
package com.book.backend.controller.admin;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.book.backend.common.BasePage;
|
||||||
|
import com.book.backend.common.R;
|
||||||
|
import com.book.backend.pojo.*;
|
||||||
|
import com.book.backend.pojo.dto.*;
|
||||||
|
import com.book.backend.pojo.dto.chart.GenChartByAiRequest;
|
||||||
|
import com.book.backend.pojo.vo.BiResponse;
|
||||||
|
import com.book.backend.service.*;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("admin")
|
||||||
|
public class AdminFunctionController {
|
||||||
|
@Resource
|
||||||
|
private BooksService booksService;
|
||||||
|
@Resource
|
||||||
|
private BookTypeService bookTypeService;
|
||||||
|
@Resource
|
||||||
|
private UsersService usersService;
|
||||||
|
@Resource
|
||||||
|
private BookRuleService bookRuleService;
|
||||||
|
@Resource
|
||||||
|
private BookAdminsService bookAdminsService;
|
||||||
|
@Resource
|
||||||
|
private ViolationService violationService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminsService adminsService;
|
||||||
|
@Resource
|
||||||
|
private ChartService chartService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图书列表
|
||||||
|
*
|
||||||
|
* @param basePage 页码,页数,条件和内容
|
||||||
|
* @return R<Page < Books>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_booklist")
|
||||||
|
@ApiOperation("获取图书列表")
|
||||||
|
public R<Page<Books>> getBookList(@RequestBody BasePage basePage) {
|
||||||
|
return booksService.getBookList(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询书籍类型的列表 用于添加图书中回显分类
|
||||||
|
*
|
||||||
|
* @return R<BookType>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_type")
|
||||||
|
@ApiOperation("查询书籍类型列表")
|
||||||
|
public R<List<BookType>> getBookTypeList() {
|
||||||
|
return bookTypeService.getBookTypeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加图书 利用DTO去接受 书籍类别的id 然后再通过id查询分类表获取分类名称 封装给图书
|
||||||
|
*
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("add_book")
|
||||||
|
@ApiOperation("添加图书")
|
||||||
|
public R<String> addBook(@RequestBody BookDTO bookDTO) {
|
||||||
|
return booksService.addBook(bookDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据图书id删除对应的图书
|
||||||
|
*
|
||||||
|
* @param bookId 图书id
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@GetMapping("delete_book/{bookId}")
|
||||||
|
@ApiOperation("根据图书id删除对应的图书")
|
||||||
|
public R<String> deleteBookByBookId(@PathVariable("bookId") Integer bookId) {
|
||||||
|
return booksService.deleteBookByBookId(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据图书id获得相对应的图书信息
|
||||||
|
*
|
||||||
|
* @param bookId 图书id
|
||||||
|
* @return R<Books>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_bookinformation/{bookId}")
|
||||||
|
@ApiOperation("根据图书id获得相对应的图书信息")
|
||||||
|
public R<Books> getBookInformationByBookId(@PathVariable("bookId") Integer bookId) {
|
||||||
|
return booksService.getBookInformationByBookId(bookId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据前端传输的图书信息更新图书
|
||||||
|
*
|
||||||
|
* @param books 图书
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("update_book")
|
||||||
|
@ApiOperation("更新图书")
|
||||||
|
public R<String> updateBookByEditForm(@RequestBody Books books) {
|
||||||
|
return booksService.updateBookByEditForm(books);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 书籍类别 获取书籍类别的列表
|
||||||
|
*
|
||||||
|
* @return R<List < BookType>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_booktype_page")
|
||||||
|
@ApiOperation("获取书籍类别的列表")
|
||||||
|
public R<Page<BookType>> getBookTypeListByPage(@RequestBody BasePage basePage) {
|
||||||
|
return bookTypeService.getBookTypeListByPage(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加书籍类别
|
||||||
|
*
|
||||||
|
* @param bookType 书籍类别
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("add_booktype")
|
||||||
|
@ApiOperation("添加书籍类别")
|
||||||
|
public R<String> addBookType(@RequestBody BookType bookType) {
|
||||||
|
return bookTypeService.addBookType(bookType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据书籍类别id 获取书籍类别信息
|
||||||
|
*
|
||||||
|
* @param typeId 书籍类别id
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@GetMapping("get_booktype/{typeId}")
|
||||||
|
@ApiOperation("获取书籍类别信息")
|
||||||
|
public R<BookType> getBookTypeByTypeId(@PathVariable("typeId") Integer typeId) {
|
||||||
|
return bookTypeService.getBookTypeByTypeId(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新书籍类别
|
||||||
|
*
|
||||||
|
* @param bookType 书籍类别
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("update_booktype")
|
||||||
|
@ApiOperation("更新书籍类别")
|
||||||
|
public R<String> updateBookType(@RequestBody BookType bookType) {
|
||||||
|
return bookTypeService.updateBookType(bookType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除书籍类别 根据书籍类别的ID
|
||||||
|
*
|
||||||
|
* @param typeId 书籍类别的id
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@GetMapping("delete_booktype/{typeId}")
|
||||||
|
@ApiOperation("删除书籍类别")
|
||||||
|
public R<String> deleteBookTypeByTypeId(@PathVariable("typeId") Integer typeId) {
|
||||||
|
return bookTypeService.deleteBookTypeByTypeId(typeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取借阅证列表(用户列表)
|
||||||
|
*
|
||||||
|
* @param basePage 用于接受模糊查询和分页构造的参数
|
||||||
|
* @return R<Page < Users>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_statementlist")
|
||||||
|
@ApiOperation("获取借阅证列表")
|
||||||
|
public R<Page<Users>> getStatementList(@RequestBody BasePage basePage) {
|
||||||
|
return usersService.getStatementList(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加借阅证
|
||||||
|
*
|
||||||
|
* @param usersDTO 用户DTO
|
||||||
|
* @return R<String>
|
||||||
|
*/
|
||||||
|
@PostMapping("add_statement")
|
||||||
|
@ApiOperation("添加借阅证")
|
||||||
|
public R<String> addStatement(@RequestBody UsersDTO usersDTO) {
|
||||||
|
return adminsService.addRule(usersDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息 根据用户id 用于回显借阅证
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return R<UsersDTO>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_statement/{userId}")
|
||||||
|
@ApiOperation("获取用户信息用于回显借阅证")
|
||||||
|
public R<UsersDTO> getStatementByUserId(@PathVariable("userId") Integer userId) {
|
||||||
|
return usersService.getStatementByUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改借阅证信息(用户信息)
|
||||||
|
*
|
||||||
|
* @param usersDTO 用户DTO
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("update_statement")
|
||||||
|
@ApiOperation("修改借阅证信息")
|
||||||
|
public R<String> updateStatement(@RequestBody UsersDTO usersDTO) {
|
||||||
|
return usersService.updateStatement(usersDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除借阅证信息 根据用户id
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@DeleteMapping("delete_statement/{userId}")
|
||||||
|
@ApiOperation("删除借阅证信息")
|
||||||
|
public R<String> deleteStatementByUserId(@PathVariable("userId") Integer userId) {
|
||||||
|
return usersService.deleteStatementByUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取规则列表(分页)
|
||||||
|
*
|
||||||
|
* @param basePage 分页构造器用于接受页数和页码
|
||||||
|
* @return R<Page < BookRule>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_rulelist_page")
|
||||||
|
@ApiOperation("获取规则列表")
|
||||||
|
public R<Page<BookRule>> getRuleListByPage(@RequestBody BasePage basePage) {
|
||||||
|
return bookRuleService.getRuleListByPage(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加规则
|
||||||
|
*
|
||||||
|
* @param bookRule 图书规则
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("add_rule")
|
||||||
|
@ApiOperation("添加规则")
|
||||||
|
public R<String> addRule(@RequestBody BookRule bookRule) {
|
||||||
|
return bookRuleService.addRule(bookRule);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据规则编号 查询规则
|
||||||
|
*
|
||||||
|
* @param ruleId 规则编号
|
||||||
|
* @return R<BookRule>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_rule_ruleid/{ruleId}")
|
||||||
|
@ApiOperation("根据规则编号查询规则")
|
||||||
|
public R<BookRuleDTO> getRuleByRuleId(@PathVariable("ruleId") Integer ruleId) {
|
||||||
|
return bookRuleService.getRuleByRuleId(ruleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改规则
|
||||||
|
*
|
||||||
|
* @param bookRuleDTO 图书规则
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PutMapping("update_rule")
|
||||||
|
@ApiOperation("修改规则")
|
||||||
|
public R<String> updateRule(@RequestBody BookRuleDTO bookRuleDTO) {
|
||||||
|
return bookRuleService.updateRule(bookRuleDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除规则
|
||||||
|
*
|
||||||
|
* @param ruleId 规则编号
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@DeleteMapping("delete_rule/{ruleId}")
|
||||||
|
@ApiOperation("删除规则")
|
||||||
|
public R<String> deleteRule(@PathVariable("ruleId") Integer ruleId) {
|
||||||
|
return bookRuleService.deleteRule(ruleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图书管理员的列表
|
||||||
|
*
|
||||||
|
* @param basePage 分页构造器传参
|
||||||
|
* @return R<Page < BookAdmins>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_bookadminlist")
|
||||||
|
@ApiOperation("获取图书管理员的列表")
|
||||||
|
public R<Page<BookAdmins>> getBookAdminListByPage(@RequestBody BasePage basePage) {
|
||||||
|
return bookAdminsService.getBookAdminListByPage(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加图书管理员
|
||||||
|
*
|
||||||
|
* @param bookAdmins 图书管理员
|
||||||
|
* @return R<String>
|
||||||
|
*/
|
||||||
|
@PostMapping("add_bookadmin")
|
||||||
|
@ApiOperation("添加图书管理员")
|
||||||
|
public R<String> addBookAdmin(@RequestBody BookAdmins bookAdmins) {
|
||||||
|
return bookAdminsService.addBookAdmin(bookAdmins);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图书管理员信息 通过图书管理员id
|
||||||
|
*
|
||||||
|
* @param bookAdminId 图书管理员id
|
||||||
|
* @return R<BookAdmins>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_bookadmin/{bookAdminId}")
|
||||||
|
@ApiOperation("获取图书管理员信息")
|
||||||
|
public R<BookAdmins> getBookAdminById(@PathVariable("bookAdminId") Integer bookAdminId) {
|
||||||
|
return bookAdminsService.getBookAdminById(bookAdminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除图书管理员 根据图书管理员id
|
||||||
|
*
|
||||||
|
* @param bookAdminId 图书管理员id
|
||||||
|
* @return R<String>
|
||||||
|
*/
|
||||||
|
@DeleteMapping("delete_bookadmin/{bookAdminId}")
|
||||||
|
@ApiOperation("删除图书管理员")
|
||||||
|
public R<String> deleteBookAdminById(@PathVariable("bookAdminId") Integer bookAdminId) {
|
||||||
|
return bookAdminsService.deleteBookAdminById(bookAdminId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改图书管理员
|
||||||
|
*
|
||||||
|
* @param bookAdmins 图书管理员
|
||||||
|
* @return R<String>
|
||||||
|
*/
|
||||||
|
@PutMapping("update_bookadmin")
|
||||||
|
@ApiOperation("修改图书管理员")
|
||||||
|
public R<String> updateBookAdmin(@RequestBody BookAdmins bookAdmins) {
|
||||||
|
return bookAdminsService.updateBookAdmin(bookAdmins);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取借阅量
|
||||||
|
*
|
||||||
|
* @return R<BorrowData>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_borrowdata")
|
||||||
|
@ApiOperation("获取借阅量")
|
||||||
|
public R<BorrowData> getBorrowDate() {
|
||||||
|
return violationService.getBorrowDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取借书分类统计情况
|
||||||
|
*
|
||||||
|
* @return R<List < BorrowTypeDTO>>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_borrowtype_statistics")
|
||||||
|
@ApiOperation("获取借书分类统计情况")
|
||||||
|
public R<List<BorrowTypeDTO>> getBorrowTypeStatistic() {
|
||||||
|
return booksService.getBorrowTypeStatistic();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除图书
|
||||||
|
*
|
||||||
|
* @param booksList 图书列表
|
||||||
|
* @return R<String>
|
||||||
|
*/
|
||||||
|
@DeleteMapping("delete_book_batch")
|
||||||
|
@ApiOperation("批量删除图书")
|
||||||
|
public R<String> deleteBookByBatch(@RequestBody List<Books> booksList) {
|
||||||
|
return booksService.deleteBookByBatch(booksList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从Excel批量导入图书
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return R<String>
|
||||||
|
* @throws IOException IO异常
|
||||||
|
*/
|
||||||
|
@PostMapping("/updown")
|
||||||
|
@ApiOperation("从Excel批量导入图书")
|
||||||
|
public R<String> upload(@RequestParam("files") MultipartFile file) throws IOException {
|
||||||
|
return adminsService.upload(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户输入信息,生成图表
|
||||||
|
* @param multipartFile 文件
|
||||||
|
* @param genChartByAiRequest 用户输入信息(分析目标,图标类型,名称),用户id
|
||||||
|
* @return R<BiResponse>
|
||||||
|
*/
|
||||||
|
@PostMapping("/gen")
|
||||||
|
@ApiOperation("根据用户输入信息,生成图表")
|
||||||
|
public R<BiResponse> genChartByAi(@RequestPart("file") MultipartFile multipartFile,
|
||||||
|
GenChartByAiRequest genChartByAiRequest) {
|
||||||
|
return chartService.genChartByAi(multipartFile,genChartByAiRequest);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.book.backend.controller.admin;
|
||||||
|
|
||||||
|
import com.book.backend.common.R;
|
||||||
|
import com.book.backend.pojo.Admins;
|
||||||
|
import com.book.backend.service.AdminsService;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin")
|
||||||
|
public class AdminLoginController {
|
||||||
|
@Resource
|
||||||
|
private AdminsService adminsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统管理员登录
|
||||||
|
* @param users 系统管理员
|
||||||
|
* @return 返回R通用数据
|
||||||
|
*/
|
||||||
|
@PostMapping("/login")
|
||||||
|
@ApiOperation("管理员登录")
|
||||||
|
public R login(@RequestBody Admins users){
|
||||||
|
return adminsService.login(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回给前端系统管理员的数据
|
||||||
|
* @param admin 系统管理员
|
||||||
|
* @return R<Admins>
|
||||||
|
*/
|
||||||
|
@PostMapping ("/getData")
|
||||||
|
@ApiOperation("获取管理员数据")
|
||||||
|
public R<Admins> getUserData(@RequestBody Admins admin){
|
||||||
|
return adminsService.getUserData(admin);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,165 @@
|
|||||||
|
package com.book.backend.controller.bookadmin;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.book.backend.common.BasePage;
|
||||||
|
import com.book.backend.common.R;
|
||||||
|
import com.book.backend.pojo.BooksBorrow;
|
||||||
|
import com.book.backend.pojo.Notice;
|
||||||
|
import com.book.backend.pojo.Violation;
|
||||||
|
import com.book.backend.pojo.dto.BooksBorrowDTO;
|
||||||
|
import com.book.backend.pojo.dto.ViolationDTO;
|
||||||
|
import com.book.backend.service.*;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/bookadmin")
|
||||||
|
public class BookAdminFunctionController {
|
||||||
|
@Resource
|
||||||
|
private BookAdminsService bookAdminsService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BooksService booksService;
|
||||||
|
@Resource
|
||||||
|
private BooksBorrowService booksBorrowService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NoticeService noticeService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅图书根据借阅证号和图书编号
|
||||||
|
*
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("borrow_book")
|
||||||
|
@ApiOperation("根据借阅证号和图书编号借阅图书")
|
||||||
|
public R<String> borrowBookByCardNumberAndBookNumber(@RequestBody BooksBorrowDTO booksBorrowDTO) {
|
||||||
|
return booksService.borrowBookByCardNumberAndBookNumber(booksBorrowDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看图书是否有逾期(查看是否借出)
|
||||||
|
*
|
||||||
|
* @param bookNumber 图书编号
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@GetMapping("query_book/{bookNumber}")
|
||||||
|
@ApiOperation("查看图书是否有逾期")
|
||||||
|
public R<String> queryBookExpireByBookNumber(@PathVariable("bookNumber") Long bookNumber) {
|
||||||
|
return booksService.queryBookExpireByBookNumber(bookNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图书逾期信息
|
||||||
|
*
|
||||||
|
* @param bookNumber 图书编号
|
||||||
|
* @return R<Violation>
|
||||||
|
*/
|
||||||
|
@GetMapping("query_expire/{bookNumber}")
|
||||||
|
@ApiOperation("获取图书逾期信息")
|
||||||
|
public R<ViolationDTO> queryExpireInformationByBookNumber(@PathVariable("bookNumber") Long bookNumber) {
|
||||||
|
return booksBorrowService.queryExpireInformationByBookNumber(bookNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归还图书
|
||||||
|
*
|
||||||
|
* @param violation 违章表
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("return_book")
|
||||||
|
@ApiOperation("归还图书")
|
||||||
|
public R<String> returnBook(@RequestBody Violation violation) {
|
||||||
|
return booksBorrowService.returnBook(violation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取还书报表
|
||||||
|
*
|
||||||
|
* @param basePage 接受分页构造器和模糊查询的传参
|
||||||
|
* @return R<Page < BooksBorrow>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_return_statement")
|
||||||
|
@ApiOperation("获取还书报表")
|
||||||
|
public R<Page<BooksBorrow>> getReturnStatement(@RequestBody BasePage basePage) {
|
||||||
|
return booksBorrowService.getReturnStatement(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取借书报表
|
||||||
|
*
|
||||||
|
* @param basePage 接受分页构造器和模糊查询的传参
|
||||||
|
* @return R<Page < ViolationDTO>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_borrow_statement")
|
||||||
|
@ApiOperation("获取借书报表")
|
||||||
|
public R<Page<ViolationDTO>> getBorrowStatement(@RequestBody BasePage basePage) {
|
||||||
|
return bookAdminsService.getBorrowStatement(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取公告列表
|
||||||
|
*
|
||||||
|
* @return R<Notice>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_noticelist")
|
||||||
|
@ApiOperation("获取公告列表")
|
||||||
|
public R<Page<Notice>> getNoticeList(@RequestBody BasePage basePage) {
|
||||||
|
return noticeService.getNoticeList(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加公告
|
||||||
|
*
|
||||||
|
* @param notice 公告
|
||||||
|
* @return R<String>
|
||||||
|
*/
|
||||||
|
@PostMapping("add_notice")
|
||||||
|
@ApiOperation("添加公告")
|
||||||
|
public R<String> addNotice(@RequestBody Notice notice) {
|
||||||
|
return noticeService.addNotice(notice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除公告根据指定的id
|
||||||
|
*
|
||||||
|
* @param noticeId 公告id
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@GetMapping("delete_notice/{noticeId}")
|
||||||
|
@ApiOperation("删除公告根据指定的id")
|
||||||
|
public R<String> deleteNoticeById(@PathVariable("noticeId") Integer noticeId) {
|
||||||
|
return noticeService.deleteNoticeById(noticeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据指定id获取公告
|
||||||
|
*
|
||||||
|
* @param noticeId 公告id
|
||||||
|
* @return R<Notice>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_notice/{noticeId}")
|
||||||
|
@ApiOperation("根据指定id获取公告")
|
||||||
|
public R<Notice> getNoticeByNoticeId(@PathVariable("noticeId") Integer noticeId) {
|
||||||
|
return noticeService.getNoticeByNoticeId(noticeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新公告根据公告id
|
||||||
|
*
|
||||||
|
* @param noticeId 公告id
|
||||||
|
* @param notice 公告
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PutMapping("update_notice/{noticeId}")
|
||||||
|
@ApiOperation("更新公告根据公告id")
|
||||||
|
public R<String> updateNoticeByNoticeId(@PathVariable("noticeId") Integer noticeId, @RequestBody Notice notice) {
|
||||||
|
return noticeService.updateNoticeByNoticeId(noticeId, notice);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.book.backend.controller.bookadmin;
|
||||||
|
|
||||||
|
import com.book.backend.common.R;
|
||||||
|
import com.book.backend.pojo.BookAdmins;
|
||||||
|
import com.book.backend.service.BookAdminsService;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/bookadmin")
|
||||||
|
public class BookAdminLoginController {
|
||||||
|
@Resource
|
||||||
|
private BookAdminsService bookAdminsService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书管理员登录
|
||||||
|
*
|
||||||
|
* @param users 图书管理员
|
||||||
|
* @return 返回R通用数据
|
||||||
|
*/
|
||||||
|
@PostMapping("/login")
|
||||||
|
@ApiOperation("图书管理员登录")
|
||||||
|
public R login(@RequestBody BookAdmins users) {
|
||||||
|
return bookAdminsService.login(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回给前端图书管理员的数据
|
||||||
|
*
|
||||||
|
* @param bookAdmins 图书管理员
|
||||||
|
* @return R<BookAdmins>
|
||||||
|
*/
|
||||||
|
@PostMapping("/getData")
|
||||||
|
@ApiOperation("获取图书管理员数据")
|
||||||
|
public R<BookAdmins> getUserData(@RequestBody BookAdmins bookAdmins) {
|
||||||
|
return bookAdminsService.getUserData(bookAdmins);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,165 @@
|
|||||||
|
package com.book.backend.controller.user;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.book.backend.common.BasePage;
|
||||||
|
import com.book.backend.common.R;
|
||||||
|
import com.book.backend.pojo.*;
|
||||||
|
import com.book.backend.pojo.dto.CommentDTO;
|
||||||
|
import com.book.backend.pojo.dto.ViolationDTO;
|
||||||
|
import com.book.backend.service.*;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserFunctionController {
|
||||||
|
@Resource
|
||||||
|
private BooksService booksService;
|
||||||
|
@Resource
|
||||||
|
private BookRuleService bookRuleService;
|
||||||
|
@Resource
|
||||||
|
private NoticeService noticeService;
|
||||||
|
@Resource
|
||||||
|
private UsersService usersService;
|
||||||
|
@Resource
|
||||||
|
private BooksBorrowService booksBorrowService;
|
||||||
|
@Resource
|
||||||
|
private ViolationService violationService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CommentService commentService;
|
||||||
|
@Resource
|
||||||
|
private AiIntelligentService aiIntelligentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书查询 分页和条件查询 (模糊查询)
|
||||||
|
*
|
||||||
|
* @param basePage 用于接受分页传参
|
||||||
|
* @return R<Page < Books>>
|
||||||
|
*/
|
||||||
|
@PostMapping("/search_book_page")
|
||||||
|
@ApiOperation("图书查询 分页和条件查询")
|
||||||
|
public R<Page<Books>> searchBookPage(@RequestBody BasePage basePage) {
|
||||||
|
return booksService.searchBookPage(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读者规则查询
|
||||||
|
*
|
||||||
|
* @return R<List < BookRule>>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_rulelist")
|
||||||
|
@ApiOperation("读者规则查询")
|
||||||
|
public R<List<BookRule>> getRuleList() {
|
||||||
|
return bookRuleService.getRuleList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询公告信息
|
||||||
|
*
|
||||||
|
* @return R<List < Notice>>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_noticelist")
|
||||||
|
@ApiOperation("查询公告信息")
|
||||||
|
public R<List<Notice>> getNoticeList() {
|
||||||
|
return noticeService.getNoticeList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rest接受参数 查询个人用户userId
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return R<Users>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_information/{userId}")
|
||||||
|
@ApiOperation("查询个人用户")
|
||||||
|
public R<Users> getUserByUserId(@PathVariable("userId") Integer userId) {
|
||||||
|
return usersService.getUserByUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
*
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("update_password")
|
||||||
|
@ApiOperation("修改密码")
|
||||||
|
public R<String> updatePassword(@RequestBody Users users) {
|
||||||
|
return usersService.updatePassword(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅信息查询 根据用户id,条件及其内容
|
||||||
|
*
|
||||||
|
* @param basePage 用于接受分页传参和用户id
|
||||||
|
* @return R<Page < BooksBorrow>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_bookborrow")
|
||||||
|
@ApiOperation("借阅信息查询")
|
||||||
|
public R<Page<BooksBorrow>> getBookBorrowPage(@RequestBody BasePage basePage) {
|
||||||
|
return booksBorrowService.getBookBorrowPage(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询违章信息(借阅证)
|
||||||
|
*
|
||||||
|
* @param basePage 获取前端的分页参数,条件和内容,借阅证
|
||||||
|
* @return R<Page < ViolationDTO>>
|
||||||
|
*/
|
||||||
|
@PostMapping("get_violation")
|
||||||
|
@ApiOperation("查询违章信息")
|
||||||
|
public R<Page<ViolationDTO>> getViolationListByPage(@RequestBody BasePage basePage) {
|
||||||
|
return violationService.getViolationListByPage(basePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取弹幕列表
|
||||||
|
*
|
||||||
|
* @return R<Comment>
|
||||||
|
*/
|
||||||
|
@GetMapping("get_commentlist")
|
||||||
|
@ApiOperation("获取弹幕列表")
|
||||||
|
public R<List<CommentDTO>> getCommentList() {
|
||||||
|
return commentService.getCommentList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加弹幕
|
||||||
|
*
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
@PostMapping("add_comment")
|
||||||
|
@ApiOperation("添加弹幕")
|
||||||
|
public R<String> addComment(@RequestBody CommentDTO commentDTO) {
|
||||||
|
return commentService.addComment(commentDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用AI模型,获取数据库中有的,并且推荐图书给用户
|
||||||
|
* @param aiIntelligent AI实体类
|
||||||
|
* @return R<String>
|
||||||
|
*/
|
||||||
|
@PostMapping("ai_intelligent")
|
||||||
|
@ApiOperation("推荐图书")
|
||||||
|
public R<String> aiRecommend(@RequestBody AiIntelligent aiIntelligent){
|
||||||
|
return aiIntelligentService.getGenResult(aiIntelligent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户ID 获取该用户和AI聊天的最近的五条消息
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return R<List<AiIntelligent>>
|
||||||
|
*/
|
||||||
|
@GetMapping("ai_list_information/{userId}")
|
||||||
|
@ApiOperation("获取该用户和AI聊天的最近的五条消息")
|
||||||
|
public R<List<AiIntelligent>> getAiInformationByUserId(@PathVariable("userId") Long userId){
|
||||||
|
return aiIntelligentService.getAiInformationByUserId(userId);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.book.backend.controller.user;
|
||||||
|
|
||||||
|
import com.book.backend.common.R;
|
||||||
|
import com.book.backend.pojo.Users;
|
||||||
|
import com.book.backend.service.UsersService;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserLoginController {
|
||||||
|
@Resource
|
||||||
|
private UsersService usersService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅用户登录
|
||||||
|
*
|
||||||
|
* @param users 借阅者用户
|
||||||
|
* @return 返回R通用数据
|
||||||
|
*/
|
||||||
|
@PostMapping("/login")
|
||||||
|
@ApiOperation("用户登录")
|
||||||
|
public R login(@RequestBody Users users) {
|
||||||
|
return usersService.login(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户id传给用户所需的信息
|
||||||
|
*
|
||||||
|
* @param users 用户
|
||||||
|
* @return R<Users>
|
||||||
|
*/
|
||||||
|
@PostMapping("/getData")
|
||||||
|
@ApiOperation("获取用户数据")
|
||||||
|
public R<Users> getUserData(@RequestBody Users users) {
|
||||||
|
return usersService.getUserData(users);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
package com.book.backend.interceptor;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.book.backend.constant.Constant;
|
||||||
|
import com.book.backend.common.JwtProperties;
|
||||||
|
import com.book.backend.utils.JwtKit;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
*/
|
||||||
|
public class AuthInterceptorHandler implements HandlerInterceptor {
|
||||||
|
@Autowired
|
||||||
|
private JwtProperties jwtProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JwtKit jwtKit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前置拦截器
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||||
|
|
||||||
|
if(!(handler instanceof HandlerMethod)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
HandlerMethod handlerMethod=(HandlerMethod)handler;
|
||||||
|
//判断如果请求的类是swagger的控制器,直接通行。
|
||||||
|
if(("springfox.documentation.swagger.web.ApiResourceController").equals(handlerMethod.getBean().getClass().getName())){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((Constant.OPTIONS).equals(request.getMethod())) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 获取到JWT的Token
|
||||||
|
String jwtToken = request.getHeader(jwtProperties.getTokenHeader());
|
||||||
|
// 截取中间payload部分 +1是Bearer + 空格(1)
|
||||||
|
String payloadToken = null;
|
||||||
|
// 创建json对象
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
|
||||||
|
if (jwtToken != null) {
|
||||||
|
payloadToken = jwtToken.substring(jwtProperties.getTokenHead().length() + 1);
|
||||||
|
}
|
||||||
|
if (payloadToken != null && (!(Constant.NULL).equals(payloadToken))) {
|
||||||
|
// 解析Token,获取Claims = Map
|
||||||
|
Claims claims = null;
|
||||||
|
try {
|
||||||
|
claims = jwtKit.parseJwtToken(payloadToken);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//token过期会捕捉到异常
|
||||||
|
jsonObject.put("status", 401);
|
||||||
|
jsonObject.put("msg", "登录过期,请重新登录");
|
||||||
|
String json1 = jsonObject.toJSONString();
|
||||||
|
renderJson(response, json1);
|
||||||
|
}
|
||||||
|
return claims != null;
|
||||||
|
// 获取payload中的报文,
|
||||||
|
}
|
||||||
|
// 如果token不存在
|
||||||
|
jsonObject.put("status", 401);
|
||||||
|
jsonObject.put("msg", "登录非法");
|
||||||
|
String json2 = jsonObject.toJSONString();
|
||||||
|
renderJson(response, json2);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderJson(HttpServletResponse response, String json) {
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setContentType("application/json;charset=UTF-8");
|
||||||
|
try (PrintWriter printWriter = response.getWriter()) {
|
||||||
|
printWriter.print(json);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.book.backend.job.cycle;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Comment;
|
||||||
|
import com.book.backend.pojo.dto.CommentDTO;
|
||||||
|
import com.book.backend.service.CommentService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="https://github.com/luoye6">小白条
|
||||||
|
* @from <a href="https://luoye6.github.io/"> 个人博客
|
||||||
|
*/
|
||||||
|
// todo 取消 @Component 注释开启任务
|
||||||
|
// 程序启动时执行一次,然后每隔1天自动执行定时任务
|
||||||
|
//@Component
|
||||||
|
@EnableScheduling
|
||||||
|
@Slf4j
|
||||||
|
public class ConvertCommentListToRedis {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CommentService commentService;
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
public ConvertCommentListToRedis() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每天凌晨三点将数据库中的留言列表转到 Redis
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 3 * * ?")
|
||||||
|
public void run() {
|
||||||
|
log.info("准备将数据库中的留言列表转移到Redis");
|
||||||
|
LocalDate localDate = LocalDate.now();
|
||||||
|
String key = "comment:"+localDate;
|
||||||
|
List<Comment> list = commentService.list();
|
||||||
|
List<CommentDTO> commentDTOList = list.stream().map((item) -> {
|
||||||
|
CommentDTO commentDTO = new CommentDTO();
|
||||||
|
commentDTO.setAvatar(item.getCommentAvatar());
|
||||||
|
commentDTO.setId(item.getCommentId());
|
||||||
|
commentDTO.setMsg(item.getCommentMessage());
|
||||||
|
commentDTO.setTime(item.getCommentTime());
|
||||||
|
commentDTO.setBarrageStyle(item.getCommentBarrageStyle());
|
||||||
|
return commentDTO;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
redisTemplate.opsForList().rightPushAll(key,commentDTOList);
|
||||||
|
redisTemplate.expire(key,7, TimeUnit.DAYS);
|
||||||
|
log.info("留言列表成功转移到Redis");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package com.book.backend.job.cycle;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.book.backend.common.exception.BusinessException;
|
||||||
|
import com.book.backend.common.exception.ErrorCode;
|
||||||
|
import com.book.backend.pojo.AiIntelligent;
|
||||||
|
import com.book.backend.pojo.UserInterfaceInfo;
|
||||||
|
import com.book.backend.pojo.Users;
|
||||||
|
import com.book.backend.service.AiIntelligentService;
|
||||||
|
import com.book.backend.service.UserInterfaceInfoService;
|
||||||
|
import com.book.backend.service.UsersService;
|
||||||
|
import com.book.backend.service.impl.UserInterfaceInfoServiceImpl;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户调用AI模型的无效回复
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/luoye6">程序员小白条</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
// todo 取消 @Component 注释开启任务
|
||||||
|
// 程序启动时执行一次,然后每隔1天自动执行定时任务
|
||||||
|
//@Component
|
||||||
|
@EnableScheduling
|
||||||
|
@Slf4j
|
||||||
|
public class IncSyncDeleteAIMessage {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AiIntelligentService aiIntelligentService;
|
||||||
|
@Resource
|
||||||
|
private UserInterfaceInfoService userInterfaceInfoService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每天执行一次
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Scheduled(fixedRate = 60 * 60 * 24 * 1000)
|
||||||
|
public void run() {
|
||||||
|
log.info("正在查询无效的AI回复数据");
|
||||||
|
// 查询无效的数据,并进行删除操作
|
||||||
|
LambdaQueryWrapper<AiIntelligent> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.isNull(AiIntelligent::getAiResult).or().eq(AiIntelligent::getAiResult, "");
|
||||||
|
List<AiIntelligent> list = aiIntelligentService.list(queryWrapper);
|
||||||
|
// 先为用户恢复次数
|
||||||
|
log.info("正在为用户恢复次数");
|
||||||
|
list.forEach(item -> {
|
||||||
|
Long userId = item.getUserId();
|
||||||
|
UserInterfaceInfo user = userInterfaceInfoService.getById(userId);
|
||||||
|
synchronized (IncSyncDeleteAIMessage.class) {
|
||||||
|
// 用户恢复次数
|
||||||
|
if (user != null) {
|
||||||
|
user.setLeftNum(user.getLeftNum() + 1);
|
||||||
|
boolean save = userInterfaceInfoService.save(user);
|
||||||
|
if (!save) {
|
||||||
|
log.info("定时任务执行失败");
|
||||||
|
throw new BusinessException(ErrorCode.OPERATION_ERROR, "操作定时任务失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 将无效的记录删除
|
||||||
|
log.info("正在删除无效的AI回复记录");
|
||||||
|
boolean remove = false;
|
||||||
|
try {
|
||||||
|
remove = aiIntelligentService.remove(queryWrapper);
|
||||||
|
if (!remove) {
|
||||||
|
log.info("未发现无效的AI回复记录");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("定时任务执行失败");
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
log.info("定时任务执行成功,删除无效的AI的结果集:"+list.size()+"个");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.book.backend.job.once;
|
||||||
|
|
||||||
|
import com.alibaba.excel.EasyExcel;
|
||||||
|
import com.alibaba.excel.context.AnalysisContext;
|
||||||
|
import com.alibaba.excel.event.AnalysisEventListener;
|
||||||
|
import com.book.backend.pojo.Books;
|
||||||
|
import com.book.backend.pojo.dto.BookData;
|
||||||
|
import com.book.backend.service.BooksService;
|
||||||
|
import com.book.backend.utils.NumberUtil;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="https://github.com/luoye6">小白条
|
||||||
|
* @from <a href="https://luoye6.github.io/"> 个人博客
|
||||||
|
*/
|
||||||
|
// 取消注释后,每次执行springboot项目,都会执行一次run方法
|
||||||
|
//@Component
|
||||||
|
public class EasyExcelBatchImportBookList implements CommandLineRunner {
|
||||||
|
@Resource
|
||||||
|
private BooksService booksService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String... args) throws Exception {
|
||||||
|
// 读取的excel文件路径
|
||||||
|
String filename = "D:\\IDEAproject\\vue_book_backend\\src\\main\\resources\\test_excel.xlsx";
|
||||||
|
// 读取excel
|
||||||
|
EasyExcel.read(filename, BookData.class, new AnalysisEventListener<BookData>() {
|
||||||
|
ArrayList<Books> booksList = new ArrayList<>();
|
||||||
|
// 每解析一行数据,该方法会被调用一次
|
||||||
|
@Override
|
||||||
|
public void invoke(BookData bookData, AnalysisContext analysisContext) {
|
||||||
|
Books books = new Books();
|
||||||
|
// 生成11位数字的图书编号
|
||||||
|
StringBuilder stringBuilder = NumberUtil.getNumber(11);
|
||||||
|
long bookNumber = Long.parseLong(new String(stringBuilder));
|
||||||
|
BeanUtils.copyProperties(bookData,books);
|
||||||
|
books.setBookNumber(bookNumber);
|
||||||
|
booksList.add(books);
|
||||||
|
// System.out.println("解析数据为:" + bookData.toString());
|
||||||
|
}
|
||||||
|
// 全部解析完成被调用
|
||||||
|
@Override
|
||||||
|
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||||
|
// 全部加入到容器list中后,一次性批量导入,先判断容器是否为空
|
||||||
|
if(!booksList.isEmpty()){
|
||||||
|
// 可以将解析的数据保存到数据库
|
||||||
|
boolean flag = booksService.saveBatch(booksList);
|
||||||
|
// 如果数据添加成功
|
||||||
|
if(flag){
|
||||||
|
System.out.println("Excel批量添加图书成功");
|
||||||
|
}else{
|
||||||
|
System.out.println("Excel批量添加图书失败");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
System.out.println("空表无法进行数据导入");
|
||||||
|
}
|
||||||
|
System.out.println("解析完成...");
|
||||||
|
|
||||||
|
}
|
||||||
|
}).sheet().doRead();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.book.backend.job.once;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.book.backend.pojo.Books;
|
||||||
|
import com.book.backend.service.BooksService;
|
||||||
|
import com.book.backend.utils.NumberUtil;
|
||||||
|
import com.book.backend.utils.RandomNameUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="https://github.com/luoye6">小白条
|
||||||
|
* @from <a href="https://luoye6.github.io/"> 个人博客
|
||||||
|
*/
|
||||||
|
// 取消注释后,每次执行springboot项目,都会执行一次run方法
|
||||||
|
//@Component
|
||||||
|
@Slf4j
|
||||||
|
public class FetchInitBookList implements CommandLineRunner {
|
||||||
|
@Resource
|
||||||
|
private BooksService booksService;
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@Override
|
||||||
|
public void run(String... args) throws Exception {
|
||||||
|
String[] bookLibraries = {"南图", "北图", "教师之家"};
|
||||||
|
String url = "https://api.ituring.com.cn/api/Search/Advanced";
|
||||||
|
// 可以手动修改page来改变获取不同的图书
|
||||||
|
String json = "{\n" +
|
||||||
|
" \"categoryId\": 1,\n" +
|
||||||
|
" \"sort\": \"new\",\n" +
|
||||||
|
" \"page\": 1,\n" +
|
||||||
|
" \"name\": \"\",\n" +
|
||||||
|
" \"edition\": 1\n" +
|
||||||
|
"}";
|
||||||
|
String result2 = HttpRequest.post(url)
|
||||||
|
.body(json)
|
||||||
|
.execute().body();
|
||||||
|
Map<String, Object> map = JSONUtil.toBean(result2, Map.class);
|
||||||
|
JSONArray bookItems = (JSONArray) map.get("bookItems");
|
||||||
|
List<Books> booksList = new ArrayList<>();
|
||||||
|
for (Object record : bookItems) {
|
||||||
|
int randomLibrary = NumberUtil.getLibraryInt();
|
||||||
|
JSONObject tempRecord = (JSONObject) record;
|
||||||
|
Books books = new Books();
|
||||||
|
// 生成11位数字的图书编号
|
||||||
|
StringBuilder stringNumber = NumberUtil.getNumber(11);
|
||||||
|
long bookNumber = Long.parseLong(new String(stringNumber));
|
||||||
|
String bookName = tempRecord.getStr("name");
|
||||||
|
String author = tempRecord.getStr("translatorNameString");
|
||||||
|
String bookDescription = tempRecord.getStr("abstract");
|
||||||
|
if(bookDescription.length()>=255){
|
||||||
|
bookDescription = bookDescription.substring(0,254);
|
||||||
|
}
|
||||||
|
books.setBookNumber(bookNumber);
|
||||||
|
books.setBookName(bookName);
|
||||||
|
books.setBookAuthor(author);
|
||||||
|
books.setBookLibrary(bookLibraries[randomLibrary]);
|
||||||
|
books.setBookType("计算机");
|
||||||
|
String location = RandomNameUtils.getRandomLocation();
|
||||||
|
books.setBookLocation(location);
|
||||||
|
books.setBookStatus("未借出");
|
||||||
|
books.setBookDescription(bookDescription);
|
||||||
|
booksList.add(books);
|
||||||
|
}
|
||||||
|
boolean b = booksService.saveBatch(booksList);
|
||||||
|
if(b){
|
||||||
|
log.info("批量添加图书成功,成功插入的条数为:{}",booksList.size());
|
||||||
|
}else{
|
||||||
|
log.error("批量添加图书失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
src/main/java/com/book/backend/manager/AiManager.java
Normal file
39
src/main/java/com/book/backend/manager/AiManager.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package com.book.backend.manager;
|
||||||
|
|
||||||
|
import com.book.backend.common.exception.BusinessException;
|
||||||
|
import com.book.backend.common.exception.ErrorCode;
|
||||||
|
import com.yupi.yucongming.dev.client.YuCongMingClient;
|
||||||
|
import com.yupi.yucongming.dev.common.BaseResponse;
|
||||||
|
import com.yupi.yucongming.dev.model.DevChatRequest;
|
||||||
|
import com.yupi.yucongming.dev.model.DevChatResponse;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于对接 AI 平台
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class AiManager {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI 对话
|
||||||
|
*
|
||||||
|
* @param modelId
|
||||||
|
* @param message
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String doChat(long modelId, String message) {
|
||||||
|
DevChatRequest devChatRequest = new DevChatRequest();
|
||||||
|
devChatRequest.setModelId(modelId);
|
||||||
|
devChatRequest.setMessage(message);
|
||||||
|
YuCongMingClient yuCongMingClient = new YuCongMingClient("xxxxxxxx", "xxxxxx");
|
||||||
|
BaseResponse<DevChatResponse> response = yuCongMingClient.doChat(devChatRequest);
|
||||||
|
if (response == null) {
|
||||||
|
throw new BusinessException(ErrorCode.SYSTEM_ERROR, "AI 响应错误");
|
||||||
|
}
|
||||||
|
return response.getData().getContent();
|
||||||
|
}
|
||||||
|
}
|
79
src/main/java/com/book/backend/manager/AiPost.java
Normal file
79
src/main/java/com/book/backend/manager/AiPost.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package com.book.backend.manager;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpResponse;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AiPost {
|
||||||
|
|
||||||
|
private static final String baseUrl = "https://openai.933999.xyz";
|
||||||
|
private static final String apiKey = "sk-1PBIyxIdJ42yyC11XRNqbEXYDt2eZRNVNbd8XxmKjnPXGh5S";
|
||||||
|
private static final String model = "gpt-4o-mini";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送消息并获取AI响应
|
||||||
|
* @param message 用户消息
|
||||||
|
* @param maxTokens 最大token数
|
||||||
|
* @return AI响应内容
|
||||||
|
* @throws Exception 发送请求异常
|
||||||
|
*/
|
||||||
|
public String sendMessageAndGetResponse(String message, int maxTokens) throws Exception {
|
||||||
|
// 构造 messages 数组
|
||||||
|
JSONArray messagesArray = new JSONArray();
|
||||||
|
JSONObject userMessage = new JSONObject();
|
||||||
|
userMessage.put("role", "user");
|
||||||
|
userMessage.put("content", message);
|
||||||
|
messagesArray.add(userMessage);
|
||||||
|
|
||||||
|
// 构造请求体
|
||||||
|
JSONObject requestBody = new JSONObject();
|
||||||
|
requestBody.put("model", model);
|
||||||
|
requestBody.put("messages", messagesArray);
|
||||||
|
// requestBody.put("max_tokens", maxTokens);
|
||||||
|
// requestBody.put("temperature", 0.2); // 更稳定输出
|
||||||
|
|
||||||
|
// 打印请求体
|
||||||
|
System.out.println("请求地址:" + baseUrl + "/v1/chat/completions");
|
||||||
|
System.out.println("请求体:" + requestBody.toStringPretty());
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpResponse response = HttpRequest.post(baseUrl + "/v1/chat/completions")
|
||||||
|
.timeout(60_000) // 60秒超时
|
||||||
|
.header("Authorization", "Bearer " + apiKey)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.body(requestBody.toString())
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
String responseText = response.body();
|
||||||
|
|
||||||
|
System.out.println("响应状态码:" + response.getStatus());
|
||||||
|
System.out.println("响应内容:" + responseText);
|
||||||
|
|
||||||
|
if (response.getStatus() != 200) {
|
||||||
|
throw new RuntimeException("AI服务请求失败:" + responseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 安全解析响应
|
||||||
|
if (!JSONUtil.isJsonObj(responseText)) {
|
||||||
|
throw new RuntimeException("返回不是合法JSON:" + responseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject responseJson = JSONUtil.parseObj(responseText);
|
||||||
|
JSONArray choices = responseJson.getJSONArray("choices");
|
||||||
|
|
||||||
|
if (choices == null || choices.isEmpty()) {
|
||||||
|
throw new RuntimeException("AI响应为空:" + responseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject messageObj = choices.getJSONObject(0).getJSONObject("message");
|
||||||
|
return messageObj.getStr("content");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("调用AI接口发生错误", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
84
src/main/java/com/book/backend/manager/AlibabaAIModel.java
Normal file
84
src/main/java/com/book/backend/manager/AlibabaAIModel.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package com.book.backend.manager;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.StopWatch;
|
||||||
|
import com.aliyun.broadscope.bailian.sdk.AccessTokenClient;
|
||||||
|
import com.aliyun.broadscope.bailian.sdk.ApplicationClient;
|
||||||
|
import com.aliyun.broadscope.bailian.sdk.models.BaiLianConfig;
|
||||||
|
import com.aliyun.broadscope.bailian.sdk.models.CompletionsRequest;
|
||||||
|
import com.aliyun.broadscope.bailian.sdk.models.CompletionsResponse;
|
||||||
|
import com.aliyun.broadscope.bailian.sdk.utils.UUIDGenerator;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里AI模型 通义千问-Plus 工具类
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/luoye6">小白条
|
||||||
|
* @from <a href="https://luoye6.github.io/"> 个人博客
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class AlibabaAIModel {
|
||||||
|
// todo 替换你自己的密钥 阿里百炼官网:https://account.aliyun.com/login/login.html
|
||||||
|
public static final String accessKeyId = "xxxx";
|
||||||
|
public static final String accessKeySecret = "xxxxxx";
|
||||||
|
public static final String agentKey = "xxxxx";
|
||||||
|
public static final String appId = "xxxxx";
|
||||||
|
/**
|
||||||
|
* 阿里云百炼也支持调用侧自己维护上下文对话历史, 同时传入sessionId和history,会优先采用调用侧传入的上下文历史
|
||||||
|
* CompletionsRequest.ChatQaPair chatQaPair = new CompletionsRequest.ChatQaPair("我想去北京", "北京的天气很不错");
|
||||||
|
* CompletionsRequest.ChatQaPair chatQaPair2 = new CompletionsRequest.ChatQaPair("北京有哪些景点", "北京有故宫、长城等");
|
||||||
|
* history.add(chatQaPair);
|
||||||
|
* history.add(chatQaPair2);
|
||||||
|
* request.setHistory(history);
|
||||||
|
*/
|
||||||
|
public static final List<CompletionsRequest.ChatQaPair> history = new ArrayList<>();
|
||||||
|
|
||||||
|
public static String doChatOnce(String prompt) {
|
||||||
|
log.info("进入AI对话");
|
||||||
|
AccessTokenClient accessTokenClient = new AccessTokenClient(accessKeyId, accessKeySecret, agentKey);
|
||||||
|
String token = accessTokenClient.getToken();
|
||||||
|
|
||||||
|
BaiLianConfig config = new BaiLianConfig()
|
||||||
|
.setApiKey(token);
|
||||||
|
CompletionsRequest request = new CompletionsRequest()
|
||||||
|
.setAppId(appId)
|
||||||
|
.setPrompt(prompt);
|
||||||
|
|
||||||
|
ApplicationClient client = new ApplicationClient(config);
|
||||||
|
CompletionsResponse response = client.completions(request);
|
||||||
|
log.info("AI对话结束");
|
||||||
|
return response.getData().getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String doChatWithHistory(String prompt, List<String[]> recentHistory) {
|
||||||
|
log.info("进入AI对话");
|
||||||
|
AccessTokenClient accessTokenClient = new AccessTokenClient(accessKeyId, accessKeySecret, agentKey);
|
||||||
|
String token = accessTokenClient.getToken();
|
||||||
|
|
||||||
|
BaiLianConfig config = new BaiLianConfig()
|
||||||
|
.setApiKey(token);
|
||||||
|
// 通过sessionId 判断是否为同一个用户
|
||||||
|
String sessionId = UUIDGenerator.generate();
|
||||||
|
// 将该用户最近的五条历史记录加入到绘画中
|
||||||
|
recentHistory.forEach(item -> {
|
||||||
|
CompletionsRequest.ChatQaPair chatQaPair = new CompletionsRequest.ChatQaPair(item[0], item[1]);
|
||||||
|
history.add(chatQaPair);
|
||||||
|
});
|
||||||
|
|
||||||
|
CompletionsRequest request = new CompletionsRequest()
|
||||||
|
.setAppId(appId)
|
||||||
|
.setPrompt(prompt)
|
||||||
|
.setSessionId(sessionId)
|
||||||
|
.setHistory(history);
|
||||||
|
ApplicationClient client = new ApplicationClient(config);
|
||||||
|
CompletionsResponse response = client.completions(request);
|
||||||
|
log.info("AI对话结束");
|
||||||
|
return response.getData().getText();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.book.backend.manager;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.RateLimiter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="https://github.com/luoye6">小白条
|
||||||
|
* @from <a href="https://luoye6.github.io/"> 个人博客
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class GuavaRateLimiterManager {
|
||||||
|
public boolean doRateLimit(Long userId) {
|
||||||
|
// 每秒允许的最大访问速率为1个许可
|
||||||
|
RateLimiter rateLimiter = RateLimiter.create(1);
|
||||||
|
if (rateLimiter.tryAcquire()) {
|
||||||
|
// 可以进行处理的代码,表示限流允许通过
|
||||||
|
log.info("用户id: " + userId + "请求一个令牌成功");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// 限流超过了速率限制的处理代码
|
||||||
|
log.info("用户id: " + userId + "请求一个令牌失败");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
307
src/main/java/com/book/backend/manager/SparkAIManager.java
Normal file
307
src/main/java/com/book/backend/manager/SparkAIManager.java
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
package com.book.backend.manager;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import okhttp3.*;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@Service
|
||||||
|
public class SparkAIManager extends WebSocketListener {
|
||||||
|
// 地址与鉴权信息 https://spark-api.xf-yun.com/v1.1/chat 1.5地址 domain参数为general
|
||||||
|
// 地址与鉴权信息 https://spark-api.xf-yun.com/v2.1/chat 2.0地址 domain参数为generalv2
|
||||||
|
// todo 目前已经有三种版本 请根据您的模型替换 hostURL 讯飞星火官网地址:https://xinghuo.xfyun.cn/sparkapi
|
||||||
|
public static final String hostUrl = "https://spark-api.xf-yun.com/v2.1/chat";
|
||||||
|
// todo 替换成你自己的 appid 图书管理系统 1.1 版本 1.2版本请找 AiIntelligentServiceImpl 替换代码块即可
|
||||||
|
public static final String appid = "xxxxx";
|
||||||
|
// todo 替换成你自己的 apiSecret 图书管理系统 1.1 版本
|
||||||
|
public static final String apiSecret = "xxxxx";
|
||||||
|
// todo 替换成你自己的 apiKey 图书管理系统 1.1 版本
|
||||||
|
public static final String apiKey = "xxxxx";
|
||||||
|
|
||||||
|
public static List<RoleContent> historyList=new ArrayList<>(); // 对话历史存储集合
|
||||||
|
|
||||||
|
public static String totalAnswer=""; // 大模型的答案汇总
|
||||||
|
|
||||||
|
// 环境治理的重要性 环保 人口老龄化 我爱我的祖国
|
||||||
|
public static String NewQuestion = "";
|
||||||
|
|
||||||
|
public static final Gson gson = new Gson();
|
||||||
|
public static MyThread myThread;
|
||||||
|
// 个性化参数
|
||||||
|
private String userId;
|
||||||
|
private Boolean wsCloseFlag;
|
||||||
|
|
||||||
|
private static Boolean totalFlag=true; // 控制提示用户是否输入
|
||||||
|
// 构造函数
|
||||||
|
public SparkAIManager(String userId, Boolean wsCloseFlag) {
|
||||||
|
this.userId = userId;
|
||||||
|
this.wsCloseFlag = wsCloseFlag;
|
||||||
|
}
|
||||||
|
public SparkAIManager(){
|
||||||
|
|
||||||
|
}
|
||||||
|
// 主函数
|
||||||
|
public String sendMessageAndGetResponse(String message,Integer sleepTime) throws Exception {
|
||||||
|
// 个性化参数入口,如果是并发使用,可以在这里模拟
|
||||||
|
|
||||||
|
while (true){
|
||||||
|
if(totalFlag){
|
||||||
|
System.out.print("我:");
|
||||||
|
totalFlag=false;
|
||||||
|
NewQuestion=message;
|
||||||
|
// 构建鉴权url
|
||||||
|
String authUrl = getAuthUrl(hostUrl, apiKey, apiSecret);
|
||||||
|
OkHttpClient client = new OkHttpClient.Builder().build();
|
||||||
|
String url = authUrl.replace("http://", "ws://").replace("https://", "wss://");
|
||||||
|
Request request = new Request.Builder().url(url).build();
|
||||||
|
for (int i = 0; i < 1; i++) {
|
||||||
|
totalAnswer="";
|
||||||
|
WebSocket webSocket = client.newWebSocket(request, new SparkAIManager(i + "",
|
||||||
|
false));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
TimeUnit.SECONDS.sleep(sleepTime);
|
||||||
|
return totalAnswer;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean canAddHistory(){ // 由于历史记录最大上线1.2W左右,需要判断是能能加入历史
|
||||||
|
int history_length=0;
|
||||||
|
for(RoleContent temp:historyList){
|
||||||
|
history_length=history_length+temp.content.length();
|
||||||
|
}
|
||||||
|
if(history_length>12000){
|
||||||
|
historyList.remove(0);
|
||||||
|
historyList.remove(1);
|
||||||
|
historyList.remove(2);
|
||||||
|
historyList.remove(3);
|
||||||
|
historyList.remove(4);
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 线程来发送音频与参数
|
||||||
|
class MyThread extends Thread {
|
||||||
|
private WebSocket webSocket;
|
||||||
|
|
||||||
|
public MyThread(WebSocket webSocket) {
|
||||||
|
this.webSocket = webSocket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
JSONObject requestJson=new JSONObject();
|
||||||
|
|
||||||
|
JSONObject header=new JSONObject(); // header参数
|
||||||
|
header.put("app_id",appid);
|
||||||
|
header.put("uid",UUID.randomUUID().toString().substring(0, 10));
|
||||||
|
|
||||||
|
JSONObject parameter=new JSONObject(); // parameter参数
|
||||||
|
JSONObject chat=new JSONObject();
|
||||||
|
chat.put("domain","generalv2");
|
||||||
|
chat.put("temperature",0.5);
|
||||||
|
chat.put("max_tokens",4096);
|
||||||
|
parameter.put("chat",chat);
|
||||||
|
|
||||||
|
JSONObject payload=new JSONObject(); // payload参数
|
||||||
|
JSONObject message=new JSONObject();
|
||||||
|
JSONArray text=new JSONArray();
|
||||||
|
|
||||||
|
// 历史问题获取
|
||||||
|
// if(historyList.size()>0){
|
||||||
|
// for(RoleContent tempRoleContent:historyList){
|
||||||
|
// text.add(JSON.toJSON(tempRoleContent));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 最新问题
|
||||||
|
RoleContent roleContent=new RoleContent();
|
||||||
|
roleContent.role="user";
|
||||||
|
roleContent.content=NewQuestion;
|
||||||
|
text.add(JSON.toJSON(roleContent));
|
||||||
|
// historyList.add(roleContent);
|
||||||
|
|
||||||
|
|
||||||
|
message.put("text",text);
|
||||||
|
payload.put("message",message);
|
||||||
|
|
||||||
|
|
||||||
|
requestJson.put("header",header);
|
||||||
|
requestJson.put("parameter",parameter);
|
||||||
|
requestJson.put("payload",payload);
|
||||||
|
// System.err.println(requestJson); // 可以打印看每次的传参明细
|
||||||
|
webSocket.send(requestJson.toString());
|
||||||
|
// 等待服务端返回完毕后关闭
|
||||||
|
while (true) {
|
||||||
|
// System.err.println(wsCloseFlag + "---");
|
||||||
|
Thread.sleep(200);
|
||||||
|
if (wsCloseFlag) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webSocket.close(1000, "");
|
||||||
|
myThread.interrupt();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpen(WebSocket webSocket, Response response) {
|
||||||
|
super.onOpen(webSocket, response);
|
||||||
|
System.out.print("大模型:");
|
||||||
|
myThread= new MyThread(webSocket);
|
||||||
|
myThread.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(WebSocket webSocket, String text) {
|
||||||
|
// System.out.println(userId + "用来区分那个用户的结果" + text);
|
||||||
|
JsonParse myJsonParse = gson.fromJson(text, JsonParse.class);
|
||||||
|
if (myJsonParse.header.code != 0) {
|
||||||
|
System.out.println("发生错误,错误码为:" + myJsonParse.header.code);
|
||||||
|
System.out.println("本次请求的sid为:" + myJsonParse.header.sid);
|
||||||
|
webSocket.close(1000, "");
|
||||||
|
}
|
||||||
|
List<Text> textList = myJsonParse.payload.choices.text;
|
||||||
|
for (Text temp : textList) {
|
||||||
|
// System.out.print(temp.content);
|
||||||
|
totalAnswer=totalAnswer+temp.content;
|
||||||
|
}
|
||||||
|
if (myJsonParse.header.status == 2) {
|
||||||
|
// 可以关闭连接,释放资源
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("*************************************************************************************");
|
||||||
|
if(canAddHistory()){
|
||||||
|
RoleContent roleContent=new RoleContent();
|
||||||
|
roleContent.setRole("assistant");
|
||||||
|
roleContent.setContent(totalAnswer);
|
||||||
|
// historyList.add(roleContent);
|
||||||
|
}else{
|
||||||
|
// historyList.remove(0);
|
||||||
|
RoleContent roleContent=new RoleContent();
|
||||||
|
roleContent.setRole("assistant");
|
||||||
|
roleContent.setContent(totalAnswer);
|
||||||
|
// historyList.add(roleContent);
|
||||||
|
}
|
||||||
|
wsCloseFlag = true;
|
||||||
|
totalFlag=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
|
||||||
|
super.onFailure(webSocket, t, response);
|
||||||
|
try {
|
||||||
|
if (null != response) {
|
||||||
|
int code = response.code();
|
||||||
|
System.out.println("onFailure code:" + code);
|
||||||
|
System.out.println("onFailure body:" + response.body().string());
|
||||||
|
if (101 != code) {
|
||||||
|
System.out.println("connection failed");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 鉴权方法
|
||||||
|
public static String getAuthUrl(String hostUrl, String apiKey, String apiSecret) throws Exception {
|
||||||
|
URL url = new URL(hostUrl);
|
||||||
|
// 时间
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||||
|
format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
String date = format.format(new Date());
|
||||||
|
// 拼接
|
||||||
|
String preStr = "host: " + url.getHost() + "\n" +
|
||||||
|
"date: " + date + "\n" +
|
||||||
|
"GET " + url.getPath() + " HTTP/1.1";
|
||||||
|
// System.err.println(preStr);
|
||||||
|
// SHA256加密
|
||||||
|
Mac mac = Mac.getInstance("hmacsha256");
|
||||||
|
SecretKeySpec spec = new SecretKeySpec(apiSecret.getBytes(StandardCharsets.UTF_8), "hmacsha256");
|
||||||
|
mac.init(spec);
|
||||||
|
|
||||||
|
byte[] hexDigits = mac.doFinal(preStr.getBytes(StandardCharsets.UTF_8));
|
||||||
|
// Base64加密
|
||||||
|
String sha = Base64.getEncoder().encodeToString(hexDigits);
|
||||||
|
// System.err.println(sha);
|
||||||
|
// 拼接
|
||||||
|
String authorization = String.format("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", apiKey, "hmac-sha256", "host date request-line", sha);
|
||||||
|
// 拼接地址
|
||||||
|
HttpUrl httpUrl = Objects.requireNonNull(HttpUrl.parse("https://" + url.getHost() + url.getPath())).newBuilder().//
|
||||||
|
addQueryParameter("authorization", Base64.getEncoder().encodeToString(authorization.getBytes(StandardCharsets.UTF_8))).//
|
||||||
|
addQueryParameter("date", date).//
|
||||||
|
addQueryParameter("host", url.getHost()).//
|
||||||
|
build();
|
||||||
|
|
||||||
|
// System.err.println(httpUrl.toString());
|
||||||
|
return httpUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//返回的json结果拆解
|
||||||
|
class JsonParse {
|
||||||
|
Header header;
|
||||||
|
Payload payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Header {
|
||||||
|
int code;
|
||||||
|
int status;
|
||||||
|
String sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Payload {
|
||||||
|
Choices choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Choices {
|
||||||
|
List<Text> text;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Text {
|
||||||
|
String role;
|
||||||
|
String content;
|
||||||
|
}
|
||||||
|
class RoleContent{
|
||||||
|
String role;
|
||||||
|
String content;
|
||||||
|
|
||||||
|
public String getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRole(String role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
109
src/main/java/com/book/backend/manager/SparkClient.java
Normal file
109
src/main/java/com/book/backend/manager/SparkClient.java
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package com.book.backend.manager;
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.constant.SparkApiVersion;
|
||||||
|
import com.book.backend.manager.exception.SparkException;
|
||||||
|
import com.book.backend.manager.listener.SparkBaseListener;
|
||||||
|
import com.book.backend.manager.listener.SparkSyncChatListener;
|
||||||
|
import com.book.backend.manager.model.SparkSyncChatResponse;
|
||||||
|
import com.book.backend.manager.model.request.SparkRequest;
|
||||||
|
import okhttp3.HttpUrl;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XfSparkClient
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkClient {
|
||||||
|
|
||||||
|
public String appid;
|
||||||
|
|
||||||
|
public String apiKey;
|
||||||
|
|
||||||
|
public String apiSecret;
|
||||||
|
|
||||||
|
public OkHttpClient client = new OkHttpClient.Builder().build();
|
||||||
|
|
||||||
|
public void chatStream(SparkRequest sparkRequest, SparkBaseListener listener) {
|
||||||
|
sparkRequest.getHeader().setAppId(appid);
|
||||||
|
listener.setSparkRequest(sparkRequest);
|
||||||
|
|
||||||
|
SparkApiVersion apiVersion = sparkRequest.getApiVersion();
|
||||||
|
String apiUrl = apiVersion.getUrl();
|
||||||
|
|
||||||
|
// 构建鉴权url
|
||||||
|
String authWsUrl = null;
|
||||||
|
try {
|
||||||
|
authWsUrl = getAuthUrl(apiUrl).replace("http://", "ws://").replace("https://", "wss://");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SparkException(500, "构建鉴权url失败", e);
|
||||||
|
}
|
||||||
|
// 创建请求
|
||||||
|
Request request = new Request.Builder().url(authWsUrl).build();
|
||||||
|
// 发送请求
|
||||||
|
client.newWebSocket(request, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkSyncChatResponse chatSync(SparkRequest sparkRequest) {
|
||||||
|
SparkSyncChatResponse chatResponse = new SparkSyncChatResponse();
|
||||||
|
SparkSyncChatListener syncChatListener = new SparkSyncChatListener(chatResponse);
|
||||||
|
this.chatStream(sparkRequest, syncChatListener);
|
||||||
|
while (!chatResponse.isOk()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(200);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Throwable exception = chatResponse.getException();
|
||||||
|
if (exception != null) {
|
||||||
|
if (!(exception instanceof SparkException)) {
|
||||||
|
exception = new SparkException(500, exception.getMessage());
|
||||||
|
}
|
||||||
|
throw (SparkException) exception;
|
||||||
|
}
|
||||||
|
return chatResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取认证之后的URL
|
||||||
|
*/
|
||||||
|
public String getAuthUrl(String apiUrl) throws Exception {
|
||||||
|
URL url = new URL(apiUrl);
|
||||||
|
// 时间
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
|
||||||
|
format.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
String date = format.format(new Date());
|
||||||
|
// 拼接
|
||||||
|
String preStr = "host: " + url.getHost() + "\n" +
|
||||||
|
"date: " + date + "\n" +
|
||||||
|
"GET " + url.getPath() + " HTTP/1.1";
|
||||||
|
// SHA256加密
|
||||||
|
Mac mac = Mac.getInstance("hmacsha256");
|
||||||
|
SecretKeySpec spec = new SecretKeySpec(apiSecret.getBytes(StandardCharsets.UTF_8), "hmacsha256");
|
||||||
|
mac.init(spec);
|
||||||
|
|
||||||
|
byte[] hexDigits = mac.doFinal(preStr.getBytes(StandardCharsets.UTF_8));
|
||||||
|
// Base64加密
|
||||||
|
String sha = Base64.getEncoder().encodeToString(hexDigits);
|
||||||
|
|
||||||
|
// 拼接
|
||||||
|
String authorization = String.format("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", apiKey, "hmac-sha256", "host date request-line", sha);
|
||||||
|
// 拼接地址
|
||||||
|
HttpUrl httpUrl = Objects.requireNonNull(HttpUrl.parse("https://" + url.getHost() + url.getPath())).newBuilder().//
|
||||||
|
addQueryParameter("authorization", Base64.getEncoder().encodeToString(authorization.getBytes(StandardCharsets.UTF_8))).//
|
||||||
|
addQueryParameter("date", date).//
|
||||||
|
addQueryParameter("host", url.getHost()).//
|
||||||
|
build();
|
||||||
|
|
||||||
|
return httpUrl.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.book.backend.manager.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkApiVersion
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
* @date 2023/8/31
|
||||||
|
*/
|
||||||
|
public enum SparkApiVersion {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1.5版本
|
||||||
|
*/
|
||||||
|
V1_5("v1.1", "https://spark-api.xf-yun.com/v1.1/chat", "general"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2.0版本
|
||||||
|
*/
|
||||||
|
V2_0("v2.1", "https://spark-api.xf-yun.com/v2.1/chat", "generalv2"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 3.0版本
|
||||||
|
*/
|
||||||
|
V3_0("v3.1", "https://spark-api.xf-yun.com/v3.1/chat", "generalv3"),
|
||||||
|
;
|
||||||
|
|
||||||
|
SparkApiVersion(String version, String url, String domain) {
|
||||||
|
this.version = version;
|
||||||
|
this.url = url;
|
||||||
|
this.domain = domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String version;
|
||||||
|
|
||||||
|
private final String url;
|
||||||
|
|
||||||
|
private final String domain;
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomain() {
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.book.backend.manager.constant;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkErrorCode
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkErrorCode {
|
||||||
|
public static final Map<Integer, String> RESPONSE_ERROR_MAP = new LinkedHashMap<>(32);
|
||||||
|
|
||||||
|
static {
|
||||||
|
RESPONSE_ERROR_MAP.put(10000, "升级为ws出现错误");
|
||||||
|
RESPONSE_ERROR_MAP.put(10001, "通过ws读取用户的消息出错");
|
||||||
|
RESPONSE_ERROR_MAP.put(10002, "通过ws向用户发送消息错误");
|
||||||
|
RESPONSE_ERROR_MAP.put(10003, "用户的消息格式有错误");
|
||||||
|
RESPONSE_ERROR_MAP.put(10004, "用户数据的schema错误");
|
||||||
|
RESPONSE_ERROR_MAP.put(10005, "用户参数值有错误");
|
||||||
|
RESPONSE_ERROR_MAP.put(10006, "用户并发错误:当前用户已连接,同一用户不能多处同时连接");
|
||||||
|
RESPONSE_ERROR_MAP.put(10007, "用户流量受限:服务正在处理用户当前的问题,需等待处理完成后再发送新的请求");
|
||||||
|
RESPONSE_ERROR_MAP.put(10008, "服务容量不足,联系工作人员");
|
||||||
|
RESPONSE_ERROR_MAP.put(10009, "和引擎建立连接失败");
|
||||||
|
RESPONSE_ERROR_MAP.put(10010, "接收引擎数据的错误");
|
||||||
|
RESPONSE_ERROR_MAP.put(10011, "发送数据给引擎的错误");
|
||||||
|
RESPONSE_ERROR_MAP.put(10012, "引擎内部错误");
|
||||||
|
RESPONSE_ERROR_MAP.put(10013, "输入内容审核不通过,涉嫌违规,请重新调整输入内容");
|
||||||
|
RESPONSE_ERROR_MAP.put(10014, "输出内容涉及敏感信息,审核不通过,后续结果无法展示给用户");
|
||||||
|
RESPONSE_ERROR_MAP.put(10015, "appid在黑名单中");
|
||||||
|
RESPONSE_ERROR_MAP.put(10016, "appid授权类的错误。未开通此功能,未开通对应版本,token不足,并发超过授权等等");
|
||||||
|
RESPONSE_ERROR_MAP.put(10017, "清除历史失败");
|
||||||
|
RESPONSE_ERROR_MAP.put(10019, "本次会话内容有涉及违规信息的倾向");
|
||||||
|
RESPONSE_ERROR_MAP.put(10110, "服务忙,请稍后再试");
|
||||||
|
RESPONSE_ERROR_MAP.put(10163, "请求引擎的参数异常,引擎的schema检查不通过");
|
||||||
|
RESPONSE_ERROR_MAP.put(10222, "引擎网络异常");
|
||||||
|
RESPONSE_ERROR_MAP.put(10907, "token数量超过上限。对话历史+问题的字数太多,需要精简输入");
|
||||||
|
RESPONSE_ERROR_MAP.put(11200, "授权错误:该appId没有相关功能的授权或者业务量超过限制");
|
||||||
|
RESPONSE_ERROR_MAP.put(11201, "授权错误:日流控超限。超过当日最大访问量的限制");
|
||||||
|
RESPONSE_ERROR_MAP.put(11202, "授权错误:秒级流控超限。秒级并发超过授权路数限制");
|
||||||
|
RESPONSE_ERROR_MAP.put(11203, "授权错误:并发流控超限。并发路数超过授权路数限制");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.book.backend.manager.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息角色常量
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public interface SparkMessageRole {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户
|
||||||
|
*/
|
||||||
|
String USER = "user";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 机器人助手
|
||||||
|
*/
|
||||||
|
String ASSISTANT = "assistant";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统指令
|
||||||
|
*/
|
||||||
|
String SYSTEM = "system";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.book.backend.manager.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.constant.SparkErrorCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkException
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 3053312855506511893L;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String sid;
|
||||||
|
|
||||||
|
public SparkException(Integer code, String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkException(Integer code, String message, Throwable t) {
|
||||||
|
super(message, t);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SparkException bizFailed(Integer code) {
|
||||||
|
String errorMessage = SparkErrorCode.RESPONSE_ERROR_MAP.get(code);
|
||||||
|
if (null == errorMessage) {
|
||||||
|
errorMessage = "未知的错误码";
|
||||||
|
}
|
||||||
|
return new SparkException(code, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSid() {
|
||||||
|
return sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSid(String sid) {
|
||||||
|
this.sid = sid;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,146 @@
|
|||||||
|
package com.book.backend.manager.listener;
|
||||||
|
|
||||||
|
import com.book.backend.manager.exception.SparkException;
|
||||||
|
import com.book.backend.manager.model.SparkMessage;
|
||||||
|
import com.book.backend.manager.model.request.SparkRequest;
|
||||||
|
import com.book.backend.manager.model.response.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import okhttp3.Response;
|
||||||
|
import okhttp3.WebSocket;
|
||||||
|
import okhttp3.WebSocketListener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkBaseListener
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkBaseListener extends WebSocketListener {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SparkBaseListener.class);
|
||||||
|
|
||||||
|
private SparkRequest sparkRequest;
|
||||||
|
|
||||||
|
public ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
public SparkBaseListener() {
|
||||||
|
objectMapper = new ObjectMapper();
|
||||||
|
// 排除值为null的字段
|
||||||
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
// 设置全局忽略未知属性
|
||||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收到回答时会调用此方法
|
||||||
|
*
|
||||||
|
* @param content 回答内容
|
||||||
|
* @param usage tokens消耗统计
|
||||||
|
* @param status 会话状态,取值为[0,1,2];0代表首次结果;1代表中间结果;2代表最后一个结果,当status为2时,webSocket连接会自动关闭
|
||||||
|
* @param sparkRequest 本次会话的请求参数
|
||||||
|
* @param sparkResponse 本次回调的响应数据
|
||||||
|
* @param webSocket 本次会话的webSocket连接
|
||||||
|
*/
|
||||||
|
public void onMessage(String content, SparkResponseUsage usage, Integer status, SparkRequest sparkRequest, SparkResponse sparkResponse, WebSocket webSocket) {
|
||||||
|
// 重写此方法,实现业务逻辑
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收到functionCall调用此方法
|
||||||
|
*
|
||||||
|
* @param functionCall functionCall
|
||||||
|
* @param usage tokens消耗统计
|
||||||
|
* @param status 会话状态,取值为[0,1,2];0代表首次结果;1代表中间结果;2代表最后一个结果,当status为2时,webSocket连接会自动关闭
|
||||||
|
* @param sparkRequest 本次会话的请求参数
|
||||||
|
* @param sparkResponse 本次回调的响应数据
|
||||||
|
* @param webSocket 本次会话的webSocket连接
|
||||||
|
*/
|
||||||
|
public void onFunctionCall(SparkResponseFunctionCall functionCall, SparkResponseUsage usage, Integer status, SparkRequest sparkRequest, SparkResponse sparkResponse, WebSocket webSocket) {
|
||||||
|
// 重写此方法,实现业务逻辑
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onOpen(@NotNull WebSocket webSocket, @NotNull Response response) {
|
||||||
|
// 发送消息
|
||||||
|
String requestJson = null;
|
||||||
|
try {
|
||||||
|
requestJson = objectMapper.writeValueAsString(sparkRequest);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new SparkException(400, "请求数据 SparkRequest 序列化失败", e);
|
||||||
|
}
|
||||||
|
webSocket.send(requestJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onMessage(@NotNull WebSocket webSocket, @NotNull String text) {
|
||||||
|
SparkResponse sparkResponse;
|
||||||
|
|
||||||
|
// 解析响应
|
||||||
|
try {
|
||||||
|
sparkResponse = objectMapper.readValue(text, SparkResponse.class);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
webSocket.close(1000, "");
|
||||||
|
throw new SparkException(500, "响应数据 SparkResponse 解析失败:" + text, e);
|
||||||
|
}
|
||||||
|
SparkResponseHeader header = sparkResponse.getHeader();
|
||||||
|
if (null == header) {
|
||||||
|
webSocket.close(1000, "");
|
||||||
|
throw new SparkException(500, "响应数据不完整 SparkResponse.header为null,完整响应:" + text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 业务状态判断
|
||||||
|
Integer code = header.getCode();
|
||||||
|
if (0 != code) {
|
||||||
|
webSocket.close(1000, "");
|
||||||
|
throw SparkException.bizFailed(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回答文本
|
||||||
|
SparkResponseChoices choices = sparkResponse.getPayload().getChoices();
|
||||||
|
List<SparkMessage> messages = choices.getText();
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
SparkResponseFunctionCall functionCall = null;
|
||||||
|
|
||||||
|
SparkResponseUsage usage = sparkResponse.getPayload().getUsage();
|
||||||
|
Integer status = header.getStatus();
|
||||||
|
|
||||||
|
for (SparkMessage message : messages) {
|
||||||
|
if (message.getFunction_call() != null) {
|
||||||
|
functionCall = message.getFunction_call();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
stringBuilder.append(message.getContent());
|
||||||
|
}
|
||||||
|
if (functionCall != null) {
|
||||||
|
this.onFunctionCall(functionCall, usage, status, sparkRequest, sparkResponse, webSocket);
|
||||||
|
} else {
|
||||||
|
String content = stringBuilder.toString();
|
||||||
|
this.onMessage(content, usage, status, sparkRequest, sparkResponse, webSocket);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最后一条结果,关闭连接
|
||||||
|
if (2 == status) {
|
||||||
|
webSocket.close(1000, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, Response response) {
|
||||||
|
logger.error("讯飞星火api发生异常:", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequest getSparkRequest() {
|
||||||
|
return sparkRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSparkRequest(SparkRequest sparkRequest) {
|
||||||
|
this.sparkRequest = sparkRequest;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
package com.book.backend.manager.listener;
|
||||||
|
|
||||||
|
import com.book.backend.manager.constant.SparkApiVersion;
|
||||||
|
import com.book.backend.manager.model.SparkMessage;
|
||||||
|
import com.book.backend.manager.model.request.SparkRequest;
|
||||||
|
import com.book.backend.manager.model.response.SparkResponse;
|
||||||
|
import com.book.backend.manager.model.response.SparkResponseFunctionCall;
|
||||||
|
import com.book.backend.manager.model.response.SparkResponseUsage;
|
||||||
|
import com.book.backend.manager.model.response.SparkTextUsage;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import okhttp3.Response;
|
||||||
|
import okhttp3.WebSocket;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkConsoleListener
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkConsoleListener extends SparkBaseListener {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SparkConsoleListener.class);
|
||||||
|
|
||||||
|
private final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
public ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
{
|
||||||
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(String content, SparkResponseUsage usage, Integer status, SparkRequest sparkRequest, SparkResponse sparkResponse, WebSocket webSocket) {
|
||||||
|
stringBuilder.append(content);
|
||||||
|
|
||||||
|
if (0 == status) {
|
||||||
|
List<SparkMessage> messages = sparkRequest.getPayload().getMessage().getText();
|
||||||
|
try {
|
||||||
|
SparkApiVersion apiVersion = sparkRequest.getApiVersion();
|
||||||
|
System.out.println("请求地址:" + apiVersion.getUrl()+" 版本:"+apiVersion.getVersion());
|
||||||
|
System.out.println("\n提问:" + objectMapper.writeValueAsString(messages));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
System.out.println("\n收到回答:\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("--content:" + content + " --完整响应:" + objectMapper.writeValueAsString(sparkResponse));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (2 == status) {
|
||||||
|
System.out.println("\n完整回答:" + stringBuilder);
|
||||||
|
SparkTextUsage textUsage = usage.getText();
|
||||||
|
System.out.println("\n回答结束;提问tokens:" + textUsage.getPromptTokens()
|
||||||
|
+ ",回答tokens:" + textUsage.getCompletionTokens()
|
||||||
|
+ ",总消耗tokens:" + textUsage.getTotalTokens());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, Response response) {
|
||||||
|
logger.error("讯飞星火api发生异常:", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收到functionCall调用此方法
|
||||||
|
*
|
||||||
|
* @param functionCall functionCall
|
||||||
|
* @param usage tokens消耗统计
|
||||||
|
* @param status 会话状态,取值为[0,1,2];0代表首次结果;1代表中间结果;2代表最后一个结果,当status为2时,webSocket连接会自动关闭
|
||||||
|
* @param sparkRequest 本次会话的请求参数
|
||||||
|
* @param sparkResponse 本次回调的响应数据
|
||||||
|
* @param webSocket 本次会话的webSocket连接
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onFunctionCall(SparkResponseFunctionCall functionCall, SparkResponseUsage usage, Integer status, SparkRequest sparkRequest, SparkResponse sparkResponse, WebSocket webSocket) {
|
||||||
|
String functionCallName = functionCall.getName();
|
||||||
|
Map<String, Object> arguments = functionCall.getMapArguments();
|
||||||
|
|
||||||
|
// 在这里根据方法名和参数自行调用方法实现
|
||||||
|
|
||||||
|
try {
|
||||||
|
System.out.println("\n收到functionCall:方法名称:" + functionCallName + ",参数:" + objectMapper.writeValueAsString(arguments));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.book.backend.manager.listener;
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.model.SparkSyncChatResponse;
|
||||||
|
import com.book.backend.manager.model.request.SparkRequest;
|
||||||
|
import com.book.backend.manager.model.response.SparkResponse;
|
||||||
|
import com.book.backend.manager.model.response.SparkResponseFunctionCall;
|
||||||
|
import com.book.backend.manager.model.response.SparkResponseUsage;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import okhttp3.WebSocket;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkSyncChatListener
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkSyncChatListener extends SparkBaseListener {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SparkSyncChatListener.class);
|
||||||
|
|
||||||
|
private final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
private final SparkSyncChatResponse sparkSyncChatResponse;
|
||||||
|
|
||||||
|
public SparkSyncChatListener(SparkSyncChatResponse sparkSyncChatResponse) {
|
||||||
|
this.sparkSyncChatResponse = sparkSyncChatResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMessage(String content, SparkResponseUsage usage, Integer status, SparkRequest sparkRequest, SparkResponse sparkResponse, WebSocket webSocket) {
|
||||||
|
stringBuilder.append(content);
|
||||||
|
if (2 == status) {
|
||||||
|
sparkSyncChatResponse.setContent(stringBuilder.toString());
|
||||||
|
sparkSyncChatResponse.setTextUsage(usage.getText());
|
||||||
|
sparkSyncChatResponse.setOk(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NotNull WebSocket webSocket, @NotNull Throwable t, Response response) {
|
||||||
|
logger.error("讯飞星火api发生异常", t);
|
||||||
|
sparkSyncChatResponse.setOk(true);
|
||||||
|
sparkSyncChatResponse.setException(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收到functionCall调用此方法
|
||||||
|
*
|
||||||
|
* @param functionCall functionCall
|
||||||
|
* @param sparkRequest 本次会话的请求参数
|
||||||
|
* @param sparkResponse 本次回调的响应数据
|
||||||
|
* @param webSocket 本次会话的webSocket连接
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onFunctionCall(SparkResponseFunctionCall functionCall, SparkResponseUsage usage, Integer status, SparkRequest sparkRequest, SparkResponse sparkResponse, WebSocket webSocket) {
|
||||||
|
if (2 == status) {
|
||||||
|
sparkSyncChatResponse.setContent(stringBuilder.toString());
|
||||||
|
sparkSyncChatResponse.setTextUsage(usage.getText());
|
||||||
|
sparkSyncChatResponse.setFunctionCall(functionCall);
|
||||||
|
sparkSyncChatResponse.setOk(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
package com.book.backend.manager.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.parameter.chat
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkChatParameter implements Serializable {
|
||||||
|
private static final long serialVersionUID = -1815416415486571475L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定访问的领域<br/>
|
||||||
|
* 必传,默认取值为 generalv2
|
||||||
|
*/
|
||||||
|
private String domain = "generalv2";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高<br/>
|
||||||
|
* 非必传,取值为[0,1],默认为0.5
|
||||||
|
*/
|
||||||
|
private Double temperature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型回答的tokens的最大长度<br/>
|
||||||
|
*
|
||||||
|
* V1.5取值为[1,4096],默认为2048
|
||||||
|
* V2.0取值为[1,8192],默认为2048。
|
||||||
|
* V3.0取值为[1,8192],默认为2048。
|
||||||
|
*/
|
||||||
|
@JsonProperty("max_tokens")
|
||||||
|
private Integer maxTokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从k个候选中随机选择⼀个(⾮等概率)<br/>
|
||||||
|
* 非必传,取值为[1,6],默认为4
|
||||||
|
*/
|
||||||
|
@JsonProperty("top_k")
|
||||||
|
private Integer topK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于关联用户会话<br/>
|
||||||
|
* 非必传,需要保障用户下的唯一性
|
||||||
|
*/
|
||||||
|
@JsonProperty("chat_id")
|
||||||
|
private String chatId;
|
||||||
|
|
||||||
|
public static SparkChatParameter defaultParameter() {
|
||||||
|
return new SparkChatParameter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomain() {
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDomain(String domain) {
|
||||||
|
this.domain = domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemperature(Double temperature) {
|
||||||
|
this.temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxTokens() {
|
||||||
|
return maxTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxTokens(Integer maxTokens) {
|
||||||
|
this.maxTokens = maxTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTopK() {
|
||||||
|
return topK;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTopK(Integer topK) {
|
||||||
|
this.topK = topK;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChatId() {
|
||||||
|
return chatId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChatId(String chatId) {
|
||||||
|
this.chatId = chatId;
|
||||||
|
}
|
||||||
|
}
|
112
src/main/java/com/book/backend/manager/model/SparkMessage.java
Normal file
112
src/main/java/com/book/backend/manager/model/SparkMessage.java
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package com.book.backend.manager.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.constant.SparkMessageRole;
|
||||||
|
import com.book.backend.manager.model.response.SparkResponseFunctionCall;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkMessage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色
|
||||||
|
*/
|
||||||
|
private String role;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容类型
|
||||||
|
*/
|
||||||
|
private String content_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 函数调用
|
||||||
|
*/
|
||||||
|
private SparkResponseFunctionCall function_call;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应时独有,请求入参请忽略
|
||||||
|
*/
|
||||||
|
private String index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建用户消息
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
*/
|
||||||
|
public static SparkMessage userContent(String content) {
|
||||||
|
return new SparkMessage(SparkMessageRole.USER, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建机器人消息
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
*/
|
||||||
|
public static SparkMessage assistantContent(String content) {
|
||||||
|
return new SparkMessage(SparkMessageRole.ASSISTANT, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建system指令
|
||||||
|
* @param content 内容
|
||||||
|
*/
|
||||||
|
public static SparkMessage systemContent(String content) {
|
||||||
|
return new SparkMessage(SparkMessageRole.SYSTEM, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkMessage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkMessage(String role, String content) {
|
||||||
|
this.role = role;
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRole(String role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent_type() {
|
||||||
|
return content_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent_type(String content_type) {
|
||||||
|
this.content_type = content_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkResponseFunctionCall getFunction_call() {
|
||||||
|
return function_call;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFunction_call(SparkResponseFunctionCall function_call) {
|
||||||
|
this.function_call = function_call;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(String index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,130 @@
|
|||||||
|
package com.book.backend.manager.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.constant.SparkApiVersion;
|
||||||
|
import com.book.backend.manager.model.request.*;
|
||||||
|
import com.book.backend.manager.model.request.function.SparkRequestFunctionMessage;
|
||||||
|
import com.book.backend.manager.model.request.function.SparkRequestFunctions;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkRequestBuilder
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestBuilder {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(SparkRequestBuilder.class);
|
||||||
|
|
||||||
|
private final SparkRequest sparkRequest;
|
||||||
|
|
||||||
|
public SparkRequestBuilder() {
|
||||||
|
sparkRequest = new SparkRequest();
|
||||||
|
|
||||||
|
// header
|
||||||
|
sparkRequest.setHeader(new SparkRequestHeader());
|
||||||
|
|
||||||
|
// parameter
|
||||||
|
sparkRequest.setParameter(new SparkRequestParameter(new SparkChatParameter()));
|
||||||
|
|
||||||
|
// payload
|
||||||
|
sparkRequest.setPayload(new SparkRequestPayload(new SparkRequestMessage(new ArrayList<>())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequest build() {
|
||||||
|
SparkApiVersion apiVersion = sparkRequest.getApiVersion();
|
||||||
|
if (sparkRequest.getPayload().getFunctions() != null && (apiVersion == SparkApiVersion.V2_0 || apiVersion == SparkApiVersion.V1_5)) {
|
||||||
|
logger.warn("apiVersion is {}, this version does not support functions", apiVersion.getVersion());
|
||||||
|
}
|
||||||
|
sparkRequest.getParameter().getChat().setDomain(apiVersion.getDomain());
|
||||||
|
return sparkRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息列表,如果想获取结合上下文的回答,需要将历史问答信息放在一起<br/>
|
||||||
|
* 必传,消息列表总tokens不能超过8192
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder messages(List<SparkMessage> messages) {
|
||||||
|
sparkRequest.getPayload().getMessage().setText(messages);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核采样阈值。用于决定结果随机性,取值越高随机性越强即相同的问题得到的不同答案的可能性越高<br/>
|
||||||
|
* 非必传,取值为[0,1],默认为0.5
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder temperature(Double temperature) {
|
||||||
|
sparkRequest.getParameter().getChat().setTemperature(temperature);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模型回答的tokens的最大长度<br/>
|
||||||
|
* 非必传,取值为[1,4096],默认为2048
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder maxTokens(Integer maxTokens) {
|
||||||
|
sparkRequest.getParameter().getChat().setMaxTokens(maxTokens);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从k个候选中随机选择⼀个(⾮等概率)<br/>
|
||||||
|
* 非必传,取值为[1,6],默认为4
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder topK(Integer topK) {
|
||||||
|
sparkRequest.getParameter().getChat().setTopK(topK);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每个用户的id,用于区分不同用户<br/>
|
||||||
|
* 非必传,最大长度32
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder uid(String uid) {
|
||||||
|
sparkRequest.getHeader().setUid(uid);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于关联用户会话<br/>
|
||||||
|
* 非必传,需要保障用户下的唯一性
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder chatId(String chatId) {
|
||||||
|
sparkRequest.getParameter().getChat().setChatId(chatId);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 覆盖默认的对话参数
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder chatParameter(SparkChatParameter chatParameter) {
|
||||||
|
sparkRequest.getParameter().setChat(chatParameter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定apiVersion<br/>
|
||||||
|
* 非必传,默认使用2.0版本
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder apiVersion(SparkApiVersion apiVersion) {
|
||||||
|
sparkRequest.setApiVersion(apiVersion);
|
||||||
|
sparkRequest.getParameter().getChat().setDomain(apiVersion.getDomain());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增function
|
||||||
|
*/
|
||||||
|
public SparkRequestBuilder addFunction(SparkRequestFunctionMessage function) {
|
||||||
|
SparkRequestFunctions functions = sparkRequest.getPayload().getFunctions();
|
||||||
|
if (null == functions) {
|
||||||
|
functions = new SparkRequestFunctions(new ArrayList<>());
|
||||||
|
sparkRequest.getPayload().setFunctions(functions);
|
||||||
|
}
|
||||||
|
functions.getText().add(function);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package com.book.backend.manager.model;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.model.response.SparkResponseFunctionCall;
|
||||||
|
import com.book.backend.manager.model.response.SparkTextUsage;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkTextChatResponse
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkSyncChatResponse implements Serializable {
|
||||||
|
private static final long serialVersionUID = -6785055441385392782L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回答内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
private SparkResponseFunctionCall functionCall;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tokens统计
|
||||||
|
*/
|
||||||
|
private SparkTextUsage textUsage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部自用字段
|
||||||
|
*/
|
||||||
|
private boolean ok = false;
|
||||||
|
|
||||||
|
private Throwable exception;
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkResponseFunctionCall getFunctionCall() {
|
||||||
|
return functionCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFunctionCall(SparkResponseFunctionCall functionCall) {
|
||||||
|
this.functionCall = functionCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkTextUsage getTextUsage() {
|
||||||
|
return textUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextUsage(SparkTextUsage textUsage) {
|
||||||
|
this.textUsage = textUsage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOk() {
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOk(boolean ok) {
|
||||||
|
this.ok = ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Throwable getException() {
|
||||||
|
return exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setException(Throwable exception) {
|
||||||
|
this.exception = exception;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.book.backend.manager.model.request;
|
||||||
|
|
||||||
|
import com.book.backend.manager.constant.SparkApiVersion;
|
||||||
|
import com.book.backend.manager.model.SparkRequestBuilder;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkRequest
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequest implements Serializable {
|
||||||
|
private static final long serialVersionUID = 8142547165395379456L;
|
||||||
|
|
||||||
|
private SparkRequestHeader header;
|
||||||
|
|
||||||
|
private SparkRequestParameter parameter;
|
||||||
|
|
||||||
|
private SparkRequestPayload payload;
|
||||||
|
|
||||||
|
private transient SparkApiVersion apiVersion = SparkApiVersion.V3_0;
|
||||||
|
|
||||||
|
public static SparkRequestBuilder builder() {
|
||||||
|
return new SparkRequestBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestHeader getHeader() {
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeader(SparkRequestHeader header) {
|
||||||
|
this.header = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestParameter getParameter() {
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParameter(SparkRequestParameter parameter) {
|
||||||
|
this.parameter = parameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestPayload getPayload() {
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPayload(SparkRequestPayload payload) {
|
||||||
|
this.payload = payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public SparkApiVersion getApiVersion() {
|
||||||
|
return apiVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public void setApiVersion(SparkApiVersion apiVersion) {
|
||||||
|
this.apiVersion = apiVersion;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.book.backend.manager.model.request;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.header
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestHeader implements Serializable {
|
||||||
|
private static final long serialVersionUID = -1426143090218924505L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用appid,从开放平台控制台创建的应用中获取<br/>
|
||||||
|
* 必传
|
||||||
|
*/
|
||||||
|
@JsonProperty("app_id")
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每个用户的id,用于区分不同用户<br/>
|
||||||
|
* 非必传,最大长度32
|
||||||
|
*/
|
||||||
|
private String uid;
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUid() {
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUid(String uid) {
|
||||||
|
this.uid = uid;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.book.backend.manager.model.request;
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.model.SparkMessage;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload.message
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestMessage implements Serializable {
|
||||||
|
private static final long serialVersionUID = 6725091574720504980L;
|
||||||
|
|
||||||
|
private List<SparkMessage> text;
|
||||||
|
|
||||||
|
public SparkRequestMessage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestMessage(List<SparkMessage> text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SparkMessage> getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(List<SparkMessage> text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.book.backend.manager.model.request;
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.model.SparkChatParameter;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.parameter
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestParameter implements Serializable {
|
||||||
|
private static final long serialVersionUID = 4502096141480336425L;
|
||||||
|
|
||||||
|
private SparkChatParameter chat;
|
||||||
|
|
||||||
|
public SparkRequestParameter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestParameter(SparkChatParameter chat) {
|
||||||
|
this.chat = chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkChatParameter getChat() {
|
||||||
|
return chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChat(SparkChatParameter chat) {
|
||||||
|
this.chat = chat;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.book.backend.manager.model.request;
|
||||||
|
|
||||||
|
|
||||||
|
import com.book.backend.manager.model.request.function.SparkRequestFunctions;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestPayload implements Serializable {
|
||||||
|
private static final long serialVersionUID = 2084163918219863102L;
|
||||||
|
|
||||||
|
private SparkRequestMessage message;
|
||||||
|
|
||||||
|
private SparkRequestFunctions functions;
|
||||||
|
|
||||||
|
public SparkRequestPayload() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestPayload(SparkRequestMessage message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestPayload(SparkRequestMessage message, SparkRequestFunctions functions) {
|
||||||
|
this.message = message;
|
||||||
|
this.functions = functions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestMessage getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(SparkRequestMessage message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestFunctions getFunctions() {
|
||||||
|
return functions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFunctions(SparkRequestFunctions functions) {
|
||||||
|
this.functions = functions;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.book.backend.manager.model.request.function;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkFunctionBuilder
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
* @date 2023/11/25
|
||||||
|
*/
|
||||||
|
public class SparkFunctionBuilder {
|
||||||
|
|
||||||
|
private final SparkRequestFunctionMessage sparkRequestFunctionMessage;
|
||||||
|
|
||||||
|
public SparkFunctionBuilder() {
|
||||||
|
sparkRequestFunctionMessage = new SparkRequestFunctionMessage();
|
||||||
|
sparkRequestFunctionMessage.setParameters(new SparkRequestFunctionParameters("object", new LinkedHashMap<>(), new ArrayList<>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SparkFunctionBuilder functionName(String name) {
|
||||||
|
return new SparkFunctionBuilder().name(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;function名称;用户输入命中后,会返回该名称
|
||||||
|
*/
|
||||||
|
public SparkFunctionBuilder name(String name) {
|
||||||
|
sparkRequestFunctionMessage.setName(name);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;function功能描述;描述function功能即可,越详细越有助于大模型理解该function
|
||||||
|
*/
|
||||||
|
public SparkFunctionBuilder description(String description) {
|
||||||
|
sparkRequestFunctionMessage.setDescription(description);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;参数类型;默认值:object
|
||||||
|
*/
|
||||||
|
public SparkFunctionBuilder parameterType(String type) {
|
||||||
|
sparkRequestFunctionMessage.getParameters().setType(type);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;参数信息描述;该内容由用户定义,命中该方法时需要返回哪些参数
|
||||||
|
*
|
||||||
|
* @param name 参数名称
|
||||||
|
* @param type 参数类型
|
||||||
|
* @param description 参数信息描述
|
||||||
|
*/
|
||||||
|
public SparkFunctionBuilder addParameterProperty(String name, String type, String description) {
|
||||||
|
sparkRequestFunctionMessage.getParameters().getProperties().put(name, new SparkRequestFunctionProperty(type, description));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必须返回的参数列表
|
||||||
|
*/
|
||||||
|
public SparkFunctionBuilder addParameterRequired(String... name) {
|
||||||
|
for (String s : name) {
|
||||||
|
sparkRequestFunctionMessage.getParameters().getRequired().add(s);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkFunctionBuilder parameters(String type, Map<String, SparkRequestFunctionProperty> properties, List<String> required) {
|
||||||
|
sparkRequestFunctionMessage.setParameters(new SparkRequestFunctionParameters(type, properties, required));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestFunctionMessage build() {
|
||||||
|
return sparkRequestFunctionMessage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.book.backend.manager.model.request.function;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload.functions.text
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestFunctionMessage implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 6587302404547694700L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;function名称;用户输入命中后,会返回该名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;function功能描述;描述function功能即可,越详细越有助于大模型理解该function
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;function参数列表
|
||||||
|
*/
|
||||||
|
private SparkRequestFunctionParameters parameters;
|
||||||
|
|
||||||
|
public SparkRequestFunctionMessage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestFunctionMessage(String name, String description, SparkRequestFunctionParameters parameters) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.parameters = parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestFunctionParameters getParameters() {
|
||||||
|
return parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParameters(SparkRequestFunctionParameters parameters) {
|
||||||
|
this.parameters = parameters;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.book.backend.manager.model.request.function;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload.functions.text
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestFunctionParameters implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1079801431462837232L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;参数类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;参数信息描述;该内容由用户定义,命中该方法时需要返回哪些参数<br/>
|
||||||
|
* key:参数名称<br/>
|
||||||
|
* value:参数信息描述
|
||||||
|
*/
|
||||||
|
private Map<String,SparkRequestFunctionProperty> properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;必须返回的参数列表;该内容由用户定义,命中方法时必须返回的字段;properties中的key
|
||||||
|
*/
|
||||||
|
private List<String> required;
|
||||||
|
|
||||||
|
public SparkRequestFunctionParameters() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestFunctionParameters(String type, Map<String, SparkRequestFunctionProperty> properties, List<String> required) {
|
||||||
|
this.type = type;
|
||||||
|
this.properties = properties;
|
||||||
|
this.required = required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, SparkRequestFunctionProperty> getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(Map<String, SparkRequestFunctionProperty> properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRequired() {
|
||||||
|
return required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequired(List<String> required) {
|
||||||
|
this.required = required;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.book.backend.manager.model.request.function;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload.functions.text.parameters.properties.*
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestFunctionProperty implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -343415637582994606L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;参数信息描述;该内容由用户定义,需要返回的参数是什么类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 必传;参数详细描述;该内容由用户定义,需要返回的参数的具体描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
public SparkRequestFunctionProperty() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestFunctionProperty(String type, String description) {
|
||||||
|
this.type = type;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.book.backend.manager.model.request.function;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload.functions
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkRequestFunctions implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7696196392354475586L;
|
||||||
|
|
||||||
|
private List<SparkRequestFunctionMessage> text;
|
||||||
|
|
||||||
|
public SparkRequestFunctions() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkRequestFunctions(List<SparkRequestFunctionMessage> text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SparkRequestFunctionMessage> getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(List<SparkRequestFunctionMessage> text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.book.backend.manager.model.response;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkResponse
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkResponse implements Serializable {
|
||||||
|
private static final long serialVersionUID = 886720558849587945L;
|
||||||
|
|
||||||
|
private SparkResponseHeader header;
|
||||||
|
|
||||||
|
private SparkResponsePayload payload;
|
||||||
|
|
||||||
|
public SparkResponseHeader getHeader() {
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeader(SparkResponseHeader header) {
|
||||||
|
this.header = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkResponsePayload getPayload() {
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPayload(SparkResponsePayload payload) {
|
||||||
|
this.payload = payload;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.book.backend.manager.model.response;
|
||||||
|
|
||||||
|
import com.book.backend.manager.model.SparkMessage;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload.choices
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkResponseChoices implements Serializable {
|
||||||
|
private static final long serialVersionUID = 3908073548592366629L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文本响应状态,取值为[0,1,2]; 0代表首个文本结果;1代表中间文本结果;2代表最后一个文本结果
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回的数据序号,取值为[0,9999999]
|
||||||
|
*/
|
||||||
|
private Integer seq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息列表
|
||||||
|
*/
|
||||||
|
private List<SparkMessage> text;
|
||||||
|
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSeq() {
|
||||||
|
return seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeq(Integer seq) {
|
||||||
|
this.seq = seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SparkMessage> getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(List<SparkMessage> text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package com.book.backend.manager.model.response;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SparkResponseFunctionCall
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
* @date 2023/11/25
|
||||||
|
*/
|
||||||
|
public class SparkResponseFunctionCall implements Serializable {
|
||||||
|
private static final long serialVersionUID = -1586729944571910329L;
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
{
|
||||||
|
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String arguments;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public String getArguments() {
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArguments(String arguments) {
|
||||||
|
this.arguments = arguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getMapArguments() {
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(arguments, new TypeReference<Map<String, Object>>() {
|
||||||
|
});
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.book.backend.manager.model.response;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.header
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkResponseHeader implements Serializable {
|
||||||
|
private static final long serialVersionUID = -2828057068263022569L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码,0表示正常,非0表示出错;详细释义可在接口说明文档最后的错误码说明了解
|
||||||
|
*/
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话状态,取值为[0,1,2];0代表首次结果;1代表中间结果;2代表最后一个结果
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话是否成功的描述信息
|
||||||
|
*/
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话的唯一id,用于讯飞技术人员查询服务端会话日志使用,出现调用错误时建议留存该字段
|
||||||
|
*/
|
||||||
|
private String sid;
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(Integer code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSid() {
|
||||||
|
return sid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSid(String sid) {
|
||||||
|
this.sid = sid;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.book.backend.manager.model.response;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkResponsePayload implements Serializable {
|
||||||
|
private static final long serialVersionUID = 8090192271782303700L;
|
||||||
|
|
||||||
|
private SparkResponseChoices choices;
|
||||||
|
|
||||||
|
private SparkResponseUsage usage;
|
||||||
|
|
||||||
|
public SparkResponseChoices getChoices() {
|
||||||
|
return choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChoices(SparkResponseChoices choices) {
|
||||||
|
this.choices = choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkResponseUsage getUsage() {
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsage(SparkResponseUsage usage) {
|
||||||
|
this.usage = usage;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.book.backend.manager.model.response;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload.usage
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkResponseUsage implements Serializable {
|
||||||
|
private static final long serialVersionUID = 2181817132625461079L;
|
||||||
|
|
||||||
|
private SparkTextUsage text;
|
||||||
|
|
||||||
|
public SparkTextUsage getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(SparkTextUsage text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
package com.book.backend.manager.model.response;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $.payload.usage.text
|
||||||
|
*
|
||||||
|
* @author briqt
|
||||||
|
*/
|
||||||
|
public class SparkTextUsage implements Serializable {
|
||||||
|
private static final long serialVersionUID = 8295933047877077971L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包含历史问题的总tokens大小(提问tokens大小)
|
||||||
|
*/
|
||||||
|
@JsonProperty("prompt_tokens")
|
||||||
|
private Integer promptTokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回答的tokens大小
|
||||||
|
*/
|
||||||
|
@JsonProperty("completion_tokens")
|
||||||
|
private Integer completionTokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* prompt_tokens和completion_tokens的和,也是本次交互计费的tokens大小
|
||||||
|
*/
|
||||||
|
@JsonProperty("total_tokens")
|
||||||
|
private Integer totalTokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保留字段,可忽略
|
||||||
|
*/
|
||||||
|
@JsonProperty("question_tokens")
|
||||||
|
private Integer questionTokens;
|
||||||
|
|
||||||
|
public Integer getPromptTokens() {
|
||||||
|
return promptTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPromptTokens(Integer promptTokens) {
|
||||||
|
this.promptTokens = promptTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCompletionTokens() {
|
||||||
|
return completionTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompletionTokens(Integer completionTokens) {
|
||||||
|
this.completionTokens = completionTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTotalTokens() {
|
||||||
|
return totalTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalTokens(Integer totalTokens) {
|
||||||
|
this.totalTokens = totalTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getQuestionTokens() {
|
||||||
|
return questionTokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuestionTokens(Integer questionTokens) {
|
||||||
|
this.questionTokens = questionTokens;
|
||||||
|
}
|
||||||
|
}
|
18
src/main/java/com/book/backend/mapper/AdminsMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/AdminsMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Admins;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_admins】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-03 20:01:01
|
||||||
|
* @Entity com.book.backend.pojo.Admins
|
||||||
|
*/
|
||||||
|
public interface AdminsMapper extends BaseMapper<Admins> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.AiIntelligent;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaobaitiao
|
||||||
|
* @description 针对表【t_ai_intelligent】的数据库操作Mapper
|
||||||
|
* @createDate 2023-08-27 18:44:26
|
||||||
|
* @Entity com.book.backend.pojo.AiIntelligent
|
||||||
|
*/
|
||||||
|
public interface AiIntelligentMapper extends BaseMapper<AiIntelligent> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/BookAdminsMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/BookAdminsMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.BookAdmins;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_book_admins】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-04 16:55:39
|
||||||
|
* @Entity com.book.backend.pojo.BookAdmins
|
||||||
|
*/
|
||||||
|
public interface BookAdminsMapper extends BaseMapper<BookAdmins> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/BookRuleMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/BookRuleMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.BookRule;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_book_rule】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-05 15:11:20
|
||||||
|
* @Entity com.book.backend.pojo.BookRule
|
||||||
|
*/
|
||||||
|
public interface BookRuleMapper extends BaseMapper<BookRule> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/BookTypeMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/BookTypeMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.BookType;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_book_type】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-04 18:51:24
|
||||||
|
* @Entity com.book.backend.pojo.BookType
|
||||||
|
*/
|
||||||
|
public interface BookTypeMapper extends BaseMapper<BookType> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/BooksBorrowMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/BooksBorrowMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.BooksBorrow;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_books_borrow】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-05 18:53:07
|
||||||
|
* @Entity com.book.backend.pojo.BooksBorrow
|
||||||
|
*/
|
||||||
|
public interface BooksBorrowMapper extends BaseMapper<BooksBorrow> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/BooksMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/BooksMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Books;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_books】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-04 18:07:43
|
||||||
|
* @Entity com.book.backend.pojo.Books
|
||||||
|
*/
|
||||||
|
public interface BooksMapper extends BaseMapper<Books> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/ChartMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/ChartMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Chart;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaobaitiao
|
||||||
|
* @description 针对表【t_chart(图表信息表)】的数据库操作Mapper
|
||||||
|
* @createDate 2023-08-30 11:05:22
|
||||||
|
* @Entity com.book.backend.pojo.Chart
|
||||||
|
*/
|
||||||
|
public interface ChartMapper extends BaseMapper<Chart> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/ChatMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/ChatMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Chat;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaobaitiao
|
||||||
|
* @description 针对表【t_chat】的数据库操作Mapper
|
||||||
|
* @createDate 2023-11-27 19:29:21
|
||||||
|
* @Entity com.book.backend.pojo.Chat
|
||||||
|
*/
|
||||||
|
public interface ChatMapper extends BaseMapper<Chat> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/CommentMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/CommentMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Comment;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_comment】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-06 19:19:20
|
||||||
|
* @Entity com.book.backend.pojo.Comment
|
||||||
|
*/
|
||||||
|
public interface CommentMapper extends BaseMapper<Comment> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/NoticeMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/NoticeMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Notice;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_notice】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-05 16:14:03
|
||||||
|
* @Entity com.book.backend.pojo.Notice
|
||||||
|
*/
|
||||||
|
public interface NoticeMapper extends BaseMapper<Notice> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.UserInterfaceInfo;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaobaitiao
|
||||||
|
* @description 针对表【t_user_interface_info】的数据库操作Mapper
|
||||||
|
* @createDate 2023-09-03 19:42:54
|
||||||
|
* @Entity com.book.backend.pojo.UserInterfaceInfo
|
||||||
|
*/
|
||||||
|
public interface UserInterfaceInfoMapper extends BaseMapper<UserInterfaceInfo> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
20
src/main/java/com/book/backend/mapper/UsersMapper.java
Normal file
20
src/main/java/com/book/backend/mapper/UsersMapper.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Users;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_users】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-02 16:20:02
|
||||||
|
* @Entity com.book.backend.pojo.Users
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface UsersMapper extends BaseMapper<Users> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
18
src/main/java/com/book/backend/mapper/ViolationMapper.java
Normal file
18
src/main/java/com/book/backend/mapper/ViolationMapper.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package com.book.backend.mapper;
|
||||||
|
|
||||||
|
import com.book.backend.pojo.Violation;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 程序员小白条
|
||||||
|
* @description 针对表【t_violation】的数据库操作Mapper
|
||||||
|
* @createDate 2023-02-06 16:31:20
|
||||||
|
* @Entity com.book.backend.pojo.Violation
|
||||||
|
*/
|
||||||
|
public interface ViolationMapper extends BaseMapper<Violation> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
56
src/main/java/com/book/backend/pojo/Admins.java
Normal file
56
src/main/java/com/book/backend/pojo/Admins.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package com.book.backend.pojo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName t_admins
|
||||||
|
*/
|
||||||
|
@TableName(value ="t_admins")
|
||||||
|
@Data
|
||||||
|
public class Admins implements Serializable {
|
||||||
|
/**
|
||||||
|
* 管理员表的唯一标识
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long adminId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码(MD5加密)
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员真实姓名
|
||||||
|
*/
|
||||||
|
private String adminName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1表示可用 0表示禁用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
50
src/main/java/com/book/backend/pojo/AiIntelligent.java
Normal file
50
src/main/java/com/book/backend/pojo/AiIntelligent.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package com.book.backend.pojo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName t_ai_intelligent
|
||||||
|
*/
|
||||||
|
@TableName(value ="t_ai_intelligent")
|
||||||
|
@Data
|
||||||
|
public class AiIntelligent implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_ID)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户输入信息
|
||||||
|
*/
|
||||||
|
private String inputMessage;
|
||||||
|
/**
|
||||||
|
* AI生成的信息
|
||||||
|
*/
|
||||||
|
private String aiResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id,标识是哪个用户的信息 可以为Null
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
61
src/main/java/com/book/backend/pojo/BookAdmins.java
Normal file
61
src/main/java/com/book/backend/pojo/BookAdmins.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package com.book.backend.pojo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName t_book_admins
|
||||||
|
*/
|
||||||
|
@TableName(value ="t_book_admins")
|
||||||
|
@Data
|
||||||
|
public class BookAdmins implements Serializable {
|
||||||
|
/**
|
||||||
|
* 图书管理员表的唯一标识
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long bookAdminId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码md5加密
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书管理员真实姓名
|
||||||
|
*/
|
||||||
|
private String bookAdminName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1表示可用 0表示禁用
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电子邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
61
src/main/java/com/book/backend/pojo/BookRule.java
Normal file
61
src/main/java/com/book/backend/pojo/BookRule.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package com.book.backend.pojo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName t_book_rule
|
||||||
|
*/
|
||||||
|
@TableName(value ="t_book_rule")
|
||||||
|
@Data
|
||||||
|
public class BookRule implements Serializable {
|
||||||
|
/**
|
||||||
|
* 借阅规则记录的唯一标识
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer ruleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅规则编号
|
||||||
|
*/
|
||||||
|
private Integer bookRuleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅天数
|
||||||
|
*/
|
||||||
|
private Integer bookDays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限制借阅的本数
|
||||||
|
*/
|
||||||
|
private Integer bookLimitNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限制的图书馆
|
||||||
|
*/
|
||||||
|
private String bookLimitLibrary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书借阅后每天逾期费用
|
||||||
|
*/
|
||||||
|
private Double bookOverdueFee;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
46
src/main/java/com/book/backend/pojo/BookType.java
Normal file
46
src/main/java/com/book/backend/pojo/BookType.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package com.book.backend.pojo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName t_book_type
|
||||||
|
*/
|
||||||
|
@TableName(value ="t_book_type")
|
||||||
|
@Data
|
||||||
|
public class BookType implements Serializable {
|
||||||
|
/**
|
||||||
|
* 图书类别唯一标识
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer typeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅类别的昵称
|
||||||
|
*/
|
||||||
|
private String typeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅类别的描述
|
||||||
|
*/
|
||||||
|
private String typeContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
76
src/main/java/com/book/backend/pojo/Books.java
Normal file
76
src/main/java/com/book/backend/pojo/Books.java
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package com.book.backend.pojo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName t_books
|
||||||
|
*/
|
||||||
|
@TableName(value ="t_books")
|
||||||
|
@Data
|
||||||
|
public class Books implements Serializable {
|
||||||
|
/**
|
||||||
|
* 图书表唯一标识
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer bookId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书编号 图书的唯一标识
|
||||||
|
*/
|
||||||
|
private Long bookNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书名称
|
||||||
|
*/
|
||||||
|
private String bookName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书作者
|
||||||
|
*/
|
||||||
|
private String bookAuthor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书所在图书馆名称
|
||||||
|
*/
|
||||||
|
private String bookLibrary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书类别
|
||||||
|
*/
|
||||||
|
private String bookType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书位置
|
||||||
|
*/
|
||||||
|
private String bookLocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书状态
|
||||||
|
*/
|
||||||
|
private String bookStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书描述
|
||||||
|
*/
|
||||||
|
private String bookDescription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
85
src/main/java/com/book/backend/pojo/BooksBorrow.java
Normal file
85
src/main/java/com/book/backend/pojo/BooksBorrow.java
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
package com.book.backend.pojo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName t_books_borrow
|
||||||
|
*/
|
||||||
|
@TableName(value ="t_books_borrow")
|
||||||
|
@Data
|
||||||
|
public class BooksBorrow implements Serializable {
|
||||||
|
/**
|
||||||
|
* 借阅表唯一标识
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer borrowId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅证编号 固定11位随机生成 用户和图书关联的唯一标识
|
||||||
|
*/
|
||||||
|
private Long cardNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图书编号 图书唯一标识
|
||||||
|
*/
|
||||||
|
private Long bookNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 借阅日期
|
||||||
|
*/
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||||
|
private LocalDateTime borrowDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 截止日期
|
||||||
|
*/
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||||
|
private LocalDateTime closeDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 归还日期
|
||||||
|
*/
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||||
|
private LocalDateTime returnDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private String updateTime;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public BooksBorrow(Integer borrowId, Long cardNumber, Long bookNumber, LocalDateTime borrowDate, LocalDateTime closeDate, LocalDateTime returnDate, String createTime, String updateTime) {
|
||||||
|
this.borrowId = borrowId;
|
||||||
|
this.cardNumber = cardNumber;
|
||||||
|
this.bookNumber = bookNumber;
|
||||||
|
this.borrowDate = borrowDate;
|
||||||
|
this.closeDate = closeDate;
|
||||||
|
this.returnDate = returnDate;
|
||||||
|
this.createTime = createTime;
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooksBorrow() {
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user