2 Commits

Author SHA1 Message Date
adf3c9f321 段階3完了 2026-10-14 16:43:20 +09:00
40ac38a484 段階3 2026-10-14 15:50:52 +09:00
10 changed files with 512 additions and 168 deletions

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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<Department> 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_INFO_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<Department> departmentList = searchDepartment
.searchBy(new com.example.rhizome.app.domain.model.SearchConditionDepartment(null,
updateDepartmentForm.getNmDepartment()));
if (departmentList == null && departmentList.isEmpty()){
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(DUPLICATION));
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
}
List<Department> departmentList2 = searchDepartment
.searchBy(new com.example.rhizome.app.domain.model.SearchConditionDepartment(
updateDepartmentForm.getIdDepartment(), null));
if (departmentList2 == null || departmentList2.isEmpty()) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(NO_TARGET));
return PageReturnAttributeKeyword.UPDATE_DEPARTMENT_INFO_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_INFO_FORM;
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
}

View File

@@ -14,5 +14,6 @@ public class PageReturnAttributeKeyword {
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 = "updateDepartmentForm";
} }

View File

@@ -23,7 +23,7 @@ public class TransitionTargetPageNameKeyword {
public static final String UPDATE_EMPLOYEE_INPUT_HTML = "updateEmployeeInput"; public static final String UPDATE_EMPLOYEE_INPUT_HTML = "updateEmployeeInput";
public static final String SELECT_DEPARTMENT_HTML = "/selectDepartment"; public static final String SELECT_DEPARTMENT_HTML = "/selectDepartment";
public static final String ERROR_HTML = "error"; public static final String ERROR_HTML = "error";
public static final String UPDATE_DEPARTMENT_INPUT_HTML = "updateDepartmentInput";
// 共通(Controller) // 共通(Controller)
public static final String INDEX_BLANK = ""; public static final String INDEX_BLANK = "";
public static final String INDEX_SLASH = "/"; public static final String INDEX_SLASH = "/";
@@ -47,9 +47,8 @@ public class TransitionTargetPageNameKeyword {
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";
public static final String DELETE_DEPARTMENT = "/deleteDepartment"; public static final String DELETE_DEPARTMENT = "/deleteDepartment";
// Department public static final String SHOW_UPDATE_DEPARTMENT = "/showUpdateDepartment";
// HTML public static final String UPDATE_DEPARTMENT_RESULT = "/updateDepartmentResult";
// Controller
/** /**
* 管理者向けのページリストを返す * 管理者向けのページリストを返す
@@ -74,8 +73,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_DEPARTMENT,
UPDATE_DEPARTMENT_RESULT);
} }
/** /**

View File

@@ -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;
}
}
}

View File

@@ -78,12 +78,18 @@
<td th:text="${departmentForm.idDepartment}"></td> <td th:text="${departmentForm.idDepartment}"></td>
<td th:text="${departmentForm.nmDepartment}"></td> <td th:text="${departmentForm.nmDepartment}"></td>
<td> <td>
<!-- 更新フォーム -->
<form action="showUpdateDepartment" method="post" style="display: inline;">
<input name="idDepartment" th:value="${departmentForm.idDepartment}" type="hidden">
<input type="submit" value="更新">
</form>
<!-- 削除フォーム --> <!-- 削除フォーム -->
<form action="deleteDepartment" method="post" onsubmit="return confirm('本当に削除しますか?');" <form action="deleteDepartment" method="post" onsubmit="return confirm('本当に削除しますか?');"
style="display: inline;"> style="display: inline;">
<input name="idDepartment" th:value="${departmentForm.idDepartment}" type="hidden"> <input name="idDepartment" th:value="${departmentForm.idDepartment}" type="hidden">
<input type="submit" value="削除"> <input type="submit" value="削除">
</form> </form>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@@ -0,0 +1,71 @@
<!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="${updateDepartmentForm}">
<div class="msgBox error" th:if="${messageError != null}">
<span class="error" th:text="${messageError.message}"></span>
</div>
<table>
<tr>
<th class="header">部署ID</th>
<td>
<input class="readOnly" readonly="readonly" th:field="*{idDepartment}" type="text" />
</td>
</tr>
<tr>
<th class="header">部署名</th>
<td>
<input maxlength="50" placeholder="部署名" required="required" th:field="*{nmDepartment}"
type="text" />
</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>

View File

@@ -0,0 +1,71 @@
<!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="${updateDepartmentForm}">
<div class="msgBox error" th:if="${messageError != null}">
<span class="error" th:text="${messageError.message}"></span>
</div>
<table>
<tr>
<th class="header">部署ID</th>
<td>
<input class="readOnly" readonly="readonly" th:field="*{idDepartment}" type="text" />
</td>
</tr>
<tr>
<th class="header">部署名</th>
<td>
<input maxlength="50" placeholder="部署名" required="required" th:field="*{nmDepartment}"
type="text" />
</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>

View File

@@ -20,11 +20,8 @@
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button> <button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
</div> </div>
</h1> </h1>
<form action="/updateEmployeeResult" <form action="/updateEmployeeResult" method="post" onsubmit="return confirm('本当によろしいですか?');"
method="post" th:object="${updateEmployeeInfoForm}">
onsubmit="return confirm('本当によろしいですか?');"
th:object="${updateEmployeeInfoForm}"
>
<div class="msgBox error" th:if="${messageError != null}"> <div class="msgBox error" th:if="${messageError != null}">
<span class="error" th:each="message : ${messageError.message}" th:text="${message}"></span> <span class="error" th:each="message : ${messageError.message}" th:text="${message}"></span>
</div> </div>
@@ -33,11 +30,7 @@
<th class="header">社員ID</th> <th class="header">社員ID</th>
<td> <td>
<label> <label>
<input class="readOnly" <input class="readOnly" readonly="readonly" th:field="*{idEmployee}" type="text" />
readonly="readonly"
th:field="*{idEmployee}"
type="text"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -45,12 +38,8 @@
<th class="header">社員名</th> <th class="header">社員名</th>
<td> <td>
<label> <label>
<input maxlength="50" <input maxlength="50" placeholder="社員名" required="required" th:field="*{nmEmployee}"
placeholder="社員名" type="text" />
required="required"
th:field="*{nmEmployee}"
type="text"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -58,13 +47,8 @@
<th class="header">社員名フリガナ</th> <th class="header">社員名フリガナ</th>
<td> <td>
<label> <label>
<input maxlength="50" <input maxlength="50" oninput="convertToKatakana(this)" placeholder="フリガナ" required="required"
oninput="convertToKatakana(this)" th:field="*{knEmployee}" type="text" />
placeholder="フリガナ"
required="required"
th:field="*{knEmployee}"
type="text"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -72,12 +56,8 @@
<th class="header">メールアドレス</th> <th class="header">メールアドレス</th>
<td> <td>
<label> <label>
<input maxlength="100" <input maxlength="100" placeholder="メールアドレス" required="required" th:field="*{mailAddress}"
placeholder="メールアドレス" type="email" />
required="required"
th:field="*{mailAddress}"
type="email"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -85,11 +65,8 @@
<th class="header">パスワード</th> <th class="header">パスワード</th>
<td> <td>
<label> <label>
<input pattern="^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{3,10}$" <input pattern="^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{3,10}$" placeholder="パスワード"
placeholder="パスワード" th:field="*{password}" type="password" />
th:field="*{password}"
type="password"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -108,11 +85,8 @@
<th class="header">パスワード確認用</th> <th class="header">パスワード確認用</th>
<td> <td>
<label> <label>
<input pattern="^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{3,10}$" <input pattern="^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{3,10}$" placeholder="パスワード確認用"
placeholder="パスワード確認用" th:field="*{passwordConfirm}" type="password" />
th:field="*{passwordConfirm}"
type="password"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -121,14 +95,12 @@
<td> <td>
<label> <label>
<input id="adminAuth1" name="adminAuth" th:checked="${updateEmployeeInfoForm.adminAuth == 1}" <input id="adminAuth1" name="adminAuth" th:checked="${updateEmployeeInfoForm.adminAuth == 1}"
type="radio" type="radio" value="1"> 管理者権限
value="1"> 管理者権限
</label> </label>
<label> <label>
<input id="adminAuth0" name="adminAuth" <input id="adminAuth0" name="adminAuth"
th:checked="${updateEmployeeInfoForm.adminAuth == null or updateEmployeeInfoForm.adminAuth == 0}" th:checked="${updateEmployeeInfoForm.adminAuth == null or updateEmployeeInfoForm.adminAuth == 0}"
type="radio" type="radio" value="0">
value="0">
一般権限 一般権限
</label> </label>
</td> </td>
@@ -140,8 +112,7 @@
<select required="required" th:field="*{idDepartment}"> <select required="required" th:field="*{idDepartment}">
<option th:each="department : ${departmentFormList}" <option th:each="department : ${departmentFormList}"
th:selected="${updateEmployeeInfoForm.idDepartment != null && department.idDepartment == updateEmployeeInfoForm.idDepartment}" th:selected="${updateEmployeeInfoForm.idDepartment != null && department.idDepartment == updateEmployeeInfoForm.idDepartment}"
th:text="${department.nmDepartment}" th:text="${department.nmDepartment}" th:value="${department.idDepartment}">
th:value="${department.idDepartment}">
</option> </option>
</select> </select>
</label> </label>
@@ -178,4 +149,5 @@
} }
</script> </script>
</html> </html>