社員情報の更新などで使うプルダウンの確認のためのひとまずプッシュ

This commit is contained in:
o-yamamoto
2026-09-24 09:58:48 +09:00
parent b7b51df086
commit 3ab46927bb
58 changed files with 1275 additions and 643 deletions

View File

@@ -3,19 +3,23 @@ package com.example.rhizome.app.domain.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* 部署情報の概念を表現するモデルクラスです。
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class Department { public class Department {
/** /**
* 部署ID * 部ID
*/ */
private final Integer idDepartment; private final Integer idDepartment;
/** /**
* 部署名 * 部名
*/ */
private final String nmDepartment; private final String nmDepartment;
/**
* 表示・非表示フラグ
*/
private final Integer isDisplay;
/**
* 部ID
*/
private final Integer idHeadquarters;
} }

View File

@@ -40,6 +40,6 @@ public class Employee {
/** /**
* 部署ID * 部署ID
*/ */
private final Integer idDepartment; private final Integer idDivision;
} }

View File

@@ -21,8 +21,8 @@ public class EmployeeInfo {
*/ */
private final Employee employee; private final Employee employee;
/** /**
* 部署名 * 課情報
*/ */
private final Department department; private final Division division;
} }

View File

@@ -38,7 +38,7 @@ public class LoginUser {
/** /**
* 部署ID * 部署ID
*/ */
private final Integer idDepartment; private final Integer idDivision;
/** /**
* ログインユーザが管理者か * ログインユーザが管理者か

View File

@@ -10,12 +10,12 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public class SearchConditionDepartment { public class SearchConditionDepartment {
/** /**
* 部署ID * ID
*/ */
private final Integer idDepartment; private final Integer idDivision;
/** /**
* 部署名 * 名前
*/ */
private final String nmDepartment; private final String nmDivision;
} }

View File

@@ -28,6 +28,6 @@ public class SearchConditionEmployee {
/** /**
* 部署ID * 部署ID
*/ */
private final Integer idDepartment; private final Integer idDivision;
} }

View File

@@ -1,6 +1,6 @@
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
public interface DeleteDepartment { public interface DeleteDepartment {
void deleteDepartment(Integer idDepartment); void deleteDepartment(Integer idDivision);
} }

View File

@@ -1,7 +1,7 @@
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.infra.entity.DivisionEntity;
public interface RegisterDepartment { public interface RegisterDepartment {
void registerDepartment(Department department); void registerDepartment(DivisionEntity divisionEntity);
} }

View File

@@ -1,14 +1,29 @@
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import java.util.List; import java.util.List;
import com.example.rhizome.app.domain.model.AllDepartmentInfo;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.Division;
import com.example.rhizome.app.domain.model.Headquarters;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
public interface SearchDepartment { public interface SearchDepartment {
List<Department> selectAll();
List<Department> searchBy(SearchConditionDepartment searchConditionDepartment); List<AllDepartmentInfo> searchAllDepartmentTable();
List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment); List<AllDepartmentInfo> searchAllDepartmentTable(SearchConditionDepartment searchConditionDepartment);
boolean searchAllDepartmentTable(
SearchConditionDepartment searchHeadquartersTable,
SearchConditionDepartment searchDepartmentTable,
SearchConditionDepartment searchDivisionTable);
List<Headquarters> searchByHeadquarters(SearchConditionDepartment searchConditionDepartment);
List<Department> searchByDepartment(SearchConditionDepartment searchConditionDepartment);
List<Division> searchByDivision(SearchConditionDepartment searchConditionDepartment);
// List<DepartmentInfo> searchByWithLike(SearchConditionDepartment searchConditionDepartment);
} }

View File

@@ -1,14 +1,14 @@
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
import java.util.List;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import java.util.List;
public interface SearchEmployee { public interface SearchEmployee {
List<Employee> searchEmployee(String mailAddress); List<Employee> searchEmployee(String mailAddress);
List<Employee> searchEmployeeByIdDepartment(Integer idDepartment); List<Employee> searchEmployeeByIdDepartment(Integer idDivision);
LoginUser searchLoginUser(String mailAddress); LoginUser searchLoginUser(String mailAddress);

View File

@@ -1,12 +1,12 @@
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
import com.example.rhizome.app.domain.model.EmployeeInfo;
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import java.util.List; import java.util.List;
public interface SearchEmployeeInfo { import com.example.rhizome.app.domain.model.AllEmployeeInfo;
List<EmployeeInfo> selectAll(); import com.example.rhizome.app.domain.model.SearchConditionEmployee;
List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee); public interface SearchEmployeeInfo {
List<AllEmployeeInfo> selectAll();
List<AllEmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee);
} }

View File

@@ -1,8 +1,8 @@
package com.example.rhizome.app.domain.service; package com.example.rhizome.app.domain.service;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.domain.model.DepartmentInfo;
public interface UpdateDepartment { public interface UpdateDepartment {
void updateDepartment(Department department); void updateDepartment(DepartmentInfo departmentInfo);
} }

View File

@@ -1,11 +1,12 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import com.example.rhizome.app.domain.service.DeleteDepartment;
import com.example.rhizome.app.infra.repository.DepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.example.rhizome.app.domain.service.DeleteDepartment;
import com.example.rhizome.app.infra.repository.DivisionRepository;
/** /**
* Department レコード削除関連の機能を持つサービス * Department レコード削除関連の機能を持つサービス
*/ */
@@ -13,7 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional @Transactional
public class DeleteDepartmentImpl implements DeleteDepartment { public class DeleteDepartmentImpl implements DeleteDepartment {
DepartmentRepository departmentRepository; DivisionRepository divisionRepository;
/** /**
* コンストラクタ * コンストラクタ
@@ -21,8 +22,8 @@ public class DeleteDepartmentImpl implements DeleteDepartment {
* @param departmentRepository DI対象 * @param departmentRepository DI対象
*/ */
@Autowired @Autowired
public DeleteDepartmentImpl(DepartmentRepository departmentRepository) { public DeleteDepartmentImpl(DivisionRepository divisionRepository) {
this.departmentRepository = departmentRepository; this.divisionRepository = divisionRepository;
} }
@@ -32,7 +33,7 @@ public class DeleteDepartmentImpl implements DeleteDepartment {
* @param idDepartment 削除対象のidDepartment * @param idDepartment 削除対象のidDepartment
*/ */
public void deleteDepartment(Integer idDepartment) { public void deleteDepartment(Integer idDepartment) {
departmentRepository.deleteById(idDepartment); divisionRepository.deleteById(idDepartment);
} }
} }

View File

@@ -1,14 +1,18 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.service.RegisterDepartment;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
import com.example.rhizome.app.infra.repository.DepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.example.rhizome.app.domain.service.RegisterDepartment;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
import com.example.rhizome.app.infra.entity.DivisionEntity;
import com.example.rhizome.app.infra.entity.HeadquartersEntity;
import com.example.rhizome.app.infra.repository.DepartmentRepository;
import com.example.rhizome.app.infra.repository.DivisionRepository;
import com.example.rhizome.app.infra.repository.HeadquartersRepository;
/** /**
* Department テーブルの登録系の機能を集約させるサービスクラスです。 * Department テーブルの登録系の機能を集約させるサービスクラスです。
*/ */
@@ -17,15 +21,20 @@ import org.springframework.transaction.annotation.Transactional;
public class RegisterDepartmentImpl implements RegisterDepartment { public class RegisterDepartmentImpl implements RegisterDepartment {
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
DivisionRepository divisionRepository;
HeadquartersRepository headquartersRepository;
/** /**
* コンストラクタ * コンストラクタ
* *
* @param departmentRepository DI対象 * @param departmentRepository DI対象
*/ */
@Autowired @Autowired
public RegisterDepartmentImpl(DepartmentRepository departmentRepository) { public RegisterDepartmentImpl(DepartmentRepository departmentRepository,
DivisionRepository divisionRepository,
HeadquartersRepository headquartersRepository) {
this.departmentRepository = departmentRepository; this.departmentRepository = departmentRepository;
this.divisionRepository = divisionRepository;
this.headquartersRepository = headquartersRepository;
} }
/** /**
@@ -33,7 +42,31 @@ public class RegisterDepartmentImpl implements RegisterDepartment {
* *
* @param department 登録対象のデータ * @param department 登録対象のデータ
*/ */
public void registerDepartment(Department department) { public void registerDepartment(DivisionEntity divisionEntity) {
departmentRepository.save(DepartmentEntity.convertFrom(department)); DepartmentEntity departmentEntity = divisionEntity.getDepartment();
HeadquartersEntity headquartersEntity = divisionEntity.getDepartment().getHeadquarters();
if(departmentEntity.getIdDepartment()==null) {
departmentEntity = new DepartmentEntity();
}
if(headquartersEntity.getIdHeadquarters()==null) {
headquartersEntity = new HeadquartersEntity();
}
divisionEntity.setIsDisplay(0);
departmentEntity.setIsDisplay(0);
headquartersEntity.setIsDisplay(0);
departmentEntity.setNmDepartment(
divisionEntity.getDepartment()
.getNmDepartment()
);
headquartersEntity.setNmHeadquarters(
divisionEntity.getDepartment()
.getHeadquarters()
.getNmHeadquarters()
);
departmentEntity.setHeadquarters(headquartersEntity);
divisionEntity.setDepartment(departmentEntity);
divisionRepository.save(divisionEntity);
} }
} }

View File

@@ -1,14 +1,15 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.service.RegisterEmployee;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.service.RegisterEmployee;
import com.example.rhizome.app.infra.entity.InsertEmployeeEntity;
import com.example.rhizome.app.infra.repository.EmployeeRepository;
/** /**
* Employee テーブルの登録系の機能を集約させるサービスクラスです。 * Employee テーブルの登録系の機能を集約させるサービスクラスです。
*/ */
@@ -29,6 +30,6 @@ public class RegisterEmployeeImpl implements RegisterEmployee {
* @param employee 登録対象のデータ * @param employee 登録対象のデータ
*/ */
public void registerEmployee(Employee employee) { public void registerEmployee(Employee employee) {
employeeRepository.save(EmployeeEntity.convertFrom(employee)); employeeRepository.save(InsertEmployeeEntity.convertFrom(employee));
} }
} }

View File

