第3段階 部署更新機能
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package com.example.rhizome.app.domain.service;
|
package com.example.rhizome.app.domain.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.example.rhizome.app.domain.model.Department;
|
import com.example.rhizome.app.domain.model.Department;
|
||||||
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
|
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
|
||||||
@@ -13,6 +12,6 @@ public interface SearchDepartment {
|
|||||||
|
|
||||||
List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment);
|
List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment);
|
||||||
|
|
||||||
Optional<Department> searchDepartmentByIdDepartment(Integer idDepartment);
|
Department searchDepartmentByIdDepartment(Integer idDepartment);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 beforeDepartment, Department updateDepartment);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.example.rhizome.app.domain.service.impl;
|
package com.example.rhizome.app.domain.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
@@ -81,7 +80,8 @@ public class SearchDepartmentImpl implements SearchDepartment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Department> searchDepartmentByIdDepartment(Integer idDepartment) {
|
public Department searchDepartmentByIdDepartment(Integer idDepartment) {
|
||||||
return DepartmentEntity.createDepartmentList(departmentRepository.findById(idDepartment));
|
return DepartmentEntity
|
||||||
|
.createDepartment(departmentRepository.findByIdDepartment(idDepartment).orElse(new DepartmentEntity()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* employee の更新系の機能を集約させるサービスクラスです。
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class UpdateDepartmentImpl implements UpdateDepartment {
|
||||||
|
|
||||||
|
DepartmentRepository departmentRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UpdateDepartmentImpl(DepartmentRepository departmentRepository) {
|
||||||
|
this.departmentRepository = departmentRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* employee の情報を元に employee table のレコードを更新する
|
||||||
|
*
|
||||||
|
* @param beforeEmployee 更新前のデータ
|
||||||
|
* @param updateEmployee 更新後のデータ
|
||||||
|
*/
|
||||||
|
public void updateDepartment(Department beforeDepartment, Department updateDepartment) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
departmentRepository.save(DepartmentEntity.convertFrom(mergeDepartment(beforeDepartment, updateDepartment)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新前のデータと更新対象のデータをマージする
|
||||||
|
*
|
||||||
|
* @param beforeEmployee 更新前のデータ
|
||||||
|
* @param updateEmployee 更新対象のデータ
|
||||||
|
* @return マージしたデータ
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Department mergeDepartment(Department beforeDepartment, Department updateDepartment) {
|
||||||
|
// 更新対象のデータのパスワードが空文字の場合は、更新前のパスワードを使用する
|
||||||
|
// 更新対象のデータの管理者権限が null の場合は、更新前の管理者権限を使用する
|
||||||
|
// 更新対象のデータの部署IDが null の場合は、更新前の部署IDを使用する
|
||||||
|
return new Department(
|
||||||
|
updateDepartment.getIdDepartment(),
|
||||||
|
updateDepartment.getNmDepartment());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -82,4 +82,11 @@ public class DepartmentEntity {
|
|||||||
departmentEntity.getNmDepartment()));
|
departmentEntity.getNmDepartment()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Department createDepartment(DepartmentEntity DepartmentEntity) {
|
||||||
|
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
|
||||||
|
return new Department(
|
||||||
|
DepartmentEntity.getIdDepartment(),
|
||||||
|
DepartmentEntity.getNmDepartment());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.example.rhizome.app.infra.repository;
|
package com.example.rhizome.app.infra.repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
@@ -48,4 +50,6 @@ public interface DepartmentRepository
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<DepartmentEntity> findByIdDepartment(Integer idDepartment);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class DeleteDepartmentController {
|
|||||||
final String ID_TO_DELETED_IS_UNKNOWN = "削除対象のIDが不明です。";
|
final String ID_TO_DELETED_IS_UNKNOWN = "削除対象のIDが不明です。";
|
||||||
final String YOU_CANNOT_DELETE_A_DEPARTMENT_THAT_HAS_ONE_OR_MORE_MEMBERS_ASSIGNED_TO_IT = "1名以上が所属している部署は削除出来ません。";
|
final String YOU_CANNOT_DELETE_A_DEPARTMENT_THAT_HAS_ONE_OR_MORE_MEMBERS_ASSIGNED_TO_IT = "1名以上が所属している部署は削除出来ません。";
|
||||||
|
|
||||||
if (searchDepartment.searchDepartmentByIdDepartment(idDepartment).isEmpty()) {
|
if (searchDepartment.searchDepartmentByIdDepartment(idDepartment) == null) {
|
||||||
// エラーメッセージをセット
|
// エラーメッセージをセット
|
||||||
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(ID_TO_DELETED_IS_UNKNOWN));
|
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(ID_TO_DELETED_IS_UNKNOWN));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
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 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.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.SearchConditionEmployeeForm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新対象の employee が存在するか確認する為のコントローラ
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class UpdateDepartmentController {
|
||||||
|
|
||||||
|
// ログ出力用インスタンス
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(UpdateDepartmentController.class.getName());
|
||||||
|
// エラーメッセージ用の定数フィールド
|
||||||
|
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||||
|
|
||||||
|
HttpSession httpSession;
|
||||||
|
SearchDepartment searchDepartment;
|
||||||
|
SearchEmployeeInfo searchEmployeeInfo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UpdateDepartmentController(HttpSession httpSession, SearchDepartment searchDepartment,
|
||||||
|
SearchEmployeeInfo searchEmployeeInfo) {
|
||||||
|
this.httpSession = httpSession;
|
||||||
|
this.searchDepartment = searchDepartment;
|
||||||
|
this.searchEmployeeInfo = searchEmployeeInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute
|
||||||
|
public SearchConditionEmployeeForm searchConditionEmployeeForm() {
|
||||||
|
return new SearchConditionEmployeeForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新対象の employee が存在するか確認する為のコントローラ
|
||||||
|
*
|
||||||
|
* @param idEmployee 更新対象の employee の id
|
||||||
|
* @param model ビューにデータを渡すためのコンテナ
|
||||||
|
* @return 遷移先の画面
|
||||||
|
*/
|
||||||
|
@PermissionCheck
|
||||||
|
@SessionCheck
|
||||||
|
@RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_DAPERTMENT, method = RequestMethod.POST)
|
||||||
|
public String showUpdateDepatment(@RequestParam("idDepartment") Integer idDepartment, Model model) {
|
||||||
|
final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。";
|
||||||
|
try {
|
||||||
|
// 部署一覧を取得し画面に返す値としてセット
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
|
||||||
|
DepartmentForm.convertFrom(searchDepartment.searchDepartmentByIdDepartment(idDepartment)));
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
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.model.Department;
|
||||||
|
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
|
||||||
|
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.DepartmentForm;
|
||||||
|
import com.example.rhizome.app.presentation.form.MessageForm;
|
||||||
|
import com.example.rhizome.app.presentation.form.UpdateDepartmentInfoForm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* employee を更新して結果を返す為のコントローラ
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class UpdateDepartmentResultController {
|
||||||
|
|
||||||
|
// ログ出力用インスタンス
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(UpdateEmployeeController.class.getName());
|
||||||
|
// エラーメッセージ用の定数フィールド
|
||||||
|
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||||
|
|
||||||
|
HttpSession httpSession;
|
||||||
|
SearchDepartment searchDepartment;
|
||||||
|
SearchEmployee searchEmployee;
|
||||||
|
UpdateDepartment updateDepartment;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UpdateDepartmentResultController(HttpSession httpSession, SearchDepartment searchDepartment,
|
||||||
|
SearchEmployee searchEmployee, UpdateDepartment updateDepartment) {
|
||||||
|
this.httpSession = httpSession;
|
||||||
|
this.searchDepartment = searchDepartment;
|
||||||
|
this.searchEmployee = searchEmployee;
|
||||||
|
this.updateDepartment = updateDepartment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新結果画面表示処理
|
||||||
|
*
|
||||||
|
* @param updateEmployeeInfoForm 更新画面のフォーム
|
||||||
|
* @param model ビューにデータを渡すためのコンテナ
|
||||||
|
* @return 遷移先の画面
|
||||||
|
*/
|
||||||
|
@PermissionCheck
|
||||||
|
@SessionCheck
|
||||||
|
@RequestMapping(value = TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_RESULT, method = RequestMethod.POST)
|
||||||
|
public String employeeUpdateResult(@ModelAttribute UpdateDepartmentInfoForm updateDepartmentInfoForm, Model model) {
|
||||||
|
|
||||||
|
final String DEPARTMENT_WITH_THE_SAME_NAME = "既に同名の部署が存在するか、値が変更されていません。";
|
||||||
|
final String NOTHING = "項目が空欄です。";
|
||||||
|
final String NO_TARGET = "更新対象のデータが見つかりません。";
|
||||||
|
|
||||||
|
final String UPDATE_COMPLETE = "更新が完了しました。";
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// 部署一覧取得
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
|
||||||
|
DepartmentForm.convertFrom(searchDepartment.selectAll()));
|
||||||
|
|
||||||
|
// 既に登録済みの部署名が存在するか
|
||||||
|
if (searchDepartment.searchBy(
|
||||||
|
new SearchConditionDepartment(null, updateDepartmentInfoForm.getNmDepartment())).size() != 0) {
|
||||||
|
System.out.println("同一部署名");
|
||||||
|
// 存在する場合はエラーメッセージを設定して更新入力画面に遷移
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
|
||||||
|
new MessageForm(DEPARTMENT_WITH_THE_SAME_NAME));
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, updateDepartmentInfoForm);
|
||||||
|
|
||||||
|
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
|
||||||
|
}
|
||||||
|
// 画面から渡ってきた値が必須を満たしているか
|
||||||
|
if (!UpdateDepartmentInfoForm.hasErrorParameter(updateDepartmentInfoForm)) {
|
||||||
|
System.out.println("部署必須否");
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING));
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, updateDepartmentInfoForm);
|
||||||
|
|
||||||
|
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新前のデータを取得
|
||||||
|
Department beforeDepartment = searchDepartment
|
||||||
|
.searchDepartmentByIdDepartment(updateDepartmentInfoForm.getIdDepartment());
|
||||||
|
if (beforeDepartment.getIdDepartment() == null) {
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NO_TARGET));
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, updateDepartmentInfoForm);
|
||||||
|
|
||||||
|
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 画面用の型からビジネスロジック用のモデルに変換し、Updateを実行
|
||||||
|
updateDepartment.updateDepartment(beforeDepartment,
|
||||||
|
updateDepartmentInfoForm.convertTo(updateDepartmentInfoForm));
|
||||||
|
|
||||||
|
// 更新結果のメッセージを画面にセットし一覧画面に遷移
|
||||||
|
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE));
|
||||||
|
|
||||||
|
// forward 先で不用意な動作をしないために UpdateEmployeeInfoForm をクリア
|
||||||
|
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_INFO_FORM_EMPTY;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ログイン情報の破棄
|
||||||
|
httpSession.invalidate();
|
||||||
|
e.printStackTrace();
|
||||||
|
// エラーログ出力
|
||||||
|
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
||||||
|
// エラー画面遷移
|
||||||
|
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,9 +10,11 @@ public class PageReturnAttributeKeyword {
|
|||||||
|
|
||||||
public static final String DEPARTMENT_FORM_LIST = "departmentFormList";
|
public static final String DEPARTMENT_FORM_LIST = "departmentFormList";
|
||||||
public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm";
|
public static final String UPDATE_EMPLOYEE_INFO_FORM = "updateEmployeeInfoForm";
|
||||||
|
|
||||||
public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm";
|
public static final String INSERT_EMPLOYEE_FORM = "insertEmployeeForm";
|
||||||
public static final String LOGIN_INFO_FORM = "loginInfoForm";
|
public static final String LOGIN_INFO_FORM = "loginInfoForm";
|
||||||
public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm";
|
public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm";
|
||||||
public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList";
|
public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList";
|
||||||
|
public static final String UPDATE_DEPARTMENT_INFO_FORM = "updateDepartmentInfoForm";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public class TransitionTargetPageNameKeyword {
|
|||||||
// Department
|
// Department
|
||||||
// HTML
|
// HTML
|
||||||
public static final String SELECT_DEPARTMENT_HTML = "selectDepartment";
|
public static final String SELECT_DEPARTMENT_HTML = "selectDepartment";
|
||||||
|
public static final String UPDATE_DEPARTMENT_INPUT_HTML = "updateDepartmentInput";
|
||||||
// Controller
|
// Controller
|
||||||
public static final String SELECT_DEPARTMENT_INFO = "/selectDepartmentInfo";
|
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";
|
||||||
@@ -55,8 +56,8 @@ public class TransitionTargetPageNameKeyword {
|
|||||||
public static final String INSERT_DEPARTMENT_INPUT = "i";
|
public static final String INSERT_DEPARTMENT_INPUT = "i";
|
||||||
public static final String INSERT_DEPARTMENT_CONFIRM = "u";
|
public static final String INSERT_DEPARTMENT_CONFIRM = "u";
|
||||||
public static final String INSERT_DEPARTMENT = "e";
|
public static final String INSERT_DEPARTMENT = "e";
|
||||||
public static final String SHOW_UPDATE_DAPERTMENT = "o";
|
public static final String SHOW_UPDATE_DAPERTMENT = "/showUpdateDepartment";
|
||||||
public static final String UPDATE_DEPARTMENT_RESULT = "k";
|
public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 管理者向けのページリストを返す
|
* 管理者向けのページリストを返す
|
||||||
@@ -82,7 +83,9 @@ public class TransitionTargetPageNameKeyword {
|
|||||||
UPDATE_EMPLOYEE_RESULT,
|
UPDATE_EMPLOYEE_RESULT,
|
||||||
SELECT_DEPARTMENT_INFO,
|
SELECT_DEPARTMENT_INFO,
|
||||||
SELECT_DEPARTMENT_INFO_FORM_EMPTY,
|
SELECT_DEPARTMENT_INFO_FORM_EMPTY,
|
||||||
DELETE_DEPARTMENT);
|
DELETE_DEPARTMENT,
|
||||||
|
SHOW_UPDATE_DAPERTMENT,
|
||||||
|
UPDATE_DEPARTMENT_RESULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.example.rhizome.app.presentation.form;
|
||||||
|
|
||||||
|
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 UpdateDepartmentInfoForm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DepartmentID
|
||||||
|
*/
|
||||||
|
private Integer idDepartment;
|
||||||
|
/**
|
||||||
|
* 社員Department名
|
||||||
|
*/
|
||||||
|
private String nmDepartment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* business 層の EmployeeInfo クラスから画面用(presentation 層)の UpdateEmployeeInfoForm に
|
||||||
|
* 変換します。
|
||||||
|
*
|
||||||
|
* @param employeeInfo business 層の EmployeeInfo インスタンス
|
||||||
|
* @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンス
|
||||||
|
*/
|
||||||
|
public static UpdateDepartmentInfoForm convertFrom(Department department) {
|
||||||
|
return new UpdateDepartmentInfoForm(
|
||||||
|
department.getIdDepartment(),
|
||||||
|
department.getNmDepartment());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* business 層の EmployeeInfo クラスから画面用(presentation 層)の UpdateEmployeeInfoForm に
|
||||||
|
* 変換します。(リスト版)
|
||||||
|
*
|
||||||
|
* @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト
|
||||||
|
* @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンスのリスト
|
||||||
|
*/
|
||||||
|
public static List<UpdateDepartmentInfoForm> convertFrom(List<Department> departmentList) {
|
||||||
|
return departmentList.stream().map(UpdateDepartmentInfoForm::convertFrom).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 画面用(presentation 層)の UpdateEmployeeInfoForm クラスから business 層の Employee クラスに
|
||||||
|
* 変換します。
|
||||||
|
*
|
||||||
|
* @param updateEmployeeInfoForm 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンス
|
||||||
|
* @return business 層の Employee インスタンス
|
||||||
|
*/
|
||||||
|
public static Department convertTo(UpdateDepartmentInfoForm updateDepartmentInfoForm) {
|
||||||
|
return new Department(
|
||||||
|
updateDepartmentInfoForm.getIdDepartment(),
|
||||||
|
updateDepartmentInfoForm.getNmDepartment());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 画面から渡ってきたパラメータのチェック
|
||||||
|
*
|
||||||
|
* @param updateEmployeeInfoForm 画面から渡ってきたパラメータ
|
||||||
|
* @return true: エラー無し false:エラーあり(必須を満たしていない)
|
||||||
|
*/
|
||||||
|
public static boolean hasErrorParameter(UpdateDepartmentInfoForm updateDepartmentInfoForm) {
|
||||||
|
|
||||||
|
boolean errorFlag = !isNullOrBlank(updateDepartmentInfoForm.getNmDepartment());
|
||||||
|
|
||||||
|
return errorFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仮引数を null or 空 判定する
|
||||||
|
*
|
||||||
|
* @param str 判定対象の文字列
|
||||||
|
* @return true:null or 空 false:null or 空 では無い
|
||||||
|
*/
|
||||||
|
private static boolean isNullOrBlank(String str) {
|
||||||
|
if (null == str) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return str.isBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
<td th:text="${departmentInfoForm.nmDepartment}"></td>
|
<td th:text="${departmentInfoForm.nmDepartment}"></td>
|
||||||
<td>
|
<td>
|
||||||
<!-- 更新フォーム -->
|
<!-- 更新フォーム -->
|
||||||
<form action="showUpdateDepatment" method="post" style="display: inline;">
|
<form action="showUpdateDepartment" method="post" style="display: inline;">
|
||||||
<input name="idDepartment" th:value="${departmentInfoForm.idDepartment}">
|
<input name="idDepartment" th:value="${departmentInfoForm.idDepartment}">
|
||||||
<input type="submit" value="更新">
|
<input type="submit" value="更新">
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
88
src/main/resources/templates/updateDepartmentInput.html
Normal file
88
src/main/resources/templates/updateDepartmentInput.html
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
||||||
|
<!-- 外部のスクリプトファイルを読み込む -->
|
||||||
|
<script th:src="@{/js/common.js}"></script>
|
||||||
|
<!-- CSSの読み込み -->
|
||||||
|
<link rel="stylesheet" th:href="@{/css/all.css}">
|
||||||
|
<link rel=stylesheet th:href="@{/css/style.css}" type="text/css">
|
||||||
|
<title>部署情報更新</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>
|
||||||
|
部署情報更新
|
||||||
|
<div class="rightSection">
|
||||||
|
<span class="loginInfo">ログイン者名:<span th:text="${session.loginUser.nmEmployee}"></span></span>
|
||||||
|
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
|
||||||
|
</div>
|
||||||
|
</h1>
|
||||||
|
<form action="/updateDepartmentResult"
|
||||||
|
method="post"
|
||||||
|
onsubmit="return confirm('本当によろしいですか?');"
|
||||||
|
th:object="${departmentFormList}"
|
||||||
|
>
|
||||||
|
<div class="msgBox error" th:if="${messageError != null}">
|
||||||
|
<span class="error" th:each="message : ${messageError.message}" th:text="${message}"></span>
|
||||||
|
</div>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th class="header">部署ID</th>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input class="readOnly"
|
||||||
|
readonly="readonly"
|
||||||
|
th:field="*{idDepartment}"
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th class="header">部署名</th>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input maxlength="50"
|
||||||
|
placeholder="部署名"
|
||||||
|
required="required"
|
||||||
|
th:field="*{nmDepartment}"
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="btnArea" colspan="2">
|
||||||
|
<input type="submit" value="更新"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
<a href="javascript:selectSubmit()">一覧に戻る</a>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function selectSubmit() {
|
||||||
|
const form = document.createElement('form');
|
||||||
|
form.setAttribute('method', 'post');
|
||||||
|
form.setAttribute('action', 'departmentAll');
|
||||||
|
|
||||||
|
// 動的送信用のHidden
|
||||||
|
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
|
||||||
|
const inputField = document.createElement("input");
|
||||||
|
inputField.setAttribute("type", "hidden");
|
||||||
|
inputField.setAttribute("value", "departmentAll");
|
||||||
|
|
||||||
|
form.appendChild(inputField);
|
||||||
|
|
||||||
|
// フォームをDOMに追加
|
||||||
|
document.body.appendChild(form);
|
||||||
|
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user