|
|
@@ -51,10 +51,10 @@ public class QualificationLevelStatsController extends BaseController {
|
|
51
|
51
|
|
|
52
|
52
|
|
|
53
|
53
|
/**
|
|
54
|
|
- * 固定的资质等级列表(一级到五级)
|
|
|
54
|
+ * 固定的资质等级列表(初级、中级、高级)
|
|
55
|
55
|
*/
|
|
56
|
56
|
private static final List<String> QUALIFICATION_LEVELS = Arrays.asList(
|
|
57
|
|
- "一级", "二级", "三级", "四级", "五级"
|
|
|
57
|
+ "初级", "中级", "高级"
|
|
58
|
58
|
);
|
|
59
|
59
|
|
|
60
|
60
|
/**
|
|
|
@@ -120,31 +120,49 @@ public class QualificationLevelStatsController extends BaseController {
|
|
120
|
120
|
List<QualificationLevelStatsDTO.LevelDistribution> distributions = new ArrayList<>();
|
|
121
|
121
|
int totalPersons = 0;
|
|
122
|
122
|
|
|
123
|
|
- // 统计实际存在的等级数据
|
|
124
|
|
- Map<String, QualificationStats> statsMap = statsList.stream()
|
|
|
123
|
+ // 统计实际存在的等级数据,按数据库存储的枚举值分组
|
|
|
124
|
+ Map<String, Integer> levelCountMap = statsList.stream()
|
|
125
|
125
|
.collect(Collectors.toMap(
|
|
126
|
|
- stat -> QualificationLevelConverter.toDisplay(stat.getLevelName()),
|
|
127
|
|
- s -> s
|
|
|
126
|
+ QualificationStats::getLevelName,
|
|
|
127
|
+ QualificationStats::getCount,
|
|
|
128
|
+ Integer::sum
|
|
128
|
129
|
));
|
|
129
|
130
|
|
|
130
|
|
- // 按固定顺序处理所有等级
|
|
131
|
|
- for (String levelName : QUALIFICATION_LEVELS) {
|
|
132
|
|
- QualificationLevelStatsDTO.LevelDistribution distribution = new QualificationLevelStatsDTO.LevelDistribution();
|
|
133
|
|
- distribution.setLevelName(levelName);
|
|
134
|
|
-
|
|
135
|
|
- QualificationStats stats = statsMap.get(levelName);
|
|
136
|
|
- if (stats != null) {
|
|
137
|
|
- distribution.setCount(stats.getCount());
|
|
138
|
|
- distribution.setPercentage(new BigDecimal(stats.getPercentage()).setScale(2, RoundingMode.HALF_UP));
|
|
139
|
|
- totalPersons += stats.getCount();
|
|
140
|
|
- } else {
|
|
141
|
|
- // 该等级无人
|
|
142
|
|
- distribution.setCount(0);
|
|
143
|
|
- distribution.setPercentage(BigDecimal.ZERO);
|
|
144
|
|
- }
|
|
145
|
|
-
|
|
146
|
|
- distributions.add(distribution);
|
|
147
|
|
- }
|
|
|
131
|
+ // 按(初级、中级、高级)分组统计
|
|
|
132
|
+ int juniorCount = levelCountMap.getOrDefault("LEVEL_FIVE", 0); // 初级
|
|
|
133
|
+ int intermediateCount = levelCountMap.getOrDefault("LEVEL_FOUR", 0); // 中级
|
|
|
134
|
+ int seniorCount = levelCountMap.getOrDefault("LEVEL_ONE", 0) +
|
|
|
135
|
+ levelCountMap.getOrDefault("LEVEL_TWO", 0) +
|
|
|
136
|
+ levelCountMap.getOrDefault("LEVEL_THREE", 0); // 高级
|
|
|
137
|
+
|
|
|
138
|
+ totalPersons = userIds.size();
|
|
|
139
|
+
|
|
|
140
|
+ // 初级
|
|
|
141
|
+ QualificationLevelStatsDTO.LevelDistribution juniorDist = new QualificationLevelStatsDTO.LevelDistribution();
|
|
|
142
|
+ juniorDist.setLevelName("初级");
|
|
|
143
|
+ juniorDist.setCount(juniorCount);
|
|
|
144
|
+ juniorDist.setPercentage(totalPersons > 0 ?
|
|
|
145
|
+ new BigDecimal(juniorCount * 100.0 / totalPersons).setScale(2, RoundingMode.HALF_UP) :
|
|
|
146
|
+ BigDecimal.ZERO);
|
|
|
147
|
+ distributions.add(juniorDist);
|
|
|
148
|
+
|
|
|
149
|
+ // 中级
|
|
|
150
|
+ QualificationLevelStatsDTO.LevelDistribution intermediateDist = new QualificationLevelStatsDTO.LevelDistribution();
|
|
|
151
|
+ intermediateDist.setLevelName("中级");
|
|
|
152
|
+ intermediateDist.setCount(intermediateCount);
|
|
|
153
|
+ intermediateDist.setPercentage(totalPersons > 0 ?
|
|
|
154
|
+ new BigDecimal(intermediateCount * 100.0 / totalPersons).setScale(2, RoundingMode.HALF_UP) :
|
|
|
155
|
+ BigDecimal.ZERO);
|
|
|
156
|
+ distributions.add(intermediateDist);
|
|
|
157
|
+
|
|
|
158
|
+ // 高级
|
|
|
159
|
+ QualificationLevelStatsDTO.LevelDistribution seniorDist = new QualificationLevelStatsDTO.LevelDistribution();
|
|
|
160
|
+ seniorDist.setLevelName("高级");
|
|
|
161
|
+ seniorDist.setCount(seniorCount);
|
|
|
162
|
+ seniorDist.setPercentage(totalPersons > 0 ?
|
|
|
163
|
+ new BigDecimal(seniorCount * 100.0 / totalPersons).setScale(2, RoundingMode.HALF_UP) :
|
|
|
164
|
+ BigDecimal.ZERO);
|
|
|
165
|
+ distributions.add(seniorDist);
|
|
148
|
166
|
|
|
149
|
167
|
pieChart.setData(distributions);
|
|
150
|
168
|
pieChart.setTotalPersons(totalPersons);
|
|
|
@@ -243,21 +261,38 @@ public class QualificationLevelStatsController extends BaseController {
|
|
243
|
261
|
}
|
|
244
|
262
|
|
|
245
|
263
|
/**
|
|
246
|
|
- * 将资质统计转换为等级人数数据
|
|
|
264
|
+ * 将资质统计转换为等级人数数据(初级、中级、高级)
|
|
247
|
265
|
*/
|
|
248
|
266
|
private List<QualificationLevelStatsDTO.LevelCount> convertToLevelCounts(List<QualificationStats> statsList) {
|
|
|
267
|
+ // 按数据库存储的枚举值分组统计
|
|
249
|
268
|
Map<String, Integer> countMap = statsList.stream()
|
|
250
|
269
|
.collect(Collectors.toMap(QualificationStats::getLevelName, QualificationStats::getCount));
|
|
251
|
270
|
|
|
252
|
|
- return QUALIFICATION_LEVELS.stream()
|
|
253
|
|
- .map(level -> {
|
|
254
|
|
- String levelName = QualificationLevelConverter.toDatabase(level);
|
|
255
|
|
- QualificationLevelStatsDTO.LevelCount count = new QualificationLevelStatsDTO.LevelCount();
|
|
256
|
|
- count.setLevelName(level);
|
|
257
|
|
- count.setCount(countMap.getOrDefault(levelName, 0));
|
|
258
|
|
- return count;
|
|
259
|
|
- })
|
|
260
|
|
- .collect(Collectors.toList());
|
|
|
271
|
+ // 计算初级、中级、高级的人数
|
|
|
272
|
+ int juniorCount = countMap.getOrDefault("LEVEL_FIVE", 0); // 初级
|
|
|
273
|
+ int intermediateCount = countMap.getOrDefault("LEVEL_FOUR", 0); // 中级
|
|
|
274
|
+ int seniorCount = countMap.getOrDefault("LEVEL_ONE", 0) +
|
|
|
275
|
+ countMap.getOrDefault("LEVEL_TWO", 0) +
|
|
|
276
|
+ countMap.getOrDefault("LEVEL_THREE", 0); // 高级
|
|
|
277
|
+
|
|
|
278
|
+ List<QualificationLevelStatsDTO.LevelCount> levelCounts = new ArrayList<>();
|
|
|
279
|
+
|
|
|
280
|
+ QualificationLevelStatsDTO.LevelCount junior = new QualificationLevelStatsDTO.LevelCount();
|
|
|
281
|
+ junior.setLevelName("初级");
|
|
|
282
|
+ junior.setCount(juniorCount);
|
|
|
283
|
+ levelCounts.add(junior);
|
|
|
284
|
+
|
|
|
285
|
+ QualificationLevelStatsDTO.LevelCount intermediate = new QualificationLevelStatsDTO.LevelCount();
|
|
|
286
|
+ intermediate.setLevelName("中级");
|
|
|
287
|
+ intermediate.setCount(intermediateCount);
|
|
|
288
|
+ levelCounts.add(intermediate);
|
|
|
289
|
+
|
|
|
290
|
+ QualificationLevelStatsDTO.LevelCount senior = new QualificationLevelStatsDTO.LevelCount();
|
|
|
291
|
+ senior.setLevelName("高级");
|
|
|
292
|
+ senior.setCount(seniorCount);
|
|
|
293
|
+ levelCounts.add(senior);
|
|
|
294
|
+
|
|
|
295
|
+ return levelCounts;
|
|
261
|
296
|
}
|
|
262
|
297
|
|
|
263
|
298
|
|