mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-01 15:26:37 +00:00
Compare commits
51 Commits
dependabot
...
v5.0.0
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
976db9420e | |||
e33db86081 | |||
48a70c2aca | |||
ea5c0e8bd1 | |||
b0c249cdca | |||
730fcb4c76 | |||
b976a00389 | |||
6d9b563583 | |||
bfb7d6cc5c | |||
9d4dc409c6 | |||
34d211afbf | |||
2d218076c4 | |||
674e4df84c | |||
331f56d112 | |||
f494aae2c7 | |||
2fc533f8ae | |||
82758271e3 | |||
4c82c2d720 | |||
4665b5c4b9 | |||
7bbabb3492 |
13
README.md
13
README.md
@ -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">
|
||||
<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://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://github.com/201206030/novel-plus"><img src="https://visitor-badge.glitch.me/badge?page_id=201206030.novel-plus" alt="visitors"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
@ -61,9 +62,9 @@ novel-plus -- 父工程
|
||||
|
||||
### 绿色主题模版
|
||||
|
||||
[](https://youdoc.gitee.io/resource/images/os/novel-plus/green.png)
|
||||
[](https://youdoc.gitee.io/resource/images/os/novel-plus/green3.png)
|
||||
[](https://youdoc.gitee.io/resource/images/os/novel-plus/green2.png)
|
||||
[](https://www.xxyopen.com/images/green_novel.png)
|
||||
[](https://www.xxyopen.com/images/resource/os/novel-plus/green3.png)
|
||||
[](https://www.xxyopen.com/images/resource/os/novel-plus/green2.png)
|
||||
|
||||
## 演示视频
|
||||
|
||||
|
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
|
3
doc/sql/20240512.sql
Normal file
3
doc/sql/20240512.sql
Normal file
@ -0,0 +1,3 @@
|
||||
update crawl_source
|
||||
set crawl_rule = replace(crawl_rule, 'ibiquge.net', 'ibiquzw.org')
|
||||
where id = 16;
|
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.java2nb</groupId>
|
||||
<artifactId>novel-admin</artifactId>
|
||||
<version>4.3.0-RC1</version>
|
||||
<version>5.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>novel-admin</name>
|
||||
@ -14,18 +14,14 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.18.RELEASE</version>
|
||||
<version>2.7.18</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>21</java.version>
|
||||
<velocity.version>1.7</velocity.version>
|
||||
<activiti.version>5.22.0</activiti.version>
|
||||
<sharding.jdbc.version>3.0.0</sharding.jdbc.version>
|
||||
<jackson.version>2.15.1</jackson.version>
|
||||
<shardingsphere-jdbc.version>5.5.1</shardingsphere-jdbc.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -60,35 +56,24 @@
|
||||
<groupId>net.sourceforge.nekohtml</groupId>
|
||||
<artifactId>nekohtml</artifactId>
|
||||
</dependency>
|
||||
<!-- 请求参数校验相关 -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<!--mybatis -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.29</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.5.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<!--druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.9</version>
|
||||
</dependency>
|
||||
<!--commons -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
@ -103,7 +88,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
@ -138,6 +123,12 @@
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>1.7</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<groupId>commons-lang</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.boot</groupId>-->
|
||||
@ -166,6 +157,12 @@
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.6.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>guava</artifactId>
|
||||
<groupId>com.google.guava</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
@ -195,24 +192,29 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>1.4</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- ShardingSphere-JDBC -->
|
||||
<dependency>
|
||||
<groupId>io.shardingsphere</groupId>
|
||||
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
||||
<version>${sharding.jdbc.version}</version>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc</artifactId>
|
||||
<version>${shardingsphere-jdbc.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.shardingsphere</groupId>
|
||||
<artifactId>sharding-jdbc-spring-namespace</artifactId>
|
||||
<version>${sharding.jdbc.version}</version>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!--war包部署需要-->
|
||||
@ -282,6 +284,11 @@
|
||||
<include name="*.*"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${project.build.directory}/build/config" overwrite="true">
|
||||
<fileset dir="${basedir}/../config">
|
||||
<include name="*.*"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy file="${project.build.directory}/${project.artifactId}-${project.version}.jar"
|
||||
tofile="${project.build.directory}/build/${project.artifactId}.jar"/>
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,19 +1,16 @@
|
||||
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.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import sun.net.util.IPAddressUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Aspect
|
||||
@ -37,11 +34,10 @@ public class WebLogAspect {
|
||||
logger.info("请求地址 : " + request.getRequestURL().toString());
|
||||
logger.info("HTTP METHOD : " + request.getMethod());
|
||||
// 获取真实的ip地址
|
||||
//logger.info("IP : " + IPAddressUtil.getClientIpAddress(request));
|
||||
logger.info("IP : " + IPUtils.getIpAddr(request));
|
||||
logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
|
||||
+ joinPoint.getSignature().getName());
|
||||
+ joinPoint.getSignature().getName());
|
||||
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 {
|
||||
|
||||
@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},'%')")
|
||||
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);
|
||||
|
||||
@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}")
|
||||
Map<String, String> get(String tableName);
|
||||
|
||||
@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")
|
||||
List<Map<String, String>> listColumns(String tableName);
|
||||
|
||||
@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")
|
||||
Map<String, String> getPriColumn(String tableName);
|
||||
}
|
||||
|
@ -2,32 +2,27 @@ package com.java2nb.common.exception;
|
||||
|
||||
|
||||
import com.java2nb.common.utils.R;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
||||
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.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
public class MainsiteErrorController implements ErrorController {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private static final String ERROR_PATH = "/error";
|
||||
|
||||
@Autowired
|
||||
ErrorAttributes errorAttributes;
|
||||
|
||||
@RequestMapping(
|
||||
value = {ERROR_PATH},
|
||||
produces = {"text/html"}
|
||||
value = {ERROR_PATH},
|
||||
produces = {"text/html"}
|
||||
)
|
||||
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
|
||||
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;
|
||||
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
@ -8,79 +7,80 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static String beanToJson(Object object) {
|
||||
if (object != null) {
|
||||
return JSON.toJSONString(object);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* String转JSON字符串
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static String stringToJsonByFastjson(String key, String value) {
|
||||
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
Map<String, String> map = new HashMap<String, String>(16);
|
||||
map.put(key, value);
|
||||
return beanToJson(map, null);
|
||||
}
|
||||
/**
|
||||
* Bean对象转JSON
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static String beanToJson(Object object) {
|
||||
if (object != null) {
|
||||
return JSON.toJSONString(object);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将json字符串转换成对象
|
||||
*
|
||||
* @param json
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static Object jsonToBean(String json, Object clazz) {
|
||||
if (StringUtils.isEmpty(json) || clazz == null) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parseObject(json, clazz.getClass());
|
||||
}
|
||||
/**
|
||||
* String转JSON字符串
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static String stringToJsonByFastjson(String key, String value) {
|
||||
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
Map<String, String> map = new HashMap<String, String>(16);
|
||||
map.put(key, value);
|
||||
return beanToJson(map, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
/**
|
||||
* 将json字符串转换成对象
|
||||
*
|
||||
* @param json
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static Object jsonToBean(String json, Object clazz) {
|
||||
if (StringUtils.isEmpty(json) || clazz == null) {
|
||||
return null;
|
||||
}
|
||||
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
|
||||
com.java2nb: debug
|
||||
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:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password: test123456
|
||||
# 连接超时时间(毫秒)
|
||||
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
|
||||
com.java2nb: error
|
||||
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:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password: test
|
||||
password: test123456
|
||||
# 连接超时时间(毫秒)
|
||||
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:
|
||||
# enabled: false
|
||||
spring:
|
||||
datasource:
|
||||
driverClassName: org.apache.shardingsphere.driver.ShardingSphereDriver
|
||||
url: jdbc:shardingsphere:absolutepath:${user.dir}/config/shardingsphere-jdbc.yml
|
||||
thymeleaf:
|
||||
mode: LEGACYHTML5
|
||||
cache: false
|
||||
@ -18,11 +21,12 @@ spring:
|
||||
profiles:
|
||||
active: dev
|
||||
|
||||
#上传文件的最大值(10M)
|
||||
#上传文件的最大值(100M)
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 10485760
|
||||
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
devtools:
|
||||
restart:
|
||||
enabled: true
|
||||
|
@ -79,7 +79,7 @@ function update() {
|
||||
},
|
||||
success: function (data) {
|
||||
if (data.code == 0) {
|
||||
layer.msg("操作成功");
|
||||
layer.msg("操作成功,重启 novel-front 后生效");
|
||||
} else {
|
||||
layer.alert(data.msg)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>novel</artifactId>
|
||||
<groupId>com.java2nb</groupId>
|
||||
<version>4.3.0-RC1</version>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -52,18 +52,16 @@
|
||||
</dependency>
|
||||
|
||||
<!-- 分库分表-->
|
||||
<!-- sharding jdbc依赖 -->
|
||||
|
||||
<!-- ShardingSphere-JDBC -->
|
||||
<dependency>
|
||||
<groupId>io.shardingsphere</groupId>
|
||||
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
||||
<version>${sharding.jdbc.version}</version>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc</artifactId>
|
||||
<version>${shardingsphere-jdbc.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.shardingsphere</groupId>
|
||||
<artifactId>sharding-jdbc-spring-namespace</artifactId>
|
||||
<version>${sharding.jdbc.version}</version>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@ -73,11 +71,6 @@
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>${pagehelper.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cuisongliu</groupId>
|
||||
<artifactId>orderbyhelper-spring-boot-starter</artifactId>
|
||||
<version>${orderbyhelper.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@ -86,15 +79,8 @@
|
||||
</dependency>
|
||||
<!--httpclient-->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.14</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -117,6 +103,12 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- 请求参数校验相关 -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.github.xxyopen</groupId>
|
||||
<artifactId>xxy-model</artifactId>
|
||||
|
@ -0,0 +1,35 @@
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@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 RestResult<Void> handlerException(Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return RestResult.error();
|
||||
}
|
||||
}
|
@ -19,4 +19,8 @@ public class HttpProxyProperties {
|
||||
|
||||
private Integer port;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@ -14,7 +14,10 @@ import org.springframework.http.ResponseEntity;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
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.Objects;
|
||||
|
||||
@ -37,10 +40,13 @@ public class FileUtil {
|
||||
//本地图片保存
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
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();
|
||||
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()
|
||||
+ picSrc.substring(picSrc.lastIndexOf("."));
|
||||
File picFile = new File(picSavePath + picSrc);
|
||||
@ -67,7 +73,6 @@ public class FileUtil {
|
||||
closeStream(input, out);
|
||||
}
|
||||
|
||||
|
||||
return picSrc;
|
||||
}
|
||||
|
||||
|
@ -1,47 +1,52 @@
|
||||
package com.java2nb.novel.core.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Slf4j
|
||||
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 {
|
||||
|
||||
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
|
||||
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, HttpMethod.GET, requestEntity,
|
||||
String.class);
|
||||
log.debug("Response code:{}", forEntity.getStatusCode());
|
||||
if (forEntity.getStatusCode() == HttpStatus.OK) {
|
||||
return forEntity.getBody();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getByHttpClientWithChrome(String url) {
|
||||
try {
|
||||
|
||||
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;
|
||||
}
|
||||
return getByHttpClientWithChrome(url, DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.java2nb.novel.core.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
public class IpUtil {
|
||||
|
||||
|
@ -2,17 +2,22 @@ package com.java2nb.novel.core.utils;
|
||||
|
||||
import com.java2nb.novel.core.config.HttpProxyProperties;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.config.Registry;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
||||
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.TrustStrategy;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.hc.client5.http.auth.AuthScope;
|
||||
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
|
||||
import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
|
||||
import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
|
||||
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.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
@ -26,21 +31,21 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class RestTemplateUtil {
|
||||
public class RestTemplates {
|
||||
|
||||
private static HttpProxyProperties httpProxyProperties;
|
||||
|
||||
RestTemplateUtil(HttpProxyProperties properties) {
|
||||
RestTemplates(HttpProxyProperties properties) {
|
||||
httpProxyProperties = properties;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static RestTemplate getInstance(String charset) {
|
||||
public static RestTemplate newInstance(String charset) {
|
||||
|
||||
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
|
||||
|
||||
//忽略证书
|
||||
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
|
||||
SSLContext sslContext = SSLContexts.custom()
|
||||
.loadTrustMaterial(null, acceptingTrustStrategy)
|
||||
.build();
|
||||
|
||||
@ -61,6 +66,15 @@ public class RestTemplateUtil {
|
||||
if (Objects.nonNull(httpProxyProperties) && Boolean.TRUE.equals(httpProxyProperties.getEnabled())) {
|
||||
HttpHost proxy = new HttpHost(httpProxyProperties.getIp(), httpProxyProperties.getPort());
|
||||
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)
|
||||
.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.UpdateGroup;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
import javax.validation.constraints.*;
|
||||
import java.util.Date;
|
||||
|
||||
public class User {
|
||||
|
@ -1,71 +1,18 @@
|
||||
spring:
|
||||
profiles:
|
||||
include: [ common ]
|
||||
config:
|
||||
import: classpath:application-common.yml
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
#Redis服务器IP
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
#Redis服务器连接端口
|
||||
port: 6379
|
||||
#Redis服务器连接密码
|
||||
password: test123456
|
||||
jedis:
|
||||
pool:
|
||||
#连接池最大连接数(使用负值表示没有限制)
|
||||
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}
|
||||
|
||||
data:
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
#Redis服务器连接端口
|
||||
port: 6379
|
||||
#Redis服务器连接密码
|
||||
password: test123456
|
||||
#连接超时时间(毫秒)
|
||||
timeout: 10000
|
||||
|
||||
content:
|
||||
save:
|
||||
@ -78,6 +25,10 @@ http:
|
||||
# 是否开启 HTTP 代理,true-开启,false-不开启
|
||||
enabled: false
|
||||
# 代理 IP
|
||||
ip: u493.kdltps.com
|
||||
ip: us.swiftproxy.net
|
||||
# 代理端口号
|
||||
port: 15818
|
||||
port: 7878
|
||||
# 代理用户名
|
||||
username: swiftproxy_u
|
||||
# 代理密码
|
||||
password: swiftproxy_p
|
@ -1,71 +1,18 @@
|
||||
spring:
|
||||
profiles:
|
||||
include: [ common ]
|
||||
config:
|
||||
import: classpath:application-common.yml
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
#Redis服务器IP
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
#Redis服务器连接端口
|
||||
port: 6379
|
||||
#Redis服务器连接密码
|
||||
password: test
|
||||
jedis:
|
||||
pool:
|
||||
#连接池最大连接数(使用负值表示没有限制)
|
||||
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}
|
||||
|
||||
data:
|
||||
redis:
|
||||
#Redis服务器IP
|
||||
host: 127.0.0.1
|
||||
#Redis服务器连接端口
|
||||
port: 6379
|
||||
#Redis服务器连接密码
|
||||
password: test123456
|
||||
#连接超时时间(毫秒)
|
||||
timeout: 10000
|
||||
|
||||
logging:
|
||||
level:
|
||||
|
@ -1,4 +1,7 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:shardingsphere:absolutepath:${user.dir}/config/shardingsphere-jdbc.yml
|
||||
driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
|
||||
cache:
|
||||
ehcache:
|
||||
config: classpath:ehcache.xml
|
||||
@ -11,10 +14,11 @@ spring:
|
||||
generator:
|
||||
write-numbers-as-strings: true
|
||||
|
||||
#上传文件的最大值(1M)
|
||||
#上传文件的最大值(100M)
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 1048576
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
mybatis:
|
||||
configuration:
|
||||
@ -26,6 +30,8 @@ mybatis:
|
||||
logging:
|
||||
config: classpath:logback-boot.xml
|
||||
|
||||
pagehelper:
|
||||
helper-dialect: mysql
|
||||
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>novel</artifactId>
|
||||
<groupId>com.java2nb</groupId>
|
||||
<version>4.3.0-RC1</version>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -21,6 +21,12 @@
|
||||
<artifactId>novel-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
@ -29,7 +35,6 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@ -58,6 +63,11 @@
|
||||
<include name="*.*"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${project.build.directory}/build/config" overwrite="true">
|
||||
<fileset dir="${basedir}/../config">
|
||||
<include name="*.*"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy file="${project.build.directory}/${project.artifactId}-${project.version}.jar"
|
||||
tofile="${project.build.directory}/build/${project.artifactId}.jar"/>
|
||||
|
||||
|
@ -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
|
@ -4,14 +4,15 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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.WebSecurity;
|
||||
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.UserDetails;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
/**
|
||||
* SpringSecurity配置
|
||||
@ -21,7 +22,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@RequiredArgsConstructor
|
||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
public class SecurityConfiguration {
|
||||
|
||||
@Value("${admin.username}")
|
||||
private String username;
|
||||
@ -29,39 +30,40 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
@Value("${admin.password}")
|
||||
private String password;
|
||||
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void configure(WebSecurity web) throws Exception {
|
||||
super.configure(web);
|
||||
@Bean
|
||||
public InMemoryUserDetailsManager userDetailsService() {
|
||||
UserDetails admin = User.builder()
|
||||
.username(username)
|
||||
.password(passwordEncoder().encode(password))
|
||||
.roles("ADMIN")
|
||||
.build();
|
||||
return new InMemoryUserDetailsManager(admin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
@Bean
|
||||
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);
|
||||
auth.inMemoryAuthentication().withUser(builder.username(username).password(password).roles("ADMIN").build());
|
||||
return http.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;
|
||||
|
||||
import com.java2nb.novel.core.utils.HttpUtil;
|
||||
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.entity.Book;
|
||||
import com.java2nb.novel.entity.BookContent;
|
||||
import com.java2nb.novel.entity.BookIndex;
|
||||
import com.java2nb.novel.utils.Constants;
|
||||
import com.java2nb.novel.utils.CrawlHttpClient;
|
||||
import io.github.xxyopen.util.IdWorker;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
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.Pattern;
|
||||
|
||||
@ -26,20 +26,19 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
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 static final ThreadLocal<Integer> retryCount = new ThreadLocal<>();
|
||||
private final CrawlHttpClient crawlHttpClient;
|
||||
|
||||
@SneakyThrows
|
||||
public static void parseBook(RuleBean ruleBean, String bookId, CrawlBookHandler handler) {
|
||||
public void parseBook(RuleBean ruleBean, String bookId, CrawlBookHandler handler) {
|
||||
Book book = new Book();
|
||||
String bookDetailUrl = ruleBean.getBookDetailUrl().replace("{bookId}", bookId);
|
||||
String bookDetailHtml = getByHttpClientWithChrome(bookDetailUrl);
|
||||
String bookDetailHtml = crawlHttpClient.get(bookDetailUrl, ruleBean.getCharset());
|
||||
if (bookDetailHtml != null) {
|
||||
Pattern bookNamePatten = PatternFactory.getPattern(ruleBean.getBookNamePatten());
|
||||
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.replaceAll("<a[^<]+</a>", "")
|
||||
.replaceAll("<font[^<]+</font>", "")
|
||||
.replaceAll("<p>\\s*</p>", "")
|
||||
.replaceAll("<p>", "")
|
||||
.replaceAll("</p>", "<br/>");
|
||||
.replaceAll("<font[^<]+</font>", "")
|
||||
.replaceAll("<p>\\s*</p>", "")
|
||||
.replaceAll("<p>", "")
|
||||
.replaceAll("</p>", "<br/>");
|
||||
//设置书籍简介
|
||||
book.setBookDesc(desc);
|
||||
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());
|
||||
Matcher updateTimeMatch = updateTimePatten.matcher(bookDetailHtml);
|
||||
boolean isFindUpdateTime = updateTimeMatch.find();
|
||||
if (isFindUpdateTime) {
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@ -149,11 +152,12 @@ public class CrawlParser {
|
||||
List<BookContent> contentList = new ArrayList<>();
|
||||
//读取目录
|
||||
String indexListUrl = ruleBean.getBookIndexUrl().replace("{bookId}", sourceBookId);
|
||||
String indexListHtml = getByHttpClientWithChrome(indexListUrl);
|
||||
String indexListHtml = crawlHttpClient.get(indexListUrl, ruleBean.getCharset());
|
||||
|
||||
if (indexListHtml != null) {
|
||||
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());
|
||||
@ -174,14 +178,16 @@ public class CrawlParser {
|
||||
BookIndex hasIndex = existBookIndexMap.get(indexNum);
|
||||
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 bookContentUrl = ruleBean.getBookContentUrl();
|
||||
int calStart = bookContentUrl.indexOf("{cal_");
|
||||
if (calStart != -1) {
|
||||
//内容页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("_");
|
||||
int calType = Integer.parseInt(calArr[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("正在手打中")) {
|
||||
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()));
|
||||
// 小说内容过滤
|
||||
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.setIndexName(indexName);
|
||||
@ -235,7 +253,7 @@ public class CrawlParser {
|
||||
} else {
|
||||
//章节插入
|
||||
//设置目录和章节内容
|
||||
Long indexId = idWorker.nextId();
|
||||
Long indexId = ID_WORKER.nextId();
|
||||
bookIndex.setId(indexId);
|
||||
bookIndex.setBookId(book.getId());
|
||||
|
||||
@ -257,7 +275,6 @@ public class CrawlParser {
|
||||
isFindIndex = indexIdMatch.find() & indexNameMatch.find();
|
||||
}
|
||||
|
||||
|
||||
if (indexList.size() > 0) {
|
||||
//如果有爬到最新章节,则设置小说主表的最新章节信息
|
||||
//获取爬取到的最新章节
|
||||
@ -290,56 +307,4 @@ public class CrawlParser {
|
||||
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;
|
||||
|
||||
import com.java2nb.novel.utils.Constants;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 爬虫解析规则bean
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class RuleBean {
|
||||
|
||||
/**
|
||||
* 网页字符编码
|
||||
*/
|
||||
private String charset = Constants.CRAWL_DEFAULT_CHARSET;
|
||||
|
||||
|
||||
/**
|
||||
* 小说更新列表url
|
||||
* */
|
||||
*/
|
||||
private String updateBookListUrl;
|
||||
|
||||
/**
|
||||
* 分类列表页URL规则
|
||||
* */
|
||||
*/
|
||||
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 pagePatten;
|
||||
@ -51,5 +59,7 @@ public class RuleBean {
|
||||
|
||||
private String bookIndexStart;
|
||||
|
||||
private String filterContent;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,23 @@
|
||||
package com.java2nb.novel.core.listener;
|
||||
|
||||
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.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.CrawlService;
|
||||
import com.java2nb.novel.utils.Constants;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
@ -24,20 +26,22 @@ import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@WebListener
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class StarterListener implements ServletContextListener {
|
||||
public class StarterListener implements ServletContextInitializer {
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
private final CrawlService crawlService;
|
||||
|
||||
private final CrawlParser crawlParser;
|
||||
|
||||
@Value("${crawl.update.thread}")
|
||||
private int updateThreadCount;
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
public void onStartup(ServletContext servletContext) {
|
||||
for (int i = 0; i < updateThreadCount; i++) {
|
||||
new Thread(() -> {
|
||||
log.info("程序启动,开始执行自动更新线程。。。");
|
||||
@ -56,20 +60,24 @@ public class StarterListener implements ServletContextListener {
|
||||
CrawlSource source = crawlService.queryCrawlSource(needUpdateBook.getCrawlSourceId());
|
||||
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.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);
|
||||
}
|
||||
//查询已存在的章节
|
||||
Map<Integer, BookIndex> existBookIndexMap = bookService.queryExistBookIndexMap(needUpdateBook.getId());
|
||||
Map<Integer, BookIndex> existBookIndexMap = bookService.queryExistBookIndexMap(
|
||||
needUpdateBook.getId());
|
||||
//解析章节目录
|
||||
CrawlParser.parseBookIndexAndContent(needUpdateBook.getCrawlBookId(), book, ruleBean, existBookIndexMap,chapter -> {
|
||||
bookService.updateBookAndIndexAndContent(book, chapter.getBookIndexList(), chapter.getBookContentList(), existBookIndexMap);
|
||||
});
|
||||
crawlParser.parseBookIndexAndContent(needUpdateBook.getCrawlBookId(), book,
|
||||
ruleBean, existBookIndexMap, chapter -> {
|
||||
bookService.updateBookAndIndexAndContent(book, chapter.getBookIndexList(),
|
||||
chapter.getBookContentList(), existBookIndexMap);
|
||||
});
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
@ -88,7 +96,6 @@ public class StarterListener implements ServletContextListener {
|
||||
|
||||
}
|
||||
|
||||
|
||||
new Thread(() -> {
|
||||
log.info("程序启动,开始执行单本采集任务线程。。。");
|
||||
while (true) {
|
||||
@ -103,7 +110,8 @@ public class StarterListener implements ServletContextListener {
|
||||
CrawlSource source = crawlService.queryCrawlSource(task.getSourceId());
|
||||
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;
|
||||
}
|
||||
|
@ -2,17 +2,12 @@ package com.java2nb.novel.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.crawl.CrawlParser;
|
||||
import com.java2nb.novel.core.crawl.RuleBean;
|
||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||
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 com.java2nb.novel.core.utils.SpringUtil;
|
||||
import com.java2nb.novel.entity.Book;
|
||||
import com.java2nb.novel.entity.CrawlSingleTask;
|
||||
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.service.BookService;
|
||||
import com.java2nb.novel.service.CrawlService;
|
||||
import com.java2nb.novel.utils.CrawlHttpClient;
|
||||
import com.java2nb.novel.vo.CrawlSingleTaskVO;
|
||||
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.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -38,7 +39,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.java2nb.novel.core.utils.HttpUtil.getByHttpClientWithChrome;
|
||||
import static com.java2nb.novel.mapper.CrawlSourceDynamicSqlSupport.*;
|
||||
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
|
||||
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||
@ -51,6 +51,7 @@ import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||
@Slf4j
|
||||
public class CrawlServiceImpl implements CrawlService {
|
||||
|
||||
private final CrawlParser crawlParser;
|
||||
|
||||
private final CrawlSourceMapper crawlSourceMapper;
|
||||
|
||||
@ -62,6 +63,8 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
|
||||
private final IdWorker idWorker = IdWorker.INSTANCE;
|
||||
|
||||
private final CrawlHttpClient crawlHttpClient;
|
||||
|
||||
|
||||
@Override
|
||||
public void addCrawlSource(CrawlSource source) {
|
||||
@ -71,15 +74,16 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
crawlSourceMapper.insertSelective(source);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCrawlSource(CrawlSource source) {
|
||||
if(source.getId()!=null){
|
||||
Optional<CrawlSource> opt=crawlSourceMapper.selectByPrimaryKey(source.getId());
|
||||
if(opt.isPresent()) {
|
||||
CrawlSource crawlSource =opt.get();
|
||||
if (source.getId() != null) {
|
||||
Optional<CrawlSource> opt = crawlSourceMapper.selectByPrimaryKey(source.getId());
|
||||
if (opt.isPresent()) {
|
||||
CrawlSource crawlSource = opt.get();
|
||||
if (crawlSource.getSourceStatus() == (byte) 1) {
|
||||
//关闭
|
||||
openOrCloseCrawl(crawlSource.getId(),(byte)0);
|
||||
openOrCloseCrawl(crawlSource.getId(), (byte) 0);
|
||||
}
|
||||
Date currentDate = new Date();
|
||||
crawlSource.setUpdateTime(currentDate);
|
||||
@ -89,14 +93,15 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBean<CrawlSource> listCrawlByPage(int page, int pageSize) {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
SelectStatementProvider render = select(id, sourceName, sourceStatus, createTime, updateTime)
|
||||
.from(crawlSource)
|
||||
.orderBy(updateTime)
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
.from(crawlSource)
|
||||
.orderBy(updateTime)
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
List<CrawlSource> crawlSources = crawlSourceMapper.selectMany(render);
|
||||
PageBean<CrawlSource> pageBean = PageBuilder.build(crawlSources);
|
||||
pageBean.setList(BeanUtil.copyList(crawlSources, CrawlSourceVO.class));
|
||||
@ -113,7 +118,8 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
if (sourceStatus == (byte) 0) {
|
||||
//关闭,直接修改数据库状态,并直接修改数据库状态后获取该爬虫正在运行的线程集合全部停止
|
||||
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) {
|
||||
for (Long ThreadId : runningCrawlThreadId) {
|
||||
Thread thread = ThreadUtil.findThread(ThreadId);
|
||||
@ -157,11 +163,12 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
|
||||
@Override
|
||||
public CrawlSource queryCrawlSource(Integer sourceId) {
|
||||
SelectStatementProvider render = select(CrawlSourceDynamicSqlSupport.sourceStatus, CrawlSourceDynamicSqlSupport.crawlRule)
|
||||
.from(crawlSource)
|
||||
.where(id, isEqualTo(sourceId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
SelectStatementProvider render = select(CrawlSourceDynamicSqlSupport.sourceStatus,
|
||||
CrawlSourceDynamicSqlSupport.crawlRule)
|
||||
.from(crawlSource)
|
||||
.where(id, isEqualTo(sourceId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
return crawlSourceMapper.selectMany(render).get(0);
|
||||
}
|
||||
|
||||
@ -182,10 +189,10 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
public PageBean<CrawlSingleTask> listCrawlSingleTaskByPage(int page, int pageSize) {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
SelectStatementProvider render = select(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask.allColumns())
|
||||
.from(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask)
|
||||
.orderBy(CrawlSingleTaskDynamicSqlSupport.createTime.descending())
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
.from(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask)
|
||||
.orderBy(CrawlSingleTaskDynamicSqlSupport.createTime.descending())
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
List<CrawlSingleTask> crawlSingleTasks = crawlSingleTaskMapper.selectMany(render);
|
||||
PageBean<CrawlSingleTask> pageBean = PageBuilder.build(crawlSingleTasks);
|
||||
pageBean.setList(BeanUtil.copyList(crawlSingleTasks, CrawlSingleTaskVO.class));
|
||||
@ -200,7 +207,8 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
@Override
|
||||
public CrawlSingleTask getCrawlSingleTask() {
|
||||
|
||||
List<CrawlSingleTask> list = crawlSingleTaskMapper.selectMany(select(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask.allColumns())
|
||||
List<CrawlSingleTask> list = crawlSingleTaskMapper.selectMany(
|
||||
select(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask.allColumns())
|
||||
.from(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask)
|
||||
.where(CrawlSingleTaskDynamicSqlSupport.taskStatus, isEqualTo((byte) 2))
|
||||
.orderBy(CrawlSingleTaskDynamicSqlSupport.createTime)
|
||||
@ -226,12 +234,12 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
|
||||
@Override
|
||||
public CrawlSource getCrawlSource(Integer id) {
|
||||
Optional<CrawlSource> opt=crawlSourceMapper.selectByPrimaryKey(id);
|
||||
if(opt.isPresent()) {
|
||||
CrawlSource crawlSource =opt.get();
|
||||
return crawlSource;
|
||||
}
|
||||
return null;
|
||||
Optional<CrawlSource> opt = crawlSourceMapper.selectByPrimaryKey(id);
|
||||
if (opt.isPresent()) {
|
||||
CrawlSource crawlSource = opt.get();
|
||||
return crawlSource;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -247,14 +255,23 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
while (page <= totalPage) {
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNotBlank(ruleBean.getCatIdRule().get("catId" + catId))) {
|
||||
//拼接分类URL
|
||||
String catBookListUrl = ruleBean.getBookListUrl()
|
||||
.replace("{catId}", ruleBean.getCatIdRule().get("catId" + catId))
|
||||
String catIdRule = ruleBean.getCatIdRule().get("catId" + catId);
|
||||
if (StringUtils.isNotBlank(catIdRule)) {
|
||||
String catBookListUrl = "";
|
||||
if (StringUtils.isNotBlank(ruleBean.getBookListUrl())) {
|
||||
// 兼容老规则
|
||||
// 拼接分类URL
|
||||
catBookListUrl = ruleBean.getBookListUrl()
|
||||
.replace("{catId}", catIdRule)
|
||||
.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) {
|
||||
Pattern bookIdPatten = Pattern.compile(ruleBean.getBookIdPatten());
|
||||
Matcher bookIdMatcher = bookIdPatten.matcher(bookListHtml);
|
||||
@ -268,14 +285,12 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String bookId = bookIdMatcher.group(1);
|
||||
parseBookAndSave(catId, ruleBean, sourceId, bookId);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
|
||||
isFindBookId = bookIdMatcher.find();
|
||||
}
|
||||
|
||||
@ -294,6 +309,10 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
if (page == totalPage) {
|
||||
// 第一遍采集完成,翻到第一页,继续第二次采集,适用于分页数比较少的最近更新列表
|
||||
page = 0;
|
||||
}
|
||||
|
||||
page += 1;
|
||||
}
|
||||
@ -306,7 +325,7 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
|
||||
final AtomicBoolean parseResult = new AtomicBoolean(false);
|
||||
|
||||
CrawlParser.parseBook(ruleBean, bookId, book -> {
|
||||
crawlParser.parseBook(ruleBean, bookId, book -> {
|
||||
if (book.getBookName() == null || book.getAuthorName() == null) {
|
||||
return;
|
||||
}
|
||||
@ -330,9 +349,11 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
book.setCrawlLastTime(new Date());
|
||||
book.setId(idWorker.nextId());
|
||||
//解析章节目录
|
||||
boolean parseIndexContentResult = CrawlParser.parseBookIndexAndContent(bookId, book, ruleBean, new HashMap<>(0), chapter -> {
|
||||
bookService.saveBookAndIndexAndContent(book, chapter.getBookIndexList(), chapter.getBookContentList());
|
||||
});
|
||||
boolean parseIndexContentResult = crawlParser.parseBookIndexAndContent(bookId, book, ruleBean,
|
||||
new HashMap<>(0), chapter -> {
|
||||
bookService.saveBookAndIndexAndContent(book, chapter.getBookIndexList(),
|
||||
chapter.getBookContentList());
|
||||
});
|
||||
parseResult.set(parseIndexContentResult);
|
||||
|
||||
} else {
|
||||
@ -356,11 +377,12 @@ public class CrawlServiceImpl implements CrawlService {
|
||||
|
||||
@Override
|
||||
public List<CrawlSource> queryCrawlSourceByStatus(Byte sourceStatus) {
|
||||
SelectStatementProvider render = select(CrawlSourceDynamicSqlSupport.id, CrawlSourceDynamicSqlSupport.sourceStatus, CrawlSourceDynamicSqlSupport.crawlRule)
|
||||
.from(crawlSource)
|
||||
.where(CrawlSourceDynamicSqlSupport.sourceStatus, isEqualTo(sourceStatus))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
SelectStatementProvider render = select(CrawlSourceDynamicSqlSupport.id,
|
||||
CrawlSourceDynamicSqlSupport.sourceStatus, CrawlSourceDynamicSqlSupport.crawlRule)
|
||||
.from(crawlSource)
|
||||
.where(CrawlSourceDynamicSqlSupport.sourceStatus, isEqualTo(sourceStatus))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
return crawlSourceMapper.selectMany(render);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ public class Constants {
|
||||
|
||||
/**
|
||||
* 本地图片保存前缀
|
||||
* */
|
||||
*/
|
||||
public static final String LOCAL_PIC_PREFIX = "/localPic/";
|
||||
|
||||
/**
|
||||
@ -23,5 +23,10 @@ public class Constants {
|
||||
/**
|
||||
* 爬取小说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:
|
||||
profiles:
|
||||
include: [common-dev]
|
||||
config:
|
||||
import: classpath:application-common-dev.yml
|
@ -1,3 +1,3 @@
|
||||
spring:
|
||||
profiles:
|
||||
include: [common-prod]
|
||||
config:
|
||||
import: classpath:application-common-prod.yml
|
@ -14,12 +14,18 @@ admin:
|
||||
username: admin
|
||||
password: admin
|
||||
|
||||
#爬虫自动更新的线程数
|
||||
#建议小说数量不多或者正在运行新书入库爬虫的情况下设置为1即可
|
||||
#随着小说数量的增多可以逐渐增加,但建议不要超出CPU的线程数
|
||||
|
||||
|
||||
crawl:
|
||||
update:
|
||||
#爬虫自动更新的线程数
|
||||
#建议小说数量不多或者正在运行新书入库爬虫的情况下设置为1即可
|
||||
#随着小说数量的增多可以逐渐增加,但建议不要超出CPU的线程数
|
||||
thread: 1
|
||||
# 采集间隔时间,单位:毫秒
|
||||
interval:
|
||||
min: 300
|
||||
max: 500
|
||||
|
||||
|
||||
|
||||
|
@ -12,9 +12,6 @@
|
||||
<!-- ConsoleAppender:把日志输出到控制台 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<!--
|
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
||||
-->
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
<!-- 控制台也要使用UTF-8,不要使用GBK,否则会中文乱码 -->
|
||||
<charset>UTF-8</charset>
|
||||
@ -22,43 +19,43 @@
|
||||
</appender>
|
||||
|
||||
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是demo.log -->
|
||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过1KB时,对当前日志进行分割 重命名 -->
|
||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是novel-crawl.log -->
|
||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过10MB时,对当前日志进行分割 重命名 -->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
|
||||
<File>logs/novel-crawl.log</File>
|
||||
<!-- 设置日志文件路径 -->
|
||||
<file>logs/novel-crawl.log</file>
|
||||
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
|
||||
<!-- TimeBasedRollingPolicy: 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- SizeAndTimeBasedRollingPolicy:基于时间和文件大小的滚动策略 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
||||
<!-- 文件名:logs/demo.2017-12-05.0.log -->
|
||||
<fileNamePattern>logs/debug.%d.%i.log</fileNamePattern>
|
||||
<!-- 文件名:logs/debug.2023-10-01.0.log -->
|
||||
<fileNamePattern>logs/debug.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
|
||||
<maxHistory>30</maxHistory>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,测试时可改成1KB看效果 -->
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<!-- 单个日志文件的最大大小 -->
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<!-- 所有日志文件的总大小限制 -->
|
||||
<totalSizeCap>1GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<!-- pattern节点,用来设置日志的输入格式 -->
|
||||
<pattern>
|
||||
%d %p (%file:%line\)- %m%n
|
||||
</pattern>
|
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
||||
<!-- 记录日志的编码:此处设置字符集 - -->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 控制台输出日志级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
|
||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||
<!-- com.java2nb 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
||||
<logger name="com.java2nb" level="DEBUG" additivity="false">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
</logger>
|
||||
</configuration>
|
||||
</configuration>
|
@ -54,6 +54,8 @@
|
||||
<!--示例:<b>https://m.xdingdiann.com/sort/0/1.html</b>
|
||||
<li><input type="text" id="updateBookListUrl" class="s_input icon_key"
|
||||
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}代表分页页码)
|
||||
<li><input type="text" id="bookListUrl" class="s_input icon_key"
|
||||
placeholder="分类列表页URL规则"></li>
|
||||
@ -144,6 +146,9 @@
|
||||
示例:<b><script></b>
|
||||
<li><input type="text" id="contentEnd" class="s_input icon_key"
|
||||
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="提交"
|
||||
id="btnRegister" class="btn_red"></li>
|
||||
@ -405,6 +410,14 @@
|
||||
|
||||
crawlRule.contentEnd = contentEnd;
|
||||
|
||||
var filterContent = $("#filterContent").val();
|
||||
crawlRule.filterContent = filterContent;
|
||||
|
||||
var charset = $('#charset').val();
|
||||
if (charset) {
|
||||
crawlRule.charset = charset;
|
||||
}
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
|
@ -55,6 +55,8 @@
|
||||
<!--示例:<b>https://m.xdingdiann.com/sort/0/1.html</b>
|
||||
<li><input type="text" id="updateBookListUrl" class="s_input icon_key"
|
||||
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}代表分页页码)
|
||||
<li><input type="text" id="bookListUrl" class="s_input icon_key"
|
||||
placeholder="分类列表页URL规则"></li>
|
||||
@ -145,6 +147,10 @@
|
||||
示例:<b><script></b>
|
||||
<li><input type="text" id="contentEnd" class="s_input icon_key"
|
||||
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="提交"
|
||||
id="btnRegister" class="btn_red"></li>
|
||||
@ -269,6 +275,8 @@
|
||||
$("#bookContentUrl").val(crawlRule.bookContentUrl);
|
||||
$("#contentStart").val(crawlRule.contentStart);
|
||||
$("#contentEnd").val(crawlRule.contentEnd);
|
||||
$("#filterContent").val(crawlRule.filterContent);
|
||||
$("#charset").val(crawlRule.charset);
|
||||
|
||||
}
|
||||
}
|
||||
@ -488,6 +496,14 @@
|
||||
|
||||
crawlRule.contentEnd = contentEnd;
|
||||
|
||||
var filterContent = $("#filterContent").val();
|
||||
crawlRule.filterContent = filterContent;
|
||||
|
||||
var charset = $('#charset').val();
|
||||
if (charset) {
|
||||
crawlRule.charset = charset;
|
||||
}
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
|
@ -6,9 +6,8 @@
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<title>爬虫管理系统登录</title>
|
||||
<link href="/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
|
||||
<link href="/css/signin.css" rel="stylesheet" crossorigin="anonymous"/>
|
||||
<link href="/css/bootstrap.min.css" rel="stylesheet"/>
|
||||
<link href="/css/signin.css" rel="stylesheet"/>
|
||||
<style>
|
||||
.btn-primary {
|
||||
color: #fff;
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>novel</artifactId>
|
||||
<groupId>com.java2nb</groupId>
|
||||
<version>4.3.0-RC1</version>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -20,6 +20,12 @@
|
||||
<artifactId>novel-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<!--JWT(Json Web Token)登录支持-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
@ -48,7 +54,12 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<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>
|
||||
</dependencies>
|
||||
|
||||
@ -79,6 +90,11 @@
|
||||
<include name="application-website.yml"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${project.build.directory}/build/config" overwrite="true">
|
||||
<fileset dir="${basedir}/../config">
|
||||
<include name="*.*"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${project.build.directory}/build/templates" overwrite="true">
|
||||
<fileset dir="${basedir}/../templates">
|
||||
<include name="**/*.*"/>
|
||||
|
@ -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: orange
|
||||
|
||||
#小说内容保存配置
|
||||
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
|
||||
|
51
novel-front/src/main/build/config/application.yml
Normal file
51
novel-front/src/main/build/config/application.yml
Normal file
@ -0,0 +1,51 @@
|
||||
#端口号
|
||||
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
|
||||
|
@ -12,11 +12,13 @@ import com.java2nb.novel.entity.AuthorIncomeDetail;
|
||||
import com.java2nb.novel.entity.Book;
|
||||
import com.java2nb.novel.service.AuthorService;
|
||||
import com.java2nb.novel.service.BookService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -32,6 +34,8 @@ public class AuthorController extends BaseController{
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
private final ChatClient chatClient;
|
||||
|
||||
/**
|
||||
* 校验笔名是否存在
|
||||
* */
|
||||
@ -54,7 +58,7 @@ public class AuthorController extends BaseController{
|
||||
* 发布小说
|
||||
* */
|
||||
@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);
|
||||
|
||||
@ -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.utils.CookieUtil;
|
||||
import com.java2nb.novel.core.utils.JwtTokenUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @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.builder.pagehelper.PageBuilder;
|
||||
import io.github.xxyopen.model.resp.RestResult;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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.util.UUIDUtil;
|
||||
import io.github.xxyopen.web.exception.BusinessException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -19,8 +21,6 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
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.utils.ThreadLocalUtil;
|
||||
import com.java2nb.novel.service.OrderService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
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.RequestMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
@ -51,7 +51,7 @@ public class PayController extends BaseController {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
//未登录,跳转到登陆页面
|
||||
httpResponse.sendRedirect("/user/login.html?originUrl=/pay/aliPay?payAmount=" + payAmount);
|
||||
httpResponse.sendRedirect("/user/login.html?originUrl=/pay/index.html");
|
||||
} else {
|
||||
//创建充值订单
|
||||
Long outTradeNo = orderService.createPayOrder((byte) 1, payAmount, userDetails.getId());
|
||||
@ -121,7 +121,7 @@ public class PayController extends BaseController {
|
||||
|
||||
PrintWriter out = httpResponse.getWriter();
|
||||
|
||||
//获取支付宝POST过来反馈信息
|
||||
//获取支付宝POST过来的信息
|
||||
Map<String, String> params = new HashMap<>();
|
||||
Map<String, String[]> requestParams = request.getParameterMap();
|
||||
for (String name : requestParams.keySet()) {
|
||||
@ -134,18 +134,10 @@ public class PayController extends BaseController {
|
||||
params.put(name, valueStr);
|
||||
}
|
||||
|
||||
//调用SDK验证签名
|
||||
//验证签名
|
||||
boolean signVerified = AlipaySignature.rsaCheckV1(params, alipayConfig.getPublicKey(),
|
||||
alipayConfig.getCharset(), alipayConfig.getSignType());
|
||||
|
||||
//——请在这里编写您的程序(以下代码仅作参考)——
|
||||
|
||||
/* 实际验证过程建议商户务必添加以下校验:
|
||||
1、需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号,
|
||||
2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
|
||||
3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email)
|
||||
4、验证app_id是否为该商户本身。
|
||||
*/
|
||||
if (signVerified) {
|
||||
//验证成功
|
||||
//商户订单号
|
||||
@ -160,21 +152,18 @@ public class PayController extends BaseController {
|
||||
String tradeStatus = new String(request.getParameter("trade_status").getBytes(StandardCharsets.ISO_8859_1),
|
||||
StandardCharsets.UTF_8);
|
||||
|
||||
//更新订单状态
|
||||
orderService.updatePayOrder(Long.parseLong(outTradeNo), tradeNo, tradeStatus);
|
||||
if ("TRADE_SUCCESS".equals(tradeStatus)) {
|
||||
//支付成功
|
||||
orderService.updatePayOrder(Long.parseLong(outTradeNo), tradeNo, 1);
|
||||
}
|
||||
|
||||
out.println("success");
|
||||
|
||||
} else {//验证失败
|
||||
out.println("fail");
|
||||
|
||||
//调试用,写文本函数记录程序运行情况是否正常
|
||||
//String sWord = AlipaySignature.getSignCheckContentV1(params);
|
||||
//AlipayConfig.logResult(sWord);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -13,13 +13,13 @@ import com.java2nb.novel.service.UserService;
|
||||
import io.github.xxyopen.model.resp.RestResult;
|
||||
import io.github.xxyopen.web.valid.AddGroup;
|
||||
import io.github.xxyopen.web.valid.UpdateGroup;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.java2nb.novel.service.*;
|
||||
import com.java2nb.novel.vo.BookCommentVO;
|
||||
import com.java2nb.novel.vo.BookSettingVO;
|
||||
import io.github.xxyopen.model.page.PageBean;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
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.RequestMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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.XssFilter;
|
||||
import jakarta.servlet.DispatcherType;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -3,13 +3,13 @@ package com.java2nb.novel.core.config;
|
||||
import com.java2nb.novel.core.converter.DateConverter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author xiongxiaoyang
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig extends WebMvcConfigurerAdapter {
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
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.utils.*;
|
||||
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 javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 项目核心过滤器
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.java2nb.novel.core.filter;
|
||||
|
||||
import com.java2nb.novel.core.wrapper.XssHttpServletRequestWrapper;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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.entity.WebsiteInfo;
|
||||
import com.java2nb.novel.mapper.WebsiteInfoMapper;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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
|
||||
*/
|
||||
@WebListener
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class StarterListener implements ServletContextListener {
|
||||
public class StarterListener implements ServletContextInitializer {
|
||||
|
||||
private final WebsiteProperties websiteProperties;
|
||||
|
||||
private final WebsiteInfoMapper websiteInfoMapper;
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
sce.getServletContext()
|
||||
.setAttribute("website", websiteInfoMapper.selectByPrimaryKey(1L).orElse(new WebsiteInfo() {{
|
||||
setName(websiteProperties.getName());
|
||||
setDomain(websiteProperties.getDomain());
|
||||
setKeyword(websiteProperties.getKeyword());
|
||||
setDescription(websiteProperties.getDescription());
|
||||
setQq(websiteProperties.getQq());
|
||||
setLogo("/images/logo.png");
|
||||
setLogoDark("/images/logo_white.png");
|
||||
}}));
|
||||
public void onStartup(ServletContext servletContext) {
|
||||
servletContext.setAttribute("website", websiteInfoMapper.selectByPrimaryKey(1L).orElse(new WebsiteInfo() {{
|
||||
setName(websiteProperties.getName());
|
||||
setDomain(websiteProperties.getDomain());
|
||||
setKeyword(websiteProperties.getKeyword());
|
||||
setDescription(websiteProperties.getDescription());
|
||||
setQq(websiteProperties.getQq());
|
||||
setLogo("/images/logo.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.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.BookService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -64,24 +66,23 @@ public class MonthIncomeStaSchedule {
|
||||
|
||||
Long bookId = book.getId();
|
||||
|
||||
|
||||
//3.月收入数据未统计入库,分作品统计数据入库
|
||||
Long monthIncome = authorService.queryTotalAccount(userId, bookId, startTime, endTime);
|
||||
|
||||
BigDecimal monthIncomeShare = new BigDecimal(monthIncome)
|
||||
.multiply(authorIncomeConfig.getShareProportion());
|
||||
.multiply(authorIncomeConfig.getShareProportion());
|
||||
long preTaxIncome = monthIncomeShare
|
||||
.multiply(authorIncomeConfig.getExchangeProportion())
|
||||
.multiply(new BigDecimal(100))
|
||||
.longValue();
|
||||
.multiply(authorIncomeConfig.getExchangeProportion())
|
||||
.multiply(new BigDecimal(100))
|
||||
.longValue();
|
||||
|
||||
totalPreTaxIncome += preTaxIncome;
|
||||
|
||||
long afterTaxIncome = monthIncomeShare
|
||||
.multiply(authorIncomeConfig.getTaxRate())
|
||||
.multiply(authorIncomeConfig.getExchangeProportion())
|
||||
.multiply(new BigDecimal(100))
|
||||
.longValue();
|
||||
.multiply(authorIncomeConfig.getTaxRate())
|
||||
.multiply(authorIncomeConfig.getExchangeProportion())
|
||||
.multiply(new BigDecimal(100))
|
||||
.longValue();
|
||||
|
||||
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.setAuthorId(authorId);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.java2nb.novel.core.utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class BrowserUtil {
|
||||
|
@ -1,15 +1,15 @@
|
||||
package com.java2nb.novel.core.utils;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
public class CookieUtil {
|
||||
|
||||
public static String getCookie(HttpServletRequest request,String key){
|
||||
public static String getCookie(HttpServletRequest request, String key){
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if(cookies != null) {
|
||||
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.CacheService;
|
||||
import io.github.xxyopen.web.util.SpringUtil;
|
||||
|
||||
/**
|
||||
* 模板操作工具类
|
||||
|
@ -1,11 +1,7 @@
|
||||
package com.java2nb.novel.core.wrapper;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
/**
|
||||
* XSS过滤处理
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.java2nb.novel.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
public interface FrontUserMapper extends UserMapper {
|
||||
|
||||
|
||||
|
||||
void addUserBalance(@Param("userId") Long userId, @Param("amount") Integer amount);
|
||||
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.java2nb.novel.service;
|
||||
|
||||
|
||||
import io.github.xxyopen.model.page.PageBean;
|
||||
import com.java2nb.novel.entity.Author;
|
||||
import com.java2nb.novel.entity.AuthorIncome;
|
||||
import com.java2nb.novel.entity.AuthorIncomeDetail;
|
||||
import io.github.xxyopen.model.page.PageBean;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -16,45 +16,51 @@ public interface AuthorService {
|
||||
|
||||
/**
|
||||
* 校验笔名是否存在
|
||||
*
|
||||
* @param penName 校验的笔名
|
||||
* @return true:存在该笔名,false: 不存在该笔名
|
||||
* */
|
||||
*/
|
||||
Boolean checkPenName(String penName);
|
||||
|
||||
/**
|
||||
* 作家注册
|
||||
*
|
||||
* @param userId 注册用户ID
|
||||
*@param author 注册信息
|
||||
* @param author 注册信息
|
||||
* @return 返回错误信息
|
||||
* */
|
||||
*/
|
||||
String register(Long userId, Author author);
|
||||
|
||||
/**
|
||||
* 判断是否是作家
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return true:是作家,false: 不是作家
|
||||
* */
|
||||
*/
|
||||
Boolean isAuthor(Long userId);
|
||||
|
||||
/**
|
||||
* 查询作家信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 作家对象
|
||||
* */
|
||||
*/
|
||||
Author queryAuthor(Long userId);
|
||||
|
||||
/**
|
||||
* 查询作家列表
|
||||
* @return 作家列表
|
||||
* @param limit 查询条数
|
||||
*
|
||||
* @param limit 查询条数
|
||||
* @param maxAuthorCreateTime 最大申请时间
|
||||
* @return 作家列表
|
||||
*/
|
||||
List<Author> queryAuthorList(int limit, Date maxAuthorCreateTime);
|
||||
|
||||
/**
|
||||
* 查询收入日统计是否入库
|
||||
*
|
||||
* @param bookId 作品ID
|
||||
* @param date 收入时间
|
||||
* @param date 收入时间
|
||||
* @return true:已入库,false:未入库
|
||||
*/
|
||||
boolean queryIsStatisticsDaily(Long bookId, Date date);
|
||||
@ -62,67 +68,75 @@ public interface AuthorService {
|
||||
|
||||
/**
|
||||
* 保存日收入统计(按作品)
|
||||
*
|
||||
* @param authorIncomeDetail 收入详情
|
||||
* */
|
||||
*/
|
||||
void saveDailyIncomeSta(AuthorIncomeDetail authorIncomeDetail);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询月收入统计是否入库
|
||||
* @param bookId 作品ID
|
||||
*
|
||||
* @param bookId 作品ID
|
||||
* @param incomeDate 收入时间
|
||||
* @return true:已入库,false:未入库
|
||||
* */
|
||||
*/
|
||||
boolean queryIsStatisticsMonth(Long bookId, Date incomeDate);
|
||||
|
||||
boolean queryIsStatisticsMonth(Long authorId, Long bookId, Date incomeDate);
|
||||
|
||||
/**
|
||||
* 查询时间段内总订阅额
|
||||
*
|
||||
* @param userId
|
||||
* @param bookId 作品ID
|
||||
* @param bookId 作品ID
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param endTime 结束时间
|
||||
* @return 订阅额(屋币)
|
||||
* */
|
||||
*/
|
||||
Long queryTotalAccount(Long userId, Long bookId, Date startTime, Date endTime);
|
||||
|
||||
|
||||
/**
|
||||
* 保存月收入统计
|
||||
*
|
||||
* @param authorIncome 收入详情
|
||||
* */
|
||||
*/
|
||||
void saveAuthorIncomeSta(AuthorIncome authorIncome);
|
||||
|
||||
/**
|
||||
* 查询收入日统计是否入库
|
||||
*
|
||||
* @param authorId 作家ID
|
||||
* @param bookId 作品ID
|
||||
* @param date 收入时间
|
||||
* @param bookId 作品ID
|
||||
* @param date 收入时间
|
||||
* @return true:已入库,false:未入库
|
||||
*/
|
||||
boolean queryIsStatisticsDaily(Long authorId, Long bookId, Date date);
|
||||
|
||||
/**
|
||||
*作家日收入统计数据分页列表查询
|
||||
* 作家日收入统计数据分页列表查询
|
||||
*
|
||||
* @param userId
|
||||
* @param page 页码
|
||||
* @param pageSize 分页大小
|
||||
* @param bookId 小说ID
|
||||
* @param page 页码
|
||||
* @param pageSize 分页大小
|
||||
* @param bookId 小说ID
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param endTime 结束时间
|
||||
* @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 userId 用户ID
|
||||
* @param bookId 小说ID
|
||||
* @param userId 用户ID
|
||||
* @param bookId 小说ID
|
||||
* @return 分页数据
|
||||
* */
|
||||
*/
|
||||
PageBean<AuthorIncome> listIncomeMonthByPage(int page, int pageSize, Long userId, Long bookId);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.java2nb.novel.service;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
@ -12,18 +11,19 @@ public interface OrderService {
|
||||
* 创建充值订单
|
||||
*
|
||||
* @param payChannel 支付渠道
|
||||
* @param payAmount 支付金额
|
||||
* @param userId 用户ID
|
||||
* @param payAmount 支付金额
|
||||
* @param userId 用户ID
|
||||
* @return 商户订单号
|
||||
* */
|
||||
*/
|
||||
Long createPayOrder(Byte payChannel, Integer payAmount, Long userId);
|
||||
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
*
|
||||
* @param outTradeNo 商户订单号
|
||||
* @param tradeNo 支付宝/微信 订单号
|
||||
* @param tradeStatus 支付状态
|
||||
* */
|
||||
void updatePayOrder(Long outTradeNo, String tradeNo, String tradeStatus);
|
||||
* @param tradeNo 支付宝/微信 订单号
|
||||
* @param payStatus 支付状态
|
||||
*/
|
||||
void updatePayOrder(Long outTradeNo, String tradeNo, int payStatus);
|
||||
}
|
||||
|
@ -1,23 +1,15 @@
|
||||
package com.java2nb.novel.service.impl;
|
||||
|
||||
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.AuthorIncome;
|
||||
import com.java2nb.novel.entity.AuthorIncomeDetail;
|
||||
import com.java2nb.novel.entity.FriendLink;
|
||||
import com.java2nb.novel.mapper.*;
|
||||
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 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.transaction.annotation.Transactional;
|
||||
|
||||
@ -25,10 +17,6 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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.select.SelectDSL.select;
|
||||
|
||||
@ -52,7 +40,7 @@ public class AuthorServiceImpl implements AuthorService {
|
||||
@Override
|
||||
public Boolean checkPenName(String penName) {
|
||||
return authorMapper.count(c ->
|
||||
c.where(AuthorDynamicSqlSupport.penName, isEqualTo(penName))) > 0;
|
||||
c.where(AuthorDynamicSqlSupport.penName, isEqualTo(penName))) > 0;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@ -61,21 +49,21 @@ public class AuthorServiceImpl implements AuthorService {
|
||||
Date currentDate = new Date();
|
||||
//判断邀请码是否有效
|
||||
if (authorCodeMapper.count(c ->
|
||||
c.where(AuthorCodeDynamicSqlSupport.inviteCode, isEqualTo(author.getInviteCode()))
|
||||
.and(AuthorCodeDynamicSqlSupport.isUse, isEqualTo((byte) 0))
|
||||
.and(AuthorCodeDynamicSqlSupport.validityTime, isGreaterThan(currentDate))) > 0) {
|
||||
//邀请码有效
|
||||
c.where(AuthorCodeDynamicSqlSupport.inviteCode, isEqualTo(author.getInviteCode()))
|
||||
.and(AuthorCodeDynamicSqlSupport.isUse, isEqualTo((byte) 0))
|
||||
.and(AuthorCodeDynamicSqlSupport.validityTime, isGreaterThan(currentDate))) > 0) {
|
||||
//邀请码有效
|
||||
//保存作家信息
|
||||
author.setUserId(userId);
|
||||
author.setCreateTime(currentDate);
|
||||
authorMapper.insertSelective(author);
|
||||
//设置邀请码状态为已使用
|
||||
authorCodeMapper.update(update(authorCode)
|
||||
.set(AuthorCodeDynamicSqlSupport.isUse)
|
||||
.equalTo((byte) 1)
|
||||
.where(AuthorCodeDynamicSqlSupport.inviteCode,isEqualTo(author.getInviteCode()))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
.set(AuthorCodeDynamicSqlSupport.isUse)
|
||||
.equalTo((byte) 1)
|
||||
.where(AuthorCodeDynamicSqlSupport.inviteCode, isEqualTo(author.getInviteCode()))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
return "";
|
||||
} else {
|
||||
//邀请码无效
|
||||
@ -87,15 +75,15 @@ public class AuthorServiceImpl implements AuthorService {
|
||||
@Override
|
||||
public Boolean isAuthor(Long userId) {
|
||||
return authorMapper.count(c ->
|
||||
c.where(AuthorDynamicSqlSupport.userId, isEqualTo(userId))) > 0;
|
||||
c.where(AuthorDynamicSqlSupport.userId, isEqualTo(userId))) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Author queryAuthor(Long userId) {
|
||||
return authorMapper.selectMany(
|
||||
select(AuthorDynamicSqlSupport.id,AuthorDynamicSqlSupport.penName,AuthorDynamicSqlSupport.status)
|
||||
.from(AuthorDynamicSqlSupport.author)
|
||||
.where(AuthorDynamicSqlSupport.userId,isEqualTo(userId))
|
||||
select(AuthorDynamicSqlSupport.id, AuthorDynamicSqlSupport.penName, AuthorDynamicSqlSupport.status)
|
||||
.from(AuthorDynamicSqlSupport.author)
|
||||
.where(AuthorDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)).get(0);
|
||||
}
|
||||
@ -103,12 +91,12 @@ public class AuthorServiceImpl implements AuthorService {
|
||||
@Override
|
||||
public List<Author> queryAuthorList(int needAuthorNumber, Date maxAuthorCreateTime) {
|
||||
return authorMapper.selectMany(select(AuthorDynamicSqlSupport.id, AuthorDynamicSqlSupport.userId)
|
||||
.from(AuthorDynamicSqlSupport.author)
|
||||
.where(AuthorDynamicSqlSupport.createTime, isLessThan(maxAuthorCreateTime))
|
||||
.orderBy(AuthorDynamicSqlSupport.createTime.descending())
|
||||
.limit(needAuthorNumber)
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
.from(AuthorDynamicSqlSupport.author)
|
||||
.where(AuthorDynamicSqlSupport.createTime, isLessThan(maxAuthorCreateTime))
|
||||
.orderBy(AuthorDynamicSqlSupport.createTime.descending())
|
||||
.limit(needAuthorNumber)
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
|
||||
@ -116,11 +104,11 @@ public class AuthorServiceImpl implements AuthorService {
|
||||
public boolean queryIsStatisticsDaily(Long bookId, Date date) {
|
||||
|
||||
return authorIncomeDetailMapper.selectMany(select(AuthorIncomeDetailDynamicSqlSupport.id)
|
||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||
.where(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isEqualTo(date))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||
.where(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isEqualTo(date))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||
|
||||
}
|
||||
|
||||
@ -133,24 +121,35 @@ public class AuthorServiceImpl implements AuthorService {
|
||||
@Override
|
||||
public boolean queryIsStatisticsMonth(Long bookId, Date incomeDate) {
|
||||
return authorIncomeMapper.selectMany(select(AuthorIncomeDynamicSqlSupport.id)
|
||||
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
||||
.where(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDynamicSqlSupport.incomeMonth, isEqualTo(incomeDate))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
||||
.where(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDynamicSqlSupport.incomeMonth, isEqualTo(incomeDate))
|
||||
.build()
|
||||
.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
|
||||
public Long queryTotalAccount(Long userId, Long bookId, Date startTime, Date endTime) {
|
||||
|
||||
return authorIncomeDetailMapper.selectStatistic(select(sum(AuthorIncomeDetailDynamicSqlSupport.incomeAccount))
|
||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||
.where(AuthorIncomeDetailDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isGreaterThanOrEqualTo(startTime))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||
.where(AuthorIncomeDetailDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isGreaterThanOrEqualTo(startTime))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
|
||||
@ -162,29 +161,30 @@ public class AuthorServiceImpl implements AuthorService {
|
||||
@Override
|
||||
public boolean queryIsStatisticsDaily(Long authorId, Long bookId, Date date) {
|
||||
return authorIncomeDetailMapper.selectMany(select(AuthorIncomeDetailDynamicSqlSupport.id)
|
||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||
.where(AuthorIncomeDetailDynamicSqlSupport.authorId, isEqualTo(authorId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isEqualTo(date))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||
.where(AuthorIncomeDetailDynamicSqlSupport.authorId, isEqualTo(authorId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isEqualTo(date))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)).size() > 0;
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
return PageBuilder.build(authorIncomeDetailMapper.selectMany(
|
||||
select(AuthorIncomeDetailDynamicSqlSupport.incomeDate, AuthorIncomeDetailDynamicSqlSupport.incomeAccount
|
||||
, AuthorIncomeDetailDynamicSqlSupport.incomeCount, AuthorIncomeDetailDynamicSqlSupport.incomeNumber)
|
||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||
.where(AuthorIncomeDetailDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isGreaterThanOrEqualTo(startTime))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isLessThanOrEqualTo(endTime))
|
||||
.orderBy(AuthorIncomeDetailDynamicSqlSupport.incomeDate.descending())
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)));
|
||||
select(AuthorIncomeDetailDynamicSqlSupport.incomeDate, AuthorIncomeDetailDynamicSqlSupport.incomeAccount
|
||||
, AuthorIncomeDetailDynamicSqlSupport.incomeCount, AuthorIncomeDetailDynamicSqlSupport.incomeNumber)
|
||||
.from(AuthorIncomeDetailDynamicSqlSupport.authorIncomeDetail)
|
||||
.where(AuthorIncomeDetailDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isGreaterThanOrEqualTo(startTime))
|
||||
.and(AuthorIncomeDetailDynamicSqlSupport.incomeDate, isLessThanOrEqualTo(endTime))
|
||||
.orderBy(AuthorIncomeDetailDynamicSqlSupport.incomeDate.descending())
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)));
|
||||
}
|
||||
|
||||
|
||||
@ -192,15 +192,15 @@ public class AuthorServiceImpl implements AuthorService {
|
||||
public PageBean<AuthorIncome> listIncomeMonthByPage(int page, int pageSize, Long userId, Long bookId) {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
return PageBuilder.build(authorIncomeMapper.selectMany(select(AuthorIncomeDynamicSqlSupport.incomeMonth
|
||||
, AuthorIncomeDynamicSqlSupport.preTaxIncome
|
||||
, AuthorIncomeDynamicSqlSupport.afterTaxIncome
|
||||
, AuthorIncomeDynamicSqlSupport.payStatus
|
||||
, AuthorIncomeDynamicSqlSupport.confirmStatus)
|
||||
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
||||
.where(AuthorIncomeDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.orderBy(AuthorIncomeDynamicSqlSupport.incomeMonth.descending())
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)));
|
||||
, AuthorIncomeDynamicSqlSupport.preTaxIncome
|
||||
, AuthorIncomeDynamicSqlSupport.afterTaxIncome
|
||||
, AuthorIncomeDynamicSqlSupport.payStatus
|
||||
, AuthorIncomeDynamicSqlSupport.confirmStatus)
|
||||
.from(AuthorIncomeDynamicSqlSupport.authorIncome)
|
||||
.where(AuthorIncomeDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(AuthorIncomeDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.orderBy(AuthorIncomeDynamicSqlSupport.incomeMonth.descending())
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3)));
|
||||
}
|
||||
}
|
||||
|
@ -29,19 +29,16 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mybatis.dynamic.sql.SortSpecification;
|
||||
import org.mybatis.dynamic.sql.render.RenderingStrategies;
|
||||
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
|
||||
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import tk.mybatis.orderbyhelper.OrderByHelper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.java2nb.novel.mapper.BookCategoryDynamicSqlSupport.bookCategory;
|
||||
@ -201,9 +198,6 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
PageHelper.startPage(page, pageSize);
|
||||
|
||||
if (StringUtils.isNotBlank(params.getSort())) {
|
||||
OrderByHelper.orderBy(params.getSort() + " desc");
|
||||
}
|
||||
return PageBuilder.build(bookMapper.searchByPage(params));
|
||||
|
||||
}
|
||||
@ -231,23 +225,22 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
@Override
|
||||
public List<BookIndex> queryIndexList(Long bookId, String orderBy, Integer page, Integer pageSize) {
|
||||
if (StringUtils.isNotBlank(orderBy)) {
|
||||
OrderByHelper.orderBy(orderBy);
|
||||
}
|
||||
if (page != null && pageSize != null) {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
}
|
||||
|
||||
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id,
|
||||
QueryExpressionDSL<org.mybatis.dynamic.sql.select.SelectModel>.QueryExpressionWhereBuilder where = select(
|
||||
BookIndexDynamicSqlSupport.id,
|
||||
BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum,
|
||||
BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime,
|
||||
BookIndexDynamicSqlSupport.isVip)
|
||||
.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()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
|
||||
return bookIndexMapper.selectMany(selectStatement);
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
|
||||
@ -384,7 +377,6 @@ public class BookServiceImpl implements BookService {
|
||||
@Override
|
||||
public PageBean<BookCommentVO> listCommentByPage(Long userId, Long bookId, int page, int pageSize) {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
OrderByHelper.orderBy("t1.create_time desc");
|
||||
return PageBuilder.build(bookCommentMapper.listCommentByPage(userId, bookId));
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.mybatis.dynamic.sql.render.RenderingStrategies;
|
||||
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
||||
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -17,6 +18,7 @@ import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
|
||||
import static org.mybatis.dynamic.sql.SqlBuilder.update;
|
||||
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||
|
||||
/**
|
||||
@ -35,7 +37,8 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Override
|
||||
public Long createPayOrder(Byte payChannel, Integer payAmount, Long userId) {
|
||||
Date currentDate = new Date();
|
||||
Long outTradeNo = Long.parseLong(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(currentDate)+new Random().nextInt(10));
|
||||
Long outTradeNo = Long.parseLong(
|
||||
new SimpleDateFormat("yyyyMMddHHmmssSSS").format(currentDate) + new Random().nextInt(10));
|
||||
OrderPay orderPay = new OrderPay();
|
||||
orderPay.setOutTradeNo(outTradeNo);
|
||||
orderPay.setPayChannel(payChannel);
|
||||
@ -49,37 +52,39 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void updatePayOrder(Long outTradeNo, String tradeNo, String tradeStatus) {
|
||||
SelectStatementProvider selectStatement = select(OrderPayDynamicSqlSupport.id,OrderPayDynamicSqlSupport.payStatus,OrderPayDynamicSqlSupport.totalAmount,OrderPayDynamicSqlSupport.userId)
|
||||
.from(OrderPayDynamicSqlSupport.orderPay)
|
||||
.where(OrderPayDynamicSqlSupport.outTradeNo, isEqualTo(outTradeNo))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
public void updatePayOrder(Long outTradeNo, String tradeNo, int payStatus) {
|
||||
SelectStatementProvider selectStatement = select(OrderPayDynamicSqlSupport.id,
|
||||
OrderPayDynamicSqlSupport.payStatus, OrderPayDynamicSqlSupport.totalAmount,
|
||||
OrderPayDynamicSqlSupport.userId)
|
||||
.from(OrderPayDynamicSqlSupport.orderPay)
|
||||
.where(OrderPayDynamicSqlSupport.outTradeNo, isEqualTo(outTradeNo))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
|
||||
OrderPay orderPay = orderPayMapper.selectMany(selectStatement).get(0);
|
||||
OrderPay orderPay = orderPayMapper.selectOne(selectStatement).orElse(null);
|
||||
|
||||
if(orderPay.getPayStatus()!=1) {
|
||||
//此订单还未处理过
|
||||
|
||||
if (tradeStatus.equals("TRADE_SUCCESS") || tradeStatus.equals("TRADE_FINISHED")) {
|
||||
if (orderPay.getPayStatus().intValue() == 2) {
|
||||
//待支付订单处理
|
||||
if (payStatus == 1) {
|
||||
//支付成功
|
||||
//1.更新订单状态为成功
|
||||
orderPay.setPayStatus((byte) 1);
|
||||
orderPay.setUpdateTime(new Date());
|
||||
orderPayMapper.updateByPrimaryKeySelective(orderPay);
|
||||
|
||||
//2.增加用户余额
|
||||
userService.addAmount(orderPay.getUserId(),orderPay.getTotalAmount()*100);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
UpdateStatementProvider updateStatement = update(OrderPayDynamicSqlSupport.orderPay)
|
||||
.set(OrderPayDynamicSqlSupport.tradeNo).equalTo(tradeNo)
|
||||
.set(OrderPayDynamicSqlSupport.payStatus).equalTo((byte) 1)
|
||||
.set(OrderPayDynamicSqlSupport.updateTime).equalTo(new Date())
|
||||
.where(OrderPayDynamicSqlSupport.id, isEqualTo(orderPay.getId()))
|
||||
.and(OrderPayDynamicSqlSupport.payStatus, isEqualTo((byte) 2))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
int updateRow = orderPayMapper.update(updateStatement);
|
||||
if (updateRow > 0) {
|
||||
//更新成功
|
||||
//2.增加用户余额
|
||||
userService.addAmount(orderPay.getUserId(), orderPay.getTotalAmount() * 100);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
package com.java2nb.novel.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.github.xxyopen.model.page.PageBean;
|
||||
import com.java2nb.novel.core.bean.UserDetails;
|
||||
import com.java2nb.novel.entity.*;
|
||||
import com.java2nb.novel.entity.User;
|
||||
import com.java2nb.novel.service.UserService;
|
||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||
import com.java2nb.novel.entity.User;
|
||||
import com.java2nb.novel.entity.*;
|
||||
import com.java2nb.novel.mapper.*;
|
||||
import com.java2nb.novel.service.UserService;
|
||||
import com.java2nb.novel.vo.BookReadHistoryVO;
|
||||
import com.java2nb.novel.vo.BookShelfVO;
|
||||
import com.java2nb.novel.vo.UserFeedbackVO;
|
||||
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.MD5Util;
|
||||
import io.github.xxyopen.web.exception.BusinessException;
|
||||
import com.java2nb.novel.mapper.*;
|
||||
import com.java2nb.novel.vo.BookReadHistoryVO;
|
||||
import com.java2nb.novel.vo.BookShelfVO;
|
||||
import com.java2nb.novel.vo.UserFeedbackVO;
|
||||
import io.github.xxyopen.web.util.BeanUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -46,7 +46,7 @@ import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
private final FrontUserMapper userMapper;
|
||||
|
||||
private final FrontUserBookshelfMapper userBookshelfMapper;
|
||||
|
||||
@ -63,17 +63,17 @@ public class UserServiceImpl implements UserService {
|
||||
public UserDetails register(User user) {
|
||||
//查询用户名是否已注册
|
||||
SelectStatementProvider selectStatement = select(count(id))
|
||||
.from(UserDynamicSqlSupport.user)
|
||||
.where(username, isEqualTo(user.getUsername()))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
.from(UserDynamicSqlSupport.user)
|
||||
.where(username, isEqualTo(user.getUsername()))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
long count = userMapper.count(selectStatement);
|
||||
if (count > 0) {
|
||||
//用户名已注册
|
||||
throw new BusinessException(ResponseStatus.USERNAME_EXIST);
|
||||
}
|
||||
User entity = new User();
|
||||
BeanUtils.copyProperties(user,entity);
|
||||
BeanUtils.copyProperties(user, entity);
|
||||
//数据库生成注册记录
|
||||
Long id = idWorker.nextId();
|
||||
entity.setId(id);
|
||||
@ -94,12 +94,12 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public UserDetails login(User user) {
|
||||
//根据用户名密码查询记录
|
||||
SelectStatementProvider selectStatement = select(id, username,nickName)
|
||||
.from(UserDynamicSqlSupport.user)
|
||||
.where(username, isEqualTo(user.getUsername()))
|
||||
.and(password, isEqualTo(MD5Util.MD5Encode(user.getPassword(), Charsets.UTF_8.name())))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
SelectStatementProvider selectStatement = select(id, username, nickName)
|
||||
.from(UserDynamicSqlSupport.user)
|
||||
.where(username, isEqualTo(user.getUsername()))
|
||||
.and(password, isEqualTo(MD5Util.MD5Encode(user.getPassword(), Charsets.UTF_8.name())))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
List<User> users = userMapper.selectMany(selectStatement);
|
||||
if (users.size() == 0) {
|
||||
throw new BusinessException(ResponseStatus.USERNAME_PASS_ERROR);
|
||||
@ -116,11 +116,11 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public Boolean queryIsInShelf(Long userId, Long bookId) {
|
||||
SelectStatementProvider selectStatement = select(count(UserBookshelfDynamicSqlSupport.id))
|
||||
.from(userBookshelf)
|
||||
.where(UserBookshelfDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(UserBookshelfDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
.from(userBookshelf)
|
||||
.where(UserBookshelfDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(UserBookshelfDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
|
||||
return userBookshelfMapper.count(selectStatement) > 0;
|
||||
}
|
||||
@ -141,10 +141,10 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public void removeFromBookShelf(Long userId, Long bookId) {
|
||||
DeleteStatementProvider deleteStatement = deleteFrom(userBookshelf)
|
||||
.where(UserBookshelfDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(UserBookshelfDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
.where(UserBookshelfDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(UserBookshelfDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
userBookshelfMapper.delete(deleteStatement);
|
||||
|
||||
}
|
||||
@ -162,10 +162,10 @@ public class UserServiceImpl implements UserService {
|
||||
Date currentDate = new Date();
|
||||
//删除该书以前的历史记录
|
||||
DeleteStatementProvider deleteStatement = deleteFrom(userReadHistory)
|
||||
.where(UserReadHistoryDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(UserReadHistoryDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
.where(UserReadHistoryDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(UserReadHistoryDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
userReadHistoryMapper.delete(deleteStatement);
|
||||
|
||||
//插入该书新的历史记录
|
||||
@ -177,17 +177,16 @@ public class UserServiceImpl implements UserService {
|
||||
userReadHistory.setUpdateTime(currentDate);
|
||||
userReadHistoryMapper.insertSelective(userReadHistory);
|
||||
|
||||
|
||||
//更新书架的阅读历史
|
||||
UpdateStatementProvider updateStatement = update(userBookshelf)
|
||||
.set(UserBookshelfDynamicSqlSupport.preContentId)
|
||||
.equalTo(preContentId)
|
||||
.set(UserBookshelfDynamicSqlSupport.updateTime)
|
||||
.equalTo(currentDate)
|
||||
.where(UserBookshelfDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(UserBookshelfDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
.set(UserBookshelfDynamicSqlSupport.preContentId)
|
||||
.equalTo(preContentId)
|
||||
.set(UserBookshelfDynamicSqlSupport.updateTime)
|
||||
.equalTo(currentDate)
|
||||
.where(UserBookshelfDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(UserBookshelfDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
|
||||
userBookshelfMapper.update(updateStatement);
|
||||
|
||||
@ -206,25 +205,26 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public PageBean<UserFeedback> listUserFeedBackByPage(Long userId, int page, int pageSize) {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
SelectStatementProvider selectStatement = select(UserFeedbackDynamicSqlSupport.content, UserFeedbackDynamicSqlSupport.createTime)
|
||||
.from(userFeedback)
|
||||
.where(UserFeedbackDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.orderBy(UserFeedbackDynamicSqlSupport.id.descending())
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
SelectStatementProvider selectStatement = select(UserFeedbackDynamicSqlSupport.content,
|
||||
UserFeedbackDynamicSqlSupport.createTime)
|
||||
.from(userFeedback)
|
||||
.where(UserFeedbackDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.orderBy(UserFeedbackDynamicSqlSupport.id.descending())
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
List<UserFeedback> userFeedbacks = userFeedbackMapper.selectMany(selectStatement);
|
||||
PageBean<UserFeedback> pageBean = PageBuilder.build(userFeedbacks);
|
||||
pageBean.setList(BeanUtil.copyList(userFeedbacks,UserFeedbackVO.class));
|
||||
pageBean.setList(BeanUtil.copyList(userFeedbacks, UserFeedbackVO.class));
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User userInfo(Long userId) {
|
||||
SelectStatementProvider selectStatement = select(username, nickName, userPhoto,userSex,accountBalance)
|
||||
.from(user)
|
||||
.where(id, isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
SelectStatementProvider selectStatement = select(username, nickName, userPhoto, userSex, accountBalance)
|
||||
.from(user)
|
||||
.where(id, isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
return userMapper.selectMany(selectStatement).get(0);
|
||||
}
|
||||
|
||||
@ -245,39 +245,35 @@ public class UserServiceImpl implements UserService {
|
||||
@Override
|
||||
public void updatePassword(Long userId, String oldPassword, String newPassword) {
|
||||
SelectStatementProvider selectStatement = select(password)
|
||||
.from(user)
|
||||
.where(id,isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
if(!userMapper.selectMany(selectStatement).get(0).getPassword().equals(MD5Util.MD5Encode(oldPassword, Charsets.UTF_8.name()))){
|
||||
.from(user)
|
||||
.where(id, isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
if (!userMapper.selectMany(selectStatement).get(0).getPassword()
|
||||
.equals(MD5Util.MD5Encode(oldPassword, Charsets.UTF_8.name()))) {
|
||||
throw new BusinessException(ResponseStatus.OLD_PASSWORD_ERROR);
|
||||
}
|
||||
UpdateStatementProvider updateStatement = update(user)
|
||||
.set(password)
|
||||
.equalTo(MD5Util.MD5Encode(newPassword, Charsets.UTF_8.name()))
|
||||
.where(id,isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
.set(password)
|
||||
.equalTo(MD5Util.MD5Encode(newPassword, Charsets.UTF_8.name()))
|
||||
.where(id, isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
userMapper.update(updateStatement);
|
||||
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void addAmount(Long userId, int amount) {
|
||||
User user = this.userInfo(userId);
|
||||
user.setId(userId);
|
||||
user.setAccountBalance(user.getAccountBalance()+amount);
|
||||
userMapper.updateByPrimaryKeySelective(user);
|
||||
|
||||
userMapper.addUserBalance(userId, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean queryIsBuyBookIndex(Long userId, Long bookIndexId) {
|
||||
|
||||
return userBuyRecordMapper.count(c ->
|
||||
c.where(UserBuyRecordDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(UserBuyRecordDynamicSqlSupport.bookIndexId,isEqualTo(bookIndexId))) > 0;
|
||||
c.where(UserBuyRecordDynamicSqlSupport.userId, isEqualTo(userId))
|
||||
.and(UserBuyRecordDynamicSqlSupport.bookIndexId, isEqualTo(bookIndexId))) > 0;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@ -285,7 +281,7 @@ public class UserServiceImpl implements UserService {
|
||||
public void buyBookIndex(Long userId, UserBuyRecord buyRecord) {
|
||||
//查询用户余额
|
||||
long balance = userInfo(userId).getAccountBalance();
|
||||
if(balance<buyRecord.getBuyAmount()){
|
||||
if (balance < buyRecord.getBuyAmount()) {
|
||||
//余额不足
|
||||
throw new BusinessException(ResponseStatus.USER_NO_BALANCE);
|
||||
}
|
||||
@ -296,60 +292,56 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
//减少用户余额
|
||||
userMapper.update(update(user)
|
||||
.set(UserDynamicSqlSupport.accountBalance)
|
||||
.equalTo(balance-buyRecord.getBuyAmount())
|
||||
.where(id,isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
.set(UserDynamicSqlSupport.accountBalance)
|
||||
.equalTo(balance - buyRecord.getBuyAmount())
|
||||
.where(id, isEqualTo(userId))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBuyMember(Long bookId, Date startTime, Date endTime) {
|
||||
return userMapper.selectStatistic(select(countDistinct(UserBuyRecordDynamicSqlSupport.userId))
|
||||
.from(UserBuyRecordDynamicSqlSupport.userBuyRecord)
|
||||
.where(UserBuyRecordDynamicSqlSupport.bookId,isEqualTo(bookId))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime,isGreaterThanOrEqualTo(startTime))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime,isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
.from(UserBuyRecordDynamicSqlSupport.userBuyRecord)
|
||||
.where(UserBuyRecordDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime, isGreaterThanOrEqualTo(startTime))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime, isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBuyCount(Long bookId, Date startTime, Date endTime) {
|
||||
return userMapper.selectStatistic(select(count(UserBuyRecordDynamicSqlSupport.id))
|
||||
.from(UserBuyRecordDynamicSqlSupport.userBuyRecord)
|
||||
.where(UserBuyRecordDynamicSqlSupport.bookId,isEqualTo(bookId))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime,isGreaterThanOrEqualTo(startTime))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime,isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
.from(UserBuyRecordDynamicSqlSupport.userBuyRecord)
|
||||
.where(UserBuyRecordDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime, isGreaterThanOrEqualTo(startTime))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime, isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBuyAccount(Long bookId, Date startTime, Date endTime) {
|
||||
return userMapper.selectStatistic(select(sum(UserBuyRecordDynamicSqlSupport.buyAmount))
|
||||
.from(UserBuyRecordDynamicSqlSupport.userBuyRecord)
|
||||
.where(UserBuyRecordDynamicSqlSupport.bookId,isEqualTo(bookId))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime,isGreaterThanOrEqualTo(startTime))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime,isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
.from(UserBuyRecordDynamicSqlSupport.userBuyRecord)
|
||||
.where(UserBuyRecordDynamicSqlSupport.bookId, isEqualTo(bookId))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime, isGreaterThanOrEqualTo(startTime))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime, isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBuyTotalMember(List<Long> bookIds, Date startTime, Date endTime) {
|
||||
return userMapper.selectStatistic(select(countDistinct(UserBuyRecordDynamicSqlSupport.userId))
|
||||
.from(UserBuyRecordDynamicSqlSupport.userBuyRecord)
|
||||
.where(UserBuyRecordDynamicSqlSupport.bookId,isIn(bookIds))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime,isGreaterThanOrEqualTo(startTime))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime,isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
.from(UserBuyRecordDynamicSqlSupport.userBuyRecord)
|
||||
.where(UserBuyRecordDynamicSqlSupport.bookId, isIn(bookIds))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime, isGreaterThanOrEqualTo(startTime))
|
||||
.and(UserBuyRecordDynamicSqlSupport.createTime, isLessThanOrEqualTo(endTime))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import com.java2nb.novel.core.serialize.CommentUserNameSerialize;
|
||||
import com.java2nb.novel.entity.BookComment;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
spring:
|
||||
profiles:
|
||||
include: [ common-dev ]
|
||||
config:
|
||||
import: classpath:application-common-dev.yml
|
||||
|
||||
|
||||
pic:
|
||||
|
@ -1,6 +1,6 @@
|
||||
spring:
|
||||
profiles:
|
||||
include: [ common-prod ]
|
||||
config:
|
||||
import: classpath:application-common-prod.yml
|
||||
|
||||
#静态文件路径配置
|
||||
resources:
|
||||
|
@ -44,7 +44,15 @@ book:
|
||||
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:把日志输出到控制台 -->
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<!--
|
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
||||
-->
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
<!-- 控制台也要使用UTF-8,不要使用GBK,否则会中文乱码 -->
|
||||
<charset>UTF-8</charset>
|
||||
@ -22,43 +19,43 @@
|
||||
</appender>
|
||||
|
||||
<!-- RollingFileAppender:滚动记录文件,先将日志记录到指定文件,当符合某个条件时,将日志记录到其他文件 -->
|
||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是demo.log -->
|
||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过1KB时,对当前日志进行分割 重命名 -->
|
||||
<!-- 以下的大概意思是:1.先按日期存日志,日期变了,将前一天的日志文件名重命名为XXX%日期%索引,新的日志仍然是novel-front.log -->
|
||||
<!-- 2.如果日期没有发生变化,但是当前日志的文件大小超过10MB时,对当前日志进行分割 重命名 -->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
|
||||
<File>logs/novel-front.log</File>
|
||||
<!-- 设置日志文件路径 -->
|
||||
<file>logs/novel-front.log</file>
|
||||
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
|
||||
<!-- TimeBasedRollingPolicy: 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- SizeAndTimeBasedRollingPolicy:基于时间和文件大小的滚动策略 -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<!-- 活动文件的名字会根据fileNamePattern的值,每隔一段时间改变一次 -->
|
||||
<!-- 文件名:logs/demo.2017-12-05.0.log -->
|
||||
<fileNamePattern>logs/debug.%d.%i.log</fileNamePattern>
|
||||
<!-- 文件名:logs/debug.2023-10-01.0.log -->
|
||||
<fileNamePattern>logs/debug.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||
<!-- 每产生一个日志文件,该日志文件的保存期限为30天 -->
|
||||
<maxHistory>30</maxHistory>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<!-- maxFileSize:这是活动文件的大小,默认值是10MB,测试时可改成1KB看效果 -->
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
<!-- 单个日志文件的最大大小 -->
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
<!-- 所有日志文件的总大小限制 -->
|
||||
<totalSizeCap>1GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<!-- pattern节点,用来设置日志的输入格式 -->
|
||||
<pattern>
|
||||
%d %p (%file:%line\)- %m%n
|
||||
</pattern>
|
||||
<pattern>%d %p (%file:%line\)- %m%n</pattern>
|
||||
<!-- 记录日志的编码:此处设置字符集 - -->
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- 控制台输出日志级别 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
|
||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||
<!-- com.java2nb 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||
<!-- 级别依次为【从高到低】: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="FILE" />
|
||||
</logger>
|
||||
</configuration>
|
||||
</configuration>
|
@ -14,7 +14,7 @@
|
||||
and t1.create_user_id = #{userId}
|
||||
</if>
|
||||
</trim>
|
||||
|
||||
order by t1.create_time desc
|
||||
|
||||
</select>
|
||||
|
||||
|
@ -31,38 +31,47 @@
|
||||
<if test="updateTimeMin != null">
|
||||
and last_index_update_time >= #{updateTimeMin}
|
||||
</if>
|
||||
<if test="sort != null">
|
||||
order by ${sort} desc
|
||||
</if>
|
||||
|
||||
</select>
|
||||
|
||||
<update id="addVisitCount" >
|
||||
update book set visit_count = visit_count + ${visitCount}
|
||||
<update id="addVisitCount">
|
||||
update book
|
||||
set visit_count = visit_count + ${visitCount}
|
||||
where id = #{bookId}
|
||||
</update>
|
||||
|
||||
<select id="listRecBookByCatId" parameterType="int" resultType="com.java2nb.novel.entity.Book">
|
||||
select id,pic_url,book_name,book_desc
|
||||
select id, pic_url, book_name, book_desc
|
||||
from book
|
||||
where cat_id = #{catId}
|
||||
and word_count > 0
|
||||
order by RAND() LIMIT 4
|
||||
</select>
|
||||
|
||||
|
||||
<update id="addCommentCount" parameterType="long">
|
||||
update book set comment_count = comment_count+1
|
||||
where id = #{bookId}
|
||||
update book
|
||||
set comment_count = comment_count + 1
|
||||
where id = #{bookId}
|
||||
</update>
|
||||
|
||||
<select id="queryNetworkPicBooks" resultType="com.java2nb.novel.entity.Book">
|
||||
select
|
||||
id,pic_url from book
|
||||
select id,
|
||||
pic_url
|
||||
from book
|
||||
where pic_url like 'http%'
|
||||
and pic_url not like concat('%',#{localPicPrefix},'%')
|
||||
limit #{limit}
|
||||
and pic_url not like concat('%', #{localPicPrefix}, '%')
|
||||
limit #{limit}
|
||||
</select>
|
||||
|
||||
<select id="selectIdsByScoreAndRandom" parameterType="int" resultType="com.java2nb.novel.entity.Book">
|
||||
|
||||
select id,book_name,author_name,pic_url,book_desc,score from book ORDER BY score,RAND() LIMIT #{limit};
|
||||
</select>
|
||||
select id, book_name, author_name, pic_url, book_desc, score
|
||||
from book
|
||||
ORDER BY score, RAND() LIMIT #{limit};
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.java2nb.novel.mapper.FrontUserMapper">
|
||||
|
||||
|
||||
<update id="addUserBalance" >
|
||||
update user set account_balance = account_balance + ${amount}
|
||||
where id = #{userId}
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 12 KiB |
@ -27,15 +27,14 @@
|
||||
if (layerStatus == 1) {
|
||||
$("#cFavs").html("<a class=\"ico_shelf\" href=\"javascript:void(0);\"><b>已收藏</b></a>");
|
||||
jQuery.cookie("u-faorites", "1");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$("#cFavs").html("<a class=\"btn_ora_white btn_addsj\" href=\"javascript:void(0);\">已在书架</a>");
|
||||
}
|
||||
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
@ -91,7 +90,7 @@
|
||||
}
|
||||
},
|
||||
SaveComment: function (cmtBId, cmtCId, cmtDetail) {
|
||||
if(!isLogin){
|
||||
if (!isLogin) {
|
||||
layer.alert('请先登陆');
|
||||
return;
|
||||
}
|
||||
@ -121,7 +120,7 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
@ -187,7 +186,7 @@
|
||||
localStorage.setItem("fonts", fonts);
|
||||
$(".readBox").css("font-size", fonts + "px");
|
||||
$("#cFonts").html(fonts);
|
||||
$("#ChapterBody").attr("class","article-content font"+fonts);
|
||||
$("#ChapterBody").attr("class", "article-content font" + fonts);
|
||||
BookDetail.reShowCover();
|
||||
},
|
||||
SetBackUpColor: function (colorNum) {
|
||||
|
@ -1,10 +1,11 @@
|
||||
var needLoginPath = ['/user/favorites.html','/user/comment.html','/user/feedback.html',
|
||||
'/user/feedback_list.html','/user/read_history.html','/user/set_name.html',
|
||||
'/user/set_password.html','/user/set_sex.html','/user/setup.html','/user/userinfo.html',
|
||||
var needLoginPath = ['/user/favorites.html', '/user/comment.html', '/user/feedback.html',
|
||||
'/user/feedback_list.html', '/user/read_history.html', '/user/set_name.html',
|
||||
'/user/set_password.html', '/user/set_sex.html', '/user/setup.html', '/user/userinfo.html',
|
||||
"/pay/index.html," +
|
||||
"/author/register.html","/author/index.html"];
|
||||
"/author/register.html", "/author/index.html"];
|
||||
var isLogin = false;
|
||||
var url = window.location.search;
|
||||
|
||||
//key(需要检索的键)
|
||||
function getSearchString(key) {
|
||||
var str = url;
|
||||
@ -14,26 +15,28 @@ function getSearchString(key) {
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var tmp_arr = arr[i].split("=");
|
||||
if(tmp_arr[0] == key){
|
||||
if (tmp_arr[0] == key) {
|
||||
return decodeURIComponent(tmp_arr[1]);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var keyword = getSearchString("k");
|
||||
if(keyword != undefined) {
|
||||
if (keyword != undefined) {
|
||||
$("#searchKey").val(keyword);
|
||||
$("#workDirection").remove();
|
||||
$("#idGirl").remove();
|
||||
}
|
||||
|
||||
function searchByK(k){
|
||||
if(!k){
|
||||
window.location.href='/book/bookclass.html?k='+encodeURIComponent(document.getElementById("searchKey").value)
|
||||
}else{
|
||||
window.location.href='/book/bookclass.html?k='+encodeURIComponent(k)
|
||||
function searchByK(k) {
|
||||
if (!k) {
|
||||
window.location.href = '/book/bookclass.html?k=' + encodeURIComponent(document.getElementById("searchKey").value)
|
||||
} else {
|
||||
window.location.href = '/book/bookclass.html?k=' + encodeURIComponent(k)
|
||||
}
|
||||
}
|
||||
|
||||
$("#searchKey").keypress(function (even) {
|
||||
if (even.which == 13) {
|
||||
even.stopPropagation();
|
||||
@ -50,37 +53,37 @@ Array.prototype.indexOf = function (val) {
|
||||
|
||||
|
||||
var token = $.cookie('Authorization');
|
||||
if(!token){
|
||||
if(needLoginPath.indexOf(window.location.pathname) != -1){
|
||||
location.href = '/user/login.html?originUrl='+decodeURIComponent(location.href);
|
||||
if (!token) {
|
||||
if (needLoginPath.indexOf(window.location.pathname) != -1) {
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
}
|
||||
|
||||
$(".user_link").html("<i class=\"line mr20\">|</i><a href=\"/user/login.html\" class=\"mr15\">登录</a><a href=\"/user/register.html\" >注册</a>");
|
||||
}else{
|
||||
} else {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/user/refreshToken",
|
||||
data: {},
|
||||
dataType: "json",
|
||||
success: function(data){
|
||||
if(data.code == 200){
|
||||
success: function (data) {
|
||||
if (data.code == 200) {
|
||||
$(".user_link").html("<i class=\"line mr20\">|</i>" +
|
||||
"<a href=\"/user/userinfo.html\" class=\"mr15\">"+data.data.nickName+"</a>" +
|
||||
"<a href=\"/user/userinfo.html\" class=\"mr15\">" + data.data.nickName + "</a>" +
|
||||
"<a href=\"javascript:logout()\" >退出</a>");
|
||||
;
|
||||
if("/user/login.html" == window.location.pathname){
|
||||
if ("/user/login.html" == window.location.pathname) {
|
||||
var orginUrl = getSearchString("originUrl");
|
||||
window.location.href = orginUrl == undefined || orginUrl.isBlank() ? "/" : orginUrl;
|
||||
return;
|
||||
}
|
||||
isLogin = true;
|
||||
if(localStorage.getItem("autoLogin") == 1){
|
||||
$.cookie('Authorization', data.data.token, { expires: 7 ,path: '/' });
|
||||
}else {
|
||||
$.cookie('Authorization', data.data.token,{ path: '/' });
|
||||
if (localStorage.getItem("autoLogin") == 1) {
|
||||
$.cookie('Authorization', data.data.token, {expires: 7, path: '/'});
|
||||
} else {
|
||||
$.cookie('Authorization', data.data.token, {path: '/'});
|
||||
}
|
||||
}else{
|
||||
if(needLoginPath.indexOf(window.location.pathname) != -1){
|
||||
} else {
|
||||
if (needLoginPath.indexOf(window.location.pathname) != -1) {
|
||||
location.href = '/user/login.html';
|
||||
}
|
||||
$(".user_link").html("<i class=\"line mr20\">|</i><a href=\"/user/login.html\" class=\"mr15\">登录</a><a href=\"/user/register.html\" >注册</a>");
|
||||
@ -94,7 +97,6 @@ if(!token){
|
||||
}
|
||||
|
||||
|
||||
|
||||
String.prototype.isPhone = function () {
|
||||
var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
|
||||
if (strTemp.test(this)) {
|
||||
@ -104,7 +106,7 @@ String.prototype.isPhone = function () {
|
||||
};
|
||||
|
||||
String.prototype.isBlank = function () {
|
||||
if(this == null || $.trim(this) == ""){
|
||||
if (this == null || $.trim(this) == "") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -118,11 +120,8 @@ String.prototype.isNickName = function () {
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function logout() {
|
||||
$.cookie('Authorization', null,{ path: '/' });
|
||||
$.cookie('Authorization', null, {path: '/'});
|
||||
location.reload();
|
||||
}
|
||||
|
||||
@ -133,9 +132,9 @@ function isImg(str) {
|
||||
|
||||
|
||||
//校验图片上传
|
||||
function checkPicUpload(file){
|
||||
function checkPicUpload(file) {
|
||||
|
||||
if(!isImg(file.value.substr(file.value.lastIndexOf(".")))){
|
||||
if (!isImg(file.value.substr(file.value.lastIndexOf(".")))) {
|
||||
layer.alert('只能上传图片格式的文件!');
|
||||
return false;
|
||||
}
|
||||
@ -144,13 +143,13 @@ function checkPicUpload(file){
|
||||
if (isIE && !file.files) {
|
||||
var filePath = file.value;
|
||||
var fileSystem = new ActiveXObject("Scripting.FileSystemfileect");
|
||||
var file = fileSystem.GetFile (filePath);
|
||||
var file = fileSystem.GetFile(filePath);
|
||||
fileSize = file.Size;
|
||||
}else {
|
||||
} else {
|
||||
fileSize = file.files[0].size;
|
||||
}
|
||||
fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
|
||||
if(fileSize>=1024){
|
||||
fileSize = Math.round(fileSize / 1024 * 100) / 100; //单位为KB
|
||||
if (fileSize >= 1024) {
|
||||
layer.alert('上传的图片大小不能超过1M!');
|
||||
return false;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ Array.prototype.remove = function (val) {
|
||||
var token = $.cookie('Authorization');
|
||||
if (!token) {
|
||||
if (needLoginPath.indexOf(window.location.pathname) != -1) {
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
}
|
||||
|
||||
// $(".user_link").html("<a href=\"/user/login.html\">登录</a>|<a href=\"/user/register.html\">注册</a>");
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<head>
|
||||
@ -7,14 +7,15 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||
<title>作家管理系统-小说精品屋</title>
|
||||
<link rel="stylesheet" href="/css/base.css?v=1"/>
|
||||
<link rel="stylesheet" href="/css/user.css" />
|
||||
<link rel="stylesheet" href="/css/user.css"/>
|
||||
</head>
|
||||
</head>
|
||||
<body class="">
|
||||
|
||||
<div class="header">
|
||||
<div class="mainNav" id="mainNav">
|
||||
<div class="box_center cf" style="text-align: center;height: 44px;line-height: 48px;color: #fff;font-size: 16px;">
|
||||
<div class="box_center cf"
|
||||
style="text-align: center;height: 44px;line-height: 48px;color: #fff;font-size: 16px;">
|
||||
|
||||
小说精品屋作家管理
|
||||
|
||||
@ -37,7 +38,9 @@
|
||||
<div class="my_r">
|
||||
<div class="my_bookshelf">
|
||||
<div class="title cf">
|
||||
<h2 class="fl ml10"><a href="/author/author_income_detail.html">订阅明细</a></h2><i class="fl ml20 mr20 font16">|</i><h2 class="fl"><a href="/author/author_income.html" class="red">稿费汇总</a></h2>
|
||||
<h2 class="fl ml10"><a href="/author/author_income_detail.html">订阅明细</a></h2><i
|
||||
class="fl ml20 mr20 font16">|</i>
|
||||
<h2 class="fl"><a href="/author/author_income.html" class="red">稿费汇总</a></h2>
|
||||
</div>
|
||||
|
||||
<div id="divData" class="updateTable">
|
||||
@ -62,7 +65,6 @@
|
||||
<tbody id="bookList">
|
||||
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="pageBox cf" id="shellPage">
|
||||
@ -120,24 +122,24 @@
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/author/listIncomeMonthByPage",
|
||||
data: {'curr':curr,'limit':limit},
|
||||
data: {'curr': curr, 'limit': limit},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.code == 200) {
|
||||
var bookList = data.data.list;
|
||||
if (bookList.length > 0) {
|
||||
var bookListHtml = "";
|
||||
for(var i=0;i<bookList.length;i++){
|
||||
for (var i = 0; i < bookList.length; i++) {
|
||||
var book = bookList[i];
|
||||
bookListHtml+=(" <tr class=\"book_list\" >\n" +
|
||||
bookListHtml += (" <tr class=\"book_list\" >\n" +
|
||||
" <td class=\"goread\">\n" +
|
||||
" "+book.incomeMonth+"</td>\n" +
|
||||
" " + book.incomeMonth + "</td>\n" +
|
||||
" <td class=\"goread\" >"
|
||||
+book.preTaxIncome/100+"</td>\n" +
|
||||
+ book.preTaxIncome / 100 + "</td>\n" +
|
||||
" <td class=\"goread\">\n" +
|
||||
" "+book.afterTaxIncome/100+"\n" +
|
||||
" " + book.afterTaxIncome / 100 + "\n" +
|
||||
" </td>\n" +
|
||||
" <td class=\"goread\">"+(book.payStatus == 1 ? '已支付' : '待支付')+
|
||||
" <td class=\"goread\">" + (book.payStatus == 1 ? '已支付' : '待支付') +
|
||||
" </td>\n" +
|
||||
|
||||
" </tr>");
|
||||
@ -176,9 +178,9 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
}else {
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
}
|
||||
|
||||
@ -191,12 +193,12 @@
|
||||
}
|
||||
|
||||
|
||||
function updateBookStatus(bookId,status) {
|
||||
function updateBookStatus(bookId, status) {
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/author/updateBookStatus",
|
||||
data: {'bookId':bookId,'status':status==0?1:0},
|
||||
data: {'bookId': bookId, 'status': status == 0 ? 1 : 0},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.code == 200) {
|
||||
@ -206,9 +208,9 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
}else {
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
}
|
||||
|
||||
@ -219,9 +221,6 @@
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<head>
|
||||
@ -7,14 +7,15 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||
<title>作家管理系统-小说精品屋</title>
|
||||
<link rel="stylesheet" href="/css/base.css?v=1"/>
|
||||
<link rel="stylesheet" href="/css/user.css" />
|
||||
<link rel="stylesheet" href="/css/user.css"/>
|
||||
</head>
|
||||
</head>
|
||||
<body class="">
|
||||
|
||||
<div class="header">
|
||||
<div class="mainNav" id="mainNav">
|
||||
<div class="box_center cf" style="text-align: center;height: 44px;line-height: 48px;color: #fff;font-size: 16px;">
|
||||
<div class="box_center cf"
|
||||
style="text-align: center;height: 44px;line-height: 48px;color: #fff;font-size: 16px;">
|
||||
|
||||
小说精品屋作家管理
|
||||
|
||||
@ -37,7 +38,9 @@
|
||||
<div class="my_r">
|
||||
<div class="my_bookshelf">
|
||||
<div class="title cf">
|
||||
<h2 class="fl ml10"><a href="/author/author_income_detail.html" class="red">订阅明细</a></h2><i class="fl ml20 mr20 font16">|</i><h2 class="fl"><a href="/author/author_income.html">稿费汇总</a></h2>
|
||||
<h2 class="fl ml10"><a href="/author/author_income_detail.html" class="red">订阅明细</a></h2><i
|
||||
class="fl ml20 mr20 font16">|</i>
|
||||
<h2 class="fl"><a href="/author/author_income.html">稿费汇总</a></h2>
|
||||
</div>
|
||||
|
||||
<div id="divData" class="updateTable">
|
||||
@ -61,7 +64,6 @@
|
||||
<tbody id="bookList">
|
||||
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="pageBox cf" id="shellPage">
|
||||
@ -117,9 +119,9 @@
|
||||
|
||||
function search(curr, limit) {
|
||||
|
||||
var data = {'curr':curr,'limit':limit};
|
||||
var data = {'curr': curr, 'limit': limit};
|
||||
|
||||
if(bookId){
|
||||
if (bookId) {
|
||||
data.bookId = bookId;
|
||||
}
|
||||
|
||||
@ -133,17 +135,17 @@
|
||||
var bookList = data.data.list;
|
||||
if (bookList.length > 0) {
|
||||
var bookListHtml = "";
|
||||
for(var i=0;i<bookList.length;i++){
|
||||
for (var i = 0; i < bookList.length; i++) {
|
||||
var book = bookList[i];
|
||||
bookListHtml+=(" <tr class=\"book_list\" >\n" +
|
||||
bookListHtml += (" <tr class=\"book_list\" >\n" +
|
||||
" <td class=\"goread\">\n" +
|
||||
" "+book.incomeDate+"</td>\n" +
|
||||
" " + book.incomeDate + "</td>\n" +
|
||||
" <td class=\"goread\" >"
|
||||
+book.incomeAccount+"</td>\n" +
|
||||
+ book.incomeAccount + "</td>\n" +
|
||||
" <td class=\"goread\">\n" +
|
||||
" "+book.incomeCount+"\n" +
|
||||
" " + book.incomeCount + "\n" +
|
||||
" </td>\n" +
|
||||
" <td class=\"goread\">"+book.incomeNumber+
|
||||
" <td class=\"goread\">" + book.incomeNumber +
|
||||
" </td>\n" +
|
||||
|
||||
" </tr>");
|
||||
@ -182,9 +184,9 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
}else {
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
}
|
||||
|
||||
@ -197,12 +199,12 @@
|
||||
}
|
||||
|
||||
|
||||
function updateBookStatus(bookId,status) {
|
||||
function updateBookStatus(bookId, status) {
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/author/updateBookStatus",
|
||||
data: {'bookId':bookId,'status':status==0?1:0},
|
||||
data: {'bookId': bookId, 'status': status == 0 ? 1 : 0},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.code == 200) {
|
||||
@ -212,9 +214,9 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
}else {
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
}
|
||||
|
||||
@ -225,9 +227,6 @@
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
|
@ -8,6 +8,79 @@
|
||||
<title>作家管理系统-小说精品屋</title>
|
||||
<link rel="stylesheet" href="/css/base.css?v=1"/>
|
||||
<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>
|
||||
<body class="">
|
||||
@ -46,18 +119,29 @@
|
||||
<ul class="log_list">
|
||||
<li><span id="LabErr"></span></li>
|
||||
<b>章节名:</b>
|
||||
<li><input type="text" id="bookIndex" name="bookIndex" class="s_input" ></li>
|
||||
<b>章节内容:</b><li id="contentLi">
|
||||
<textarea name="bookContent" rows="30" cols="80" id="bookContent"
|
||||
class="textarea"></textarea></li><br/>
|
||||
<li><input type="text" id="bookIndex" name="bookIndex" class="s_input"></li>
|
||||
<b>章节内容:</b>
|
||||
<li id="contentLi" style="width: 500px">
|
||||
<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>
|
||||
<li><input type="radio" name="isVip" value="0" checked >免费
|
||||
<input type="radio" name="isVip" value="1" >收费</li>
|
||||
<b>是否收费:</b>
|
||||
<li><input type="radio" name="isVip" value="0" checked>免费
|
||||
<input type="radio" name="isVip" value="1">收费
|
||||
</li>
|
||||
|
||||
|
||||
<li style="margin-top: 10px"><input type="button" onclick="addBookContent()" name="btnRegister" value="提交"
|
||||
id="btnRegister" class="btn_red">
|
||||
<li style="margin-top: 10px"><input type="button" onclick="addBookContent()"
|
||||
name="btnRegister" value="提交"
|
||||
id="btnRegister" class="btn_red">
|
||||
|
||||
|
||||
</li>
|
||||
@ -113,9 +197,10 @@
|
||||
|
||||
|
||||
var lock = false;
|
||||
|
||||
function addBookContent() {
|
||||
|
||||
if(lock){
|
||||
if (lock) {
|
||||
return;
|
||||
}
|
||||
lock = true;
|
||||
@ -125,14 +210,14 @@
|
||||
|
||||
|
||||
var indexName = $("#bookIndex").val();
|
||||
if(!indexName){
|
||||
if (!indexName) {
|
||||
$("#LabErr").html("章节名不能为空!");
|
||||
lock = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var content = $("#bookContent").val();
|
||||
if(!content){
|
||||
if (!content) {
|
||||
$("#LabErr").html("章节内容不能为空!");
|
||||
lock = false;
|
||||
return;
|
||||
@ -142,17 +227,15 @@
|
||||
var isVip = $("input:checked[name=isVip]").val();
|
||||
|
||||
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/author/addBookContent",
|
||||
data: {'bookId':bookId,'indexName':indexName,'content':content,'isVip':isVip},
|
||||
data: {'bookId': bookId, 'indexName': indexName, 'content': content, 'isVip': isVip},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.code == 200) {
|
||||
|
||||
window.location.href = '/author/index_list.html?bookId='+bookId;
|
||||
window.location.href = '/author/index_list.html?bookId=' + bookId;
|
||||
|
||||
|
||||
} 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>
|
||||
</html>
|
||||
|
@ -231,7 +231,7 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
@ -261,7 +261,7 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
|
@ -213,7 +213,7 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
@ -300,7 +300,7 @@
|
||||
layer.close(index);
|
||||
$.ajax({
|
||||
type: "delete",
|
||||
url: "/author/deleteIndex/"+indexId,
|
||||
url: "/author/deleteIndex/" + indexId,
|
||||
data: {},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
@ -311,7 +311,7 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
|
@ -380,7 +380,7 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
|
@ -2,10 +2,10 @@
|
||||
<div class="box_center cf">
|
||||
<div class="copyright">
|
||||
<ul>
|
||||
<li class="menu"><a href="/?to=mobile">手机站</a><i class="line">|</i><a href="/">网站首页</a><i
|
||||
<li class="menu"><!--<a href="/?to=mobile">手机站</a><i class="line">|</i>--><a href="/">网站首页</a><i
|
||||
class="line">|</i><a href="/user/feedback.html">反馈留言</a><i class="line">|</i><a
|
||||
href="/author/index.html">作家专区</a><i class="line">|</i><a
|
||||
href="/mobile/fiction_house.apk">客户端</a></li>
|
||||
href="/author/index.html">作家专区</a><!--<i class="line">|</i><a
|
||||
href="/mobile/fiction_house.apk">客户端</a>--></li>
|
||||
<li th:text="'Copyright (C) '+${application.website.domain}+' All rights reserved '+${application.website.name}+'版权所有'"></li>
|
||||
|
||||
</ul>
|
||||
|
@ -161,11 +161,6 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#footer {
|
||||
padding-top: 10px;
|
||||
line-height: 43px;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
</head>
|
||||
@ -210,6 +205,26 @@
|
||||
字体:<a id="fontbig" class="sizebg" onclick="nr_setbg('big')">大</a> <a id="fontmiddle" class="button sizebgon"
|
||||
onclick="nr_setbg('middle')">中</a> <a
|
||||
id="fontsmall" class="sizebg" onclick="nr_setbg('small')">小</a>
|
||||
<a href="javascript:speakChapter()" style="margin-left: 10px">
|
||||
<svg t="1707099868768" class="icon" viewBox="0 0 800 800" version="1.1" xmlns="http://www.w3.org/2000/svg"
|
||||
p-id="1783" id="mx_n_1707099868769" width="22" height="22">
|
||||
<path d="M393.707231 292.571429L343.13933 487.619048l46.955908 234.779541-97.523809-45.149912-66.82187-108.359788-21.671958-86.687831 66.82187-113.777778z"
|
||||
fill="#3eaf7c" p-id="1784"></path>
|
||||
<path d="M451.499118 509.291005a104.747795 61.40388 90 1 0 122.80776 0 104.747795 61.40388 90 1 0-122.80776 0Z"
|
||||
fill="#3eaf7c" p-id="1785"></path>
|
||||
<path d="M426.215168 781.996473c-3.611993 0-7.223986-1.805996-10.835979-3.611993l-117.389771-86.687831c-36.119929-23.477954-65.015873-57.791887-83.075838-99.329806-10.835979-25.283951-16.253968-52.373898-16.253968-81.269841s5.417989-55.985891 16.253968-81.269842c16.253968-41.537919 45.149912-74.045855 83.075838-97.523809l110.165785-77.657848c9.029982-5.417989 19.865961-3.611993 25.28395 3.611993 5.417989 9.029982 3.611993 19.865961-3.611993 25.28395L319.661376 361.199295c-32.507937 19.865961-55.985891 48.761905-70.433863 81.269841-9.029982 21.671958-14.447972 45.149912-14.447972 68.627866 0 23.477954 3.611993 45.149912 12.641976 66.821869 14.447972 34.313933 37.925926 63.209877 68.627866 83.075838l117.38977 86.687831c7.223986 5.417989 9.029982 18.059965 3.611993 25.28395 0 5.417989-5.417989 9.029982-10.835978 9.029983z"
|
||||
fill="#3eaf7c" p-id="1786"></path>
|
||||
<path d="M523.738977 830.758377c-108.359788 0-193.241623-140.867725-193.241623-317.855379S415.379189 193.241623 523.738977 193.241623c25.283951 0 50.567901 7.223986 74.045855 23.477954 9.029982 5.417989 10.835979 16.253968 5.41799 25.28395s-16.253968 10.835979-25.283951 5.41799c-18.059965-10.835979-34.313933-18.059965-54.179894-18.059965-84.881834 0-157.121693 130.031746-157.121693 281.73545S438.857143 794.638448 523.738977 794.638448s157.121693-130.031746 157.121693-281.73545c0-74.045855-16.253968-146.285714-46.955908-198.659612-5.417989-9.029982-1.805996-19.865961 7.223986-25.28395 9.029982-5.417989 19.865961-1.805996 25.28395 7.223986 32.507937 59.597884 50.567901 135.449735 50.567902 216.719576C718.786596 689.890653 633.904762 830.758377 523.738977 830.758377z"
|
||||
fill="#3eaf7c" p-id="1787"></path>
|
||||
<path d="M523.738977 646.546737c-48.761905 0-86.687831-59.597884-86.687831-133.643739S474.977072 379.259259 523.738977 379.259259s86.687831 59.597884 86.687831 133.643739-37.925926 133.643739-86.687831 133.643739z m0-232.973545c-23.477954 0-50.567901 39.731922-50.567901 97.52381s27.089947 97.52381 50.567901 97.523809 50.567901-39.731922 50.567901-97.523809-27.089947-97.52381-50.567901-97.52381z"
|
||||
fill="#3eaf7c" p-id="1788"></path>
|
||||
<path d="M523.738977 413.573192h-1.805996l-92.105821-10.835979c-9.029982-1.805996-16.253968-10.835979-16.253968-19.865961 1.805996-9.029982 10.835979-16.253968 19.865961-16.253968l92.105821 10.835979c9.029982 1.805996 16.253968 10.835979 16.253968 19.865961 0 9.029982-9.029982 16.253968-18.059965 16.253968zM372.035273 662.800705c-9.029982 0-16.253968-7.223986-18.059964-16.253968-1.805996-9.029982 5.417989-18.059965 16.253968-19.865961l153.5097-16.253968c9.029982-1.805996 18.059965 5.417989 19.865961 16.253968 1.805996 9.029982-5.417989 18.059965-16.253968 19.865961l-153.5097 16.253968h-1.805997z"
|
||||
fill="#3eaf7c" p-id="1789"></path>
|
||||
<path d="M763.936508 364.811287c-5.417989 0-9.029982-1.805996-12.641975-5.417989-7.223986-7.223986-7.223986-18.059965 0-25.283951l25.28395-25.28395c7.223986-7.223986 18.059965-7.223986 25.283951 0s7.223986 18.059965 0 25.28395L776.578483 359.393298c-3.611993 3.611993-9.029982 5.417989-12.641975 5.417989zM771.160494 720.592593c-5.417989 0-9.029982-1.805996-12.641975-5.41799l-25.283951-25.28395c-7.223986-7.223986-7.223986-18.059965 0-25.283951s18.059965-7.223986 25.283951 0l25.28395 25.283951c7.223986 7.223986 7.223986 18.059965 0 25.28395-3.611993 3.611993-7.223986 5.417989-12.641975 5.41799zM819.922399 529.156966h-54.179895c-10.835979 0-18.059965-7.223986-18.059964-18.059964s7.223986-18.059965 18.059964-18.059965h54.179895c10.835979 0 18.059965 7.223986 18.059964 18.059965s-9.029982 18.059965-18.059964 18.059964z"
|
||||
fill="#3eaf7c" p-id="1790"></path>
|
||||
</svg>
|
||||
</a>
|
||||
|
||||
</p>
|
||||
<div class="indexDiv" style="height: 42px;line-height: 42px;text-align:center;background: #f2f2f2">
|
||||
|
||||
@ -300,8 +315,6 @@
|
||||
}
|
||||
})
|
||||
|
||||
$("#content").css("min-height", ($(window).height() - 60) + "px");
|
||||
|
||||
|
||||
})();
|
||||
|
||||
@ -352,7 +365,7 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
|
||||
} else {
|
||||
@ -389,6 +402,79 @@
|
||||
|
||||
}
|
||||
|
||||
console.log(speechSynthesis.getVoices());
|
||||
|
||||
$(window).on('beforeunload', function () {
|
||||
if (speechSynthesis.speaking) {
|
||||
speechSynthesis.cancel()
|
||||
}
|
||||
});
|
||||
|
||||
function speakChapter() {
|
||||
console.log('speechSynthesis.paused', speechSynthesis.paused)
|
||||
console.log('speechSynthesis.pending', speechSynthesis.pending)
|
||||
console.log('speechSynthesis.speaking', speechSynthesis.speaking)
|
||||
if (speechSynthesis.speaking && !speechSynthesis.paused) {
|
||||
speechSynthesis.pause();
|
||||
return;
|
||||
}
|
||||
if (speechSynthesis.speaking && speechSynthesis.paused) {
|
||||
speechSynthesis.resume();
|
||||
}
|
||||
speak({
|
||||
'text': $('#chaptercontent').text(),
|
||||
'speechRate': 0.5,
|
||||
'pitch': 1,
|
||||
'lang': 'zh-CN'
|
||||
}, function () {
|
||||
console.log('语音播放结束');
|
||||
}, function () {
|
||||
console.log('语音开始播放');
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 文字转语音方法
|
||||
* @public
|
||||
* @param { text, rate, lang, volume, pitch } object
|
||||
* @param text 要合成的文字内容,字符串
|
||||
* @param speechRate 读取文字的语速 0.1~10 正常1
|
||||
* @param lang 读取文字时的语言
|
||||
* @param volume 读取时声音的音量 0~1 正常1
|
||||
* @param voice 读取文字的语音服务
|
||||
* @param pitch 读取时声音的音高 0~2 正常1
|
||||
* @returns SpeechSynthesisUtterance
|
||||
*/
|
||||
function speak({text, speechRate, lang, volume, pitch, voice}, endEvent, startEvent) {
|
||||
if (!window.SpeechSynthesisUtterance) {
|
||||
console.warn('当前浏览器不支持文字转语音服务')
|
||||
return;
|
||||
}
|
||||
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
|
||||
const speechUtterance = new SpeechSynthesisUtterance();
|
||||
speechUtterance.text = text;
|
||||
speechUtterance.rate = speechRate || 1;
|
||||
speechUtterance.lang = lang || 'zh-CN';
|
||||
speechUtterance.volume = volume || 1;
|
||||
speechUtterance.pitch = pitch || 1;
|
||||
speechUtterance.voice = voice || null;
|
||||
speechUtterance.onend = function () {
|
||||
endEvent && endEvent();
|
||||
};
|
||||
speechUtterance.onstart = function () {
|
||||
startEvent && startEvent();
|
||||
};
|
||||
speechSynthesis.speak(speechUtterance);
|
||||
|
||||
return speechUtterance;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
@ -274,7 +274,7 @@
|
||||
|
||||
} else if (data.code == 1001) {
|
||||
//未登录
|
||||
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
|
||||
location.href = '/user/login.html?originUrl=' + encodeURIComponent(location.href);
|
||||
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
@ -289,8 +289,6 @@
|
||||
}
|
||||
|
||||
|
||||
$("#content").css("min-height", ($(window).height() - 60) + "px");
|
||||
|
||||
function downloadFile() {
|
||||
var fileUrl = '/book/download?bookId=' + $("#bookIdHidden").val() + '&bookName=' + $("#bookNamedHidden").val();
|
||||
window.location.href = fileUrl;
|
||||
|
@ -36,41 +36,43 @@
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="content">
|
||||
<input type="hidden" id="bookIdHidden" th:value="${book.id}"/>
|
||||
<div style="height: 50px;line-height: 50px;text-align: center" class="layui-header header header-doc layui-bg-cyan">
|
||||
<input type="hidden" id="bookIdHidden" th:value="${book.id}"/>
|
||||
<div style="height: 50px;line-height: 50px;text-align: center"
|
||||
class="layui-header header header-doc layui-bg-cyan">
|
||||
|
||||
<div style="float: left;margin-left: 10px">
|
||||
<a href="javascript:history.go(-1)">
|
||||
<i style="font-size: 20px;color: #fff;" class="layui-icon"></i></a>
|
||||
<div style="float: left;margin-left: 10px">
|
||||
<a href="javascript:history.go(-1)">
|
||||
<i style="font-size: 20px;color: #fff;" class="layui-icon"></i></a>
|
||||
</div>
|
||||
<a style="color: #ffffff;" th:href="'/book/'+ ${book.id} + '.html'"><b class="layui-icon"
|
||||
th:utext="${book.bookName}"></b></a>
|
||||
<div style="float: right;margin-right: 10px">
|
||||
<a href="/"><i style="font-size: 20px;color: #fff;" class="layui-icon"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<a style="color: #ffffff;" th:href="'/book/'+ ${book.id} + '.html'"><b class="layui-icon" th:utext="${book.bookName}"></b></a>
|
||||
<div style="float: right;margin-right: 10px">
|
||||
<a href="/"><i style="font-size: 20px;color: #fff;" class="layui-icon"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p style="height: 30px;line-height: 30px;padding: 10px">
|
||||
<p style="height: 30px;line-height: 30px;padding: 10px">
|
||||
|
||||
<a href="#buttom" style="color: red"> ↓直达页面底部</a>
|
||||
</p>
|
||||
|
||||
|
||||
<div class="layui-colla-content layui-show indexP layui-row">
|
||||
<p class="line-limit-length layui-col-xs12 layui-col-sm4 layui-col-md3 layui-col-lg2" style="padding-left:10px;height: 50px;line-height: 50px;" th:each="index : ${bookIndexList}">
|
||||
<a style="color:#333;" th:href="'/book/'+${index.bookId}+'/'+${index.id}+'.html'" th:utext="${index.indexName}">
|
||||
|
||||
</a>
|
||||
<a href="#buttom" style="color: red"> ↓直达页面底部</a>
|
||||
</p>
|
||||
|
||||
|
||||
<div class="layui-colla-content layui-show indexP layui-row">
|
||||
<p class="line-limit-length layui-col-xs12 layui-col-sm4 layui-col-md3 layui-col-lg2"
|
||||
style="padding-left:10px;height: 50px;line-height: 50px;" th:each="index : ${bookIndexList}">
|
||||
<a style="color:#333;" th:href="'/book/'+${index.bookId}+'/'+${index.id}+'.html'"
|
||||
th:utext="${index.indexName}">
|
||||
|
||||
</div>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div th:replace="mobile/common/footer :: footer">
|
||||
</div>
|
||||
@ -80,13 +82,14 @@
|
||||
<div th:replace="mobile/common/js :: js">
|
||||
</div>
|
||||
<script>
|
||||
$("#content").css("min-height",($(window).height()-60)+"px");
|
||||
$.get("/book/addVisit",{"bookId":$("#bookIdHidden").val()},function(){});
|
||||
function toMyCollect(){
|
||||
$.get("/book/addVisit", {"bookId": $("#bookIdHidden").val()}, function () {
|
||||
});
|
||||
|
||||
function toMyCollect() {
|
||||
var token = localStorage.getItem("token");
|
||||
if(token) {
|
||||
if (token) {
|
||||
window.location.href = "/book/search?token=" + token;
|
||||
}else{
|
||||
} else {
|
||||
window.location.href = "/user/login.html";
|
||||
}
|
||||
}
|
||||
|
@ -62,10 +62,6 @@
|
||||
height: 180px;
|
||||
}
|
||||
|
||||
#footer {
|
||||
padding-top: 10px;
|
||||
line-height: 43px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -1,6 +1,11 @@
|
||||
<div th:fragment="css">
|
||||
<link rel="stylesheet" href="/mobile/layui/css/layui.css">
|
||||
<style type="text/css">
|
||||
body {
|
||||
min-height: 100vh;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.app {
|
||||
display: none;
|
||||
}
|
||||
@ -22,9 +27,12 @@
|
||||
}
|
||||
|
||||
#footer {
|
||||
padding-top: 6px;
|
||||
height: 60px;
|
||||
line-height: 54px;
|
||||
position: absolute;
|
||||
bottom: 0px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 50px;
|
||||
line-height: 48px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
|
@ -1,15 +1,19 @@
|
||||
<div th:fragment="footer" id="footer"
|
||||
class="layui-footer footer footer-demo layui-bg-cyan">
|
||||
<!--<a href="/mobile/book/searchSoftBook.html" style="font-size: 14px;color: #fff;">轻小说</a>
|
||||
<a href="/mobile/book/searchSoftBook.html?catId=9" style="font-size: 14px;color: #fff;margin-left: 8px">漫画</a>-->
|
||||
<a href="/?to=pc" style="font-size: 14px;color: #fff;margin-left: 8px">电脑站</a>
|
||||
<a href="/user/read_history.html" style="font-size: 14px;color: #fff;margin-left: 8px">阅读记录</a>
|
||||
<a href="/user/favorites.html" style="font-size: 14px;color: #fff;margin-left: 8px">书架</a>
|
||||
<a href="/mobile/fiction_house.apk" style="font-size: 14px;color: #fff;margin-left: 8px">客户端</a>
|
||||
<!--<a href="https://www.zinglizingli.xyz/me/index.html" style="font-size: 14px;color: #fff;margin-left: 8px">开发者</a>-->
|
||||
<div th:fragment="footer">
|
||||
<div style="height: 50px"></div>
|
||||
<div id="footer"
|
||||
class="layui-footer footer footer-demo layui-bg-cyan">
|
||||
<!--<a href="/mobile/book/searchSoftBook.html" style="font-size: 14px;color: #fff;">轻小说</a>
|
||||
<a href="/mobile/book/searchSoftBook.html?catId=9" style="font-size: 14px;color: #fff;margin-left: 8px">漫画</a>-->
|
||||
<!--<a href="/?to=pc" style="font-size: 14px;color: #fff;margin-left: 8px">电脑站</a>-->
|
||||
<a href="/" style="font-size: 16px;color: #fff;">首页</a>
|
||||
<a href="/user/read_history.html" style="font-size: 16px;color: #fff;margin-left: 18px">阅读记录</a>
|
||||
<a href="/user/favorites.html" style="font-size: 16px;color: #fff;margin-left: 18px">书架</a>
|
||||
<!--<a href="/mobile/fiction_house.apk" style="font-size: 14px;color: #fff;margin-left: 8px">客户端</a>-->
|
||||
<!--<a href="https://www.zinglizingli.xyz/me/index.html" style="font-size: 14px;color: #fff;margin-left: 8px">开发者</a>-->
|
||||
|
||||
|
||||
<div style="float: right"><a href="#top"><i class="layui-icon"
|
||||
style="margin-right:15px;font-size: 30px;color:#fff "></i></a>
|
||||
<div style="margin-top:-3px;float: right"><a href="#top"><i class="layui-icon"
|
||||
style="margin-right:15px;font-size: 25px;color:#fff "></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -208,7 +208,7 @@
|
||||
if (data.code == 200) {
|
||||
var updateRankBooks = data.data;
|
||||
var updateRankBookHtml = "";
|
||||
for (var i = 0; i < 10; i++) {
|
||||
for (var i = 0; i < updateRankBooks.length; i++) {
|
||||
|
||||
var updateRankBook = updateRankBooks[i];
|
||||
if (updateRankBook.bookDesc) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user