@@ -1,17 +1,27 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import com.example.rhizome.app.domain.model.Department; import java.util.List;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
import com.example.rhizome.app.infra.repository.DepartmentRepository;
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;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import com.example.rhizome.app.domain.model.AllDepartmentInfo;
import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.Division;
import com.example.rhizome.app.domain.model.Headquarters;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
import com.example.rhizome.app.infra.entity.DepartmentInfoEntity;
import com.example.rhizome.app.infra.entity.DivisionEntity;
import com.example.rhizome.app.infra.entity.HeadquartersEntity;
import com.example.rhizome.app.infra.repository.DepartmentInfoRepository;
import com.example.rhizome.app.infra.repository.DepartmentRepository;
import com.example.rhizome.app.infra.repository.DivisionRepository;
import com.example.rhizome.app.infra.repository.HeadquartersRepository;
/** /**
* 部署情報検索系の機能を集約させるサービスクラスです。 * 部署情報検索系の機能を集約させるサービスクラスです。
@@ -19,64 +29,123 @@ import java.util.List;
@Service @Service
@Transactional @Transactional
public class SearchDepartmentImpl implements SearchDepartment { public class SearchDepartmentImpl implements SearchDepartment {
DivisionRepository divisionRepository;
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
HeadquartersRepository headquartersRepository;
DepartmentInfoRepository departmentInfoRepository;
/** /**
* コンストラクタ * コンストラクタ
* *
* @param departmentRepository DI対象 * @param departmentRepository DI対象
*/ */
@Autowired @Autowired
public SearchDepartmentImpl(DepartmentRepository departmentRepository) { public SearchDepartmentImpl(
DepartmentRepository departmentRepository
,DivisionRepository divisionRepository
,HeadquartersRepository headquartersRepository
,DepartmentInfoRepository departmentInfoRepository) {
this.departmentRepository = departmentRepository; this.departmentRepository = departmentRepository;
this.divisionRepository = divisionRepository;
this.headquartersRepository = headquartersRepository;
this.departmentInfoRepository = departmentInfoRepository;
} }
/** /**
* 部署情報を全件取得する * 部署情報を全件取得する
* *
* @return 取得した部署情報レコード全件 * @return 取得した本部情報レコード全件
*/ */
public List<Department> selectAll() { public List<AllDepartmentInfo>searchAllDepartmentTable(){
return DepartmentEntity.createDepartmentList(departmentRepository.findAll()); return DepartmentInfoEntity.createDepartmentInfoList(departmentInfoRepository.searchAllDepartmentTable());
} }
public List<AllDepartmentInfo>searchAllDepartmentTable(SearchConditionDepartment searchConditionDepartment){
return DepartmentInfoEntity.AfterSearchCreateDepartmentInfoList(
departmentInfoRepository.findAll(Specification
.where(DepartmentInfoRepository.idDivisionEqual(searchConditionDepartment.getIdDivision()))
.and(DepartmentInfoRepository.nmDivisionEqual(searchConditionDepartment.getNmDivision()))
)
);
}
public boolean searchAllDepartmentTable(
SearchConditionDepartment searchHeadquartersTable,
SearchConditionDepartment searchDepartmentTable,
SearchConditionDepartment searchDivisionTable){
if(departmentInfoRepository.searchAllDepartmentTable(
searchHeadquartersTable.getNmDivision(),
searchDepartmentTable.getNmDivision(),
searchDivisionTable.getNmDivision()).isEmpty()) {
return false;
}else{
return true;
}
}
/** /**
* searchConditionDepartment の情報を元に Department のレコードを取得 * searchConditionDepartment の情報を元に Department のレコードを取得
* *
* @param searchConditionDepartment 検索条件 * @param searchConditionDepartment 検索条件
* @return 検索結果のレコード * @return 検索結果のレコード
*/ */
public List<Department> searchBy(SearchConditionDepartment searchConditionDepartment) { public List<Headquarters> searchByHeadquarters(SearchConditionDepartment searchConditionDepartment) {
return HeadquartersEntity
.createHeadquartersList(
headquartersRepository.findAll(Specification
.where(HeadquartersRepository.idHeadquartersEqual(searchConditionDepartment.getIdDivision()))
.and(HeadquartersRepository.nmHeadquartersEqual(searchConditionDepartment.getNmDivision()))
)
);
}
public List<Department> searchByDepartment(SearchConditionDepartment searchConditionDepartment) {
// 動的に検索条件を絞り込む // 動的に検索条件を絞り込む
// Specification は Criteria API の Predicate をラップしたもの // // Specification は Criteria API //の Predicate をラップしたもの
return DepartmentEntity return DepartmentEntity
.createDepartmentList( .createDepartmentList(
departmentRepository.findAll(Specification departmentRepository.findAll(Specification
.where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment())) .where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDivision()))
.and(DepartmentRepository.nmDepartmentEqual(searchConditionDepartment.getNmDepartment())) .and(DepartmentRepository.nmDepartmentEqual(searchConditionDepartment.getNmDivision()))
)
);
}
public List<Division> searchByDivision(SearchConditionDepartment searchConditionDepartment) {
// 動的に検索条件を絞り込む
// // Specification は Criteria AP//I の Predicate をラップしたもの
return DivisionEntity
.createDivisionList(
divisionRepository.findAll(Specification
.where(DivisionRepository.idDivisionEqual(searchConditionDepartment.getIdDivision()))
.and(DivisionRepository.nmDivisionEqual(searchConditionDepartment.getNmDivision()))
) )
); );
} }
/**
* searchConditionDepartment の情報を元に Department のレコードを取得
* 部分一致検索
*
* @param searchConditionDepartment 検索条件
* @return 検索結果のレコード
*/
public List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment) {
// 動的に検索条件を絞り込む
// Specification は Criteria API の Predicate をラップしたもの
return DepartmentEntity
.createDepartmentList(
departmentRepository.findAll(Specification
.where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
.and(DepartmentRepository.nmDepartmentLike(searchConditionDepartment.getNmDepartment()))
)
);
}
// /**
// * searchConditionDepartment の情報を元に Department のレコードを取得
// * 部分一致検索
// *
// * @param searchConditionDepartment 検索条件
// * @return 検索結果のレコード
// */
// public List<DepartmentInfo> searchByWithLike(SearchConditionDepartment searchConditionDepartment) {
// // 動的に検索条件を絞り込む
// // Specification は Criteria API の Predicate をラップしたもの
// return DepartmentEntity
// .createDepartmentList(
// departmentRepository.findAll(Specification
// .where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
// .and(DepartmentRepository.nmDepartmentLike(searchConditionDepartment.getNmDepartment()))
// )
// );
//
// }
} }

View File

@@ -1,15 +1,16 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import java.util.List;
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.model.Employee;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.service.SearchEmployee; import com.example.rhizome.app.domain.service.SearchEmployee;
import com.example.rhizome.app.infra.entity.EmployeeEntity; import com.example.rhizome.app.infra.entity.EmployeeEntity;
import com.example.rhizome.app.infra.repository.EmployeeRepository; 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;
import java.util.List;
/** /**
* Employee テーブル検索系の機能を集約させるサービスクラスです。 * Employee テーブル検索系の機能を集約させるサービスクラスです。
@@ -64,7 +65,7 @@ public class SearchEmployeeImpl implements SearchEmployee {
* @return Table から取得したレコードの情報 * @return Table から取得したレコードの情報
*/ */
@Override @Override
public List<Employee> searchEmployeeByIdDepartment(Integer idDepartment) { public List<Employee> searchEmployeeByIdDepartment(Integer idDivision) {
return EmployeeEntity.createEmployeeList(employeeRepository.findByIdDepartment(idDepartment)); return EmployeeEntity.createEmployeeList(employeeRepository.findByDivision_idDivision(idDivision));
} }
} }

View File

@@ -1,16 +1,17 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import com.example.rhizome.app.domain.model.EmployeeInfo; import java.util.List;
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
import com.example.rhizome.app.infra.repository.EmployeeInfoRepository;
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;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import com.example.rhizome.app.domain.model.AllEmployeeInfo;
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
import com.example.rhizome.app.infra.repository.EmployeeInfoRepository;
/** /**
* SearchEmployeeInfoImpl (employee join department) 検索系の機能を集約させるサービスクラスです * SearchEmployeeInfoImpl (employee join department) 検索系の機能を集約させるサービスクラスです
@@ -32,9 +33,9 @@ public class SearchEmployeeInfoImpl implements SearchEmployeeInfo {
* *
* @return 取得したレコード全件 * @return 取得したレコード全件
*/ */
public List<EmployeeInfo> selectAll() { public List<AllEmployeeInfo> selectAll() {
return EmployeeDepartmentEntity.createEmployeeInfoList(employeeInfoRepository.findAll()); return EmployeeDepartmentEntity.createEmployeeInfoList(employeeInfoRepository.findAlltable());
} }
@@ -44,17 +45,18 @@ public class SearchEmployeeInfoImpl implements SearchEmployeeInfo {
* @param searchConditionEmployee 検索条件 * @param searchConditionEmployee 検索条件
* @return 検索結果のレコードリスト * @return 検索結果のレコードリスト
*/ */
public List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee) { public List<AllEmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee) {
// 動的に検索条件を絞り込む // 動的に検索条件を絞り込む
// Specification は Criteria API の Predicate をラップしたもの // Specification は Criteria API の Predicate をラップしたもの
return EmployeeDepartmentEntity return EmployeeDepartmentEntity
.createEmployeeInfoList( .AfterSearchCreateEmployeeInfoList(
employeeInfoRepository.findAll(Specification employeeInfoRepository.findAll(Specification
.where(EmployeeInfoRepository.idEmployeeEqual(searchConditionEmployee.getIdEmployee())) .where(EmployeeInfoRepository.idEmployeeEqual(searchConditionEmployee.getIdEmployee()))
.and(EmployeeInfoRepository.nmEmployeeEqual(searchConditionEmployee.getNmEmployee())) .and(EmployeeInfoRepository.nmEmployeeEqual(searchConditionEmployee.getNmEmployee()))
.and(EmployeeInfoRepository.knEmployeeEqual(searchConditionEmployee.getKnEmployee())) .and(EmployeeInfoRepository.knEmployeeEqual(searchConditionEmployee.getKnEmployee()))
.and(EmployeeInfoRepository.mailAddressEqual(searchConditionEmployee.getMailAddress())) .and(EmployeeInfoRepository.mailAddressEqual(searchConditionEmployee.getMailAddress()))
.and(EmployeeInfoRepository.idDepartmentEqual(searchConditionEmployee.getIdDepartment())) .and(EmployeeInfoRepository.idDivisionEqual(searchConditionEmployee.getIdDivision()))
) )
); );

View File

@@ -1,13 +1,14 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
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;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.example.rhizome.app.domain.model.DepartmentInfo;
import com.example.rhizome.app.domain.service.UpdateDepartment;
import com.example.rhizome.app.infra.entity.DepartmentInfoEntity;
import com.example.rhizome.app.infra.repository.DepartmentInfoRepository;
/** /**
* department の更新系の機能を集約させるサービスクラスです。 * department の更新系の機能を集約させるサービスクラスです。
*/ */
@@ -15,11 +16,13 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional @Transactional
public class UpdateDepartmentImpl implements UpdateDepartment { public class UpdateDepartmentImpl implements UpdateDepartment {
DepartmentRepository departmentRepository;
DepartmentInfoRepository departmentInfoRepository;
@Autowired @Autowired
public UpdateDepartmentImpl(DepartmentRepository departmentRepository) { public UpdateDepartmentImpl(DepartmentInfoRepository departmentInfoRepository
this.departmentRepository = departmentRepository; ) {
this.departmentInfoRepository = departmentInfoRepository;
} }
/** /**
@@ -27,9 +30,12 @@ public class UpdateDepartmentImpl implements UpdateDepartment {
* *
* @param department 更新のデータ * @param department 更新のデータ
*/ */
public void updateDepartment(Department department) { public void updateDepartment(DepartmentInfo departmentInfo) {
System.out.println(departmentInfo.getIdDivision());
departmentRepository.save(DepartmentEntity.convertFrom(department)); departmentInfoRepository.save(DepartmentInfoEntity.convertFrom(departmentInfo));
} }
} }

View File

@@ -6,7 +6,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.service.UpdateEmployee; import com.example.rhizome.app.domain.service.UpdateEmployee;
import com.example.rhizome.app.infra.entity.EmployeeEntity; import com.example.rhizome.app.infra.entity.InsertEmployeeEntity;
import com.example.rhizome.app.infra.repository.EmployeeRepository; import com.example.rhizome.app.infra.repository.EmployeeRepository;
/** /**
@@ -31,7 +31,7 @@ public class UpdateEmployeeImpl implements UpdateEmployee {
*/ */
public void updateEmployee(Employee beforeEmployee, Employee updateEmployee) { public void updateEmployee(Employee beforeEmployee, Employee updateEmployee) {
employeeRepository.save(EmployeeEntity.convertFrom(mergeEmployee(beforeEmployee, updateEmployee))); employeeRepository.save(InsertEmployeeEntity.convertFrom(mergeEmployee(beforeEmployee, updateEmployee)));
} }
@@ -54,7 +54,7 @@ public class UpdateEmployeeImpl implements UpdateEmployee {
updateEmployee.getPassword().isBlank() ? beforeEmployee.getPassword() : updateEmployee.getPassword(), updateEmployee.getPassword().isBlank() ? beforeEmployee.getPassword() : updateEmployee.getPassword(),
updateEmployee.getHireDate(), updateEmployee.getHireDate(),
updateEmployee.getAdminAuth() == null ? beforeEmployee.getAdminAuth() : updateEmployee.getAdminAuth(), updateEmployee.getAdminAuth() == null ? beforeEmployee.getAdminAuth() : updateEmployee.getAdminAuth(),
updateEmployee.getIdDepartment() == null ? beforeEmployee.getIdDepartment() : updateEmployee.getIdDepartment() updateEmployee.getIdDivision() == null ? beforeEmployee.getIdDivision() : updateEmployee.getIdDivision()
); );
} }

View File

@@ -7,14 +7,28 @@
package com.example.rhizome.app.infra.entity; package com.example.rhizome.app.infra.entity;
import java.util.List;
import javax.persistence.CascadeType;
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.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.Department;
import com.example.rhizome.app.domain.model.DepartmentInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.List;
/** /**
* Department テーブルの Entity * Department テーブルの Entity
* *
@@ -28,17 +42,26 @@ import java.util.List;
public class DepartmentEntity { public class DepartmentEntity {
/** /**
* 部署ID * 部ID
*/ */
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_department", nullable = false) @Column(name = "id_department", nullable = false)
private Integer idDepartment; private Integer idDepartment;
/** /**
* 部署名 * 部名
*/ */
@Column(name = "nm_department", nullable = false) @Column(name = "nm_department", nullable = false)
private String nmDepartment; private String nmDepartment;
/**
* 表示・非表示フラグ
*/
@Column(name = "is_display", nullable = false)
private Integer isDisplay;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "id_headquarters")
@Fetch(FetchMode.JOIN)
private HeadquartersEntity headquarters;
/** /**
* DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。 * DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。
@@ -53,7 +76,10 @@ public class DepartmentEntity {
.stream() .stream()
.map(departmentEntity -> new Department( .map(departmentEntity -> new Department(
departmentEntity.getIdDepartment(), departmentEntity.getIdDepartment(),
departmentEntity.getNmDepartment() departmentEntity.getNmDepartment(),
departmentEntity.getIsDisplay(),
departmentEntity.getHeadquarters() == null ? null : departmentEntity.getHeadquarters().getIdHeadquarters()
)).toList(); )).toList();
} }
@@ -63,10 +89,16 @@ public class DepartmentEntity {
* @param department department モデルの値 * @param department department モデルの値
* @return DepartmentEntity に変換したインスタンス * @return DepartmentEntity に変換したインスタンス
*/ */
public static DepartmentEntity convertFrom(Department department) { public static DepartmentEntity convertFrom(DepartmentInfo departmentInfo) {
return new DepartmentEntity( return new DepartmentEntity(
department.getIdDepartment(), departmentInfo.getIdDepartment(),
department.getNmDepartment() departmentInfo.getNmDepartment(),
(Integer)0,
new HeadquartersEntity(
departmentInfo.getIdHeadquarters(),
departmentInfo.getNmHeadquarters(),
(Integer)0
)
); );
} }
} }

