|
@@ -1,10 +1,8 @@
|
|
package com.book.server.service.impl;
|
|
package com.book.server.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
+
|
|
import com.book.server.common.entity.PageResult;
|
|
import com.book.server.common.entity.PageResult;
|
|
-import com.book.server.common.entity.Result;
|
|
|
|
|
|
+import com.book.server.common.util.JsonUtils;
|
|
import com.book.server.dao.entity.Book;
|
|
import com.book.server.dao.entity.Book;
|
|
import com.book.server.dao.entity.BookCategory;
|
|
import com.book.server.dao.entity.BookCategory;
|
|
import com.book.server.dao.entity.ManageBlock;
|
|
import com.book.server.dao.entity.ManageBlock;
|
|
@@ -17,27 +15,22 @@ import com.book.server.dao.mapper.BookCategoryMapper;
|
|
import com.book.server.dao.mapper.BookMapper;
|
|
import com.book.server.dao.mapper.BookMapper;
|
|
import com.book.server.dao.mapper.ManageBlockMapper;
|
|
import com.book.server.dao.mapper.ManageBlockMapper;
|
|
import com.book.server.dao.mapper.ManageBlockResourceMapper;
|
|
import com.book.server.dao.mapper.ManageBlockResourceMapper;
|
|
-import com.book.server.model.VO.BlockRes;
|
|
|
|
-import com.book.server.model.VO.Chapter;
|
|
|
|
-import com.book.server.model.VO.BookRes;
|
|
|
|
-import com.book.server.model.VO.ManageBlockResourceRes;
|
|
|
|
-import com.book.server.model.VO.QueryVO;
|
|
|
|
|
|
+import com.book.server.model.VO.*;
|
|
import com.book.server.service.BookService;
|
|
import com.book.server.service.BookService;
|
|
import com.book.server.utils.HttpTool;
|
|
import com.book.server.utils.HttpTool;
|
|
|
|
+import com.google.gson.JsonArray;
|
|
|
|
+import com.google.gson.JsonElement;
|
|
|
|
+import com.google.gson.JsonObject;
|
|
|
|
+import com.google.gson.JsonParser;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
-import org.springframework.cache.annotation.Cacheable;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class BookServiceImpl implements BookService {
|
|
public class BookServiceImpl implements BookService {
|
|
@@ -82,7 +75,7 @@ public class BookServiceImpl implements BookService {
|
|
ArrayList<BookRes> bookResList = new ArrayList<>();
|
|
ArrayList<BookRes> bookResList = new ArrayList<>();
|
|
for (Book book : books) {
|
|
for (Book book : books) {
|
|
BookRes bookRes = new BookRes();
|
|
BookRes bookRes = new BookRes();
|
|
- BeanUtils.copyProperties(book,bookRes);
|
|
|
|
|
|
+ BeanUtils.copyProperties(book, bookRes);
|
|
bookRes.setCategoryName(map.get(book.getBookCategoryId()));
|
|
bookRes.setCategoryName(map.get(book.getBookCategoryId()));
|
|
bookResList.add(bookRes);
|
|
bookResList.add(bookRes);
|
|
}
|
|
}
|
|
@@ -130,12 +123,12 @@ public class BookServiceImpl implements BookService {
|
|
.example()
|
|
.example()
|
|
);
|
|
);
|
|
HashMap<Long, Book> bookHashMap = new HashMap<>();
|
|
HashMap<Long, Book> bookHashMap = new HashMap<>();
|
|
- books.forEach(x->{
|
|
|
|
|
|
+ books.forEach(x -> {
|
|
bookHashMap.put(x.getId(), x);
|
|
bookHashMap.put(x.getId(), x);
|
|
});
|
|
});
|
|
- manageBlockResources.forEach(x->{
|
|
|
|
|
|
+ manageBlockResources.forEach(x -> {
|
|
ManageBlockResourceRes manageBlockResourceRes = new ManageBlockResourceRes();
|
|
ManageBlockResourceRes manageBlockResourceRes = new ManageBlockResourceRes();
|
|
- BeanUtils.copyProperties(x,manageBlockResourceRes);
|
|
|
|
|
|
+ BeanUtils.copyProperties(x, manageBlockResourceRes);
|
|
manageBlockResourceResList.add(manageBlockResourceRes);
|
|
manageBlockResourceResList.add(manageBlockResourceRes);
|
|
|
|
|
|
Book book = bookHashMap.get(x.getBookId());
|
|
Book book = bookHashMap.get(x.getBookId());
|
|
@@ -164,8 +157,9 @@ public class BookServiceImpl implements BookService {
|
|
String bookInfoUrl = "http://new.emeixs.com/index.php/Home/Interface/listing";
|
|
String bookInfoUrl = "http://new.emeixs.com/index.php/Home/Interface/listing";
|
|
|
|
|
|
String jsonStr = HttpTool.sendGet(bookInfoUrl, "");
|
|
String jsonStr = HttpTool.sendGet(bookInfoUrl, "");
|
|
- JSONObject listJson = JSON.parseObject(jsonStr);
|
|
|
|
- JSONArray list = listJson.getJSONArray("list");
|
|
|
|
|
|
+ JsonObject jsonObject = JsonUtils.getObject(jsonStr, JsonObject.class);
|
|
|
|
+ JsonArray list = jsonObject.getAsJsonArray("list");
|
|
|
|
+
|
|
Map<String, String> typeMap = new HashMap<String, String>();
|
|
Map<String, String> typeMap = new HashMap<String, String>();
|
|
typeMap.put("15", "豪门总裁");
|
|
typeMap.put("15", "豪门总裁");
|
|
typeMap.put("16", "婚恋家庭");
|
|
typeMap.put("16", "婚恋家庭");
|
|
@@ -179,29 +173,33 @@ public class BookServiceImpl implements BookService {
|
|
typeMap.put("24", "其他");
|
|
typeMap.put("24", "其他");
|
|
List<Book> bookList = new ArrayList<>();
|
|
List<Book> bookList = new ArrayList<>();
|
|
for (int i = 0; i < list.size(); i++) {
|
|
for (int i = 0; i < list.size(); i++) {
|
|
- JSONObject bookObject = list.getJSONObject(i);
|
|
|
|
- String author_name = bookObject.getString("author_name");
|
|
|
|
- String book_brief = bookObject.getString("book_brief");
|
|
|
|
- String book_id = bookObject.getString("book_id");
|
|
|
|
- String book_name = bookObject.getString("book_name");
|
|
|
|
- String chapter = bookObject.getString("chapter");
|
|
|
|
- String charge = bookObject.getString("charge");
|
|
|
|
- String cover = bookObject.getString("cover");
|
|
|
|
- String ctype_id = bookObject.getString("ctype_id");
|
|
|
|
- String gender = bookObject.getString("gender");
|
|
|
|
- String is_show = bookObject.getString("is_show");
|
|
|
|
- String state = bookObject.getString("state");
|
|
|
|
- String type_id = bookObject.getString("type_id");
|
|
|
|
- String words = bookObject.getString("words");
|
|
|
|
|
|
+ JsonElement jsonElement = list.get(i);
|
|
|
|
+ JsonObject bookObject = jsonElement.getAsJsonObject();
|
|
|
|
+ String author_name = bookObject.get("author_name").getAsString();
|
|
|
|
+ String book_brief = bookObject.get("book_brief").getAsString();
|
|
|
|
+ String book_id = bookObject.get("book_id").getAsString();
|
|
|
|
+ String book_name = bookObject.get("book_name").getAsString();
|
|
|
|
+ String chapter = bookObject.get("chapter").getAsString();
|
|
|
|
+ String charge = bookObject.get("charge").getAsString();
|
|
|
|
+ String cover = bookObject.get("cover").getAsString();
|
|
|
|
+ String ctype_id = bookObject.get("ctype_id").getAsString();
|
|
|
|
+ String gender = bookObject.get("gender").getAsString();
|
|
|
|
+ String is_show = bookObject.get("is_show").getAsString();
|
|
|
|
+ String state = bookObject.get("state").getAsString();
|
|
|
|
+ String type_id = bookObject.get("type_id").getAsString();
|
|
|
|
+ String words = bookObject.get("words").getAsString();
|
|
|
|
+
|
|
//章节列表
|
|
//章节列表
|
|
String chaptersStr = HttpTool.sendGet("http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + book_id, "");
|
|
String chaptersStr = HttpTool.sendGet("http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + book_id, "");
|
|
- JSONArray listChapters = JSON.parseArray(chaptersStr);
|
|
|
|
- JSONObject firstChapters = listChapters.getJSONObject(1);
|
|
|
|
- String first_chapter_id = firstChapters.getString("content_id");
|
|
|
|
- String first_chapter_name = firstChapters.getString("name");
|
|
|
|
- JSONObject lastChapters = listChapters.getJSONObject(listChapters.size() - 1);
|
|
|
|
- String last_chapter_id = lastChapters.getString("content_id");
|
|
|
|
- String last_chapter_name = lastChapters.getString("name");
|
|
|
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
|
+ JsonArray jsonArray = parser.parse(chaptersStr).getAsJsonArray();
|
|
|
|
+ JsonObject firstChapters = jsonArray.get(1).getAsJsonObject();
|
|
|
|
+ String first_chapter_id = firstChapters.get("content_id").getAsString();
|
|
|
|
+ String first_chapter_name = firstChapters.get("name").getAsString();
|
|
|
|
+ JsonObject lastChapters = jsonArray.get(jsonArray.size() - 1).getAsJsonObject();
|
|
|
|
+ String last_chapter_id = lastChapters.get("content_id").getAsString();
|
|
|
|
+ String last_chapter_name = lastChapters.get("name").getAsString();
|
|
|
|
+
|
|
|
|
|
|
Book book = new Book();
|
|
Book book = new Book();
|
|
book.setId(Long.parseLong(book_id));
|
|
book.setId(Long.parseLong(book_id));
|
|
@@ -249,8 +247,8 @@ public class BookServiceImpl implements BookService {
|
|
for (Book book : bookList) {
|
|
for (Book book : bookList) {
|
|
int i = new Random().nextInt(bookList.size());
|
|
int i = new Random().nextInt(bookList.size());
|
|
book.setRecommandBookId(bookList.get(i).getId());
|
|
book.setRecommandBookId(bookList.get(i).getId());
|
|
- System.out.println(JSON.toJSONString(book));
|
|
|
|
- bookMapper.insert(book);
|
|
|
|
|
|
+ System.out.println(JsonUtils.toJsonStr(book));
|
|
|
|
+ bookMapper.insert(book);
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -261,26 +259,28 @@ public class BookServiceImpl implements BookService {
|
|
public List<Chapter> getChaptersByBookId(String bookId) {
|
|
public List<Chapter> getChaptersByBookId(String bookId) {
|
|
List<Chapter> list = new ArrayList<>();
|
|
List<Chapter> list = new ArrayList<>();
|
|
try {
|
|
try {
|
|
- if (StringUtils.isEmpty(bookId)){
|
|
|
|
|
|
+ if (StringUtils.isEmpty(bookId)) {
|
|
throw new IllegalArgumentException("bookId cannot be null or empty");
|
|
throw new IllegalArgumentException("bookId cannot be null or empty");
|
|
}
|
|
}
|
|
- final String chaptersUrl = "http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + bookId;
|
|
|
|
|
|
+ final String chaptersUrl = "http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + bookId;
|
|
String result = HttpTool.sendGet(chaptersUrl, "");
|
|
String result = HttpTool.sendGet(chaptersUrl, "");
|
|
if (StringUtils.isEmpty(result)) {
|
|
if (StringUtils.isEmpty(result)) {
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
- JSONArray jsonArray = JSON.parseArray(result);
|
|
|
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
|
+ JsonArray jsonArray = parser.parse(result).getAsJsonArray();
|
|
|
|
+
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
- JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
|
|
|
+ JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
|
|
Chapter chapter = new Chapter();
|
|
Chapter chapter = new Chapter();
|
|
- chapter.setBookId(jsonObject.getString("book_id"));
|
|
|
|
- chapter.setContentId(jsonObject.getString("content_id"));
|
|
|
|
- chapter.setIsPay(jsonObject.getString("ispay"));
|
|
|
|
- chapter.setName(jsonObject.getString("name"));
|
|
|
|
- chapter.setNum(jsonObject.getString("num"));
|
|
|
|
- chapter.setType(jsonObject.getString("type"));
|
|
|
|
- chapter.setVolumeId(jsonObject.getString("volume_id"));
|
|
|
|
- chapter.setWords(jsonObject.getString("words"));
|
|
|
|
|
|
+ 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());
|
|
list.add(chapter);
|
|
list.add(chapter);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|