Merge branch 'y-kumaki' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/ShareBooks_new into h-seya
# Conflicts: # src/main/java/com/example/demo/repository/BookLendRepository.java # src/main/java/com/example/demo/service/BookLendService.java
This commit is contained in:
@@ -1,13 +1,30 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
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.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import com.example.demo.entity.Employee;
|
||||||
|
import com.example.demo.repository.EmployeeRepository;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class BookLendController {
|
public class BookLendController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
@PostMapping("/bookLend")
|
@PostMapping("/bookLend")
|
||||||
public String bookLend() {
|
public String bookLend(Model model) {
|
||||||
return "bookLend";
|
return "bookLend";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 社員IDを取得してプルダウンに表示させる
|
||||||
|
@PostMapping("/bookLend/employeeId")
|
||||||
|
public String selectEmployeeId(Employee employee, Model model) {
|
||||||
|
model.addAttribute("employeeList", employeeRepository.findByEmployeeId(employee.getEmployeeId()));
|
||||||
|
model.addAttribute("bookLend", employee);
|
||||||
|
return "bookLend";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,30 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import com.example.demo.entity.BookLend;
|
||||||
|
import com.example.demo.service.BookLendService;
|
||||||
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class LendListController {
|
public class LendListController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BookLendService lendlistService;
|
||||||
|
|
||||||
@GetMapping("/lendList")
|
@GetMapping("/lendList")
|
||||||
public String lendList() {
|
public String list(Model model) {
|
||||||
|
|
||||||
|
List<BookLend> aaa = lendlistService.findAll();
|
||||||
|
|
||||||
|
// findAllを使って、DBから一覧を取得 でバックで取得したのを確認
|
||||||
|
model.addAttribute("list",lendlistService.findAll());
|
||||||
|
|
||||||
return "lendList";
|
return "lendList";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class Book {
|
|||||||
private int bookId;
|
private int bookId;
|
||||||
|
|
||||||
// 図書管理ID(BK-1など)
|
// 図書管理ID(BK-1など)
|
||||||
@Column(name = "book_manage_id", nullable = true)
|
@Column(name = "book_manage_id", nullable = true, unique = true)
|
||||||
private String bookManageId;
|
private String bookManageId;
|
||||||
|
|
||||||
// タイトル
|
// タイトル
|
||||||
@@ -78,7 +78,7 @@ public class Book {
|
|||||||
|
|
||||||
// 寄贈者社員ID??
|
// 寄贈者社員ID??
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "donor_id", nullable = false)
|
@JoinColumn(name = "donor_id", nullable = true)
|
||||||
private Employee employee;
|
private Employee employee;
|
||||||
|
|
||||||
//備考
|
//備考
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import jakarta.persistence.GeneratedValue;
|
|||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.OneToOne;
|
import jakarta.persistence.OneToOne;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@@ -28,9 +29,9 @@ public class BookLend {
|
|||||||
@JoinColumn(name = "book_manage_id", referencedColumnName = "book_manage_id",nullable = false)
|
@JoinColumn(name = "book_manage_id", referencedColumnName = "book_manage_id",nullable = false)
|
||||||
private Book book;
|
private Book book;
|
||||||
|
|
||||||
// 図書管理ID(BK-1など)
|
@ManyToOne
|
||||||
@Column(name = "employee_id", nullable = false)
|
@JoinColumn(name = "employee_id", nullable = false)
|
||||||
private Integer employeeId;
|
private Employee employeeBooklend;
|
||||||
|
|
||||||
// 貸出日
|
// 貸出日
|
||||||
@Column(name = "book_lend_date", nullable = false)
|
@Column(name = "book_lend_date", nullable = false)
|
||||||
|
|||||||
@@ -34,4 +34,7 @@ public class Employee {
|
|||||||
@OneToMany(mappedBy = "employee")
|
@OneToMany(mappedBy = "employee")
|
||||||
private List<Book> employees = new ArrayList<>();
|
private List<Book> employees = new ArrayList<>();
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "employeeBooklend")
|
||||||
|
private List<BookLend> employeesBooklend = new ArrayList<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package com.example.demo.repository;
|
package com.example.demo.repository;
|
||||||
|
|
||||||
// 図書の貸出処理に使用予定
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
public interface BookLendRepository {
|
import com.example.demo.entity.BookLend;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface BookLendRepository extends JpaRepository<BookLend, Integer> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.example.demo.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import com.example.demo.entity.Employee;
|
||||||
|
|
||||||
|
public interface EmployeeRepository extends JpaRepository<Employee, Integer>{
|
||||||
|
|
||||||
|
List<Employee> findByEmployeeId(Integer employeeId);
|
||||||
|
}
|
||||||
@@ -1,7 +1,21 @@
|
|||||||
package com.example.demo.service;
|
package com.example.demo.service;
|
||||||
|
|
||||||
// 図書の貸出処理に使用予定
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.entity.BookLend;
|
||||||
|
import com.example.demo.repository.BookLendRepository;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class BookLendService {
|
public class BookLendService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BookLendRepository bookLendRepository;
|
||||||
|
|
||||||
|
public List<BookLend> findAll() {
|
||||||
|
return bookLendRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,201 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>図書貸出処理</title>
|
<title>図書貸出処理</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<h1>
|
||||||
図書貸出処理
|
図書貸出処理
|
||||||
<form id="loanForm"action="bookLendConfirmation" method="post">
|
</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
以下の図書を貸出します。貸出先と貸出日・返却予定日を入力してください。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
図書情報
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="info-table">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
図書管理ID
|
||||||
|
</th>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
(図書管理IDをここに表示させる)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
図書タイトル
|
||||||
|
</th>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
(タイトルをここに表示させる)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
著者名
|
||||||
|
</th>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
(著者名をここに表示させる)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
ISBN
|
||||||
|
</th>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
(ISBNをここに表示させる)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
社員情報
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
|
||||||
|
<label for="employeeSelect">
|
||||||
|
社員ID
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<!-- <select th:field="*{employeeId}" onchange="this.form.action='/bookLend/employeeId';this.form.submit();">-->
|
||||||
|
|
||||||
|
<option value="">
|
||||||
|
社員IDを選択してください
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option th:each="employee : ${employeeList}" th:value="${employee.employeeId}">
|
||||||
|
</option>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="employeeName">
|
||||||
|
社員名
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input type="text" id="employeeName" value="" placeholder="社員名が表示されます" readonly>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>
|
||||||
|
貸出・返却日入力
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="date-section">
|
||||||
|
|
||||||
|
<div class="date-box">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
貸出日(自動取得)
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input type="date" id="loanDate" name="loanDate" value="">
|
||||||
|
|
||||||
|
<div class="note">
|
||||||
|
※ 現在の日付が自動で設定されます。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="date-box">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
貸出期間日数
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input type="text" id="loanDays" placeholder="日数を入力してください">
|
||||||
|
|
||||||
|
<div class="note">
|
||||||
|
※ 数値(1以上)で入力してください。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="date-box">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
返却予定日(必須)
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input type="date" id="returnDate" name="returnDate">
|
||||||
|
|
||||||
|
<div class="note">
|
||||||
|
※ カレンダーから日付を選択してください。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="error">
|
||||||
|
※ 現在の日付より前は選択できません。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="warning-area">
|
||||||
|
|
||||||
|
<strong>
|
||||||
|
注意事項
|
||||||
|
</strong>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
貸出処理を行うと、対象の図書のステータスが「貸出中」に変更されます。
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
返却予定日を必ず指定してください。
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="lendForm" action="bookLendConfirmation" method="post">
|
||||||
<div class="button-area">
|
<div class="button-area">
|
||||||
|
|
||||||
<div class="right-buttons">
|
<div class="right-buttons">
|
||||||
<button type="button" class="btn btn-primary"
|
<button type="button" class="btn btn-primary" onclick="submitLend()">
|
||||||
onclick="submitLoan()">貸出する</button>
|
貸出する
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function submitLoan() {
|
function submitLend() {
|
||||||
|
|
||||||
if (confirm('この図書を貸出しますか?')) {
|
if (confirm('この図書を貸出しますか?')) {
|
||||||
// OK選択時にフォーム送信を実行し、BookLendReturnControllerに処理を投げる
|
// OK選択時にフォーム送信を実行し、BookLendReturnControllerに処理を投げる
|
||||||
document.getElementById('loanForm').submit();
|
document.getElementById('loanForm').submit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>貸出中図書一覧</title>
|
<title>貸出中図書一覧</title>
|
||||||
|
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@@ -12,6 +13,36 @@
|
|||||||
<!-- action先要修正 -->
|
<!-- action先要修正 -->
|
||||||
<form action="/lendList" method="GET">
|
<form action="/lendList" method="GET">
|
||||||
<input type="submit" value="返却" class="btn">
|
<input type="submit" value="返却" class="btn">
|
||||||
|
|
||||||
|
|
||||||
|
<table>
|
||||||
|
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>社員ID</th>
|
||||||
|
<th>社員名</th>
|
||||||
|
<th>管理ID</th>
|
||||||
|
<th>タイトル</th>
|
||||||
|
<th>返却予定日</th>
|
||||||
|
<th>超過日数</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<tr th:each="booklist : ${list}">
|
||||||
|
|
||||||
|
<td th:text="*{booklist.employeeBooklend.employeeId}"></td>
|
||||||
|
<td th:text="*{booklist.employeeBooklend.employeeName}"></td>
|
||||||
|
<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>-->
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- 以下ポップアップ -->
|
<!-- 以下ポップアップ -->
|
||||||
|
|||||||
Reference in New Issue
Block a user