【組織の階層構造導入】実装

This commit is contained in:
o-yamamoto
2026-09-29 17:00:18 +09:00
parent 820d030602
commit e7b3b42feb
85 changed files with 3827 additions and 3609 deletions

View File

@@ -63,7 +63,7 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<scope>test</scope> <!-- <scope>test</scope>-->
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -3,6 +3,9 @@ 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 AllEmployeeInfo { public class AllEmployeeInfo {

View File

@@ -3,6 +3,10 @@ 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 {

View File

@@ -30,9 +30,14 @@ public interface SearchDepartment {
List<Division> searchByDivision(SearchConditionDepartment searchConditionDepartment); List<Division> searchByDivision(SearchConditionDepartment searchConditionDepartment);
List<Department>searchByIdHeadquarters(Integer idHeadquarters); List<Department> searchByIdHeadquarters(Integer idHeadquarters);
List<Division>searchByIdDepartment(Integer idDepartment); List<Division> searchByIdDepartment(Integer idDepartment);
List<Headquarters> searchHeadquartersByIdHeadquarters(Integer idHeadquarters);
List<Department> searchDepartmentByIdDepartment(Integer idDepartment);
List<Division> searchDivisionByIdDivision(Integer idDivision);
// List<DepartmentInfo> searchByWithLike(SearchConditionDepartment searchConditionDepartment);
} }

View File

@@ -19,7 +19,7 @@ public class DeleteDepartmentImpl implements DeleteDepartment {
/** /**
* コンストラクタ * コンストラクタ
* *
* @param departmentRepository DI対象 * @param divisionRepository DI対象
*/ */
@Autowired @Autowired
public DeleteDepartmentImpl(DivisionRepository divisionRepository) { public DeleteDepartmentImpl(DivisionRepository divisionRepository) {
@@ -28,12 +28,12 @@ public class DeleteDepartmentImpl implements DeleteDepartment {
/** /**
* idDepartment を元に department データを削除 * idDivision を元に division データを削除するメソッド
* *
* @param idDepartment 削除対象のidDepartment * @param idDivision 削除対象のidDivision
*/ */
public void deleteDepartment(Integer idDepartment) { public void deleteDepartment(Integer idDivision) {
divisionRepository.deleteById(idDepartment); divisionRepository.deleteByIdDivision(idDivision);
} }
} }

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.DeleteEmployee;
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.service.DeleteEmployee;
import com.example.rhizome.app.infra.repository.EmployeeRepository;
/** /**
* Employee レコード削除関連の機能を持つサービス * Employee レコード削除関連の機能を持つサービス
*/ */
@@ -20,9 +21,8 @@ public class DeleteEmployeeImpl implements DeleteEmployee {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
} }
/** /**
* idEmployee を元に employee データを削除 * idEmployee を元に employee データを削除するメソッド
* *
* @param idEmployee 削除対象のidEmployee * @param idEmployee 削除対象のidEmployee
*/ */

View File

@@ -1,6 +1,5 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
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;
@@ -23,10 +22,13 @@ public class RegisterDepartmentImpl implements RegisterDepartment {
DepartmentRepository departmentRepository; DepartmentRepository departmentRepository;
DivisionRepository divisionRepository; DivisionRepository divisionRepository;
HeadquartersRepository headquartersRepository; HeadquartersRepository headquartersRepository;
/** /**
* コンストラクタ * コンストラクタ
* *
* @param departmentRepository DI対象 * @param departmentRepository DI対象
* @param divisionRepository DI対象
* @param headquartersRepository DI対象
*/ */
@Autowired @Autowired
public RegisterDepartmentImpl(DepartmentRepository departmentRepository, public RegisterDepartmentImpl(DepartmentRepository departmentRepository,
@@ -38,42 +40,39 @@ public class RegisterDepartmentImpl implements RegisterDepartment {
} }
/** /**
* department インスタンスの内容を登録する * division,department,headquartersインスタンスの内容を登録する
* *
* @param department 登録対象のデータ * @param divisionEntity 登録対象のデータ
* @param departmentEntity 登録対象のデータ
* @param headquartersEntity 登録対象のデータ
*/ */
public void registerDepartment(DivisionEntity divisionEntity) { public void registerDepartment(DivisionEntity divisionEntity) {
DepartmentEntity departmentEntity = divisionEntity.getDepartment(); DepartmentEntity departmentEntity = divisionEntity.getDepartment();
HeadquartersEntity headquartersEntity = divisionEntity.getDepartment().getHeadquarters(); HeadquartersEntity headquartersEntity = divisionEntity.getDepartment().getHeadquarters();
HeadquartersEntity originHeadquartersEntity = HeadquartersEntity originHeadquartersEntity = headquartersRepository.findByNmHeadquarters(
headquartersRepository.findByNmHeadquarters(
divisionEntity.getDepartment().getHeadquarters().getNmHeadquarters()); divisionEntity.getDepartment().getHeadquarters().getNmHeadquarters());
if(originHeadquartersEntity!=null){ if (originHeadquartersEntity != null) {
headquartersEntity=originHeadquartersEntity; headquartersEntity = originHeadquartersEntity;
}else { } else {
headquartersEntity = new HeadquartersEntity(); headquartersEntity = new HeadquartersEntity();
headquartersEntity.setNmHeadquarters( headquartersEntity.setNmHeadquarters(
divisionEntity.getDepartment() divisionEntity.getDepartment()
.getHeadquarters() .getHeadquarters()
.getNmHeadquarters() .getNmHeadquarters());
);
} }
DepartmentEntity originDepartmentEntity = DepartmentEntity originDepartmentEntity = departmentRepository.findByHeadquartersAndNmDepartment(
departmentRepository.findByHeadquartersAndNmDepartment( originHeadquartersEntity,
headquartersEntity,
divisionEntity.getDepartment().getNmDepartment()); divisionEntity.getDepartment().getNmDepartment());
if(originDepartmentEntity!=null) { if (originDepartmentEntity != null) {
departmentEntity=originDepartmentEntity; departmentEntity = originDepartmentEntity;
}else { } else {
departmentEntity = new DepartmentEntity(); departmentEntity = new DepartmentEntity();
departmentEntity.setNmDepartment( departmentEntity.setNmDepartment(
divisionEntity.getDepartment() divisionEntity.getDepartment()
.getNmDepartment() .getNmDepartment());
);
} }
divisionEntity.setIsDisplay(0); divisionEntity.setIsDisplay(0);
departmentEntity.setIsDisplay(0); departmentEntity.setIsDisplay(0);
headquartersEntity.setIsDisplay(0); headquartersEntity.setIsDisplay(0);

View File

@@ -1,6 +1,5 @@
package com.example.rhizome.app.domain.service.impl; package com.example.rhizome.app.domain.service.impl;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -23,6 +22,7 @@ import com.example.rhizome.app.infra.repository.DepartmentRepository;
import com.example.rhizome.app.infra.repository.DivisionRepository; import com.example.rhizome.app.infra.repository.DivisionRepository;
import com.example.rhizome.app.infra.repository.HeadquartersRepository; import com.example.rhizome.app.infra.repository.HeadquartersRepository;
import com.example.rhizome.app.infra.repository.RegisterDepartmentRepository; import com.example.rhizome.app.infra.repository.RegisterDepartmentRepository;
import com.example.rhizome.app.infra.repository.RegisterDivisionRepository;
/** /**
* 部署情報検索系の機能を集約させるサービスクラスです。 * 部署情報検索系の機能を集約させるサービスクラスです。
@@ -35,76 +35,101 @@ public class SearchDepartmentImpl implements SearchDepartment {
HeadquartersRepository headquartersRepository; HeadquartersRepository headquartersRepository;
DepartmentInfoRepository departmentInfoRepository; DepartmentInfoRepository departmentInfoRepository;
RegisterDepartmentRepository registerDepartmentRepository; RegisterDepartmentRepository registerDepartmentRepository;
RegisterDivisionRepository registerDivisionRepository;
/** /**
* コンストラクタ * コンストラクタ
* *
* @param divisionRepository DI対象
* @param departmentRepository DI対象 * @param departmentRepository DI対象
* @param headquartersRepository DI対象
* @param departmentInfoRepository DI対象
* @param RegisterDepartmentRepository DI対象
* @param RegisterDivisionRepository DI対象
*/ */
@Autowired @Autowired
public SearchDepartmentImpl( public SearchDepartmentImpl(
DepartmentRepository departmentRepository DepartmentRepository departmentRepository, DivisionRepository divisionRepository,
,DivisionRepository divisionRepository HeadquartersRepository headquartersRepository, DepartmentInfoRepository departmentInfoRepository,
,HeadquartersRepository headquartersRepository RegisterDepartmentRepository registerDepartmentRepository,
,DepartmentInfoRepository departmentInfoRepository RegisterDivisionRepository registerDivisionRepository) {
,RegisterDepartmentRepository registerDepartmentRepository) {
this.departmentRepository = departmentRepository; this.departmentRepository = departmentRepository;
this.divisionRepository = divisionRepository; this.divisionRepository = divisionRepository;
this.headquartersRepository = headquartersRepository; this.headquartersRepository = headquartersRepository;
this.departmentInfoRepository = departmentInfoRepository; this.departmentInfoRepository = departmentInfoRepository;
this.registerDepartmentRepository = registerDepartmentRepository; this.registerDepartmentRepository = registerDepartmentRepository;
this.registerDivisionRepository = registerDivisionRepository;
} }
/** /**
* 部署情報を全件取得する * 部署情報を全件取得する
* *
* @return 取得した本部情報レコード全件 * @return 取得した部署情報レコード全件
*/ */
public List<AllDepartmentInfo>searchAllDepartmentTable(){ public List<AllDepartmentInfo> searchAllDepartmentTable() {
return DepartmentInfoEntity.createDepartmentInfoList(departmentInfoRepository.searchAllDepartmentTable()); return DepartmentInfoEntity.createDepartmentInfoList(departmentInfoRepository.searchAllDepartmentTable());
} }
/**
* 課の条件を基に部署情報を全件取得する
* @param SearchConditionDepartment 検索条件
public List<AllDepartmentInfo>searchAllDepartmentTable(SearchConditionDepartment searchConditionDepartment){ * @return 検索結果のレコード
*/
public List<AllDepartmentInfo> searchAllDepartmentTable(SearchConditionDepartment searchConditionDepartment) {
return DepartmentInfoEntity.AfterSearchCreateDepartmentInfoList( return DepartmentInfoEntity.AfterSearchCreateDepartmentInfoList(
departmentInfoRepository.findAll(Specification departmentInfoRepository.findAll(Specification
.where(DepartmentInfoRepository.idDivisionEqual(searchConditionDepartment.getIdDivision())) .where(DepartmentInfoRepository.idDivisionEqual(searchConditionDepartment.getIdDivision()))
.and(DepartmentInfoRepository.nmDivisionEqual(searchConditionDepartment.getNmDivision())) .and(DepartmentInfoRepository.nmDivisionEqual(searchConditionDepartment.getNmDivision()))));
)
);
} }
/**
* 三つの部署の名前を基に部署情報を取得する→重複チェック
* @param SearchConditionDepartment searchHeadquartersTable 検索条件
* @param SearchConditionDepartment searchDepartmentTable 検索条件
* @param SearchConditionDepartment searchDivisionTable 検索条件
* @return 重複があればtrue
* @return 重複が無ければfalse
*/
public boolean searchAllDepartmentTable( public boolean searchAllDepartmentTable(
SearchConditionDepartment searchHeadquartersTable, SearchConditionDepartment searchHeadquartersTable,
SearchConditionDepartment searchDepartmentTable, SearchConditionDepartment searchDepartmentTable,
SearchConditionDepartment searchDivisionTable){ SearchConditionDepartment searchDivisionTable) {
if(departmentInfoRepository.searchAllDepartmentTable( if (departmentInfoRepository.searchAllDepartmentTable(
searchHeadquartersTable.getNmDivision(), searchHeadquartersTable.getNmDivision(),
searchDepartmentTable.getNmDivision(), searchDepartmentTable.getNmDivision(),
searchDivisionTable.getNmDivision()).isEmpty()) { searchDivisionTable.getNmDivision()).isEmpty()) {
return false; return false;
}else{ } else {
return true; return true;
} }
} }
/**
* 三つの部署のIDを基に部署情報を取得する→重複チェック
* @param Integer idHeadquarters 検索条件
* @param Integer idDepartment 検索条件
* @param Integer idDivision 検索条件
* @return 重複があればtrue
* @return 重複が無ければfalse
*/
public boolean searchAllDepartmentTable( public boolean searchAllDepartmentTable(
Integer idHeadquarters, Integer idHeadquarters,
Integer idDepartment, Integer idDepartment,
Integer idDivision){ Integer idDivision) {
if(departmentInfoRepository.searchAllDepartmentTable( if (departmentInfoRepository.searchAllDepartmentTable(
idHeadquarters, idHeadquarters,
idDepartment, idDepartment,
idDivision).isEmpty()) { idDivision).isEmpty()) {
return false; return false;
}else{ } else {
return true; return true;
} }
} }
/** /**
* searchConditionDepartment の情報を元に Department のレコードを取得 * searchConditionDepartment の情報を元に Headquarters のレコードを取得
* *
* @param searchConditionDepartment 検索条件 * @param searchConditionDepartment 検索条件
* @return 検索結果のレコード * @return 検索結果のレコード
@@ -114,24 +139,38 @@ public class SearchDepartmentImpl implements SearchDepartment {
return HeadquartersEntity return HeadquartersEntity
.createHeadquartersList( .createHeadquartersList(
headquartersRepository.findAll(Specification headquartersRepository.findAll(Specification
.where(HeadquartersRepository.idHeadquartersEqual(searchConditionDepartment.getIdDivision())) .where(HeadquartersRepository
.and(HeadquartersRepository.nmHeadquartersEqual(searchConditionDepartment.getNmDivision())) .idHeadquartersEqual(searchConditionDepartment.getIdDivision()))
) .and(HeadquartersRepository
); .nmHeadquartersEqual(searchConditionDepartment.getNmDivision()))));
} }
/**
* searchConditionDepartment の情報を元に Department のレコードを取得
*
* @param searchConditionDepartment 検索条件
* @return 検索結果のレコード
*/
public List<Department> searchByDepartment(SearchConditionDepartment searchConditionDepartment) { 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.getIdDivision())) .where(DepartmentRepository
.and(DepartmentRepository.nmDepartmentEqual(searchConditionDepartment.getNmDivision())) .idDepartmentEqual(searchConditionDepartment.getIdDivision()))
) .and(DepartmentRepository
); .nmDepartmentEqual(searchConditionDepartment.getNmDivision()))));
} }
/**
* searchConditionDepartment の情報を元に Division のレコードを取得
*
* @param searchConditionDepartment 検索条件
* @return 検索結果のレコード
*/
public List<Division> searchByDivision(SearchConditionDepartment searchConditionDepartment) { public List<Division> searchByDivision(SearchConditionDepartment searchConditionDepartment) {
// 動的に検索条件を絞り込む // 動的に検索条件を絞り込む
// // Specification は Criteria AP//I の Predicate をラップしたもの // // Specification は Criteria AP//I の Predicate をラップしたもの
@@ -139,26 +178,70 @@ public class SearchDepartmentImpl implements SearchDepartment {
.createDivisionList( .createDivisionList(
divisionRepository.findAll(Specification divisionRepository.findAll(Specification
.where(DivisionRepository.idDivisionEqual(searchConditionDepartment.getIdDivision())) .where(DivisionRepository.idDivisionEqual(searchConditionDepartment.getIdDivision()))
.and(DivisionRepository.nmDivisionEqual(searchConditionDepartment.getNmDivision())) .and(DivisionRepository.nmDivisionEqual(searchConditionDepartment.getNmDivision()))));
)
);
} }
public List<Department>searchByIdHeadquarters(Integer idHeadquarters){ /**
System.out.println("3"); * idHeadquarters の情報を元に Department のレコードを取得
*
* @param Integer idHeadquarters 検索条件
* @return 検索結果のレコード
*/
public List<Department> searchByIdHeadquarters(Integer idHeadquarters) {
registerDepartmentRepository.findAll(Specification registerDepartmentRepository.findAll(Specification
.where(RegisterDepartmentRepository.idHeadquartersEqual(idHeadquarters))); .where(RegisterDepartmentRepository.idHeadquartersEqual(idHeadquarters)));
System.out.println("SearchDepartmentImpl=>4");
return DepartmentEntity return DepartmentEntity
.createDepartmentListBy(registerDepartmentRepository.findAll(Specification .createDepartmentListBy(registerDepartmentRepository.findAll(Specification
.where(RegisterDepartmentRepository.idHeadquartersEqual(idHeadquarters)))); .where(RegisterDepartmentRepository.idHeadquartersEqual(idHeadquarters))));
} }
public List<Division>searchByIdDepartment(Integer idDepartment){
/**
* idDepartment の情報を元に Division のレコードを取得
*
* @param Integer idDepartment 検索条件
* @return 検索結果のレコード
*/
public List<Division> searchByIdDepartment(Integer idDepartment) {
return DivisionEntity
.createRegisterDivisionList(registerDivisionRepository.findAll(Specification
.where(RegisterDivisionRepository.idDepartmentEqual(idDepartment))));
}
/**
* idHeadquarters の情報を元に Headquarters のレコードを取得
*
* @param Integer idHeadquarters 検索条件
* @return 検索結果のレコード
*/
public List<Headquarters> searchHeadquartersByIdHeadquarters(Integer idHeadquarters) {
return HeadquartersEntity
.createHeadquartersList(headquartersRepository.findAll(Specification
.where(HeadquartersRepository.idHeadquartersEqual(idHeadquarters))));
}
/**
* idDepartment の情報を元に Department のレコードを取得
*
* @param Integer idDepartment 検索条件
* @return 検索結果のレコード
*/
public List<Department> searchDepartmentByIdDepartment(Integer idDepartment) {
return DepartmentEntity
.createDepartmentList(departmentRepository.findAll(Specification
.where(DepartmentRepository.idDepartmentEqual(idDepartment))));
}
/**
* idDivision の情報を元に Division のレコードを取得
*
* @param Integer idDivision 検索条件
* @return 検索結果のレコード
*/
public List<Division> searchDivisionByIdDivision(Integer idDivision) {
return DivisionEntity return DivisionEntity
.createDivisionList(divisionRepository.findAll(Specification .createDivisionList(divisionRepository.findAll(Specification
.where(DivisionRepository.idDepartmentEqual(idDepartment)))); .where(DivisionRepository.idDivisionEqual(idDivision))));
} }
} }