View File

@@ -2,22 +2,13 @@ package com.example.rhizome.app.infra.entity;
import java.util.List; 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.NamedEntityGraph;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.example.rhizome.app.domain.model.AllEmployeeInfo;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.domain.model.Department;
import com.example.rhizome.app.domain.model.Division;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo; import com.example.rhizome.app.domain.model.Headquarters;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@@ -28,66 +19,23 @@ import lombok.NoArgsConstructor;
* *
* @author IT-College * @author IT-College
*/ */
@Entity
@Table(name = "employee")
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@NamedEntityGraph( @NamedEntityGraph(
name = "employee_with_department", name = "employee_with_division_with_department_with_headquarters",
includeAllAttributes = true includeAllAttributes = true
) )
public class EmployeeDepartmentEntity { public class EmployeeDepartmentEntity {
/** private EmployeeEntity Employee;
* 社員ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_employee", nullable = false)
private Integer idEmployee;
/** private DivisionEntity division;
* 社員名
*/
@Column(name = "nm_employee", nullable = false)
private String nmEmployee;
/**
* 社員名カナ
*/
@Column(name = "kn_employee", nullable = false)
private String knEmployee;
/**
* メールアドレス
*/
@Column(name = "mail_address", nullable = false)
private String mailAddress;
/**
* パスワード
*/
@Column(name = "password", nullable = false)
private String password;
/**
* 入社年月日
*/
@Column(name = "hire_date", nullable = false)
private String hireDate;
/**
* 管理者権限
*/
@Column(name = "admin_auth", nullable = false)
private Integer adminAuth;
@ManyToOne
@JoinColumn(name = "id_department", referencedColumnName = "id_department", insertable = false, updatable = false)
@Fetch(FetchMode.JOIN)
private DepartmentEntity department; private DepartmentEntity department;
private HeadquartersEntity headquarters;
/** /**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。 * EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。
@@ -95,24 +43,49 @@ public class EmployeeDepartmentEntity {
* @param employeeDepartmentEntity  EmployeeDepartmentEntity のインスタンス * @param employeeDepartmentEntity  EmployeeDepartmentEntity のインスタンス
* @return EmployeeInfo のインスタンス * @return EmployeeInfo のインスタンス
*/ */
public static EmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) { public static AllEmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) {
// コンストラクタを使って書くとSetterを使用するより簡略化出来ます。 // コンストラクタを使って書くとSetterを使用するより簡略化出来ます。
// 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、 // 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、
// どうしてこの書き方が出来るのかを理解できる様になりましょう。 // どうしてこの書き方が出来るのかを理解できる様になりましょう。
return new EmployeeInfo( return new AllEmployeeInfo(
new Employee( new Employee(
employeeDepartmentEntity.getIdEmployee(), employeeDepartmentEntity.getEmployee().getIdEmployee(),
employeeDepartmentEntity.getNmEmployee(), employeeDepartmentEntity.getEmployee().getNmEmployee(),
employeeDepartmentEntity.getKnEmployee(), employeeDepartmentEntity.getEmployee().getKnEmployee(),
employeeDepartmentEntity.getMailAddress(), employeeDepartmentEntity.getEmployee().getMailAddress(),
employeeDepartmentEntity.getPassword(), employeeDepartmentEntity.getEmployee().getPassword(),
employeeDepartmentEntity.getHireDate(), employeeDepartmentEntity.getEmployee().getHireDate(),
employeeDepartmentEntity.getAdminAuth(), employeeDepartmentEntity.getEmployee().getAdminAuth(),
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment() ), employeeDepartmentEntity.getDivision()
== null ? null : employeeDepartmentEntity.getDivision().getIdDivision()),
new Division(
employeeDepartmentEntity.getDivision()
== null ? null : employeeDepartmentEntity.getDivision().getIdDivision(),
employeeDepartmentEntity.getDivision()
== null ? null : employeeDepartmentEntity.getDivision().getNmDivision(),
employeeDepartmentEntity.getDivision()
== null ? null : employeeDepartmentEntity.getDivision().getIsDisplay(),
employeeDepartmentEntity.getDepartment()
== null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment()
),
new Department( new Department(
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment(), employeeDepartmentEntity.getDepartment()
employeeDepartmentEntity.getDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getNmDepartment() == null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment(),
employeeDepartmentEntity.getDepartment()
== null ? null : employeeDepartmentEntity.getDepartment().getNmDepartment(),
employeeDepartmentEntity.getDepartment()
== null ? null : employeeDepartmentEntity.getDepartment().getIsDisplay(),
employeeDepartmentEntity.getHeadquarters()
== null ? null : employeeDepartmentEntity.getHeadquarters().getIdHeadquarters()
),
new Headquarters(
employeeDepartmentEntity.getHeadquarters()
== null ? null : employeeDepartmentEntity.getHeadquarters().getIdHeadquarters(),
employeeDepartmentEntity.getHeadquarters()
== null ? null : employeeDepartmentEntity.getHeadquarters().getNmHeadquarters(),
employeeDepartmentEntity.getHeadquarters()
== null ? null : employeeDepartmentEntity.getHeadquarters().getIsDisplay()
) )
); );
@@ -125,12 +98,66 @@ public class EmployeeDepartmentEntity {
* @param employeeDepartmentEntityList EmployeeDepartmentEntity インスタンスのリスト * @param employeeDepartmentEntityList EmployeeDepartmentEntity インスタンスのリスト
* @return EmployeeInfo インスタンスのリスト * @return EmployeeInfo インスタンスのリスト
*/ */
public static List<EmployeeInfo> createEmployeeInfoList(List<EmployeeDepartmentEntity> employeeDepartmentEntityList) { public static List<AllEmployeeInfo> createEmployeeInfoList(List<EmployeeDepartmentEntity> employeeDepartmentEntityList) {
// StreamAPI を使うとこうなります。 // StreamAPI を使うとこうなります。
return employeeDepartmentEntityList.stream().map(EmployeeDepartmentEntity::createEmployeeInfo).toList(); return employeeDepartmentEntityList.stream().map(EmployeeDepartmentEntity::createEmployeeInfo).toList();
} }
public static AllEmployeeInfo createEmployeeInfo(EmployeeEntity employeeEntity) {
// コンストラクタを使って書くとSetterを使用するより簡略化出来ます。
// 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、
// どうしてこの書き方が出来るのかを理解できる様になりましょう。
return new AllEmployeeInfo(
new Employee(
employeeEntity.getIdEmployee(),
employeeEntity.getNmEmployee(),
employeeEntity.getKnEmployee(),
employeeEntity.getMailAddress(),
employeeEntity.getPassword(),
employeeEntity.getHireDate(),
employeeEntity.getAdminAuth(),
employeeEntity.getDivision()
== null ? null : employeeEntity.getDivision().getIdDivision()),
new Division(
employeeEntity.getDivision()
== null ? null : employeeEntity.getDivision().getIdDivision(),
employeeEntity.getDivision()
== null ? null : employeeEntity.getDivision().getNmDivision(),
employeeEntity.getDivision()
== null ? null : employeeEntity.getDivision().getIsDisplay(),
employeeEntity.getDivision().getDepartment()
== null ? null : employeeEntity.getDivision().getDepartment().getIdDepartment()
),
new Department(
employeeEntity.getDivision().getDepartment()
== null ? null : employeeEntity.getDivision().getDepartment().getIdDepartment(),
employeeEntity.getDivision().getDepartment()
== null ? null : employeeEntity.getDivision().getDepartment().getNmDepartment(),
employeeEntity.getDivision().getDepartment()
== null ? null : employeeEntity.getDivision().getDepartment().getIsDisplay(),
employeeEntity.getDivision().getDepartment().getHeadquarters()
== null ? null : employeeEntity.getDivision().getDepartment().getHeadquarters().getIdHeadquarters()
),
new Headquarters(
employeeEntity.getDivision().getDepartment().getHeadquarters()
== null ? null : employeeEntity.getDivision().getDepartment().getHeadquarters().getIdHeadquarters(),
employeeEntity.getDivision().getDepartment().getHeadquarters()
== null ? null : employeeEntity.getDivision().getDepartment().getHeadquarters().getNmHeadquarters(),
employeeEntity.getDivision().getDepartment().getHeadquarters()
== null ? null : employeeEntity.getDivision().getDepartment().getHeadquarters().getIsDisplay()
)
);
}
public static List<AllEmployeeInfo> AfterSearchCreateEmployeeInfoList(List<EmployeeEntity> employeeEntityList) {
// StreamAPI を使うとこうなります。
return employeeEntityList.stream().map(EmployeeDepartmentEntity::createEmployeeInfo).toList();
}
} }

View File

@@ -14,9 +14,15 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
@@ -82,9 +88,10 @@ public class EmployeeEntity {
/** /**
* 部署ID * 部署ID
*/ */
@Column(name = "id_department", nullable = false) @ManyToOne
private Integer idDepartment; @JoinColumn(name = "id_division")
@Fetch(FetchMode.JOIN)
private DivisionEntity division;
/** /**
@@ -93,17 +100,21 @@ public class EmployeeEntity {
* @param employee Employee Table の中身 * @param employee Employee Table の中身
* @return EmployeeEntity のインスタンス(1レコード分) * @return EmployeeEntity のインスタンス(1レコード分)
*/ */
public static EmployeeEntity convertFrom(Employee employee) { public static EmployeeEntity convertFrom(EmployeeInfo employeeInfo) {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。 // 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return new EmployeeEntity( return new EmployeeEntity(
employee.getIdEmployee(), employeeInfo.getEmployee().getIdEmployee(),
employee.getNmEmployee(), employeeInfo.getEmployee().getNmEmployee(),
employee.getKnEmployee(), employeeInfo.getEmployee().getKnEmployee(),
employee.getMailAddress(), employeeInfo.getEmployee().getMailAddress(),
employee.getPassword(), employeeInfo.getEmployee().getPassword(),
employee.getHireDate(), employeeInfo.getEmployee().getHireDate(),
employee.getAdminAuth(), employeeInfo.getEmployee().getAdminAuth(),
employee.getIdDepartment() new DivisionEntity(
employeeInfo.getDivision().getIdDivision(),
employeeInfo.getDivision().getNmDivision(),
employeeInfo.getDivision().getIsDisplay(),
null)
); );
} }
@@ -121,8 +132,6 @@ public class EmployeeEntity {
employeeEntity.setNmEmployee(searchConditionEmployee.getNmEmployee()); employeeEntity.setNmEmployee(searchConditionEmployee.getNmEmployee());
employeeEntity.setKnEmployee(searchConditionEmployee.getKnEmployee()); employeeEntity.setKnEmployee(searchConditionEmployee.getKnEmployee());
employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress()); employeeEntity.setMailAddress(searchConditionEmployee.getMailAddress());
employeeEntity.setIdDepartment(searchConditionEmployee.getIdDepartment());
return employeeEntity; return employeeEntity;
@@ -144,7 +153,7 @@ public class EmployeeEntity {
employeeEntity.getPassword(), employeeEntity.getPassword(),
employeeEntity.getHireDate(), employeeEntity.getHireDate(),
employeeEntity.getAdminAuth(), employeeEntity.getAdminAuth(),
employeeEntity.getIdDepartment() employeeEntity.getDivision().getIdDivision()
); );
} }
@@ -182,8 +191,10 @@ public class EmployeeEntity {
getMailAddress(), getMailAddress(),
getPassword(), getPassword(),
getAdminAuth(), getAdminAuth(),
getIdDepartment() getDivision().getIdDivision()
); );
} }
} }

View File

