2段階_途中まで
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.rhizome.app.domain.service;
|
||||||
|
|
||||||
|
public interface DeleteDepartment {
|
||||||
|
void deleteDepartment(Integer idDepartment);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.example.rhizome.app.domain.service.impl;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import com.example.rhizome.app.domain.service.DeleteDepartment;
|
||||||
|
import com.example.rhizome.app.infra.repository.DepartmentRepository;
|
||||||
|
|
||||||
|
public class DeleteDepartmentImpl implements DeleteDepartment {
|
||||||
|
DepartmentRepository departmentRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DeleteDepartmentImpl(DepartmentRepository departmentRepository) {
|
||||||
|
this.departmentRepository = departmentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteDepartment(Integer idDepartment) {
|
||||||
|
// ★考える:Repository のどのメソッドで「IDを指定して削除」できる?
|
||||||
|
// (お手本の DeleteEmployeeImpl を見る)
|
||||||
|
departmentRepository.deleteById(idDepartment);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package com.example.rhizome.app.domain.service.impl;
|
package com.example.rhizome.app.domain.service.impl;
|
||||||
|
|
||||||
import com.example.rhizome.app.domain.service.DeleteEmployee;
|
|
||||||
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
|
||||||
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 org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.example.rhizome.app.domain.service.DeleteEmployee;
|
||||||
|
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Employee レコード削除関連の機能を持つサービス
|
* Employee レコード削除関連の機能を持つサービス
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package com.example.rhizome.app.presentation.controller;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import com.example.rhizome.app.domain.service.DeleteDepartment;
|
||||||
|
import com.example.rhizome.app.domain.service.SearchDepartment;
|
||||||
|
import com.example.rhizome.app.domain.service.SearchEmployee;
|
||||||
|
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
|
||||||
|
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
|
||||||
|
import com.example.rhizome.app.presentation.form.DepartmentForm;
|
||||||
|
import com.example.rhizome.app.presentation.form.SearchConditionDepartmentForm;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class DeleteDepartmentController {
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(DeleteDepartmentController.class.getName());
|
||||||
|
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||||
|
|
||||||
|
HttpSession httpSession;
|
||||||
|
DeleteDepartment deleteDepartment;
|
||||||
|
SearchDepartment searchDepartment;
|
||||||
|
SearchEmployee searchEmployee; // 所属社員の確認に使う(既存)
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
@Autowired
|
||||||
|
public DeleteDepartmentController(HttpSession httpSession, DeleteDepartment deleteDepartment,
|
||||||
|
SearchDepartment searchDepartment, SearchEmployee searchEmployee) {
|
||||||
|
this.httpSession = httpSession;
|
||||||
|
this.deleteDepartment = deleteDepartment;
|
||||||
|
this.searchDepartment = searchDepartment;
|
||||||
|
this.searchEmployee = searchEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = TransitionTargetPageNameKeyword.DELETE_DEPARTMENT, method = RequestMethod.POST)
|
||||||
|
public String deleteDepartment(@RequestParam(value = "idDepartment", required = false) Integer idDepartment, Model model) {
|
||||||
|
|
||||||
|
final String UNKNOWN_ID = "削除対象のIDが不明です。";
|
||||||
|
final String HAS_EMPLOYEE = "1名以上が所属している部署は削除出来ません。";
|
||||||
|
final String DELETE_COMPLETE = "削除しました。";
|
||||||
|
|
||||||
|
try {
|
||||||
|
// ★① idDepartment が null、または searchDepartment.searchBy(new SearchConditionDepartment(idDepartment, null)) が空
|
||||||
|
// → MESSAGE_ERROR に UNKNOWN_ID を載せて一覧へ
|
||||||
|
deleteDepartment.deleteDepartment(idDepartment);
|
||||||
|
// ★② searchEmployee.searchEmployeeByIdDepartment(idDepartment) が空でない
|
||||||
|
// → MESSAGE_ERROR に HAS_EMPLOYEE を載せて一覧へ
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,DepartmentForm.convertFrom(searchDepartment.selectAll()));
|
||||||
|
// ★③ deleteDepartment.deleteDepartment(idDepartment) → MESSAGE_INFO に DELETE_COMPLETE を載せて一覧へ
|
||||||
|
model.addAttribute("searchConditinDepartmentForm", new SearchConditionDepartmentForm());
|
||||||
|
|
||||||
|
// return "一覧へ戻る(ステップ 2-5 で決める)";
|
||||||
|
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
httpSession.invalidate();
|
||||||
|
e.printStackTrace();
|
||||||
|
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,"部署を削除できませんでした");
|
||||||
|
// return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||||
|
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.example.rhizome.app.presentation.controller;
|
package com.example.rhizome.app.presentation.controller;
|
||||||
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
//import java.util.List;
|
//import java.util.List;
|
||||||
@@ -28,69 +27,80 @@ import com.example.rhizome.app.presentation.form.SearchConditionDepartmentForm;
|
|||||||
@Controller
|
@Controller
|
||||||
public class SelectDepartmentController {
|
public class SelectDepartmentController {
|
||||||
|
|
||||||
// ログ出力用インスタンス
|
// ログ出力用インスタンス
|
||||||
private final static Logger LOGGER = Logger.getLogger(SelectDepartmentController.class.getName());
|
private final static Logger LOGGER = Logger.getLogger(SelectDepartmentController.class.getName());
|
||||||
// エラーメッセージ用の定数フィールド
|
// エラーメッセージ用の定数フィールド
|
||||||
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||||
|
|
||||||
// private static final String DEPARTMENT_HTML = "/department";
|
// public static final String SELECT_DEPARTMENT_FORM_EMPTY = "/selectDepartmentAll";
|
||||||
|
|
||||||
HttpSession httpSession;
|
|
||||||
SearchDepartment searchDepartment;
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
// private static final String DEPARTMENT_HTML = "/department";
|
||||||
public SelectDepartmentController (HttpSession httpSession, SearchDepartment serchDepartment) {
|
|
||||||
this.httpSession = httpSession;
|
|
||||||
this.searchDepartment = serchDepartment;
|
|
||||||
}
|
|
||||||
|
|
||||||
//空の検索条件FormをこのControllerの画面用に用意する
|
HttpSession httpSession;
|
||||||
@ModelAttribute
|
SearchDepartment searchDepartment;
|
||||||
public SearchConditionDepartmentForm searchConditionDepartmentForm() {
|
|
||||||
return new SearchConditionDepartmentForm();
|
@Autowired
|
||||||
}
|
public SelectDepartmentController(HttpSession httpSession, SearchDepartment serchDepartment) {
|
||||||
|
this.httpSession = httpSession;
|
||||||
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT, method = RequestMethod.POST)
|
this.searchDepartment = serchDepartment;
|
||||||
public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) {
|
}
|
||||||
try {
|
|
||||||
// ★考える:①検索サービスを呼ぶ(Form→Model変換 → 部分一致のメソッド)
|
//空の検索条件FormをこのControllerの画面用に用意する
|
||||||
// ②結果(List<Department>)を DepartmentForm.convertFrom(...) で画面用に変換
|
@ModelAttribute
|
||||||
// ③ model に PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST という名前で載せる
|
public SearchConditionDepartmentForm searchConditionDepartmentForm() {
|
||||||
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,DepartmentForm
|
return new SearchConditionDepartmentForm();
|
||||||
.convertFrom(searchDepartment.searchByWithLike(SearchConditionDepartmentForm
|
}
|
||||||
.convertTo(searchConditionDepartmentForm)
|
|
||||||
)
|
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT, method = RequestMethod.POST)
|
||||||
)
|
public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) {
|
||||||
);
|
try {
|
||||||
|
// ★考える:①検索サービスを呼ぶ(Form→Model変換 → 部分一致のメソッド)
|
||||||
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
|
// ②結果(List<Department>)を DepartmentForm.convertFrom(...) で画面用に変換
|
||||||
}catch(Exception e) {
|
// ③ model に PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST という名前で載せる
|
||||||
//httpSessionを破棄
|
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm
|
||||||
httpSession.invalidate();
|
.convertFrom(searchDepartment.searchByWithLike(SearchConditionDepartmentForm
|
||||||
|
.convertTo(searchConditionDepartmentForm))));
|
||||||
//エラー内容を出力
|
|
||||||
e.printStackTrace();
|
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
|
||||||
|
} catch (Exception e) {
|
||||||
//ログにエラーを記録
|
//httpSessionを破棄
|
||||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
httpSession.invalidate();
|
||||||
|
|
||||||
//エラー画面へ遷移
|
//エラー内容を出力
|
||||||
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
e.printStackTrace();
|
||||||
}
|
|
||||||
}
|
//ログにエラーを記録
|
||||||
|
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
||||||
|
|
||||||
|
//エラー画面へ遷移
|
||||||
|
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_FORM_EMPTY, method = RequestMethod.POST)
|
||||||
|
public String select(Model model) {
|
||||||
|
try {
|
||||||
|
// ★全件取得 → DepartmentForm に変換 → DEPARTMENT_FORM_LIST で model へ
|
||||||
|
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
|
||||||
|
} catch (Exception e) {
|
||||||
|
httpSession.invalidate();
|
||||||
|
e.printStackTrace();
|
||||||
|
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
||||||
|
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* 社員検索画面表示処理コントローラ
|
||||||
* 社員検索画面表示処理コントローラ
|
*
|
||||||
*
|
* @param searchConditionEmployeeForm 検索画面のフォーム
|
||||||
* @param searchConditionEmployeeForm 検索画面のフォーム
|
* @param model ビューにデータを渡すためのコンテナ
|
||||||
* @param model ビューにデータを渡すためのコンテナ
|
* @return 遷移先の画面
|
||||||
* @return 遷移先の画面
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
// @PermissionCheck
|
// @PermissionCheck
|
||||||
// @SessionCheck
|
// @SessionCheck
|
||||||
// @RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT,
|
// @RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT,
|
||||||
@@ -109,12 +119,9 @@ public class SelectDepartmentController {
|
|||||||
// SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm())
|
// SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm())
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * 社員検索画面表示処理コントローラ
|
// * 社員検索画面表示処理コントローラ
|
||||||
// * 検索条件無しの状態を作るため、空の検索条件で検索した結果を画面に返す
|
// * 検索条件無しの状態を作るため、空の検索条件で検索した結果を画面に返す
|
||||||
// *
|
// *
|
||||||
// * @param model ビューにデータを渡すためのコンテナ
|
// * @param model ビューにデータを渡すためのコンテナ
|
||||||
// * @return 遷移先の画面
|
// * @return 遷移先の画面
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ public class SelectEmployeeController {
|
|||||||
private final static Logger LOGGER = Logger.getLogger(SelectEmployeeController.class.getName());
|
private final static Logger LOGGER = Logger.getLogger(SelectEmployeeController.class.getName());
|
||||||
// エラーメッセージ用の定数フィールド
|
// エラーメッセージ用の定数フィールド
|
||||||
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||||
|
|
||||||
|
public static final String SELECT_DEPARTMENT_FORM_EMPTY = "/selectDepartmentAll";
|
||||||
|
|
||||||
HttpSession httpSession;
|
HttpSession httpSession;
|
||||||
SearchDepartment searchDepartment;
|
SearchDepartment searchDepartment;
|
||||||
|
|||||||
@@ -56,8 +56,14 @@ public class TransitionTargetPageNameKeyword {
|
|||||||
// Department
|
// Department
|
||||||
// HTML 実装手順書ステップ1-2通りの定数追加
|
// HTML 実装手順書ステップ1-2通りの定数追加
|
||||||
public static final String SELECT_DEPARTMENT_HTML = "selectDepartment";
|
public static final String SELECT_DEPARTMENT_HTML = "selectDepartment";
|
||||||
|
|
||||||
// Controller 実装手順書ステップ1-2通りの定数追加 -> 管理者向けと重複、エラーでたため一旦コメアウト
|
// Controller 実装手順書ステップ1-2通りの定数追加 -> 管理者向けと重複、エラーでたため一旦コメアウト
|
||||||
public static final String SELECT_DEPARTMENT = "/selectDepartment";
|
public static final String SELECT_DEPARTMENT = "/selectDepartment";
|
||||||
|
|
||||||
|
// ステップ2-3*TransitionTargetPageNameKeyword の Department(Controller) の枠に追記
|
||||||
|
public static final String DELETE_DEPARTMENT = "/deleteDepartment";
|
||||||
|
|
||||||
|
public static final String SELECT_DEPARTMENT_FORM_EMPTY = "/selectDepartmentAll";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 管理者向けのページリストを返す
|
* 管理者向けのページリストを返す
|
||||||
|
|||||||
@@ -1,4 +1,17 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
<!--<html> HTML文書の開始タグ-->
|
||||||
|
<!--<head> ページの設定情報を含む部分-->
|
||||||
|
<!--<title> ページのタイトルを指定するタグ-->
|
||||||
|
<!--<body> 実際に表示される内容を記述する部分-->
|
||||||
|
<!--<h1> 見出し最大サイズ・<p>段落の基本タグ-->
|
||||||
|
<!--<div> 汎用のブロック要素 複数の要素をまとめてレイアウトするためのコンテナ-->
|
||||||
|
<!--<table> 表全体を囲む-->
|
||||||
|
<!--<tr> 行全体を囲む-->
|
||||||
|
<!--<th> 行見出しセルを囲む-->
|
||||||
|
<!--<td> 行データセルを囲む-->
|
||||||
|
<!--<a href ="URL"> 飛び先のURLを指定"> -->
|
||||||
|
|
||||||
|
|
||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
||||||
|
|||||||
Reference in New Issue
Block a user