View File

@@ -26,7 +26,6 @@ public class SearchEmployeeImpl implements SearchEmployee {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
} }
/** /**
* mailAddress を元に Employee Table を検索します。 * mailAddress を元に Employee Table を検索します。
* *
@@ -54,14 +53,14 @@ public class SearchEmployeeImpl implements SearchEmployee {
* @return Table から取得したレコードの情報 * @return Table から取得したレコードの情報
*/ */
public Employee searchEmployeeByIdEmployee(Integer idEmployee) { public Employee searchEmployeeByIdEmployee(Integer idEmployee) {
return EmployeeEntity.createEmployee(employeeRepository.findByIdEmployee(idEmployee).orElse(new EmployeeEntity())); return EmployeeEntity
.createEmployee(employeeRepository.findByIdEmployee(idEmployee).orElse(new EmployeeEntity()));
} }
/** /**
* idDepartment を元に Employee Table を検索します。 * idDivision を元に Employee Table を検索します。
* *
* @param idDepartment 部署ID * @param idDivision 本部ID
* @return Table から取得したレコードの情報 * @return Table から取得したレコードの情報
*/ */
@Override @Override

View File

@@ -27,9 +27,8 @@ public class SearchEmployeeInfoImpl implements SearchEmployeeInfo {
this.employeeInfoRepository = employeeInfoRepository; this.employeeInfoRepository = employeeInfoRepository;
} }
/** /**
* EmployeeInfo (employee join department) のレコードを全件取得 * EmployeeInfo (employee join division join department join headquarters) のレコードを全件取得
* *
* @return 取得したレコード全件 * @return 取得したレコード全件
*/ */
@@ -40,7 +39,9 @@ public class SearchEmployeeInfoImpl implements SearchEmployeeInfo {
} }
/** /**
* SearchConditionEmployee の情報を元に EmployeeInfo (employee join department) のレコードを取得 * SearchConditionEmployee の情報を元に
* EmployeeInfo (employee join division join department join headquarters)
* のレコードを取得
* *
* @param searchConditionEmployee 検索条件 * @param searchConditionEmployee 検索条件
* @return 検索結果のレコードリスト * @return 検索結果のレコードリスト
@@ -56,9 +57,7 @@ public class SearchEmployeeInfoImpl implements SearchEmployeeInfo {
.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.idDivisionEqual(searchConditionEmployee.getIdDivision())) .and(EmployeeInfoRepository.idDivisionEqual(searchConditionEmployee.getIdDivision()))));
)
);
} }
} }

View File

@@ -6,19 +6,26 @@ import java.time.Period;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.example.rhizome.app.domain.service.TenureCalc; import com.example.rhizome.app.domain.service.TenureCalc;
@Service @Service
public class TenureCalucImpl implements TenureCalc { public class TenureCalucImpl implements TenureCalc {
public String tenureCalc(String hireDate){ /**
* hireDate をもとに勤続年数を計算
*
* @param String hireDate
* @return 計算結果の勤続年数
*/
public String tenureCalc(String hireDate) {
String tenure; String tenure;
LocalDate hiredate = LocalDate.parse(hireDate); LocalDate hiredate = LocalDate.parse(hireDate);
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
Period period = Period.between(hiredate, today); Period period = Period.between(hiredate, today);
if(period.getYears()<=0&&period.getMonths()<=0) { if (period.getYears() <= 0 && period.getMonths() <= 0) {
tenure = "0年0ヶ月"; tenure = "0年0ヶ月";
return tenure; return tenure;
}else { } else {
tenure=period.getYears()+"年"+period.getMonths()+"ヶ月"; tenure = period.getYears() + "年" + period.getMonths() + "ヶ月";
return tenure; return tenure;
} }

View File

@@ -18,19 +18,18 @@ import com.example.rhizome.app.infra.repository.DivisionRepository;
@Transactional @Transactional
public class UpdateDepartmentImpl implements UpdateDepartment { public class UpdateDepartmentImpl implements UpdateDepartment {
DivisionRepository divisionRepository; DivisionRepository divisionRepository;
@Autowired @Autowired
public UpdateDepartmentImpl(DivisionRepository divisionRepository public UpdateDepartmentImpl(DivisionRepository divisionRepository) {
) {
this.divisionRepository = divisionRepository; this.divisionRepository = divisionRepository;
} }
/** /**
* department の情報を元に department table のレコードを更新する * departmentInfo の情報を元に
* division table(division join department join headquarters) のレコードを更新する
* *
* @param department 更新のデータ * @param departmentInfo 更新のデータ
*/ */
public void updateDepartment(DepartmentInfo departmentInfo) { public void updateDepartment(DepartmentInfo departmentInfo) {
DivisionEntity divisionEntity = DivisionEntity.convertFrom(departmentInfo); DivisionEntity divisionEntity = DivisionEntity.convertFrom(departmentInfo);
@@ -38,18 +37,14 @@ public class UpdateDepartmentImpl implements UpdateDepartment {
HeadquartersEntity headquartersEntity = divisionEntity.getDepartment().getHeadquarters(); HeadquartersEntity headquartersEntity = divisionEntity.getDepartment().getHeadquarters();
departmentEntity.setNmDepartment( departmentEntity.setNmDepartment(
divisionEntity.getDepartment() divisionEntity.getDepartment()
.getNmDepartment() .getNmDepartment());
);
headquartersEntity.setNmHeadquarters( headquartersEntity.setNmHeadquarters(
divisionEntity.getDepartment() divisionEntity.getDepartment()
.getHeadquarters() .getHeadquarters()
.getNmHeadquarters() .getNmHeadquarters());
);
departmentEntity.setHeadquarters(headquartersEntity); departmentEntity.setHeadquarters(headquartersEntity);
divisionEntity.setDepartment(departmentEntity); divisionEntity.setDepartment(departmentEntity);
divisionRepository.save(divisionEntity); divisionRepository.save(divisionEntity);
} }
} }

View File

@@ -54,8 +54,8 @@ 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.getIdDivision() == null ? beforeEmployee.getIdDivision() : updateEmployee.getIdDivision() updateEmployee.getIdDivision() == null ? beforeEmployee.getIdDivision()
); : updateEmployee.getIdDivision());
} }

View File

