diff --git a/doc/sql/20210726.sql b/doc/sql/20210726.sql
new file mode 100644
index 00000000..7e56bf6b
--- /dev/null
+++ b/doc/sql/20210726.sql
@@ -0,0 +1 @@
+alter table news add column `read_count` BIGINT NOT NULL DEFAULT '0' COMMENT '阅读量' after content;
\ No newline at end of file
diff --git a/doc/sql/novel_plus.sql b/doc/sql/novel_plus.sql
index c9def487..f8128220 100644
--- a/doc/sql/novel_plus.sql
+++ b/doc/sql/novel_plus.sql
@@ -1838,4 +1838,6 @@ INSERT INTO `sys_role_menu`(`id`, `role_id`, `menu_id`) VALUES (4888, 1, 234);
delete from sys_menu where menu_id = 202;
-INSERT INTO crawl_source(`id`, `source_name`, `crawl_rule`, `source_status`, `create_time`, `update_time`) VALUES (16, 'i笔趣阁', '{\"bookListUrl\":\"http://m.ibiquge.net/xclass/{catId}/{page}.html\",\"catIdRule\":{\"catId1\":\"1\",\"catId2\":\"2\",\"catId3\":\"3\",\"catId4\":\"4\",\"catId5\":\"6\",\"catId6\":\"5\",\"catId7\":\"7\"},\"bookIdPatten\":\"href=\\\"/(\\\\d+_\\\\d+)/\\\"\",\"pagePatten\":\"value=\\\"(\\\\d+)/\\\\d+\\\"\",\"totalPagePatten\":\"value=\\\"\\\\d+/(\\\\d+)\\\"\",\"bookDetailUrl\":\"http://m.ibiquge.net/{bookId}/\",\"bookNamePatten\":\"([^/]+) \",\"authorNamePatten\":\"([^/]+) \",\"picUrlPatten\":\" ]+)\\\"\\\\s+onerror=\\\"this.src=\",\"picUrlPrefix\":\"http://m.ibiquge.net\",\"statusPatten\":\">状态:([^/]+)\",\"bookStatusRule\":{\"连载\":0,\"完结\":1},\"visitCountPatten\":\">点击:(\\\\d+)\",\"descStart\":\"
\",\"descEnd\":\"
\",\"bookIndexUrl\":\"http://www.ibiquge.net/{bookId}/\",\"bookIndexStart\":\"正文\",\"indexIdPatten\":\"[^/]+ \",\"indexNamePatten\":\"([^/]+) \",\"bookContentUrl\":\"http://www.ibiquge.net/{bookId}/{indexId}.html\",\"contentStart\":\"\",\"contentEnd\":\"\"}', 0, '2021-02-04 21:31:23', '2021-02-04 21:31:23');
\ No newline at end of file
+INSERT INTO crawl_source(`id`, `source_name`, `crawl_rule`, `source_status`, `create_time`, `update_time`) VALUES (16, 'i笔趣阁', '{\"bookListUrl\":\"http://m.ibiquge.net/xclass/{catId}/{page}.html\",\"catIdRule\":{\"catId1\":\"1\",\"catId2\":\"2\",\"catId3\":\"3\",\"catId4\":\"4\",\"catId5\":\"6\",\"catId6\":\"5\",\"catId7\":\"7\"},\"bookIdPatten\":\"href=\\\"/(\\\\d+_\\\\d+)/\\\"\",\"pagePatten\":\"value=\\\"(\\\\d+)/\\\\d+\\\"\",\"totalPagePatten\":\"value=\\\"\\\\d+/(\\\\d+)\\\"\",\"bookDetailUrl\":\"http://m.ibiquge.net/{bookId}/\",\"bookNamePatten\":\"
([^/]+) \",\"authorNamePatten\":\"
([^/]+) \",\"picUrlPatten\":\"
]+)\\\"\\\\s+onerror=\\\"this.src=\",\"picUrlPrefix\":\"http://m.ibiquge.net\",\"statusPatten\":\">状态:([^/]+)\",\"bookStatusRule\":{\"连载\":0,\"完结\":1},\"visitCountPatten\":\">点击:(\\\\d+)\",\"descStart\":\"
\",\"descEnd\":\"
\",\"bookIndexUrl\":\"http://www.ibiquge.net/{bookId}/\",\"bookIndexStart\":\"正文\",\"indexIdPatten\":\"
[^/]+ \",\"indexNamePatten\":\"
([^/]+) \",\"bookContentUrl\":\"http://www.ibiquge.net/{bookId}/{indexId}.html\",\"contentStart\":\"\",\"contentEnd\":\"
\"}', 0, '2021-02-04 21:31:23', '2021-02-04 21:31:23');
+
+alter table news add column `read_count` BIGINT NOT NULL DEFAULT '0' COMMENT '阅读量' after content;
\ No newline at end of file
diff --git a/novel-common/src/main/java/com/java2nb/novel/entity/News.java b/novel-common/src/main/java/com/java2nb/novel/entity/News.java
index c4972484..c5553494 100644
--- a/novel-common/src/main/java/com/java2nb/novel/entity/News.java
+++ b/novel-common/src/main/java/com/java2nb/novel/entity/News.java
@@ -1,11 +1,9 @@
package com.java2nb.novel.entity;
-
-import javax.annotation.Generated;
-import java.io.Serializable;
import java.util.Date;
+import javax.annotation.Generated;
-public class News implements Serializable {
+public class News {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long id;
@@ -21,6 +19,9 @@ public class News implements Serializable {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private String title;
+ @Generated("org.mybatis.generator.api.MyBatisGenerator")
+ private Long readCount;
+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Date createTime;
@@ -86,6 +87,16 @@ public void setTitle(String title) {
this.title = title == null ? null : title.trim();
}
+ @Generated("org.mybatis.generator.api.MyBatisGenerator")
+ public Long getReadCount() {
+ return readCount;
+ }
+
+ @Generated("org.mybatis.generator.api.MyBatisGenerator")
+ public void setReadCount(Long readCount) {
+ this.readCount = readCount;
+ }
+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public Date getCreateTime() {
return createTime;
diff --git a/novel-common/src/main/java/com/java2nb/novel/mapper/NewsDynamicSqlSupport.java b/novel-common/src/main/java/com/java2nb/novel/mapper/NewsDynamicSqlSupport.java
index 43da731e..7bb23e35 100644
--- a/novel-common/src/main/java/com/java2nb/novel/mapper/NewsDynamicSqlSupport.java
+++ b/novel-common/src/main/java/com/java2nb/novel/mapper/NewsDynamicSqlSupport.java
@@ -25,6 +25,9 @@ public final class NewsDynamicSqlSupport {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn
title = news.title;
+ @Generated("org.mybatis.generator.api.MyBatisGenerator")
+ public static final SqlColumn readCount = news.readCount;
+
@Generated("org.mybatis.generator.api.MyBatisGenerator")
public static final SqlColumn createTime = news.createTime;
@@ -52,6 +55,8 @@ public static final class News extends SqlTable {
public final SqlColumn title = column("title", JDBCType.VARCHAR);
+ public final SqlColumn readCount = column("read_count", JDBCType.BIGINT);
+
public final SqlColumn createTime = column("create_time", JDBCType.TIMESTAMP);
public final SqlColumn createUserId = column("create_user_id", JDBCType.BIGINT);
diff --git a/novel-common/src/main/java/com/java2nb/novel/mapper/NewsMapper.java b/novel-common/src/main/java/com/java2nb/novel/mapper/NewsMapper.java
index 91d3ad50..f5a69167 100644
--- a/novel-common/src/main/java/com/java2nb/novel/mapper/NewsMapper.java
+++ b/novel-common/src/main/java/com/java2nb/novel/mapper/NewsMapper.java
@@ -35,7 +35,7 @@
@Mapper
public interface NewsMapper {
@Generated("org.mybatis.generator.api.MyBatisGenerator")
- BasicColumn[] selectList = BasicColumn.columnList(id, catId, catName, sourceName, title, createTime, createUserId, updateTime, updateUserId, content);
+ BasicColumn[] selectList = BasicColumn.columnList(id, catId, catName, sourceName, title, readCount, createTime, createUserId, updateTime, updateUserId, content);
@Generated("org.mybatis.generator.api.MyBatisGenerator")
@SelectProvider(type=SqlProviderAdapter.class, method="select")
@@ -66,6 +66,7 @@ public interface NewsMapper {
@Result(column="cat_name", property="catName", jdbcType=JdbcType.VARCHAR),
@Result(column="source_name", property="sourceName", jdbcType=JdbcType.VARCHAR),
@Result(column="title", property="title", jdbcType=JdbcType.VARCHAR),
+ @Result(column="read_count", property="readCount", jdbcType=JdbcType.BIGINT),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="create_user_id", property="createUserId", jdbcType=JdbcType.BIGINT),
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
@@ -103,6 +104,7 @@ default int insert(News record) {
.map(catName).toProperty("catName")
.map(sourceName).toProperty("sourceName")
.map(title).toProperty("title")
+ .map(readCount).toProperty("readCount")
.map(createTime).toProperty("createTime")
.map(createUserId).toProperty("createUserId")
.map(updateTime).toProperty("updateTime")
@@ -119,6 +121,7 @@ default int insertMultiple(Collection records) {
.map(catName).toProperty("catName")
.map(sourceName).toProperty("sourceName")
.map(title).toProperty("title")
+ .map(readCount).toProperty("readCount")
.map(createTime).toProperty("createTime")
.map(createUserId).toProperty("createUserId")
.map(updateTime).toProperty("updateTime")
@@ -135,6 +138,7 @@ default int insertSelective(News record) {
.map(catName).toPropertyWhenPresent("catName", record::getCatName)
.map(sourceName).toPropertyWhenPresent("sourceName", record::getSourceName)
.map(title).toPropertyWhenPresent("title", record::getTitle)
+ .map(readCount).toPropertyWhenPresent("readCount", record::getReadCount)
.map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
.map(createUserId).toPropertyWhenPresent("createUserId", record::getCreateUserId)
.map(updateTime).toPropertyWhenPresent("updateTime", record::getUpdateTime)
@@ -177,6 +181,7 @@ static UpdateDSL updateAllColumns(News record, UpdateDSL updateSelectiveColumns(News record, UpdateDSL
-
+
diff --git a/novel-front/src/main/java/com/java2nb/novel/controller/NewsController.java b/novel-front/src/main/java/com/java2nb/novel/controller/NewsController.java
index 930ea6fc..6eec3263 100644
--- a/novel-front/src/main/java/com/java2nb/novel/controller/NewsController.java
+++ b/novel-front/src/main/java/com/java2nb/novel/controller/NewsController.java
@@ -1,12 +1,16 @@
package com.java2nb.novel.controller;
import com.github.pagehelper.PageInfo;
+import com.java2nb.novel.core.bean.PageBean;
import com.java2nb.novel.core.bean.ResultBean;
+import com.java2nb.novel.entity.News;
import com.java2nb.novel.service.NewsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
+import java.util.List;
+
/**
* @author 11797
*/
@@ -22,7 +26,7 @@ public class NewsController {
* 查询首页新闻
* */
@GetMapping("listIndexNews")
- public ResultBean listIndexNews(){
+ public ResultBean> listIndexNews(){
return ResultBean.ok(newsService.listIndexNews());
}
@@ -30,10 +34,19 @@ public ResultBean listIndexNews(){
* 分页查询新闻列表
* */
@GetMapping("listByPage")
- public ResultBean listByPage(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "5") int pageSize){
+ public ResultBean> listByPage(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "5") int pageSize){
return ResultBean.ok(newsService.listByPage(page,pageSize));
}
+ /**
+ * 增加新闻阅读量
+ * */
+ @PostMapping("addReadCount")
+ public ResultBean addReadCount(@RequestParam(value = "newsId") Integer newsId){
+ newsService.addReadCount(newsId);
+ return ResultBean.ok();
+ }
+
}
diff --git a/novel-front/src/main/java/com/java2nb/novel/mapper/FrontNewsMapper.java b/novel-front/src/main/java/com/java2nb/novel/mapper/FrontNewsMapper.java
new file mode 100644
index 00000000..ad706078
--- /dev/null
+++ b/novel-front/src/main/java/com/java2nb/novel/mapper/FrontNewsMapper.java
@@ -0,0 +1,21 @@
+package com.java2nb.novel.mapper;
+
+import com.java2nb.novel.entity.Book;
+import com.java2nb.novel.vo.BookSpVO;
+import com.java2nb.novel.vo.BookVO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author Administrator
+ */
+public interface FrontNewsMapper extends NewsMapper {
+
+ /**
+ * 增加新闻阅读量
+ * @param newsId 新闻ID
+ * */
+ void addReadCount(@Param("newsId") Integer newsId);
+
+}
diff --git a/novel-front/src/main/java/com/java2nb/novel/service/BookService.java b/novel-front/src/main/java/com/java2nb/novel/service/BookService.java
index 87d3d5be..442a582e 100644
--- a/novel-front/src/main/java/com/java2nb/novel/service/BookService.java
+++ b/novel-front/src/main/java/com/java2nb/novel/service/BookService.java
@@ -115,7 +115,8 @@ public interface BookService {
/**
* 增加点击次数
* @param bookId 书籍ID
- * @param visitCount*/
+ * @param visitCount 点击量
+ * */
void addVisitCount(Long bookId, Integer visitCount);
/**
diff --git a/novel-front/src/main/java/com/java2nb/novel/service/NewsService.java b/novel-front/src/main/java/com/java2nb/novel/service/NewsService.java
index 32234397..719a0e53 100644
--- a/novel-front/src/main/java/com/java2nb/novel/service/NewsService.java
+++ b/novel-front/src/main/java/com/java2nb/novel/service/NewsService.java
@@ -32,4 +32,10 @@ public interface NewsService {
* @return 新闻分页数据
* */
PageBean listByPage(int page, int pageSize);
+
+ /**
+ * 增加新闻阅读量
+ * @param newsId 新闻ID
+ * */
+ void addReadCount(Integer newsId);
}
diff --git a/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java b/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java
index 63c2cbe5..76e3fc1e 100644
--- a/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java
+++ b/novel-front/src/main/java/com/java2nb/novel/service/impl/BookServiceImpl.java
@@ -513,7 +513,6 @@ public void addBook(Book book, Long authorId, String penName) {
//该作者发布过此书名的小说
throw new BusinessException(ResponseStatus.BOOKNAME_EXISTS);
}
- ;
book.setAuthorName(penName);
book.setAuthorId(authorId);
book.setVisitCount(0L);
@@ -566,7 +565,7 @@ public void addBookContent(Long bookId, String indexName, String content, Byte i
.render(RenderingStrategies.MYBATIS3));
//计算价格
- int bookPrice = new BigDecimal(wordCount).divide(bookPriceConfig.getWordCount()).multiply(bookPriceConfig.getValue()).intValue();
+ int bookPrice = new BigDecimal(wordCount).multiply(bookPriceConfig.getValue()).divide(bookPriceConfig.getWordCount(),0,BigDecimal.ROUND_DOWN).intValue();
//更新小说目录表
int indexNum = 0;
diff --git a/novel-front/src/main/java/com/java2nb/novel/service/impl/NewsServiceImpl.java b/novel-front/src/main/java/com/java2nb/novel/service/impl/NewsServiceImpl.java
index 0863c73e..ea756781 100644
--- a/novel-front/src/main/java/com/java2nb/novel/service/impl/NewsServiceImpl.java
+++ b/novel-front/src/main/java/com/java2nb/novel/service/impl/NewsServiceImpl.java
@@ -3,6 +3,7 @@
import com.github.pagehelper.PageHelper;
import com.java2nb.novel.core.bean.PageBean;
import com.java2nb.novel.core.utils.BeanUtil;
+import com.java2nb.novel.mapper.FrontNewsMapper;
import com.java2nb.novel.service.NewsService;
import com.java2nb.novel.core.cache.CacheKey;
import com.java2nb.novel.core.cache.CacheService;
@@ -27,7 +28,7 @@
@RequiredArgsConstructor
public class NewsServiceImpl implements NewsService {
- private final NewsMapper newsMapper;
+ private final FrontNewsMapper newsMapper;
private final CacheService cacheService;
@@ -72,4 +73,9 @@ public PageBean listByPage(int page, int pageSize) {
pageBean.setList(BeanUtil.copyList(news,NewsVO.class));
return pageBean;
}
+
+ @Override
+ public void addReadCount(Integer newsId) {
+ newsMapper.addReadCount(newsId);
+ }
}
diff --git a/novel-front/src/main/resources/mybatis/mapping/NewsMapper.xml b/novel-front/src/main/resources/mybatis/mapping/NewsMapper.xml
new file mode 100644
index 00000000..a70eabd3
--- /dev/null
+++ b/novel-front/src/main/resources/mybatis/mapping/NewsMapper.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+ update news set read_count = read_count + 1
+ where id = #{newsId}
+
+
\ No newline at end of file
diff --git a/novel-front/src/main/resources/templates/about/news_info.html b/novel-front/src/main/resources/templates/about/news_info.html
index 1b07a917..81f4e873 100644
--- a/novel-front/src/main/resources/templates/about/news_info.html
+++ b/novel-front/src/main/resources/templates/about/news_info.html
@@ -10,6 +10,7 @@
+
@@ -19,7 +20,7 @@
-
来源:[[${news.sourceName}]]
+
来源:[[${news.sourceName}]]
@@ -33,4 +34,8 @@