Skip to content

Commit

Permalink
新增加入书架的书籍下次可继续上次阅读记录阅读
Browse files Browse the repository at this point in the history
  • Loading branch information
201206030 committed Dec 1, 2019
1 parent 2b8eb63 commit ace84ef
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
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;
Expand All @@ -45,6 +42,9 @@ public class BookService {
@Autowired
private ScreenBulletMapper screenBulletMapper;

@Autowired
private UserRefBookMapper userRefBookMapper;

@Autowired
private CommonCacheUtil cacheUtil;

Expand Down Expand Up @@ -330,9 +330,14 @@ private String chargeBookContent(String content) throws IOException {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ public void collectOrCancelBook(Long userid, Long bookId) {
addToCollect(bookId, userid);
}
}

public Integer queryBookIndexNumber(String userId, Long bookId) {
return userRefBookMapper.queryBookIndexNumber(userId,bookId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ public Map<String,Object> bookContent(@PathVariable("bookId") Long bookId, @Path
return modelMap;
}

@RequestMapping("addVisit")
/*@RequestMapping("addVisit")
public String addVisit(@RequestParam("bookId") Long bookId) {
bookService.addVisitCount(bookId);
bookService.addVisitCount(bookId, userId, indexNum);
return "ok";
}
}*/


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;

Expand All @@ -35,6 +36,9 @@ public class BookController {
@Autowired
private BookService bookService;

@Autowired
private UserService userService;

@Autowired
private CommonCacheUtil commonCacheUtil;

Expand Down Expand Up @@ -187,7 +191,16 @@ public String searchMhBook(@RequestParam(value = "curr", defaultValue = "1") int
}

@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);
//查询最新目录信息
Expand Down Expand Up @@ -260,9 +273,10 @@ public String bookContent(@PathVariable("bookId") Long bookId, @PathVariable("in

@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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
11 changes: 9 additions & 2 deletions novel-front/src/main/resources/templates/books/book_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -458,8 +466,7 @@
isMobile = isIphone || isAndroid;


$.get("/book/addVisit", {"bookId": $("#bookIdHidden").val()}, function () {
});


</script>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions sql/2019-12-01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table user_ref_book add column `index_num` int(5);
2 changes: 1 addition & 1 deletion sql/books.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit ace84ef

Please sign in to comment.