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

---
 expert-system/src/main/java/com/gkhy/system/service/impl/ProjectManagementServiceImpl.java |  648 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 480 insertions(+), 168 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 f677602..682408b 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
@@ -2,12 +2,15 @@
 
 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;
 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.*;
@@ -18,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 +50,12 @@
     @Autowired
     private SysExpertInfoMapper sysExpertInfoMapper;
 
+    @Autowired
+    private OutProjectExpertMapper outProjectExpertMapper;
+
+    @Autowired
+    private OutProjectExpertDetailMapper outProjectExpertDetailMapper;
+
     /**
      * 查询项目管理
      *
@@ -65,8 +75,8 @@
      */
     @Override
     public List<ProjectManagement> selectProjectManagementList(ProjectManagement projectManagement) {
-        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
-           projectManagement.setDeptId(SecurityUtils.getDeptId());
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && SecurityUtils.getUserId() != 130L) {
+            projectManagement.setDeptId(SecurityUtils.getDeptId());
         }
         return projectManagementMapper.selectProjectManagementList(projectManagement);
     }
@@ -80,24 +90,25 @@
     @Override
     public Long insertProjectManagement(ProjectManageSaveReq projectManagement) {
         ProjectManagement projectManagementSave = new ProjectManagement();
-        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())){
+        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
             throw new ServiceException("无权新增");
         }
         projectManagementSave.setDelFlag(DeleteFlagEnum.UN_DELETE.getCode());
         BeanUtil.copyProperties(projectManagement, projectManagementSave);
-        if (projectManagement.getId() != null){
+        if (projectManagement.getId() != null) {
             checkDataPer(projectManagement.getId());
 
             projectManagementSave.setUpdateBy(SecurityUtils.getUsername());
             projectManagementSave.setUpdateTime(DateUtils.getNowDate());
-           // projectManagementMapper.updateProjectManagement(projectManagementSave);
+            // projectManagementMapper.updateProjectManagement(projectManagementSave);
             updateById(projectManagementSave);
-        }else {
+        } else {
+            projectManagementSave.setProjectCode(RandomStringGenerator.generateRandomString(10));
             projectManagementSave.setStep(1L);
             projectManagementSave.setCreateBy(SecurityUtils.getUsername());
             projectManagementSave.setCreateTime(DateUtils.getNowDate());
             save(projectManagementSave);
-          //  projectManagementMapper.insertProjectManagement(projectManagementSave);
+            //  projectManagementMapper.insertProjectManagement(projectManagementSave);
         }
 
 
@@ -112,7 +123,7 @@
      */
     @Override
     @Transactional
-    public void updateProjectManagement(ProjectExpertSaveBatchReqDto projectManagement)  {
+    public void updateProjectManagement(ProjectExpertSaveBatchReqDto projectManagement) {
         ProjectManagement projectManagement1 = checkDataPer(projectManagement.getId());
         //专家选取
 
@@ -120,98 +131,227 @@
         projectManagementSave.setUpdateBy(SecurityUtils.getUsername());
         projectManagementSave.setUpdateTime(DateUtils.getNowDate());
         projectManagementSave.setId(projectManagement.getId());
-        if (projectManagement1.getState() != 1 && projectManagement1.getState() != 0 ){
+        if (projectManagement1.getState() != 1 && projectManagement1.getState() != 0) {
             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 (hasDuplicateExpertId(saveData)){
-            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("外部专家身份证重复!");
+            }
 
-        if ((projectManagement1.getStep() == 1 || projectManagement1.getStep() == 2) && (projectManagement.getStep() == 2 ) ){
+        }
+
+        boolean flag = false;
+
+
+        if ((projectManagement1.getStep() == 1 || projectManagement1.getStep() == 2) && (projectManagement.getStep() == 2)) {
             projectManagementSave.setStep(2L);
             projectManagementSave.setState(1L);
-        }else if (projectManagement1.getStep() == 2 && projectManagement.getStep() == 3){
+
+            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());
-            List<ProjectExpertSaveReqDto> collect = saveData.stream()
-                    .filter(dto -> "1".equals(dto.getTeamLeader().toString()))
+
+        }
+        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("保存专家失败!");
+                                }
+                            }
 
-            if (StringUtils.isEmpty(collect)){
-                throw new ServiceException("缺少组长!");
-            }
-            if (collect.size() > 1){
-                throw new ServiceException("组长只能选一人!");
-            }
-            projectManagementSave.setExpertName(collect.get(0).getExpertName());
-            projectManagementSave.setExpertId(collect.get(0).getExpertId());
-        }
+                        }
 
-        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("保存专家失败!");
-            }
-        }
-        projectManagementSave.setExpertNum((long) saveData.size());
+//        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){
+            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){
+        if (i < 1) {
             throw new ServiceException("保存专家失败!");
         }
     }
 
 
