package com.gkhy.labRiskManage.domain.basic.service.impl;
|
|
import com.gkhy.labRiskManage.application.basic.dto.bo.BasicExperimentPersonAppInsertBO;
|
import com.gkhy.labRiskManage.application.basic.dto.bo.BasicExperimentPersonAppQueryBO;
|
import com.gkhy.labRiskManage.application.basic.dto.bo.BasicExperimentPersonAppUpdateBO;
|
import com.gkhy.labRiskManage.commons.domain.SearchResult;
|
import com.gkhy.labRiskManage.commons.enums.ResultCode;
|
import com.gkhy.labRiskManage.commons.enums.StatusEnum;
|
import com.gkhy.labRiskManage.commons.enums.UserTagEnum;
|
import com.gkhy.labRiskManage.commons.exception.BusinessException;
|
import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils;
|
import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO;
|
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
|
import com.gkhy.labRiskManage.domain.basic.converter.ToInsertPersonBOConverter;
|
import com.gkhy.labRiskManage.domain.basic.converter.ToQueryPersonBOConverter;
|
import com.gkhy.labRiskManage.domain.basic.entity.BasicExperimentPerson;
|
import com.gkhy.labRiskManage.domain.basic.model.bo.PersonInsertBO;
|
import com.gkhy.labRiskManage.domain.basic.model.bo.PersonQueryBO;
|
import com.gkhy.labRiskManage.domain.basic.model.dto.*;
|
import com.gkhy.labRiskManage.domain.basic.repository.jpa.BasicExperimentPersonRepository;
|
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentPersonService;
|
import com.gkhy.labRiskManage.domain.riskReport.utils.GetRoleTagUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.Sort;
|
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.ObjectUtils;
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Root;
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
|
/**
|
* 基础实验人员管理
|
*/
|
@Service
|
public class BasicExperimentPersonServiceImpl implements BasicExperimentPersonService {
|
|
@Autowired
|
private BasicExperimentPersonRepository personRepository;
|
@Autowired
|
private UserDomainService userDomainService;
|
|
/**
|
* 基础实验人员 - 插入
|
* */
|
@Override
|
public PersonInsertDTO insertBasicExperimentPerson(Long currentUserId, BasicExperimentPersonAppInsertBO personAppInsertDO) {
|
|
if (currentUserId < 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
|
}
|
|
//接收,转换参数 todo ,目前所有信息,缺乏唯一性标识。需要如身份证,手机号,人员身份码之类的信息
|
ToInsertPersonBOConverter converter = new ToInsertPersonBOConverter();
|
PersonInsertBO personInsertBO = converter.toInsertPersonDTO(personAppInsertDO);
|
|
//参数校验
|
if (ObjectUtils.isEmpty(personInsertBO)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "人员信息不能为空");
|
}
|
if (ObjectUtils.isEmpty(personInsertBO.getPersonName())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "姓名不能为空");
|
}
|
if (ObjectUtils.isEmpty(personInsertBO.getPersonAge())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "年龄不能为空");
|
}
|
if (ObjectUtils.isEmpty(personInsertBO.getPersonGender())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "性别不能为空");
|
}
|
if (ObjectUtils.isEmpty(personInsertBO.getPersonMajor())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "专业不能为空");
|
}
|
// if (ObjectUtils.isEmpty(insertPersonDO.getDepName())){
|
// throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "所属部门不能为空");
|
// } todo 暂时没有部门
|
if (ObjectUtils.isEmpty(personInsertBO.getAptitude())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "相关资质不能为空");
|
}
|
if (ObjectUtils.isEmpty(personInsertBO.getTraining())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "培训情况不能为空");
|
}
|
if (ObjectUtils.isEmpty(personInsertBO.getPhone())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "手机号不能为空");
|
}
|
BasicExperimentPerson personByPhone = personRepository.getPersonByPhone(personInsertBO.getPhone());
|
if (!ObjectUtils.isEmpty(personByPhone)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "手机号已被使用");
|
}
|
|
BasicExperimentPerson person = BeanCopyUtils.copyBean(personInsertBO, BasicExperimentPerson.class);
|
UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
|
//获取参数
|
LocalDateTime date = LocalDateTime.now();
|
//封装参数
|
person.setCreateByUserId(userInfoById.getId());
|
person.setCreateTime(date);
|
person.setUpdateByUserId(userInfoById.getId());
|
person.setUpdateTime(date);
|
person.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
|
|
|
BasicExperimentPerson saveResult = personRepository.save(person);
|
return BeanCopyUtils.copyBean(saveResult, PersonInsertDTO.class);
|
}
|
|
/**
|
* 基础实验人员 - 分页查询
|
* */
|
@Override
|
public SearchResult<PersonQueryDTO> getBasicExperimentPersonPage(Long currentUserId, BasicExperimentPersonAppQueryBO queryParam) {
|
|
//校验参数
|
if (ObjectUtils.isEmpty(queryParam.getPageSize())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
|
}
|
if (ObjectUtils.isEmpty(queryParam.getPageIndex())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空");
|
}
|
if (queryParam.getPersonName() == ""){
|
queryParam.setPersonName(null);
|
}
|
if (queryParam.getDepName() == ""){
|
queryParam.setDepName(null);
|
}
|
|
//接收,转换参数
|
ToQueryPersonBOConverter converter = new ToQueryPersonBOConverter();
|
PersonQueryBO queryPageParam = converter.toQueryPersonDOConverter(queryParam);
|
|
SearchResult searchResult = new SearchResult<>();
|
|
searchResult.setPageIndex(queryPageParam.getPageIndex());
|
searchResult.setPageSize(queryPageParam.getPageSize());
|
|
UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
|
int roleTag = GetRoleTagUtils.GetRoleTagUtils(user);
|
|
//封装查询参数
|
Specification<BasicExperimentPerson> specification = new Specification<BasicExperimentPerson>() {
|
@Override
|
public Predicate toPredicate(Root<BasicExperimentPerson> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
List<Predicate> predicateList = new ArrayList<>();
|
if (queryPageParam.getPersonName() != null && !queryPageParam.getPersonName().equals("")){
|
predicateList.add(criteriaBuilder.equal(root.get("personName"), queryPageParam.getPersonName()));
|
}
|
if (queryPageParam.getDepName() != null && !queryPageParam.getDepName().equals("")){
|
predicateList.add(criteriaBuilder.equal(root.get("depName"), queryPageParam.getDepName()));
|
}
|
if (queryPageParam.getTraining() != null && !queryPageParam.getTraining().equals("")){
|
predicateList.add(criteriaBuilder.equal(root.get("training"), queryPageParam.getTraining()));
|
}
|
if (roleTag == UserTagEnum.USER_TAG_0.getCode()){
|
predicateList.add(criteriaBuilder.equal(root.get("createByUserId"), currentUserId));
|
}
|
predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode()));
|
return criteriaBuilder.and(predicateList.toArray(new Predicate[0]));
|
}
|
};
|
PageRequest pageParam = PageRequest.of(queryPageParam.getPageIndex() - 1, queryPageParam.getPageSize(), Sort.Direction.DESC, "updateTime");
|
|
Page<BasicExperimentPerson> pageResult = personRepository.findAll(specification, pageParam);
|
List<PersonQueryDTO> personQueryDTOS = BeanCopyUtils.copyBeanList(pageResult.getContent(), PersonQueryDTO.class);
|
// BasicExperimentPerson person = new BasicExperimentPerson();
|
// person.set
|
// personQueryDTOS.add()
|
|
List<UserInfoDomainDTO> userList = userDomainService.getUserList();
|
for (PersonQueryDTO personQueryDTO : personQueryDTOS) {
|
for (UserInfoDomainDTO userInfo : userList) {
|
if (userInfo.getId() == personQueryDTO.getCreateByUserId()){
|
personQueryDTO.setCreateByUserName(userInfo.getRealName());
|
}
|
if (userInfo.getId() == personQueryDTO.getUpdateByUserId()){
|
personQueryDTO.setUpdateByUserName(userInfo.getRealName());
|
}
|
}
|
}
|
|
searchResult.setData(personQueryDTOS);
|
searchResult.setTotal(pageResult.getTotalElements());
|
|
return searchResult;
|
}
|
|
/**
|
* 基础实验人员 - 修改
|
* */
|
@Override
|
public PersonUpdateDTO updateBasicExperimentPerson(Long currentUserId, BasicExperimentPersonAppUpdateBO updateParam) {
|
|
if (currentUserId < 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
|
}
|
|
//参数校验
|
if (ObjectUtils.isEmpty(updateParam)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "人员信息不能为空");
|
}
|
if (ObjectUtils.isEmpty(updateParam.getPersonName())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "姓名不能为空");
|
}
|
if (ObjectUtils.isEmpty(updateParam.getPersonAge())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "年龄不能为空");
|
}
|
if (ObjectUtils.isEmpty(updateParam.getPersonGender())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "性别不能为空");
|
}
|
if (ObjectUtils.isEmpty(updateParam.getPersonMajor())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "专业不能为空");
|
}
|
// if (ObjectUtils.isEmpty(insertPersonDO.getDepName())){
|
// throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "所属部门不能为空");
|
// } todo 暂时没有部门
|
if (ObjectUtils.isEmpty(updateParam.getAptitude())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "相关资质不能为空");
|
}
|
if (ObjectUtils.isEmpty(updateParam.getTraining())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "培训情况不能为空");
|
}
|
if (ObjectUtils.isEmpty(updateParam.getPhone())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "手机号不能为空");
|
}
|
BasicExperimentPerson personByPhone = personRepository.getPersonByPhone(updateParam.getPhone());
|
// if (!ObjectUtils.isEmpty(personByPhone) && updateParam.getId() != personByPhone.getId()){
|
// throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "手机号已被使用");
|
// }
|
|
BasicExperimentPerson personById = personRepository.getPersonById(updateParam.getId());
|
BasicExperimentPerson person = BeanCopyUtils.copyBean(personById, BasicExperimentPerson.class);
|
UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
|
|
//获取参数
|
LocalDateTime date = LocalDateTime.now();
|
//封装参数
|
person.setUpdateByUserId(userInfoById.getId());
|
person.setUpdateTime(date);
|
person.setPersonName(updateParam.getPersonName());
|
person.setPersonAge(updateParam.getPersonAge());
|
person.setPersonGender(updateParam.getPersonGender());
|
person.setPersonMajor(updateParam.getPersonMajor());
|
person.setDepName(updateParam.getDepName());
|
person.setAptitude(updateParam.getAptitude());
|
person.setTraining(updateParam.getTraining());
|
person.setPhone(updateParam.getPhone());
|
person.setImage(updateParam.getImage());
|
|
//更新数据
|
BasicExperimentPerson saveResult = personRepository.save(person);
|
|
return BeanCopyUtils.copyBean(saveResult, PersonUpdateDTO.class);
|
}
|
|
/**
|
* 基础实验人员 - 删除
|
* */
|
@Override
|
public PersonDeleteDTO deleteBasicExperimentPerson(Long currentUserId, Long id) {
|
|
if (currentUserId < 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆");
|
}
|
|
//校验参数
|
if (ObjectUtils.isEmpty(id)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请求参数错误");
|
}
|
BasicExperimentPerson personById = personRepository.getPersonById(id);
|
if (ObjectUtils.isEmpty(personById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "该人员不存在,或已被删除");
|
}
|
UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId);
|
LocalDateTime date = LocalDateTime.now();
|
//设置数据为删除
|
personById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
|
personById.setUpdateByUserId(userInfoById.getId());
|
personById.setUpdateTime(date);
|
//执行数据更新
|
BasicExperimentPerson deleteResult = personRepository.save(personById);
|
|
return BeanCopyUtils.copyBean(deleteResult, PersonDeleteDTO.class);
|
}
|
|
/**
|
* 基础实验人员 - 列表
|
* */
|
@Override
|
public List<PersonListDTO> listBasicExperimentPerson(Long currentUserId) {
|
|
UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
|
int roleTag = GetRoleTagUtils.GetRoleTagUtils(user);
|
|
List<BasicExperimentPerson> peopleList = new ArrayList<>();
|
|
if (roleTag != UserTagEnum.USER_TAG_0.getCode()){
|
peopleList = personRepository.listPerson(currentUserId);
|
}else {
|
peopleList = personRepository.listPersonByUserId(currentUserId);
|
}
|
return BeanCopyUtils.copyBeanList(peopleList, PersonListDTO.class);
|
}
|
|
/**
|
* 基础实验人员 - 查询 by id
|
* */
|
@Override
|
public PersonQueryDTO getBasicExperimentPersonById(Long id) {
|
if (ObjectUtils.isEmpty(id)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请求参数不能为空");
|
}
|
|
BasicExperimentPerson personById = personRepository.getPersonById(id);
|
|
if (ObjectUtils.isEmpty(personById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), "请检查是否输入有误或人员已被删除");
|
}
|
return BeanCopyUtils.copyBean(personById, PersonQueryDTO.class);
|
}
|
|
/**
|
* 基础实验人员 - 查询 by id --评估计划使用
|
* */
|
@Override
|
public PersonQueryDTO getPersonByIdAndSellInfo(Long id, String Info) {
|
if (ObjectUtils.isEmpty(id)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请求参数不能为空");
|
}
|
|
BasicExperimentPerson personById = personRepository.getPersonById(id);
|
|
if (ObjectUtils.isEmpty(personById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), Info + "不存在,请检查是否输入有误或人员已被删除");
|
}
|
return BeanCopyUtils.copyBean(personById, PersonQueryDTO.class);
|
}
|
|
/**
|
* 基础实验人员 - 通过id列表查询
|
* */
|
@Override
|
public List<PersonQueryDTO> getBasicExperimentPersonByIdList(List<Long> ids) {
|
if (ids.size() < 1){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), "请求参数不能为空");
|
}
|
|
List<BasicExperimentPerson> listResult = personRepository.batchById(ids);
|
if (listResult.size() < 1){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), "查询结果为空");
|
}
|
|
return BeanCopyUtils.copyBeanList(listResult, PersonQueryDTO.class);
|
}
|
}
|