@@ -1,5 +1,6 @@
package com.example.demo.service ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
import java.util.Optional ;
@@ -9,8 +10,11 @@ import org.springframework.stereotype.Service;
import com.example.demo.entity.Book_collectionEntity ;
import com.example.demo.entity.Borrow_booksEntity ;
import com.example.demo.form.LendingForm ;
import com.example.demo.form.LoginInfoForm ;
import com.example.demo.form.ReturnForm ;
import com.example.demo.form.SearchConditionBookForm ;
import com.example.demo.model.LeadingListModel ;
import com.example.demo.repository.Book_CollectionRepository ;
import com.example.demo.repository.Borrow_BooksRepository ;
import com.example.demo.repository.EmployeeRepository ;
@@ -117,4 +121,79 @@ public class ReturnService {
noteText ) ;
}
public List < LeadingListModel > getBorrowList ( ) {
List < LeadingListModel > result = new ArrayList < LeadingListModel > ( ) ;
List < Borrow_booksEntity > borrow = borrowRepository . findByStatus ( '2' ) ;
for ( Borrow_booksEntity borrow_booksEntity : borrow ) {
String nmEmployee = employeeRepository . findById ( borrow_booksEntity . getIdApplicant ( ) ) . get ( ) . getNmEmployee ( ) ;
String nmBook = book_CollectionRepository . findById ( borrow_booksEntity . getIdBook ( ) ) . get ( ) . getNmBook ( ) ;
LeadingListModel a = new LeadingListModel ( borrow_booksEntity . getIdRequest ( ) ,
nmEmployee ,
nmBook ,
borrow_booksEntity . getDateRequest ( ) ,
borrow_booksEntity . getDateBorrow ( ) ,
borrow_booksEntity . getDateScheduledReturn ( ) ) ;
result . add ( a ) ;
}
return result ;
}
//書籍貸出申請機能
public void executeLending ( LendingForm form , int idEmployee ) {
var book_collection = book_CollectionRepository . findById ( form . getId_book ( ) ) ; //更新したい本のEntityを取得
book_collection . get ( ) . setFlgLending ( '1' ) ; //フラグだけ書き換え
book_CollectionRepository . save ( book_collection . get ( ) ) ;
Borrow_booksEntity borrow = new Borrow_booksEntity ( ) ; //空の申請レコード
borrow . setIdApproval ( idEmployee ) ; //申請者ID
borrow . setIdBook ( form . getId_book ( ) ) ; //蔵書ID
borrow . setDateRequest ( new Date ( ) ) ; //申請日
borrow . setStatus ( '1' ) ; //ステータスを承認待ちに
borrow . setIdUpdate ( idEmployee ) ; //更新者ID
borrow . setDateUpdate ( new Date ( ) ) ; //更新日
borrowRepository . save ( borrow ) ;
}
//貸出テーブルの「ステータス」が「1:承認待」の情報を全件取得
public List < LeadingListModel > getAwaitingApprovalList ( ) {
List < LeadingListModel > result = new ArrayList < LeadingListModel > ( ) ;
List < Borrow_booksEntity > borrow = borrowRepository . findByStatus ( '1' ) ;
for ( Borrow_booksEntity borrow_booksEntity : borrow ) {
String nmEmployee = employeeRepository . findById ( borrow_booksEntity . getIdApplicant ( ) ) . get ( ) . getNmEmployee ( ) ;
String nmBook = book_CollectionRepository . findById ( borrow_booksEntity . getIdBook ( ) ) . get ( ) . getNmBook ( ) ;
LeadingListModel a = new LeadingListModel ( borrow_booksEntity . getIdRequest ( ) ,
nmEmployee ,
nmBook ,
borrow_booksEntity . getDateRequest ( ) ,
borrow_booksEntity . getDateBorrow ( ) ,
borrow_booksEntity . getDateScheduledReturn ( ) ) ;
result . add ( a ) ;
}
return result ;
}
//メアドとパスワードが合っていればtureで返す
public boolean canlogin ( String mail , String pass ) {
if ( mail = = null | | mail . isEmpty ( ) | | pass = = null | | pass . isEmpty ( ) ) {
return false ;
}
return employeeRepository . findByMailAddressAndPassword ( mail , pass ) . isPresent ( ) ;
}
//LoginInfoFormの情報からidEmployeeを返す
public int getUserID ( LoginInfoForm form ) {
return employeeRepository . findByMailAddressAndPassword ( form . getMailAddress ( ) , form . getPassword ( ) ) . get ( )
. getIdEmployee ( ) ;
}
//LoginInfoFormの情報からFlgを返す 0なら一般,1なら管理
public Character getUserFlg ( LoginInfoForm form ) {
return employeeRepository . findByMailAddressAndPassword ( form . getMailAddress ( ) , form . getPassword ( ) ) . get ( )
. getFlgAdmin ( ) ;
}
}