修复的问题越来越多

main
SLMS Development Team 4 months ago
parent 11dbd595d2
commit c49f975e23

@ -297,31 +297,5 @@ public class VoiceController {
}
}
/**
*
*/
private String parseXunFeiResponse(String json) {
try {
// 简单解析提取ws字段中的cw内容
if (!json.contains("\"ws\"")) return null;
StringBuilder text = new StringBuilder();
int wsStart = json.indexOf("\"ws\"");
if (wsStart == -1) return null;
// 查找所有 "w":" 模式
int pos = wsStart;
while ((pos = json.indexOf("\"w\":\"", pos)) != -1) {
pos += 5;
int end = json.indexOf("\"", pos);
if (end > pos) {
text.append(json.substring(pos, end));
pos = end;
}
}
return text.toString();
} catch (Exception e) {
return null;
}
}
}

@ -36,6 +36,17 @@ public class WebController {
private final AIService aiService;
private static final int PAGE_SIZE = 10;
// Model attribute constants
private static final String BOOKS_ATTR = "books";
private static final String TOTAL_PAGES_ATTR = "totalPages";
private static final String LOGIN_VIEW = "login";
private static final String REDIRECT_HOME = "redirect:/";
private static final String ERROR_ATTR = "error";
private static final String BUILD_LIBS_PATH = "/build/libs/";
private static final String MODEL_ATTR = "model";
private static final String BOOKS_VIEW = "books";
private static final String LOANS_VIEW = "loans";
public WebController() {
this.bookService = new BookService();
@ -84,19 +95,19 @@ public class WebController {
// 分页
int total = allBooks.size();
int totalPages = (int) Math.ceil((double) total / PAGE_SIZE);
page = Math.max(1, Math.min(page, Math.max(1, totalPages)));
page = Math.clamp(page, 1, Math.max(1, totalPages));
int start = (page - 1) * PAGE_SIZE;
int end = Math.min(start + PAGE_SIZE, total);
List<Book> books = allBooks.subList(start, end);
model.addAttribute("books", books);
model.addAttribute(BOOKS_ATTR, books);
model.addAttribute("currentPage", page);
model.addAttribute("totalPages", totalPages);
model.addAttribute(TOTAL_PAGES_ATTR, totalPages);
model.addAttribute("totalBooks", total);
model.addAttribute("category", category);
model.addAttribute("keyword", keyword);
model.addAttribute("user", session.getAttribute("user"));
return "books";
return BOOKS_VIEW;
}
@GetMapping("/loans")
@ -106,23 +117,23 @@ public class WebController {
int total = allLoans.size();
int totalPages = (int) Math.ceil((double) total / PAGE_SIZE);
page = Math.max(1, Math.min(page, Math.max(1, totalPages)));
page = Math.clamp(page, 1, Math.max(1, totalPages));
int start = (page - 1) * PAGE_SIZE;
int end = Math.min(start + PAGE_SIZE, total);
List<Loan> loans = allLoans.subList(start, end);
model.addAttribute("loans", loans);
model.addAttribute("currentPage", page);
model.addAttribute("totalPages", totalPages);
model.addAttribute(TOTAL_PAGES_ATTR, totalPages);
model.addAttribute("user", session.getAttribute("user"));
return "loans";
return LOANS_VIEW;
}
// ==================== 用户登录 ====================
@GetMapping("/login")
public String loginPage() {
return "login";
return LOGIN_VIEW;
}
@PostMapping("/login")
@ -132,10 +143,10 @@ public class WebController {
User user = userService.login(email, password);
if (user != null) {
session.setAttribute("user", user);
return "redirect:/";
return REDIRECT_HOME;
}
model.addAttribute("error", "邮箱或密码错误");
return "login";
model.addAttribute(ERROR_ATTR, "邮箱或密码错误");
return LOGIN_VIEW;
}
@GetMapping("/login/quick/{type}")
@ -150,7 +161,7 @@ public class WebController {
if (user != null) {
session.setAttribute("user", user);
}
return "redirect:/";
return REDIRECT_HOME;
}
@GetMapping("/logout")
@ -177,7 +188,7 @@ public class WebController {
model.addAttribute("success", "注册成功,请等待审核");
return "login";
}
model.addAttribute("error", "注册失败,邮箱可能已存在");
model.addAttribute(ERROR_ATTR, "注册失败,邮箱可能已存在");
return "register";
}
@ -238,7 +249,7 @@ public class WebController {
if (success) {
return "redirect:/books?success=true";
}
model.addAttribute("error", "图书添加失败");
model.addAttribute(ERROR_ATTR, "图书添加失败");
return "add-book";
}
@ -267,7 +278,7 @@ public class WebController {
if (success) {
return "redirect:/loans?borrowSuccess=true";
}
model.addAttribute("error", "借阅失败,图书可能不存在或已被借出");
model.addAttribute(ERROR_ATTR, "借阅失败,图书可能不存在或已被借出");
return "borrow-book";
}
@ -283,7 +294,7 @@ public class WebController {
if (success) {
return "redirect:/loans?returnSuccess=true";
}
model.addAttribute("error", "归还失败");
model.addAttribute(ERROR_ATTR, "归还失败");
return "return-book";
}
@ -330,9 +341,9 @@ public class WebController {
private ResponseEntity<Resource> downloadJar(String module, String filename) {
// 尝试多个可能的JAR路径
String[] possiblePaths = {
module + "/build/libs/" + filename,
module + "/build/libs/" + module + "-1.0.0-all.jar",
module + "/build/libs/" + module + ".jar"
module + BUILD_LIBS_PATH + filename,
module + BUILD_LIBS_PATH + module + "-1.0.0-all.jar",
module + BUILD_LIBS_PATH + module + ".jar"
};
for (String pathStr : possiblePaths) {
@ -365,10 +376,10 @@ public class WebController {
int end = Math.min(start + size, total);
Map<String, Object> result = new HashMap<>();
result.put("books", allBooks.subList(start, end));
result.put(BOOKS_ATTR, allBooks.subList(start, end));
result.put("total", total);
result.put("page", page);
result.put("totalPages", (int) Math.ceil((double) total / size));
result.put(TOTAL_PAGES_ATTR, (int) Math.ceil((double) total / size));
return result;
}
@ -456,9 +467,9 @@ public class WebController {
public Map<String, Object> getAiProviders() {
Map<String, Object> result = new HashMap<>();
result.put("providers", List.of(
Map.of("id", "deepseek", "name", "DeepSeek", "model", "deepseek-chat"),
Map.of("id", "zhipu", "name", "智谱AI", "model", "GLM-4"),
Map.of("id", "mock", "name", "演示模式", "model", "Mock")
Map.of("id", "deepseek", "name", "DeepSeek", MODEL_ATTR, "deepseek-chat"),
Map.of("id", "zhipu", "name", "智谱AI", MODEL_ATTR, "GLM-4"),
Map.of("id", "mock", "name", "演示模式", MODEL_ATTR, "Mock")
));
result.put("default", "deepseek");
return result;

@ -1,6 +1,6 @@
package com.smartlibrary.backend.acceptance;
import com.smartlibrary.factory.BookFactoryProvider;
import com.smartlibrary.model.Book;
import com.smartlibrary.model.Loan;
import com.smartlibrary.model.User;

@ -2,13 +2,7 @@ package com.smartlibrary.backend.integration;
import com.smartlibrary.model.Book;
import com.smartlibrary.model.Loan;
import com.smartlibrary.notification.EmailNotification;
import com.smartlibrary.notification.InAppNotification;
import com.smartlibrary.notification.Notification;
import com.smartlibrary.notification.SMSNotification;
import com.smartlibrary.observer.BookEventType;
import com.smartlibrary.observer.BookNotificationObserver;
import com.smartlibrary.observer.BookStatusManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@ -1,6 +1,6 @@
package com.smartlibrary.mock;
import com.smartlibrary.mock.MockDataFactory;
import com.smartlibrary.model.Book;
import com.smartlibrary.model.Loan;
import com.smartlibrary.factory.BookFactory;

@ -1,21 +1,11 @@
package com.smartlibrary.cli;
import com.smartlibrary.model.Book;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;
/**
* AI
* AI
*/
public class AICommandHandler {
private final Scanner scanner;
private boolean aiServicesAvailable = false;
public AICommandHandler(Scanner scanner) {
this.scanner = scanner;
public AICommandHandler() {
System.out.println("[AI] AI服务功能开发中暂时使用基础功能");
}
@ -43,6 +33,7 @@ public class AICommandHandler {
public void handleSummary(String bookId) {
System.out.println("\n[摘要] 图书摘要:");
System.out.println("抱歉,图书摘要功能正在开发中!");
System.out.println("图书ID" + bookId);
System.out.println("提示此功能需要集成智谱AI服务");
}

@ -1,15 +1,20 @@
package com.smartlibrary.cli;
import com.smartlibrary.service.*;
import com.smartlibrary.model.*;
import com.smartlibrary.ai.SmartAIService;
import com.smartlibrary.ai.AIIndexService;
import com.smartlibrary.ai.DeepSeekService;
import com.smartlibrary.ai.AIService;
import com.smartlibrary.model.Book;
import com.smartlibrary.model.User;
import com.smartlibrary.service.BookService;
import com.smartlibrary.service.UserService;
import com.smartlibrary.service.LoanHistoryService;
import com.smartlibrary.service.ReaderInteractionService;
import com.smartlibrary.service.NotificationService;
import com.smartlibrary.service.SystemSettingsService;
import com.smartlibrary.service.ReservationService;
import com.smartlibrary.voice.XunFeiSpeechService;
import com.smartlibrary.voice.XunFeiIATService;
import com.smartlibrary.voice.VoiceException;
import com.smartlibrary.util.QRCodeUtil;
import com.smartlibrary.ai.DeepSeekService;
import com.smartlibrary.ai.SmartAIService;
import com.smartlibrary.ai.AIIndexService;
import java.time.LocalDate;
import java.util.List;
import java.util.Scanner;
@ -22,51 +27,35 @@ public class CLIApplication {
private final BookService bookService;
private final UserService userService;
private final NotificationService notificationService;
private final ReservationService reservationService;
private final LoanHistoryService loanHistoryService;
private final ReaderInteractionService readerService;
private final StatisticsService statisticsService;
private final SystemSettingsService settingsService;
private final SmartAIService aiService;
private final AIService deepSeekService;
private final DeepSeekService deepSeekService;
private final AIIndexService aiIndexService;
private final XunFeiSpeechService speechService;
private final MockDataService mockDataService;
private final SystemSettingsService settingsService;
private final ReservationService reservationService;
private final Scanner scanner;
private final XunFeiSpeechService speechService;
private boolean running = true;
private User currentUser = null;
private String lastAIResponse = ""; // 保存最后一次AI回复用于语音播报
private String lastAIResponse = "";
public CLIApplication() {
this.bookService = new BookService();
this.userService = new UserService();
this.notificationService = new NotificationService();
this.reservationService = new ReservationService();
this.loanHistoryService = new LoanHistoryService();
this.readerService = new ReaderInteractionService();
this.statisticsService = new StatisticsService();
this.settingsService = new SystemSettingsService();
this.aiService = new SmartAIService();
this.deepSeekService = new DeepSeekService();
this.aiIndexService = new AIIndexService();
this.settingsService = new SystemSettingsService();
this.reservationService = new ReservationService();
this.speechService = new XunFeiSpeechService();
this.mockDataService = new MockDataService(bookService);
this.scanner = new Scanner(System.in);
// 初始化Mock数据如果数据库为空
initializeMockDataIfNeeded();
}
/**
* Mock便
*/
private void initializeMockDataIfNeeded() {
if (mockDataService.needsInitialization()) {
System.out.println("📚 首次运行,正在初始化示例数据...");
mockDataService.initializeMockData();
System.out.println("✓ 示例数据初始化完成!");
}
}
public static void main(String[] args) {
System.out.println("=================================");

@ -24,7 +24,7 @@ class AICommandHandlerTest {
@BeforeEach
void setUp() {
Scanner scanner = new Scanner(new ByteArrayInputStream("".getBytes()));
handler = new AICommandHandler(scanner);
handler = new AICommandHandler();
// 捕获输出
outputStream = new ByteArrayOutputStream();

@ -1,5 +1,5 @@
#MCSLMS DataSource Configuration - v1.7.0
#Tue Dec 16 14:57:32 CST 2025
#Tue Dec 16 18:13:49 CST 2025
database.host=127.0.0.1
database.name=testdb
database.password=

Loading…
Cancel
Save