途中
This commit is contained in:
@@ -5,23 +5,25 @@ import java.util.logging.Logger;
|
|||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
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.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
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 org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
import com.example.demo.common.BusinessException;
|
import com.example.demo.common.BusinessException;
|
||||||
|
import com.example.demo.common.Const;
|
||||||
import com.example.demo.common.LoginUser;
|
import com.example.demo.common.LoginUser;
|
||||||
|
import com.example.demo.dto.BorrowView;
|
||||||
import com.example.demo.form.RentalForm;
|
import com.example.demo.form.RentalForm;
|
||||||
import com.example.demo.service.LoanService;
|
import com.example.demo.service.LoanService;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class AdminLoanController {
|
public class AdminLoanController {
|
||||||
|
|
||||||
// ログ出力用インスタンス
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(AdminLoanController.class.getName());
|
private final static Logger LOGGER = Logger.getLogger(AdminLoanController.class.getName());
|
||||||
|
|
||||||
// エラーメッセージ用の定数フィールド
|
|
||||||
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||||
|
|
||||||
private final LoanService loanService;
|
private final LoanService loanService;
|
||||||
@@ -31,11 +33,52 @@ public class AdminLoanController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/admin/applications/{id}")
|
||||||
|
public String showApprovalConfirm(@PathVariable("id") Integer idRequest, HttpSession session, Model model) {
|
||||||
|
|
||||||
|
// セッションからログイン情報のチェック
|
||||||
|
LoginUser loginUser = (LoginUser) session.getAttribute("LOGIN_USER");
|
||||||
|
if (loginUser == null) {
|
||||||
|
return "redirect:/login";
|
||||||
|
}
|
||||||
|
|
||||||
|
// エラーによる差し戻し(Form)がModel内に存在する場合は、二重に作成しない
|
||||||
|
if (!model.containsAttribute("approvalConfilm")) {
|
||||||
|
try {
|
||||||
|
// LoanServiceから現在の承認待ち状態のデータを取得
|
||||||
|
BorrowView view = loanService.getView(idRequest, Const.STATUS_WAITING);
|
||||||
|
|
||||||
|
// 取得したデータを画面用の RentalForm(approvalConfilm)に詰め替える
|
||||||
|
RentalForm form = new RentalForm();
|
||||||
|
form.setIdRequest(view.getIdRequest());
|
||||||
|
form.setNmEmployee(view.getNmApplicant());
|
||||||
|
form.setDateRequest(view.getDateRequest() != null ? view.getDateRequest().toString() : "");
|
||||||
|
form.setIsbn(view.getIsbn());
|
||||||
|
form.setNmBook(view.getNmBook());
|
||||||
|
form.setPublisher(view.getPublisher());
|
||||||
|
form.setNote(view.getNote() != null ? view.getNote() : "");
|
||||||
|
form.setDateBorrow(view.getDateBorrow() != null ? view.getDateBorrow().toString() : "");
|
||||||
|
form.setDateScheduledReturn(
|
||||||
|
view.getDateScheduledReturn() != null ? view.getDateScheduledReturn().toString() : "");
|
||||||
|
|
||||||
|
// 画面オブジェクトをモデルに設定
|
||||||
|
model.addAttribute("approvalConfilm", form);
|
||||||
|
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
// 対象データがない、または既に別の人に処理されていた場合は、一覧画面にメッセージ付きで戻す
|
||||||
|
model.addAttribute("errorMessage", e.getMessage());
|
||||||
|
return "redirect:/applicationList";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 書籍貸出承認確認画面(HTMLファイル名)を呼び出す
|
||||||
|
return "admin/approvalConfirm";
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/submit")
|
@PostMapping("/submit")
|
||||||
public String executeApproval(
|
public String executeApproval(
|
||||||
@ModelAttribute("approvalConfilm") RentalForm form,
|
@ModelAttribute("approvalConfilm") RentalForm form,
|
||||||
@RequestParam("action")
|
@RequestParam("action") String action,
|
||||||
String action,
|
|
||||||
HttpSession session,
|
HttpSession session,
|
||||||
RedirectAttributes redirectAttributes) {
|
RedirectAttributes redirectAttributes) {
|
||||||
|
|
||||||
@@ -46,13 +89,12 @@ public class AdminLoanController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// アクション(ボタンのvalue属性)に応じたサービス処理の実行
|
||||||
if ("approve".equals(action)) {
|
if ("approve".equals(action)) {
|
||||||
// 確定したLoanServiceのインスタンスメソッド呼び出し
|
|
||||||
loanService.approve(form.getIdRequest(), loginUser);
|
loanService.approve(form.getIdRequest(), loginUser);
|
||||||
redirectAttributes.addFlashAttribute("successMessage", "申請を承認しました。");
|
redirectAttributes.addFlashAttribute("successMessage", "申請を承認しました。");
|
||||||
|
|
||||||
} else if ("reject".equals(action)) {
|
} else if ("reject".equals(action)) {
|
||||||
// 確定したLoanServiceのインスタンスメソッドを呼び出し、IDにはidRequestを渡す
|
|
||||||
loanService.reject(form.getIdRequest(), loginUser);
|
loanService.reject(form.getIdRequest(), loginUser);
|
||||||
redirectAttributes.addFlashAttribute("successMessage", "申請を却下しました。");
|
redirectAttributes.addFlashAttribute("successMessage", "申請を却下しました。");
|
||||||
|
|
||||||
@@ -62,7 +104,11 @@ public class AdminLoanController {
|
|||||||
|
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
redirectAttributes.addFlashAttribute("errorMessage", e.getMessage());
|
redirectAttributes.addFlashAttribute("errorMessage", e.getMessage());
|
||||||
return "redirect:/admin/rental/detail/" + form.getIdRequest();
|
|
||||||
|
// エラーが起きた入力データをそのまま保持して詳細(確認)画面に戻す
|
||||||
|
redirectAttributes.addFlashAttribute("approvalConfilm", form);
|
||||||
|
|
||||||
|
return "redirect:/admin/applications/" + form.getIdRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
return "redirect:/applicationList";
|
return "redirect:/applicationList";
|
||||||
|
|||||||
Reference in New Issue
Block a user