图书管理章节拆分
This commit is contained in:
@@ -17,6 +17,7 @@ import com.peanut.common.utils.Query;
|
|||||||
import com.peanut.modules.book.dao.BookDao;
|
import com.peanut.modules.book.dao.BookDao;
|
||||||
import com.peanut.modules.book.entity.*;
|
import com.peanut.modules.book.entity.*;
|
||||||
import com.peanut.modules.book.entity.SysDictDataEntity;
|
import com.peanut.modules.book.entity.SysDictDataEntity;
|
||||||
|
import com.peanut.modules.book.service.BookChapterContentService;
|
||||||
import com.peanut.modules.book.service.BookChapterService;
|
import com.peanut.modules.book.service.BookChapterService;
|
||||||
import com.peanut.modules.book.service.BookService;
|
import com.peanut.modules.book.service.BookService;
|
||||||
import com.peanut.modules.book.service.PublisherService;
|
import com.peanut.modules.book.service.PublisherService;
|
||||||
@@ -52,6 +53,8 @@ public class BookServiceImpl extends ServiceImpl<BookDao, BookEntity> implements
|
|||||||
private BookChapterService bookChapterService;
|
private BookChapterService bookChapterService;
|
||||||
@Autowired
|
@Autowired
|
||||||
ConstantPropertiesUtils constantPropertiesUtils;
|
ConstantPropertiesUtils constantPropertiesUtils;
|
||||||
|
@Autowired
|
||||||
|
private BookChapterContentService bookChapterContentService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -452,86 +455,43 @@ public class BookServiceImpl extends ServiceImpl<BookDao, BookEntity> implements
|
|||||||
String novel = bookEntity.getNovel();
|
String novel = bookEntity.getNovel();
|
||||||
InputStream inputStream = FileDownloadUtil.getInputStream(novel);
|
InputStream inputStream = FileDownloadUtil.getInputStream(novel);
|
||||||
Document doc = new Document(inputStream);
|
Document doc = new Document(inputStream);
|
||||||
String title2Text = "";
|
int index = 0;
|
||||||
Map<String, List<String[]>> paraMap = new HashMap<>();
|
int x1 = 0;
|
||||||
Map<String, String> headMap = new HashMap<>();
|
int x2 = 0;
|
||||||
List<String> title_list = new ArrayList<>();
|
String chapterName = "";
|
||||||
|
int chapterId = 0;
|
||||||
for (int i = 0; i < doc.getSections().getCount(); i++) {
|
for (int i = 0; i < doc.getSections().getCount(); i++) {
|
||||||
String currentTitle = "";
|
|
||||||
Section section = doc.getSections().get(i);
|
Section section = doc.getSections().get(i);
|
||||||
for (int j = 0; j < section.getParagraphs().getCount() - 1; j++) {
|
for (int j = 0; j < section.getParagraphs().getCount() - 1; j++) {
|
||||||
Paragraph paragraph = section.getParagraphs().get(j);
|
Paragraph paragraph = section.getParagraphs().get(j);
|
||||||
if (paragraph.getStyleName().equals("Heading1")) {
|
BookChapterEntity chapter = new BookChapterEntity();
|
||||||
String textq = paragraph.getText();
|
chapter.setBookId(bookId);
|
||||||
currentTitle = textq;
|
chapter.setNumber(index++);
|
||||||
title_list.add(currentTitle);
|
chapter.setSort(j);
|
||||||
List<String[]> secondTitleList = new ArrayList<>();
|
if (paragraph.getStyleName().equals("Heading1")&&StringUtils.isNotBlank(paragraph.getText())) {
|
||||||
paraMap.put(currentTitle, secondTitleList);
|
x1 = j;
|
||||||
if (!section.getParagraphs().get(j + 1).getStyleName().matches("Heading2")) {
|
chapterName = paragraph.getText();
|
||||||
int head_index = j;
|
}else if (paragraph.getStyleName().equals("Heading2")&&StringUtils.isNotBlank(paragraph.getText())){
|
||||||
StringBuilder builder = new StringBuilder();
|
x2 = j;
|
||||||
do {
|
chapter.setChapter(chapterName);
|
||||||
builder.append(section.getParagraphs().get(head_index).getText());
|
chapter.setContent(paragraph.getText());
|
||||||
head_index++;
|
System.out.println(paragraph.getText());
|
||||||
//防止index超出异常发生
|
bookChapterService.save(chapter);
|
||||||
if (head_index >= section.getParagraphs().getCount()) {
|
chapterId = chapter.getId();
|
||||||
break;
|
}else if (StringUtils.isNotBlank(paragraph.getText())){
|
||||||
}
|
if (x1 > x2){
|
||||||
} while (!section.getParagraphs().get(head_index).getStyleName().equals("Heading2"));
|
chapter.setChapter(chapterName);
|
||||||
String head_text = builder.toString();
|
chapter.setContent(paragraph.getText());
|
||||||
headMap.put(currentTitle, head_text);
|
System.out.println(paragraph.getText());
|
||||||
|
bookChapterService.save(chapter);
|
||||||
}
|
|
||||||
} else if (paragraph.getStyleName().equals("Heading2") && StringUtils.isNotBlank(paragraph.getText().trim())) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
boolean isRun = false;
|
|
||||||
do {
|
|
||||||
if (isRun) {
|
|
||||||
builder.append(section.getParagraphs().get(j).getText());
|
|
||||||
}
|
|
||||||
isRun = true;
|
|
||||||
j++;
|
|
||||||
//防止index超出异常发生
|
|
||||||
if (j >= section.getParagraphs().getCount()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (!section.getParagraphs().get(j).getStyleName().equals("Heading2") && !section.getParagraphs().get(j).getStyleName().equals("Heading1"));
|
|
||||||
j--;
|
|
||||||
String text = builder.toString();
|
|
||||||
title2Text = paragraph.getText(); // 获取标题二的文本内容
|
|
||||||
if (null != title2Text && !"".equals(title2Text)) {
|
|
||||||
String[] s = new String[]{title2Text, text};
|
|
||||||
paraMap.get(currentTitle).add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int index = 0;
|
|
||||||
for (String title : title_list) {
|
|
||||||
if (null == paraMap.get(title) || paraMap.get(title).size() == 0) {
|
|
||||||
index++;
|
|
||||||
BookChapterEntity bookChapterEntity = new BookChapterEntity();
|
|
||||||
|
|
||||||
bookChapterEntity.setBookId(bookId);
|
|
||||||
bookChapterEntity.setNumber(index);
|
|
||||||
bookChapterEntity.setChapter(title);
|
|
||||||
bookChapterEntity.setSort(1);
|
|
||||||
if (null != headMap.get(title)) {
|
|
||||||
bookChapterEntity.setContent(headMap.get(title));
|
|
||||||
}else {
|
}else {
|
||||||
bookChapterEntity.setContent("");
|
BookChapterContentEntity content = new BookChapterContentEntity();
|
||||||
|
content.setBookId(bookId);
|
||||||
|
content.setBookChatperId(chapterId);
|
||||||
|
content.setNumber(index);
|
||||||
|
content.setContent(paragraph.getText());
|
||||||
|
bookChapterContentService.save(content);
|
||||||
}
|
}
|
||||||
bookChapterService.save(bookChapterEntity);
|
|
||||||
} else {
|
|
||||||
for (String[] t : paraMap.get(title)) {
|
|
||||||
index++;
|
|
||||||
BookChapterEntity bookChapterEntity = new BookChapterEntity();
|
|
||||||
bookChapterEntity.setBookId(bookId);
|
|
||||||
bookChapterEntity.setSort(2);
|
|
||||||
bookChapterEntity.setNumber(index);
|
|
||||||
bookChapterEntity.setChapter(title + "," + t[0]);
|
|
||||||
bookChapterEntity.setContent(t[1]);
|
|
||||||
bookChapterService.save(bookChapterEntity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user