@@ -6,7 +6,6 @@
*/ */
package com.example.rhizome.app.infra.entity; package com.example.rhizome.app.infra.entity;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@@ -39,10 +38,7 @@ import lombok.NoArgsConstructor;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
//@NamedEntityGraph(
// name = "department_with_headquarters",
// includeAllAttributes = true
//)
public class DepartmentEntity { public class DepartmentEntity {
/** /**
@@ -69,7 +65,7 @@ public class DepartmentEntity {
private HeadquartersEntity headquarters; private HeadquartersEntity headquarters;
/** /**
* DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。 * DepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。(リスト版)
* *
* @param departmentEntityList department Table のリスト * @param departmentEntityList department Table のリスト
* @return List<Department> リスト * @return List<Department> リスト
@@ -83,11 +79,18 @@ public class DepartmentEntity {
departmentEntity.getIdDepartment(), departmentEntity.getIdDepartment(),
departmentEntity.getNmDepartment(), departmentEntity.getNmDepartment(),
departmentEntity.getIsDisplay(), departmentEntity.getIsDisplay(),
departmentEntity.getHeadquarters() == null ? null : departmentEntity.getHeadquarters().getIdHeadquarters() departmentEntity.getHeadquarters() == null ? null
: departmentEntity.getHeadquarters().getIdHeadquarters()
)).toList(); )).toList();
} }
/**
* RegisterDepartmentEntity(DataAccess層依存)から Department(BusinessLogic層依存型)に変換します。(リスト版)
*
* @param departmentEntityList RegisterDepartmentEntity のリスト
* @return Departmentのリスト
*/
public static List<Department> createDepartmentListBy(List<RegisterDepartmentEntity> departmentEntityList) { public static List<Department> createDepartmentListBy(List<RegisterDepartmentEntity> departmentEntityList) {
// Stream API を利用するとこうなります。 // Stream API を利用するとこうなります。
@@ -103,21 +106,19 @@ public class DepartmentEntity {
} }
/** /**
* Department(BusinessLogic層依存型) から DepartmentEntity(DataAccess層依存)に変換します。 * DepartmentInfo から DepartmentEntity に変換します。
* *
* @param department department モデルの値 * @param departmentInfo DepartmentInfo
* @return DepartmentEntity に変換したインスタンス * @return DepartmentEntity のインスタンス
*/ */
public static DepartmentEntity convertFrom(DepartmentInfo departmentInfo) { public static DepartmentEntity convertFrom(DepartmentInfo departmentInfo) {
return new DepartmentEntity( return new DepartmentEntity(
departmentInfo.getIdDepartment(), departmentInfo.getIdDepartment(),
departmentInfo.getNmDepartment(), departmentInfo.getNmDepartment(),
(Integer)0, (Integer) 0,
new HeadquartersEntity( new HeadquartersEntity(
departmentInfo.getIdHeadquarters(), departmentInfo.getIdHeadquarters(),
departmentInfo.getNmHeadquarters(), departmentInfo.getNmHeadquarters(),
(Integer)0 (Integer) 0));
) }
);
}
} }

View File

@@ -14,13 +14,14 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* Division join Department,Headquarters テーブルの Entity
*
*/
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@NamedEntityGraph( @NamedEntityGraph(name = "division_with_department_with_headquarters", includeAllAttributes = true)
name = "division_with_department_with_headquarters",
includeAllAttributes = true
)
public class DepartmentInfoEntity { public class DepartmentInfoEntity {
private DivisionEntity division; private DivisionEntity division;
@@ -29,7 +30,12 @@ public class DepartmentInfoEntity {
private HeadquartersEntity headquarters; private HeadquartersEntity headquarters;
/**
* DepartmentInfo をDepartmentInfoEntityに変換します。
*
*@param departmentInfo DepartmentInfo のインスタンス
*@return DepartmentInfoEntityのインスタンス
*/
public static DepartmentInfoEntity convertFrom(DepartmentInfo departmentInfo) { public static DepartmentInfoEntity convertFrom(DepartmentInfo departmentInfo) {
return new DepartmentInfoEntity( return new DepartmentInfoEntity(
new DivisionEntity( new DivisionEntity(
@@ -43,10 +49,7 @@ public class DepartmentInfoEntity {
new HeadquartersEntity( new HeadquartersEntity(
departmentInfo.getIdHeadquarters(), departmentInfo.getIdHeadquarters(),
departmentInfo.getNmHeadquarters(), departmentInfo.getNmHeadquarters(),
0 0))),
)
)
),
new DepartmentEntity( new DepartmentEntity(
departmentInfo.getIdDepartment(), departmentInfo.getIdDepartment(),
departmentInfo.getNmDepartment(), departmentInfo.getNmDepartment(),
@@ -54,68 +57,58 @@ public class DepartmentInfoEntity {
new HeadquartersEntity( new HeadquartersEntity(
departmentInfo.getIdHeadquarters(), departmentInfo.getIdHeadquarters(),
departmentInfo.getNmHeadquarters(), departmentInfo.getNmHeadquarters(),
0 0)),
)
),
new HeadquartersEntity( new HeadquartersEntity(
departmentInfo.getIdHeadquarters(), departmentInfo.getIdHeadquarters(),
departmentInfo.getNmHeadquarters(), departmentInfo.getNmHeadquarters(),
0 0)
)
); );
} }
/** /**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。 * DepartmentInfoEntity を AllDepartmentInfo に変換します。
* *
* @param employeeDepartmentEntity  EmployeeDepartmentEntity のインスタンス * @param departmentInfoEntity  DepartmentInfoEntity のインスタンス
* @return EmployeeInfo のインスタンス * @return AllDepartmentInfo のインスタンス
*/ */
public static AllDepartmentInfo createDepartmentInfo(DepartmentInfoEntity departmentInfoEntity) { public static AllDepartmentInfo createDepartmentInfo(DepartmentInfoEntity departmentInfoEntity) {
// コンストラクタを使って書くとSetterを使用するより簡略化出来ます。
// 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、
// どうしてこの書き方が出来るのかを理解できる様になりましょう。
return new AllDepartmentInfo( return new AllDepartmentInfo(
new Division( new Division(
departmentInfoEntity.getDivision() departmentInfoEntity.getDivision() == null ? null
== null ? null : departmentInfoEntity.getDivision().getIdDivision(), : departmentInfoEntity.getDivision().getIdDivision(),
departmentInfoEntity.getDivision() departmentInfoEntity.getDivision() == null ? null
== null ? null : departmentInfoEntity.getDivision().getNmDivision(), : departmentInfoEntity.getDivision().getNmDivision(),
departmentInfoEntity.getDivision() departmentInfoEntity.getDivision() == null ? null
== null ? null : departmentInfoEntity.getDivision().getIsDisplay(), : departmentInfoEntity.getDivision().getIsDisplay(),
departmentInfoEntity.getDepartment() departmentInfoEntity.getDepartment() == null ? null
== null ? null : departmentInfoEntity.getDepartment().getIdDepartment() : departmentInfoEntity.getDepartment().getIdDepartment()),
),
new Department( new Department(
departmentInfoEntity.getDepartment() departmentInfoEntity.getDepartment() == null ? null
== null ? null : departmentInfoEntity.getDepartment().getIdDepartment(), : departmentInfoEntity.getDepartment().getIdDepartment(),
departmentInfoEntity.getDepartment() departmentInfoEntity.getDepartment() == null ? null
== null ? null : departmentInfoEntity.getDepartment().getNmDepartment(), : departmentInfoEntity.getDepartment().getNmDepartment(),
departmentInfoEntity.getDepartment() departmentInfoEntity.getDepartment() == null ? null
== null ? null : departmentInfoEntity.getDepartment().getIsDisplay(), : departmentInfoEntity.getDepartment().getIsDisplay(),
departmentInfoEntity.getHeadquarters() departmentInfoEntity.getHeadquarters() == null ? null
== null ? null : departmentInfoEntity.getHeadquarters().getIdHeadquarters() : departmentInfoEntity.getHeadquarters().getIdHeadquarters()),
),
new Headquarters( new Headquarters(
departmentInfoEntity.getHeadquarters() departmentInfoEntity.getHeadquarters() == null ? null
== null ? null : departmentInfoEntity.getHeadquarters().getIdHeadquarters(), : departmentInfoEntity.getHeadquarters().getIdHeadquarters(),
departmentInfoEntity.getHeadquarters() departmentInfoEntity.getHeadquarters() == null ? null
== null ? null : departmentInfoEntity.getHeadquarters().getNmHeadquarters(), : departmentInfoEntity.getHeadquarters().getNmHeadquarters(),
departmentInfoEntity.getHeadquarters() departmentInfoEntity.getHeadquarters() == null ? null
== null ? null : departmentInfoEntity.getHeadquarters().getIsDisplay() : departmentInfoEntity.getHeadquarters().getIsDisplay()));
)
);
} }
/** /**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。 * DepartmentInfoEntity を AllDepartmentInfo に変換します。
* (リスト版) * (リスト版)
* *
* @param employeeDepartmentEntityList EmployeeDepartmentEntity インスタンスのリスト * @param departmentInfoEntity DepartmentInfoEntity インスタンスのリスト
* @return EmployeeInfo インスタンスのリスト * @return AllDepartmentInfo インスタンスのリスト
*/ */
public static List<AllDepartmentInfo> createDepartmentInfoList(List<DepartmentInfoEntity> departmentInfoEntity) { public static List<AllDepartmentInfo> createDepartmentInfoList(List<DepartmentInfoEntity> departmentInfoEntity) {
@@ -124,40 +117,44 @@ public class DepartmentInfoEntity {
} }
/**
* DivisionEntity を AllDepartmentInfo に変換します。
*
* @param divisionEntity DivisionEntity インスタンス
* @return AllDepartmentInfo インスタンス
*/
public static AllDepartmentInfo createDepartmentInfo(DivisionEntity divisionEntity) { public static AllDepartmentInfo createDepartmentInfo(DivisionEntity divisionEntity) {
// コンストラクタを使って書くとSetterを使用するより簡略化出来ます。
// 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、
// どうしてこの書き方が出来るのかを理解できる様になりましょう。
return new AllDepartmentInfo( return new AllDepartmentInfo(
new Division( new Division(
divisionEntity.getIdDivision(), divisionEntity.getIdDivision(),
divisionEntity.getNmDivision(), divisionEntity.getNmDivision(),
divisionEntity.getIsDisplay(), divisionEntity.getIsDisplay(),
divisionEntity.getDepartment().getIdDepartment() divisionEntity.getDepartment().getIdDepartment()),
),
new Department( new Department(
divisionEntity.getDepartment() divisionEntity.getDepartment() == null ? null
== null ? null : divisionEntity.getDepartment().getIdDepartment(), : divisionEntity.getDepartment().getIdDepartment(),
divisionEntity.getDepartment() divisionEntity.getDepartment() == null ? null
== null ? null : divisionEntity.getDepartment().getNmDepartment(), : divisionEntity.getDepartment().getNmDepartment(),
divisionEntity.getDepartment() divisionEntity.getDepartment() == null ? null : divisionEntity.getDepartment().getIsDisplay(),
== null ? null : divisionEntity.getDepartment().getIsDisplay(), divisionEntity.getDepartment().getHeadquarters() == null ? null
divisionEntity.getDepartment().getHeadquarters() : divisionEntity.getDepartment().getHeadquarters().getIdHeadquarters()),
== null ? null : divisionEntity.getDepartment().getHeadquarters().getIdHeadquarters()
),
new Headquarters( new Headquarters(
divisionEntity.getDepartment().getHeadquarters() divisionEntity.getDepartment().getHeadquarters() == null ? null
== null ? null : divisionEntity.getDepartment().getHeadquarters().getIdHeadquarters(), : divisionEntity.getDepartment().getHeadquarters().getIdHeadquarters(),
divisionEntity.getDepartment().getHeadquarters() divisionEntity.getDepartment().getHeadquarters() == null ? null
== null ? null : divisionEntity.getDepartment().getHeadquarters().getNmHeadquarters(), : divisionEntity.getDepartment().getHeadquarters().getNmHeadquarters(),
divisionEntity.getDepartment().getHeadquarters() divisionEntity.getDepartment().getHeadquarters() == null ? null
== null ? null : divisionEntity.getDepartment().getHeadquarters().getIsDisplay() : divisionEntity.getDepartment().getHeadquarters().getIsDisplay()));
)
);
} }
/**
* DivisionEntity を AllDepartmentInfo に変換します。(リスト版)
*
* @param divisionEntity DivisionEntity インスタンスのリスト
* @return AllDepartmentInfo インスタンスのリスト
*/
public static List<AllDepartmentInfo> AfterSearchCreateDepartmentInfoList(List<DivisionEntity> divisionEntity) { public static List<AllDepartmentInfo> AfterSearchCreateDepartmentInfoList(List<DivisionEntity> divisionEntity) {
// StreamAPI を使うとこうなります。 // StreamAPI を使うとこうなります。

View File

@@ -21,7 +21,10 @@ import com.example.rhizome.app.domain.model.Division;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* Division テーブルの Entity
*
*/
@Entity @Entity
@Table(name = "division") @Table(name = "division")
@Data @Data
@@ -51,27 +54,33 @@ public class DivisionEntity {
@Fetch(FetchMode.JOIN) @Fetch(FetchMode.JOIN)
private DepartmentEntity department; private DepartmentEntity department;
/**
* DepartmentInfo を DivisionEntity に変換します。
*
* @param departmentInfo  DepartmentInfo のインスタンス
* @return DivisionEntity join Department,Headquarters のインスタンス
*/
public static DivisionEntity convertFrom(DepartmentInfo departmentInfo) { public static DivisionEntity convertFrom(DepartmentInfo departmentInfo) {
return new DivisionEntity( return new DivisionEntity(
departmentInfo.getIdDivision(), departmentInfo.getIdDivision(),
departmentInfo.getNmDivision(), departmentInfo.getNmDivision(),
(Integer)0, (Integer) 0,
new DepartmentEntity( new DepartmentEntity(
departmentInfo.getIdDepartment(), departmentInfo.getIdDepartment(),
departmentInfo.getNmDepartment(), departmentInfo.getNmDepartment(),
(Integer)0, (Integer) 0,
new HeadquartersEntity( new HeadquartersEntity(
departmentInfo.getIdHeadquarters(), departmentInfo.getIdHeadquarters(),
departmentInfo.getNmHeadquarters(), departmentInfo.getNmHeadquarters(),
(Integer)0 (Integer) 0)));
)
)
);
} }
/**
* DivisionEntity を Divisionに変換します。
*
* @param divisionEntity  DivisionEntity のインスタンス
* @return Divisionのインスタンス
*/
public static Division createDivision(DivisionEntity divisionEntity) { public static Division createDivision(DivisionEntity divisionEntity) {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。 // 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return new Division( return new Division(
@@ -83,20 +92,36 @@ public class DivisionEntity {
); );
} }
/**
* DivisionEntity を Divisionに変換します。(リスト版)
*
* @param divisionEntity  DivisionEntity のインスタンスのリスト
* @return Divisionのインスタンスのリスト
*/
public static List<Division> createDivisionList(List<DivisionEntity> divisionEntityList) { public static List<Division> createDivisionList(List<DivisionEntity> divisionEntityList) {
return divisionEntityList return divisionEntityList
.stream() .stream()
.map(DivisionEntity ::createDivision ).toList(); .map(DivisionEntity::createDivision).toList();
} }
/**
* RegisterDivisionEntity を Divisionに変換します。(リスト版)
*
* @param divisionEntityList  RegisterDivisionEntity のインスタンスのリスト
* @return Divisionのインスタンスのリスト
*/
public static List<Division> createRegisterDivisionList(List<RegisterDivisionEntity> divisionEntityList) {
return divisionEntityList
.stream()
.map(divisionEntity -> new Division(
divisionEntity.getIdDivision(),
divisionEntity.getNmDivision(),
divisionEntity.getIsDisplay(),
divisionEntity.getIdDepartment() == null ? null : divisionEntity.getIdDepartment()
)).toList();
}
} }

View File

@@ -15,17 +15,14 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* Employee + Department の Join 情報を保持するEntity * Employee + Division + Department + Headquarters の Join 情報を保持するEntity
* *
* @author IT-College * @author IT-College
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@NamedEntityGraph( @NamedEntityGraph(name = "employee_with_division_with_department_with_headquarters", includeAllAttributes = true)
name = "employee_with_division_with_department_with_headquarters",
includeAllAttributes = true
)
public class EmployeeDepartmentEntity { public class EmployeeDepartmentEntity {
private EmployeeEntity Employee; private EmployeeEntity Employee;
@@ -36,12 +33,11 @@ public class EmployeeDepartmentEntity {
private HeadquartersEntity headquarters; private HeadquartersEntity headquarters;
/** /**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。 * EmployeeDepartmentEntity(DataAccess層依存) を AllEmployeeInfo(BusinessLogic層依存) に変換します。
* *
* @param employeeDepartmentEntity  EmployeeDepartmentEntity のインスタンス * @param employeeDepartmentEntity  EmployeeDepartmentEntity のインスタンス
* @return EmployeeInfo のインスタンス * @return AllEmployeeInfo のインスタンス
*/ */
public static AllEmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) { public static AllEmployeeInfo createEmployeeInfo(EmployeeDepartmentEntity employeeDepartmentEntity) {
@@ -57,59 +53,59 @@ public class EmployeeDepartmentEntity {
employeeDepartmentEntity.getEmployee().getPassword(), employeeDepartmentEntity.getEmployee().getPassword(),
employeeDepartmentEntity.getEmployee().getHireDate(), employeeDepartmentEntity.getEmployee().getHireDate(),
employeeDepartmentEntity.getEmployee().getAdminAuth(), employeeDepartmentEntity.getEmployee().getAdminAuth(),
employeeDepartmentEntity.getDivision() employeeDepartmentEntity.getDivision() == null ? null
== null ? null : employeeDepartmentEntity.getDivision().getIdDivision()), : employeeDepartmentEntity.getDivision().getIdDivision()),
new Division( new Division(
employeeDepartmentEntity.getDivision() employeeDepartmentEntity.getDivision() == null ? null
== null ? null : employeeDepartmentEntity.getDivision().getIdDivision(), : employeeDepartmentEntity.getDivision().getIdDivision(),
employeeDepartmentEntity.getDivision() employeeDepartmentEntity.getDivision() == null ? null
== null ? null : employeeDepartmentEntity.getDivision().getNmDivision(), : employeeDepartmentEntity.getDivision().getNmDivision(),
employeeDepartmentEntity.getDivision() employeeDepartmentEntity.getDivision() == null ? null
== null ? null : employeeDepartmentEntity.getDivision().getIsDisplay(), : employeeDepartmentEntity.getDivision().getIsDisplay(),
employeeDepartmentEntity.getDepartment() employeeDepartmentEntity.getDepartment() == null ? null
== null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment() : employeeDepartmentEntity.getDepartment().getIdDepartment()),
),
new Department( new Department(
employeeDepartmentEntity.getDepartment() employeeDepartmentEntity.getDepartment() == null ? null
== null ? null : employeeDepartmentEntity.getDepartment().getIdDepartment(), : employeeDepartmentEntity.getDepartment().getIdDepartment(),
employeeDepartmentEntity.getDepartment() employeeDepartmentEntity.getDepartment() == null ? null
== null ? null : employeeDepartmentEntity.getDepartment().getNmDepartment(), : employeeDepartmentEntity.getDepartment().getNmDepartment(),
employeeDepartmentEntity.getDepartment() employeeDepartmentEntity.getDepartment() == null ? null
== null ? null : employeeDepartmentEntity.getDepartment().getIsDisplay(), : employeeDepartmentEntity.getDepartment().getIsDisplay(),
employeeDepartmentEntity.getHeadquarters() employeeDepartmentEntity.getHeadquarters() == null ? null
== null ? null : employeeDepartmentEntity.getHeadquarters().getIdHeadquarters() : employeeDepartmentEntity.getHeadquarters().getIdHeadquarters()),
),
new Headquarters( new Headquarters(
employeeDepartmentEntity.getHeadquarters() employeeDepartmentEntity.getHeadquarters() == null ? null
== null ? null : employeeDepartmentEntity.getHeadquarters().getIdHeadquarters(), : employeeDepartmentEntity.getHeadquarters().getIdHeadquarters(),
employeeDepartmentEntity.getHeadquarters() employeeDepartmentEntity.getHeadquarters() == null ? null
== null ? null : employeeDepartmentEntity.getHeadquarters().getNmHeadquarters(), : employeeDepartmentEntity.getHeadquarters().getNmHeadquarters(),
employeeDepartmentEntity.getHeadquarters() employeeDepartmentEntity.getHeadquarters() == null ? null
== null ? null : employeeDepartmentEntity.getHeadquarters().getIsDisplay() : employeeDepartmentEntity.getHeadquarters().getIsDisplay()));
)
);
} }
/** /**
* EmployeeDepartmentEntity(DataAccess層依存) を EmployeeInfo(BusinessLogic層依存) に変換します。 * EmployeeDepartmentEntity(DataAccess層依存) を AllEmployeeInfo(BusinessLogic層依存) に変換します。
* (リスト版) * (リスト版)
* *
* @param employeeDepartmentEntityList EmployeeDepartmentEntity インスタンスのリスト * @param employeeDepartmentEntityList EmployeeDepartmentEntity インスタンスのリスト
* @return EmployeeInfo インスタンスのリスト * @return AllEmployeeInfo インスタンスのリスト
*/ */
public static List<AllEmployeeInfo> 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();
} }
/**
* EmployeeEntity(DataAccess層依存) を AllEmployeeInfo(BusinessLogic層依存) に変換します。
*
* @param employeeEntity  EmployeeEntity のインスタンス
* @return AllEmployeeInfo のインスタンス
*/
public static AllEmployeeInfo createEmployeeInfo(EmployeeEntity employeeEntity) { public static AllEmployeeInfo createEmployeeInfo(EmployeeEntity employeeEntity) {
// コンストラクタを使って書くとSetterを使用するより簡略化出来ます。
// 混乱してしまう人は落ち着いて EmployeeInfo のフィールドを見に行って、
// どうしてこの書き方が出来るのかを理解できる様になりましょう。
return new AllEmployeeInfo( return new AllEmployeeInfo(
new Employee( new Employee(
employeeEntity.getIdEmployee(), employeeEntity.getIdEmployee(),
@@ -119,40 +115,38 @@ public class EmployeeDepartmentEntity {
employeeEntity.getPassword(), employeeEntity.getPassword(),
employeeEntity.getHireDate(), employeeEntity.getHireDate(),
employeeEntity.getAdminAuth(), employeeEntity.getAdminAuth(),
employeeEntity.getDivision() employeeEntity.getDivision() == null ? null : employeeEntity.getDivision().getIdDivision()),
== null ? null : employeeEntity.getDivision().getIdDivision()),
new Division( new Division(
employeeEntity.getDivision() employeeEntity.getDivision() == null ? null : employeeEntity.getDivision().getIdDivision(),
== null ? null : employeeEntity.getDivision().getIdDivision(), employeeEntity.getDivision() == null ? null : employeeEntity.getDivision().getNmDivision(),
employeeEntity.getDivision() employeeEntity.getDivision() == null ? null : employeeEntity.getDivision().getIsDisplay(),
== null ? null : employeeEntity.getDivision().getNmDivision(), employeeEntity.getDivision().getDepartment() == null ? null
employeeEntity.getDivision() : employeeEntity.getDivision().getDepartment().getIdDepartment()),
== null ? null : employeeEntity.getDivision().getIsDisplay(),
employeeEntity.getDivision().getDepartment()
== null ? null : employeeEntity.getDivision().getDepartment().getIdDepartment()
),
new Department( new Department(
employeeEntity.getDivision().getDepartment() employeeEntity.getDivision().getDepartment() == null ? null
== null ? null : employeeEntity.getDivision().getDepartment().getIdDepartment(), : employeeEntity.getDivision().getDepartment().getIdDepartment(),
employeeEntity.getDivision().getDepartment() employeeEntity.getDivision().getDepartment() == null ? null
== null ? null : employeeEntity.getDivision().getDepartment().getNmDepartment(), : employeeEntity.getDivision().getDepartment().getNmDepartment(),
employeeEntity.getDivision().getDepartment() employeeEntity.getDivision().getDepartment() == null ? null
== null ? null : employeeEntity.getDivision().getDepartment().getIsDisplay(), : employeeEntity.getDivision().getDepartment().getIsDisplay(),
employeeEntity.getDivision().getDepartment().getHeadquarters() employeeEntity.getDivision().getDepartment().getHeadquarters() == null ? null
== null ? null : employeeEntity.getDivision().getDepartment().getHeadquarters().getIdHeadquarters() : employeeEntity.getDivision().getDepartment().getHeadquarters().getIdHeadquarters()),
),
new Headquarters( new Headquarters(
employeeEntity.getDivision().getDepartment().getHeadquarters() employeeEntity.getDivision().getDepartment().getHeadquarters() == null ? null
== null ? null : employeeEntity.getDivision().getDepartment().getHeadquarters().getIdHeadquarters(), : employeeEntity.getDivision().getDepartment().getHeadquarters().getIdHeadquarters(),
employeeEntity.getDivision().getDepartment().getHeadquarters() employeeEntity.getDivision().getDepartment().getHeadquarters() == null ? null
== null ? null : employeeEntity.getDivision().getDepartment().getHeadquarters().getNmHeadquarters(), : employeeEntity.getDivision().getDepartment().getHeadquarters().getNmHeadquarters(),
employeeEntity.getDivision().getDepartment().getHeadquarters() employeeEntity.getDivision().getDepartment().getHeadquarters() == null ? null
== null ? null : employeeEntity.getDivision().getDepartment().getHeadquarters().getIsDisplay() : employeeEntity.getDivision().getDepartment().getHeadquarters().getIsDisplay()));
)
);
} }
/**
* EmployeeEntity(DataAccess層依存) を AllEmployeeInfo(BusinessLogic層依存) に変換します。(リスト版)
*
* @param employeeEntity  EmployeeEntity のインスタンスのリスト
* @return AllEmployeeInfo のインスタンスのリスト
*/
public static List<AllEmployeeInfo> AfterSearchCreateEmployeeInfoList(List<EmployeeEntity> employeeEntityList) { public static List<AllEmployeeInfo> AfterSearchCreateEmployeeInfoList(List<EmployeeEntity> employeeEntityList) {

View File

@@ -6,7 +6,6 @@
*/ */
package com.example.rhizome.app.infra.entity; package com.example.rhizome.app.infra.entity;
import java.util.List; import java.util.List;
import javax.persistence.Column; import javax.persistence.Column;
@@ -33,7 +32,6 @@ import lombok.NoArgsConstructor;
/** /**
* EmployeeテーブルのEntity * EmployeeテーブルのEntity
* *
* @author IT-College
*/ */
@Entity @Entity
@Table(name = "employee") @Table(name = "employee")
@@ -93,11 +91,10 @@ public class EmployeeEntity {
@Fetch(FetchMode.JOIN) @Fetch(FetchMode.JOIN)
private DivisionEntity division; private DivisionEntity division;
/** /**
* Employee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。 * EmployeeInfo(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。
* *
* @param employee Employee Table の中身 * @param employeeInfo EmployeeInfo Table の中身
* @return EmployeeEntity のインスタンス(1レコード分) * @return EmployeeEntity のインスタンス(1レコード分)
*/ */
public static EmployeeEntity convertFrom(EmployeeInfo employeeInfo) { public static EmployeeEntity convertFrom(EmployeeInfo employeeInfo) {
@@ -114,8 +111,7 @@ public class EmployeeEntity {
employeeInfo.getDivision().getIdDivision(), employeeInfo.getDivision().getIdDivision(),
employeeInfo.getDivision().getNmDivision(), employeeInfo.getDivision().getNmDivision(),
employeeInfo.getDivision().getIsDisplay(), employeeInfo.getDivision().getIsDisplay(),
null) null));
);
} }
/** /**
@@ -153,8 +149,7 @@ public class EmployeeEntity {
employeeEntity.getPassword(), employeeEntity.getPassword(),
employeeEntity.getHireDate(), employeeEntity.getHireDate(),
employeeEntity.getAdminAuth(), employeeEntity.getAdminAuth(),
employeeEntity.getDivision().getIdDivision() employeeEntity.getDivision().getIdDivision());
);
} }
/** /**
@@ -191,10 +186,7 @@ public class EmployeeEntity {
getMailAddress(), getMailAddress(),
getPassword(), getPassword(),
getAdminAuth(), getAdminAuth(),
getDivision().getIdDivision() getDivision().getIdDivision());
);
} }
} }

View File

@@ -16,6 +16,10 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/**
* HeadquartersテーブルのEntity
*
*/
@Entity @Entity
@Table(name = "headquarters") @Table(name = "headquarters")
@Data @Data
@@ -40,31 +44,38 @@ public class HeadquartersEntity {
@Column(name = "is_display", nullable = false) @Column(name = "is_display", nullable = false)
private Integer isDisplay; private Integer isDisplay;
public static Headquarters createHeadquarters(HeadquartersEntity headquartersEntity) { public static Headquarters createHeadquarters(HeadquartersEntity headquartersEntity) {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。 // 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
return new Headquarters( return new Headquarters(
headquartersEntity.getIdHeadquarters(), headquartersEntity.getIdHeadquarters(),
headquartersEntity.getNmHeadquarters(), headquartersEntity.getNmHeadquarters(),
headquartersEntity.getIsDisplay() headquartersEntity.getIsDisplay());
);
} }
/**
* DBから返ってきたHeadquartersEntityのリストをHeadquartersのリストに変換する
*
* @param HeadquartersEntityのリスト
* @return headquartersのリスト
*/
public static List<Headquarters> createHeadquartersList(List<HeadquartersEntity> headquartersEntityList) { public static List<Headquarters> createHeadquartersList(List<HeadquartersEntity> headquartersEntityList) {
return headquartersEntityList return headquartersEntityList
.stream() .stream()
.map(HeadquartersEntity ::createHeadquarters ).toList(); .map(HeadquartersEntity::createHeadquarters).toList();
} }
/**
* 三つのテーブルがつながった部署情報であるDepartmentInfoから
* 本部情報だけを引っ張ってきてHeadquartersEntityに入れる
*
* @param DepartmentInfo
* @return 新しく作成されたHeadquartersEntity
*
*/
public static HeadquartersEntity convertFrom(DepartmentInfo departmentInfo) { public static HeadquartersEntity convertFrom(DepartmentInfo departmentInfo) {
return new HeadquartersEntity( return new HeadquartersEntity(
departmentInfo.getIdHeadquarters(), departmentInfo.getIdHeadquarters(),
departmentInfo.getNmHeadquarters(), departmentInfo.getNmHeadquarters(),
(Integer)0 (Integer) 0);
);
} }
} }

View File

@@ -14,9 +14,8 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* EmployeeテーブルのEntity * 社員情報登録用のEmployeeテーブルのEntity
* *
* @author IT-College
*/ */
@Entity @Entity
@Table(name = "employee") @Table(name = "employee")
@@ -26,7 +25,6 @@ import lombok.NoArgsConstructor;
public class InsertEmployeeEntity { public class InsertEmployeeEntity {
/** /**
* 社員ID * 社員ID
*/ */
@@ -76,12 +74,11 @@ public class InsertEmployeeEntity {
@Column(name = "id_division", nullable = false) @Column(name = "id_division", nullable = false)
private Integer idDivision; private Integer idDivision;
/** /**
* Employee(BusinessLogic 依存)を EmployeeEntity(DataAccess層依存)に変換します。 * Employee(BusinessLogic 依存)を InsertEmployeeEntity(DataAccess層依存)に変換します。
* *
* @param employee Employee Table の中身 * @param employee Employee Table の中身
* @return EmployeeEntity のインスタンス(1レコード分) * @return InsertEmployeeEntity のインスタンス(1レコード分)
*/ */
public static InsertEmployeeEntity convertFrom(Employee employee) { public static InsertEmployeeEntity convertFrom(Employee employee) {
// 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。 // 値を既に持ったインスタンスの生成に、コンストラクタを使用するとこうなります。
@@ -93,8 +90,7 @@ public class InsertEmployeeEntity {
employee.getPassword(), employee.getPassword(),
employee.getHireDate(), employee.getHireDate(),
employee.getAdminAuth(), employee.getAdminAuth(),
employee.getIdDivision() employee.getIdDivision());
);
} }
} }

View File

@@ -1,4 +1,5 @@
package com.example.rhizome.app.infra.entity; package com.example.rhizome.app.infra.entity;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
@@ -11,19 +12,15 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* Department テーブルの Entity * 社員情報登録用のDepartment テーブルの Entity
* *
* @author IT-College
*/ */
@Entity @Entity
@Table(name = "department") @Table(name = "department")
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
//@NamedEntityGraph(
// name = "department_with_headquarters",
// includeAllAttributes = true
//)
public class RegisterDepartmentEntity { public class RegisterDepartmentEntity {
/** /**
@@ -44,8 +41,7 @@ public class RegisterDepartmentEntity {
@Column(name = "is_display", nullable = false) @Column(name = "is_display", nullable = false)
private Integer isDisplay; private Integer isDisplay;
@Column(name = "id_headquarters",nullable = false) @Column(name = "id_headquarters", nullable = false)
private Integer idHeadquarters; private Integer idHeadquarters;
} }

View File

@@ -56,7 +56,6 @@ public interface DepartmentInfoRepository
@EntityGraph(attributePaths = { "department", "department.headquarters" }) @EntityGraph(attributePaths = { "department", "department.headquarters" })
void save(@Nullable Specification<DivisionEntity> spec); void save(@Nullable Specification<DivisionEntity> spec);
@Query("SELECT DISTINCT new com.example.rhizome.app.infra.entity.DepartmentInfoEntity(di,de,h)FROM DivisionEntity di " @Query("SELECT DISTINCT new com.example.rhizome.app.infra.entity.DepartmentInfoEntity(di,de,h)FROM DivisionEntity di "
+ "INNER JOIN di.department de " + "INNER JOIN di.department de "
+ "INNER JOIN de.headquarters h " + "INNER JOIN de.headquarters h "
@@ -81,6 +80,4 @@ public interface DepartmentInfoRepository
@Param("idDepartment") Integer idDepartment, @Param("idDepartment") Integer idDepartment,
@Param("idDivision") Integer idDivision); @Param("idDivision") Integer idDivision);
} }

View File

@@ -8,7 +8,6 @@ import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.DepartmentEntity; import com.example.rhizome.app.infra.entity.DepartmentEntity;
import com.example.rhizome.app.infra.entity.HeadquartersEntity; import com.example.rhizome.app.infra.entity.HeadquartersEntity;
/** /**
* Specification: * Specification:
* 関数型インターフェースです。 * 関数型インターフェースです。
@@ -22,12 +21,11 @@ import com.example.rhizome.app.infra.entity.HeadquartersEntity;
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。 * 戻り値はクエリを格納しているPredicateオブジェクトとなります。
*/ */
@Repository @Repository
public interface DepartmentRepository extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> { public interface DepartmentRepository
extends JpaRepository<DepartmentEntity, Integer>, JpaSpecificationExecutor<DepartmentEntity> {
static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) { static Specification<DepartmentEntity> idDepartmentEqual(Integer idDepartment) {
return idDepartment == null ? return idDepartment == null ? null :
null :
// 戻り値の型 Specification<DepartmentEntity> にキャスト // 戻り値の型 Specification<DepartmentEntity> にキャスト
(Specification<DepartmentEntity>) (Specification<DepartmentEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)" // ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
@@ -36,27 +34,17 @@ public interface DepartmentRepository extends JpaRepository<DepartmentEntity, In
} }
static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) { static Specification<DepartmentEntity> nmDepartmentEqual(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ? return (nmDepartment == null || nmDepartment.isEmpty()) ? null
null : : (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
(Specification<DepartmentEntity>) .like(root.get("nmDepartment"), nmDepartment);
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), nmDepartment);
} }
static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) { static Specification<DepartmentEntity> nmDepartmentLike(String nmDepartment) {
return (nmDepartment == null || nmDepartment.isEmpty()) ? return (nmDepartment == null || nmDepartment.isEmpty()) ? null
null : : (Specification<DepartmentEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
(Specification<DepartmentEntity>) .like(root.get("nmDepartment"), "%" + nmDepartment + "%");
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDepartment"), "%" + nmDepartment + "%");
} }
DepartmentEntity findByHeadquartersAndNmDepartment(HeadquartersEntity headquartersEntity, String nmDepartment);
DepartmentEntity findByHeadquartersAndNmDepartment(HeadquartersEntity headquartersEntity,String nmDepartment);
// @Query("SELECT DISTINCT new com.example.rhizome.app.infra.entity.DepartmentEntity(de,h)FROM DepartmentEntity de "
// + "INNER JOIN de.headquarters h "
// + "WHERE h.idHeadquarters =:idHeadquarters")
// List<DepartmentEntity> searchDepartmentByIdHeadquarters(
// @Param("idHeadquarters") Integer IdHeadquarters);
} }

View File

@@ -1,18 +1,22 @@
package com.example.rhizome.app.infra.repository; package com.example.rhizome.app.infra.repository;
import javax.transaction.Transactional;
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.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.DivisionEntity; import com.example.rhizome.app.infra.entity.DivisionEntity;
@Repository @Repository
public interface DivisionRepository extends JpaRepository<DivisionEntity, Integer>, JpaSpecificationExecutor<DivisionEntity>{ public interface DivisionRepository
extends JpaRepository<DivisionEntity, Integer>, JpaSpecificationExecutor<DivisionEntity> {
static Specification<DivisionEntity> idDivisionEqual(Integer idDivision) { static Specification<DivisionEntity> idDivisionEqual(Integer idDivision) {
return idDivision == null ? return idDivision == null ? null :
null :
// 戻り値の型 Specification<DepartmentEntity> にキャスト // 戻り値の型 Specification<DepartmentEntity> にキャスト
(Specification<DivisionEntity>) (Specification<DivisionEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)" // ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
@@ -21,14 +25,13 @@ public interface DivisionRepository extends JpaRepository<DivisionEntity, Intege
} }
static Specification<DivisionEntity> nmDivisionEqual(String nmDivision) { static Specification<DivisionEntity> nmDivisionEqual(String nmDivision) {
return (nmDivision == null || nmDivision.isEmpty()) ? return (nmDivision == null || nmDivision.isEmpty()) ? null
null : : (Specification<DivisionEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
(Specification<DivisionEntity>) .like(root.get("nmDivision"), nmDivision);
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmDivision"), nmDivision);
} }
static Specification<DivisionEntity> idDepartmentEqual(Integer idDepartment) { static Specification<DivisionEntity> idDepartmentEqual(Integer idDepartment) {
return idDepartment == null ? return idDepartment == null ? null :
null :
// 戻り値の型 Specification<DepartmentEntity> にキャスト // 戻り値の型 Specification<DepartmentEntity> にキャスト
(Specification<DivisionEntity>) (Specification<DivisionEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)" // ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
@@ -36,4 +39,10 @@ public interface DivisionRepository extends JpaRepository<DivisionEntity, Intege
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idDepartment"), idDepartment); (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idDepartment"), idDepartment);
} }
@Transactional
@Modifying
@Query("DELETE FROM DivisionEntity di "
+ "WHERE di.idDivision =:idDivision")
void deleteByIdDivision(Integer idDivision);
} }

