新增加入书架的书籍下次可继续上次阅读记录阅读

This commit is contained in:
xxy 2019-12-01 13:32:37 +08:00
parent 2b8eb63836
commit ace84ef155
10 changed files with 62 additions and 16 deletions

View File

@ -28,4 +28,8 @@ public interface UserRefBookMapper {
int updateByPrimaryKeySelective(UserRefBook record);
int updateByPrimaryKey(UserRefBook record);
void updateNewstIndex(@Param("bookId") Long bookId,@Param("userId") String userId,@Param("indexNum") Integer indexNum);
Integer queryBookIndexNumber(@Param("userId") String userId,@Param("bookId") Long bookId);
}

View File

@ -17,10 +17,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.orderbyhelper.OrderByHelper;
import xyz.zinglizingli.books.constant.CacheKeyConstans;
import xyz.zinglizingli.books.mapper.BookContentMapper;
import xyz.zinglizingli.books.mapper.BookIndexMapper;
import xyz.zinglizingli.books.mapper.BookMapper;
import xyz.zinglizingli.books.mapper.ScreenBulletMapper;
import xyz.zinglizingli.books.mapper.*;
import xyz.zinglizingli.books.po.*;
import xyz.zinglizingli.common.cache.CommonCacheUtil;
import xyz.zinglizingli.common.utils.RestTemplateUtil;
@ -45,6 +42,9 @@ public class BookService {
@Autowired
private ScreenBulletMapper screenBulletMapper;
@Autowired
private UserRefBookMapper userRefBookMapper;
@Autowired
private CommonCacheUtil cacheUtil;
@ -330,9 +330,14 @@ public class BookService {
return contentBuilder.toString();
}
public void addVisitCount(Long bookId) {
public void addVisitCount(Long bookId, String userId, Integer indexNum) {
bookMapper.addVisitCount(bookId);
if(org.apache.commons.lang3.StringUtils.isNotBlank(userId)) {
userRefBookMapper.updateNewstIndex(bookId, userId, indexNum);
}
}
public String queryIndexNameByBookIdAndIndexNum(Long bookId, Integer indexNum) {

View File

@ -83,4 +83,8 @@ public class UserService {
addToCollect(bookId, userid);
}
}
public Integer queryBookIndexNumber(String userId, Long bookId) {
return userRefBookMapper.queryBookIndexNumber(userId,bookId);
}
}

View File

@ -176,13 +176,13 @@ public class ApiBookController {
return modelMap;
}
@RequestMapping("addVisit")
/*@RequestMapping("addVisit")
public String addVisit(@RequestParam("bookId") Long bookId) {
bookService.addVisitCount(bookId);
bookService.addVisitCount(bookId, userId, indexNum);
return "ok";
}
}*/
}

View File