@@ -1,11 +1,12 @@
package com.example.rhizome.app.infra.repository; package com.example.rhizome.app.infra.repository;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
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;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.DepartmentEntity;
/** /**
* Specification: * Specification:
@@ -47,4 +48,10 @@ public interface DepartmentRepository extends JpaRepository<DepartmentEntity, In
(Specification<DepartmentEntity>) (Specification<DepartmentEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), "%" + nmDepartment + "%"); (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), "%" + nmDepartment + "%");
} }
} }

View File

@@ -1,11 +1,18 @@
package com.example.rhizome.app.infra.repository; package com.example.rhizome.app.infra.repository;
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity; import java.util.List;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.EntityGraph;
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;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
import com.example.rhizome.app.infra.entity.EmployeeEntity;
/** /**
* ワンポイント情報(ここで登場する関数型インターフェース Specification について解説します) * ワンポイント情報(ここで登場する関数型インターフェース Specification について解説します)
* Specification: * Specification:
@@ -20,42 +27,59 @@ import org.springframework.stereotype.Repository;
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。 * 戻り値はクエリを格納しているPredicateオブジェクトとなります。
*/ */
@Repository @Repository
public interface EmployeeInfoRepository extends JpaRepository<EmployeeDepartmentEntity, Integer>, JpaSpecificationExecutor<EmployeeDepartmentEntity> { public interface EmployeeInfoRepository extends JpaRepository<EmployeeEntity, Integer>, JpaSpecificationExecutor<EmployeeEntity> {
static Specification<EmployeeDepartmentEntity> idEmployeeEqual(Integer idEmployee) { static Specification<EmployeeEntity> idEmployeeEqual(Integer idEmployee) {
return idEmployee == null ? return idEmployee == null ?
null : null :
// 戻り値の型 Specification<EmployeeDepartmentEntity> にキャスト // 戻り値の型 Specification<EmployeeDepartmentEntity> にキャスト
(Specification<EmployeeDepartmentEntity>) (Specification<EmployeeEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idEmployee' = idEmployee(変数)" // ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idEmployee' = idEmployee(変数)"
// を作成している // を作成している
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idEmployee"), idEmployee); (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idEmployee"), idEmployee);
} }
static Specification<EmployeeDepartmentEntity> nmEmployeeEqual(String nmEmployee) { static Specification<EmployeeEntity> nmEmployeeEqual(String nmEmployee) {
return (nmEmployee == null || nmEmployee.isEmpty()) ? return (nmEmployee == null || nmEmployee.isEmpty()) ?
null : null :
(Specification<EmployeeDepartmentEntity>) (Specification<EmployeeEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmEmployee"), "%" + nmEmployee + "%"); (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmEmployee"), "%" + nmEmployee + "%");
} }
static Specification<EmployeeDepartmentEntity> knEmployeeEqual(String knEmployee) { static Specification<EmployeeEntity> knEmployeeEqual(String knEmployee) {
return (knEmployee == null || knEmployee.isEmpty()) ? return (knEmployee == null || knEmployee.isEmpty()) ?
null : null :
(Specification<EmployeeDepartmentEntity>) (Specification<EmployeeEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("knEmployee"), "%" + knEmployee + "%"); (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("knEmployee"), "%" + knEmployee + "%");
} }
static Specification<EmployeeDepartmentEntity> mailAddressEqual(String mailAddress) { static Specification<EmployeeEntity> mailAddressEqual(String mailAddress) {
return (mailAddress == null || mailAddress.isEmpty()) ? return (mailAddress == null || mailAddress.isEmpty()) ?
null : null :
(Specification<EmployeeDepartmentEntity>) (Specification<EmployeeEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("mailAddress"), "%" + mailAddress + "%"); (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("mailAddress"), "%" + mailAddress + "%");
} }
static Specification<EmployeeDepartmentEntity> idDepartmentEqual(Integer idDepartment) { static Specification<EmployeeEntity> idDivisionEqual(Integer idDivision) {
return (root, query, criteriaBuilder) -> return (root, query, criteriaBuilder) ->
idDepartment == null ? null : idDivision == null ? null :
criteriaBuilder.equal(root.join("department").get("idDepartment"), idDepartment); criteriaBuilder.equal(root.join("division").get("idDivision"), idDivision);
} }
@Query("SELECT DISTINCT new com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity(e,di,de,h)FROM EmployeeEntity e "
+ "INNER JOIN e.division di "
+ "INNER JOIN di.department de "
+ "INNER JOIN de.headquarters h ")
List<EmployeeDepartmentEntity> findAlltable();
// @Query("SELECT DISTINCT new com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity(e,di,de,h)FROM EmployeeEntity e "
// + "INNER JOIN e.division di "
// + "INNER JOIN di.department de "
// + "INNER JOIN de.headquarters h "
// + "WHERE (:idEmployee IS NULL OR e.idEmployee = idEmployee) "
// + "AND (:nmEmployee IS NULL OR e.nmEmployee LIKE %nmEmployee%) "
// + "AND(:knEmployee IS NULL OR e.knEmployee LIKE %knEmployee%) "
// + "AND(:mailAddress IS NULL OR e.mailAddress Like %mailAddress%) "
// +"AND(:idDivision IS NULL OR e.idDivision LIKE %idDivision%)")
@EntityGraph(attributePaths = {"division", "division.department", "division.department.headquarters"})
List<EmployeeEntity> findAll(@Nullable Specification<EmployeeEntity> spec);
} }

View File

@@ -1,12 +1,14 @@
package com.example.rhizome.app.infra.repository; package com.example.rhizome.app.infra.repository;
import com.example.rhizome.app.infra.entity.EmployeeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.EmployeeEntity;
import com.example.rhizome.app.infra.entity.InsertEmployeeEntity;
@Repository @Repository
public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Integer> { public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Integer> {
Optional<EmployeeEntity> findByMailAddressAndPassword(String mailAddress, String password); Optional<EmployeeEntity> findByMailAddressAndPassword(String mailAddress, String password);
@@ -24,5 +26,7 @@ public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Intege
/** /**
* IDで検索 * IDで検索
**/ **/
List<EmployeeEntity> findByIdDepartment(Integer idDepartment); List<EmployeeEntity> findByDivision_idDivision(Integer idDivision);
void save(InsertEmployeeEntity insertEmployeeEntity);
} }

View File

@@ -1,6 +1,20 @@
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.beans.factory.annotation.Autowired;
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.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.DeleteDepartment; import com.example.rhizome.app.domain.service.DeleteDepartment;
@@ -10,18 +24,6 @@ import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAt
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm; import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.DELETE_DEPARTMENT;
/** /**
* 削除処理のコントロータ * 削除処理のコントロータ
@@ -63,18 +65,20 @@ public class DeleteDepartmentController {
@PermissionCheck @PermissionCheck
@SessionCheck @SessionCheck
@RequestMapping(value = DELETE_DEPARTMENT, method = RequestMethod.POST) @RequestMapping(value = DELETE_DEPARTMENT, method = RequestMethod.POST)
public String deleteEmployee(@RequestParam("idDepartment") Integer idDepartment, Model model) { public String deleteEmployee(@RequestParam("idDivision") Integer idDivision, Model model) {
try { try {
// 削除処理実施 // 削除処理実施
deleteExec(model, idDepartment); deleteExec(model, idDivision);
// 部署一覧を取得し、画面に返す用のクラスに詰め替える // 部署一覧を取得し、画面に返す用のクラスに詰め替える
// 作成した部署一覧をセット // 作成した部署一覧をセット
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()) DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()
)
); );
// 検索画面に遷移 // 検索画面に遷移
@@ -98,13 +102,13 @@ public class DeleteDepartmentController {
* @param model ビューにデータを渡すためのコンテナ * @param model ビューにデータを渡すためのコンテナ
* @param idDepartment 削除対象のidDepartment * @param idDepartment 削除対象のidDepartment
*/ */
private void deleteExec(Model model, Integer idDepartment) { private void deleteExec(Model model, Integer idDivision) {
final String DELETE_TARGET_ID_CAN_NOT_DELETE = "1名以上が所属している部署は削除出来ません。"; final String DELETE_TARGET_ID_CAN_NOT_DELETE = "1名以上が所属している部署は削除出来ません。";
final String DELETE_COMPLETE = "削除しました。"; final String DELETE_COMPLETE = "削除しました。";
// 1名上所属している人が居れば削除不可 // 1名上所属している人が居れば削除不可
if (!searchEmployee.searchEmployeeByIdDepartment(idDepartment).isEmpty()) { if (!searchEmployee.searchEmployeeByIdDepartment(idDivision).isEmpty()) {
// 削除対象だった場合 // 削除対象だった場合
// エラーメッセージをセット // エラーメッセージをセット
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DELETE_TARGET_ID_CAN_NOT_DELETE)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DELETE_TARGET_ID_CAN_NOT_DELETE));
@@ -113,7 +117,7 @@ public class DeleteDepartmentController {
} }
// 削除を実施 // 削除を実施
deleteDepartment.deleteDepartment(idDepartment); deleteDepartment.deleteDepartment(idDivision);
// 削除完了したメッセージをセット // 削除完了したメッセージをセット
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(DELETE_COMPLETE)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(DELETE_COMPLETE));

View File

