Compare commits
18 Commits
h-hein
...
879d7235e0
| Author | SHA1 | Date | |
|---|---|---|---|
| 879d7235e0 | |||
| 0754c4507e | |||
| ef71711641 | |||
| 6b2c08c031 | |||
| b128e92598 | |||
| 1585457395 | |||
| 3e1eb9f6bd | |||
| 0566219226 | |||
| a2a406dd8b | |||
| 81d722be8d | |||
| 97e8df70f5 | |||
| bb34fe164e | |||
| cdfdef6d93 | |||
| 945d8a465a | |||
| eaaf022694 | |||
| 87cdd2ca48 | |||
| 174f843618 | |||
| f370d03e10 |
@@ -1,2 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>4.1.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>book-rent</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<name>book-rent</name>
|
||||
<description/>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-testCompile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.example.demo.common;
|
||||
|
||||
public class BusinessException {
|
||||
public class BusinessException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public BusinessException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
package com.example.demo.common;
|
||||
|
||||
public class Const {
|
||||
|
||||
|
||||
/** テーブル定義書のコード値(数値の直書きを避けるため一箇所に集約) */
|
||||
public final class Const {
|
||||
private Const() {}
|
||||
|
||||
public static final String SESSION_LOGIN_USER = "loginUser";
|
||||
|
||||
/** 管理者フラグ */
|
||||
public static final String ADMIN_NO = "0";
|
||||
public static final String ADMIN_YES = "1";
|
||||
|
||||
/** 初期パスワード(機能一覧 EMP-01) */
|
||||
public static final String DEFAULT_PASSWORD = "sakura2024";
|
||||
|
||||
/** 退職フラグ */
|
||||
public static final String RETIRE_NO = "0";
|
||||
public static final String RETIRE_YES = "1";
|
||||
|
||||
/** 貸出フラグ */
|
||||
public static final String LENDING_OK = "0"; // 貸出可
|
||||
public static final String LENDING_NG = "1"; // 貸出不可
|
||||
|
||||
/** 貸出ステータス */
|
||||
public static final String STATUS_RETURNED = "0"; // 返却済
|
||||
public static final String STATUS_WAITING = "1"; // 承認待
|
||||
public static final String STATUS_LENDING = "2"; // 貸出中
|
||||
public static final String STATUS_REJECTED = "9"; // 却下
|
||||
}
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
package com.example.demo.common;
|
||||
|
||||
public class LoginUser {
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/** セッションに保持するログイン情報(社員ID・社員名・社員名よみ・メールアドレス・管理者フラグ) */
|
||||
public class LoginUser implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Integer idEmployee;
|
||||
private final String nmEmployee;
|
||||
private final String knEmployee;
|
||||
private final String mailAddress;
|
||||
private final String flgAdmin;
|
||||
|
||||
public LoginUser(Integer idEmployee, String nmEmployee, String knEmployee, String mailAddress, String flgAdmin) {
|
||||
this.idEmployee = idEmployee;
|
||||
this.nmEmployee = nmEmployee;
|
||||
this.knEmployee = knEmployee;
|
||||
this.mailAddress = mailAddress;
|
||||
this.flgAdmin = flgAdmin;
|
||||
}
|
||||
|
||||
public Integer getIdEmployee() { return idEmployee; }
|
||||
public String getNmEmployee() { return nmEmployee; }
|
||||
public String getKnEmployee() { return knEmployee; }
|
||||
public String getMailAddress() { return mailAddress; }
|
||||
public String getFlgAdmin() { return flgAdmin; }
|
||||
public boolean isAdmin() { return Const.ADMIN_YES.equals(flgAdmin); }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,37 @@
|
||||
package com.example.demo.config;
|
||||
|
||||
public class LoginCheckInterceptor {
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
|
||||
/**
|
||||
* 全業務画面共通のアクセス制御(NFR-02)。
|
||||
* ・未ログイン → ログイン画面へ
|
||||
* ・/admin/** は管理者のみ(画面のボタン非表示だけでなくサーバー側でも確認)
|
||||
*/
|
||||
public class LoginCheckInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
// ブラウザの「戻る」でログアウト後の画面が見えないようにする
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
|
||||
HttpSession session = request.getSession(false);
|
||||
LoginUser user = session == null ? null : (LoginUser) session.getAttribute(Const.SESSION_LOGIN_USER);
|
||||
if (user == null) {
|
||||
response.sendRedirect(request.getContextPath() + "/login");
|
||||
return false;
|
||||
}
|
||||
String path = request.getRequestURI().substring(request.getContextPath().length());
|
||||
if (path.startsWith("/admin") && !user.isAdmin()) {
|
||||
response.sendRedirect(request.getContextPath() + "/menu");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
package com.example.demo.config;
|
||||
|
||||
public class WebConfig {
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new LoginCheckInterceptor())
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/login", "/css/**", "/js/**", "/error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,125 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
public class AdminBookController {
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.SessionAttribute;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.example.demo.common.BusinessException;
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.form.BookForm;
|
||||
import com.example.demo.service.BookAdminService;
|
||||
|
||||
/** BOOK-02 書籍登録 / BOOK-03 書籍編集(管理者のみ:/admin/** で拒否)。入力 → 確認 → 完了 */
|
||||
@Controller
|
||||
public class AdminBookController {
|
||||
private static final String NEW = "/admin/books/new";
|
||||
private static final String EDIT = "/admin/books/edit";
|
||||
|
||||
private final BookAdminService bookAdminService;
|
||||
|
||||
public AdminBookController(BookAdminService bookAdminService) {
|
||||
this.bookAdminService = bookAdminService;
|
||||
}
|
||||
|
||||
// ===== BOOK-02 登録 =====
|
||||
@GetMapping(NEW)
|
||||
public String newInput(Model model) {
|
||||
return input(new BookForm(), List.of(), "書籍登録", NEW, model);
|
||||
}
|
||||
|
||||
@PostMapping(NEW + "/input")
|
||||
public String newBack(@ModelAttribute("form") BookForm form, Model model) {
|
||||
return input(form, List.of(), "書籍登録", NEW, model);
|
||||
}
|
||||
|
||||
@PostMapping(NEW + "/confirm")
|
||||
public String newConfirm(@ModelAttribute("form") BookForm form, Model model) {
|
||||
List<String> errors = bookAdminService.validate(form);
|
||||
if (!errors.isEmpty()) return input(form, errors, "書籍登録", NEW, model);
|
||||
return confirm("書籍登録", NEW, model);
|
||||
}
|
||||
|
||||
@PostMapping(NEW + "/execute")
|
||||
public String newExecute(@ModelAttribute("form") BookForm form,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser admin,
|
||||
Model model, RedirectAttributes ra) {
|
||||
try {
|
||||
bookAdminService.register(form, admin);
|
||||
} catch (BusinessException e) {
|
||||
return input(form, List.of(e.getMessage()), "書籍登録", NEW, model);
|
||||
}
|
||||
ra.addFlashAttribute("message", "書籍登録が完了しました。");
|
||||
return "redirect:" + NEW + "/complete";
|
||||
}
|
||||
|
||||
@GetMapping(NEW + "/complete")
|
||||
public String newComplete(Model model) {
|
||||
model.addAttribute("backUrl", "/books");
|
||||
model.addAttribute("backLabel", "書籍一覧に戻る");
|
||||
return "complete";
|
||||
}
|
||||
|
||||
// ===== BOOK-03 編集 =====
|
||||
@GetMapping(EDIT)
|
||||
public String editInput(@RequestParam Integer idBook, Model model, RedirectAttributes ra) {
|
||||
try {
|
||||
BookForm form = bookAdminService.toForm(bookAdminService.find(idBook));
|
||||
return input(form, List.of(), "書籍編集", EDIT, model);
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/books";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(EDIT + "/input")
|
||||
public String editBack(@ModelAttribute("form") BookForm form, Model model) {
|
||||
return input(form, List.of(), "書籍編集", EDIT, model);
|
||||
}
|
||||
|
||||
@PostMapping(EDIT + "/confirm")
|
||||
public String editConfirm(@ModelAttribute("form") BookForm form, Model model) {
|
||||
List<String> errors = bookAdminService.validate(form);
|
||||
if (!errors.isEmpty()) return input(form, errors, "書籍編集", EDIT, model);
|
||||
return confirm("書籍編集", EDIT, model);
|
||||
}
|
||||
|
||||
@PostMapping(EDIT + "/execute")
|
||||
public String editExecute(@ModelAttribute("form") BookForm form,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser admin,
|
||||
Model model, RedirectAttributes ra) {
|
||||
try {
|
||||
bookAdminService.update(form, admin);
|
||||
} catch (BusinessException e) {
|
||||
return input(form, List.of(e.getMessage()), "書籍編集", EDIT, model);
|
||||
}
|
||||
ra.addFlashAttribute("message", "書籍編集が完了しました。");
|
||||
return "redirect:" + EDIT + "/complete";
|
||||
}
|
||||
|
||||
@GetMapping(EDIT + "/complete")
|
||||
public String editComplete(Model model) {
|
||||
return newComplete(model);
|
||||
}
|
||||
|
||||
private String input(BookForm form, List<String> errors, String title, String base, Model model) {
|
||||
model.addAttribute("form", form);
|
||||
model.addAttribute("errors", errors);
|
||||
model.addAttribute("title", title);
|
||||
model.addAttribute("base", base);
|
||||
return "bookInput";
|
||||
}
|
||||
|
||||
private String confirm(String title, String base, Model model) {
|
||||
model.addAttribute("title", title);
|
||||
model.addAttribute("base", base);
|
||||
return "bookConfirm";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,118 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
public class AdminLoanController {
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.SessionAttribute;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.example.demo.common.BusinessException;
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.service.LoanService;
|
||||
|
||||
/**
|
||||
* 管理者用:LOAN-02 申請一覧、LOAN-03 承認/却下、LOAN-04 貸出中一覧、LOAN-05 返却。
|
||||
* /admin/** は LoginCheckInterceptor で管理者以外を拒否する。
|
||||
*/
|
||||
@Controller
|
||||
public class AdminLoanController {
|
||||
private final LoanService loanService;
|
||||
|
||||
public AdminLoanController(LoanService loanService) {
|
||||
this.loanService = loanService;
|
||||
}
|
||||
|
||||
// ===== LOAN-02 書籍申請一覧(承認待) =====
|
||||
@GetMapping("/admin/applications")
|
||||
public String applications(Model model) {
|
||||
model.addAttribute("list", loanService.listByStatus(Const.STATUS_WAITING));
|
||||
return "applicationList";
|
||||
}
|
||||
|
||||
// ===== LOAN-03 承認/却下 =====
|
||||
@GetMapping("/admin/applications/{id}")
|
||||
public String approvalConfirm(@PathVariable Integer id, Model model, RedirectAttributes ra) {
|
||||
try {
|
||||
model.addAttribute("r", loanService.getView(id, Const.STATUS_WAITING));
|
||||
return "approvalConfirm";
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/admin/applications";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/admin/applications/{id}/approve")
|
||||
public String approve(@PathVariable Integer id,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser admin, RedirectAttributes ra) {
|
||||
try {
|
||||
loanService.approve(id, admin);
|
||||
ra.addFlashAttribute("message", "書籍貸出申請を承認しました。");
|
||||
return "redirect:/admin/approval/complete";
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/admin/applications";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/admin/applications/{id}/reject")
|
||||
public String reject(@PathVariable Integer id,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser admin, RedirectAttributes ra) {
|
||||
try {
|
||||
loanService.reject(id, admin);
|
||||
ra.addFlashAttribute("message", "書籍貸出申請を却下しました。");
|
||||
return "redirect:/admin/approval/complete";
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/admin/applications";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/admin/approval/complete")
|
||||
public String approvalComplete(Model model) {
|
||||
model.addAttribute("backUrl", "/admin/applications");
|
||||
model.addAttribute("backLabel", "承認待ち一覧に戻る");
|
||||
return "complete";
|
||||
}
|
||||
|
||||
// ===== LOAN-04 貸出中書籍一覧 =====
|
||||
@GetMapping("/admin/lendings")
|
||||
public String lendings(Model model) {
|
||||
model.addAttribute("list", loanService.listByStatus(Const.STATUS_LENDING));
|
||||
return "lendingList";
|
||||
}
|
||||
|
||||
// ===== LOAN-05 返却 =====
|
||||
@GetMapping("/admin/lendings/{id}")
|
||||
public String returnConfirm(@PathVariable Integer id, Model model, RedirectAttributes ra) {
|
||||
try {
|
||||
model.addAttribute("r", loanService.getView(id, Const.STATUS_LENDING));
|
||||
return "returnConfirm";
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/admin/lendings";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/admin/lendings/{id}/return")
|
||||
public String doReturn(@PathVariable Integer id,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser admin, RedirectAttributes ra) {
|
||||
try {
|
||||
loanService.returnBook(id, admin);
|
||||
ra.addFlashAttribute("message", "書籍の返却が完了しました。");
|
||||
return "redirect:/admin/return/complete";
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/admin/lendings";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/admin/return/complete")
|
||||
public String returnComplete(Model model) {
|
||||
model.addAttribute("backUrl", "/admin/lendings");
|
||||
model.addAttribute("backLabel", "貸出中書籍一覧に戻る");
|
||||
return "complete";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.example.demo.service.BookService;
|
||||
|
||||
|
||||
/** BOOK-01:書籍検索(bookList.html) */
|
||||
@Controller
|
||||
public class BookController {
|
||||
private final BookService bookService;
|
||||
|
||||
public BookController(BookService bookService) {
|
||||
this.bookService = bookService;
|
||||
}
|
||||
|
||||
/** メニューの「書籍一覧」=条件なし(全件)、検索ボタン=条件付きで同じURLを使う */
|
||||
@GetMapping("/books")
|
||||
public String list(@RequestParam(defaultValue = "") String nmBook,
|
||||
@RequestParam(defaultValue = "") String publisher,
|
||||
@RequestParam(defaultValue = "") String note,
|
||||
Model model) {
|
||||
model.addAttribute("books", bookService.searchLendable(nmBook, publisher, note));
|
||||
// 検索条件を保持
|
||||
model.addAttribute("nmBook", nmBook);
|
||||
model.addAttribute("publisher", publisher);
|
||||
model.addAttribute("note", note);
|
||||
return "bookList";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,34 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.resource.NoResourceFoundException;
|
||||
|
||||
/** 予期しない例外:内部情報を画面に出さず、原因調査用にログへ出力する(NFR-04, NFR-08) */
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
/** 存在しないURL(favicon.ico など)はエラーログを出さず404にする */
|
||||
@ExceptionHandler(NoResourceFoundException.class)
|
||||
public ModelAndView handleNotFound(NoResourceFoundException e) {
|
||||
ModelAndView mav = new ModelAndView("error");
|
||||
mav.setStatus(HttpStatus.NOT_FOUND);
|
||||
mav.addObject("errorMessage", "ページが見つかりません。");
|
||||
return mav;
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ModelAndView handle(Exception e) {
|
||||
log.error("予期しないエラーが発生しました", e);
|
||||
ModelAndView mav = new ModelAndView("error");
|
||||
mav.addObject("errorMessage", "システムエラーが発生しました。しばらくしてからもう一度お試しください。");
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
public class LoanContorller {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.SessionAttribute;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.example.demo.common.BusinessException;
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.service.LoanService;
|
||||
|
||||
/** LOAN-01:書籍貸出申請(一般ユーザーのみ)。入力 → 確認 → 完了 */
|
||||
@Controller
|
||||
@RequestMapping("/loan")
|
||||
public class LoanController {
|
||||
private final LoanService loanService;
|
||||
|
||||
public LoanController(LoanService loanService) {
|
||||
this.loanService = loanService;
|
||||
}
|
||||
|
||||
/** 書籍一覧 →(申請ボタン)→ 申請入力 */
|
||||
@GetMapping("/apply")
|
||||
public String input(@RequestParam Integer idBook,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser user,
|
||||
Model model, RedirectAttributes ra) {
|
||||
return showInput(idBook, "", "", List.of(), user, model, ra);
|
||||
}
|
||||
|
||||
/** 確認画面 →(申請情報入力に戻る)→ 申請入力(入力値を保持) */
|
||||
@PostMapping("/apply/input")
|
||||
public String back(@RequestParam Integer idBook,
|
||||
@RequestParam(defaultValue = "") String dateBorrow,
|
||||
@RequestParam(defaultValue = "") String dateScheduledReturn,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser user,
|
||||
Model model, RedirectAttributes ra) {
|
||||
return showInput(idBook, dateBorrow, dateScheduledReturn, List.of(), user, model, ra);
|
||||
}
|
||||
|
||||
/** 申請入力 →(申請確認)→ 確認 */
|
||||
@PostMapping("/apply/confirm")
|
||||
public String confirm(@RequestParam Integer idBook,
|
||||
@RequestParam(defaultValue = "") String dateBorrow,
|
||||
@RequestParam(defaultValue = "") String dateScheduledReturn,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser user,
|
||||
Model model, RedirectAttributes ra) {
|
||||
List<String> errors = loanService.validateDates(dateBorrow, dateScheduledReturn);
|
||||
if (!errors.isEmpty()) {
|
||||
return showInput(idBook, dateBorrow, dateScheduledReturn, errors, user, model, ra);
|
||||
}
|
||||
if (user.isAdmin()) return "redirect:/menu";
|
||||
try {
|
||||
model.addAttribute("book", loanService.getLendableBook(idBook));
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/books";
|
||||
}
|
||||
model.addAttribute("idBook", idBook);
|
||||
model.addAttribute("dateBorrow", dateBorrow);
|
||||
model.addAttribute("dateScheduledReturn", dateScheduledReturn);
|
||||
return "loanApplyConfirm";
|
||||
}
|
||||
|
||||
/** 確認 →(申請)→ 完了。二重送信防止のため登録後はリダイレクトする(PRG) */
|
||||
@PostMapping("/apply/execute")
|
||||
public String execute(@RequestParam Integer idBook,
|
||||
@RequestParam(defaultValue = "") String dateBorrow,
|
||||
@RequestParam(defaultValue = "") String dateScheduledReturn,
|
||||
@SessionAttribute(Const.SESSION_LOGIN_USER) LoginUser user,
|
||||
RedirectAttributes ra) {
|
||||
if (user.isAdmin()) return "redirect:/menu";
|
||||
try {
|
||||
Integer id = loanService.apply(idBook, dateBorrow, dateScheduledReturn, user);
|
||||
ra.addFlashAttribute("message", "書籍貸出申請が完了しました。(申請ID:" + id + ")");
|
||||
return "redirect:/loan/apply/complete";
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/books";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/apply/complete")
|
||||
public String complete(Model model) {
|
||||
model.addAttribute("backUrl", "/books");
|
||||
model.addAttribute("backLabel", "書籍一覧に戻る");
|
||||
return "complete";
|
||||
}
|
||||
|
||||
private String showInput(Integer idBook, String dateBorrow, String dateScheduledReturn, List<String> errors,
|
||||
LoginUser user, Model model, RedirectAttributes ra) {
|
||||
if (user.isAdmin()) return "redirect:/menu"; // 申請は一般ユーザーのみ
|
||||
try {
|
||||
model.addAttribute("book", loanService.getLendableBook(idBook));
|
||||
} catch (BusinessException e) {
|
||||
ra.addFlashAttribute("errorMessage", e.getMessage());
|
||||
return "redirect:/books";
|
||||
}
|
||||
model.addAttribute("idBook", idBook);
|
||||
model.addAttribute("dateBorrow", dateBorrow);
|
||||
model.addAttribute("dateScheduledReturn", dateScheduledReturn);
|
||||
model.addAttribute("errors", errors);
|
||||
return "loanApplyInput";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,73 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
public class LoginController {
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.service.AuthService;
|
||||
|
||||
/** AUTH-01:ログイン/ログアウト(login.html) */
|
||||
@Controller
|
||||
public class LoginController {
|
||||
private final AuthService authService;
|
||||
|
||||
public LoginController(AuthService authService) {
|
||||
this.authService = authService;
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
public String root() {
|
||||
return "redirect:/menu";
|
||||
}
|
||||
|
||||
@GetMapping("/login")
|
||||
public String loginForm(HttpSession session) {
|
||||
if (session.getAttribute(Const.SESSION_LOGIN_USER) != null) {
|
||||
return "redirect:/menu";
|
||||
}
|
||||
return "login";
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public String login(@RequestParam(defaultValue = "") String mailAddress,
|
||||
@RequestParam(defaultValue = "") String password,
|
||||
HttpServletRequest request, Model model) {
|
||||
String mail = mailAddress.trim();
|
||||
model.addAttribute("mailAddress", mail); // 入力値を保持(パスワードは保持しない)
|
||||
|
||||
if (mail.isEmpty() || password.isEmpty()) {
|
||||
model.addAttribute("errorMessage", "メールアドレスとパスワードを入力してください。");
|
||||
return "login";
|
||||
}
|
||||
Optional<LoginUser> user = authService.authenticate(mail, password);
|
||||
if (user.isEmpty()) {
|
||||
// どちらが誤りかは分からない文言にする
|
||||
model.addAttribute("errorMessage", "メールアドレスまたはパスワードが正しくありません。");
|
||||
return "login";
|
||||
}
|
||||
// セッション固定化攻撃対策:古いセッションを破棄して新規発行
|
||||
HttpSession old = request.getSession(false);
|
||||
if (old != null) {
|
||||
old.invalidate();
|
||||
}
|
||||
request.getSession(true).setAttribute(Const.SESSION_LOGIN_USER, user.get());
|
||||
return "redirect:/menu";
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public String logout(HttpSession session) {
|
||||
session.invalidate();
|
||||
return "redirect:/login";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/** メニュー画面(menu.html)。表示内容は管理者フラグで切り替える。 */
|
||||
@Controller
|
||||
public class MenuController {
|
||||
|
||||
@GetMapping("/menu")
|
||||
public String showMenu(Model model) {
|
||||
|
||||
// 仮のログインユーザー名
|
||||
model.addAttribute("loginUserName", "テストユーザー");
|
||||
|
||||
// menu.htmlを表示
|
||||
public String menu() {
|
||||
return "menu";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,72 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
public class BorrowView {
|
||||
import java.time.LocalDate;
|
||||
|
||||
/** 貸出情報+申請者名+書籍情報(一覧・確認画面表示用) */
|
||||
public class BorrowView {
|
||||
private final Integer idRequest;
|
||||
private final String nmApplicant;
|
||||
private final String nmBook;
|
||||
private final LocalDate dateRequest;
|
||||
private final LocalDate dateBorrow;
|
||||
private final LocalDate dateScheduledReturn;
|
||||
private final String isbn;
|
||||
private final String publisher;
|
||||
private final String note;
|
||||
private final String status;
|
||||
|
||||
public BorrowView(Integer idRequest, String nmApplicant, String nmBook, LocalDate dateRequest,
|
||||
LocalDate dateBorrow, LocalDate dateScheduledReturn, String isbn,
|
||||
String publisher, String note, String status) {
|
||||
this.idRequest = idRequest;
|
||||
this.nmApplicant = nmApplicant;
|
||||
this.nmBook = nmBook;
|
||||
this.dateRequest = dateRequest;
|
||||
this.dateBorrow = dateBorrow;
|
||||
this.dateScheduledReturn = dateScheduledReturn;
|
||||
this.isbn = isbn;
|
||||
this.publisher = publisher;
|
||||
this.note = note;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Integer getIdRequest() {
|
||||
return idRequest;
|
||||
}
|
||||
|
||||
public String getNmApplicant() {
|
||||
return nmApplicant;
|
||||
}
|
||||
|
||||
public String getNmBook() {
|
||||
return nmBook;
|
||||
}
|
||||
|
||||
public LocalDate getDateRequest() {
|
||||
return dateRequest;
|
||||
}
|
||||
|
||||
public LocalDate getDateBorrow() {
|
||||
return dateBorrow;
|
||||
}
|
||||
|
||||
public LocalDate getDateScheduledReturn() {
|
||||
return dateScheduledReturn;
|
||||
}
|
||||
|
||||
public String getIsbn() {
|
||||
return isbn;
|
||||
}
|
||||
|
||||
public String getPublisher() {
|
||||
return publisher;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,108 @@
|
||||
package com.example.demo.entity;
|
||||
|
||||
public class BookCollection {
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/** 蔵書テーブル */
|
||||
@Entity
|
||||
@Table(name = "book_collection")
|
||||
public class BookCollection {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id_book")
|
||||
private Integer idBook;
|
||||
@Column(name = "isbn")
|
||||
private String isbn;
|
||||
@Column(name = "nm_book")
|
||||
private String nmBook;
|
||||
@Column(name = "kn_book")
|
||||
private String knBook;
|
||||
@Column(name = "publisher")
|
||||
private String publisher;
|
||||
@Column(name = "note", columnDefinition = "text")
|
||||
private String note;
|
||||
@Column(name = "flg_lending")
|
||||
private String flgLending;
|
||||
@Column(name = "id_update")
|
||||
private Integer idUpdate;
|
||||
@Column(name = "date_update")
|
||||
private LocalDateTime dateUpdate;
|
||||
|
||||
public Integer getIdBook() {
|
||||
return idBook;
|
||||
}
|
||||
|
||||
public void setIdBook(Integer v) {
|
||||
this.idBook = v;
|
||||
}
|
||||
|
||||
public String getIsbn() {
|
||||
return isbn;
|
||||
}
|
||||
|
||||
public void setIsbn(String v) {
|
||||
this.isbn = v;
|
||||
}
|
||||
|
||||
public String getNmBook() {
|
||||
return nmBook;
|
||||
}
|
||||
|
||||
public void setNmBook(String v) {
|
||||
this.nmBook = v;
|
||||
}
|
||||
|
||||
public String getKnBook() {
|
||||
return knBook;
|
||||
}
|
||||
|
||||
public void setKnBook(String v) {
|
||||
this.knBook = v;
|
||||
}
|
||||
|
||||
public String getPublisher() {
|
||||
return publisher;
|
||||
}
|
||||
|
||||
public void setPublisher(String v) {
|
||||
this.publisher = v;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public void setNote(String v) {
|
||||
this.note = v;
|
||||
}
|
||||
|
||||
public String getFlgLending() {
|
||||
return flgLending;
|
||||
}
|
||||
|
||||
public void setFlgLending(String v) {
|
||||
this.flgLending = v;
|
||||
}
|
||||
|
||||
public Integer getIdUpdate() {
|
||||
return idUpdate;
|
||||
}
|
||||
|
||||
public void setIdUpdate(Integer v) {
|
||||
this.idUpdate = v;
|
||||
}
|
||||
|
||||
public LocalDateTime getDateUpdate() {
|
||||
return dateUpdate;
|
||||
}
|
||||
|
||||
public void setDateUpdate(LocalDateTime v) {
|
||||
this.dateUpdate = v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,139 @@
|
||||
package com.example.demo.entity;
|
||||
|
||||
public class BorrowBook {
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/** 貸出テーブル(LOAN-01〜05 で使用) */
|
||||
@Entity
|
||||
@Table(name = "borrow_books")
|
||||
public class BorrowBook {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id_request")
|
||||
private Integer idRequest;
|
||||
@Column(name = "id_applicant")
|
||||
private Integer idApplicant;
|
||||
@Column(name = "id_book")
|
||||
private Integer idBook;
|
||||
@Column(name = "date_request")
|
||||
private LocalDate dateRequest;
|
||||
@Column(name = "status")
|
||||
private String status;
|
||||
@Column(name = "id_approval")
|
||||
private Integer idApproval;
|
||||
@Column(name = "date_approval")
|
||||
private LocalDate dateApproval;
|
||||
@Column(name = "date_borrow")
|
||||
private LocalDate dateBorrow;
|
||||
@Column(name = "date_scheduled_return")
|
||||
private LocalDate dateScheduledReturn;
|
||||
@Column(name = "date_return")
|
||||
private LocalDate dateReturn;
|
||||
@Column(name = "id_update")
|
||||
private Integer idUpdate;
|
||||
@Column(name = "date_update")
|
||||
private LocalDateTime dateUpdate;
|
||||
|
||||
public Integer getIdRequest() {
|
||||
return idRequest;
|
||||
}
|
||||
|
||||
public void setIdRequest(Integer v) {
|
||||
this.idRequest = v;
|
||||
}
|
||||
|
||||
public Integer getIdApplicant() {
|
||||
return idApplicant;
|
||||
}
|
||||
|
||||
public void setIdApplicant(Integer v) {
|
||||
this.idApplicant = v;
|
||||
}
|
||||
|
||||
public Integer getIdBook() {
|
||||
return idBook;
|
||||
}
|
||||
|
||||
public void setIdBook(Integer v) {
|
||||
this.idBook = v;
|
||||
}
|
||||
|
||||
public LocalDate getDateRequest() {
|
||||
return dateRequest;
|
||||
}
|
||||
|
||||
public void setDateRequest(LocalDate v) {
|
||||
this.dateRequest = v;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String v) {
|
||||
this.status = v;
|
||||
}
|
||||
|
||||
public Integer getIdApproval() {
|
||||
return idApproval;
|
||||
}
|
||||
|
||||
public void setIdApproval(Integer v) {
|
||||
this.idApproval = v;
|
||||
}
|
||||
|
||||
public LocalDate getDateApproval() {
|
||||
return dateApproval;
|
||||
}
|
||||
|
||||
public void setDateApproval(LocalDate v) {
|
||||
this.dateApproval = v;
|
||||
}
|
||||
|
||||
public LocalDate getDateBorrow() {
|
||||
return dateBorrow;
|
||||
}
|
||||
|
||||
public void setDateBorrow(LocalDate v) {
|
||||
this.dateBorrow = v;
|
||||
}
|
||||
|
||||
public LocalDate getDateScheduledReturn() {
|
||||
return dateScheduledReturn;
|
||||
}
|
||||
|
||||
public void setDateScheduledReturn(LocalDate v) {
|
||||
this.dateScheduledReturn = v;
|
||||
}
|
||||
|
||||
public LocalDate getDateReturn() {
|
||||
return dateReturn;
|
||||
}
|
||||
|
||||
public void setDateReturn(LocalDate v) {
|
||||
this.dateReturn = v;
|
||||
}
|
||||
|
||||
public Integer getIdUpdate() {
|
||||
return idUpdate;
|
||||
}
|
||||
|
||||
public void setIdUpdate(Integer v) {
|
||||
this.idUpdate = v;
|
||||
}
|
||||
|
||||
public LocalDateTime getDateUpdate() {
|
||||
return dateUpdate;
|
||||
}
|
||||
|
||||
public void setDateUpdate(LocalDateTime v) {
|
||||
this.dateUpdate = v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,108 @@
|
||||
package com.example.demo.entity;
|
||||
|
||||
public class Employee {
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/** 社員マスタ */
|
||||
@Entity
|
||||
@Table(name = "employee")
|
||||
public class Employee {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id_employee")
|
||||
private Integer idEmployee;
|
||||
@Column(name = "nm_employee")
|
||||
private String nmEmployee;
|
||||
@Column(name = "kn_employee")
|
||||
private String knEmployee;
|
||||
@Column(name = "mail_address")
|
||||
private String mailAddress;
|
||||
@Column(name = "password")
|
||||
private String password;
|
||||
@Column(name = "flg_admin")
|
||||
private String flgAdmin;
|
||||
@Column(name = "flg_retirement")
|
||||
private String flgRetirement;
|
||||
@Column(name = "id_update")
|
||||
private Integer idUpdate;
|
||||
@Column(name = "date_update")
|
||||
private LocalDateTime dateUpdate;
|
||||
|
||||
public Integer getIdEmployee() {
|
||||
return idEmployee;
|
||||
}
|
||||
|
||||
public void setIdEmployee(Integer v) {
|
||||
this.idEmployee = v;
|
||||
}
|
||||
|
||||
public String getNmEmployee() {
|
||||
return nmEmployee;
|
||||
}
|
||||
|
||||
public void setNmEmployee(String v) {
|
||||
this.nmEmployee = v;
|
||||
}
|
||||
|
||||
public String getKnEmployee() {
|
||||
return knEmployee;
|
||||
}
|
||||
|
||||
public void setKnEmployee(String v) {
|
||||
this.knEmployee = v;
|
||||
}
|
||||
|
||||
public String getMailAddress() {
|
||||
return mailAddress;
|
||||
}
|
||||
|
||||
public void setMailAddress(String v) {
|
||||
this.mailAddress = v;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String v) {
|
||||
this.password = v;
|
||||
}
|
||||
|
||||
public String getFlgAdmin() {
|
||||
return flgAdmin;
|
||||
}
|
||||
|
||||
public void setFlgAdmin(String v) {
|
||||
this.flgAdmin = v;
|
||||
}
|
||||
|
||||
public String getFlgRetirement() {
|
||||
return flgRetirement;
|
||||
}
|
||||
|
||||
public void setFlgRetirement(String v) {
|
||||
this.flgRetirement = v;
|
||||
}
|
||||
|
||||
public Integer getIdUpdate() {
|
||||
return idUpdate;
|
||||
}
|
||||
|
||||
public void setIdUpdate(Integer v) {
|
||||
this.idUpdate = v;
|
||||
}
|
||||
|
||||
public LocalDateTime getDateUpdate() {
|
||||
return dateUpdate;
|
||||
}
|
||||
|
||||
public void setDateUpdate(LocalDateTime v) {
|
||||
this.dateUpdate = v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,71 @@
|
||||
package com.example.demo.form;
|
||||
|
||||
/** 書籍登録・編集フォーム */
|
||||
public class BookForm {
|
||||
private Integer idBook;
|
||||
private String isbn = "";
|
||||
private String nmBook = "";
|
||||
private String knBook = "";
|
||||
private String publisher = "";
|
||||
private String note = "";
|
||||
|
||||
public void trim() {
|
||||
isbn = t(isbn);
|
||||
nmBook = t(nmBook);
|
||||
knBook = t(knBook);
|
||||
publisher = t(publisher);
|
||||
note = t(note);
|
||||
}
|
||||
|
||||
private static String t(String s) {
|
||||
return s == null ? "" : s.trim();
|
||||
}
|
||||
|
||||
public Integer getIdBook() {
|
||||
return idBook;
|
||||
}
|
||||
|
||||
public void setIdBook(Integer v) {
|
||||
this.idBook = v;
|
||||
}
|
||||
|
||||
public String getIsbn() {
|
||||
return isbn;
|
||||
}
|
||||
|
||||
public void setIsbn(String v) {
|
||||
this.isbn = v;
|
||||
}
|
||||
|
||||
public String getNmBook() {
|
||||
return nmBook;
|
||||
}
|
||||
|
||||
public void setNmBook(String v) {
|
||||
this.nmBook = v;
|
||||
}
|
||||
|
||||
public String getKnBook() {
|
||||
return knBook;
|
||||
}
|
||||
|
||||
public void setKnBook(String v) {
|
||||
this.knBook = v;
|
||||
}
|
||||
|
||||
public String getPublisher() {
|
||||
return publisher;
|
||||
}
|
||||
|
||||
public void setPublisher(String v) {
|
||||
this.publisher = v;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public void setNote(String v) {
|
||||
this.note = v;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
package com.example.demo.form;
|
||||
|
||||
/** 社員登録・編集フォーム */
|
||||
public class EmployeeForm {
|
||||
private Integer idEmployee;
|
||||
private String nmEmployee = "";
|
||||
private String knEmployee = "";
|
||||
private String mailAddress = "";
|
||||
private String password = "";
|
||||
private String flgAdmin = "0";
|
||||
private String flgRetirement = "0";
|
||||
|
||||
public void trim() {
|
||||
nmEmployee = t(nmEmployee); knEmployee = t(knEmployee); mailAddress = t(mailAddress);
|
||||
flgAdmin = t(flgAdmin); flgRetirement = t(flgRetirement);
|
||||
if (password == null) password = "";
|
||||
}
|
||||
private static String t(String s) { return s == null ? "" : s.trim(); }
|
||||
|
||||
public Integer getIdEmployee() { return idEmployee; }
|
||||
public void setIdEmployee(Integer v) { this.idEmployee = v; }
|
||||
public String getNmEmployee() { return nmEmployee; }
|
||||
public void setNmEmployee(String v) { this.nmEmployee = v; }
|
||||
public String getKnEmployee() { return knEmployee; }
|
||||
public void setKnEmployee(String v) { this.knEmployee = v; }
|
||||
public String getMailAddress() { return mailAddress; }
|
||||
public void setMailAddress(String v) { this.mailAddress = v; }
|
||||
public String getPassword() { return password; }
|
||||
public void setPassword(String v) { this.password = v; }
|
||||
public String getFlgAdmin() { return flgAdmin; }
|
||||
public void setFlgAdmin(String v) { this.flgAdmin = v; }
|
||||
public String getFlgRetirement() { return flgRetirement; }
|
||||
public void setFlgRetirement(String v) { this.flgRetirement = v; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
package com.example.demo.repository;
|
||||
|
||||
public class BookCollectionRepository {
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import com.example.demo.entity.BookCollection;
|
||||
|
||||
public interface BookCollectionRepository extends JpaRepository<BookCollection, Integer> {
|
||||
|
||||
/**
|
||||
* 貸出可の蔵書を部分一致(AND)で検索する。
|
||||
* 空文字の条件は「指定なし」。LIKE の特殊文字は呼び出し側で '!' を使ってエスケープ済み。
|
||||
*/
|
||||
@Query("select b from BookCollection b "
|
||||
+ "where b.flgLending = :lending "
|
||||
+ "and (:nm = '' or b.nmBook like concat('%', :nm, '%') escape '!') "
|
||||
+ "and (:publisher = '' or b.publisher like concat('%', :publisher, '%') escape '!') "
|
||||
+ "and (:note = '' or b.note like concat('%', :note, '%') escape '!') "
|
||||
+ "order by b.idBook")
|
||||
List<BookCollection> search(@Param("lending") String lending,
|
||||
@Param("nm") String nm,
|
||||
@Param("publisher") String publisher,
|
||||
@Param("note") String note);
|
||||
|
||||
/**
|
||||
* 貸出フラグを from → to に更新する(現在値が from のときだけ更新)。
|
||||
* 戻り値が0なら、既に他の操作で状態が変わっている(状態不整合)。
|
||||
*/
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("update BookCollection b set b.flgLending = :to, b.idUpdate = :uid, b.dateUpdate = :now "
|
||||
+ "where b.idBook = :id and b.flgLending = :from")
|
||||
int updateLending(@Param("id") Integer id, @Param("from") String from, @Param("to") String to,
|
||||
@Param("uid") Integer uid, @Param("now") LocalDateTime now);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,36 @@
|
||||
package com.example.demo.repository;
|
||||
|
||||
public class BorrowBookRepository {
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.persistence.LockModeType;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Lock;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import com.example.demo.dto.BorrowView;
|
||||
import com.example.demo.entity.BorrowBook;
|
||||
|
||||
public interface BorrowBookRepository extends JpaRepository<BorrowBook, Integer> {
|
||||
|
||||
String VIEW = "select new com.example.demo.dto.BorrowView("
|
||||
+ "r.idRequest, e.nmEmployee, b.nmBook, r.dateRequest, r.dateBorrow, r.dateScheduledReturn, "
|
||||
+ "b.isbn, b.publisher, b.note, r.status) "
|
||||
+ "from BorrowBook r, Employee e, BookCollection b "
|
||||
+ "where r.idApplicant = e.idEmployee and r.idBook = b.idBook ";
|
||||
|
||||
/** LOAN-02 / LOAN-04:ステータス指定の一覧 */
|
||||
@Query(VIEW + "and r.status = :status order by r.idRequest")
|
||||
List<BorrowView> findViewsByStatus(@Param("status") String status);
|
||||
|
||||
/** 確認画面用:申請IDで1件 */
|
||||
@Query(VIEW + "and r.idRequest = :id")
|
||||
List<BorrowView> findViewById(@Param("id") Integer id);
|
||||
|
||||
/** 承認・却下・返却:更新前に行ロックを取って同時操作を防ぐ */
|
||||
@Lock(LockModeType.PESSIMISTIC_WRITE)
|
||||
@Query("select r from BorrowBook r where r.idRequest = :id")
|
||||
Optional<BorrowBook> findForUpdate(@Param("id") Integer id);
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
package com.example.demo.repository;
|
||||
|
||||
public class EmployeeRepository {
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.example.demo.entity.Employee;
|
||||
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
|
||||
Optional<Employee> findByMailAddressAndFlgRetirement(String mailAddress, String flgRetirement);
|
||||
|
||||
Optional<Employee> findByMailAddress(String mailAddress);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,34 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
public class AuthService {
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.entity.Employee;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
|
||||
/** AUTH-01:認証 */
|
||||
@Service
|
||||
public class AuthService {
|
||||
private final EmployeeRepository employeeRepository;
|
||||
|
||||
public AuthService(EmployeeRepository employeeRepository) {
|
||||
this.employeeRepository = employeeRepository;
|
||||
}
|
||||
|
||||
/** 在籍中の社員のうち、メールアドレスとパスワードが一致する者を返す。一致しなければ empty。 */
|
||||
public Optional<LoginUser> authenticate(String mailAddress, String password) {
|
||||
return employeeRepository
|
||||
.findByMailAddressAndFlgRetirement(mailAddress, Const.RETIRE_NO)
|
||||
.filter(e -> e.getPassword().equals(password))
|
||||
.map(AuthService::toLoginUser);
|
||||
}
|
||||
|
||||
private static LoginUser toLoginUser(Employee e) {
|
||||
return new LoginUser(e.getIdEmployee(), e.getNmEmployee(), e.getKnEmployee(),
|
||||
e.getMailAddress(), e.getFlgAdmin());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,93 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
public class BookAdminService {
|
||||
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.example.demo.common.BusinessException;
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.entity.BookCollection;
|
||||
import com.example.demo.form.BookForm;
|
||||
import com.example.demo.repository.BookCollectionRepository;
|
||||
|
||||
/** BOOK-02:書籍登録、BOOK-03:書籍編集 */
|
||||
@Service
|
||||
public class BookAdminService {
|
||||
private final BookCollectionRepository bookRepository;
|
||||
|
||||
public BookAdminService(BookCollectionRepository bookRepository) {
|
||||
this.bookRepository = bookRepository;
|
||||
}
|
||||
|
||||
/** 入力チェック(ISBN必須13文字以内、書籍名必須50、よみ100、出版社50)。※ISBNを数字13桁に限定するかは要確認 */
|
||||
public List<String> validate(BookForm f) {
|
||||
f.trim();
|
||||
List<String> e = new ArrayList<>();
|
||||
if (f.getIsbn().isEmpty()) e.add("ISBNを入力してください。");
|
||||
else if (f.getIsbn().length() > 13) e.add("ISBNは13文字以内で入力してください。");
|
||||
if (f.getNmBook().isEmpty()) e.add("書籍名を入力してください。");
|
||||
else if (f.getNmBook().length() > 50) e.add("書籍名は50文字以内で入力してください。");
|
||||
if (f.getKnBook().length() > 100) e.add("書籍名よみは100文字以内で入力してください。");
|
||||
if (f.getPublisher().length() > 50) e.add("出版社は50文字以内で入力してください。");
|
||||
return e;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public BookCollection find(Integer idBook) {
|
||||
return bookRepository.findById(idBook)
|
||||
.orElseThrow(() -> new BusinessException("対象の書籍が見つかりません。"));
|
||||
}
|
||||
|
||||
public BookForm toForm(BookCollection b) {
|
||||
BookForm f = new BookForm();
|
||||
f.setIdBook(b.getIdBook());
|
||||
f.setIsbn(b.getIsbn());
|
||||
f.setNmBook(b.getNmBook());
|
||||
f.setKnBook(b.getKnBook() == null ? "" : b.getKnBook());
|
||||
f.setPublisher(b.getPublisher() == null ? "" : b.getPublisher());
|
||||
f.setNote(b.getNote() == null ? "" : b.getNote());
|
||||
return f;
|
||||
}
|
||||
|
||||
/** 新規登録:貸出可として登録する。 */
|
||||
@Transactional
|
||||
public Integer register(BookForm f, LoginUser admin) {
|
||||
check(f);
|
||||
BookCollection b = new BookCollection();
|
||||
apply(b, f);
|
||||
b.setFlgLending(Const.LENDING_OK);
|
||||
b.setIdUpdate(admin.getIdEmployee());
|
||||
b.setDateUpdate(LocalDateTime.now());
|
||||
return bookRepository.save(b).getIdBook();
|
||||
}
|
||||
|
||||
/** 編集:書籍情報のみ更新する(貸出フラグは変更しない)。 */
|
||||
@Transactional
|
||||
public void update(BookForm f, LoginUser admin) {
|
||||
check(f);
|
||||
BookCollection b = find(f.getIdBook());
|
||||
apply(b, f);
|
||||
b.setIdUpdate(admin.getIdEmployee());
|
||||
b.setDateUpdate(LocalDateTime.now());
|
||||
}
|
||||
|
||||
private void check(BookForm f) {
|
||||
List<String> errors = validate(f);
|
||||
if (!errors.isEmpty()) throw new BusinessException(String.join(" ", errors));
|
||||
}
|
||||
|
||||
private static void apply(BookCollection b, BookForm f) {
|
||||
b.setIsbn(f.getIsbn());
|
||||
b.setNmBook(f.getNmBook());
|
||||
b.setKnBook(f.getKnBook().isEmpty() ? null : f.getKnBook());
|
||||
b.setPublisher(f.getPublisher().isEmpty() ? null : f.getPublisher());
|
||||
b.setNote(f.getNote().isEmpty() ? null : f.getNote());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
public class BookService {
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.entity.BookCollection;
|
||||
import com.example.demo.repository.BookCollectionRepository;
|
||||
|
||||
/** BOOK-01:書籍検索 */
|
||||
@Service
|
||||
public class BookService {
|
||||
private final BookCollectionRepository bookRepository;
|
||||
|
||||
public BookService(BookCollectionRepository bookRepository) {
|
||||
this.bookRepository = bookRepository;
|
||||
}
|
||||
|
||||
/** 貸出可の蔵書を検索する。全て未入力なら全件。 */
|
||||
@Transactional(readOnly = true)
|
||||
public List<BookCollection> searchLendable(String nmBook, String publisher, String note) {
|
||||
return bookRepository.search(Const.LENDING_OK, normalize(nmBook), normalize(publisher), normalize(note));
|
||||
}
|
||||
|
||||
/** 前後の空白除去+LIKE特殊文字(! % _)のエスケープ(エスケープ文字は '!') */
|
||||
static String normalize(String s) {
|
||||
if (s == null) return "";
|
||||
return s.trim().replace("!", "!!").replace("%", "!%").replace("_", "!_");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,164 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
public class EmployeeService {
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.example.demo.common.BusinessException;
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.entity.Employee;
|
||||
import com.example.demo.form.EmployeeForm;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
|
||||
/** EMP-01:社員登録、EMP-02:社員編集 */
|
||||
@Service
|
||||
public class EmployeeService {
|
||||
private static final Pattern MAIL = Pattern.compile("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$");
|
||||
private static final String MSG_DUP = "このメールアドレスは既に登録されています。";
|
||||
|
||||
private final EmployeeRepository employeeRepository;
|
||||
|
||||
public EmployeeService(EmployeeRepository employeeRepository) {
|
||||
this.employeeRepository = employeeRepository;
|
||||
}
|
||||
|
||||
// ---------- 検索 ----------
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<Employee> findByMail(String mail) {
|
||||
return employeeRepository.findByMailAddress(mail == null ? "" : mail.trim());
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Employee find(Integer id) {
|
||||
return employeeRepository.findById(id)
|
||||
.orElseThrow(() -> new BusinessException("対象の社員が見つかりません。"));
|
||||
}
|
||||
|
||||
/** 編集画面の初期値(パスワードは空:管理者は変更時のみ入力) */
|
||||
public EmployeeForm toForm(Employee e) {
|
||||
EmployeeForm f = new EmployeeForm();
|
||||
f.setIdEmployee(e.getIdEmployee());
|
||||
f.setNmEmployee(e.getNmEmployee());
|
||||
f.setKnEmployee(e.getKnEmployee());
|
||||
f.setMailAddress(e.getMailAddress());
|
||||
f.setFlgAdmin(e.getFlgAdmin());
|
||||
f.setFlgRetirement(e.getFlgRetirement());
|
||||
return f;
|
||||
}
|
||||
|
||||
// ---------- 入力チェック ----------
|
||||
|
||||
/** 社員登録:社員名・よみ・メール・管理者フラグ。パスワードは初期値で登録する。 */
|
||||
public List<String> validateRegist(EmployeeForm f) {
|
||||
f.trim();
|
||||
List<String> e = new ArrayList<>();
|
||||
checkBasic(f, e);
|
||||
checkMail(f, null, e);
|
||||
checkFlag(f.getFlgAdmin(), "管理者フラグ", e);
|
||||
return e;
|
||||
}
|
||||
|
||||
/** 管理者による編集:全項目。パスワードは空なら変更しない。 */
|
||||
public List<String> validateUpdateByAdmin(EmployeeForm f) {
|
||||
f.trim();
|
||||
List<String> e = new ArrayList<>();
|
||||
checkBasic(f, e);
|
||||
checkMail(f, f.getIdEmployee(), e);
|
||||
checkFlag(f.getFlgAdmin(), "管理者フラグ", e);
|
||||
checkFlag(f.getFlgRetirement(), "退職フラグ", e);
|
||||
if (f.getPassword().length() > 256) e.add("パスワードは256文字以内で入力してください。");
|
||||
return e;
|
||||
}
|
||||
|
||||
/** 一般ユーザーによる編集:パスワードのみ(必須)。 */
|
||||
public List<String> validateUpdateBySelf(EmployeeForm f) {
|
||||
f.trim();
|
||||
List<String> e = new ArrayList<>();
|
||||
if (f.getPassword().isEmpty()) e.add("パスワードを入力してください。");
|
||||
else if (f.getPassword().length() > 256) e.add("パスワードは256文字以内で入力してください。");
|
||||
return e;
|
||||
}
|
||||
|
||||
private void checkBasic(EmployeeForm f, List<String> e) {
|
||||
if (f.getNmEmployee().isEmpty()) e.add("社員名を入力してください。");
|
||||
else if (f.getNmEmployee().length() > 50) e.add("社員名は50文字以内で入力してください。");
|
||||
// ※社員名よみの文字種(ひらがなのみ等)は設計で確定する。現状は文字数のみチェック
|
||||
if (f.getKnEmployee().isEmpty()) e.add("社員名よみを入力してください。");
|
||||
else if (f.getKnEmployee().length() > 100) e.add("社員名よみは100文字以内で入力してください。");
|
||||
}
|
||||
|
||||
private void checkMail(EmployeeForm f, Integer selfId, List<String> e) {
|
||||
String m = f.getMailAddress();
|
||||
if (m.isEmpty()) { e.add("メールアドレスを入力してください。"); return; }
|
||||
if (m.length() > 256) { e.add("メールアドレスは256文字以内で入力してください。"); return; }
|
||||
if (!MAIL.matcher(m).matches()) { e.add("メールアドレスの形式が正しくありません。"); return; }
|
||||
Optional<Employee> dup = employeeRepository.findByMailAddress(m);
|
||||
if (dup.isPresent() && !dup.get().getIdEmployee().equals(selfId)) e.add(MSG_DUP);
|
||||
}
|
||||
|
||||
private static void checkFlag(String v, String label, List<String> e) {
|
||||
if (!"0".equals(v) && !"1".equals(v)) e.add(label + "が正しくありません。");
|
||||
}
|
||||
|
||||
// ---------- 登録・更新 ----------
|
||||
|
||||
@Transactional
|
||||
public Integer register(EmployeeForm f, LoginUser admin) {
|
||||
raise(validateRegist(f));
|
||||
Employee e = new Employee();
|
||||
e.setNmEmployee(f.getNmEmployee());
|
||||
e.setKnEmployee(f.getKnEmployee());
|
||||
e.setMailAddress(f.getMailAddress());
|
||||
e.setPassword(Const.DEFAULT_PASSWORD);
|
||||
e.setFlgAdmin(f.getFlgAdmin());
|
||||
e.setFlgRetirement(Const.RETIRE_NO);
|
||||
e.setIdUpdate(admin.getIdEmployee());
|
||||
e.setDateUpdate(LocalDateTime.now());
|
||||
try {
|
||||
return employeeRepository.saveAndFlush(e).getIdEmployee();
|
||||
} catch (DataIntegrityViolationException ex) {
|
||||
throw new BusinessException(MSG_DUP); // 同時登録によるUNIQUE制約違反
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateByAdmin(EmployeeForm f, LoginUser admin) {
|
||||
raise(validateUpdateByAdmin(f));
|
||||
Employee e = find(f.getIdEmployee());
|
||||
e.setNmEmployee(f.getNmEmployee());
|
||||
e.setKnEmployee(f.getKnEmployee());
|
||||
e.setMailAddress(f.getMailAddress());
|
||||
if (!f.getPassword().isEmpty()) e.setPassword(f.getPassword());
|
||||
e.setFlgAdmin(f.getFlgAdmin());
|
||||
e.setFlgRetirement(f.getFlgRetirement());
|
||||
e.setIdUpdate(admin.getIdEmployee());
|
||||
e.setDateUpdate(LocalDateTime.now());
|
||||
try {
|
||||
employeeRepository.saveAndFlush(e);
|
||||
} catch (DataIntegrityViolationException ex) {
|
||||
throw new BusinessException(MSG_DUP);
|
||||
}
|
||||
}
|
||||
|
||||
/** 一般ユーザー:自分自身(セッションの社員ID)のパスワードのみ更新する。 */
|
||||
@Transactional
|
||||
public void updateBySelf(EmployeeForm f, LoginUser self) {
|
||||
raise(validateUpdateBySelf(f));
|
||||
Employee e = find(self.getIdEmployee());
|
||||
e.setPassword(f.getPassword());
|
||||
e.setIdUpdate(self.getIdEmployee());
|
||||
e.setDateUpdate(LocalDateTime.now());
|
||||
}
|
||||
|
||||
private static void raise(List<String> errors) {
|
||||
if (!errors.isEmpty()) throw new BusinessException(String.join(" ", errors));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,159 @@
|
||||
package com.example.demo.service;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.example.demo.common.BusinessException;
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.dto.BorrowView;
|
||||
import com.example.demo.entity.BookCollection;
|
||||
import com.example.demo.entity.BorrowBook;
|
||||
import com.example.demo.repository.BookCollectionRepository;
|
||||
import com.example.demo.repository.BorrowBookRepository;
|
||||
|
||||
/** LOAN-01〜05:貸出申請・承認/却下・返却。貸出ステータスと蔵書の貸出フラグは同一トランザクションで更新する。 */
|
||||
@Service
|
||||
public class LoanService {
|
||||
private static final String MSG_STATE = "他の操作で状態が変わっています。最新の状態を確認してください。";
|
||||
|
||||
private final BorrowBookRepository borrowRepository;
|
||||
private final BookCollectionRepository bookRepository;
|
||||
|
||||
public LoanService(BorrowBookRepository borrowRepository, BookCollectionRepository bookRepository) {
|
||||
this.borrowRepository = borrowRepository;
|
||||
this.bookRepository = bookRepository;
|
||||
}
|
||||
|
||||
// ---------- LOAN-01 貸出申請 ----------
|
||||
|
||||
/** 貸出可の蔵書を取得する。存在しない/貸出不可なら BusinessException。 */
|
||||
@Transactional(readOnly = true)
|
||||
public BookCollection getLendableBook(Integer idBook) {
|
||||
return bookRepository.findById(idBook)
|
||||
.filter(b -> Const.LENDING_OK.equals(b.getFlgLending()))
|
||||
.orElseThrow(() -> new BusinessException("この書籍は現在貸出できません。書籍一覧を確認してください。"));
|
||||
}
|
||||
|
||||
/** 貸出日・返却予定日の入力チェック。エラーがなければ空のリスト。 */
|
||||
public List<String> validateDates(String dateBorrow, String dateScheduledReturn) {
|
||||
List<String> errors = new ArrayList<>();
|
||||
LocalDate b = parse(dateBorrow);
|
||||
LocalDate r = parse(dateScheduledReturn);
|
||||
if (isBlank(dateBorrow)) errors.add("貸出日を入力してください。");
|
||||
else if (b == null) errors.add("貸出日の形式が正しくありません。");
|
||||
if (isBlank(dateScheduledReturn)) errors.add("返却予定日を入力してください。");
|
||||
else if (r == null) errors.add("返却予定日の形式が正しくありません。");
|
||||
if (b != null && r != null && r.isBefore(b)) errors.add("返却予定日は貸出日より前の日付にできません。");
|
||||
return errors;
|
||||
}
|
||||
|
||||
public static LocalDate parse(String s) {
|
||||
if (isBlank(s)) return null;
|
||||
try {
|
||||
return LocalDate.parse(s.trim());
|
||||
} catch (DateTimeParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isBlank(String s) {
|
||||
return s == null || s.trim().isEmpty();
|
||||
}
|
||||
|
||||
/** 申請を登録し、蔵書を貸出不可にする(全体で1トランザクション)。 */
|
||||
@Transactional
|
||||
public Integer apply(Integer idBook, String dateBorrow, String dateScheduledReturn, LoginUser user) {
|
||||
List<String> errors = validateDates(dateBorrow, dateScheduledReturn);
|
||||
if (!errors.isEmpty()) throw new BusinessException(String.join(" ", errors));
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 貸出可 → 貸出不可。0件なら他の人が先に申請済み
|
||||
int updated = bookRepository.updateLending(idBook, Const.LENDING_OK, Const.LENDING_NG, user.getIdEmployee(), now);
|
||||
if (updated == 0) throw new BusinessException("この書籍は現在貸出できません。書籍一覧を確認してください。");
|
||||
|
||||
BorrowBook r = new BorrowBook();
|
||||
r.setIdApplicant(user.getIdEmployee());
|
||||
r.setIdBook(idBook);
|
||||
r.setDateRequest(LocalDate.now());
|
||||
r.setStatus(Const.STATUS_WAITING);
|
||||
r.setDateBorrow(parse(dateBorrow));
|
||||
r.setDateScheduledReturn(parse(dateScheduledReturn));
|
||||
r.setIdUpdate(user.getIdEmployee());
|
||||
r.setDateUpdate(now);
|
||||
return borrowRepository.save(r).getIdRequest();
|
||||
}
|
||||
|
||||
// ---------- 一覧・確認画面 ----------
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<BorrowView> listByStatus(String status) {
|
||||
return borrowRepository.findViewsByStatus(status);
|
||||
}
|
||||
|
||||
/** 申請IDで1件取得し、期待するステータスであることを確認する。 */
|
||||
@Transactional(readOnly = true)
|
||||
public BorrowView getView(Integer idRequest, String expectedStatus) {
|
||||
BorrowView v = borrowRepository.findViewById(idRequest).stream().findFirst()
|
||||
.orElseThrow(() -> new BusinessException("対象の申請が見つかりません。"));
|
||||
if (!expectedStatus.equals(v.getStatus())) throw new BusinessException(MSG_STATE);
|
||||
return v;
|
||||
}
|
||||
|
||||
// ---------- LOAN-03 承認/却下 ----------
|
||||
|
||||
@Transactional
|
||||
public void approve(Integer idRequest, LoginUser admin) {
|
||||
BorrowBook r = lockWithStatus(idRequest, Const.STATUS_WAITING);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
r.setStatus(Const.STATUS_LENDING);
|
||||
r.setIdApproval(admin.getIdEmployee());
|
||||
r.setDateApproval(LocalDate.now());
|
||||
r.setIdUpdate(admin.getIdEmployee());
|
||||
r.setDateUpdate(now);
|
||||
// 蔵書の貸出フラグは貸出不可のまま
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void reject(Integer idRequest, LoginUser admin) {
|
||||
BorrowBook r = lockWithStatus(idRequest, Const.STATUS_WAITING);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
r.setStatus(Const.STATUS_REJECTED);
|
||||
r.setIdUpdate(admin.getIdEmployee());
|
||||
r.setDateUpdate(now);
|
||||
borrowRepository.saveAndFlush(r);
|
||||
releaseBook(r.getIdBook(), admin, now);
|
||||
}
|
||||
|
||||
// ---------- LOAN-05 返却 ----------
|
||||
|
||||
@Transactional
|
||||
public void returnBook(Integer idRequest, LoginUser admin) {
|
||||
BorrowBook r = lockWithStatus(idRequest, Const.STATUS_LENDING);
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
r.setStatus(Const.STATUS_RETURNED);
|
||||
r.setDateReturn(LocalDate.now());
|
||||
r.setIdUpdate(admin.getIdEmployee());
|
||||
r.setDateUpdate(now);
|
||||
borrowRepository.saveAndFlush(r);
|
||||
releaseBook(r.getIdBook(), admin, now);
|
||||
}
|
||||
|
||||
private BorrowBook lockWithStatus(Integer idRequest, String expectedStatus) {
|
||||
BorrowBook r = borrowRepository.findForUpdate(idRequest)
|
||||
.orElseThrow(() -> new BusinessException("対象の申請が見つかりません。"));
|
||||
if (!expectedStatus.equals(r.getStatus())) throw new BusinessException(MSG_STATE);
|
||||
return r;
|
||||
}
|
||||
|
||||
/** 蔵書を貸出可に戻す。失敗時は例外でトランザクション全体がロールバックされる。 */
|
||||
private void releaseBook(Integer idBook, LoginUser admin, LocalDateTime now) {
|
||||
int updated = bookRepository.updateLending(idBook, Const.LENDING_NG, Const.LENDING_OK, admin.getIdEmployee(), now);
|
||||
if (updated == 0) throw new BusinessException(MSG_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
spring.application.name=book-rent
|
||||
# --- MySQL (CREATE DATABASE.sql で作成した book_manage) ---
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/book_manage?serverTimezone=Asia/Tokyo&characterEncoding=UTF-8
|
||||
spring.datasource.username=bookuser
|
||||
spring.datasource.password=Book2026
|
||||
|
||||
# テーブルはSQLで作成済み。JPAでは変更しない
|
||||
spring.jpa.hibernate.ddl-auto=none
|
||||
spring.jpa.open-in-view=false
|
||||
spring.jpa.properties.hibernate.jdbc.time_zone=Asia/Tokyo
|
||||
|
||||
spring.thymeleaf.cache=false
|
||||
server.servlet.session.timeout=30m
|
||||
90
book-rent/src/main/resources/static/css/style.css
Normal file
90
book-rent/src/main/resources/static/css/style.css
Normal file
@@ -0,0 +1,90 @@
|
||||
body
|
||||
{font-family:
|
||||
"Meiryo","Hiragino Sans",sans-serif;
|
||||
margin:0;color:#222;
|
||||
background:#f6f7f9}
|
||||
header.top
|
||||
{display:flex;
|
||||
justify-content:space-between;
|
||||
align-items:center;
|
||||
background:#176a78;color:#fff;
|
||||
padding:10px 20px
|
||||
}
|
||||
header.top form
|
||||
{display:inline;
|
||||
margin:0}
|
||||
header.top .user
|
||||
{margin-right:12px
|
||||
}
|
||||
main
|
||||
{max-width:960px;
|
||||
margin:24px auto;
|
||||
padding:0 16px
|
||||
}
|
||||
h1
|
||||
{font-size:20px
|
||||
}
|
||||
.card
|
||||
{background:#fff;
|
||||
border:1px solid #dde;
|
||||
border-radius:6px;
|
||||
padding:20px;
|
||||
margin-bottom:16px
|
||||
}
|
||||
label
|
||||
{display:block;
|
||||
margin:10px 0 4px;
|
||||
font-weight:bold
|
||||
}
|
||||
input[type=text],input[type=password],input[type=email]
|
||||
{width:100%;
|
||||
max-width:360px;
|
||||
padding:6px;
|
||||
box-sizing:border-box
|
||||
}
|
||||
button,.btn
|
||||
{display:inline-block;
|
||||
background:#176a78;
|
||||
color:#fff;border:0;
|
||||
border-radius:4px;
|
||||
padding:7px 16px;
|
||||
cursor:pointer;
|
||||
text-decoration:none;
|
||||
font-size:14px
|
||||
}
|
||||
button.sub,.btn.sub
|
||||
{background:#6b7b80
|
||||
}
|
||||
.error
|
||||
{background:#fdecea;color:#b3261e;
|
||||
border:1px solid #f5c2be;
|
||||
padding:8px 12px;
|
||||
border-radius:4px;
|
||||
margin-bottom:12px
|
||||
}
|
||||
.info
|
||||
{background:#e8f4ea;
|
||||
color:#1b5e20;
|
||||
border:1px solid #bfdcc3;
|
||||
padding:8px 12px;
|
||||
border-radius:4px;
|
||||
margin-bottom:12px
|
||||
}
|
||||
table
|
||||
{border-collapse:collapse;
|
||||
width:100%;
|
||||
background:#fff
|
||||
}
|
||||
th,td
|
||||
{border:1px solid #dde;
|
||||
padding:6px 8px;
|
||||
text-align:left;
|
||||
font-size:14px
|
||||
}
|
||||
th
|
||||
{background:#eaf4f6
|
||||
}
|
||||
.menu a
|
||||
{display:block;
|
||||
margin:8px 0
|
||||
}
|
||||
34
book-rent/src/main/resources/templates/applicationList.html
Normal file
34
book-rent/src/main/resources/templates/applicationList.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>書籍貸出申請一覧(承認待ち)</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>書籍貸出申請一覧(承認待ち)</h1>
|
||||
<div class="error" th:if="${errorMessage}" th:text="${errorMessage}"></div>
|
||||
<div class="error" th:each="e : ${errors}" th:text="${e}"></div>
|
||||
<div class="card">
|
||||
<p th:if="${#lists.isEmpty(list)}">承認待ちの申請はありません。</p>
|
||||
<table th:unless="${#lists.isEmpty(list)}">
|
||||
<thead><tr><th>申請ID</th><th>申請者名</th><th>書籍名</th><th>申請日</th><th>貸出日</th><th>返却予定日</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<tr th:each="r : ${list}">
|
||||
<td th:text="${r.idRequest}"></td>
|
||||
<td th:text="${r.nmApplicant}"></td>
|
||||
<td th:text="${r.nmBook}"></td>
|
||||
<td th:text="${r.dateRequest}"></td>
|
||||
<td th:text="${r.dateBorrow}"></td>
|
||||
<td th:text="${r.dateScheduledReturn}"></td>
|
||||
<td><a class="btn" th:href="@{/admin/applications/{id}(id=${r.idRequest})}">承認</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p><a class="btn sub" th:href="@{/menu}">メニューに戻る</a></p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
42
book-rent/src/main/resources/templates/bookConfirm.html
Normal file
42
book-rent/src/main/resources/templates/bookConfirm.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>書籍情報確認</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>書籍情報確認</h1>
|
||||
<div class="card">
|
||||
<h2 th:text="${title}">書籍登録</h2>
|
||||
<table>
|
||||
<tr><th>ISBN</th><td th:text="${form.isbn}"></td></tr>
|
||||
<tr><th>書籍名</th><td th:text="${form.nmBook}"></td></tr>
|
||||
<tr><th>書籍名よみ</th><td th:text="${form.knBook}"></td></tr>
|
||||
<tr><th>出版社</th><td th:text="${form.publisher}"></td></tr>
|
||||
<tr><th>特記事項</th><td th:text="${form.note}"></td></tr>
|
||||
</table>
|
||||
<form th:action="@{${base + '/execute'}}" method="post" style="display:inline">
|
||||
<input type="hidden" name="idBook" th:value="${form.idBook}">
|
||||
<input type="hidden" name="isbn" th:value="${form.isbn}">
|
||||
<input type="hidden" name="nmBook" th:value="${form.nmBook}">
|
||||
<input type="hidden" name="knBook" th:value="${form.knBook}">
|
||||
<input type="hidden" name="publisher" th:value="${form.publisher}">
|
||||
<input type="hidden" name="note" th:value="${form.note}">
|
||||
<button type="submit" th:text="${title == '書籍登録'} ? '登録' : '編集'">登録</button>
|
||||
</form>
|
||||
<form th:action="@{${base + '/input'}}" method="post" style="display:inline">
|
||||
<input type="hidden" name="idBook" th:value="${form.idBook}">
|
||||
<input type="hidden" name="isbn" th:value="${form.isbn}">
|
||||
<input type="hidden" name="nmBook" th:value="${form.nmBook}">
|
||||
<input type="hidden" name="knBook" th:value="${form.knBook}">
|
||||
<input type="hidden" name="publisher" th:value="${form.publisher}">
|
||||
<input type="hidden" name="note" th:value="${form.note}">
|
||||
<button type="submit" class="sub">書籍情報入力に戻る</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
34
book-rent/src/main/resources/templates/bookInput.html
Normal file
34
book-rent/src/main/resources/templates/bookInput.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>書籍情報入力</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>書籍情報入力</h1>
|
||||
<div class="error" th:if="${errorMessage}" th:text="${errorMessage}"></div>
|
||||
<div class="error" th:each="e : ${errors}" th:text="${e}"></div>
|
||||
<div class="card">
|
||||
<h2 th:text="${title}">書籍登録</h2>
|
||||
<form th:action="@{${base + '/confirm'}}" method="post">
|
||||
<input type="hidden" name="idBook" th:value="${form.idBook}">
|
||||
<label for="isbn">ISBN(必須・13文字以内)</label>
|
||||
<input type="text" id="isbn" name="isbn" th:value="${form.isbn}" maxlength="13">
|
||||
<label for="nmBook">書籍名(必須・50文字以内)</label>
|
||||
<input type="text" id="nmBook" name="nmBook" th:value="${form.nmBook}" maxlength="50">
|
||||
<label for="knBook">書籍名よみ(100文字以内)</label>
|
||||
<input type="text" id="knBook" name="knBook" th:value="${form.knBook}" maxlength="100">
|
||||
<label for="publisher">出版社(50文字以内)</label>
|
||||
<input type="text" id="publisher" name="publisher" th:value="${form.publisher}" maxlength="50">
|
||||
<label for="note">特記事項</label>
|
||||
<input type="text" id="note" name="note" th:value="${form.note}">
|
||||
<p><button type="submit" th:text="${title} + '確認'">確認</button>
|
||||
<a class="btn sub" th:href="@{/books}">書籍一覧に戻る</a></p>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
67
book-rent/src/main/resources/templates/bookList.html
Normal file
67
book-rent/src/main/resources/templates/bookList.html
Normal file
@@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>書籍一覧</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>書籍一覧</h1>
|
||||
<div class="error" th:if="${errorMessage}" th:text="${errorMessage}"></div>
|
||||
<div class="card">
|
||||
<form th:action="@{/books}" method="get">
|
||||
<label for="nmBook">書籍名</label>
|
||||
<input type="text" id="nmBook" name="nmBook" th:value="${nmBook}">
|
||||
<label for="publisher">出版社</label>
|
||||
<input type="text" id="publisher" name="publisher" th:value="${publisher}">
|
||||
<label for="note">特記事項</label>
|
||||
<input type="text" id="note" name="note" th:value="${note}">
|
||||
<p><button type="submit">検索</button>
|
||||
<a class="btn sub" th:href="@{/menu}">メニューに戻る</a>
|
||||
<a class="btn" th:if="${session.loginUser.admin}" th:href="@{/admin/books/new}">書籍新規登録</a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2>検索結果</h2>
|
||||
<p th:if="${#lists.isEmpty(books)}">該当する書籍はありません。</p>
|
||||
<table th:unless="${#lists.isEmpty(books)}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>蔵書ID</th>
|
||||
<th>ISBN</th>
|
||||
<th>書籍名</th>
|
||||
<th>書籍名よみ</th>
|
||||
<th>出版社</th>
|
||||
<th>特記事項</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="b : ${books}">
|
||||
<td th:text="${b.idBook}"></td>
|
||||
<td th:text="${b.isbn}"></td>
|
||||
<td th:text="${b.nmBook}"></td>
|
||||
<td th:text="${b.knBook}"></td>
|
||||
<td th:text="${b.publisher}"></td>
|
||||
<td th:text="${b.note}"></td>
|
||||
<td>
|
||||
<!-- 一般:貸出申請(LOAN-01) / 管理者:編集(BOOK-03) -->
|
||||
<a class="btn" th:unless="${session.loginUser.admin}"
|
||||
th:href="@{/loan/apply(idBook=${b.idBook})}">貸出申請</a>
|
||||
<a class="btn" th:if="${session.loginUser.admin}"
|
||||
th:href="@{/admin/books/edit(idBook=${b.idBook})}">編集</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
19
book-rent/src/main/resources/templates/complete.html
Normal file
19
book-rent/src/main/resources/templates/complete.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>完了</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>完了</h1>
|
||||
<div class="info" th:text="${message} ?: '処理が完了しました。'"></div>
|
||||
<p>
|
||||
<a class="btn" th:href="@{${backUrl}}" th:text="${backLabel}">戻る</a>
|
||||
<a class="btn sub" th:href="@{/menu}">メニューに戻る</a>
|
||||
</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
17
book-rent/src/main/resources/templates/error.html
Normal file
17
book-rent/src/main/resources/templates/error.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>エラー</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>エラー</h1>
|
||||
<div class="card">
|
||||
<div class="error" th:text="${errorMessage} ?: 'エラーが発生しました。'"></div>
|
||||
<a class="btn" th:href="@{/menu}">メニューに戻る</a>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
15
book-rent/src/main/resources/templates/fragments/header.html
Normal file
15
book-rent/src/main/resources/templates/fragments/header.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<body>
|
||||
<!-- ログイン後の全画面共通ヘッダー:右上にログイン者名とログアウト(要件定義書 7.1) -->
|
||||
<header class="top" th:fragment="header">
|
||||
<span>書籍貸出管理システム</span>
|
||||
<span>
|
||||
<span class="user" th:text="${session.loginUser.nmEmployee}">社員名</span>
|
||||
<form th:action="@{/logout}" method="post"><button type="submit" class="sub">ログアウト</button></form>
|
||||
</span>
|
||||
</header>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
38
book-rent/src/main/resources/templates/loanApplyConfirm.html
Normal file
38
book-rent/src/main/resources/templates/loanApplyConfirm.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>書籍貸出申請確認</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>書籍貸出申請確認</h1>
|
||||
<div class="card">
|
||||
<table>
|
||||
<tr><th>書籍名</th><td th:text="${book.nmBook}"></td></tr>
|
||||
<tr><th>ISBN</th><td th:text="${book.isbn}"></td></tr>
|
||||
<tr><th>出版社</th><td th:text="${book.publisher}"></td></tr>
|
||||
<tr><th>特記事項</th><td th:text="${book.note}"></td></tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr><th>貸出日</th><td th:text="${dateBorrow}"></td></tr>
|
||||
<tr><th>返却予定日</th><td th:text="${dateScheduledReturn}"></td></tr>
|
||||
</table>
|
||||
<form th:action="@{/loan/apply/execute}" method="post" style="display:inline">
|
||||
<input type="hidden" name="idBook" th:value="${idBook}">
|
||||
<input type="hidden" name="dateBorrow" th:value="${dateBorrow}">
|
||||
<input type="hidden" name="dateScheduledReturn" th:value="${dateScheduledReturn}">
|
||||
<button type="submit">申請</button>
|
||||
</form>
|
||||
<form th:action="@{/loan/apply/input}" method="post" style="display:inline">
|
||||
<input type="hidden" name="idBook" th:value="${idBook}">
|
||||
<input type="hidden" name="dateBorrow" th:value="${dateBorrow}">
|
||||
<input type="hidden" name="dateScheduledReturn" th:value="${dateScheduledReturn}">
|
||||
<button type="submit" class="sub">申請情報入力に戻る</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
33
book-rent/src/main/resources/templates/loanApplyInput.html
Normal file
33
book-rent/src/main/resources/templates/loanApplyInput.html
Normal file
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>書籍貸出申請</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>書籍貸出申請</h1>
|
||||
<div class="error" th:if="${errorMessage}" th:text="${errorMessage}"></div>
|
||||
<div class="error" th:each="e : ${errors}" th:text="${e}"></div>
|
||||
<div class="card">
|
||||
<table>
|
||||
<tr><th>書籍名</th><td th:text="${book.nmBook}"></td></tr>
|
||||
<tr><th>ISBN</th><td th:text="${book.isbn}"></td></tr>
|
||||
<tr><th>出版社</th><td th:text="${book.publisher}"></td></tr>
|
||||
<tr><th>特記事項</th><td th:text="${book.note}"></td></tr>
|
||||
</table>
|
||||
<form th:action="@{/loan/apply/confirm}" method="post">
|
||||
<input type="hidden" name="idBook" th:value="${idBook}">
|
||||
<label for="dateBorrow">貸出日</label>
|
||||
<input type="date" id="dateBorrow" name="dateBorrow" th:value="${dateBorrow}">
|
||||
<label for="dateScheduledReturn">返却予定日</label>
|
||||
<input type="date" id="dateScheduledReturn" name="dateScheduledReturn" th:value="${dateScheduledReturn}">
|
||||
<p><button type="submit">申請確認</button>
|
||||
<a class="btn sub" th:href="@{/books}">書籍一覧に戻る</a></p>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,93 +2,122 @@
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<!-- 外部スクリプトの読み込み -->
|
||||
<script th:src="@{/js/common.js}"></script>
|
||||
|
||||
<!-- CSSの読み込み -->
|
||||
<link rel="stylesheet" th:href="@{/css/all.css}" type="text/css">
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}" type="text/css">
|
||||
|
||||
<title>ログイン</title>
|
||||
<meta charset="UTF-8">
|
||||
<title>ログイン</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="loginContainer">
|
||||
|
||||
<h1>ログイン</h1>
|
||||
|
||||
<form th:action="@{/doLogin}"
|
||||
method="post"
|
||||
th:object="${loginInfoForm}">
|
||||
|
||||
<!-- エラーメッセージ -->
|
||||
<div class="msgBox error"
|
||||
th:if="${messageError != null}">
|
||||
<span class="error"
|
||||
th:text="${messageError.message}"></span>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<!-- メールアドレス -->
|
||||
<tr>
|
||||
<th class="header">メールアドレス</th>
|
||||
<td>
|
||||
<input
|
||||
id="mailAddress"
|
||||
type="text"
|
||||
th:field="*{mailAddress}"
|
||||
placeholder="メールアドレス"
|
||||
required
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- パスワード -->
|
||||
<tr>
|
||||
<th class="header">パスワード</th>
|
||||
<td>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
th:field="*{password}"
|
||||
placeholder="パスワード"
|
||||
required
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- ボタン -->
|
||||
<tr>
|
||||
<td class="btnArea" colspan="2">
|
||||
<input
|
||||
type="submit"
|
||||
value="ログイン"
|
||||
/>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onclick="clearInput()">
|
||||
リセット
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- 入力内容のリセット -->
|
||||
<script>
|
||||
function clearInput() {
|
||||
document.getElementById('mailAddress').value = '';
|
||||
document.getElementById('password').value = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<h1>書籍貸出管理システム</h1>
|
||||
<div class="card">
|
||||
<h2>ログイン</h2>
|
||||
<div class="error" th:if="${errorMessage}" th:text="${errorMessage}"></div>
|
||||
<form th:action="@{/login}" method="post">
|
||||
<label for="mailAddress">メールアドレス</label>
|
||||
<input type="text" id="mailAddress" name="mailAddress" th:value="${mailAddress}"
|
||||
autocomplete="username">
|
||||
<label for="password">パスワード</label>
|
||||
<input type="password" id="password" name="password" autocomplete="current-password">
|
||||
<p><button type="submit">ログイン</button></p>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
<!--<!DOCTYPE html>-->
|
||||
<!--<html xmlns:th="http://www.thymeleaf.org">-->
|
||||
|
||||
<!--<head>-->
|
||||
<!-- <meta charset="UTF-8">-->
|
||||
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0">-->
|
||||
|
||||
<!-- 外部スクリプトの読み込み -->
|
||||
<!-- <script th:src="@{/js/common.js}"></script>-->
|
||||
|
||||
<!-- CSSの読み込み -->
|
||||
<!-- <link rel="stylesheet" th:href="@{/css/all.css}" type="text/css">-->
|
||||
<!-- <link rel="stylesheet" th:href="@{/css/style.css}" type="text/css">-->
|
||||
|
||||
<!-- <title>ログイン</title>-->
|
||||
<!--</head>-->
|
||||
|
||||
<!--<body>-->
|
||||
|
||||
<!-- <div class="loginContainer">-->
|
||||
|
||||
<!-- <h1>ログイン</h1>-->
|
||||
|
||||
<!-- <form th:action="@{/doLogin}"-->
|
||||
<!-- method="post"-->
|
||||
<!-- th:object="${loginInfoForm}">-->
|
||||
|
||||
<!-- エラーメッセージ -->
|
||||
<!-- <div class="msgBox error"-->
|
||||
<!-- th:if="${messageError != null}">-->
|
||||
<!-- <span class="error"-->
|
||||
<!-- th:text="${messageError.message}"></span>-->
|
||||
<!-- </div>-->
|
||||
|
||||
<!-- <table>-->
|
||||
<!-- メールアドレス -->
|
||||
<!-- <tr>-->
|
||||
<!-- <th class="header">メールアドレス</th>-->
|
||||
<!-- <td>-->
|
||||
<!-- <input-->
|
||||
<!-- id="mailAddress"-->
|
||||
<!-- type="text"-->
|
||||
<!-- th:field="*{mailAddress}"-->
|
||||
<!-- placeholder="メールアドレス"-->
|
||||
<!-- required-->
|
||||
<!-- />-->
|
||||
<!-- </td>-->
|
||||
<!-- </tr>-->
|
||||
|
||||
<!-- パスワード -->
|
||||
<!-- <tr>-->
|
||||
<!-- <th class="header">パスワード</th>-->
|
||||
<!-- <td>-->
|
||||
<!-- <input-->
|
||||
<!-- id="password"-->
|
||||
<!-- type="password"-->
|
||||
<!-- th:field="*{password}"-->
|
||||
<!-- placeholder="パスワード"-->
|
||||
<!-- required-->
|
||||
<!-- />-->
|
||||
<!-- </td>-->
|
||||
<!-- </tr>-->
|
||||
|
||||
<!-- ボタン -->
|
||||
<!-- <tr>-->
|
||||
<!-- <td class="btnArea" colspan="2">-->
|
||||
<!-- <input-->
|
||||
<!-- type="submit"-->
|
||||
<!-- value="ログイン"-->
|
||||
<!-- />-->
|
||||
|
||||
<!-- <button-->
|
||||
<!-- type="button"-->
|
||||
<!-- onclick="clearInput()">-->
|
||||
<!-- リセット-->
|
||||
<!-- </button>-->
|
||||
<!-- </td>-->
|
||||
<!-- </tr>-->
|
||||
<!-- </table>-->
|
||||
|
||||
<!-- </form>-->
|
||||
|
||||
<!-- </div>-->
|
||||
|
||||
<!-- 入力内容のリセット -->
|
||||
<!-- <script>-->
|
||||
<!-- function clearInput() {-->
|
||||
<!-- document.getElementById('mailAddress').value = '';-->
|
||||
<!-- document.getElementById('password').value = '';-->
|
||||
<!-- }-->
|
||||
<!-- </script>-->
|
||||
|
||||
<!--</body>-->
|
||||
<!--</html>-->
|
||||
@@ -1,36 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>メニュー</title>
|
||||
|
||||
<link rel="stylesheet" th:href="@{/css/all.css}">
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
<meta charset="UTF-8">
|
||||
<title>メニュー</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>メニュー</h1>
|
||||
|
||||
<div class="userInfo">
|
||||
<span>ログインユーザー:</span>
|
||||
<span th:text="${loginUserName}">ユーザー名</span>
|
||||
|
||||
<form th:action="@{/logout}" method="post">
|
||||
<button type="submit">ログアウト</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="menuArea">
|
||||
<form th:action="@{/book/list}" method="get">
|
||||
<button type="submit">書籍一覧</button>
|
||||
</form>
|
||||
|
||||
<form th:action="@{/book/rent}" method="get">
|
||||
<button type="submit">書籍貸出申請一覧</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>メニュー</h1>
|
||||
<div class="error" th:if="${errorMessage}" th:text="${errorMessage}"></div>
|
||||
<div class="card menu">
|
||||
<a class="btn" th:href="@{/books}">書籍一覧</a>
|
||||
<!-- 管理者のみ(サーバー側でも /admin/** は管理者以外を拒否している) -->
|
||||
<th:block th:if="${session.loginUser.admin}">
|
||||
<a class="btn" th:href="@{/admin/applications}">書籍貸出申請一覧</a>
|
||||
<a class="btn" th:href="@{/admin/lendings}">貸出中書籍一覧</a>
|
||||
<a class="btn" th:href="@{/admin/employees/new}">社員登録</a>
|
||||
</th:block>
|
||||
<a class="btn" th:href="@{/employees/search}">社員編集</a>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
31
book-rent/src/main/resources/templates/returnConfirm.html
Normal file
31
book-rent/src/main/resources/templates/returnConfirm.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>書籍返却確認</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<main>
|
||||
<h1>書籍返却確認</h1>
|
||||
<div class="error" th:if="${errorMessage}" th:text="${errorMessage}"></div>
|
||||
<div class="error" th:each="e : ${errors}" th:text="${e}"></div>
|
||||
<div class="card">
|
||||
<table>
|
||||
<tr><th>申請ID</th><td th:text="${r.idRequest}"></td></tr>
|
||||
<tr><th>申請者名</th><td th:text="${r.nmApplicant}"></td></tr>
|
||||
<tr><th>申請日</th><td th:text="${r.dateRequest}"></td></tr>
|
||||
<tr><th>ISBN</th><td th:text="${r.isbn}"></td></tr>
|
||||
<tr><th>書籍名</th><td th:text="${r.nmBook}"></td></tr>
|
||||
<tr><th>出版社</th><td th:text="${r.publisher}"></td></tr>
|
||||
<tr><th>特記事項</th><td th:text="${r.note}"></td></tr>
|
||||
<tr><th>貸出日</th><td th:text="${r.dateBorrow}"></td></tr>
|
||||
<tr><th>返却予定日</th><td th:text="${r.dateScheduledReturn}"></td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<form method="post" style="display:inline" th:action="@{/admin/lendings/{id}/return(id=${r.idRequest})}"><button type="submit">返却</button></form>
|
||||
<a class="btn sub" th:href="@{/admin/lendings}">貸出中書籍一覧に戻る</a>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user