xiangpei
2025-04-10 8d2f2f78c0c02205b91946f4f5cfdc03bcb3383a
business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java
@@ -7,9 +7,11 @@
import cn.hutool.core.util.ZipUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.common.base.Result;
@@ -18,10 +20,7 @@
import com.ycl.common.core.domain.BaseEntity;
import com.ycl.common.core.domain.entity.SysDictData;
import com.ycl.common.enums.YesOrNo;
import com.ycl.common.enums.business.FileTypeEnum;
import com.ycl.common.enums.business.ImportanceTypeEnum;
import com.ycl.common.enums.business.ProjectCategoryEnum;
import com.ycl.common.enums.business.ProjectStatusEnum;
import com.ycl.common.enums.business.*;
import com.ycl.common.exception.base.BaseException;
import com.ycl.common.utils.CopyUtils;
import com.ycl.common.utils.DateUtils;
@@ -67,6 +66,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.time.Year;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -97,6 +97,7 @@
    private final ProjectUnitRegistrationInfoServiceImpl projectUnitRegistrationInfoServiceImpl;
    private final SysDeptMapper sysDeptMapper;
    private final ISysDictDataService dictDataService;
    private final ProcessLogService processLogService;
    /**
@@ -152,23 +153,20 @@
     * @return
     */
    public boolean  checkProjectNameAndIdIsUnique(ProjectInfo entity,Long updateId){
        QueryWrapper<ProjectInfo> queryWrapper = new QueryWrapper<ProjectInfo>();
        LambdaQueryWrapper<ProjectInfo> queryWrapper = new LambdaQueryWrapper<>();
        if (updateId == null) {
            queryWrapper.eq("project_name", entity.getProjectName());
            queryWrapper.eq("deleted",0);
            if (StringUtils.isNotEmpty(entity.getProjectCode())) {
                queryWrapper.eq("project_code", entity.getProjectCode());
            }
            List<ProjectInfo> project = projectInfoMapper.selectList(queryWrapper);
            return project == null || project.isEmpty();
        }else {
            List<ProjectInfo> project = projectInfoMapper.checkProjectNameAndIdIsUnique(updateId,entity.getProjectName(),entity.getProjectCode());
            return project == null || project.isEmpty();
            List<ProjectInfo> list = new LambdaQueryChainWrapper<>(baseMapper)
                    .eq(ProjectInfo::getProjectName, entity.getProjectName())
                    .eq(ProjectInfo::getProjectCode, entity.getProjectCode())
                    .list();
            return list == null || list.isEmpty();
        } else {
            List<ProjectInfo> list = new LambdaQueryChainWrapper<>(baseMapper)
                    .eq(ProjectInfo::getProjectName, entity.getProjectName())
                    .eq(ProjectInfo::getProjectCode, entity.getProjectCode())
                    .ne(ProjectInfo::getId, updateId)
                    .list();
            return list == null || list.isEmpty();
        }
    }
