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