增加新闻阅读数

This commit is contained in:
xiaoyang
2021-07-26 19:06:57 +08:00
parent b99b6ae4f2
commit 1cffbae495
14 changed files with 101 additions and 14 deletions

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -115,7 +115,8 @@ public interface BookService {
/**
* 增加点击次数
* @param bookId 书籍ID
* @param visitCount*/
* @param visitCount 点击量
* */
void addVisitCount(Long bookId, Integer visitCount);
/**

View File

@ -32,4 +32,10 @@ public interface NewsService {
* @return 新闻分页数据
* */
PageBean<News> listByPage(int page, int pageSize);
/**
* 增加新闻阅读量
* @param newsId 新闻ID
* */
void addReadCount(Integer newsId);
}

View File

@ -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;

View File

@ -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);
}
}