View File

@@ -27,11 +27,11 @@ import com.example.rhizome.app.infra.entity.EmployeeEntity;
* 戻り値はクエリを格納しているPredicateオブジェクトとなります。 * 戻り値はクエリを格納しているPredicateオブジェクトとなります。
*/ */
@Repository @Repository
public interface EmployeeInfoRepository extends JpaRepository<EmployeeEntity, Integer>, JpaSpecificationExecutor<EmployeeEntity> { public interface EmployeeInfoRepository
extends JpaRepository<EmployeeEntity, Integer>, JpaSpecificationExecutor<EmployeeEntity> {
static Specification<EmployeeEntity> idEmployeeEqual(Integer idEmployee) { static Specification<EmployeeEntity> idEmployeeEqual(Integer idEmployee) {
return idEmployee == null ? return idEmployee == null ? null :
null :
// 戻り値の型 Specification<EmployeeDepartmentEntity> にキャスト // 戻り値の型 Specification<EmployeeDepartmentEntity> にキャスト
(Specification<EmployeeEntity>) (Specification<EmployeeEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idEmployee' = idEmployee(変数)" // ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idEmployee' = idEmployee(変数)"
@@ -40,46 +40,35 @@ public interface EmployeeInfoRepository extends JpaRepository<EmployeeEntity, In
} }
static Specification<EmployeeEntity> nmEmployeeEqual(String nmEmployee) { static Specification<EmployeeEntity> nmEmployeeEqual(String nmEmployee) {
return (nmEmployee == null || nmEmployee.isEmpty()) ? return (nmEmployee == null || nmEmployee.isEmpty()) ? null
null : : (Specification<EmployeeEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
(Specification<EmployeeEntity>) .like(root.get("nmEmployee"), "%" + nmEmployee + "%");
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmEmployee"), "%" + nmEmployee + "%");
} }
static Specification<EmployeeEntity> knEmployeeEqual(String knEmployee) { static Specification<EmployeeEntity> knEmployeeEqual(String knEmployee) {
return (knEmployee == null || knEmployee.isEmpty()) ? return (knEmployee == null || knEmployee.isEmpty()) ? null
null : : (Specification<EmployeeEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
(Specification<EmployeeEntity>) .like(root.get("knEmployee"), "%" + knEmployee + "%");
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("knEmployee"), "%" + knEmployee + "%");
} }
static Specification<EmployeeEntity> mailAddressEqual(String mailAddress) { static Specification<EmployeeEntity> mailAddressEqual(String mailAddress) {
return (mailAddress == null || mailAddress.isEmpty()) ? return (mailAddress == null || mailAddress.isEmpty()) ? null
null : : (Specification<EmployeeEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
(Specification<EmployeeEntity>) .like(root.get("mailAddress"), "%" + mailAddress + "%");
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("mailAddress"), "%" + mailAddress + "%");
} }
static Specification<EmployeeEntity> idDivisionEqual(Integer idDivision) { static Specification<EmployeeEntity> idDivisionEqual(Integer idDivision) {
return (root, query, criteriaBuilder) -> return (root, query, criteriaBuilder) -> idDivision == null ? null
idDivision == null ? null : : criteriaBuilder.equal(root.join("division").get("idDivision"), idDivision);
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 " @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 e.division di "
+ "INNER JOIN di.department de " + "INNER JOIN di.department de "
+ "INNER JOIN de.headquarters h ") + "INNER JOIN de.headquarters h ")
List<EmployeeDepartmentEntity> findAlltable(); 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 " @EntityGraph(attributePaths = { "division", "division.department", "division.department.headquarters" })
// + "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); List<EmployeeEntity> findAll(@Nullable Specification<EmployeeEntity> spec);
} }

View File

@@ -8,24 +8,23 @@ import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.HeadquartersEntity; import com.example.rhizome.app.infra.entity.HeadquartersEntity;
@Repository @Repository
public interface HeadquartersRepository extends JpaRepository<HeadquartersEntity, Integer>, JpaSpecificationExecutor<HeadquartersEntity>{ public interface HeadquartersRepository
extends JpaRepository<HeadquartersEntity, Integer>, JpaSpecificationExecutor<HeadquartersEntity> {
static Specification<HeadquartersEntity> idHeadquartersEqual(Integer idHeadquarters) { static Specification<HeadquartersEntity> idHeadquartersEqual(Integer idHeadquarters) {
return idHeadquarters == null ? return idHeadquarters == null ? null :
null :
// 戻り値の型 Specification<DepartmentEntity> にキャスト // 戻り値の型 Specification<DepartmentEntity> にキャスト
(Specification<HeadquartersEntity>) (Specification<HeadquartersEntity>)
// ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)" // ラムダ式で記載しているが書いてあることは criteriaBuilder を使って Where句の後の "'idDepartment' = idDepartment(変数)"
// を作成している // を作成している
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idHeadquarters"), idHeadquarters); (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idHeadquarters"),
idHeadquarters);
} }
static Specification<HeadquartersEntity> nmHeadquartersEqual(String nmHeadquarters) { static Specification<HeadquartersEntity> nmHeadquartersEqual(String nmHeadquarters) {
return (nmHeadquarters == null || nmHeadquarters.isEmpty()) ? return (nmHeadquarters == null || nmHeadquarters.isEmpty()) ? null
null : : (Specification<HeadquartersEntity>) (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder
(Specification<HeadquartersEntity>) .like(root.get("nmHeadquarters"), nmHeadquarters);
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.like(root.get("nmHeadquarters"), nmHeadquarters);
} }
HeadquartersEntity findByNmHeadquarters(String nmHeadquarters); HeadquartersEntity findByNmHeadquarters(String nmHeadquarters);
} }

View File

@@ -6,18 +6,18 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import com.example.rhizome.app.infra.entity.RegisterDepartmentEntity; import com.example.rhizome.app.infra.entity.RegisterDepartmentEntity;
@Repository @Repository
public interface RegisterDepartmentRepository extends JpaRepository<RegisterDepartmentEntity, Integer>, JpaSpecificationExecutor<RegisterDepartmentEntity> { public interface RegisterDepartmentRepository
extends JpaRepository<RegisterDepartmentEntity, Integer>, JpaSpecificationExecutor<RegisterDepartmentEntity> {
static Specification<RegisterDepartmentEntity> idHeadquartersEqual(Integer idHeadquarters) { static Specification<RegisterDepartmentEntity> idHeadquartersEqual(Integer idHeadquarters) {
System.out.println("RegisterDepartmentRepository=>5"); return idHeadquarters == null ? null :
return idHeadquarters == null ?
null :
//戻り値の型 Specification<DepartmentEntity> にキャスト //戻り値の型 Specification<DepartmentEntity> にキャスト
(Specification<RegisterDepartmentEntity>) (Specification<RegisterDepartmentEntity>)
(root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idHeadquarters"), idHeadquarters); (root, criteriaQuery, criteriaBuilder) -> criteriaBuilder.equal(root.get("idHeadquarters"),
idHeadquarters);
} }
} }

View File

@@ -1,6 +1,5 @@
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 static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import java.util.logging.Level; import java.util.logging.Level;
@@ -47,8 +46,7 @@ public class DeleteDepartmentController {
DeleteDepartment deleteDepartment, DeleteDepartment deleteDepartment,
SearchDepartment searchDepartment, SearchDepartment searchDepartment,
SearchEmployee searchEmployee, SearchEmployee searchEmployee,
HttpSession httpSession HttpSession httpSession) {
) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.deleteDepartment = deleteDepartment; this.deleteDepartment = deleteDepartment;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
@@ -58,7 +56,7 @@ public class DeleteDepartmentController {
/** /**
* 削除処理のコントローラ * 削除処理のコントローラ
* *
* @param idDepartment 削除対象のidDepartment * @param idDivision 削除対象のidDivision
* @param model ビューにデータを渡すためのコンテナ * @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面 * @return 遷移先の画面
*/ */
@@ -77,9 +75,7 @@ public class DeleteDepartmentController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable() searchDepartment.searchAllDepartmentTable()));
)
);
// 検索画面に遷移 // 検索画面に遷移
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_ALL; return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_ALL;
@@ -111,7 +107,8 @@ public class DeleteDepartmentController {
if (!searchEmployee.searchEmployeeByIdDepartment(idDivision).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));
// 検索画面に遷移 // 検索画面に遷移
return; return;
} }
@@ -124,5 +121,4 @@ public class DeleteDepartmentController {
} }
} }

