社員情報登録時のプルダウンの分割化の相談の参照用の一時プッシュ追加分

This commit is contained in:
o-yamamoto
2026-09-28 14:26:46 +09:00
parent 995fe03b73
commit 820d030602
2 changed files with 147 additions and 139 deletions

View File

@@ -2,6 +2,7 @@ package com.example.rhizome.app.presentation.controller;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -10,9 +11,12 @@ 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.GetMapping;
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 org.springframework.web.bind.annotation.ResponseBody;
import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
@@ -20,7 +24,9 @@ import com.example.rhizome.app.domain.service.RegisterEmployee;
import com.example.rhizome.app.domain.service.SearchDepartment;
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.DepartmentInfoForm;
import com.example.rhizome.app.presentation.form.DivisionInfoForm;
import com.example.rhizome.app.presentation.form.HeadquartersInfoForm;
import com.example.rhizome.app.presentation.form.InsertEmployeeForm;
/**
@@ -51,44 +57,14 @@ public class InsertEmployeeInputController {
return new InsertEmployeeForm();
}
/**
* 登録画面表示処理
*
* @param insertEmployeeForm 登録画面のフォーム
* @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面
*/
@SessionCheck
@PermissionCheck
@RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) {
try {
// 部署コードリストを作成し、画面に返す値としてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST
,DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()));
// パラメータをセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
//プルダウン絞り込み実装用
//プルダウン絞り込み無し実装用
// /**
// * 登録画面表示処理
// *
// * @param insertEmployeeForm 登録画面のフォーム
// * @param model ビューにデータを渡すためのコンテナ
// * @return 遷移先の画面
// */
// @SessionCheck
// @PermissionCheck
// @RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
@@ -97,7 +73,7 @@ public class InsertEmployeeInputController {
// try {
// // 部署コードリストを作成し、画面に返す値としてセット
// model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST
// ,HeadquartersInfoForm.convertFrom(
// ,DepartmentForm.convertFrom(
// searchDepartment.searchAllDepartmentTable()));
//
// // パラメータをセット
@@ -118,45 +94,75 @@ public class InsertEmployeeInputController {
// return TransitionTargetPageNameKeyword.ERROR_HTML;
// }
// }
//プルダウン絞り込み実装用
@SessionCheck
@PermissionCheck
@RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) {
// @GetMapping("insertEmployeeInput/searchDepartment" )
// @ResponseBody
// public List<DepartmentInfoForm>departmentsByHeadquarters(
// @RequestParam("id_headquarters")Integer idHeadquarters){
// System.out.println("koko");
//
// List<DepartmentInfoForm> departmentByHeadquarters=
// DepartmentInfoForm.convertFrom(
// searchDepartment.searchByIdHeadquarters(idHeadquarters));
// System.out.println("2");
// return departmentByHeadquarters
// .stream()
// .map(DepartmentInfoForm-> new DepartmentInfoForm(
// DepartmentInfoForm.getIdDepartment(),
// DepartmentInfoForm.getNmDepartment()))
// .distinct()
// .toList();
//
//
// }
// @GetMapping("/insertEmployeeInput/searchDepartment/searchDivision")
// @ResponseBody
// public List<DivisionInfoForm>divisionBydepartment(
// @RequestParam("idDepartment")Integer idDepartment){
// List<DivisionInfoForm> divisionBydepartment=
// DivisionInfoForm.convertFrom(
// searchDepartment.searchByIdDepartment(idDepartment));
//
// return divisionBydepartment
// .stream()
// .map(DivisionInfoForm-> new DivisionInfoForm(
// DivisionInfoForm.getIdDivision(),
// DivisionInfoForm.getNmDivision()))
// .distinct()
// .toList();
//
//
// }
try {
// 部署コードリストを作成し、画面に返す値としてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST
,HeadquartersInfoForm.convertFrom(
searchDepartment.searchAllDepartmentTable()));
// パラメータをセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}
@GetMapping("insertEmployeeInput/searchDepartment" )
@ResponseBody
public List<DepartmentInfoForm>departmentsByHeadquarters(
@RequestParam("id_headquarters")Integer idHeadquarters){
System.out.println("koko");
List<DepartmentInfoForm> departmentByHeadquarters=
DepartmentInfoForm.convertFrom(
searchDepartment.searchByIdHeadquarters(idHeadquarters));
System.out.println("2");
return departmentByHeadquarters
.stream()
.map(DepartmentInfoForm-> new DepartmentInfoForm(
DepartmentInfoForm.getIdDepartment(),
DepartmentInfoForm.getNmDepartment()))
.distinct()
.toList();
}
@GetMapping("/insertEmployeeInput/searchDepartment/searchDivision")
@ResponseBody
public List<DivisionInfoForm>divisionBydepartment(
@RequestParam("idDepartment")Integer idDepartment){
List<DivisionInfoForm> divisionBydepartment=
DivisionInfoForm.convertFrom(
searchDepartment.searchByIdDepartment(idDepartment));
return divisionBydepartment
.stream()
.map(DivisionInfoForm-> new DivisionInfoForm(
DivisionInfoForm.getIdDivision(),
DivisionInfoForm.getNmDivision()))
.distinct()
.toList();
}
}

View File

@@ -167,43 +167,45 @@
<th class="header" >所属部</th>
<td>
<!-- プルダウン絞り込み実装用-->
<!-- <label>-->
<!-- <select id="departmentSelect" required="required" th:field="*{idDepartment}"> -->
<!-- <option value="">先に本部を選択してください</option>-->
<label>
<select id="departmentSelect" required="required" th:field="*{idDepartment}">
<option value="">先に本部を選択してください</option>
<!-- </select>-->
<!-- </label>-->
<label>
<select id="departmentSelect" required="required" th:field="*{idDepartment}">
</select>
</label>
<!-- プルダウン絞り込み無し実装用-->
<!-- <label>-->
<!-- <select id="departmentSelect" required="required" th:field="*{idDepartment}">-->
<option th:each="department : ${departmentFormList}"
th:utext="
${department.nmDepartment}"
th:value="${department.idDepartment}">
</option>
<!-- <option th:each="department : ${departmentFormList}"-->
<!-- th:utext="-->
<!-- ${department.nmDepartment}"-->
<!-- th:value="${department.idDepartment}">-->
<!-- </option>-->
</select>
</label>
<!-- </select>-->
<!-- </label>-->
</td>
</tr>
<tr>
<th class="header" >所属課</th>
<td>
<label>
<select id="divisionSelect" required="required" th:field="*{idDivision}">
<option th:each="division : ${departmentFormList}"
th:utext="
${division.nmDivision}"
th:value="${division.idDivision}">
</option>
</select>
</label>
<!-- プルダウン絞り込み無し実装用-->
<!-- <label>-->
<!-- <select id="divisionSelect" required="required" th:field="*{idDivision}">-->
<!-- <option th:each="division : ${departmentFormList}"-->
<!-- th:utext="-->
<!-- ${division.nmDivision}"-->
<!-- th:value="${division.idDivision}">-->
<!-- </option>-->
<!-- </select>-->
<!-- </label>-->
<!-- プルダウン絞り込み実装用-->
<!-- <label>-->
<!-- <select id="divisionSelect" required="required" th:field="*{idDivision}">-->
<!-- <option value="">先に部を選択してください</option>-->
<!-- </select>-->
<!-- </label>-->
<label>
<select id="divisionSelect" required="required" th:field="*{idDivision}">
<option value="">先に部を選択してください</option>
</select>
</label>
</td>
</tr>
@@ -217,46 +219,46 @@
<a href="showMenu">メニューに戻る</a>
</body>
<!--プルダウン絞り込み実装用(途中)-->
<!--<script>-->
<!--const headquartersSelect = document.getElementById('headquartersSelect');-->
<!--const departmentSelect = document.getElementById('departmentSelect');-->
<!--const divisionSelect = document.getElementById('divisionSelect');-->
<script>
const headquartersSelect = document.getElementById('headquartersSelect');
const departmentSelect = document.getElementById('departmentSelect');
const divisionSelect = document.getElementById('divisionSelect');
<!--headquartersSelect.addEventListener('change', function() {-->
<!-- const id_headquarters = this.value; -->
headquartersSelect.addEventListener('change', function() {
const id_headquarters = this.value;
<!-- departmentSelect.disabled = true;-->
<!-- divisionSelect.disabled = true;-->
<!-- departmentSelect.innerHTML = '<option value="">-- 部を選択 --</option>';-->
<!-- divisionSelect.innerHTML = '<option value="">-- 先に部を選択してください --</option>';-->
<!-- console.log("koko");-->
<!-- if (!id_headquarters) return;-->
<!-- fetch(`insertEmployeeInput/searchDepartment?id_headquarters=${id_headquarters}`,{ -->
<!-- method: 'GET',-->
<!-- headers: {-->
<!-- 'Accept': 'application/json' -->
<!-- }-->
<!-- })-->
departmentSelect.disabled = true;
divisionSelect.disabled = true;
departmentSelect.innerHTML = '<option value="">-- 部を選択 --</option>';
divisionSelect.innerHTML = '<option value="">-- 先に部を選択してください --</option>';
console.log("koko");
if (!id_headquarters) return;
fetch(`insertEmployeeInput/searchDepartment?id_headquarters=${id_headquarters}`,{
method: 'GET',
headers: {
'Accept': 'application/json'
}
})
<!-- .then(res => {-->
<!-- console.log("koko");-->
<!-- return res.json();-->
<!-- })-->
<!-- .then(list => {-->
<!-- departmentSelect.disabled = false; -->
<!-- list.forEach(form => {-->
<!-- const opt = document.createElement('option');-->
<!-- opt.value = form.idDepartment; -->
<!-- opt.textContent = form.nmDepartment; -->
<!-- departmentSelect.appendChild(opt);-->
<!-- });-->
<!-- })-->
.then(res => {
console.log("koko");
return res.json();
})
.then(list => {
departmentSelect.disabled = false;
list.forEach(form => {
const opt = document.createElement('option');
opt.value = form.idDepartment;
opt.textContent = form.nmDepartment;
departmentSelect.appendChild(opt);
});
})
<!--});-->
});
<!--</script>-->
</script>
</html>