heheng
2025-05-09 b72086c16e178ea31a865646aeb64bea210e48b7
src/main/java/com/gkhy/labRiskManage/domain/experiment/service/impl/ExperimentInfoServiceImpl.java
@@ -43,6 +43,7 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@@ -76,31 +77,32 @@
    @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(),"该账号无权限录入实验信息!");
        }
        // 20211105去掉权限验证
//        //验证权限
//        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.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(),"请选择实验负责人!");
        }
@@ -177,9 +179,10 @@
        }
        ExperimentInfo experimentInfo = new ExperimentInfo();
        BeanUtils.copyProperties(experimentAppInsertBO, experimentInfo);
        experimentInfo.setStagingTag(ExperimentStagingEnum.SAVE.getValue());
        experimentInfo.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        experimentInfo.setLiabilityUser(operator.getName());
        experimentInfo.setLiabilityUserId(currentUserId);
//        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());
@@ -193,33 +196,58 @@
        return converter.getExperimentInfoDTO(experiment);
    }
    @Override
    public ExperimentInfoDTO temporary(Long currentUserId, ExperimentAppInsertBO experimentAppInsertBO) {
        UserInfoDomainDTO operator = userDomainService.getUserInfoById(currentUserId);
        ExperimentInfo experimentInfo = new ExperimentInfo();
        BeanUtils.copyProperties(experimentAppInsertBO, experimentInfo);
        experimentInfo.setStagingTag(ExperimentStagingEnum.NOT_SAVE.getValue());
        experimentInfo.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        experimentInfo.setLiabilityUser(experimentAppInsertBO.getLiabilityUser());
        experimentInfo.setLiabilityUserId(experimentAppInsertBO.getLiabilityUserId());
        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(),"该账号无权限录入实验信息!");
        }
        // 20211105去掉权限验证
//        //验证权限
//        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.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(),"请填写实验负责人手机号!");
        }
@@ -304,9 +332,10 @@
        }
        ExperimentInfo experimentInfo = new ExperimentInfo();
        BeanUtils.copyProperties(experimentAppInsertBO, experimentInfo);
        experimentInfo.setStagingTag(ExperimentStagingEnum.SAVE.getValue());
        experimentInfo.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        experimentInfo.setLiabilityUserId(currentUserId);
        experimentInfo.setLiabilityUser(operator.getName());
//        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());
@@ -319,6 +348,32 @@
        ExperimentInfo experiment = repository.save(experimentInfo);
        return converter.getExperimentInfoDTO(experiment);
    }
    @Override
    public ExperimentInfoDTO developTemporary(Long currentUserId, ExperimentAppInsertBO experimentAppInsertBO) {
        UserInfoDomainDTO operator = userDomainService.getUserInfoById(currentUserId);
        ExperimentInfo experimentInfo = new ExperimentInfo();
        BeanUtils.copyProperties(experimentAppInsertBO, experimentInfo);
        experimentInfo.setStagingTag(ExperimentStagingEnum.NOT_SAVE.getValue());
        experimentInfo.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        experimentInfo.setLiabilityUserId(experimentAppInsertBO.getLiabilityUserId());
        experimentInfo.setLiabilityUser(experimentAppInsertBO.getLiabilityUser());
//        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
@@ -551,11 +606,14 @@
                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 (!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.getExperimentId())){
                    predicateList.add(criteriaBuilder.equal(root.get("id"), queryBO.getExperimentId()));
                }
                if (!ObjectUtils.isEmpty(queryBO.getStartTime())){
                    predicateList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createTime"), queryBO.getStartTime()));
@@ -566,14 +624,23 @@
                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"));
                if (ObjectUtils.isEmpty(queryBO.getExperimentId())){
                    if(roleTag == UserTagEnum.USER_TAG_0.getCode() || roleTag == UserTagEnum.USER_TAG_1.getCode()){
                        Join<ExperimentInfo, RiskAssessPlan> experimentJion = root.join("riskAssessPlans", JoinType.LEFT);
                        //criteriaBuilder.equal(root.get("liabilityUserId"), currentUserId),
                        predicateList.add(criteriaBuilder.or(
                                criteriaBuilder.equal(root.get("safeLiabilityUserId"), currentUserId),
                                criteriaBuilder.equal(experimentJion.get("identificationUserId"), currentUserId),
                                criteriaBuilder.equal(experimentJion.get("evaluateUserId"), currentUserId))
                        );
                        query.groupBy(root.get("id"));
                    }
                }
                if (!ObjectUtils.isEmpty(ExperimentTypeEnum.prase(queryBO.getExperimentType()))){
                    Join<ExperimentInfo, ExperimentAndType> typeJoin = root.join("types", JoinType.LEFT);
                    predicateList.add(criteriaBuilder.equal(typeJoin.get("typeId"), queryBO.getExperimentType()));
                }
                //返回组装的条件