Compare commits

...

87 Commits

Author SHA1 Message Date
cd11854eff v2.8.0发布 2020-11-17 10:52:44 +08:00
85f5048fd9 v2.8.0发布 2020-11-17 10:49:59 +08:00
f625ee38e1 作家后台完善 2020-11-17 10:25:31 +08:00
2c3e346ea7 修复小说阅读的时候按键盘→会报错的bug 2020-11-12 12:03:45 +08:00
66093cb065 v2.7.1发布 2020-11-10 11:56:11 +08:00
beba6e5154 作家后台小说列表新增昨日订阅量统计 2020-11-09 18:18:27 +08:00
04d3aef82b 展示图更新 2020-11-09 15:10:30 +08:00
018daf8d37 修改上传提示图片 2020-11-09 14:53:18 +08:00
8e0f1f12a4 作者后台菜单栏图标修改 2020-11-09 14:11:02 +08:00
165c96cd48 v2.7.0发布 2020-11-06 08:01:07 +08:00
e343134ce2 手机端购买页面更新&版本号更改 2020-11-05 07:47:17 +08:00
a1adb2c7df 删除垃圾文件夹 2020-11-03 15:21:19 +08:00
81a82d8e72 展示图更新 2020-11-03 15:18:50 +08:00
1d33094bd7 展示图更新 2020-11-03 15:15:46 +08:00
4cccea5d75 作家专区新增稿费收入查询(订阅明细+稿费汇总) 2020-11-03 14:58:59 +08:00
fbfb68583f update 2020-11-03 09:01:33 +08:00
655957904b update 2020-11-03 08:55:32 +08:00
99e973091d 自动更新排除掉原创小说 2020-11-03 08:41:48 +08:00
5fdf618223 自动更新排除掉原创小说 2020-11-03 08:30:45 +08:00
03c4e6c54b v2.6.5发布 2020-11-03 07:41:38 +08:00
29527301cf front模块添加message配置文件,覆盖common模块的配置,方便打包后直接修改网站信息 2020-11-03 07:36:13 +08:00
29d03a7a22 通用header.html加入script参数 2020-11-03 07:24:13 +08:00
ad4199dc4e 添加示例网站 2020-11-03 06:57:46 +08:00
4f7f9af6a9 update readme 2020-11-03 06:54:52 +08:00
ee2a0f514f 排行榜页面显示问题修复 2020-10-25 20:27:24 +08:00
70f04bd37c 小说封面图片上传 2020-08-10 07:12:14 +08:00
9d621edaec update readme 2020-07-03 09:31:57 +08:00
56c0a81c1b update readme 2020-07-03 08:57:38 +08:00
6b3b88c147 Merge branch 'release_v2.6.1' into release_v2.6.2 2020-07-02 23:17:14 +08:00
894ee67f56 优化mac端浏览器的识别问题 2020-07-02 23:15:21 +08:00
a88891b72f v2.6.2发布 2020-06-29 16:45:51 +08:00
5c7724c813 修改首页缓存时间 2020-06-29 16:43:10 +08:00
79c9f3e0f1 Merge branch 'release_v2.6.0' into release_v2.6.1 2020-06-25 10:49:15 +08:00
575142f9f3 修复部分maven版本admin模块build失败的问题 2020-06-25 10:46:27 +08:00
83c2460c83 v2.6.1发布 2020-06-22 11:06:52 +08:00
c7642ac2ef 修复搜索引擎模式下按更新时间筛选的bug 2020-06-22 11:01:23 +08:00
5af570a514 v2.6.0发布 2020-06-15 18:08:09 +08:00
0d96ff81b6 v2.6.0发布 2020-06-15 17:47:12 +08:00
7733cf1e3f 更新版本号 2020-06-15 15:13:37 +08:00
c9c714e71e 增加单本采集任务 2020-06-15 15:08:15 +08:00
3cbb6bf3fb 遇到错误章节直接中断改为遇到错误章节跳过,解决某些网站由于大量章节错误而导致的大量书籍未爬取完的情况 2020-06-15 10:06:35 +08:00
750e234f60 更新 2020-06-09 04:26:32 +08:00
c1d485c42b 更新 2020-06-09 04:19:10 +08:00
0e2e6229cd 增加新源,过滤简介中的特殊字符,提高爬虫兼容性 2020-06-08 16:54:58 +08:00
f8a669eb01 关闭分表的升级通道 2020-06-01 17:33:46 +08:00
6d56399d0f 文档更新 2020-06-01 16:12:46 +08:00
1a0c1f864b v2.5.0发布 2020-06-01 15:40:37 +08:00
b193aca288 默认开启分表功能(适用于新用户),通过添加配置spring.autoconfigure.exclude=io.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration来关闭分表功能(适用于老用户升级) 2020-06-01 11:31:05 +08:00
7a6d7a4442 暂时关闭分表功能,有需要自己开启 2020-06-01 09:24:37 +08:00
5505840b6e 暂时关闭分表功能,有需要的自己开启 2020-06-01 09:22:00 +08:00
xxy
8eb3048b91 文档更新 2020-05-29 10:10:25 +08:00
xxy
1b138c2aad 文档更新 2020-05-29 10:06:45 +08:00
f5e2dbaa6b 更改配置文件中redis配置位置 2020-05-26 18:52:38 +08:00
xxy
b6cb9aaedc 文档更新 2020-05-26 18:17:34 +08:00
f9f1e474ec 引入shardingjdbc,将小说内容表分为10个小表 2020-05-26 18:09:19 +08:00
xxy
06bf848e99 更新文档 2020-05-26 13:17:23 +08:00
6e171d20ed 集成fastDfs 2020-05-26 13:07:53 +08:00
c62acc288e 集成OSS对象存储 2020-05-26 11:31:30 +08:00
xxy
9975faed01 点击量计算优化 2020-05-26 02:27:39 +08:00
xxy
8fde3a3725 点击量计算优化 2020-05-26 02:13:28 +08:00
xxy
430504ee28 点击量计算优化 2020-05-26 02:10:37 +08:00
xxy
16447c60ec 引入redisson 2020-05-26 00:28:12 +08:00
xxy
be7cbe2d6f 欲引入Redisson框架实现分布式锁 2020-05-26 00:04:00 +08:00
xxy
8f1ed88b07 es采集优化 2020-05-25 23:38:46 +08:00
xxy
9b9851e7ab 文档更新 2020-05-25 23:16:08 +08:00
a55edf0408 es优化 2020-05-25 21:37:00 +08:00
856c4c0667 es优化 2020-05-25 21:26:47 +08:00
e4dd5bcb71 引入rabbitmq流量削峰,累积点击量后统一更新 2020-05-25 21:06:51 +08:00
5dbddbdd96 es导入优化 2020-05-25 17:51:05 +08:00
73be43e1c5 优化es采集 2020-05-25 17:11:03 +08:00
ce2a3b4647 集成redis 2020-05-25 16:54:39 +08:00
68abdeca93 文档更新 2020-05-25 10:59:24 +08:00
0b505a3922 v2.1.2发布 2020-05-25 10:51:22 +08:00
353cb8c536 修复网路图片保存时文件损坏的情况 2020-05-25 10:40:50 +08:00
xxy
e1e1310b9e 解决book_index的主键生成冲突 2020-05-24 17:59:03 +08:00
4c42ac0d29 文档更新 2020-05-24 09:17:49 +08:00
d025d3d514 优化列表页显示 2020-05-24 02:04:02 +08:00
a0fb8e481a 1.解决爬虫线程停止失败的bug,2新增新笔趣阁源,兼容更多源站 2020-05-24 00:54:27 +08:00
80b933db8d v2.1.1发布 2020-05-22 11:58:42 +08:00
87a060280a 1.解决小说/章节发布表单重复提交问题,2.解决小说章节发布字数计算问题,3.解决个人发布小说字体更改问题 2020-05-22 11:49:18 +08:00
9c78f400dc v2.1.0发布 2020-05-21 09:15:47 +08:00
c2cdf73893 1优化网络图片转换策略 2020-05-21 08:46:46 +08:00
a13ea78c3f 1优化es导入策略,2增加默认图片,在读取网络图片失败时设置,防止一直失败重试 2020-05-21 08:16:37 +08:00
0144b77983 v2.1.0发布 2020-05-20 22:13:53 +08:00
07b9ffde96 修改版本号 2020-05-20 21:30:19 +08:00
002a0723f7 索引+搜索优化 2020-05-20 21:23:59 +08:00
8a628f081f 集成elasticsearch搜索引擎 2020-05-20 18:08:29 +08:00
138 changed files with 6475 additions and 631 deletions

114
README.md
View File