@@ -1,6 +1,21 @@
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.Objects;
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.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.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
@@ -12,19 +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.DepartmentForm;
import com.example.rhizome.app.presentation.form.LoginUserForm; import com.example.rhizome.app.presentation.form.LoginUserForm;
import com.example.rhizome.app.presentation.form.MessageForm; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.DELETE_EMPLOYEE;
/** /**
* 削除処理のコントロータ * 削除処理のコントロータ
@@ -66,7 +68,8 @@ public class DeleteEmployeeController {
// 作成した部署一覧をセット // 作成した部署一覧をセット
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()) DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable())
); );
// 削除処理実施 // 削除処理実施

View File

@@ -1,5 +1,19 @@
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.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.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.SearchConditionDepartment; import com.example.rhizome.app.domain.model.SearchConditionDepartment;
@@ -7,21 +21,9 @@ import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.impl.SearchDepartmentImpl; import com.example.rhizome.app.domain.service.impl.SearchDepartmentImpl;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.InsertDepartmentForm; import com.example.rhizome.app.presentation.form.InsertDepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm; 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.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_CONFIRM;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML;
/** /**
* 新規部署情報チェック用のコントローラ * 新規部署情報チェック用のコントローラ
@@ -64,10 +66,15 @@ public class InsertDepartmentConfirmController {
@RequestMapping(value = INSERT_DEPARTMENT_CONFIRM, method = RequestMethod.POST) @RequestMapping(value = INSERT_DEPARTMENT_CONFIRM, method = RequestMethod.POST)
public String insertDepartmentConfirm(InsertDepartmentForm insertDepartmentForm, Model model) { public String insertDepartmentConfirm(InsertDepartmentForm insertDepartmentForm, Model model) {
final String DUPLICATION = "既に同名の部署が存在します。"; final String DUPLICATION = "既に同名の本部名または部または課が存在します。";
final String IRREGULARITY = "部署名が不正です。"; final String IRREGULARITY = "本部名または部または課が不正です。";
try { try {
model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable())
);
// 入力内容に誤りがあるか // 入力内容に誤りがあるか
if (insertDepartmentForm.haveNmDepartment()) { if (insertDepartmentForm.haveNmDepartment()) {
@@ -79,12 +86,22 @@ public class InsertDepartmentConfirmController {
// 登録画面に遷移 // 登録画面に遷移
return INSERT_DEPARTMENT_INPUT_HTML; return INSERT_DEPARTMENT_INPUT_HTML;
} }
// 部署名で重複が無いかチェック
if (!searchDepartment.searchBy(
new SearchConditionDepartment(
null,
insertDepartmentForm.getNmDepartment())).isEmpty()) {
SearchConditionDepartment searchHeadquartersTable =new SearchConditionDepartment(
null,
insertDepartmentForm.getNmHeadquarters());
SearchConditionDepartment searchDepartmentTable = new SearchConditionDepartment(
null,
insertDepartmentForm.getNmDepartment());
SearchConditionDepartment searchDivisionTable = new SearchConditionDepartment(
null,
insertDepartmentForm.getNmDivision());
// 部署名で重複が無いかチェック
if (searchDepartment.searchAllDepartmentTable(
searchHeadquartersTable,
searchDepartmentTable,
searchDivisionTable)){
// 存在する場合はエラーメッセージを設定して更新入力画面に遷移 // 存在する場合はエラーメッセージを設定して更新入力画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));

View File

@@ -1,15 +1,12 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import com.example.rhizome.aop.aspect.PermissionCheck; import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.SearchConditionDepartment; import java.util.logging.Level;
import com.example.rhizome.app.domain.service.RegisterDepartment; import java.util.logging.Logger;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; import javax.servlet.http.HttpSession;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.InsertDepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@@ -17,12 +14,18 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpSession; import com.example.rhizome.aop.aspect.PermissionCheck;
import java.util.logging.Level; import com.example.rhizome.aop.aspect.SessionCheck;
import java.util.logging.Logger; import com.example.rhizome.app.domain.model.DepartmentInfo;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_DEPARTMENT; import com.example.rhizome.app.domain.service.RegisterDepartment;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.infra.entity.DivisionEntity;
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.InsertDepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm;
/** /**
* 新規登録用のコントローラ * 新規登録用のコントローラ
@@ -73,7 +76,7 @@ public class InsertDepartmentController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.selectAll() searchDepartment.searchAllDepartmentTable()
)); ));
// 入力内容に誤りがあるか // 入力内容に誤りがあるか
@@ -87,10 +90,18 @@ public class InsertDepartmentController {
return INSERT_DEPARTMENT_INPUT_HTML; return INSERT_DEPARTMENT_INPUT_HTML;
} }
// 部署名で重複が無いかチェック // 部署名で重複が無いかチェック
if (!searchDepartment.searchBy( if (!searchDepartment.searchByHeadquarters(
new SearchConditionDepartment( new SearchConditionDepartment(
null, null,
insertDepartmentForm.getNmDepartment())).isEmpty()) { insertDepartmentForm.getNmHeadquarters())).isEmpty()
&&!searchDepartment.searchByDepartment(
new SearchConditionDepartment(
null,
insertDepartmentForm.getNmDepartment())).isEmpty()
&&!searchDepartment.searchByDivision(
new SearchConditionDepartment(
null,
insertDepartmentForm.getNmDivision())).isEmpty()) {
// 存在する場合はエラーメッセージを設定して更新入力画面に遷移 // 存在する場合はエラーメッセージを設定して更新入力画面に遷移
@@ -99,9 +110,14 @@ public class InsertDepartmentController {
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML;
} }
DepartmentInfo departmentInfo = InsertDepartmentForm.convertTo(insertDepartmentForm);
DivisionEntity divisionEntity = DivisionEntity.convertFrom(departmentInfo);
System.out.println(divisionEntity);
// 登録処理 // 登録処理
registerDepartment.registerDepartment(InsertDepartmentForm.convertTo(insertDepartmentForm)); registerDepartment.registerDepartment(divisionEntity);
// 登録結果画面に遷移 // 登録結果画面に遷移
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_RESULT_HTML; return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_RESULT_HTML;

View File

@@ -1,11 +1,10 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import com.example.rhizome.aop.aspect.PermissionCheck; import java.util.logging.Level;
import com.example.rhizome.aop.aspect.SessionCheck; import java.util.logging.Logger;
import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword; import javax.servlet.http.HttpSession;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.InsertDepartmentForm;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@@ -13,9 +12,13 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpSession; import com.example.rhizome.aop.aspect.PermissionCheck;
import java.util.logging.Level; import com.example.rhizome.aop.aspect.SessionCheck;
import java.util.logging.Logger; 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.InsertDepartmentForm;
/** /**
* 登録画面表示用コントローラ * 登録画面表示用コントローラ
@@ -60,6 +63,11 @@ public class InsertDepartmentInputController {
public String insertInput(InsertDepartmentForm insertDepartmentForm, Model model) { public String insertInput(InsertDepartmentForm insertDepartmentForm, Model model) {
try { try {
model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable())
);
// パラメータをセット // パラメータをセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm); model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm);

View File

@@ -1,5 +1,20 @@
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.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.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
@@ -12,19 +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.DepartmentForm;
import com.example.rhizome.app.presentation.form.InsertEmployeeForm; import com.example.rhizome.app.presentation.form.InsertEmployeeForm;
import com.example.rhizome.app.presentation.form.MessageForm; 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.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_CONFIRM;
/** /**
* 新規登録者情報チェック用のコントローラ * 新規登録者情報チェック用のコントローラ
@@ -76,7 +78,7 @@ public class InsertEmployeeConfirmController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.selectAll() searchDepartment.searchAllDepartmentTable()
)); ));
// 登録用パラメータチェック // 登録用パラメータチェック

View File

@@ -74,7 +74,7 @@ public class InsertEmployeeController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.selectAll() searchDepartment.searchAllDepartmentTable()
)); ));
// Confirm画面から渡ってきた値をチェック // Confirm画面から渡ってきた値をチェック
@@ -85,7 +85,7 @@ public class InsertEmployeeController {
insertEmployeeForm.getPassword(), insertEmployeeForm.getPassword(),
insertEmployeeForm.getHireDate(), insertEmployeeForm.getHireDate(),
insertEmployeeForm.getAdminAuth(), insertEmployeeForm.getAdminAuth(),
insertEmployeeForm.getIdDepartment() insertEmployeeForm.getIdDivision()
); );
// エラーが1件以上有る場合 // エラーが1件以上有る場合

View File

@@ -1,5 +1,19 @@
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.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.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.RegisterEmployee; import com.example.rhizome.app.domain.service.RegisterEmployee;
@@ -8,18 +22,6 @@ import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAt
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.DepartmentForm; import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.InsertEmployeeForm; import com.example.rhizome.app.presentation.form.InsertEmployeeForm;
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.logging.Level;
import java.util.logging.Logger;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT;
/** /**
* 登録画面表示用コントローラ * 登録画面表示用コントローラ
@@ -64,7 +66,9 @@ public class InsertEmployeeInputController {
try { try {
// 部署コードリストを作成し、画面に返す値としてセット // 部署コードリストを作成し、画面に返す値としてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll())); model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST
, DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()));
// パラメータをセット // パラメータをセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm); model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);

View File

@@ -62,8 +62,10 @@ public class SelectDepartmentController {
// 作成した部署一覧をセット // 作成した部署一覧をセット
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.searchBy(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm))) DepartmentForm.convertFrom(
); searchDepartment.searchAllDepartmentTable(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm))
));
// 検索ページに遷移 // 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
@@ -94,12 +96,13 @@ public class SelectDepartmentController {
public String selectAll(Model model) { public String selectAll(Model model) {
try { try {
// 部署一覧を取得し、画面に返す用のクラスに詰め替える // 部署一覧を取得し、画面に返す用のクラスに詰め替える
// 作成した部署一覧をセット // 作成した部署一覧をセット
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()) DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()
)
); );
// 検索ページに遷移 // 検索ページに遷移

View File

@@ -70,20 +70,21 @@ public class SelectEmployeeController {
// 作成した部署一覧をセット // 作成した部署一覧をセット
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()) DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable())
); );
// 検索条件を元に検索を実施 // 検索条件を元に検索を実施
// 取得した EmployeeInfo( employee + department )の情報を画面に返す用の型に詰め替えてセット // 取得した EmployeeInfo( employee + department )の情報を画面に返す用の型に詰め替えてセット
List<EmployeeInfoForm>employeeInfoForm = EmployeeInfoForm.convertFrom(searchEmployeeInfo.searchBy(SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm))); List<EmployeeInfoForm>employeeInfoForm = EmployeeInfoForm.convertFrom(searchEmployeeInfo.searchBy(SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm)));
for(EmployeeInfoForm form:employeeInfoForm) { for(EmployeeInfoForm form:employeeInfoForm) {
String tenure = tenureCalc.tenureCalc(form.getHireDate()); String tenure = tenureCalc.tenureCalc(form.getHireDate());
form.setTenure(tenure); form.setTenure(tenure);
} }
model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, employeeInfoForm); model.addAttribute(PageReturnAttributeKeyword.EMPLOYEE_INFO_FORM_LIST, employeeInfoForm);
// 検索ページに遷移 // 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_HTML; return TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_HTML;
@@ -117,14 +118,13 @@ public class SelectEmployeeController {
// 作成した部署一覧をセット // 作成した部署一覧をセット
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom(searchDepartment.selectAll()) DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable())
); );
// 検索条件を元に検索を実施 // 検索条件を元に検索を実施
List<EmployeeInfoForm>employeeInfoForm =EmployeeInfoForm.convertFrom( List<EmployeeInfoForm>employeeInfoForm =EmployeeInfoForm.convertFrom(
searchEmployeeInfo.searchBy( searchEmployeeInfo.selectAll());
SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm())
));
for(EmployeeInfoForm form:employeeInfoForm) { for(EmployeeInfoForm form:employeeInfoForm) {
String tenure = tenureCalc.tenureCalc(form.getHireDate()); String tenure = tenureCalc.tenureCalc(form.getHireDate());
form.setTenure(tenure); form.setTenure(tenure);

View File

@@ -1,15 +1,11 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import com.example.rhizome.aop.aspect.PermissionCheck; import java.util.List;
import com.example.rhizome.aop.aspect.SessionCheck; import java.util.logging.Level;
import com.example.rhizome.app.domain.model.Department; import java.util.logging.Logger;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.service.SearchEmployeeInfo; import javax.servlet.http.HttpSession;
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.SearchConditionEmployeeForm;
import com.example.rhizome.app.presentation.form.UpdateDepartmentForm;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@@ -18,10 +14,16 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession; import com.example.rhizome.aop.aspect.PermissionCheck;
import java.util.List; import com.example.rhizome.aop.aspect.SessionCheck;
import java.util.logging.Level; import com.example.rhizome.app.domain.model.AllDepartmentInfo;
import java.util.logging.Logger; import com.example.rhizome.app.domain.model.SearchConditionDepartment;
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.MessageForm;
import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm;
import com.example.rhizome.app.presentation.form.UpdateDepartmentForm;
/** /**
* 更新対象の Department が存在するか確認する為のコントローラ * 更新対象の Department が存在するか確認する為のコントローラ
@@ -59,24 +61,24 @@ public class UpdateDepartmentController {
@PermissionCheck @PermissionCheck
@SessionCheck @SessionCheck
@RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_DEPARTMENT, method = RequestMethod.POST) @RequestMapping(value = TransitionTargetPageNameKeyword.SHOW_UPDATE_DEPARTMENT, method = RequestMethod.POST)
public String showUpdateEmployee(@RequestParam("idDepartment") Integer idDepartment, Model model) { public String showUpdateEmployee(@RequestParam("idDivision") Integer idDivision, Model model) {
final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。"; final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。";
try { try {
// id を条件に更新対象のレコードを検索、取得する // id を条件に更新対象のレコードを検索、取得する
List<Department> departmentList = searchDepartment.searchBy( List<AllDepartmentInfo>divisionList = searchDepartment.searchAllDepartmentTable(
new SearchConditionDepartment(idDepartment, new SearchConditionDepartment(idDivision,
null)); null));
// DBに更新対象のデータがあるか // DBに更新対象のデータがあるか
if (departmentList.isEmpty()) { if (divisionList.isEmpty()) {
// ない場合はエラーメッセージをセットして検索画面に戻る // ない場合はエラーメッセージをセットして検索画面に戻る
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(UPDATE_TARGET_ID_NOT_FOUND)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(UPDATE_TARGET_ID_NOT_FOUND));
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;
} }
// 更新画面に表示する値をセット // 更新画面に表示する値をセット
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, UpdateDepartmentForm.convertFrom(departmentList.get(0))); model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, UpdateDepartmentForm.convertFrom(divisionList.get(0)));
// Update画面に遷移 // Update画面に遷移
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;

View File

@@ -1,6 +1,18 @@
package com.example.rhizome.app.presentation.controller; 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.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.SearchConditionDepartment; import com.example.rhizome.app.domain.model.SearchConditionDepartment;
@@ -11,16 +23,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.DepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm; import com.example.rhizome.app.presentation.form.MessageForm;
import com.example.rhizome.app.presentation.form.UpdateDepartmentForm; import com.example.rhizome.app.presentation.form.UpdateDepartmentForm;
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.logging.Level;
import java.util.logging.Logger;
/** /**
* department を更新して結果を返す為のコントローラ * department を更新して結果を返す為のコントローラ
@@ -37,6 +39,7 @@ public class UpdateDepartmentResultController {
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
UpdateDepartment updateDepartment; UpdateDepartment updateDepartment;
@Autowired @Autowired
public UpdateDepartmentResultController(HttpSession httpSession, SearchDepartment searchDepartment, UpdateDepartment updateDepartment) { public UpdateDepartmentResultController(HttpSession httpSession, SearchDepartment searchDepartment, UpdateDepartment updateDepartment) {
this.httpSession = httpSession; this.httpSession = httpSession;
@@ -62,7 +65,9 @@ public class UpdateDepartmentResultController {
try { try {
// 更新対象の部署データがない // 更新対象の部署データがない
if (updateDepartmentForm.getNmDepartment().isBlank()) { if (updateDepartmentForm.getNmHeadquarters().isBlank()||
updateDepartmentForm.getNmDepartment().isBlank()||
updateDepartmentForm.getNmDivision().isBlank()) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(NOTHING));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm); model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm);
@@ -70,10 +75,18 @@ public class UpdateDepartmentResultController {
} }
// 部署名で重複が無いかチェック // 部署名で重複が無いかチェック
if (!searchDepartment.searchBy( if (!searchDepartment.searchByHeadquarters(
new SearchConditionDepartment( new SearchConditionDepartment(
null, null,
updateDepartmentForm.getNmDepartment())).isEmpty()) { updateDepartmentForm.getNmHeadquarters())).isEmpty()||
!searchDepartment.searchByDepartment(
new SearchConditionDepartment(
null,
updateDepartmentForm.getNmDepartment())).isEmpty()||
!searchDepartment.searchByDivision(
new SearchConditionDepartment(
null,
updateDepartmentForm.getNmDivision())).isEmpty()) {
// 存在する場合はエラーメッセージを設定して更新入力画面に遷移 // 存在する場合はエラーメッセージを設定して更新入力画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm); model.addAttribute(PageReturnAttributeKeyword.UPDATE_DEPARTMENT_FORM, updateDepartmentForm);
@@ -85,7 +98,9 @@ public class UpdateDepartmentResultController {
updateDepartment.updateDepartment(UpdateDepartmentForm.convertTo(updateDepartmentForm)); updateDepartment.updateDepartment(UpdateDepartmentForm.convertTo(updateDepartmentForm));
// 部署一覧取得 // 部署一覧取得
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll())); model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable())
);
// 更新結果のメッセージを画面にセットし一覧画面に遷移 // 更新結果のメッセージを画面にセットし一覧画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE));

View File

@@ -1,8 +1,22 @@
package com.example.rhizome.app.presentation.controller; 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.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.EmployeeInfo; import com.example.rhizome.app.domain.model.AllEmployeeInfo;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import com.example.rhizome.app.domain.service.SearchDepartment; import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.SearchEmployeeInfo; import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
@@ -12,18 +26,6 @@ import com.example.rhizome.app.presentation.form.DepartmentForm;
import com.example.rhizome.app.presentation.form.MessageForm; import com.example.rhizome.app.presentation.form.MessageForm;
import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm; import com.example.rhizome.app.presentation.form.SearchConditionEmployeeForm;
import com.example.rhizome.app.presentation.form.UpdateEmployeeInfoForm; import com.example.rhizome.app.presentation.form.UpdateEmployeeInfoForm;
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 javax.servlet.http.HttpSession;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* 更新対象の employee が存在するか確認する為のコントローラ * 更新対象の employee が存在するか確認する為のコントローラ
@@ -67,10 +69,11 @@ public class UpdateEmployeeController {
try { try {
// 部署一覧を取得し画面に返す値としてセット // 部署一覧を取得し画面に返す値としてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll())); model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()));
// id を条件に更新対象のレコードを検索、取得する // id を条件に更新対象のレコードを検索、取得する
List<EmployeeInfo> employeeInfoList = searchEmployeeInfo.searchBy( List<AllEmployeeInfo> employeeInfoList = searchEmployeeInfo.searchBy(
new SearchConditionEmployee(idEmployee, new SearchConditionEmployee(idEmployee,
null, null,
null, null,

View File

@@ -93,7 +93,8 @@ public class UpdateEmployeeResultController {
try { try {
// 部署一覧取得 // 部署一覧取得
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(searchDepartment.selectAll())); model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()));
// パスワードが仕様を満たしているか確認 // パスワードが仕様を満たしているか確認
String error = UpdateEmployeeInfoForm.validatePassword( String error = UpdateEmployeeInfoForm.validatePassword(

View File

@@ -1,12 +1,13 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.Department; import java.util.List;
import com.example.rhizome.app.domain.model.AllDepartmentInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List;
/** /**
* 画面の表示に使う部署コード管理用のクラス * 画面の表示に使う部署コード管理用のクラス
*/ */
@@ -15,14 +16,29 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class DepartmentForm { public class DepartmentForm {
/** /**
* 部署ID * 本部ID
*/
private Integer idHeadquarters;
/**
* 本部名
*/
private String nmHeadquarters;
/**
* 部ID
*/ */
private Integer idDepartment; private Integer idDepartment;
/** /**
* 部署名 * 部名
*/ */
private String nmDepartment; private String nmDepartment;
/**
* 課ID
*/
private Integer idDivision;
/**
* 課名
*/
private String nmDivision;
/** /**
* business 層の Department クラスから画面用(presentation 層)の DepartmentForm に * business 層の Department クラスから画面用(presentation 層)の DepartmentForm に
* 変換します。 * 変換します。
@@ -30,8 +46,15 @@ public class DepartmentForm {
* @param department business 層の Department インスタンス * @param department business 層の Department インスタンス
* @return 画面用(presentation 層)の DepartmentForm インスタンス * @return 画面用(presentation 層)の DepartmentForm インスタンス
*/ */
public static DepartmentForm convertFrom(Department department) { public static DepartmentForm convertFrom(AllDepartmentInfo allDepartmentInfo) {
return new DepartmentForm(department.getIdDepartment(), department.getNmDepartment()); return new DepartmentForm(
allDepartmentInfo.getHeadquarters().getIdHeadquarters(),
allDepartmentInfo.getHeadquarters().getNmHeadquarters(),
allDepartmentInfo.getDepartment().getIdDepartment(),
allDepartmentInfo.getDepartment().getNmDepartment(),
allDepartmentInfo.getDivision().getIdDivision(),
allDepartmentInfo.getDivision().getNmDivision()
);
} }
/** /**
@@ -41,7 +64,8 @@ public class DepartmentForm {
* @param departmentList business 層の Department インスタンスのリスト * @param departmentList business 層の Department インスタンスのリスト
* @return 画面用(presentation 層)の DepartmentForm インスタンスのリスト * @return 画面用(presentation 層)の DepartmentForm インスタンスのリスト
*/ */
public static List<DepartmentForm> convertFrom(List<Department> departmentList) { public static List<DepartmentForm> convertFrom(List<AllDepartmentInfo>allDepartmentInfoList
return departmentList.stream().map(DepartmentForm::convertFrom).toList(); ) {
return allDepartmentInfoList.stream().map(DepartmentForm::convertFrom).toList();
} }
} }

