“djh”
2025-11-26 cf4a5deced71464d424ce5931774f6df0c4c6bb3
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.system.domain.*;
import com.gkhy.exam.system.domain.req.EmployeeRecordReq;
import com.gkhy.exam.system.domain.vo.EmployeeRecordVO;
import com.gkhy.exam.system.domain.vo.statistic.CompanyStatisticsVo;
import com.gkhy.exam.system.mapper.*;
import com.gkhy.exam.system.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class StatisticsServiceImpl implements StatisticsService {
 
    @Autowired
    private CompanySummaryMapper companySummaryMapper;
    @Autowired
    private EmployeeRecordMapper employeeRecordMapper;
 
    @Autowired
    private StandingBookMapper standingBookMapper;
 
    @Autowired
    private AnnualVerificationPlanMapper annualVerificationPlanMapper;
 
    @Autowired
    private AnnualVerificationDeviceMapper annualVerificationDeviceMapper;
    @Autowired
    private CompanyQualityPolicyMapper companyQualityPolicyMapper;
 
    @Autowired
    private QualityMapper qualityMapper;
    @Autowired
    private QualityTargetMapper qualityTargetMapper;
 
    @Autowired
    private ContractLedgerMapper contractLedgerMapper;
 
    @Autowired
    private AnnualReportMapper annualReportMapper;
 
    @Autowired
    private InternalKnowledgeMapper internalKnowledgeMapper;
 
    @Autowired
    private TrainPlanMapper trainPlanMapper;
 
    @Autowired
    private InternalAuditCheckMapper internalAuditCheckMapper;
 
    @Autowired
    private ContinuousImproveMapper continuousImproveMapper;
 
    @Autowired
    private OutsourcedProductMapper outsourcedProductMapper;
 
    @Override
    public CompanyStatisticsVo getCompanyStatistics(Integer companyId, String year) {
 
        String yearBegin = year + "-01-01 00:00:00";
        String yearEnd = year + "-12-31 23:59:59";
 
        CompanyStatisticsVo companyStatisticsVo = companySummaryMapper.selectCompanyStatistics(companyId);
        if (companyStatisticsVo == null) {
            return companyStatisticsVo;
        }
        companyStatisticsVo.setYear(year);
        EmployeeRecordReq req = new EmployeeRecordReq();
        req.setCompanyId(companyId.longValue());
        List<EmployeeRecordVO> sysUsers = employeeRecordMapper.selectEmployeeRecordList(req);
        int totalUser = sysUsers.size();
        long countJS = sysUsers.stream()
                .filter(user -> user.getPersonType() != null)
                .filter(user -> user.getPersonType() == 1)  // 技术类
                .count();
        companyStatisticsVo.setTotalEmployee(totalUser);
        companyStatisticsVo.setProfessionalEmployee(
                countJS > 0 ? (int) countJS : 0
        );
 
        //企业资源和能力情况
 
        LambdaQueryWrapper<StandingBook> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StandingBook::getCompanyId, companyId);
        queryWrapper.eq(StandingBook::getDelFlag, 0);
        List<StandingBook> standingBooks = standingBookMapper.selectList(queryWrapper);
        //计算计算机总数
        long computerTotal = standingBooks.stream()
                .filter(st -> st.getDeviceType() != null)
                .filter(st -> st.getDeviceType() == 1)
                .count();
        //生成设备
        long productionEquipment = standingBooks.stream()
                .filter(st -> st.getDeviceType() != null)
                .filter(st -> st.getDeviceType() == 5)
                .count();
        companyStatisticsVo.setComputerTotal(computerTotal > 0 ? (int) computerTotal : 0);
        companyStatisticsVo.setProductionEquipment(productionEquipment > 0 ? (int) productionEquipment : 0);
        companyStatisticsVo.setOtherOfficeEquipment(standingBooks.size() - (int) computerTotal - (int) productionEquipment);
 
        LambdaQueryWrapper<AnnualVerificationPlan> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(AnnualVerificationPlan::getCompanyId, companyId).eq(AnnualVerificationPlan::getDelFlag, 0).eq(AnnualVerificationPlan::getYear, year);
        List<AnnualVerificationPlan> annualVerificationPlans = annualVerificationPlanMapper.selectList(queryWrapper1);
        if (!annualVerificationPlans.isEmpty()) {
            AnnualVerificationPlan annualVerificationPlan = annualVerificationPlans.get(0);
            LambdaQueryWrapper<AnnualVerificationDevice> queryWrapper2 = new LambdaQueryWrapper<>();
            queryWrapper2.eq(AnnualVerificationDevice::getAnnualVerificationId, annualVerificationPlan.getId()).eq(AnnualVerificationDevice::getDelFlag, 0).eq(AnnualVerificationDevice::getPlanType, 2);
            List<AnnualVerificationDevice> annualVerificationDevices = annualVerificationDeviceMapper.selectList(queryWrapper2);
            companyStatisticsVo.setDetectionEquipment(annualVerificationDevices.size());
            queryWrapper2.between(AnnualVerificationDevice::getCreateTime, yearBegin, yearEnd);
            List<AnnualVerificationDevice> annualVerificationDevices1 = annualVerificationDeviceMapper.selectList(queryWrapper2);
            companyStatisticsVo.setDetectionEquipmentAdd(annualVerificationDevices1.size());
        } else {
            companyStatisticsVo.setDetectionEquipment(0);
        }
 
        LambdaQueryWrapper<CompanyQualityPolicy> queryWrapper3 = new LambdaQueryWrapper<>();
        queryWrapper3.eq(CompanyQualityPolicy::getCompanyId, companyId).eq(CompanyQualityPolicy::getDelFlag, 1);
        List<CompanyQualityPolicy> qualities = companyQualityPolicyMapper.selectList(queryWrapper3);
        if (!qualities.isEmpty()) {
            companyStatisticsVo.setCompanyQualityPolicy(qualities.get(0).getPolicy());
        }
 
 
        LambdaQueryWrapper<Quality> queryWrapper4 = new LambdaQueryWrapper<>();
        queryWrapper4.eq(Quality::getCompanyId, companyId).eq(Quality::getDelFlag, 1).eq(Quality::getYear, year);
        List<Quality> qualities1 = qualityMapper.selectList(queryWrapper4);
        if (!qualities1.isEmpty()) {
            LambdaQueryWrapper<QualityTarget> queryWrapper5 = new LambdaQueryWrapper<>();
            queryWrapper5.eq(QualityTarget::getQualityId, qualities1.get(0).getId()).eq(QualityTarget::getDelFlag, 1).orderByDesc(QualityTarget::getCreateTime);
            List<QualityTarget> qualityTargets = qualityTargetMapper.selectList(queryWrapper5);
            if (!qualityTargets.isEmpty()) {
                List<String> collect = qualityTargets.stream().map(QualityTarget::getMessage).collect(Collectors.toList());
                companyStatisticsVo.setCompanyQualityTarget(collect);
            }
        }
        LambdaQueryWrapper<ContractLedger> queryWrapper6 = new LambdaQueryWrapper<>();
        queryWrapper6.eq(ContractLedger::getCompanyId, companyId).eq(ContractLedger::getDelFlag, 1).between(ContractLedger::getSignDate, yearBegin, yearEnd);
 
        List<ContractLedger> contractLedgers = contractLedgerMapper.selectList(queryWrapper6);
        companyStatisticsVo.setContractLedger(contractLedgers.size());
        if (!contractLedgers.isEmpty()) {
            Long count = contractLedgers.stream().filter(contractLedger -> contractLedger.getDeliver() == 1).count();
            companyStatisticsVo.setDeliveredContract(count.intValue());
        } else {
            companyStatisticsVo.setDeliveredContract(0);
        }
        //满意度
        LambdaQueryWrapper<AnnualReport> queryWrapper7 = new LambdaQueryWrapper<>();
        queryWrapper7.eq(AnnualReport::getCompanyId, companyId).eq(AnnualReport::getDelFlag, 1).eq(AnnualReport::getYear, year);
        AnnualReport annualReport = annualReportMapper.selectOne(queryWrapper7);
        if (annualReport != null) {
            companyStatisticsVo.setSumSatisficing(annualReport.getSumSatisficing());
        } else {
            companyStatisticsVo.setSumSatisficing("0");
        }
        //只是产权数量
        LambdaQueryWrapper<InternalKnowledge> queryWrapper8 = new LambdaQueryWrapper<>();
        queryWrapper8.eq(InternalKnowledge::getCompanyId, companyId).eq(InternalKnowledge::getDelFlag, 0)
                .between(InternalKnowledge::getCreateTime, yearBegin, yearEnd);
        Long l = internalKnowledgeMapper.selectCount(queryWrapper8);
        companyStatisticsVo.setPatent(l.intValue());
        //培训计划名称
        LambdaQueryWrapper<TrainPlan> queryWrapper9 = new LambdaQueryWrapper<>();
        queryWrapper9.eq(TrainPlan::getCompanyId, companyId).eq(TrainPlan::getDelFlag, 1).between(TrainPlan::getTrainTime, yearBegin, yearEnd);
        List<TrainPlan> trainPlans = trainPlanMapper.selectList(queryWrapper9);
        if (!trainPlans.isEmpty()) {
            String courseNames = trainPlans.stream()
                    .map(TrainPlan::getTrainName)
                    .collect(Collectors.joining(","));
            companyStatisticsVo.setTrainPlanName(courseNames);
        }
        //内审检查不符合
        int statisticData = internalAuditCheckMapper.getStatisticData(companyId, yearBegin, yearEnd);
        companyStatisticsVo.setInternalAuditCheckResult(statisticData);
        //改进项
        int conStatistic = continuousImproveMapper.getConStatistic(companyId, year);
        companyStatisticsVo.setConStatisticNum(conStatistic);
        LambdaQueryWrapper<OutsourcedProduct> queryWrapper10 = new LambdaQueryWrapper<>();
        queryWrapper10.eq(OutsourcedProduct::getCompanyId, companyId).eq(OutsourcedProduct::getDelFlag, 0)
                .between(OutsourcedProduct::getCreateTime, yearBegin, yearEnd);
        List<OutsourcedProduct> outsourcedProducts = outsourcedProductMapper.selectList(queryWrapper10);
        if (!outsourcedProducts.isEmpty()){
            String ps = outsourcedProducts.stream()
                    .map(OutsourcedProduct::getProductName)
                    .collect(Collectors.joining(","));
            companyStatisticsVo.setOutsourcedProduct(ps);
        }
 
        req.setCompanyId(companyId.longValue());
        req.setStartTime(yearBegin);
        req.setEndTime(yearEnd);
        List<EmployeeRecordVO> sysUsersAdd = employeeRecordMapper.selectEmployeeRecordList(req);
        int totalUserAdd = sysUsersAdd.size();
        long countJSAdd = sysUsersAdd.stream()
                .filter(user -> user.getPersonType() != null)
                .filter(user -> user.getPersonType() == 1)  // 技术类
                .count();
        companyStatisticsVo.setTotalEmployeeAdd(totalUserAdd);
        companyStatisticsVo.setProfessionalEmployeeAdd(
                countJSAdd > 0 ? (int) countJSAdd : 0
        );
 
        queryWrapper9.eq(TrainPlan::getStatus, 0);
        Long l1 = trainPlanMapper.selectCount(queryWrapper9);
        companyStatisticsVo.setTrainPlanCompleted(l1.intValue());
 
        return companyStatisticsVo;
    }
 
}