Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
177b326baa | ||
|
|
513f1fe53a | ||
|
|
fc2bc31a52 | ||
|
|
f07be31978 | ||
|
|
b0e1174ef2 | ||
|
|
141f3e3b5d | ||
|
|
6ca6d6399b | ||
| 1520676916 | |||
| 47ce48e323 | |||
|
|
441d91d1e2 | ||
| 34b2e8c5de | |||
|
|
3a7b165e76 | ||
| f5c8bb302c | |||
| c5c5c3dcc9 | |||
| f8973bd47f |
@@ -18,45 +18,47 @@ import com.example.demo.service.BookInsertService;
|
||||
@Controller
|
||||
public class BookInsertController {
|
||||
|
||||
@Autowired
|
||||
private BookInsertService bookInsertService;
|
||||
@Autowired
|
||||
private BookInsertService bookInsertService;
|
||||
|
||||
@Autowired
|
||||
private BookCategoryRepository categoryRepository;
|
||||
@Autowired
|
||||
private BookCategoryRepository categoryRepository;
|
||||
|
||||
@Autowired
|
||||
private SubCategoryRepository subCategoryRepository;
|
||||
@Autowired
|
||||
private SubCategoryRepository subCategoryRepository;
|
||||
|
||||
@Autowired
|
||||
private StorageLocationRepository storageLocationRepository;
|
||||
@Autowired
|
||||
private StorageLocationRepository storageLocationRepository;
|
||||
|
||||
@Autowired
|
||||
private BookInsertRepository bookInsertRepository;
|
||||
@Autowired
|
||||
private BookInsertRepository bookInsertRepository;
|
||||
|
||||
@GetMapping("/bookInsert")
|
||||
public String bookInsert(Model model) {
|
||||
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
|
||||
model.addAttribute("bookInsert",new BookInsert());
|
||||
model.addAttribute("categoryList",categoryRepository.findAll());
|
||||
model.addAttribute("subCategoryList",subCategoryRepository.findAll());
|
||||
model.addAttribute("locationList",storageLocationRepository.findAll());
|
||||
model.addAttribute("bookInsert",new BookInsert());
|
||||
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
|
||||
model.addAttribute("bookInsert", new BookInsert());
|
||||
model.addAttribute("categoryList", categoryRepository.findAll());
|
||||
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
|
||||
model.addAttribute("locationList", storageLocationRepository.findAll());
|
||||
model.addAttribute("bookInsert", new BookInsert());
|
||||
return "bookInsert";
|
||||
}
|
||||
|
||||
// 初期表示: 空のformを渡す(th:fieldの初期値が空になる)
|
||||
|
||||
// 確認画面から戻る: POSTされた入力中の値がformに入ったまま入力画面へ
|
||||
//入力内容確認してOKであれば確認画面へ
|
||||
@PostMapping("/bookInsertConfirm")
|
||||
public String bookInsertConfirm(@Validated BookInsert bookInsert,BindingResult result,Model model) {
|
||||
if(result.hasErrors()) {
|
||||
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
|
||||
model.addAttribute("categoryList",categoryRepository.findAll());
|
||||
if(bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
|
||||
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
||||
public String bookInsertConfirm(@Validated BookInsert bookInsert, BindingResult result, Model model) {
|
||||
if (result.hasErrors()) {
|
||||
model.addAttribute("nextBookManageId", bookInsertService.createBookManageId());
|
||||
model.addAttribute("categoryList", categoryRepository.findAll());
|
||||
if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
|
||||
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);
|
||||
@@ -64,32 +66,23 @@ private BookInsertRepository bookInsertRepository;
|
||||
|
||||
}
|
||||
bookInsertService.save(bookInsert);
|
||||
model.addAttribute("bookInsert",bookInsert);
|
||||
model.addAttribute("bookInsert", bookInsert);
|
||||
return "bookInsertConfirm";
|
||||
}
|
||||
|
||||
//確認画面から「もどる」ボタンを押したら入力画面に戻る
|
||||
@PostMapping("/bookInsert")
|
||||
public String bookInsertBack(BookInsert bookInsert,Model model) {
|
||||
model.addAttribute("nextBookManageId",bookInsertService.createBookManageId());
|
||||
model.addAttribute("categoryList",categoryRepository.findAll());
|
||||
if(bookInsert.getBookCategoryId() !=null) {
|
||||
model.addAttribute("subCategoryList",subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
||||
} else{
|
||||
model.addAttribute("subCategoryList",subCategoryRepository.findAll());
|
||||
}
|
||||
model.addAttribute("locationList",storageLocationRepository.findAll());
|
||||
model.addAttribute("bookInsert",bookInsert);
|
||||
return "bookInsert";
|
||||
}
|
||||
|
||||
@PostMapping("/bookInsert/category")
|
||||
public String changeCategory(BookInsert bookInsert,Model model) {
|
||||
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("nextBookManageId", bookInsertService.createBookManageId());
|
||||
model.addAttribute("categoryList", categoryRepository.findAll());
|
||||
if (bookInsert.getBookCategoryId() != null) { //nullじゃなかったら
|
||||
model.addAttribute("subCategoryList",
|
||||
subCategoryRepository.findByBookCategory_BookCategoryId(bookInsert.getBookCategoryId()));
|
||||
//そのカテゴリに属するサブカテゴリを持ってくる
|
||||
} else {
|
||||
model.addAttribute("subCategoryList", subCategoryRepository.findAll());
|
||||
}
|
||||
model.addAttribute("locationList", storageLocationRepository.findAll());
|
||||
model.addAttribute("bookInsert", bookInsert);
|
||||
|
||||
return "bookInsert";
|
||||
@@ -97,13 +90,7 @@ private BookInsertRepository bookInsertRepository;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
|
||||
//subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
|
||||
//「カテゴリIDが1のサブカテゴリを取ってくる」
|
||||
//model.addAttribute("subCategoryList",取得結果)
|
||||
|
||||
|
||||
|
||||
|
||||
//画面で選択したカテゴリbookInsert.getBookCategoryId()に選択した結果をいれる
|
||||
//subCategoryRepository.findBookCategory_BookCategoryId(bookInsert.getBookCategoryId(1)));
|
||||
//「カテゴリIDが1のサブカテゴリを取ってくる」
|
||||
//model.addAttribute("subCategoryList",取得結果)
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
import com.example.demo.service.BookLendService;
|
||||
import com.example.demo.service.BookServiceImpl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -19,7 +22,7 @@ public class BookLendController {
|
||||
private final BookServiceImpl bookServiceImpl;
|
||||
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
private final BookLendService bookLendService;
|
||||
|
||||
@PostMapping("/bookLend")
|
||||
public String bookLend(Model model) {
|
||||
@@ -28,11 +31,22 @@ public class BookLendController {
|
||||
|
||||
@PostMapping("/bookLend/{id}")
|
||||
public String bookLend(@PathVariable int id, Model model) {
|
||||
System.out.println(id);
|
||||
model.addAttribute("book", bookServiceImpl.findById(id));
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.entity.BookLend;
|
||||
import com.example.demo.service.BookLendService;
|
||||
|
||||
|
||||
@@ -20,12 +18,19 @@ public class LendListController {
|
||||
@GetMapping("/lendList")
|
||||
public String list(Model model) {
|
||||
|
||||
List<BookLend> aaa = lendlistService.findAll();
|
||||
|
||||
// findAllを使って、DBから一覧を取得 でバックで取得したのを確認
|
||||
model.addAttribute("list",lendlistService.findAll());
|
||||
|
||||
return "lendList";
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/return-book")
|
||||
public String retun(@RequestParam(name="lendId") int returnBook){
|
||||
|
||||
lendlistService.regist(returnBook);
|
||||
|
||||
|
||||
return "bookLendResult";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class LoginController {
|
||||
AccountEntity accountEntity = loginService.login(loginForm);
|
||||
if (accountEntity == null) {
|
||||
model.addAttribute("loginError",
|
||||
"ログインIDまたはパスワードが正しくありません");
|
||||
"社員IDまたはパスワードが正しくありません");
|
||||
return "login";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.example.demo.entity;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -35,11 +35,11 @@ public class BookLend {
|
||||
|
||||
// 貸出日
|
||||
@Column(name = "book_lend_date", nullable = false)
|
||||
private Date bookLendDate;
|
||||
private LocalDate bookLendDate;
|
||||
|
||||
// 返却日
|
||||
@Column(name = "book_return_date", nullable = false)
|
||||
private Date bookReturnDate;
|
||||
private LocalDate bookReturnDate;
|
||||
|
||||
// 貸出状態
|
||||
@Column(name = "book_status", nullable = false)
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
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 {
|
||||
|
||||
private Book book;
|
||||
|
||||
@NotBlank(message = "社員IDの入力は必須です")
|
||||
private Employee employeeBooklend;
|
||||
|
||||
private Date bookLendDate;
|
||||
|
||||
@NotNull(message = "返却日の入力は必須です")
|
||||
private Date bookReturnDate;
|
||||
|
||||
private Integer bookStatus;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.Employee;
|
||||
import com.example.demo.repository.BookLendRepository;
|
||||
import com.example.demo.repository.BookRepository;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
|
||||
@Service
|
||||
public class BookLendService {
|
||||
@@ -14,8 +20,49 @@ public class BookLendService {
|
||||
@Autowired
|
||||
private BookLendRepository bookLendRepository;
|
||||
|
||||
@Autowired
|
||||
private BookRepository bookRepository;
|
||||
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
public List<BookLend> findAll() {
|
||||
return bookLendRepository.findAll();
|
||||
return bookLendRepository.findBybookStatus(1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
図書貸出処理
|
||||
</h1>
|
||||
|
||||
<div class="float-end">
|
||||
<a th:href="@{/topmenu}">
|
||||
トップメニューへ
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
以下の図書を貸出します。貸出先の社員IDと返却予定日を入力してください。
|
||||
</p>
|
||||
@@ -20,7 +26,7 @@
|
||||
図書情報
|
||||
</h2>
|
||||
|
||||
<form id="lendForm" action="bookLendConfirm" method="post">
|
||||
<form th:action="@{/bookLend/confirm}" method="POST" id="lendForm">
|
||||
|
||||
<div class="card-body">
|
||||
<table class="info-table">
|
||||
@@ -34,8 +40,8 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr th:each="book : ${book}">
|
||||
<td th:hidden="*{book.bookId}"></td>
|
||||
<tr>
|
||||
<!-- <td th:hidden="*{book.bookId}"></td>-->
|
||||
<td th:text="*{book.bookManageId}"></td>
|
||||
<td th:text="*{book.title}"></td>
|
||||
<td th:text="*{book.author}"></td>
|
||||
@@ -59,7 +65,7 @@
|
||||
社員ID
|
||||
</label>
|
||||
|
||||
<input type="text" id="employeeId" placeholder="社員IDを入力してください">
|
||||
<input type="text" name="employeeId" placeholder="社員IDを入力してください">
|
||||
|
||||
</select>
|
||||
</div>
|
||||
@@ -112,8 +118,10 @@
|
||||
貸出処理を行うと、対象の図書のステータスが「貸出中」に変更されます。
|
||||
</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="貸出する">
|
||||
<!-- <button type="button" class="btn btn-primary" onclick="submitLend()">-->
|
||||
|
||||
<input type="reset" name="reset" value="入力内容をクリア">
|
||||
|
||||
|
||||
20
src/main/resources/templates/bookLendResult.html
Normal file
20
src/main/resources/templates/bookLendResult.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!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>
|
||||
@@ -10,9 +10,9 @@
|
||||
<body>
|
||||
<h1>貸出中図書一覧</h1>
|
||||
|
||||
<!-- action先要修正 -->
|
||||
<form action="/lendList" method="GET">
|
||||
<input type="submit" value="返却" class="btn">
|
||||
<div class="float-end">
|
||||
<a th:href="@{/topmenu}">トップメニューへ</a>
|
||||
</div>
|
||||
|
||||
|
||||
<table>
|
||||
@@ -24,7 +24,7 @@
|
||||
<th>管理ID</th>
|
||||
<th>タイトル</th>
|
||||
<th>返却予定日</th>
|
||||
<th>超過日数</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -37,42 +37,30 @@
|
||||
<td th:text="*{booklist.book.bookManageId}"></td>
|
||||
<td th:text="*{booklist.book.title}"></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>
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
</form>
|
||||
<script>
|
||||
|
||||
<!-- 以下ポップアップ -->
|
||||
<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>
|
||||
function MoveCheck() {
|
||||
return window.confirm("返却処理を実行します。よろしいですか?");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ログイン</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -16,7 +17,7 @@
|
||||
<form th:action="@{/login}" th:object="${loginForm}" method="post">
|
||||
<div class="form-group">
|
||||
<label for="employeeId">社員ID</label>
|
||||
<input id="employeeId" type="text" th:field="*{employeeId}">
|
||||
<input id="employeeId" type="text" th:field="*{employeeId}"pattern="^[0-9]+$"title="数値以外は入力しないでください">
|
||||
<p class="field-error" th:errors="*{employeeId}"></p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
</a>
|
||||
|
||||
<hr>
|
||||
</th>
|
||||
|
||||
<a class="card" href="/passwordChange">
|
||||
<h3>パスワード変更</h3>
|
||||
@@ -105,7 +106,7 @@
|
||||
初期パスワードを<br> 変更します。
|
||||
</p>
|
||||
</a>
|
||||
</th>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user