mirror of
https://github.com/201206030/novel-plus.git
synced 2025-04-26 17:20:52 +00:00
增加新闻阅读数
This commit is contained in:
parent
b99b6ae4f2
commit
1cffbae495
1
doc/sql/20210726.sql
Normal file
1
doc/sql/20210726.sql
Normal file
@ -0,0 +1 @@
|
||||
alter table news add column `read_count` BIGINT NOT NULL DEFAULT '0' COMMENT '阅读量' after content;
|
@ -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\":\"<span class=\\\"title\\\">([^/]+)</span>\",\"authorNamePatten\":\"<a href=\\\"/author/\\\\d+/\\\">([^/]+)</a>\",\"picUrlPatten\":\"<img src=\\\"([^>]+)\\\"\\\\s+onerror=\\\"this.src=\",\"picUrlPrefix\":\"http://m.ibiquge.net\",\"statusPatten\":\">状态:([^/]+)</li>\",\"bookStatusRule\":{\"连载\":0,\"完结\":1},\"visitCountPatten\":\">点击:(\\\\d+)</li>\",\"descStart\":\"<p class=\\\"review\\\">\",\"descEnd\":\"</p>\",\"bookIndexUrl\":\"http://www.ibiquge.net/{bookId}/\",\"bookIndexStart\":\"正文</dt>\",\"indexIdPatten\":\"<a\\\\s+style=\\\"\\\"\\\\s+href=\\\"/\\\\d+_\\\\d+/(\\\\d+)\\\\.html\\\">[^/]+</a>\",\"indexNamePatten\":\"<a\\\\s+style=\\\"\\\"\\\\s+href=\\\"/\\\\d+_\\\\d+/\\\\d+\\\\.html\\\">([^/]+)</a>\",\"bookContentUrl\":\"http://www.ibiquge.net/{bookId}/{indexId}.html\",\"contentStart\":\"</p>\",\"contentEnd\":\"<div align=\\\"center\\\">\"}', 0, '2021-02-04 21:31:23', '2021-02-04 21:31:23');
|
||||
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\":\"<span class=\\\"title\\\">([^/]+)</span>\",\"authorNamePatten\":\"<a href=\\\"/author/\\\\d+/\\\">([^/]+)</a>\",\"picUrlPatten\":\"<img src=\\\"([^>]+)\\\"\\\\s+onerror=\\\"this.src=\",\"picUrlPrefix\":\"http://m.ibiquge.net\",\"statusPatten\":\">状态:([^/]+)</li>\",\"bookStatusRule\":{\"连载\":0,\"完结\":1},\"visitCountPatten\":\">点击:(\\\\d+)</li>\",\"descStart\":\"<p class=\\\"review\\\">\",\"descEnd\":\"</p>\",\"bookIndexUrl\":\"http://www.ibiquge.net/{bookId}/\",\"bookIndexStart\":\"正文</dt>\",\"indexIdPatten\":\"<a\\\\s+style=\\\"\\\"\\\\s+href=\\\"/\\\\d+_\\\\d+/(\\\\d+)\\\\.html\\\">[^/]+</a>\",\"indexNamePatten\":\"<a\\\\s+style=\\\"\\\"\\\\s+href=\\\"/\\\\d+_\\\\d+/\\\\d+\\\\.html\\\">([^/]+)</a>\",\"bookContentUrl\":\"http://www.ibiquge.net/{bookId}/{indexId}.html\",\"contentStart\":\"</p>\",\"contentEnd\":\"<div align=\\\"center\\\">\"}', 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;
|
@ -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 class News implements Serializable {
|
||||
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;
|
||||
|
@ -25,6 +25,9 @@ public final class NewsDynamicSqlSupport {
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<String> title = news.title;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<Long> readCount = news.readCount;
|
||||
|
||||
@Generated("org.mybatis.generator.api.MyBatisGenerator")
|
||||
public static final SqlColumn<Date> createTime = news.createTime;
|
||||
|
||||
@ -52,6 +55,8 @@ public final class NewsDynamicSqlSupport {
|
||||
|
||||
public final SqlColumn<String> title = column("title", JDBCType.VARCHAR);
|
||||
|
||||
public final SqlColumn<Long> readCount = column("read_count", JDBCType.BIGINT);
|
||||
|
||||
public final SqlColumn<Date> createTime = column("create_time", JDBCType.TIMESTAMP);
|
||||
|
||||
public final SqlColumn<Long> createUserId = column("create_user_id", JDBCType.BIGINT);
|
||||
|
@ -35,7 +35,7 @@ import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
|
||||
@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 @@ public interface NewsMapper {
|
||||
.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 @@ public interface NewsMapper {
|
||||
.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 @@ public interface NewsMapper {
|
||||
.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 @@ public interface NewsMapper {
|
||||
.set(catName).equalTo(record::getCatName)
|
||||
.set(sourceName).equalTo(record::getSourceName)
|
||||
.set(title).equalTo(record::getTitle)
|
||||
.set(readCount).equalTo(record::getReadCount)
|
||||
.set(createTime).equalTo(record::getCreateTime)
|
||||
.set(createUserId).equalTo(record::getCreateUserId)
|
||||
.set(updateTime).equalTo(record::getUpdateTime)
|
||||
@ -191,6 +196,7 @@ public interface NewsMapper {
|
||||
.set(catName).equalToWhenPresent(record::getCatName)
|
||||
.set(sourceName).equalToWhenPresent(record::getSourceName)
|
||||
.set(title).equalToWhenPresent(record::getTitle)
|
||||
.set(readCount).equalToWhenPresent(record::getReadCount)
|
||||
.set(createTime).equalToWhenPresent(record::getCreateTime)
|
||||
.set(createUserId).equalToWhenPresent(record::getCreateUserId)
|
||||
.set(updateTime).equalToWhenPresent(record::getUpdateTime)
|
||||
@ -205,6 +211,7 @@ public interface NewsMapper {
|
||||
.set(catName).equalTo(record::getCatName)
|
||||
.set(sourceName).equalTo(record::getSourceName)
|
||||
.set(title).equalTo(record::getTitle)
|
||||
.set(readCount).equalTo(record::getReadCount)
|
||||
.set(createTime).equalTo(record::getCreateTime)
|
||||
.set(createUserId).equalTo(record::getCreateUserId)
|
||||
.set(updateTime).equalTo(record::getUpdateTime)
|
||||
@ -221,6 +228,7 @@ public interface NewsMapper {
|
||||
.set(catName).equalToWhenPresent(record::getCatName)
|
||||
.set(sourceName).equalToWhenPresent(record::getSourceName)
|
||||
.set(title).equalToWhenPresent(record::getTitle)
|
||||
.set(readCount).equalToWhenPresent(record::getReadCount)
|
||||
.set(createTime).equalToWhenPresent(record::getCreateTime)
|
||||
.set(createUserId).equalToWhenPresent(record::getCreateUserId)
|
||||
.set(updateTime).equalToWhenPresent(record::getUpdateTime)
|
||||
|
@ -44,7 +44,7 @@
|
||||
</javaClientGenerator>
|
||||
|
||||
<!--生成全部表tableName设为%-->
|
||||
<table tableName="book"/>
|
||||
<table tableName="news"/>
|
||||
|
||||
<!-- 指定数据库表 -->
|
||||
<!--<table schema="jly" tableName="job_position" domainObjectName="JobPositionTest"/>-->
|
||||
|
@ -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<List<News>> listIndexNews(){
|
||||
return ResultBean.ok(newsService.listIndexNews());
|
||||
}
|
||||
|
||||
@ -30,10 +34,19 @@ public class NewsController {
|
||||
* 分页查询新闻列表
|
||||
* */
|
||||
@GetMapping("listByPage")
|
||||
public ResultBean listByPage(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "5") int pageSize){
|
||||
public ResultBean<PageBean<News>> 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<Void> addReadCount(@RequestParam(value = "newsId") Integer newsId){
|
||||
newsService.addReadCount(newsId);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -115,7 +115,8 @@ public interface BookService {
|
||||
/**
|
||||
* 增加点击次数
|
||||
* @param bookId 书籍ID
|
||||
* @param visitCount*/
|
||||
* @param visitCount 点击量
|
||||
* */
|
||||
void addVisitCount(Long bookId, Integer visitCount);
|
||||
|
||||
/**
|
||||
|
@ -32,4 +32,10 @@ public interface NewsService {
|
||||
* @return 新闻分页数据
|
||||
* */
|
||||
PageBean<News> listByPage(int page, int pageSize);
|
||||
|
||||
/**
|
||||
* 增加新闻阅读量
|
||||
* @param newsId 新闻ID
|
||||
* */
|
||||
void addReadCount(Integer newsId);
|
||||
}
|
||||
|
@ -513,7 +513,6 @@ public class BookServiceImpl implements BookService {
|
||||
//该作者发布过此书名的小说
|
||||
throw new BusinessException(ResponseStatus.BOOKNAME_EXISTS);
|
||||
}
|
||||
;
|
||||
book.setAuthorName(penName);
|
||||
book.setAuthorId(authorId);
|
||||
book.setVisitCount(0L);
|
||||
@ -566,7 +565,7 @@ public class BookServiceImpl implements BookService {
|
||||
.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;
|
||||
|
@ -3,6 +3,7 @@ package com.java2nb.novel.service.impl;
|
||||
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 @@ import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||
@RequiredArgsConstructor
|
||||
public class NewsServiceImpl implements NewsService {
|
||||
|
||||
private final NewsMapper newsMapper;
|
||||
private final FrontNewsMapper newsMapper;
|
||||
|
||||
private final CacheService cacheService;
|
||||
|
||||
@ -72,4 +73,9 @@ public class NewsServiceImpl implements NewsService {
|
||||
pageBean.setList(BeanUtil.copyList(news,NewsVO.class));
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReadCount(Integer newsId) {
|
||||
newsMapper.addReadCount(newsId);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.java2nb.novel.mapper.FrontNewsMapper">
|
||||
<update id="addReadCount">
|
||||
update news set read_count = read_count + 1
|
||||
where id = #{newsId}
|
||||
</update>
|
||||
</mapper>
|
@ -10,6 +10,7 @@
|
||||
|
||||
<div th:replace="common/top :: top('')">
|
||||
</div>
|
||||
<input type="hidden" id="newsId" th:value="${news.id}"/>
|
||||
<div class="main box_center cf">
|
||||
<div class="newsMain cf">
|
||||
<div class="nav_sub">
|
||||
@ -19,7 +20,7 @@
|
||||
<div class="news_title">
|
||||
<h2 th:utext="${news.title}"></h2>
|
||||
<!--while [[...]] corresponds to th:text (i.e. result will be HTML-escaped), [(...)] corresponds to th:utext-->
|
||||
<p class="from">来源:[[${news.sourceName}]] <span class="time" th:text="'时间:'+${#dates.format(news.createTime, 'yy-MM-dd')}"></span> <span class="time" th:text="'点击:'+'888'"></span></p>
|
||||
<p class="from">来源:[[${news.sourceName}]] <span class="time" th:text="'时间:'+${#dates.format(news.createTime, 'yy-MM-dd')}"></span> <span class="time" th:text="'阅读量:'+${news.readCount}"></span></p>
|
||||
</div>
|
||||
<div class="news_info" th:utext="${news.content}">
|
||||
</div>
|
||||
@ -33,4 +34,8 @@
|
||||
</body>
|
||||
<div th:replace="common/js :: js"></div>
|
||||
<script src="/javascript/bookdetail.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
$.post("/news/addReadCount", {"newsId": $("#newsId").val()}, function () {
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user