View File

@@ -3,7 +3,7 @@ package com.example.rhizome.app.presentation.form;
import java.util.List; import java.util.List;
import com.example.rhizome.app.domain.model.EmployeeInfo; import com.example.rhizome.app.domain.model.AllEmployeeInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@@ -50,13 +50,29 @@ public class EmployeeInfoForm {
*/ */
private Integer adminAuth; private Integer adminAuth;
/** /**
* 部署ID * 本部ID
*/
private Integer idHeadquarters;
/**
* 本部名
*/
private String nmHeadquarters;
/**
* 部ID
*/ */
private Integer idDepartment; private Integer idDepartment;
/** /**
* 部署名 * 部名
*/ */
private String nmDepartment; private String nmDepartment;
/**
* 課ID
*/
private Integer idDivision;
/**
* 課名
*/
private String nmDivision;
/** /**
* business 層の EmployeeInfo クラスから画面用(presentation 層)の EmployeeInfoForm に * business 層の EmployeeInfo クラスから画面用(presentation 層)の EmployeeInfoForm に
@@ -65,18 +81,22 @@ public class EmployeeInfoForm {
* @param employeeInfo business 層の EmployeeInfo インスタンス * @param employeeInfo business 層の EmployeeInfo インスタンス
* @return クラスから画面用(presentation 層)の EmployeeInfoForm インスタンス * @return クラスから画面用(presentation 層)の EmployeeInfoForm インスタンス
*/ */
public static EmployeeInfoForm convertFrom(EmployeeInfo employeeInfo) { public static EmployeeInfoForm convertFrom(AllEmployeeInfo allEmployeeInfo) {
return new EmployeeInfoForm( return new EmployeeInfoForm(
employeeInfo.getEmployee().getIdEmployee(), allEmployeeInfo.getEmployee().getIdEmployee(),
employeeInfo.getEmployee().getNmEmployee(), allEmployeeInfo.getEmployee().getNmEmployee(),
employeeInfo.getEmployee().getKnEmployee(), allEmployeeInfo.getEmployee().getKnEmployee(),
employeeInfo.getEmployee().getMailAddress(), allEmployeeInfo.getEmployee().getMailAddress(),
employeeInfo.getEmployee().getPassword(), allEmployeeInfo.getEmployee().getPassword(),
employeeInfo.getEmployee().getHireDate(), allEmployeeInfo.getEmployee().getHireDate(),
null, null,
employeeInfo.getEmployee().getAdminAuth(), allEmployeeInfo.getEmployee().getAdminAuth(),
employeeInfo.getDepartment().getIdDepartment(), allEmployeeInfo.getHeadquarters().getIdHeadquarters(),
employeeInfo.getDepartment().getNmDepartment() allEmployeeInfo.getHeadquarters().getNmHeadquarters(),
allEmployeeInfo.getDepartment().getIdDepartment(),
allEmployeeInfo.getDepartment().getNmDepartment(),
allEmployeeInfo.getDivision().getIdDivision(),
allEmployeeInfo.getDivision().getNmDivision()
); );
} }
@@ -87,7 +107,7 @@ public class EmployeeInfoForm {
* @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト * @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト
* @return クラスから画面用(presentation 層)の EmployeeInfoForm インスタンスのリスト * @return クラスから画面用(presentation 層)の EmployeeInfoForm インスタンスのリスト
*/ */
public static List<EmployeeInfoForm> convertFrom(List<EmployeeInfo> employeeInfoList) { public static List<EmployeeInfoForm> convertFrom(List<AllEmployeeInfo> allEmployeeInfoList) {
return employeeInfoList.stream().map(EmployeeInfoForm::convertFrom).toList(); return allEmployeeInfoList.stream().map(EmployeeInfoForm::convertFrom).toList();
} }
} }

View File

@@ -1,6 +1,7 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.domain.model.DepartmentInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -12,29 +13,63 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class InsertDepartmentForm { public class InsertDepartmentForm {
/** /**
* 部署ID * 本部ID
*/
private Integer idHeadquarters;
/**
* 本部名
*/
private String nmHeadquarters;
/**
* 部ID
*/ */
private Integer idDepartment; private Integer idDepartment;
/** /**
* 部署名 * 部名
*/ */
private String nmDepartment; private String nmDepartment;
/**
* 課ID
*/
private Integer idDivision;
/**
* 課名
*/
private String nmDivision;
/** /**
* 画面用(presentation 層)の InsertDepartmentForm クラス を Business 層の Department クラスに変換 * 画面用(presentation 層)の InsertDepartmentForm クラス を Business 層の Department クラスに変換
* *
* @param insertDepartmentForm presentation 層用のクラス * @param insertDepartmentForm presentation 層用のクラス
* @return Business 層用のモデル * @return Business 層用のモデル
*/ */
public static Department convertTo(InsertDepartmentForm insertDepartmentForm) { public static DepartmentInfo convertTo(InsertDepartmentForm insertDepartmentForm) {
return new Department(insertDepartmentForm.getIdDepartment(), insertDepartmentForm.getNmDepartment()); return new DepartmentInfo(insertDepartmentForm.getIdHeadquarters(),
insertDepartmentForm.getNmHeadquarters(),
insertDepartmentForm.getIdDepartment(),
insertDepartmentForm.getNmDepartment(),
insertDepartmentForm.getIdDivision(),
insertDepartmentForm.getNmDivision());
} }
public boolean haveNmDepartment() { public boolean haveNmDepartment() {
return nmDepartment.isBlank();
if (idHeadquarters == null && nmHeadquarters.isBlank()) {
return true;
}
if (idDepartment == null && nmDepartment.isBlank()) {
return true;
}
if (idDivision == null && nmDivision.isBlank()) {
return true;
}
return false;
} }
} }

View File

@@ -54,7 +54,7 @@ public class InsertEmployeeForm {
/** /**
* 部署ID * 部署ID
*/ */
private Integer idDepartment; private Integer idDivision;
/** /**
@@ -113,7 +113,7 @@ public class InsertEmployeeForm {
insertEmployeeForm.getPassword(), insertEmployeeForm.getPassword(),
insertEmployeeForm.getHireDate(), insertEmployeeForm.getHireDate(),
insertEmployeeForm.getAdminAuth(), insertEmployeeForm.getAdminAuth(),
insertEmployeeForm.getIdDepartment() insertEmployeeForm.getIdDivision()
); );
} }
@@ -149,7 +149,7 @@ public class InsertEmployeeForm {
error.add(MANAGEMENT_ERROR); error.add(MANAGEMENT_ERROR);
} }
if (idDepartment == null) { if (idDivision == null) {
error.add(DEPARTMENT_ID_NULL_BLANK); error.add(DEPARTMENT_ID_NULL_BLANK);
} }
if(isNullOrBlank(hireDate)) { if(isNullOrBlank(hireDate)) {

View File

@@ -2,6 +2,7 @@ package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -37,7 +38,7 @@ public class LoginUserForm {
private Integer adminAuth; private Integer adminAuth;
/** /**
* 部署ID * 課ID
*/ */
private Integer idDepartment; private Integer idDepartment;
@@ -56,7 +57,7 @@ public class LoginUserForm {
loginUser.getMailAddress(), loginUser.getMailAddress(),
loginUser.getPassword(), loginUser.getPassword(),
loginUser.getAdminAuth(), loginUser.getAdminAuth(),
loginUser.getIdDepartment() loginUser.getIdDivision()
); );
} }

View File

@@ -1,13 +1,14 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import java.util.List;
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;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List;
/** /**
* 画面から渡ってきた検索条件をまとめ、再度画面に表示する為のクラス * 画面から渡ってきた検索条件をまとめ、再度画面に表示する為のクラス
*/ */
@@ -18,11 +19,11 @@ public class SearchConditionDepartmentForm {
/** /**
* 部署ID * 部署ID
*/ */
private Integer idDepartment; private Integer idDivision;
/** /**
* 部署名 * 部署名
*/ */
private String nmDepartment; private String nmDivision;
/** /**
* business 層の Department クラスから画面用(presentation 層)の SearchConditionDepartmentForm に * business 層の Department クラスから画面用(presentation 層)の SearchConditionDepartmentForm に
@@ -55,8 +56,8 @@ public class SearchConditionDepartmentForm {
*/ */
public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) { public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) {
return new SearchConditionDepartment( return new SearchConditionDepartment(
searchConditionDepartmentForm.getIdDepartment(), searchConditionDepartmentForm.getIdDivision(),
searchConditionDepartmentForm.nmDepartment searchConditionDepartmentForm.nmDivision
); );
} }

