zxl
11 小时以前 fa90edeeb9396b8a8031f7fb14cc30c4386cc1db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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<ProjectInfo> 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<String> 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<String,Integer> 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<String, List<ProjectInfo>> 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<ProjectVO> 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<String,Integer> 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<ProjectInfoVO> projectInfoAndFunding = projectInfoMapper.getProjectInfoAndFunding(new BaseEntity());
        return Result.ok().data(projectInfoAndFunding);
    }
 
    @Override
    public Result projectAdvanceCheckPoint() {
        return null;
    }
}