View File

@@ -76,7 +76,8 @@ public class DeleteEmployeeController {
deleteExec( deleteExec(
model, model,
idEmployee, idEmployee,
LoginUserForm.convertTo((LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER))); LoginUserForm.convertTo(
(LoginUserForm) httpSession.getAttribute(SessionKeyword.LOGIN_USER)));
// 検索画面に遷移 // 検索画面に遷移
return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO_FORM_EMPTY; return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO_FORM_EMPTY;

View File

@@ -1,17 +1,18 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import com.example.rhizome.app.domain.service.impl.LoginImpl; import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.form.LoginUserForm; import javax.servlet.http.HttpSession;
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;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpSession; import com.example.rhizome.app.domain.service.impl.LoginImpl;
import com.example.rhizome.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.*; import com.example.rhizome.app.presentation.form.LoginUserForm;
@Controller @Controller
public class IndexController { public class IndexController {
@@ -34,7 +35,7 @@ public class IndexController {
* @param model ビューにデータを渡すためのコンテナ * @param model ビューにデータを渡すためのコンテナ
* @return 遷移先の画面 * @return 遷移先の画面
*/ */
@RequestMapping(value = {INDEX_BLANK, INDEX_SLASH, INDEX_LOGIN}) @RequestMapping(value = { INDEX_BLANK, INDEX_SLASH, INDEX_LOGIN })
public String index(Model model) { public String index(Model model) {
// セッション情報を破棄 // セッション情報を破棄
if (httpSession != null) { if (httpSession != null) {

View File

@@ -43,8 +43,7 @@ public class InsertDepartmentConfirmController {
@Autowired @Autowired
public InsertDepartmentConfirmController( public InsertDepartmentConfirmController(
HttpSession httpSession, HttpSession httpSession,
SearchDepartmentImpl searchDepartment SearchDepartmentImpl searchDepartment) {
) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
} }
@@ -73,8 +72,7 @@ public class InsertDepartmentConfirmController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()) searchDepartment.searchAllDepartmentTable()));
);
// 入力内容に誤りがあるか // 入力内容に誤りがあるか
if (insertDepartmentForm.haveNmDepartment()) { if (insertDepartmentForm.haveNmDepartment()) {
@@ -86,8 +84,8 @@ public class InsertDepartmentConfirmController {
// 登録画面に遷移 // 登録画面に遷移
return INSERT_DEPARTMENT_INPUT_HTML; return INSERT_DEPARTMENT_INPUT_HTML;
} }
//重複のチェック用の各部署のSearchConditionDeopartmentを用意
SearchConditionDepartment searchHeadquartersTable =new SearchConditionDepartment( SearchConditionDepartment searchHeadquartersTable = new SearchConditionDepartment(
null, null,
insertDepartmentForm.getNmHeadquarters()); insertDepartmentForm.getNmHeadquarters());
SearchConditionDepartment searchDepartmentTable = new SearchConditionDepartment( SearchConditionDepartment searchDepartmentTable = new SearchConditionDepartment(
@@ -97,11 +95,11 @@ public class InsertDepartmentConfirmController {
null, null,
insertDepartmentForm.getNmDivision()); insertDepartmentForm.getNmDivision());
// 部署名で重複が無いかチェック // 部署の組み合わせで重複が無いかチェック
if (searchDepartment.searchAllDepartmentTable( if (searchDepartment.searchAllDepartmentTable(
searchHeadquartersTable, searchHeadquartersTable,
searchDepartmentTable, searchDepartmentTable,
searchDivisionTable)){ searchDivisionTable)) {
// 存在する場合はエラーメッセージを設定して更新入力画面に遷移 // 存在する場合はエラーメッセージを設定して更新入力画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
@@ -115,7 +113,6 @@ public class InsertDepartmentConfirmController {
// 登録確認画面に遷移 // 登録確認画面に遷移
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_CONFIRM_HTML; return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_CONFIRM_HTML;
} catch (Exception e) { } catch (Exception e) {
// ログイン情報の破棄 // ログイン情報の破棄
httpSession.invalidate(); httpSession.invalidate();
@@ -129,6 +126,3 @@ public class InsertDepartmentConfirmController {
} }
} }
} }

View File

@@ -47,7 +47,8 @@ public class InsertDepartmentController {
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
@Autowired @Autowired
public InsertDepartmentController(HttpSession httpSession, RegisterDepartment registerDepartment, SearchDepartment searchDepartment, SearchDepartmentImpl searchDepartmentImpl) { public InsertDepartmentController(HttpSession httpSession, RegisterDepartment registerDepartment,
SearchDepartment searchDepartment, SearchDepartmentImpl searchDepartmentImpl) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.registerDepartment = registerDepartment; this.registerDepartment = registerDepartment;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
@@ -80,8 +81,7 @@ public class InsertDepartmentController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable() searchDepartment.searchAllDepartmentTable()));
));
// 入力内容に誤りがあるか // 入力内容に誤りがあるか
if (insertDepartmentForm.haveNmDepartment()) { if (insertDepartmentForm.haveNmDepartment()) {
@@ -94,8 +94,7 @@ public class InsertDepartmentController {
return INSERT_DEPARTMENT_INPUT_HTML; return INSERT_DEPARTMENT_INPUT_HTML;
} }
// 部署の組み合わせで重複が無いかチェック
// 部署名で重複が無いかチェック
if (searchDepartment.searchAllDepartmentTable( if (searchDepartment.searchAllDepartmentTable(
new SearchConditionDepartment( new SearchConditionDepartment(
insertDepartmentForm.getIdHeadquarters(), insertDepartmentForm.getIdHeadquarters(),
@@ -107,18 +106,16 @@ public class InsertDepartmentController {
insertDepartmentForm.getIdDivision(), insertDepartmentForm.getIdDivision(),
insertDepartmentForm.getNmDivision()))) { insertDepartmentForm.getNmDivision()))) {
// 存在する場合はエラーメッセージを設定して更新入力画面に遷移 // 存在する場合はエラーメッセージを設定して更新入力画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DUPLICATION));
model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm); model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm);
return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML; return TransitionTargetPageNameKeyword.INSERT_DEPARTMENT_INPUT_HTML;
} }
//divisionEntityにinsertDepartmentFormで画面から渡ってきた値を入れる
DepartmentInfo departmentInfo = InsertDepartmentForm.convertTo(insertDepartmentForm); DepartmentInfo departmentInfo = InsertDepartmentForm.convertTo(insertDepartmentForm);
DivisionEntity divisionEntity = DivisionEntity.convertFrom(departmentInfo); DivisionEntity divisionEntity = DivisionEntity.convertFrom(departmentInfo);
System.out.println(divisionEntity);
// 登録処理 // 登録処理
registerDepartment.registerDepartment(divisionEntity); registerDepartment.registerDepartment(divisionEntity);
@@ -138,6 +135,3 @@ public class InsertDepartmentController {
} }
} }
} }

View File

@@ -17,7 +17,9 @@ import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.service.SearchDepartment; 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.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.DepartmentInfoForm;
import com.example.rhizome.app.presentation.form.DivisionInfoForm;
import com.example.rhizome.app.presentation.form.HeadquartersInfoForm;
import com.example.rhizome.app.presentation.form.InsertDepartmentForm; import com.example.rhizome.app.presentation.form.InsertDepartmentForm;
/** /**
@@ -38,8 +40,7 @@ public class InsertDepartmentInputController {
@Autowired @Autowired
public InsertDepartmentInputController( public InsertDepartmentInputController(
HttpSession httpSession, HttpSession httpSession,
SearchDepartment searchDepartment SearchDepartment searchDepartment) {
) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
} }
@@ -49,7 +50,6 @@ public class InsertDepartmentInputController {
return new InsertDepartmentForm(); return new InsertDepartmentForm();
} }
/** /**
* 部署登録画面表示処理 * 部署登録画面表示処理
* *
@@ -63,11 +63,19 @@ public class InsertDepartmentInputController {
public String insertInput(InsertDepartmentForm insertDepartmentForm, Model model) { public String insertInput(InsertDepartmentForm insertDepartmentForm, Model model) {
try { try {
//各部署情報を重複魚消して表示するために別々に画面へ送る
model.addAttribute(
PageReturnAttributeKeyword.HEADQUARTERS_FORM_LIST,
HeadquartersInfoForm.convertFrom(
searchDepartment.searchAllDepartmentTable()));
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentInfoForm.convertFromTo(
searchDepartment.searchAllDepartmentTable()) searchDepartment.searchAllDepartmentTable()));
); model.addAttribute(
PageReturnAttributeKeyword.DIVISION_FORM_LIST,
DivisionInfoForm.convertFromTo(
searchDepartment.searchAllDepartmentTable()));
// パラメータをセット // パラメータをセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm); model.addAttribute(PageReturnAttributeKeyword.INSERT_DEPARTMENT_FORM, insertDepartmentForm);
@@ -87,6 +95,3 @@ public class InsertDepartmentInputController {
} }
} }
} }

View File

@@ -48,8 +48,7 @@ public class InsertEmployeeConfirmController {
public InsertEmployeeConfirmController( public InsertEmployeeConfirmController(
HttpSession httpSession, HttpSession httpSession,
SearchDepartmentImpl searchDepartment, SearchDepartmentImpl searchDepartment,
SearchEmployeeImpl searchEmployee SearchEmployeeImpl searchEmployee) {
) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
this.searchEmployee = searchEmployee; this.searchEmployee = searchEmployee;
@@ -78,8 +77,7 @@ public class InsertEmployeeConfirmController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable() searchDepartment.searchAllDepartmentTable()));
));
// 登録用パラメータチェック // 登録用パラメータチェック
List<String> error = insertEmployeeForm.validateParameter(); List<String> error = insertEmployeeForm.validateParameter();
@@ -88,7 +86,8 @@ public class InsertEmployeeConfirmController {
if (!error.isEmpty()) { if (!error.isEmpty()) {
// 誤りがあった場合 // 誤りがあった場合
// 誤りがあった箇所のエラーメッセージを表示 // 誤りがあった箇所のエラーメッセージを表示
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(String.join(", ", error) + "が不正です。")); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(String.join(", ", error) + "が不正です。"));
// 画面に返す為の登録情報をセット // 画面に返す為の登録情報をセット
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm); model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// 登録画面に遷移 // 登録画面に遷移
@@ -111,23 +110,11 @@ public class InsertEmployeeConfirmController {
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
} }
final String DEPARTMENT_VALID ="部署情報の組み合わせが違います。";
if(!searchDepartment.searchAllDepartmentTable(
insertEmployeeForm.getIdHeadquarters()
,insertEmployeeForm.getIdDepartment()
,insertEmployeeForm.getIdDivision())) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DEPARTMENT_VALID));
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
}
// 登録確認ページに遷移 // 登録確認ページに遷移
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm); model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
// 登録確認画面に遷移 // 登録確認画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_CONFIRM_HTML; return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_CONFIRM_HTML;
} catch (Exception e) { } catch (Exception e) {
// ログイン情報の破棄 // ログイン情報の破棄
httpSession.invalidate(); httpSession.invalidate();
@@ -141,6 +128,3 @@ public class InsertEmployeeConfirmController {
} }
} }
} }

View File

@@ -45,7 +45,8 @@ public class InsertEmployeeController {
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
@Autowired @Autowired
public InsertEmployeeController(HttpSession httpSession, RegisterEmployeeImpl registerEmployee, SearchDepartmentImpl searchDepartment) { public InsertEmployeeController(HttpSession httpSession, RegisterEmployeeImpl registerEmployee,
SearchDepartmentImpl searchDepartment) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.registerEmployee = registerEmployee; this.registerEmployee = registerEmployee;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
@@ -74,8 +75,7 @@ public class InsertEmployeeController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable() searchDepartment.searchAllDepartmentTable()));
));
// Confirm画面から渡ってきた値をチェック // Confirm画面から渡ってきた値をチェック
List<String> error = validateParameter( List<String> error = validateParameter(
@@ -85,27 +85,17 @@ public class InsertEmployeeController {
insertEmployeeForm.getPassword(), insertEmployeeForm.getPassword(),
insertEmployeeForm.getHireDate(), insertEmployeeForm.getHireDate(),
insertEmployeeForm.getAdminAuth(), insertEmployeeForm.getAdminAuth(),
insertEmployeeForm.getIdDivision() insertEmployeeForm.getIdDivision());
);
// エラーが1件以上有る場合 // エラーが1件以上有る場合
if (!error.isEmpty()) { if (!error.isEmpty()) {
// エラー内容を画面に表示 // エラー内容を画面に表示
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(String.join(", ", error) + "が不正です。")); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(String.join(", ", error) + "が不正です。"));
// 登録画面に遷移 // 登録画面に遷移
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
} }
final String DEPARTMENT_VALID ="部署情報の組み合わせが違います。";
if(!searchDepartment.searchAllDepartmentTable(
insertEmployeeForm.getIdHeadquarters()
,insertEmployeeForm.getIdDepartment()
,insertEmployeeForm.getIdDivision())) {
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(DEPARTMENT_VALID));
model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
}
// 登録処理 // 登録処理
registerEmployee.registerEmployee(InsertEmployeeForm.convertTo(insertEmployeeForm)); registerEmployee.registerEmployee(InsertEmployeeForm.convertTo(insertEmployeeForm));
// 登録結果画面に遷移 // 登録結果画面に遷移
@@ -140,8 +130,7 @@ public class InsertEmployeeController {
String password, String password,
String hireDate, String hireDate,
Integer management, Integer management,
Integer departmentId Integer departmentId) {
) {
final String EMPLOYEE_NAME_NULL_BLANK = "社員名"; final String EMPLOYEE_NAME_NULL_BLANK = "社員名";
final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ"; final String EMPLOYEE_KANA_NULL_BLANK = "社員名フリガナ";
@@ -213,6 +202,3 @@ public class InsertEmployeeController {
} }
} }

View File

@@ -46,7 +46,8 @@ public class InsertEmployeeInputController {
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
@Autowired @Autowired
public InsertEmployeeInputController(HttpSession httpSession, RegisterEmployee registerEmployee, SearchDepartment searchDepartment) { public InsertEmployeeInputController(HttpSession httpSession, RegisterEmployee registerEmployee,
SearchDepartment searchDepartment) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.registerEmployee = registerEmployee; this.registerEmployee = registerEmployee;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
@@ -57,53 +58,22 @@ public class InsertEmployeeInputController {
return new InsertEmployeeForm(); return new InsertEmployeeForm();
} }
//プルダウン絞り込み無し実装用 /**
// /** * 社員情報登録画面の表示を行う
// * 登録画面表示処理 *
// * * @param InsertEmployeeFormを保持したインスタンス
// * @param insertEmployeeForm 登録画面のフォーム * @param model ビューにデータを渡すためのコンテナ
// * @param model ビューにデータを渡すためのコンテナ * @return 遷移先の画面
// * @return 遷移先の画面 */
// */
// @SessionCheck
// @PermissionCheck
// @RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
// public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) {
//
// try {
// // 部署コードリストを作成し、画面に返す値としてセット
// model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST
// ,DepartmentForm.convertFrom(
// searchDepartment.searchAllDepartmentTable()));
//
// // パラメータをセット
// model.addAttribute(PageReturnAttributeKeyword.INSERT_EMPLOYEE_FORM, insertEmployeeForm);
//
// // 登録画面に遷移
// return TransitionTargetPageNameKeyword.INSERT_EMPLOYEE_INPUT_HTML;
//
// } catch (Exception e) {
// // ログイン情報の破棄
// httpSession.invalidate();
//
// e.printStackTrace();
//
// // エラーログ出力
// LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// // エラー画面遷移
// return TransitionTargetPageNameKeyword.ERROR_HTML;
// }
// }
//プルダウン絞り込み実装用
@SessionCheck @SessionCheck
@PermissionCheck @PermissionCheck
@RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST) @RequestMapping(value = INSERT_EMPLOYEE_INPUT, method = RequestMethod.POST)
public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) { public String insertInput(InsertEmployeeForm insertEmployeeForm, Model model) {
try { try {
// 部署コードリストを作成し、画面に返す値としてセット // 部署コードリストを作成し、画面に返す値としてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, HeadquartersInfoForm.convertFrom(
,HeadquartersInfoForm.convertFrom(
searchDepartment.searchAllDepartmentTable())); searchDepartment.searchAllDepartmentTable()));
// パラメータをセット // パラメータをセット
@@ -125,45 +95,49 @@ public class InsertEmployeeInputController {
} }
} }
@GetMapping("insertEmployeeInput/searchDepartment" ) /**
* 社員情報登録画面の部情報のプルダウンの表示を行う
*
* @param idHeadquarters
* @return 遷移先の画面
*/
//画面で本部のプルダウンが選択された時にJSでこのメソッドに飛ぶ
@GetMapping("insertEmployeeInput/searchDepartment")
@ResponseBody @ResponseBody
public List<DepartmentInfoForm>departmentsByHeadquarters( public List<DepartmentInfoForm> departmentsByHeadquarters(
@RequestParam("id_headquarters")Integer idHeadquarters){ @RequestParam("id_headquarters") Integer idHeadquarters) {
System.out.println("koko"); List<DepartmentInfoForm> departmentByHeadquarters = DepartmentInfoForm.convertFrom(
List<DepartmentInfoForm> departmentByHeadquarters=
DepartmentInfoForm.convertFrom(
searchDepartment.searchByIdHeadquarters(idHeadquarters)); searchDepartment.searchByIdHeadquarters(idHeadquarters));
System.out.println("2");
return departmentByHeadquarters return departmentByHeadquarters
.stream() .stream()
.map(DepartmentInfoForm-> new DepartmentInfoForm( .map(DepartmentInfoForm -> new DepartmentInfoForm(
DepartmentInfoForm.getIdDepartment(), DepartmentInfoForm.getIdDepartment(),
DepartmentInfoForm.getNmDepartment())) DepartmentInfoForm.getNmDepartment()))
.distinct() .distinct()
.toList(); .toList();
} }
/**
* 社員情報登録画面の課情報のプルダウンの表示を行う
*
* @param idDepartment
* @return 遷移先の画面
*/
//画面で部のプルダウンが選択された時にJSでこのメソッドに飛ぶ
@GetMapping("/insertEmployeeInput/searchDepartment/searchDivision") @GetMapping("/insertEmployeeInput/searchDepartment/searchDivision")
@ResponseBody @ResponseBody
public List<DivisionInfoForm>divisionBydepartment( public List<DivisionInfoForm> divisionBydepartment(
@RequestParam("idDepartment")Integer idDepartment){ @RequestParam("id_department") Integer idDepartment) {
List<DivisionInfoForm> divisionBydepartment= List<DivisionInfoForm> divisionByDepartment = DivisionInfoForm.convertFrom(
DivisionInfoForm.convertFrom(
searchDepartment.searchByIdDepartment(idDepartment)); searchDepartment.searchByIdDepartment(idDepartment));
return divisionByDepartment
return divisionBydepartment
.stream() .stream()
.map(DivisionInfoForm-> new DivisionInfoForm( .map(DivisionInfoForm -> new DivisionInfoForm(
DivisionInfoForm.getIdDivision(), DivisionInfoForm.getIdDivision(),
DivisionInfoForm.getNmDivision())) DivisionInfoForm.getNmDivision()))
.distinct() .distinct()
.toList(); .toList();
} }
} }