View File

@@ -1,6 +1,7 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -32,7 +33,7 @@ public class SearchConditionEmployeeForm {
/** /**
* 部署ID * 部署ID
*/ */
private Integer idDepartment; private Integer idDivision;
/** /**
* business 層の SearchConditionEmployee クラスから画面用(presentation 層)の SearchConditionEmployeeForm に * business 層の SearchConditionEmployee クラスから画面用(presentation 層)の SearchConditionEmployeeForm に
@@ -47,7 +48,7 @@ public class SearchConditionEmployeeForm {
searchConditionEmployee.getNmEmployee(), searchConditionEmployee.getNmEmployee(),
searchConditionEmployee.getKnEmployee(), searchConditionEmployee.getKnEmployee(),
searchConditionEmployee.getMailAddress(), searchConditionEmployee.getMailAddress(),
searchConditionEmployee.getIdDepartment() searchConditionEmployee.getIdDivision()
); );
} }
@@ -64,7 +65,7 @@ public class SearchConditionEmployeeForm {
searchConditionEmployeeForm.getNmEmployee(), searchConditionEmployeeForm.getNmEmployee(),
searchConditionEmployeeForm.getKnEmployee(), searchConditionEmployeeForm.getKnEmployee(),
searchConditionEmployeeForm.getMailAddress(), searchConditionEmployeeForm.getMailAddress(),
searchConditionEmployeeForm.getIdDepartment() searchConditionEmployeeForm.getIdDivision()
); );
} }
} }

View File

@@ -1,28 +1,42 @@
package com.example.rhizome.app.presentation.form; package com.example.rhizome.app.presentation.form;
import com.example.rhizome.app.domain.model.Department; import com.example.rhizome.app.domain.model.AllDepartmentInfo;
import com.example.rhizome.app.domain.model.DepartmentInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/** /**
* 画面の表示に使う部署コード管理用のクラス * 画面の表示に使う部署コード管理用のクラス
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor
public class UpdateDepartmentForm { public class UpdateDepartmentForm {
/** /**
* 部署ID * 本部ID
*/
private Integer idHeadquarters;
/**
* 本部名
*/
private String nmHeadquarters;
/**
* 部ID
*/ */
private Integer idDepartment; private Integer idDepartment;
/** /**
* 部署名 * 部名
*/ */
private String nmDepartment; private String nmDepartment;
/**
* 課ID
*/
private Integer idDivision;
/**
* 課名
*/
private String nmDivision;
/** /**
* business 層の Department クラスから画面用(presentation 層)の UpdateDepartmentForm に * business 層の Department クラスから画面用(presentation 層)の UpdateDepartmentForm に
* 変換します。 * 変換します。
@@ -30,8 +44,14 @@ public class UpdateDepartmentForm {
* @param department business 層の Department インスタンス * @param department business 層の Department インスタンス
* @return 画面用(presentation 層)の UpdateDepartmentForm インスタンス * @return 画面用(presentation 層)の UpdateDepartmentForm インスタンス
*/ */
public static UpdateDepartmentForm convertFrom(Department department) { public static UpdateDepartmentForm convertFrom(AllDepartmentInfo allDepartmentInfo) {
return new UpdateDepartmentForm(department.getIdDepartment(), department.getNmDepartment()); return new UpdateDepartmentForm(
allDepartmentInfo.getHeadquarters().getIdHeadquarters(),
allDepartmentInfo.getHeadquarters().getNmHeadquarters(),
allDepartmentInfo.getDepartment().getIdDepartment(),
allDepartmentInfo.getDepartment().getNmDepartment(),
allDepartmentInfo.getDivision().getIdDivision(),
allDepartmentInfo.getDivision().getNmDivision());
} }
/** /**
@@ -41,9 +61,9 @@ public class UpdateDepartmentForm {
* @param departmentList business 層の Department インスタンスのリスト * @param departmentList business 層の Department インスタンスのリスト
* @return 画面用(presentation 層)の UpdateDepartmentForm インスタンスのリスト * @return 画面用(presentation 層)の UpdateDepartmentForm インスタンスのリスト
*/ */
public static List<UpdateDepartmentForm> convertFrom(List<Department> departmentList) { // public static List<UpdateDepartmentForm> convertFrom(List<Department> departmentList) {
return departmentList.stream().map(UpdateDepartmentForm::convertFrom).toList(); // return departmentList.stream().map(UpdateDepartmentForm::convertFrom).toList();
} // }
/** /**
* presentation 層の UpdateDepartmentForm クラスから Business 層の Department クラスに * presentation 層の UpdateDepartmentForm クラスから Business 層の Department クラスに
@@ -52,10 +72,24 @@ public class UpdateDepartmentForm {
* @param updateDepartmentForm presentation 層のインスタンス * @param updateDepartmentForm presentation 層のインスタンス
* @return Business 層の Department インスタンス * @return Business 層の Department インスタンス
*/ */
public static Department convertTo(UpdateDepartmentForm updateDepartmentForm) { // public static Department convertTo(UpdateDepartmentForm updateDepartmentForm) {
return new Department( // return new Department(
// updateDepartmentForm.getIdDepartment(),
// updateDepartmentForm.getNmDepartment(),
// (Integer)0,
// updateDepartmentForm.getIdHeadquarters()
//
// );
// }
public static DepartmentInfo convertTo(UpdateDepartmentForm updateDepartmentForm) {
return new DepartmentInfo(
updateDepartmentForm.getIdHeadquarters(),
updateDepartmentForm.getNmHeadquarters(),
updateDepartmentForm.getIdDepartment(), updateDepartmentForm.getIdDepartment(),
updateDepartmentForm.getNmDepartment() updateDepartmentForm.getNmDepartment(),
updateDepartmentForm.getIdDivision(),
updateDepartmentForm.getNmDivision()
); );
} }
} }

View File

