From 2507dec2202249714045bf0ce7e5976c4eaae3fa Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 10 Sep 2026 16:06:16 +0900 Subject: [PATCH] =?UTF-8?q?[ADD]=20=E9=83=A8=E7=BD=B2=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InsertDepartmentConfirmController.java | 66 ++++++++++ .../InsertDepartmentController.java | 120 ++++++++++++++++++ .../InsertDepartmentInputController.java | 64 ++++++++++ .../form/InsertDepartmentForm.java | 46 +++++++ .../templates/insertDepartmentConfirm.html | 86 +++++++++++++ .../templates/insertDepartmentInput.html | 67 ++++++++++ .../templates/insertDepartmentResult.html | 35 +++++ 7 files changed, 484 insertions(+) create mode 100644 src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentConfirmController.java create mode 100644 src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentController.java create mode 100644 src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentInputController.java create mode 100644 src/main/java/com/example/rhizome/app/presentation/form/InsertDepartmentForm.java create mode 100644 src/main/resources/templates/insertDepartmentConfirm.html create mode 100644 src/main/resources/templates/insertDepartmentInput.html create mode 100644 src/main/resources/templates/insertDepartmentResult.html diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentConfirmController.java b/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentConfirmController.java new file mode 100644 index 0000000..58edd6f --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentConfirmController.java @@ -0,0 +1,66 @@ +package com.example.rhizome.app.presentation.controller; + +import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*; + +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.impl.SearchDepartmentImpl; +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.InsertDepartmentForm; + +@Controller +public class InsertDepartmentConfirmController { + + private final static Logger LOGGER = Logger.getLogger(InsertDepartmentConfirmController.class.getName()); + + private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; + + HttpSession httpSession; + SearchDepartment searchDepartment; + + @Autowired + public InsertDepartmentConfirmController( + HttpSession httpSession, + SearchDepartmentImpl searchDepartment) { + this.httpSession = httpSession; + this.searchDepartment = searchDepartment; + } + + @ModelAttribute + public InsertDepartmentForm insertDepartmentForm() { + return new InsertDepartmentForm(); + } + + @PermissionCheck + @SessionCheck + @RequestMapping(value = INSERT_DEPARTMENT_CONFIRM, method = RequestMethod.POST) + public String insertDepartmentConfirm(InsertDepartmentForm insertDepartmentForm, Model model) { + + try { + model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm); + return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_CONFIRM_HTML; + + } catch (Exception e) { + httpSession.invalidate(); + + e.printStackTrace(); + + LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); + return TransitionTargetPageNameKeyword.ERROR_HTML; + } + } +} diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentController.java b/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentController.java new file mode 100644 index 0000000..0088a19 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentController.java @@ -0,0 +1,120 @@ +package com.example.rhizome.app.presentation.controller; + +import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*; + +import java.util.ArrayList; +import java.util.List; +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.model.Department; +import com.example.rhizome.app.domain.model.SearchConditionDepartment; +import com.example.rhizome.app.domain.service.RegisterDepartment; +import com.example.rhizome.app.domain.service.SearchDepartment; +import com.example.rhizome.app.domain.service.impl.RegisterDepartmentImpl; +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.InsertDepartmentForm; +import com.example.rhizome.app.presentation.form.MessageForm; + +@Controller +public class InsertDepartmentController { + + private final static Logger LOGGER = Logger.getLogger(InsertDepartmentController.class.getName()); + + private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; + + HttpSession httpSession; + RegisterDepartment registerDepartment; + SearchDepartment searchDepartment; + + @Autowired + public InsertDepartmentController(HttpSession httpSession, RegisterDepartmentImpl registerEmployee, + SearchDepartment searchDepartment) { + this.httpSession = httpSession; + this.registerDepartment = registerEmployee; + this.searchDepartment = searchDepartment; + } + + @ModelAttribute + public InsertDepartmentForm insertDepartmentForm() { + return new InsertDepartmentForm(); + } + + @PermissionCheck + @SessionCheck + @RequestMapping(value = INSERT_DEPARTMENT, method = RequestMethod.POST) + public String insertDepartment(InsertDepartmentForm insertDepartmentForm, Model model) { + + try { + List error = validateParameter( + insertDepartmentForm.getNmDepartment()); + + if (!error.isEmpty()) { + model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, + new MessageForm(String.join(", ", error) + "が不正です。")); + model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm); + return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; + } + + final String DUPLICATION = "既に同名の部署が存在します。"; + + SearchConditionDepartment searchConditionDepartment = new SearchConditionDepartment(null, + insertDepartmentForm.getNmDepartment()); + + List departmentList = searchDepartment.searchByDepartmentName(searchConditionDepartment); + + if (!departmentList.isEmpty()) { + model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); + model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm); + return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; + } + + registerDepartment.registerDepartment(InsertDepartmentForm.convertTo(insertDepartmentForm)); + return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_RESULT_HTML; + + } catch (Exception e) { + httpSession.invalidate(); + + e.printStackTrace(); + + LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); + return TransitionTargetPageNameKeyword.ERROR_HTML; + } + } + + private List validateParameter( + String departmentName) { + + final String DEPARTMENT_NAME_NULL_BLANK = "部署名"; + + List error = new ArrayList<>(); + + if (isNullOrBlank(departmentName)) { + error.add(DEPARTMENT_NAME_NULL_BLANK); + } + + return error; + + } + + private static boolean isNullOrBlank(String str) { + if (null == str) { + return true; + } + + return str.isBlank(); + } + +} diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentInputController.java b/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentInputController.java new file mode 100644 index 0000000..4b4d8d2 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/controller/InsertDepartmentInputController.java @@ -0,0 +1,64 @@ +package com.example.rhizome.app.presentation.controller; + +import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*; + +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.RegisterDepartment; +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.InsertDepartmentForm; + +@Controller +public class InsertDepartmentInputController { + + private final static Logger LOGGER = Logger.getLogger(InsertDepartmentInputController.class.getName()); + + private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; + + HttpSession httpSession; + RegisterDepartment registerDepartment; + + @Autowired + public InsertDepartmentInputController(HttpSession httpSession, RegisterDepartment registerDepartment) { + this.httpSession = httpSession; + this.registerDepartment = registerDepartment; + } + + @ModelAttribute + public InsertDepartmentForm insertDepartmentForm() { + return new InsertDepartmentForm(); + } + + @SessionCheck + @PermissionCheck + @RequestMapping(value = INSERT_DEPARTMENT_INPUT, method = RequestMethod.POST) + public String insertInput(InsertDepartmentForm insertDepartmentForm, Model model) { + + try { + model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm); + + return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; + + } catch (Exception e) { + httpSession.invalidate(); + + e.printStackTrace(); + + LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); + return TransitionTargetPageNameKeyword.ERROR_HTML; + } + } +} diff --git a/src/main/java/com/example/rhizome/app/presentation/form/InsertDepartmentForm.java b/src/main/java/com/example/rhizome/app/presentation/form/InsertDepartmentForm.java new file mode 100644 index 0000000..a6a2fe3 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/form/InsertDepartmentForm.java @@ -0,0 +1,46 @@ +package com.example.rhizome.app.presentation.form; + +import java.util.ArrayList; +import java.util.List; + +import com.example.rhizome.app.domain.model.Department; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class InsertDepartmentForm { + + private String nmDepartment; + + private static boolean isNullOrBlank(String str) { + if (null == str) { + return true; + } + + return str.isBlank(); + } + + public static Department convertTo(InsertDepartmentForm insertDepartmentForm) { + return new Department( + null, + insertDepartmentForm.getNmDepartment()); + } + + public List validateParameter() { + final String DEPARTMENT_NAME_NULL_BLANK = "部署名"; + + List error = new ArrayList<>(); + + if (isNullOrBlank(nmDepartment)) { + error.add(DEPARTMENT_NAME_NULL_BLANK); + } + + return error; + + } + +} diff --git a/src/main/resources/templates/insertDepartmentConfirm.html b/src/main/resources/templates/insertDepartmentConfirm.html new file mode 100644 index 0000000..fbb27bb --- /dev/null +++ b/src/main/resources/templates/insertDepartmentConfirm.html @@ -0,0 +1,86 @@ + + + + + + + + + + + + 登録内容確認 + + + +

登録内容確認    +
+ ログイン者名: + +
+

+ +
+ +
+ +
+ + + + + + + + + + + + + +
部署ID + +
部署名 + +
+ +
+ 登録内容の編集 | メニューに戻る +
+ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/insertDepartmentInput.html b/src/main/resources/templates/insertDepartmentInput.html new file mode 100644 index 0000000..0089f7b --- /dev/null +++ b/src/main/resources/templates/insertDepartmentInput.html @@ -0,0 +1,67 @@ + + + + + + + + + + + + 部署登録 + + + +

+ 部署登録    +
+ ログイン者名: + +
+

+
+ +
+ +
+ + + + + + + + + + + + + + +
部署ID + +
部署名 + +
+ +
+
+メニューに戻る + + \ No newline at end of file diff --git a/src/main/resources/templates/insertDepartmentResult.html b/src/main/resources/templates/insertDepartmentResult.html new file mode 100644 index 0000000..2b3d205 --- /dev/null +++ b/src/main/resources/templates/insertDepartmentResult.html @@ -0,0 +1,35 @@ + + + + + + + + + + 社員登録完了 + + + +

社員登録が完了しました

+
+続けて登録する | メニューに戻る + + + \ No newline at end of file