View File

@@ -1,5 +1,18 @@
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.app.domain.model.LoginInfo; import com.example.rhizome.app.domain.model.LoginInfo;
import com.example.rhizome.app.domain.model.LoginUser; import com.example.rhizome.app.domain.model.LoginUser;
@@ -11,18 +24,6 @@ import com.example.rhizome.app.presentation.form.LoginInfoForm;
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 com.example.rhizome.app.presentation.form.UpdatePersonalUserForm; import com.example.rhizome.app.presentation.form.UpdatePersonalUserForm;
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.DO_LOGIN;
/** /**
* ログイン関連のコントローラ * ログイン関連のコントローラ
@@ -70,7 +71,8 @@ public class LoginController {
if (!LoginUserForm.checkParameter(loginInfoForm)) { if (!LoginUserForm.checkParameter(loginInfoForm)) {
// mail,passwordが仕様を満たしていない場合 // mail,passwordが仕様を満たしていない場合
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR, new MessageForm(MAIL_ADDRESS_PASSWORD_ERROR)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_ERROR,
new MessageForm(MAIL_ADDRESS_PASSWORD_ERROR));
// エラーだった場合に login.html に処理を戻す。mailAddress, password を login.htmlに表示するために // エラーだった場合に login.html に処理を戻す。mailAddress, password を login.htmlに表示するために
// ここで addAttribute する // ここで addAttribute する
@@ -104,7 +106,8 @@ public class LoginController {
if (!loginUser.isAdminUser()) { if (!loginUser.isAdminUser()) {
// 管理者ではない場合直で自分の情報を更新するページに遷移する // 管理者ではない場合直で自分の情報を更新するページに遷移する
// 編集対象のログイン者の情報を画面に渡す値にセット // 編集対象のログイン者の情報を画面に渡す値にセット
model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM, UpdatePersonalUserForm.convertFrom(loginUser)); model.addAttribute(PageReturnAttributeKeyword.UPDATE_PERSONAL_EMPLOYEE_USER_FORM,
UpdatePersonalUserForm.convertFrom(loginUser));
// 個人の情報更新ページに遷移 // 個人の情報更新ページに遷移
return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_PERSONAL_EMPLOYEE_INPUT_HTML;
} }
@@ -142,7 +145,6 @@ public class LoginController {
// セッションにない場合は画面からの input 値 を取得 // セッションにない場合は画面からの input 値 を取得
return new LoginInfo( return new LoginInfo(
loginInfoForm.getMailAddress(), loginInfoForm.getMailAddress(),
loginInfoForm.getPassword() loginInfoForm.getPassword());
);
} }
} }

View File

@@ -1,10 +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.presentation.controller.pageproperty.PageReturnAttributeKeyword; import java.util.logging.Level;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import java.util.logging.Logger;
import com.example.rhizome.app.presentation.form.LoginUserForm;
import javax.servlet.http.HttpSession;
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;
@@ -12,11 +14,11 @@ 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.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import static com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword.LOGOUT; import com.example.rhizome.app.presentation.form.LoginUserForm;
/** /**
* ログアウト処理のコントローラ * ログアウト処理のコントローラ

View File

@@ -1,12 +1,13 @@
package com.example.rhizome.app.presentation.controller; package com.example.rhizome.app.presentation.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
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.presentation.controller.pageproperty.TransitionTargetPageNameKeyword; import com.example.rhizome.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.rhizome.app.presentation.form.MessageForm; import com.example.rhizome.app.presentation.form.MessageForm;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
/** /**
* メニュー画面表示用コントローラ * メニュー画面表示用コントローラ

View File

@@ -63,7 +63,8 @@ public class SelectDepartmentController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable(SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm)) searchDepartment.searchAllDepartmentTable(
SearchConditionDepartmentForm.convertTo(searchConditionDepartmentForm))
)); ));
@@ -101,9 +102,7 @@ public class SelectDepartmentController {
model.addAttribute( model.addAttribute(
PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST,
DepartmentForm.convertFrom( DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable() searchDepartment.searchAllDepartmentTable()));
)
);
// 検索ページに遷移 // 検索ページに遷移
return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML; return TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_HTML;

View File

@@ -75,9 +75,11 @@ public class SelectEmployeeController {
); );
// 検索条件を元に検索を実施 // 検索条件を元に検索を実施
// 取得した EmployeeInfo( employee + department )の情報を画面に返す用の型に詰め替えてセット // 取得した EmployeeInfo( employee + department )の情報を画面に返す用の型に詰め替えてセット
//プラスで勤続年数を計算してformにセット
List<EmployeeInfoForm>employeeInfoForm = EmployeeInfoForm.convertFrom(
List<EmployeeInfoForm>employeeInfoForm = EmployeeInfoForm.convertFrom(searchEmployeeInfo.searchBy(SearchConditionEmployeeForm.convertTo(searchConditionEmployeeForm))); 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);

View File

@@ -1,6 +1,6 @@
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.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -15,6 +15,9 @@ 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.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.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.service.SearchDepartment; import com.example.rhizome.app.domain.service.SearchDepartment;
import com.example.rhizome.app.domain.service.UpdateDepartment; import com.example.rhizome.app.domain.service.UpdateDepartment;
@@ -39,9 +42,9 @@ 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;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
this.updateDepartment = updateDepartment; this.updateDepartment = updateDepartment;
@@ -65,16 +68,41 @@ public class UpdateDepartmentResultController {
try { try {
// 更新対象の部署データがない // 更新対象の部署データがない
if (updateDepartmentForm.getNmHeadquarters().isBlank()|| if (updateDepartmentForm.getNmHeadquarters().isBlank() ||
updateDepartmentForm.getNmDepartment().isBlank()|| updateDepartmentForm.getNmDepartment().isBlank() ||
updateDepartmentForm.getNmDivision().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);
return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_DEPARTMENT_INPUT_HTML;
} }
// 部署名で重複が無いかチェック // 部署名で重複が無いかチェック
List<Headquarters> beforeHeadquartersList = searchDepartment
.searchHeadquartersByIdHeadquarters(updateDepartmentForm.getIdHeadquarters());
List<Department> beforeDepartmentList = searchDepartment
.searchDepartmentByIdDepartment(updateDepartmentForm.getIdDepartment());
List<Division> beforeDivisionList = searchDepartment
.searchDivisionByIdDivision(updateDepartmentForm.getIdDivision());
Headquarters beforeHeadquarters = beforeHeadquartersList.get(0);
Department beforeDepartment = beforeDepartmentList.get(0);
Division beforeDivision = beforeDivisionList.get(0);
Headquarters afterHeadquarters = new Headquarters(
updateDepartmentForm.getIdHeadquarters(),
updateDepartmentForm.getNmHeadquarters(),
null);
Department afterDepartment = new Department(
updateDepartmentForm.getIdDepartment(),
updateDepartmentForm.getNmDepartment(),
null,
updateDepartmentForm.getIdHeadquarters());
Division afterDivision = new Division(
updateDepartmentForm.getIdDivision(),
updateDepartmentForm.getNmDivision(),
null,
updateDepartmentForm.getIdDepartment());
if (searchDepartment.searchAllDepartmentTable( if (searchDepartment.searchAllDepartmentTable(
new SearchConditionDepartment( new SearchConditionDepartment(
updateDepartmentForm.getIdHeadquarters(), updateDepartmentForm.getIdHeadquarters(),
@@ -84,7 +112,31 @@ public class UpdateDepartmentResultController {
updateDepartmentForm.getNmDepartment()), updateDepartmentForm.getNmDepartment()),
new SearchConditionDepartment( new SearchConditionDepartment(
updateDepartmentForm.getIdDivision(), updateDepartmentForm.getIdDivision(),
updateDepartmentForm.getNmDivision()))) { updateDepartmentForm.getNmDivision()))
|| (!beforeHeadquarters.getNmHeadquarters().equals(afterHeadquarters.getNmHeadquarters())
&&
!searchDepartment.searchByHeadquarters(
new SearchConditionDepartment(
null,
updateDepartmentForm.getNmHeadquarters()))
.isEmpty())
|| (!beforeDepartment.getNmDepartment().equals(afterDepartment.getNmDepartment())
&&
!searchDepartment.searchByDepartment(
new SearchConditionDepartment(
null,
updateDepartmentForm.getNmDepartment()))
.isEmpty())
|| (!beforeDivision.getNmDivision().equals(afterDivision.getNmDivision())
&&
!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);
@@ -97,15 +149,13 @@ public class UpdateDepartmentResultController {
// 部署一覧取得 // 部署一覧取得
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom( model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom(
searchDepartment.searchAllDepartmentTable()) searchDepartment.searchAllDepartmentTable()));
);
// 更新結果のメッセージを画面にセットし一覧画面に遷移 // 更新結果のメッセージを画面にセットし一覧画面に遷移
model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE)); model.addAttribute(PageReturnAttributeKeyword.MESSAGE_INFO, new MessageForm(UPDATE_COMPLETE));
// forward 先で不用意な動作をしないために UpdateEmployeeInfoForm をクリア // forward 先で不用意な動作をしないために UpdateEmployeeInfoForm をクリア
return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_ALL; return "forward:" + TransitionTargetPageNameKeyword.SELECT_DEPARTMENT_ALL;
} catch (Exception e) { } catch (Exception e) {
// ログイン情報の破棄 // ログイン情報の破棄
httpSession.invalidate(); httpSession.invalidate();

View File

@@ -9,20 +9,27 @@ import javax.servlet.http.HttpSession;
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;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; 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 org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.example.rhizome.aop.aspect.PermissionCheck; import com.example.rhizome.aop.aspect.PermissionCheck;
import com.example.rhizome.aop.aspect.SessionCheck; import com.example.rhizome.aop.aspect.SessionCheck;
import com.example.rhizome.app.domain.model.AllDepartmentInfo;
import com.example.rhizome.app.domain.model.AllEmployeeInfo; import com.example.rhizome.app.domain.model.AllEmployeeInfo;
import com.example.rhizome.app.domain.model.SearchConditionDepartment;
import com.example.rhizome.app.domain.model.SearchConditionEmployee; import com.example.rhizome.app.domain.model.SearchConditionEmployee;
import com.example.rhizome.app.domain.service.RegisterEmployee;
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;
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.DepartmentInfoForm;
import com.example.rhizome.app.presentation.form.DivisionInfoForm;
import com.example.rhizome.app.presentation.form.HeadquartersInfoForm;
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;
@@ -41,12 +48,15 @@ public class UpdateEmployeeController {
HttpSession httpSession; HttpSession httpSession;
SearchDepartment searchDepartment; SearchDepartment searchDepartment;
SearchEmployeeInfo searchEmployeeInfo; SearchEmployeeInfo searchEmployeeInfo;
RegisterEmployee registerEmployee;
@Autowired @Autowired
public UpdateEmployeeController(HttpSession httpSession, SearchDepartment searchDepartment, SearchEmployeeInfo searchEmployeeInfo) { public UpdateEmployeeController(HttpSession httpSession, SearchDepartment searchDepartment,
SearchEmployeeInfo searchEmployeeInfo, RegisterEmployee registerEmployee) {
this.httpSession = httpSession; this.httpSession = httpSession;
this.searchDepartment = searchDepartment; this.searchDepartment = searchDepartment;
this.searchEmployeeInfo = searchEmployeeInfo; this.searchEmployeeInfo = searchEmployeeInfo;
this.registerEmployee = registerEmployee;
} }
@ModelAttribute @ModelAttribute
@@ -68,10 +78,9 @@ public class UpdateEmployeeController {
final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。"; final String UPDATE_TARGET_ID_NOT_FOUND = "更新対象のデータが見つかりません。";
try { try {
// 部署一覧を取得し画面に返す値としてセット // 部署コードリストを作成し、画面に返す値としてセット
model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, DepartmentForm.convertFrom( model.addAttribute(PageReturnAttributeKeyword.DEPARTMENT_FORM_LIST, HeadquartersInfoForm.convertFrom(
searchDepartment.searchAllDepartmentTable())); searchDepartment.searchAllDepartmentTable()));
// id を条件に更新対象のレコードを検索、取得する // id を条件に更新対象のレコードを検索、取得する
List<AllEmployeeInfo> employeeInfoList = searchEmployeeInfo.searchBy( List<AllEmployeeInfo> employeeInfoList = searchEmployeeInfo.searchBy(
new SearchConditionEmployee(idEmployee, new SearchConditionEmployee(idEmployee,
@@ -83,17 +92,27 @@ public class UpdateEmployeeController {
// DBに更新対象のデータがあるか // DBに更新対象のデータがあるか
if (employeeInfoList.isEmpty()) { if (employeeInfoList.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_EMPLOYEE_INFO; return "forward:" + TransitionTargetPageNameKeyword.SELECT_EMPLOYEE_INFO;
} }
//idDivisionからidHeadquartersを調べてUpdateEmployeeInfoFormに入れる
System.out.println("A");
UpdateEmployeeInfoForm updateInfo = UpdateEmployeeInfoForm.convertFrom(employeeInfoList.get(0));
SearchConditionDepartment beforeUpdate = new SearchConditionDepartment(
updateInfo.getIdDivision(),
null);
List<AllDepartmentInfo> afterSearchDepartment = searchDepartment.searchAllDepartmentTable(beforeUpdate);
updateInfo.setIdHeadquarters(afterSearchDepartment.get(0).getHeadquarters().getIdHeadquarters());
// 更新画面に遷移 // 更新画面に遷移
model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM, UpdateEmployeeInfoForm.convertFrom(employeeInfoList.get(0))); model.addAttribute(PageReturnAttributeKeyword.UPDATE_EMPLOYEE_INFO_FORM,
updateInfo);
// Update画面に遷移 // Update画面に遷移
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
} catch (Exception e) { } catch (Exception e) {
// ログイン情報の破棄 // ログイン情報の破棄
httpSession.invalidate(); httpSession.invalidate();
@@ -107,4 +126,50 @@ public class UpdateEmployeeController {
} }
} }
/**
* 社員情報更新画面の部情報のプルダウンの表示を行う
*
* @param idHeadquarters
* @return 遷移先の画面
*/
//画面で本部のプルダウンが選択された時にJSでこのメソッドに飛ぶ
@GetMapping("updateEmployeeInput/searchDepartment")
@ResponseBody
public List<DepartmentInfoForm> departmentsByHeadquarters(
@RequestParam("id_headquarters") Integer idHeadquarters) {
List<DepartmentInfoForm> departmentByHeadquarters = DepartmentInfoForm.convertFrom(
searchDepartment.searchByIdHeadquarters(idHeadquarters));
return departmentByHeadquarters
.stream()
.map(DepartmentInfoForm -> new DepartmentInfoForm(
DepartmentInfoForm.getIdDepartment(),
DepartmentInfoForm.getNmDepartment()))
.distinct()
.toList();
}
/**
* 社員情報更新画面の課情報のプルダウンの表示を行う
*
* @param idDepartment
* @return 遷移先の画面
*/
//画面で部のプルダウンが選択された時にJSでこのメソッドに飛ぶ
@GetMapping("/updateEmployeeInput/searchDepartment/searchDivision")
@ResponseBody
public List<DivisionInfoForm> divisionBydepartment(
@RequestParam("id_department") Integer idDepartment) {
List<DivisionInfoForm> divisionByDepartment = DivisionInfoForm.convertFrom(
searchDepartment.searchByIdDepartment(idDepartment));
return divisionByDepartment
.stream()
.map(DivisionInfoForm -> new DivisionInfoForm(
DivisionInfoForm.getIdDivision(),
DivisionInfoForm.getNmDivision()))
.distinct()
.toList();
}
} }

