[EDIT]:第二段階(部署削除機能)まで実装完了しました。

This commit is contained in:
h-seya
2026-09-10 16:50:19 +09:00
parent 4591fd0cc5
commit e140f668d3
7 changed files with 111 additions and 36 deletions

View File

@@ -1,16 +1,17 @@
package com.example.rhizome.aop.aspect; package com.example.rhizome.aop.aspect;
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword; import javax.servlet.http.HttpServletRequest;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.exception.InsufficientPermissionException;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest; import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.exception.InsufficientPermissionException;
/** /**
* 権限チェック用のAOP * 権限チェック用のAOP

View File

@@ -9,16 +9,18 @@ import com.example.rhizome.app.infra.repository.DepartmentRepository;
@Service @Service
@Transactional @Transactional
public class DeleteDepartmentImpl implements DeleteDepartment{ public class DeleteDepartmentImpl implements DeleteDepartment {
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
@Autowired @Autowired
public DeleteDepartmentImpl() { public DeleteDepartmentImpl(DepartmentRepository departmentRepository) {
this.departmentRepository = departmentRepository;
} }
public void deleteDepartment(Integer idDepartment) {
departmentRepository.deleteById(idDepartment);
}
} }

View File

@@ -1,10 +1,76 @@
package com.example.rhizome.app.presentation.controller; 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.stereotype.Controller; 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.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.service.DeleteDepartment;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.app.presentation.form.MessageForm;
@Controller @Controller
public class DeleteDepartmentController { public class DeleteDepartmentController {
private final static Logger LOGGER = Logger.getLogger(DeleteDepartmentController.class.getName());
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
HttpSession httpSession;
DeleteDepartment deleteDepartment;
public DeleteDepartmentController(DeleteDepartment deleteDepartment, HttpSession httpSession) {
this.httpSession = httpSession;
this.deleteDepartment = deleteDepartment;
}
@PermissionCheck
@SessionCheck
@RequestMapping(value = DELETE_DEPARTMENT, method = RequestMethod.POST)
public String deleteDepartment(@RequestParam("idDepartment") Integer idDepartment, Model model) {
try {
deleteExec(
model,
idDepartment,
LoginUserForm.convertTo((LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER)));
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_FORM_EMPTY;
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
private void deleteExec(Model model, Integer idDepartment, LoginUser loginUser) {
final String DELETE_COMPLETE = "削除しました。";
deleteDepartment.deleteDepartment(idDepartment);
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(DELETE_COMPLETE));
}
} }

View File

@@ -80,20 +80,21 @@ public class SelectDepartmentController {
} }
} }
// @PermissionCheck // 管理者メニューから部署検索画面へ遷移する際に使用する
// @SessionCheck @PermissionCheck
// @RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT, @SessionCheck
// method = RequestMethod.POST) @RequestMapping(value = TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_FORM_EMPTY,
// public String select(Model model) { method = RequestMethod.POST)
// public String select(Model model) {
// // 検索条件を元に検索を実施
// model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, // 検索条件を元に検索を実施
// DepartmentForm.convertFrom( model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
// searchDepartment.searchBy( DepartmentForm.convertFrom(
// SearchConditionDepartmentForm.convertTo( searchDepartment.searchBy(
// searchConditionDepartmentForm())))); SearchConditionDepartmentForm.convertTo(
// searchConditionDepartmentForm()))));
// // 検索ページに遷移
// return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; // 検索ページに遷移
// } return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
}
} }

View File

@@ -30,6 +30,7 @@ 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 = "エラーが発生しました!";
@@ -51,6 +52,7 @@ public class SelectEmployeeController {
/** /**
* 社員検索画面表示処理コントローラ * 社員検索画面表示処理コントローラ
* 管理者メニューから社員検索画面へ遷移する際に使用する
* *
* @param searchConditionEmployeeForm 検索画面のフォーム * @param searchConditionEmployeeForm 検索画面のフォーム
* @param model ビューにデータを渡すためのコンテナ * @param model ビューにデータを渡すためのコンテナ

View File

@@ -51,7 +51,7 @@ public class TransitionTargetPageNameKeyword {
public static final String INSERT_EMPLOYEE_CONFIRM = "/insertEmployeeConfirm"; public static final String INSERT_EMPLOYEE_CONFIRM = "/insertEmployeeConfirm";
public static final String INSERT_EMPLOYEE = "/insertEmployee"; public static final String INSERT_EMPLOYEE = "/insertEmployee";
public static final String SELECT_EMPLOYEE_INFO = "/selectEmployeeInfo"; public static final String SELECT_EMPLOYEE_INFO = "/selectEmployeeInfo";
public static final String SELECT_EMPLOYEE_INFO_FORM_EMPTY = "/selectAll"; public static final String SELECT_EMPLOYEE_INFO_FORM_EMPTY = "/employeeSelectAll";
public static final String SHOW_UPDATE_EMPLOYEE = "/showUpdateEmployee"; public static final String SHOW_UPDATE_EMPLOYEE = "/showUpdateEmployee";
public static final String UPDATE_EMPLOYEE_RESULT = "/updateEmployeeResult"; public static final String UPDATE_EMPLOYEE_RESULT = "/updateEmployeeResult";
@@ -61,6 +61,7 @@ public class TransitionTargetPageNameKeyword {
public static final String INSERT_DEPARTMENT_CONFIRM = "/insertDepartmentConfirm"; public static final String INSERT_DEPARTMENT_CONFIRM = "/insertDepartmentConfirm";
public static final String INSERT_DEPARTMENT = "/insertDepartment"; public static final String INSERT_DEPARTMENT = "/insertDepartment";
public static final String SELECT_DEPARTMENT = "/selectDepartment"; public static final String SELECT_DEPARTMENT = "/selectDepartment";
public static final String SELECT_DEPARTMENT_FORM_EMPTY = "/departmentSelectAll";
public static final String SHOW_UPDATE_DEPARTMENT = "/showUpdateDepartment"; public static final String SHOW_UPDATE_DEPARTMENT = "/showUpdateDepartment";
public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult"; public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult";
@@ -90,7 +91,9 @@ public class TransitionTargetPageNameKeyword {
SHOW_UPDATE_EMPLOYEE, SHOW_UPDATE_EMPLOYEE,
UPDATE_EMPLOYEE_RESULT, UPDATE_EMPLOYEE_RESULT,
SELECT_DEPARTMENT, SELECT_DEPARTMENT,
INSERT_DEPARTMENT_INPUT INSERT_DEPARTMENT_INPUT,
SELECT_DEPARTMENT_FORM_EMPTY,
DELETE_DEPARTMENT
); );
} }

View File

@@ -57,13 +57,13 @@
function selectEmployeeSubmit() { function selectEmployeeSubmit() {
const form = document.createElement('form'); const form = document.createElement('form');
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'selectEmployeeInfo'); form.setAttribute('action', 'employeeSelectAll');
// 動的送信用のHidden // 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない // 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "selectEmployeeInfo"); inputField.setAttribute("value", "employeeSelectAll");
form.appendChild(inputField); form.appendChild(inputField);
@@ -77,13 +77,13 @@
function selectDepartmentSubmit() { function selectDepartmentSubmit() {
const form = document.createElement('form'); const form = document.createElement('form');
form.setAttribute('method', 'post'); form.setAttribute('method', 'post');
form.setAttribute('action', 'selectDepartment'); form.setAttribute('action', 'departmentSelectAll');
// 動的送信用のHidden // 動的送信用のHidden
// 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない // 動的にFormを作成する場合は何かしら送信しないと、正しく動作しない
const inputField = document.createElement("input"); const inputField = document.createElement("input");
inputField.setAttribute("type", "hidden"); inputField.setAttribute("type", "hidden");
inputField.setAttribute("value", "selectDepartment"); inputField.setAttribute("value", "departmentSelectAll");
form.appendChild(inputField); form.appendChild(inputField);