package com.ycl.service.impl; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.ycl.common.annotation.DataScope; import com.ycl.common.base.Result; import com.ycl.common.constant.ProcessOverTimeConstants; import com.ycl.common.core.domain.BaseEntity; import com.ycl.common.enums.business.CodingRulerCodeTypeEnum; import com.ycl.common.enums.business.CodingRulerStatusEnum; import com.ycl.common.enums.business.ProjectCategoryEnum; import com.ycl.common.enums.business.ProjectStatusEnum; import com.ycl.common.utils.SecurityUtils; import com.ycl.domain.entity.ProjectInfo; import com.ycl.domain.form.ProjectProgressStatisticsForm; import com.ycl.domain.vo.ProjectInfoVO; import com.ycl.domain.vo.ProjectVO; import com.ycl.mapper.ProjectInfoMapper; import com.ycl.service.IndexHomeService; import com.ycl.service.ProjectInfoService; import com.ycl.service.ProjectProcessService; import com.ycl.system.mapper.SysDeptMapper; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.*; import java.util.stream.Collectors; /** * nongtou-project-java * 首页实现类 * * @author : zxl * @date : 2025-11-26 16:51 **/ @Service @RequiredArgsConstructor public class IndexHomeServiceImpl implements IndexHomeService { private final SysDeptMapper sysDeptMapper; private final ProjectInfoMapper projectInfoMapper; @Override public Result projectCodingStatusCount() { //权限控制 Long userId = SecurityUtils.getUserId(); List list; if (SecurityUtils.isAdmin(userId)){ //查询全部 list = new LambdaQueryChainWrapper<>(projectInfoMapper) .eq(ProjectInfo::getDeleted, Boolean.FALSE) .eq(ProjectInfo::getUsedStatus, 2) //审核通过 .list(); }else{ String ancestors = sysDeptMapper.selectAncestors(userId); String[] ancestorArr = ancestors.split(","); List ancestorList = Arrays.stream(ancestorArr).collect(Collectors.toList()); ancestorList.add(SecurityUtils.getDeptId() + ""); //获得本单位以及其子单位deptId; list = new LambdaQueryChainWrapper<>(projectInfoMapper) .eq(ProjectInfo::getDeleted, Boolean.FALSE) .eq(ProjectInfo::getUsedStatus, 2) //审核通过 .in(ProjectInfo::getProjectOwnerUnit, ancestorList) .list(); } Map map = new HashMap<>(); map.put(ProcessOverTimeConstants.GREEN,0); map.put(ProcessOverTimeConstants.YELLOW,0); map.put(ProcessOverTimeConstants.RED,0); map.put("total",0); if (CollectionUtils.isEmpty(list)) { //返回默认值 return Result.ok().data(map); } Map> collect = list.stream() .filter(project -> project.getCoding() != null) // 过滤coding为null的情况 .collect(Collectors.groupingBy(ProjectInfo::getCoding)); if (collect.containsKey(ProcessOverTimeConstants.GREEN)) { map.put(ProcessOverTimeConstants.GREEN, collect.get(ProcessOverTimeConstants.GREEN).size()); } if (collect.containsKey(ProcessOverTimeConstants.YELLOW)) { map.put(ProcessOverTimeConstants.YELLOW, collect.get(ProcessOverTimeConstants.YELLOW).size()); } if (collect.containsKey(ProcessOverTimeConstants.RED)) { map.put(ProcessOverTimeConstants.RED, collect.get(ProcessOverTimeConstants.RED).size()); } map.put("total", list.size()); return Result.ok().data(map); } @Override public Result projectStageCount() { List projectVOS = projectInfoMapper.homeCount(new BaseEntity()); int reserve = 0; int previous = 0; int implement = 0; int finish = 0; for (ProjectVO projectVO : projectVOS) { if (ProjectCategoryEnum.RESERVE.getDesc().equals(ProjectCategoryEnum.getPhaseByProjectStatus(projectVO.getProjectPhase()))) { reserve+=1; } else if (ProjectCategoryEnum.PREVIOUS.getDesc().equals(ProjectCategoryEnum.getPhaseByProjectStatus(projectVO.getProjectPhase()))) { previous+=1; } else if (ProjectCategoryEnum.IMPLEMENT.getDesc().equals(ProjectCategoryEnum.getPhaseByProjectStatus(projectVO.getProjectPhase()))) { implement+=1; } else if (ProjectCategoryEnum.FINISH.getDesc().equals(ProjectCategoryEnum.getPhaseByProjectStatus(projectVO.getProjectPhase()))) { finish+=1; } } Map map = new HashMap<>(); map.put(ProjectCategoryEnum.RESERVE.getCode(),reserve); map.put(ProjectCategoryEnum.PREVIOUS.getCode(),previous); map.put(ProjectCategoryEnum.IMPLEMENT.getCode(),implement); map.put(ProjectCategoryEnum.FINISH.getCode(),finish); return Result.ok().data(map); } @Override public Result projectTaskStatus(ProjectProgressStatisticsForm form) { return null; } @Override @DataScope(deptAlias = "d") public Result projectFundingStatus( ) { List projectInfoAndFunding = projectInfoMapper.getProjectInfoAndFunding(new BaseEntity()); return Result.ok().data(projectInfoAndFunding); } @Override public Result projectAdvanceCheckPoint() { return null; } }