Compare commits
11 Commits
6ca6d6399b
...
s-tajihi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6d9aa555b | ||
|
|
22a213a4db | ||
|
|
013b08e9b8 | ||
|
|
443e416386 | ||
|
|
9b4b31924b | ||
| 01ffb88358 | |||
|
|
5c9ea74c69 | ||
| 10f7551bbd | |||
| 229f578d69 | |||
|
|
df4cc6465c | ||
|
|
27a4fa71c4 |
@@ -1,15 +1,12 @@
|
||||
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.service.BookLendService;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
import com.example.demo.service.BookServiceImpl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -22,7 +19,7 @@ public class BookLendController {
|
||||
private final BookServiceImpl bookServiceImpl;
|
||||
|
||||
@Autowired
|
||||
private final BookLendService bookLendService;
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@PostMapping("/bookLend")
|
||||
public String bookLend(Model model) {
|
||||
@@ -31,22 +28,11 @@ 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,8 +1,11 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
@@ -11,7 +14,9 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.entity.AccountEntity;
|
||||
import com.example.demo.entity.Employee;
|
||||
import com.example.demo.form.LoginForm;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
import com.example.demo.service.LoginService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -21,12 +26,20 @@ import lombok.RequiredArgsConstructor;
|
||||
public class LoginController {
|
||||
|
||||
private final LoginService loginService;
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
|
||||
// Boot起動直後にログイン画面に移動する用のメソッド
|
||||
@GetMapping("/")
|
||||
public String index(HttpSession session) {
|
||||
public String index(Model model,HttpSession session) {
|
||||
if (session.getAttribute("loginEmployee") != null) {
|
||||
return "redirect:/topmenu";
|
||||
if(session.getAttribute("EmployeeId") != null) {
|
||||
|
||||
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
||||
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
||||
}
|
||||
return "topmenu";
|
||||
}
|
||||
return "redirect:/login";
|
||||
}
|
||||
@@ -34,7 +47,12 @@ public class LoginController {
|
||||
@GetMapping("/login")
|
||||
public String loginForm(Model model, HttpSession session) {
|
||||
if (session.getAttribute("loginEmployee") != null) {
|
||||
return "redirect:/topmenu";
|
||||
if(session.getAttribute("EmployeeId") != null) {
|
||||
|
||||
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
||||
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
||||
}
|
||||
return "topmenu";
|
||||
}
|
||||
|
||||
model.addAttribute("loginForm", new LoginForm());
|
||||
@@ -61,7 +79,13 @@ public class LoginController {
|
||||
}
|
||||
|
||||
session.setAttribute("loginEmployee", accountEntity);
|
||||
return "redirect:/topmenu";
|
||||
|
||||
List<Employee> emrp = employeeRepository.findByEmployeeId(accountEntity.getEmployee().getEmployeeId());
|
||||
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
||||
session.setAttribute("EmployeeId", accountEntity.getEmployee().getEmployeeId());
|
||||
|
||||
|
||||
return "topmenu";
|
||||
}
|
||||
|
||||
// ログアウト処理
|
||||
@@ -73,7 +97,13 @@ public class LoginController {
|
||||
|
||||
// 各画面からトップメニューへの遷移用
|
||||
@GetMapping("/topmenu")
|
||||
public String showTopMenu() {
|
||||
public String showTopMenu(Model model,HttpSession session) {
|
||||
|
||||
if(session.getAttribute("EmployeeId") != null) {
|
||||
|
||||
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
||||
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
||||
}
|
||||
return "topmenu";
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.example.demo.entity;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.sql.Date;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
@@ -35,11 +35,11 @@ public class BookLend {
|
||||
|
||||
// 貸出日
|
||||
@Column(name = "book_lend_date", nullable = false)
|
||||
private LocalDate bookLendDate;
|
||||
private Date bookLendDate;
|
||||
|
||||
// 返却日
|
||||
@Column(name = "book_return_date", nullable = false)
|
||||
private LocalDate bookReturnDate;
|
||||
private Date bookReturnDate;
|
||||
|
||||
// 貸出状態
|
||||
@Column(name = "book_status", nullable = false)
|
||||
|
||||
@@ -1,27 +1,7 @@
|
||||
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,17 +1,12 @@
|
||||
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 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 {
|
||||
@@ -19,37 +14,8 @@ public class BookLendService {
|
||||
@Autowired
|
||||
private BookLendRepository bookLendRepository;
|
||||
|
||||
@Autowired
|
||||
private BookRepository bookRepository;
|
||||
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
public List<BookLend> findAll() {
|
||||
return bookLendRepository.findAll();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr th:each="book : ${book}" th:if="${book.bookManageId != null}">
|
||||
<tr th:each="book : ${book}" th:if="${book.bookManageId != null && book.isDeleted != 1}">
|
||||
|
||||
<td th:hidden="*{book.bookId}"></td>
|
||||
<td th:text="*{book.bookManageId}"></td>
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
図書情報
|
||||
</h2>
|
||||
|
||||
<form th:action="@{/bookLend/confirm}" method="POST"
|
||||
id="lendForm">
|
||||
<form id="lendForm" action="bookLendConfirm" method="post">
|
||||
|
||||
<div class="card-body">
|
||||
<table class="info-table">
|
||||
@@ -35,8 +34,8 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<!-- <td th:hidden="*{book.bookId}"></td>-->
|
||||
<tr th:each="book : ${book}">
|
||||
<td th:hidden="*{book.bookId}"></td>
|
||||
<td th:text="*{book.bookManageId}"></td>
|
||||
<td th:text="*{book.title}"></td>
|
||||
<td th:text="*{book.author}"></td>
|
||||
@@ -60,7 +59,7 @@
|
||||
社員ID
|
||||
</label>
|
||||
|
||||
<input type="text" name="employeeId" placeholder="社員IDを入力してください">
|
||||
<input type="text" id="employeeId" placeholder="社員IDを入力してください">
|
||||
|
||||
</select>
|
||||
</div>
|
||||
@@ -113,10 +112,8 @@
|
||||
貸出処理を行うと、対象の図書のステータスが「貸出中」に変更されます。
|
||||
</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="入力内容をクリア">
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -17,7 +17,7 @@
|
||||
<div class="header-right">
|
||||
|
||||
<span class="user">
|
||||
テストユーザー(一般)
|
||||
<h1 th:text="${LoginName}"></h1>
|
||||
</span>
|
||||
|
||||
<a class="button-link" th:href="@{/logout}">
|
||||
@@ -61,6 +61,7 @@
|
||||
<hr>
|
||||
|
||||
<!-- ===== 管理者のみ ===== -->
|
||||
<th th:if="${session.loginEmployee.adminFlag == 1}">
|
||||
|
||||
<a class="card" href="/bookInsert">
|
||||
|
||||
@@ -71,6 +72,7 @@
|
||||
</p>
|
||||
</a>
|
||||
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
@@ -103,7 +105,12 @@
|
||||
初期パスワードを<br> 変更します。
|
||||
</p>
|
||||
</a>
|
||||
</th>
|
||||
|
||||
</body>
|
||||
|
||||
<script>
|
||||
var admin =getElementByID
|
||||
</script>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user