@ -1,10 +1,28 @@
[![index](./assets/热门云产品1040.100.jpg)](https://cloud.tencent.com/act/cps/redirect?redirect=1052&cps_key=736e609d66e0ac4e57813316cec6fd0b&from=console)
[![index]( https://s1.ax1x.com/2020/07/03/NOSA5q.jpg )]( https://cloud.tencent.com/act/cps/redirect?redirect=1052&cps_key=736e609d66e0ac4e57813316cec6fd0b&from=console )
# 小说精品屋-plus
#### 演示地址
#### 新项目小说精品屋-微服务版
[点击前往](http://www.java2nb.com)(前台门户)
基于小说精品屋-plus构建的Spring Cloud 微服务小说门户平台
Gitee仓库地址 https://gitee.com/xiongxyang/novel-cloud
GitHub仓库地址 https://github.com/201206030/novel-cloud
#### 示例网站
[网站1点击前往](http://www.bqmfxs.cn)
[网站2点击前往](http://iyuedu.space)
[网站3点击前往](http://suxiange.com)
[网站4点击前往](http://ruoshu.com)
[网站5点击前往](https://www.jingjiao.net)
[网站6点击前往](http://www.shucheng.in)
#### 前言
@ -12,9 +30,9 @@
#### 项目介绍
[小说精品屋](https://github.com/201206030/fiction_house)是一个多平台web、安卓app、微信小程序、功能完善的小说弹幕网站包含精品小说专区、轻小说专区和漫画专区。包括小说/漫画分类、小说/漫画搜索、小说/漫画排行、完本小说/漫画、小说/漫画评分、小说/漫画在线阅读、小说/漫画书架、小说/漫画阅读记录、小说下载、小说弹幕、小说/漫画自动爬取、小说内容自动分享到微博、邮件自动推广、链接自动推送到百度搜索引擎等功能。包含电脑端、移动端、微信小程序等多个平台现已开源web端、安卓端、小程序端源码。
小说精品屋-plus是在[小说精品屋](https://github.com/201206030/fiction_house)的基础上去除了漫画和弹幕模块专注于小说是一个多端PC、移动阅读、功能完善的小说原创/爬虫网站项目既包含了作家专区供原创作者上传小说又提供了爬虫工具通过规则多线程全自动采集任意小说网站数据已兼容99%的小说网站),新书自动入库,老书自动更新。
小说精品屋-plus是在小说精品屋的基础上重新进行了数据库设计代码重构和功能增强提升了程序整体的可读性和性能增加了很多商用特性主要升级如下
小说精品屋-plus重新进行了数据库设计代码重构和功能增强提升了程序整体的可读性和性能增加了很多商用特性主要升级如下
- [x] 数据库重新设计结构调整
- [x] 服务端代码重构MyBatis3升级为MyBatis3DynamicSql
@ -40,7 +58,31 @@ novel-plus -- 父工程
```
#### 技术选型
Springboot+Mybatis+Mysql+Ehcache+Thymeleaf+Layui
| 技术 | 说明
| -------------------- | ---------------------------
| SpringBoot | Spring应用快速开发脚手架
| MyBatis | 持久层ORM框架
| MyBatis Dynamic SQL | Mybatis动态sql
| PageHelper | MyBatis分页插件
| MyBatisGenerator | 持久层代码生成插件
| Sharding-Jdbc | 代码层分库分表中间件
| JJWT | JWT登录支持
| SpringSecurity | 安全框架
| Shiro | 安全框架
| Ehcache | Java进程内缓存框架(默认缓存)
| Redis | 分布式缓存(缓存替换方案默认关闭一行配置开启)
| ElasticSearch | 搜索引擎(搜索增强方案默认关闭一行配置开启)
| RabbitMq | 消息队列(流量削峰默认关闭一行配置开启)
| OSS | 阿里云对象存储服务(图片存储方式之一一行配置即可切换)
| FastDfs |开源轻量级分布式文件系统(图片存储方式之一一行配置即可切换)
| Redisson | 实现分布式锁
| Lombok | 简化对象封装工具
| Docker | 应用容器引擎
| Mysql | 数据库服务
| Thymeleaf | 模板引擎
| Layui | 前端UI
#### PC站截图
@ -52,69 +94,73 @@ Springboot+Mybatis+Mysql+Ehcache+Thymeleaf+Layui
![img](https://oscimg.oschina.net/oscnet/up-d0b2e03129bfae47b8bb96a491b73d383c5.png)
3. 排行榜
3. 搜索页
![img](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/QQ20200520-215756.png)
![img](https://oscimg.oschina.net/oscnet/up-ed5f689557718924acac76bc3ebca36afcb.png)
4. 排行榜
![img](https://oscimg.oschina.net/oscnet/up-78d5a68586cd92a86c669311f414508f922.png)
4. 详情页
5. 详情页
![img](https://oscimg.oschina.net/oscnet/up-8be2495a2869f93626b0c9c1df6f329747a.png)
5. 阅读页
6. 阅读页
![img](https://oscimg.oschina.net/oscnet/up-517c84148d2db8e11717a8bbecc57fa1be7.png)
6. 用户中心
7. 用户中心
![img](https://oscimg.oschina.net/oscnet/up-805a30e7a663a3fd5cb39a7ea26bc132a01.png)
7. 充值
8. 充值
![img](https://oscimg.oschina.net/oscnet/up-5a601b0b3af3224d0bebcfe12fc15075d34.png)
![img](https://oscimg.oschina.net/oscnet/up-face25d02c07b05b2ce954cc4bf4ee6a0cc.png)
8.作家专区
9. 作家专区
![img](https://oscimg.oschina.net/oscnet/up-30766372cc7f56480ff1d7d55198204f6ea.png)
![img](https://oscimg.oschina.net/oscnet/up-9737995e465b86f3bee3211221f6c3b8a56.png)
![img](https://s3.ax1x.com/2020/11/17/DVFiQI.png)
9.购买
![img](https://s1.ax1x.com/2020/11/09/B7X5oF.png)
![img](https://s1.ax1x.com/2020/11/09/B7XLsx.png)
10. 购买
![img](https://oscimg.oschina.net/oscnet/up-ce0f585efd82a9670335f118cf5897c85e9.png)
![img](https://oscimg.oschina.net/oscnet/up-f849960f4c1303fea77d26e64fc505a7180.png)
#### 手机站截图
1. 首页
![index](./assets/QQ%E5%9B%BE%E7%89%8720191018162208.jpg)
![index](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/QQ%E5%9B%BE%E7%89%8720191018162208.jpg)
2. 小说详情页
![微信图片_20190904181558](./assets/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20190904181558.png)
![微信图片_20190904181558](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20190904181558.png)
3. 目录页
![QQ图片20191018161901](./assets/QQ%E5%9B%BE%E7%89%8720191108022250.png)
![QQ图片20191018161901](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/QQ%E5%9B%BE%E7%89%8720191108022250.png)
4. 小说阅读页
![QQ图片20191018161901](./assets/QQ%E5%9B%BE%E7%89%8720191018161901.png)
![QQ图片20191018161901](https://gitee.com/xiongxyang/novel-plus/raw/release_v2.1.0/assets/QQ%E5%9B%BE%E7%89%8720191018161901.png)
#### 爬虫管理系统截图
![QQ图片20191018161901](./assets/crawl_index.png)
![img](https://s1.ax1x.com/2020/11/03/BsOgbD.png)
![img](https://s1.ax1x.com/2020/11/03/BsOHr8.png)
#### 后台管理系统截图
@ -161,16 +207,20 @@ docker安装教程[点击前往](https://my.oschina.net/java2nb/blog/4271989)
#### QQ交流群
![mini-code](./assets/小说精品屋开源项目交流群群聊二维码.png)
![mini-code](https://s1.ax1x.com/2020/10/31/BUQVeI.png)
#### 捐赠支持
#### 赞赏支持
开源项目不易若此项目能得到你的青睐可以捐赠支持作者持续开发与维护
开源项目不易若此项目能得到你的青睐那么你可以赞赏支持作者持续开发与维护
![mini-code](./assets/jk.png)
- 服务器的费用也是一笔开销
- 为用户提供更好的开发环境
- 一杯咖啡
![mini-code](https://s1.ax1x.com/2020/10/31/BUQJwq.png)
#### 备注
精品小说屋所有相关项目均已在开源中国公开感兴趣的可进入[开源中国](https://www.oschina.net/p/fiction_house)按关键字`精品小说屋`搜索。
[![index](./assets/120060.jpg)](https://www.aliyun.com/minisite/goods?userCode=uf4nasee )
[![index](https://s1.ax1x.com/2020/07/03/NOSuMF.jpg)](https://www.aliyun.com/minisite/goods?userCode=uf4nasee )

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 185 KiB

82
es/index_create.txt Normal file
View File

@ -0,0 +1,82 @@
PUT /novel
{
"mappings" : {
"book" : {
"properties" : {
"id" : {
"type" : "long"
},
"authorId" : {
"type" : "long"
},
"authorName" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 1.9
},
"bookName" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 2
},
"bookDesc" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 0.1
},
"bookStatus" : {
"type" : "short"
},
"catId" : {
"type" : "integer"
},
"catName" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 1.0
},
"lastIndexId" : {
"type" : "long"
},
"lastIndexName" : {
"type" : "text",
"analyzer": "ik_smart",
"boost": 0.1
},
"lastIndexUpdateTime" : {
"type": "keyword"
},
"picUrl" : {
"type" : "keyword"
},
"score" : {
"type" : "float"
},
"wordCount" : {
"type" : "integer"
},
"workDirection" : {
"type" : "short"
},
"visitCount" : {
"type": "long"
}
}
}
}
}

6
novel-admin/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM java:8
ADD novel-admin-1.0.0.jar /root
ENV dburl=""
ENV username=""
ENV password=""
ENTRYPOINT ["sh","-c","java -Dspring.datasource.url=${dburl} -Dspring.datasource.username=${username} -Dspring.datasource.password=${password} -jar /root/novel-admin-1.0.0.jar"]

View File

@ -1,8 +0,0 @@
2020-05-13 21:52:00,972 INFO (StartupInfoLogger.java:50)- Starting TestDemo on USER-20180729KA with PID 3532 (started by Administrator in E:\baseprojectparent\novel-plus\novel-admin)
2020-05-13 21:52:01,113 DEBUG (StartupInfoLogger.java:53)- Running with Spring Boot v2.0.1.RELEASE, Spring v5.0.5.RELEASE
2020-05-13 21:52:01,131 INFO (SpringApplication.java:663)- The following profiles are active: dev
2020-05-13 21:52:54,469 DEBUG (ApplicationContextRegister.java:29)- ApplicationContext registed-->org.springframework.web.context.support.GenericWebApplicationContext@5b529706: startup date [Wed May 13 21:52:01 CST 2020]; root of context hierarchy
2020-05-13 21:53:49,622 INFO (StartupInfoLogger.java:59)- Started TestDemo in 114.268 seconds (JVM running for 124.957)
2020-05-18 09:48:03,219 INFO (StartupInfoLogger.java:50)- Starting TestDemo on DESKTOP-CPCLUI6 with PID 13172 (started by 11797 in D:\gitee\novel-plus\novel-admin)
2020-05-18 09:48:03,223 DEBUG (StartupInfoLogger.java:53)- Running with Spring Boot v2.0.1.RELEASE, Spring v5.0.5.RELEASE
2020-05-18 09:48:03,227 INFO (SpringApplication.java:663)- The following profiles are active: dev

View File

@ -137,10 +137,6 @@
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-data-redis</artifactId>-->

View File

@ -12,7 +12,7 @@ spring:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
username: root
password:
password: test123456
#password:
initialSize: 1
minIdle: 3

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>2.0.2</version>
<version>2.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -31,11 +31,20 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!--ehcache-->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<!--集成redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>${redis.version}</version>
</dependency>
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
@ -48,6 +57,22 @@
<version>${mybatis.version}</version>
</dependency>
<!-- 分库分表-->
<!-- sharding jdbc依赖 -->
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>${sharding.jdbc.version}</version>
</dependency>
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-namespace</artifactId>
<version>${sharding.jdbc.version}</version>
</dependency>
<!--分页助手启动器-->
<dependency>
<groupId>com.github.pagehelper</groupId>

View File

@ -46,4 +46,23 @@ public interface CacheKey {
* */
String RUNNING_CRAWL_THREAD_KEY_PREFIX = "runningCrawlTreadDataKeyPrefix";
/**
* 上一次搜索引擎更新的时间
* */
String ES_LAST_UPDATE_TIME = "esLastUpdateTime";
/**
* 搜索引擎转换锁
* */
String ES_TRANS_LOCK = "esTransLock";
/**
* 上一次搜索引擎是否更新过小说点击量
* */
String ES_IS_UPDATE_VISIT = "esIsUpdateVisit";
/**
* 累积的小说点击量
* */
String BOOK_ADD_VISIT_COUNT = "bookAddVisitCount";
}

View File

@ -51,9 +51,5 @@ public interface CacheService {
* */
void expire(String key, long timeout);
/**
* 刷新缓存
* */
void refresh(String key);
}

View File

@ -1,22 +1,23 @@
package com.java2nb.novel.core.cache.impl;
import com.java2nb.novel.core.cache.CacheService;
import lombok.RequiredArgsConstructor;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
/**
* @author xxy
*/
@ConditionalOnProperty(prefix = "cache", name = "type", havingValue = "ehcache")
@RequiredArgsConstructor
@Service
public class EhCacheServiceImpl implements CacheService {
@Autowired
private CacheManager cacheManager ;
private static final String CACHE_NAME = "utilCache";
private final CacheManager cacheManager ;
/**
@ -30,14 +31,6 @@ public class EhCacheServiceImpl implements CacheService {
}
public CacheManager getCacheManager() {
return cacheManager;
}
@Override
public String get(String key) {
Element element = getCache().get(key);
@ -125,20 +118,6 @@ public class EhCacheServiceImpl implements CacheService {
}
@Override
public void refresh(String key) {
Element element = getCache().get(key);
if (element != null) {
Object value = element.getValue();
int timeToLive = element.getTimeToLive();
element = new Element(key, value);
element.setTimeToLive(timeToLive);
Cache cache = getCache();
cache.put(element);
}
}
}

View File

@ -0,0 +1,73 @@
package com.java2nb.novel.core.cache.impl;
import com.java2nb.novel.core.cache.CacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/**
* @author xxy
*/
@ConditionalOnProperty(prefix = "cache", name = "type", havingValue = "redis")
@RequiredArgsConstructor
@Service
public class RedisServiceImpl implements CacheService {
private final StringRedisTemplate stringRedisTemplate;
private final RedisTemplate<Object, Object> redisTemplate;
@Override
public String get(String key) {
return stringRedisTemplate.opsForValue().get(key);
}
@Override
public void set(String key, String value) {
stringRedisTemplate.opsForValue().set(key,value);
}
@Override
public void set(String key, String value, long timeout) {
stringRedisTemplate.opsForValue().set(key,value,timeout, TimeUnit.SECONDS);
}
@Override
public Object getObject(String key) {
return redisTemplate.opsForValue().get(key);
}
@Override
public void setObject(String key, Object value) {
redisTemplate.opsForValue().set(key,value);
}
@Override
public void setObject(String key, Object value, long timeout) {
redisTemplate.opsForValue().set(key,value,timeout, TimeUnit.SECONDS);
}
@Override
public void del(String key) {
redisTemplate.delete(key);
stringRedisTemplate.delete(key);
}
@Override
public boolean contains(String key) {
return redisTemplate.hasKey(key) || stringRedisTemplate.hasKey(key);
}
@Override
public void expire(String key, long timeout) {
redisTemplate.expire(key,timeout, TimeUnit.SECONDS);
stringRedisTemplate.expire(key,timeout, TimeUnit.SECONDS);
}
}

View File

@ -0,0 +1,62 @@
package com.java2nb.novel.core.converter;
import org.springframework.core.convert.converter.Converter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 表单形式的全局时间类型转换器
* @author xiongxiaoyang
*/
public class DateConverter implements Converter<String, Date> {
private static final List<String> formats = new ArrayList<>(4);
static {
formats.add("yyyy-MM");
formats.add("yyyy-MM-dd");
formats.add("yyyy-MM-dd HH:mm");
formats.add("yyyy-MM-dd HH:mm:ss");
}
@Override
public Date convert(String source) {
String value = source.trim();
if ("".equals(value)) {
return null;
}
if (source.matches("^\\d{4}-\\d{1,2}$")) {
return parseDate(source, formats.get(0));
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}$")) {
return parseDate(source, formats.get(1));
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}$")) {
return parseDate(source, formats.get(2));
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}$")) {
return parseDate(source, formats.get(3));
} else {
throw new IllegalArgumentException("Invalid boolean value '" + source + "'");
}
}
/**
* 格式化日期
*
* @param dateStr String 字符型日期
* @param format String 格式
* @return Date 日期
*/
private Date parseDate(String dateStr, String format) {
Date date = null;
try {
DateFormat dateFormat = new SimpleDateFormat(format);
date = dateFormat.parse(dateStr);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
}

View File

@ -55,9 +55,18 @@ public enum ResponseStatus {
* */
INVITE_CODE_INVALID(4001, "邀请码无效!"),
AUTHOR_STATUS_FORBIDDEN(4002, "作者状态异常,暂不能管理小说!")
, BOOKNAME_EXISTS(4003,"已发布过同名小说!")
, BOOKNAME_EXISTS(4003,"已发布过同名小说!"),
/**
* 小说相关错误
*/
BOOK_EXISTS(5001,"该小说已存在")
,
/**
* 搜索引擎相关错误
* */
ES_SEARCH_FAIL(9001,"搜索引擎查询错误!"),
/**

View File

@ -0,0 +1,119 @@
package com.java2nb.novel.core.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
/**
* 日期工具
* @author cd
*/
public class DateUtil {
public static final String DATE_PATTERN = "yyyy-MM-dd";
public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static final String TIME_PATTERN = "HH:mm:ss";
/**
* 获取昨天的日期时间
* */
public static Date getYesterday(){
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -1);
return calendar.getTime();
}
/**
* 根据日期,获取当天开始时间
* */
public static Date getDateStartTime(Date date){
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
/*
* Calendar.HOUR_OF_DAY:是指获取24小时制的小时,取值范围:0-23;
* Calendar.HOUR:是指获取12小时制的小时,取值范围:0-12,凌晨和中午都是0,不是12;
* 需要配合Calendar.AM_PM使用;
* */
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
return calendar.getTime();
}
/**
* 根据日期,获取当天结束时间
* */
public static Date getDateEndTime(Date date){
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY,23);
calendar.set(Calendar.MINUTE,59);
calendar.set(Calendar.SECOND,59);
calendar.set(Calendar.MILLISECOND,999);
return calendar.getTime();
}
/**
* 获取上个月开始时间
*
* @return
*/
public static Date getLastMonthStartTime(){
// 获取当前日期
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, 0);
calendar.add(Calendar.MONTH, -1);
// 设置为1号,当前日期既为本月第一天
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
/**
* 获取上个月结束时间
*
* @return
*/
public static Date getLastMonthEndTime(){
// 获取当前日期
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, 0);
calendar.add(Calendar.MONTH, -1);
// 获取当前月最后一天
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
return calendar.getTime();
}
/**
* 格式化日期
* */
public static String formatDate(Date date,String patten){
return new SimpleDateFormat(patten).format(date);
}
public static void main(String[] args) {
System.out.println(formatDate(getYesterday(),DATE_TIME_PATTERN));
System.out.println(formatDate(getDateStartTime(getYesterday()),DATE_TIME_PATTERN));
System.out.println(formatDate(getDateEndTime(getYesterday()),DATE_TIME_PATTERN));
System.out.println(formatDate(getLastMonthStartTime(),DATE_TIME_PATTERN));
System.out.println(formatDate(getLastMonthEndTime(),DATE_TIME_PATTERN));
}
}

View File

@ -1,6 +1,7 @@
package com.java2nb.novel.core.utils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.Charsets;
import org.apache.http.client.utils.DateUtils;
import org.springframework.core.io.Resource;
@ -9,6 +10,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import javax.imageio.ImageIO;
import java.io.*;
import java.util.Date;
import java.util.Objects;
@ -17,18 +19,21 @@ import java.util.Objects;
* 文件操作工具类
* @author 11797
*/
@Slf4j
public class FileUtil {
/**
* 网络图片转本地
* */
@SneakyThrows
public static String network2Local(String picSrc,String picSavePath,String visitPrefix) {
InputStream input = null;
OutputStream out = null;
try {
//本地图片保存
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);
InputStream input = Objects.requireNonNull(resEntity.getBody()).getInputStream();
input = Objects.requireNonNull(resEntity.getBody()).getInputStream();
Date currentDate = new Date();
picSrc = visitPrefix + DateUtils.formatDate(currentDate, "yyyy") + "/" + DateUtils.formatDate(currentDate, "MM") + "/" + DateUtils.formatDate(currentDate, "dd") + "/"
+ UUIDUtil.getUUID32()
@ -38,13 +43,41 @@ public class FileUtil {
if (!parentFile.exists()) {
parentFile.mkdirs();
}
OutputStream out = new FileOutputStream(picFile);
out = new FileOutputStream(picFile);
byte[] b = new byte[4096];
for (int n; (n = input.read(b)) != -1; ) {
out.write(b, 0, n);
}
out.close();
out.flush();
if( ImageIO.read(picFile) == null){
picSrc = "/images/default.gif";
}
}catch (Exception e){
log.error(e.getMessage(),e);
picSrc = "/images/default.gif";
}finally {
if(input != null){
try {
input.close();
} catch (IOException e) {
log.error(e.getMessage(),e);
}finally {
if(out != null){
try {
out.close();
} catch (IOException e) {
log.error(e.getMessage(),e);
}
}
}
}
}
return picSrc;
}

View File

@ -0,0 +1,73 @@
package com.java2nb.novel.core.utils;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
/**
* @author xiongxiaoyang
*/
public class StringUtil {
/**
* 将驼峰式命名的字符串转换为下划线大写方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。</br>
* 例如HelloWorld->HELLO_WORLD
* @param name 转换前的驼峰式命名的字符串
* @return 转换后下划线大写方式命名的字符串
*/
public static String underscoreName(String name) {
StringBuilder result = new StringBuilder();
if (name != null && name.length() > 0) {
// 将第一个字符处理成大写
result.append(name.substring(0, 1).toUpperCase());
// 循环处理其余字符
for (int i = 1; i < name.length(); i++) {
String s = name.substring(i, i + 1);
// 在大写字母前添加下划线
if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
result.append("_");
}
// 其他字符直接转成大写
result.append(s.toUpperCase());
}
}
return result.toString();
}
/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
* 例如HELLO_WORLD->HelloWorld
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String camelName(String name) {
StringBuilder result = new StringBuilder();
// 快速检查
if (name == null || name.isEmpty()) {
// 没必要转换
return "";
} else if (!name.contains("_")) {
// 不含下划线,仅将首字母小写
return name.substring(0, 1).toLowerCase() + name.substring(1);
}
// 用下划线将原始字符串分割
String camels[] = name.split("_");
for (String camel : camels) {
// 跳过原始字符串中开头、结尾的下换线或双重下划线
if (camel.isEmpty()) {
continue;
}
// 处理真正的驼峰片段
if (result.length() == 0) {
// 第一个驼峰片段,全部字母都小写
result.append(camel.toLowerCase());
} else {
// 其他的驼峰片段,首字母大写
result.append(camel.substring(0, 1).toUpperCase());
result.append(camel.substring(1).toLowerCase());
}
}
return result.toString();
}
}

View File

@ -0,0 +1,152 @@
package com.java2nb.novel.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import javax.annotation.Generated;
public class AuthorIncome {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long id;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long userId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long authorId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long bookId;
@JsonFormat(pattern = "yyyy年MM月", timezone = "GMT+8")
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Date incomeMonth;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long preTaxIncome;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long afterTaxIncome;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Byte payStatus;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Byte confirmStatus;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private String detail;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Date createTime;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getId() {
return id;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setId(Long id) {
this.id = id;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getUserId() {
return userId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setUserId(Long userId) {
this.userId = userId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getAuthorId() {
return authorId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setAuthorId(Long authorId) {
this.authorId = authorId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getBookId() {
return bookId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setBookId(Long bookId) {
this.bookId = bookId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Date getIncomeMonth() {
return incomeMonth;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setIncomeMonth(Date incomeMonth) {
this.incomeMonth = incomeMonth;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getPreTaxIncome() {
return preTaxIncome;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setPreTaxIncome(Long preTaxIncome) {
this.preTaxIncome = preTaxIncome;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getAfterTaxIncome() {
return afterTaxIncome;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setAfterTaxIncome(Long afterTaxIncome) {
this.afterTaxIncome = afterTaxIncome;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Byte getPayStatus() {
return payStatus;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setPayStatus(Byte payStatus) {
this.payStatus = payStatus;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Byte getConfirmStatus() {
return confirmStatus;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setConfirmStatus(Byte confirmStatus) {
this.confirmStatus = confirmStatus;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public String getDetail() {
return detail;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setDetail(String detail) {
this.detail = detail == null ? null : detail.trim();
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Date getCreateTime() {
return createTime;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

View File

@ -0,0 +1,126 @@
package com.java2nb.novel.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import javax.annotation.Generated;
public class AuthorIncomeDetail {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long id;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long userId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long authorId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long bookId;
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Date incomeDate;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Integer incomeAccount;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Integer incomeCount;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Integer incomeNumber;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Date createTime;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getId() {
return id;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setId(Long id) {
this.id = id;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getUserId() {
return userId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setUserId(Long userId) {
this.userId = userId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getAuthorId() {
return authorId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setAuthorId(Long authorId) {
this.authorId = authorId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getBookId() {
return bookId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setBookId(Long bookId) {
this.bookId = bookId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Date getIncomeDate() {
return incomeDate;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setIncomeDate(Date incomeDate) {
this.incomeDate = incomeDate;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Integer getIncomeAccount() {
return incomeAccount;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setIncomeAccount(Integer incomeAccount) {
this.incomeAccount = incomeAccount;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Integer getIncomeCount() {
return incomeCount;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setIncomeCount(Integer incomeCount) {
this.incomeCount = incomeCount;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Integer getIncomeNumber() {
return incomeNumber;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setIncomeNumber(Integer incomeNumber) {
this.incomeNumber = incomeNumber;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Date getCreateTime() {
return createTime;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

View File

@ -47,6 +47,9 @@ public class Book implements Serializable{
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Integer commentCount;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Integer yesterdayBuy;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long lastIndexId;
@ -220,6 +223,16 @@ public class Book implements Serializable{
this.commentCount = commentCount;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Integer getYesterdayBuy() {
return yesterdayBuy;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setYesterdayBuy(Integer yesterdayBuy) {
this.yesterdayBuy = yesterdayBuy;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Long getLastIndexId() {
return lastIndexId;

View File

@ -10,9 +10,21 @@ public class CrawlSingleTask {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Integer sourceId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private String sourceName;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private String sourceBookId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Integer catId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private String bookName;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private String authorName;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Byte taskStatus;
@ -42,6 +54,16 @@ public class CrawlSingleTask {
this.sourceId = sourceId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public String getSourceName() {
return sourceName;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setSourceName(String sourceName) {
this.sourceName = sourceName == null ? null : sourceName.trim();
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public String getSourceBookId() {
return sourceBookId;
@ -52,6 +74,36 @@ public class CrawlSingleTask {
this.sourceBookId = sourceBookId == null ? null : sourceBookId.trim();
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Integer getCatId() {
return catId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setCatId(Integer catId) {
this.catId = catId;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public String getBookName() {
return bookName;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setBookName(String bookName) {
this.bookName = bookName == null ? null : bookName.trim();
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public String getAuthorName() {
return authorName;
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public void setAuthorName(String authorName) {
this.authorName = authorName == null ? null : authorName.trim();
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Byte getTaskStatus() {
return taskStatus;

View File

@ -0,0 +1,64 @@
package com.java2nb.novel.mapper;
import java.sql.JDBCType;
import java.util.Date;
import javax.annotation.Generated;
import org.mybatis.dynamic.sql.SqlColumn;
import org.mybatis.dynamic.sql.SqlTable;
public final class AuthorIncomeDetailDynamicSqlSupport {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final AuthorIncomeDetail authorIncomeDetail = new AuthorIncomeDetail();
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> id = authorIncomeDetail.id;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> userId = authorIncomeDetail.userId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> authorId = authorIncomeDetail.authorId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> bookId = authorIncomeDetail.bookId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Date> incomeDate = authorIncomeDetail.incomeDate;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> incomeAccount = authorIncomeDetail.incomeAccount;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> incomeCount = authorIncomeDetail.incomeCount;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> incomeNumber = authorIncomeDetail.incomeNumber;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Date> createTime = authorIncomeDetail.createTime;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final class AuthorIncomeDetail extends SqlTable {
public final SqlColumn<Long> id = column("id", JDBCType.BIGINT);
public final SqlColumn<Long> userId = column("user_id", JDBCType.BIGINT);
public final SqlColumn<Long> authorId = column("author_id", JDBCType.BIGINT);
public final SqlColumn<Long> bookId = column("book_id", JDBCType.BIGINT);
public final SqlColumn<Date> incomeDate = column("income_date", JDBCType.DATE);
public final SqlColumn<Integer> incomeAccount = column("income_account", JDBCType.INTEGER);
public final SqlColumn<Integer> incomeCount = column("income_count", JDBCType.INTEGER);
public final SqlColumn<Integer> incomeNumber = column("income_number", JDBCType.INTEGER);
public final SqlColumn<Date> createTime = column("create_time", JDBCType.TIMESTAMP);
public AuthorIncomeDetail() {
super("author_income_detail");
}
}
}

View File

@ -0,0 +1,222 @@
package com.java2nb.novel.mapper;
import static com.java2nb.novel.mapper.AuthorIncomeDetailDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;
import com.java2nb.novel.entity.AuthorIncomeDetail;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
@Mapper
public interface AuthorIncomeDetailMapper {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
BasicColumn[] selectList = BasicColumn.columnList(id, userId, authorId, bookId, incomeDate, incomeAccount, incomeCount, incomeNumber, createTime);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type=SqlProviderAdapter.class, method="select")
long count(SelectStatementProvider selectStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@DeleteProvider(type=SqlProviderAdapter.class, method="delete")
int delete(DeleteStatementProvider deleteStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@InsertProvider(type=SqlProviderAdapter.class, method="insert")
int insert(InsertStatementProvider<AuthorIncomeDetail> insertStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
int insertMultiple(MultiRowInsertStatementProvider<AuthorIncomeDetail> multipleInsertStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type=SqlProviderAdapter.class, method="select")
@ResultMap("AuthorIncomeDetailResult")
Optional<AuthorIncomeDetail> selectOne(SelectStatementProvider selectStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type=SqlProviderAdapter.class, method="select")
@Results(id="AuthorIncomeDetailResult", value = {
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
@Result(column="author_id", property="authorId", jdbcType=JdbcType.BIGINT),
@Result(column="book_id", property="bookId", jdbcType=JdbcType.BIGINT),
@Result(column="income_date", property="incomeDate", jdbcType=JdbcType.DATE),
@Result(column="income_account", property="incomeAccount", jdbcType=JdbcType.INTEGER),
@Result(column="income_count", property="incomeCount", jdbcType=JdbcType.INTEGER),
@Result(column="income_number", property="incomeNumber", jdbcType=JdbcType.INTEGER),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
})
List<AuthorIncomeDetail> selectMany(SelectStatementProvider selectStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@UpdateProvider(type=SqlProviderAdapter.class, method="update")
int update(UpdateStatementProvider updateStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default long count(CountDSLCompleter completer) {
return MyBatis3Utils.countFrom(this::count, authorIncomeDetail, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int delete(DeleteDSLCompleter completer) {
return MyBatis3Utils.deleteFrom(this::delete, authorIncomeDetail, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int deleteByPrimaryKey(Long id_) {
return delete(c ->
c.where(id, isEqualTo(id_))
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int insert(AuthorIncomeDetail record) {
return MyBatis3Utils.insert(this::insert, record, authorIncomeDetail, c ->
c.map(id).toProperty("id")
.map(userId).toProperty("userId")
.map(authorId).toProperty("authorId")
.map(bookId).toProperty("bookId")
.map(incomeDate).toProperty("incomeDate")
.map(incomeAccount).toProperty("incomeAccount")
.map(incomeCount).toProperty("incomeCount")
.map(incomeNumber).toProperty("incomeNumber")
.map(createTime).toProperty("createTime")
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int insertMultiple(Collection<AuthorIncomeDetail> records) {
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, authorIncomeDetail, c ->
c.map(id).toProperty("id")
.map(userId).toProperty("userId")
.map(authorId).toProperty("authorId")
.map(bookId).toProperty("bookId")
.map(incomeDate).toProperty("incomeDate")
.map(incomeAccount).toProperty("incomeAccount")
.map(incomeCount).toProperty("incomeCount")
.map(incomeNumber).toProperty("incomeNumber")
.map(createTime).toProperty("createTime")
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int insertSelective(AuthorIncomeDetail record) {
return MyBatis3Utils.insert(this::insert, record, authorIncomeDetail, c ->
c.map(id).toPropertyWhenPresent("id", record::getId)
.map(userId).toPropertyWhenPresent("userId", record::getUserId)
.map(authorId).toPropertyWhenPresent("authorId", record::getAuthorId)
.map(bookId).toPropertyWhenPresent("bookId", record::getBookId)
.map(incomeDate).toPropertyWhenPresent("incomeDate", record::getIncomeDate)
.map(incomeAccount).toPropertyWhenPresent("incomeAccount", record::getIncomeAccount)
.map(incomeCount).toPropertyWhenPresent("incomeCount", record::getIncomeCount)
.map(incomeNumber).toPropertyWhenPresent("incomeNumber", record::getIncomeNumber)
.map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default Optional<AuthorIncomeDetail> selectOne(SelectDSLCompleter completer) {
return MyBatis3Utils.selectOne(this::selectOne, selectList, authorIncomeDetail, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default List<AuthorIncomeDetail> select(SelectDSLCompleter completer) {
return MyBatis3Utils.selectList(this::selectMany, selectList, authorIncomeDetail, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default List<AuthorIncomeDetail> selectDistinct(SelectDSLCompleter completer) {
return MyBatis3Utils.selectDistinct(this::selectMany, selectList, authorIncomeDetail, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default Optional<AuthorIncomeDetail> selectByPrimaryKey(Long id_) {
return selectOne(c ->
c.where(id, isEqualTo(id_))
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int update(UpdateDSLCompleter completer) {
return MyBatis3Utils.update(this::update, authorIncomeDetail, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
static UpdateDSL<UpdateModel> updateAllColumns(AuthorIncomeDetail record, UpdateDSL<UpdateModel> dsl) {
return dsl.set(id).equalTo(record::getId)
.set(userId).equalTo(record::getUserId)
.set(authorId).equalTo(record::getAuthorId)
.set(bookId).equalTo(record::getBookId)
.set(incomeDate).equalTo(record::getIncomeDate)
.set(incomeAccount).equalTo(record::getIncomeAccount)
.set(incomeCount).equalTo(record::getIncomeCount)
.set(incomeNumber).equalTo(record::getIncomeNumber)
.set(createTime).equalTo(record::getCreateTime);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
static UpdateDSL<UpdateModel> updateSelectiveColumns(AuthorIncomeDetail record, UpdateDSL<UpdateModel> dsl) {
return dsl.set(id).equalToWhenPresent(record::getId)
.set(userId).equalToWhenPresent(record::getUserId)
.set(authorId).equalToWhenPresent(record::getAuthorId)
.set(bookId).equalToWhenPresent(record::getBookId)
.set(incomeDate).equalToWhenPresent(record::getIncomeDate)
.set(incomeAccount).equalToWhenPresent(record::getIncomeAccount)
.set(incomeCount).equalToWhenPresent(record::getIncomeCount)
.set(incomeNumber).equalToWhenPresent(record::getIncomeNumber)
.set(createTime).equalToWhenPresent(record::getCreateTime);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int updateByPrimaryKey(AuthorIncomeDetail record) {
return update(c ->
c.set(userId).equalTo(record::getUserId)
.set(authorId).equalTo(record::getAuthorId)
.set(bookId).equalTo(record::getBookId)
.set(incomeDate).equalTo(record::getIncomeDate)
.set(incomeAccount).equalTo(record::getIncomeAccount)
.set(incomeCount).equalTo(record::getIncomeCount)
.set(incomeNumber).equalTo(record::getIncomeNumber)
.set(createTime).equalTo(record::getCreateTime)
.where(id, isEqualTo(record::getId))
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int updateByPrimaryKeySelective(AuthorIncomeDetail record) {
return update(c ->
c.set(userId).equalToWhenPresent(record::getUserId)
.set(authorId).equalToWhenPresent(record::getAuthorId)
.set(bookId).equalToWhenPresent(record::getBookId)
.set(incomeDate).equalToWhenPresent(record::getIncomeDate)
.set(incomeAccount).equalToWhenPresent(record::getIncomeAccount)
.set(incomeCount).equalToWhenPresent(record::getIncomeCount)
.set(incomeNumber).equalToWhenPresent(record::getIncomeNumber)
.set(createTime).equalToWhenPresent(record::getCreateTime)
.where(id, isEqualTo(record::getId))
);
}
@SelectProvider(type=SqlProviderAdapter.class, method="select")
@ResultType(value = Long.class)
Long selectStatistic(SelectStatementProvider selectStatement);
}

View File

@ -0,0 +1,74 @@
package com.java2nb.novel.mapper;
import java.sql.JDBCType;
import java.util.Date;
import javax.annotation.Generated;
import org.mybatis.dynamic.sql.SqlColumn;
import org.mybatis.dynamic.sql.SqlTable;
public final class AuthorIncomeDynamicSqlSupport {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final AuthorIncome authorIncome = new AuthorIncome();
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> id = authorIncome.id;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> userId = authorIncome.userId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> authorId = authorIncome.authorId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> bookId = authorIncome.bookId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Date> incomeMonth = authorIncome.incomeMonth;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> preTaxIncome = authorIncome.preTaxIncome;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> afterTaxIncome = authorIncome.afterTaxIncome;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Byte> payStatus = authorIncome.payStatus;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Byte> confirmStatus = authorIncome.confirmStatus;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<String> detail = authorIncome.detail;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Date> createTime = authorIncome.createTime;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final class AuthorIncome extends SqlTable {
public final SqlColumn<Long> id = column("id", JDBCType.BIGINT);
public final SqlColumn<Long> userId = column("user_id", JDBCType.BIGINT);
public final SqlColumn<Long> authorId = column("author_id", JDBCType.BIGINT);
public final SqlColumn<Long> bookId = column("book_id", JDBCType.BIGINT);
public final SqlColumn<Date> incomeMonth = column("income_month", JDBCType.DATE);
public final SqlColumn<Long> preTaxIncome = column("pre_tax_income", JDBCType.BIGINT);
public final SqlColumn<Long> afterTaxIncome = column("after_tax_income", JDBCType.BIGINT);
public final SqlColumn<Byte> payStatus = column("pay_status", JDBCType.TINYINT);
public final SqlColumn<Byte> confirmStatus = column("confirm_status", JDBCType.TINYINT);
public final SqlColumn<String> detail = column("detail", JDBCType.VARCHAR);
public final SqlColumn<Date> createTime = column("create_time", JDBCType.TIMESTAMP);
public AuthorIncome() {
super("author_income");
}
}
}

View File

@ -0,0 +1,240 @@
package com.java2nb.novel.mapper;
import static com.java2nb.novel.mapper.AuthorIncomeDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;
import com.java2nb.novel.entity.AuthorIncome;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
@Mapper
public interface AuthorIncomeMapper {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
BasicColumn[] selectList = BasicColumn.columnList(id, userId, authorId, bookId, incomeMonth, preTaxIncome, afterTaxIncome, payStatus, confirmStatus, detail, createTime);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type=SqlProviderAdapter.class, method="select")
long count(SelectStatementProvider selectStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@DeleteProvider(type=SqlProviderAdapter.class, method="delete")
int delete(DeleteStatementProvider deleteStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@InsertProvider(type=SqlProviderAdapter.class, method="insert")
int insert(InsertStatementProvider<AuthorIncome> insertStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
int insertMultiple(MultiRowInsertStatementProvider<AuthorIncome> multipleInsertStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type=SqlProviderAdapter.class, method="select")
@ResultMap("AuthorIncomeResult")
Optional<AuthorIncome> selectOne(SelectStatementProvider selectStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type=SqlProviderAdapter.class, method="select")
@Results(id="AuthorIncomeResult", value = {
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
@Result(column="author_id", property="authorId", jdbcType=JdbcType.BIGINT),
@Result(column="book_id", property="bookId", jdbcType=JdbcType.BIGINT),
@Result(column="income_month", property="incomeMonth", jdbcType=JdbcType.DATE),
@Result(column="pre_tax_income", property="preTaxIncome", jdbcType=JdbcType.BIGINT),
@Result(column="after_tax_income", property="afterTaxIncome", jdbcType=JdbcType.BIGINT),
@Result(column="pay_status", property="payStatus", jdbcType=JdbcType.TINYINT),
@Result(column="confirm_status", property="confirmStatus", jdbcType=JdbcType.TINYINT),
@Result(column="detail", property="detail", jdbcType=JdbcType.VARCHAR),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
})
List<AuthorIncome> selectMany(SelectStatementProvider selectStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@UpdateProvider(type=SqlProviderAdapter.class, method="update")
int update(UpdateStatementProvider updateStatement);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default long count(CountDSLCompleter completer) {
return MyBatis3Utils.countFrom(this::count, authorIncome, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int delete(DeleteDSLCompleter completer) {
return MyBatis3Utils.deleteFrom(this::delete, authorIncome, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int deleteByPrimaryKey(Long id_) {
return delete(c ->
c.where(id, isEqualTo(id_))
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int insert(AuthorIncome record) {
return MyBatis3Utils.insert(this::insert, record, authorIncome, c ->
c.map(id).toProperty("id")
.map(userId).toProperty("userId")
.map(authorId).toProperty("authorId")
.map(bookId).toProperty("bookId")
.map(incomeMonth).toProperty("incomeMonth")
.map(preTaxIncome).toProperty("preTaxIncome")
.map(afterTaxIncome).toProperty("afterTaxIncome")
.map(payStatus).toProperty("payStatus")
.map(confirmStatus).toProperty("confirmStatus")
.map(detail).toProperty("detail")
.map(createTime).toProperty("createTime")
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int insertMultiple(Collection<AuthorIncome> records) {
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, authorIncome, c ->
c.map(id).toProperty("id")
.map(userId).toProperty("userId")
.map(authorId).toProperty("authorId")
.map(bookId).toProperty("bookId")
.map(incomeMonth).toProperty("incomeMonth")
.map(preTaxIncome).toProperty("preTaxIncome")
.map(afterTaxIncome).toProperty("afterTaxIncome")
.map(payStatus).toProperty("payStatus")
.map(confirmStatus).toProperty("confirmStatus")
.map(detail).toProperty("detail")
.map(createTime).toProperty("createTime")
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int insertSelective(AuthorIncome record) {
return MyBatis3Utils.insert(this::insert, record, authorIncome, c ->
c.map(id).toPropertyWhenPresent("id", record::getId)
.map(userId).toPropertyWhenPresent("userId", record::getUserId)
.map(authorId).toPropertyWhenPresent("authorId", record::getAuthorId)
.map(bookId).toPropertyWhenPresent("bookId", record::getBookId)
.map(incomeMonth).toPropertyWhenPresent("incomeMonth", record::getIncomeMonth)
.map(preTaxIncome).toPropertyWhenPresent("preTaxIncome", record::getPreTaxIncome)
.map(afterTaxIncome).toPropertyWhenPresent("afterTaxIncome", record::getAfterTaxIncome)
.map(payStatus).toPropertyWhenPresent("payStatus", record::getPayStatus)
.map(confirmStatus).toPropertyWhenPresent("confirmStatus", record::getConfirmStatus)
.map(detail).toPropertyWhenPresent("detail", record::getDetail)
.map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default Optional<AuthorIncome> selectOne(SelectDSLCompleter completer) {
return MyBatis3Utils.selectOne(this::selectOne, selectList, authorIncome, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default List<AuthorIncome> select(SelectDSLCompleter completer) {
return MyBatis3Utils.selectList(this::selectMany, selectList, authorIncome, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default List<AuthorIncome> selectDistinct(SelectDSLCompleter completer) {
return MyBatis3Utils.selectDistinct(this::selectMany, selectList, authorIncome, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default Optional<AuthorIncome> selectByPrimaryKey(Long id_) {
return selectOne(c ->
c.where(id, isEqualTo(id_))
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int update(UpdateDSLCompleter completer) {
return MyBatis3Utils.update(this::update, authorIncome, completer);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
static UpdateDSL<UpdateModel> updateAllColumns(AuthorIncome record, UpdateDSL<UpdateModel> dsl) {
return dsl.set(id).equalTo(record::getId)
.set(userId).equalTo(record::getUserId)
.set(authorId).equalTo(record::getAuthorId)
.set(bookId).equalTo(record::getBookId)
.set(incomeMonth).equalTo(record::getIncomeMonth)
.set(preTaxIncome).equalTo(record::getPreTaxIncome)
.set(afterTaxIncome).equalTo(record::getAfterTaxIncome)
.set(payStatus).equalTo(record::getPayStatus)
.set(confirmStatus).equalTo(record::getConfirmStatus)
.set(detail).equalTo(record::getDetail)
.set(createTime).equalTo(record::getCreateTime);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
static UpdateDSL<UpdateModel> updateSelectiveColumns(AuthorIncome record, UpdateDSL<UpdateModel> dsl) {
return dsl.set(id).equalToWhenPresent(record::getId)
.set(userId).equalToWhenPresent(record::getUserId)
.set(authorId).equalToWhenPresent(record::getAuthorId)
.set(bookId).equalToWhenPresent(record::getBookId)
.set(incomeMonth).equalToWhenPresent(record::getIncomeMonth)
.set(preTaxIncome).equalToWhenPresent(record::getPreTaxIncome)
.set(afterTaxIncome).equalToWhenPresent(record::getAfterTaxIncome)
.set(payStatus).equalToWhenPresent(record::getPayStatus)
.set(confirmStatus).equalToWhenPresent(record::getConfirmStatus)
.set(detail).equalToWhenPresent(record::getDetail)
.set(createTime).equalToWhenPresent(record::getCreateTime);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int updateByPrimaryKey(AuthorIncome record) {
return update(c ->
c.set(userId).equalTo(record::getUserId)
.set(authorId).equalTo(record::getAuthorId)
.set(bookId).equalTo(record::getBookId)
.set(incomeMonth).equalTo(record::getIncomeMonth)
.set(preTaxIncome).equalTo(record::getPreTaxIncome)
.set(afterTaxIncome).equalTo(record::getAfterTaxIncome)
.set(payStatus).equalTo(record::getPayStatus)
.set(confirmStatus).equalTo(record::getConfirmStatus)
.set(detail).equalTo(record::getDetail)
.set(createTime).equalTo(record::getCreateTime)
.where(id, isEqualTo(record::getId))
);
}
@Generated("org.mybatis.generator.api.MyBatisGenerator")
default int updateByPrimaryKeySelective(AuthorIncome record) {
return update(c ->
c.set(userId).equalToWhenPresent(record::getUserId)
.set(authorId).equalToWhenPresent(record::getAuthorId)
.set(bookId).equalToWhenPresent(record::getBookId)
.set(incomeMonth).equalToWhenPresent(record::getIncomeMonth)
.set(preTaxIncome).equalToWhenPresent(record::getPreTaxIncome)
.set(afterTaxIncome).equalToWhenPresent(record::getAfterTaxIncome)
.set(payStatus).equalToWhenPresent(record::getPayStatus)
.set(confirmStatus).equalToWhenPresent(record::getConfirmStatus)
.set(detail).equalToWhenPresent(record::getDetail)
.set(createTime).equalToWhenPresent(record::getCreateTime)
.where(id, isEqualTo(record::getId))
);
}
}

View File

@ -24,7 +24,7 @@ public final class BookContentDynamicSqlSupport {
public final SqlColumn<Long> indexId = column("index_id", JDBCType.BIGINT);
public final SqlColumn<String> content = column("content", JDBCType.LONGVARCHAR);
public final SqlColumn<String> content = column("content", JDBCType.VARCHAR);
public BookContent() {
super("book_content");

View File

@ -63,7 +63,7 @@ public interface BookContentMapper {
@Results(id="BookContentResult", value = {
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="index_id", property="indexId", jdbcType=JdbcType.BIGINT),
@Result(column="content", property="content", jdbcType=JdbcType.LONGVARCHAR)
@Result(column="content", property="content", jdbcType=JdbcType.VARCHAR)
})
List<BookContent> selectMany(SelectStatementProvider selectStatement);

View File

@ -52,6 +52,9 @@ public final class BookDynamicSqlSupport {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> commentCount = book.commentCount;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> yesterdayBuy = book.yesterdayBuy;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Long> lastIndexId = book.lastIndexId;
@ -115,6 +118,8 @@ public final class BookDynamicSqlSupport {
public final SqlColumn<Integer> commentCount = column("comment_count", JDBCType.INTEGER);
public final SqlColumn<Integer> yesterdayBuy = column("yesterday_buy", JDBCType.INTEGER);
public final SqlColumn<Long> lastIndexId = column("last_index_id", JDBCType.BIGINT);
public final SqlColumn<String> lastIndexName = column("last_index_name", JDBCType.VARCHAR);

View File

@ -4,10 +4,12 @@ import static com.java2nb.novel.mapper.BookDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;
import com.java2nb.novel.entity.Book;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
@ -35,7 +37,7 @@ import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
@Mapper
public interface BookMapper {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
BasicColumn[] selectList = BasicColumn.columnList(id, workDirection, catId, catName, picUrl, bookName, authorId, authorName, bookDesc, score, bookStatus, visitCount, wordCount, commentCount, lastIndexId, lastIndexName, lastIndexUpdateTime, isVip, status, updateTime, createTime, crawlSourceId, crawlBookId, crawlLastTime, crawlIsStop);
BasicColumn[] selectList = BasicColumn.columnList(id, workDirection, catId, catName, picUrl, bookName, authorId, authorName, bookDesc, score, bookStatus, visitCount, wordCount, commentCount, yesterdayBuy, lastIndexId, lastIndexName, lastIndexUpdateTime, isVip, status, updateTime, createTime, crawlSourceId, crawlBookId, crawlLastTime, crawlIsStop);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type = SqlProviderAdapter.class, method = "select")
@ -75,6 +77,7 @@ public interface BookMapper {
@Result(column = "visit_count", property = "visitCount", jdbcType = JdbcType.BIGINT),
@Result(column = "word_count", property = "wordCount", jdbcType = JdbcType.INTEGER),
@Result(column = "comment_count", property = "commentCount", jdbcType = JdbcType.INTEGER),
@Result(column="yesterday_buy", property="yesterdayBuy", jdbcType=JdbcType.INTEGER),
@Result(column = "last_index_id", property = "lastIndexId", jdbcType = JdbcType.BIGINT),
@Result(column = "last_index_name", property = "lastIndexName", jdbcType = JdbcType.VARCHAR),
@Result(column = "last_index_update_time", property = "lastIndexUpdateTime", jdbcType = JdbcType.TIMESTAMP),
@ -127,6 +130,7 @@ public interface BookMapper {
.map(visitCount).toProperty("visitCount")
.map(wordCount).toProperty("wordCount")
.map(commentCount).toProperty("commentCount")
.map(yesterdayBuy).toProperty("yesterdayBuy")
.map(lastIndexId).toProperty("lastIndexId")
.map(lastIndexName).toProperty("lastIndexName")
.map(lastIndexUpdateTime).toProperty("lastIndexUpdateTime")
@ -158,6 +162,7 @@ public interface BookMapper {
.map(visitCount).toProperty("visitCount")
.map(wordCount).toProperty("wordCount")
.map(commentCount).toProperty("commentCount")
.map(yesterdayBuy).toProperty("yesterdayBuy")
.map(lastIndexId).toProperty("lastIndexId")
.map(lastIndexName).toProperty("lastIndexName")
.map(lastIndexUpdateTime).toProperty("lastIndexUpdateTime")
@ -189,6 +194,7 @@ public interface BookMapper {
.map(visitCount).toPropertyWhenPresent("visitCount", record::getVisitCount)
.map(wordCount).toPropertyWhenPresent("wordCount", record::getWordCount)
.map(commentCount).toPropertyWhenPresent("commentCount", record::getCommentCount)
.map(yesterdayBuy).toPropertyWhenPresent("yesterdayBuy", record::getYesterdayBuy)
.map(lastIndexId).toPropertyWhenPresent("lastIndexId", record::getLastIndexId)
.map(lastIndexName).toPropertyWhenPresent("lastIndexName", record::getLastIndexName)
.map(lastIndexUpdateTime).toPropertyWhenPresent("lastIndexUpdateTime", record::getLastIndexUpdateTime)
@ -246,6 +252,7 @@ public interface BookMapper {
.set(visitCount).equalTo(record::getVisitCount)
.set(wordCount).equalTo(record::getWordCount)
.set(commentCount).equalTo(record::getCommentCount)
.set(yesterdayBuy).equalTo(record::getYesterdayBuy)
.set(lastIndexId).equalTo(record::getLastIndexId)
.set(lastIndexName).equalTo(record::getLastIndexName)
.set(lastIndexUpdateTime).equalTo(record::getLastIndexUpdateTime)
@ -275,6 +282,7 @@ public interface BookMapper {
.set(visitCount).equalToWhenPresent(record::getVisitCount)
.set(wordCount).equalToWhenPresent(record::getWordCount)
.set(commentCount).equalToWhenPresent(record::getCommentCount)
.set(yesterdayBuy).equalToWhenPresent(record::getYesterdayBuy)
.set(lastIndexId).equalToWhenPresent(record::getLastIndexId)
.set(lastIndexName).equalToWhenPresent(record::getLastIndexName)
.set(lastIndexUpdateTime).equalToWhenPresent(record::getLastIndexUpdateTime)
@ -304,6 +312,7 @@ public interface BookMapper {
.set(visitCount).equalTo(record::getVisitCount)
.set(wordCount).equalTo(record::getWordCount)
.set(commentCount).equalTo(record::getCommentCount)
.set(yesterdayBuy).equalTo(record::getYesterdayBuy)
.set(lastIndexId).equalTo(record::getLastIndexId)
.set(lastIndexName).equalTo(record::getLastIndexName)
.set(lastIndexUpdateTime).equalTo(record::getLastIndexUpdateTime)
@ -335,6 +344,7 @@ public interface BookMapper {
.set(visitCount).equalToWhenPresent(record::getVisitCount)
.set(wordCount).equalToWhenPresent(record::getWordCount)
.set(commentCount).equalToWhenPresent(record::getCommentCount)
.set(yesterdayBuy).equalToWhenPresent(record::getYesterdayBuy)
.set(lastIndexId).equalToWhenPresent(record::getLastIndexId)
.set(lastIndexName).equalToWhenPresent(record::getLastIndexName)
.set(lastIndexUpdateTime).equalToWhenPresent(record::getLastIndexUpdateTime)

View File

@ -16,9 +16,21 @@ public final class CrawlSingleTaskDynamicSqlSupport {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> sourceId = crawlSingleTask.sourceId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<String> sourceName = crawlSingleTask.sourceName;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<String> sourceBookId = crawlSingleTask.sourceBookId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Integer> catId = crawlSingleTask.catId;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<String> bookName = crawlSingleTask.bookName;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<String> authorName = crawlSingleTask.authorName;
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn<Byte> taskStatus = crawlSingleTask.taskStatus;
@ -34,8 +46,16 @@ public final class CrawlSingleTaskDynamicSqlSupport {
public final SqlColumn<Integer> sourceId = column("source_id", JDBCType.INTEGER);
public final SqlColumn<String> sourceName = column("source_name", JDBCType.VARCHAR);
public final SqlColumn<String> sourceBookId = column("source_book_id", JDBCType.VARCHAR);
public final SqlColumn<Integer> catId = column("cat_id", JDBCType.INTEGER);
public final SqlColumn<String> bookName = column("book_name", JDBCType.VARCHAR);
public final SqlColumn<String> authorName = column("author_name", JDBCType.VARCHAR);
public final SqlColumn<Byte> taskStatus = column("task_status", JDBCType.TINYINT);
public final SqlColumn<Byte> excCount = column("exc_count", JDBCType.TINYINT);

View File

@ -35,7 +35,7 @@ import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
@Mapper
public interface CrawlSingleTaskMapper {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
BasicColumn[] selectList = BasicColumn.columnList(id, sourceId, sourceBookId, taskStatus, excCount, createTime);
BasicColumn[] selectList = BasicColumn.columnList(id, sourceId, sourceName, sourceBookId, catId, bookName, authorName, taskStatus, excCount, createTime);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type=SqlProviderAdapter.class, method="select")
@ -63,7 +63,11 @@ public interface CrawlSingleTaskMapper {
@Results(id="CrawlSingleTaskResult", value = {
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="source_id", property="sourceId", jdbcType=JdbcType.INTEGER),
@Result(column="source_name", property="sourceName", jdbcType=JdbcType.VARCHAR),
@Result(column="source_book_id", property="sourceBookId", jdbcType=JdbcType.VARCHAR),
@Result(column="cat_id", property="catId", jdbcType=JdbcType.INTEGER),
@Result(column="book_name", property="bookName", jdbcType=JdbcType.VARCHAR),
@Result(column="author_name", property="authorName", jdbcType=JdbcType.VARCHAR),
@Result(column="task_status", property="taskStatus", jdbcType=JdbcType.TINYINT),
@Result(column="exc_count", property="excCount", jdbcType=JdbcType.TINYINT),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
@ -96,7 +100,11 @@ public interface CrawlSingleTaskMapper {
return MyBatis3Utils.insert(this::insert, record, crawlSingleTask, c ->
c.map(id).toProperty("id")
.map(sourceId).toProperty("sourceId")
.map(sourceName).toProperty("sourceName")
.map(sourceBookId).toProperty("sourceBookId")
.map(catId).toProperty("catId")
.map(bookName).toProperty("bookName")
.map(authorName).toProperty("authorName")
.map(taskStatus).toProperty("taskStatus")
.map(excCount).toProperty("excCount")
.map(createTime).toProperty("createTime")
@ -108,7 +116,11 @@ public interface CrawlSingleTaskMapper {
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, crawlSingleTask, c ->
c.map(id).toProperty("id")
.map(sourceId).toProperty("sourceId")
.map(sourceName).toProperty("sourceName")
.map(sourceBookId).toProperty("sourceBookId")
.map(catId).toProperty("catId")
.map(bookName).toProperty("bookName")
.map(authorName).toProperty("authorName")
.map(taskStatus).toProperty("taskStatus")
.map(excCount).toProperty("excCount")
.map(createTime).toProperty("createTime")
@ -120,7 +132,11 @@ public interface CrawlSingleTaskMapper {
return MyBatis3Utils.insert(this::insert, record, crawlSingleTask, c ->
c.map(id).toPropertyWhenPresent("id", record::getId)
.map(sourceId).toPropertyWhenPresent("sourceId", record::getSourceId)
.map(sourceName).toPropertyWhenPresent("sourceName", record::getSourceName)
.map(sourceBookId).toPropertyWhenPresent("sourceBookId", record::getSourceBookId)
.map(catId).toPropertyWhenPresent("catId", record::getCatId)
.map(bookName).toPropertyWhenPresent("bookName", record::getBookName)
.map(authorName).toPropertyWhenPresent("authorName", record::getAuthorName)
.map(taskStatus).toPropertyWhenPresent("taskStatus", record::getTaskStatus)
.map(excCount).toPropertyWhenPresent("excCount", record::getExcCount)
.map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
@ -158,7 +174,11 @@ public interface CrawlSingleTaskMapper {
static UpdateDSL<UpdateModel> updateAllColumns(CrawlSingleTask record, UpdateDSL<UpdateModel> dsl) {
return dsl.set(id).equalTo(record::getId)
.set(sourceId).equalTo(record::getSourceId)
.set(sourceName).equalTo(record::getSourceName)
.set(sourceBookId).equalTo(record::getSourceBookId)
.set(catId).equalTo(record::getCatId)
.set(bookName).equalTo(record::getBookName)
.set(authorName).equalTo(record::getAuthorName)
.set(taskStatus).equalTo(record::getTaskStatus)
.set(excCount).equalTo(record::getExcCount)
.set(createTime).equalTo(record::getCreateTime);
@ -168,7 +188,11 @@ public interface CrawlSingleTaskMapper {
static UpdateDSL<UpdateModel> updateSelectiveColumns(CrawlSingleTask record, UpdateDSL<UpdateModel> dsl) {
return dsl.set(id).equalToWhenPresent(record::getId)
.set(sourceId).equalToWhenPresent(record::getSourceId)
.set(sourceName).equalToWhenPresent(record::getSourceName)
.set(sourceBookId).equalToWhenPresent(record::getSourceBookId)
.set(catId).equalToWhenPresent(record::getCatId)
.set(bookName).equalToWhenPresent(record::getBookName)
.set(authorName).equalToWhenPresent(record::getAuthorName)
.set(taskStatus).equalToWhenPresent(record::getTaskStatus)
.set(excCount).equalToWhenPresent(record::getExcCount)
.set(createTime).equalToWhenPresent(record::getCreateTime);
@ -178,7 +202,11 @@ public interface CrawlSingleTaskMapper {
default int updateByPrimaryKey(CrawlSingleTask record) {
return update(c ->
c.set(sourceId).equalTo(record::getSourceId)
.set(sourceName).equalTo(record::getSourceName)
.set(sourceBookId).equalTo(record::getSourceBookId)
.set(catId).equalTo(record::getCatId)
.set(bookName).equalTo(record::getBookName)
.set(authorName).equalTo(record::getAuthorName)
.set(taskStatus).equalTo(record::getTaskStatus)
.set(excCount).equalTo(record::getExcCount)
.set(createTime).equalTo(record::getCreateTime)
@ -190,7 +218,11 @@ public interface CrawlSingleTaskMapper {
default int updateByPrimaryKeySelective(CrawlSingleTask record) {
return update(c ->
c.set(sourceId).equalToWhenPresent(record::getSourceId)
.set(sourceName).equalToWhenPresent(record::getSourceName)
.set(sourceBookId).equalToWhenPresent(record::getSourceBookId)
.set(catId).equalToWhenPresent(record::getCatId)
.set(bookName).equalToWhenPresent(record::getBookName)
.set(authorName).equalToWhenPresent(record::getAuthorName)
.set(taskStatus).equalToWhenPresent(record::getTaskStatus)
.set(excCount).equalToWhenPresent(record::getExcCount)
.set(createTime).equalToWhenPresent(record::getCreateTime)

View File

@ -8,14 +8,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
@ -229,4 +223,8 @@ public interface UserMapper {
.where(id, isEqualTo(record::getId))
);
}
@SelectProvider(type=SqlProviderAdapter.class, method="select")
@ResultType(value = Integer.class)
Integer selectStatistic(SelectStatementProvider selectStatement);
}

View File

@ -1,19 +1,77 @@
spring:
profiles:
include: [common]
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_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}
pic:
save:
type: 2 #图片保存方式, 1不保存使用网络图片 2本地保存
type: 2 #图片保存方式, 1不保存使用爬取的网络图片 2保存在自己的存储介质
storage: local #存储介质local本地OSS阿里云对象存储fastDfs分布式文件系统
path: /var/pic #图片保存路径

View File

@ -11,6 +11,9 @@ spring:
generator:
write-numbers-as-strings: true
#缓存类型ehcache(默认)redis
cache:
type: ehcache
mybatis:
configuration:

View File

@ -9,7 +9,7 @@
</commentGenerator>
<jdbcConnection
connectionURL="jdbc:mysql://127.0.0.1:3306/novel_plus?tinyInt1isBit=false&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai&amp;nullCatalogMeansCurrent=true"
driverClass="com.mysql.jdbc.Driver" password=""
driverClass="com.mysql.jdbc.Driver" password="test123456"
userId="root" />
<!-- 默认false把JDBC DECIMAL NUMERIC 类型解析为 Integer true时把JDBC DECIMAL
@ -44,7 +44,7 @@
</javaClientGenerator>
<!--生成全部表tableName设为%-->
<table tableName="user_buy_record" domainObjectName="UserBuyRecord"/>
<table tableName="book"/>
<!-- 指定数据库表 -->
<!--<table schema="jly" tableName="job_position" domainObjectName="JobPositionTest"/>-->

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>2.0.2</version>
<version>2.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -25,6 +25,8 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -3,11 +3,12 @@ package com.java2nb.novel.controller;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.core.bean.ResultBean;
import com.java2nb.novel.core.utils.BeanUtil;
import com.java2nb.novel.entity.CrawlSingleTask;
import com.java2nb.novel.entity.CrawlSource;
import com.java2nb.novel.service.CrawlService;
import com.java2nb.novel.vo.CrawlSingleTaskVO;
import com.java2nb.novel.vo.CrawlSourceVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -56,6 +57,38 @@ public class CrawlController {
return ResultBean.ok();
}
/**
* 新增单本采集任务
* */
@PostMapping("addCrawlSingleTask")
public ResultBean addCrawlSingleTask(CrawlSingleTask singleTask){
crawlService.addCrawlSingleTask(singleTask);
return ResultBean.ok();
}
/**
* 单本采集任务分页列表查询
* */
@PostMapping("listCrawlSingleTaskByPage")
public ResultBean listCrawlSingleTaskByPage(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "10") int pageSize){
return ResultBean.ok(new PageInfo<>(BeanUtil.copyList(crawlService.listCrawlSingleTaskByPage(page,pageSize), CrawlSingleTaskVO.class)
));
}
/**
* 删除采集任务
* */
@PostMapping("delCrawlSingleTask")
public ResultBean delCrawlSingleTask(Long id){
crawlService.delCrawlSingleTask(id);
return ResultBean.ok();
}

View File

@ -30,6 +30,8 @@ import static java.util.regex.Pattern.compile;
@Slf4j
public class CrawlParser {
private static IdWorker idWorker = new IdWorker();
public static final Integer BOOK_INDEX_LIST_KEY = 1;
public static final Integer BOOK_CONTENT_LIST_KEY = 2;
@ -94,6 +96,12 @@ public class CrawlParser {
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/>");
//设置书籍简介
book.setBookDesc(desc);
if (StringUtils.isNotBlank(ruleBean.getStatusPatten())) {
@ -173,6 +181,7 @@ public class CrawlParser {
String lastIndexName = null;
while (isFindIndex) {
BookIndex hasIndex = hasIndexs.get(indexNum);
String indexName = indexNameMatch.group(1);
@ -199,7 +208,7 @@ public class CrawlParser {
if(hasIndexs.size() == 0){
//新书入库
//设置目录和章节内容
Long indexId = new IdWorker().nextId();
Long indexId = idWorker.nextId();
lastIndexId = indexId;
lastIndexName = indexName;
bookIndex.setId(indexId);
@ -232,8 +241,6 @@ public class CrawlParser {
}
} else {
break;
}

View File

@ -3,10 +3,7 @@ package com.java2nb.novel.core.listener;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.java2nb.novel.core.crawl.CrawlParser;
import com.java2nb.novel.core.crawl.RuleBean;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.entity.BookContent;
import com.java2nb.novel.entity.BookIndex;
import com.java2nb.novel.entity.CrawlSource;
import com.java2nb.novel.entity.*;
import com.java2nb.novel.service.BookService;
import com.java2nb.novel.service.CrawlService;
import com.java2nb.novel.utils.Constants;
@ -40,9 +37,9 @@ public class StarterListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
log.info("程序启动,开始执行自动更新线程。。。");
for (int i = 0; i < updateThreadCount; i++) {
new Thread(() -> {
log.info("程序启动,开始执行自动更新线程。。。");
while (true) {
try {
//1.查询最新目录更新时间在一个月之内的前100条需要更新的数据
@ -61,7 +58,7 @@ public class StarterListener implements ServletContextListener {
Book book = CrawlParser.parseBook(ruleBean, needUpdateBook.getCrawlBookId());
//这里只做老书更新
book.setId(needUpdateBook.getId());
if(needUpdateBook.getPicUrl()!=null && needUpdateBook.getPicUrl().startsWith(Constants.LOCAL_PIC_PREFIX)) {
if (needUpdateBook.getPicUrl() != null && needUpdateBook.getPicUrl().contains(Constants.LOCAL_PIC_PREFIX)) {
//本地图片则不更新
book.setPicUrl(null);
}
@ -83,6 +80,42 @@ public class StarterListener implements ServletContextListener {
}
}).start();
}
}
new Thread(() -> {
log.info("程序启动,开始执行单本采集任务线程。。。");
while (true) {
CrawlSingleTask task = null;
byte crawlStatus = 0;
try {
//获取采集任务
task = crawlService.getCrawlSingleTask();
if (task != null) {
//查询爬虫规则
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())) {
//采集成功
crawlStatus = 1;
}
}
Thread.sleep(1000 * 60);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
if (task != null) {
crawlService.updateCrawlSingleTask(task, crawlStatus);
}
}
}).start();
}
}

View File

@ -1,6 +1,7 @@
package com.java2nb.novel.service;
import com.java2nb.novel.core.crawl.RuleBean;
import com.java2nb.novel.entity.CrawlSingleTask;
import com.java2nb.novel.entity.CrawlSource;
import java.util.List;
@ -39,6 +40,16 @@ public interface CrawlService {
* */
void updateCrawlSourceStatus(Integer sourceId, Byte sourceStatus);
/**
* 采集并保存小说
* @param catId 分类ID
* @param bookId 小说ID
* @param sourceId 源ID
* @param ruleBean 采集规则\
* @return true:成功false:失败
* */
boolean parseBookAndSave(int catId, RuleBean ruleBean, Integer sourceId, String bookId);
/**
* 根据爬虫状态查询爬虫源集合
* @param sourceStatus 状态0关闭1开启
@ -61,4 +72,37 @@ public interface CrawlService {
* @return 源信息
* */
CrawlSource queryCrawlSource(Integer sourceId);
/**
* 新增单本采集任务
* @param singleTask 任务信息对象
* */
void addCrawlSingleTask(CrawlSingleTask singleTask);
/**
* 单本采集任务分页列表查询
* @param page 当前页码
* @param pageSize 分页大小
* @return 单本采集任务集合
* */
List<CrawlSingleTask> listCrawlSingleTaskByPage(int page, int pageSize);
/**
* 删除采集任务
* @param id 任务ID
* */
void delCrawlSingleTask(Long id);
/**
* 获取采集任务
* @return 采集任务
* */
CrawlSingleTask getCrawlSingleTask();
/**
* 更新单本采集任务
* @param task 采集任务
* @param status 采集状态
* */
void updateCrawlSingleTask(CrawlSingleTask task, Byte status);
}

View File

@ -6,12 +6,12 @@ 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 com.java2nb.novel.core.exception.BusinessException;
import com.java2nb.novel.core.utils.IdWorker;
import com.java2nb.novel.core.utils.SpringUtil;
import com.java2nb.novel.core.utils.ThreadUtil;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.entity.BookContent;
import com.java2nb.novel.entity.BookIndex;
import com.java2nb.novel.entity.*;
import com.java2nb.novel.entity.CrawlSource;
import com.java2nb.novel.mapper.*;
import com.java2nb.novel.service.BookService;
@ -33,8 +33,7 @@ import static com.java2nb.novel.core.utils.HttpUtil.getByHttpClient;
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.crawlBookId;
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.crawlSourceId;
import static com.java2nb.novel.mapper.CrawlSourceDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
import static org.mybatis.dynamic.sql.SqlBuilder.update;
import static org.mybatis.dynamic.sql.SqlBuilder.*;
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
/**
@ -48,6 +47,8 @@ public class CrawlServiceImpl implements CrawlService {
private final CrawlSourceMapper crawlSourceMapper;
private final CrawlSingleTaskMapper crawlSingleTaskMapper;
private final BookService bookService;
@ -140,6 +141,62 @@ public class CrawlServiceImpl implements CrawlService {
return crawlSourceMapper.selectMany(render).get(0);
}
@Override
public void addCrawlSingleTask(CrawlSingleTask singleTask) {
if(bookService.queryIsExistByBookNameAndAuthorName(singleTask.getBookName(),singleTask.getAuthorName())){
throw new BusinessException(ResponseStatus.BOOK_EXISTS);
}
singleTask.setCreateTime(new Date());
crawlSingleTaskMapper.insertSelective(singleTask);
}
@Override
public List<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);
return crawlSingleTaskMapper.selectMany(render);
}
@Override
public void delCrawlSingleTask(Long id) {
crawlSingleTaskMapper.deleteByPrimaryKey(id);
}
@Override
public CrawlSingleTask getCrawlSingleTask() {
List<CrawlSingleTask> list = crawlSingleTaskMapper.selectMany(select(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask.allColumns())
.from(CrawlSingleTaskDynamicSqlSupport.crawlSingleTask)
.where(CrawlSingleTaskDynamicSqlSupport.taskStatus,isEqualTo((byte)2))
.orderBy(CrawlSingleTaskDynamicSqlSupport.createTime)
.limit(1)
.build()
.render(RenderingStrategies.MYBATIS3));
return list.size() > 0 ? list.get(0) : null;
}
@Override
public void updateCrawlSingleTask(CrawlSingleTask task, Byte status) {
byte excCount = task.getExcCount();
excCount+=1;
task.setExcCount(excCount);
if(status == 1 || excCount == 5){
//当采集成功或者采集次数等于5则更新采集最终状态并停止采集
task.setTaskStatus(status);
}
crawlSingleTaskMapper.updateByPrimaryKeySelective(task);
}
/**
* 解析分类列表
*/
@ -167,36 +224,13 @@ public class CrawlServiceImpl implements CrawlService {
boolean isFindBookId = bookIdMatcher.find();
while (isFindBookId) {
try {
if(Thread.currentThread().isInterrupted()){
return;
}
String bookId = bookIdMatcher.group(1);
Book book = CrawlParser.parseBook(ruleBean, bookId);
//这里只做新书入库,查询是否存在这本书
Book existBook = bookService.queryBookByBookNameAndAuthorName(book.getBookName(), book.getAuthorName());
//如果该小说不存在则可以解析入库但是标记该小说正在入库30分钟之后才允许再次入库
if (existBook == null) {
//没有该书,可以入库
book.setCatId(catId);
//根据分类ID查询分类
book.setCatName(bookService.queryCatNameByCatId(catId));
if (catId == 7) {
//女频
book.setWorkDirection((byte) 1);
} else {
//男频
book.setWorkDirection((byte) 0);
}
book.setCrawlBookId(bookId);
book.setCrawlSourceId(sourceId);
book.setCrawlLastTime(new Date());
book.setId(new IdWorker().nextId());
//解析章节目录
Map<Integer, List> indexAndContentList = CrawlParser.parseBookIndexAndContent(bookId, book, ruleBean, new HashMap<>(0));
bookService.saveBookAndIndexAndContent(book, (List<BookIndex>) indexAndContentList.get(CrawlParser.BOOK_INDEX_LIST_KEY), (List<BookContent>) indexAndContentList.get(CrawlParser.BOOK_CONTENT_LIST_KEY));
} else {
//只更新书籍的爬虫相关字段
bookService.updateCrawlProperties(existBook.getId(), sourceId, bookId);
}
parseBookAndSave(catId, ruleBean, sourceId, bookId);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
@ -227,6 +261,43 @@ public class CrawlServiceImpl implements CrawlService {
}
@Override
public boolean parseBookAndSave(int catId, RuleBean ruleBean, Integer sourceId, String bookId) {
Book book = CrawlParser.parseBook(ruleBean, bookId);
if(book.getBookName() == null || book.getAuthorName() == null){
return false;
}
//这里只做新书入库,查询是否存在这本书
Book existBook = bookService.queryBookByBookNameAndAuthorName(book.getBookName(), book.getAuthorName());
//如果该小说不存在则可以解析入库但是标记该小说正在入库30分钟之后才允许再次入库
if (existBook == null) {
//没有该书,可以入库
book.setCatId(catId);
//根据分类ID查询分类
book.setCatName(bookService.queryCatNameByCatId(catId));
if (catId == 7) {
//女频
book.setWorkDirection((byte) 1);
} else {
//男频
book.setWorkDirection((byte) 0);
}
book.setCrawlBookId(bookId);
book.setCrawlSourceId(sourceId);
book.setCrawlLastTime(new Date());
book.setId(new IdWorker().nextId());
//解析章节目录
Map<Integer, List> indexAndContentList = CrawlParser.parseBookIndexAndContent(bookId, book, ruleBean, new HashMap<>(0));
bookService.saveBookAndIndexAndContent(book, (List<BookIndex>) indexAndContentList.get(CrawlParser.BOOK_INDEX_LIST_KEY), (List<BookContent>) indexAndContentList.get(CrawlParser.BOOK_CONTENT_LIST_KEY));
} else {
//只更新书籍的爬虫相关字段
bookService.updateCrawlProperties(existBook.getId(), sourceId, bookId);
}
return true;
}
@Override
public void updateCrawlSourceStatus(Integer sourceId, Byte sourceStatus) {
CrawlSource source = new CrawlSource();

View File

@ -0,0 +1,26 @@
package com.java2nb.novel.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.java2nb.novel.entity.CrawlSingleTask;
import com.java2nb.novel.entity.CrawlSource;
import lombok.Data;
import java.util.Date;
/**
* @author Administrator
*/
@Data
public class CrawlSingleTaskVO extends CrawlSingleTask {
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm")
private Date createTime;
@Override
public String toString() {
return super.toString();
}
}

View File

@ -6,7 +6,7 @@
<select id="queryNeedUpdateBook" resultType="com.java2nb.novel.entity.Book">
select id,crawl_source_id,crawl_book_id,crawl_last_time,pic_url
from book where last_index_update_time > #{startDate}
from book where last_index_update_time > #{startDate} and crawl_source_id is not null
order by crawl_last_time
limit ${limit}

View File

@ -10,7 +10,7 @@
.user_l .log_list { width:350px }
.user_l .s_input { margin-bottom:25px; font-size:14px }
.s_input { width:348px; height:30px; line-height:38px\9; vertical-align:middle; border:1px solid #ddd; border-radius:2px }
.icon_name, .icon_key, .icon_code { width:312px; padding-left:36px; background:url(../images/icon_user.png) no-repeat 13px 13px }
.icon_name, .icon_key, .icon_code { width:312px; padding-left:36px}
.icon_key { background-position: 13px -51px }
.icon_code { background-position: 13px -117px; width:200px; float:left }
.code_pic { height:38px; float:right }
@ -37,7 +37,7 @@
.fast_tit .title { background:#fff; font-size:16px; padding:3px 14px; position:relative; display:inline-block; z-index:999 }
/*userinfo*/
.my_l { width:198px; float:left; font-size: 13px; padding-top: 20px; }
.my_l li a { display:block; height:42px; line-height:42px; padding-left:62px; border-left:4px solid #fff; background:url(../images/icon_user.png) no-repeat; margin-bottom:5px; color: #666 }
.my_l li a { display:block; height:42px; line-height:42px; padding-left:62px; border-left:4px solid #fff; margin-bottom:5px; color: #666 }
.my_l li .on { background-color:#fafafa; border-left:2px solid #f80; color:#000; border-radius: 0 2px 2px 0 }
.my_l .link_1 { background-position:32px -188px }
.my_l .link_2 { background-position:32px -230px }

View File

@ -0,0 +1,188 @@
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<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"/>
</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>
</div>
</div>
<div class="main box_center cf">
<div class="userBox cf">
<div class="my_l">
<ul class="log_list">
<li><a class="link_1" href="/">爬虫源管理</a></li>
<li><a class="link_1 on" href="/crawl/crawlSingleTask_list.html">单本采集管理</a></li>
<!--<li><a class="link_1 " href="/user/userinfo.html">批量小说爬取</a></li>
<li><a class="link_4 " href="/user/favorites.html">单本小说爬取</a></li>-->
</ul>
</div>
<div class="my_r">
<div class="my_bookshelf">
<div class="userBox cf">
<form method="post" action="./register.html" id="form2">
<div class="user_l">
<div></div>
<h3>采集信息填写示例均为笔趣阁http://www.mcmssc.com</h3>
<ul class="log_list">
<li><span id="LabErr"></span></li>
<input type="hidden" id="sourceName" class="s_input icon_name" >
<b>采集源:</b>
<li><select id="sourceId" class="s_input icon_key">
</select></li>
<b>采集分类:</b>
<li><select id="catId" class="s_input icon_key">
<option value="1">玄幻奇幻</option>
<option value="2">武侠仙侠</option>
<option value="3">都市言情</option>
<option value="4">历史军事</option>
<option value="5">科幻灵异</option>
<option value="6">网游竞技</option>
<option value="7">女生频道</option>
</select>
</li>
示例:<b>73_73911</b>
<li><input type="text" id="sourceBookId" class="s_input icon_key"
placeholder="采集的源站小说ID"/></li>
示例:<b>苏厨</b>
<li><input type="text" id="bookName" class="s_input icon_key"
placeholder="采集的小说名"/></li>
示例:<b>二子从周</b>
<li><input type="text" id="authorName" class="s_input icon_key"
placeholder="采集的小说作者名"/></li>
<!--示例:<b>https://m.xdingdiann.com/sort/0/1.html</b>
<li><input type="text" id="updateBookListUrl" class="s_input icon_key"
placeholder="小说更新列表url"></li>-->
<li><input type="button" onclick="addCrawlSingleTask()" name="btnRegister" value="提交"
id="btnRegister" class="btn_red"></li>
</ul>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="/javascript/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="/layui/layui.all.js" type="text/javascript"></script>
<script src="/javascript/header.js" type="text/javascript"></script>
<script src="/javascript/user.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "/crawl/listCrawlByPage",
data: {'curr':1,'limit':100},
dataType: "json",
success: function (data) {
if (data.code == 200) {
var crawlSourceList = data.data.list;
if (crawlSourceList.length > 0) {
var crawlSourceListHtml = "";
for(var i=0;i<crawlSourceList.length;i++){
var crawlSource = crawlSourceList[i];
crawlSourceListHtml+=("<option value=\""+crawlSource.id+"\">"+crawlSource.sourceName+"</option>");
}
$("#sourceId").html(crawlSourceListHtml);
}
} else if (data.code == 1001) {
//未登录
location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);
}else {
layer.alert(data.msg);
}
},
error: function () {
layer.alert('网络异常');
}
})
});
function addCrawlSingleTask() {
var sourceId = $("#sourceId").find("option:selected").val();
var catId = $("#catId").find("option:selected").val();
var sourceName = $("#sourceId").find("option:selected").html();
var sourceBookId = $("#sourceBookId").val();
if (!sourceBookId){
layer.alert("采集的源站小说ID不能为空");
return;
}
var bookName = $("#bookName").val();
if (!bookName){
layer.alert("采集的小说名不能为空");
return;
}
var authorName = $("#authorName").val();
if (!authorName){
layer.alert("采集的小说作者名不能为空");
return;
}
$.ajax({
type: "POST",
url: "/crawl/addCrawlSingleTask",
data: {'sourceId': sourceId, 'sourceName': sourceName,'catId':catId,'sourceBookId' : sourceBookId,'bookName':bookName,'authorName':authorName},
dataType: "json",
success: function (data) {
if (data.code == 200) {
window.location.href = '/crawl/crawlSingleTask_list.html';
} else {
layer.alert(data.msg);
}
},
error: function () {
layer.alert('网络异常');
}
})
}
</script>
</html>

View File

@ -0,0 +1,230 @@
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<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"/>
</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>
</div>
</div>
<div class="main box_center cf">
<div class="userBox cf">
<div class="my_l">
<ul class="log_list">
<li><a class="link_1" href="/">爬虫源管理</a></li>
<li><a class="link_1 on" href="/crawl/crawlSingleTask_list.html">单本采集管理</a></li>
<!-- <li><a class="link_1 " href="/user/userinfo.html">批量小说爬取</a></li>
<li><a class="link_4 " href="/user/favorites.html">单本小说爬取</a></li>-->
</ul>
</div>
<div class="my_r">
<div class="my_bookshelf">
<div class="title cf">
<h2 class="fl">单本采集任务列表</h2>
<div class="fr"><a href="/crawl/crawlSingleTask_add.html" class="btn_red">增加单本采集任务</a></div>
</div>
<div id="divData" class="updateTable">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="style">
序号
</th>
<th class="name">
采集小说名
</th>
<th class="name">
采集小说作者名
</th>
<th class="goread">
采集次数
</th>
<th class="goread">
状态
</th>
<th class="name">
创建时间
</th>
<th class="goread">
操作
</th>
</tr>
</thead>
<tbody id="crawlSourceList">
</tbody>
</table>
<div class="pageBox cf" id="shellPage">
</div>
</div>
<!--<div id="divData" class="updateTable">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="name">
爬虫源(已开启的爬虫源)
</th>
<th class="chapter">
成功爬取数量websocket实现
</th>
<th class="time">
目标爬取数量
</th>
<th class="goread">
状态(正在运行,已停止)(一次只能运行一个爬虫源)
</th>
<th class="goread">
操作(启动,停止)
</th>
</tr>
</thead>
<tbody id="bookShelfList">
</tbody>
</table>
<div class="pageBox cf" id="shellPage">
</div>
</div>-->
</div>
</div>
</div>
</div>
</body>
<script src="/javascript/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="/layui/layui.all.js" type="text/javascript"></script>
<script src="/javascript/header.js" type="text/javascript"></script>
<script src="/javascript/user.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
search(1, 10);
function search(curr, limit) {
$.ajax({
type: "POST",
url: "/crawl/listCrawlSingleTaskByPage",
data: {'curr': curr, 'limit': limit},
dataType: "json",
success: function (data) {
if (data.code == 200) {
var crawlSourceList = data.data.list;
if (crawlSourceList.length > 0) {
var crawlSourceListHtml = "";
for (var i = 0; i < crawlSourceList.length; i++) {
var crawlSource = crawlSourceList[i];
crawlSourceListHtml += (" <tr class=\"book_list\" vals=\"291\">\n" +
" <td class=\"style bookclass\">\n" +
" [" + (i + 1) + "]\n" +
" </td>\n" +
" <td class=\"name\">\n" +
" " + crawlSource.bookName + "\n" +
" </td>\n" +
" <td class=\"name\">\n" +
" " + crawlSource.authorName + "\n" +
" </td>\n" +
" <td class=\"goread\">\n" +
" " + crawlSource.excCount + "\n" +
" </td>\n" +
" <td class=\"goread\">\n" +
" " + (crawlSource.taskStatus == 0 ? '采集失败' : (crawlSource.taskStatus == 1 ? '采集成功' : (crawlSource.excCount>0?'采集中':'排队中'))) + "\n" +
" </td>\n" +
" <td class=\"name\" valsc=\"291|2037554|1\">"
+ crawlSource.createTime + "</td>\n" +
" <td class=\"goread\" id='opt" + crawlSource.id + "'><a href='javascript:del(" + crawlSource.id + ")'>删除 </a></td> </tr>");
}
$("#crawlSourceList").html(crawlSourceListHtml);
layui.use('laypage', function () {
var laypage = layui.laypage;
//执行一个laypage实例
laypage.render({
elem: 'shellPage' //注意,这里的 test1 是 ID不用加 # 号
, count: data.data.total //数据总数,从服务端得到,
, curr: data.data.pageNum
, limit: data.data.pageSize
, jump: function (obj, first) {
//obj包含了当前分页的所有参数比如
console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
console.log(obj.limit); //得到每页显示的条数
//首次不执行
if (!first) {
search(obj.curr, obj.limit);
} else {
}
}
});
});
}
} else {
layer.alert(data.msg);
}
},
error: function () {
layer.alert('网络异常');
}
})
}
function del(id) {
$.ajax({
type: "POST",
url: "/crawl/delCrawlSingleTask",
data: {'id': id},
dataType: "json",
success: function (data) {
if (data.code == 200) {
location.reload();
} else {
layer.alert(data.msg);
}
},
error: function () {
layer.alert('网络异常');
}
})
}
</script>
</html>

View File

@ -29,6 +29,7 @@
<ul class="log_list">
<li><a class="link_1 on" href="/">爬虫源管理</a></li>
<li><a class="link_1" href="/crawl/crawlSingleTask_list.html">单本采集管理</a></li>
<!--<li><a class="link_1 " href="/user/userinfo.html">批量小说爬取</a></li>
<li><a class="link_4 " href="/user/favorites.html">单本小说爬取</a></li>-->
</ul>

View File

@ -28,6 +28,7 @@
<ul class="log_list">
<li><a class="link_1 on" href="/">爬虫源管理</a></li>
<li><a class="link_1" href="/crawl/crawlSingleTask_list.html">单本采集管理</a></li>
<!-- <li><a class="link_1 " href="/user/userinfo.html">批量小说爬取</a></li>
<li><a class="link_4 " href="/user/favorites.html">单本小说爬取</a></li>-->
</ul>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>2.0.2</version>
<version>2.8.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -27,11 +27,57 @@
<version>${jjwt.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>io.searchbox</groupId>
<artifactId>jest</artifactId>
<version>${jest.version}</version>
</dependency>
<!--aliyunOSS-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>${aliyun-sdk-oss.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<!--FastDfs-->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>${fastdfs-client.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<!--引入redisson分布式锁-->
<!-- <dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>${redisson.version}</version>
</dependency>-->
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.9.153.ALL</version>
<version>${alipay-sdk-java.version}</version>
</dependency>
</dependencies>

View File

@ -1,10 +1,13 @@
package com.java2nb.novel;
import com.github.tobato.fastdfs.FdfsClientConfig;
import io.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@ -18,6 +21,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableScheduling
@EnableCaching
@MapperScan(basePackages = {"com.java2nb.novel.mapper"})
@Import(FdfsClientConfig.class)
public class FrontNovelApplication {
public static void main(String[] args) {

View File

@ -2,7 +2,9 @@ package com.java2nb.novel.controller;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.core.bean.ResultBean;
import com.java2nb.novel.core.bean.UserDetails;
import com.java2nb.novel.core.enums.ResponseStatus;
import com.java2nb.novel.core.exception.BusinessException;
import com.java2nb.novel.core.utils.BeanUtil;
import com.java2nb.novel.entity.Author;
import com.java2nb.novel.entity.Book;
@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
/**
* @author 11797
@ -55,18 +58,14 @@ public class AuthorController extends BaseController{
* 发布小说
* */
@PostMapping("addBook")
public ResultBean addBook(Book book,HttpServletRequest request){
public ResultBean addBook(@RequestParam("bookDesc") String bookDesc,Book book,HttpServletRequest request){
//查询作家信息
Author author = authorService.queryAuthor(getUserDetails(request).getId());
//判断作者状态是否正常
if(author.getStatus()==1){
//封禁状态,不能发布小说
return ResultBean.fail(ResponseStatus.AUTHOR_STATUS_FORBIDDEN);
}
Author author = checkAuthor(request);
//bookDesc不能使用book对象来接收否则会自动去掉前面的空格
book.setBookDesc(bookDesc
.replaceAll("\\n","<br>")
.replaceAll("\\s","&nbsp;"));
//发布小说
bookService.addBook(book,author.getId(),author.getPenName());
@ -78,14 +77,7 @@ public class AuthorController extends BaseController{
* */
@PostMapping("updateBookStatus")
public ResultBean updateBookStatus(Long bookId,Byte status,HttpServletRequest request){
//查询作家信息
Author author = authorService.queryAuthor(getUserDetails(request).getId());
//判断作者状态是否正常
if(author.getStatus()==1){
//封禁状态,不能发布小说
return ResultBean.fail(ResponseStatus.AUTHOR_STATUS_FORBIDDEN);
}
Author author = checkAuthor(request);
//更新小说状态,上架或下架
bookService.updateBookStatus(bookId,status,author.getId());
@ -96,21 +88,29 @@ public class AuthorController extends BaseController{
/**
* 发布章节内容
* */
@PostMapping("addBookContent")
public ResultBean addBookContent(Long bookId,String indexName,String content,HttpServletRequest request){
//查询作家信息
Author author = authorService.queryAuthor(getUserDetails(request).getId());
* 删除章节
*/
@PostMapping("deleteIndex")
public ResultBean deleteIndex(Long indexId, HttpServletRequest request) {
//判断作者状态是否正常
if(author.getStatus()==1){
//封禁状态,不能发布小说
return ResultBean.fail(ResponseStatus.AUTHOR_STATUS_FORBIDDEN);
Author author = checkAuthor(request);
//删除章节
bookService.deleteIndex(indexId, author.getId());
return ResultBean.ok();
}
//发布章节内容
bookService.addBookContent(bookId,indexName,content,author.getId());
/**
* 更新章节名
*/
@PostMapping("updateIndexName")
public ResultBean updateIndexName(Long indexId, String indexName, HttpServletRequest request) {
Author author = checkAuthor(request);
//更新章节名
bookService.updateIndexName(indexId, indexName, author.getId());
return ResultBean.ok();
}
@ -118,4 +118,104 @@ public class AuthorController extends BaseController{
/**
* 发布章节内容
*/
@PostMapping("addBookContent")
public ResultBean addBookContent(Long bookId, String indexName, String content,Byte isVip, HttpServletRequest request) {
Author author = checkAuthor(request);
content = content.replaceAll("\\n", "<br>")
.replaceAll("\\s", "&nbsp;");
//发布章节内容
bookService.addBookContent(bookId, indexName, content,isVip, author.getId());
return ResultBean.ok();
}
/**
* 查询章节内容
*/
@PostMapping("queryIndexContent")
public ResultBean queryIndexContent(Long indexId, HttpServletRequest request) {
Author author = checkAuthor(request);
String content = bookService.queryIndexContent(indexId, author.getId());
content = content.replaceAll("<br>", "\n")
.replaceAll("&nbsp;", " ");
return ResultBean.ok(content);
}
/**
* 更新章节内容
*/
@PostMapping("updateBookContent")
public ResultBean updateBookContent(Long indexId, String indexName, String content, HttpServletRequest request) {
Author author = checkAuthor(request);
content = content.replaceAll("\\n", "<br>")
.replaceAll("\\s", "&nbsp;");
//更新章节内容
bookService.updateBookContent(indexId, indexName, content, author.getId());
return ResultBean.ok();
}
/**
* 作家日收入统计数据分页列表查询
* */
@PostMapping("listIncomeDailyByPage")
public ResultBean listIncomeDailyByPage(@RequestParam(value = "curr", defaultValue = "1") int page,
@RequestParam(value = "limit", defaultValue = "10") int pageSize ,
@RequestParam(value = "bookId", defaultValue = "0") Long bookId,
@RequestParam(value = "startTime",defaultValue = "2020-05-01") Date startTime,
@RequestParam(value = "endTime",defaultValue = "2030-01-01") Date endTime,
HttpServletRequest request){
return ResultBean.ok(new PageInfo<>(authorService.listIncomeDailyByPage(page,pageSize,getUserDetails(request).getId(),bookId,startTime,endTime)
));
}
/**
* 作家月收入统计数据分页列表查询
* */
@PostMapping("listIncomeMonthByPage")
public ResultBean listIncomeMonthByPage(@RequestParam(value = "curr", defaultValue = "1") int page,
@RequestParam(value = "limit", defaultValue = "10") int pageSize ,
@RequestParam(value = "bookId", defaultValue = "0") Long bookId,
HttpServletRequest request){
return ResultBean.ok(new PageInfo<>(authorService.listIncomeMonthByPage(page,pageSize,getUserDetails(request).getId(),bookId)
));
}
private Author checkAuthor(HttpServletRequest request) {
UserDetails userDetails = getUserDetails(request);
if (userDetails == null) {
throw new BusinessException(ResponseStatus.NO_LOGIN);
}
//查询作家信息
Author author = authorService.queryAuthor(userDetails.getId());
//判断作者状态是否正常
if (author.getStatus() == 1) {
//封禁状态,不能发布小说
throw new BusinessException(ResponseStatus.AUTHOR_STATUS_FORBIDDEN);
}
return author;
}
}

View File

@ -4,14 +4,14 @@ import com.github.pagehelper.PageInfo;
import com.java2nb.novel.core.bean.ResultBean;
import com.java2nb.novel.core.bean.UserDetails;
import com.java2nb.novel.core.enums.ResponseStatus;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.entity.BookComment;
import com.java2nb.novel.entity.BookIndex;
import com.java2nb.novel.search.BookSP;
import com.java2nb.novel.service.BookService;
import com.java2nb.novel.vo.BookVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -33,6 +32,11 @@ public class BookController extends BaseController{
private final BookService bookService;
private final RabbitTemplate rabbitTemplate;
@Value("${spring.rabbitmq.enable}")
private Integer enableMq;
/**
* 查询首页小说设置列表数据
@ -79,8 +83,8 @@ public class BookController extends BaseController{
* */
@PostMapping("searchByPage")
public ResultBean searchByPage(BookSP bookSP, @RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "20") int pageSize){
List<BookVO> books = bookService.searchByPage(bookSP,page,pageSize);
return ResultBean.ok(new PageInfo<>(books));
PageInfo<BookVO> pageInfo = bookService.searchByPage(bookSP,page,pageSize);
return ResultBean.ok(pageInfo);
}
/**
@ -105,7 +109,11 @@ public class BookController extends BaseController{
* */
@PostMapping("addVisitCount")
public ResultBean addVisitCount(Long bookId){
bookService.addVisitCount(bookId);
if(enableMq == 1) {
rabbitTemplate.convertAndSend("ADD-BOOK-VISIT-EXCHANGE", null, bookId);
}else {
bookService.addVisitCount(bookId, 1);
}
return ResultBean.ok();
}
@ -159,7 +167,15 @@ public class BookController extends BaseController{
* */
@PostMapping("queryNewIndexList")
public ResultBean queryNewIndexList(Long bookId){
return ResultBean.ok(bookService.queryIndexList(bookId,"index_num desc",10));
return ResultBean.ok(bookService.queryIndexList(bookId,"index_num desc",1,10));
}
/**
* 目录页
* */
@PostMapping("/queryIndexList")
public ResultBean indexList(Long bookId,@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "5") int pageSize,@RequestParam(value = "orderBy") String orderBy) {
return ResultBean.ok(new PageInfo<>(bookService.queryIndexList(bookId,orderBy,page,pageSize)));
}

View File

@ -1,17 +1,32 @@
package com.java2nb.novel.controller;
import com.java2nb.novel.core.bean.ResultBean;
import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.core.utils.RandomValidateCodeUtil;
import com.java2nb.novel.core.utils.RestTemplateUtil;
import com.java2nb.novel.core.utils.UUIDUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.Charsets;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.util.Date;
import java.util.Objects;
/**
* @author 11797
@ -24,6 +39,9 @@ public class FileController {
private final CacheService cacheService;
@Value("${pic.save.path}")
private String picSavePath;
/**
* 生成验证码
*/
@ -44,5 +62,32 @@ public class FileController {
}
}
/**
* 文件上传
*/
@ResponseBody
@PostMapping("/upload")
ResultBean upload(@RequestParam("file") MultipartFile file) {
Date currentDate = new Date();
try {
String savePath =
Constants.LOCAL_PIC_PREFIX + DateUtils.formatDate(currentDate, "yyyy") + "/" +
DateUtils.formatDate(currentDate, "MM") + "/" +
DateUtils.formatDate(currentDate, "dd") ;
String oriName = file.getOriginalFilename();
String saveFileName = UUIDUtil.getUUID32() + oriName.substring(oriName.lastIndexOf("."));
File saveFile = new File( picSavePath + savePath, saveFileName);
if (!saveFile.getParentFile().exists()) {
saveFile.getParentFile().mkdirs();
}
file.transferTo(saveFile);
return ResultBean.ok(savePath+"/"+saveFileName);
} catch (Exception e) {
log.error(e.getMessage(), e);
return ResultBean.error();
}
}
}

View File

@ -101,9 +101,11 @@ public class PageController extends BaseController{
public String bookDetail(@PathVariable("bookId") Long bookId, Model model) {
Book book = bookService.queryBookDetail(bookId);
model.addAttribute("book",book);
if(book.getLastIndexId() != null) {
//查询首章目录ID
Long firstBookIndexId = bookService.queryFirstBookIndexId(bookId);
model.addAttribute("firstBookIndexId", firstBookIndexId);
}
return ThreadLocalUtil.getTemplateDir()+"book/book_detail";
}
@ -114,7 +116,7 @@ public class PageController extends BaseController{
public String indexList(@PathVariable("bookId") Long bookId, Model model) {
Book book = bookService.queryBookDetail(bookId);
model.addAttribute("book",book);
List<BookIndex> bookIndexList = bookService.queryIndexList(bookId,null,null);
List<BookIndex> bookIndexList = bookService.queryIndexList(bookId,null,1,null);
model.addAttribute("bookIndexList",bookIndexList);
model.addAttribute("bookIndexCount",bookIndexList.size());
return ThreadLocalUtil.getTemplateDir()+"book/book_index";
@ -140,6 +142,8 @@ public class PageController extends BaseController{
//查询内容
BookContent bookContent = bookService.queryBookContent(bookIndex.getId());
model.addAttribute("bookContent",bookContent);
boolean needBuy = false;
//判断该目录是否收费
if(bookIndex.getIsVip()!=null && bookIndex.getIsVip() == 1 ){
UserDetails user = getUserDetails(request);
@ -152,11 +156,10 @@ public class PageController extends BaseController{
if(!isBuy){
//没有购买过,需要购买
bookContent.setContent(null);
model.addAttribute("needBuy",true);
return "book/book_content";
needBuy = true;
}
}
model.addAttribute("needBuy",false);
model.addAttribute("needBuy",needBuy);
return ThreadLocalUtil.getTemplateDir()+"book/book_content";
}

View File

@ -0,0 +1,24 @@
package com.java2nb.novel.core.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
/**
* 作家收入配置
* @author cd
*/
@Component
@Data
@ConfigurationProperties(prefix = "author.income")
public class AuthorIncomeConfig {
private BigDecimal taxRate;
private BigDecimal shareProportion;
private BigDecimal exchangeProportion;
}

View File

@ -0,0 +1,13 @@
package com.java2nb.novel.core.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.jmx.support.RegistrationPolicy;
/**
* @author 11797
*/
@Configuration
@EnableMBeanExport(registration= RegistrationPolicy.IGNORE_EXISTING)
public class FdfsConfiguration {
}

View File

@ -0,0 +1,30 @@
package com.java2nb.novel.core.config;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author 11797
*/
@Data
@Component
@ConfigurationProperties(prefix="novel.file")
public class OssProperties{
private String endpoint;
private String keyId;
private String keySecret;
private String fileHost;
private String bucketName;
private String webUrl;
}

View File

@ -0,0 +1,59 @@
package com.java2nb.novel.core.config;
import org.springframework.amqp.core.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author 11797
*/
@Configuration
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "enable", havingValue = "1")
public class RabbitConfig {
/**
* 更新数据库队列
*/
@Bean
public Queue updateDbQueue() {
return new Queue("UPDATE-DB-QUEUE", true);
}
/**
* 更新数据库队列
*/
@Bean
public Queue updateEsQueue() {
return new Queue("UPDATE-ES-QUEUE", true);
}
/**
* 增加点击量交换机
*/
@Bean
public FanoutExchange addVisitExchange() {
return new FanoutExchange("ADD-BOOK-VISIT-EXCHANGE");
}
/**
* 更新搜索引擎队列绑定到增加点击量交换机中
*/
@Bean
public Binding updateEsBinding() {
return BindingBuilder.bind(updateEsQueue()).to(addVisitExchange());
}
/**
* 更新数据库绑定到增加点击量交换机中
*/
@Bean
public Binding updateDbBinding() {
return BindingBuilder.bind(updateDbQueue()).to(addVisitExchange());
}
}

View File

@ -0,0 +1,18 @@
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;
/**
* @author xiongxiaoyang
*/
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new DateConverter());
}
}

View File

@ -0,0 +1,107 @@
package com.java2nb.novel.core.listener;
import com.java2nb.novel.core.cache.CacheKey;
import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.service.BookService;
import com.java2nb.novel.service.SearchService;
import com.java2nb.novel.vo.EsBookVO;
import com.rabbitmq.client.Channel;
import io.searchbox.client.JestClient;
import io.searchbox.core.Index;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import java.text.SimpleDateFormat;
/**
* @author 11797
*/
@Component
@Slf4j
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "enable", havingValue = "1")
public class BookVisitAddListener {
private final BookService bookService;
private final CacheService cacheService;
private final SearchService searchService;
// private final RedissonClient redissonClient;
/**
* 更新数据库
* 流量削峰每本小说累积10个点击更新一次
*/
@SneakyThrows
@RabbitListener(queues = {"UPDATE-DB-QUEUE"})
public void updateDb(Long bookId, Channel channel, Message message) {
log.debug("收到更新数据库消息:" + bookId);
Thread.sleep(1000 * 2);
//TODO 操作共享资源visitCount集群环境下有线程安全问题引入Redisson框架实现分布式锁
//RLock lock = redissonClient.getLock("visitCount");
//lock.lock();
//目前visitCount不重要数据可丢失暂不实现分布式锁
Integer visitCount = (Integer) cacheService.getObject(CacheKey.BOOK_ADD_VISIT_COUNT+bookId);
if(visitCount == null){
visitCount = 0 ;
}
cacheService.setObject(CacheKey.BOOK_ADD_VISIT_COUNT+bookId,++visitCount);
if(visitCount >= Constants.ADD_MAX_VISIT_COUNT) {
bookService.addVisitCount(bookId,visitCount);
cacheService.del(CacheKey.BOOK_ADD_VISIT_COUNT+bookId);
}
//TODO 操作共享资源visitCount集群环境下有线程安全问题引入Redisson框架实现分布式锁
//lock.unlock();
}
/**
* 更新搜索引擎
* 流量削峰每本小说1个小时更新一次
*/
@RabbitListener(queues = {"UPDATE-ES-QUEUE"})
public void updateEs(Long bookId, Channel channel, Message message) {
log.debug("收到更新搜索引擎消息:" + bookId);
if (cacheService.get(CacheKey.ES_IS_UPDATE_VISIT + bookId) == null) {
cacheService.set(CacheKey.ES_IS_UPDATE_VISIT + bookId, "1", 60 * 60);
try {
Thread.sleep(1000 * 5);
Book book = bookService.queryBookDetail(bookId);
searchService.importToEs(book);
}catch (Exception e){
cacheService.del(CacheKey.ES_IS_UPDATE_VISIT + bookId);
log.error("更新搜索引擎失败"+bookId);
}
}
}
}

View File

@ -0,0 +1,87 @@
package com.java2nb.novel.core.schedule;
import com.java2nb.novel.core.cache.CacheKey;
import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.utils.BeanUtil;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.service.BookService;
import com.java2nb.novel.service.SearchService;
import com.java2nb.novel.vo.EsBookVO;
import io.searchbox.client.JestClient;
import io.searchbox.core.DocumentResult;
import io.searchbox.core.Index;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* 小说导入搜索引擎
*
* @author Administrator
*/
@ConditionalOnProperty(prefix = "spring.elasticsearch", name = "enable", havingValue = "1")
@Service
@RequiredArgsConstructor
@Slf4j
public class BookToEsSchedule {
private final BookService bookService;
private final CacheService cacheService;
private final SearchService searchService;
/**
* 1分钟导入一次
*/
@Scheduled(fixedRate = 1000 * 60)
public void saveToEs() {
//TODO 引入Redisson框架实现分布式锁
//可以重复更新,只是效率可能略有降低,所以暂不实现分布式锁
if (cacheService.get(CacheKey.ES_TRANS_LOCK) == null) {
cacheService.set(CacheKey.ES_TRANS_LOCK, "1", 60 * 20);
try {
//查询需要更新的小说
Date lastDate = (Date) cacheService.getObject(CacheKey.ES_LAST_UPDATE_TIME);
if (lastDate == null) {
lastDate = new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-01");
}
List<Book> books = bookService.queryBookByUpdateTimeByPage(lastDate, 100);
for (Book book : books) {
searchService.importToEs(book);
lastDate = book.getUpdateTime();
Thread.sleep(5000);
}
cacheService.setObject(CacheKey.ES_LAST_UPDATE_TIME, lastDate);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
cacheService.del(CacheKey.ES_TRANS_LOCK);
}
}
}

View File

@ -1,8 +1,10 @@
package com.java2nb.novel.core.schedule;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.service.BookService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -12,14 +14,15 @@ import org.springframework.stereotype.Service;
import java.util.List;
/**
* 网络图片转存本地任务
* 将爬取的网络图片转存为自己的存储介质本地OSSfastDfs任务
*
* @author Administrator
*/
@ConditionalOnProperty(prefix = "pic.save", name = "type", havingValue = "2")
@Service
@RequiredArgsConstructor
@Slf4j
public class Network2LocalPicSchedule {
public class CrawlPicTransSchedule {
private final BookService bookService;
@ -33,20 +36,18 @@ public class Network2LocalPicSchedule {
* 10分钟转一次
*/
@Scheduled(fixedRate = 1000 * 60 * 10)
@SneakyThrows
public void trans() {
log.info("Network2LocalPicSchedule。。。。。。。。。。。。");
Integer offset = 0, limit = 100;
List<Book> networkPicBooks;
do {
networkPicBooks = bookService.queryNetworkPicBooks(limit, offset);
List<Book> networkPicBooks = bookService.queryNetworkPicBooks(Constants.LOCAL_PIC_PREFIX,100);
for (Book book : networkPicBooks) {
bookService.updateBookPicToLocal(book.getPicUrl(), book.getId());
//3秒钟转化一张图片10分钟转化200张
Thread.sleep(3000);
}
offset += limit;
} while (networkPicBooks.size() > 0);
}

View File

@ -0,0 +1,142 @@
package com.java2nb.novel.core.schedule;
import com.java2nb.novel.core.config.AuthorIncomeConfig;
import com.java2nb.novel.core.utils.DateUtil;
import com.java2nb.novel.entity.Author;
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 com.java2nb.novel.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 作家日收入统计任务
*
* @author cd
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class DailyIncomeStaSchedule {
private final AuthorService authorService;
private final UserService userService;
private final BookService bookService;
/**
* 每天凌晨0点统计上一天数据
*/
@Scheduled(cron = "0 0 0 * * ?")
public void statistics() {
//获取昨天的日期时间
Date yesterday = DateUtil.getYesterday();
//获取昨天的开始时间
Date startTime = DateUtil.getDateStartTime(yesterday);
//获取昨天的结束时间
Date endTime = DateUtil.getDateEndTime(yesterday);
//每次查询的作家数量
int needAuthorNumber = 10;
//查询出来的真实作家数量
int realAuthorNumber;
//每次查询最大申请时间
Date maxAuthorCreateTime = new Date();
do {
//1.查询作家列表
List<Author> authors = authorService.queryAuthorList(needAuthorNumber, maxAuthorCreateTime);
realAuthorNumber = authors.size();
for (Author author : authors) {
maxAuthorCreateTime = author.getCreateTime();
Long authorId = author.getId();
Long userId = author.getUserId();
//2.查询作家作品
List<Book> books = bookService.queryBookList(authorId);
int buyTotalMember = 0;
int buyTotalCount = 0;
int buyTotalAccount = 0;
List<Long> bookIds = new ArrayList<>(books.size());
for (Book book : books) {
Long bookId = book.getId();
//3.查询该作家作品昨日的订阅人数
int buyMember = userService.queryBuyMember(bookId, startTime, endTime);
int buyCount = 0;
int buyAccount = 0;
if (buyMember > 0) {
//4.查询该作家作品昨日的订阅次数
buyCount = userService.queryBuyCount(bookId, startTime, endTime);
//5.查询该作家作品昨日的订阅总额
buyAccount = userService.queryBuyAccount(bookId, startTime, endTime);
}
//6.判断该作家作品昨日收入数据是否统计入库
boolean isStatistics = authorService.queryIsStatisticsDaily(bookId, yesterday);
if (!isStatistics) {
//7.该作家作品昨日收入数据未统计入库,分作品统计数据入库
AuthorIncomeDetail authorIncomeDetail = new AuthorIncomeDetail();
authorIncomeDetail.setAuthorId(authorId);
authorIncomeDetail.setUserId(userId);
authorIncomeDetail.setBookId(bookId);
authorIncomeDetail.setIncomeDate(yesterday);
authorIncomeDetail.setIncomeNumber(buyMember);
authorIncomeDetail.setIncomeCount(buyCount);
authorIncomeDetail.setIncomeAccount(buyAccount);
authorIncomeDetail.setCreateTime(new Date());
authorService.saveDailyIncomeSta(authorIncomeDetail);
}
buyTotalCount += buyCount;
buyTotalAccount += buyAccount;
bookIds.add(bookId);
}
//8.判断该作家所有作品昨日收入数据是否统计入库
boolean isStatistics = authorService.queryIsStatisticsDaily(authorId,0L, yesterday);
if (!isStatistics) {
if (buyTotalCount > 0) {
//总订阅次数大于0则订阅人数也大于0
buyTotalMember = userService.queryBuyTotalMember(bookIds, startTime, endTime);
}
//9.作家所有作品昨日收入数据统计入库
AuthorIncomeDetail authorIncomeAllDetail = new AuthorIncomeDetail();
authorIncomeAllDetail.setAuthorId(authorId);
authorIncomeAllDetail.setUserId(userId);
authorIncomeAllDetail.setBookId(0L);
authorIncomeAllDetail.setIncomeDate(yesterday);
authorIncomeAllDetail.setIncomeNumber(buyTotalMember);
authorIncomeAllDetail.setIncomeCount(buyTotalCount);
authorIncomeAllDetail.setIncomeAccount(buyTotalAccount);
authorIncomeAllDetail.setCreateTime(new Date());
authorService.saveDailyIncomeSta(authorIncomeAllDetail);
}
}
} while (needAuthorNumber == realAuthorNumber);
}
}

View File

@ -0,0 +1,129 @@
package com.java2nb.novel.core.schedule;
import com.java2nb.novel.core.config.AuthorIncomeConfig;
import com.java2nb.novel.core.utils.DateUtil;
import com.java2nb.novel.entity.*;
import com.java2nb.novel.service.AuthorService;
import com.java2nb.novel.service.BookService;
import com.java2nb.novel.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 作家日收入统计任务
*
* @author cd
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class MonthIncomeStaSchedule {
private final AuthorService authorService;
private final BookService bookService;
private final AuthorIncomeConfig authorIncomeConfig;
/**
* 每个月1号凌晨2点统计上个月数据
*/
@Scheduled(cron = "0 0 2 1 * ?")
public void statistics() {
//获取上个月的开始时间和结束时间
Date startTime = DateUtil.getLastMonthStartTime();
Date endTime = DateUtil.getLastMonthEndTime();
//每次查询的作家数量
int needAuthorNumber = 10;
//查询出来的真实作家数量
int realAuthorNumber;
//每次查询最大申请时间
Date maxAuthorCreateTime = new Date();
do {
//1.查询作家列表
List<Author> authors = authorService.queryAuthorList(needAuthorNumber, maxAuthorCreateTime);
realAuthorNumber = authors.size();
for (Author author : authors) {
maxAuthorCreateTime = author.getCreateTime();
Long authorId = author.getId();
Long userId = author.getUserId();
//2.查询作家作品
List<Book> books = bookService.queryBookList(authorId);
Long totalPreTaxIncome = 0L;
Long totalAfterTaxIncome = 0L;
for (Book book : books) {
Long bookId = book.getId();
//3.月收入数据未统计入库,分作品统计数据入库
Long monthIncome = authorService.queryTotalAccount(userId, bookId, startTime, endTime);
BigDecimal monthIncomeShare = new BigDecimal(monthIncome)
.multiply(authorIncomeConfig.getShareProportion());
Long preTaxIncome = monthIncomeShare
.multiply(authorIncomeConfig.getExchangeProportion())
.multiply(new BigDecimal(100))
.longValue();
totalPreTaxIncome += preTaxIncome;
Long afterTaxIncome = monthIncomeShare
.multiply(authorIncomeConfig.getTaxRate())
.multiply(authorIncomeConfig.getExchangeProportion())
.multiply(new BigDecimal(100))
.longValue();
totalAfterTaxIncome += afterTaxIncome;
//4.查询月收入统计是否入库
if (monthIncome > 0 && !authorService.queryIsStatisticsMonth(bookId, endTime)) {
AuthorIncome authorIncome = new AuthorIncome();
authorIncome.setAuthorId(authorId);
authorIncome.setUserId(userId);
authorIncome.setBookId(bookId);
authorIncome.setPreTaxIncome(preTaxIncome);
authorIncome.setAfterTaxIncome(afterTaxIncome);
authorIncome.setIncomeMonth(endTime);
authorIncome.setCreateTime(new Date());
authorService.saveAuthorIncomeSta(authorIncome);
}
}
if (totalPreTaxIncome > 0 && !authorService.queryIsStatisticsMonth(0L, endTime)) {
AuthorIncome authorIncome = new AuthorIncome();
authorIncome.setAuthorId(authorId);
authorIncome.setUserId(userId);
authorIncome.setBookId(0L);
authorIncome.setPreTaxIncome(totalPreTaxIncome);
authorIncome.setAfterTaxIncome(totalAfterTaxIncome);
authorIncome.setIncomeMonth(endTime);
authorIncome.setCreateTime(new Date());
authorService.saveAuthorIncomeSta(authorIncome);
}
}
} while (needAuthorNumber == realAuthorNumber);
}
}

View File

@ -18,19 +18,20 @@ public class BrowserUtil {
"lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-",
"newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams",
"sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-",
"symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi",
"symb", "t-mo", "teli", "tim-", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi",
"wapp", "wapr", "webc", "winw", "winw", "xda", "xda-", "Googlebot-Mobile" };
/**
*
* @Title: JudgelsMobile @Description: TODO(判断是否是手机浏览器) @param @param
* request @param @return 设定文件 @return boolean 返回类型 @throws
* 判断是否是手机浏览器
*/
public static boolean isMobile(HttpServletRequest request) {
boolean isMobile = false;
if (request.getHeader("User-Agent") != null) {
String userAgent = request.getHeader("User-Agent");
if (userAgent != null) {
userAgent = userAgent.toLowerCase();
for (String mobileAgent : mobileAgents) {
if (request.getHeader("User-Agent").toLowerCase().indexOf(mobileAgent) > 0) {
if (userAgent.indexOf(mobileAgent) > 0) {
isMobile = true;
break;
}

View File

@ -12,7 +12,7 @@ public class Constants {
public static final String TEMPLATE_PATH_PREFIX_KEY = "templatePathPrefixKey";
/**
* 本地图片保存前缀
* 保存图片到自己的存储介质路径前缀
* */
public static final String LOCAL_PIC_PREFIX = "/localPic/";
@ -30,4 +30,9 @@ public class Constants {
* 首页设置的小说数量
* */
public static final int INDEX_BOOK_SETTING_NUM = 32;
/**
* 累积的最大点击量
* */
public static final Integer ADD_MAX_VISIT_COUNT = 10;
}

View File

@ -5,6 +5,7 @@ import com.java2nb.novel.search.BookSP;
import com.java2nb.novel.vo.BookVO;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
@ -15,13 +16,13 @@ public interface FrontBookMapper extends BookMapper {
List<BookVO> searchByPage(BookSP params);
void addVisitCount(@Param("bookId") Long bookId);
void addVisitCount(@Param("bookId") Long bookId, @Param("visitCount") Integer visitCount);
List<Book> listRecBookByCatId(@Param("catId") Integer catId);
void addCommentCount(@Param("bookId") Long bookId);
List<Book> queryNetworkPicBooks(@Param("limit") Integer limit,@Param("offset") Integer offset);
List<Book> queryNetworkPicBooks(@Param("localPicPrefix") String localPicPrefix, @Param("limit") Integer limit);
/**
* 按评分随机查询小说集合

View File

@ -2,8 +2,11 @@ package com.java2nb.novel.service;
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 java.util.Date;
import java.util.List;
/**
@ -39,4 +42,87 @@ public interface AuthorService {
* @return 作家对象
* */
Author queryAuthor(Long userId);
/**
* 查询作家列表
* @return 作家列表
* @param limit 查询条数
* @param maxAuthorCreateTime 最大申请时间
*/
List<Author> queryAuthorList(int limit, Date maxAuthorCreateTime);
/**
* 查询收入日统计是否入库
* @param bookId 作品ID
* @param date 收入时间
* @return true:已入库false未入库
*/
boolean queryIsStatisticsDaily(Long bookId, Date date);
/**
* 保存日收入统计(按作品)
* @param authorIncomeDetail 收入详情
* */
void saveDailyIncomeSta(AuthorIncomeDetail authorIncomeDetail);
/**
* 查询月收入统计是否入库
* @param bookId 作品ID
* @param incomeDate 收入时间
* @return true:已入库false未入库
* */
boolean queryIsStatisticsMonth(Long bookId, Date incomeDate);
/**
* 查询时间段内总订阅额
*
* @param userId
* @param bookId 作品ID
* @param startTime 开始时间
* @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 收入时间
* @return true:已入库false未入库
*/
boolean queryIsStatisticsDaily(Long authorId, Long bookId, Date date);
/**
*作家日收入统计数据分页列表查询
* @param userId
* @param page 页码
* @param pageSize 分页大小
* @param bookId 小说ID
* @param startTime 开始时间
* @param endTime 结束时间
* @return 日收入统计数据列表
*/
List<AuthorIncomeDetail> listIncomeDailyByPage(int page, int pageSize, Long userId, Long bookId, Date startTime, Date endTime);
/**
* 作家月收入统计数据分页列表查询
* @param page 页码
* @param pageSize 分页大小
* @param userId 用户ID
* @param bookId 小说ID
* @return
* */
List<AuthorIncome> listIncomeMonthByPage(int page, int pageSize, Long userId, Long bookId);
}

View File

@ -1,12 +1,14 @@
package com.java2nb.novel.service;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.search.BookSP;
import com.java2nb.novel.vo.BookCommentVO;
import com.java2nb.novel.vo.BookSettingVO;
import com.java2nb.novel.entity.*;
import com.java2nb.novel.vo.BookVO;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -44,9 +46,9 @@ public interface BookService {
* @param params 搜索参数
* @param page 页码
* @param pageSize 分页大小
* @return 小说集合
* @return 小说集合分页信息
* */
List<BookVO> searchByPage(BookSP params, int page, int pageSize);
PageInfo searchByPage(BookSP params, int page, int pageSize);
/**
* 查询小说分类列表
@ -64,10 +66,12 @@ public interface BookService {
* 查询目录列表
* @param bookId 书籍ID
* @param orderBy 排序
*@param limit 查询条数
* @param page 查询页码
*@param pageSize 分页大小
*@return 目录集合
* */
List<BookIndex> queryIndexList(Long bookId, String orderBy, Integer limit);
List<BookIndex> queryIndexList(Long bookId, String orderBy, Integer page, Integer pageSize);
/**
* 查询目录
@ -110,8 +114,8 @@ public interface BookService {
/**
* 增加点击次数
* @param bookId 书籍ID
* */
void addVisitCount(Long bookId);
* @param visitCount*/
void addVisitCount(Long bookId, Integer visitCount);
/**
* 查询章节数
@ -178,16 +182,17 @@ public interface BookService {
/**
* 查询网络图片的小说
*
* @param localPicPrefix
* @param limit 查询条数
* @param offset 开始行数
* @return 返回小说集合
* */
List<Book> queryNetworkPicBooks(Integer limit, Integer offset);
List<Book> queryNetworkPicBooks(String localPicPrefix, Integer limit);
/**
* 更新小说网络图片到本地
* @param picUrl 网络图片路径
* 更新爬取的小说网络图片到自己的存储介质本地、OSS、fastDfs
* @param picUrl 爬取的网络图片路径
* @param bookId 小说ID
*/
void updateBookPicToLocal(String picUrl, Long bookId);
@ -197,6 +202,7 @@ public interface BookService {
* @param userId 用户ID
* @param page 页码
* @param pageSize 分页大小
* @return 小说集合
* */
List<Book> listBookPageByUserId(Long userId, int page, int pageSize);
@ -221,7 +227,55 @@ public interface BookService {
* @param bookId 小说ID
* @param indexName 章节名
* @param content 章节内容
* @param authorId 作者ID
* @param isVip 是否收费
* @param authorId 作者ID */
void addBookContent(Long bookId, String indexName, String content, Byte isVip, Long authorId);
/**
* 根据更新时间分页查询书籍列表
* @param startDate 开始时间,包括该时间
* @param limit 查询数量
* @return 书籍列表
* */
void addBookContent(Long bookId, String indexName, String content, Long authorId);
List<Book> queryBookByUpdateTimeByPage(Date startDate, int limit);
/**
* 查询作品列表
* @param authorId 作家ID
* @return 作品列表
*/
List<Book> queryBookList(Long authorId);
/**
* 删除章节
* @param indexId
* @param authorId 作家ID
*/
void deleteIndex(Long indexId, Long authorId);
/**
* 更新章节名
* @param indexId
* @param indexName
* @param authorId
*/
void updateIndexName(Long indexId, String indexName, Long authorId);
/**
* 查询章节内容
* @param indexId
* @param authorId
* @return
*/
String queryIndexContent(Long indexId, Long authorId);
/**
* 更新章节内容
* @param indexId
* @param indexName
* @param content
* @param authorId
*/
void updateBookContent( Long indexId, String indexName, String content, Long authorId);
}

View File

@ -0,0 +1,17 @@
package com.java2nb.novel.service;
/**
* @author 11797
*/
public interface FileService {
/**
* 将爬取的网络图片转存为自己的存储介质本地、OSS、fastDfs
* @param picSrc 爬取的网络图片路径
* @param picSavePath 保存路径
* @return 新图片地址
* */
String transFile(String picSrc, String picSavePath);
}

View File

@ -0,0 +1,27 @@
package com.java2nb.novel.service;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.search.BookSP;
/**
* @author 11797
*/
public interface SearchService {
/**
* 导入到es
* @param book 小说数据
*/
void importToEs(Book book);
/**
* 搜索
* @param params 搜索参数
* @param page 当前页码
* @param pageSize 每页大小
* @return 分页信息
*/
PageInfo searchBook(BookSP params, int page, int pageSize);
}

View File

@ -9,6 +9,7 @@ import com.java2nb.novel.vo.BookShelfVO;
import com.java2nb.novel.entity.User;
import com.java2nb.novel.vo.UserFeedbackVO;
import java.util.Date;
import java.util.List;
/**
@ -138,4 +139,40 @@ public interface UserService {
* @param buyRecord 购买信息
* */
void buyBookIndex(Long userId, UserBuyRecord buyRecord);
/**
* 查询作品时间段内的订阅人数
* @param bookId 作品ID
* @param startTime 开始时间
* @param endTime 结束时间
* @return 订阅人数
*/
int queryBuyMember(Long bookId, Date startTime, Date endTime);
/**
* 查询作品时间段内的订阅次数
* @param bookId 作品ID
* @param startTime 开始时间
* @param endTime 结束时间
* @return 订阅次数
*/
int queryBuyCount(Long bookId, Date startTime, Date endTime);
/**
* 查询作品时间段内的订阅总额(屋币)
* @param bookId 作品ID
* @param startTime 开始时间
* @param endTime 结束时间
* @return 订阅总额(屋币)
*/
int queryBuyAccount(Long bookId, Date startTime, Date endTime);
/**
* 查询作者时间段内的订阅人数
* @param bookIds z作者的所有作品ID
* @param startTime 开始时间
* @param endTime 结束时间
* @return 订阅人数
*/
int queryBuyTotalMember(List<Long> bookIds, Date startTime, Date endTime);
}

View File

@ -1,10 +1,13 @@
package com.java2nb.novel.service.impl;
import com.github.pagehelper.PageHelper;
import com.java2nb.novel.core.cache.CacheKey;
import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.enums.ResponseStatus;
import com.java2nb.novel.core.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;
@ -38,6 +41,11 @@ public class AuthorServiceImpl implements AuthorService {
private final AuthorCodeMapper authorCodeMapper;
private final AuthorIncomeDetailMapper authorIncomeDetailMapper;
private final AuthorIncomeMapper authorIncomeMapper;
@Override
public Boolean checkPenName(String penName) {
@ -89,4 +97,108 @@ public class AuthorServiceImpl implements AuthorService {
.build()
.render(RenderingStrategies.MYBATIS3)).get(0);
}
@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));
}
@Override
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;
}
@Override
public void saveDailyIncomeSta(AuthorIncomeDetail authorIncomeDetail) {
authorIncomeDetailMapper.insertSelective(authorIncomeDetail);
}
@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;
}
@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));
}
@Override
public void saveAuthorIncomeSta(AuthorIncome authorIncome) {
authorIncomeMapper.insertSelective(authorIncome);
}
@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;
}
@Override
public List<AuthorIncomeDetail> listIncomeDailyByPage(int page, int pageSize, Long userId, Long bookId, Date startTime, Date endTime) {
PageHelper.startPage(page, pageSize);
return 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));
}
@Override
public List<AuthorIncome> listIncomeMonthByPage(int page, int pageSize, Long userId, Long bookId) {
PageHelper.startPage(page, pageSize);
return 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));
}
}

View File

@ -2,28 +2,30 @@ package com.java2nb.novel.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.core.cache.CacheKey;
import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.enums.ResponseStatus;
import com.java2nb.novel.core.exception.BusinessException;
import com.java2nb.novel.core.utils.BeanUtil;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.core.utils.FileUtil;
import com.java2nb.novel.core.utils.IdWorker;
import com.java2nb.novel.core.utils.*;
import com.java2nb.novel.entity.*;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.mapper.*;
import com.java2nb.novel.search.BookSP;
import com.java2nb.novel.service.AuthorService;
import com.java2nb.novel.service.BookService;
import com.java2nb.novel.service.FileService;
import com.java2nb.novel.service.SearchService;
import com.java2nb.novel.vo.BookCommentVO;
import com.java2nb.novel.vo.BookSettingVO;
import com.java2nb.novel.vo.BookVO;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
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.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
@ -31,6 +33,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.orderbyhelper.OrderByHelper;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -40,6 +43,7 @@ import java.util.stream.Collectors;
import static com.java2nb.novel.mapper.BookCategoryDynamicSqlSupport.bookCategory;
import static com.java2nb.novel.mapper.BookCommentDynamicSqlSupport.bookComment;
import static com.java2nb.novel.mapper.BookContentDynamicSqlSupport.bookContent;
import static com.java2nb.novel.mapper.BookContentDynamicSqlSupport.content;
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.*;
import static com.java2nb.novel.mapper.BookIndexDynamicSqlSupport.bookIndex;
import static org.mybatis.dynamic.sql.SqlBuilder.*;
@ -50,14 +54,18 @@ import static org.mybatis.dynamic.sql.select.SelectDSL.select;
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class BookServiceImpl implements BookService {
/**
* 本地图片保存路径
* */
*/
@Value("${pic.save.path}")
private String picSavePath;
@Value("${spring.elasticsearch.enable}")
private Integer esEnable;
private final FrontBookSettingMapper bookSettingMapper;
private final FrontBookMapper bookMapper;
@ -76,6 +84,10 @@ public class BookServiceImpl implements BookService {
private final AuthorService authorService;
private final SearchService searchService;
private final FileService fileService;
@SneakyThrows
@Override
@ -96,7 +108,7 @@ public class BookServiceImpl implements BookService {
/**
* 初始化首页小说设置
* */
*/
private List<BookSettingVO> initIndexBookSetting() {
Date currentDate = new Date();
List<Book> books = bookMapper.selectIdsByScoreAndRandom(Constants.INDEX_BOOK_SETTING_NUM);
@ -171,18 +183,36 @@ public class BookServiceImpl implements BookService {
}
@Override
public List<BookVO> searchByPage(BookSP params, int page, int pageSize) {
PageHelper.startPage(page, pageSize);
public PageInfo searchByPage(BookSP params, int page, int pageSize) {
if (params.getUpdatePeriod() != null) {
long cur = System.currentTimeMillis();
long period = params.getUpdatePeriod() * 24 * 3600 * 1000;
long time = cur - period;
params.setUpdateTimeMin(new Date(time));
}
if (esEnable == 1) {
try {
return searchService.searchBook(params,page,pageSize);
}catch (Exception e){
log.error(e.getMessage(),e);
}
}
PageHelper.startPage(page, pageSize);
if (StringUtils.isNotBlank(params.getSort())) {
OrderByHelper.orderBy(params.getSort() + " desc");
}
return bookMapper.searchByPage(params);
return new PageInfo<>(bookMapper.searchByPage(params));
}
@Override
@ -197,7 +227,7 @@ public class BookServiceImpl implements BookService {
@Override
public Book queryBookDetail(Long bookId) {
SelectStatementProvider selectStatement = select(id, catName, catId, picUrl, bookName, authorId, authorName, bookDesc, bookStatus, visitCount, wordCount, lastIndexId, lastIndexName, lastIndexUpdateTime,score,status)
SelectStatementProvider selectStatement = select(book.allColumns())
.from(book)
.where(id, isEqualTo(bookId))
.build()
@ -206,12 +236,12 @@ public class BookServiceImpl implements BookService {
}
@Override
public List<BookIndex> queryIndexList(Long bookId,String orderBy, Integer limit) {
public List<BookIndex> queryIndexList(Long bookId, String orderBy, Integer page, Integer pageSize) {
if (StringUtils.isNotBlank(orderBy)) {
OrderByHelper.orderBy(orderBy);
}
if(limit != null){
PageHelper.startPage(1,limit);
if (page != null && pageSize != null) {
PageHelper.startPage(page, pageSize);
}
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip)
@ -223,6 +253,7 @@ public class BookServiceImpl implements BookService {
return bookIndexMapper.selectMany(selectStatement);
}
@Override
public BookIndex queryBookIndex(Long bookIndexId) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip)
@ -315,9 +346,8 @@ public class BookServiceImpl implements BookService {
}
@Override
public void addVisitCount(Long bookId) {
bookMapper.addVisitCount(bookId);
public void addVisitCount(Long bookId, Integer visitCount) {
bookMapper.addVisitCount(bookId,visitCount);
}
@Override
@ -409,7 +439,6 @@ public class BookServiceImpl implements BookService {
}
@Override
public Long queryIdByNameAndAuthor(String bookName, String author) {
//查询小说ID
@ -438,14 +467,14 @@ public class BookServiceImpl implements BookService {
}
@Override
public List<Book> queryNetworkPicBooks(Integer limit, Integer offset) {
return bookMapper.queryNetworkPicBooks(limit,offset);
public List<Book> queryNetworkPicBooks(String localPicPrefix, Integer limit) {
return bookMapper.queryNetworkPicBooks(localPicPrefix,limit);
}
@Override
public void updateBookPicToLocal(String picUrl, Long bookId) {
picUrl = FileUtil.network2Local(picUrl,picSavePath, Constants.LOCAL_PIC_PREFIX);
picUrl = fileService.transFile(picUrl, picSavePath);
bookMapper.update(update(book)
.set(BookDynamicSqlSupport.picUrl)
@ -463,7 +492,7 @@ public class BookServiceImpl implements BookService {
PageHelper.startPage(page, pageSize);
SelectStatementProvider selectStatement = select(id, bookName, visitCount, lastIndexName, status)
SelectStatementProvider selectStatement = select(id, bookName, picUrl, catName, visitCount, yesterdayBuy, lastIndexUpdateTime, updateTime, wordCount, lastIndexName, status)
.from(book)
.where(authorId, isEqualTo(authorService.queryAuthor(userId).getId()))
.orderBy(BookDynamicSqlSupport.createTime.descending())
@ -479,7 +508,8 @@ public class BookServiceImpl implements BookService {
if (queryIdByNameAndAuthor(book.getBookName(), penName) != null) {
//该作者发布过此书名的小说
throw new BusinessException(ResponseStatus.BOOKNAME_EXISTS);
};
}
;
book.setAuthorName(penName);
book.setAuthorId(authorId);
book.setVisitCount(0L);
@ -503,9 +533,9 @@ public class BookServiceImpl implements BookService {
.render(RenderingStrategies.MYBATIS3));
}
@Transactional
@Transactional(rollbackFor = Exception.class)
@Override
public void addBookContent(Long bookId, String indexName, String content, Long authorId) {
public void addBookContent(Long bookId, String indexName, String content, Byte isVip, Long authorId) {
Book book = queryBookDetail(bookId);
if (!authorId.equals(book.getAuthorId())) {
@ -541,7 +571,7 @@ public class BookServiceImpl implements BookService {
lastBookIndex.setIndexName(indexName);
lastBookIndex.setIndexNum(indexNum);
lastBookIndex.setBookId(bookId);
lastBookIndex.setIsVip(book.getStatus());
lastBookIndex.setIsVip(isVip);
lastBookIndex.setCreateTime(currentDate);
lastBookIndex.setUpdateTime(currentDate);
bookIndexMapper.insertSelective(lastBookIndex);
@ -553,8 +583,236 @@ public class BookServiceImpl implements BookService {
bookContentMapper.insertSelective(bookContent);
}
@Override
public List<Book> queryBookByUpdateTimeByPage(Date startDate, int limit) {
return bookMapper.selectMany(select(book.allColumns())
.from(book)
.where(updateTime, isGreaterThan(startDate))
.orderBy(updateTime)
.limit(limit)
.build()
.render(RenderingStrategies.MYBATIS3));
}
@Override
public List<Book> queryBookList(Long authorId) {
return bookMapper.selectMany(select(id, bookName)
.from(book)
.where(BookDynamicSqlSupport.authorId,isEqualTo(authorId))
.build()
.render(RenderingStrategies.MYBATIS3));
}
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteIndex(Long indexId, Long authorId) {
//查询小说章节表信息
List<BookIndex> bookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount)
.from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategy.MYBATIS3));
if (bookIndices.size() > 0) {
BookIndex bookIndex = bookIndices.get(0);
//获取小说ID
Long bookId = bookIndex.getBookId();
//查询小说表信息
List<Book> books = bookMapper.selectMany(
select(wordCount, BookDynamicSqlSupport.authorId)
.from(book)
.where(id, isEqualTo(bookId))
.build()
.render(RenderingStrategy.MYBATIS3));
if (books.size() > 0) {
Book book = books.get(0);
int wordCount = book.getWordCount();
//作者ID相同表明该小说是登录用户发布可以删除
if (book.getAuthorId().equals(authorId)) {
//删除目录表和内容表记录
bookIndexMapper.deleteByPrimaryKey(indexId);
bookContentMapper.delete(deleteFrom(bookContent).where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId)).build()
.render(RenderingStrategies.MYBATIS3));
//更新总字数
wordCount = wordCount - bookIndex.getWordCount();
//更新最新章节
Long lastIndexId = null;
String lastIndexName = null;
Date lastIndexUpdateTime = null;
List<BookIndex> lastBookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.createTime)
.from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.orderBy(BookIndexDynamicSqlSupport.indexNum.descending())
.limit(1)
.build()
.render(RenderingStrategy.MYBATIS3));
if (lastBookIndices.size() > 0) {
BookIndex lastBookIndex = lastBookIndices.get(0);
lastIndexId = lastBookIndex.getId();
lastIndexName = lastBookIndex.getIndexName();
lastIndexUpdateTime = lastBookIndex.getCreateTime();
}
//更新小说主表信息
bookMapper.update(update(BookDynamicSqlSupport.book)
.set(BookDynamicSqlSupport.wordCount)
.equalTo(wordCount)
.set(updateTime)
.equalTo(new Date())
.set(BookDynamicSqlSupport.lastIndexId)
.equalTo(lastIndexId)
.set(BookDynamicSqlSupport.lastIndexName)
.equalTo(lastIndexName)
.set(BookDynamicSqlSupport.lastIndexUpdateTime)
.equalTo(lastIndexUpdateTime)
.where(id, isEqualTo(bookId))
.build()
.render(RenderingStrategies.MYBATIS3));
}
}
}
}
@Override
public void updateIndexName(Long indexId, String indexName, Long authorId) {
//查询小说章节表信息
List<BookIndex> bookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount)
.from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategy.MYBATIS3));
if (bookIndices.size() > 0) {
BookIndex bookIndex = bookIndices.get(0);
//获取小说ID
Long bookId = bookIndex.getBookId();
//查询小说表信息
List<Book> books = bookMapper.selectMany(
select(wordCount, BookDynamicSqlSupport.authorId)
.from(book)
.where(id, isEqualTo(bookId))
.build()
.render(RenderingStrategy.MYBATIS3));
if (books.size() > 0) {
Book book = books.get(0);
//作者ID相同表明该小说是登录用户发布可以修改
if (book.getAuthorId().equals(authorId)) {
bookIndexMapper.update(
update(BookIndexDynamicSqlSupport.bookIndex)
.set(BookIndexDynamicSqlSupport.indexName)
.equalTo(indexName)
.set(BookIndexDynamicSqlSupport.updateTime)
.equalTo(new Date())
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId))
.build()
.render(RenderingStrategy.MYBATIS3));
}
}
}
}
@Override
public String queryIndexContent(Long indexId, Long authorId) {
//查询小说章节表信息
List<BookIndex> bookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount)
.from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategy.MYBATIS3));
if (bookIndices.size() > 0) {
BookIndex bookIndex = bookIndices.get(0);
//获取小说ID
Long bookId = bookIndex.getBookId();
//查询小说表信息
List<Book> books = bookMapper.selectMany(
select(wordCount, BookDynamicSqlSupport.authorId)
.from(book)
.where(id, isEqualTo(bookId))
.build()
.render(RenderingStrategy.MYBATIS3));
if (books.size() > 0) {
Book book = books.get(0);
//作者ID相同表明该小说是登录用户发布
if (book.getAuthorId().equals(authorId)) {
return bookContentMapper.selectMany(
select(content)
.from(bookContent)
.where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId))
.limit(1)
.build().render(RenderingStrategy.MYBATIS3))
.get(0).getContent();
}
}
}
return "";
}
@Transactional(rollbackFor = Exception.class)
@Override
public void updateBookContent(Long indexId, String indexName, String content, Long authorId) {
//查询小说章节表信息
List<BookIndex> bookIndices = bookIndexMapper.selectMany(
select(BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.wordCount)
.from(bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId)).build().render(RenderingStrategy.MYBATIS3));
if (bookIndices.size() > 0) {
BookIndex bookIndex = bookIndices.get(0);
//获取小说ID
Long bookId = bookIndex.getBookId();
//查询小说表信息
List<Book> books = bookMapper.selectMany(
select(wordCount, BookDynamicSqlSupport.authorId)
.from(book)
.where(id, isEqualTo(bookId))
.build()
.render(RenderingStrategy.MYBATIS3));
if (books.size() > 0) {
Book book = books.get(0);
//作者ID相同表明该小说是登录用户发布可以修改
if (book.getAuthorId().equals(authorId)) {
Date currentDate = new Date();
int wordCount = content.length();
//更新小说目录表
int update = bookIndexMapper.update(
update(BookIndexDynamicSqlSupport.bookIndex)
.set(BookIndexDynamicSqlSupport.indexName)
.equalTo(indexName)
.set(BookIndexDynamicSqlSupport.wordCount)
.equalTo(wordCount)
.set(BookIndexDynamicSqlSupport.updateTime)
.equalTo(currentDate)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(indexId))
.build().render(RenderingStrategy.MYBATIS3));
//更新小说内容表
bookContentMapper.update(
update(BookContentDynamicSqlSupport.bookContent)
.set(BookContentDynamicSqlSupport.content)
.equalTo(content)
.where(BookContentDynamicSqlSupport.indexId, isEqualTo(indexId))
.build().render(RenderingStrategy.MYBATIS3));
}
}
}
}
}

View File

@ -0,0 +1,60 @@
package com.java2nb.novel.service.impl;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.core.utils.FileUtil;
import com.java2nb.novel.service.FileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
/**
* @author 11797
*/
@Service
@RequiredArgsConstructor
@Slf4j
@ConditionalOnProperty(prefix = "pic.save", name = "storage", havingValue = "fastDfs")
public class FastDfsFileServiceImpl implements FileService {
private final FastFileStorageClient storageClient;
@Value("${fdfs.webUrl}")
private String webUrl;
@Override
public String transFile(String picSrc, String picSavePath) {
File file;
String filePath = FileUtil.network2Local(picSrc, picSavePath, Constants.LOCAL_PIC_PREFIX);
if (filePath.contains(Constants.LOCAL_PIC_PREFIX)) {
file = new File(picSavePath + filePath);
} else {
//默认图片不存储
return filePath;
}
try {
FileInputStream inputStream = new FileInputStream(file);
StorePath storePath = storageClient.uploadFile(inputStream, file.length(),
FilenameUtils.getExtension(file.getName()), null);
//这里额外加上LOCAL_PIC_PREFIX路径表明该图片是个人资源而不是爬虫爬取的网络资源不需要再次进行转换
// 实际访问时再通过nginx的rewite指令来重写路径去掉LOCAL_PIC_PREFIX
return webUrl+Constants.LOCAL_PIC_PREFIX+storePath.getFullPath();
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
//删除
file.delete();
}
return "/images/default.gif";
}
}

View File

@ -40,7 +40,7 @@ public class FriendLinkServiceImpl implements FriendLinkService {
.build()
.render(RenderingStrategies.MYBATIS3);
result = friendLinkMapper.selectMany(selectStatement);
cacheService.setObject(CacheKey.INDEX_LINK_KEY,result);
cacheService.setObject(CacheKey.INDEX_LINK_KEY,result,60 * 60 * 24);
}
return result;
}

View File

@ -0,0 +1,23 @@
package com.java2nb.novel.service.impl;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.core.utils.FileUtil;
import com.java2nb.novel.service.FileService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
/**
* @author 11797
*/
@Service
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "pic.save", name = "storage", havingValue = "local")
public class LocalFileServiceImpl implements FileService {
@Override
public String transFile(String picSrc, String picSavePath){
return FileUtil.network2Local(picSrc, picSavePath, Constants.LOCAL_PIC_PREFIX);
}
}

View File

@ -42,7 +42,7 @@ public class NewsServiceImpl implements NewsService {
.build()
.render(RenderingStrategies.MYBATIS3);
result = newsMapper.selectMany(selectStatement);
cacheService.setObject(CacheKey.INDEX_NEWS_KEY,result);
cacheService.setObject(CacheKey.INDEX_NEWS_KEY,result,60 * 60 * 12);
}
return result;
}

View File

@ -0,0 +1,76 @@
package com.java2nb.novel.service.impl;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.CannedAccessControlList;
import com.aliyun.oss.model.CreateBucketRequest;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import com.java2nb.novel.core.config.OssProperties;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.core.utils.FileUtil;
import com.java2nb.novel.service.FileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import java.io.File;
/**
* @author 11797
*/
@Service
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "pic.save", name = "storage", havingValue = "OSS")
@Slf4j
public class OssFileServiceImpl implements FileService {
private final OssProperties ossProperties;
@Override
public String transFile(String picSrc, String picSavePath) {
File file;
String filePath = FileUtil.network2Local(picSrc, picSavePath, Constants.LOCAL_PIC_PREFIX);
if (filePath.contains(Constants.LOCAL_PIC_PREFIX)) {
file = new File(picSavePath+filePath);
} else {
//默认图片不存储
return filePath;
}
filePath = filePath.replaceFirst(picSavePath,"");
filePath = filePath.startsWith("/") ? filePath.replaceFirst("/","") : filePath;
OSSClient ossClient = new OSSClient(ossProperties.getEndpoint(), ossProperties.getKeyId(), ossProperties.getKeySecret());
try {
//容器不存在,就创建
if (!ossClient.doesBucketExist(ossProperties.getBucketName())) {
ossClient.createBucket(ossProperties.getBucketName());
CreateBucketRequest createBucketRequest = new CreateBucketRequest(ossProperties.getBucketName());
createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
ossClient.createBucket(createBucketRequest);
}
//上传文件
PutObjectResult result = ossClient.putObject(new PutObjectRequest(ossProperties.getBucketName(), filePath, file));
//设置权限 这里是公开读
ossClient.setBucketAcl(ossProperties.getBucketName(), CannedAccessControlList.PublicRead);
if(result != null) {
return ossProperties.getWebUrl() + "/" + filePath;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
//关闭
ossClient.shutdown();
file.delete();
}
return "/images/default.gif";
}
}

View File

@ -0,0 +1,202 @@
package com.java2nb.novel.service.impl;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.core.enums.ResponseStatus;
import com.java2nb.novel.core.exception.BusinessException;
import com.java2nb.novel.core.utils.StringUtil;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.search.BookSP;
import com.java2nb.novel.service.SearchService;
import com.java2nb.novel.vo.EsBookVO;
import io.searchbox.client.JestClient;
import io.searchbox.core.*;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author 11797
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class SearchServiceImpl implements SearchService {
private final String INDEX = "novel";
private final String TYPE = "book";
private final JestClient jestClient;
@Override
@SneakyThrows
public void importToEs(Book book) {
//导入到ES
EsBookVO esBookVO = new EsBookVO();
BeanUtils.copyProperties(book, esBookVO, "lastIndexUpdateTime");
esBookVO.setLastIndexUpdateTime(new SimpleDateFormat("yyyy/MM/dd HH:mm").format(book.getLastIndexUpdateTime()));
Index action = new Index.Builder(esBookVO).index(INDEX).type(TYPE).id(book.getId().toString()).build();
jestClient.execute(action);
}
@SneakyThrows
@Override
public PageInfo searchBook(BookSP params, int page, int pageSize) {
List<EsBookVO> bookList = new ArrayList<>(0);
//使用搜索引擎搜索
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
// 构造查询哪个字段
if (StringUtils.isNoneBlank(params.getKeyword())) {
boolQueryBuilder = boolQueryBuilder.must(QueryBuilders.queryStringQuery(params.getKeyword()));
}
// 作品方向
if (params.getWorkDirection() != null) {
boolQueryBuilder.filter(QueryBuilders.termQuery("workDirection", params.getWorkDirection()));
}
// 分类
if (params.getCatId() != null) {
boolQueryBuilder.filter(QueryBuilders.termQuery("catId", params.getCatId()));
}
if (params.getBookStatus() != null) {
boolQueryBuilder.filter(QueryBuilders.termQuery("bookStatus", params.getBookStatus()));
}
if (params.getWordCountMin() == null) {
params.setWordCountMin(0);
}
if (params.getWordCountMax() == null) {
params.setWordCountMax(Integer.MAX_VALUE);
}
boolQueryBuilder.filter(QueryBuilders.rangeQuery("wordCount").gte(params.getWordCountMin()).lte(params.getWordCountMax()));
if (params.getUpdateTimeMin() != null) {
boolQueryBuilder.filter(QueryBuilders.rangeQuery("lastIndexUpdateTime").gte(new SimpleDateFormat("yyyy/MM/dd HH:mm").format(params.getUpdateTimeMin())));
}
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(boolQueryBuilder);
Count count = new Count.Builder().addIndex(INDEX).addType(TYPE)
.query(searchSourceBuilder.toString()).build();
CountResult results = jestClient.execute(count);
Double total = results.getCount();
// 高亮字段
HighlightBuilder highlightBuilder = new HighlightBuilder();
highlightBuilder.field("authorName");
highlightBuilder.field("bookName");
highlightBuilder.field("bookDesc");
highlightBuilder.field("lastIndexName");
highlightBuilder.field("catName");
highlightBuilder.preTags("<span style='color:red'>").postTags("</span>");
highlightBuilder.fragmentSize(20000);
searchSourceBuilder.highlighter(highlightBuilder);
//设置排序
if (params.getSort() != null) {
searchSourceBuilder.sort(StringUtil.camelName(params.getSort()), SortOrder.DESC);
}
// 设置分页
searchSourceBuilder.from((page - 1) * pageSize);
searchSourceBuilder.size(pageSize);
// 构建Search对象
Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex(INDEX).addType(TYPE).build();
log.debug(search.toString());
SearchResult result;
result = jestClient.execute(search);
log.debug(result.getJsonString());
if (result.isSucceeded()) {
Map resultMap = new ObjectMapper().readValue(result.getJsonString(), Map.class);
if (resultMap.get("hits") != null) {
Map hitsMap = (Map) resultMap.get("hits");
if (hitsMap.size() > 0 && hitsMap.get("hits") != null) {
List hitsList = (List) hitsMap.get("hits");
if (hitsList.size() > 0 && result.getSourceAsString() != null) {
JavaType jt = new ObjectMapper().getTypeFactory().constructParametricType(ArrayList.class, EsBookVO.class);
bookList = new ObjectMapper().readValue("[" + result.getSourceAsString() + "]", jt);
if (bookList != null) {
for (int i = 0; i < bookList.size(); i++) {
hitsMap = (Map) hitsList.get(i);
Map highlightMap = (Map) hitsMap.get("highlight");
if (highlightMap != null && highlightMap.size() > 0) {
List<String> authorNameList = (List<String>) highlightMap.get("authorName");
if (authorNameList != null && authorNameList.size() > 0) {
bookList.get(i).setAuthorName(authorNameList.get(0));
}
List<String> bookNameList = (List<String>) highlightMap.get("bookName");
if (bookNameList != null && bookNameList.size() > 0) {
bookList.get(i).setBookName(bookNameList.get(0));
}
List<String> bookDescList = (List<String>) highlightMap.get("bookDesc");
if (bookDescList != null && bookDescList.size() > 0) {
bookList.get(i).setBookDesc(bookDescList.get(0));
}
List<String> lastIndexNameList = (List<String>) highlightMap.get("lastIndexName");
if (lastIndexNameList != null && lastIndexNameList.size() > 0) {
bookList.get(i).setLastIndexName(lastIndexNameList.get(0));
}
List<String> catNameList = (List<String>) highlightMap.get("catName");
if (catNameList != null && catNameList.size() > 0) {
bookList.get(i).setCatName(catNameList.get(0));
}
}
}
}
}
}
}
PageInfo<EsBookVO> pageInfo = new PageInfo<>(bookList);
pageInfo.setTotal(total.longValue());
pageInfo.setPageNum(page);
pageInfo.setPageSize(pageSize);
return pageInfo;
}
throw new BusinessException(ResponseStatus.ES_SEARCH_FAIL);
}
}

View File

@ -303,6 +303,51 @@ public class UserServiceImpl implements UserService {
.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));
}
@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));
}
@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));
}
@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));
}

View File

@ -0,0 +1,85 @@
package com.java2nb.novel.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.java2nb.novel.entity.Book;
import lombok.Data;
import javax.annotation.Generated;
import java.io.Serializable;
import java.util.Date;
/**
* @author Administrator
*/
@Data
public class EsBookVO {
private Long id;
private Byte workDirection;
private Integer catId;
private String catName;
private String picUrl;
private String bookName;
private Long authorId;
private String authorName;
private String bookDesc;
private Float score;
private Byte bookStatus;
private Long visitCount;
private Integer wordCount;
private Integer commentCount;
private Long lastIndexId;
private String lastIndexName;
private String lastIndexUpdateTime;
private Byte isVip;
private Byte status;
private Integer crawlSourceId;
private String crawlBookId;
private Byte crawlIsStop;
}

View File

@ -0,0 +1,16 @@
#FastDfs的配置 ====================================
#读取inputsream阻塞时间
fdfs:
connect-timeout: 600
so-timeout: 1500
#tracker地址
trackerList: 127.0.0.1:22122
#缩略图配置
thumbImage:
height: 150
width: 150
#通过nginx 访问地址
webUrl: http://127.0.0.1/
#获取连接池最大数量
pool.max-total: 200

View File

@ -0,0 +1,9 @@
#OSS
novel:
file:
endpoint: oss-cn-shenzhen.aliyuncs.com #不同的服务器地址不同
key-id: dhjjrue6767778878 #去OSS控制台获取
key-secret: dssdkkrkelrkellk44554 #去OSS控制台获取
bucket-name: novel #这个自己创建bucket时的命名控制台创建也行代码创建也行
file-host: pic #文件路径
web-url: https://xxyimg.oss-cn-hangzhou.aliyuncs.com #OSS文件的web访问地址

View File

@ -4,7 +4,30 @@ server:
spring:
profiles:
active: dev
include: alipay
include: alipay,oss,fastdfs
rabbitmq:
enable: 0
host: 127.0.0.1
username: guest
password: guest
virtual-host: /novel-plus
template:
# 缺省的交换机名称此处配置后发送消息如果不指定交换机就会使用这个
exchange: novel.exchange
publisher-confirms: false
elasticsearch:
#是否开启搜索引擎1开启0不开启
enable: 0
jest:
uris: http://127.0.0.1:9200
redisson:
singleServerConfig:
address: 127.0.0.1:6379
jwt:
secret: novel!#20191230
@ -26,4 +49,11 @@ xss:
urlPatterns: /book/addBookComment,/user/addFeedBack,/author/addBook,/author/addBookContent,/author/register.html
author:
income:
#税率(扣税后所得比率)
tax-rate: 0.9
#分佣比例
share-proportion: 0.7
#兑换比率(人民币)
exchange-proportion: 0.01

View File

@ -0,0 +1,5 @@
#网站配置
#网站名
website.name=小说精品屋
#PC站网站域名
website.domain=www.java2nb.com

View File

@ -34,8 +34,9 @@
</select>
<update id="addVisitCount" parameterType="long">
update book set visit_count = visit_count + 1 where id = #{bookId}
<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">
@ -54,8 +55,9 @@
<select id="queryNetworkPicBooks" resultType="com.java2nb.novel.entity.Book">
select
id,pic_url from book
where pic_url like 'http://%' or pic_url like 'https://%'
limit #{offset},#{limit}
where pic_url like 'http%'
and pic_url not like concat('%',#{localPicPrefix},'%')
limit #{limit}
</select>
<select id="selectIdsByScoreAndRandom" parameterType="int" resultType="com.java2nb.novel.entity.Book">

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,217 @@
jQuery.extend({
createUploadIframe: function(id, uri)
{
//create frame
var frameId = 'jUploadFrame' + id;
var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"';
if(window.ActiveXObject)
{
if(typeof uri== 'boolean'){
iframeHtml += ' src="' + 'javascript:false' + '"';
}
else if(typeof uri== 'string'){
iframeHtml += ' src="' + uri + '"';
}
}
iframeHtml += ' />';
jQuery(iframeHtml).appendTo(document.body);
return jQuery('#' + frameId).get(0);
},
createUploadForm: function(id,fileElementId,data,fileElement)
{
//create form
var formId = 'jUploadForm' + id;
var fileId = 'jUploadFile' + id;
var form = jQuery('<form action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
if(data)
{
for(var i in data)
{
jQuery('<input type="hidden" name="' + i + '" value="' + data[i] + '" />').appendTo(form);
}
}
var oldElement;
if(fileElement == null)
oldElement = jQuery('#' + fileElementId);
else
oldElement = fileElement;
var newElement = jQuery(oldElement).clone();
jQuery(oldElement).attr('id', fileId);
jQuery(oldElement).before(newElement);
jQuery(oldElement).appendTo(form);
//set attributes
jQuery(form).css('position', 'absolute');
jQuery(form).css('top', '-1200px');
jQuery(form).css('left', '-1200px');
jQuery(form).appendTo('body');
return form;
},
ajaxFileUpload: function(s) {
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
s = jQuery.extend({}, jQuery.ajaxSettings, s);
var id = new Date().getTime()
var form = jQuery.createUploadForm(id, s.fileElementId, (typeof(s.data)=='undefined'?false:s.data),s.fileElement);
var io = jQuery.createUploadIframe(id, s.secureuri);
var frameId = 'jUploadFrame' + id;
var formId = 'jUploadForm' + id;
// Watch for a new set of requests
if ( s.global && ! jQuery.active++ )
{
jQuery.event.trigger( "ajaxStart" );
}
var requestDone = false;
// Create the request object
var xml = {}
if ( s.global )
jQuery.event.trigger("ajaxSend", [xml, s]);
// Wait for a response to come back
var uploadCallback = function(isTimeout)
{
var io = document.getElementById(frameId);
try
{
if(io.contentWindow)
{
xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
}else if(io.contentDocument)
{
xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
}
}catch(e)
{
jQuery.handleError(s, xml, null, e);
}
if ( xml || isTimeout == "timeout")
{
requestDone = true;
var status;
try {
status = isTimeout != "timeout" ? "success" : "error";
// Make sure that the request was successful or notmodified
if ( status != "error" )
{
// process the data (runs the xml through httpData regardless of callback)
var data = jQuery.uploadHttpData( xml, s.dataType );
// If a local callback was specified, fire it and pass it the data
if ( s.success )
s.success( data, status );
// Fire the global callback
if( s.global )
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
} else
jQuery.handleError(s, xml, status);
} catch(e)
{
status = "error";
jQuery.handleError(s, xml, status, e);
}
// The request was completed
if( s.global )
jQuery.event.trigger( "ajaxComplete", [xml, s] );
// Handle the global AJAX counter
if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
// Process result
if ( s.complete )
s.complete(xml, status);
jQuery(io).unbind()
setTimeout(function()
{ try
{
jQuery(io).remove();
jQuery(form).remove();
} catch(e)
{
jQuery.handleError(s, xml, null, e);
}
}, 100)
xml = null
}
}
// Timeout checker
if ( s.timeout > 0 )
{
setTimeout(function(){
// Check to see if the request is still happening
if( !requestDone ) uploadCallback( "timeout" );
}, s.timeout);
}
try
{
var form = jQuery('#' + formId);
jQuery(form).attr('action', s.url);
jQuery(form).attr('method', 'POST');
jQuery(form).attr('target', frameId);
if(form.encoding)
{
jQuery(form).attr('encoding', 'multipart/form-data');
}
else
{
jQuery(form).attr('enctype', 'multipart/form-data');
}
jQuery(form).submit();
} catch(e)
{
jQuery.handleError(s, xml, null, e);
}
jQuery('#' + frameId).load(uploadCallback);
return {abort: function(){
try
{
jQuery('#' + frameId).remove();
jQuery(form).remove();
}
catch(e){}
}};
},
uploadHttpData: function( r, type ) {
var data = !type;
data = type == "xml" || data ? r.responseXML : r.responseText;
// If the type is "script", eval it in global context
if ( type == "script" )
jQuery.globalEval( data );
// Get the JavaScript object, if JSON is used.
if ( type == "json" )
data = jQuery.parseJSON(jQuery(data).text());
// evaluate scripts within html
if ( type == "html" )
jQuery("<div>").html(data).evalScripts();
return data;
},
handleError: function( s, xml, status, e ) {
// If a local callback was specified, fire it
if ( s.error )
s.error( xml, status, e );
// Fire the global callback
if ( s.global )
jQuery.event.trigger( "ajaxError", [xml, s, e] );
}
});

View File

@ -238,17 +238,17 @@
if (preId > 0) {
location.href = '/book/' + bid + '/' + preId + '.html';
} else {
location.href = '/book/chapterlist-' + bid + '.html';
location.href = '/book/indexList-' + bid + '.html';
}
} else if (e.keyCode == 39) {
if (nextId > 0) {
location.href = '/book/' + bid + '/' + nextId + '.html';
} else {
location.href = '/book/chapterlist-' + bid + '.html';
location.href = '/book/indexList-' + bid + '.html';
}
}
});
BookDetail.SetReadHistory(bid, cid, crank);
//BookDetail.SetReadHistory(bid, cid, crank);
},
SetReadHistory: function (bid, cid, crank) {
var strHistory = jQuery.cookie("wapviewhistory");

View File

@ -0,0 +1,16 @@
//格式化时间函数
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};

View File

@ -2,7 +2,7 @@
<!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 th:replace="common/header :: common_head(~{::title},~{::meta},~{::link})">
<head th:replace="common/header :: common_head(~{::title},~{::meta},~{::link},~{})">
<title th:text="'联系我们_'+#{website.name}"></title>
<meta name="keywords" content="联系我们,小说,小说网,言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,原创网络文学" />
<meta name="description" th:content="#{website.name}+'小说每日更新小说连载,小说排行榜,提供言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,首发小说,最新章节免费小说阅读,精彩尽在'+#{website.name}+'小说!'" />

View File

@ -2,7 +2,7 @@
<!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 th:replace="common/header :: common_head(~{::title},~{::meta},~{::link})">
<head th:replace="common/header :: common_head(~{::title},~{::meta},~{::link},~{})">
<title th:text="'版权声明_'+#{website.name}"></title>
<meta name="keywords" content="版权声明,小说,小说网,言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,原创网络文学" />
<meta name="description" th:content="#{website.name}+'小说每日更新小说连载,小说排行榜,提供言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,首发小说,最新章节免费小说阅读,精彩尽在'+#{website.name}+'小说!'" />

View File

@ -1,6 +1,6 @@
<!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 th:replace="common/header :: common_head(~{::title},~{::meta},~{::link})">
<head th:replace="common/header :: common_head(~{::title},~{::meta},~{::link},~{})">
<title th:text="'关于我们_'+#{website.name}"></title>
<meta name="keywords" content="关于我们,小说,小说网,言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,原创网络文学" />
<meta name="description" th:content="#{website.name}+'每日更新小说连载,小说排行榜,提供言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,首发小说,最新章节免费小说阅读,精彩尽在'+#{website.name}+'小说!'" />

View File

@ -1,7 +1,7 @@
<!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 th:replace="common/header :: common_head(~{::title},~{::meta},~{::link})">
<head th:replace="common/header :: common_head(~{::title},~{::meta},~{::link},~{})">
<title th:text="'新闻公共_'+#{website.name}"></title>
<meta name="keywords" content="新闻公告,小说,小说网,言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,原创网络文学"/>
<meta name="description"

View File

@ -1,6 +1,6 @@
<!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 th:replace="common/header :: common_head(~{::title},~{::meta},~{::link})">
<head th:replace="common/header :: common_head(~{::title},~{::meta},~{::link},~{})">
<title th:text="'新闻公告_'+#{website.name}"></title>
<meta name="keywords" content="新闻公告,小说,小说网,言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,原创网络文学"/>
<meta name="description" th:content="#{website.name}+'小说每日更新小说连载,小说排行榜,提供言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,首发小说,最新章节免费小说阅读,精彩尽在'+#{website.name}+'小说!'" />

View File

@ -2,7 +2,7 @@
<!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 th:replace="common/header :: common_head(~{::title},~{::meta},~{::link})">
<head th:replace="common/header :: common_head(~{::title},~{::meta},~{::link},~{})">
<title th:text="'投稿说明_'+#{website.name}"></title>
<meta name="keywords" content="投稿说明,小说,小说网,言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,原创网络文学" />
<meta name="description" th:content="#{website.name}+'小说每日更新小说连载,小说排行榜,提供言情小说,都市小说,玄幻小说,穿越小说,青春小说,总裁豪门小说,网络小说,免费小说,全本小说,首发小说,最新章节免费小说阅读,精彩尽在'+#{website.name}+'小说!'" />

Some files were not shown because too many files have changed in this diff Show More