From f33cfe86447c16df8ca665e2e1a5f3333ff57792 Mon Sep 17 00:00:00 2001
From: heheng <475597332@qq.com>
Date: 星期三, 27 八月 2025 17:02:27 +0800
Subject: [PATCH] 版本改造

---
 expert-system/src/main/java/com/gkhy/system/service/impl/ProjectManagementServiceImpl.java |  803 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 792 insertions(+), 11 deletions(-)

diff --git a/expert-system/src/main/java/com/gkhy/system/service/impl/ProjectManagementServiceImpl.java b/expert-system/src/main/java/com/gkhy/system/service/impl/ProjectManagementServiceImpl.java
index ddee76c..e17abc1 100644
--- a/expert-system/src/main/java/com/gkhy/system/service/impl/ProjectManagementServiceImpl.java
+++ b/expert-system/src/main/java/com/gkhy/system/service/impl/ProjectManagementServiceImpl.java
@@ -1,13 +1,29 @@
 package com.gkhy.system.service.impl;
 
+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 java.util.List;
-        import com.rchuing.common.utils.DateUtils;
+import com.gkhy.common.enums.DeleteFlagEnum;
+import com.gkhy.common.exception.ServiceException;
+import com.gkhy.common.utils.DateUtils;
+import com.gkhy.common.utils.SecurityUtils;
+import com.gkhy.common.utils.StringUtils;
+import com.gkhy.common.utils.uuid.RandomStringGenerator;
+import com.gkhy.system.domain.*;
+import com.gkhy.system.domain.vo.request.*;
+import com.gkhy.system.domain.vo.response.*;
+import com.gkhy.system.mapper.*;
+import com.gkhy.system.service.IProjectFileService;
+import com.gkhy.system.service.IProjectManagementService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.gkhy.system.mapper.ProjectManagementMapper;
-import com.gkhy.system.domain.ProjectManagement;
-import com.gkhy.system.service.IProjectManagementService;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 项目管理Service业务层处理
@@ -19,6 +35,26 @@
 public class ProjectManagementServiceImpl extends ServiceImpl<ProjectManagementMapper, ProjectManagement> implements IProjectManagementService {
     @Autowired
     private ProjectManagementMapper projectManagementMapper;
+
+    @Autowired
+    private ProjectExpertMapper projectExpertMapper;
+
+    @Autowired
+    private ProjectFileMapper projectFileMapper;
+
+    @Autowired
+    private ProjectExpertDetailMapper projectExpertDetailMapper;
+
+    @Autowired
+    private IProjectFileService projectFileService;
+    @Autowired
+    private SysExpertInfoMapper sysExpertInfoMapper;
+
+    @Autowired
+    private OutProjectExpertMapper outProjectExpertMapper;
+
+    @Autowired
+    private OutProjectExpertDetailMapper outProjectExpertDetailMapper;
 
     /**
      * 查询项目管理
@@ -39,6 +75,9 @@
      */
     @Override
     public List<ProjectManagement> selectProjectManagementList(ProjectManagement projectManagement) {
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && SecurityUtils.getUserId() != 130L) {
+            projectManagement.setDeptId(SecurityUtils.getDeptId());
+        }
         return projectManagementMapper.selectProjectManagementList(projectManagement);
     }
 
@@ -49,9 +88,31 @@
      * @return 结果
      */
     @Override
