|
@@ -2,14 +2,18 @@ package com.book.server.service.impl;
|
|
|
|
|
|
|
|
|
import com.book.dao.cps.mapper.*;
|
|
|
-import com.book.dao.cps.pojo.Book;
|
|
|
-import com.book.dao.cps.pojo.BookCategory;
|
|
|
-import com.book.dao.cps.pojo.ManageBlock;
|
|
|
-import com.book.dao.cps.pojo.SearchKeyword;
|
|
|
+import com.book.dao.cps.pojo.*;
|
|
|
+import com.book.dao.cpsshard.entity.Recharge;
|
|
|
import com.book.dao.cpsshard.entity.UserRecentlyRead;
|
|
|
+import com.book.dao.cpsshard.mapper.ConsumeMapper;
|
|
|
+import com.book.dao.cpsshard.mapper.RechargeMapper;
|
|
|
import com.book.dao.cpsshard.mapper.UserRecentlyReadMapper;
|
|
|
+import com.book.dao.cpsshard.pojo.example.ConsumeExample;
|
|
|
+import com.book.dao.cpsshard.pojo.example.RechargeExample;
|
|
|
import com.book.dao.cpsshard.pojo.example.UserRecentlyReadExample;
|
|
|
import com.book.server.common.entity.Result;
|
|
|
+import com.book.server.common.entity.ResultCode;
|
|
|
+import com.book.server.common.util.DateUtils;
|
|
|
import com.book.server.common.util.JsonUtils;
|
|
|
import com.book.dao.cps.pojo.example.*;
|
|
|
import com.book.dao.VO.*;
|
|
@@ -25,6 +29,8 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -279,13 +285,55 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ConfigMapper configMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ConsumeMapper consumeMapper;
|
|
|
+ @Autowired
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RechargeMapper rechargeMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public Result<BookContent> getContentByContentId(BookContentVO bookContentVO) {
|
|
|
+ BookContent content = null;
|
|
|
Book book = bookMapper.selectByPrimaryKey(bookContentVO.getBookId());
|
|
|
- if (book.getFreeChapterNum() == null) {
|
|
|
+ //是否是付费章节
|
|
|
+ Integer freeChapterNum = book.getFreeChapterNum();
|
|
|
+ if (freeChapterNum == null) { //查看默认配置
|
|
|
+ freeChapterNum = Integer.valueOf(configMapper.selectByName("book_free_chapter_num").getValue());
|
|
|
+ }
|
|
|
+ if (bookContentVO.getContentId() > freeChapterNum) { //收费
|
|
|
+ //是否已购买
|
|
|
+ long count = consumeMapper.countByExample(ConsumeExample.newAndCreateCriteria()
|
|
|
+ .andBookIdEqualTo(bookContentVO.getBookId())
|
|
|
+ .andUserIdEqualTo(bookContentVO.getUserId())
|
|
|
+ .example()
|
|
|
+ );
|
|
|
+ if (count == 0) { // 没有购买记录
|
|
|
+ User user = userMapper.selectByPrimaryKey(bookContentVO.getUserId());
|
|
|
+ //查询免费看点
|
|
|
+ List<Recharge> recharges = rechargeMapper.selectByExample(
|
|
|
+ RechargeExample.newAndCreateCriteria()
|
|
|
+ .andUserIdEqualTo(bookContentVO.getUserId())
|
|
|
+ .andTypeEqualTo("5") // 免费类型
|
|
|
+ .andCreatetimeGreaterThan(DateUtils.get3DayAgo())
|
|
|
+ .example()
|
|
|
+ );
|
|
|
+ Integer freeCount = 0;
|
|
|
+ if (recharges != null) {
|
|
|
+ freeCount = recharges.stream().mapToInt(x -> x.getFreeKandian()).sum();
|
|
|
+ }
|
|
|
+ //免费是否足够
|
|
|
+ //if (freeCount > )
|
|
|
+ //免费+充值是否足够
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- BookContent content = null;
|
|
|
+ //获取章节内容
|
|
|
if (bookContentVO.getBookId() > 110_0000 && bookContentVO.getBookId() < 110_9999) {
|
|
|
// 自定义的书籍 TODO
|
|
|
} else {
|