@@ -325,6 +323,9 @@
        if (query.getProjectEndTime() != null) {
            query.setProjectEndTime(DateUtils.getDayEnd(query.getProjectEndTime()));
        }
        if (YesOrNo.YES.getCode().equals(query.getCenter())) {
            query.setProjectPhase("6");
        }
        // 异常项目暂时返回空
        if (YesOrNo.YES.getCode().equals(query.getExe())) {
            return Result.ok().data(new ArrayList<>()).total(0);
@@ -350,12 +351,13 @@
        baseMapper.getPage(query, page);
        List<ProjectInfoVO> records = page.getRecords();
        List<ProjectVO> list = new ArrayList<>();
        int year = Year.now().getValue();
        records.forEach(vo -> {
            ProjectInfoVO.transform(vo);
            ProjectVO projectVO = new ProjectVO();
            copyToProjectVO(vo, projectVO);
            List<Long> departmentList = vo.getCompetentDepartmentList();
            projectVO.setAuditRole(SecurityUtils.isAdmin(SecurityUtils.getUserId()) || (!CollectionUtils.isEmpty(departmentList) && departmentList.contains(SecurityUtils.getDeptId())));
            String competentDepartment = vo.getCompetentDepartment();
            projectVO.setAuditRole(SecurityUtils.isAdmin(SecurityUtils.getUserId()) || (StringUtils.isNotEmpty(competentDepartment) && competentDepartment.equals(SecurityUtils.getDeptId() + "")));
            // 翻译项目阶段
            String phase = ProjectCategoryEnum.getPhaseByProjectStatus(projectVO.getProjectPhase());
            projectVO.setProjectPhase(phase);
@@ -365,6 +367,14 @@
                if (Objects.nonNull(dictData)) {
                    projectVO.setProjectSubType(dictData.getDictLabel());
                }
            }
            // 获取本年度的投资金额
            List<ProjectInfoYearPlan> yearPlans = new LambdaQueryChainWrapper<>(projectInfoYearPlanService.getBaseMapper())
                    .eq(ProjectInfoYearPlan::getProjectInfoId, projectVO.getId())
                    .eq(ProjectInfoYearPlan::getYear, year)
                    .list();
            if (! CollectionUtils.isEmpty(yearPlans)) {
                projectVO.setYearInvestAmount(yearPlans.get(0).getYearTotalMoney());
            }
            list.add(projectVO);
        });
@@ -395,8 +405,8 @@
        ProjectInfo entity = baseMapper.getById(id);
        Assert.notNull(entity, "记录不存在");
        ProjectInfoVO vo = ProjectInfoVO.getVoByEntity(entity, null);
        List<Long> departmentList = vo.getCompetentDepartmentList();
        vo.setAuditRole(SecurityUtils.isAdmin(SecurityUtils.getUserId()) || (!CollectionUtils.isEmpty(departmentList) && departmentList.contains(SecurityUtils.getDeptId())));
        String competentDepartment = vo.getCompetentDepartment();
        vo.setAuditRole(SecurityUtils.isAdmin(SecurityUtils.getUserId()) || (StringUtils.isNotEmpty(competentDepartment) && competentDepartment.equals(SecurityUtils.getDeptId() + "")));
        QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>();
        fileQueryWrapper.eq("type", FileTypeEnum.PROJECT_INFO.getType());
        fileQueryWrapper.eq("bus_id", vo.getId());
@@ -466,15 +476,22 @@
                finish.add(item);
            }
            if (ImportanceTypeEnum.PROVINCIAL_KEY.getType().equals(item.getImportanceType())) {
                province.add(item);
            } else if (ImportanceTypeEnum.SUINING_KEY.getType().equals(item.getImportanceType())) {
                city.add(item);
            } else if (ImportanceTypeEnum.SHEHONG_KEY.getType().equals(item.getImportanceType())) {
                county.add(item);
            } else // if  (ImportanceTypeEnum.NORMAL.getType().equals(item.getImportanceType()))
            {
            if (StringUtils.isBlank(item.getImportanceType())) {
                normal.add(item);
                // 使用contains,因为重点分类可多选,使用,分割存储的
            } else {
                if (item.getImportanceType().contains(ImportanceTypeEnum.PROVINCIAL_KEY.getType())) {
                    province.add(item);
                }
                if (item.getImportanceType().contains(ImportanceTypeEnum.SUINING_KEY.getType())) {
                    city.add(item);
                }
                if (item.getImportanceType().contains(ImportanceTypeEnum.SHEHONG_KEY.getType())) {
                    county.add(item);
                }
                if (item.getImportanceType().contains(ImportanceTypeEnum.NORMAL.getType())) {
                    normal.add(item);
                }
            }
        });
        //单位先默认为元
@@ -528,6 +545,12 @@
    public Map<String, Integer> countExceptionProject(IndexDTO indexDTO) {
        Map<String, Integer> map = new HashMap<>();
        map.put("processExceptionProject", 0);
        // 查询发生过容缺的项目数
        List<String> projectIds = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper())
                .select(ProcessLog::getProjectId)
                .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.WAIT)
                .list().stream().map(ProcessLog::getProjectId).distinct().collect(Collectors.toList());
        map.put("hasWaitProjectNum", projectIds.size());
        return map;
    }