@@ -2,8 +2,8 @@ package com.example.rhizome.app.presentation.form;
import java.util.List; import java.util.List;
import com.example.rhizome.app.domain.model.AllEmployeeInfo;
import com.example.rhizome.app.domain.model.Employee; import com.example.rhizome.app.domain.model.Employee;
import com.example.rhizome.app.domain.model.EmployeeInfo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@@ -52,7 +52,7 @@ public class UpdateEmployeeInfoForm {
/** /**
* 部署ID * 部署ID
*/ */
private Integer idDepartment; private Integer idDivision;
/** /**
* business 層の EmployeeInfo クラスから画面用(presentation 層)の UpdateEmployeeInfoForm に * business 層の EmployeeInfo クラスから画面用(presentation 層)の UpdateEmployeeInfoForm に
@@ -61,17 +61,17 @@ public class UpdateEmployeeInfoForm {
* @param employeeInfo business 層の EmployeeInfo インスタンス * @param employeeInfo business 層の EmployeeInfo インスタンス
* @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンス * @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンス
*/ */
public static UpdateEmployeeInfoForm convertFrom(EmployeeInfo employeeInfo) { public static UpdateEmployeeInfoForm convertFrom(AllEmployeeInfo allemployeeInfo) {
return new UpdateEmployeeInfoForm( return new UpdateEmployeeInfoForm(
employeeInfo.getEmployee().getIdEmployee(), allemployeeInfo.getEmployee().getIdEmployee(),
employeeInfo.getEmployee().getNmEmployee(), allemployeeInfo.getEmployee().getNmEmployee(),
employeeInfo.getEmployee().getKnEmployee(), allemployeeInfo.getEmployee().getKnEmployee(),
employeeInfo.getEmployee().getMailAddress(), allemployeeInfo.getEmployee().getMailAddress(),
employeeInfo.getEmployee().getPassword(), allemployeeInfo.getEmployee().getPassword(),
null, null,
employeeInfo.getEmployee().getHireDate(), allemployeeInfo.getEmployee().getHireDate(),
employeeInfo.getEmployee().getAdminAuth(), allemployeeInfo.getEmployee().getAdminAuth(),
employeeInfo.getDepartment().getIdDepartment() allemployeeInfo.getDivision().getIdDivision()
); );
} }
@@ -82,8 +82,8 @@ public class UpdateEmployeeInfoForm {
* @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト * @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト
* @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンスのリスト * @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンスのリスト
*/ */
public static List<UpdateEmployeeInfoForm> convertFrom(List<EmployeeInfo> employeeInfoList) { public static List<UpdateEmployeeInfoForm> convertFrom(List<AllEmployeeInfo> allemployeeInfoList) {
return employeeInfoList.stream().map(UpdateEmployeeInfoForm::convertFrom).toList(); return allemployeeInfoList.stream().map(UpdateEmployeeInfoForm::convertFrom).toList();
} }
/** /**
@@ -102,7 +102,7 @@ public class UpdateEmployeeInfoForm {
updateEmployeeInfoForm.getPassword(), updateEmployeeInfoForm.getPassword(),
updateEmployeeInfoForm.getHireDate(), updateEmployeeInfoForm.getHireDate(),
updateEmployeeInfoForm.getAdminAuth(), updateEmployeeInfoForm.getAdminAuth(),
updateEmployeeInfoForm.getIdDepartment() updateEmployeeInfoForm.getIdDivision()
); );
} }

View File

@@ -30,7 +30,7 @@
</div> </div>
<table> <table>
<tr> <tr>
<th class="header">部署ID</th> <th class="header"> 本部ID</th>
<td> <td>
<label> <label>
<input class="readOnly" <input class="readOnly"
@@ -41,7 +41,30 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="header">部署名</th> <th class="header">本部名</th>
<td>
<label>
<input class="readOnly"
name="nmHeadquarters"
readonly="readonly"
th:value="*{nmHeadquarters}"
type="text"/>
</label>
</td>
</tr>
<tr>
<th class="header">部ID</th>
<td>
<label>
<input class="readOnly"
readonly="readonly"
type="text"
value="自動で設定されます"/>
</label>
</td>
</tr>
<tr>
<th class="header">部名</th>
<td> <td>
<label> <label>
<input class="readOnly" <input class="readOnly"
@@ -52,6 +75,31 @@
</label> </label>
</td> </td>
</tr> </tr>
<tr>
<th class="header">課ID</th>
<td>
<label>
<input class="readOnly"
readonly="readonly"
type="text"
value="自動で設定されます"/>
</label>
</td>
</tr>
<tr>
<th class="header">課名</th>
<td>
<label>
<input class="readOnly"
name="nmDivision"
readonly="readonly"
th:value="*{nmDivision}"
type="text"/>
</label>
</td>
</tr>
<tr> <tr>
<td class="btnArea" colspan="2"> <td class="btnArea" colspan="2">
<input type="submit" value="登録"/> <input type="submit" value="登録"/>

View File

@@ -13,16 +13,14 @@
</head> </head>
<body> <body>
<h1> <h1>
部署登録    部署登録   
<div class="rightSection"> <div class="rightSection">
<span class="loginInfo">ログイン者名:<span th:text="${session.loginUser.nmEmployee}"></span></span> <span class="loginInfo">ログイン者名:<span th:text="${session.loginUser.nmEmployee}"></span></span>
<button class="logoutButton" onclick="logoutSubmit()">ログアウト</button> <button class="logoutButton" onclick="logoutSubmit()">ログアウト</button>
</div> </div>
</h1> </h1>
<form action="insertDepartmentConfirm" <form action="insertDepartmentConfirm" method="post" th:object="${insertDepartmentForm}">
method="post"
th:object="${insertDepartmentForm}">
<div class="msgBox error" th:if="${messageError} != null"> <div class="msgBox error" th:if="${messageError} != null">
<span class="error" th:text="${messageError.message}"></span> <span class="error" th:text="${messageError.message}"></span>
@@ -30,37 +28,113 @@
<table> <table>
<tr> <tr>
<th class="header">部署ID</th> <th class="header">本部ID</th>
<td> <td>
<label> <label>
<input class="readOnly" <input class="readOnly" readonly="readonly" type="text" value="自動で設定されます" />
readonly="readonly"
type="text"
value="自動で設定されます"
/>
</label> </label>
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="header">部署名</th> <th class="header">本部名</th>
<td> <td>
<label> <label>
<input maxlength="50" <input maxlength="50" placeholder="本部名" th:field="*{nmHeadquarters}" type="text" />
placeholder="部署名"
required="required"
th:field="*{nmDepartment}"
type="text"
/>
</label> </label>
</td> </td>
</tr> </tr>
<tr>
<th class="header"></th>
<td>
<label>
<select th:field="*{nmHeadquarters}">
<option value="">本部を選択</option>
<option
th:each="headquarters : ${departmentFormList}"
th:selected="${insertDepartmentForm.idHeadquarters != null && headquarters.idHeadquarters == insertDepartmentForm.idHeadquarters}"
th:text="${headquarters.nmHeadquarters}" th:value="${headquarters.nmHeadquarters}">
</option>
</select>
</label>
</td>
</tr>
<tr>
<th class="header">部ID</th>
<td>
<label>
<input class="readOnly" readonly="readonly" type="text" value="自動で設定されます" />
</label>
</td>
</tr>
<tr>
<th class="header">部名</th>
<td>
<label>
<input maxlength="50" placeholder="部名" th:field="*{nmDepartment}" type="text" />
</label>
</td>
</tr>
<tr>
<th class="header"></th>
<td>
<label>
<select th:field="*{nmDepartment}">
<option value="">部を選択</option>
<option
th:each="department : ${departmentFormList}"
th:selected="${insertDepartmentForm.idDepartment != null && department.idDepartment == insertDepartmentForm.idDepartment}"
th:text="${department.nmDepartment}" th:value="${department.nmDepartment}">
</option>
</select>
</label>
</td>
</tr>
<tr>
<th class="header">課ID</th>
<td>
<label>
<input class="readOnly" readonly="readonly" type="text" value="自動で設定されます" />
</label>
</td>
</tr>
<tr>
<th class="header">課名</th>
<td>
<label>
<input maxlength="50" placeholder="課名" th:field="*{nmDivision}" type="text" />
</label>
</td>
</tr>
<tr>
<th class="header"></th>
<td>
<label>
<select th:field="*{nmDivision}">
<option value="">課を選択</option>
<option th:each="division : ${departmentFormList}"
th:selected="${insertDepartmentForm.idDivision != null && division.idDivision == insertDepartmentForm.idDivision}"
th:text="${division.nmDivision}" th:value="${division.nmDivision}">
</option>
</select>
</label>
</td>
</tr>
<tr> <tr>
<td class="btnArea" colspan="2"> <td class="btnArea" colspan="2">
<input type="submit" value="登録確認"/> <input type="submit" value="登録確認" />
</td> </td>
</tr> </tr>
</table> </table>
</form> </form>
<a href="showMenu">メニューに戻る</a> <a href="showMenu">メニューに戻る</a>
</body> </body>
</html> </html>

View File

@@ -122,12 +122,16 @@
<th class="header">所属部署</th> <th class="header">所属部署</th>
<td> <td>
<label> <label>
<select name="idDepartment" required="required" th:field="*{idDepartment}"> <select name="idDivision" required="required" th:field="*{idDivision}">
<th:block th:each="department : ${departmentFormList}"> <th:block th:each="division : ${departmentFormList}">
<th:block <th:block
th:if="${insertEmployeeForm.idDepartment != null && department.idDepartment == insertEmployeeForm.idDepartment}"> th:if="${insertEmployeeForm.idDivision != null && division.idDivision == insertEmployeeForm.idDivision}">
<option th:text="${department.nmDepartment}" <option
th:value="${department.idDepartment}"> th:utext="
${division.nmHeadquarters}+' '+
${division.nmDepartment}+' '+
${division.nmDivision}"
th:value="${division.idDivision}">
</option> </option>
</th:block> </th:block>
</th:block> </th:block>

View File

@@ -149,11 +149,15 @@
<th class="header">所属部署</th> <th class="header">所属部署</th>
<td> <td>
<label> <label>
<select required="required" th:field="*{idDepartment}"> <select required="required" th:field="*{idDivision}">
<option th:each="department : ${departmentFormList}" <option value="">所属部署を選択</option>
th:selected="${insertEmployeeForm.idDepartment != null && department.idDepartment == insertEmployeeForm.idDepartment}" <option th:each="division : ${departmentFormList}"
th:text="${department.nmDepartment}" th:selected="${insertEmployeeForm.idDivision != null && division.idDivision == insertEmployeeForm.idDivision}"
th:value="${department.idDepartment}"> th:utext="
${division.nmHeadquarters}+' '+
${division.nmDepartment}+' '+
${division.nmDivision}"
th:value="${division.idDivision}">
</option> </option>
</select> </select>
</label> </label>

View File

@@ -32,7 +32,7 @@
<th class="header">部署ID</th> <th class="header">部署ID</th>
<td> <td>
<input placeholder="部署ID" <input placeholder="部署ID"
th:field="*{idDepartment}" th:field="*{idDivision}"
type="number"/> type="number"/>
</td> </td>
</tr> </tr>
@@ -40,7 +40,7 @@
<th class="header">部署名</th> <th class="header">部署名</th>
<td> <td>
<input placeholder="部署名" <input placeholder="部署名"
th:field="*{nmDepartment}" th:field="*{nmDivision}"
type="text"/> type="text"/>
</td> </td>
</tr> </tr>
@@ -70,25 +70,33 @@
<table class="half-table-grid table-striped table-hover"> <table class="half-table-grid table-striped table-hover">
<thead> <thead>
<tr> <tr>
<th style="width: 60px;">部署ID</th> <th style="width: 60px;">本部ID</th>
<th style="width: 100px;">部署名</th> <th style="width: 100px;">本部名</th>
<th style="width: 60px;">部ID</th>
<th style="width: 100px;">部名</th>
<th style="width: 60px;">課ID</th>
<th style="width: 100px;">課名</th>
<th style="width: 150px;">操作</th> <th style="width: 150px;">操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr th:each="departmentForm : ${departmentFormList}"> <tr th:each="departmentForm : ${departmentFormList}">
<td th:text="${departmentForm.idHeadquarters}"></td>
<td th:text="${departmentForm.nmHeadquarters}"></td>
<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 th:text="${departmentForm.idDivision}"></td>
<td th:text="${departmentForm.nmDivision}"></td>
<td> <td>
<!-- 更新フォーム --> <!-- 更新フォーム -->
<form action="showUpdateDepartment" method="post" style="display: inline;"> <form action="showUpdateDepartment" method="post" style="display: inline;">
<input name="idDepartment" th:value="${departmentForm.idDepartment}" type="hidden"> <input name="idDivision" th:value="${departmentForm.idDivision}" type="hidden">
<input type="submit" value="更新"> <input type="submit" value="更新">
</form> </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="idDivision" th:value="${departmentForm.idDivision}" type="hidden">
<input type="submit" value="削除"> <input type="submit" value="削除">
</form> </form>
</td> </td>
@@ -105,8 +113,8 @@
<script type="text/javascript"> <script type="text/javascript">
function clearInput() { function clearInput() {
document.getElementById('idDepartment').value = ''; document.getElementById('idDivision').value = '';
document.getElementById('nmDepartment').value = ''; document.getElementById('nmDivision').value = '';
} }

View File

@@ -64,12 +64,12 @@
<tr> <tr>
<th class="header">所属部署</th> <th class="header">所属部署</th>
<td> <td>
<select th:field="*{idDepartment}"> <select th:field="*{idDivision}">
<option value=""></option> <option value=""></option>
<option th:each="department : ${departmentFormList}" <option th:each="division : ${departmentFormList}"
th:selected="${searchConditionEmployeeForm.idDepartment != null && department.idDepartment == searchConditionEmployeeForm.idDepartment}" th:selected="${searchConditionEmployeeForm.idDivision != null && division.idDivision == searchConditionEmployeeForm.idDivision}"
th:text="${department.nmDepartment}" th:text="${division.nmDivision}"
th:value="${department.idDepartment}"> th:value="${division.idDivision}">
</option> </option>
</select> </select>
</td> </td>
@@ -122,7 +122,10 @@
<td th:text="${employeeInfoForm.hireDate}"></td> <td th:text="${employeeInfoForm.hireDate}"></td>
<td th:text="${employeeInfoForm.tenure}"></td> <td th:text="${employeeInfoForm.tenure}"></td>
<td th:text="${employeeInfoForm.adminAuth}"></td> <td th:text="${employeeInfoForm.adminAuth}"></td>
<td th:text="${employeeInfoForm.nmDepartment}"></td> <td th:utext="${employeeInfoForm.nmHeadquarters}+'<br/>・'+
${employeeInfoForm.nmDepartment}+'<br/>・'+
${employeeInfoForm.nmDivision}"
></td>
<td> <td>
<!-- 更新フォーム --> <!-- 更新フォーム -->
<form action="showUpdateEmployee" method="post" style="display: inline;"> <form action="showUpdateEmployee" method="post" style="display: inline;">
@@ -153,7 +156,7 @@
document.getElementById('nmEmployee').value = ''; document.getElementById('nmEmployee').value = '';
document.getElementById('knEmployee').value = ''; document.getElementById('knEmployee').value = '';
document.getElementById('mailAddress').value = ''; document.getElementById('mailAddress').value = '';
document.getElementById('idDepartment').selectedIndex = 0; document.getElementById('idDivision').selectedIndex = 0;
} }

View File

@@ -30,7 +30,32 @@
</div> </div>
<table> <table>
<tr> <tr>
<th class="header">部署ID</th> <th class="header">本部ID</th>
<td>
<label>
<input class="readOnly"
readonly="readonly"
th:field="*{idHeadquarters}"
type="text"
/>
</label>
</td>
</tr>
<tr>
<th class="header">本部名</th>
<td>
<label>
<input maxlength="10"
placeholder="本部名"
required="required"
th:field="*{nmHeadquarters}"
type="text"
/>
</label>
</td>
</tr>
<tr>
<th class="header">部ID</th>
<td> <td>
<label> <label>
<input class="readOnly" <input class="readOnly"
@@ -42,11 +67,11 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="header">部署名</th> <th class="header">部名</th>
<td> <td>
<label> <label>
<input maxlength="10" <input maxlength="10"
placeholder="部署名" placeholder="部名"
required="required" required="required"
th:field="*{nmDepartment}" th:field="*{nmDepartment}"
type="text" type="text"
@@ -54,6 +79,31 @@
</label> </label>
</td> </td>
</tr> </tr>
<tr>
<th class="header">課ID</th>
<td>
<label>
<input class="readOnly"
readonly="readonly"
th:field="*{idDivision}"
type="text"
/>
</label>
</td>
</tr>
<tr>
<th class="header">課名</th>
<td>
<label>
<input maxlength="10"
placeholder="課名"
required="required"
th:field="*{nmDivision}"
type="text"
/>
</label>
</td>
</tr>
<tr> <tr>
<td class="btnArea" colspan="2"> <td class="btnArea" colspan="2">
<input type="submit" value="更新"/> <input type="submit" value="更新"/>

View File

@@ -137,12 +137,17 @@
<th class="header">所属部署</th> <th class="header">所属部署</th>
<td> <td>
<label> <label>
<select required="required" th:field="*{idDepartment}"> <select required="required" th:field="*{idDivision}">
<option th:each="department : ${departmentFormList}"
th:selected="${updateEmployeeInfoForm.idDepartment != null && department.idDepartment == updateEmployeeInfoForm.idDepartment}" <option th:each="division : ${departmentFormList}"
th:text="${department.nmDepartment}" th:selected="${updateEmployeeInfoForm.idDivision != null && division.idDivision == updateEmployeeInfoForm.idDivision}"
th:value="${department.idDepartment}"> th:utext="
${division.nmHeadquarters}+' '+
${division.nmDepartment}+' '+
${division.nmDivision}"
th:value="${division.idDivision}">
</option> </option>
</select> </select>
</label> </label>
</td> </td>

View File

@@ -1,3 +1,8 @@
-- DB と User作成 関連
-- 必要であればコメント外してください
-- CREATE DATABASE rezodb;
-- CREATE USER 'rezouser'@'localhost' IDENTIFIED BY 'Rezo_0000';
-- GRANT ALL ON rezodb.* TO 'rezouser'@'localhost';
-- employeeテーブルの作成 -- employeeテーブルの作成
@@ -80,7 +85,7 @@ INSERT INTO department (nm_department,id_headquarters,is_display) VALUES ('シ
INSERT INTO department (nm_department,id_headquarters,is_display) VALUES ('教育事業部',104,0); INSERT INTO department (nm_department,id_headquarters,is_display) VALUES ('教育事業部',104,0);
INSERT INTO department (nm_department,id_headquarters,is_display) VALUES ('営業企画部',105,0); INSERT INTO department (nm_department,id_headquarters,is_display) VALUES ('営業企画部',105,0);
-- 部テーブルのデータ -- 課テーブルのデータ
INSERT INTO division (nm_division,id_department,is_display) VALUES ('役員',200,0); INSERT INTO division (nm_division,id_department,is_display) VALUES ('役員',200,0);
INSERT INTO division (nm_division,id_department,is_display) VALUES ('人事・総務課',201,0); INSERT INTO division (nm_division,id_department,is_display) VALUES ('人事・総務課',201,0);
INSERT INTO division (nm_division,id_department,is_display) VALUES ('経理課',202,0); INSERT INTO division (nm_division,id_department,is_display) VALUES ('経理課',202,0);