diff --git a/backend/src/main/java/com/smartlibrary/backend/controller/WebController.java b/backend/src/main/java/com/smartlibrary/backend/controller/WebController.java index 9962207..7c972ef 100644 --- a/backend/src/main/java/com/smartlibrary/backend/controller/WebController.java +++ b/backend/src/main/java/com/smartlibrary/backend/controller/WebController.java @@ -4,6 +4,9 @@ import com.smartlibrary.model.Book; import com.smartlibrary.model.Loan; import com.smartlibrary.service.BookService; import com.smartlibrary.service.StatisticsService; +import com.smartlibrary.service.NotificationService; +import com.smartlibrary.service.LoanHistoryService; +import com.smartlibrary.service.ReservationService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @@ -296,6 +299,74 @@ public class WebController { return statisticsService.getMonthlyBorrowTrend(12); } + // ========== v1.5.0 通知与历史 ========== + + /** + * 用户通知中心页面 + */ + @GetMapping("/notifications") + public String notifications(@RequestParam(defaultValue = "GUEST") String userId, Model model) { + NotificationService notificationService = new NotificationService(); + model.addAttribute("notifications", notificationService.getUserNotifications(userId)); + model.addAttribute("unreadCount", notificationService.getUnreadCount(userId)); + model.addAttribute("userId", userId); + return "notifications"; + } + + /** + * 借阅历史页面 + */ + @GetMapping("/history") + public String loanHistory(@RequestParam(defaultValue = "GUEST") String userId, Model model) { + LoanHistoryService historyService = new LoanHistoryService(); + model.addAttribute("history", historyService.getUserHistory(userId)); + model.addAttribute("totalFine", historyService.getTotalFine(userId)); + model.addAttribute("userId", userId); + return "history"; + } + + /** + * 预约管理页面 + */ + @GetMapping("/reservations") + public String reservations(@RequestParam(defaultValue = "GUEST") String userId, Model model) { + ReservationService reservationService = new ReservationService(); + model.addAttribute("reservations", reservationService.getUserReservations(userId)); + model.addAttribute("userId", userId); + model.addAttribute("books", bookService.findAllBooks()); + return "reservations"; + } + + /** + * 预约图书 + */ + @PostMapping("/reservations/add") + public String addReservation(@RequestParam String bookId, @RequestParam String userId) { + ReservationService reservationService = new ReservationService(); + reservationService.reserveBook(bookId, userId); + return "redirect:/reservations?userId=" + userId + "&success=true"; + } + + /** + * 取消预约 + */ + @PostMapping("/reservations/cancel/{id}") + public String cancelReservation(@PathVariable String id, @RequestParam String userId) { + ReservationService reservationService = new ReservationService(); + reservationService.cancelReservation(id); + return "redirect:/reservations?userId=" + userId + "&cancelled=true"; + } + + /** + * 续借图书 + */ + @PostMapping("/loans/renew/{loanId}") + public String renewLoan(@PathVariable String loanId) { + LoanHistoryService historyService = new LoanHistoryService(); + historyService.renewLoan(loanId); + return "redirect:/loans?renewed=true"; + } + /** * 切换端说明页面 */ diff --git a/backend/src/main/resources/templates/fragments/layout.html b/backend/src/main/resources/templates/fragments/layout.html index c804dc8..f4da0d1 100644 --- a/backend/src/main/resources/templates/fragments/layout.html +++ b/backend/src/main/resources/templates/fragments/layout.html @@ -12,7 +12,10 @@ - + + + + diff --git a/backend/src/main/resources/templates/history.html b/backend/src/main/resources/templates/history.html new file mode 100644 index 0000000..e24f50a --- /dev/null +++ b/backend/src/main/resources/templates/history.html @@ -0,0 +1,149 @@ + + + + + + 借阅历史 - MCSLMS v1.5.0 + + + + +