heheng
3 天以前 f33cfe86447c16df8ca665e2e1a5f3333ff57792
expert-system/src/main/java/com/gkhy/system/service/impl/ProjectManagementServiceImpl.java
@@ -2,6 +2,8 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.common.enums.DeleteFlagEnum;
import com.gkhy.common.exception.ServiceException;
@@ -19,6 +21,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -46,6 +49,12 @@
    private IProjectFileService projectFileService;
    @Autowired
    private SysExpertInfoMapper sysExpertInfoMapper;
    @Autowired
    private OutProjectExpertMapper outProjectExpertMapper;
    @Autowired
    private OutProjectExpertDetailMapper outProjectExpertDetailMapper;
    /**
     * 查询项目管理
@@ -126,42 +135,120 @@
            throw new ServiceException("该步骤不可操作专家数据!");
        }
        //outExpertInfoMapper
        List<ProjectExpertSaveReqDto> saveData = projectManagement.getSaveData();
        if (!StringUtils.isNotEmpty(saveData)){
        List<OutProjectExpert> saveOutData = projectManagement.getSaveOutData();
        if (ObjectUtil.isEmpty(saveData) && ObjectUtil.isEmpty(saveOutData)) {
            throw new ServiceException("专家不可为空!");
        }
        //专家库校验重复
        if (ObjectUtil.isNotEmpty(saveData)) {
        if (hasDuplicateExpertId(saveData)){
            throw new ServiceException("专家重复!");
        }
//        long count = saveData.stream()
//                .filter(dto -> dto.getSelectionMode() == 1)
//                .count();
//        if (count < 1){
//            throw new ServiceException("固定专家不能为空!");
//        }
        }
        if (ObjectUtil.isNotEmpty(saveOutData)){
            List<OutProjectExpert> uniqueList = saveOutData.stream()
                    .collect(Collectors.collectingAndThen(
                            Collectors.toMap(OutProjectExpert::getIdCard, o -> o, (existing, replacement) -> existing, LinkedHashMap::new),
                            map -> new ArrayList<>(map.values())
                    ));
            if (uniqueList.size() != saveOutData.size()){
                throw new ServiceException("外部专家身份证重复!");
            }
        }
        boolean flag = false;
        if ((projectManagement1.getStep() == 1 || projectManagement1.getStep() == 2) && (projectManagement.getStep() == 2  ) ){
            projectManagementSave.setStep(2L);
            projectManagementSave.setState(1L);
            List<ProjectExpertSaveReqDto> collect = saveData.stream()
            List<ProjectExpertSaveReqDto> collect = new ArrayList<>();
            List<OutProjectExpert> saveOutDataSp = new ArrayList<>();
            List<OutProjectExpert> saveOutDataSp11 = new ArrayList<>();
            if (ObjectUtil.isNotEmpty(saveData)) {
                 collect = saveData.stream()
                    .filter(dto -> "1".equals(dto.getTeamLeader().toString()))
                    .collect(Collectors.toList());
            if (StringUtils.isEmpty(collect)){
            }
            if (ObjectUtil.isNotEmpty(saveOutData)) {
                 saveOutDataSp = saveOutData.stream()
                        .filter(dto -> "1".equals(dto.getTeamLeader().toString()))
                        .collect(Collectors.toList());
                saveOutDataSp11 = saveOutData.stream()
                        .filter(dto -> "0".equals(dto.getTeamLeader().toString()))
                        .collect(Collectors.toList());
            }
            if (StringUtils.isEmpty(collect) && StringUtils.isEmpty(saveOutDataSp)) {
                throw new ServiceException("缺少组长!");
            }
            if (collect.size() > 1){
            if (collect.size()+saveOutDataSp.size() > 1) {
                throw new ServiceException("组长只能选一人!");
            }
            if (ObjectUtil.isNotEmpty( collect)){
            projectManagementSave.setExpertName(collect.get(0).getExpertName());
            projectManagementSave.setExpertId(collect.get(0).getExpertId());
                projectManagementSave.setExpertType(1L);
            }else {
                OutProjectExpert outExpertInfo = saveOutDataSp.get(0);
                flag = true;
                if (outExpertInfo.getId() != null){
                    outExpertInfo.setUpdateTime(LocalDateTime.now());
                    outExpertInfo.setUpdateBy(SecurityUtils.getUsername());
                    int update = outProjectExpertMapper.updateById(outExpertInfo);
                    if (update < 1) {
                        throw new ServiceException("保存专家失败!");
                    }
                }else {
                    outExpertInfo.setProjectId(projectManagement.getId());
                    int insert = outProjectExpertMapper.insert(outExpertInfo);
                    if (insert < 1) {
                        throw new ServiceException("保存专家失败!");
                    }
                }
                projectManagementSave.setExpertName(saveOutDataSp.get(0).getName());
                projectManagementSave.setExpertId(saveOutDataSp.get(0).getId());
                projectManagementSave.setExpertType(2L);
                if (ObjectUtil.isNotEmpty(saveOutDataSp11)){
                    flag = true;
                    saveOutDataSp11.forEach(
                            outExpertInfo1 -> {
                                if (outExpertInfo1.getId() != null){
                                    outExpertInfo1.setUpdateTime(LocalDateTime.now());
                                    outExpertInfo1.setUpdateBy(SecurityUtils.getUsername());
                                    int insert2 = outProjectExpertMapper.updateById(outExpertInfo1);
                                    if (insert2 < 1) {
                                        throw new ServiceException("保存专家失败!");
                                    }
                                }else {
                                    outExpertInfo1.setProjectId(projectManagement.getId());
                                    outExpertInfo1.setCreateTime(LocalDateTime.now());
                                    outExpertInfo1.setCreateBy(SecurityUtils.getUsername());
                                    int insert2 = outProjectExpertMapper.insert(outExpertInfo1);
                                    if (insert2 < 1) {
                                        throw new ServiceException("保存专家失败!");
                                    }
                                }
                            }
                    );
                }
            }
        }else if (projectManagement1.getStep() == 2 && projectManagement.getStep() == 3){
            projectManagementSave.setStep(2L);
            projectManagementSave.setState(2L);
            projectManagementSave.setProjectCheckTime(new Date());
        }
        if (ObjectUtil.isNotEmpty(saveData)){
        List<ProjectExpertSaveReqDto> saveList = saveData.stream()
                .filter(dto -> dto.getId() == null)
                .collect(Collectors.toList());
@@ -182,7 +269,42 @@
                throw new ServiceException("保存专家失败!");
            }
        }
        projectManagementSave.setExpertNum((long) saveData.size());
        }
        if (!flag){
            if (ObjectUtil.isNotEmpty(saveOutData)){
                saveOutData.forEach(
                        outExpertInfo1 -> {
                            if (outExpertInfo1.getId() != null){
                                outExpertInfo1.setUpdateTime(LocalDateTime.now());
                                outExpertInfo1.setUpdateBy(SecurityUtils.getUsername());
                                int insert2 = outProjectExpertMapper.updateById(outExpertInfo1);
                                if (insert2 < 1) {
                                    throw new ServiceException("保存专家失败!");
                                }
                            }else {
                                outExpertInfo1.setProjectId(projectManagement.getId());
                                outExpertInfo1.setCreateTime(LocalDateTime.now());
                                outExpertInfo1.setCreateBy(SecurityUtils.getUsername());
                                int insert2 = outProjectExpertMapper.insert(outExpertInfo1);
                                if (insert2 < 1) {
                                    throw new ServiceException("保存专家失败!");
                                }
                            }
                        }
                );
            }
        }
//        int outData = 0;
//        if(!ObjectUtil.isEmpty(saveOutData)){
//            outData = saveOutData.size();
//        }
//        int inData = 0;
//        if (!ObjectUtil.isEmpty(saveData)){
//            inData = saveData.size();
//        }
        List<Long> delData = projectManagement.getDelData();
        if (delData != null && delData.size() > 0) {
            int i = projectExpertMapper.deleteProjectExpertByIds(delData.toArray(new Long[delData.size()]));
@@ -190,6 +312,21 @@
                throw new ServiceException("保存专家失败!");
            }
        }
        List<Long> delOutData = projectManagement.getDelOutData();
        if (ObjectUtil.isNotEmpty(delOutData)){
            // 删除外部专家数据
            int update = outProjectExpertMapper.update(new OutProjectExpert(),
                    new LambdaUpdateWrapper<OutProjectExpert>().set(OutProjectExpert::getDelFlag, 1)
                            .set(OutProjectExpert::getUpdateTime, new Date()).set(OutProjectExpert::getUpdateBy, SecurityUtils.getUsername())
                            .in(OutProjectExpert::getId, delOutData));
            if (update < 1) {
                throw new ServiceException("保存外部专家失败!");
            }
        }
        Long l = outProjectExpertMapper.selectCount(new LambdaQueryWrapper<OutProjectExpert>().eq(OutProjectExpert::getDelFlag, 0).eq(OutProjectExpert::getProjectId, projectManagement.getId()));
        Long l1 = projectExpertMapper.selectCount(new LambdaQueryWrapper<ProjectExpert>().eq(ProjectExpert::getDelFlag, 0).eq(ProjectExpert::getProjectId, projectManagement.getId()));
        projectManagementSave.setExpertNum(l+l1);
        int i = projectManagementMapper.updateProjectManagement(projectManagementSave);
        if (i < 1){
            throw new ServiceException("保存专家失败!");
@@ -220,7 +357,6 @@
        }
        return projectExpert;
    }
    public  boolean hasDuplicateExpertId(List<ProjectExpertSaveReqDto> saveData) {
@@ -263,7 +399,20 @@
    @Override
    public ProjectExpertManagementInfoRes projectExpertCheckInfo(Long id) {
        return projectManagementMapper.projectExpertCheckInfo(id);
        // 查询
        ProjectExpertManagementInfoRes projectExpertManagementInfoRes = projectManagementMapper.projectExpertCheckInfo(id);
        List<ProjectExpertCheckResp> projectExpertCheckResps = projectExpertManagementInfoRes.getProjectExpertCheckResp();
        if (ObjectUtil.isNotEmpty(projectExpertCheckResps)){
            projectExpertCheckResps.forEach(projectExpertCheckResp -> {
                projectExpertCheckResp.setSelectionTime(projectExpertManagementInfoRes.getCreateTime());
            });
            projectExpertCheckResps.sort(Comparator
                    .comparing(ProjectExpertCheckResp::getTeamLeader, Comparator.nullsLast(Comparator.reverseOrder()))
                    .thenComparing(ProjectExpertCheckResp::getExpertType, Comparator.nullsLast(Comparator.naturalOrder())));
        }
        return projectExpertManagementInfoRes;
    }
    @Override
@@ -315,6 +464,30 @@
    }
    @Override
    public void projectBuildCheck(ProjectExpertSaveBatchReqDto projectManagement) {
        ProjectManagement projectManagement1 = checkDataPer(projectManagement.getId());
        //专家选取
        ProjectManagement projectManagementSave = new ProjectManagement();
        projectManagementSave.setUpdateBy(SecurityUtils.getUsername());
        projectManagementSave.setUpdateTime(DateUtils.getNowDate());
        projectManagementSave.setId(projectManagement.getId());
        if (projectManagement1.getStep() == 2 && projectManagement.getStep() == 3) {
            projectManagementSave.setStep(2L);
            projectManagementSave.setState(2L);
            projectManagementSave.setProjectCheckTime(new Date());
        }else {
            throw new ServiceException("该步骤无法生成审批单!");
        }
        int i = projectManagementMapper.updateProjectManagement(projectManagementSave);
        if (i<0){
            throw new ServiceException("生成审批单失败!");
        }
    }
    @Override
    public void projectArchive(ProjectArchiveReq req) {
        ProjectManagement projectManagement = checkDataPer(req.getId());
@@ -360,19 +533,24 @@
    @Override
    public List<ProjectExpertEvaluationResp> projectExpertEvaluationList(Long projectId) {
        return projectExpertMapper.projectExpertEvaluationList(projectId);
        List<ProjectExpertEvaluationResp> projectExpertEvaluationResps = projectExpertMapper.projectExpertEvaluationList(projectId);
        projectExpertEvaluationResps.sort(Comparator
                    .comparing(ProjectExpertCheckResp::getTeamLeader, Comparator.nullsLast(Comparator.reverseOrder()))
                    .thenComparing(ProjectExpertCheckResp::getSelectionMode, Comparator.nullsLast(Comparator.reverseOrder()))
                    .thenComparing(ProjectExpertCheckResp::getExpertType, Comparator.nullsLast(Comparator.naturalOrder())));
        return projectExpertEvaluationResps;
    }
    @Override
    @Transactional
    public void projectExpertDetailSave(ProjectExpertScoreSaveReq req) {
        Long projectId = null;
        Long expertType = req.getExpertType();
        List<Long> delData = req.getDelData();
        if (StringUtils.isNotEmpty(delData)){
            projectExpertDetailMapper.deleteProjectExpertDetailByIds(delData.toArray(new Long[delData.size()]));
        }
        List<ProjectExpertScoreSaveReq.Score> saveData = req.getSaveData();
        if (expertType == 1) {
        ProjectExpert projectExpert1 = projectExpertMapper.selectProjectExpertById(req.getProjectExpertId());
        if (projectExpert1 == null){
            throw new ServiceException("项目专家不存在!");
@@ -381,7 +559,11 @@
        if (projectManagement1.getState() != 4){
            throw new ServiceException("项目未完成!");
        }
            projectId = projectExpert1.getProjectId();
            if (StringUtils.isNotEmpty(delData)) {
                projectExpertDetailMapper.deleteProjectExpertDetailByIds(delData.toArray(new Long[delData.size()]));
            }
        //更新项目专家表
        ProjectExpert projectExpert = new ProjectExpert();
        BeanUtil.copyProperties(req, projectExpert);
@@ -392,8 +574,6 @@
        if (i < 1){
            throw new ServiceException("保存失败!");
        }
        List<ProjectExpertScoreSaveReq.Score> saveData = req.getSaveData();
        if (StringUtils.isNotEmpty(saveData)){
            List<ProjectExpertDetail> projectExpertDetails = dealData(saveData, req.getProjectExpertId());
@@ -417,11 +597,51 @@
            }
        }
        }else {
            OutProjectExpert outProjectExpert1 = outProjectExpertMapper.selectById(req.getProjectExpertId());
            if (outProjectExpert1 == null) {
                throw new ServiceException("项目专家不存在!");
            }
            ProjectManagement projectManagement1 = checkData(outProjectExpert1.getProjectId());
            if (projectManagement1.getState() != 4) {
                throw new ServiceException("项目未完成!");
            }
            projectId = outProjectExpert1.getProjectId();
            if (StringUtils.isNotEmpty(delData)){
                outProjectExpertDetailMapper.update(new OutProjectExpertDetail(),
                        new LambdaUpdateWrapper<OutProjectExpertDetail>().in(OutProjectExpertDetail::getId, delData)
                                .set(OutProjectExpertDetail::getDelFlag, 1).set(OutProjectExpertDetail::getUpdateBy, SecurityUtils.getUsername())
                                .set(OutProjectExpertDetail::getUpdateTime, new Date()));
            }
            OutProjectExpert outProjectExpert = new OutProjectExpert();
            BeanUtil.copyProperties(req, outProjectExpert);
            outProjectExpert.setId(req.getProjectExpertId());
            outProjectExpert.setScore(req.getScore().intValue());
            outProjectExpert.setEvaluationState(1);
            int update = outProjectExpertMapper.updateById(outProjectExpert);
            if (update < 1) {
                throw new ServiceException("保存失败!");
            }
            if (StringUtils.isNotEmpty(saveData)) {
                List<OutProjectExpertDetail> outProjectExpertDetails = dealOutData(saveData, req.getProjectExpertId());
                outProjectExpertDetails.forEach(outProjectExpertDetail -> {
                    if (outProjectExpertDetail.getId() == null){
                        outProjectExpertDetailMapper.insert(outProjectExpertDetail);
                    }else {
                        outProjectExpertDetailMapper.updateById(outProjectExpertDetail);
                    }
                });
            }
        }
        //验证是否都已考评
        int unEva = projectExpertMapper.getUnEva(projectExpert1.getProjectId());
        if (unEva == 0){
        int unEva = projectExpertMapper.getUnEva(projectId);
        Long l = outProjectExpertMapper.selectCount(new LambdaQueryWrapper<OutProjectExpert>().eq(OutProjectExpert::getProjectId, projectId)
                .eq(OutProjectExpert::getDelFlag, 0).eq(OutProjectExpert::getEvaluationState, 0));
        if (unEva+l == 0) {
            ProjectManagement projectManagement = new ProjectManagement();
            projectManagement.setId(projectExpert1.getProjectId());
            projectManagement.setId(projectId);
            projectManagement.setEvaluationState(1L);
            projectManagement.setUpdateBy(SecurityUtils.getUsername());
            int i1 = projectManagementMapper.updateProjectManagement(projectManagement);
@@ -437,7 +657,14 @@
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            req.setDeptId(SecurityUtils.getDeptId());
        }
        return projectExpertMapper.projectExpertEvaList(req);
//        if (req.getExpertType() == 1){
//            return projectExpertMapper.projectExpertEvaList(req);
//        }else {
//            return projectExpertMapper.projectExpertEvaOutList(req);
//        }
    }
    @Override
@@ -480,8 +707,9 @@
    }
    @Override
    public ProjectDetailResp selectProjectExpertDetail(Long projectExpertId) {
    public ProjectDetailResp selectProjectExpertDetail(Long projectExpertId,Long expertType) {
        ProjectDetailResp projectDetailResp = new ProjectDetailResp();
        if (expertType == 1){
        ProjectExpert projectExpert = projectExpertMapper.selectProjectExpertById(projectExpertId);
        BeanUtil.copyProperties(projectExpert, projectDetailResp);
        if (projectDetailResp != null){
@@ -508,6 +736,39 @@
            }
        }
        }else if (expertType == 2){
            OutProjectExpert outProjectExpert = outProjectExpertMapper.selectById(projectExpertId);
            BeanUtil.copyProperties(outProjectExpert, projectDetailResp);
            if (projectDetailResp != null) {
                LambdaQueryWrapper<OutProjectExpertDetail> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(OutProjectExpertDetail::getOutProjectExpertId, projectExpertId);
                List<OutProjectExpertDetail> outProjectExpertDetails = outProjectExpertDetailMapper.selectList(queryWrapper);
                if (StringUtils.isNotEmpty(outProjectExpertDetails)) {
                    List<ProjectExpertDetail> projectExpertDetails = new ArrayList<>();
                    outProjectExpertDetails.forEach(outProjectExpertDetail -> {
                        ProjectExpertDetail projectExpertDetail = new ProjectExpertDetail();
                        BeanUtil.copyProperties(outProjectExpertDetail, projectExpertDetail);
                        projectExpertDetails.add(projectExpertDetail);
                    });
                    projectDetailResp.setExpertDetails(projectExpertDetails);
                }
                Long projectId = projectDetailResp.getProjectId();
                ProjectManagement projectManagement = projectManagementMapper.selectProjectManagementById(projectId);
                projectDetailResp.setDeptId(projectManagement.getDeptId());
                projectDetailResp.setDeptName(projectDetailResp.getDeptName());
                projectDetailResp.setProjectName(projectManagement.getProjectName());
                projectDetailResp.setProjectDateStart(projectManagement.getProjectDateStart());
                projectDetailResp.setProjectDateEnd(projectManagement.getProjectDateEnd());
                if (StringUtils.isNotEmpty(projectManagement.getJobCategory())) {
                    projectDetailResp.setJobCategory(projectManagement.getJobCategory());
                }
            }
        }
        return projectDetailResp;
    }
@@ -554,6 +815,27 @@
    }
    private List<OutProjectExpertDetail> dealOutData(List<ProjectExpertScoreSaveReq.Score> data, Long projectExpertId) {
        List<OutProjectExpertDetail> dealData = new ArrayList<>();
        data.forEach(dto -> {
            OutProjectExpertDetail projectExpertDetail = new OutProjectExpertDetail();
            projectExpertDetail.setOutProjectExpertId(projectExpertId);
            projectExpertDetail.setContent(dto.getContent());
            projectExpertDetail.setScore(dto.getScore().intValue());
            projectExpertDetail.setScoreType(dto.getScoreType());
            if (dto.getId() == null) {
                projectExpertDetail.setCreateBy(SecurityUtils.getUsername());
            } else {
                projectExpertDetail.setId(dto.getId());
                projectExpertDetail.setUpdateBy(SecurityUtils.getUsername());
            }
            dealData.add(projectExpertDetail);
        });
        return dealData;
    }
    public ProjectManagement checkData(Long id){
        ProjectManagement projectManagement = projectManagementMapper.selectProjectManagementById(id);
        if (ObjectUtil.isNull(projectManagement)){
@@ -584,7 +866,6 @@
            throw new ServiceException("非本处室数据,无权操作!");
        }
    }
}