-    public int insertProjectManagement(ProjectManagement projectManagement) {
-                projectManagement.setCreateTime(DateUtils.getNowDate());
-            return projectManagementMapper.insertProjectManagement(projectManagement);
+    public Long insertProjectManagement(ProjectManageSaveReq projectManagement) {
+        ProjectManagement projectManagementSave = new ProjectManagement();
+        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
+            throw new ServiceException("无权新增");
+        }
+        projectManagementSave.setDelFlag(DeleteFlagEnum.UN_DELETE.getCode());
+        BeanUtil.copyProperties(projectManagement, projectManagementSave);
+        if (projectManagement.getId() != null) {
+            checkDataPer(projectManagement.getId());
+
+            projectManagementSave.setUpdateBy(SecurityUtils.getUsername());
+            projectManagementSave.setUpdateTime(DateUtils.getNowDate());
+            // projectManagementMapper.updateProjectManagement(projectManagementSave);
+            updateById(projectManagementSave);
+        } else {
+            projectManagementSave.setProjectCode(RandomStringGenerator.generateRandomString(10));
+            projectManagementSave.setStep(1L);
+            projectManagementSave.setCreateBy(SecurityUtils.getUsername());
+            projectManagementSave.setCreateTime(DateUtils.getNowDate());
+            save(projectManagementSave);
+            //  projectManagementMapper.insertProjectManagement(projectManagementSave);
+        }
+
+
+        return projectManagementSave.getId();
     }
 
     /**
@@ -61,9 +122,250 @@
      * @return 结果
      */
     @Override
-    public int updateProjectManagement(ProjectManagement projectManagement) {
-                projectManagement.setUpdateTime(DateUtils.getNowDate());
-        return projectManagementMapper.updateProjectManagement(projectManagement);
+    @Transactional
+    public void updateProjectManagement(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.getState() != 1 && projectManagement1.getState() != 0) {
+            throw new ServiceException("该步骤不可操作专家数据!");
+        }
+
+        //outExpertInfoMapper
+        List<ProjectExpertSaveReqDto> saveData = projectManagement.getSaveData();
+        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("专家重复!");
+            }
+        }
+        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 = 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 (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()+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());
+            if (StringUtils.isNotEmpty(saveList)) {
+                List<ProjectExpert> projectExperts = convertToProjectExpertList(saveList, projectManagement.getId());
+                int i = projectExpertMapper.batchInsertProjectExpert(projectExperts);
+                if (i < 1) {
+                    throw new ServiceException("保存专家失败!");
+                }
+            }
+            List<ProjectExpertSaveReqDto> editList = saveData.stream()
+                    .filter(dto -> dto.getId() != null)
+                    .collect(Collectors.toList());
+            if (StringUtils.isNotEmpty(editList)) {
+                List<ProjectExpert> projectExperts = convertToProjectExpertList(editList, projectManagement.getId());
+                int i = projectExpertMapper.batchUpdateProjectExpert(projectExperts);
+                if (i < 1) {
+                    throw new ServiceException("保存专家失败!");
+                }
+            }
+        }
+        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()]));
+            if (i < 1) {
+                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("保存专家失败!");
+        }
+    }
+
+
+    public List<ProjectExpert> convertToProjectExpertList(List<ProjectExpertSaveReqDto> reqDtos, Long projectId) {
+        List<ProjectExpert> projectExpertList = new ArrayList<>();
+        reqDtos.forEach(reqDto -> {
+            ProjectExpert projectExpert = convertToProjectExpert(reqDto, projectId);
+            projectExpertList.add(projectExpert);
+        });
+        return projectExpertList;
+    }
+
+    private ProjectExpert convertToProjectExpert(ProjectExpertSaveReqDto reqDto, Long projectId) {
+        ProjectExpert projectExpert = new ProjectExpert();
+        projectExpert.setProjectId(projectId);
+        projectExpert.setExpertId(reqDto.getExpertId());
+        projectExpert.setSelectionMode(reqDto.getSelectionMode());
+        projectExpert.setTeamLeader(reqDto.getTeamLeader());
+        if (reqDto.getId() == null) {
+            projectExpert.setCreateBy(SecurityUtils.getUsername());
+        } else {
+            projectExpert.setUpdateBy(SecurityUtils.getUsername());
+            projectExpert.setId(reqDto.getId());
+        }
+        return projectExpert;
+    }
+
+
+    public boolean hasDuplicateExpertId(List<ProjectExpertSaveReqDto> saveData) {
+        // 使用 Stream API 收集 expertId 的频率
+        Map<Long, Long> frequencyMap = saveData.stream()
+                .collect(Collectors.groupingBy(ProjectExpertSaveReqDto::getExpertId, Collectors.counting()));
+
+        // 检查是否有任何 expertId 的频率大于 1
+        return frequencyMap.values().stream().anyMatch(count -> count > 1);
     }
 
     /**
@@ -74,6 +376,13 @@
      */
     @Override
     public int deleteProjectManagementByIds(Long[] ids) {
+        // 校验
+        for (Long id : ids) {
+            checkDelData(id);
+        }
+//        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) ){
+//            throw new ServiceException("无权操作!");
+//        }
         return projectManagementMapper.deleteProjectManagementByIds(ids);
     }
 
