mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-01 23:26:38 +00:00
Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
e4e511aed8 | |||
ec9674f2aa | |||
06074faf9a | |||
73654dda2b | |||
c0634a335e | |||
5dcc2b0b46 | |||
6cdb68899b | |||
d955b11165 | |||
1081b8e10a | |||
4b1507b2d1 | |||
82658f3b5f | |||
acf9c76757 | |||
4b00ea68a9 | |||
d9f9fd8bd2 | |||
c1583f83bb | |||
eecbb2dd9c | |||
0afc7b1bbf | |||
f5a9a7423f | |||
3858cd4e49 | |||
c4a6acf2b3 | |||
8781cc54d4 | |||
84a06a7037 | |||
a046899dd6 | |||
14a1ff69bf | |||
467290b908 | |||
d77ce5b446 | |||
8d35aa80ab | |||
11978c2c9e | |||
81c1514a21 | |||
af1237e2d7 | |||
9033ca6331 | |||
fd200772c9 | |||
73502a279b | |||
85b64bbc10 | |||
6d0ab33757 | |||
74d7ea7000 | |||
cdfe481d60 | |||
0ff87614ea | |||
2cb9f85081 | |||
d8e559ab50 | |||
3849a9b86f | |||
71b9d1d916 | |||
4b9dbe969c | |||
2136f7490f | |||
3586ffbc0a | |||
f78a2a36cf | |||
a8219253e9 | |||
5c35f7af0a | |||
d55e1a3e22 | |||
21a6a49ce9 | |||
3735023cef | |||
89992dc781 |
79
.github/workflows/release.yml
vendored
Normal file
79
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
name: Create novel-plus Maven Release with ZIPs
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
# 匹配所有以'v'开头的标签
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up JDK 21
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
java-version: '21'
|
||||||
|
# 可选,默认是 temurin,也可以选择其他发行版
|
||||||
|
distribution: 'temurin'
|
||||||
|
|
||||||
|
- name: Build project with Maven
|
||||||
|
run: mvn clean install -DskipTests=true -Pcentral-repo
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
id: create_release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
# 使用 tag_name 而不是 github.ref
|
||||||
|
tag_name: ${{ github.ref_name }}
|
||||||
|
release_name: novel-plus ${{ github.ref_name }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
|
||||||
|
|
||||||
|
# 使用 action 来替代直接 curl 进行上传
|
||||||
|
- name: Upload sql.zip
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: ${{ github.workspace }}/novel-common/target/build/sql.zip
|
||||||
|
asset_name: sql.zip
|
||||||
|
asset_content_type: application/zip
|
||||||
|
|
||||||
|
- name: Upload novel-crawl.zip
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: ${{ github.workspace }}/novel-crawl/target/build/novel-crawl.zip
|
||||||
|
asset_name: novel-crawl.zip
|
||||||
|
asset_content_type: application/zip
|
||||||
|
|
||||||
|
- name: Upload novel-front.zip
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: ${{ github.workspace }}/novel-front/target/build/novel-front.zip
|
||||||
|
asset_name: novel-front.zip
|
||||||
|
asset_content_type: application/zip
|
||||||
|
|
||||||
|
- name: Upload novel-admin.zip
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: ${{ github.workspace }}/novel-admin/target/build/novel-admin.zip
|
||||||
|
asset_name: novel-admin.zip
|
||||||
|
asset_content_type: application/zip
|
@ -1,11 +1,12 @@
|
|||||||
[]( https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=736e609d66e0ac4e57813316cec6fd0b&from=console )
|
<p align="center">
|
||||||
|
<a href="https://www.swiftproxy.net/?code=T2WV1VT50"><img src="https://xxyopen.com/images/ad1.png" alt="AD" ></a>
|
||||||
|
<a href="https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=736e609d66e0ac4e57813316cec6fd0b&from=console"><img src="https://youdoc.github.io/img/tencent.jpg" alt="AD" ></a>
|
||||||
|
</p>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href='https://github.com/201206030/novel-plus'><img alt="Github stars" src="https://img.shields.io/github/stars/201206030/novel-plus?logo=github"></a>
|
<a href='https://github.com/201206030/novel-plus'><img alt="Github stars" src="https://img.shields.io/github/stars/201206030/novel-plus?logo=github"></a>
|
||||||
<a href='https://github.com/201206030/novel-plus'><img alt="Github forks" src="https://img.shields.io/github/forks/201206030/novel-plus?logo=github"></a>
|
<a href='https://github.com/201206030/novel-plus'><img alt="Github forks" src="https://img.shields.io/github/forks/201206030/novel-plus?logo=github"></a>
|
||||||
<a href='https://gitee.com/novel_dev_team/novel-plus'><img alt="Gitee stars" src="https://gitee.com/novel_dev_team/novel-plus/badge/star.svg?theme=gitee"></a>
|
<a href='https://gitee.com/novel_dev_team/novel-plus'><img alt="Gitee stars" src="https://gitee.com/novel_dev_team/novel-plus/badge/star.svg?theme=gitee"></a>
|
||||||
<a href='https://gitee.com/novel_dev_team/novel-plus'><img alt="Gitee forks" src="https://gitee.com/novel_dev_team/novel-plus/badge/fork.svg?theme=gitee"></a>
|
<a href='https://gitee.com/novel_dev_team/novel-plus'><img alt="Gitee forks" src="https://gitee.com/novel_dev_team/novel-plus/badge/fork.svg?theme=gitee"></a>
|
||||||
<a href="https://github.com/201206030/novel-plus"><img src="https://visitor-badge.glitch.me/badge?page_id=201206030.novel-plus" alt="visitors"></a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@ -41,6 +42,7 @@ novel-plus -- 父工程
|
|||||||
| 技术 | 说明
|
| 技术 | 说明
|
||||||
|---------------------| ---------------------------
|
|---------------------| ---------------------------
|
||||||
| Spring Boot | Spring 应用快速开发脚手架
|
| Spring Boot | Spring 应用快速开发脚手架
|
||||||
|
| Spring AI | Spring 官方 AI 框架
|
||||||
| MyBatis | 持久层 ORM 框架
|
| MyBatis | 持久层 ORM 框架
|
||||||
| MyBatis Dynamic SQL | Mybatis 动态 sql
|
| MyBatis Dynamic SQL | Mybatis 动态 sql
|
||||||
| PageHelper | MyBatis 分页插件
|
| PageHelper | MyBatis 分页插件
|
||||||
|
53
config/shardingsphere-jdbc.yml
Normal file
53
config/shardingsphere-jdbc.yml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
mode:
|
||||||
|
# 单机模式
|
||||||
|
type: Standalone
|
||||||
|
# 元数据持久化
|
||||||
|
repository:
|
||||||
|
# 数据库持久化
|
||||||
|
type: JDBC
|
||||||
|
|
||||||
|
# 数据源配置
|
||||||
|
dataSources:
|
||||||
|
ds_1:
|
||||||
|
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||||
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
jdbcUrl: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||||
|
username: root
|
||||||
|
password: test123456
|
||||||
|
ds_2:
|
||||||
|
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||||
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
url: jdbc:mysql://localhost:3306/information_schema?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||||
|
username: root
|
||||||
|
password: test123456
|
||||||
|
# 规则配置
|
||||||
|
rules:
|
||||||
|
- !SINGLE
|
||||||
|
tables:
|
||||||
|
- "*.*"
|
||||||
|
- !SHARDING
|
||||||
|
tables: # 数据分片规则配置
|
||||||
|
book_content:
|
||||||
|
# 分库策略,缺省表示使用默认分库策略
|
||||||
|
actualDataNodes: ds_${1}.book_content${0..9}
|
||||||
|
# 分表策略
|
||||||
|
tableStrategy:
|
||||||
|
standard:
|
||||||
|
# 分片列名称
|
||||||
|
shardingColumn: index_id
|
||||||
|
# 分片算法名称
|
||||||
|
shardingAlgorithmName: bookContentSharding
|
||||||
|
|
||||||
|
shardingAlgorithms:
|
||||||
|
bookContentSharding:
|
||||||
|
# 行表达式分片算法,使用 Groovy 的表达式,提供对 SQL 语句中的 = 和 IN 的分片操作支持
|
||||||
|
type: INLINE
|
||||||
|
props:
|
||||||
|
# 分片算法的行表达式
|
||||||
|
algorithm-expression: book_content${index_id % 10}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
props:
|
||||||
|
# 是否在日志中打印 SQL
|
||||||
|
sql-show: true
|
44
doc/sql/20250317.sql
Normal file
44
doc/sql/20250317.sql
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
INSERT INTO crawl_source (source_name, crawl_rule, source_status, create_time, update_time)
|
||||||
|
VALUES ('香书小说网', '{
|
||||||
|
"bookListUrl": "http://www.xbiqugu.la/fenlei/{catId}_{page}.html",
|
||||||
|
"catIdRule": {
|
||||||
|
"catId1": "1",
|
||||||
|
"catId2": "2",
|
||||||
|
"catId3": "3",
|
||||||
|
"catId4": "4",
|
||||||
|
"catId5": "6",
|
||||||
|
"catId6": "5"
|
||||||
|
},
|
||||||
|
"bookIdPatten": "<a\\\\s+href=\\"http://www.xbiqugu.la/(\\\\d+/\\\\d+)/\\"\\\\s+target=\\"_blank\\">",
|
||||||
|
"pagePatten": "<em\\\\s+id=\\"pagestats\\">(\\\\d+)/\\\\d+</em>",
|
||||||
|
"totalPagePatten": "<em\\\\s+id=\\"pagestats\\">\\\\d+/(\\\\d+)</em>",
|
||||||
|
"bookDetailUrl": "http://www.xbiqugu.la/{bookId}/",
|
||||||
|
"bookNamePatten": "<h1>([^/]+)</h1>",
|
||||||
|
"authorNamePatten": "者:([^/]+)</p>",
|
||||||
|
"picUrlPatten": "src=\\"(http://www.xbiqugu.la/files/article/image/\\\\d+/\\\\d+/\\\\d+s\\\\.jpg)\\"",
|
||||||
|
"bookStatusRule": {},
|
||||||
|
"descStart": "<div id=\\"intro\\">",
|
||||||
|
"descEnd": "</div>",
|
||||||
|
"upadateTimePatten": "<p>最后更新:(\\\\d+-\\\\d+-\\\\d+\\\\s\\\\d+:\\\\d+:\\\\d+)</p>",
|
||||||
|
"upadateTimeFormatPatten": "yyyy-MM-dd HH:mm:ss",
|
||||||
|
"bookIndexUrl": "http://www.xbiqugu.la/{bookId}/",
|
||||||
|
"indexIdPatten": "<a\\\\s+href=''/\\\\d+/\\\\d+/(\\\\d+)\\\\.html''\\\\s+>[^/]+</a>",
|
||||||
|
"indexNamePatten": "<a\\\\s+href=''/\\\\d+/\\\\d+/\\\\d+\\\\.html''\\\\s+>([^/]+)</a>",
|
||||||
|
"bookContentUrl": "http://www.xbiqugu.la/{bookId}/{indexId}.html",
|
||||||
|
"contentStart": "<div id=\\"content\\">",
|
||||||
|
"contentEnd": "<p>",
|
||||||
|
"filterContent":"<div\\\\s+id=\\"content_tip\\">\\\\s*<b>([^/]+)</b>\\\\s*</div>"
|
||||||
|
}', 0, '2024-06-01 10:11:39', '2024-06-01 10:11:39');
|
||||||
|
|
||||||
|
|
||||||
|
update crawl_source
|
||||||
|
set crawl_rule = replace(crawl_rule, 'ibiquzw.org', 'biquxs.info')
|
||||||
|
where id = 16;
|
||||||
|
|
||||||
|
delete
|
||||||
|
from sys_menu
|
||||||
|
where menu_id = 104;
|
||||||
|
|
||||||
|
delete
|
||||||
|
from sys_menu
|
||||||
|
where menu_id = 57;
|
@ -1,7 +1,5 @@
|
|||||||
CREATE
|
CREATE database if NOT EXISTS `novel_plus` default character set utf8mb4 collate utf8mb4_unicode_ci;
|
||||||
database if NOT EXISTS `novel_plus` default character set utf8mb4 collate utf8mb4_unicode_ci;
|
use `novel_plus`;
|
||||||
use
|
|
||||||
`novel_plus`;
|
|
||||||
|
|
||||||
SET NAMES utf8mb4;
|
SET NAMES utf8mb4;
|
||||||
|
|
||||||
@ -3105,4 +3103,54 @@ where id = 16;
|
|||||||
update website_info
|
update website_info
|
||||||
set logo = '/images/logo.png',
|
set logo = '/images/logo.png',
|
||||||
logo_dark='/images/logo.png'
|
logo_dark='/images/logo.png'
|
||||||
where id = 1;
|
where id = 1;
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO crawl_source (source_name, crawl_rule, source_status, create_time, update_time)
|
||||||
|
VALUES ('香书小说网', '{
|
||||||
|
"bookListUrl": "http://www.xbiqugu.net/fenlei/{catId}_{page}.html",
|
||||||
|
"catIdRule": {
|
||||||
|
"catId1": "1",
|
||||||
|
"catId2": "2",
|
||||||
|
"catId3": "3",
|
||||||
|
"catId4": "4",
|
||||||
|
"catId5": "6",
|
||||||
|
"catId6": "5"
|
||||||
|
},
|
||||||
|
"bookIdPatten": "<a\\\\s+href=\\"http://www.xbiqugu.net/(\\\\d+/\\\\d+)/\\"\\\\s+target=\\"_blank\\">",
|
||||||
|
"pagePatten": "<em\\\\s+id=\\"pagestats\\">(\\\\d+)/\\\\d+</em>",
|
||||||
|
"totalPagePatten": "<em\\\\s+id=\\"pagestats\\">\\\\d+/(\\\\d+)</em>",
|
||||||
|
"bookDetailUrl": "http://www.xbiqugu.net/{bookId}/",
|
||||||
|
"bookNamePatten": "<h1>([^/]+)</h1>",
|
||||||
|
"authorNamePatten": "者:([^/]+)</p>",
|
||||||
|
"picUrlPatten": "src=\\"(http://www.xbiqugu.net/files/article/image/\\\\d+/\\\\d+/\\\\d+s\\\\.jpg)\\"",
|
||||||
|
"bookStatusRule": {},
|
||||||
|
"descStart": "<div id=\\"intro\\">",
|
||||||
|
"descEnd": "</div>",
|
||||||
|
"upadateTimePatten": "<p>最后更新:(\\\\d+-\\\\d+-\\\\d+\\\\s\\\\d+:\\\\d+:\\\\d+)</p>",
|
||||||
|
"upadateTimeFormatPatten": "yyyy-MM-dd HH:mm:ss",
|
||||||
|
"bookIndexUrl": "http://www.xbiqugu.net/{bookId}/",
|
||||||
|
"indexIdPatten": "<a\\\\s+href=''/\\\\d+/\\\\d+/(\\\\d+)\\\\.html''\\\\s+>[^/]+</a>",
|
||||||
|
"indexNamePatten": "<a\\\\s+href=''/\\\\d+/\\\\d+/\\\\d+\\\\.html''\\\\s+>([^/]+)</a>",
|
||||||
|
"bookContentUrl": "http://www.xbiqugu.net/{bookId}/{indexId}.html",
|
||||||
|
"contentStart": "<div id=\\"content\\">",
|
||||||
|
"contentEnd": "<p>",
|
||||||
|
"filterContent":"<div\\\\s+id=\\"content_tip\\">\\\\s*<b>([^/]+)</b>\\\\s*</div>"
|
||||||
|
}', 0, '2024-06-01 10:11:39', '2024-06-01 10:11:39');
|
||||||
|
|
||||||
|
|
||||||
|
update crawl_source
|
||||||
|
set crawl_rule = replace(crawl_rule, 'ibiquzw.org', 'biquxs.info')
|
||||||
|
where id = 16;
|
||||||
|
|
||||||
|
|
||||||
|
update crawl_source
|
||||||
|
set crawl_rule = replace(crawl_rule, 'xbiqugu.net', 'xbiqugu.la');
|
||||||
|
|
||||||
|
delete
|
||||||
|
from sys_menu
|
||||||
|
where menu_id = 104;
|
||||||
|
|
||||||
|
delete
|
||||||
|
from sys_menu
|
||||||
|
where menu_id = 57;
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.java2nb</groupId>
|
<groupId>com.java2nb</groupId>
|
||||||
<artifactId>novel-admin</artifactId>
|
<artifactId>novel-admin</artifactId>
|
||||||
<version>4.3.0</version>
|
<version>5.0.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>novel-admin</name>
|
<name>novel-admin</name>
|
||||||
@ -14,18 +14,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.1.18.RELEASE</version>
|
<version>2.7.18</version>
|
||||||
<relativePath/>
|
<relativePath/>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<java.version>21</java.version>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<velocity.version>1.7</velocity.version>
|
<velocity.version>1.7</velocity.version>
|
||||||
<activiti.version>5.22.0</activiti.version>
|
<shardingsphere-jdbc.version>5.5.1</shardingsphere-jdbc.version>
|
||||||
<sharding.jdbc.version>3.0.0</sharding.jdbc.version>
|
|
||||||
<jackson.version>2.15.1</jackson.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -60,35 +56,24 @@
|
|||||||
<groupId>net.sourceforge.nekohtml</groupId>
|
<groupId>net.sourceforge.nekohtml</groupId>
|
||||||
<artifactId>nekohtml</artifactId>
|
<artifactId>nekohtml</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 请求参数校验相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.validator</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
</dependency>
|
||||||
<!--mybatis -->
|
<!--mybatis -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>8.0.29</version>
|
<version>8.0.29</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.mybatis</groupId>
|
|
||||||
<artifactId>mybatis</artifactId>
|
|
||||||
<version>3.5.6</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
<version>1.1.1</version>
|
<version>1.1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--druid -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba</groupId>
|
|
||||||
<artifactId>druid</artifactId>
|
|
||||||
<version>1.2.9</version>
|
|
||||||
</dependency>
|
|
||||||
<!--commons -->
|
<!--commons -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>3.6</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-configuration</groupId>
|
<groupId>commons-configuration</groupId>
|
||||||
<artifactId>commons-configuration</artifactId>
|
<artifactId>commons-configuration</artifactId>
|
||||||
@ -138,6 +123,12 @@
|
|||||||
<groupId>org.apache.velocity</groupId>
|
<groupId>org.apache.velocity</groupId>
|
||||||
<artifactId>velocity</artifactId>
|
<artifactId>velocity</artifactId>
|
||||||
<version>1.7</version>
|
<version>1.7</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--<dependency>-->
|
<!--<dependency>-->
|
||||||
<!--<groupId>org.springframework.boot</groupId>-->
|
<!--<groupId>org.springframework.boot</groupId>-->
|
||||||
@ -166,6 +157,12 @@
|
|||||||
<groupId>io.springfox</groupId>
|
<groupId>io.springfox</groupId>
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
<version>2.6.1</version>
|
<version>2.6.1</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>io.springfox</groupId>
|
||||||
@ -195,24 +192,29 @@
|
|||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-text</artifactId>
|
<artifactId>commons-text</artifactId>
|
||||||
<version>1.4</version>
|
<version>1.4</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- ShardingSphere-JDBC -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.shardingsphere</groupId>
|
<groupId>org.apache.shardingsphere</groupId>
|
||||||
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
<artifactId>shardingsphere-jdbc</artifactId>
|
||||||
<version>${sharding.jdbc.version}</version>
|
<version>${shardingsphere-jdbc.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.shardingsphere</groupId>
|
<groupId>org.yaml</groupId>
|
||||||
<artifactId>sharding-jdbc-spring-namespace</artifactId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
<version>${sharding.jdbc.version}</version>
|
<version>2.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>${jackson.version}</version>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--war包部署需要-->
|
<!--war包部署需要-->
|
||||||
@ -330,4 +332,35 @@
|
|||||||
</snapshots>
|
</snapshots>
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<!-- 定义一个用于切换到中央仓库的profile -->
|
||||||
|
<id>central-repo</id>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<url>https://repo.maven.apache.org/maven2/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>central-plugin</id>
|
||||||
|
<url>https://repo.maven.apache.org/maven2/</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
#端口号
|
|
||||||
server:
|
|
||||||
port: 8088
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
redis:
|
|
||||||
host: 127.0.0.1
|
|
||||||
port: 6379
|
|
||||||
password: test123456
|
|
||||||
|
|
||||||
sharding:
|
|
||||||
jdbc:
|
|
||||||
datasource:
|
|
||||||
ds0:
|
|
||||||
jdbc-url: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
9
novel-admin/src/main/build/config/application.yml
Normal file
9
novel-admin/src/main/build/config/application.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#端口号
|
||||||
|
server:
|
||||||
|
port: 8088
|
||||||
|
spring:
|
||||||
|
redis:
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 6379
|
||||||
|
password: test123456
|
||||||
|
|
47
novel-admin/src/main/build/config/shardingsphere-jdbc.yml
Normal file
47
novel-admin/src/main/build/config/shardingsphere-jdbc.yml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
mode:
|
||||||
|
# 单机模式
|
||||||
|
type: Standalone
|
||||||
|
# 元数据持久化
|
||||||
|
repository:
|
||||||
|
# 数据库持久化
|
||||||
|
type: JDBC
|
||||||
|
|
||||||
|
# 数据源配置
|
||||||
|
dataSources:
|
||||||
|
ds_1:
|
||||||
|
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||||
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
jdbcUrl: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||||
|
username: root
|
||||||
|
password: test123456
|
||||||
|
# 规则配置
|
||||||
|
rules:
|
||||||
|
- !SINGLE
|
||||||
|
tables:
|
||||||
|
- "*.*"
|
||||||
|
- !SHARDING
|
||||||
|
tables: # 数据分片规则配置
|
||||||
|
book_content:
|
||||||
|
# 分库策略,缺省表示使用默认分库策略
|
||||||
|
actualDataNodes: ds_${1}.book_content${0..9}
|
||||||
|
# 分表策略
|
||||||
|
tableStrategy:
|
||||||
|
standard:
|
||||||
|
# 分片列名称
|
||||||
|
shardingColumn: index_id
|
||||||
|
# 分片算法名称
|
||||||
|
shardingAlgorithmName: bookContentSharding
|
||||||
|
|
||||||
|
shardingAlgorithms:
|
||||||
|
bookContentSharding:
|
||||||
|
# 行表达式分片算法,使用 Groovy 的表达式,提供对 SQL 语句中的 = 和 IN 的分片操作支持
|
||||||
|
type: INLINE
|
||||||
|
props:
|
||||||
|
# 分片算法的行表达式
|
||||||
|
algorithm-expression: book_content${index_id % 10}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
props:
|
||||||
|
# 是否在日志中打印 SQL
|
||||||
|
sql-show: true
|
@ -11,27 +11,37 @@ import org.springframework.context.ApplicationContext;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.sql.Connection;
|
||||||
|
|
||||||
|
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@ServletComponentScan
|
@ServletComponentScan
|
||||||
@MapperScan("com.java2nb.*.dao")
|
@MapperScan("com.java2nb.*.dao")
|
||||||
@SpringBootApplication(exclude = {
|
@SpringBootApplication(exclude = {
|
||||||
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
|
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
|
||||||
})
|
})
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AdminApplication {
|
public class AdminApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(AdminApplication.class, args);
|
SpringApplication.run(AdminApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
|
public CommandLineRunner commandLineRunner(ApplicationContext ctx, DataSource dataSource) {
|
||||||
return args -> {
|
return args -> {
|
||||||
log.info("项目启动啦,访问路径:{}", "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + ctx.getEnvironment().getProperty("server.port"));
|
log.info("创建连接池...");
|
||||||
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
|
log.info("连接池已创建.");
|
||||||
|
log.info("数据库:{}", connection.getMetaData().getDatabaseProductName());
|
||||||
|
log.info("数据库版本:{}", connection.getMetaData().getDatabaseProductVersion());
|
||||||
|
}
|
||||||
|
log.info("项目启动啦,访问路径:{}",
|
||||||
|
"http://" + InetAddress.getLocalHost().getHostAddress() + ":" + ctx.getEnvironment()
|
||||||
|
.getProperty("server.port"));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
package com.java2nb.common.aspect;
|
package com.java2nb.common.aspect;
|
||||||
|
|
||||||
import com.java2nb.common.utils.HttpContextUtils;
|
import com.java2nb.common.utils.IPUtils;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.*;
|
import org.aspectj.lang.annotation.*;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
import sun.net.util.IPAddressUtil;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
@ -37,11 +34,10 @@ public class WebLogAspect {
|
|||||||
logger.info("请求地址 : " + request.getRequestURL().toString());
|
logger.info("请求地址 : " + request.getRequestURL().toString());
|
||||||
logger.info("HTTP METHOD : " + request.getMethod());
|
logger.info("HTTP METHOD : " + request.getMethod());
|
||||||
// 获取真实的ip地址
|
// 获取真实的ip地址
|
||||||
//logger.info("IP : " + IPAddressUtil.getClientIpAddress(request));
|
logger.info("IP : " + IPUtils.getIpAddr(request));
|
||||||
logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
|
logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
|
||||||
+ joinPoint.getSignature().getName());
|
+ joinPoint.getSignature().getName());
|
||||||
logger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
|
logger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
|
||||||
// loggger.info("参数 : " + joinPoint.getArgs());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,132 +0,0 @@
|
|||||||
package com.java2nb.common.config;
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
|
||||||
import com.alibaba.druid.support.http.StatViewServlet;
|
|
||||||
import com.alibaba.druid.support.http.WebStatFilter;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
||||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by PrimaryKey on 17/2/4.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("AlibabaRemoveCommentedCode")
|
|
||||||
@Configuration
|
|
||||||
public class DruidDBConfig {
|
|
||||||
private Logger logger = LoggerFactory.getLogger(DruidDBConfig.class);
|
|
||||||
@Value("${spring.datasource.url}")
|
|
||||||
private String dbUrl;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.username}")
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.driverClassName}")
|
|
||||||
private String driverClassName;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.initialSize}")
|
|
||||||
private int initialSize;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.minIdle}")
|
|
||||||
private int minIdle;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.maxActive}")
|
|
||||||
private int maxActive;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.maxWait}")
|
|
||||||
private int maxWait;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
|
|
||||||
private int timeBetweenEvictionRunsMillis;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.minEvictableIdleTimeMillis}")
|
|
||||||
private int minEvictableIdleTimeMillis;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.validationQuery}")
|
|
||||||
private String validationQuery;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.testWhileIdle}")
|
|
||||||
private boolean testWhileIdle;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.testOnBorrow}")
|
|
||||||
private boolean testOnBorrow;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.testOnReturn}")
|
|
||||||
private boolean testOnReturn;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.poolPreparedStatements}")
|
|
||||||
private boolean poolPreparedStatements;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}")
|
|
||||||
private int maxPoolPreparedStatementPerConnectionSize;
|
|
||||||
|
|
||||||
@Value("${spring.datasource.filters}")
|
|
||||||
private String filters;
|
|
||||||
|
|
||||||
@Value("{spring.datasource.connectionProperties}")
|
|
||||||
private String connectionProperties;
|
|
||||||
|
|
||||||
@Bean(initMethod = "init", destroyMethod = "close") //声明其为Bean实例
|
|
||||||
@Primary //在同样的DataSource中,首先使用被标注的DataSource
|
|
||||||
public DataSource dataSource() {
|
|
||||||
DruidDataSource datasource = new DruidDataSource();
|
|
||||||
|
|
||||||
datasource.setUrl(this.dbUrl);
|
|
||||||
datasource.setUsername(username);
|
|
||||||
datasource.setPassword(password);
|
|
||||||
datasource.setDriverClassName(driverClassName);
|
|
||||||
|
|
||||||
//configuration
|
|
||||||
datasource.setInitialSize(initialSize);
|
|
||||||
datasource.setMinIdle(minIdle);
|
|
||||||
datasource.setMaxActive(maxActive);
|
|
||||||
datasource.setMaxWait(maxWait);
|
|
||||||
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
|
|
||||||
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
|
|
||||||
datasource.setValidationQuery(validationQuery);
|
|
||||||
datasource.setTestWhileIdle(testWhileIdle);
|
|
||||||
datasource.setTestOnBorrow(testOnBorrow);
|
|
||||||
datasource.setTestOnReturn(testOnReturn);
|
|
||||||
datasource.setPoolPreparedStatements(poolPreparedStatements);
|
|
||||||
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
|
|
||||||
try {
|
|
||||||
datasource.setFilters(filters);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
logger.error("druid configuration initialization filter", e);
|
|
||||||
}
|
|
||||||
datasource.setConnectionProperties(connectionProperties);
|
|
||||||
|
|
||||||
return datasource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ServletRegistrationBean druidServlet() {
|
|
||||||
ServletRegistrationBean reg = new ServletRegistrationBean();
|
|
||||||
reg.setServlet(new StatViewServlet());
|
|
||||||
reg.addUrlMappings("/druid/*");
|
|
||||||
reg.addInitParameter("allow", ""); //白名单
|
|
||||||
return reg;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean public FilterRegistrationBean filterRegistrationBean() {
|
|
||||||
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
|
|
||||||
filterRegistrationBean.setFilter(new WebStatFilter());
|
|
||||||
filterRegistrationBean.addUrlPatterns("/*");
|
|
||||||
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
|
|
||||||
filterRegistrationBean.addInitParameter("profileEnable", "true");
|
|
||||||
filterRegistrationBean.addInitParameter("principalCookieName","USER_COOKIE");
|
|
||||||
filterRegistrationBean.addInitParameter("principalSessionName","USER_SESSION");
|
|
||||||
filterRegistrationBean.addInitParameter("DruidWebStatFilter","/*");
|
|
||||||
return filterRegistrationBean;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
|||||||
package com.java2nb.common.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.service.Contact;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ${DESCRIPTION}
|
|
||||||
*
|
|
||||||
* @author xiongxy
|
|
||||||
* @create 2019-11-02 23:53
|
|
||||||
*/
|
|
||||||
@EnableSwagger2
|
|
||||||
@Configuration
|
|
||||||
public class Swagger2Config {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket createRestApi() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.select()
|
|
||||||
//为当前包路径
|
|
||||||
.apis(RequestHandlerSelectors.any())
|
|
||||||
.paths(PathSelectors.any())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
//构建 api文档的详细信息函数
|
|
||||||
private ApiInfo apiInfo() {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
//页面标题
|
|
||||||
.title("功能测试")
|
|
||||||
//创建人
|
|
||||||
.contact(new Contact("xiongxy", "1179705413@qq.com", "1179705413@qq.com"))
|
|
||||||
//版本号
|
|
||||||
.version("1.0")
|
|
||||||
//描述
|
|
||||||
.description("API 描述")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,25 +9,25 @@ import java.util.Map;
|
|||||||
public interface GeneratorMapper {
|
public interface GeneratorMapper {
|
||||||
|
|
||||||
@Select(
|
@Select(
|
||||||
"select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables"
|
"select table_name tableName, engine, table_comment tableComment, create_time createTime from tables"
|
||||||
+ " where table_schema = 'novel_plus' and table_name like concat('%',#{tableName},'%')")
|
+ " where table_schema = 'novel_plus' and table_name like concat('%',#{tableName},'%')")
|
||||||
List<Map<String, Object>> list(@Param("tableName") String tableName);
|
List<Map<String, Object>> list(@Param("tableName") String tableName);
|
||||||
|
|
||||||
@Select("select count(*) from information_schema.tables where table_schema = 'novel_plus'")
|
@Select("select count(*) from tables where table_schema = 'novel_plus'")
|
||||||
int count(Map<String, Object> map);
|
int count(Map<String, Object> map);
|
||||||
|
|
||||||
@Select(
|
@Select(
|
||||||
"select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables \r\n"
|
"select table_name tableName, engine, table_comment tableComment, create_time createTime from tables \r\n"
|
||||||
+ " where table_schema = 'novel_plus' and table_name = #{tableName}")
|
+ " where table_schema = 'novel_plus' and table_name = #{tableName}")
|
||||||
Map<String, String> get(String tableName);
|
Map<String, String> get(String tableName);
|
||||||
|
|
||||||
@Select(
|
@Select(
|
||||||
"select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns\r\n"
|
"select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from columns\r\n"
|
||||||
+ " where table_name = #{tableName} and table_schema = 'novel_plus' order by ordinal_position")
|
+ " where table_name = #{tableName} and table_schema = 'novel_plus' order by ordinal_position")
|
||||||
List<Map<String, String>> listColumns(String tableName);
|
List<Map<String, String>> listColumns(String tableName);
|
||||||
|
|
||||||
@Select(
|
@Select(
|
||||||
"select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns\r\n"
|
"select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from columns\r\n"
|
||||||
+ " where table_name = #{tableName} and table_schema = 'novel_plus' and column_key = 'PRI' limit 1")
|
+ " where table_name = #{tableName} and table_schema = 'novel_plus' and column_key = 'PRI' limit 1")
|
||||||
Map<String, String> getPriColumn(String tableName);
|
Map<String, String> getPriColumn(String tableName);
|
||||||
}
|
}
|
||||||
|
@ -2,32 +2,27 @@ package com.java2nb.common.exception;
|
|||||||
|
|
||||||
|
|
||||||
import com.java2nb.common.utils.R;
|
import com.java2nb.common.utils.R;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
||||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class MainsiteErrorController implements ErrorController {
|
public class MainsiteErrorController implements ErrorController {
|
||||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
||||||
private static final String ERROR_PATH = "/error";
|
private static final String ERROR_PATH = "/error";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ErrorAttributes errorAttributes;
|
ErrorAttributes errorAttributes;
|
||||||
|
|
||||||
@RequestMapping(
|
@RequestMapping(
|
||||||
value = {ERROR_PATH},
|
value = {ERROR_PATH},
|
||||||
produces = {"text/html"}
|
produces = {"text/html"}
|
||||||
)
|
)
|
||||||
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
|
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
|
||||||
int code = response.getStatus();
|
int code = response.getStatus();
|
||||||
@ -58,9 +53,4 @@ public class MainsiteErrorController implements ErrorController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getErrorPath() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return ERROR_PATH;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package com.java2nb.common.utils;
|
package com.java2nb.common.utils;
|
||||||
|
|
||||||
import com.alibaba.druid.util.StringUtils;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
|
||||||
@ -8,79 +7,80 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class JSONUtils {
|
public class JSONUtils {
|
||||||
/**
|
|
||||||
* Bean对象转JSON
|
|
||||||
*
|
|
||||||
* @param object
|
|
||||||
* @param dataFormatString
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String beanToJson(Object object, String dataFormatString) {
|
|
||||||
if (object != null) {
|
|
||||||
if (StringUtils.isEmpty(dataFormatString)) {
|
|
||||||
return JSONObject.toJSONString(object);
|
|
||||||
}
|
|
||||||
return JSON.toJSONStringWithDateFormat(object, dataFormatString);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bean对象转JSON
|
* Bean对象转JSON
|
||||||
*
|
*
|
||||||
* @param object
|
* @param object
|
||||||
* @return
|
* @param dataFormatString
|
||||||
*/
|
* @return
|
||||||
public static String beanToJson(Object object) {
|
*/
|
||||||
if (object != null) {
|
public static String beanToJson(Object object, String dataFormatString) {
|
||||||
return JSON.toJSONString(object);
|
if (object != null) {
|
||||||
} else {
|
if (StringUtils.isEmpty(dataFormatString)) {
|
||||||
return null;
|
return JSONObject.toJSONString(object);
|
||||||
}
|
}
|
||||||
}
|
return JSON.toJSONStringWithDateFormat(object, dataFormatString);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String转JSON字符串
|
* Bean对象转JSON
|
||||||
*
|
*
|
||||||
* @param key
|
* @param object
|
||||||
* @param value
|
* @return
|
||||||
* @return
|
*/
|
||||||
*/
|
public static String beanToJson(Object object) {
|
||||||
public static String stringToJsonByFastjson(String key, String value) {
|
if (object != null) {
|
||||||
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
|
return JSON.toJSONString(object);
|
||||||
return null;
|
} else {
|
||||||
}
|
return null;
|
||||||
Map<String, String> map = new HashMap<String, String>(16);
|
}
|
||||||
map.put(key, value);
|
}
|
||||||
return beanToJson(map, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将json字符串转换成对象
|
* String转JSON字符串
|
||||||
*
|
*
|
||||||
* @param json
|
* @param key
|
||||||
* @param clazz
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Object jsonToBean(String json, Object clazz) {
|
public static String stringToJsonByFastjson(String key, String value) {
|
||||||
if (StringUtils.isEmpty(json) || clazz == null) {
|
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return JSON.parseObject(json, clazz.getClass());
|
Map<String, String> map = new HashMap<String, String>(16);
|
||||||
}
|
map.put(key, value);
|
||||||
|
return beanToJson(map, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* json字符串转map
|
* 将json字符串转换成对象
|
||||||
*
|
*
|
||||||
* @param json
|
* @param json
|
||||||
* @return
|
* @param clazz
|
||||||
*/
|
* @return
|
||||||
@SuppressWarnings("unchecked")
|
*/
|
||||||
public static Map<String, Object> jsonToMap(String json) {
|
public static Object jsonToBean(String json, Object clazz) {
|
||||||
if (StringUtils.isEmpty(json)) {
|
if (StringUtils.isEmpty(json) || clazz == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return JSON.parseObject(json, Map.class);
|
return JSON.parseObject(json, clazz.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* json字符串转map
|
||||||
|
*
|
||||||
|
* @param json
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static Map<String, Object> jsonToMap(String json) {
|
||||||
|
if (StringUtils.isEmpty(json)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JSON.parseObject(json, Map.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,92 +7,11 @@ logging:
|
|||||||
root: info
|
root: info
|
||||||
com.java2nb: debug
|
com.java2nb: debug
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
|
||||||
url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
#password:
|
|
||||||
initialSize: 1
|
|
||||||
minIdle: 3
|
|
||||||
maxActive: 20
|
|
||||||
# 配置获取连接等待超时的时间
|
|
||||||
maxWait: 60000
|
|
||||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
|
||||||
timeBetweenEvictionRunsMillis: 60000
|
|
||||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
|
||||||
minEvictableIdleTimeMillis: 30000
|
|
||||||
validationQuery: select 'x'
|
|
||||||
testWhileIdle: true
|
|
||||||
testOnBorrow: false
|
|
||||||
testOnReturn: false
|
|
||||||
# 打开PSCache,并且指定每个连接上PSCache的大小
|
|
||||||
poolPreparedStatements: true
|
|
||||||
maxPoolPreparedStatementPerConnectionSize: 20
|
|
||||||
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
|
|
||||||
filters: stat,slf4j
|
|
||||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
|
||||||
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
|
||||||
# 合并多个DruidDataSource的监控数据
|
|
||||||
#useGlobalDataSourceStat: true
|
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: 6379
|
port: 6379
|
||||||
password: test123456
|
password: test123456
|
||||||
# 连接超时时间(毫秒)
|
# 连接超时时间(毫秒)
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
jedis:
|
|
||||||
pool:
|
|
||||||
# 连接池中的最大空闲连接
|
|
||||||
max-idle: 8
|
|
||||||
# 连接池中的最小空闲连接
|
|
||||||
min-idle: 10
|
|
||||||
# 连接池最大连接数(使用负值表示没有限制)
|
|
||||||
max-active: 100
|
|
||||||
# 连接池最大阻塞等待时间(使用负值表示没有限制)
|
|
||||||
max-wait: -1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
####使用shardingJdbc时,
|
|
||||||
####所有的jdbcType都不能是LONGVARCHAR,否则会导致java.io.NotSerializableException: java.io.StringReader错误
|
|
||||||
##### 应该替换所有的 LONGVARCHAR 类型为VARCHAR
|
|
||||||
|
|
||||||
sharding:
|
|
||||||
jdbc:
|
|
||||||
datasource:
|
|
||||||
names: ds0,ds1
|
|
||||||
ds0:
|
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
jdbc-url: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
ds1:
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
|
||||||
url: jdbc:mysql://localhost:3306/information_schema?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
config:
|
|
||||||
sharding:
|
|
||||||
props:
|
|
||||||
sql.show: true
|
|
||||||
tables:
|
|
||||||
book_content: #book_content表
|
|
||||||
key-generator-column-name: id #主键
|
|
||||||
actual-data-nodes: ds${0}.book_content${0..9} #数据节点
|
|
||||||
# database-strategy: #分库策略
|
|
||||||
# inline:
|
|
||||||
# sharding-column: book_id
|
|
||||||
# algorithm-expression: ds${book_id % 10}
|
|
||||||
table-strategy: #分表策略
|
|
||||||
inline:
|
|
||||||
shardingColumn: index_id
|
|
||||||
algorithm-expression: book_content${index_id % 10}
|
|
||||||
tables:
|
|
||||||
actual-data-nodes: ds${1}.tables
|
|
||||||
columns:
|
|
||||||
actual-data-nodes: ds${1}.columns
|
|
||||||
default-data-source-name: ds0
|
|
@ -7,86 +7,11 @@ logging:
|
|||||||
root: error
|
root: error
|
||||||
com.java2nb: error
|
com.java2nb: error
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
|
||||||
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
#password:
|
|
||||||
initialSize: 1
|
|
||||||
minIdle: 3
|
|
||||||
maxActive: 20
|
|
||||||
# 配置获取连接等待超时的时间
|
|
||||||
maxWait: 60000
|
|
||||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
|
||||||
timeBetweenEvictionRunsMillis: 60000
|
|
||||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
|
||||||
minEvictableIdleTimeMillis: 30000
|
|
||||||
validationQuery: select 'x'
|
|
||||||
testWhileIdle: true
|
|
||||||
testOnBorrow: false
|
|
||||||
testOnReturn: false
|
|
||||||
# 打开PSCache,并且指定每个连接上PSCache的大小
|
|
||||||
poolPreparedStatements: true
|
|
||||||
maxPoolPreparedStatementPerConnectionSize: 20
|
|
||||||
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
|
|
||||||
filters: stat,slf4j
|
|
||||||
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
|
||||||
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
|
||||||
# 合并多个DruidDataSource的监控数据
|
|
||||||
#useGlobalDataSourceStat: true
|
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: 6379
|
port: 6379
|
||||||
password: test
|
password: test123456
|
||||||
# 连接超时时间(毫秒)
|
# 连接超时时间(毫秒)
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
jedis:
|
|
||||||
pool:
|
|
||||||
# 连接池中的最大空闲连接
|
|
||||||
max-idle: 8
|
|
||||||
# 连接池中的最小空闲连接
|
|
||||||
min-idle: 10
|
|
||||||
# 连接池最大连接数(使用负值表示没有限制)
|
|
||||||
max-active: 100
|
|
||||||
# 连接池最大阻塞等待时间(使用负值表示没有限制)
|
|
||||||
max-wait: -1
|
|
||||||
|
|
||||||
|
|
||||||
####使用shardingJdbc时,
|
|
||||||
####所有的jdbcType都不能是LONGVARCHAR,否则会导致java.io.NotSerializableException: java.io.StringReader错误
|
|
||||||
##### 应该替换所有的 LONGVARCHAR 类型为VARCHAR
|
|
||||||
|
|
||||||
sharding:
|
|
||||||
jdbc:
|
|
||||||
datasource:
|
|
||||||
names: ds0 #,ds1
|
|
||||||
ds0:
|
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
jdbc-url: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
# ds1:
|
|
||||||
# type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
# driver-class-name: com.mysql.jdbc.Driver
|
|
||||||
# url: jdbc:mysql://localhost:3306/novel_plus2
|
|
||||||
# username: root
|
|
||||||
# password: test123456
|
|
||||||
config:
|
|
||||||
sharding:
|
|
||||||
props:
|
|
||||||
sql.show: true
|
|
||||||
tables:
|
|
||||||
book_content: #book_content表
|
|
||||||
key-generator-column-name: id #主键
|
|
||||||
actual-data-nodes: ds${0}.book_content${0..9} #数据节点
|
|
||||||
# database-strategy: #分库策略
|
|
||||||
# inline:
|
|
||||||
# sharding-column: book_id
|
|
||||||
# algorithm-expression: ds${book_id % 10}
|
|
||||||
table-strategy: #分表策略
|
|
||||||
inline:
|
|
||||||
shardingColumn: index_id
|
|
||||||
algorithm-expression: book_content${index_id % 10}
|
|
||||||
|
@ -9,6 +9,9 @@ server:
|
|||||||
# basic:
|
# basic:
|
||||||
# enabled: false
|
# enabled: false
|
||||||
spring:
|
spring:
|
||||||
|
datasource:
|
||||||
|
driverClassName: org.apache.shardingsphere.driver.ShardingSphereDriver
|
||||||
|
url: jdbc:shardingsphere:absolutepath:${user.dir}/config/shardingsphere-jdbc.yml
|
||||||
thymeleaf:
|
thymeleaf:
|
||||||
mode: LEGACYHTML5
|
mode: LEGACYHTML5
|
||||||
cache: false
|
cache: false
|
||||||
@ -23,10 +26,7 @@ spring:
|
|||||||
multipart:
|
multipart:
|
||||||
max-file-size: 100MB
|
max-file-size: 100MB
|
||||||
max-request-size: 100MB
|
max-request-size: 100MB
|
||||||
|
|
||||||
devtools:
|
|
||||||
restart:
|
|
||||||
enabled: true
|
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
@ -36,9 +36,6 @@ mybatis:
|
|||||||
map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
mapper-locations: mybatis/**/*Mapper.xml
|
mapper-locations: mybatis/**/*Mapper.xml
|
||||||
typeAliasesPackage: com.java2nb.**.domain
|
typeAliasesPackage: com.java2nb.**.domain
|
||||||
#[弃用]配置缓存和session存储方式,默认ehcache,可选redis,[弃用]调整至 spring cache type【shiro.用户,权限,session,spring.cache通用】
|
|
||||||
#[弃用]cacheType: ehcache
|
|
||||||
|
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
config: classpath:logback-boot.xml
|
config: classpath:logback-boot.xml
|
||||||
|
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 162 KiB |
@ -79,7 +79,7 @@ function update() {
|
|||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.code == 0) {
|
if (data.code == 0) {
|
||||||
layer.msg("操作成功");
|
layer.msg("操作成功,重启 novel-front 后生效");
|
||||||
} else {
|
} else {
|
||||||
layer.alert(data.msg)
|
layer.alert(data.msg)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<title>小说精品屋 - 文件管理器</title>
|
<title>小说精品屋 - 文件管理器</title>
|
||||||
<meta name="keywords" content="">
|
<meta name="keywords" content="">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<link rel="shortcut icon" href="favicon.ico">
|
<link rel="shortcut icon" href="/favicon.ico">
|
||||||
<link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
<link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
||||||
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
||||||
<link href="/css/animate.css" rel="stylesheet">
|
<link href="/css/animate.css" rel="stylesheet">
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<title>403 页面</title>
|
<title>403 页面</title>
|
||||||
<meta name="keywords" content="">
|
<meta name="keywords" content="">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<link rel="shortcut icon" href="favicon.ico">
|
<link rel="shortcut icon" href="/favicon.ico">
|
||||||
<link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
<link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
||||||
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
||||||
<link href="/css/animate.css" rel="stylesheet">
|
<link href="/css/animate.css" rel="stylesheet">
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<meta name="keywords" content="">
|
<meta name="keywords" content="">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
|
|
||||||
<link rel="shortcut icon" href="favicon.ico"> <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
<link rel="shortcut icon" href="/favicon.ico"> <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
||||||
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
||||||
|
|
||||||
<link href="/css/animate.css" rel="stylesheet">
|
<link href="/css/animate.css" rel="stylesheet">
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<meta name="keywords" content="">
|
<meta name="keywords" content="">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
|
|
||||||
<link rel="shortcut icon" href="favicon.ico"> <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
<link rel="shortcut icon" href="/favicon.ico"> <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
||||||
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
||||||
|
|
||||||
<link href="/css/animate.css" rel="stylesheet">
|
<link href="/css/animate.css" rel="stylesheet">
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<title>500错误</title>
|
<title>500错误</title>
|
||||||
<meta name="keywords" content="">
|
<meta name="keywords" content="">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<link rel="shortcut icon" href="favicon.ico"> <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
<link rel="shortcut icon" href="/favicon.ico"> <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
||||||
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
||||||
<link href="/css/animate.css" rel="stylesheet">
|
<link href="/css/animate.css" rel="stylesheet">
|
||||||
<link href="/css/style.css?v=4.1.0" rel="stylesheet">
|
<link href="/css/style.css?v=4.1.0" rel="stylesheet">
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<title></title>
|
<title></title>
|
||||||
<meta name="keywords" content="">
|
<meta name="keywords" content="">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<link rel="shortcut icon" href="favicon.ico">
|
<link rel="shortcut icon" href="/favicon.ico">
|
||||||
<link href="css/bootstrap.min.css?v=3.3.6"
|
<link href="css/bootstrap.min.css?v=3.3.6"
|
||||||
th:href="@{/css/bootstrap.min.css?v=3.3.6}" rel="stylesheet">
|
th:href="@{/css/bootstrap.min.css?v=3.3.6}" rel="stylesheet">
|
||||||
<link href="/css/font-awesome.css?v=4.4.0"
|
<link href="/css/font-awesome.css?v=4.4.0"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<meta http-equiv="refresh" content="0;ie.html"/>
|
<meta http-equiv="refresh" content="0;ie.html"/>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
<link rel="shortcut icon" href="favicon.ico">
|
<link rel="shortcut icon" href="/favicon.ico">
|
||||||
<link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
<link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
||||||
<link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
|
<link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
|
||||||
<link href="/css/plugins/toastr/toastr.min.css" rel="stylesheet">
|
<link href="/css/plugins/toastr/toastr.min.css" rel="stylesheet">
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<meta name="keywords" content="">
|
<meta name="keywords" content="">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
|
|
||||||
<link rel="shortcut icon" href="favicon.ico">
|
<link rel="shortcut icon" href="/favicon.ico">
|
||||||
<link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
<link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
|
||||||
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
<link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
|
||||||
<link href="/css/animate.css" rel="stylesheet">
|
<link href="/css/animate.css" rel="stylesheet">
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<title></title>
|
<title></title>
|
||||||
<meta name="keywords" content="">
|
<meta name="keywords" content="">
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<link rel="shortcut icon" href="favicon.ico">
|
<link rel="shortcut icon" href="/favicon.ico">
|
||||||
<link rel="stylesheet" href="/css/bootstrap.min.css" />
|
<link rel="stylesheet" href="/css/bootstrap.min.css" />
|
||||||
<link rel="stylesheet" href="/css/animate.css" />
|
<link rel="stylesheet" href="/css/animate.css" />
|
||||||
<link rel="stylesheet" href="/css/font-awesome.css" />
|
<link rel="stylesheet" href="/css/font-awesome.css" />
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>novel</artifactId>
|
<artifactId>novel</artifactId>
|
||||||
<groupId>com.java2nb</groupId>
|
<groupId>com.java2nb</groupId>
|
||||||
<version>4.3.0</version>
|
<version>5.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -52,18 +52,16 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 分库分表-->
|
<!-- 分库分表-->
|
||||||
<!-- sharding jdbc依赖 -->
|
<!-- ShardingSphere-JDBC -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.shardingsphere</groupId>
|
<groupId>org.apache.shardingsphere</groupId>
|
||||||
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
<artifactId>shardingsphere-jdbc</artifactId>
|
||||||
<version>${sharding.jdbc.version}</version>
|
<version>${shardingsphere-jdbc.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.shardingsphere</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>sharding-jdbc-spring-namespace</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>${sharding.jdbc.version}</version>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
@ -73,11 +71,6 @@
|
|||||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
<version>${pagehelper.version}</version>
|
<version>${pagehelper.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.cuisongliu</groupId>
|
|
||||||
<artifactId>orderbyhelper-spring-boot-starter</artifactId>
|
|
||||||
<version>${orderbyhelper.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
@ -86,15 +79,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<!--httpclient-->
|
<!--httpclient-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient5</artifactId>
|
||||||
<version>4.5.14</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-logging</groupId>
|
|
||||||
<artifactId>commons-logging</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -117,6 +103,12 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 请求参数校验相关 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.validator</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.xxyopen</groupId>
|
<groupId>io.github.xxyopen</groupId>
|
||||||
<artifactId>xxy-model</artifactId>
|
<artifactId>xxy-model</artifactId>
|
||||||
@ -138,5 +130,29 @@
|
|||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>1.8</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<tasks>
|
||||||
|
<zip destfile='${project.build.directory}/build/sql.zip'>
|
||||||
|
<zipfileset filemode="755" dir='${basedir}/../doc/sql'/>
|
||||||
|
</zip>
|
||||||
|
</tasks>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.java2nb.novel.core.advice;
|
||||||
|
|
||||||
|
import io.github.xxyopen.model.resp.RestResult;
|
||||||
|
import io.github.xxyopen.model.resp.SysResultCode;
|
||||||
|
import io.github.xxyopen.web.exception.BusinessException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.validation.BindException;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一异常处理器
|
||||||
|
*
|
||||||
|
* @author xiongxiaoyang
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestControllerAdvice
|
||||||
|
public class CommonExceptionHandler {
|
||||||
|
|
||||||
|
public CommonExceptionHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler({BindException.class})
|
||||||
|
public RestResult<Void> handlerBindException(BindException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return RestResult.fail(SysResultCode.PARAM_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler({BusinessException.class})
|
||||||
|
public RestResult<Void> handlerBusinessException(BusinessException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return RestResult.fail(e.getResultCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(Exception.class)
|
||||||
|
public Object handleException(HttpServletRequest request, Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
if (isJsonRequest(request)) {
|
||||||
|
// 如果是REST请求,返回JSON格式的错误响应
|
||||||
|
return RestResult.error();
|
||||||
|
} else {
|
||||||
|
//跳转页面过程中出现异常时统一跳转到404页面
|
||||||
|
return new ModelAndView("404");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isJsonRequest(HttpServletRequest request) {
|
||||||
|
String acceptHeader = request.getHeader("Accept");
|
||||||
|
return acceptHeader != null && acceptHeader.contains(MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,26 +0,0 @@
|
|||||||
package com.java2nb.novel.core.advice;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 页面异常处理器
|
|
||||||
*
|
|
||||||
* @author 11797
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@ControllerAdvice(basePackages = "com.java2nb.novel.controller.page")
|
|
||||||
public class PageExceptionHandler {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理所有异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(Exception.class)
|
|
||||||
public String handlerException(Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
//跳转页面过程中出现异常时统一跳转到404页面
|
|
||||||
return "404";
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,4 +19,8 @@ public class HttpProxyProperties {
|
|||||||
|
|
||||||
private Integer port;
|
private Integer port;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import lombok.SneakyThrows;
|
|||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.codec.Charsets;
|
import org.apache.commons.codec.Charsets;
|
||||||
import org.apache.http.client.utils.DateUtils;
|
import org.apache.hc.client5.http.utils.DateUtils;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@ -14,7 +14,10 @@ import org.springframework.http.ResponseEntity;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -37,10 +40,13 @@ public class FileUtil {
|
|||||||
//本地图片保存
|
//本地图片保存
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
||||||
ResponseEntity<Resource> resEntity = RestTemplateUtil.getInstance(Charsets.ISO_8859_1.name()).exchange(picSrc, HttpMethod.GET, requestEntity, Resource.class);
|
ResponseEntity<Resource> resEntity = RestTemplates.newInstance(Charsets.ISO_8859_1.name())
|
||||||
|
.exchange(picSrc, HttpMethod.GET, requestEntity, Resource.class);
|
||||||
input = Objects.requireNonNull(resEntity.getBody()).getInputStream();
|
input = Objects.requireNonNull(resEntity.getBody()).getInputStream();
|
||||||
Date currentDate = new Date();
|
Date currentDate = new Date();
|
||||||
picSrc = visitPrefix + DateUtils.formatDate(currentDate, "yyyy") + "/" + DateUtils.formatDate(currentDate, "MM") + "/" + DateUtils.formatDate(currentDate, "dd") + "/"
|
picSrc =
|
||||||
|
visitPrefix + DateUtils.formatDate(currentDate, "yyyy") + "/" + DateUtils.formatDate(currentDate, "MM")
|
||||||
|
+ "/" + DateUtils.formatDate(currentDate, "dd") + "/"
|
||||||
+ UUIDUtil.getUUID32()
|
+ UUIDUtil.getUUID32()
|
||||||
+ picSrc.substring(picSrc.lastIndexOf("."));
|
+ picSrc.substring(picSrc.lastIndexOf("."));
|
||||||
File picFile = new File(picSavePath + picSrc);
|
File picFile = new File(picSavePath + picSrc);
|
||||||
@ -67,7 +73,6 @@ public class FileUtil {
|
|||||||
closeStream(input, out);
|
closeStream(input, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return picSrc;
|
return picSrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,47 +1,52 @@
|
|||||||
package com.java2nb.novel.core.utils;
|
package com.java2nb.novel.core.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class HttpUtil {
|
public class HttpUtil {
|
||||||
|
|
||||||
private static RestTemplate restTemplate = RestTemplateUtil.getInstance("utf-8");
|
private static final String DEFAULT_CHARSET = "utf-8";
|
||||||
|
|
||||||
|
private static final Map<String, RestTemplate> REST_TEMPLATE_MAP = new HashMap<>();
|
||||||
|
|
||||||
public static String getByHttpClient(String url) {
|
public static String getByHttpClientWithChrome(String url, String charset) {
|
||||||
|
log.debug("Get url:{}", url);
|
||||||
|
if (!Charset.isSupported(charset)) {
|
||||||
|
log.error("字符编码{}无效!", charset);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RestTemplate restTemplate = REST_TEMPLATE_MAP.computeIfAbsent(charset,
|
||||||
|
k -> RestTemplates.newInstance(charset));
|
||||||
try {
|
try {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
|
headers.add("user-agent",
|
||||||
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36");
|
||||||
|
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
||||||
|
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity,
|
||||||
|
String.class);
|
||||||
|
log.debug("Response code:{}", forEntity.getStatusCode());
|
||||||
if (forEntity.getStatusCode() == HttpStatus.OK) {
|
if (forEntity.getStatusCode() == HttpStatus.OK) {
|
||||||
return forEntity.getBody();
|
return forEntity.getBody();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getByHttpClientWithChrome(String url) {
|
public static String getByHttpClientWithChrome(String url) {
|
||||||
try {
|
return getByHttpClientWithChrome(url, DEFAULT_CHARSET);
|
||||||
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.add("user-agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36");
|
|
||||||
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
|
||||||
ResponseEntity<String> forEntity = restTemplate.exchange(url.toString(), HttpMethod.GET, requestEntity, String.class);
|
|
||||||
|
|
||||||
if (forEntity.getStatusCode() == HttpStatus.OK) {
|
|
||||||
return forEntity.getBody();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.java2nb.novel.core.utils;
|
package com.java2nb.novel.core.utils;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
public class IpUtil {
|
public class IpUtil {
|
||||||
|
|
||||||
|
@ -2,17 +2,22 @@ package com.java2nb.novel.core.utils;
|
|||||||
|
|
||||||
import com.java2nb.novel.core.config.HttpProxyProperties;
|
import com.java2nb.novel.core.config.HttpProxyProperties;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.config.Registry;
|
import org.apache.hc.client5.http.auth.AuthScope;
|
||||||
import org.apache.http.config.RegistryBuilder;
|
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
|
||||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
|
||||||
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
||||||
import org.apache.http.conn.ssl.TrustStrategy;
|
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
|
||||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
|
||||||
|
import org.apache.hc.core5.http.HttpHost;
|
||||||
|
import org.apache.hc.core5.http.config.Registry;
|
||||||
|
import org.apache.hc.core5.http.config.RegistryBuilder;
|
||||||
|
import org.apache.hc.core5.ssl.SSLContexts;
|
||||||
|
import org.apache.hc.core5.ssl.TrustStrategy;
|
||||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
@ -26,21 +31,21 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class RestTemplateUtil {
|
public class RestTemplates {
|
||||||
|
|
||||||
private static HttpProxyProperties httpProxyProperties;
|
private static HttpProxyProperties httpProxyProperties;
|
||||||
|
|
||||||
RestTemplateUtil(HttpProxyProperties properties) {
|
RestTemplates(HttpProxyProperties properties) {
|
||||||
httpProxyProperties = properties;
|
httpProxyProperties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static RestTemplate getInstance(String charset) {
|
public static RestTemplate newInstance(String charset) {
|
||||||
|
|
||||||
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
|
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
|
||||||
|
|
||||||
//忽略证书
|
//忽略证书
|
||||||
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
|
SSLContext sslContext = SSLContexts.custom()
|
||||||
.loadTrustMaterial(null, acceptingTrustStrategy)
|
.loadTrustMaterial(null, acceptingTrustStrategy)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -61,6 +66,15 @@ public class RestTemplateUtil {
|
|||||||
if (Objects.nonNull(httpProxyProperties) && Boolean.TRUE.equals(httpProxyProperties.getEnabled())) {
|
if (Objects.nonNull(httpProxyProperties) && Boolean.TRUE.equals(httpProxyProperties.getEnabled())) {
|
||||||
HttpHost proxy = new HttpHost(httpProxyProperties.getIp(), httpProxyProperties.getPort());
|
HttpHost proxy = new HttpHost(httpProxyProperties.getIp(), httpProxyProperties.getPort());
|
||||||
clientBuilder.setProxy(proxy);
|
clientBuilder.setProxy(proxy);
|
||||||
|
if (StringUtils.isNotBlank(httpProxyProperties.getUsername()) && StringUtils.isNotBlank(
|
||||||
|
httpProxyProperties.getPassword())) {
|
||||||
|
// 创建CredentialsProvider实例并添加代理认证信息
|
||||||
|
BasicCredentialsProvider provider = new BasicCredentialsProvider();
|
||||||
|
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
|
||||||
|
httpProxyProperties.getUsername(), httpProxyProperties.getPassword().toCharArray());
|
||||||
|
provider.setCredentials(new AuthScope(null, -1), credentials);
|
||||||
|
clientBuilder.setDefaultCredentialsProvider(provider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CloseableHttpClient httpClient = clientBuilder.setConnectionManager(connectionManager)
|
CloseableHttpClient httpClient = clientBuilder.setConnectionManager(connectionManager)
|
||||||
.build();
|
.build();
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.java2nb.novel.core.utils;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SpringUtil implements ApplicationContextAware {
|
||||||
|
private static ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
public SpringUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||||
|
if (SpringUtil.applicationContext == null) {
|
||||||
|
SpringUtil.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationContext getApplicationContext() {
|
||||||
|
return applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getBean(String name) {
|
||||||
|
return getApplicationContext().getBean(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getBean(Class<T> clazz) {
|
||||||
|
return (T)getApplicationContext().getBean(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getBean(String name, Class<T> clazz) {
|
||||||
|
return (T)getApplicationContext().getBean(name, clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,9 +2,9 @@ package com.java2nb.novel.entity;
|
|||||||
|
|
||||||
import io.github.xxyopen.web.valid.AddGroup;
|
import io.github.xxyopen.web.valid.AddGroup;
|
||||||
import io.github.xxyopen.web.valid.UpdateGroup;
|
import io.github.xxyopen.web.valid.UpdateGroup;
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
|
||||||
import javax.annotation.Generated;
|
import javax.annotation.Generated;
|
||||||
import javax.validation.constraints.*;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class User {
|
public class User {
|
||||||
|
@ -1,71 +1,18 @@
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
config:
|
||||||
include: [ common ]
|
import: classpath:application-common.yml
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
#Redis服务器IP
|
#Redis服务器IP
|
||||||
redis:
|
data:
|
||||||
host: 127.0.0.1
|
redis:
|
||||||
#Redis服务器连接端口
|
host: 127.0.0.1
|
||||||
port: 6379
|
#Redis服务器连接端口
|
||||||
#Redis服务器连接密码
|
port: 6379
|
||||||
password: test123456
|
#Redis服务器连接密码
|
||||||
jedis:
|
password: test123456
|
||||||
pool:
|
#连接超时时间(毫秒)
|
||||||
#连接池最大连接数(使用负值表示没有限制)
|
timeout: 10000
|
||||||
max-active: 8
|
|
||||||
#连接池最大阻塞等待时间(使用负值表示没有限制)
|
|
||||||
max-wait: 1
|
|
||||||
#连接池最大阻塞等待时间(使用负值表示没有限制)
|
|
||||||
max-idle: 8
|
|
||||||
#连接池中的最小空闲连接
|
|
||||||
min-idle: 0
|
|
||||||
#连接超时时间(毫秒)
|
|
||||||
timeout: 30000
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
|
|
||||||
|
|
||||||
####使用shardingJdbc时,
|
|
||||||
####所有的jdbcType都不能是LONGVARCHAR,否则会导致java.io.NotSerializableException: java.io.StringReader错误
|
|
||||||
##### 应该替换所有的 LONGVARCHAR 类型为VARCHAR
|
|
||||||
|
|
||||||
sharding:
|
|
||||||
jdbc:
|
|
||||||
datasource:
|
|
||||||
names: ds0 #,ds1
|
|
||||||
ds0:
|
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
jdbc-url: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
# ds1:
|
|
||||||
# type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
# driver-class-name: com.mysql.jdbc.Driver
|
|
||||||
# url: jdbc:mysql://localhost:3306/novel_plus2
|
|
||||||
# username: root
|
|
||||||
# password: test123456
|
|
||||||
config:
|
|
||||||
sharding:
|
|
||||||
props:
|
|
||||||
sql.show: true
|
|
||||||
tables:
|
|
||||||
book_content: #book_content表
|
|
||||||
key-generator-column-name: id #主键
|
|
||||||
actual-data-nodes: ds${0}.book_content${0..9} #数据节点
|
|
||||||
# database-strategy: #分库策略
|
|
||||||
# inline:
|
|
||||||
# sharding-column: book_id
|
|
||||||
# algorithm-expression: ds${book_id % 10}
|
|
||||||
table-strategy: #分表策略
|
|
||||||
inline:
|
|
||||||
shardingColumn: index_id
|
|
||||||
algorithm-expression: book_content${index_id % 10}
|
|
||||||
|
|
||||||
|
|
||||||
content:
|
content:
|
||||||
save:
|
save:
|
||||||
@ -78,6 +25,10 @@ http:
|
|||||||
# 是否开启 HTTP 代理,true-开启,false-不开启
|
# 是否开启 HTTP 代理,true-开启,false-不开启
|
||||||
enabled: false
|
enabled: false
|
||||||
# 代理 IP
|
# 代理 IP
|
||||||
ip: u493.kdltps.com
|
ip: us.swiftproxy.net
|
||||||
# 代理端口号
|
# 代理端口号
|
||||||
port: 15818
|
port: 7878
|
||||||
|
# 代理用户名
|
||||||
|
username: swiftproxy_u
|
||||||
|
# 代理密码
|
||||||
|
password: swiftproxy_p
|
@ -1,71 +1,18 @@
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
config:
|
||||||
include: [ common ]
|
import: classpath:application-common.yml
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
#Redis服务器IP
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 127.0.0.1
|
#Redis服务器IP
|
||||||
#Redis服务器连接端口
|
host: 127.0.0.1
|
||||||
port: 6379
|
#Redis服务器连接端口
|
||||||
#Redis服务器连接密码
|
port: 6379
|
||||||
password: test
|
#Redis服务器连接密码
|
||||||
jedis:
|
password: test123456
|
||||||
pool:
|
#连接超时时间(毫秒)
|
||||||
#连接池最大连接数(使用负值表示没有限制)
|
timeout: 10000
|
||||||
max-active: 8
|
|
||||||
#连接池最大阻塞等待时间(使用负值表示没有限制)
|
|
||||||
max-wait: 1
|
|
||||||
#连接池最大阻塞等待时间(使用负值表示没有限制)
|
|
||||||
max-idle: 8
|
|
||||||
#连接池中的最小空闲连接
|
|
||||||
min-idle: 0
|
|
||||||
#连接超时时间(毫秒)
|
|
||||||
timeout: 30000
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://127.0.0.1:3306/novel_biz?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
|
|
||||||
|
|
||||||
####使用shardingJdbc时,
|
|
||||||
####所有的jdbcType都不能是LONGVARCHAR,否则会导致java.io.NotSerializableException: java.io.StringReader错误
|
|
||||||
##### 应该替换所有的 LONGVARCHAR 类型为VARCHAR
|
|
||||||
|
|
||||||
sharding:
|
|
||||||
jdbc:
|
|
||||||
datasource:
|
|
||||||
names: ds0 #,ds1
|
|
||||||
ds0:
|
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
jdbc-url: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
# ds1:
|
|
||||||
# type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
# driver-class-name: com.mysql.jdbc.Driver
|
|
||||||
# url: jdbc:mysql://localhost:3306/novel_plus2
|
|
||||||
# username: root
|
|
||||||
# password: test123456
|
|
||||||
config:
|
|
||||||
sharding:
|
|
||||||
props:
|
|
||||||
sql.show: true
|
|
||||||
tables:
|
|
||||||
book_content: #book_content表
|
|
||||||
key-generator-column-name: id #主键
|
|
||||||
actual-data-nodes: ds${0}.book_content${0..9} #数据节点
|
|
||||||
# database-strategy: #分库策略
|
|
||||||
# inline:
|
|
||||||
# sharding-column: book_id
|
|
||||||
# algorithm-expression: ds${book_id % 10}
|
|
||||||
table-strategy: #分表策略
|
|
||||||
inline:
|
|
||||||
shardingColumn: index_id
|
|
||||||
algorithm-expression: book_content${index_id % 10}
|
|
||||||
|
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
spring:
|
spring:
|
||||||
cache:
|
datasource:
|
||||||
ehcache:
|
url: jdbc:shardingsphere:absolutepath:${user.dir}/config/shardingsphere-jdbc.yml
|
||||||
config: classpath:ehcache.xml
|
driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
|
||||||
thymeleaf:
|
thymeleaf:
|
||||||
mode: LEGACYHTML5 #去除thymeleaf的html严格校验thymeleaf.mode=LEGACYHTML5
|
mode: LEGACYHTML5 #去除thymeleaf的html严格校验thymeleaf.mode=LEGACYHTML5
|
||||||
cache: false # 是否开启模板缓存,默认true,建议在开发时关闭缓存,不然没法看到实时
|
cache: false # 是否开启模板缓存,默认true,建议在开发时关闭缓存,不然没法看到实时
|
||||||
@ -27,6 +27,8 @@ mybatis:
|
|||||||
logging:
|
logging:
|
||||||
config: classpath:logback-boot.xml
|
config: classpath:logback-boot.xml
|
||||||
|
|
||||||
|
pagehelper:
|
||||||
|
helper-dialect: mysql
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>novel</artifactId>
|
<artifactId>novel</artifactId>
|
||||||
<groupId>com.java2nb</groupId>
|
<groupId>com.java2nb</groupId>
|
||||||
<version>4.3.0</version>
|
<version>5.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -21,6 +21,12 @@
|
|||||||
<artifactId>novel-common</artifactId>
|
<artifactId>novel-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
@ -29,7 +35,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
#端口号
|
|
||||||
server:
|
|
||||||
port: 8083
|
|
||||||
|
|
||||||
#不分表的数据库配置
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: root
|
|
||||||
redis:
|
|
||||||
host: 127.0.0.1
|
|
||||||
port: 6379
|
|
||||||
password: test123456
|
|
||||||
|
|
||||||
####使用shardingJdbc时,
|
|
||||||
####所有的jdbcType都不能是LONGVARCHAR,否则会导致java.io.NotSerializableException: java.io.StringReader错误
|
|
||||||
##### 应该替换所有的 LONGVARCHAR 类型为VARCHAR
|
|
||||||
sharding:
|
|
||||||
jdbc:
|
|
||||||
datasource:
|
|
||||||
ds0:
|
|
||||||
jdbc-url: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
|
|
||||||
#登录用户名密码
|
|
||||||
admin:
|
|
||||||
username: admin
|
|
||||||
password: admin
|
|
||||||
#
|
|
||||||
##爬虫自动更新的线程数
|
|
||||||
##建议小说数量不多或者正在运行新书入库爬虫的情况下设置为1即可
|
|
||||||
##随着小说数量的增多可以逐渐增加,但建议不要超出CPU的线程数
|
|
||||||
crawl:
|
|
||||||
update:
|
|
||||||
thread: 1
|
|
||||||
|
|
||||||
#小说内容保存配置
|
|
||||||
content:
|
|
||||||
save:
|
|
||||||
storage: db # 小说内容存储方式:db-数据库,txt-TXT文本
|
|
||||||
path: /Users/xiongxiaoyang/books # 小说TXT文本保存路径
|
|
||||||
|
|
||||||
# HTTP 代理配置
|
|
||||||
http:
|
|
||||||
proxy:
|
|
||||||
# 是否开启 HTTP 代理,true-开启,false-不开启
|
|
||||||
enabled: false
|
|
||||||
# 代理 IP
|
|
||||||
ip: u493.kdltps.com
|
|
||||||
# 代理端口号
|
|
||||||
port: 15818
|
|
47
novel-crawl/src/main/build/config/application.yml
Normal file
47
novel-crawl/src/main/build/config/application.yml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#端口号
|
||||||
|
server:
|
||||||
|
port: 8083
|
||||||
|
|
||||||
|
spring:
|
||||||
|
data:
|
||||||
|
redis:
|
||||||
|
#Redis服务器IP
|
||||||
|
host: 127.0.0.1
|
||||||
|
#Redis服务器连接端口
|
||||||
|
port: 6379
|
||||||
|
#Redis服务器连接密码
|
||||||
|
password: test123456
|
||||||
|
#连接超时时间(毫秒)
|
||||||
|
timeout: 10000
|
||||||
|
|
||||||
|
#登录用户名密码
|
||||||
|
admin:
|
||||||
|
username: admin
|
||||||
|
password: admin
|
||||||
|
#
|
||||||
|
##爬虫自动更新的线程数
|
||||||
|
##建议小说数量不多或者正在运行新书入库爬虫的情况下设置为1即可
|
||||||
|
##随着小说数量的增多可以逐渐增加,但建议不要超出CPU的线程数
|
||||||
|
crawl:
|
||||||
|
update:
|
||||||
|
thread: 1
|
||||||
|
|
||||||
|
#小说内容保存配置
|
||||||
|
content:
|
||||||
|
save:
|
||||||
|
storage: db # 小说内容存储方式:db-数据库,txt-TXT文本
|
||||||
|
path: /Users/xiongxiaoyang/books # 小说TXT文本保存路径
|
||||||
|
|
||||||
|
# HTTP 代理配置
|
||||||
|
http:
|
||||||
|
proxy:
|
||||||
|
# 是否开启 HTTP 代理,true-开启,false-不开启
|
||||||
|
enabled: false
|
||||||
|
# 代理 IP
|
||||||
|
ip: us.swiftproxy.net
|
||||||
|
# 代理端口号
|
||||||
|
port: 7878
|
||||||
|
# 代理用户名
|
||||||
|
username: swiftproxy_u
|
||||||
|
# 代理密码
|
||||||
|
password: swiftproxy_p
|
47
novel-crawl/src/main/build/config/shardingsphere-jdbc.yml
Normal file
47
novel-crawl/src/main/build/config/shardingsphere-jdbc.yml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
mode:
|
||||||
|
# 单机模式
|
||||||
|
type: Standalone
|
||||||
|
# 元数据持久化
|
||||||
|
repository:
|
||||||
|
# 数据库持久化
|
||||||
|
type: JDBC
|
||||||
|
|
||||||
|
# 数据源配置
|
||||||
|
dataSources:
|
||||||
|
ds_1:
|
||||||
|
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||||
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
jdbcUrl: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||||
|
username: root
|
||||||
|
password: test123456
|
||||||
|
# 规则配置
|
||||||
|
rules:
|
||||||
|
- !SINGLE
|
||||||
|
tables:
|
||||||
|
- "*.*"
|
||||||
|
- !SHARDING
|
||||||
|
tables: # 数据分片规则配置
|
||||||
|
book_content:
|
||||||
|
# 分库策略,缺省表示使用默认分库策略
|
||||||
|
actualDataNodes: ds_${1}.book_content${0..9}
|
||||||
|
# 分表策略
|
||||||
|
tableStrategy:
|
||||||
|
standard:
|
||||||
|
# 分片列名称
|
||||||
|
shardingColumn: index_id
|
||||||
|
# 分片算法名称
|
||||||
|
shardingAlgorithmName: bookContentSharding
|
||||||
|
|
||||||
|
shardingAlgorithms:
|
||||||
|
bookContentSharding:
|
||||||
|
# 行表达式分片算法,使用 Groovy 的表达式,提供对 SQL 语句中的 = 和 IN 的分片操作支持
|
||||||
|
type: INLINE
|
||||||
|
props:
|
||||||
|
# 分片算法的行表达式
|
||||||
|
algorithm-expression: book_content${index_id % 10}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
props:
|
||||||
|
# 是否在日志中打印 SQL
|
||||||
|
sql-show: true
|
@ -4,14 +4,15 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.Customizer;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
import org.springframework.security.core.userdetails.User;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SpringSecurity配置
|
* SpringSecurity配置
|
||||||
@ -21,7 +22,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class SecurityConfiguration {
|
||||||
|
|
||||||
@Value("${admin.username}")
|
@Value("${admin.username}")
|
||||||
private String username;
|
private String username;
|
||||||
@ -29,39 +30,40 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
@Value("${admin.password}")
|
@Value("${admin.password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PasswordEncoder passwordEncoder() {
|
public PasswordEncoder passwordEncoder() {
|
||||||
return new BCryptPasswordEncoder();
|
return new BCryptPasswordEncoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
@Override
|
public InMemoryUserDetailsManager userDetailsService() {
|
||||||
public void configure(WebSecurity web) throws Exception {
|
UserDetails admin = User.builder()
|
||||||
super.configure(web);
|
.username(username)
|
||||||
|
.password(passwordEncoder().encode(password))
|
||||||
|
.roles("ADMIN")
|
||||||
|
.build();
|
||||||
|
return new InMemoryUserDetailsManager(admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
public void configure(AuthenticationManagerBuilder auth) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
http
|
||||||
|
.csrf(csrf -> csrf.disable()) // 禁用 CSRF
|
||||||
|
.authorizeHttpRequests(auth -> auth
|
||||||
|
.requestMatchers("/css/**", "/favicon.ico").permitAll() // 允许访问静态资源
|
||||||
|
.anyRequest().hasRole("ADMIN") // 其他请求需要 ADMIN 角色
|
||||||
|
)
|
||||||
|
.formLogin(form -> form
|
||||||
|
.loginPage("/login.html") // 自定义登录页面
|
||||||
|
.loginProcessingUrl("/login") // 登录处理 URL
|
||||||
|
.permitAll()
|
||||||
|
)
|
||||||
|
.logout(logout -> logout
|
||||||
|
.logoutUrl("/logout") // 登出 URL
|
||||||
|
.logoutSuccessUrl("/") // 登出成功后跳转的页面
|
||||||
|
)
|
||||||
|
.httpBasic(Customizer.withDefaults()); // 启用 HTTP Basic 认证
|
||||||
|
|
||||||
User.UserBuilder builder = User.builder().passwordEncoder(passwordEncoder()::encode);
|
return http.build();
|
||||||
auth.inMemoryAuthentication().withUser(builder.username(username).password(password).roles("ADMIN").build());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
|
||||||
http.csrf().disable()
|
|
||||||
.authorizeRequests()
|
|
||||||
.antMatchers("/css/**").permitAll()
|
|
||||||
.antMatchers("/favicon.ico").permitAll()
|
|
||||||
.antMatchers("/**").hasRole("ADMIN")
|
|
||||||
.and().formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll()
|
|
||||||
.and().logout()
|
|
||||||
.logoutUrl("/logout")
|
|
||||||
.logoutSuccessUrl("/")
|
|
||||||
.and().httpBasic();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,23 +1,23 @@
|
|||||||
package com.java2nb.novel.core.crawl;
|
package com.java2nb.novel.core.crawl;
|
||||||
|
|
||||||
import com.java2nb.novel.core.utils.HttpUtil;
|
|
||||||
import com.java2nb.novel.core.utils.RandomBookInfoUtil;
|
import com.java2nb.novel.core.utils.RandomBookInfoUtil;
|
||||||
import com.java2nb.novel.core.utils.RestTemplateUtil;
|
|
||||||
import com.java2nb.novel.core.utils.StringUtil;
|
import com.java2nb.novel.core.utils.StringUtil;
|
||||||
import com.java2nb.novel.entity.Book;
|
import com.java2nb.novel.entity.Book;
|
||||||
import com.java2nb.novel.entity.BookContent;
|
import com.java2nb.novel.entity.BookContent;
|
||||||
import com.java2nb.novel.entity.BookIndex;
|
import com.java2nb.novel.entity.BookIndex;
|
||||||
import com.java2nb.novel.utils.Constants;
|
import com.java2nb.novel.utils.Constants;
|
||||||
|
import com.java2nb.novel.utils.CrawlHttpClient;
|
||||||
import io.github.xxyopen.util.IdWorker;
|
import io.github.xxyopen.util.IdWorker;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -26,20 +26,19 @@ import java.util.regex.Pattern;
|
|||||||
*
|
*
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class CrawlParser {
|
public class CrawlParser {
|
||||||
|
|
||||||
private static final IdWorker idWorker = IdWorker.INSTANCE;
|
private final IdWorker ID_WORKER = IdWorker.INSTANCE;
|
||||||
|
|
||||||
private static final RestTemplate restTemplate = RestTemplateUtil.getInstance("utf-8");
|
private final CrawlHttpClient crawlHttpClient;
|
||||||
|
|
||||||
private static final ThreadLocal<Integer> retryCount = new ThreadLocal<>();
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void parseBook(RuleBean ruleBean, String bookId, CrawlBookHandler handler) {
|
public void parseBook(RuleBean ruleBean, String bookId, CrawlBookHandler handler) {
|
||||||
Book book = new Book();
|
Book book = new Book();
|
||||||
String bookDetailUrl = ruleBean.getBookDetailUrl().replace("{bookId}", bookId);
|
String bookDetailUrl = ruleBean.getBookDetailUrl().replace("{bookId}", bookId);
|
||||||
String bookDetailHtml = getByHttpClientWithChrome(bookDetailUrl);
|
String bookDetailHtml = crawlHttpClient.get(bookDetailUrl, ruleBean.getCharset());
|
||||||
if (bookDetailHtml != null) {
|
if (bookDetailHtml != null) {
|
||||||
Pattern bookNamePatten = PatternFactory.getPattern(ruleBean.getBookNamePatten());
|
Pattern bookNamePatten = PatternFactory.getPattern(ruleBean.getBookNamePatten());
|
||||||
Matcher bookNameMatch = bookNamePatten.matcher(bookDetailHtml);
|
Matcher bookNameMatch = bookNamePatten.matcher(bookDetailHtml);
|
||||||
@ -89,14 +88,15 @@ public class CrawlParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String desc = bookDetailHtml.substring(bookDetailHtml.indexOf(ruleBean.getDescStart()) + ruleBean.getDescStart().length());
|
String desc = bookDetailHtml.substring(
|
||||||
|
bookDetailHtml.indexOf(ruleBean.getDescStart()) + ruleBean.getDescStart().length());
|
||||||
desc = desc.substring(0, desc.indexOf(ruleBean.getDescEnd()));
|
desc = desc.substring(0, desc.indexOf(ruleBean.getDescEnd()));
|
||||||
//过滤掉简介中的特殊标签
|
//过滤掉简介中的特殊标签
|
||||||
desc = desc.replaceAll("<a[^<]+</a>", "")
|
desc = desc.replaceAll("<a[^<]+</a>", "")
|
||||||
.replaceAll("<font[^<]+</font>", "")
|
.replaceAll("<font[^<]+</font>", "")
|
||||||
.replaceAll("<p>\\s*</p>", "")
|
.replaceAll("<p>\\s*</p>", "")
|
||||||
.replaceAll("<p>", "")
|
.replaceAll("<p>", "")
|
||||||
.replaceAll("</p>", "<br/>");
|
.replaceAll("</p>", "<br/>");
|
||||||
//设置书籍简介
|
//设置书籍简介
|
||||||
book.setBookDesc(desc);
|
book.setBookDesc(desc);
|
||||||
if (StringUtils.isNotBlank(ruleBean.getStatusPatten())) {
|
if (StringUtils.isNotBlank(ruleBean.getStatusPatten())) {
|
||||||
@ -112,14 +112,16 @@ public class CrawlParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(ruleBean.getUpadateTimePatten()) && StringUtils.isNotBlank(ruleBean.getUpadateTimeFormatPatten())) {
|
if (StringUtils.isNotBlank(ruleBean.getUpadateTimePatten()) && StringUtils.isNotBlank(
|
||||||
|
ruleBean.getUpadateTimeFormatPatten())) {
|
||||||
Pattern updateTimePatten = PatternFactory.getPattern(ruleBean.getUpadateTimePatten());
|
Pattern updateTimePatten = PatternFactory.getPattern(ruleBean.getUpadateTimePatten());
|
||||||
Matcher updateTimeMatch = updateTimePatten.matcher(bookDetailHtml);
|
Matcher updateTimeMatch = updateTimePatten.matcher(bookDetailHtml);
|
||||||
boolean isFindUpdateTime = updateTimeMatch.find();
|
boolean isFindUpdateTime = updateTimeMatch.find();
|
||||||
if (isFindUpdateTime) {
|
if (isFindUpdateTime) {
|
||||||
String updateTime = updateTimeMatch.group(1);
|
String updateTime = updateTimeMatch.group(1);
|
||||||
//设置更新时间
|
//设置更新时间
|
||||||
book.setLastIndexUpdateTime(new SimpleDateFormat(ruleBean.getUpadateTimeFormatPatten()).parse(updateTime));
|
book.setLastIndexUpdateTime(
|
||||||
|
new SimpleDateFormat(ruleBean.getUpadateTimeFormatPatten()).parse(updateTime));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,7 +143,8 @@ public class CrawlParser {
|
|||||||
handler.handle(book);
|
handler.handle(book);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean parseBookIndexAndContent(String sourceBookId, Book book, RuleBean ruleBean, Map<Integer, BookIndex> existBookIndexMap, CrawlBookChapterHandler handler) {
|
public boolean parseBookIndexAndContent(String sourceBookId, Book book, RuleBean ruleBean,
|
||||||
|
Map<Integer, BookIndex> existBookIndexMap, CrawlBookChapterHandler handler) {
|
||||||
|
|
||||||
Date currentDate = new Date();
|
Date currentDate = new Date();
|
||||||
|
|
||||||
@ -149,11 +152,12 @@ public class CrawlParser {
|
|||||||
List<BookContent> contentList = new ArrayList<>();
|
List<BookContent> contentList = new ArrayList<>();
|
||||||
//读取目录
|
//读取目录
|
||||||
String indexListUrl = ruleBean.getBookIndexUrl().replace("{bookId}", sourceBookId);
|
String indexListUrl = ruleBean.getBookIndexUrl().replace("{bookId}", sourceBookId);
|
||||||
String indexListHtml = getByHttpClientWithChrome(indexListUrl);
|
String indexListHtml = crawlHttpClient.get(indexListUrl, ruleBean.getCharset());
|
||||||
|
|
||||||
if (indexListHtml != null) {
|
if (indexListHtml != null) {
|
||||||
if (StringUtils.isNotBlank(ruleBean.getBookIndexStart())) {
|
if (StringUtils.isNotBlank(ruleBean.getBookIndexStart())) {
|
||||||
indexListHtml = indexListHtml.substring(indexListHtml.indexOf(ruleBean.getBookIndexStart()) + ruleBean.getBookIndexStart().length());
|
indexListHtml = indexListHtml.substring(
|
||||||
|
indexListHtml.indexOf(ruleBean.getBookIndexStart()) + ruleBean.getBookIndexStart().length());
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern indexIdPatten = PatternFactory.getPattern(ruleBean.getIndexIdPatten());
|
Pattern indexIdPatten = PatternFactory.getPattern(ruleBean.getIndexIdPatten());
|
||||||
@ -174,14 +178,16 @@ public class CrawlParser {
|
|||||||
BookIndex hasIndex = existBookIndexMap.get(indexNum);
|
BookIndex hasIndex = existBookIndexMap.get(indexNum);
|
||||||
String indexName = indexNameMatch.group(1);
|
String indexName = indexNameMatch.group(1);
|
||||||
|
|
||||||
if (hasIndex == null || !StringUtils.deleteWhitespace(hasIndex.getIndexName()).equals(StringUtils.deleteWhitespace(indexName))) {
|
if (hasIndex == null || !StringUtils.deleteWhitespace(hasIndex.getIndexName())
|
||||||
|
.equals(StringUtils.deleteWhitespace(indexName))) {
|
||||||
|
|
||||||
String sourceIndexId = indexIdMatch.group(1);
|
String sourceIndexId = indexIdMatch.group(1);
|
||||||
String bookContentUrl = ruleBean.getBookContentUrl();
|
String bookContentUrl = ruleBean.getBookContentUrl();
|
||||||
int calStart = bookContentUrl.indexOf("{cal_");
|
int calStart = bookContentUrl.indexOf("{cal_");
|
||||||
if (calStart != -1) {
|
if (calStart != -1) {
|
||||||
//内容页URL需要进行计算才能得到
|
//内容页URL需要进行计算才能得到
|
||||||
String calStr = bookContentUrl.substring(calStart, calStart + bookContentUrl.substring(calStart).indexOf("}"));
|
String calStr = bookContentUrl.substring(calStart,
|
||||||
|
calStart + bookContentUrl.substring(calStart).indexOf("}"));
|
||||||
String[] calArr = calStr.split("_");
|
String[] calArr = calStr.split("_");
|
||||||
int calType = Integer.parseInt(calArr[1]);
|
int calType = Integer.parseInt(calArr[1]);
|
||||||
if (calType == 1) {
|
if (calType == 1) {
|
||||||
@ -206,13 +212,25 @@ public class CrawlParser {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String contentUrl = bookContentUrl.replace("{bookId}", sourceBookId).replace("{indexId}", sourceIndexId);
|
String contentUrl = bookContentUrl.replace("{bookId}", sourceBookId)
|
||||||
|
.replace("{indexId}", sourceIndexId);
|
||||||
|
|
||||||
//查询章节内容
|
//查询章节内容
|
||||||
String contentHtml = getByHttpClientWithChrome(contentUrl);
|
String contentHtml = crawlHttpClient.get(contentUrl, ruleBean.getCharset());
|
||||||
if (contentHtml != null && !contentHtml.contains("正在手打中")) {
|
if (contentHtml != null && !contentHtml.contains("正在手打中")) {
|
||||||
String content = contentHtml.substring(contentHtml.indexOf(ruleBean.getContentStart()) + ruleBean.getContentStart().length());
|
String content = contentHtml.substring(
|
||||||
|
contentHtml.indexOf(ruleBean.getContentStart()) + ruleBean.getContentStart().length());
|
||||||
content = content.substring(0, content.indexOf(ruleBean.getContentEnd()));
|
content = content.substring(0, content.indexOf(ruleBean.getContentEnd()));
|
||||||
|
// 小说内容过滤
|
||||||
|
String filterContent = ruleBean.getFilterContent();
|
||||||
|
if (StringUtils.isNotBlank(filterContent)) {
|
||||||
|
String[] filterRules = filterContent.replace("\r\n", "\n").split("\n");
|
||||||
|
for (String filterRule : filterRules) {
|
||||||
|
if (StringUtils.isNotBlank(filterRule)) {
|
||||||
|
content = content.replaceAll(filterRule, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//插入章节目录和章节内容
|
//插入章节目录和章节内容
|
||||||
BookIndex bookIndex = new BookIndex();
|
BookIndex bookIndex = new BookIndex();
|
||||||
bookIndex.setIndexName(indexName);
|
bookIndex.setIndexName(indexName);
|
||||||
@ -235,7 +253,7 @@ public class CrawlParser {
|
|||||||
} else {
|
} else {
|
||||||
//章节插入
|
//章节插入
|
||||||
//设置目录和章节内容
|
//设置目录和章节内容
|
||||||
Long indexId = idWorker.nextId();
|
Long indexId = ID_WORKER.nextId();
|
||||||
bookIndex.setId(indexId);
|
bookIndex.setId(indexId);
|
||||||
bookIndex.setBookId(book.getId());
|
bookIndex.setBookId(book.getId());
|
||||||
|
|
||||||
@ -257,7 +275,6 @@ public class CrawlParser {
|
|||||||
isFindIndex = indexIdMatch.find() & indexNameMatch.find();
|
isFindIndex = indexIdMatch.find() & indexNameMatch.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (indexList.size() > 0) {
|
if (indexList.size() > 0) {
|
||||||
//如果有爬到最新章节,则设置小说主表的最新章节信息
|
//如果有爬到最新章节,则设置小说主表的最新章节信息
|
||||||
//获取爬取到的最新章节
|
//获取爬取到的最新章节
|
||||||
@ -290,56 +307,4 @@ public class CrawlParser {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String getByHttpClient(String url) {
|
|
||||||
try {
|
|
||||||
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
|
|
||||||
if (forEntity.getStatusCode() == HttpStatus.OK) {
|
|
||||||
String body = forEntity.getBody();
|
|
||||||
assert body != null;
|
|
||||||
if (body.length() < Constants.INVALID_HTML_LENGTH) {
|
|
||||||
return processErrorHttpResult(url);
|
|
||||||
}
|
|
||||||
//成功获得html内容
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return processErrorHttpResult(url);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getByHttpClientWithChrome(String url) {
|
|
||||||
try {
|
|
||||||
|
|
||||||
String body = HttpUtil.getByHttpClientWithChrome(url);
|
|
||||||
if (body != null && body.length() < Constants.INVALID_HTML_LENGTH) {
|
|
||||||
return processErrorHttpResult(url);
|
|
||||||
}
|
|
||||||
//成功获得html内容
|
|
||||||
return body;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return processErrorHttpResult(url);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
private static String processErrorHttpResult(String url) {
|
|
||||||
Integer count = retryCount.get();
|
|
||||||
if (count == null) {
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
if (count < Constants.HTTP_FAIL_RETRY_COUNT) {
|
|
||||||
Thread.sleep(new Random().nextInt(10 * 1000));
|
|
||||||
retryCount.set(++count);
|
|
||||||
return getByHttpClient(url);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,37 @@
|
|||||||
package com.java2nb.novel.core.crawl;
|
package com.java2nb.novel.core.crawl;
|
||||||
|
|
||||||
|
import com.java2nb.novel.utils.Constants;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 爬虫解析规则bean
|
* 爬虫解析规则bean
|
||||||
|
*
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class RuleBean {
|
public class RuleBean {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网页字符编码
|
||||||
|
*/
|
||||||
|
private String charset = Constants.CRAWL_DEFAULT_CHARSET;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小说更新列表url
|
* 小说更新列表url
|
||||||
* */
|
*/
|
||||||
private String updateBookListUrl;
|
private String updateBookListUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分类列表页URL规则
|
* 分类列表页URL规则
|
||||||
* */
|
*/
|
||||||
private String bookListUrl;
|
private String bookListUrl;
|
||||||
|
|
||||||
private Map<String,String> catIdRule;
|
private Map<String, String> catIdRule;
|
||||||
|
|
||||||
private Map<String,Byte> bookStatusRule;
|
private Map<String, Byte> bookStatusRule;
|
||||||
|
|
||||||
private String bookIdPatten;
|
private String bookIdPatten;
|
||||||
private String pagePatten;
|
private String pagePatten;
|
||||||
@ -51,5 +59,7 @@ public class RuleBean {
|
|||||||
|
|
||||||
private String bookIndexStart;
|
private String bookIndexStart;
|
||||||
|
|
||||||
|
private String filterContent;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
package com.java2nb.novel.core.listener;
|
package com.java2nb.novel.core.listener;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.java2nb.novel.core.crawl.ChapterBean;
|
|
||||||
import com.java2nb.novel.core.crawl.CrawlParser;
|
import com.java2nb.novel.core.crawl.CrawlParser;
|
||||||
import com.java2nb.novel.core.crawl.RuleBean;
|
import com.java2nb.novel.core.crawl.RuleBean;
|
||||||
import com.java2nb.novel.entity.*;
|
import com.java2nb.novel.entity.Book;
|
||||||
|
import com.java2nb.novel.entity.BookIndex;
|
||||||
|
import com.java2nb.novel.entity.CrawlSingleTask;
|
||||||
|
import com.java2nb.novel.entity.CrawlSource;
|
||||||
import com.java2nb.novel.service.BookService;
|
import com.java2nb.novel.service.BookService;
|
||||||
import com.java2nb.novel.service.CrawlService;
|
import com.java2nb.novel.service.CrawlService;
|
||||||
import com.java2nb.novel.utils.Constants;
|
import com.java2nb.novel.utils.Constants;
|
||||||
|
import jakarta.servlet.ServletContext;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
import javax.servlet.ServletContextListener;
|
|
||||||
import javax.servlet.annotation.WebListener;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -24,20 +26,22 @@ import java.util.concurrent.TimeUnit;
|
|||||||
/**
|
/**
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
@WebListener
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class StarterListener implements ServletContextListener {
|
public class StarterListener implements ServletContextInitializer {
|
||||||
|
|
||||||
private final BookService bookService;
|
private final BookService bookService;
|
||||||
|
|
||||||
private final CrawlService crawlService;
|
private final CrawlService crawlService;
|
||||||
|
|
||||||
|
private final CrawlParser crawlParser;
|
||||||
|
|
||||||
@Value("${crawl.update.thread}")
|
@Value("${crawl.update.thread}")
|
||||||
private int updateThreadCount;
|
private int updateThreadCount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void onStartup(ServletContext servletContext) {
|
||||||
for (int i = 0; i < updateThreadCount; i++) {
|
for (int i = 0; i < updateThreadCount; i++) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
log.info("程序启动,开始执行自动更新线程。。。");
|
log.info("程序启动,开始执行自动更新线程。。。");
|
||||||
@ -56,20 +60,24 @@ public class StarterListener implements ServletContextListener {
|
|||||||
CrawlSource source = crawlService.queryCrawlSource(needUpdateBook.getCrawlSourceId());
|
CrawlSource source = crawlService.queryCrawlSource(needUpdateBook.getCrawlSourceId());
|
||||||
RuleBean ruleBean = new ObjectMapper().readValue(source.getCrawlRule(), RuleBean.class);
|
RuleBean ruleBean = new ObjectMapper().readValue(source.getCrawlRule(), RuleBean.class);
|
||||||
//解析小说基本信息
|
//解析小说基本信息
|
||||||
CrawlParser.parseBook(ruleBean, needUpdateBook.getCrawlBookId(),book -> {
|
crawlParser.parseBook(ruleBean, needUpdateBook.getCrawlBookId(), book -> {
|
||||||
//这里只做老书更新
|
//这里只做老书更新
|
||||||
book.setId(needUpdateBook.getId());
|
book.setId(needUpdateBook.getId());
|
||||||
book.setWordCount(needUpdateBook.getWordCount());
|
book.setWordCount(needUpdateBook.getWordCount());
|
||||||
if (needUpdateBook.getPicUrl() != null && needUpdateBook.getPicUrl().contains(Constants.LOCAL_PIC_PREFIX)) {
|
if (needUpdateBook.getPicUrl() != null && needUpdateBook.getPicUrl()
|
||||||
|
.contains(Constants.LOCAL_PIC_PREFIX)) {
|
||||||
//本地图片则不更新
|
//本地图片则不更新
|
||||||
book.setPicUrl(null);
|
book.setPicUrl(null);
|
||||||
}
|
}
|
||||||
//查询已存在的章节
|
//查询已存在的章节
|
||||||
Map<Integer, BookIndex> existBookIndexMap = bookService.queryExistBookIndexMap(needUpdateBook.getId());
|
Map<Integer, BookIndex> existBookIndexMap = bookService.queryExistBookIndexMap(
|
||||||
|
needUpdateBook.getId());
|
||||||
//解析章节目录
|
//解析章节目录
|
||||||
CrawlParser.parseBookIndexAndContent(needUpdateBook.getCrawlBookId(), book, ruleBean, existBookIndexMap,chapter -> {
|
crawlParser.parseBookIndexAndContent(needUpdateBook.getCrawlBookId(), book,
|
||||||
bookService.updateBookAndIndexAndContent(book, chapter.getBookIndexList(), chapter.getBookContentList(), existBookIndexMap);
|
ruleBean, existBookIndexMap, chapter -> {
|
||||||
});
|
bookService.updateBookAndIndexAndContent(book, chapter.getBookIndexList(),
|
||||||
|
chapter.getBookContentList(), existBookIndexMap);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
@ -88,7 +96,6 @@ public class StarterListener implements ServletContextListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
log.info("程序启动,开始执行单本采集任务线程。。。");
|
log.info("程序启动,开始执行单本采集任务线程。。。");
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -103,7 +110,8 @@ public class StarterListener implements ServletContextListener {
|
|||||||
CrawlSource source = crawlService.queryCrawlSource(task.getSourceId());
|
CrawlSource source = crawlService.queryCrawlSource(task.getSourceId());
|
||||||
RuleBean ruleBean = new ObjectMapper().readValue(source.getCrawlRule(), RuleBean.class);
|
RuleBean ruleBean = new ObjectMapper().readValue(source.getCrawlRule(), RuleBean.class);
|
||||||
|
|
||||||
if (crawlService.parseBookAndSave(task.getCatId(), ruleBean, task.getSourceId(), task.getSourceBookId())) {
|
if (crawlService.parseBookAndSave(task.getCatId(), ruleBean, task.getSourceId(),
|
||||||
|
task.getSourceBookId())) {
|
||||||
//采集成功
|
//采集成功
|
||||||
crawlStatus = 1;
|
crawlStatus = 1;
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,12 @@ package com.java2nb.novel.service.impl;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.github.xxyopen.model.page.PageBean;
|
|
||||||
import com.java2nb.novel.core.cache.CacheKey;
|
import com.java2nb.novel.core.cache.CacheKey;
|
||||||
import com.java2nb.novel.core.cache.CacheService;
|
import com.java2nb.novel.core.cache.CacheService;
|
||||||
import com.java2nb.novel.core.crawl.CrawlParser;
|
import com.java2nb.novel.core.crawl.CrawlParser;
|
||||||
import com.java2nb.novel.core.crawl.RuleBean;
|
import com.java2nb.novel.core.crawl.RuleBean;
|
||||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||||
import io.github.xxyopen.model.page.builder.pagehelper.PageBuilder;
|
import com.java2nb.novel.core.utils.SpringUtil;
|
||||||
import io.github.xxyopen.util.IdWorker;
|
|
||||||
import io.github.xxyopen.util.ThreadUtil;
|
|
||||||
import io.github.xxyopen.web.exception.BusinessException;
|
|
||||||
import io.github.xxyopen.web.util.BeanUtil;
|
|
||||||
import com.java2nb.novel.entity.Book;
|
import com.java2nb.novel.entity.Book;
|
||||||
import com.java2nb.novel.entity.CrawlSingleTask;
|
import com.java2nb.novel.entity.CrawlSingleTask;
|
||||||
import com.java2nb.novel.entity.CrawlSource;
|
import com.java2nb.novel.entity.CrawlSource;
|
||||||
@ -22,9 +17,15 @@ import com.java2nb.novel.mapper.CrawlSourceDynamicSqlSupport;
|
|||||||
import com.java2nb.novel.mapper.CrawlSourceMapper;
|
import com.java2nb.novel.mapper.CrawlSourceMapper;
|
||||||
import com.java2nb.novel.service.BookService;
|
import com.java2nb.novel.service.BookService;
|
||||||
import com.java2nb.novel.service.CrawlService;
|
import com.java2nb.novel.service.CrawlService;
|
||||||
|
import com.java2nb.novel.utils.CrawlHttpClient;
|
||||||
import com.java2nb.novel.vo.CrawlSingleTaskVO;
|
import com.java2nb.novel.vo.CrawlSingleTaskVO;
|
||||||
import com.java2nb.novel.vo.CrawlSourceVO;
|
import com.java2nb.novel.vo.CrawlSourceVO;
|
||||||
import io.github.xxyopen.web.util.SpringUtil;
|
import io.github.xxyopen.model.page.PageBean;
|
||||||
|
import io.github.xxyopen.model.page.builder.pagehelper.PageBuilder;
|
||||||
|
import io.github.xxyopen.util.IdWorker;
|
||||||
|
import io.github.xxyopen.util.ThreadUtil;
|
||||||
|
import io.github.xxyopen.web.exception.BusinessException;
|
||||||
|
import io.github.xxyopen.web.util.BeanUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -38,7 +39,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static com.java2nb.novel.core.utils.HttpUtil.getByHttpClientWithChrome;
|
|
||||||
import static com.java2nb.novel.mapper.CrawlSourceDynamicSqlSupport.*;
|
import static com.java2nb.novel.mapper.CrawlSourceDynamicSqlSupport.*;
|
||||||
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
|
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
|
||||||
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||||
@ -51,6 +51,7 @@ import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class CrawlServiceImpl implements CrawlService {
|
public class CrawlServiceImpl implements CrawlService {
|
||||||
|
|
||||||
|
private final CrawlParser crawlParser;
|
||||||
|
|
||||||
private final CrawlSourceMapper crawlSourceMapper;
|
private final CrawlSourceMapper crawlSourceMapper;
|
||||||
|
|
||||||
@ -62,6 +63,8 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
|
|
||||||
private final IdWorker idWorker = IdWorker.INSTANCE;
|
private final IdWorker idWorker = IdWorker.INSTANCE;
|
||||||
|
|
||||||
|
private final CrawlHttpClient crawlHttpClient;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCrawlSource(CrawlSource source) {
|
public void addCrawlSource(CrawlSource source) {
|
||||||
@ -71,15 +74,16 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
crawlSourceMapper.insertSelective(source);
|
crawlSourceMapper.insertSelective(source);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCrawlSource(CrawlSource source) {
|
public void updateCrawlSource(CrawlSource source) {
|
||||||
if(source.getId()!=null){
|
if (source.getId() != null) {
|
||||||
Optional<CrawlSource> opt=crawlSourceMapper.selectByPrimaryKey(source.getId());
|
Optional<CrawlSource> opt = crawlSourceMapper.selectByPrimaryKey(source.getId());
|
||||||
if(opt.isPresent()) {
|
if (opt.isPresent()) {
|
||||||
CrawlSource crawlSource =opt.get();
|
CrawlSource crawlSource = opt.get();
|
||||||
if (crawlSource.getSourceStatus() == (byte) 1) {
|
if (crawlSource.getSourceStatus() == (byte) 1) {
|
||||||
//关闭
|
//关闭
|
||||||
openOrCloseCrawl(crawlSource.getId(),(byte)0);
|
openOrCloseCrawl(crawlSource.getId(), (byte) 0);
|
||||||
}
|
}
|
||||||
Date currentDate = new Date();
|
Date currentDate = new Date();
|
||||||
crawlSource.setUpdateTime(currentDate);
|
crawlSource.setUpdateTime(currentDate);
|
||||||
@ -89,14 +93,15 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageBean<CrawlSource> listCrawlByPage(int page, int pageSize) {
|
public PageBean<CrawlSource> listCrawlByPage(int page, int pageSize) {
|
||||||
PageHelper.startPage(page, pageSize);
|
PageHelper.startPage(page, pageSize);
|
||||||
SelectStatementProvider render = select(id, sourceName, sourceStatus, createTime, updateTime)
|
SelectStatementProvider render = select(id, sourceName, sourceStatus, createTime, updateTime)
|
||||||
.from(crawlSource)
|
.from(crawlSource)
|
||||||
.orderBy(updateTime)
|
.orderBy(updateTime)
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3);
|
.render(RenderingStrategies.MYBATIS3);
|
||||||
List<CrawlSource> crawlSources = crawlSourceMapper.selectMany(render);
|
List<CrawlSource> crawlSources = crawlSourceMapper.selectMany(render);
|
||||||
PageBean<CrawlSource> pageBean = PageBuilder.build(crawlSources);
|
PageBean<CrawlSource> pageBean = PageBuilder.build(crawlSources);
|
||||||
pageBean.setList(BeanUtil.copyList(crawlSources, CrawlSourceVO.class));
|
pageBean.setList(BeanUtil.copyList(crawlSources, CrawlSourceVO.class));
|
||||||
@ -113,7 +118,8 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
if (sourceStatus == (byte) 0) {
|
if (sourceStatus == (byte) 0) {
|
||||||
//关闭,直接修改数据库状态,并直接修改数据库状态后获取该爬虫正在运行的线程集合全部停止
|
//关闭,直接修改数据库状态,并直接修改数据库状态后获取该爬虫正在运行的线程集合全部停止
|
||||||
SpringUtil.getBean(CrawlService.class).updateCrawlSourceStatus(sourceId, sourceStatus);
|
SpringUtil.getBean(CrawlService.class).updateCrawlSourceStatus(sourceId, sourceStatus);
|
||||||
Set<Long> runningCrawlThreadId = (Set<Long>) cacheService.getObject(CacheKey.RUNNING_CRAWL_THREAD_KEY_PREFIX + sourceId);
|
Set<Long> runningCrawlThreadId = (Set<Long>) cacheService.getObject(
|
||||||
|
CacheKey.RUNNING_CRAWL_THREAD_KEY_PREFIX + sourceId);
|
||||||
if (runningCrawlThreadId != null) {
|
if (runningCrawlThreadId != null) {
|
||||||
for (Long ThreadId : runningCrawlThreadId) {
|
for (Long ThreadId : runningCrawlThreadId) {
|
||||||
Thread thread = ThreadUtil.findThread(ThreadId);
|
Thread thread = ThreadUtil.findThread(ThreadId);
|
||||||
@ -157,11 +163,12 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CrawlSource queryCrawlSource(Integer sourceId) {
|
public CrawlSource queryCrawlSource(Integer sourceId) {
|
||||||
SelectStatementProvider render = select(CrawlSourceDynamicSqlSupport.sourceStatus, CrawlSourceDynamicSqlSupport.crawlRule)
|
SelectStatementProvider render = select(CrawlSourceDynamicSqlSupport.sourceStatus,
|
||||||
.from(crawlSource)
|
CrawlSourceDynamicSqlSupport.crawlRule)
|
||||||
.where(id, isEqualTo(sourceId))
|
.from(crawlSource)
|
||||||
.build()
|
.where(id, isEqualTo(sourceId))
|
||||||
.render(RenderingStrategies.MYBATIS3);
|
.build()
|
||||||
|
.render(RenderingStrategies.MYBATIS3);
|
||||||
return crawlSourceMapper.selectMany(render).get(0);
|
return crawlSourceMapper.selectMany(render).get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,10 +189,10 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
public PageBean<CrawlSingleTask> listCrawlSingleTaskByPage(int page, int pageSize) {
|
public PageBean<CrawlSingleTask> listCrawlSingleTaskByPage(int page, int pageSize) {
|
||||||
PageHelper.startPage(page, pageSize);
|
PageHelper.startPage(page, pageSize);
|
||||||
SelectStatementProvider render = select(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask.allColumns())
|
SelectStatementProvider render = select(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask.allColumns())
|
||||||
.from(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask)
|
.from(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask)
|
||||||
.orderBy(CrawlSingleTaskDynamicSqlSupport.createTime.descending())
|
.orderBy(CrawlSingleTaskDynamicSqlSupport.createTime.descending())
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3);
|
.render(RenderingStrategies.MYBATIS3);
|
||||||
List<CrawlSingleTask> crawlSingleTasks = crawlSingleTaskMapper.selectMany(render);
|
List<CrawlSingleTask> crawlSingleTasks = crawlSingleTaskMapper.selectMany(render);
|
||||||
PageBean<CrawlSingleTask> pageBean = PageBuilder.build(crawlSingleTasks);
|
PageBean<CrawlSingleTask> pageBean = PageBuilder.build(crawlSingleTasks);
|
||||||
pageBean.setList(BeanUtil.copyList(crawlSingleTasks, CrawlSingleTaskVO.class));
|
pageBean.setList(BeanUtil.copyList(crawlSingleTasks, CrawlSingleTaskVO.class));
|
||||||
@ -200,7 +207,8 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
@Override
|
@Override
|
||||||
public CrawlSingleTask getCrawlSingleTask() {
|
public CrawlSingleTask getCrawlSingleTask() {
|
||||||
|
|
||||||
List<CrawlSingleTask> list = crawlSingleTaskMapper.selectMany(select(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask.allColumns())
|
List<CrawlSingleTask> list = crawlSingleTaskMapper.selectMany(
|
||||||
|
select(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask.allColumns())
|
||||||
.from(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask)
|
.from(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask)
|
||||||
.where(CrawlSingleTaskDynamicSqlSupport.taskStatus, isEqualTo((byte) 2))
|
.where(CrawlSingleTaskDynamicSqlSupport.taskStatus, isEqualTo((byte) 2))
|
||||||
.orderBy(CrawlSingleTaskDynamicSqlSupport.createTime)
|
.orderBy(CrawlSingleTaskDynamicSqlSupport.createTime)
|
||||||
@ -226,12 +234,12 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CrawlSource getCrawlSource(Integer id) {
|
public CrawlSource getCrawlSource(Integer id) {
|
||||||
Optional<CrawlSource> opt=crawlSourceMapper.selectByPrimaryKey(id);
|
Optional<CrawlSource> opt = crawlSourceMapper.selectByPrimaryKey(id);
|
||||||
if(opt.isPresent()) {
|
if (opt.isPresent()) {
|
||||||
CrawlSource crawlSource =opt.get();
|
CrawlSource crawlSource = opt.get();
|
||||||
return crawlSource;
|
return crawlSource;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -247,14 +255,23 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
while (page <= totalPage) {
|
while (page <= totalPage) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
String catIdRule = ruleBean.getCatIdRule().get("catId" + catId);
|
||||||
if (StringUtils.isNotBlank(ruleBean.getCatIdRule().get("catId" + catId))) {
|
if (StringUtils.isNotBlank(catIdRule)) {
|
||||||
//拼接分类URL
|
String catBookListUrl = "";
|
||||||
String catBookListUrl = ruleBean.getBookListUrl()
|
if (StringUtils.isNotBlank(ruleBean.getBookListUrl())) {
|
||||||
.replace("{catId}", ruleBean.getCatIdRule().get("catId" + catId))
|
// 兼容老规则
|
||||||
|
// 拼接分类URL
|
||||||
|
catBookListUrl = ruleBean.getBookListUrl()
|
||||||
|
.replace("{catId}", catIdRule)
|
||||||
.replace("{page}", page + "");
|
.replace("{page}", page + "");
|
||||||
|
} else {
|
||||||
|
// 新规则
|
||||||
|
// 拼接分类URL
|
||||||
|
catBookListUrl = catIdRule.replace("{page}", page + "");
|
||||||
|
}
|
||||||
|
log.info("catBookListUrl:{}", catBookListUrl);
|
||||||
|
|
||||||
String bookListHtml = getByHttpClientWithChrome(catBookListUrl);
|
String bookListHtml = crawlHttpClient.get(catBookListUrl, ruleBean.getCharset());
|
||||||
if (bookListHtml != null) {
|
if (bookListHtml != null) {
|
||||||
Pattern bookIdPatten = Pattern.compile(ruleBean.getBookIdPatten());
|
Pattern bookIdPatten = Pattern.compile(ruleBean.getBookIdPatten());
|
||||||
Matcher bookIdMatcher = bookIdPatten.matcher(bookListHtml);
|
Matcher bookIdMatcher = bookIdPatten.matcher(bookListHtml);
|
||||||
@ -268,14 +285,12 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String bookId = bookIdMatcher.group(1);
|
String bookId = bookIdMatcher.group(1);
|
||||||
parseBookAndSave(catId, ruleBean, sourceId, bookId);
|
parseBookAndSave(catId, ruleBean, sourceId, bookId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
isFindBookId = bookIdMatcher.find();
|
isFindBookId = bookIdMatcher.find();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,6 +309,10 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
if (page == totalPage) {
|
||||||
|
// 第一遍采集完成,翻到第一页,继续第二次采集,适用于分页数比较少的最近更新列表
|
||||||
|
page = 0;
|
||||||
|
}
|
||||||
|
|
||||||
page += 1;
|
page += 1;
|
||||||
}
|
}
|
||||||
@ -306,7 +325,7 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
|
|
||||||
final AtomicBoolean parseResult = new AtomicBoolean(false);
|
final AtomicBoolean parseResult = new AtomicBoolean(false);
|
||||||
|
|
||||||
CrawlParser.parseBook(ruleBean, bookId, book -> {
|
crawlParser.parseBook(ruleBean, bookId, book -> {
|
||||||
if (book.getBookName() == null || book.getAuthorName() == null) {
|
if (book.getBookName() == null || book.getAuthorName() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -330,9 +349,11 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
book.setCrawlLastTime(new Date());
|
book.setCrawlLastTime(new Date());
|
||||||
book.setId(idWorker.nextId());
|
book.setId(idWorker.nextId());
|
||||||
//解析章节目录
|
//解析章节目录
|
||||||
boolean parseIndexContentResult = CrawlParser.parseBookIndexAndContent(bookId, book, ruleBean, new HashMap<>(0), chapter -> {
|
boolean parseIndexContentResult = crawlParser.parseBookIndexAndContent(bookId, book, ruleBean,
|
||||||
bookService.saveBookAndIndexAndContent(book, chapter.getBookIndexList(), chapter.getBookContentList());
|
new HashMap<>(0), chapter -> {
|
||||||
});
|
bookService.saveBookAndIndexAndContent(book, chapter.getBookIndexList(),
|
||||||
|
chapter.getBookContentList());
|
||||||
|
});
|
||||||
parseResult.set(parseIndexContentResult);
|
parseResult.set(parseIndexContentResult);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -356,11 +377,12 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CrawlSource> queryCrawlSourceByStatus(Byte sourceStatus) {
|
public List<CrawlSource> queryCrawlSourceByStatus(Byte sourceStatus) {
|
||||||
SelectStatementProvider render = select(CrawlSourceDynamicSqlSupport.id, CrawlSourceDynamicSqlSupport.sourceStatus, CrawlSourceDynamicSqlSupport.crawlRule)
|
SelectStatementProvider render = select(CrawlSourceDynamicSqlSupport.id,
|
||||||
.from(crawlSource)
|
CrawlSourceDynamicSqlSupport.sourceStatus, CrawlSourceDynamicSqlSupport.crawlRule)
|
||||||
.where(CrawlSourceDynamicSqlSupport.sourceStatus, isEqualTo(sourceStatus))
|
.from(crawlSource)
|
||||||
.build()
|
.where(CrawlSourceDynamicSqlSupport.sourceStatus, isEqualTo(sourceStatus))
|
||||||
.render(RenderingStrategies.MYBATIS3);
|
.build()
|
||||||
|
.render(RenderingStrategies.MYBATIS3);
|
||||||
return crawlSourceMapper.selectMany(render);
|
return crawlSourceMapper.selectMany(render);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ public class Constants {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地图片保存前缀
|
* 本地图片保存前缀
|
||||||
* */
|
*/
|
||||||
public static final String LOCAL_PIC_PREFIX = "/localPic/";
|
public static final String LOCAL_PIC_PREFIX = "/localPic/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,5 +23,10 @@ public class Constants {
|
|||||||
/**
|
/**
|
||||||
* 爬取小说http请求失败重试次数
|
* 爬取小说http请求失败重试次数
|
||||||
*/
|
*/
|
||||||
public static final Integer HTTP_FAIL_RETRY_COUNT = 5;
|
public static final Integer HTTP_FAIL_RETRY_COUNT = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 爬虫默认编码
|
||||||
|
*/
|
||||||
|
public static final String CRAWL_DEFAULT_CHARSET = "UTF-8";
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package com.java2nb.novel.utils;
|
||||||
|
|
||||||
|
import com.java2nb.novel.core.utils.HttpUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class CrawlHttpClient {
|
||||||
|
|
||||||
|
@Value("${crawl.interval.min}")
|
||||||
|
private Integer intervalMin;
|
||||||
|
|
||||||
|
@Value("${crawl.interval.max}")
|
||||||
|
private Integer intervalMax;
|
||||||
|
|
||||||
|
private final Random random = new Random();
|
||||||
|
|
||||||
|
private static final ThreadLocal<Integer> RETRY_COUNT = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public String get(String url, String charset) {
|
||||||
|
if (Objects.nonNull(intervalMin) && Objects.nonNull(intervalMax) && intervalMax > intervalMin) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(random.nextInt(intervalMax - intervalMin + 1) + intervalMin);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String body = HttpUtil.getByHttpClientWithChrome(url, charset);
|
||||||
|
if (Objects.isNull(body) || body.length() < Constants.INVALID_HTML_LENGTH) {
|
||||||
|
return processErrorHttpResult(url, charset);
|
||||||
|
}
|
||||||
|
//成功获得html内容
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String processErrorHttpResult(String url, String charset) {
|
||||||
|
Integer count = RETRY_COUNT.get();
|
||||||
|
if (count == null) {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
if (count < Constants.HTTP_FAIL_RETRY_COUNT) {
|
||||||
|
RETRY_COUNT.set(++count);
|
||||||
|
return get(url, charset);
|
||||||
|
}
|
||||||
|
RETRY_COUNT.remove();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,3 +1,3 @@
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
config:
|
||||||
include: [common-dev]
|
import: classpath:application-common-dev.yml
|
@ -1,3 +1,3 @@
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
config:
|
||||||
include: [common-prod]
|
import: classpath:application-common-prod.yml
|
@ -14,12 +14,18 @@ admin:
|
|||||||
username: admin
|
username: admin
|
||||||
password: admin
|
password: admin
|
||||||
|
|
||||||
#爬虫自动更新的线程数
|
|
||||||
#建议小说数量不多或者正在运行新书入库爬虫的情况下设置为1即可
|
|
||||||
#随着小说数量的增多可以逐渐增加,但建议不要超出CPU的线程数
|
|
||||||
crawl:
|
crawl:
|
||||||
update:
|
update:
|
||||||
|
#爬虫自动更新的线程数
|
||||||
|
#建议小说数量不多或者正在运行新书入库爬虫的情况下设置为1即可
|
||||||
|
#随着小说数量的增多可以逐渐增加,但建议不要超出CPU的线程数
|
||||||
thread: 1
|
thread: 1
|
||||||
|
# 采集间隔时间,单位:毫秒
|
||||||
|
interval:
|
||||||
|
min: 300
|
||||||
|
max: 500
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,9 +12,6 @@
|
|||||||
<!-- ConsoleAppender:把日志输出到控制台 -->
|
<!-- ConsoleAppender:把日志输出到控制台 -->
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<!--
|
|
||||||
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
|
||||||
-->
|
|
||||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
<!-- 控制台也要使用UTF-8,不要使用GBK,否则会中文乱码 -->
|
<!-- 控制台也要使用UTF-8,不要使用GBK,否则会中文乱码 -->
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
@ -22,43 +19,43 @@
|
|||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
||||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是demo.log -->
|
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是novel-crawl.log -->
|
||||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过1KB时,对当前日志进行分割 重命名 -->
|
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过10MB时,对当前日志进行分割 重命名 -->
|
||||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<!-- 设置日志文件路径 -->
|
||||||
<File>logs/novel-crawl.log</File>
|
<file>logs/novel-crawl.log</file>
|
||||||
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
|
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
|
||||||
<!-- TimeBasedRollingPolicy: 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动 -->
|
<!-- SizeAndTimeBasedRollingPolicy:基于时间和文件大小的滚动策略 -->
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||||
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
||||||
<!-- 文件名:logs/demo.2017-12-05.0.log -->
|
<!-- 文件名:logs/debug.2023-10-01.0.log -->
|
||||||
<fileNamePattern>logs/debug.%d.%i.log</fileNamePattern>
|
<fileNamePattern>logs/debug.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||||
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
|
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
|
||||||
<maxHistory>30</maxHistory>
|
<maxHistory>30</maxHistory>
|
||||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
<!-- 单个日志文件的最大大小 -->
|
||||||
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,测试时可改成1KB看效果 -->
|
<maxFileSize>10MB</maxFileSize>
|
||||||
<maxFileSize>10MB</maxFileSize>
|
<!-- 所有日志文件的总大小限制 -->
|
||||||
</timeBasedFileNamingAndTriggeringPolicy>
|
<totalSizeCap>1GB</totalSizeCap>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<!-- pattern节点,用来设置日志的输入格式 -->
|
<!-- pattern节点,用来设置日志的输入格式 -->
|
||||||
<pattern>
|
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
||||||
%d %p (%file:%line\)- %m%n
|
|
||||||
</pattern>
|
|
||||||
<!-- 记录日志的编码:此处设置字符集 - -->
|
<!-- 记录日志的编码:此处设置字符集 - -->
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- 控制台输出日志级别 -->
|
<!-- 控制台输出日志级别 -->
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||||
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
<!-- com.java2nb 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||||
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
||||||
<logger name="com.java2nb" level="DEBUG" additivity="false">
|
<logger name="com.java2nb" level="DEBUG" additivity="false">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
</logger>
|
</logger>
|
||||||
</configuration>
|
</configuration>
|
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 162 KiB |
@ -54,6 +54,8 @@
|
|||||||
<!--示例:<b>https://m.xdingdiann.com/sort/0/1.html</b>
|
<!--示例:<b>https://m.xdingdiann.com/sort/0/1.html</b>
|
||||||
<li><input type="text" id="updateBookListUrl" class="s_input icon_key"
|
<li><input type="text" id="updateBookListUrl" class="s_input icon_key"
|
||||||
placeholder="小说更新列表url"></li>-->
|
placeholder="小说更新列表url"></li>-->
|
||||||
|
示例:<b>utf-8</b>
|
||||||
|
<li><input type="text" id="charset" class="s_input icon_name" placeholder="网站编码"></li>
|
||||||
示例:<b>http://m.xdingdiann.com/sort/{catId}/{page}.html</b> ({catId}代表分类ID,{page}代表分页页码)
|
示例:<b>http://m.xdingdiann.com/sort/{catId}/{page}.html</b> ({catId}代表分类ID,{page}代表分页页码)
|
||||||
<li><input type="text" id="bookListUrl" class="s_input icon_key"
|
<li><input type="text" id="bookListUrl" class="s_input icon_key"
|
||||||
placeholder="分类列表页URL规则"></li>
|
placeholder="分类列表页URL规则"></li>
|
||||||
@ -144,6 +146,9 @@
|
|||||||
示例:<b><script></b>
|
示例:<b><script></b>
|
||||||
<li><input type="text" id="contentEnd" class="s_input icon_key"
|
<li><input type="text" id="contentEnd" class="s_input icon_key"
|
||||||
placeholder="小说内容结束截取字符串:"></li>
|
placeholder="小说内容结束截取字符串:"></li>
|
||||||
|
示例:<b><div\s+id="content_tip">\s*<b>([^/]+)</b>\s*</div></b>
|
||||||
|
<li><textarea id="filterContent"
|
||||||
|
placeholder="过滤内容(多个内容换行)" rows="5" cols="52"></textarea></li>
|
||||||
|
|
||||||
<li><input type="button" onclick="addCrawlSource()" name="btnRegister" value="提交"
|
<li><input type="button" onclick="addCrawlSource()" name="btnRegister" value="提交"
|
||||||
id="btnRegister" class="btn_red"></li>
|
id="btnRegister" class="btn_red"></li>
|
||||||
@ -405,6 +410,14 @@
|
|||||||
|
|
||||||
crawlRule.contentEnd = contentEnd;
|
crawlRule.contentEnd = contentEnd;
|
||||||
|
|
||||||
|
var filterContent = $("#filterContent").val();
|
||||||
|
crawlRule.filterContent = filterContent;
|
||||||
|
|
||||||
|
var charset = $('#charset').val();
|
||||||
|
if (charset) {
|
||||||
|
crawlRule.charset = charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
@ -55,6 +55,8 @@
|
|||||||
<!--示例:<b>https://m.xdingdiann.com/sort/0/1.html</b>
|
<!--示例:<b>https://m.xdingdiann.com/sort/0/1.html</b>
|
||||||
<li><input type="text" id="updateBookListUrl" class="s_input icon_key"
|
<li><input type="text" id="updateBookListUrl" class="s_input icon_key"
|
||||||
placeholder="小说更新列表url"></li>-->
|
placeholder="小说更新列表url"></li>-->
|
||||||
|
示例:<b>utf-8</b>
|
||||||
|
<li><input type="text" id="charset" class="s_input icon_name" placeholder="网站编码"></li>
|
||||||
示例:<b>http://m.xdingdiann.com/sort/{catId}/{page}.html</b> ({catId}代表分类ID,{page}代表分页页码)
|
示例:<b>http://m.xdingdiann.com/sort/{catId}/{page}.html</b> ({catId}代表分类ID,{page}代表分页页码)
|
||||||
<li><input type="text" id="bookListUrl" class="s_input icon_key"
|
<li><input type="text" id="bookListUrl" class="s_input icon_key"
|
||||||
placeholder="分类列表页URL规则"></li>
|
placeholder="分类列表页URL规则"></li>
|
||||||
@ -145,6 +147,10 @@
|
|||||||
示例:<b><script></b>
|
示例:<b><script></b>
|
||||||
<li><input type="text" id="contentEnd" class="s_input icon_key"
|
<li><input type="text" id="contentEnd" class="s_input icon_key"
|
||||||
placeholder="小说内容结束截取字符串:"></li>
|
placeholder="小说内容结束截取字符串:"></li>
|
||||||
|
示例:<b><div\s+id="content_tip">\s*<b>([^/]+)</b>\s*</div></b>
|
||||||
|
<li><textarea id="filterContent"
|
||||||
|
placeholder="过滤内容(多个内容换行)" rows="5" cols="52"></textarea></li>
|
||||||
|
|
||||||
|
|
||||||
<li><input type="button" onclick="updateCrawlSource()" name="btnRegister" value="提交"
|
<li><input type="button" onclick="updateCrawlSource()" name="btnRegister" value="提交"
|
||||||
id="btnRegister" class="btn_red"></li>
|
id="btnRegister" class="btn_red"></li>
|
||||||
@ -269,6 +275,8 @@
|
|||||||
$("#bookContentUrl").val(crawlRule.bookContentUrl);
|
$("#bookContentUrl").val(crawlRule.bookContentUrl);
|
||||||
$("#contentStart").val(crawlRule.contentStart);
|
$("#contentStart").val(crawlRule.contentStart);
|
||||||
$("#contentEnd").val(crawlRule.contentEnd);
|
$("#contentEnd").val(crawlRule.contentEnd);
|
||||||
|
$("#filterContent").val(crawlRule.filterContent);
|
||||||
|
$("#charset").val(crawlRule.charset);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -488,6 +496,14 @@
|
|||||||
|
|
||||||
crawlRule.contentEnd = contentEnd;
|
crawlRule.contentEnd = contentEnd;
|
||||||
|
|
||||||
|
var filterContent = $("#filterContent").val();
|
||||||
|
crawlRule.filterContent = filterContent;
|
||||||
|
|
||||||
|
var charset = $('#charset').val();
|
||||||
|
if (charset) {
|
||||||
|
crawlRule.charset = charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>novel</artifactId>
|
<artifactId>novel</artifactId>
|
||||||
<groupId>com.java2nb</groupId>
|
<groupId>com.java2nb</groupId>
|
||||||
<version>4.3.0</version>
|
<version>5.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -20,6 +20,12 @@
|
|||||||
<artifactId>novel-common</artifactId>
|
<artifactId>novel-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--JWT(Json Web Token)登录支持-->
|
<!--JWT(Json Web Token)登录支持-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
@ -48,7 +54,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson.version}</version>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- AI -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.ai</groupId>
|
||||||
|
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
#端口号
|
|
||||||
server:
|
|
||||||
port: 8085
|
|
||||||
|
|
||||||
#不分表的数据库配置
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: root
|
|
||||||
redis:
|
|
||||||
host: 127.0.0.1
|
|
||||||
port: 6379
|
|
||||||
password: test123456
|
|
||||||
|
|
||||||
####使用shardingJdbc时,
|
|
||||||
####所有的jdbcType都不能是LONGVARCHAR,否则会导致java.io.NotSerializableException: java.io.StringReader错误
|
|
||||||
##### 应该替换所有的 LONGVARCHAR 类型为VARCHAR
|
|
||||||
sharding:
|
|
||||||
jdbc:
|
|
||||||
datasource:
|
|
||||||
ds0:
|
|
||||||
jdbc-url: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
password: test123456
|
|
||||||
|
|
||||||
pic:
|
|
||||||
save:
|
|
||||||
#图片保存方式, 1不保存,使用网络图片 ,2本地保存
|
|
||||||
type: 2
|
|
||||||
#图片保存路径
|
|
||||||
path: /var/pic
|
|
||||||
|
|
||||||
|
|
||||||
#模版配置
|
|
||||||
templates:
|
|
||||||
name: green
|
|
||||||
|
|
||||||
#小说内容保存配置
|
|
||||||
content:
|
|
||||||
save:
|
|
||||||
storage: db # 小说内容存储方式:db-数据库,txt-TXT文本
|
|
||||||
path: /Users/xiongxiaoyang/books # 小说TXT文本保存路径
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# HTTP 代理配置
|
|
||||||
http:
|
|
||||||
proxy:
|
|
||||||
# 是否开启 HTTP 代理,true-开启,false-不开启
|
|
||||||
enabled: false
|
|
||||||
# 代理 IP
|
|
||||||
ip: u493.kdltps.com
|
|
||||||
# 代理端口号
|
|
||||||
port: 15818
|
|
||||||
|
|
61
novel-front/src/main/build/config/application.yml
Normal file
61
novel-front/src/main/build/config/application.yml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#端口号
|
||||||
|
server:
|
||||||
|
port: 8085
|
||||||
|
|
||||||
|
spring:
|
||||||
|
data:
|
||||||
|
redis:
|
||||||
|
#Redis服务器IP
|
||||||
|
host: 127.0.0.1
|
||||||
|
#Redis服务器连接端口
|
||||||
|
port: 6379
|
||||||
|
#Redis服务器连接密码
|
||||||
|
password: test123456
|
||||||
|
#连接超时时间(毫秒)
|
||||||
|
timeout: 10000
|
||||||
|
|
||||||
|
|
||||||
|
pic:
|
||||||
|
save:
|
||||||
|
#图片保存方式, 1不保存,使用网络图片 ,2本地保存
|
||||||
|
type: 2
|
||||||
|
#图片保存路径
|
||||||
|
path: /var/pic
|
||||||
|
|
||||||
|
|
||||||
|
#模版配置
|
||||||
|
templates:
|
||||||
|
name: green
|
||||||
|
|
||||||
|
#小说内容保存配置
|
||||||
|
content:
|
||||||
|
save:
|
||||||
|
storage: db # 小说内容存储方式:db-数据库,txt-TXT文本
|
||||||
|
path: /Users/xiongxiaoyang/books # 小说TXT文本保存路径
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# HTTP 代理配置
|
||||||
|
http:
|
||||||
|
proxy:
|
||||||
|
# 是否开启 HTTP 代理,true-开启,false-不开启
|
||||||
|
enabled: false
|
||||||
|
# 代理 IP
|
||||||
|
ip: us.swiftproxy.net
|
||||||
|
# 代理端口号
|
||||||
|
port: 7878
|
||||||
|
# 代理用户名
|
||||||
|
username: swiftproxy_u
|
||||||
|
# 代理密码
|
||||||
|
password: swiftproxy_p
|
||||||
|
|
||||||
|
|
||||||
|
--- #--------------------- Spring AI 配置----------------------
|
||||||
|
spring:
|
||||||
|
ai:
|
||||||
|
openai:
|
||||||
|
api-key: sk-nnhjmxuljagcuubbovjztbhkiawqaabzziazeurppinxtgva
|
||||||
|
base-url: https://api.siliconflow.cn
|
||||||
|
chat:
|
||||||
|
options:
|
||||||
|
model: deepseek-ai/DeepSeek-R1-Distill-Llama-8B
|
47
novel-front/src/main/build/config/shardingsphere-jdbc.yml
Normal file
47
novel-front/src/main/build/config/shardingsphere-jdbc.yml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
mode:
|
||||||
|
# 单机模式
|
||||||
|
type: Standalone
|
||||||
|
# 元数据持久化
|
||||||
|
repository:
|
||||||
|
# 数据库持久化
|
||||||
|
type: JDBC
|
||||||
|
|
||||||
|
# 数据源配置
|
||||||
|
dataSources:
|
||||||
|
ds_1:
|
||||||
|
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
|
||||||
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
|
jdbcUrl: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||||
|
username: root
|
||||||
|
password: test123456
|
||||||
|
# 规则配置
|
||||||
|
rules:
|
||||||
|
- !SINGLE
|
||||||
|
tables:
|
||||||
|
- "*.*"
|
||||||
|
- !SHARDING
|
||||||
|
tables: # 数据分片规则配置
|
||||||
|
book_content:
|
||||||
|
# 分库策略,缺省表示使用默认分库策略
|
||||||
|
actualDataNodes: ds_${1}.book_content${0..9}
|
||||||
|
# 分表策略
|
||||||
|
tableStrategy:
|
||||||
|
standard:
|
||||||
|
# 分片列名称
|
||||||
|
shardingColumn: index_id
|
||||||
|
# 分片算法名称
|
||||||
|
shardingAlgorithmName: bookContentSharding
|
||||||
|
|
||||||
|
shardingAlgorithms:
|
||||||
|
bookContentSharding:
|
||||||
|
# 行表达式分片算法,使用 Groovy 的表达式,提供对 SQL 语句中的 = 和 IN 的分片操作支持
|
||||||
|
type: INLINE
|
||||||
|
props:
|
||||||
|
# 分片算法的行表达式
|
||||||
|
algorithm-expression: book_content${index_id % 10}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
props:
|
||||||
|
# 是否在日志中打印 SQL
|
||||||
|
sql-show: true
|
@ -12,11 +12,13 @@ import com.java2nb.novel.entity.AuthorIncomeDetail;
|
|||||||
import com.java2nb.novel.entity.Book;
|
import com.java2nb.novel.entity.Book;
|
||||||
import com.java2nb.novel.service.AuthorService;
|
import com.java2nb.novel.service.AuthorService;
|
||||||
import com.java2nb.novel.service.BookService;
|
import com.java2nb.novel.service.BookService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,6 +34,8 @@ public class AuthorController extends BaseController{
|
|||||||
|
|
||||||
private final BookService bookService;
|
private final BookService bookService;
|
||||||
|
|
||||||
|
private final ChatClient chatClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验笔名是否存在
|
* 校验笔名是否存在
|
||||||
* */
|
* */
|
||||||
@ -54,7 +58,7 @@ public class AuthorController extends BaseController{
|
|||||||
* 发布小说
|
* 发布小说
|
||||||
* */
|
* */
|
||||||
@PostMapping("addBook")
|
@PostMapping("addBook")
|
||||||
public RestResult<Void> addBook(@RequestParam("bookDesc") String bookDesc,Book book,HttpServletRequest request){
|
public RestResult<Void> addBook(@RequestParam("bookDesc") String bookDesc, Book book, HttpServletRequest request){
|
||||||
|
|
||||||
Author author = checkAuthor(request);
|
Author author = checkAuthor(request);
|
||||||
|
|
||||||
@ -220,6 +224,54 @@ public class AuthorController extends BaseController{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI扩写
|
||||||
|
*/
|
||||||
|
@PostMapping("ai/expand")
|
||||||
|
public RestResult<String> expandText(@RequestParam("text") String text, @RequestParam("ratio") Double ratio) {
|
||||||
|
String prompt = "请将以下文本扩写为原长度的" + ratio/100 + "倍:" + text;
|
||||||
|
return RestResult.ok(chatClient.prompt()
|
||||||
|
.user(prompt)
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI缩写
|
||||||
|
*/
|
||||||
|
@PostMapping("ai/condense")
|
||||||
|
public RestResult<String> condenseText(@RequestParam("text") String text, @RequestParam("ratio") Integer ratio) {
|
||||||
|
String prompt = "请将以下文本缩写为原长度的" + 100/ratio + "分之一:" + text;
|
||||||
|
return RestResult.ok(chatClient.prompt()
|
||||||
|
.user(prompt)
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI续写
|
||||||
|
*/
|
||||||
|
@PostMapping("ai/continue")
|
||||||
|
public RestResult<String> continueText(@RequestParam("text") String text, @RequestParam("length") Integer length) {
|
||||||
|
String prompt = "请续写以下文本,续写长度约为" + length + "字:" + text;
|
||||||
|
return RestResult.ok(chatClient.prompt()
|
||||||
|
.user(prompt)
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI润色
|
||||||
|
*/
|
||||||
|
@PostMapping("ai/polish")
|
||||||
|
public RestResult<String> polishText(@RequestParam("text") String text) {
|
||||||
|
String prompt = "请润色优化以下文本,保持原意:" + text;
|
||||||
|
return RestResult.ok(chatClient.prompt()
|
||||||
|
.user(prompt)
|
||||||
|
.call()
|
||||||
|
.content());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,11 +3,10 @@ package com.java2nb.novel.controller;
|
|||||||
import com.java2nb.novel.core.bean.UserDetails;
|
import com.java2nb.novel.core.bean.UserDetails;
|
||||||
import com.java2nb.novel.core.utils.CookieUtil;
|
import com.java2nb.novel.core.utils.CookieUtil;
|
||||||
import com.java2nb.novel.core.utils.JwtTokenUtil;
|
import com.java2nb.novel.core.utils.JwtTokenUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 11797
|
* @author 11797
|
||||||
|
@ -15,11 +15,11 @@ import com.java2nb.novel.vo.BookVO;
|
|||||||
import io.github.xxyopen.model.page.PageBean;
|
import io.github.xxyopen.model.page.PageBean;
|
||||||
import io.github.xxyopen.model.page.builder.pagehelper.PageBuilder;
|
import io.github.xxyopen.model.page.builder.pagehelper.PageBuilder;
|
||||||
import io.github.xxyopen.model.resp.RestResult;
|
import io.github.xxyopen.model.resp.RestResult;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -10,6 +10,8 @@ import com.java2nb.novel.core.utils.RandomValidateCodeUtil;
|
|||||||
import io.github.xxyopen.model.resp.RestResult;
|
import io.github.xxyopen.model.resp.RestResult;
|
||||||
import io.github.xxyopen.util.UUIDUtil;
|
import io.github.xxyopen.util.UUIDUtil;
|
||||||
import io.github.xxyopen.web.exception.BusinessException;
|
import io.github.xxyopen.web.exception.BusinessException;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -19,8 +21,6 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ import com.java2nb.novel.core.bean.UserDetails;
|
|||||||
import com.java2nb.novel.core.config.AlipayProperties;
|
import com.java2nb.novel.core.config.AlipayProperties;
|
||||||
import com.java2nb.novel.core.utils.ThreadLocalUtil;
|
import com.java2nb.novel.core.utils.ThreadLocalUtil;
|
||||||
import com.java2nb.novel.service.OrderService;
|
import com.java2nb.novel.service.OrderService;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -19,8 +21,6 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -13,13 +13,13 @@ import com.java2nb.novel.service.UserService;
|
|||||||
import io.github.xxyopen.model.resp.RestResult;
|
import io.github.xxyopen.model.resp.RestResult;
|
||||||
import io.github.xxyopen.web.valid.AddGroup;
|
import io.github.xxyopen.web.valid.AddGroup;
|
||||||
import io.github.xxyopen.web.valid.UpdateGroup;
|
import io.github.xxyopen.web.valid.UpdateGroup;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.java2nb.novel.service.*;
|
|||||||
import com.java2nb.novel.vo.BookCommentVO;
|
import com.java2nb.novel.vo.BookCommentVO;
|
||||||
import com.java2nb.novel.vo.BookSettingVO;
|
import com.java2nb.novel.vo.BookSettingVO;
|
||||||
import io.github.xxyopen.model.page.PageBean;
|
import io.github.xxyopen.model.page.PageBean;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -17,7 +18,6 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.java2nb.novel.core.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.web.client.RestClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ai 相关配置
|
||||||
|
*
|
||||||
|
* @author xiongxiaoyang
|
||||||
|
* @date 2025/2/19
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class AiConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目的:配置自定义的 RestClientBuilder 对象
|
||||||
|
* <p>
|
||||||
|
* 原因:Spring AI 框架的 ChatClient 内部通过 RestClient(Spring Framework 6 和 Spring Boot 3 中引入) 发起 HTTP REST 请求与远程的大模型服务进行通信,
|
||||||
|
* 如果项目中没有配置自定义的 RestClientBuilder 对象, 那么在 RestClient 的自动配置类 org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration
|
||||||
|
* 中配置的 RestClientBuilder 对象会使用 Spring 容器中提供的 HttpMessageConverters, 由于本项目中配置了 spring.jackson.generator.write-numbers-as-strings
|
||||||
|
* = true, 所以 Spring 容器中的 HttpMessageConverters 在 RestClient 发起 HTTP REST 请求转换 Java 对象为 JSON 字符串时会自动将 Number 类型的
|
||||||
|
* Java 对象属性转换为字符串而导致请求参数错误
|
||||||
|
* <p>
|
||||||
|
* 示例:"temperature": 0.7 =》"temperature": "0.7"
|
||||||
|
* {"code":20015,"message":"The parameter is invalid. Please check again.","data":null}
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public RestClient.Builder restClientBuilder() {
|
||||||
|
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||||
|
// 连接超时时间
|
||||||
|
factory.setConnectTimeout(5000);
|
||||||
|
// 读取超时时间
|
||||||
|
factory.setReadTimeout(60000);
|
||||||
|
return RestClient.builder().requestFactory(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ChatClient chatClient(ChatClient.Builder chatClientBuilder) {
|
||||||
|
return chatClientBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,13 +2,13 @@ package com.java2nb.novel.core.config;
|
|||||||
|
|
||||||
import com.java2nb.novel.core.filter.NovelFilter;
|
import com.java2nb.novel.core.filter.NovelFilter;
|
||||||
import com.java2nb.novel.core.filter.XssFilter;
|
import com.java2nb.novel.core.filter.XssFilter;
|
||||||
|
import jakarta.servlet.DispatcherType;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import javax.servlet.DispatcherType;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@ package com.java2nb.novel.core.config;
|
|||||||
import com.java2nb.novel.core.converter.DateConverter;
|
import com.java2nb.novel.core.converter.DateConverter;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.format.FormatterRegistry;
|
import org.springframework.format.FormatterRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xiongxiaoyang
|
* @author xiongxiaoyang
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebMvcConfig extends WebMvcConfigurerAdapter {
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
@Override
|
@Override
|
||||||
public void addFormatters(FormatterRegistry registry) {
|
public void addFormatters(FormatterRegistry registry) {
|
||||||
registry.addConverter(new DateConverter());
|
registry.addConverter(new DateConverter());
|
||||||
|
@ -4,13 +4,14 @@ import com.java2nb.novel.core.cache.CacheKey;
|
|||||||
import com.java2nb.novel.core.cache.CacheService;
|
import com.java2nb.novel.core.cache.CacheService;
|
||||||
import com.java2nb.novel.core.utils.*;
|
import com.java2nb.novel.core.utils.*;
|
||||||
import io.github.xxyopen.util.UUIDUtil;
|
import io.github.xxyopen.util.UUIDUtil;
|
||||||
import io.github.xxyopen.web.util.SpringUtil;
|
import jakarta.servlet.*;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import javax.servlet.*;
|
import java.io.FileInputStream;
|
||||||
import javax.servlet.http.Cookie;
|
import java.io.IOException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import java.io.InputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import java.io.OutputStream;
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 项目核心过滤器
|
* 项目核心过滤器
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.java2nb.novel.core.filter;
|
package com.java2nb.novel.core.filter;
|
||||||
|
|
||||||
import com.java2nb.novel.core.wrapper.XssHttpServletRequestWrapper;
|
import com.java2nb.novel.core.wrapper.XssHttpServletRequestWrapper;
|
||||||
|
import jakarta.servlet.*;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import javax.servlet.*;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -3,38 +3,36 @@ package com.java2nb.novel.core.listener;
|
|||||||
import com.java2nb.novel.core.config.WebsiteProperties;
|
import com.java2nb.novel.core.config.WebsiteProperties;
|
||||||
import com.java2nb.novel.entity.WebsiteInfo;
|
import com.java2nb.novel.entity.WebsiteInfo;
|
||||||
import com.java2nb.novel.mapper.WebsiteInfoMapper;
|
import com.java2nb.novel.mapper.WebsiteInfoMapper;
|
||||||
|
import jakarta.servlet.ServletContext;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
|
||||||
import javax.servlet.ServletContextListener;
|
|
||||||
import javax.servlet.annotation.WebListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动监听器
|
* 启动监听器
|
||||||
*
|
*
|
||||||
* @author xiongxiaoyang
|
* @author xiongxiaoyang
|
||||||
*/
|
*/
|
||||||
@WebListener
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class StarterListener implements ServletContextListener {
|
public class StarterListener implements ServletContextInitializer {
|
||||||
|
|
||||||
private final WebsiteProperties websiteProperties;
|
private final WebsiteProperties websiteProperties;
|
||||||
|
|
||||||
private final WebsiteInfoMapper websiteInfoMapper;
|
private final WebsiteInfoMapper websiteInfoMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void onStartup(ServletContext servletContext) {
|
||||||
sce.getServletContext()
|
servletContext.setAttribute("website", websiteInfoMapper.selectByPrimaryKey(1L).orElse(new WebsiteInfo() {{
|
||||||
.setAttribute("website", websiteInfoMapper.selectByPrimaryKey(1L).orElse(new WebsiteInfo() {{
|
setName(websiteProperties.getName());
|
||||||
setName(websiteProperties.getName());
|
setDomain(websiteProperties.getDomain());
|
||||||
setDomain(websiteProperties.getDomain());
|
setKeyword(websiteProperties.getKeyword());
|
||||||
setKeyword(websiteProperties.getKeyword());
|
setDescription(websiteProperties.getDescription());
|
||||||
setDescription(websiteProperties.getDescription());
|
setQq(websiteProperties.getQq());
|
||||||
setQq(websiteProperties.getQq());
|
setLogo("/images/logo.png");
|
||||||
setLogo("/images/logo.png");
|
setLogoDark("/images/logo_white.png");
|
||||||
setLogoDark("/images/logo_white.png");
|
}}));
|
||||||
}}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ package com.java2nb.novel.core.schedule;
|
|||||||
|
|
||||||
import com.java2nb.novel.core.config.AuthorIncomeProperties;
|
import com.java2nb.novel.core.config.AuthorIncomeProperties;
|
||||||
import com.java2nb.novel.core.utils.DateUtil;
|
import com.java2nb.novel.core.utils.DateUtil;
|
||||||
import com.java2nb.novel.entity.*;
|
import com.java2nb.novel.entity.Author;
|
||||||
|
import com.java2nb.novel.entity.AuthorIncome;
|
||||||
|
import com.java2nb.novel.entity.Book;
|
||||||
import com.java2nb.novel.service.AuthorService;
|
import com.java2nb.novel.service.AuthorService;
|
||||||
import com.java2nb.novel.service.BookService;
|
import com.java2nb.novel.service.BookService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -64,24 +66,23 @@ public class MonthIncomeStaSchedule {
|
|||||||
|
|
||||||
Long bookId = book.getId();
|
Long bookId = book.getId();
|
||||||
|
|
||||||
|
|
||||||
//3.月收入数据未统计入库,分作品统计数据入库
|
//3.月收入数据未统计入库,分作品统计数据入库
|
||||||
Long monthIncome = authorService.queryTotalAccount(userId, bookId, startTime, endTime);
|
Long monthIncome = authorService.queryTotalAccount(userId, bookId, startTime, endTime);
|
||||||
|
|
||||||
BigDecimal monthIncomeShare = new BigDecimal(monthIncome)
|
BigDecimal monthIncomeShare = new BigDecimal(monthIncome)
|
||||||
.multiply(authorIncomeConfig.getShareProportion());
|
.multiply(authorIncomeConfig.getShareProportion());
|
||||||
long preTaxIncome = monthIncomeShare
|
long preTaxIncome = monthIncomeShare
|
||||||
.multiply(authorIncomeConfig.getExchangeProportion())
|
.multiply(authorIncomeConfig.getExchangeProportion())
|
||||||
.multiply(new BigDecimal(100))
|
.multiply(new BigDecimal(100))
|
||||||
.longValue();
|
.longValue();
|
||||||
|
|
||||||
totalPreTaxIncome += preTaxIncome;
|
totalPreTaxIncome += preTaxIncome;
|
||||||
|
|
||||||
long afterTaxIncome = monthIncomeShare
|
long afterTaxIncome = monthIncomeShare
|
||||||
.multiply(authorIncomeConfig.getTaxRate())
|
.multiply(authorIncomeConfig.getTaxRate())
|
||||||
.multiply(authorIncomeConfig.getExchangeProportion())
|
.multiply(authorIncomeConfig.getExchangeProportion())
|
||||||
.multiply(new BigDecimal(100))
|
.multiply(new BigDecimal(100))
|
||||||
.longValue();
|
.longValue();
|
||||||
|
|
||||||
totalAfterTaxIncome += afterTaxIncome;
|
totalAfterTaxIncome += afterTaxIncome;
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ public class MonthIncomeStaSchedule {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalPreTaxIncome > 0 && !authorService.queryIsStatisticsMonth(0L, endTime)) {
|
if (totalPreTaxIncome > 0 && !authorService.queryIsStatisticsMonth(authorId, 0L, endTime)) {
|
||||||
|
|
||||||
AuthorIncome authorIncome = new AuthorIncome();
|
AuthorIncome authorIncome = new AuthorIncome();
|
||||||
authorIncome.setAuthorId(authorId);
|
authorIncome.setAuthorId(authorId);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.java2nb.novel.core.utils;
|
package com.java2nb.novel.core.utils;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class BrowserUtil {
|
public class BrowserUtil {
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package com.java2nb.novel.core.utils;
|
package com.java2nb.novel.core.utils;
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
import jakarta.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
public class CookieUtil {
|
public class CookieUtil {
|
||||||
|
|
||||||
public static String getCookie(HttpServletRequest request,String key){
|
public static String getCookie(HttpServletRequest request, String key){
|
||||||
Cookie[] cookies = request.getCookies();
|
Cookie[] cookies = request.getCookies();
|
||||||
if(cookies != null) {
|
if(cookies != null) {
|
||||||
for (Cookie cookie : cookies) {
|
for (Cookie cookie : cookies) {
|
||||||
|
@ -2,7 +2,6 @@ package com.java2nb.novel.core.utils;
|
|||||||
|
|
||||||
import com.java2nb.novel.core.cache.CacheKey;
|
import com.java2nb.novel.core.cache.CacheKey;
|
||||||
import com.java2nb.novel.core.cache.CacheService;
|
import com.java2nb.novel.core.cache.CacheService;
|
||||||
import io.github.xxyopen.web.util.SpringUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板操作工具类
|
* 模板操作工具类
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package com.java2nb.novel.core.wrapper;
|
package com.java2nb.novel.core.wrapper;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletRequestWrapper;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletRequestWrapper;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XSS过滤处理
|
* XSS过滤处理
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.java2nb.novel.service;
|
package com.java2nb.novel.service;
|
||||||
|
|
||||||
|
|
||||||
import io.github.xxyopen.model.page.PageBean;
|
|
||||||
import com.java2nb.novel.entity.Author;
|
import com.java2nb.novel.entity.Author;
|
||||||
import com.java2nb.novel.entity.AuthorIncome;
|
import com.java2nb.novel.entity.AuthorIncome;
|
||||||
import com.java2nb.novel.entity.AuthorIncomeDetail;
|
import com.java2nb.novel.entity.AuthorIncomeDetail;
|
||||||
|
import io.github.xxyopen.model.page.PageBean;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -16,45 +16,51 @@ public interface AuthorService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验笔名是否存在
|
* 校验笔名是否存在
|
||||||
|
*
|
||||||
* @param penName 校验的笔名
|
* @param penName 校验的笔名
|
||||||
* @return true:存在该笔名,false: 不存在该笔名
|
* @return true:存在该笔名,false: 不存在该笔名
|
||||||
* */
|
*/
|
||||||
Boolean checkPenName(String penName);
|
Boolean checkPenName(String penName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作家注册
|
* 作家注册
|
||||||
|
*
|
||||||
* @param userId 注册用户ID
|
* @param userId 注册用户ID
|
||||||
*@param author 注册信息
|
* @param author 注册信息
|
||||||
* @return 返回错误信息
|
* @return 返回错误信息
|
||||||
* */
|
*/
|
||||||
String register(Long userId, Author author);
|
String register(Long userId, Author author);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否是作家
|
* 判断是否是作家
|
||||||
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return true:是作家,false: 不是作家
|
* @return true:是作家,false: 不是作家
|
||||||
* */
|
*/
|
||||||
Boolean isAuthor(Long userId);
|
Boolean isAuthor(Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询作家信息
|
* 查询作家信息
|
||||||
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 作家对象
|
* @return 作家对象
|
||||||
* */
|
*/
|
||||||
Author queryAuthor(Long userId);
|
Author queryAuthor(Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询作家列表
|
* 查询作家列表
|
||||||
* @return 作家列表
|
*
|
||||||
* @param limit 查询条数
|
* @param limit 查询条数
|
||||||
* @param maxAuthorCreateTime 最大申请时间
|
* @param maxAuthorCreateTime 最大申请时间
|
||||||
|
* @return 作家列表
|
||||||
*/
|
*/
|
||||||
List<Author> queryAuthorList(int limit, Date maxAuthorCreateTime);
|
List<Author> queryAuthorList(int limit, Date maxAuthorCreateTime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询收入日统计是否入库
|
* 查询收入日统计是否入库
|
||||||
|
*
|
||||||
* @param bookId 作品ID
|
* @param bookId 作品ID
|
||||||
* @param date 收入时间
|
* @param date 收入时间
|
||||||
* @return true:已入库,false:未入库
|
* @return true:已入库,false:未入库
|
||||||
*/
|
*/
|
||||||
boolean queryIsStatisticsDaily(Long bookId, Date date);
|
boolean queryIsStatisticsDaily(Long bookId, Date date);
|
||||||
@ -62,67 +68,75 @@ public interface AuthorService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存日收入统计(按作品)
|
* 保存日收入统计(按作品)
|
||||||
|
*
|
||||||
* @param authorIncomeDetail 收入详情
|
* @param authorIncomeDetail 收入详情
|
||||||
* */
|
*/
|
||||||
void saveDailyIncomeSta(AuthorIncomeDetail authorIncomeDetail);
|
void saveDailyIncomeSta(AuthorIncomeDetail authorIncomeDetail);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询月收入统计是否入库
|
* 查询月收入统计是否入库
|
||||||
* @param bookId 作品ID
|
*
|
||||||
|
* @param bookId 作品ID
|
||||||
* @param incomeDate 收入时间
|
* @param incomeDate 收入时间
|
||||||
* @return true:已入库,false:未入库
|
* @return true:已入库,false:未入库
|
||||||
* */
|
*/
|
||||||
boolean queryIsStatisticsMonth(Long bookId, Date incomeDate);
|
boolean queryIsStatisticsMonth(Long bookId, Date incomeDate);
|
||||||
|
|
||||||
|
boolean queryIsStatisticsMonth(Long authorId, Long bookId, Date incomeDate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询时间段内总订阅额
|
* 查询时间段内总订阅额
|
||||||
*
|
*
|
||||||
* @param userId
|
* @param userId
|
||||||
* @param bookId 作品ID
|
* @param bookId 作品ID
|
||||||
* @param startTime 开始时间
|
* @param startTime 开始时间
|
||||||
* @param endTime 结束时间
|
* @param endTime 结束时间
|
||||||
* @return 订阅额(屋币)
|
* @return 订阅额(屋币)
|
||||||
* */
|
*/
|
||||||
Long queryTotalAccount(Long userId, Long bookId, Date startTime, Date endTime);
|
Long queryTotalAccount(Long userId, Long bookId, Date startTime, Date endTime);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存月收入统计
|
* 保存月收入统计
|
||||||
|
*
|
||||||
* @param authorIncome 收入详情
|
* @param authorIncome 收入详情
|
||||||
* */
|
*/
|
||||||
void saveAuthorIncomeSta(AuthorIncome authorIncome);
|
void saveAuthorIncomeSta(AuthorIncome authorIncome);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询收入日统计是否入库
|
* 查询收入日统计是否入库
|
||||||
|
*
|
||||||
* @param authorId 作家ID
|
* @param authorId 作家ID
|
||||||
* @param bookId 作品ID
|
* @param bookId 作品ID
|
||||||
* @param date 收入时间
|
* @param date 收入时间
|
||||||
* @return true:已入库,false:未入库
|
* @return true:已入库,false:未入库
|
||||||
*/
|
*/
|
||||||
boolean queryIsStatisticsDaily(Long authorId, Long bookId, Date date);
|
boolean queryIsStatisticsDaily(Long authorId, Long bookId, Date date);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*作家日收入统计数据分页列表查询
|
* 作家日收入统计数据分页列表查询
|
||||||
|
*
|
||||||
* @param userId
|
* @param userId
|
||||||
* @param page 页码
|
* @param page 页码
|
||||||
* @param pageSize 分页大小
|
* @param pageSize 分页大小
|
||||||
* @param bookId 小说ID
|
* @param bookId 小说ID
|
||||||
* @param startTime 开始时间
|
* @param startTime 开始时间
|
||||||
* @param endTime 结束时间
|
* @param endTime 结束时间
|
||||||
* @return 日收入统计数据分页数据
|
* @return 日收入统计数据分页数据
|
||||||
*/
|
*/
|
||||||
PageBean<AuthorIncomeDetail> listIncomeDailyByPage(int page, int pageSize, Long userId, Long bookId, Date startTime, Date endTime);
|
PageBean<AuthorIncomeDetail> listIncomeDailyByPage(int page, int pageSize, Long userId, Long bookId, Date startTime,
|
||||||
|
Date endTime);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作家月收入统计数据分页列表查询
|
* 作家月收入统计数据分页列表查询
|
||||||
* @param page 页码
|
*
|
||||||
|
* @param page 页码
|
||||||
* @param pageSize 分页大小
|
* @param pageSize 分页大小
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param bookId 小说ID
|
* @param bookId 小说ID
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
* */
|
*/
|
||||||
PageBean<AuthorIncome> listIncomeMonthByPage(int page, int pageSize, Long userId, Long bookId);
|
PageBean<AuthorIncome> listIncomeMonthByPage(int page, int pageSize, Long userId, Long bookId);
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
package com.java2nb.novel.service.impl;
|
package com.java2nb.novel.service.impl;
|
||||||
|
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.github.xxyopen.model.page.PageBean;
|
|
||||||
import com.java2nb.novel.core.cache.CacheKey;
|
|
||||||
import com.java2nb.novel.core.cache.CacheService;
|
|
||||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
|
||||||
import io.github.xxyopen.model.page.builder.pagehelper.PageBuilder;
|
|
||||||
import io.github.xxyopen.web.exception.BusinessException;
|
|
||||||
import com.java2nb.novel.entity.Author;
|
import com.java2nb.novel.entity.Author;
|
||||||
import com.java2nb.novel.entity.AuthorIncome;
|
import com.java2nb.novel.entity.AuthorIncome;
|
||||||
import com.java2nb.novel.entity.AuthorIncomeDetail;
|
import com.java2nb.novel.entity.AuthorIncomeDetail;
|
||||||
import com.java2nb.novel.entity.FriendLink;
|
|
||||||
import com.java2nb.novel.mapper.*;
|
import com.java2nb.novel.mapper.*;
|
||||||
import com.java2nb.novel.service.AuthorService;
|
import com.java2nb.novel.service.AuthorService;
|
||||||
import com.java2nb.novel.service.FriendLinkService;
|
import io.github.xxyopen.model.page.PageBean;
|
||||||
|
import io.github.xxyopen.model.page.builder.pagehelper.PageBuilder;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.mybatis.dynamic.sql.render.RenderingStrategies;
|
import org.mybatis.dynamic.sql.render.RenderingStrategies;
|
||||||
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
|
|
||||||
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -25,10 +17,6 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.java2nb.novel.mapper.AuthorCodeDynamicSqlSupport.authorCode;
|
import static com.java2nb.novel.mapper.AuthorCodeDynamicSqlSupport.authorCode;
|
||||||
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.book;
|
|
||||||
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.id;
|
|
||||||
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.updateTime;
|
|
||||||
import static com.java2nb.novel.mapper.FriendLinkDynamicSqlSupport.*;
|
|
||||||
import static org.mybatis.dynamic.sql.SqlBuilder.*;
|
import static org.mybatis.dynamic.sql.SqlBuilder.*;
|
||||||
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||||
|
|
||||||
@ -52,7 +40,7 @@ public class AuthorServiceImpl implements AuthorService {
|
|||||||
@Override
|
@Override
|
||||||
public Boolean checkPenName(String penName) {
|
public Boolean checkPenName(String penName) {
|
||||||
return authorMapper.count(c ->
|
return authorMapper.count(c ->
|
||||||
c.where(AuthorDynamicSqlSupport.penName, isEqualTo(penName))) > 0;
|
c.where(AuthorDynamicSqlSupport.penName, isEqualTo(penName))) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@ -61,21 +49,21 @@ public class AuthorServiceImpl implements AuthorService {
|
|||||||
Date currentDate = new Date();
|
Date currentDate = new Date();
|
||||||
//判断邀请码是否有效
|
//判断邀请码是否有效
|
||||||
if (authorCodeMapper.count(c ->
|
if (authorCodeMapper.count(c ->
|
||||||
c.where(AuthorCodeDynamicSqlSupport.inviteCode, isEqualTo(author.getInviteCode()))
|
c.where(AuthorCodeDynamicSqlSupport.inviteCode, isEqualTo(author.getInviteCode()))
|
||||||
.and(AuthorCodeDynamicSqlSupport.isUse, isEqualTo((byte) 0))
|
.and(AuthorCodeDynamicSqlSupport.isUse, isEqualTo((byte) 0))
|
||||||
.and(AuthorCodeDynamicSqlSupport.validityTime, isGreaterThan(currentDate))) > 0) {
|
.and(AuthorCodeDynamicSqlSupport.validityTime, isGreaterThan(currentDate))) > 0) {
|
||||||
//邀请码有效
|
//邀请码有效
|
||||||
//保存作家信息
|
//保存作家信息
|
||||||
author.setUserId(userId);
|
author.setUserId(userId);
|
||||||
author.setCreateTime(currentDate);
|
author.setCreateTime(currentDate);
|
||||||
authorMapper.insertSelective(author);
|
authorMapper.insertSelective(author);
|
||||||
//设置邀请码状态为已使用
|
//设置邀请码状态为已使用
|
||||||
authorCodeMapper.update(update(authorCode)
|
authorCodeMapper.update(update(authorCode)
|
||||||
.set(AuthorCodeDynamicSqlSupport.isUse)
|
.set(AuthorCodeDynamicSqlSupport.isUse)
|
||||||
.equalTo((byte) 1)
|
.equalTo((byte) 1)
|
||||||
.where(AuthorCodeDynamicSqlSupport.inviteCode,isEqualTo(author.getInviteCode()))
|
.where(AuthorCodeDynamicSqlSupport.inviteCode, isEqualTo(author.getInviteCode()))
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3));
|
.render(RenderingStrategies.MYBATIS3));
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
//邀请码无效
|
//邀请码无效
|
||||||
@ -87,15 +75,15 @@ public class AuthorServiceImpl implements AuthorService {
|
|||||||
@Override
|
@Override
|
||||||
public Boolean isAuthor(Long userId) {
|
public Boolean isAuthor(Long userId) {
|
||||||
return authorMapper.count(c ->
|
return authorMapper.count(c ->
|
||||||
c.where(AuthorDynamicSqlSupport.userId, isEqualTo(userId))) > 0;
|
c.where(AuthorDynamicSqlSupport.userId, isEqualTo(userId))) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Author queryAuthor(Long userId) {
|
public Author queryAuthor(Long userId) {
|
||||||
return authorMapper.selectMany(
|
return authorMapper.selectMany(
|
||||||
select(AuthorDynamicSqlSupport.id,AuthorDynamicSqlSupport.penName,AuthorDynamicSqlSupport.status)
|
select(AuthorDynamicSqlSupport.id, AuthorDynamicSqlSupport.penName, AuthorDynamicSqlSupport.status)
|
||||||
.from(AuthorDynamicSqlSupport.author)
|
.from(AuthorDynamicSqlSupport.author)
|
||||||
.where(AuthorDynamicSqlSupport.userId,isEqualTo(userId))
|
.where(AuthorDynamicSqlSupport.userId, isEqualTo(userId))
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3)).get(0);
|
.render(RenderingStrategies.MYBATIS3)).get(0);
|
||||||
}
|
}
|
||||||
@ -103,12 +91,12 @@ public class AuthorServiceImpl implements AuthorService {
|
|||||||
@Override
|
@Override
|
||||||
public List<Author> queryAuthorList(int needAuthorNumber, Date maxAuthorCreateTime) {
|
public List<Author> queryAuthorList(int needAuthorNumber, Date maxAuthorCreateTime) {
|
||||||
return authorMapper.selectMany(select(AuthorDynamicSqlSupport.id, AuthorDynamicSqlSupport.userId)
|
return authorMapper.selectMany(select(AuthorDynamicSqlSupport.id, AuthorDynamicSqlSupport.userId)
|
||||||
.from(AuthorDynamicSqlSupport.author)
|
.from(AuthorDynamicSqlSupport.author)
|
||||||
.where(AuthorDynamicSqlSupport.createTime, isLessThan(maxAuthorCreateTime))
|
.where(AuthorDynamicSqlSupport.createTime, isLessThan(maxAuthorCreateTime))
|
||||||
.orderBy(AuthorDynamicSqlSupport.createTime.descending())
|
.orderBy(AuthorDynamicSqlSupport.createTime.descending())
|
||||||
.limit(needAuthorNumber)
|
.limit(needAuthorNumber)
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3));
|
.render(RenderingStrategies.MYBATIS3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,11 +104,11 @@ public class AuthorServiceImpl implements AuthorService {
|
|||||||
public boolean queryIsStatisticsDaily(Long bookId, Date date) {
|
public boolean queryIsStatisticsDaily(Long bookId, Date date) {
|
||||||
|
|
||||||
return authorIncomeDetailMapper.selectMany(select(AuthorIncomeDetailDynamicSqlSupport.id)
|
return authorIncomeDetailMapper.selectMany(select(AuthorIncomeDetailDynamicSqlSupport.id)
|
||||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||||
.where(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
.where(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isEqualTo(date))
|
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isEqualTo(date))
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,24 +121,35 @@ public class AuthorServiceImpl implements AuthorService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean queryIsStatisticsMonth(Long bookId, Date incomeDate) {
|
public boolean queryIsStatisticsMonth(Long bookId, Date incomeDate) {
|
||||||
return authorIncomeMapper.selectMany(select(AuthorIncomeDynamicSqlSupport.id)
|
return authorIncomeMapper.selectMany(select(AuthorIncomeDynamicSqlSupport.id)
|
||||||
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
||||||
.where(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
.where(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||||
.and(AuthorIncomeDynamicSqlSupport.incomeMonth, isEqualTo(incomeDate))
|
.and(AuthorIncomeDynamicSqlSupport.incomeMonth, isEqualTo(incomeDate))
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean queryIsStatisticsMonth(Long authorId, Long bookId, Date incomeDate) {
|
||||||
|
return authorIncomeMapper.selectMany(select(AuthorIncomeDynamicSqlSupport.id)
|
||||||
|
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
||||||
|
.where(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||||
|
.and(AuthorIncomeDynamicSqlSupport.authorId, isEqualTo(authorId))
|
||||||
|
.and(AuthorIncomeDynamicSqlSupport.incomeMonth, isEqualTo(incomeDate))
|
||||||
|
.build()
|
||||||
|
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long queryTotalAccount(Long userId, Long bookId, Date startTime, Date endTime) {
|
public Long queryTotalAccount(Long userId, Long bookId, Date startTime, Date endTime) {
|
||||||
|
|
||||||
return authorIncomeDetailMapper.selectStatistic(select(sum(AuthorIncomeDetailDynamicSqlSupport.incomeAccount))
|
return authorIncomeDetailMapper.selectStatistic(select(sum(AuthorIncomeDetailDynamicSqlSupport.incomeAccount))
|
||||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||||
.where(AuthorIncomeDetailDynamicSqlSupport.userId, isEqualTo(userId))
|
.where(AuthorIncomeDetailDynamicSqlSupport.userId, isEqualTo(userId))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isGreaterThanOrEqualTo(startTime))
|
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isGreaterThanOrEqualTo(startTime))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isLessThanOrEqualTo(endTime))
|
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isLessThanOrEqualTo(endTime))
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3));
|
.render(RenderingStrategies.MYBATIS3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -162,29 +161,30 @@ public class AuthorServiceImpl implements AuthorService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean queryIsStatisticsDaily(Long authorId, Long bookId, Date date) {
|
public boolean queryIsStatisticsDaily(Long authorId, Long bookId, Date date) {
|
||||||
return authorIncomeDetailMapper.selectMany(select(AuthorIncomeDetailDynamicSqlSupport.id)
|
return authorIncomeDetailMapper.selectMany(select(AuthorIncomeDetailDynamicSqlSupport.id)
|
||||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||||
.where(AuthorIncomeDetailDynamicSqlSupport.authorId, isEqualTo(authorId))
|
.where(AuthorIncomeDetailDynamicSqlSupport.authorId, isEqualTo(authorId))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isEqualTo(date))
|
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isEqualTo(date))
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageBean<AuthorIncomeDetail> listIncomeDailyByPage(int page, int pageSize, Long userId, Long bookId, Date startTime, Date endTime) {
|
public PageBean<AuthorIncomeDetail> listIncomeDailyByPage(int page, int pageSize, Long userId, Long bookId,
|
||||||
|
Date startTime, Date endTime) {
|
||||||
PageHelper.startPage(page, pageSize);
|
PageHelper.startPage(page, pageSize);
|
||||||
return PageBuilder.build(authorIncomeDetailMapper.selectMany(
|
return PageBuilder.build(authorIncomeDetailMapper.selectMany(
|
||||||
select(AuthorIncomeDetailDynamicSqlSupport.incomeDate, AuthorIncomeDetailDynamicSqlSupport.incomeAccount
|
select(AuthorIncomeDetailDynamicSqlSupport.incomeDate, AuthorIncomeDetailDynamicSqlSupport.incomeAccount
|
||||||
, AuthorIncomeDetailDynamicSqlSupport.incomeCount, AuthorIncomeDetailDynamicSqlSupport.incomeNumber)
|
, AuthorIncomeDetailDynamicSqlSupport.incomeCount, AuthorIncomeDetailDynamicSqlSupport.incomeNumber)
|
||||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||||
.where(AuthorIncomeDetailDynamicSqlSupport.userId, isEqualTo(userId))
|
.where(AuthorIncomeDetailDynamicSqlSupport.userId, isEqualTo(userId))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isGreaterThanOrEqualTo(startTime))
|
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isGreaterThanOrEqualTo(startTime))
|
||||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isLessThanOrEqualTo(endTime))
|
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isLessThanOrEqualTo(endTime))
|
||||||
.orderBy(AuthorIncomeDetailDynamicSqlSupport.incomeDate.descending())
|
.orderBy(AuthorIncomeDetailDynamicSqlSupport.incomeDate.descending())
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3)));
|
.render(RenderingStrategies.MYBATIS3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -192,15 +192,15 @@ public class AuthorServiceImpl implements AuthorService {
|
|||||||
public PageBean<AuthorIncome> listIncomeMonthByPage(int page, int pageSize, Long userId, Long bookId) {
|
public PageBean<AuthorIncome> listIncomeMonthByPage(int page, int pageSize, Long userId, Long bookId) {
|
||||||
PageHelper.startPage(page, pageSize);
|
PageHelper.startPage(page, pageSize);
|
||||||
return PageBuilder.build(authorIncomeMapper.selectMany(select(AuthorIncomeDynamicSqlSupport.incomeMonth
|
return PageBuilder.build(authorIncomeMapper.selectMany(select(AuthorIncomeDynamicSqlSupport.incomeMonth
|
||||||
, AuthorIncomeDynamicSqlSupport.preTaxIncome
|
, AuthorIncomeDynamicSqlSupport.preTaxIncome
|
||||||
, AuthorIncomeDynamicSqlSupport.afterTaxIncome
|
, AuthorIncomeDynamicSqlSupport.afterTaxIncome
|
||||||
, AuthorIncomeDynamicSqlSupport.payStatus
|
, AuthorIncomeDynamicSqlSupport.payStatus
|
||||||
, AuthorIncomeDynamicSqlSupport.confirmStatus)
|
, AuthorIncomeDynamicSqlSupport.confirmStatus)
|
||||||
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
||||||
.where(AuthorIncomeDynamicSqlSupport.userId, isEqualTo(userId))
|
.where(AuthorIncomeDynamicSqlSupport.userId, isEqualTo(userId))
|
||||||
.and(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
.and(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||||
.orderBy(AuthorIncomeDynamicSqlSupport.incomeMonth.descending())
|
.orderBy(AuthorIncomeDynamicSqlSupport.incomeMonth.descending())
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3)));
|
.render(RenderingStrategies.MYBATIS3)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,19 +29,16 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.mybatis.dynamic.sql.SortSpecification;
|
import org.mybatis.dynamic.sql.SortSpecification;
|
||||||
import org.mybatis.dynamic.sql.render.RenderingStrategies;
|
import org.mybatis.dynamic.sql.render.RenderingStrategies;
|
||||||
|
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
|
||||||
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import tk.mybatis.orderbyhelper.OrderByHelper;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.java2nb.novel.mapper.BookCategoryDynamicSqlSupport.bookCategory;
|
import static com.java2nb.novel.mapper.BookCategoryDynamicSqlSupport.bookCategory;
|
||||||
@ -201,9 +198,6 @@ public class BookServiceImpl implements BookService {
|
|||||||
|
|
||||||
PageHelper.startPage(page, pageSize);
|
PageHelper.startPage(page, pageSize);
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(params.getSort())) {
|
|
||||||
OrderByHelper.orderBy(params.getSort() + " desc");
|
|
||||||
}
|
|
||||||
return PageBuilder.build(bookMapper.searchByPage(params));
|
return PageBuilder.build(bookMapper.searchByPage(params));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -231,23 +225,22 @@ public class BookServiceImpl implements BookService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BookIndex> queryIndexList(Long bookId, String orderBy, Integer page, Integer pageSize) {
|
public List<BookIndex> queryIndexList(Long bookId, String orderBy, Integer page, Integer pageSize) {
|
||||||
if (StringUtils.isNotBlank(orderBy)) {
|
|
||||||
OrderByHelper.orderBy(orderBy);
|
|
||||||
}
|
|
||||||
if (page != null && pageSize != null) {
|
if (page != null && pageSize != null) {
|
||||||
PageHelper.startPage(page, pageSize);
|
PageHelper.startPage(page, pageSize);
|
||||||
}
|
}
|
||||||
|
QueryExpressionDSL<org.mybatis.dynamic.sql.select.SelectModel>.QueryExpressionWhereBuilder where = select(
|
||||||
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id,
|
BookIndexDynamicSqlSupport.id,
|
||||||
BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum,
|
BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum,
|
||||||
BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime,
|
BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime,
|
||||||
BookIndexDynamicSqlSupport.isVip)
|
BookIndexDynamicSqlSupport.isVip)
|
||||||
.from(bookIndex)
|
.from(bookIndex)
|
||||||
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
|
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId));
|
||||||
|
if("index_num desc".equals(orderBy)){
|
||||||
|
where.orderBy(BookIndexDynamicSqlSupport.indexNum.descending());
|
||||||
|
}
|
||||||
|
return bookIndexMapper.selectMany(where
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3);
|
.render(RenderingStrategies.MYBATIS3));
|
||||||
|
|
||||||
return bookIndexMapper.selectMany(selectStatement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -384,7 +377,6 @@ public class BookServiceImpl implements BookService {
|
|||||||
@Override
|
@Override
|
||||||
public PageBean<BookCommentVO> listCommentByPage(Long userId, Long bookId, int page, int pageSize) {
|
public PageBean<BookCommentVO> listCommentByPage(Long userId, Long bookId, int page, int pageSize) {
|
||||||
PageHelper.startPage(page, pageSize);
|
PageHelper.startPage(page, pageSize);
|
||||||
OrderByHelper.orderBy("t1.create_time desc");
|
|
||||||
return PageBuilder.build(bookCommentMapper.listCommentByPage(userId, bookId));
|
return PageBuilder.build(bookCommentMapper.listCommentByPage(userId, bookId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import com.java2nb.novel.core.serialize.CommentUserNameSerialize;
|
|||||||
import com.java2nb.novel.entity.BookComment;
|
import com.java2nb.novel.entity.BookComment;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.annotation.Generated;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
config:
|
||||||
include: [ common-dev ]
|
import: classpath:application-common-dev.yml
|
||||||
|
|
||||||
|
|
||||||
pic:
|
pic:
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
config:
|
||||||
include: [ common-prod ]
|
import: classpath:application-common-prod.yml
|
||||||
|
|
||||||
#静态文件路径配置
|
#静态文件路径配置
|
||||||
resources:
|
|
||||||
static-locations: file:${user.dir}/templates/${templates.name}/static/
|
|
||||||
#thymeleaf模版路径配置
|
#thymeleaf模版路径配置
|
||||||
thymeleaf:
|
thymeleaf:
|
||||||
prefix: file:${user.dir}/templates/${templates.name}/html/
|
prefix: file:${user.dir}/templates/${templates.name}/html/
|
||||||
suffix: .html
|
suffix: .html
|
||||||
|
web:
|
||||||
|
resources:
|
||||||
|
static-locations: file:${user.dir}/templates/${templates.name}/static/
|
||||||
|
|
||||||
#模版配置
|
#模版配置
|
||||||
templates:
|
templates:
|
||||||
|
@ -44,7 +44,15 @@ book:
|
|||||||
value: 5
|
value: 5
|
||||||
|
|
||||||
|
|
||||||
|
--- #--------------------- Spring AI 配置----------------------
|
||||||
|
spring:
|
||||||
|
ai:
|
||||||
|
openai:
|
||||||
|
api-key: sk-nnhjmxuljagcuubbovjztbhkiawqaabzziazeurppinxtgva
|
||||||
|
base-url: https://api.siliconflow.cn
|
||||||
|
chat:
|
||||||
|
options:
|
||||||
|
model: deepseek-ai/DeepSeek-R1-Distill-Llama-8B
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,9 +12,6 @@
|
|||||||
<!-- ConsoleAppender:把日志输出到控制台 -->
|
<!-- ConsoleAppender:把日志输出到控制台 -->
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<!--
|
|
||||||
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
|
||||||
-->
|
|
||||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
<!-- 控制台也要使用UTF-8,不要使用GBK,否则会中文乱码 -->
|
<!-- 控制台也要使用UTF-8,不要使用GBK,否则会中文乱码 -->
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
@ -22,43 +19,43 @@
|
|||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
||||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是demo.log -->
|
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是novel-front.log -->
|
||||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过1KB时,对当前日志进行分割 重命名 -->
|
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过10MB时,对当前日志进行分割 重命名 -->
|
||||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<!-- 设置日志文件路径 -->
|
||||||
<File>logs/novel-front.log</File>
|
<file>logs/novel-front.log</file>
|
||||||
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
|
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
|
||||||
<!-- TimeBasedRollingPolicy: 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动 -->
|
<!-- SizeAndTimeBasedRollingPolicy:基于时间和文件大小的滚动策略 -->
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||||
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
||||||
<!-- 文件名:logs/demo.2017-12-05.0.log -->
|
<!-- 文件名:logs/debug.2023-10-01.0.log -->
|
||||||
<fileNamePattern>logs/debug.%d.%i.log</fileNamePattern>
|
<fileNamePattern>logs/debug.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||||
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
|
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
|
||||||
<maxHistory>30</maxHistory>
|
<maxHistory>30</maxHistory>
|
||||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
<!-- 单个日志文件的最大大小 -->
|
||||||
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,测试时可改成1KB看效果 -->
|
<maxFileSize>10MB</maxFileSize>
|
||||||
<maxFileSize>10MB</maxFileSize>
|
<!-- 所有日志文件的总大小限制 -->
|
||||||
</timeBasedFileNamingAndTriggeringPolicy>
|
<totalSizeCap>1GB</totalSizeCap>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<!-- pattern节点,用来设置日志的输入格式 -->
|
<!-- pattern节点,用来设置日志的输入格式 -->
|
||||||
<pattern>
|
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
||||||
%d %p (%file:%line\)- %m%n
|
|
||||||
</pattern>
|
|
||||||
<!-- 记录日志的编码:此处设置字符集 - -->
|
<!-- 记录日志的编码:此处设置字符集 - -->
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- 控制台输出日志级别 -->
|
<!-- 控制台输出日志级别 -->
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||||
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
<!-- com.java2nb 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||||
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
||||||
<logger name="com.java2nb" level="DEBUG" additivity="false">
|
<logger name="com.java2nb" level="DEBUG" additivity="false">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
</logger>
|
</logger>
|
||||||
</configuration>
|
</configuration>
|
@ -14,7 +14,7 @@
|
|||||||
and t1.create_user_id = #{userId}
|
and t1.create_user_id = #{userId}
|
||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
|
order by t1.create_time desc
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@
|
|||||||
<if test="updateTimeMin != null">
|
<if test="updateTimeMin != null">
|
||||||
and last_index_update_time >= #{updateTimeMin}
|
and last_index_update_time >= #{updateTimeMin}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="sort != null">
|
||||||
|
order by ${sort} desc
|
||||||
|
</if>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 162 KiB |
@ -8,6 +8,79 @@
|
|||||||
<title>作家管理系统-小说精品屋</title>
|
<title>作家管理系统-小说精品屋</title>
|
||||||
<link rel="stylesheet" href="/css/base.css?v=1"/>
|
<link rel="stylesheet" href="/css/base.css?v=1"/>
|
||||||
<link rel="stylesheet" href="/css/user.css"/>
|
<link rel="stylesheet" href="/css/user.css"/>
|
||||||
|
<style>
|
||||||
|
/* 编辑器容器样式 */
|
||||||
|
.editor-container {
|
||||||
|
margin: 10px 0px;
|
||||||
|
padding: 20px;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 文本域样式 */
|
||||||
|
#bookContent {
|
||||||
|
width: 93%;
|
||||||
|
height: 400px;
|
||||||
|
padding: 15px;
|
||||||
|
border: 1px solid #e6e6e6;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 工具栏样式 */
|
||||||
|
.ai-toolbar {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px; /* 按钮间距 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 自定义链接按钮样式 */
|
||||||
|
.ai-link {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
background: linear-gradient(135deg, #6a11cb, #2575fc);
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 链接按钮悬停效果 */
|
||||||
|
.ai-link:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 链接按钮点击效果 */
|
||||||
|
.ai-link:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 不同按钮的颜色 */
|
||||||
|
.ai-link.expand {
|
||||||
|
background: linear-gradient(135deg, #ff9a9e, #fad0c4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ai-link.condense {
|
||||||
|
background: linear-gradient(135deg, #a18cd1, #fbc2eb);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ai-link.continue {
|
||||||
|
background: linear-gradient(135deg, #f6d365, #fda085);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ai-link.polish {
|
||||||
|
background: linear-gradient(135deg, #ff6f61, #ffcc00);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
</head>
|
</head>
|
||||||
<body class="">
|
<body class="">
|
||||||
@ -46,18 +119,29 @@
|
|||||||
<ul class="log_list">
|
<ul class="log_list">
|
||||||
<li><span id="LabErr"></span></li>
|
<li><span id="LabErr"></span></li>
|
||||||
<b>章节名:</b>
|
<b>章节名:</b>
|
||||||
<li><input type="text" id="bookIndex" name="bookIndex" class="s_input" ></li>
|
<li><input type="text" id="bookIndex" name="bookIndex" class="s_input"></li>
|
||||||
<b>章节内容:</b><li id="contentLi">
|
<b>章节内容:</b>
|
||||||
<textarea name="bookContent" rows="30" cols="80" id="bookContent"
|
<li id="contentLi" style="width: 500px">
|
||||||
class="textarea"></textarea></li><br/>
|
<div class="editor-container">
|
||||||
|
<div class="ai-toolbar">
|
||||||
|
<a class="ai-link expand" data-type="expand">AI扩写</a>
|
||||||
|
<a class="ai-link condense" data-type="condense">AI缩写</a>
|
||||||
|
<a class="ai-link continue" data-type="continue">AI续写</a>
|
||||||
|
<a class="ai-link polish" data-type="polish">AI润色</a>
|
||||||
|
</div>
|
||||||
|
<textarea id="bookContent" name="bookContent"
|
||||||
|
placeholder="请输入文本内容..."></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
<b>是否收费:</b>
|
<b>是否收费:</b>
|
||||||
<li><input type="radio" name="isVip" value="0" checked >免费
|
<li><input type="radio" name="isVip" value="0" checked>免费
|
||||||
<input type="radio" name="isVip" value="1" >收费</li>
|
<input type="radio" name="isVip" value="1">收费
|
||||||
|
</li>
|
||||||
|
|
||||||
|
|
||||||
<li style="margin-top: 10px"><input type="button" onclick="addBookContent()" name="btnRegister" value="提交"
|
<li style="margin-top: 10px"><input type="button" onclick="addBookContent()"
|
||||||
id="btnRegister" class="btn_red">
|
name="btnRegister" value="提交"
|
||||||
|
id="btnRegister" class="btn_red">
|
||||||
|
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
@ -113,9 +197,10 @@
|
|||||||
|
|
||||||
|
|
||||||
var lock = false;
|
var lock = false;
|
||||||
|
|
||||||
function addBookContent() {
|
function addBookContent() {
|
||||||
|
|
||||||
if(lock){
|
if (lock) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lock = true;
|
lock = true;
|
||||||
@ -125,14 +210,14 @@
|
|||||||
|
|
||||||
|
|
||||||
var indexName = $("#bookIndex").val();
|
var indexName = $("#bookIndex").val();
|
||||||
if(!indexName){
|
if (!indexName) {
|
||||||
$("#LabErr").html("章节名不能为空!");
|
$("#LabErr").html("章节名不能为空!");
|
||||||
lock = false;
|
lock = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var content = $("#bookContent").val();
|
var content = $("#bookContent").val();
|
||||||
if(!content){
|
if (!content) {
|
||||||
$("#LabErr").html("章节内容不能为空!");
|
$("#LabErr").html("章节内容不能为空!");
|
||||||
lock = false;
|
lock = false;
|
||||||
return;
|
return;
|
||||||
@ -142,17 +227,15 @@
|
|||||||
var isVip = $("input:checked[name=isVip]").val();
|
var isVip = $("input:checked[name=isVip]").val();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/author/addBookContent",
|
url: "/author/addBookContent",
|
||||||
data: {'bookId':bookId,'indexName':indexName,'content':content,'isVip':isVip},
|
data: {'bookId': bookId, 'indexName': indexName, 'content': content, 'isVip': isVip},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.code == 200) {
|
if (data.code == 200) {
|
||||||
|
|
||||||
window.location.href = '/author/index_list.html?bookId='+bookId;
|
window.location.href = '/author/index_list.html?bookId=' + bookId;
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -169,5 +252,110 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 打字机效果函数
|
||||||
|
function typeWriter(textarea, text, speed = 50) {
|
||||||
|
let i = 0;
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
if (i < text.length) {
|
||||||
|
textarea.val(textarea.val() + text.charAt(i));
|
||||||
|
i++;
|
||||||
|
// 滚动到底部
|
||||||
|
textarea.scrollTop(textarea[0].scrollHeight);
|
||||||
|
} else {
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
}, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.ai-toolbar .ai-link').click(function(e){
|
||||||
|
e.preventDefault(); // 阻止默认链接行为
|
||||||
|
const type = $(this).data('type');
|
||||||
|
const textarea = $('#bookContent');
|
||||||
|
const selectedText = textarea.val().substring(textarea[0].selectionStart, textarea[0].selectionEnd);
|
||||||
|
|
||||||
|
// 检查是否选中文本
|
||||||
|
if (!selectedText) {
|
||||||
|
layer.msg('请先选中要处理的文本');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loading = layer.load(1, {shade: 0.3});
|
||||||
|
|
||||||
|
// 参数配置
|
||||||
|
let params = {text: selectedText};
|
||||||
|
if(type === 'expand' || type === 'condense'){
|
||||||
|
layer.prompt({
|
||||||
|
title: '请输入比例',
|
||||||
|
value: 2,
|
||||||
|
btn: ['确定', '取消'],
|
||||||
|
btn2: function(){
|
||||||
|
layer.close(loading);
|
||||||
|
},
|
||||||
|
cancel: function(){
|
||||||
|
layer.close(loading);
|
||||||
|
}
|
||||||
|
}, function(value, index){
|
||||||
|
if(isNaN(Number(value)) || isNaN(parseFloat(value))){
|
||||||
|
layer.msg('请输入正确的比例');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(type === 'expand' && value <= 1){
|
||||||
|
layer.msg('请输入正确的比例');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(type === 'condense' && (value <=0 || value >= 1)){
|
||||||
|
layer.msg('请输入正确的比例');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
params.ratio = parseFloat(value) * 100;
|
||||||
|
layer.close(index);
|
||||||
|
sendRequest(type, params, loading, textarea);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}else if(type === 'continue'){
|
||||||
|
layer.prompt({
|
||||||
|
title: '请输入续写长度(字数)',
|
||||||
|
value: 200,
|
||||||
|
btn: ['确定', '取消'],
|
||||||
|
btn2: function(){
|
||||||
|
layer.close(loading);
|
||||||
|
},
|
||||||
|
cancel: function(){
|
||||||
|
layer.close(loading);
|
||||||
|
}
|
||||||
|
}, function(value, index){
|
||||||
|
if(!Number.isInteger(Number(value)) || value <= 0){
|
||||||
|
layer.msg('请输入正确的长度');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
params.length = parseInt(value);
|
||||||
|
layer.close(index);
|
||||||
|
sendRequest(type, params, loading, textarea);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendRequest(type, params, loading, textarea);
|
||||||
|
});
|
||||||
|
|
||||||
|
function sendRequest(type, params, loading, textarea){
|
||||||
|
$.ajax({
|
||||||
|
url: '/author/ai/' + type,
|
||||||
|
type: 'POST',
|
||||||
|
data: params,
|
||||||
|
success: function(res){
|
||||||
|
layer.close(loading);
|
||||||
|
// 将生成的内容追加到文本末尾
|
||||||
|
const newText = "\n\n" + res.data; // 添加换行符分隔
|
||||||
|
typeWriter(textarea, newText); // 使用打字机效果
|
||||||
|
},
|
||||||
|
error: function(){
|
||||||
|
layer.msg('请求失败,请稍后重试');
|
||||||
|
layer.close(loading);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<meta name="keywords" th:content="${application.website.name}+',小说,小说网,言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,原创网络文学'"/>
|
<meta name="keywords" th:content="${application.website.name}+',小说,小说网,言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,原创网络文学'"/>
|
||||||
<meta name="description"
|
<meta name="description"
|
||||||
th:content="${application.website.name}+'每日更新小说连载,小说排行榜,提供言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,首发小说,最新章节免费小说阅读,精彩尽在'+${application.website.name}+'。'"/>
|
th:content="${application.website.name}+'每日更新小说连载,小说排行榜,提供言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,首发小说,最新章节免费小说阅读,精彩尽在'+${application.website.name}+'。'"/>
|
||||||
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon"/>
|
<link href="/favicon.ico" type="image/x-icon" rel="shortcut icon"/>
|
||||||
<link href="favicon.ico" type="image/x-icon" rel="Bookmark"/>
|
<link href="/favicon.ico" type="image/x-icon" rel="Bookmark"/>
|
||||||
<link rel="stylesheet" href="/css/main.css"/>
|
<link rel="stylesheet" href="/css/main.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
<meta name="keywords" th:content="${application.website.keyword}"/>
|
<meta name="keywords" th:content="${application.website.keyword}"/>
|
||||||
<meta name="description"
|
<meta name="description"
|
||||||
th:content="${application.website.description}"/>
|
th:content="${application.website.description}"/>
|
||||||
<link href="favicon.ico" type="image/x-icon" rel="shortcut icon"/>
|
<link href="/favicon.ico" type="image/x-icon" rel="shortcut icon"/>
|
||||||
<link href="favicon.ico" type="image/x-icon" rel="Bookmark"/>
|
<link href="/favicon.ico" type="image/x-icon" rel="Bookmark"/>
|
||||||
<link rel="stylesheet" href="/css/main.css"/>
|
<link rel="stylesheet" href="/css/main.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -114,7 +114,7 @@
|
|||||||
style="color: #3eaf7c" id="accountBalance">10</em> 屋币<!--<em class="red">+0</em>代金券-->
|
style="color: #3eaf7c" id="accountBalance">10</em> 屋币<!--<em class="red">+0</em>代金券-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="payAmount" class="pay_way layui-row layui-col-space15" style="text-align: center;padding-top: 20px;">
|
<div id="payAmount" class="pay_way layui-row" style="text-align: center;padding-top: 20px;">
|
||||||
<h5>选择充值金额</h5>
|
<h5>选择充值金额</h5>
|
||||||
<li vals="10" class="layui-col-xs4 layui-col-sm3 layui-col-md2">
|
<li vals="10" class="layui-col-xs4 layui-col-sm3 layui-col-md2">
|
||||||
<div class="layui-panel">
|
<div class="layui-panel">
|
||||||
|
@ -20,6 +20,28 @@
|
|||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
|
body {
|
||||||
|
|
||||||
|
-webkit-user-select: none; /* Chrome, Safari, Opera */
|
||||||
|
|
||||||
|
|
||||||
|
-moz-user-select: none; /* Firefox */
|
||||||
|
|
||||||
|
|
||||||
|
-ms-user-select: none; /* Internet Explorer/Edge */
|
||||||
|
|
||||||
|
|
||||||
|
user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera, and Firefox */
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.line-limit-length {
|
.line-limit-length {
|
||||||
|
|
||||||
@ -62,11 +84,21 @@
|
|||||||
height: 180px;
|
height: 180px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#tipLayer {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
background-color: rgba(255, 0, 0, 0.8);
|
||||||
|
color: white;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 3px;
|
||||||
|
cursor: pointer;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<input type="hidden" id="limit" th:value="${limit}"/>
|
<input type="hidden" id="limit" th:value="${limit}"/>
|
||||||
<input type="hidden" id="curr" th:value="${curr}"/>
|
<input type="hidden" id="curr" th:value="${curr}"/>
|
||||||
<input type="hidden" id="total" th:value="${total}"/>
|
<input type="hidden" id="total" th:value="${total}"/>
|
||||||
@ -95,6 +127,10 @@
|
|||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<div id="tipLayer"
|
||||||
|
style="display:none; position:absolute; background-color:rgba(255, 0, 0, 0.8); color:white; padding:5px; border-radius:3px; cursor:pointer;">
|
||||||
|
移出书架
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="books" style="text-align: center;"></div>
|
<div id="books" style="text-align: center;"></div>
|
||||||
@ -105,11 +141,12 @@
|
|||||||
|
|
||||||
<a name="buttom"></a>
|
<a name="buttom"></a>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<div th:replace="mobile/common/js :: js"></div>
|
<div th:replace="mobile/common/js :: js"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
var timeout, isLongPress = false;
|
||||||
|
|
||||||
search(1, 20);
|
search(1, 20);
|
||||||
|
|
||||||
function search(curr, limit) {
|
function search(curr, limit) {
|
||||||
@ -136,22 +173,16 @@
|
|||||||
book.bookDesc = book.bookDesc.replace(/<[^>]+>/g, "").replace(/\s+/g, "").replace(/ /g, "");
|
book.bookDesc = book.bookDesc.replace(/<[^>]+>/g, "").replace(/\s+/g, "").replace(/ /g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
bookListHtml += ("<div class=\"layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
|
bookListHtml += ("<div id='"+book.bookId+"' onclick='read(\""+book.bookId+"\",\""+book.preContentId+"\")' class=\"item layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
|
||||||
" <a href='/book/" + book.bookId + "/" + book.preContentId + ".html'>\n" +
|
|
||||||
" <div class=\"layui-col-xs6 layui-col-sm3 layui-col-md2 layui-col-lg2\" style=\"text-align: center\">\n" +
|
" <div class=\"layui-col-xs6 layui-col-sm3 layui-col-md2 layui-col-lg2\" style=\"text-align: center\">\n" +
|
||||||
" <img style='width: 130px;height: 180px' align=\"center\"\n" +
|
" <img style='width: 130px;height: 180px' align=\"center\"\n" +
|
||||||
" src=\"" + book.picUrl + "\"/>\n" +
|
" src=\"" + book.picUrl + "\"/>\n" +
|
||||||
"\n" +
|
|
||||||
" </div>\n" +
|
" </div>\n" +
|
||||||
" </a>\n" +
|
" \n" +
|
||||||
" <div style=\"padding: 10px\" class=\"layui-col-xs6 layui-col-sm8 layui-col-md8 layui-col-lg8\">\n" +
|
" <div style=\"padding: 10px\" class=\"layui-col-xs6 layui-col-sm8 layui-col-md8 layui-col-lg8\">\n" +
|
||||||
" <a href='/book/" + book.bookId + "/" + book.preContentId + ".html'>\n" +
|
|
||||||
" <div class=\"line-limit-length\" style=\";color: #000;font-size: 15px\">" + book.bookName + "</div>\n" +
|
" <div class=\"line-limit-length\" style=\";color: #000;font-size: 15px\">" + book.bookName + "</div>\n" +
|
||||||
" </a>\n" +
|
|
||||||
" <div style=\";color: #4c6978;float: right;\"><i style=\"color: red\"></i></div>\n" +
|
" <div style=\";color: #4c6978;float: right;\"><i style=\"color: red\"></i></div>\n" +
|
||||||
" <a href='/book/" + book.bookId + "/" + book.preContentId + ".html'>\n" +
|
|
||||||
" <div style=\";color: #a6a6a6;\" class=\"line-limit-length\">作者:" + book.authorName + "</div>\n" +
|
" <div style=\";color: #a6a6a6;\" class=\"line-limit-length\">作者:" + book.authorName + "</div>\n" +
|
||||||
" </a>\n" +
|
|
||||||
" <div style=\"margin-top: 5px;color: #a6a6a6;\">类别:" + book.catName + "</div>\n" +
|
" <div style=\"margin-top: 5px;color: #a6a6a6;\">类别:" + book.catName + "</div>\n" +
|
||||||
" <div style=\"margin-top: 5px;color: #a6a6a6;\">状态:" + (book.bookStatus == 0 ? '连载' : '完结') + "</div>\n" +
|
" <div style=\"margin-top: 5px;color: #a6a6a6;\">状态:" + (book.bookStatus == 0 ? '连载' : '完结') + "</div>\n" +
|
||||||
" <div style=\"margin-top: 5px;color: #a6a6a6;\">更新:<i style='color: red'>" + book.lastIndexUpdateTime.substr(0, 11) + "</i>\n" +
|
" <div style=\"margin-top: 5px;color: #a6a6a6;\">更新:<i style='color: red'>" + book.lastIndexUpdateTime.substr(0, 11) + "</i>\n" +
|
||||||
@ -165,6 +196,43 @@
|
|||||||
}
|
}
|
||||||
$("#bookList").html(bookListHtml);
|
$("#bookList").html(bookListHtml);
|
||||||
|
|
||||||
|
|
||||||
|
$(".item").on('touchstart', function(e) {
|
||||||
|
var element = $(this);
|
||||||
|
// 清除可能存在的定时器
|
||||||
|
clearTimeout(timeout);
|
||||||
|
isLongPress = false;
|
||||||
|
|
||||||
|
// 获取触摸点位置
|
||||||
|
var touch = e.originalEvent.touches[0];
|
||||||
|
|
||||||
|
// 设置一个定时器,在500ms后触发(可以根据需要调整时间)
|
||||||
|
timeout = setTimeout(function() {
|
||||||
|
e.preventDefault();
|
||||||
|
showTip(touch, element);
|
||||||
|
}, 1000);
|
||||||
|
}).on('touchend', function(e) {
|
||||||
|
if (!isLongPress) {
|
||||||
|
// 如果没有发生长按,则执行点击事件的逻辑
|
||||||
|
clearTimeout(timeout);
|
||||||
|
}
|
||||||
|
}).on('touchmove', function() {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
hideTip();
|
||||||
|
}).on('contextmenu', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#tipLayer').click(function() {
|
||||||
|
// 点击tips层时删除对应的.item元素
|
||||||
|
removeFromBookShelf($(this).data('target').attr("id"));
|
||||||
|
$(this).data('target').remove();
|
||||||
|
hideTip();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
layui.use('laypage', function () {
|
layui.use('laypage', function () {
|
||||||
var laypage = layui.laypage;
|
var laypage = layui.laypage;
|
||||||
|
|
||||||
@ -203,6 +271,23 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showTip(touchEvent, element) {
|
||||||
|
isLongPress = true;
|
||||||
|
// 根据触摸点位置设置弹出层的位置
|
||||||
|
$('#tipLayer')
|
||||||
|
.css({
|
||||||
|
top: touchEvent.pageY - 100, // 调整这个值以改变弹出层相对于触摸点的位置
|
||||||
|
left: touchEvent.pageX - ($('#tipLayer').outerWidth() / 2)
|
||||||
|
})
|
||||||
|
.data('target', element) // 存储目标元素以便后续操作
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideTip() {
|
||||||
|
isLongPress = false;
|
||||||
|
$('#tipLayer').hide().removeData('target'); // 隐藏tips并清除数据
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function searchByAllCondition(curr, limit, newKeyword) {
|
function searchByAllCondition(curr, limit, newKeyword) {
|
||||||
var toUrl = "/book/search?curr=" + curr + "&limit=" + limit;
|
var toUrl = "/book/search?curr=" + curr + "&limit=" + limit;
|
||||||
@ -248,18 +333,35 @@
|
|||||||
searchByAllCondition(1, 20, keywords);
|
searchByAllCondition(1, 20, keywords);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function read(bookId,contentId){
|
||||||
|
if(isLongPress){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
location.href = '/book/'+bookId+"/"+contentId+".html"
|
||||||
|
hideTip();
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
||||||
function toMyCollect() {
|
function removeFromBookShelf(bookId) {
|
||||||
var token = localStorage.getItem("token");
|
|
||||||
if (token) {
|
$.ajax({
|
||||||
window.location.href = "/book/search?token=" + token;
|
type: "delete",
|
||||||
} else {
|
url: "/user/removeFromBookShelf/" + bookId,
|
||||||
window.location.href = "/user/login.html";
|
data: {},
|
||||||
}
|
dataType: "json",
|
||||||
}
|
success: function (data) {
|
||||||
|
if (data.code == 200) {
|
||||||
|
$("#shelf" + bookId).remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
更新时间
|
更新时间
|
||||||
</th>
|
</th>
|
||||||
<th class="goread">
|
<th class="goread">
|
||||||
书签
|
操作
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -94,7 +94,7 @@
|
|||||||
var bookShelfListHtml = "";
|
var bookShelfListHtml = "";
|
||||||
for (var i = 0; i < bookShelfList.length; i++) {
|
for (var i = 0; i < bookShelfList.length; i++) {
|
||||||
var book = bookShelfList[i];
|
var book = bookShelfList[i];
|
||||||
bookShelfListHtml += (" <tr class=\"book_list\" vals=\"291\">\n" +
|
bookShelfListHtml += (" <tr id='shelf" + book.bookId + "' class=\"book_list\" vals=\"291\">\n" +
|
||||||
" <td class=\"style bookclass\">\n" +
|
" <td class=\"style bookclass\">\n" +
|
||||||
" <a href=\"/book/bookclass.html?c=" + book.catId + "\" >[" + book.catName + "]</a>\n" +
|
" <a href=\"/book/bookclass.html?c=" + book.catId + "\" >[" + book.catName + "]</a>\n" +
|
||||||
" </td>\n" +
|
" </td>\n" +
|
||||||
@ -109,7 +109,8 @@
|
|||||||
" " + book.lastIndexUpdateTime + "\n" +
|
" " + book.lastIndexUpdateTime + "\n" +
|
||||||
" </td>\n" +
|
" </td>\n" +
|
||||||
" <td class=\"goread\">\n" +
|
" <td class=\"goread\">\n" +
|
||||||
"<a href='/book/" + book.bookId + "/" + book.preContentId + ".html'>继续阅读</a>" +
|
"<div style=''><a href='/book/" + book.bookId + "/" + book.preContentId + ".html'>继续阅读</a></div>" +
|
||||||
|
"<div style='line-height:8px;padding-bottom:13px'><a href='javascript:removeFromBookShelf(\"" + book.bookId + "\")'>移出书架</a></div>" +
|
||||||
" </td>\n" +
|
" </td>\n" +
|
||||||
" </tr>");
|
" </tr>");
|
||||||
}
|
}
|
||||||
@ -160,5 +161,21 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeFromBookShelf(bookId) {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "delete",
|
||||||
|
url: "/user/removeFromBookShelf/" + bookId,
|
||||||
|
data: {},
|
||||||
|
dataType: "json",
|
||||||
|
success: function (data) {
|
||||||
|
if (data.code == 200) {
|
||||||
|
$("#shelf" + bookId).remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user