main
tamguo 7 years ago
parent c7d809b09d
commit 689af76638

@ -13,6 +13,8 @@ import com.tamguo.config.dao.SuperEntity;
public class ChapterEntity extends SuperEntity<ChapterEntity> implements Serializable { public class ChapterEntity extends SuperEntity<ChapterEntity> implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String subjectId;
private String courseId; private String courseId;
private String name; private String name;
@ -116,4 +118,12 @@ public class ChapterEntity extends SuperEntity<ChapterEntity> implements Seriali
this.parentCodes = parentCodes; this.parentCodes = parentCodes;
} }
public String getSubjectId() {
return subjectId;
}
public void setSubjectId(String subjectId) {
this.subjectId = subjectId;
}
} }

@ -52,7 +52,8 @@ public class QuestionService implements IQuestionService{
@Autowired @Autowired
CacheService cacheService; CacheService cacheService;
private static final String FILES_NO_FORMAT = "000000000"; private static final String FILES_NO_FORMAT = "000000000";
private static final String FILES_PREFIX = "likeshuxue"; private static final String FILES_PREFIX = "shengwu";
private static final String COURSE_ID = "shengwu";
private static final String DOMAIN = "http://www.tamguo.com"; private static final String DOMAIN = "http://www.tamguo.com";
private RunData runData; private RunData runData;
@ -139,7 +140,7 @@ public class QuestionService implements IQuestionService{
System.out.println("down images " + (ret?"success":"fail") + "" + img); System.out.println("down images " + (ret?"success":"fail") + "" + img);
// 替换URL // 替换URL
question.setAnswer(question.getAnswer().replace(img, DOMAIN + "/files/question/" + fileDatePath + "/" + fileName)); question.setAnswer(question.getAnswer().replace(img, DOMAIN + "/files/question/" + COURSE_ID + '/' + fileDatePath + "/" + fileName));
} }
question.setAnswer(question.getAnswer()); question.setAnswer(question.getAnswer());
} }
@ -160,7 +161,7 @@ public class QuestionService implements IQuestionService{
System.out.println("down images " + (ret?"success":"fail") + "" + img); System.out.println("down images " + (ret?"success":"fail") + "" + img);
// 替换URL // 替换URL
question.setAnalysis(question.getAnalysis().replace(img, DOMAIN + "/files/question/" + fileDatePath + "/" + fileName)); question.setAnalysis(question.getAnalysis().replace(img, DOMAIN + "/files/question/" + COURSE_ID + '/' + fileDatePath + "/" + fileName));
} }
question.setAnalysis(question.getAnalysis()); question.setAnalysis(question.getAnalysis());
} }
@ -181,7 +182,7 @@ public class QuestionService implements IQuestionService{
System.out.println("down images " + (ret?"success":"fail") + "" + img); System.out.println("down images " + (ret?"success":"fail") + "" + img);
// 替换URL // 替换URL
question.setContent(question.getContent().replace(img, DOMAIN + "/files/question/" + fileDatePath + "/" + fileName)); question.setContent(question.getContent().replace(img, DOMAIN + "/files/question/" + COURSE_ID + '/' + fileDatePath + "/" + fileName));
} }
question.setContent(question.getContent()); question.setContent(question.getContent());
} }
@ -198,7 +199,7 @@ public class QuestionService implements IQuestionService{
} }
private String getFilePath() { private String getFilePath() {
return "/home/webdata/files/question/"; return "/home/webdata/files/question/" + COURSE_ID + "/";
} }
private String getFileDatePath() { private String getFileDatePath() {

@ -30,8 +30,9 @@ import com.xuxueli.crawler.rundata.RunData;
@Service @Service
public class SubjectService implements ISubjectService{ public class SubjectService implements ISubjectService{
private final static String COURSE_ID = "likeshuxue"; private final static String COURSE_ID = "shengwu";
private final static String BOOK_ID = "1025976567395184642"; private final static String BOOK_ID = "1025976567395184645";
private final static String SUBJECT_ID = "gaokao";
@Autowired @Autowired
SubjectMapper subjectMapper; SubjectMapper subjectMapper;
@Autowired @Autowired
@ -52,7 +53,7 @@ public class SubjectService implements ISubjectService{
@Override @Override
public void crawlerSubject() { public void crawlerSubject() {
XxlCrawler crawler = new XxlCrawler.Builder() XxlCrawler crawler = new XxlCrawler.Builder()
.setUrls("https://tiku.baidu.com/tikupc/chapterlist/1bfd700abb68a98271fefa04-16-knowpoint-11") .setUrls("https://tiku.baidu.com/tikupc/chapterlist/1bfd700abb68a98271fefa04-20-knowpoint-11")
.setAllowSpread(false) .setAllowSpread(false)
.setFailRetryCount(5) .setFailRetryCount(5)
.setThreadCount(20) .setThreadCount(20)
@ -62,7 +63,7 @@ public class SubjectService implements ISubjectService{
public void parse(Document html, Element pageVoElement, SubjectVo subjectVo) { public void parse(Document html, Element pageVoElement, SubjectVo subjectVo) {
// 解析封装 PageVo 对象 // 解析封装 PageVo 对象
String pageUrl = html.baseUri(); String pageUrl = html.baseUri();
if(pageUrl.contains("https://tiku.baidu.com/tikupc/chapterlist/")) { if(pageUrl.contains("https://tiku.baidu.com/tikupc/chapterlist/1bfd700abb68a98271fefa04-20-knowpoint-11")) {
logger.info("开始解析书籍:{}" , pageUrl); logger.info("开始解析书籍:{}" , pageUrl);
ChapterEntity chapterCondition = new ChapterEntity(); ChapterEntity chapterCondition = new ChapterEntity();
chapterCondition.setName(subjectVo.getChapterCurrName()); chapterCondition.setName(subjectVo.getChapterCurrName());
@ -82,6 +83,7 @@ public class SubjectService implements ISubjectService{
rootChapter.setTreeLevel(0); rootChapter.setTreeLevel(0);
rootChapter.setParentCodes("-1,"); rootChapter.setParentCodes("-1,");
rootChapter.setBookId(BOOK_ID); rootChapter.setBookId(BOOK_ID);
rootChapter.setSubjectId(SUBJECT_ID);
chapterMapper.insert(rootChapter); chapterMapper.insert(rootChapter);
Elements elements = pageVoElement.getElementsByClass("detail-chapter"); Elements elements = pageVoElement.getElementsByClass("detail-chapter");
@ -99,6 +101,7 @@ public class SubjectService implements ISubjectService{
chapter.setBookId(BOOK_ID); chapter.setBookId(BOOK_ID);
chapter.setTreeLeaf(false); chapter.setTreeLeaf(false);
chapter.setTreeLevel(1); chapter.setTreeLevel(1);
chapter.setSubjectId(SUBJECT_ID);
chapterMapper.insert(chapter); chapterMapper.insert(chapter);
chapter.setParentCodes(rootChapter.getParentCodes() + chapter.getId() + ","); chapter.setParentCodes(rootChapter.getParentCodes() + chapter.getId() + ",");
chapterMapper.updateById(chapter); chapterMapper.updateById(chapter);
@ -119,6 +122,7 @@ public class SubjectService implements ISubjectService{
chapter1.setQuestionNum(0); chapter1.setQuestionNum(0);
chapter1.setPointNum(0); chapter1.setPointNum(0);
chapter1.setOrders(i+1); chapter1.setOrders(i+1);
chapter1.setSubjectId(SUBJECT_ID);
chapter1.setTreeLeaf(false); chapter1.setTreeLeaf(false);
chapter1.setTreeLevel(2); chapter1.setTreeLevel(2);
@ -143,6 +147,7 @@ public class SubjectService implements ISubjectService{
chapter2.setOrders(k+1); chapter2.setOrders(k+1);
chapter2.setTreeLeaf(true); chapter2.setTreeLeaf(true);
chapter2.setTreeLevel(3); chapter2.setTreeLevel(3);
chapter2.setSubjectId(SUBJECT_ID);
chapterMapper.insert(chapter2); chapterMapper.insert(chapter2);
chapter2.setParentCodes(chapter1.getParentCodes() + chapter2.getId() + ","); chapter2.setParentCodes(chapter1.getParentCodes() + chapter2.getId() + ",");
chapterMapper.updateById(chapter2); chapterMapper.updateById(chapter2);

@ -1,3 +1,4 @@
package com.tamguo; package com.tamguo;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;

Loading…
Cancel
Save