改修の実装【社員検索機能の項目追加:「入社年月日」、「勤続年数」を追加】

This commit is contained in:
o-yamamoto
2026-09-09 15:53:39 +09:00
parent 53c704d2a7
commit 5ba4106d45
12 changed files with 166 additions and 52 deletions

View File

@@ -29,6 +29,10 @@ public class Employee {
* パスワード
*/
private final String password;
/**
* 入社年月日
*/
private final String hireDate;
/**
* 管理者権限
*/

View File

@@ -1,12 +1,13 @@
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.Employee;
import com.example.rhizome.app.domain.service.UpdateEmployee;
import com.example.rhizome.app.infra.entity.EmployeeEntity;
import com.example.rhizome.app.infra.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* employee の更新系の機能を集約させるサービスクラスです。
@@ -51,6 +52,7 @@ public class UpdateEmployeeImpl implements UpdateEmployee {
updateEmployee.getKnEmployee(),
updateEmployee.getMailAddress(),
updateEmployee.getPassword().isBlank() ? beforeEmployee.getPassword() : updateEmployee.getPassword(),
updateEmployee.getHireDate(),
updateEmployee.getAdminAuth() == null ? beforeEmployee.getAdminAuth() : updateEmployee.getAdminAuth(),
updateEmployee.getIdDepartment() == null ? beforeEmployee.getIdDepartment() : updateEmployee.getIdDepartment()
);

View File

@@ -1,16 +1,27 @@
package com.example.rhizome.app.infra.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedEntityGraph;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.*;
import java.util.List;
/**
* Employee + Department の Join 情報を保持するEntity
@@ -60,6 +71,12 @@ public class EmployeeDepartmentEntity {
@Column(name = "password", nullable = false)
private String password;
/**
* 入社年月日
*/
@Column(name = "hire_date", nullable = false)
private String hireDate;
/**
* 管理者権限
*/
@@ -70,6 +87,7 @@ public class EmployeeDepartmentEntity {
@JoinColumn(name = "id_department", referencedColumnName = "id_department", insertable = false, updatable = false)
@Fetch(FetchMode.JOIN)
private DepartmentEntity department;
/**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。
@@ -89,9 +107,9 @@ public class EmployeeDepartmentEntity {
employeeDepartmentEntity.getKnEmployee(),
employeeDepartmentEntity.getMailAddress(),
employeeDepartmentEntity.getPassword(),
employeeDepartmentEntity.getHireDate(),
employeeDepartmentEntity.getAdminAuth(),
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment()
),
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment() ),
new Department(
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment(),
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getNmDepartment()

View File

@@ -7,16 +7,23 @@
package com.example.rhizome.app.infra.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.List;
/**
* EmployeeテーブルのEntity
*
@@ -61,6 +68,11 @@ public class EmployeeEntity {
@Column(name = "password", nullable = false)
private String password;
/**
* 入社年月日
*/
@Column(name = "hire_Date", nullable = false)
private String hireDate;
/**
* 管理者権限
*/
@@ -72,6 +84,7 @@ public class EmployeeEntity {
*/
@Column(name = "id_department", nullable = false)
private Integer idDepartment;
/**
@@ -88,6 +101,7 @@ public class EmployeeEntity {
employee.getKnEmployee(),
employee.getMailAddress(),
employee.getPassword(),
employee.getHireDate(),
employee.getAdminAuth(),
employee.getIdDepartment()
);
@@ -128,6 +142,7 @@ public class EmployeeEntity {
employeeEntity.getKnEmployee(),
employeeEntity.getMailAddress(),
employeeEntity.getPassword(),
employeeEntity.getHireDate(),
employeeEntity.getAdminAuth(),
employeeEntity.getIdDepartment()
);

View File

@@ -1,5 +1,21 @@
package com.example.rhizome.app.presentation.controller;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import java.util.ArrayList;
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 com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.RegisterEmployee;
@@ -11,20 +27,6 @@ import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTa
import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.InsertEmployeeForm;
import com.example.rhizome.app.presentation.form.MessageForm;
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 javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_EMPLOYEE;
/**
* 新規登録用のコントローラ
@@ -81,6 +83,7 @@ public class InsertEmployeeController {
insertEmployeeForm.getKnEmployee(),
insertEmployeeForm.getMailAddress(),
insertEmployeeForm.getPassword(),
insertEmployeeForm.getHireDate(),
insertEmployeeForm.getAdminAuth(),
insertEmployeeForm.getIdDepartment()
);
@@ -125,6 +128,7 @@ public class InsertEmployeeController {
String employeeKana,
String mailAddress,
String password,
String hireDate,
Integer management,
Integer departmentId
) {
@@ -133,6 +137,7 @@ public class InsertEmployeeController {
final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ";
final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス";
final String PASSWORD_NULL_BLANK = "パスワード";
final String HIREDATE_NULL_BLANK = "入社年月日";
final String MANAGEMENT_ERROR = "管理者権限指定";
final String DEPARTMENT_ID_NULL_BLANK = "所属部署";
@@ -161,6 +166,11 @@ public class InsertEmployeeController {
// エラー内容を追加
error.add(PASSWORD_NULL_BLANK);
}
// null or 空文字判定
if (isNullOrBlank(hireDate)) {
// エラー内容を追加
error.add(HIREDATE_NULL_BLANK);
}
// 管理者権限の値が不正か
if (management == null) {

View File

@@ -1,14 +1,11 @@
package com.example.rhizome.app.presentation.controller;
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.EmployeeInfoForm;
import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm;
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;
@@ -16,9 +13,16 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpSession;
import java.util.logging.Level;
import java.util.logging.Logger;
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.domain.service.TenureCalc;
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.EmployeeInfoForm;
import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm;
/**
* 社員検索画面用コントローラ リスト全件表示、検索表示、更新、削除が可能
@@ -34,12 +38,13 @@ public class SelectEmployeeController {
HttpSession httpSession;
SearchDepartment searchDepartment;
SearchEmployeeInfo searchEmployeeInfo;
TenureCalc tenureCalc;
@Autowired
public SelectEmployeeController(HttpSession httpSession, SearchDepartment searchDepartment, SearchEmployeeInfo searchEmployeeInfo) {
public SelectEmployeeController(HttpSession httpSession, SearchDepartment searchDepartment, SearchEmployeeInfo searchEmployeeInfo ,TenureCalc tenureCalc) {
this.httpSession = httpSession;
this.searchDepartment = searchDepartment;
this.searchEmployeeInfo = searchEmployeeInfo;
this.tenureCalc = tenureCalc;
}
@ModelAttribute
@@ -70,7 +75,14 @@ public class SelectEmployeeController {
// 検索条件を元に検索を実施
// 取得した EmployeeInfo( employee + department )の情報を画面に返す用の型に詰め替えてセット
model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, EmployeeInfoForm.convertFrom(searchEmployeeInfo.searchBy(SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm))));
List<EmployeeInfoForm>employeeInfoForm = EmployeeInfoForm.convertFrom(searchEmployeeInfo.searchBy(SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm)));
for(EmployeeInfoForm form:employeeInfoForm) {
String tenure = tenureCalc.tenureCalc(form.getHireDate());
form.setTenure(tenure);
}
model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, employeeInfoForm);
// 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_HTML;

View File

@@ -1,13 +1,14 @@
package com.example.rhizome.app.presentation.form;
import java.util.List;
import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 画面に表示するために employee と department を Join した構造を扱うクラス
*/
@@ -37,7 +38,15 @@ public class EmployeeInfoForm {
*/
private String password;
/**
* パスワード
* 入社年月日
*/
private String hireDate;
/**
* 勤続年数
*/
private String tenure;
/**
* 管理者権限
*/
private Integer adminAuth;
/**
@@ -63,6 +72,8 @@ public class EmployeeInfoForm {
employeeInfo.getEmployee().getKnEmployee(),
employeeInfo.getEmployee().getMailAddress(),
employeeInfo.getEmployee().getPassword(),
employeeInfo.getEmployee().getHireDate(),
null,
employeeInfo.getEmployee().getAdminAuth(),
employeeInfo.getDepartment().getIdDepartment(),
employeeInfo.getDepartment().getNmDepartment()

View File

@@ -1,13 +1,14 @@
package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.Employee;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
import com.example.rhizome.app.domain.model.Employee;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 画面から渡ってきた登録内容をまとめ、再度画面に表示する為のクラス
*/
@@ -40,6 +41,10 @@ public class InsertEmployeeForm {
* 確認用パスワード
*/
private String passwordConfirm;
/**
* 入社年月日
*/
private String hireDate;
/**
* 管理者権限
@@ -50,6 +55,7 @@ public class InsertEmployeeForm {
* 部署ID
*/
private Integer idDepartment;
/**
* パスワードのValidation
@@ -105,6 +111,7 @@ public class InsertEmployeeForm {
insertEmployeeForm.getKnEmployee(),
insertEmployeeForm.getMailAddress(),
insertEmployeeForm.getPassword(),
insertEmployeeForm.getHireDate(),
insertEmployeeForm.getAdminAuth(),
insertEmployeeForm.getIdDepartment()
);
@@ -121,6 +128,7 @@ public class InsertEmployeeForm {
final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス";
final String MANAGEMENT_ERROR = "管理者権限指定";
final String DEPARTMENT_ID_NULL_BLANK = "所属部署";
final String HIREDATE_NULL_BLANK ="入社年月日";
List<String> error = new ArrayList<>();
@@ -144,6 +152,9 @@ public class InsertEmployeeForm {
if (idDepartment == null) {
error.add(DEPARTMENT_ID_NULL_BLANK);
}
if(isNullOrBlank(hireDate)) {
error.add(HIREDATE_NULL_BLANK);
}
return error;

View File

@@ -1,13 +1,14 @@
package com.example.rhizome.app.presentation.form;
import java.util.List;
import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 画面から渡ってきた更新内容をまとめ、再度画面に表示する為のクラス
*/
@@ -94,6 +95,7 @@ public class UpdateEmployeeInfoForm {
updateEmployeeInfoForm.getKnEmployee(),
updateEmployeeInfoForm.getMailAddress(),
updateEmployeeInfoForm.getPassword(),
null,
updateEmployeeInfoForm.getAdminAuth(),
updateEmployeeInfoForm.getIdDepartment()
);

View File

@@ -89,6 +89,18 @@
</label>
</td>
</tr>
<tr>
<th class="header">入社年月日</th>
<td>
<label>
<input class="readOnly"
name="hireDate"
readonly="readonly"
th:value="*{hireDate}"
type="date"/>
</label>
</td>
</tr>
<tr>
<th class="header">管理者権限</th>
<td>

View File

@@ -114,6 +114,19 @@
</label>
</td>
</tr>
<tr>
<th class="header">入社年月日</th>
<td>
<label>
<input
placeholder="入社年月日"
required="required"
th:field="*{hireDate}"
type="date"
/>
</label>
</td>
</tr>
<tr>
<th class="header">管理者権限</th>
<td>

View File

@@ -105,6 +105,8 @@
<th style="width: 150px;">フリガナ</th>
<th style="width: 150px;">メールアドレス</th>
<th style="width: 100px;">パスワード</th>
<th style="width: 60px;">入社年月日</th>
<th style="width: 60px;">勤続年数</th>
<th style="width: 70px;">管理者フラグ</th>
<th style="width: 150px;">所属部署</th>
<th style="width: 150px;">操作</th>
@@ -117,6 +119,8 @@
<td th:text="${employeeInfoForm.knEmployee}"></td>
<td th:text="${employeeInfoForm.mailAddress}"></td>
<td th:text="${employeeInfoForm.password}"></td>
<td th:text="${employeeInfoForm.hireDate}"></td>
<td th:text="${employeeInfoForm.tenure}"></td>
<td th:text="${employeeInfoForm.adminAuth}"></td>
<td th:text="${employeeInfoForm.nmDepartment}"></td>
<td>