@@ -87,4 +396,476 @@
     public int deleteProjectManagementById(Long id) {
         return projectManagementMapper.deleteProjectManagementById(id);
     }
+
+    @Override
+    public ProjectExpertManagementInfoRes projectExpertCheckInfo(Long 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
+    @Transactional
+    public void projectCheck(ProjectCheckReq req) {
+        ProjectManagement projectManagement = checkDataPer(req.getId());
+
+        if (req.getState() != 3L && req.getState() != 1) {
+            throw new ServiceException("参数异常!");
+        }
+        Long state = projectManagement.getState();
+        if (state != 2) {
+            throw new ServiceException("未生成审批单不可审批通过操作!");
+        }
+
+        List<ProjectFile> projectFile = req.getProjectFile();
+        ProjectManagement projectManagementUp = new ProjectManagement();
+        projectManagementUp.setId(req.getId());
+        projectManagementUp.setState(req.getState());
+        projectManagementUp.setUpdateBy(SecurityUtils.getUsername());
+        if (req.getState() == 3) {
+            projectManagementUp.setStep(3L);
+        } else if (req.getState() == 1) {
+            projectManagementUp.setExpertName("");
+            projectManagementUp.setExpertId(0l);
+            projectManagementUp.setExpertNum(0L);
+            projectManagementUp.setStep(1L);
+        }
+        int i = projectManagementMapper.updateProjectManagement(projectManagementUp);
+        //驳回删
+        if (req.getState() == 1) {
+            projectFileMapper.deleteProjectFileByIdAndType(req.getId(), "1");
+            projectExpertMapper.deleteProjectExpertByProjectId(req.getId());
+        }
+        if (i > 0 && StringUtils.isNotEmpty(projectFile) && req.getState() == 3) {
+            //删除之前的该类型
+            projectFileMapper.deleteProjectFileByIdAndType(req.getId(), "1");
+            String username = SecurityUtils.getUsername();
+            projectFile.forEach(file -> {
+                file.setCreateBy(username);
+                file.setProjectId(req.getId());
+            });
+            //int i1 = projectFileMapper.insertProjectFiles(projectFile);
+            Boolean b = projectFileService.saveBatchProjectFile(projectFile);
+            if (!b) {
+                throw new ServiceException("保存附件失败!");
+            }
+        }
+    }
+
+    @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());
+
+        Long state = projectManagement.getState();
+        if (state != 3L) {
+            throw new ServiceException("此状态不可归档!");
+        }
+        List<ProjectFile> projectFile = req.getProjectFile();
+        ProjectManagement projectManagementUp = new ProjectManagement();
+        projectManagementUp.setId(req.getId());
+        projectManagementUp.setState(4L);
+        projectManagementUp.setStep(4L);
+//        projectManagementUp.setDesc(req.getDesc());
+        projectManagementUp.setProjectEndTime(req.getProjectEndTime());
+        projectManagementUp.setUpdateBy(SecurityUtils.getUsername());
+        int i = projectManagementMapper.updateProjectManagement(projectManagementUp);
+        if (i > 0 && StringUtils.isNotEmpty(projectFile)) {
+            String username = SecurityUtils.getUsername();
+            projectFile.forEach(file -> {
+                file.setCreateBy(username);
+                file.setProjectId(req.getId());
+            });
+//            int i1 = projectFileMapper.insertProjectFiles(projectFile);
+//            if (i1 < 1){
+//                throw new ServiceException("保存附件失败!");
+//            }
+            Boolean b = projectFileService.saveBatchProjectFile(projectFile);
+            if (!b) {
+                throw new ServiceException("保存附件失败!");
+            }
+        }
+
+    }
+
+    @Override
+    public List<ProjectExpertStateResp> getProjectExpertSate(ProjectExpertStateReq req) {
+
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
+            req.setDeptId(SecurityUtils.getDeptId());
+        }
+        return projectManagementMapper.getProjectExpertSate(req);
+    }
+
+    @Override
+    public List<ProjectExpertEvaluationResp> projectExpertEvaluationList(Long 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();
+        List<ProjectExpertScoreSaveReq.Score> saveData = req.getSaveData();
+        if (expertType == 1) {
+            ProjectExpert projectExpert1 = projectExpertMapper.selectProjectExpertById(req.getProjectExpertId());
+            if (projectExpert1 == null) {
+                throw new ServiceException("项目专家不存在!");
+            }
+            ProjectManagement projectManagement1 = checkData(projectExpert1.getProjectId());
+            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);
+            projectExpert.setId(req.getProjectExpertId());
+            projectExpert.setScore(req.getScore());
+            projectExpert.setEvaluationState(1L);
+            int i = projectExpertMapper.updateProjectExpert(projectExpert);
+            if (i < 1) {
+                throw new ServiceException("保存失败!");
+            }
+
+            if (StringUtils.isNotEmpty(saveData)) {
+                List<ProjectExpertDetail> projectExpertDetails = dealData(saveData, req.getProjectExpertId());
+                List<ProjectExpertDetail> saveList = projectExpertDetails.stream()
+                        .filter(dto -> dto.getId() == null)
+                        .collect(Collectors.toList());
+                if (StringUtils.isNotEmpty(saveList)) {
+                    int i12 = projectExpertDetailMapper.batchInsertProjectExpertDetail(saveList);
+                    if (i12 < 1) {
+                        throw new ServiceException("保存失败!");
+                    }
+                }
+                List<ProjectExpertDetail> updateList = projectExpertDetails.stream()
+                        .filter(dto -> dto.getId() != null)
+                        .collect(Collectors.toList());
+                if (StringUtils.isNotEmpty(updateList)) {
+                    int i1 = projectExpertDetailMapper.batchUpdateProjectExpertDetail(updateList);
+                    if (i1 < 1) {
+                        throw new ServiceException("保存失败!");
+                    }
+                }
+            }
+
+        }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(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(projectId);
+            projectManagement.setEvaluationState(1L);
+            projectManagement.setUpdateBy(SecurityUtils.getUsername());
+            int i1 = projectManagementMapper.updateProjectManagement(projectManagement);
+            if (i1 < 1) {
+                throw new ServiceException("保存失败!");
+            }
+        }
+
+    }
+
+    @Override
+    public List<ProjectExpertResp> projectExpertEvaList(SysProjectExpertReq req) {
+        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
+    public List<ProjectExpertDetail> selectProjectExpertDetailList(Long projectExpertId) {
+        ProjectExpertDetail projectExpertDetail = new ProjectExpertDetail();
+        projectExpertDetail.setProjectExpertId(projectExpertId);
+        return projectExpertDetailMapper.selectProjectExpertDetailList(projectExpertDetail);
+    }
+
+    @Override
+    public List<ProjectFile> selectProjectFileList(Long projectId, String module) {
+        ProjectFile projectFile = new ProjectFile();
+        projectFile.setProjectId(projectId);
+        projectFile.setModule(module);
+        List<ProjectFile> projectFiles = projectFileMapper.selectProjectFileList(projectFile);
+        if (StringUtils.isNotEmpty(projectFiles)) {
+            return projectFiles;
+        }
+        return Collections.emptyList();
+    }
+
+    @Override
+    public ProjectNumResp getProjectNum() {
+        ProjectNumResp projectNumResp = new ProjectNumResp();
+        List<Integer> dataNum = projectManagementMapper.getDataNum(SecurityUtils.isAdmin(SecurityUtils.getUserId()) ? null : SecurityUtils.getDeptId());
+        if (!StringUtils.isEmpty(dataNum)) {
+            Map<Integer, Long> statusCounts = dataNum.stream()
+                    .collect(Collectors.groupingBy(
+                            status -> status,
+                            Collectors.counting()
+                    ));
+            projectNumResp.setTotal(dataNum.size());
+            int i = statusCounts.get(2) == null ? 0 : statusCounts.get(2).intValue();
+            projectNumResp.setApproval(statusCounts.get(3) == null ? 0 + i : statusCounts.get(3).intValue() + i);
+            projectNumResp.setExpert(statusCounts.get(1) == null ? 0 : statusCounts.get(1).intValue());
+            projectNumResp.setStaging(statusCounts.get(0) == null ? 0 : statusCounts.get(0).intValue());
+            projectNumResp.setEnd(statusCounts.get(4) == null ? 0 : statusCounts.get(4).intValue());
+        }
+        return projectNumResp;
+    }
+
+    @Override
+    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) {
+                ProjectExpertDetail projectExpertDetail = new ProjectExpertDetail();
+                projectExpertDetail.setProjectExpertId(projectExpertId);
+                List<ProjectExpertDetail> projectExpertDetails = projectExpertDetailMapper.selectProjectExpertDetailList(projectExpertDetail);
+                if (StringUtils.isNotEmpty(projectExpertDetails)) {
+                    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());
+                }
+                SysExpertInfo sysExpertInfo = sysExpertInfoMapper.selectById(projectDetailResp.getExpertId());
+                if (sysExpertInfo != null) {
+                    projectDetailResp.setTitle(sysExpertInfo.getTitle());
+                    projectDetailResp.setJob(sysExpertInfo.getJob());
+                }
+
+            }
+        }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;
+    }
+
+    @Override
+    public List<ProjectExpertExportInfoRes> projectExpertExportList(Long projectId) {
+        ProjectManagement projectManagement = checkData(projectId);
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && projectManagement.getDeptId().intValue() != SecurityUtils.getDeptId().intValue()) {
+            throw new ServiceException("非本部门数据,无权操作!");
+        }
+        if (projectManagement.getState() != 4) {
+            throw new ServiceException("项目未完成,无权操作!");
+        }
+        if (projectManagement.getEvaluationState() == 0) {
+            throw new ServiceException("有专家未完成评定与报销,请完善后再试");
+        }
+
+        return projectExpertMapper.projectExpertExportList(projectId);
+
+    }
+
+    @Override
+    public List<ProjectDataResp> selectProjectData(ProjectManagement projectManagement) {
+        return projectManagementMapper.selectProjectData(projectManagement);
+    }
+
+    private List<ProjectExpertDetail> dealData(List<ProjectExpertScoreSaveReq.Score> data, Long projectExpertId) {
+        List<ProjectExpertDetail> dealData = new ArrayList<>();
+        data.forEach(dto -> {
+            ProjectExpertDetail projectExpertDetail = new ProjectExpertDetail();
+            projectExpertDetail.setProjectExpertId(projectExpertId);
+            projectExpertDetail.setContent(dto.getContent());
+            projectExpertDetail.setScore(dto.getScore());
+            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;
+    }
+
+
+    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)) {
+            throw new ServiceException("数据不存在!");
+        }
+        return projectManagement;
+    }
+
+    public ProjectManagement checkDataPer(Long id) {
+        ProjectManagement projectManagement = checkData(id);
+        Long deptId = projectManagement.getDeptId();
+        // 本部门审批?
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && deptId.intValue() != SecurityUtils.getDeptId().intValue()) {
+            throw new ServiceException("非本处室数据,无权操作!");
+        }
+        if (projectManagement.getState() == 4) {
+            throw new ServiceException("已结项,无权操作!");
+        }
+        return projectManagement;
+    }
+
+
+    private void checkDelData(Long id) {
+        ProjectManagement projectManagement = checkData(id);
+        Long deptId = projectManagement.getDeptId();
+        // 本部门审批?
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && deptId.intValue() != SecurityUtils.getDeptId().intValue()) {
+            throw new ServiceException("非本处室数据,无权操作!");
+        }
+    }
+
+
 }
\ No newline at end of file

--
Gitblit v1.9.2