@@ -809,6 +832,12 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result editProject(ProjectForm form) {
        // 草稿的情况,需要判定有没有选业主单位(因为草稿不校验必填),没选则默认设置为当前人的单位
        if (ProjectConstant.DRAFT.equals(form.getProjectInfoForm().getUsedStatus())) {
            if (Objects.isNull(form.getProjectInfoForm().getProjectOwnerUnit())) {
                form.getProjectInfoForm().setProjectOwnerUnit(SecurityUtils.getDeptId());
            }
        }
        Long projectId = form.getProjectInfoForm().getId();
        if (ObjectUtil.isNotNull(form.getProjectInfoForm())) {
            if (ObjectUtil.isNull(form.getProjectInfoForm().getId())) {
@@ -817,12 +846,12 @@
                Long userId = SecurityUtils.getUserId();
                entity.setCreateBy(userId);
                entity.setUpdateBy(userId);
                //如果是储备项目(未开工项目)不需要审核
                if ("0".equals(entity.getProjectPhase())) {
                //如果是储备项目(未开工项目)不需要审核(草稿除外)
                if (ProjectCategoryEnum.RESERVE.getType().equals(entity.getProjectPhase()) && ! ProjectConstant.DRAFT.equals(entity.getUsedStatus())) {
                    entity.setUsedStatus(ProjectConstant.PASS);
                }
                // 管理员修改的直接通过
                if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
                // 管理员修改的直接通过(管理员保存为草稿,那么状态还是草稿)
                if (SecurityUtils.isAdmin(SecurityUtils.getUserId()) && ! ProjectConstant.DRAFT.equals(entity.getUsedStatus())) {
                    entity.setUsedStatus(ProjectConstant.PASS);
                }
                if(!checkProjectNameAndIdIsUnique(entity,null)){
@@ -862,12 +891,12 @@
                ProjectInfoForm.getEntityByForm(form.getProjectInfoForm(), entity);
                Long userId = SecurityUtils.getUserId();
                entity.setUpdateBy(userId);
                //如果是储备项目(未开工项目)不需要审核
                if (ProjectConstant.COMMIT.equals(entity.getUsedStatus()) && ProjectStatusEnum.PENDDING.getType().equals(entity.getProjectStatus())) {
                //如果是储备项目(未开工项目)不需要审核(草稿除外)
                if (ProjectCategoryEnum.RESERVE.getType().equals(entity.getProjectPhase()) && ! ProjectConstant.DRAFT.equals(entity.getUsedStatus())) {
                    entity.setUsedStatus(ProjectConstant.PASS);
                }
                // 管理员修改的直接通过
                if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
                // 管理员修改的直接通过(管理员保存为草稿,那么状态还是草稿)
                if (SecurityUtils.isAdmin(SecurityUtils.getUserId()) && ! ProjectConstant.DRAFT.equals(entity.getUsedStatus())) {
                    entity.setUsedStatus(ProjectConstant.PASS);
                }
                if(!checkProjectNameAndIdIsUnique(entity, entity.getId())){
@@ -923,6 +952,10 @@
                if (Objects.nonNull(form.getProjectUnitRegistrationInfoForm().getId())) {
                    projectUnitRegistrationInfoServiceImpl.update(form.getProjectUnitRegistrationInfoForm());
                } else {
                    // 先删掉之前的,再新增
                    new LambdaUpdateChainWrapper<>(projectUnitRegistrationInfoServiceImpl.getBaseMapper())
                            .eq(ProjectUnitRegistrationInfo::getProjectId, projectId)
                            .remove();
                    form.getProjectUnitRegistrationInfoForm().setProjectId(projectId);
                    projectUnitRegistrationInfoServiceImpl.add(form.getProjectUnitRegistrationInfoForm());
                }