StatPrimaryService.java
8.32 KB
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
package com.gsc4cloud.gsc.multidata.service.primary;
import com.gsc4cloud.gsc.multidata.dto.BusinessCoverageDTO;
import com.gsc4cloud.gsc.multidata.dto.LongCourseCompletionDTO;
import com.gsc4cloud.gsc.multidata.dto.ShortCourseCompletionDTO;
import com.gsc4cloud.gsc.multidata.dto.TabletCountDTO;
import com.gsc4cloud.gsc.multidata.mapper.primary.InspectionBadgeRecordingsMapper;
import com.gsc4cloud.gsc.multidata.utils.DatetimeScopeUtil;
import com.gsc4cloud.gsc.multidata.utils.UsageRateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class StatPrimaryService {
@Value("${zhi.merchant.id:44206988}")
private Integer zhMerchantId;
@Autowired
private InspectionBadgeRecordingsMapper inspectionBadgeRecordingsMapper;
public Double getTabletUsageRate() {
String startTime = DatetimeScopeUtil.getLastMonthStart();
String endTime = DatetimeScopeUtil.getLastMonthEnd();
// 平板月使用率(实际登录人数/发平板的总人数)
// 1. 获取实际登录人数
int actualLoginCount = inspectionBadgeRecordingsMapper.countDistinctBadgeIdsBetweenTimes(startTime, endTime);
// 2. 获取发平板的总人数
int totalAssetManagement = inspectionBadgeRecordingsMapper.countTotalAssetManagement();
log.info("实际登录人数:{},发平板的总人数:{}", actualLoginCount, totalAssetManagement);
// 使用专门的工具类计算使用率
return UsageRateUtil.calculateUsageRate(actualLoginCount, totalAssetManagement);
}
public Double getTabletCoverageRate() {
if (zhMerchantId==null) {
log.error("商户ID为空,无法获取商户信息");
return 0.0;
}
// 平板月覆盖率(发平板的总人数/直营驻店总人数)
// 1. 获取发平板的总人数
int totalAssetManagement = inspectionBadgeRecordingsMapper.countTotalAssetManagement();
// 2. 获取直营驻店总人数
int directStoreEmployeeCount = inspectionBadgeRecordingsMapper.countDistinctDirectStoreEmployees(zhMerchantId);
log.info("发平板的总人数:{},直营驻店总人数:{}", totalAssetManagement, directStoreEmployeeCount);
// 使用专门的工具类计算覆盖率
return UsageRateUtil.calculateUsageRate(totalAssetManagement, directStoreEmployeeCount);
}
public Double getCoverageRate() {
String startTime = DatetimeScopeUtil.getLastMonthStart();
String endTime = DatetimeScopeUtil.getLastMonthEnd();
// 提单月覆盖率(提单人数/轻改业务且有发平板的总人数)
// 1. 获取 提单人数
int actualOrderCount = inspectionBadgeRecordingsMapper.countDistinctWorkOrderNumbersBetweenTimes(startTime, endTime);
// 2. 获取 轻改业务且有发平板的总人数
TabletCountDTO totalAssetManagement = inspectionBadgeRecordingsMapper.countAllBizTotalAssetManagement();
log.info("提单人数:{},轻改业务且有发平板的总人数:{}", actualOrderCount, totalAssetManagement);
return UsageRateUtil.calculateUsageRate(actualOrderCount, totalAssetManagement.getLightUpgradeTabletCount());
}
public Map<String, Double> getBusinessWeekUsageRate() {
String startTime = DatetimeScopeUtil.getLastWeekStart();
String endTime = DatetimeScopeUtil.getLastWeekEnd();
// 获取各业务类型的平板使用人数
List<BusinessCoverageDTO> businessCoverageList = inspectionBadgeRecordingsMapper.getBusinessCoverageList(startTime, endTime);
// 获取各种类型的平板总数
TabletCountDTO tabletCountDTO = inspectionBadgeRecordingsMapper.countAllBizTotalAssetManagement();
// 计算各业务的覆盖率
Map<String, Double> coverageRates = new HashMap<>();
// 初始化三个业务的覆盖率为0.0
coverageRates.put("light_upgrade", 0.0);
coverageRates.put("warranty", 0.0);
coverageRates.put("equity", 0.0);
for (BusinessCoverageDTO coverage : businessCoverageList) {
String businessType = coverage.getCheckTypeLabel();
int userCount = coverage.getTabletUserCount();
// 根据业务类型获取对应的总平板数
int totalTablets = 0;
switch (businessType) {
case "light_upgrade":
totalTablets = tabletCountDTO.getLightUpgradeTabletCount() != null ? tabletCountDTO.getLightUpgradeTabletCount() : 0;
break;
case "warranty":
totalTablets = tabletCountDTO.getWarrantyTabletCount() != null ? tabletCountDTO.getWarrantyTabletCount() : 0;
break;
case "equity":
totalTablets = tabletCountDTO.getEquityTabletCount() != null ? tabletCountDTO.getEquityTabletCount() : 0;
break;
default:
// 对于未知业务类型,暂时跳过
continue;
}
// 计算覆盖率
double coverageRate = UsageRateUtil.calculateUsageRate(userCount, totalTablets);
coverageRates.put(businessType, coverageRate);
}
return coverageRates;
}
public Double getLongCourseCompletionRate() {
String startTime = DatetimeScopeUtil.getLastMonthStart();
String endTime = DatetimeScopeUtil.getLastMonthEnd();
// 长课程月学习完成率(已完成观看长课程数量/下发长课程数量)
LongCourseCompletionDTO completionDTO = inspectionBadgeRecordingsMapper.getLongCourseCompletion(startTime, endTime);
if (completionDTO == null) {
return 0.0;
}
log.info("长课程总数:{},已完成长课程数:{}", completionDTO.getTotalCourseCount(), completionDTO.getCompletedCourseCount());
return UsageRateUtil.calculateUsageRate(
completionDTO.getCompletedCourseCount() != null ? completionDTO.getCompletedCourseCount() : 0,
completionDTO.getTotalCourseCount() != null ? completionDTO.getTotalCourseCount() : 0
);
}
public Double getShortCourseCompletionRate() {
String startTime = DatetimeScopeUtil.getLastMonthStart();
String endTime = DatetimeScopeUtil.getLastMonthEnd();
// 短课程月学习完成率(已完成观看短课程数量/下发短课程数量)
ShortCourseCompletionDTO completionDTO = inspectionBadgeRecordingsMapper.getShortCourseCompletion(startTime, endTime);
if (completionDTO == null) {
return 0.0;
}
log.info("短课程总数:{},已完成短课程数:{}", completionDTO.getTotalCourseCount(), completionDTO.getCompletedCourseCount());
return UsageRateUtil.calculateUsageRate(
completionDTO.getCompletedCourseCount() != null ? completionDTO.getCompletedCourseCount() : 0,
completionDTO.getTotalCourseCount() != null ? completionDTO.getTotalCourseCount() : 0
);
}
public Double getExhibitionCoverageRate() {
// 展业门店覆盖率(展业门店数/总门店数)
// 1. 获取展业门店数(scene=7且subMerchantType=7)
Integer exhibitionMerchantCount = inspectionBadgeRecordingsMapper.countDistinctExhibitionMerchants();
// 2. 获取总门店数(subMerchantType=7)
Integer totalMerchantCount = inspectionBadgeRecordingsMapper.countDistinctTotalMerchants();
log.info("展业门店数:{},总门店数:{}", exhibitionMerchantCount, totalMerchantCount);
// 使用专门的工具类计算覆盖率
return UsageRateUtil.calculateUsageRate(
exhibitionMerchantCount != null ? exhibitionMerchantCount : 0,
totalMerchantCount != null ? totalMerchantCount : 0
);
}
/**
* 获取各业务下平板总数
* @return 平板总数DTO
*/
public TabletCountDTO getAllBizTabletCount() {
return inspectionBadgeRecordingsMapper.countAllBizTotalAssetManagement();
}
}