[STYLE] serviceの無駄な改行やスペースなどの削除
This commit is contained in:
@@ -4,7 +4,7 @@ import com.example.rhizome.app.domain.model.LoginInfo;
|
|||||||
import com.example.rhizome.app.domain.model.LoginUser;
|
import com.example.rhizome.app.domain.model.LoginUser;
|
||||||
|
|
||||||
public interface Login {
|
public interface Login {
|
||||||
LoginUser doLogin(LoginInfo loginInfo);
|
LoginUser doLogin(LoginInfo loginInfo);
|
||||||
|
|
||||||
boolean canLogin(LoginInfo loginInfo);
|
boolean canLogin(LoginInfo loginInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ package com.example.rhizome.app.domain.service;
|
|||||||
import com.example.rhizome.app.domain.model.Department;
|
import com.example.rhizome.app.domain.model.Department;
|
||||||
|
|
||||||
public interface RegisterDepartment {
|
public interface RegisterDepartment {
|
||||||
void registerDepartment(Department department);
|
void registerDepartment(Department department);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ package com.example.rhizome.app.domain.service;
|
|||||||
import com.example.rhizome.app.domain.model.Employee;
|
import com.example.rhizome.app.domain.model.Employee;
|
||||||
|
|
||||||
public interface RegisterEmployee {
|
public interface RegisterEmployee {
|
||||||
void registerEmployee(Employee employee);
|
void registerEmployee(Employee employee);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.example.rhizome.app.domain.service;
|
package com.example.rhizome.app.domain.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.example.rhizome.app.domain.model.EmployeeInfo;
|
import com.example.rhizome.app.domain.model.EmployeeInfo;
|
||||||
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
|
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface SearchEmployeeInfo {
|
public interface SearchEmployeeInfo {
|
||||||
List<EmployeeInfo> selectAll();
|
List<EmployeeInfo> selectAll();
|
||||||
|
|
||||||
List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee);
|
List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ package com.example.rhizome.app.domain.service;
|
|||||||
import com.example.rhizome.app.domain.model.Employee;
|
import com.example.rhizome.app.domain.model.Employee;
|
||||||
|
|
||||||
public interface UpdateEmployee {
|
public interface UpdateEmployee {
|
||||||
void updateEmployee(Employee beforeEmployee, Employee updateEmployee);
|
void updateEmployee(Employee beforeEmployee, Employee updateEmployee);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,25 @@
|
|||||||
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;
|
||||||
* Employee レコード削除関連の機能を持つサービス
|
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class DeleteEmployeeImpl implements DeleteEmployee {
|
public class DeleteEmployeeImpl implements DeleteEmployee {
|
||||||
|
|
||||||
EmployeeRepository employeeRepository;
|
EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DeleteEmployeeImpl(EmployeeRepository employeeRepository) {
|
public DeleteEmployeeImpl(EmployeeRepository employeeRepository) {
|
||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteEmployee(Integer idEmployee) {
|
||||||
/**
|
employeeRepository.deleteById(idEmployee);
|
||||||
* idEmployee を元に employee データを削除
|
}
|
||||||
*
|
|
||||||
* @param idEmployee 削除対象のidEmployee
|
|
||||||
*/
|
|
||||||
public void deleteEmployee(Integer idEmployee) {
|
|
||||||
employeeRepository.deleteById(idEmployee);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,38 @@
|
|||||||
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.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
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;
|
||||||
import com.example.rhizome.app.domain.service.Login;
|
import com.example.rhizome.app.domain.service.Login;
|
||||||
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
||||||
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ログイン系の機能を集約させるサービスクラスです。
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class LoginImpl implements Login {
|
public class LoginImpl implements Login {
|
||||||
|
|
||||||
EmployeeRepository employeeRepository;
|
EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public LoginImpl(EmployeeRepository employeeRepository) {
|
public LoginImpl(EmployeeRepository employeeRepository) {
|
||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LoginUser doLogin(LoginInfo loginInfo) {
|
||||||
|
return employeeRepository
|
||||||
|
.findByMailAddressAndPassword(loginInfo.getMailAddress(), loginInfo.getPassword())
|
||||||
|
.orElse(new EmployeeEntity())
|
||||||
|
.createLoginUser();
|
||||||
|
|
||||||
/**
|
}
|
||||||
* メールアドレス、パスワードでログイン判定を行う
|
|
||||||
*
|
|
||||||
* @param loginInfo ログインを試みるアカウント
|
|
||||||
* @return loginUser のインスタンス
|
|
||||||
*/
|
|
||||||
public LoginUser doLogin(LoginInfo loginInfo) {
|
|
||||||
// ログイン情報を元にログインユーザーを取得
|
|
||||||
return employeeRepository
|
|
||||||
.findByMailAddressAndPassword(loginInfo.getMailAddress(), loginInfo.getPassword())
|
|
||||||
.orElse(new EmployeeEntity())
|
|
||||||
.createLoginUser();
|
|
||||||
|
|
||||||
}
|
public boolean canLogin(LoginInfo loginInfo) {
|
||||||
|
return employeeRepository
|
||||||
|
.findByMailAddressAndPassword(loginInfo.getMailAddress(), loginInfo.getPassword())
|
||||||
|
.isPresent();
|
||||||
|
|
||||||
/**
|
}
|
||||||
* メールアドレス、パスワードでログイン判定を行う
|
|
||||||
*
|
|
||||||
* @param loginInfo ログインを試みるアカウント
|
|
||||||
* @return loginUser のインスタンス
|
|
||||||
*/
|
|
||||||
public boolean canLogin(LoginInfo loginInfo) {
|
|
||||||
// ログイン情報を元にログインユーザーを取得
|
|
||||||
return employeeRepository
|
|
||||||
.findByMailAddressAndPassword(loginInfo.getMailAddress(), loginInfo.getPassword())
|
|
||||||
.isPresent();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,26 @@
|
|||||||
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.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.example.rhizome.app.domain.model.Employee;
|
import com.example.rhizome.app.domain.model.Employee;
|
||||||
import com.example.rhizome.app.domain.service.RegisterEmployee;
|
import com.example.rhizome.app.domain.service.RegisterEmployee;
|
||||||
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
||||||
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Employee テーブルの登録系の機能を集約させるサービスクラスです。
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class RegisterEmployeeImpl implements RegisterEmployee {
|
public class RegisterEmployeeImpl implements RegisterEmployee {
|
||||||
|
|
||||||
EmployeeRepository employeeRepository;
|
EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public RegisterEmployeeImpl(EmployeeRepository employeeRepository) {
|
public RegisterEmployeeImpl(EmployeeRepository employeeRepository) {
|
||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void registerEmployee(Employee employee) {
|
||||||
* employee インスタンスの内容を登録する
|
employeeRepository.save(EmployeeEntity.convertFrom(employee));
|
||||||
*
|
}
|
||||||
* @param employee 登録対象のデータ
|
|
||||||
*/
|
|
||||||
public void registerEmployee(Employee employee) {
|
|
||||||
employeeRepository.save(EmployeeEntity.convertFrom(employee));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +1,75 @@
|
|||||||
package com.example.rhizome.app.domain.service.impl;
|
package com.example.rhizome.app.domain.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.example.rhizome.app.domain.model.Department;
|
import com.example.rhizome.app.domain.model.Department;
|
||||||
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.infra.entity.DepartmentEntity;
|
import com.example.rhizome.app.infra.entity.DepartmentEntity;
|
||||||
import com.example.rhizome.app.infra.repository.DepartmentRepository;
|
import com.example.rhizome.app.infra.repository.DepartmentRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 部署情報検索系の機能を集約させるサービスクラスです。
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class SearchDepartmentImpl implements SearchDepartment {
|
public class SearchDepartmentImpl implements SearchDepartment {
|
||||||
|
|
||||||
DepartmentRepository departmentRepository;
|
DepartmentRepository departmentRepository;
|
||||||
|
|
||||||
/**
|
@Autowired
|
||||||
* コンストラクタ
|
public SearchDepartmentImpl(DepartmentRepository departmentRepository) {
|
||||||
*
|
this.departmentRepository = departmentRepository;
|
||||||
* @param departmentRepository DI対象
|
}
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
public SearchDepartmentImpl(DepartmentRepository departmentRepository) {
|
|
||||||
this.departmentRepository = departmentRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public List<Department> selectAll() {
|
||||||
* 部署情報を全件取得する
|
return DepartmentEntity.createDepartmentList(departmentRepository.findAll());
|
||||||
*
|
}
|
||||||
* @return 取得した部署情報レコード全件
|
|
||||||
*/
|
|
||||||
public List<Department> selectAll() {
|
|
||||||
return DepartmentEntity.createDepartmentList(departmentRepository.findAll());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public List<Department> searchBy(SearchConditionDepartment searchConditionDepartment) {
|
||||||
* searchConditionDepartment の情報を元に Department のレコードを取得
|
return DepartmentEntity
|
||||||
*
|
.createDepartmentList(
|
||||||
* @param searchConditionDepartment 検索条件
|
departmentRepository.findAll(Specification
|
||||||
* @return 検索結果のレコード
|
.where(DepartmentRepository
|
||||||
*/
|
.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
|
||||||
public List<Department> searchBy(SearchConditionDepartment searchConditionDepartment) {
|
.and(DepartmentRepository
|
||||||
// 動的に検索条件を絞り込む
|
.nmDepartmentEqual(searchConditionDepartment.getNmDepartment()))));
|
||||||
// Specification は Criteria API の Predicate をラップしたもの
|
|
||||||
return DepartmentEntity
|
|
||||||
.createDepartmentList(
|
|
||||||
departmentRepository.findAll(Specification
|
|
||||||
.where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
|
|
||||||
.and(DepartmentRepository.nmDepartmentEqual(searchConditionDepartment.getNmDepartment()))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment) {
|
||||||
* searchConditionDepartment の情報を元に Department のレコードを取得
|
return DepartmentEntity
|
||||||
* 部分一致検索
|
.createDepartmentList(
|
||||||
*
|
departmentRepository.findAll(Specification
|
||||||
* @param searchConditionDepartment 検索条件
|
.where(DepartmentRepository
|
||||||
* @return 検索結果のレコード
|
.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
|
||||||
*/
|
.and(DepartmentRepository
|
||||||
public List<Department> searchByWithLike(SearchConditionDepartment searchConditionDepartment) {
|
.nmDepartmentLike(searchConditionDepartment.getNmDepartment()))));
|
||||||
// 動的に検索条件を絞り込む
|
|
||||||
// Specification は Criteria API の Predicate をラップしたもの
|
}
|
||||||
return DepartmentEntity
|
|
||||||
.createDepartmentList(
|
@Override
|
||||||
departmentRepository.findAll(Specification
|
public List<Department> searchByDepartmentName(SearchConditionDepartment searchConditionDepartment) {
|
||||||
.where(DepartmentRepository.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))
|
|
||||||
.and(DepartmentRepository.nmDepartmentLike(searchConditionDepartment.getNmDepartment()))
|
return DepartmentEntity
|
||||||
)
|
.createDepartmentList(
|
||||||
);
|
departmentRepository.findAll(Specification
|
||||||
|
.where(DepartmentRepository
|
||||||
|
.nmDepartmentEqual(searchConditionDepartment.getNmDepartment()))));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Department> searchByDepartmentId(SearchConditionDepartment searchConditionDepartment) {
|
||||||
|
|
||||||
|
return DepartmentEntity
|
||||||
|
.createDepartmentList(
|
||||||
|
departmentRepository.findAll(Specification
|
||||||
|
.where(DepartmentRepository
|
||||||
|
.idDepartmentEqual(searchConditionDepartment.getIdDepartment()))));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,70 +1,43 @@
|
|||||||
package com.example.rhizome.app.domain.service.impl;
|
package com.example.rhizome.app.domain.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.example.rhizome.app.domain.model.Employee;
|
import com.example.rhizome.app.domain.model.Employee;
|
||||||
import com.example.rhizome.app.domain.model.LoginUser;
|
import com.example.rhizome.app.domain.model.LoginUser;
|
||||||
import com.example.rhizome.app.domain.service.SearchEmployee;
|
import com.example.rhizome.app.domain.service.SearchEmployee;
|
||||||
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
||||||
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Employee テーブル検索系の機能を集約させるサービスクラスです。
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class SearchEmployeeImpl implements SearchEmployee {
|
public class SearchEmployeeImpl implements SearchEmployee {
|
||||||
|
|
||||||
EmployeeRepository employeeRepository;
|
EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public SearchEmployeeImpl(EmployeeRepository employeeRepository) {
|
public SearchEmployeeImpl(EmployeeRepository employeeRepository) {
|
||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Employee> searchEmployee(String mailAddress) {
|
||||||
|
return EmployeeEntity.createEmployeeList(employeeRepository.findByMailAddress(mailAddress).stream().toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public LoginUser searchLoginUser(String mailAddress) {
|
||||||
* mailAddress を元に Employee Table を検索します。
|
return employeeRepository.findByMailAddress(mailAddress).orElse(new EmployeeEntity()).createLoginUser();
|
||||||
*
|
}
|
||||||
* @param mailAddress 検索対象の mailAddress
|
|
||||||
* @return Table から取得したレコードの情報
|
|
||||||
*/
|
|
||||||
public List<Employee> searchEmployee(String mailAddress) {
|
|
||||||
return EmployeeEntity.createEmployeeList(employeeRepository.findByMailAddress(mailAddress).stream().toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public Employee searchEmployeeByIdEmployee(Integer idEmployee) {
|
||||||
* mailAddress を元に ログイン者の情報 を検索します。
|
return EmployeeEntity
|
||||||
*
|
.createEmployee(employeeRepository.findByIdEmployee(idEmployee).orElse(new EmployeeEntity()));
|
||||||
* @param mailAddress 検索対象の mailAddress
|
}
|
||||||
* @return login者の情報
|
|
||||||
*/
|
|
||||||
public LoginUser searchLoginUser(String mailAddress) {
|
|
||||||
return employeeRepository.findByMailAddress(mailAddress).orElse(new EmployeeEntity()).createLoginUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* idEmployee を元に Employee Table を検索します。
|
public List<Employee> searchEmployeeByIdDepartment(Integer idDepartment) {
|
||||||
*
|
return EmployeeEntity.createEmployeeList(employeeRepository.findByIdDepartment(idDepartment));
|
||||||
* @param idEmployee 検索対象の idEmployee
|
}
|
||||||
* @return Table から取得したレコードの情報
|
|
||||||
*/
|
|
||||||
public Employee searchEmployeeByIdEmployee(Integer idEmployee) {
|
|
||||||
return EmployeeEntity.createEmployee(employeeRepository.findByIdEmployee(idEmployee).orElse(new EmployeeEntity()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* idDepartment を元に Employee Table を検索します。
|
|
||||||
*
|
|
||||||
* @param idDepartment 部署ID
|
|
||||||
* @return Table から取得したレコードの情報
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<Employee> searchEmployeeByIdDepartment(Integer idDepartment) {
|
|
||||||
return EmployeeEntity.createEmployeeList(employeeRepository.findByIdDepartment(idDepartment));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +1,45 @@
|
|||||||
package com.example.rhizome.app.domain.service.impl;
|
package com.example.rhizome.app.domain.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.example.rhizome.app.domain.model.EmployeeInfo;
|
import com.example.rhizome.app.domain.model.EmployeeInfo;
|
||||||
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
|
import com.example.rhizome.app.domain.model.SearchConditionEmployee;
|
||||||
import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
|
import com.example.rhizome.app.domain.service.SearchEmployeeInfo;
|
||||||
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
|
import com.example.rhizome.app.infra.entity.EmployeeDepartmentEntity;
|
||||||
import com.example.rhizome.app.infra.repository.EmployeeInfoRepository;
|
import com.example.rhizome.app.infra.repository.EmployeeInfoRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SearchEmployeeInfoImpl (employee join department) 検索系の機能を集約させるサービスクラスです
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class SearchEmployeeInfoImpl implements SearchEmployeeInfo {
|
public class SearchEmployeeInfoImpl implements SearchEmployeeInfo {
|
||||||
|
|
||||||
EmployeeInfoRepository employeeInfoRepository;
|
EmployeeInfoRepository employeeInfoRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public SearchEmployeeInfoImpl(EmployeeInfoRepository employeeInfoRepository) {
|
public SearchEmployeeInfoImpl(EmployeeInfoRepository employeeInfoRepository) {
|
||||||
this.employeeInfoRepository = employeeInfoRepository;
|
this.employeeInfoRepository = employeeInfoRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<EmployeeInfo> selectAll() {
|
||||||
|
|
||||||
/**
|
return EmployeeDepartmentEntity.createEmployeeInfoList(employeeInfoRepository.findAll());
|
||||||
* EmployeeInfo (employee join department) のレコードを全件取得
|
|
||||||
*
|
|
||||||
* @return 取得したレコード全件
|
|
||||||
*/
|
|
||||||
public List<EmployeeInfo> selectAll() {
|
|
||||||
|
|
||||||
return EmployeeDepartmentEntity.createEmployeeInfoList(employeeInfoRepository.findAll());
|
}
|
||||||
|
|
||||||
}
|
public List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee) {
|
||||||
|
return EmployeeDepartmentEntity
|
||||||
|
.createEmployeeInfoList(
|
||||||
|
employeeInfoRepository.findAll(Specification
|
||||||
|
.where(EmployeeInfoRepository.idEmployeeEqual(searchConditionEmployee.getIdEmployee()))
|
||||||
|
.and(EmployeeInfoRepository.nmEmployeeEqual(searchConditionEmployee.getNmEmployee()))
|
||||||
|
.and(EmployeeInfoRepository.knEmployeeEqual(searchConditionEmployee.getKnEmployee()))
|
||||||
|
.and(EmployeeInfoRepository.mailAddressEqual(searchConditionEmployee.getMailAddress()))
|
||||||
|
.and(EmployeeInfoRepository
|
||||||
|
.idDepartmentEqual(searchConditionEmployee.getIdDepartment()))));
|
||||||
|
|
||||||
/**
|
}
|
||||||
* SearchConditionEmployee の情報を元に EmployeeInfo (employee join department) のレコードを取得
|
|
||||||
*
|
|
||||||
* @param searchConditionEmployee 検索条件
|
|
||||||
* @return 検索結果のレコードリスト
|
|
||||||
*/
|
|
||||||
public List<EmployeeInfo> searchBy(SearchConditionEmployee searchConditionEmployee) {
|
|
||||||
// 動的に検索条件を絞り込む
|
|
||||||
// Specification は Criteria API の Predicate をラップしたもの
|
|
||||||
return EmployeeDepartmentEntity
|
|
||||||
.createEmployeeInfoList(
|
|
||||||
employeeInfoRepository.findAll(Specification
|
|
||||||
.where(EmployeeInfoRepository.idEmployeeEqual(searchConditionEmployee.getIdEmployee()))
|
|
||||||
.and(EmployeeInfoRepository.nmEmployeeEqual(searchConditionEmployee.getNmEmployee()))
|
|
||||||
.and(EmployeeInfoRepository.knEmployeeEqual(searchConditionEmployee.getKnEmployee()))
|
|
||||||
.and(EmployeeInfoRepository.mailAddressEqual(searchConditionEmployee.getMailAddress()))
|
|
||||||
.and(EmployeeInfoRepository.idDepartmentEqual(searchConditionEmployee.getIdDepartment()))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +1,42 @@
|
|||||||
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.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.example.rhizome.app.domain.model.Employee;
|
import com.example.rhizome.app.domain.model.Employee;
|
||||||
import com.example.rhizome.app.domain.service.UpdateEmployee;
|
import com.example.rhizome.app.domain.service.UpdateEmployee;
|
||||||
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
import com.example.rhizome.app.infra.entity.EmployeeEntity;
|
||||||
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
import com.example.rhizome.app.infra.repository.EmployeeRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* employee の更新系の機能を集約させるサービスクラスです。
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class UpdateEmployeeImpl implements UpdateEmployee {
|
public class UpdateEmployeeImpl implements UpdateEmployee {
|
||||||
|
|
||||||
EmployeeRepository employeeRepository;
|
EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UpdateEmployeeImpl(EmployeeRepository employeeRepository) {
|
public UpdateEmployeeImpl(EmployeeRepository employeeRepository) {
|
||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void updateEmployee(Employee beforeEmployee, Employee updateEmployee) {
|
||||||
* employee の情報を元に employee table のレコードを更新する
|
|
||||||
*
|
|
||||||
* @param beforeEmployee 更新前のデータ
|
|
||||||
* @param updateEmployee 更新後のデータ
|
|
||||||
*/
|
|
||||||
public void updateEmployee(Employee beforeEmployee, Employee updateEmployee) {
|
|
||||||
|
|
||||||
employeeRepository.save(EmployeeEntity.convertFrom(mergeEmployee(beforeEmployee, updateEmployee)));
|
employeeRepository.save(EmployeeEntity.convertFrom(mergeEmployee(beforeEmployee, updateEmployee)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private Employee mergeEmployee(Employee beforeEmployee, Employee updateEmployee) {
|
||||||
* 更新前のデータと更新対象のデータをマージする
|
return new Employee(
|
||||||
*
|
updateEmployee.getIdEmployee(),
|
||||||
* @param beforeEmployee 更新前のデータ
|
updateEmployee.getNmEmployee(),
|
||||||
* @param updateEmployee 更新対象のデータ
|
updateEmployee.getKnEmployee(),
|
||||||
* @return マージしたデータ
|
updateEmployee.getMailAddress(),
|
||||||
*/
|
updateEmployee.getPassword().isBlank() ? beforeEmployee.getPassword() : updateEmployee.getPassword(),
|
||||||
private Employee mergeEmployee(Employee beforeEmployee, Employee updateEmployee) {
|
updateEmployee.getAdminAuth() == null ? beforeEmployee.getAdminAuth() : updateEmployee.getAdminAuth(),
|
||||||
// 更新対象のデータのパスワードが空文字の場合は、更新前のパスワードを使用する
|
updateEmployee.getIdDepartment() == null ? beforeEmployee.getIdDepartment()
|
||||||
// 更新対象のデータの管理者権限が null の場合は、更新前の管理者権限を使用する
|
: updateEmployee.getIdDepartment());
|
||||||
// 更新対象のデータの部署IDが null の場合は、更新前の部署IDを使用する
|
|
||||||
return new Employee(
|
|
||||||
updateEmployee.getIdEmployee(),
|
|
||||||
updateEmployee.getNmEmployee(),
|
|
||||||
updateEmployee.getKnEmployee(),
|
|
||||||
updateEmployee.getMailAddress(),
|
|
||||||
updateEmployee.getPassword().isBlank() ? beforeEmployee.getPassword() : updateEmployee.getPassword(),
|
|
||||||
updateEmployee.getAdminAuth() == null ? beforeEmployee.getAdminAuth() : updateEmployee.getAdminAuth(),
|
|
||||||
updateEmployee.getIdDepartment() == null ? beforeEmployee.getIdDepartment() : updateEmployee.getIdDepartment()
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user