|
|
@@ -13,7 +13,11 @@ import com.ruoyi.web.modules.prosperity.domain.vo.AchievementAnnualSummaryVo;
|
|
13
|
13
|
import com.ruoyi.web.modules.prosperity.domain.vo.AchievementMonthlyVo;
|
|
14
|
14
|
|
|
15
|
15
|
/**
|
|
16
|
|
- * 年度报告数据组装与汇总计算(纯逻辑,便于单测)。
|
|
|
16
|
+ * 年度报告 / 大屏共同富裕成果组装(口径一致):
|
|
|
17
|
+ * <ul>
|
|
|
18
|
+ * <li>按月序列:所选年 1~库中最大统计月,缺月补 0</li>
|
|
|
19
|
+ * <li>总览:最大统计月的单月指标</li>
|
|
|
20
|
+ * </ul>
|
|
17
|
21
|
*/
|
|
18
|
22
|
public final class AchievementReportAggregator
|
|
19
|
23
|
{
|
|
|
@@ -41,42 +45,65 @@ public final class AchievementReportAggregator
|
|
41
|
45
|
}
|
|
42
|
46
|
}
|
|
43
|
47
|
|
|
|
48
|
+ /**
|
|
|
49
|
+ * 所选年内台账的最大统计月;无有效行返回 0。
|
|
|
50
|
+ */
|
|
|
51
|
+ public static int resolveMaxMonth(int statYear, List<BizCommonProsperityAchievement> rows)
|
|
|
52
|
+ {
|
|
|
53
|
+ int maxMonth = 0;
|
|
|
54
|
+ if (rows == null)
|
|
|
55
|
+ {
|
|
|
56
|
+ return 0;
|
|
|
57
|
+ }
|
|
|
58
|
+ String yearPrefix = String.valueOf(statYear) + "-";
|
|
|
59
|
+ for (BizCommonProsperityAchievement row : rows)
|
|
|
60
|
+ {
|
|
|
61
|
+ if (row == null || StringUtils.isEmpty(row.getStatPeriod())
|
|
|
62
|
+ || !row.getStatPeriod().startsWith(yearPrefix))
|
|
|
63
|
+ {
|
|
|
64
|
+ continue;
|
|
|
65
|
+ }
|
|
|
66
|
+ int month = parseMonthFromStatPeriod(row.getStatPeriod());
|
|
|
67
|
+ if (month >= 1 && month <= 12 && month > maxMonth)
|
|
|
68
|
+ {
|
|
|
69
|
+ maxMonth = month;
|
|
|
70
|
+ }
|
|
|
71
|
+ }
|
|
|
72
|
+ return maxMonth;
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
44
|
75
|
public static AchievementAnnualReportVo buildReport(int statYear, List<BizCommonProsperityAchievement> rows)
|
|
45
|
76
|
{
|
|
46
|
77
|
AchievementAnnualReportVo report = new AchievementAnnualReportVo();
|
|
47
|
78
|
report.setStatYear(statYear);
|
|
48
|
|
- boolean hasData = rows != null && !rows.isEmpty();
|
|
|
79
|
+ boolean hasData = rows != null && !rows.isEmpty() && resolveMaxMonth(statYear, rows) > 0;
|
|
49
|
80
|
report.setHasData(hasData);
|
|
50
|
81
|
List<AchievementMonthlyVo> monthly = buildMonthly(statYear, rows);
|
|
51
|
82
|
report.setMonthly(monthly);
|
|
52
|
|
- report.setSummary(hasData ? calcSummary(monthly) : null);
|
|
|
83
|
+ report.setSummary(hasData ? calcSummaryFromMaxMonth(statYear, rows) : null);
|
|
53
|
84
|
return report;
|
|
54
|
85
|
}
|
|
55
|
86
|
|
|
|
87
|
+ /**
|
|
|
88
|
+ * 所选年 1~库中最大月;无数据返回空列表。
|
|
|
89
|
+ */
|
|
56
|
90
|
public static List<AchievementMonthlyVo> buildMonthly(int statYear, List<BizCommonProsperityAchievement> rows)
|
|
57
|
91
|
{
|
|
58
|
|
- Map<Integer, BizCommonProsperityAchievement> byMonth = new HashMap<>();
|
|
59
|
|
- if (rows != null)
|
|
|
92
|
+ Map<Integer, BizCommonProsperityAchievement> byMonth = indexByMonth(statYear, rows);
|
|
|
93
|
+ int maxMonth = 0;
|
|
|
94
|
+ for (Integer m : byMonth.keySet())
|
|
60
|
95
|
{
|
|
61
|
|
- for (BizCommonProsperityAchievement row : rows)
|
|
|
96
|
+ if (m != null && m > maxMonth)
|
|
62
|
97
|
{
|
|
63
|
|
- if (row == null || StringUtils.isEmpty(row.getStatPeriod()))
|
|
64
|
|
- {
|
|
65
|
|
- continue;
|
|
66
|
|
- }
|
|
67
|
|
- if (!row.getStatPeriod().startsWith(String.valueOf(statYear) + "-"))
|
|
68
|
|
- {
|
|
69
|
|
- continue;
|
|
70
|
|
- }
|
|
71
|
|
- int month = parseMonthFromStatPeriod(row.getStatPeriod());
|
|
72
|
|
- if (month >= 1 && month <= 12)
|
|
73
|
|
- {
|
|
74
|
|
- byMonth.put(month, row);
|
|
75
|
|
- }
|
|
|
98
|
+ maxMonth = m;
|
|
76
|
99
|
}
|
|
77
|
100
|
}
|
|
78
|
|
- List<AchievementMonthlyVo> monthly = new ArrayList<>(MONTHS_IN_YEAR);
|
|
79
|
|
- for (int m = 1; m <= MONTHS_IN_YEAR; m++)
|
|
|
101
|
+ if (maxMonth <= 0)
|
|
|
102
|
+ {
|
|
|
103
|
+ return new ArrayList<>();
|
|
|
104
|
+ }
|
|
|
105
|
+ List<AchievementMonthlyVo> monthly = new ArrayList<>(maxMonth);
|
|
|
106
|
+ for (int m = 1; m <= maxMonth; m++)
|
|
80
|
107
|
{
|
|
81
|
108
|
BizCommonProsperityAchievement src = byMonth.get(m);
|
|
82
|
109
|
if (src != null)
|
|
|
@@ -141,52 +168,142 @@ public final class AchievementReportAggregator
|
|
141
|
168
|
return monthly;
|
|
142
|
169
|
}
|
|
143
|
170
|
|
|
144
|
|
- public static AchievementAnnualSummaryVo calcSummary(List<AchievementMonthlyVo> monthly)
|
|
|
171
|
+ /**
|
|
|
172
|
+ * 取所选年内台账最大统计月的单月指标;无有效台账返回 {@code null}。
|
|
|
173
|
+ */
|
|
|
174
|
+ public static AchievementAnnualSummaryVo calcSummaryFromMaxMonth(
|
|
|
175
|
+ int statYear, List<BizCommonProsperityAchievement> rows)
|
|
145
|
176
|
{
|
|
|
177
|
+ BizCommonProsperityAchievement latest = findMaxMonthRow(statYear, rows);
|
|
|
178
|
+ if (latest == null)
|
|
|
179
|
+ {
|
|
|
180
|
+ return null;
|
|
|
181
|
+ }
|
|
146
|
182
|
AchievementAnnualSummaryVo summary = new AchievementAnnualSummaryVo();
|
|
147
|
|
- BigDecimal incomeSum = BigDecimal.ZERO;
|
|
148
|
|
- int employmentSum = 0;
|
|
149
|
|
- int jobsSum = 0;
|
|
150
|
|
- int envSum = 0;
|
|
151
|
|
- BigDecimal greenSum = BigDecimal.ZERO;
|
|
152
|
|
- int heritageSum = 0;
|
|
153
|
|
- int integrationSum = 0;
|
|
154
|
|
- int unitySum = 0;
|
|
155
|
|
- BigDecimal digitalSum = BigDecimal.ZERO;
|
|
156
|
|
- int brandCountSum = 0;
|
|
157
|
|
- BigDecimal premiumSum = BigDecimal.ZERO;
|
|
158
|
|
-
|
|
159
|
|
- for (AchievementMonthlyVo item : monthly)
|
|
160
|
|
- {
|
|
161
|
|
- incomeSum = incomeSum.add(nvl(item.getCollectiveEconomyIncome()));
|
|
162
|
|
- employmentSum += nvlInt(item.getEmploymentDrivenCount());
|
|
163
|
|
- jobsSum += nvlInt(item.getNewJobPositions());
|
|
164
|
|
- envSum += nvlInt(item.getEnvProjectCount());
|
|
165
|
|
- greenSum = greenSum.add(nvl(item.getNewGreenArea()));
|
|
166
|
|
- heritageSum += nvlInt(item.getCulturalHeritageCount());
|
|
167
|
|
- integrationSum += nvlInt(item.getEthnicIntegrationProjectCount());
|
|
168
|
|
- unitySum += nvlInt(item.getEthnicUnityActivityCount());
|
|
169
|
|
- digitalSum = digitalSum.add(nvl(item.getDigitalPlatformUsageRate()));
|
|
170
|
|
- brandCountSum += nvlInt(item.getRegionalPublicBrandCount());
|
|
171
|
|
- premiumSum = premiumSum.add(nvl(item.getBrandPremiumRate()));
|
|
172
|
|
- }
|
|
173
|
|
-
|
|
174
|
|
- summary.setCollectiveEconomyIncome(incomeSum.setScale(2, RoundingMode.HALF_UP));
|
|
175
|
|
- summary.setEmploymentDrivenCount(employmentSum);
|
|
176
|
|
- summary.setNewJobPositions(jobsSum);
|
|
177
|
|
- summary.setEnvProjectCount(envSum);
|
|
178
|
|
- summary.setNewGreenArea(greenSum.setScale(2, RoundingMode.HALF_UP));
|
|
179
|
|
- summary.setCulturalHeritageCount(heritageSum);
|
|
180
|
|
- summary.setEthnicIntegrationProjectCount(integrationSum);
|
|
181
|
|
- summary.setEthnicUnityActivityCount(unitySum);
|
|
|
183
|
+ summary.setCollectiveEconomyIncome(nvl(latest.getCollectiveEconomyIncome()).setScale(2, RoundingMode.HALF_UP));
|
|
|
184
|
+ summary.setEmploymentDrivenCount(nvlInt(latest.getEmploymentDrivenCount()));
|
|
|
185
|
+ summary.setNewJobPositions(nvlInt(latest.getNewJobPositions()));
|
|
|
186
|
+ summary.setEnvProjectCount(nvlInt(latest.getEnvProjectCount()));
|
|
|
187
|
+ summary.setNewGreenArea(nvl(latest.getNewGreenArea()).setScale(2, RoundingMode.HALF_UP));
|
|
|
188
|
+ summary.setCulturalHeritageCount(nvlInt(latest.getCulturalHeritageCount()));
|
|
|
189
|
+ summary.setEthnicIntegrationProjectCount(nvlInt(latest.getEthnicIntegrationProjectCount()));
|
|
|
190
|
+ summary.setEthnicUnityActivityCount(nvlInt(latest.getEthnicUnityActivityCount()));
|
|
182
|
191
|
summary.setDigitalPlatformUsageRate(
|
|
183
|
|
- digitalSum.divide(BigDecimal.valueOf(MONTHS_IN_YEAR), RATE_SCALE, RoundingMode.HALF_UP));
|
|
184
|
|
- summary.setRegionalPublicBrandCount(brandCountSum);
|
|
185
|
|
- summary.setBrandPremiumRate(
|
|
186
|
|
- premiumSum.divide(BigDecimal.valueOf(MONTHS_IN_YEAR), RATE_SCALE, RoundingMode.HALF_UP));
|
|
|
192
|
+ nvl(latest.getDigitalPlatformUsageRate()).setScale(RATE_SCALE, RoundingMode.HALF_UP));
|
|
|
193
|
+ summary.setRegionalPublicBrandCount(nvlInt(latest.getRegionalPublicBrandCount()));
|
|
|
194
|
+ summary.setBrandPremiumRate(nvl(latest.getBrandPremiumRate()).setScale(RATE_SCALE, RoundingMode.HALF_UP));
|
|
187
|
195
|
return summary;
|
|
188
|
196
|
}
|
|
189
|
197
|
|
|
|
198
|
+ /**
|
|
|
199
|
+ * @deprecated 使用 {@link #calcSummaryFromMaxMonth(int, List)}
|
|
|
200
|
+ */
|
|
|
201
|
+ @Deprecated
|
|
|
202
|
+ public static AchievementAnnualSummaryVo calcSummaryFromMaxMonth(List<BizCommonProsperityAchievement> rows)
|
|
|
203
|
+ {
|
|
|
204
|
+ if (rows == null || rows.isEmpty())
|
|
|
205
|
+ {
|
|
|
206
|
+ return null;
|
|
|
207
|
+ }
|
|
|
208
|
+ for (BizCommonProsperityAchievement row : rows)
|
|
|
209
|
+ {
|
|
|
210
|
+ if (row != null && StringUtils.isNotEmpty(row.getStatPeriod()) && row.getStatPeriod().length() >= 4)
|
|
|
211
|
+ {
|
|
|
212
|
+ try
|
|
|
213
|
+ {
|
|
|
214
|
+ int year = Integer.parseInt(row.getStatPeriod().substring(0, 4));
|
|
|
215
|
+ return calcSummaryFromMaxMonth(year, rows);
|
|
|
216
|
+ }
|
|
|
217
|
+ catch (NumberFormatException ignored)
|
|
|
218
|
+ {
|
|
|
219
|
+ // try next
|
|
|
220
|
+ }
|
|
|
221
|
+ }
|
|
|
222
|
+ }
|
|
|
223
|
+ return null;
|
|
|
224
|
+ }
|
|
|
225
|
+
|
|
|
226
|
+ /**
|
|
|
227
|
+ * 在所选年台账行中取最大统计月的一条。
|
|
|
228
|
+ */
|
|
|
229
|
+ public static BizCommonProsperityAchievement findMaxMonthRow(
|
|
|
230
|
+ int statYear, List<BizCommonProsperityAchievement> rows)
|
|
|
231
|
+ {
|
|
|
232
|
+ BizCommonProsperityAchievement latest = null;
|
|
|
233
|
+ int maxMonth = -1;
|
|
|
234
|
+ if (rows == null)
|
|
|
235
|
+ {
|
|
|
236
|
+ return null;
|
|
|
237
|
+ }
|
|
|
238
|
+ String yearPrefix = String.valueOf(statYear) + "-";
|
|
|
239
|
+ for (BizCommonProsperityAchievement row : rows)
|
|
|
240
|
+ {
|
|
|
241
|
+ if (row == null || StringUtils.isEmpty(row.getStatPeriod())
|
|
|
242
|
+ || !row.getStatPeriod().startsWith(yearPrefix))
|
|
|
243
|
+ {
|
|
|
244
|
+ continue;
|
|
|
245
|
+ }
|
|
|
246
|
+ int month = parseMonthFromStatPeriod(row.getStatPeriod());
|
|
|
247
|
+ if (month >= 1 && month <= 12 && month >= maxMonth)
|
|
|
248
|
+ {
|
|
|
249
|
+ maxMonth = month;
|
|
|
250
|
+ latest = row;
|
|
|
251
|
+ }
|
|
|
252
|
+ }
|
|
|
253
|
+ return latest;
|
|
|
254
|
+ }
|
|
|
255
|
+
|
|
|
256
|
+ /** @deprecated 使用 {@link #findMaxMonthRow(int, List)} */
|
|
|
257
|
+ @Deprecated
|
|
|
258
|
+ public static BizCommonProsperityAchievement findMaxMonthRow(List<BizCommonProsperityAchievement> rows)
|
|
|
259
|
+ {
|
|
|
260
|
+ if (rows == null || rows.isEmpty())
|
|
|
261
|
+ {
|
|
|
262
|
+ return null;
|
|
|
263
|
+ }
|
|
|
264
|
+ for (BizCommonProsperityAchievement row : rows)
|
|
|
265
|
+ {
|
|
|
266
|
+ if (row != null && StringUtils.isNotEmpty(row.getStatPeriod()) && row.getStatPeriod().length() >= 4)
|
|
|
267
|
+ {
|
|
|
268
|
+ try
|
|
|
269
|
+ {
|
|
|
270
|
+ int year = Integer.parseInt(row.getStatPeriod().substring(0, 4));
|
|
|
271
|
+ return findMaxMonthRow(year, rows);
|
|
|
272
|
+ }
|
|
|
273
|
+ catch (NumberFormatException ignored)
|
|
|
274
|
+ {
|
|
|
275
|
+ // try next
|
|
|
276
|
+ }
|
|
|
277
|
+ }
|
|
|
278
|
+ }
|
|
|
279
|
+ return null;
|
|
|
280
|
+ }
|
|
|
281
|
+
|
|
|
282
|
+ private static Map<Integer, BizCommonProsperityAchievement> indexByMonth(
|
|
|
283
|
+ int statYear, List<BizCommonProsperityAchievement> rows)
|
|
|
284
|
+ {
|
|
|
285
|
+ Map<Integer, BizCommonProsperityAchievement> byMonth = new HashMap<>();
|
|
|
286
|
+ if (rows == null)
|
|
|
287
|
+ {
|
|
|
288
|
+ return byMonth;
|
|
|
289
|
+ }
|
|
|
290
|
+ String yearPrefix = String.valueOf(statYear) + "-";
|
|
|
291
|
+ for (BizCommonProsperityAchievement row : rows)
|
|
|
292
|
+ {
|
|
|
293
|
+ if (row == null || StringUtils.isEmpty(row.getStatPeriod())
|
|
|
294
|
+ || !row.getStatPeriod().startsWith(yearPrefix))
|
|
|
295
|
+ {
|
|
|
296
|
+ continue;
|
|
|
297
|
+ }
|
|
|
298
|
+ int month = parseMonthFromStatPeriod(row.getStatPeriod());
|
|
|
299
|
+ if (month >= 1 && month <= 12)
|
|
|
300
|
+ {
|
|
|
301
|
+ byMonth.put(month, row);
|
|
|
302
|
+ }
|
|
|
303
|
+ }
|
|
|
304
|
+ return byMonth;
|
|
|
305
|
+ }
|
|
|
306
|
+
|
|
190
|
307
|
private static AchievementMonthlyVo fromEntity(int month, BizCommonProsperityAchievement src)
|
|
191
|
308
|
{
|
|
192
|
309
|
AchievementMonthlyVo vo = new AchievementMonthlyVo();
|