3 Commits

13 changed files with 145 additions and 236 deletions

View File

@@ -18,79 +18,92 @@ import com.example.demo.service.BookInsertService;
@Controller @Controller
public class BookInsertController { public class BookInsertController {
@Autowired @Autowired
private BookInsertService bookInsertService; private BookInsertService bookInsertService;
@Autowired @Autowired
private BookCategoryRepository categoryRepository; private BookCategoryRepository categoryRepository;
@Autowired @Autowired
private SubCategoryRepository subCategoryRepository; private SubCategoryRepository subCategoryRepository;
@Autowired @Autowired
private StorageLocationRepository storageLocationRepository; private StorageLocationRepository storageLocationRepository;
@Autowired @Autowired
private BookInsertRepository bookInsertRepository; private BookInsertRepository bookInsertRepository;
@GetMapping("/bookInsert") @GetMapping("/bookInsert")
public String bookInsert(Model model) { public String bookInsert(Model model) {
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId()); model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("bookInsert", new BookInsert()); model.addAttribute("bookInsert",new BookInsert());
model.addAttribute("categoryList", categoryRepository.findAll()); model.addAttribute("categoryList",categoryRepository.findAll());
model.addAttribute("subCategoryList", subCategoryRepository.findAll()); model.addAttribute("subCategoryList",subCategoryRepository.findAll());
model.addAttribute("locationList", storageLocationRepository.findAll()); model.addAttribute("locationList",storageLocationRepository.findAll());
model.addAttribute("bookInsert", new BookInsert()); model.addAttribute("bookInsert",new BookInsert());
return "bookInsert"; return "bookInsert";
} }
// 初期表示: 空のformを渡す(th:fieldの初期値が空になる) // 初期表示: 空のformを渡す(th:fieldの初期値が空になる)
// 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ // 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ
//入力内容確認してOKであれば確認画面へ @PostMapping("/bookInsertConfirm")
@PostMapping("/bookInsertConfirm") public String bookInsertConfirm(@Validated BookInsert bookInsert,BindingResult result,Model model) {
public String bookInsertConfirm(@Validated BookInsert bookInsert, BindingResult result, Model model) { if(result.hasErrors()) {
if (result.hasErrors()) { model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId()); model.addAttribute("categoryList",categoryRepository.findAll());
model.addAttribute("categoryList", categoryRepository.findAll()); if(bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
model.addAttribute("subCategoryList", //そのカテゴリに属するサブカテゴリを持ってくる
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId())); } else{
//そのカテゴリに属するサブカテゴリを持ってくる model.addAttribute("subCategoryList",subCategoryRepository.findAll());
} else { }
model.addAttribute("subCategoryList", subCategoryRepository.findAll()); model.addAttribute("locationList",storageLocationRepository.findAll());
} model.addAttribute("bookInsert", bookInsert);
model.addAttribute("locationList",storageLocationRepository.findAll()); return "bookInsert";
model.addAttribute("bookInsert", bookInsert);
return "bookInsert";
} }
bookInsertService.save(bookInsert); bookInsertService.save(bookInsert);
model.addAttribute("bookInsert", bookInsert); model.addAttribute("bookInsert",bookInsert);
return "bookInsertConfirm"; return "bookInsertConfirm";
} }
@PostMapping("/bookInsert/category") //確認画面から「もどる」ボタンを押したら入力画面に戻る
public String changeCategory(BookInsert bookInsert, Model model) { @PostMapping("/bookInsert")
//カテゴリプルダウンに表示するデータを取得 public String bookInsertBack(BookInsert bookInsert,Model model) {
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId()); model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("categoryList", categoryRepository.findAll()); model.addAttribute("categoryList",categoryRepository.findAll());
if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら if(bookInsert.getBookCategoryId() !=null) {
model.addAttribute("subCategoryList", model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId())); } else{
//そのカテゴリに属するサブカテゴリを持ってくる model.addAttribute("subCategoryList",subCategoryRepository.findAll());
} else { }
model.addAttribute("subCategoryList", subCategoryRepository.findAll()); model.addAttribute("locationList",storageLocationRepository.findAll());
} model.addAttribute("bookInsert",bookInsert);
model.addAttribute("locationList", storageLocationRepository.findAll()); return "bookInsert";
model.addAttribute("bookInsert", bookInsert); }
return "bookInsert"; @PostMapping("/bookInsert/category")
} public String changeCategory(BookInsert bookInsert,Model model) {
//カテゴリプルダウンに表示するデータを取得
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
model.addAttribute("categoryList",categoryRepository.findAll());
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
model.addAttribute("locationList",storageLocationRepository.findAll());
model.addAttribute("bookInsert", bookInsert);
return "bookInsert";
}
} }
//画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
//subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
//「カテゴリIDが1のサブカテゴリを取ってくる」 //画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
//model.addAttribute("subCategoryList",取得結果) //subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
//「カテゴリIDが1のサブカテゴリを取ってくる」
//model.addAttribute("subCategoryList",取得結果)

