|
@@ -6,6 +6,9 @@ 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.cpsshard.entity.UserRecentlyRead;
|
|
|
+import com.book.dao.cpsshard.mapper.UserRecentlyReadMapper;
|
|
|
+import com.book.dao.cpsshard.pojo.example.UserRecentlyReadExample;
|
|
|
import com.book.server.common.util.JsonUtils;
|
|
|
import com.book.dao.cps.pojo.example.*;
|
|
|
import com.book.dao.VO.*;
|
|
@@ -212,42 +215,42 @@ public class BookServiceImpl implements BookService {
|
|
|
public List<Chapter> getChaptersByBookId(String bookId) {
|
|
|
List<Chapter> list = new ArrayList<>();
|
|
|
|
|
|
- if (StringUtils.isEmpty(bookId)) {
|
|
|
- throw new IllegalArgumentException("bookId cannot be null or empty");
|
|
|
- }
|
|
|
- final String chaptersUrl = "http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + bookId;
|
|
|
- String result = HttpTool.sendGet(chaptersUrl, "");
|
|
|
- if (StringUtils.isEmpty(result)) {
|
|
|
- return list;
|
|
|
- }
|
|
|
- JsonParser parser = new JsonParser();
|
|
|
- JsonArray jsonArray = parser.parse(result).getAsJsonArray();
|
|
|
- Book book = bookMapper.selectByPrimaryKey(Long.parseLong(bookId));
|
|
|
- if (book == null) {
|
|
|
- return list;
|
|
|
- }
|
|
|
- Integer freeChapterNum = book.getFreeChapterNum();
|
|
|
+ if (StringUtils.isEmpty(bookId)) {
|
|
|
+ throw new IllegalArgumentException("bookId cannot be null or empty");
|
|
|
+ }
|
|
|
+ final String chaptersUrl = "http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + bookId;
|
|
|
+ String result = HttpTool.sendGet(chaptersUrl, "");
|
|
|
+ if (StringUtils.isEmpty(result)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
+ JsonArray jsonArray = parser.parse(result).getAsJsonArray();
|
|
|
+ Book book = bookMapper.selectByPrimaryKey(Long.parseLong(bookId));
|
|
|
+ if (book == null) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ Integer freeChapterNum = book.getFreeChapterNum();
|
|
|
|
|
|
- if (freeChapterNum==null){
|
|
|
- freeChapterNum = 20;
|
|
|
- }
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
|
|
|
- Chapter chapter = new Chapter();
|
|
|
- chapter.setReadAble("1");
|
|
|
- chapter.setBookId(jsonObject.get("book_id").getAsString());
|
|
|
- chapter.setContentId(jsonObject.get("content_id").getAsString());
|
|
|
- chapter.setIsPay(jsonObject.get("ispay").getAsString());
|
|
|
- chapter.setName(jsonObject.get("name").getAsString());
|
|
|
- chapter.setNum(jsonObject.get("num").getAsString());
|
|
|
- chapter.setType(jsonObject.get("type").getAsString());
|
|
|
- chapter.setVolumeId(jsonObject.get("volume_id").getAsString());
|
|
|
- chapter.setWords(jsonObject.get("words").getAsString());
|
|
|
- if (i + 1 == freeChapterNum) {
|
|
|
- chapter.setReadAble("0");
|
|
|
- }
|
|
|
- list.add(chapter);
|
|
|
+ if (freeChapterNum == null) {
|
|
|
+ freeChapterNum = 20;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
|
|
|
+ Chapter chapter = new Chapter();
|
|
|
+ chapter.setReadAble("1");
|
|
|
+ chapter.setBookId(jsonObject.get("book_id").getAsString());
|
|
|
+ chapter.setContentId(jsonObject.get("content_id").getAsString());
|
|
|
+ chapter.setIsPay(jsonObject.get("ispay").getAsString());
|
|
|
+ chapter.setName(jsonObject.get("name").getAsString());
|
|
|
+ chapter.setNum(jsonObject.get("num").getAsString());
|
|
|
+ chapter.setType(jsonObject.get("type").getAsString());
|
|
|
+ chapter.setVolumeId(jsonObject.get("volume_id").getAsString());
|
|
|
+ chapter.setWords(jsonObject.get("words").getAsString());
|
|
|
+ if (i + 1 == freeChapterNum) {
|
|
|
+ chapter.setReadAble("0");
|
|
|
}
|
|
|
+ list.add(chapter);
|
|
|
+ }
|
|
|
|
|
|
return list;
|
|
|
}
|
|
@@ -301,6 +304,29 @@ public class BookServiceImpl implements BookService {
|
|
|
return content;
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserRecentlyReadMapper userRecentlyReadMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserRecentlyRead getRecentReadByUserIdAndBookId(UserRecentlyRead userRecentlyRead) {
|
|
|
+ UserRecentlyReadExample example = UserRecentlyReadExample.newAndCreateCriteria()
|
|
|
+ .andUserIdEqualTo(userRecentlyRead.getUserId())
|
|
|
+ .andBookIdEqualTo(userRecentlyRead.getBookId())
|
|
|
+ .example();
|
|
|
+ return userRecentlyReadMapper.selectOneByExample(example);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<UserRecentlyRead> getRecentReadByUserId(UserRecentlyRead userRecentlyRead) {
|
|
|
+ UserRecentlyReadExample example = UserRecentlyReadExample.newAndCreateCriteria()
|
|
|
+ .andUserIdEqualTo(userRecentlyRead.getUserId())
|
|
|
+ .example();
|
|
|
+ example.orderBy(UserRecentlyRead.Column.updatetime.desc());
|
|
|
+ //暂定为获取30条
|
|
|
+ example.page(0, 30);
|
|
|
+ return userRecentlyReadMapper.selectByExample(example);
|
|
|
+ }
|
|
|
+
|
|
|
private List<BookRes> getRandom(List<BookRes> bookRes) {
|
|
|
if (bookRes.size() <= 4) {
|
|
|
return bookRes;
|