heheng
2024-11-27 3c633caa438147d94cbc37993b818766de06aafb
expert-system/src/main/java/com/gkhy/system/service/impl/ProjectManagementServiceImpl.java
@@ -3,6 +3,7 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
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;
@@ -17,6 +18,7 @@
import com.gkhy.system.mapper.ProjectExpertMapper;
import com.gkhy.system.mapper.ProjectFileMapper;
import com.gkhy.system.mapper.ProjectManagementMapper;
import com.gkhy.system.service.IProjectFileService;
import com.gkhy.system.service.IProjectManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -45,6 +47,9 @@
    @Autowired
    private ProjectExpertDetailMapper projectExpertDetailMapper;
    @Autowired
    private IProjectFileService projectFileService;
    /**
     * 查询项目管理
     *
@@ -64,6 +69,9 @@
     */
    @Override
    public List<ProjectManagement> selectProjectManagementList(ProjectManagement projectManagement) {
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
           projectManagement.setDeptId(SecurityUtils.getDeptId());
        }
        return projectManagementMapper.selectProjectManagementList(projectManagement);
    }
@@ -76,8 +84,10 @@
    @Override
    public Long insertProjectManagement(ProjectManageSaveReq projectManagement) {
        ProjectManagement projectManagementSave = new ProjectManagement();
        projectManagementSave.setDelFlag(0L);
        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());
@@ -112,7 +122,7 @@
        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("该步骤不可操作专家数据!");
        }
@@ -123,18 +133,18 @@
        if (hasDuplicateExpertId(saveData)){
            throw new ServiceException("专家重复!");
        }
        long count = saveData.stream()
                .filter(dto -> dto.getSelectionMode() == 1)
                .count();
        if (count < 1){
            throw new ServiceException("固定专家不能为空!");
        }
//        long count = saveData.stream()
//                .filter(dto -> dto.getSelectionMode() == 1)
//                .count();
//        if (count < 1){
//            throw new ServiceException("固定专家不能为空!");
//        }
        if (projectManagement1.getStep() == 1 || projectManagement1.getStep() == 2){
        if ((projectManagement1.getStep() == 1 || projectManagement1.getStep() == 2) && (projectManagement.getStep() == 2 ) ){
            projectManagementSave.setStep(2L);
            projectManagementSave.setState(1L);
        }else if (projectManagement1.getStep() == 3){
            projectManagementSave.setStep(3L);
        }else if (projectManagement1.getStep() == 2 && projectManagement.getStep() == 3){
            projectManagementSave.setStep(2L);
            projectManagementSave.setState(2L);
            projectManagementSave.setProjectCheckTime(new Date());
            List<ProjectExpertSaveReqDto> collect = saveData.stream()
@@ -179,7 +189,6 @@
                throw new ServiceException("保存专家失败!");
            }
        }
        int i = projectManagementMapper.updateProjectManagement(projectManagementSave);
        if (i < 1){
            throw new ServiceException("保存专家失败!");
@@ -219,13 +228,7 @@
                .collect(Collectors.groupingBy(ProjectExpertSaveReqDto::getExpertId, Collectors.counting()));
        // 检查是否有任何 expertId 的频率大于 1
        boolean hasDuplicates = frequencyMap.values().stream().anyMatch(count -> count > 1);
        if (hasDuplicates) {
           return true;
        }
        return false;
       return  frequencyMap.values().stream().anyMatch(count -> count > 1);
    }
    /**
@@ -236,7 +239,7 @@
     */
    @Override
    public int deleteProjectManagementByIds(Long[] ids) {
        //todo 校验
        // 校验
        for (Long id : ids) {
            checkDataPer(id);
        }
@@ -267,14 +270,9 @@
        if (req.getState() != 3L &&  req.getState() != 1 ){
            throw new ServiceException("参数异常!");
        }
        if (projectManagement.getStep() != 3){
            throw new ServiceException("非审批步骤!");
        }
        Long state = projectManagement.getState();
        if (req.getState() == 3 && state != 2){
        if (state != 2){
            throw new ServiceException("未生成审批单不可审批通过操作!");
        }else if (req.getState() == 1 && state != 2){
            throw new ServiceException("不可操作!");
        }
        List<ProjectFile> projectFile = req.getProjectFile();
@@ -283,7 +281,7 @@
        projectManagementUp.setState(req.getState());
        projectManagementUp.setUpdateBy(SecurityUtils.getUsername());
        if (req.getState() == 3){
            projectManagementUp.setStep(4L);
            projectManagementUp.setStep(3L);
        }else if (req.getState() == 1){
            projectManagementUp.setStep(2L);
        }
@@ -300,8 +298,9 @@
                file.setCreateBy(username);
                file.setProjectId(req.getId());
            });
            int i1 = projectFileMapper.insertProjectFiles(projectFile);
            if (i1 < 1){
            //int i1 = projectFileMapper.insertProjectFiles(projectFile);
            Boolean b = projectFileService.saveBatchProjectFile(projectFile);
            if (!b){
                throw new ServiceException("保存附件失败!");
            }
        }
@@ -319,6 +318,7 @@
        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());
@@ -329,8 +329,12 @@
                file.setCreateBy(username);
                file.setProjectId(req.getId());
            });
            int i1 = projectFileMapper.insertProjectFiles(projectFile);
            if (i1 < 1){
//            int i1 = projectFileMapper.insertProjectFiles(projectFile);
//            if (i1 < 1){
//                throw new ServiceException("保存附件失败!");
//            }
            Boolean b = projectFileService.saveBatchProjectFile(projectFile);
            if (!b){
                throw new ServiceException("保存附件失败!");
            }
        }
@@ -339,6 +343,10 @@
    @Override
    public List<ProjectExpertStateResp> getProjectExpertSate(ProjectExpertStateReq req) {
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            req.setDeptId(SecurityUtils.getDeptId());
        }
        return projectManagementMapper.getProjectExpertSate(req);
    }
@@ -417,6 +425,9 @@
    @Override
    public List<ProjectExpertResp> projectExpertEvaList(SysProjectExpertReq req) {
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            req.setDeptId(SecurityUtils.getDeptId());
        }
        return projectExpertMapper.projectExpertEvaList(req);
    }
@@ -446,8 +457,8 @@
        if (!StringUtils.isEmpty(dataNum)){
            Map<Integer, Long> statusCounts = dataNum.stream()
                    .collect(Collectors.groupingBy(
                            status -> status,  // 分组键
                            Collectors.counting()  // 计数
                            status -> status,
                            Collectors.counting()
                    ));
            projectNumResp.setTotal(dataNum.size());
            projectNumResp.setApproval(statusCounts.get(3)  == null ? 0 : statusCounts.get(3).intValue());