View File

@@ -1,15 +1,12 @@
package com.example.demo.controller; package com.example.demo.controller;
import java.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.service.BookLendService; import com.example.demo.repository.EmployeeRepository;
import com.example.demo.service.BookServiceImpl; import com.example.demo.service.BookServiceImpl;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -22,7 +19,7 @@ public class BookLendController {
private final BookServiceImpl bookServiceImpl; private final BookServiceImpl bookServiceImpl;
@Autowired @Autowired
private final BookLendService bookLendService; private EmployeeRepository employeeRepository;
@PostMapping("/bookLend") @PostMapping("/bookLend")
public String bookLend(Model model) { public String bookLend(Model model) {
@@ -31,22 +28,11 @@ public class BookLendController {
@PostMapping("/bookLend/{id}") @PostMapping("/bookLend/{id}")
public String bookLend(@PathVariable int id, Model model) { public String bookLend(@PathVariable int id, Model model) {
System.out.println(id);
model.addAttribute("book", bookServiceImpl.findById(id)); model.addAttribute("book", bookServiceImpl.findById(id));
return "bookLend"; return "bookLend";
} }
// 貸出処理
@PostMapping("/bookLend/confirm")
public String bookLendConfirm(
@RequestParam(name = "bookId") int bookId,
@RequestParam(name = "bookManageId") String bookManageId,
@RequestParam(name = "employeeId") int employeeId,
@RequestParam(name = "returnDate") LocalDate bookReturnDate,
Model model) {
bookLendService.save(bookId,bookManageId,employeeId,bookReturnDate);
return "redirect:/book";
}
} }

View File

@@ -1,11 +1,13 @@
package com.example.demo.controller; package com.example.demo.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.entity.BookLend;
import com.example.demo.service.BookLendService; import com.example.demo.service.BookLendService;
@@ -18,19 +20,12 @@ public class LendListController {
@GetMapping("/lendList") @GetMapping("/lendList")
public String list(Model model) { public String list(Model model) {
List<BookLend> aaa = lendlistService.findAll();
// findAllを使って、DBから一覧を取得 でバックで取得したのを確認 // findAllを使って、DBから一覧を取得 でバックで取得したのを確認
model.addAttribute("list",lendlistService.findAll()); model.addAttribute("list",lendlistService.findAll());
return "lendList"; return "lendList";
} }
@GetMapping("/return-book")
public String retun(@RequestParam(name="lendId") int returnBook){
lendlistService.regist(returnBook);
return "bookLendResult";
}
} }

View File

@@ -74,7 +74,7 @@ public class LoginController {
AccountEntity accountEntity = loginService.login(loginForm); AccountEntity accountEntity = loginService.login(loginForm);
if (accountEntity == null) { if (accountEntity == null) {
model.addAttribute("loginError", model.addAttribute("loginError",
"社員IDまたはパスワードが正しくありません"); "ログインIDまたはパスワードが正しくありません");
return "login"; return "login";
} }

View File

@@ -1,6 +1,6 @@
package com.example.demo.entity; package com.example.demo.entity;
import java.time.LocalDate; import java.sql.Date;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@@ -35,11 +35,11 @@ public class BookLend {
// 貸出日 // 貸出日
@Column(name = "book_lend_date", nullable = false) @Column(name = "book_lend_date", nullable = false)
private LocalDate bookLendDate; private Date bookLendDate;
// 返却日 // 返却日
@Column(name = "book_return_date", nullable = false) @Column(name = "book_return_date", nullable = false)
private LocalDate bookReturnDate; private Date bookReturnDate;
// 貸出状態 // 貸出状態
@Column(name = "book_status", nullable = false) @Column(name = "book_status", nullable = false)

View File

@@ -1,27 +1,7 @@
package com.example.demo.form; package com.example.demo.form;
import java.sql.Date;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import com.example.demo.entity.Book;
import com.example.demo.entity.Employee;
// 図書の貸出処理に使用予定 // 図書の貸出処理に使用予定
public class BookLendForm { public class BookLendForm {
private Book book;
@NotBlank(message = "社員IDの入力は必須です")
private Employee employeeBooklend;
private Date bookLendDate;
@NotNull(message = "返却日の入力は必須です")
private Date bookReturnDate;
private Integer bookStatus;
} }

View File

@@ -1,18 +1,12 @@
package com.example.demo.service; package com.example.demo.service;
import java.time.LocalDate;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.example.demo.entity.Book;
import com.example.demo.entity.BookLend; import com.example.demo.entity.BookLend;
import com.example.demo.entity.Employee;
import com.example.demo.repository.BookLendRepository; import com.example.demo.repository.BookLendRepository;
import com.example.demo.repository.BookRepository;
import com.example.demo.repository.EmployeeRepository;
@Service @Service
public class BookLendService { public class BookLendService {
@@ -20,49 +14,8 @@ public class BookLendService {
@Autowired @Autowired
private BookLendRepository bookLendRepository; private BookLendRepository bookLendRepository;
@Autowired
private BookRepository bookRepository;
@Autowired
private EmployeeRepository employeeRepository;
public List<BookLend> findAll() { public List<BookLend> findAll() {
return bookLendRepository.findBybookStatus(1); return bookLendRepository.findAll();
}
@Transactional
public void regist(Integer lendId) {
BookLend booklend = bookLendRepository.findById(lendId).orElse(null);
booklend.setBookStatus(0);
bookLendRepository.save(booklend);
}
public void save(int bookId, String bookManageId, int employeeId,
LocalDate bookReturnDate) {
BookLend bookLend = new BookLend();
Book book = bookRepository.findById(bookId)
.orElseThrow(
() -> new IllegalArgumentException("対象の本が見つかりません"));
Employee employee = employeeRepository.findById(employeeId)
.orElseThrow(
() -> new IllegalArgumentException("対象のが見つかりません"));
bookLend.setBook(book);
bookLend.setEmployeeBooklend(employee);
bookLend.setBookLendDate(LocalDate.now());
bookLend.setBookReturnDate(bookReturnDate);
bookLend.setBookStatus(1);
bookLendRepository.save(bookLend);
} }
} }

View File

@@ -78,7 +78,7 @@
</thead> </thead>
<tbody> <tbody>
<tr th:each="book : ${book}" th:if="${book.bookManageId != null && book.isDeleted != 1}"> <tr th:each="book : ${book}" th:if="${book.bookManageId != null}">
<td th:hidden="*{book.bookId}"></td> <td th:hidden="*{book.bookId}"></td>
<td th:text="*{book.bookManageId}"></td> <td th:text="*{book.bookManageId}"></td>

View File

@@ -12,12 +12,6 @@
図書貸出処理 図書貸出処理
</h1> </h1>
<div class="float-end">
<a th:href="@{/topmenu}">
トップメニューへ
</a>
</div>
<p> <p>
以下の図書を貸出します。貸出先の社員IDと返却予定日を入力してください。 以下の図書を貸出します。貸出先の社員IDと返却予定日を入力してください。
</p> </p>
@@ -26,7 +20,7 @@
図書情報 図書情報
</h2> </h2>
<form th:action="@{/bookLend/confirm}" method="POST" id="lendForm"> <form id="lendForm" action="bookLendConfirm" method="post">
<div class="card-body"> <div class="card-body">
<table class="info-table"> <table class="info-table">
@@ -40,8 +34,8 @@
</thead> </thead>
<tbody> <tbody>
<tr> <tr th:each="book : ${book}">
<!-- <td th:hidden="*{book.bookId}"></td>--> <td th:hidden="*{book.bookId}"></td>
<td th:text="*{book.bookManageId}"></td> <td th:text="*{book.bookManageId}"></td>
<td th:text="*{book.title}"></td> <td th:text="*{book.title}"></td>
<td th:text="*{book.author}"></td> <td th:text="*{book.author}"></td>
@@ -65,7 +59,7 @@
社員ID 社員ID
</label> </label>
<input type="text" name="employeeId" placeholder="社員IDを入力してください"> <input type="text" id="employeeId" placeholder="社員IDを入力してください">
</select> </select>
</div> </div>
@@ -85,7 +79,7 @@
</label> </label>
<p th:text="${#calendars.format(#calendars.createNowForTimeZone('Asia/Tokyo'), <p th:text="${#calendars.format(#calendars.createNowForTimeZone('Asia/Tokyo'),
'yyyy年MM月dd日')}"> 'yyyy年MM月dd日')}">
</p> </p>
</div> </div>
@@ -118,10 +112,8 @@
貸出処理を行うと、対象の図書のステータスが「貸出中」に変更されます。 貸出処理を行うと、対象の図書のステータスが「貸出中」に変更されます。
</p> </p>
<input type="hidden" name="bookManageId" th:value="${book.bookManageId}">
<input type="hidden" name="bookId" th:value="${book.bookId}">
<input type="submit" name="submit" onclick="submitLend()" value="貸出する"> <input type="submit" name="submit" onclick="submitLend()" value="貸出する">
<!-- <button type="button" class="btn btn-primary" onclick="submitLend()">-->
<input type="reset" name="reset" value="入力内容をクリア"> <input type="reset" name="reset" value="入力内容をクリア">

View File

@@ -1,20 +0,0 @@
<!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>
<h1>返却処理が完了しました。</h1>
<td>
<form th:action="@{/lendList}" method="get">
<button type="submit" th:value="貸出">貸出中図書一覧に戻る</button>
</td>
</body>
</html>

View File

@@ -10,12 +10,12 @@
<body> <body>
<h1>貸出中図書一覧</h1> <h1>貸出中図書一覧</h1>
<div class="float-end"> <!-- action先要修正 -->
<a th:href="@{/topmenu}">トップメニューへ</a> <form action="/lendList" method="GET">
</div> <input type="submit" value="返却" class="btn">
<table> <table>
<thead> <thead>
<tr> <tr>
@@ -24,7 +24,7 @@
<th>管理ID</th> <th>管理ID</th>
<th>タイトル</th> <th>タイトル</th>
<th>返却予定日</th> <th>返却予定日</th>
<th>超過日数</th>
</tr> </tr>
</thead> </thead>
@@ -37,30 +37,42 @@
<td th:text="*{booklist.book.bookManageId}"></td> <td th:text="*{booklist.book.bookManageId}"></td>
<td th:text="*{booklist.book.title}"></td> <td th:text="*{booklist.book.title}"></td>
<td th:text="*{booklist.bookReturnDate}"></td> <td th:text="*{booklist.bookReturnDate}"></td>
<!-- <td th:text="*{booklist.}"></td>-->
<td>
<form th:action="@{/return-book}" method="get">
<button type="submit" name="lendId" th:value="${booklist.lendId}"
onclick="return MoveCheck();">返却
</button>
</form>
</td>
</tr> </tr>
</tbody> </tbody>
</table>
</table>
<script> </form>
function MoveCheck() { <!-- 以下ポップアップ -->
return window.confirm("返却処理を実行します。よろしいですか?"); <div id="registerModal" class="modal-overlay">
}
<div class="modal">
<div class="modal-message">
返却処理が完了しました!
</div>
<div class="modal-buttons">
<!-- OK -->
<form method="get" action="/lendList">
<button type="submit" class="modal-btn">
OK
</button>
</form>
</div>
</div>
</div>
</script>
</body> </body>

View File

@@ -4,7 +4,6 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>ログイン</title> <title>ログイン</title>
</head> </head>
<body> <body>
@@ -17,7 +16,7 @@
<form th:action="@{/login}" th:object="${loginForm}" method="post"> <form th:action="@{/login}" th:object="${loginForm}" method="post">
<div class="form-group"> <div class="form-group">
<label for="employeeId">社員ID</label> <label for="employeeId">社員ID</label>
<input id="employeeId" type="text" th:field="*{employeeId}"pattern="^[0-9]+$"title="数値以外は入力しないでください"> <input id="employeeId" type="text" th:field="*{employeeId}">
<p class="field-error" th:errors="*{employeeId}"></p> <p class="field-error" th:errors="*{employeeId}"></p>
</div> </div>

View File

@@ -97,7 +97,6 @@
</a> </a>
<hr> <hr>
</th>
<a class="card" href="/passwordChange"> <a class="card" href="/passwordChange">
<h3>パスワード変更</h3> <h3>パスワード変更</h3>
@@ -106,7 +105,7 @@
初期パスワードを<br> 変更します。 初期パスワードを<br> 変更します。
</p> </p>
</a> </a>
</th>
</body> </body>