From 4c134b81b83db2a2d91907af0eda569eff50790a Mon Sep 17 00:00:00 2001 From: s-sakiyama <26-m-s-stella-tecnica@it-college.jp> Date: Tue, 13 Oct 2026 10:23:24 +0900 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AE=B5=E9=9A=8E=E7=9B=AE?= =?UTF-8?q?=E3=80=80=E9=83=A8=E7=BD=B2=E6=A4=9C=E7=B4=A2=E6=A9=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SelectDepartmentController.java | 123 ++++++++++++++ .../PageReturnAttributeKeyword.java | 16 +- .../TransitionTargetPageNameKeyword.java | 153 +++++++++--------- .../form/SearchConditionDepartmentForm.java | 51 ++++++ src/main/resources/templates/menu.html | 12 +- .../resources/templates/selectDepartment.html | 117 ++++++++++++++ 6 files changed, 391 insertions(+), 81 deletions(-) create mode 100644 src/main/java/com/example/rhizome/app/presentation/controller/SelectDepartmentController.java create mode 100644 src/main/java/com/example/rhizome/app/presentation/form/SearchConditionDepartmentForm.java create mode 100644 src/main/resources/templates/selectDepartment.html diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/SelectDepartmentController.java b/src/main/java/com/example/rhizome/app/presentation/controller/SelectDepartmentController.java new file mode 100644 index 0000000..1beabbd --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/controller/SelectDepartmentController.java @@ -0,0 +1,123 @@ +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.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import com.example.rhizome.aop.aspect.PermissionCheck; +import com.example.rhizome.aop.aspect.SessionCheck; +import com.example.rhizome.app.domain.service.SearchDepartment; +import com.example.rhizome.app.domain.service.SearchEmployeeInfo; +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 SelectDepartmentController { + + // ログ出力用インスタンス + private final static Logger LOGGER = Logger.getLogger(SelectDepartmentController.class.getName()); + // エラーメッセージ用の定数フィールド + private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; + + HttpSession httpSession; + SearchDepartment searchDepartment; + SearchEmployeeInfo searchEmployeeInfo; + + @Autowired + public SelectDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment, + SearchEmployeeInfo searchEmployeeInfo) { + this.httpSession = httpSession; + this.searchDepartment = searchDepartment; + this.searchEmployeeInfo = searchEmployeeInfo; + } + + @ModelAttribute + public SearchConditionDepartmentForm searchConditionDepartmentForm() { + return new SearchConditionDepartmentForm(); + } + + /** + * 社員検索画面表示処理コントローラ + * + * @param searchConditionEmployeeForm 検索画面のフォーム + * @param model ビューにデータを渡すためのコンテナ + * @return 遷移先の画面 + */ + @PermissionCheck + @SessionCheck + @RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO, method = RequestMethod.POST) + public String select(SearchConditionDepartmentForm searchConditionDepartmentForm, Model model) { + try { + + // 部署一覧を取得し、画面に返す用のクラスに詰め替える + // 作成した部署一覧をセット + model.addAttribute( + PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, + DepartmentForm.convertFrom(searchDepartment.selectAll())); + + // 検索条件を元に検索を実施 + //取得した EmployeeInfo( employee + department )の情報を画面に返す用の型に詰め替えてセット + // model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, EmployeeInfoForm.convertFrom( + // searchEmployeeInfo.searchBy(SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm))); + model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom( + searchDepartment + .searchByWithLike(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm)))); + + // 検索ページに遷移 + 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 model ビューにデータを渡すためのコンテナ + * @return 遷移先の画面 + */ + @PermissionCheck + @SessionCheck + @RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY, method = RequestMethod.POST) + public String select(Model model) { + + // 部署一覧を取得し、画面に返す用のクラスに詰め替える + // 作成した部署一覧をセット + model.addAttribute( + PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, + DepartmentForm.convertFrom(searchDepartment.selectAll())); + + // 検索条件を元に検索を実施 + // model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, + // EmployeeInfoForm.convertFrom( + // searchEmployeeInfo.searchBy( + // SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm())))); + + // 検索ページに遷移 + return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; + } + +} diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java index 5e9ec04..4971aeb 100644 --- a/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java +++ b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java @@ -5,14 +5,14 @@ package com.example.rhizome.app.presentation.controller.pageproperty; */ public class PageReturnAttributeKeyword { - public static final String MESSAGE_ERROR = "messageError"; - public static final String MESSAGE_INFO = "messageInfo"; + public static final String MESSAGE_ERROR = "messageError"; + public static final String MESSAGE_INFO = "messageInfo"; - public static final String DEPARTMENT_FORM_LIST = "departmentFormList"; - public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm"; - public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm"; - public static final String LOGIN_INFO_FORM = "loginInfoForm"; - public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm"; - public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList"; + public static final String DEPARTMENT_FORM_LIST = "departmentFormList"; + public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm"; + public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm"; + public static final String LOGIN_INFO_FORM = "loginInfoForm"; + public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm"; + public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList"; } diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/TransitionTargetPageNameKeyword.java b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/TransitionTargetPageNameKeyword.java index 90ded96..a8bfb5d 100644 --- a/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/TransitionTargetPageNameKeyword.java +++ b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/TransitionTargetPageNameKeyword.java @@ -7,87 +7,96 @@ import java.util.Set; */ public class TransitionTargetPageNameKeyword { - // 共通 - public static final String LOGIN_HTML = "login"; + // 共通 + public static final String LOGIN_HTML = "login"; - // 一般向け - public static final String UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML = "updatePersonalEmployeeInput"; - public static final String UPDATE_PERSONAL_RESULT_HTML = "updatePersonalEmployeeResult"; + // 一般向け + public static final String UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML = "updatePersonalEmployeeInput"; + public static final String UPDATE_PERSONAL_RESULT_HTML = "updatePersonalEmployeeResult"; - // 管理者向け - public static final String MENU_HTML = "menu"; - public static final String SELECT_EMPLOYEE_HTML = "selectEmployee"; - public static final String INSERT_EMPLOYEE_INPUT_HTML = "insertEmployeeInput"; - public static final String INSERT_EMPLOYEE_CONFIRM_HTML = "insertEmployeeConfirm"; - public static final String INSERT_EMPLOYEE_RESULT_HTML = "insertEmployeeResult"; - public static final String UPDATE_EMPLOYEE_INPUT_HTML = "updateEmployeeInput"; + // 管理者向け + public static final String MENU_HTML = "menu"; + public static final String SELECT_EMPLOYEE_HTML = "selectEmployee"; + public static final String INSERT_EMPLOYEE_INPUT_HTML = "insertEmployeeInput"; + public static final String INSERT_EMPLOYEE_CONFIRM_HTML = "insertEmployeeConfirm"; + public static final String INSERT_EMPLOYEE_RESULT_HTML = "insertEmployeeResult"; + public static final String UPDATE_EMPLOYEE_INPUT_HTML = "updateEmployeeInput"; - public static final String ERROR_HTML = "error"; + public static final String ERROR_HTML = "error"; - // 共通(Controller) - public static final String INDEX_BLANK = ""; - public static final String INDEX_SLASH = "/"; - public static final String INDEX_LOGIN = "/login"; - public static final String LOGOUT = "/logout"; - public static final String DO_LOGIN = "/doLogin"; + // 共通(Controller) + public static final String INDEX_BLANK = ""; + public static final String INDEX_SLASH = "/"; + public static final String INDEX_LOGIN = "/login"; + public static final String LOGOUT = "/logout"; + public static final String DO_LOGIN = "/doLogin"; - // 一般向け(Controller) - public static final String PERSONAL_UPDATE_RESULT = "/updatePersonalEmployeeResult"; + // 一般向け(Controller) + public static final String PERSONAL_UPDATE_RESULT = "/updatePersonalEmployeeResult"; - // 管理者向け(Controller) - public static final String DELETE_EMPLOYEE = "/deleteEmployee"; - public static final String INSERT_EMPLOYEE_INPUT = "/insertEmployeeInput"; - public static final String INSERT_EMPLOYEE_CONFIRM = "/insertEmployeeConfirm"; - public static final String INSERT_EMPLOYEE = "/insertEmployee"; - public static final String SHOW_MENU = "/showMenu"; - public static final String SELECT_EMPLOYEE_INFO = "/selectEmployeeInfo"; - public static final String SELECT_EMPLOYEE_INFO_FORM_EMPTY = "/selectAll"; - public static final String SHOW_UPDATE_EMPLOYEE = "/showUpdateEmployee"; - public static final String UPDATE_EMPLOYEE_RESULT = "/updateEmployeeResult"; + // 管理者向け(Controller) + public static final String DELETE_EMPLOYEE = "/deleteEmployee"; + public static final String INSERT_EMPLOYEE_INPUT = "/insertEmployeeInput"; + public static final String INSERT_EMPLOYEE_CONFIRM = "/insertEmployeeConfirm"; + public static final String INSERT_EMPLOYEE = "/insertEmployee"; + public static final String SHOW_MENU = "/showMenu"; + public static final String SELECT_EMPLOYEE_INFO = "/selectEmployeeInfo"; + public static final String SELECT_EMPLOYEE_INFO_FORM_EMPTY = "/selectAll"; + public static final String SHOW_UPDATE_EMPLOYEE = "/showUpdateEmployee"; + public static final String UPDATE_EMPLOYEE_RESULT = "/updateEmployeeResult"; - // Department - // HTML - // Controller + // Department + // HTML + public static final String SELECT_DEPARTMENT_HTML = "selectDepartment"; + // Controller + public static final String SELECT_DEPARTMENT_INFO = "/selectDepartmentInfo"; + public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY = "/departmentAll"; + public static final String DELETE_DEPARTMENT = "a"; + public static final String INSERT_DEPARTMENT_INPUT = "i"; + public static final String INSERT_DEPARTMENT_CONFIRM = "u"; + public static final String INSERT_DEPARTMENT = "e"; + public static final String SHOW_UPDATE_DAPERTMENT = "o"; + public static final String UPDATE_DEPARTMENT_RESULT = "k"; - /** - * 管理者向けのページリストを返す - * - * @return 管理者向けのページリスト - */ - public static Set getAdminPageList() { + /** + * 管理者向けのページリストを返す + * + * @return 管理者向けのページリスト + */ + public static Set getAdminPageList() { - return Set.of( - INDEX_BLANK, - INDEX_SLASH, - INDEX_LOGIN, - LOGOUT, - DO_LOGIN, - DELETE_EMPLOYEE, - INSERT_EMPLOYEE_INPUT, - INSERT_EMPLOYEE_CONFIRM, - INSERT_EMPLOYEE, - SHOW_MENU, - SELECT_EMPLOYEE_INFO, - SELECT_EMPLOYEE_INFO_FORM_EMPTY, - SHOW_UPDATE_EMPLOYEE, - UPDATE_EMPLOYEE_RESULT - ); - } + return Set.of( + INDEX_BLANK, + INDEX_SLASH, + INDEX_LOGIN, + LOGOUT, + DO_LOGIN, + DELETE_EMPLOYEE, + INSERT_EMPLOYEE_INPUT, + INSERT_EMPLOYEE_CONFIRM, + INSERT_EMPLOYEE, + SHOW_MENU, + SELECT_EMPLOYEE_INFO, + SELECT_EMPLOYEE_INFO_FORM_EMPTY, + SHOW_UPDATE_EMPLOYEE, + UPDATE_EMPLOYEE_RESULT, + SELECT_DEPARTMENT_INFO, + SELECT_DEPARTMENT_INFO_FORM_EMPTY); + } - /** - * 一般向けのページリストを返す - * - * @return 一般向けのページリスト - */ - public static Set getUserPageList() { - return Set.of( - INDEX_BLANK, - INDEX_SLASH, - INDEX_LOGIN, - LOGOUT, - DO_LOGIN, - PERSONAL_UPDATE_RESULT - ); - } + /** + * 一般向けのページリストを返す + * + * @return 一般向けのページリスト + */ + public static Set getUserPageList() { + return Set.of( + INDEX_BLANK, + INDEX_SLASH, + INDEX_LOGIN, + LOGOUT, + DO_LOGIN, + PERSONAL_UPDATE_RESULT); + } } diff --git a/src/main/java/com/example/rhizome/app/presentation/form/SearchConditionDepartmentForm.java b/src/main/java/com/example/rhizome/app/presentation/form/SearchConditionDepartmentForm.java new file mode 100644 index 0000000..1969c42 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/form/SearchConditionDepartmentForm.java @@ -0,0 +1,51 @@ +package com.example.rhizome.app.presentation.form; + +import com.example.rhizome.app.domain.model.SearchConditionDepartment; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 画面から渡ってきた検索条件をまとめ、再度画面に表示する為のクラス + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class SearchConditionDepartmentForm { + + /** + * 部署ID + */ + private Integer idDepartment; + /** + * 部署名 + */ + private String nmDepartment; + + /** + * business 層の SearchConditionEmployee クラスから画面用(presentation 層)の SearchConditionEmployeeForm に + * 変換します。 + * + * @param searchConditionEmployee business 層の SearchConditionEmployee インスタンス + * @return 画面用(presentation 層)の SearchConditionEmployeeForm インスタンス + */ + public static SearchConditionDepartmentForm convertFrom(SearchConditionDepartment searchConditionDepartment) { + return new SearchConditionDepartmentForm( + searchConditionDepartment.getIdDepartment(), + searchConditionDepartment.getNmDepartment()); + } + + /** + * 画面用(presentation 層)の SearchConditionEmployeeForm クラスから business 層の SearchConditionEmployee クラスに + * 変換します。 + * + * @param searchConditionEmployeeForm 画面用(presentation 層)の SearchConditionEmployeeForm インスタンス + * @return business 層の SearchConditionEmployee インスタンス + */ + public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) { + return new SearchConditionDepartment( + searchConditionDepartmentForm.getIdDepartment(), + searchConditionDepartmentForm.getNmDepartment()); + } +} diff --git a/src/main/resources/templates/menu.html b/src/main/resources/templates/menu.html index 6d0ee4a..bc0ef14 100644 --- a/src/main/resources/templates/menu.html +++ b/src/main/resources/templates/menu.html @@ -32,6 +32,16 @@ 社員登録 新規でユーザ追加を行います。 + + 部署検索 + + 登録済みの部署一覧表示と
更新、削除を行います。 + + + + 部署登録 + 新規で部署追加を行います。 + @@ -59,7 +69,7 @@ function selectDepartmentSubmit() { const form = document.createElement('form'); form.setAttribute('method', 'post'); - form.setAttribute('action', 'selectDepartment'); + form.setAttribute('action', 'selectDepartmentInfo'); // 動的送信用のHidden // 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない diff --git a/src/main/resources/templates/selectDepartment.html b/src/main/resources/templates/selectDepartment.html new file mode 100644 index 0000000..0792ebe --- /dev/null +++ b/src/main/resources/templates/selectDepartment.html @@ -0,0 +1,117 @@ + + + + + + + + + + + + 検索 + + + +

+ 検索条件入力    +
+ ログイン者名: + +
+

+
+ +
+ +
+ + + + + + + + + + + + + + +
部署ID + +
部署名 + +
+ + + +
+
+
+メニューに戻る +
+

検索結果

+
+ + + +
+ + + + + + + + + + + + + + + + + + +
部署ID部署名操作
+ +
+ + +
+ +
+ + +
+
+
+ + + 検索結果はありません。 + + + + + \ No newline at end of file