diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index a4d6df9..9d588ba 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -13,5 +13,17 @@
$ProjectFileDir$
+
+ mysql.8
+ true
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://mysql.lanyuanxiaoyao.com:43780/bookstore
+
+
+
+
+
+ $ProjectFileDir$
+
\ No newline at end of file
diff --git a/.idea/data_source_mapping.xml b/.idea/data_source_mapping.xml
new file mode 100644
index 0000000..e31d277
--- /dev/null
+++ b/.idea/data_source_mapping.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/client/src/pages/book/Chapter.tsx b/client/src/pages/book/Chapter.tsx
index 36eb976..60be467 100644
--- a/client/src/pages/book/Chapter.tsx
+++ b/client/src/pages/book/Chapter.tsx
@@ -62,7 +62,7 @@ function Chapter() {
actionType: 'ajax',
tooltip: '序号重排',
tooltipPlacement: 'top',
- api: `get:${commonInfo.baseUrl}/line/generate_sequence`
+ api: `get:${commonInfo.baseUrl}/line/generate_sequence/${id}`
}
]
),
diff --git a/src/main/java/com/lanyuanxiaoyao/bookstore/BookStoreApplication.java b/src/main/java/com/lanyuanxiaoyao/bookstore/BookStoreApplication.java
index 9383c59..df504be 100644
--- a/src/main/java/com/lanyuanxiaoyao/bookstore/BookStoreApplication.java
+++ b/src/main/java/com/lanyuanxiaoyao/bookstore/BookStoreApplication.java
@@ -1,10 +1,23 @@
package com.lanyuanxiaoyao.bookstore;
+import cn.hutool.core.lang.Tuple;
+import cn.hutool.core.text.csv.CsvUtil;
+import cn.hutool.core.util.NumberUtil;
+import cn.hutool.core.util.ObjectUtil;
import com.blinkfox.fenix.EnableFenix;
+import com.lanyuanxiaoyao.bookstore.entity.Chapter;
+import com.lanyuanxiaoyao.bookstore.entity.Line;
+import com.lanyuanxiaoyao.bookstore.service.BookService;
+import com.lanyuanxiaoyao.bookstore.service.ChapterService;
+import jakarta.annotation.Resource;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.stream.Collectors;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+import org.springframework.transaction.annotation.Transactional;
/**
* 启动类
@@ -20,4 +33,44 @@ public class BookStoreApplication {
public static void main(String[] args) {
SpringApplication.run(BookStoreApplication.class, args);
}
+
+ @Resource
+ private BookService bookService;
+ @Resource
+ private ChapterService chapterService;
+
+ @Transactional(rollbackFor = Throwable.class)
+ // @EventListener(ApplicationReadyEvent.class)
+ public void loadOldData() throws FileNotFoundException {
+ var reader = CsvUtil.getReader(new FileReader("C:\\Users\\lanyuanxiaoyao\\Result_6.csv"));
+ var rows = reader.stream()
+ .map(row -> new Row(Long.parseLong(row.get(0)), row.get(1), Long.parseLong(row.get(2)), row.get(3)))
+ .toList();
+ var book = bookService.detailOrThrow(3602572744994816L);
+ rows.stream()
+ .map(row -> new Tuple(row.chapterSequence(), row.chapterTitle()))
+ .distinct()
+ .forEach(tuple -> {
+ var chapter = new Chapter();
+ chapter.setSequence(NumberUtil.toDouble(tuple.get(0)));
+ chapter.setName(tuple.get(1));
+ chapter.setBook(book);
+
+ var lines = rows.stream()
+ .filter(row -> ObjectUtil.equals(row.chapterSequence(), tuple.get(0)) && ObjectUtil.equals(row.chapterTitle(), tuple.get(1)))
+ .map(row -> {
+ var line = new Line();
+ line.setSequence(NumberUtil.toDouble(row.lineSequence()));
+ line.setText(row.lineText());
+ line.setChapter(chapter);
+ return line;
+ })
+ .collect(Collectors.toSet());
+ chapter.setContent(lines);
+ chapterService.save(chapter);
+ });
+ }
+
+ public record Row(long chapterSequence, String chapterTitle, long lineSequence, String lineText) {
+ }
}
diff --git a/src/main/java/com/lanyuanxiaoyao/bookstore/controller/ChapterController.java b/src/main/java/com/lanyuanxiaoyao/bookstore/controller/ChapterController.java
index 47ebf6a..25ae242 100644
--- a/src/main/java/com/lanyuanxiaoyao/bookstore/controller/ChapterController.java
+++ b/src/main/java/com/lanyuanxiaoyao/bookstore/controller/ChapterController.java
@@ -129,7 +129,7 @@ public class ChapterController extends SimpleControllerSupport generateSequence() {
- lineService.generateSequence();
+ @GetMapping("generate_sequence/{chapter_id}")
+ public GlobalResponse