@ -17,6 +17,7 @@ import xyz.zinglizingli.books.po.BookContent;
import xyz.zinglizingli.books.po.BookIndex;
import xyz.zinglizingli.books.po.ScreenBullet;
import xyz.zinglizingli.books.service.BookService;
import xyz.zinglizingli.books.service.UserService;
import xyz.zinglizingli.books.vo.BookVO;
import xyz.zinglizingli.common.cache.CommonCacheUtil;
@ -35,6 +36,9 @@ public class BookController {
@Autowired
private BookService bookService;
@Autowired
private UserService userService;
@Autowired
private CommonCacheUtil commonCacheUtil;
@ -187,7 +191,16 @@ public class BookController {
}
@RequestMapping("{bookId}.html")
public String detail(@PathVariable("bookId") Long bookId, ModelMap modelMap) {
public String detail(@PathVariable("bookId") Long bookId, @RequestParam(value = "token",required = false)String token, ModelMap modelMap) {
String userId = commonCacheUtil.get(token);
if(org.apache.commons.lang3.StringUtils.isNotBlank(userId)){
Integer indexNumber = userService.queryBookIndexNumber(userId,bookId);
if(indexNumber!=null){
return "redirect:/book/"+bookId+"/"+indexNumber+".html";
}
}
//查询基本信息
Book book = bookService.queryBaseInfo(bookId);
//查询最新目录信息
@ -260,9 +273,10 @@ public class BookController {
@RequestMapping("addVisit")
@ResponseBody
public String addVisit(@RequestParam("bookId") Long bookId) {
public String addVisit(@RequestParam("bookId") Long bookId,@RequestParam("indexNum") Integer indexNum,@RequestParam("token") String token) {
String userId = commonCacheUtil.get(token);
bookService.addVisitCount(bookId);
bookService.addVisitCount(bookId,userId,indexNum);
return "ok";
}

View File

@ -178,4 +178,15 @@
book_id = #{bookId,jdbcType=BIGINT}
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateNewstIndex">
update user_ref_book
set index_num = #{indexNum}
where book_id = #{bookId} and user_id = #{userId}
</update>
<select id="queryBookIndexNumber" resultType="java.lang.Integer">
select index_num from user_ref_book
where book_id = #{bookId} and user_id = #{userId}
</select>
</mapper>

View File

@ -375,6 +375,14 @@
<input type="hidden" id="contentIdHidden" th:value="${bookContent.id}"/>
<input type="hidden" id="indexNumHidden" th:value="${bookContent.indexNum}"/>
<script>
var token = localStorage.getItem("token");
$.get("/book/addVisit", {"bookId": $("#bookIdHidden").val(),"indexNum":$("#indexNumHidden").val(),"token":token}, function () {
});
</script>
<div style="height: 50px;line-height: 50px;text-align: center" class="layui-header header header-doc layui-bg-cyan">
<div style="width:10%;float: left;margin-left: 10px">
@ -458,8 +466,7 @@
isMobile = isIphone || isAndroid;
$.get("/book/addVisit", {"bookId": $("#bookIdHidden").val()}, function () {
});
</script>
<script>

View File

@ -112,14 +112,14 @@
<div th:each="book : ${books}" class="layui-row" style="margin-bottom:10px;padding:10px;background: #f2f2f2">
<a th:href="'/book/'+ ${book.id} + '.html'">
<a th:href="'/book/'+ ${book.id} + '.html'+ ${token!=null?'?token='+token:''}">
<div class="layui-col-xs6 layui-col-sm3 layui-col-md2 layui-col-lg2" style="text-align: center">
<img align="center"
th:src="${book.picUrl}"/>
</div>
</a>
<div style="padding: 20px" class="layui-col-xs6 layui-col-sm8 layui-col-md8 layui-col-lg8">
<a th:href="'/book/'+ ${book.id} + '.html'">
<a th:href="'/book/'+ ${book.id} + '.html'+ ${token!=null?'?token='+token:''}">
<div class="line-limit-length" style=";color: #4c6978;font-weight: bold;font-size: 15px"
th:text="${book.bookName}"></div>
</a>

1
sql/2019-12-01.sql Normal file
View File

@ -0,0 +1 @@
alter table user_ref_book add column `index_num` int(5);

View File

@ -1009,5 +1009,5 @@ INSERT INTO `sys_dict` (`id`, `name`, `value`, `type`, `description`, `sort`, `p
INSERT INTO `sys_dict` (`id`, `name`, `value`, `type`, `description`, `sort`, `parent_id`, `create_by`, `create_date`, `update_by`, `update_date`, `remarks`, `del_flag`) VALUES ('128', '网游竞技', '6', 'novel_category', '小说分类', '6', NULL, NULL, NULL, NULL, NULL, '', NULL);
INSERT INTO `sys_dict` (`id`, `name`, `value`, `type`, `description`, `sort`, `parent_id`, `create_by`, `create_date`, `update_by`, `update_date`, `remarks`, `del_flag`) VALUES ('129', '女生频道', '7', 'novel_category', '小说分类', '7', NULL, NULL, NULL, NULL, NULL, '', NULL);
alter table user_ref_book add column `index_num` int(5);