View File

@@ -151,6 +151,7 @@ public class UpdateEmployeeResultController {
return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML; return TransitionTargetPageNameKeyword.UPDATE_EMPLOYEE_INPUT_HTML;
} }
//勤続年数は更新対象ではないのでそのまま移し替える
updateEmployeeInfoForm.setHireDate(beforeEmployee.getHireDate()); updateEmployeeInfoForm.setHireDate(beforeEmployee.getHireDate());
// 画面用の型からビジネスロジック用のモデルに変換し、Updateを実行 // 画面用の型からビジネスロジック用のモデルに変換し、Updateを実行

View File

@@ -16,5 +16,7 @@ public class PageReturnAttributeKeyword {
public static final String LOGIN_INFO_FORM = "loginInfoForm"; public static final String LOGIN_INFO_FORM = "loginInfoForm";
public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm"; public static final String UPDATE_PERSONAL_EMPLOYEE_USER_FORM = "updatePersonalEmployeeUserForm";
public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList"; public static final String EMPLOYEE_INFO_FORM_LIST = "employeeInfoFormList";
public static final String HEADQUARTERS_FORM_LIST = "headquartersFormList";
public static final String DIVISION_FORM_LIST = "divisionFormList";
} }

View File

@@ -66,6 +66,6 @@ public class DepartmentForm {
*/ */
public static List<DepartmentForm> convertFrom(List<AllDepartmentInfo>allDepartmentInfoList public static List<DepartmentForm> convertFrom(List<AllDepartmentInfo>allDepartmentInfoList
) { ) {
return allDepartmentInfoList.stream().map(DepartmentForm::convertFrom).toList(); return allDepartmentInfoList.stream().map(DepartmentForm::convertFrom).distinct().toList();
} }
} }

View File

@@ -2,6 +2,7 @@ package com.example.rhizome.app.presentation.form;
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.Department;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -34,4 +35,14 @@ public class DepartmentInfoForm {
) { ) {
return DepartmentList.stream().map(DepartmentInfoForm::convertFrom).toList(); return DepartmentList.stream().map(DepartmentInfoForm::convertFrom).toList();
} }
public static DepartmentInfoForm convertFrom(AllDepartmentInfo allDepartmentInfo) {
return new DepartmentInfoForm(
allDepartmentInfo.getDepartment().getIdDepartment(),
allDepartmentInfo.getDepartment().getNmDepartment()
);
}
public static List<DepartmentInfoForm> convertFromTo(List<AllDepartmentInfo>AllDepartmentInfoList
) {
return AllDepartmentInfoList.stream().map(DepartmentInfoForm::convertFrom).distinct().toList();
}
} }

View File

@@ -2,6 +2,7 @@ package com.example.rhizome.app.presentation.form;
import java.util.List; import java.util.List;
import com.example.rhizome.app.domain.model.AllDepartmentInfo;
import com.example.rhizome.app.domain.model.Division; import com.example.rhizome.app.domain.model.Division;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -32,4 +33,14 @@ public class DivisionInfoForm {
) { ) {
return divisionList.stream().map(DivisionInfoForm::convertFrom).toList(); return divisionList.stream().map(DivisionInfoForm::convertFrom).toList();
} }
public static DivisionInfoForm convertFrom(AllDepartmentInfo allDepartmentInfo) {
return new DivisionInfoForm(
allDepartmentInfo.getDivision().getIdDivision(),
allDepartmentInfo.getDivision().getNmDivision()
);
}
public static List<DivisionInfoForm> convertFromTo(List<AllDepartmentInfo>AllDepartmentInfoList
) {
return AllDepartmentInfoList.stream().map(DivisionInfoForm::convertFrom).distinct().toList();
}
} }

View File

