From 40ac38a484705d0e49850f78c793965aa3479a51 Mon Sep 17 00:00:00 2001 From: o-matsuda <26-o-matsuda-stellatecnica@it-college.co.jp> Date: Wed, 14 Oct 2026 15:50:52 +0900 Subject: [PATCH] =?UTF-8?q?=E6=AE=B5=E9=9A=8E=EF=BC=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/domain/service/UpdateDepartment.java | 8 + .../service/impl/UpdateDepartmentImpl.java | 29 ++ .../UpdateDepartmentController.java | 138 ++++++++ .../PageReturnAttributeKeyword.java | 1 + .../TransitionTargetPageNameKeyword.java | 14 +- .../form/UpdateDepartmentForm.java | 48 +++ .../resources/templates/selectDepartment.html | 6 + .../resources/templates/updateDepartment.html | 60 ++++ .../templates/updateEmployeeInput.html | 294 ++++++++---------- 9 files changed, 430 insertions(+), 168 deletions(-) create mode 100644 src/main/java/com/example/rhizome/app/domain/service/UpdateDepartment.java create mode 100644 src/main/java/com/example/rhizome/app/domain/service/impl/UpdateDepartmentImpl.java create mode 100644 src/main/java/com/example/rhizome/app/presentation/controller/UpdateDepartmentController.java create mode 100644 src/main/java/com/example/rhizome/app/presentation/form/UpdateDepartmentForm.java create mode 100644 src/main/resources/templates/updateDepartment.html diff --git a/src/main/java/com/example/rhizome/app/domain/service/UpdateDepartment.java b/src/main/java/com/example/rhizome/app/domain/service/UpdateDepartment.java new file mode 100644 index 0000000..7c6296d --- /dev/null +++ b/src/main/java/com/example/rhizome/app/domain/service/UpdateDepartment.java @@ -0,0 +1,8 @@ +package com.example.rhizome.app.domain.service; + +import com.example.rhizome.app.domain.model.Department; + +public interface UpdateDepartment { + void updateDepartment(Department depart); + + } diff --git a/src/main/java/com/example/rhizome/app/domain/service/impl/UpdateDepartmentImpl.java b/src/main/java/com/example/rhizome/app/domain/service/impl/UpdateDepartmentImpl.java new file mode 100644 index 0000000..e0ab707 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/domain/service/impl/UpdateDepartmentImpl.java @@ -0,0 +1,29 @@ +package com.example.rhizome.app.domain.service.impl; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.example.rhizome.app.domain.model.Department; +import com.example.rhizome.app.domain.service.UpdateDepartment; +import com.example.rhizome.app.infra.entity.DepartmentEntity; +import com.example.rhizome.app.infra.repository.DepartmentRepository; + +@Service +@Transactional +public class UpdateDepartmentImpl implements UpdateDepartment { + + DepartmentRepository departmentRepository; + + @Autowired + public UpdateDepartmentImpl(DepartmentRepository departmentRepository) { + this.departmentRepository = departmentRepository; + } + + public void updateDepartment(Department department) { + DepartmentEntity entity = new DepartmentEntity(); + entity.setIdDepartment(department.getIdDepartment()); + entity.setNmDepartment(department.getNmDepartment()); + departmentRepository.save(entity); + } +} diff --git a/src/main/java/com/example/rhizome/app/presentation/controller/UpdateDepartmentController.java b/src/main/java/com/example/rhizome/app/presentation/controller/UpdateDepartmentController.java new file mode 100644 index 0000000..4cf8892 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/controller/UpdateDepartmentController.java @@ -0,0 +1,138 @@ +package com.example.rhizome.app.presentation.controller; + +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 org.springframework.web.bind.annotation.RequestParam; + +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.service.SearchDepartment; +import com.example.rhizome.app.domain.service.SearchEmployee; +import com.example.rhizome.app.domain.service.UpdateDepartment; +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.MessageForm; +import com.example.rhizome.app.presentation.form.SearchConditionDepartment; +import com.example.rhizome.app.presentation.form.UpdateDepartmentForm; + +@Controller +public class UpdateDepartmentController { + // ログ出力用インスタンス + private final static Logger LOGGER = Logger.getLogger(DeleteDepartmentController.class.getName()); + + private static final String SEVERE_ERROR_MESSAGE = "エラーが発生しました!"; + + HttpSession httpSession; + UpdateDepartment updateDepartment; + SearchDepartment searchDepartment; + SearchEmployee searchEmployee; + + @Autowired + public UpdateDepartmentController(UpdateDepartment updateDepartment, SearchDepartment searchDepartment, + HttpSession httpSession, SearchEmployee searchEmployee) { + this.httpSession = httpSession; + this.updateDepartment = updateDepartment; + this.searchDepartment = searchDepartment; + this.searchEmployee = searchEmployee; + } + + @ModelAttribute + public SearchConditionDepartment searchConditionDepartment() { + return new SearchConditionDepartment(); + } + + @PermissionCheck + @SessionCheck + @RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_DEPARTMENT, method = RequestMethod.POST) + public String showUpdateDepartment(@RequestParam("idDepartment") Integer idDepartment, Model model) { + final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。"; + + try { + List departmentList = searchDepartment + .searchBy(new com.example.rhizome.app.domain.model.SearchConditionDepartment(idDepartment, null)); + if (departmentList.isEmpty()) { + model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, + new MessageForm(UPDATE_TARGET_ID_NOT_FOUND)); + return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO; + } + // 更新画面に遷移 + model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, + UpdateDepartmentForm.convertFrom(departmentList.get(0))); + + // Update画面に遷移 + return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML; + } catch (Exception e) { + // ログイン情報の破棄 + httpSession.invalidate(); + + e.printStackTrace(); + + // エラーログ出力 + LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e); + // エラー画面遷移 + return TransitionTargetPageNameKeyword.ERROR_HTML; + } + + } + + @RequestMapping(value = TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_RESULT, method = RequestMethod.POST) + public String departmentUpdateResult(@ModelAttribute UpdateDepartmentForm updateDepartmentForm, Model model) { + + final String NOTHING = "項目が空欄です。"; + final String DUPLICATION = "既に同名の部署が存在するか、値が変更されていません。"; + final String NO_TARGET = "更新対象のデータが見つかりません。"; + final String UPDATE_COMPLETE = "更新が完了しました。"; + try { + + boolean bo = updateDepartmentForm.hasRequiredValue(); + if (bo == false) { + model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, + new MessageForm(NOTHING)); + return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML; + } + List departmentList = searchDepartment + .searchBy(new com.example.rhizome.app.domain.model.SearchConditionDepartment(null, + updateDepartmentForm.getNmDepartment())); + if (departmentList == null) { + model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, + new MessageForm(DUPLICATION)); + return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML; + } + List departmentList2 = searchDepartment + .searchBy(new com.example.rhizome.app.domain.model.SearchConditionDepartment( + updateDepartmentForm.getIdDepartment(), null)); + if (departmentList2 == null) { + model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, + new MessageForm(NO_TARGET)); + return PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM; + } + Department department = new Department(updateDepartmentForm.getIdDepartment(), + updateDepartmentForm.getNmDepartment()); + updateDepartment.updateDepartment(department); + model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, + new MessageForm(UPDATE_COMPLETE)); + return PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM; + } 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/pageproperty/PageReturnAttributeKeyword.java b/src/main/java/com/example/rhizome/app/presentation/controller/pageproperty/PageReturnAttributeKeyword.java index 5e9ec04..2c6e4ed 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 @@ -14,5 +14,6 @@ public class PageReturnAttributeKeyword { 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 UPDATE_DEPARTMENT_FORM = "updateDepartmentForm"; } 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 8da5999..dee07f0 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 @@ -23,7 +23,7 @@ public class TransitionTargetPageNameKeyword { public static final String UPDATE_EMPLOYEE_INPUT_HTML = "updateEmployeeInput"; public static final String SELECT_DEPARTMENT_HTML = "/selectDepartment"; public static final String ERROR_HTML = "error"; - + public static final String UPDATE_DEPARTMENT_INPUT_HTML = "updateDepartmentInput"; // 共通(Controller) public static final String INDEX_BLANK = ""; public static final String INDEX_SLASH = "/"; @@ -45,11 +45,10 @@ public class TransitionTargetPageNameKeyword { public static final String SHOW_UPDATE_EMPLOYEE = "/showUpdateEmployee"; public static final String UPDATE_EMPLOYEE_RESULT = "/updateEmployeeResult"; public static final String SELECT_DEPARTMENT_INFO = "/selectDepartmentInfo"; - public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY ="/departmentAll"; + public static final String SELECT_DEPARTMENT_INFO_FORM_EMPTY = "/departmentAll"; public static final String DELETE_DEPARTMENT = "/deleteDepartment"; - // Department - // HTML - // Controller + public static final String SHOW_UPDATE_DEPARTMENT = "/showUpdateDepartment"; + public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult"; /** * 管理者向けのページリストを返す @@ -74,8 +73,9 @@ public class TransitionTargetPageNameKeyword { UPDATE_EMPLOYEE_RESULT, SELECT_DEPARTMENT_INFO, SELECT_DEPARTMENT_INFO_FORM_EMPTY, - DELETE_DEPARTMENT); - + DELETE_DEPARTMENT, + SHOW_UPDATE_DEPARTMENT, + UPDATE_DEPARTMENT_RESULT); } /** diff --git a/src/main/java/com/example/rhizome/app/presentation/form/UpdateDepartmentForm.java b/src/main/java/com/example/rhizome/app/presentation/form/UpdateDepartmentForm.java new file mode 100644 index 0000000..78afc73 --- /dev/null +++ b/src/main/java/com/example/rhizome/app/presentation/form/UpdateDepartmentForm.java @@ -0,0 +1,48 @@ +package com.example.rhizome.app.presentation.form; + +import com.example.rhizome.app.domain.model.Department; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class UpdateDepartmentForm { + + //部署ID + private Integer idDepartment; + //部署名 + private String nmDepartment; + + /** + * business 層の Department クラスから画面用(presentation 層)の UpdateDepartmentForm に + * 変換します。 + * + * @param departmentInfo business 層の DepartmentInfo インスタンス + * @return 画面用(presentation 層)の UpdateDepartmentForm インスタンス + */ + public static UpdateDepartmentForm convertFrom(Department department) { + return new UpdateDepartmentForm(department.getIdDepartment(), department.getNmDepartment()); + } + + /** + * 画面用(presentation 層)の UpdateDepartmentForm クラスから business 層の Department クラスに + * 変換します。 + * + * @param updateDepartmentForm 画面用(presentation 層)の UpdateDepartmentForm インスタンス + * @return business 層の Department インスタンス + */ + public static Department convertTo(UpdateDepartmentForm form) { + return new Department(form.getIdDepartment(), form.getNmDepartment()); + } + + public boolean hasRequiredValue() { + if (idDepartment == null && (nmDepartment == null || nmDepartment.isBlank())) { + return false; + } else { + return true; + } + } +} diff --git a/src/main/resources/templates/selectDepartment.html b/src/main/resources/templates/selectDepartment.html index af24a99..abca277 100644 --- a/src/main/resources/templates/selectDepartment.html +++ b/src/main/resources/templates/selectDepartment.html @@ -78,12 +78,18 @@ + +
+ + +
+ diff --git a/src/main/resources/templates/updateDepartment.html b/src/main/resources/templates/updateDepartment.html new file mode 100644 index 0000000..4243093 --- /dev/null +++ b/src/main/resources/templates/updateDepartment.html @@ -0,0 +1,60 @@ + + + + + + + + + + + + 部署情報更新 + + + +

+ 部署情報更新    +
+ ログイン者名: + +
+

+
+ +
+ +
+ + + + + + + + + + + + +
部署ID + +
部署名 + +
+
+ 一覧に戻る + + + + \ No newline at end of file diff --git a/src/main/resources/templates/updateEmployeeInput.html b/src/main/resources/templates/updateEmployeeInput.html index 83d43a5..1688c0c 100644 --- a/src/main/resources/templates/updateEmployeeInput.html +++ b/src/main/resources/templates/updateEmployeeInput.html @@ -3,179 +3,151 @@ - - - - - - - 社員情報更新 + + + + + + + 社員情報更新 -

- 社員情報更新    -
- ログイン者名: - -
-

-
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + +
社員ID - -
社員名 - -
社員名フリガナ - -
メールアドレス - -
パスワード - -
- + ログイン者名: + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - -
社員ID + +
社員名 + +
社員名フリガナ + +
メールアドレス + +
パスワード + +
+ - ※半角英数字をそれぞれ1種類以上含む3-10文字 - -
パスワード確認用 - -
管理者権限 - - -
所属部署 - -
- -
- -一覧に戻る + ※半角英数字をそれぞれ1種類以上含む3-10文字 +
+
パスワード確認用 + +
管理者権限 + + +
所属部署 + +
+ +
+ + 一覧に戻る + \ No newline at end of file