package com.gkhy.labRiskManage.domain.experiment.service.impl;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.gkhy.labRiskManage.application.experiment.dto.bo.ExperimentAppInsertBO;
|
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.UserRoleEnum;
|
import com.gkhy.labRiskManage.commons.enums.UserTagEnum;
|
import com.gkhy.labRiskManage.commons.exception.BusinessException;
|
import com.gkhy.labRiskManage.commons.model.PageQuery;
|
import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils;
|
import com.gkhy.labRiskManage.domain.account.entity.Role;
|
import com.gkhy.labRiskManage.domain.account.entity.SysUserRoleBind;
|
import com.gkhy.labRiskManage.domain.account.entity.User;
|
import com.gkhy.labRiskManage.domain.account.model.dto.SysUserRoleBindDomainDTO;
|
import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO;
|
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
|
import com.gkhy.labRiskManage.domain.experiment.converter.ExperimentInfoDomainConverter;
|
import com.gkhy.labRiskManage.domain.experiment.entity.*;
|
import com.gkhy.labRiskManage.domain.experiment.model.bo.ExperimentDevelopUpdateBO;
|
import com.gkhy.labRiskManage.domain.basic.model.dto.PersonQueryDTO;
|
import com.gkhy.labRiskManage.domain.basic.model.dto.SiteQueryDTO;
|
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentPersonService;
|
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentSiteService;
|
import com.gkhy.labRiskManage.domain.experiment.enums.*;
|
import com.gkhy.labRiskManage.domain.experiment.model.bo.ExperimentInfoQueryBO;
|
import com.gkhy.labRiskManage.domain.experiment.model.dto.*;
|
import com.gkhy.labRiskManage.domain.experiment.repository.jpa.ExperimentInfoRepository;
|
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentInfoService;
|
import com.gkhy.labRiskManage.domain.riskReport.entity.ReportRiskAssessInfo;
|
import com.gkhy.labRiskManage.domain.riskReport.entity.RiskAssessPlan;
|
import com.gkhy.labRiskManage.domain.riskReport.model.bo.UpdateExperimentInfoBO;
|
import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.ReportRiskAssessInfoRepository;
|
import com.gkhy.labRiskManage.domain.riskReport.service.ReportRiskAssessInfoService;
|
import com.gkhy.labRiskManage.domain.riskReport.utils.GetRoleTagUtils;
|
import jodd.util.StringUtil;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Sort;
|
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.ObjectUtils;
|
|
import javax.persistence.criteria.*;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* 实验信息
|
*/
|
@Service
|
public class ExperimentInfoServiceImpl implements ExperimentInfoService {
|
@Autowired
|
private ExperimentInfoRepository repository;
|
|
@Autowired
|
private BasicExperimentPersonService basicExperimentPersonService;
|
@Autowired
|
private UserDomainService userDomainService;
|
@Autowired
|
private ExperimentInfoDomainConverter converter;
|
|
@Autowired
|
private ReportRiskAssessInfoRepository reportRiskAssessInfoRepository;
|
|
@Override
|
public ExperimentInfoDTO save(Long currentUserId, ExperimentAppInsertBO experimentAppInsertBO) {
|
UserInfoDomainDTO operator = userDomainService.getUserInfoById(currentUserId);
|
//验证权限
|
List<SysUserRoleBindDomainDTO> roles = operator.getRoles();
|
boolean flag = false;
|
if(roles != null && roles.size() > 0){
|
for (SysUserRoleBindDomainDTO role : roles){
|
if (role.getRoleName().equals(UserRoleEnum.USER_ROLE_1.getDesc())) {
|
flag = true;
|
break;
|
}
|
}
|
}
|
if (!flag){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"该账号无权限录入实验信息!");
|
}
|
|
//验证
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExperimentName())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验名称!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExperimentType())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"请选择实验类型!");
|
}
|
if(ObjectUtils.isEmpty(ExperimentTypeEnum.prase(experimentAppInsertBO.getExperimentType()))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"实验类型非法!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getLiabilityUserId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请选择实验负责人!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getLiabilityUserPhone())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验负责人手机号!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getSafeLiabilityUser())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写安全负责人!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getSafeLiabilityUserPhone())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写安全负责人手机号!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getDep())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请输入部门!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExperimentStep())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验步骤!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExperimentMethod())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验操作方法!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getProcess())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写工艺过程!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getKeyProcess())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写关键流程!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getTimeout())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请选择是否存在过夜、老化实验!");
|
}
|
if(ObjectUtils.isEmpty(TimeoutEnum.prase(experimentAppInsertBO.getTimeout()))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"是否存在过夜、老化实验数据校验非法!");
|
}
|
|
if(experimentAppInsertBO.getTimeout().equals(TimeoutEnum.EXISTENT.getValue()) && ObjectUtils.isEmpty(experimentAppInsertBO.getTimeoutManager())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写过夜、老化实验保障管理措施!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getClosed())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请选择是否在密闭条件下!");
|
}
|
if(ObjectUtils.isEmpty(CloseConditionEnum.prase(experimentAppInsertBO.getClosed()))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"是否在密闭条件下数据校验非法!");
|
}
|
if(experimentAppInsertBO.getClosed().equals(CloseConditionEnum.CLOSE_YES.getValue()) && ObjectUtils.isEmpty(experimentAppInsertBO.getUnclosedManager())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写密闭实验保障管理措施!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExplosionProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getFireProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防火措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getPoisonProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getSafeManagerMethod())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写安全管理制度!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExplosionProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExplosionProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExplosionProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(PertitionConditionEnum.prase(experimentAppInsertBO.getPartitionCondition()))){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"是否需要分区隔断参数非法!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getCreateExperimentTime())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请选择实验立项时间!");
|
}
|
ExperimentInfo experimentInfo = new ExperimentInfo();
|
BeanUtils.copyProperties(experimentAppInsertBO, experimentInfo);
|
experimentInfo.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
|
experimentInfo.setLiabilityUser(operator.getName());
|
experimentInfo.setLiabilityUserId(currentUserId);
|
experimentInfo.setStage(ExperimentStageEnum.NOT_EVALUATION.getValue());
|
experimentInfo.setStatus(ExperimentStatusEnum.NOT_APPLY.getValue());
|
experimentInfo.setExperimentTag(ExperimentTagEnum.NEW_CREATE.getValue());
|
experimentInfo.setRectifyStatus(ExperimentRectifyStatusEnum.NOT_RECTIFY.getValue());
|
experimentInfo.setExperimentCode(generateTestNumber());
|
experimentInfo.setCreateByUserId(currentUserId);
|
experimentInfo.setInformant(operator == null?"":operator.getName());
|
experimentInfo.setUpdateByUserId(currentUserId);
|
experimentInfo.setApprovalStatus(ExperimentApprovalStatusEnum.NOT_APPROVAL.getValue());
|
ExperimentInfo experiment = repository.save(experimentInfo);
|
|
return converter.getExperimentInfoDTO(experiment);
|
}
|
@Override
|
public ExperimentInfoDTO developSave(Long currentUserId, ExperimentAppInsertBO experimentAppInsertBO) {
|
UserInfoDomainDTO operator = userDomainService.getUserInfoById(currentUserId);
|
//验证权限
|
List<SysUserRoleBindDomainDTO> roles = operator.getRoles();
|
boolean flag = false;
|
if(roles != null && roles.size() > 0){
|
for (SysUserRoleBindDomainDTO role : roles){
|
if (role.getRoleName().equals(UserRoleEnum.USER_ROLE_1.getDesc())) {
|
flag = true;
|
break;
|
}
|
}
|
}
|
if (!flag){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"该账号无权限录入实验信息!");
|
}
|
//验证
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExperimentName())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验名称!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExperimentType())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"请选择实验类型!");
|
}
|
if(ObjectUtils.isEmpty(ExperimentTypeEnum.prase(experimentAppInsertBO.getExperimentType()))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"实验类型非法!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getLiabilityUserPhone())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验负责人手机号!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getSafeLiabilityUser())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写安全负责人!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getSafeLiabilityUserPhone())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写安全负责人手机号!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getDep())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请输入部门!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExperimentStep())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验步骤!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExperimentMethod())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验操作方法!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getProcess())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写工艺过程!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getKeyProcess())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写关键流程!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getTimeout())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请选择是否存在过夜、老化实验!");
|
}
|
if(ObjectUtils.isEmpty(TimeoutEnum.prase(experimentAppInsertBO.getTimeout()))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"是否存在过夜、老化实验数据校验非法!");
|
}
|
if(experimentAppInsertBO.getTimeout().equals(TimeoutEnum.EXISTENT.getValue()) && ObjectUtils.isEmpty(experimentAppInsertBO.getTimeoutManager())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写过夜、老化实验保障管理措施!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getClosed())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请选择是否在密闭条件下!");
|
}
|
if(ObjectUtils.isEmpty(CloseConditionEnum.prase(experimentAppInsertBO.getClosed()))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"是否在密闭条件下数据校验非法!");
|
}
|
if(experimentAppInsertBO.getClosed().equals(CloseConditionEnum.CLOSE_YES.getValue()) && ObjectUtils.isEmpty(experimentAppInsertBO.getUnclosedManager())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写密闭实验保障管理措施!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExplosionProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getFireProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防火措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getPoisonProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getSafeManagerMethod())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写安全管理制度!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExplosionProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExplosionProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getExplosionProof())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请填写实验场所防爆措施条件和设施情况!");
|
}
|
if(ObjectUtils.isEmpty(PertitionConditionEnum.prase(experimentAppInsertBO.getPartitionCondition()))){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"是否需要分区隔断参数非法!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getCreateExperimentTime())){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"请选择实验立项时间!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getSisStatus())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请选择是否是安全信息系统!");
|
}
|
if(ObjectUtils.isEmpty(SafeInformationSystemEnum.prase(experimentAppInsertBO.getSisStatus()))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(), "安全信息系统数据校验错误!");
|
}
|
if(SafeInformationSystemEnum.YES.getValue().equals(experimentAppInsertBO.getSisStatus()) && ObjectUtils.isEmpty(experimentAppInsertBO.getSafeInformationSystem())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请填写安全信息系统名称!");
|
}
|
if(ObjectUtils.isEmpty(experimentAppInsertBO.getStartTime())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请填写请实验开展时间!");
|
}
|
ExperimentInfo experimentInfo = new ExperimentInfo();
|
BeanUtils.copyProperties(experimentAppInsertBO, experimentInfo);
|
experimentInfo.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
|
experimentInfo.setLiabilityUserId(currentUserId);
|
experimentInfo.setLiabilityUser(operator.getName());
|
experimentInfo.setStage(ExperimentStageEnum.NOT_EVALUATION.getValue());
|
experimentInfo.setStatus(ExperimentStatusEnum.NOT_APPLY.getValue());
|
experimentInfo.setExperimentTag(ExperimentTagEnum.AREADLY_DEVELOP.getValue());
|
experimentInfo.setRectifyStatus(ExperimentRectifyStatusEnum.NOT_RECTIFY.getValue());
|
experimentInfo.setExperimentCode(generateTestNumber());
|
experimentInfo.setCreateByUserId(currentUserId);
|
experimentInfo.setInformant(operator == null?"":operator.getName());
|
experimentInfo.setUpdateByUserId(currentUserId);
|
experimentInfo.setApprovalStatus(ExperimentApprovalStatusEnum.NOT_APPROVAL.getValue());
|
ExperimentInfo experiment = repository.save(experimentInfo);
|
|
return converter.getExperimentInfoDTO(experiment);
|
}
|
|
@Override
|
public boolean deleteById(Long id,Long currentUserId) {
|
boolean flag = false;
|
if(ObjectUtils.isEmpty(id)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验主键不可为空!");
|
}
|
//获取该条实现信息
|
ExperimentInfo experimentInfo = repository.getExperimentInfoById(id);
|
if(ObjectUtils.isEmpty(experimentInfo)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), " 该实验信息不存在,或已被删除");
|
}
|
if(experimentInfo.getStatus().equals(ExperimentStatusEnum.YES_APPLY.getValue())){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode(),"该条实验信息已申请评估,不可删除!");
|
}
|
LocalDateTime date = LocalDateTime.now();
|
//设置数据为删除
|
experimentInfo.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
|
experimentInfo.setUpdateByUserId(currentUserId); // todo 没有用户信息
|
experimentInfo.setUpdateTime(date);
|
ExperimentInfo deleteExperiment = repository.save(experimentInfo);
|
if(!ObjectUtils.isEmpty(deleteExperiment)){
|
flag = true;
|
}
|
return flag;
|
}
|
@Override
|
public ExperimentInfoDTO getExperimentById(Long id) {
|
if(ObjectUtils.isEmpty(id)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验主键不可为空!");
|
}
|
//获取该条实现信息
|
ExperimentInfo experimentInfo = repository.getExperimentInfoById(id);
|
if(ObjectUtils.isEmpty(experimentInfo)){ //todo 暂时抛出100
|
throw new BusinessException(this.getClass(), ResultCode.OK.getCode(),"实验信息不存在或已被删除");
|
}
|
return converter.getExperimentInfoDTO(experimentInfo);
|
}
|
@Override
|
public ExperimentInfoDTO getExperimentByName(String experimentName) {
|
if(StringUtil.isBlank(experimentName)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验名称不可为空!");
|
}
|
//获取该条实现信息
|
ExperimentInfo experimentInfo = repository.getExperimentInfoByName(experimentName);
|
if(ObjectUtils.isEmpty(experimentInfo)){ //todo 暂时抛出100
|
throw new BusinessException(this.getClass(), ResultCode.OK.getCode(),"实验信息不存在或已被删除");
|
}
|
return converter.getExperimentInfoDTO(experimentInfo);
|
}
|
|
@Override
|
public List<ExperimentInfoDTO> getExperimentInfoByIds(List<Long> idList) {
|
if (CollectionUtils.isEmpty(idList)) {
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "该实验信息主键不可为空!");
|
}
|
List<ExperimentInfo> experimentInfoByIdList = repository.getExperimentInfoByIds(idList);
|
|
return converter.getExperimentInfoDTOSimpleList(experimentInfoByIdList);
|
}
|
|
@Override
|
public boolean updateDevelop(Long currentUserId, List<ExperimentDevelopUpdateBO> developUpdateBOList) {
|
boolean flag = false;
|
if (CollectionUtils.isEmpty(developUpdateBOList)) {
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请选择需要开展实验信息!");
|
}
|
List<Long> idList = developUpdateBOList.stream().map(ExperimentDevelopUpdateBO::getId).collect(Collectors.toList());
|
//获取实验信息
|
List<ExperimentInfo> experimentInfoByIdList = repository.getExperimentInfoByIds(idList);
|
List<ExperimentInfo> updateExoerimentInfoList = new ArrayList<>();
|
for(ExperimentDevelopUpdateBO experimentDevelopUpdateBO:developUpdateBOList){
|
if(ObjectUtils.isEmpty(experimentDevelopUpdateBO.getSisStatus())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请选择是否是安全信息系统!");
|
}
|
if(ObjectUtils.isEmpty(SafeInformationSystemEnum.prase(experimentDevelopUpdateBO.getSisStatus()))){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(), "安全信息系统数据校验错误!");
|
}
|
if(SafeInformationSystemEnum.YES.getValue().equals(experimentDevelopUpdateBO.getSisStatus()) && ObjectUtils.isEmpty(experimentDevelopUpdateBO.getSafeInformationSystem())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请填写安全信息系统名称!");
|
}
|
if(ObjectUtils.isEmpty(experimentDevelopUpdateBO.getStartTime())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "请填写请实验开展时间!");
|
}
|
List<ExperimentInfo> selectList = experimentInfoByIdList.stream().filter(experimentInfo -> experimentInfo.getId().equals(experimentDevelopUpdateBO.getId())).collect(Collectors.toList());
|
if(selectList.size() == 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(), "实验信息不存在或已删除!");
|
}
|
ExperimentInfo experimentInfo = selectList.get(0);
|
if(experimentInfo.getExperimentTag().equals(ExperimentTagEnum.AREADLY_DEVELOP.getValue())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "实验已开展不可再次开展!");
|
}
|
experimentInfo.setExperimentTag(ExperimentTagEnum.AREADLY_DEVELOP.getValue());
|
experimentInfo.setSisStatus(experimentDevelopUpdateBO.getSisStatus());
|
experimentInfo.setSafeInformationSystem(experimentDevelopUpdateBO.getSafeInformationSystem());
|
experimentInfo.setUpdateTime(LocalDateTime.now());
|
experimentInfo.setUpdateByUserId(currentUserId);
|
experimentInfo.setStartTime(experimentDevelopUpdateBO.getStartTime());
|
updateExoerimentInfoList.add(experimentInfo);
|
}
|
List<ExperimentInfo> experimentInfos = repository.saveAll(updateExoerimentInfoList);
|
if (!CollectionUtils.isEmpty(experimentInfos)) {
|
flag = true;
|
}
|
return flag;
|
}
|
|
@Override
|
public boolean applyEvaluation(Long currentUserId, List<Long> ids) {
|
boolean flag = false;
|
if(CollectionUtils.isEmpty(ids)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "实验信息主键不可为空!");
|
}
|
//获取实验信息
|
List<ExperimentInfo> experimentInfoByIdList = repository.getExperimentInfoByIds(ids);
|
List<ExperimentInfo> updateExperimentInfoList = new ArrayList<>();
|
for(Long id:ids){
|
List<ExperimentInfo> selectList = experimentInfoByIdList.stream().filter(experimentInfo -> experimentInfo.getId().equals(id)).collect(Collectors.toList());
|
if(selectList.size() == 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(), "实验信息不存在或已删除!");
|
}
|
ExperimentInfo experimentInfo = selectList.get(0);
|
if(experimentInfo.getStatus().equals(ExperimentStatusEnum.YES_APPLY.getValue())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "实验已申请评估不可再次申请!");
|
}
|
experimentInfo.setStatus(ExperimentStatusEnum.YES_APPLY.getValue());
|
experimentInfo.setAssessApplyTime(LocalDateTime.now());
|
experimentInfo.setUpdateTime(LocalDateTime.now());
|
experimentInfo.setUpdateByUserId(currentUserId);
|
updateExperimentInfoList.add(experimentInfo);
|
}
|
List<ExperimentInfo> experimentInfos = repository.saveAll(updateExperimentInfoList);
|
if(!CollectionUtils.isEmpty(experimentInfos)){
|
flag = true;
|
}
|
|
|
|
return flag;
|
}
|
|
/**
|
* 修改申请评估状态
|
* @param currentUserId
|
* @param ids
|
* @return
|
*/
|
@Override
|
public boolean revokeApplyEvaluation(Long currentUserId, List<Long> ids) {
|
boolean flag = false;
|
if(CollectionUtils.isEmpty(ids)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "实验信息主键不可为空!");
|
}
|
//获取实验信息
|
List<ExperimentInfo> experimentInfoByIdList = repository.getExperimentInfoByIds(ids);
|
List<ExperimentInfo> updateExperimentInfoList = new ArrayList<>();
|
for(Long id:ids){
|
List<ExperimentInfo> selectList = experimentInfoByIdList.stream().filter(experimentInfo -> experimentInfo.getId().equals(id)).collect(Collectors.toList());
|
if(selectList.size() == 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(), "实验信息不存在或已删除!");
|
}
|
ExperimentInfo experimentInfo = selectList.get(0);
|
if(experimentInfo.getStatus().equals(ExperimentStatusEnum.NOT_APPLY.getValue()) || !experimentInfo.getStage().equals(ExperimentStageEnum.NOT_EVALUATION.getValue())){
|
//未申请评估或者评估中评估完成
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "实验未申请评估,评估中,评估完成,不可执行撤销操作!");
|
}
|
experimentInfo.setStatus(ExperimentStatusEnum.NOT_APPLY.getValue());
|
experimentInfo.setUpdateTime(LocalDateTime.now());
|
experimentInfo.setUpdateByUserId(currentUserId);
|
updateExperimentInfoList.add(experimentInfo);
|
}
|
List<ExperimentInfo> experimentInfos = repository.saveAll(updateExperimentInfoList);
|
if(!CollectionUtils.isEmpty(experimentInfos)){
|
flag = true;
|
}
|
return flag;
|
}
|
|
@Override
|
public List<ExperimentInfoDTO> getExperimentInfoList(Long currentUserId) {
|
return converter.getExperimentInfoDTOSimpleList(repository.getExperimentInfoList(currentUserId));
|
}
|
|
@Override
|
public boolean updateRectify(Long experimentId) {
|
if(ObjectUtils.isEmpty(experimentId)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "实验信息主键不可为空!");
|
}
|
ExperimentInfo experimentInfo = repository.getExperimentInfoById(experimentId);
|
if (ObjectUtils.isEmpty(experimentInfo)) {
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(), "实验信息不存在或已删除!");
|
}
|
if (!experimentInfo.getRectifyStatus().equals(ExperimentRectifyStatusEnum.WAIT_RECTIFY.getValue())) {
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode(), "非待整改实验,不可申请整改!");
|
}
|
experimentInfo.setRectifyStatus(ExperimentRectifyStatusEnum.YES_RECTIFY.getValue());
|
ExperimentInfo save = repository.save(experimentInfo);
|
if(ObjectUtils.isEmpty(save)){
|
return false;
|
}
|
return true;
|
|
}
|
|
@Override
|
public SearchResult<List<ExperimentInfoDTO>> listByPage(PageQuery<ExperimentInfoQueryBO> pageQuery,Long currentUserId) {
|
SearchResult searchResult = new SearchResult<>();
|
searchResult.setPageIndex(pageQuery.getPageIndex());
|
searchResult.setPageSize(pageQuery.getPageSize());
|
ExperimentInfoQueryBO queryBO = pageQuery.getSearchParams();
|
UserInfoDomainDTO user = userDomainService.getUserById(currentUserId);
|
int roleTag = GetRoleTagUtils.GetRoleTagUtils(user);
|
|
// TODO: 2023/11/10
|
List<ReportRiskAssessInfo> byLevel = reportRiskAssessInfoRepository.getByLevel(queryBO.getAssessLevel());
|
List<Long> ids = new ArrayList<>();
|
for (ReportRiskAssessInfo reportRiskAssessInfo : byLevel) {
|
ids.add(reportRiskAssessInfo.getExperimentId());
|
}
|
|
Specification<ExperimentInfo> specification = new Specification<ExperimentInfo>() {
|
@Override
|
public Predicate toPredicate(Root<ExperimentInfo> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
List<Predicate> predicateList = new ArrayList<>();
|
predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode()));
|
if(!ObjectUtils.isEmpty(ExperimentStatusEnum.prase(queryBO.getStatus()))){
|
predicateList.add(criteriaBuilder.equal(root.get("status"),queryBO.getStatus()));
|
}
|
if(!ObjectUtils.isEmpty(ExperimentTagEnum.prase(queryBO.getExperimentTag()))){
|
predicateList.add(criteriaBuilder.equal(root.get("experimentTag"),queryBO.getExperimentTag()));
|
}
|
if (!ObjectUtils.isEmpty(ExperimentTypeEnum.prase(queryBO.getExperimentType()))){
|
predicateList.add(criteriaBuilder.equal(root.get("experimentType"), queryBO.getExperimentType()));
|
}
|
if (StrUtil.isNotBlank(queryBO.getExperimentName())){
|
predicateList.add(criteriaBuilder.like(root.get("experimentName"), '%'+ queryBO.getExperimentName()+'%'));
|
}
|
if (!ObjectUtils.isEmpty(queryBO.getStartTime())){
|
predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createTime"), queryBO.getStartTime()));
|
}
|
if (!ObjectUtils.isEmpty(queryBO.getEndTime())){
|
predicateList.add(criteriaBuilder.lessThanOrEqualTo(root.get("createTime"), queryBO.getEndTime()));
|
}
|
if (!ObjectUtils.isEmpty(queryBO.getAssessLevel())){
|
predicateList.add(criteriaBuilder.in(root.get("id")).value(ids));
|
}
|
if(roleTag == UserTagEnum.USER_TAG_0.getCode()){
|
Join<ExperimentInfo, RiskAssessPlan> experimentJion = root.join("riskAssessPlans", JoinType.LEFT);
|
predicateList.add(criteriaBuilder.or(
|
criteriaBuilder.equal(root.get("liabilityUserId"), currentUserId),
|
criteriaBuilder.equal(experimentJion.get("identificationUserId"), currentUserId),
|
criteriaBuilder.equal(experimentJion.get("evaluateUserId"), currentUserId))
|
);
|
query.groupBy(root.get("id"));
|
}
|
|
//返回组装的条件
|
return criteriaBuilder.and(predicateList.toArray(predicateList.toArray(new Predicate[0])));
|
}
|
};
|
Pageable pageable = PageRequest.of(pageQuery.getPageIndex()-1, pageQuery.getPageSize(), Sort.Direction.DESC, "createTime");
|
Page<ExperimentInfo> pageResult = repository.findAll(specification, pageable);
|
|
List<ExperimentInfoDTO> experimentInfoDTODetailList = converter.getExperimentInfoDTODetailList(pageResult.getContent());
|
for (ExperimentInfoDTO experimentInfoDTO : experimentInfoDTODetailList) {
|
ReportRiskAssessInfo report = reportRiskAssessInfoRepository.getByExperimentId(experimentInfoDTO.getId());
|
if (!ObjectUtils.isEmpty(report) && report.getCreateTime().isBefore(report.getUpdateTime())){
|
experimentInfoDTO.setAssessPerson(report.getAssessPerson());
|
}
|
}
|
|
searchResult.setTotal(pageResult.getTotalElements());
|
searchResult.setPages(pageResult.getTotalPages());
|
searchResult.setData(experimentInfoDTODetailList);
|
return searchResult;
|
}
|
|
|
/**
|
* 生成实验编号
|
*/
|
private String generateTestNumber(){
|
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd" );
|
SimpleDateFormat sdf2 =new SimpleDateFormat("yyyyMMdd" );
|
String time = sdf.format(new Date());
|
//获取当天新立项数量
|
Integer count = repository.countByCreateTime(time);
|
|
String serialCode = null;
|
if(count >= 1000){
|
serialCode = "" + (count+1);
|
}else if(count >=0){
|
String countStr = String.valueOf(count+1);
|
serialCode = "000".substring(0,(3- countStr.length()))+countStr;
|
}
|
return sdf2.format(new Date()) + serialCode;
|
}
|
|
/**
|
* 实验信息 - 修改实验状态
|
*/
|
@Override
|
public ExperimentInfoDTO updateExperimentStage(Long id, Byte stage) {
|
|
// ExperimentInfo experimentInfo = repository.updateExperimentStage(id, StatusEnum.EXPERIMENT_STATUS_FINISH.getCode());
|
ExperimentInfo experimentInfoById = repository.getExperimentInfoById(id);
|
|
experimentInfoById.setStage(stage);
|
|
ExperimentInfo experimentInfo = repository.save(experimentInfoById);
|
|
if (ObjectUtils.isEmpty(experimentInfo)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "实验评估状态修改失败");
|
}
|
|
return BeanCopyUtils.copyBean(experimentInfo, ExperimentInfoDTO.class);
|
}
|
|
@Override
|
public List<ExperimentInfoDTO> getExperimentByUser(Long currentUserId) {
|
|
List<ExperimentInfo> experimentList = repository.getExperimentByUser(currentUserId);
|
if (ObjectUtils.isEmpty(experimentList)){
|
List<ExperimentInfoDTO> experiment = new ArrayList<>();
|
return experiment;
|
}
|
return BeanCopyUtils.copyBeanList(experimentList, ExperimentInfoDTO.class);
|
}
|
|
@Override
|
public ExperimentInfo updateExperimentStatus(UpdateExperimentInfoBO updateBO) {
|
|
ExperimentInfo experimentInfoById = repository.getExperimentInfoById(updateBO.getExperimentId());
|
if (ObjectUtils.isEmpty(experimentInfoById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "实验不存在");
|
}
|
|
experimentInfoById.setApprovalStatus(updateBO.getApprovalStatus());
|
if (updateBO.getRectifyStatus() == ExperimentRectifyStatusEnum.WAIT_RECTIFY.getValue()){
|
experimentInfoById.setRectifyStatus(updateBO.getRectifyStatus());
|
}
|
return repository.save(experimentInfoById);
|
}
|
}
|