feat(图书初步): 图书初步
This commit is contained in:
Guwan 2024-12-15 22:24:00 +08:00
parent 0350786d00
commit bc378ee9ec
6 changed files with 2596 additions and 6 deletions

View File

@ -24,6 +24,7 @@ public class DatabaseInitConfig implements ApplicationRunner {
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(new ClassPathResource("db/schema.sql"));
populator.addScript(new ClassPathResource("db/data.sql"));
// populator.addScript(new ClassPathResource("db/daaixianzun.sql"));
populator.setContinueOnError(true);
populator.execute(dataSource);
log.info("数据库初始化完成");

View File

@ -20,6 +20,9 @@ public class SecurityConstants {
"/api/user/getEmailCode", // 获取邮箱验证码
"/api/user/getPhoneCode", // 获取手机验证码
"/chat.html",
"/daxz.html/**",
"/polling-chat.html",
"/ws/chat/**",

View File

@ -9,14 +9,15 @@ import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -128,7 +129,7 @@ public class CommonController {
// 输出该卷的每一节标题和正文内容
for (int j = 0; j < sections.size(); j++) {
System.out.print(volumes.get(i));
// System.out.print(volumes.get(i));
String section = sections.get(j);
String sectionContent = sectionContents.get(j);
@ -153,7 +154,7 @@ public class CommonController {
bookContent.setSection(section);
bookContent.setSectionContent(sectionContent);
System.out.println("bookContent = " + bookContent);
bookContents.add(bookContent);
@ -166,10 +167,32 @@ public class CommonController {
}
@GetMapping("/getBookComment")
public Result<String> getBookComment(Long id) {
BookContent bookContent = bookContentService.getById(id);
return Result.success(bookContent.getSectionContent());
}
@GetMapping("/getBookCommentByPath")
public ResponseEntity<Map<String, Object>> getBookCommentByPath(@RequestParam("id") Long id) {
// 从数据库中获取评论内容
String comments = bookContentService.getById(id).getSectionContent();
BookContent byId = bookContentService.getById(id);
// 构造返回数据
Map<String, Object> response = new HashMap<>();
response.put("data", byId);
return ResponseEntity.ok(response);
}

File diff suppressed because one or more lines are too long

View File

@ -59,4 +59,18 @@ CREATE TABLE `video` (
PRIMARY KEY (`id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_created_time` (`created_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='视频表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='视频表';
CREATE TABLE IF NOT EXISTS `book_content` (
`id` bigint NOT NULL AUTO_INCREMENT,
`book_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`volume` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`section` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`section_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2342 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -0,0 +1,171 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>大爱仙尊 - Book Comments</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
text-align: left;
padding-left: 20px;
}
.container {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 20px;
max-width: 800px;
width: 100%;
height: 90%;
overflow-y: auto;
}
h1 {
color: #333;
margin-bottom: 20px;
}
#comments {
margin: 20px 0;
padding: 15px;
background-color: #f9f9f9;
border-radius: 8px;
min-height: 200px;
font-size: 16px;
color: #555;
white-space: pre-wrap;
line-height: 1.8;
max-height: 420px;
overflow-y: auto;
}
#comments p {
text-indent: 2em;
margin-bottom: 10px;
}
.button-container {
margin-top: 20px;
}
button {
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin: 0 10px;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
button:disabled {
background-color: #ddd;
cursor: not-allowed;
}
</style>
</head>
<body>
<div class="container">
<h4 id="pageTitle">Loading...</h4>
<div id="comments">Loading comments...</div>
<div class="button-container">
<button id="prevButton" onclick="navigateComment('prev')">上一节</button>
<button id="nextButton" onclick="navigateComment('next')">下一节</button>
</div>
</div>
<script>
let bookId = 1; // Default book ID
const commentsPerPage = 1; // Number of comments per page
let currentPage = 1; // Current page number
// Get bookId from URL parameters
const urlParams = new URLSearchParams(window.location.search);
bookId = urlParams.get('id') || 1; // Get id from query string or default to 1
async function getComment() {
try {
const response = await fetch(`/common/getBookCommentByPath?id=${bookId}`);
const data = await response.json();
if (data && data.data) {
console.log(data.data)
// 拼接卷和节作为标题
const volumeTitle = data.data.volume || 'Unknown Volume';
const sectionTitle = data.data.section || 'Unknown Section';
const fullTitle = `${volumeTitle} - ${sectionTitle}`;
// 设置页面标题
document.title = fullTitle; // 设置浏览器标签页标题
document.getElementById("pageTitle").innerHTML = fullTitle;
data.data.volume + data.data.section
document.getElementById("comments").innerHTML = formatContent(data.data.sectionContent);
checkButtonState();
setTimeout(scrollToTop, 0); // Use setTimeout to ensure it's executed after DOM update
} else {
document.getElementById("comments").innerHTML = "No comments found.";
}
} catch (error) {
console.log("Error fetching data:", error);
}
}
// Format content to add indent and paragraph spacing
function formatContent(content) {
const paragraphs = content.split('\n').map(paragraph => `<p>${paragraph}</p>`).join('');
return paragraphs;
}
// Navigation function to go to previous or next comment
function navigateComment(direction) {
if (direction === 'prev') {
currentPage = Math.max(1, currentPage - 1); // Ensure page number doesn't go below 1
} else if (direction === 'next') {
currentPage = currentPage + 1; // Increment for next page
}
// Update URL and reload comment
bookId = currentPage;
getComment();
}
// Check button state based on the current page
function checkButtonState() {
document.getElementById("prevButton").disabled = currentPage === 1;
document.getElementById("nextButton").disabled = currentPage === 100000; // Assuming 10 pages, adjust as needed
}
// Scroll the page to the top
function scrollToTop() {
console.log("Scrolling to top..."); // Debug log
window.scrollTo(0, 0); // Scroll to the top of the page
}
// Load comments when the page is ready
getComment();
</script>
</body>
</html>