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 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 queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(StandingBook::getCompanyId, companyId); queryWrapper.eq(StandingBook::getDelFlag, 0); List 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 queryWrapper1 = new LambdaQueryWrapper<>(); queryWrapper1.eq(AnnualVerificationPlan::getCompanyId, companyId).eq(AnnualVerificationPlan::getDelFlag, 0).eq(AnnualVerificationPlan::getYear, year); List annualVerificationPlans = annualVerificationPlanMapper.selectList(queryWrapper1); if (!annualVerificationPlans.isEmpty()) { AnnualVerificationPlan annualVerificationPlan = annualVerificationPlans.get(0); LambdaQueryWrapper queryWrapper2 = new LambdaQueryWrapper<>(); queryWrapper2.eq(AnnualVerificationDevice::getAnnualVerificationId, annualVerificationPlan.getId()).eq(AnnualVerificationDevice::getDelFlag, 0).eq(AnnualVerificationDevice::getPlanType, 2); List annualVerificationDevices = annualVerificationDeviceMapper.selectList(queryWrapper2); companyStatisticsVo.setDetectionEquipment(annualVerificationDevices.size()); queryWrapper2.between(AnnualVerificationDevice::getCreateTime, yearBegin, yearEnd); List annualVerificationDevices1 = annualVerificationDeviceMapper.selectList(queryWrapper2); companyStatisticsVo.setDetectionEquipmentAdd(annualVerificationDevices1.size()); } else { companyStatisticsVo.setDetectionEquipment(0); } LambdaQueryWrapper queryWrapper3 = new LambdaQueryWrapper<>(); queryWrapper3.eq(CompanyQualityPolicy::getCompanyId, companyId).eq(CompanyQualityPolicy::getDelFlag, 1); List qualities = companyQualityPolicyMapper.selectList(queryWrapper3); if (!qualities.isEmpty()) { companyStatisticsVo.setCompanyQualityPolicy(qualities.get(0).getPolicy()); } LambdaQueryWrapper queryWrapper4 = new LambdaQueryWrapper<>(); queryWrapper4.eq(Quality::getCompanyId, companyId).eq(Quality::getDelFlag, 1).eq(Quality::getYear, year); List qualities1 = qualityMapper.selectList(queryWrapper4); if (!qualities1.isEmpty()) { LambdaQueryWrapper queryWrapper5 = new LambdaQueryWrapper<>(); queryWrapper5.eq(QualityTarget::getQualityId, qualities1.get(0).getId()).eq(QualityTarget::getDelFlag, 1).orderByDesc(QualityTarget::getCreateTime); List qualityTargets = qualityTargetMapper.selectList(queryWrapper5); if (!qualityTargets.isEmpty()) { List collect = qualityTargets.stream().map(QualityTarget::getMessage).collect(Collectors.toList()); companyStatisticsVo.setCompanyQualityTarget(collect); } } LambdaQueryWrapper queryWrapper6 = new LambdaQueryWrapper<>(); queryWrapper6.eq(ContractLedger::getCompanyId, companyId).eq(ContractLedger::getDelFlag, 1).between(ContractLedger::getSignDate, yearBegin, yearEnd); List 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 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 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 queryWrapper9 = new LambdaQueryWrapper<>(); queryWrapper9.eq(TrainPlan::getCompanyId, companyId).eq(TrainPlan::getDelFlag, 1).between(TrainPlan::getTrainTime, yearBegin, yearEnd); List 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 queryWrapper10 = new LambdaQueryWrapper<>(); queryWrapper10.eq(OutsourcedProduct::getCompanyId, companyId).eq(OutsourcedProduct::getDelFlag, 0) .between(OutsourcedProduct::getCreateTime, yearBegin, yearEnd); List 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 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; } }