@@ -1,6 +1,5 @@
package com.example.rhizome.app.presentation.form; 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.AllEmployeeInfo;
@@ -75,11 +74,10 @@ public class EmployeeInfoForm {
private String nmDivision; private String nmDivision;
/** /**
* business 層の EmployeeInfo クラスから画面用(presentation 層)の EmployeeInfoForm に * AllEmployeeInfo からEmployeeInfoForm に変換します。
* 変換します。
* *
* @param employeeInfo business 層の EmployeeInfo インスタンス * @param allEmployeeInfo AllEmployeeInfo インスタンス
* @return クラスから画面用(presentation 層)の EmployeeInfoForm インスタンス * @return EmployeeInfoForm インスタンス
*/ */
public static EmployeeInfoForm convertFrom(AllEmployeeInfo allEmployeeInfo) { public static EmployeeInfoForm convertFrom(AllEmployeeInfo allEmployeeInfo) {
return new EmployeeInfoForm( return new EmployeeInfoForm(
@@ -96,16 +94,14 @@ public class EmployeeInfoForm {
allEmployeeInfo.getDepartment().getIdDepartment(), allEmployeeInfo.getDepartment().getIdDepartment(),
allEmployeeInfo.getDepartment().getNmDepartment(), allEmployeeInfo.getDepartment().getNmDepartment(),
allEmployeeInfo.getDivision().getIdDivision(), allEmployeeInfo.getDivision().getIdDivision(),
allEmployeeInfo.getDivision().getNmDivision() allEmployeeInfo.getDivision().getNmDivision());
);
} }
/** /**
* business 層の EmployeeInfo クラスから画面用(presentation 層)の EmployeeInfoForm に * AllEmployeeInfo からEmployeeInfoForm に変換します。(リスト版)
* 変換します。(リスト版)
* *
* @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト * @param allEmployeeInfo AllEmployeeInfo インスタンスのリスト
* @return クラスから画面用(presentation 層)の EmployeeInfoForm インスタンスのリスト * @return EmployeeInfoForm インスタンスのリスト
*/ */
public static List<EmployeeInfoForm> convertFrom(List<AllEmployeeInfo> allEmployeeInfoList) { public static List<EmployeeInfoForm> convertFrom(List<AllEmployeeInfo> allEmployeeInfoList) {
return allEmployeeInfoList.stream().map(EmployeeInfoForm::convertFrom).toList(); return allEmployeeInfoList.stream().map(EmployeeInfoForm::convertFrom).toList();

View File

@@ -21,16 +21,26 @@ public class HeadquartersInfoForm {
*/ */
private String nmHeadquarters; private String nmHeadquarters;
/**
* AllDepartmentInfoから HeadquartersInfoFormに変換します。
*
* @param allDepartmentInfo AllDepartmentInfo インスタンス
* @return HeadquartersInfoForm インスタンス
*/
public static HeadquartersInfoForm convertFrom(AllDepartmentInfo allDepartmentInfo) { public static HeadquartersInfoForm convertFrom(AllDepartmentInfo allDepartmentInfo) {
return new HeadquartersInfoForm( return new HeadquartersInfoForm(
allDepartmentInfo.getHeadquarters().getIdHeadquarters(), allDepartmentInfo.getHeadquarters().getIdHeadquarters(),
allDepartmentInfo.getHeadquarters().getNmHeadquarters() allDepartmentInfo.getHeadquarters().getNmHeadquarters());
);
} }
public static List<HeadquartersInfoForm> convertFrom(List<AllDepartmentInfo>allDepartmentInfoList
) { /**
return allDepartmentInfoList.stream().map(HeadquartersInfoForm::convertFrom).toList(); * AllDepartmentInfoから HeadquartersInfoFormに変換します。(リスト版)
*
* @param allDepartmentInfo AllDepartmentInfo インスタンスのリスト
* @return HeadquartersInfoForm インスタンスのリスト
*/
public static List<HeadquartersInfoForm> convertFrom(List<AllDepartmentInfo> allDepartmentInfoList) {
return allDepartmentInfoList.stream().map(HeadquartersInfoForm::convertFrom).distinct().toList();
} }
} }

View File

@@ -40,10 +40,10 @@ public class InsertDepartmentForm {
private String nmDivision; private String nmDivision;
/** /**
* 画面用(presentation 層)の InsertDepartmentForm クラス を Business 層の Department クラスに変換 * 画面用(presentation 層)の InsertDepartmentForm クラス を Business 層の DepartmentInfo クラスに変換
* *
* @param insertDepartmentForm presentation 層用のクラス * @param insertDepartmentForm presentation 層用のクラス
* @return Business 層用のモデル * @return DepartmentFormのインスタンス
*/ */
public static DepartmentInfo convertTo(InsertDepartmentForm insertDepartmentForm) { public static DepartmentInfo convertTo(InsertDepartmentForm insertDepartmentForm) {
return new DepartmentInfo(insertDepartmentForm.getIdHeadquarters(), return new DepartmentInfo(insertDepartmentForm.getIdHeadquarters(),

View File

@@ -66,7 +66,6 @@ public class InsertEmployeeForm {
*/ */
private Integer idDivision; private Integer idDivision;
/** /**
* パスワードのValidation * パスワードのValidation
* チェック対象にエラーが有った場合エラーリストに文言を追加する * チェック対象にエラーが有った場合エラーリストに文言を追加する
@@ -123,8 +122,7 @@ public class InsertEmployeeForm {
insertEmployeeForm.getPassword(), insertEmployeeForm.getPassword(),
insertEmployeeForm.getHireDate(), insertEmployeeForm.getHireDate(),
insertEmployeeForm.getAdminAuth(), insertEmployeeForm.getAdminAuth(),
insertEmployeeForm.getIdDivision() insertEmployeeForm.getIdDivision());
);
} }
/** /**
@@ -138,7 +136,7 @@ public class InsertEmployeeForm {
final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス"; final String MAIL_ADDRESS_NULL_BLANK = "メールアドレス";
final String MANAGEMENT_ERROR = "管理者権限指定"; final String MANAGEMENT_ERROR = "管理者権限指定";
final String DEPARTMENT_ID_NULL_BLANK = "所属部署"; final String DEPARTMENT_ID_NULL_BLANK = "所属部署";
final String HIREDATE_NULL_BLANK ="入社年月日"; final String HIREDATE_NULL_BLANK = "入社年月日";
List<String> error = new ArrayList<>(); List<String> error = new ArrayList<>();
@@ -162,7 +160,7 @@ public class InsertEmployeeForm {
if (idDivision == null) { if (idDivision == null) {
error.add(DEPARTMENT_ID_NULL_BLANK); error.add(DEPARTMENT_ID_NULL_BLANK);
} }
if(isNullOrBlank(hireDate)) { if (isNullOrBlank(hireDate)) {
error.add(HIREDATE_NULL_BLANK); error.add(HIREDATE_NULL_BLANK);
} }

View File

@@ -1,6 +1,5 @@
package com.example.rhizome.app.presentation.form; 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;
@@ -57,8 +56,7 @@ public class LoginUserForm {
loginUser.getMailAddress(), loginUser.getMailAddress(),
loginUser.getPassword(), loginUser.getPassword(),
loginUser.getAdminAuth(), loginUser.getAdminAuth(),
loginUser.getIdDivision() loginUser.getIdDivision());
);
} }
/** /**
@@ -76,8 +74,7 @@ public class LoginUserForm {
loginUserForm.getMailAddress(), loginUserForm.getMailAddress(),
loginUserForm.getPassword(), loginUserForm.getPassword(),
loginUserForm.getAdminAuth(), loginUserForm.getAdminAuth(),
loginUserForm.getIdDepartment() loginUserForm.getIdDepartment());
);
} }
/** /**

View File

@@ -57,8 +57,7 @@ public class SearchConditionDepartmentForm {
public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) { public static SearchConditionDepartment convertTo(SearchConditionDepartmentForm searchConditionDepartmentForm) {
return new SearchConditionDepartment( return new SearchConditionDepartment(
searchConditionDepartmentForm.getIdDivision(), searchConditionDepartmentForm.getIdDivision(),
searchConditionDepartmentForm.nmDivision searchConditionDepartmentForm.nmDivision);
);
} }
} }

View File

@@ -48,8 +48,7 @@ public class SearchConditionEmployeeForm {
searchConditionEmployee.getNmEmployee(), searchConditionEmployee.getNmEmployee(),
searchConditionEmployee.getKnEmployee(), searchConditionEmployee.getKnEmployee(),
searchConditionEmployee.getMailAddress(), searchConditionEmployee.getMailAddress(),
searchConditionEmployee.getIdDivision() searchConditionEmployee.getIdDivision());
);
} }
/** /**
@@ -65,7 +64,6 @@ public class SearchConditionEmployeeForm {
searchConditionEmployeeForm.getNmEmployee(), searchConditionEmployeeForm.getNmEmployee(),
searchConditionEmployeeForm.getKnEmployee(), searchConditionEmployeeForm.getKnEmployee(),
searchConditionEmployeeForm.getMailAddress(), searchConditionEmployeeForm.getMailAddress(),
searchConditionEmployeeForm.getIdDivision() searchConditionEmployeeForm.getIdDivision());
);
} }
} }

View File

@@ -37,11 +37,11 @@ public class UpdateDepartmentForm {
* 課名 * 課名
*/ */
private String nmDivision; private String nmDivision;
/** /**
* business 層の Department クラスから画面用(presentation 層)の UpdateDepartmentForm に * AllDepartmentInfoクラスから UpdateDepartmentForm に変換します。
* 変換します。
* *
* @param department business 層の Department インスタンス * @param allDepartmentInfo AllDepartmentInfo インスタンス
* @return 画面用(presentation 層)の UpdateDepartmentForm インスタンス * @return 画面用(presentation 層)の UpdateDepartmentForm インスタンス
*/ */
public static UpdateDepartmentForm convertFrom(AllDepartmentInfo allDepartmentInfo) { public static UpdateDepartmentForm convertFrom(AllDepartmentInfo allDepartmentInfo) {
@@ -55,32 +55,11 @@ public class UpdateDepartmentForm {
} }
/** /**
* business 層の Department クラスから画面用(presentation 層)の UpdateDepartmentForm に * UpdateDepartmentFormから DepartmentInfo に変換します。
* 変換します。(リスト版)
* *
* @param departmentList business 層の Department インスタンスのリスト * @param updateDepartmentForm UpdateDepartmentFormインスタンス
* @return 画面用(presentation 層)の UpdateDepartmentForm インスタンスのリスト * @return DepartmentInfo インスタンス
*/ */
// public static List<UpdateDepartmentForm> convertFrom(List<Department> departmentList) {
// return departmentList.stream().map(UpdateDepartmentForm::convertFrom).toList();
// }
/**
* presentation 層の UpdateDepartmentForm クラスから Business 層の Department クラスに
* 変換します。
*
* @param updateDepartmentForm presentation 層のインスタンス
* @return Business 層の Department インスタンス
*/
// public static Department convertTo(UpdateDepartmentForm updateDepartmentForm) {
// return new Department(
// updateDepartmentForm.getIdDepartment(),
// updateDepartmentForm.getNmDepartment(),
// (Integer)0,
// updateDepartmentForm.getIdHeadquarters()
//
// );
// }
public static DepartmentInfo convertTo(UpdateDepartmentForm updateDepartmentForm) { public static DepartmentInfo convertTo(UpdateDepartmentForm updateDepartmentForm) {
return new DepartmentInfo( return new DepartmentInfo(
updateDepartmentForm.getIdHeadquarters(), updateDepartmentForm.getIdHeadquarters(),

View File

@@ -50,15 +50,18 @@ public class UpdateEmployeeInfoForm {
*/ */
private Integer adminAuth; private Integer adminAuth;
/** /**
* 部署ID * 部ID
*/ */
private Integer idDivision; private Integer idDivision;
/**
* 本部ID
*/
private Integer idHeadquarters;
/** /**
* business 層の EmployeeInfo クラスから画面用(presentation 層)の UpdateEmployeeInfoForm に * AllEmployeeInfo クラスからUpdateEmployeeInfoForm に変換します。
* 変換します。
* *
* @param employeeInfo business 層の EmployeeInfo インスタンス * @param allemployeeInfo AllEmployeeInfo インスタンス
* @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンス * @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンス
*/ */
public static UpdateEmployeeInfoForm convertFrom(AllEmployeeInfo allemployeeInfo) { public static UpdateEmployeeInfoForm convertFrom(AllEmployeeInfo allemployeeInfo) {
@@ -71,15 +74,15 @@ public class UpdateEmployeeInfoForm {
null, null,
allemployeeInfo.getEmployee().getHireDate(), allemployeeInfo.getEmployee().getHireDate(),
allemployeeInfo.getEmployee().getAdminAuth(), allemployeeInfo.getEmployee().getAdminAuth(),
allemployeeInfo.getDivision().getIdDivision() allemployeeInfo.getDivision().getIdDivision(),
); allemployeeInfo.getHeadquarters().getIdHeadquarters());
} }
/** /**
* business 層の EmployeeInfo クラスから画面用(presentation 層)の UpdateEmployeeInfoForm に * AllEmployeeInfo クラスから画面用 UpdateEmployeeInfoForm に変換します。(リスト版)
* 変換します。(リスト版)
* *
* @param employeeInfoList business 層の EmployeeInfo インスタンスのリスト * @param allemployeeInfoList business 層の AllEmployeeInfo インスタンスのリスト
* @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンスのリスト * @return 画面用(presentation 層)の UpdateEmployeeInfoForm インスタンスのリスト
*/ */
public static List<UpdateEmployeeInfoForm> convertFrom(List<AllEmployeeInfo> allemployeeInfoList) { public static List<UpdateEmployeeInfoForm> convertFrom(List<AllEmployeeInfo> allemployeeInfoList) {
@@ -102,8 +105,7 @@ public class UpdateEmployeeInfoForm {
updateEmployeeInfoForm.getPassword(), updateEmployeeInfoForm.getPassword(),
updateEmployeeInfoForm.getHireDate(), updateEmployeeInfoForm.getHireDate(),
updateEmployeeInfoForm.getAdminAuth(), updateEmployeeInfoForm.getAdminAuth(),
updateEmployeeInfoForm.getIdDivision() updateEmployeeInfoForm.getIdDivision());
);
} }
/** /**
@@ -126,7 +128,6 @@ public class UpdateEmployeeInfoForm {
errorFlag = true; errorFlag = true;
} }
return errorFlag; return errorFlag;
} }

View File

@@ -59,8 +59,7 @@ public class UpdatePersonalUserForm {
updatePersonalUserForm.getPassword(), updatePersonalUserForm.getPassword(),
updatePersonalUserForm.getHireDate(), updatePersonalUserForm.getHireDate(),
null, null,
null null);
);
} }
/** /**
@@ -98,8 +97,7 @@ public class UpdatePersonalUserForm {
loginUser.getMailAddress(), loginUser.getMailAddress(),
loginUser.getPassword(), loginUser.getPassword(),
null, null,
null null);
);
} }
/** /**
@@ -122,7 +120,6 @@ public class UpdatePersonalUserForm {
errorFlag = true; errorFlag = true;
} }
return errorFlag; return errorFlag;
} }

View File

@@ -35,11 +35,13 @@
</label> </label>
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="header">本部名</th> <th class="header">本部名</th>
<td> <td>
<label> <label>
<input maxlength="50" placeholder="本部名" th:field="*{nmHeadquarters}" type="text"id= "nmHeadquarters1" /> <input maxlength="50" placeholder="本部名" th:field="*{nmHeadquarters}" type="text"
id="nmHeadquarters1" />
</label> </label>
</td> </td>
</tr> </tr>
@@ -47,18 +49,17 @@
<th class="header"></th> <th class="header"></th>
<td> <td>
<label> <label>
<select th:field="*{nmHeadquarters}"id= "nmHeadquarters2"> <select th:field="*{nmHeadquarters}" id="nmHeadquarters2">
<option value="">本部を選択</option> <option value="">本部を選択</option>
<option <option th:each="headquarters : ${headquartersFormList}"
th:each="headquarters : ${departmentFormList}"
th:selected="${insertDepartmentForm.idHeadquarters != null && headquarters.idHeadquarters == insertDepartmentForm.idHeadquarters}" th:selected="${insertDepartmentForm.idHeadquarters != null && headquarters.idHeadquarters == insertDepartmentForm.idHeadquarters}"
th:text="${headquarters.nmHeadquarters}" th:value="${headquarters.nmHeadquarters}" th:text="${headquarters.nmHeadquarters}" th:value="${headquarters.nmHeadquarters}">
>
</option> </option>
</select> </select>
</label> </label>
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="header">部ID</th> <th class="header">部ID</th>
<td> <td>
@@ -67,11 +68,13 @@
</label> </label>
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="header">部名</th> <th class="header">部名</th>
<td> <td>
<label> <label>
<input maxlength="50" placeholder="部名" th:field="*{nmDepartment}" type="text" id="nmDepartment1"/> <input maxlength="50" placeholder="部名" th:field="*{nmDepartment}" type="text"
id="nmDepartment1" />
</label> </label>
</td> </td>
</tr> </tr>
@@ -79,10 +82,9 @@
<th class="header"></th> <th class="header"></th>
<td> <td>
<label> <label>
<select th:field="*{nmDepartment}"id="nmDepartment2"> <select th:field="*{nmDepartment}" id="nmDepartment2">
<option value="">部を選択</option> <option value="">部を選択</option>
<option <option th:each="department : ${departmentFormList}"
th:each="department : ${departmentFormList}"
th:selected="${insertDepartmentForm.idDepartment != null && department.idDepartment == insertDepartmentForm.idDepartment}" th:selected="${insertDepartmentForm.idDepartment != null && department.idDepartment == insertDepartmentForm.idDepartment}"
th:text="${department.nmDepartment}" th:value="${department.nmDepartment}"> th:text="${department.nmDepartment}" th:value="${department.nmDepartment}">
</option> </option>
@@ -100,11 +102,12 @@
</tr> </tr>
<tr> <tr>
<th class="header">課名</th> <th class="header">課名</th>
<td> <td>
<label> <label>
<input maxlength="50" placeholder="課名" th:field="*{nmDivision}" type="text" id="nmDivision1"/> <input maxlength="50" placeholder="課名" th:field="*{nmDivision}" type="text" id="nmDivision1" />
</label> </label>
</td> </td>
</tr> </tr>
@@ -115,9 +118,9 @@
<th class="header"></th> <th class="header"></th>
<td> <td>
<label> <label>
<select th:field="*{nmDivision}"id="nmDivision2"> <select th:field="*{nmDivision}" id="nmDivision2">
<option value="">課を選択</option> <option value="">課を選択</option>
<option th:each="division : ${departmentFormList}" <option th:each="division : ${divisionFormList}"
th:selected="${insertDepartmentForm.idDivision != null && division.idDivision == insertDepartmentForm.idDivision}" th:selected="${insertDepartmentForm.idDivision != null && division.idDivision == insertDepartmentForm.idDivision}"
th:text="${division.nmDivision}" th:value="${division.nmDivision}"> th:text="${division.nmDivision}" th:value="${division.nmDivision}">
</option> </option>
@@ -138,24 +141,49 @@
<a href="showMenu">メニューに戻る</a> <a href="showMenu">メニューに戻る</a>
</body> </body>
<script type="text/javascript"> <script type="text/javascript">
document.getElementById('insertDepartmentForm').addEventListener('submit',function(e){ const nmHeadquarters1 = document.getElementById('nmHeadquarters1');
if(document.getElementById('nmHeadquarters1').value!==""){ const nmHeadquarters2 = document.getElementById('nmHeadquarters2');
document.getElementById('nmHeadquarters2').removeAttribute('name');
}else if(document.getElementById('nmHeadquarters2').value!==""){ document.getElementById('insertDepartmentForm').addEventListener('submit', function (e) {
document.getElementById('nmHeadquarters1').removeAttribute('name'); if (nmHeadquarters1.value !== "") {
nmHeadquarters2.removeAttribute('name');
} else if (nmHeadquarters2.value !== "") {
nmHeadquarters1.removeAttribute('name');
} }
if(document.getElementById('nmDepartment1').value!==""){ // ↓両方の入力欄が空で登録確認ボタンを押した時用どちらかの空の情報を送る
document.getElementById('nmDepartment2').removeAttribute('name'); // (どちらかじゃないと","が入ってしまう)
}else if(document.getElementById('nmDepartment2').value!==""){ else if (nmHeadquarters2.value === "" && nmHeadquarters1.value === "") {
document.getElementById('nmDepartment1').removeAttribute('name'); nmHeadquarters2.removeAttribute('name');
}
if(document.getElementById('nmDivision1').value!==""){
document.getElementById('nmDivision2').removeAttribute('name');
}else if(document.getElementById('nmDivision2').value!==""){
document.getElementById('nmDivision1').removeAttribute('name');
} }
}); const nmDepartment1 = document.getElementById('nmDepartment1');
const nmDepartment2 = document.getElementById('nmDepartment2');
if (nmDepartment1.value !== "") {
nmDepartment2.removeAttribute('name');
} else if (nmDepartment2.value !== "") {
nmDepartment1.removeAttribute('name');
// ↓両方の入力欄が空で登録確認ボタンを押した時用どちらかの空の情報を送る
// (どちらかじゃないと","が入ってしまう)
} else if (nmDepartment1.value === "" && nmDepartment2.value === "") {
nmDepartment2.removeAttribute('name');
}
const nmDivision1 = document.getElementById('nmDivision1');
const nmDivision2 = document.getElementById('nmDivision2');
if (document.getElementById('nmDivision1').value !== "") {
document.getElementById('nmDivision2').removeAttribute('name');
} else if (document.getElementById('nmDivision2').value !== "") {
document.getElementById('nmDivision1').removeAttribute('name');
// ↓両方の入力欄が空で登録確認ボタンを押した時用どちらかの空の情報を送る
// (どちらかじゃないと","が入ってしまう)
} else if (nmDivision1.value === "" && nmDivision2.value === "") {
nmDivision2.removeAttribute('name');
}
});
</script> </script>

View File

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

View File

@@ -44,6 +44,7 @@
type="text"/> type="text"/>
</td> </td>
</tr> </tr>
<!-- 現状は課のみで検索ができる仕様-->
<tr> <tr>
<td class="btnArea" colspan="2"> <td class="btnArea" colspan="2">
<input type="submit" value="検索"/> <input type="submit" value="検索"/>

View File

@@ -71,6 +71,7 @@
th:text="${division.nmDivision}" th:text="${division.nmDivision}"
th:value="${division.idDivision}"> th:value="${division.idDivision}">
</option> </option>
<!-- 現状課だけでの検索の実装-->
</select> </select>
</td> </td>
</tr> </tr>
@@ -126,6 +127,7 @@
${employeeInfoForm.nmDepartment}+'<br/>・'+ ${employeeInfoForm.nmDepartment}+'<br/>・'+
${employeeInfoForm.nmDivision}" ${employeeInfoForm.nmDivision}"
></td> ></td>
<td> <td>
<!-- 更新フォーム --> <!-- 更新フォーム -->
<form action="showUpdateEmployee" method="post" style="display: inline;"> <form action="showUpdateEmployee" method="post" style="display: inline;">

View File

@@ -13,18 +13,15 @@
</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="/updateEmployeeResult" <form action="/updateEmployeeResult" method="post" onsubmit="return confirm('本当によろしいですか?');"
method="post" th:object="${updateEmployeeInfoForm}">
onsubmit="return confirm('本当によろしいですか?');"
th:object="${updateEmployeeInfoForm}"
>
<div class="msgBox error" th:if="${messageError != null}"> <div class="msgBox error" th:if="${messageError != null}">
<span class="error" th:each="message : ${messageError.message}" th:text="${message}"></span> <span class="error" th:each="message : ${messageError.message}" th:text="${message}"></span>
</div> </div>
@@ -33,11 +30,7 @@
<th class="header">社員ID</th> <th class="header">社員ID</th>
<td> <td>
<label> <label>
<input class="readOnly" <input class="readOnly" readonly="readonly" th:field="*{idEmployee}" type="text" />
readonly="readonly"
th:field="*{idEmployee}"
type="text"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -45,12 +38,8 @@
<th class="header">社員名</th> <th class="header">社員名</th>
<td> <td>
<label> <label>
<input maxlength="50" <input maxlength="50" placeholder="社員名" required="required" th:field="*{nmEmployee}"
placeholder="社員名" type="text" />
required="required"
th:field="*{nmEmployee}"
type="text"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -58,13 +47,8 @@
<th class="header">社員名フリガナ</th> <th class="header">社員名フリガナ</th>
<td> <td>
<label> <label>
<input maxlength="50" <input maxlength="50" oninput="convertToKatakana(this)" placeholder="フリガナ" required="required"
oninput="convertToKatakana(this)" th:field="*{knEmployee}" type="text" />
placeholder="フリガナ"
required="required"
th:field="*{knEmployee}"
type="text"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -72,12 +56,8 @@
<th class="header">メールアドレス</th> <th class="header">メールアドレス</th>
<td> <td>
<label> <label>
<input maxlength="100" <input maxlength="100" placeholder="メールアドレス" required="required" th:field="*{mailAddress}"
placeholder="メールアドレス" type="email" />
required="required"
th:field="*{mailAddress}"
type="email"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -85,11 +65,8 @@
<th class="header">パスワード</th> <th class="header">パスワード</th>
<td> <td>
<label> <label>
<input pattern="^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{3,10}$" <input pattern="^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{3,10}$" placeholder="パスワード"
placeholder="パスワード" th:field="*{password}" type="password" />
th:field="*{password}"
type="password"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -108,11 +85,8 @@
<th class="header">パスワード確認用</th> <th class="header">パスワード確認用</th>
<td> <td>
<label> <label>
<input pattern="^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{3,10}$" <input pattern="^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{3,10}$" placeholder="パスワード確認用"
placeholder="パスワード確認用" th:field="*{passwordConfirm}" type="password" />
th:field="*{passwordConfirm}"
type="password"
/>
</label> </label>
</td> </td>
</tr> </tr>
@@ -121,54 +95,51 @@
<td> <td>
<label> <label>
<input id="adminAuth1" name="adminAuth" th:checked="${updateEmployeeInfoForm.adminAuth == 1}" <input id="adminAuth1" name="adminAuth" th:checked="${updateEmployeeInfoForm.adminAuth == 1}"
type="radio" type="radio" value="1"> 管理者権限
value="1"> 管理者権限
</label> </label>
<label> <label>
<input id="adminAuth0" name="adminAuth" <input id="adminAuth0" name="adminAuth"
th:checked="${updateEmployeeInfoForm.adminAuth == null or updateEmployeeInfoForm.adminAuth == 0}" th:checked="${updateEmployeeInfoForm.adminAuth == null or updateEmployeeInfoForm.adminAuth == 0}"
type="radio" type="radio" value="0">
value="0">
一般権限 一般権限
</label> </label>
</td> </td>
</tr> </tr>
<tr> <tr>
<th class="header" style="vertical-align: top;">所属部署</th> <th class="header">所属本部</th>
<td> <td>
<label> <label>
<select required="required" > <select id="headquartersSelect" required="required" th:field="*{idHeadquarters}">
<option value="">本部を選択</option>
<option th:each="headquarters : ${departmentFormList}" <option th:each="headquarters : ${departmentFormList}" th:utext="
th:utext=" ${headquarters.nmHeadquarters}" th:value="${headquarters.idHeadquarters}">
${headquarters.nmHeadquarters}"
th:value="${headquarters.idHeadquarters}">
</option> </option>
</select> </select>
</label> </label>
<br> </td>
</tr>
<tr>
<th class="header">所属部</th>
<td>
<label> <label>
<select required="required" > <select id="departmentSelect" required="required">
<option th:each="department : ${departmentFormList}" <option value="">先に本部を選択してください</option>
th:utext="
${department.nmDepartment}"
th:value="${department.idDepartment}">
</option>
</select> </select>
</label> </label>
<br>
</td>
</tr>
<tr>
<th class="header">所属課</th>
<td>
<label> <label>
<select required="required" th:field="*{idDivision}"> <select id="divisionSelect" required="required" th:field="*{idDivision}">
<option th:each="division : ${departmentFormList}" <option value="">先に部を選択してください</option>
th:utext="
${division.nmDivision}"
th:value="${division.idDivision}">
</option>
</select> </select>
</label> </label>
@@ -176,12 +147,12 @@
</tr> </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="javascript:selectSubmit()">一覧に戻る</a> <a href="javascript:selectSubmit()">一覧に戻る</a>
</body> </body>
<script> <script>
@@ -204,5 +175,73 @@
form.submit(); form.submit();
} }
const headquartersSelect = document.getElementById('headquartersSelect');
const departmentSelect = document.getElementById('departmentSelect');
const divisionSelect = document.getElementById('divisionSelect');
headquartersSelect.addEventListener('change', function () {
const id_headquarters = this.value;
departmentSelect.disabled = true;
divisionSelect.disabled = true;
departmentSelect.innerHTML = '<option value="">-- 部を選択 --</option>';
divisionSelect.innerHTML = '<option value="">-- 先に部を選択してください --</option>';
if (!id_headquarters) return;
fetch(`updateEmployeeInput/searchDepartment?id_headquarters=${id_headquarters}`, {
method: 'GET',
headers: {
'Accept': 'application/json'
}
})
.then(res => {
return res.json();
})
.then(list => {
departmentSelect.disabled = false;
list.forEach(form => {
const opt = document.createElement('option');
opt.value = form.idDepartment;
opt.textContent = form.nmDepartment;
departmentSelect.appendChild(opt);
});
})
});
departmentSelect.addEventListener('change', function () {
const id_department = this.value;
divisionSelect.disabled = true;
divisionSelect.innerHTML = '<option value="">-- 課を選択 --</option>';
if (!id_department) return;
fetch(`/updateEmployeeInput/searchDepartment/searchDivision?id_department=${id_department}`, {
method: 'GET',
headers: {
'Accept': 'application/json'
}
})
.then(res => {
return res.json();
})
.then(list => {
divisionSelect.disabled = false;
list.forEach(form => {
const opt = document.createElement('option');
opt.value = form.idDivision;
opt.textContent = form.nmDivision;
divisionSelect.appendChild(opt);
});
})
});
</script> </script>
</html> </html>