-    public List<ProjectExpert> convertToProjectExpertList(List<ProjectExpertSaveReqDto> reqDtos,Long projectId) {
+    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;
+        reqDtos.forEach(reqDto -> {
+            ProjectExpert projectExpert = convertToProjectExpert(reqDto, projectId);
+            projectExpertList.add(projectExpert);
+        });
+        return projectExpertList;
     }
 
-    private ProjectExpert convertToProjectExpert(ProjectExpertSaveReqDto reqDto,Long projectId) {
+    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){
+        if (reqDto.getId() == null) {
             projectExpert.setCreateBy(SecurityUtils.getUsername());
-        }else {
+        } else {
             projectExpert.setUpdateBy(SecurityUtils.getUsername());
             projectExpert.setId(reqDto.getId());
         }
@@ -219,14 +359,13 @@
     }
 
 
-
-    public  boolean hasDuplicateExpertId(List<ProjectExpertSaveReqDto> saveData) {
+    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);
+        return frequencyMap.values().stream().anyMatch(count -> count > 1);
     }
 
     /**
@@ -238,12 +377,12 @@
     @Override
     public int deleteProjectManagementByIds(Long[] ids) {
         // 校验
-//        for (Long id : ids) {
-//            checkDataPer(id);
-//        }
-        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) ){
-            throw new ServiceException("无权操作!");
+        for (Long id : ids) {
+            checkDelData(id);
         }
+//        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) ){
+//            throw new ServiceException("无权操作!");
+//        }
         return projectManagementMapper.deleteProjectManagementByIds(ids);
     }
 
@@ -260,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
@@ -268,11 +420,11 @@
     public void projectCheck(ProjectCheckReq req) {
         ProjectManagement projectManagement = checkDataPer(req.getId());
 
-        if (req.getState() != 3L &&  req.getState() != 1 ){
+        if (req.getState() != 3L && req.getState() != 1) {
             throw new ServiceException("参数异常!");
         }
         Long state = projectManagement.getState();
-        if (state != 2){
+        if (state != 2) {
             throw new ServiceException("未生成审批单不可审批通过操作!");
         }
 
@@ -281,17 +433,24 @@
         projectManagementUp.setId(req.getId());
         projectManagementUp.setState(req.getState());
         projectManagementUp.setUpdateBy(SecurityUtils.getUsername());
-        if (req.getState() == 3){
+        if (req.getState() == 3) {
             projectManagementUp.setStep(3L);
-        }else if (req.getState() == 1){
-            projectManagementUp.setStep(2L);
+        } 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){
+        if (req.getState() == 1) {
             projectFileMapper.deleteProjectFileByIdAndType(req.getId(), "1");
+            projectExpertMapper.deleteProjectExpertByProjectId(req.getId());
+            outProjectExpertMapper.update(new OutProjectExpert(),new LambdaUpdateWrapper<OutProjectExpert>()
+                    .eq(OutProjectExpert::getProjectId, req.getId()).set(OutProjectExpert::getDelFlag, 1).set(OutProjectExpert::getUpdateTime, new Date())
+                    .set(OutProjectExpert::getUpdateBy, SecurityUtils.getUsername()));
         }
-        if (i > 0 && StringUtils.isNotEmpty(projectFile) && req.getState() == 3){
+        if (i > 0 && StringUtils.isNotEmpty(projectFile) && req.getState() == 3) {
             //删除之前的该类型
             projectFileMapper.deleteProjectFileByIdAndType(req.getId(), "1");
             String username = SecurityUtils.getUsername();
@@ -301,10 +460,34 @@
             });
             //int i1 = projectFileMapper.insertProjectFiles(projectFile);
             Boolean b = projectFileService.saveBatchProjectFile(projectFile);
-            if (!b){
+            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
@@ -312,7 +495,7 @@
         ProjectManagement projectManagement = checkDataPer(req.getId());
 
         Long state = projectManagement.getState();
-        if (state != 3L){
+        if (state != 3L) {
             throw new ServiceException("此状态不可归档!");
         }
         List<ProjectFile> projectFile = req.getProjectFile();
@@ -324,7 +507,7 @@
         projectManagementUp.setProjectEndTime(req.getProjectEndTime());
         projectManagementUp.setUpdateBy(SecurityUtils.getUsername());
         int i = projectManagementMapper.updateProjectManagement(projectManagementUp);
-        if (i > 0 && StringUtils.isNotEmpty(projectFile)){
+        if (i > 0 && StringUtils.isNotEmpty(projectFile)) {
             String username = SecurityUtils.getUsername();
             projectFile.forEach(file -> {
                 file.setCreateBy(username);
@@ -335,7 +518,7 @@
 //                throw new ServiceException("保存附件失败!");
 //            }
             Boolean b = projectFileService.saveBatchProjectFile(projectFile);
-            if (!b){
+            if (!b) {
                 throw new ServiceException("保存附件失败!");
             }
         }
@@ -345,7 +528,7 @@
     @Override
     public List<ProjectExpertStateResp> getProjectExpertSate(ProjectExpertStateReq req) {
 
-        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
             req.setDeptId(SecurityUtils.getDeptId());
         }
         return projectManagementMapper.getProjectExpertSate(req);
@@ -353,72 +536,119 @@
 
     @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()]));
-        }
-
-
-        ProjectExpert projectExpert1 = projectExpertMapper.selectProjectExpertById(req.getProjectExpertId());
-        if (projectExpert1 == null){
-            throw new ServiceException("项目专家不存在!");
-        }
-        ProjectManagement projectManagement1 = checkData(projectExpert1.getProjectId());
-        if (projectManagement1.getState() != 4){
-            throw new ServiceException("项目未完成!");
-        }
-
-        //更新项目专家表
-        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("保存失败!");
-        }
-
         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(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("保存失败!");
+            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("保存失败!");
+                    }
                 }
             }
-            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(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);
-            if (i1 < 1){
+            if (i1 < 1) {
                 throw new ServiceException("保存失败!");
             }
         }
@@ -427,10 +657,17 @@
 
     @Override
     public List<ProjectExpertResp> projectExpertEvaList(SysProjectExpertReq req) {
-        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
+        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
@@ -441,12 +678,12 @@
     }
 
     @Override
-    public List<ProjectFile> selectProjectFileList(Long projectId,String module ) {
+    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)){
+        if (StringUtils.isNotEmpty(projectFiles)) {
             return projectFiles;
         }
         return Collections.emptyList();
@@ -456,60 +693,98 @@
     public ProjectNumResp getProjectNum() {
         ProjectNumResp projectNumResp = new ProjectNumResp();
         List<Integer> dataNum = projectManagementMapper.getDataNum(SecurityUtils.isAdmin(SecurityUtils.getUserId()) ? null : SecurityUtils.getDeptId());
-        if (!StringUtils.isEmpty(dataNum)){
+        if (!StringUtils.isEmpty(dataNum)) {
             Map<Integer, Long> statusCounts = dataNum.stream()
                     .collect(Collectors.groupingBy(
                             status -> status,
                             Collectors.counting()
                     ));
             projectNumResp.setTotal(dataNum.size());
-            projectNumResp.setApproval(statusCounts.get(3)  == null ? 0 : statusCounts.get(3).intValue());
+            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());
+            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) {
+    public ProjectDetailResp selectProjectExpertDetail(Long projectExpertId,Long expertType) {
         ProjectDetailResp projectDetailResp = new ProjectDetailResp();
-        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);
+        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());
+                }
+
             }
-            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());
-            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()){
+        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && projectManagement.getDeptId().intValue() != SecurityUtils.getDeptId().intValue()) {
             throw new ServiceException("非本部门数据,无权操作!");
         }
-        if (projectManagement.getState() != 4){
+        if (projectManagement.getState() != 4) {
             throw new ServiceException("项目未完成,无权操作!");
         }
-        if (projectManagement.getEvaluationState() == 0){
+        if (projectManagement.getEvaluationState() == 0) {
             throw new ServiceException("有专家未完成评定与报销,请完善后再试");
         }
 
@@ -517,7 +792,12 @@
 
     }
 
-    private List<ProjectExpertDetail> dealData(List<ProjectExpertScoreSaveReq.Score> data,Long projectExpertId){
+    @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();
@@ -525,9 +805,9 @@
             projectExpertDetail.setContent(dto.getContent());
             projectExpertDetail.setScore(dto.getScore());
             projectExpertDetail.setScoreType(dto.getScoreType());
-            if (dto.getId() == null){
+            if (dto.getId() == null) {
                 projectExpertDetail.setCreateBy(SecurityUtils.getUsername());
-            }else {
+            } else {
                 projectExpertDetail.setId(dto.getId());
                 projectExpertDetail.setUpdateBy(SecurityUtils.getUsername());
             }
@@ -538,25 +818,57 @@
     }
 
 
-    public ProjectManagement checkData(Long id){
+    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)){
+        if (ObjectUtil.isNull(projectManagement)) {
             throw new ServiceException("数据不存在!");
         }
         return projectManagement;
     }
 
-    public ProjectManagement checkDataPer(Long id){
+    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 (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && deptId.intValue() != SecurityUtils.getDeptId().intValue()) {
+            throw new ServiceException("非本处室数据,无权操作!");
         }
-        if (projectManagement.getState() == 4){
+        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