|
|
1
|
+/*
|
|
|
2
|
+ * Decompiled with CFR 0.152.
|
|
|
3
|
+ *
|
|
|
4
|
+ * Could not load the following classes:
|
|
|
5
|
+ * com.alibaba.fastjson.JSONArray
|
|
|
6
|
+ * com.alibaba.fastjson.JSONObject
|
|
|
7
|
+ * org.slf4j.Logger
|
|
|
8
|
+ * org.slf4j.LoggerFactory
|
|
|
9
|
+ * org.springframework.stereotype.Service
|
|
|
10
|
+ */
|
|
1
|
11
|
package com.qgutech.qgyun.apaas.sync.jdy.service;
|
|
2
|
12
|
|
|
3
|
13
|
import com.alibaba.fastjson.JSONArray;
|
|
...
|
...
|
@@ -5,523 +15,2426 @@ import com.alibaba.fastjson.JSONObject; |
|
5
|
15
|
import com.qgutech.qgyun.apaas.sync.jdy.api.JiandaoYunApi;
|
|
6
|
16
|
import com.qgutech.qgyun.apaas.sync.jdy.api.QxApi;
|
|
7
|
17
|
import com.qgutech.qgyun.apaas.sync.jdy.config.JdyRiskProperties;
|
|
8
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
9
|
|
-import org.springframework.stereotype.Service;
|
|
10
|
|
-
|
|
|
18
|
+import com.qgutech.qgyun.apaas.sync.jdy.db.KingbaseRiskDao;
|
|
|
19
|
+import com.qgutech.qgyun.apaas.sync.jdy.service.JdyExcelExportService;
|
|
11
|
20
|
import java.io.File;
|
|
|
21
|
+import java.sql.Connection;
|
|
|
22
|
+import java.sql.Date;
|
|
|
23
|
+import java.sql.DriverManager;
|
|
|
24
|
+import java.sql.PreparedStatement;
|
|
|
25
|
+import java.sql.ResultSet;
|
|
12
|
26
|
import java.time.Instant;
|
|
|
27
|
+import java.time.LocalDate;
|
|
|
28
|
+import java.time.LocalTime;
|
|
|
29
|
+import java.time.YearMonth;
|
|
13
|
30
|
import java.time.ZoneId;
|
|
14
|
31
|
import java.time.ZonedDateTime;
|
|
15
|
32
|
import java.time.format.DateTimeFormatter;
|
|
16
|
33
|
import java.time.temporal.ChronoUnit;
|
|
17
|
34
|
import java.util.ArrayList;
|
|
|
35
|
+import java.util.Arrays;
|
|
|
36
|
+import java.util.Collections;
|
|
|
37
|
+import java.util.HashMap;
|
|
|
38
|
+import java.util.HashSet;
|
|
|
39
|
+import java.util.Iterator;
|
|
18
|
40
|
import java.util.LinkedHashMap;
|
|
19
|
41
|
import java.util.LinkedHashSet;
|
|
20
|
42
|
import java.util.List;
|
|
|
43
|
+import java.util.Locale;
|
|
21
|
44
|
import java.util.Map;
|
|
22
|
45
|
import java.util.Set;
|
|
|
46
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
47
|
+import java.util.function.Supplier;
|
|
|
48
|
+import org.slf4j.Logger;
|
|
|
49
|
+import org.slf4j.LoggerFactory;
|
|
|
50
|
+import org.springframework.stereotype.Service;
|
|
23
|
51
|
|
|
24
|
|
-/**
|
|
25
|
|
- * 风险场景统计:调用长安简道云开放 API 读取表单数据,按规则过滤并输出命中计数;
|
|
26
|
|
- * 并可按 syncCode 把「计数 + 简道云原始数据 Excel 附件」写回启效表单。
|
|
27
|
|
- */
|
|
28
|
|
-@Slf4j
|
|
29
|
52
|
@Service
|
|
30
|
53
|
public class JdyRiskStatisticsService {
|
|
31
|
|
-
|
|
|
54
|
+ private static final Logger log = LoggerFactory.getLogger(JdyRiskStatisticsService.class);
|
|
32
|
55
|
private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai");
|
|
33
|
56
|
private static final DateTimeFormatter MONTH_FMT = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
34
|
|
-
|
|
|
57
|
+ private static final DateTimeFormatter DAY_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
58
|
+ private static final Map<String, Biz> BIZ = new LinkedHashMap<String, Biz>();
|
|
|
59
|
+ private static final Map<String, Biz> BIZ_BY_SCENARIO = new LinkedHashMap<String, Biz>();
|
|
35
|
60
|
private final JdyRiskProperties props;
|
|
36
|
61
|
private final JdyExcelExportService excelExportService;
|
|
|
62
|
+ private static final long CACHE_TTL_MS = 21600000L;
|
|
|
63
|
+ private final Map<String, CacheEntry> cacheMap = new ConcurrentHashMap<String, CacheEntry>();
|
|
|
64
|
+ private final ThreadLocal<ZonedDateTime> referenceNow = new ThreadLocal();
|
|
|
65
|
+ private final ThreadLocal<Map<String, JSONArray>> backfillData = new ThreadLocal();
|
|
|
66
|
+ private final ThreadLocal<Map<String, JSONArray>> backfillPages = new ThreadLocal();
|
|
|
67
|
+ /** 历史回补的数据截止日(含),用于把最后一个统计区间截到指定日期(如 2026-10-30)。 */
|
|
|
68
|
+ private final ThreadLocal<LocalDate> backfillEndDate = new ThreadLocal();
|
|
|
69
|
+
|
|
|
70
|
+ private JSONArray listAllDataCached(JiandaoYunApi jdy, String appId, String entryId) {
|
|
|
71
|
+ Map<String, JSONArray> cache = this.backfillData.get();
|
|
|
72
|
+ if (cache == null) {
|
|
|
73
|
+ return jdy.listAllData(this.props.getApiKey(), appId, entryId);
|
|
|
74
|
+ }
|
|
|
75
|
+ String key = appId + "|" + entryId;
|
|
|
76
|
+ JSONArray v = cache.get(key);
|
|
|
77
|
+ if (v == null) {
|
|
|
78
|
+ v = jdy.listAllData(this.props.getApiKey(), appId, entryId);
|
|
|
79
|
+ cache.put(key, v);
|
|
|
80
|
+ }
|
|
|
81
|
+ return v;
|
|
|
82
|
+ }
|
|
|
83
|
+
|
|
|
84
|
+ private void forEachPageCached(JiandaoYunApi jdy, String appId, String entryId, List<String> fields,
|
|
|
85
|
+ java.util.function.Consumer<JSONArray> consumer) {
|
|
|
86
|
+ Map<String, JSONArray> cache = this.backfillPages.get();
|
|
|
87
|
+ if (cache == null) {
|
|
|
88
|
+ jdy.forEachPage(this.props.getApiKey(), appId, entryId, fields, consumer);
|
|
|
89
|
+ return;
|
|
|
90
|
+ }
|
|
|
91
|
+ String fs = fields == null ? "" : String.join(",", fields);
|
|
|
92
|
+ String key = appId + "|" + entryId + "|" + fs;
|
|
|
93
|
+ JSONArray all = cache.get(key);
|
|
|
94
|
+ if (all == null) {
|
|
|
95
|
+ final JSONArray target = new JSONArray();
|
|
|
96
|
+ jdy.forEachPage(this.props.getApiKey(), appId, entryId, fields, page -> {
|
|
|
97
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
98
|
+ target.add((Object)page.getJSONObject(i));
|
|
|
99
|
+ }
|
|
|
100
|
+ });
|
|
|
101
|
+ cache.put(key, target);
|
|
|
102
|
+ all = target;
|
|
|
103
|
+ }
|
|
|
104
|
+ consumer.accept(all);
|
|
|
105
|
+ }
|
|
|
106
|
+
|
|
|
107
|
+ private static Biz invBiz(String sceneTitle, String sceneId, String sivnbu, String ilecyn) {
|
|
|
108
|
+ Biz b = new Biz("4", "\u5b58\u8d27\u7ba1\u7406", "R6LrkJ9nwIPWLoAbj9t", "\u7269\u6d41\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", sceneId, sceneTitle);
|
|
|
109
|
+ b.sceneMemberId = "UAAXYEx5XV0HnEomYxp";
|
|
|
110
|
+ b.sceneMemberTitle = "\u90ed\u656c\u4eea";
|
|
|
111
|
+ b.jetcalId = "UAAXYEx5XV0HnEomYxp";
|
|
|
112
|
+ b.jetcalTitle = "\u90ed\u656c\u4eea";
|
|
|
113
|
+ b.sivnbu = sivnbu;
|
|
|
114
|
+ b.ilecyn = ilecyn;
|
|
|
115
|
+ return b;
|
|
|
116
|
+ }
|
|
|
117
|
+
|
|
|
118
|
+ private static Biz claimBiz(String sceneTitle, String sceneId, String sivnbu, String ilecyn) {
|
|
|
119
|
+ Biz b = new Biz("4", "\u751f\u4ea7\u8fc7\u7a0b\u4f9b\u5e94\u5546\u635f\u5931\u7d22\u8d54", "ahUsBuZJ92r9B0qa394", "\u5236\u9020\u8fd0\u8425\u5904", "xbV3UUbZMtQrKJXOeuq", "\u5f20\u5f3a", sceneId, sceneTitle);
|
|
|
120
|
+ b.sceneMemberId = "0BLwHBhr1ulchOtGiBm";
|
|
|
121
|
+ b.sceneMemberTitle = "\u7ae0\u57ce\u4e61";
|
|
|
122
|
+ b.jetcalId = "0BLwHBhr1ulchOtGiBm";
|
|
|
123
|
+ b.jetcalTitle = "\u7ae0\u57ce\u4e61";
|
|
|
124
|
+ b.sivnbu = sivnbu;
|
|
|
125
|
+ b.ilecyn = ilecyn;
|
|
|
126
|
+ return b;
|
|
|
127
|
+ }
|
|
|
128
|
+
|
|
|
129
|
+ private static Biz bizOf(JdyRiskProperties.Scenario s) {
|
|
|
130
|
+ Biz b = BIZ_BY_SCENARIO.get(s.getId());
|
|
|
131
|
+ return b != null ? b : BIZ.get(s.getSyncCode());
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+ private static Biz projectBiz(String businessLine, String sceneId, String sceneTitle) {
|
|
|
135
|
+ Biz b;
|
|
|
136
|
+ if ("\u5de5\u5e8f\u59d4\u5916\u4e1a\u52a1".equals(businessLine)) {
|
|
|
137
|
+ b = new Biz("3", businessLine, "ahUsBuZJ92r9B0qa394", "\u5236\u9020\u8fd0\u8425\u5904", "xbV3UUbZMtQrKJXOeuq", "\u5f20\u5f3a", sceneId, sceneTitle);
|
|
|
138
|
+ b.sceneMemberId = "0BLwHBhr1ulchOtGiBm";
|
|
|
139
|
+ b.sceneMemberTitle = "\u7ae0\u57ce\u4e61";
|
|
|
140
|
+ } else {
|
|
|
141
|
+ b = new Biz("3", businessLine, "hFfriNVYr51k7kygFST", "\u5408\u80a5\u957f\u5b89\u91c7\u8d2d\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", sceneId, sceneTitle);
|
|
|
142
|
+ b.sceneMemberId = "wh8J34cBYHayy79SFFQ";
|
|
|
143
|
+ b.sceneMemberTitle = "\u66fe\u5ff5\u5149";
|
|
|
144
|
+ }
|
|
|
145
|
+ return b;
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
|
148
|
+ private ZonedDateTime now() {
|
|
|
149
|
+ ZonedDateTime r = this.referenceNow.get();
|
|
|
150
|
+ return r != null ? r : ZonedDateTime.now(ZONE);
|
|
|
151
|
+ }
|
|
37
|
152
|
|
|
38
|
153
|
public JdyRiskStatisticsService(JdyRiskProperties props, JdyExcelExportService excelExportService) {
|
|
39
|
154
|
this.props = props;
|
|
40
|
155
|
this.excelExportService = excelExportService;
|
|
41
|
156
|
}
|
|
42
|
157
|
|
|
43
|
|
- /** 只统计,返回 {count_1:.., count_2:.., ...}。 */
|
|
|
158
|
+ private <T> T cached(String key, Supplier<T> loader) {
|
|
|
159
|
+ long now = System.currentTimeMillis();
|
|
|
160
|
+ CacheEntry e = this.cacheMap.get(key);
|
|
|
161
|
+ if (e != null && e.expireAt > now) {
|
|
|
162
|
+ return (T)e.value;
|
|
|
163
|
+ }
|
|
|
164
|
+ T v = loader.get();
|
|
|
165
|
+ this.cacheMap.put(key, new CacheEntry(v, now + 21600000L));
|
|
|
166
|
+ return v;
|
|
|
167
|
+ }
|
|
|
168
|
+
|
|
44
|
169
|
public Map<String, Object> countAll() {
|
|
45
|
|
- Map<String, Object> result = new LinkedHashMap<>();
|
|
46
|
|
- JiandaoYunApi jdy = new JiandaoYunApi(props.getHost());
|
|
47
|
|
- for (JdyRiskProperties.Scenario s : props.getScenarios()) {
|
|
|
170
|
+ LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
|
|
|
171
|
+ JiandaoYunApi jdy = new JiandaoYunApi(this.props.getHost());
|
|
|
172
|
+ for (JdyRiskProperties.Scenario s : this.props.getScenarios()) {
|
|
48
|
173
|
try {
|
|
49
|
|
- String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
50
|
|
- if ("scenario7".equals(type)) {
|
|
51
|
|
- result.put(s.getId(), buildScenario7Rows(jdy, s).size());
|
|
52
|
|
- } else {
|
|
53
|
|
- JSONArray all = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
54
|
|
- JSONArray rows = filterScope(all, s);
|
|
55
|
|
- result.put(s.getId(), count(s, rows));
|
|
56
|
|
- }
|
|
57
|
|
- } catch (Exception e) {
|
|
58
|
|
- log.error("场景[{}] 统计失败", s.getId(), e);
|
|
|
174
|
+ result.put(s.getId(), this.countOneInternal(jdy, s));
|
|
|
175
|
+ }
|
|
|
176
|
+ catch (Exception e) {
|
|
|
177
|
+ log.error("\u573a\u666f[{}] \u7edf\u8ba1\u5931\u8d25", (Object)s.getId(), (Object)e);
|
|
59
|
178
|
result.put(s.getId(), "ERROR: " + e.getMessage());
|
|
60
|
179
|
}
|
|
61
|
180
|
}
|
|
62
|
181
|
return result;
|
|
63
|
182
|
}
|
|
64
|
183
|
|
|
65
|
|
- /** 统计全部场景并按 syncCode 把计数 + Excel 附件写回启效。 */
|
|
66
|
184
|
public Map<String, Object> countAndSync() {
|
|
67
|
|
- log.info("========== 开始风险场景统计并写回启效(全部 {} 个场景) ==========", props.getScenarios().size());
|
|
68
|
|
- Map<String, Object> result = new LinkedHashMap<>();
|
|
69
|
|
- Context ctx = context();
|
|
70
|
|
- for (JdyRiskProperties.Scenario s : props.getScenarios()) {
|
|
71
|
|
- syncOneScenario(s, ctx, result);
|
|
|
185
|
+ log.info("========== \u5f00\u59cb\u98ce\u9669\u573a\u666f\u7edf\u8ba1\u5e76\u5199\u56de\u542f\u6548\uff08\u5168\u90e8 {} \u4e2a\u573a\u666f\uff09 ==========", (Object)this.props.getScenarios().size());
|
|
|
186
|
+ LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
|
|
|
187
|
+ Context ctx = this.context();
|
|
|
188
|
+ for (JdyRiskProperties.Scenario s : this.props.getScenarios()) {
|
|
|
189
|
+ this.syncOneScenario(s, ctx, result);
|
|
72
|
190
|
}
|
|
73
|
|
- log.info("========== 风险场景统计并写回完成 ==========");
|
|
|
191
|
+ log.info("========== \u98ce\u9669\u573a\u666f\u7edf\u8ba1\u5e76\u5199\u56de\u5b8c\u6210 ==========");
|
|
74
|
192
|
return result;
|
|
75
|
193
|
}
|
|
76
|
194
|
|
|
77
|
|
- /** 只处理单个场景(参数为场景 id 如 count_1,或 syncCode 如 SYNC0001)。 */
|
|
78
|
195
|
public Map<String, Object> countAndSyncOne(String scenarioId) {
|
|
79
|
|
- Map<String, Object> result = new LinkedHashMap<>();
|
|
80
|
|
- JdyRiskProperties.Scenario s = findScenario(scenarioId);
|
|
|
196
|
+ LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
|
|
|
197
|
+ JdyRiskProperties.Scenario s = this.findScenario(scenarioId);
|
|
81
|
198
|
if (s == null) {
|
|
82
|
|
- result.put("error", "场景不存在: " + scenarioId);
|
|
|
199
|
+ result.put("error", "\u573a\u666f\u4e0d\u5b58\u5728: " + scenarioId);
|
|
83
|
200
|
return result;
|
|
84
|
201
|
}
|
|
85
|
|
- log.info("========== 开始单场景统计并写回: {} ==========", scenarioId);
|
|
86
|
|
- syncOneScenario(s, context(), result);
|
|
|
202
|
+ log.info("========== \u5f00\u59cb\u5355\u573a\u666f\u7edf\u8ba1\u5e76\u5199\u56de: {} ==========", (Object)scenarioId);
|
|
|
203
|
+ this.syncOneScenario(s, this.context(), result);
|
|
87
|
204
|
return result;
|
|
88
|
205
|
}
|
|
89
|
206
|
|
|
90
|
|
- /** 只统计单个场景(不写回)。 */
|
|
91
|
207
|
public Map<String, Object> countOne(String scenarioId) {
|
|
92
|
|
- Map<String, Object> result = new LinkedHashMap<>();
|
|
93
|
|
- JdyRiskProperties.Scenario s = findScenario(scenarioId);
|
|
|
208
|
+ LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
|
|
|
209
|
+ JdyRiskProperties.Scenario s = this.findScenario(scenarioId);
|
|
94
|
210
|
if (s == null) {
|
|
95
|
|
- result.put("error", "场景不存在: " + scenarioId);
|
|
|
211
|
+ result.put("error", "\u573a\u666f\u4e0d\u5b58\u5728: " + scenarioId);
|
|
96
|
212
|
return result;
|
|
97
|
213
|
}
|
|
98
|
|
- JiandaoYunApi jdy = new JiandaoYunApi(props.getHost());
|
|
|
214
|
+ JiandaoYunApi jdy = new JiandaoYunApi(this.props.getHost());
|
|
99
|
215
|
try {
|
|
100
|
|
- String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
101
|
|
- if ("scenario7".equals(type)) {
|
|
102
|
|
- result.put(s.getId(), buildScenario7Rows(jdy, s).size());
|
|
103
|
|
- } else {
|
|
104
|
|
- JSONArray all = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
105
|
|
- result.put(s.getId(), count(s, filterScope(all, s)));
|
|
106
|
|
- }
|
|
107
|
|
- } catch (Exception e) {
|
|
|
216
|
+ result.put(s.getId(), this.countOneInternal(jdy, s));
|
|
|
217
|
+ }
|
|
|
218
|
+ catch (Exception e) {
|
|
108
|
219
|
result.put(s.getId(), "ERROR: " + e.getMessage());
|
|
109
|
220
|
}
|
|
110
|
221
|
return result;
|
|
111
|
222
|
}
|
|
112
|
223
|
|
|
|
224
|
+ /*
|
|
|
225
|
+ * WARNING - Removed try catching itself - possible behaviour change.
|
|
|
226
|
+ */
|
|
|
227
|
+ public Map<String, Object> backfill(String fromMonth, String toMonth, List<String> scenarioIds, boolean dryRun, boolean wipe) {
|
|
|
228
|
+ return backfill(fromMonth, toMonth, scenarioIds, dryRun, wipe, null);
|
|
|
229
|
+ }
|
|
|
230
|
+
|
|
|
231
|
+ /*
|
|
|
232
|
+ * WARNING - Removed try catching itself - possible behaviour change.
|
|
|
233
|
+ */
|
|
|
234
|
+ public Map<String, Object> backfill(String fromMonth, String toMonth, List<String> scenarioIds, boolean dryRun, boolean wipe, String toDate) {
|
|
|
235
|
+ YearMonth to;
|
|
|
236
|
+ YearMonth from;
|
|
|
237
|
+ LocalDate endDate = null;
|
|
|
238
|
+ LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
|
|
|
239
|
+ try {
|
|
|
240
|
+ from = YearMonth.parse(fromMonth);
|
|
|
241
|
+ to = YearMonth.parse(toMonth);
|
|
|
242
|
+ if (toDate != null && !toDate.trim().isEmpty()) {
|
|
|
243
|
+ endDate = LocalDate.parse(toDate.trim());
|
|
|
244
|
+ }
|
|
|
245
|
+ }
|
|
|
246
|
+ catch (Exception e) {
|
|
|
247
|
+ result.put("error", "月份格式应为 yyyy-MM,截止日应为 yyyy-MM-dd: " + fromMonth + "~" + toMonth + " / " + toDate);
|
|
|
248
|
+ return result;
|
|
|
249
|
+ }
|
|
|
250
|
+ if (to.isBefore(from)) {
|
|
|
251
|
+ result.put("error", "to \u4e0d\u80fd\u65e9\u4e8e from");
|
|
|
252
|
+ return result;
|
|
|
253
|
+ }
|
|
|
254
|
+ ArrayList<JdyRiskProperties.Scenario> targets = new ArrayList<JdyRiskProperties.Scenario>();
|
|
|
255
|
+ for (JdyRiskProperties.Scenario s : this.props.getScenarios()) {
|
|
|
256
|
+ if (!JdyRiskStatisticsService.matchesTarget(s, scenarioIds)) continue;
|
|
|
257
|
+ if (!JdyRiskStatisticsService.isBackfillSupported(s)) {
|
|
|
258
|
+ result.put(s.getId(), "SKIP: \u5468\u671f\u7c7b\u578b\u4e0d\u786e\u5b9a(" + s.getType() + ")");
|
|
|
259
|
+ continue;
|
|
|
260
|
+ }
|
|
|
261
|
+ targets.add(s);
|
|
|
262
|
+ }
|
|
|
263
|
+ if (targets.isEmpty()) {
|
|
|
264
|
+ result.put("error", "\u6ca1\u6709\u53ef\u56de\u8865\u7684\u573a\u666f");
|
|
|
265
|
+ return result;
|
|
|
266
|
+ }
|
|
|
267
|
+ log.info("========== \u5386\u53f2\u56de\u8865 {} ~ {}\uff0c\u573a\u666f={}\uff0cdryRun={}\uff0cwipe={} ==========", new Object[]{fromMonth, toMonth, targets.size(), dryRun, wipe});
|
|
|
268
|
+ Context ctx = this.context();
|
|
|
269
|
+ LinkedHashMap<String, JSONObject> templates = new LinkedHashMap<String, JSONObject>();
|
|
|
270
|
+ for (JdyRiskProperties.Scenario s : targets) {
|
|
|
271
|
+ JSONObject t = this.findRecordBySyncCode(ctx.allRecords, s, JdyRiskStatisticsService.bizOf(s));
|
|
|
272
|
+ if (t == null) continue;
|
|
|
273
|
+ templates.put(s.getId(), t);
|
|
|
274
|
+ }
|
|
|
275
|
+ if (wipe && !dryRun) {
|
|
|
276
|
+ int deleted = this.wipeTargets(ctx, targets);
|
|
|
277
|
+ result.put("_deleted", deleted);
|
|
|
278
|
+ JSONArray kept = new JSONArray();
|
|
|
279
|
+ JdyRiskProperties.Qx qx = this.props.getQx();
|
|
|
280
|
+ for (JSONObject t : templates.values()) {
|
|
|
281
|
+ // 模板仅用于克隆业务字段,清掉预警时间避免 findTodayRecord 误命中已删除记录
|
|
|
282
|
+ if (qx.getTimeField() != null && !qx.getTimeField().isEmpty()) {
|
|
|
283
|
+ t.remove(qx.getTimeField());
|
|
|
284
|
+ }
|
|
|
285
|
+ if (qx.getTimeField2() != null && !qx.getTimeField2().isEmpty()) {
|
|
|
286
|
+ t.remove(qx.getTimeField2());
|
|
|
287
|
+ }
|
|
|
288
|
+ kept.add((Object)t);
|
|
|
289
|
+ }
|
|
|
290
|
+ ctx = new Context(ctx.qxApi, ctx.token, ctx.jdy, kept);
|
|
|
291
|
+ }
|
|
|
292
|
+ this.backfillData.set(new HashMap<String, JSONArray>());
|
|
|
293
|
+ this.backfillPages.set(new HashMap<String, JSONArray>());
|
|
|
294
|
+ if (endDate != null) {
|
|
|
295
|
+ this.backfillEndDate.set(endDate);
|
|
|
296
|
+ }
|
|
|
297
|
+ try {
|
|
|
298
|
+ for (JdyRiskProperties.Scenario s : targets) {
|
|
|
299
|
+ List<ZonedDateTime> runDates = this.runDatesFor(s, from, to);
|
|
|
300
|
+ for (ZonedDateTime runDate : runDates) {
|
|
|
301
|
+ String key = s.getId() + "@" + runDate.toLocalDate();
|
|
|
302
|
+ this.referenceNow.set(runDate);
|
|
|
303
|
+ try {
|
|
|
304
|
+ if (dryRun) {
|
|
|
305
|
+ result.put(key, this.countOneInternal(ctx.jdy, s));
|
|
|
306
|
+ continue;
|
|
|
307
|
+ }
|
|
|
308
|
+ LinkedHashMap<String, Object> one = new LinkedHashMap<String, Object>();
|
|
|
309
|
+ this.syncOneScenario(s, ctx, one);
|
|
|
310
|
+ Object v = one.get(s.getId());
|
|
|
311
|
+ result.put(key, v != null ? v : one);
|
|
|
312
|
+ }
|
|
|
313
|
+ catch (Exception e) {
|
|
|
314
|
+ log.error("\u5386\u53f2\u56de\u8865\u5931\u8d25: {} {}", new Object[]{s.getId(), runDate, e});
|
|
|
315
|
+ result.put(key, "ERROR: " + e.getMessage());
|
|
|
316
|
+ }
|
|
|
317
|
+ finally {
|
|
|
318
|
+ this.referenceNow.remove();
|
|
|
319
|
+ }
|
|
|
320
|
+ }
|
|
|
321
|
+ }
|
|
|
322
|
+ } finally {
|
|
|
323
|
+ this.backfillData.remove();
|
|
|
324
|
+ this.backfillPages.remove();
|
|
|
325
|
+ this.backfillEndDate.remove();
|
|
|
326
|
+ }
|
|
|
327
|
+ log.info("========== \u5386\u53f2\u56de\u8865\u5b8c\u6210 ==========");
|
|
|
328
|
+ return result;
|
|
|
329
|
+ }
|
|
|
330
|
+
|
|
|
331
|
+ /**
|
|
|
332
|
+ * 设备域场景20/21/22 一键历史回补(人大金仓)。
|
|
|
333
|
+ * <p>默认区间 2026-01-01 ~ 2026-10-30:按月生成启效记录;
|
|
|
334
|
+ * 场景21按每月 1-10、11-20、21-月底 三个区间生成。</p>
|
|
|
335
|
+ */
|
|
|
336
|
+ public Map<String, Object> backfillDb(String fromDate, String toDate, boolean dryRun, boolean wipe) {
|
|
|
337
|
+ try {
|
|
|
338
|
+ LocalDate from = LocalDate.parse(fromDate);
|
|
|
339
|
+ LocalDate to = LocalDate.parse(toDate);
|
|
|
340
|
+ return this.backfill(YearMonth.from(from).toString(), YearMonth.from(to).toString(),
|
|
|
341
|
+ Arrays.asList("count_20", "count_21", "count_22"), dryRun, wipe, to.toString());
|
|
|
342
|
+ } catch (Exception e) {
|
|
|
343
|
+ LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
|
|
|
344
|
+ result.put("error", "\u65e5\u671f\u683c\u5f0f\u5e94\u4e3a yyyy-MM-dd: " + fromDate + " ~ " + toDate);
|
|
|
345
|
+ return result;
|
|
|
346
|
+ }
|
|
|
347
|
+ }
|
|
|
348
|
+
|
|
|
349
|
+ private static boolean matchesTarget(JdyRiskProperties.Scenario s, List<String> ids) { if (ids == null || ids.isEmpty()) {
|
|
|
350
|
+ return true;
|
|
|
351
|
+ }
|
|
|
352
|
+ for (String id : ids) {
|
|
|
353
|
+ if (id == null || !id.equals(s.getId()) && !id.equals(s.getSyncCode())) continue;
|
|
|
354
|
+ return true;
|
|
|
355
|
+ }
|
|
|
356
|
+ return false;
|
|
|
357
|
+ }
|
|
|
358
|
+
|
|
|
359
|
+ private static boolean isBackfillSupported(JdyRiskProperties.Scenario s) {
|
|
|
360
|
+ String type;
|
|
|
361
|
+ String string = type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
362
|
+ if ("scenario11".equals(type)) {
|
|
|
363
|
+ return false;
|
|
|
364
|
+ }
|
|
|
365
|
+ if (JdyRiskStatisticsService.isDbType(type)) {
|
|
|
366
|
+ return true;
|
|
|
367
|
+ }
|
|
|
368
|
+ if (s.isMonthOnly() || s.isPrevMonthOnly() || s.isPrevQuarterOnly() || s.isQuarterOnly()
|
|
|
369
|
+ || s.isYearOnly() || s.isHalfMonthOnly() || s.isPrevThreeMonths()
|
|
|
370
|
+ || s.isMonthlyOverdueIncremental()) {
|
|
|
371
|
+ return true;
|
|
|
372
|
+ }
|
|
|
373
|
+ return "scenario22".equals(type) || "scenario28".equals(type) || "scenario30".equals(type) || "scenario31".equals(type) || "scenario32".equals(type);
|
|
|
374
|
+ }
|
|
|
375
|
+
|
|
|
376
|
+ private List<ZonedDateTime> runDatesFor(JdyRiskProperties.Scenario s, YearMonth from, YearMonth to) {
|
|
|
377
|
+ ArrayList<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
|
|
|
378
|
+ LinkedHashSet<LocalDate> seen = new LinkedHashSet<LocalDate>();
|
|
|
379
|
+ String runType = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
380
|
+ if (JdyRiskStatisticsService.isDbType(runType)) {
|
|
|
381
|
+ return this.dbRunDates(runType, from, to);
|
|
|
382
|
+ }
|
|
|
383
|
+ if (s.isYearOnly()) {
|
|
|
384
|
+ dates.add(ZonedDateTime.now(ZONE));
|
|
|
385
|
+ return dates;
|
|
|
386
|
+ }
|
|
|
387
|
+ if (s.isHalfMonthOnly()) {
|
|
|
388
|
+ YearMonth m = from;
|
|
|
389
|
+ while (!m.isAfter(to)) {
|
|
|
390
|
+ LocalDate first = m.atDay(16);
|
|
|
391
|
+ LocalDate nextFirst = m.plusMonths(1L).atDay(1);
|
|
|
392
|
+ if (seen.add(first)) {
|
|
|
393
|
+ dates.add(ZonedDateTime.of(first, LocalTime.of(1, 0), ZONE));
|
|
|
394
|
+ }
|
|
|
395
|
+ if (seen.add(nextFirst)) {
|
|
|
396
|
+ dates.add(ZonedDateTime.of(nextFirst, LocalTime.of(1, 0), ZONE));
|
|
|
397
|
+ }
|
|
|
398
|
+ m = m.plusMonths(1L);
|
|
|
399
|
+ }
|
|
|
400
|
+ return dates;
|
|
|
401
|
+ }
|
|
|
402
|
+ if (s.isPrevThreeMonths()) {
|
|
|
403
|
+ YearMonth m = from.plusMonths(3L);
|
|
|
404
|
+ YearMonth end = to.plusMonths(1L);
|
|
|
405
|
+ while (!m.isAfter(end)) {
|
|
|
406
|
+ LocalDate rd = m.atDay(1);
|
|
|
407
|
+ if (seen.add(rd)) {
|
|
|
408
|
+ dates.add(ZonedDateTime.of(rd, LocalTime.of(1, 0), ZONE));
|
|
|
409
|
+ }
|
|
|
410
|
+ m = m.plusMonths(1L);
|
|
|
411
|
+ }
|
|
|
412
|
+ return dates;
|
|
|
413
|
+ }
|
|
|
414
|
+ boolean quarter = s.isPrevQuarterOnly() || s.isQuarterOnly();
|
|
|
415
|
+ YearMonth ym = from;
|
|
|
416
|
+ while (!ym.isAfter(to)) {
|
|
|
417
|
+ LocalDate runDate = null;
|
|
|
418
|
+ LocalTime runTime = LocalTime.of(3, 0);
|
|
|
419
|
+ if (quarter) {
|
|
|
420
|
+ int m = ym.getMonthValue();
|
|
|
421
|
+ if (m == 3 || m == 6 || m == 9 || m == 12) {
|
|
|
422
|
+ runDate = ym.plusMonths(1L).atDay(5);
|
|
|
423
|
+ }
|
|
|
424
|
+ } else if (s.isMonthOnly()) {
|
|
|
425
|
+ runDate = ym.atEndOfMonth();
|
|
|
426
|
+ runTime = LocalTime.of(23, 0);
|
|
|
427
|
+ } else {
|
|
|
428
|
+ int day = "count_1".equals(s.getId()) ? 20 : 5;
|
|
|
429
|
+ runDate = ym.plusMonths(1L).atDay(day);
|
|
|
430
|
+ }
|
|
|
431
|
+ if (runDate != null && seen.add(runDate)) {
|
|
|
432
|
+ dates.add(ZonedDateTime.of(runDate, runTime, ZONE));
|
|
|
433
|
+ }
|
|
|
434
|
+ ym = ym.plusMonths(1L);
|
|
|
435
|
+ }
|
|
|
436
|
+ return dates;
|
|
|
437
|
+ }
|
|
|
438
|
+
|
|
|
439
|
+ /**
|
|
|
440
|
+ * 人大金仓场景的历史回补运行日期:
|
|
|
441
|
+ * <ul>
|
|
|
442
|
+ * <li>scenario33(废料预警):数据月 m 的记录在 m+1 月 12 号 01:00 生成</li>
|
|
|
443
|
+ * <li>scenario34(过磅记录):数据月内 11 号 01:00(1-10)、21 号 01:00(11-20)、月末 23:00(21-月底)</li>
|
|
|
444
|
+ * <li>scenario35(运输异常):数据月 m 的记录在 m+1 月 1 号 01:00 生成</li>
|
|
|
445
|
+ * </ul>
|
|
|
446
|
+ */
|
|
|
447
|
+ private List<ZonedDateTime> dbRunDates(String type, YearMonth from, YearMonth to) {
|
|
|
448
|
+ ArrayList<ZonedDateTime> dates = new ArrayList<ZonedDateTime>();
|
|
|
449
|
+ LocalDate cap = this.backfillEndDate.get();
|
|
|
450
|
+ YearMonth ym = from;
|
|
|
451
|
+ while (!ym.isAfter(to)) {
|
|
|
452
|
+ if ("scenario33".equals(type)) {
|
|
|
453
|
+ dates.add(ZonedDateTime.of(ym.plusMonths(1L).atDay(12), LocalTime.of(1, 0), ZONE));
|
|
|
454
|
+ } else if ("scenario35".equals(type)) {
|
|
|
455
|
+ dates.add(ZonedDateTime.of(ym.plusMonths(1L).atDay(1), LocalTime.of(1, 0), ZONE));
|
|
|
456
|
+ } else if ("scenario34".equals(type)) {
|
|
|
457
|
+ dates.add(ZonedDateTime.of(ym.atDay(11), LocalTime.of(1, 0), ZONE));
|
|
|
458
|
+ dates.add(ZonedDateTime.of(ym.atDay(21), LocalTime.of(1, 0), ZONE));
|
|
|
459
|
+ LocalDate last = ym.atEndOfMonth();
|
|
|
460
|
+ if (cap != null && !cap.isBefore(ym.atDay(21)) && cap.isBefore(last)) {
|
|
|
461
|
+ last = cap;
|
|
|
462
|
+ }
|
|
|
463
|
+ if (!last.isBefore(ym.atDay(21)) && last.getMonthValue() == ym.getMonthValue()) {
|
|
|
464
|
+ dates.add(ZonedDateTime.of(last, LocalTime.of(23, 0), ZONE));
|
|
|
465
|
+ }
|
|
|
466
|
+ }
|
|
|
467
|
+ ym = ym.plusMonths(1L);
|
|
|
468
|
+ }
|
|
|
469
|
+ return dates;
|
|
|
470
|
+ }
|
|
|
471
|
+
|
|
|
472
|
+ private int wipeTargets(Context ctx, List<JdyRiskProperties.Scenario> targets) {
|
|
|
473
|
+ JdyRiskProperties.Qx qx = this.props.getQx();
|
|
|
474
|
+ String deleteCode = qx.getDeleteCode();
|
|
|
475
|
+ if (deleteCode == null || deleteCode.isEmpty()) {
|
|
|
476
|
+ deleteCode = "ilr3ne7bDel";
|
|
|
477
|
+ }
|
|
|
478
|
+ int deleted = 0;
|
|
|
479
|
+ for (int i = 0; i < ctx.allRecords.size(); ++i) {
|
|
|
480
|
+ String id;
|
|
|
481
|
+ JSONObject r = ctx.allRecords.getJSONObject(i);
|
|
|
482
|
+ if (!JdyRiskStatisticsService.belongsToAny(r, targets) || (id = r.getString("id")) == null || id.isEmpty()) continue;
|
|
|
483
|
+ try {
|
|
|
484
|
+ ctx.qxApi.deleteData(ctx.token, qx.getAppId(), deleteCode, id);
|
|
|
485
|
+ ++deleted;
|
|
|
486
|
+ continue;
|
|
|
487
|
+ }
|
|
|
488
|
+ catch (Exception e) {
|
|
|
489
|
+ log.error("\u56de\u8865\u6e05\u5e93\u5220\u9664\u5931\u8d25 id={}: {}", (Object)id, (Object)e.getMessage());
|
|
|
490
|
+ }
|
|
|
491
|
+ }
|
|
|
492
|
+ log.info("\u56de\u8865\u6e05\u5e93\u5b8c\u6210\uff0c\u5220\u9664 {} \u6761\uff08\u4ec5\u9650\u672c\u6b21\u56de\u8865\u573a\u666f\uff09", (Object)deleted);
|
|
|
493
|
+ return deleted;
|
|
|
494
|
+ }
|
|
|
495
|
+
|
|
|
496
|
+ private static boolean belongsToAny(JSONObject r, List<JdyRiskProperties.Scenario> targets) {
|
|
|
497
|
+ String sc = r.getString("syncCode");
|
|
|
498
|
+ if (sc == null) {
|
|
|
499
|
+ return false;
|
|
|
500
|
+ }
|
|
|
501
|
+ JSONObject scene = r.getJSONObject("miidqb");
|
|
|
502
|
+ String sceneId = scene != null ? scene.getString("id") : r.getString("miidqbId");
|
|
|
503
|
+ for (JdyRiskProperties.Scenario s : targets) {
|
|
|
504
|
+ if (!sc.equals(s.getSyncCode())) continue;
|
|
|
505
|
+ Biz biz = JdyRiskStatisticsService.bizOf(s);
|
|
|
506
|
+ if (biz != null && biz.sceneId != null) {
|
|
|
507
|
+ if (!biz.sceneId.equals(sceneId)) continue;
|
|
|
508
|
+ return true;
|
|
|
509
|
+ }
|
|
|
510
|
+ return true;
|
|
|
511
|
+ }
|
|
|
512
|
+ return false;
|
|
|
513
|
+ }
|
|
|
514
|
+
|
|
|
515
|
+ private long countOneInternal(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
516
|
+ String type;
|
|
|
517
|
+ String string = type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
518
|
+ if ("scenario7".equals(type)) {
|
|
|
519
|
+ return this.buildScenario7Rows(jdy, s).size();
|
|
|
520
|
+ }
|
|
|
521
|
+ if ("scenario11".equals(type)) {
|
|
|
522
|
+ return this.buildScenario11((JiandaoYunApi)jdy, (JdyRiskProperties.Scenario)s).count;
|
|
|
523
|
+ }
|
|
|
524
|
+ if ("scenario30".equals(type) || "scenario31".equals(type) || "scenario32".equals(type)) {
|
|
|
525
|
+ return this.customSheets((JiandaoYunApi)jdy, (JdyRiskProperties.Scenario)s).count;
|
|
|
526
|
+ }
|
|
|
527
|
+ if ("scenario22".equals(type)) {
|
|
|
528
|
+ return this.buildS28((JiandaoYunApi)jdy, (JdyRiskProperties.Scenario)s).count;
|
|
|
529
|
+ }
|
|
|
530
|
+ if ("scenario28".equals(type)) {
|
|
|
531
|
+ return this.buildS29((JiandaoYunApi)jdy, (JdyRiskProperties.Scenario)s).count;
|
|
|
532
|
+ }
|
|
|
533
|
+ if (JdyRiskStatisticsService.isDbType(type)) {
|
|
|
534
|
+ return this.buildDbRows((JdyRiskProperties.Scenario)s).count;
|
|
|
535
|
+ }
|
|
|
536
|
+ if (JdyRiskStatisticsService.isReasonType(type)) {
|
|
|
537
|
+ return this.buildReasonRows((JiandaoYunApi)jdy, (JdyRiskProperties.Scenario)s).count;
|
|
|
538
|
+ }
|
|
|
539
|
+ return this.count(s, this.buildScopeRows(jdy, s));
|
|
|
540
|
+ }
|
|
|
541
|
+
|
|
113
|
542
|
private JdyRiskProperties.Scenario findScenario(String scenarioId) {
|
|
114
|
543
|
if (scenarioId == null) {
|
|
115
|
544
|
return null;
|
|
116
|
545
|
}
|
|
117
|
|
- for (JdyRiskProperties.Scenario s : props.getScenarios()) {
|
|
118
|
|
- if (scenarioId.equals(s.getId()) || scenarioId.equals(s.getSyncCode())) {
|
|
119
|
|
- return s;
|
|
120
|
|
- }
|
|
|
546
|
+ for (JdyRiskProperties.Scenario s : this.props.getScenarios()) {
|
|
|
547
|
+ if (!scenarioId.equals(s.getId()) && !scenarioId.equals(s.getSyncCode())) continue;
|
|
|
548
|
+ return s;
|
|
121
|
549
|
}
|
|
122
|
550
|
return null;
|
|
123
|
551
|
}
|
|
124
|
552
|
|
|
125
|
|
- /** 登录启效并一次性拉取全部记录(本地按 syncCode 匹配)。 */
|
|
126
|
553
|
private Context context() {
|
|
127
|
|
- JdyRiskProperties.Qx qx = props.getQx();
|
|
|
554
|
+ JdyRiskProperties.Qx qx = this.props.getQx();
|
|
128
|
555
|
QxApi qxApi = new QxApi(qx.getBaseUrl());
|
|
129
|
556
|
String token = qxApi.login(qx.getUsername(), qx.getPassword(), qx.getCorpCode());
|
|
130
|
|
- JiandaoYunApi jdy = new JiandaoYunApi(props.getHost());
|
|
|
557
|
+ JiandaoYunApi jdy = new JiandaoYunApi(this.props.getHost());
|
|
131
|
558
|
JSONArray allRecords = qxApi.pageAll(token, qx.getAppId(), qx.getQueryCode());
|
|
132
|
|
- log.info("启效记录总数={}(按 syncCode 本地匹配)", allRecords.size());
|
|
|
559
|
+ log.info("\u542f\u6548\u8bb0\u5f55\u603b\u6570={}\uff08\u6309 syncCode \u672c\u5730\u5339\u914d\uff09", (Object)allRecords.size());
|
|
133
|
560
|
return new Context(qxApi, token, jdy, allRecords);
|
|
134
|
561
|
}
|
|
135
|
562
|
|
|
136
|
|
- private static class Context {
|
|
137
|
|
- final QxApi qxApi;
|
|
138
|
|
- final String token;
|
|
139
|
|
- final JiandaoYunApi jdy;
|
|
140
|
|
- final JSONArray allRecords;
|
|
141
|
|
-
|
|
142
|
|
- Context(QxApi qxApi, String token, JiandaoYunApi jdy, JSONArray allRecords) {
|
|
143
|
|
- this.qxApi = qxApi;
|
|
144
|
|
- this.token = token;
|
|
145
|
|
- this.jdy = jdy;
|
|
146
|
|
- this.allRecords = allRecords;
|
|
147
|
|
- }
|
|
148
|
|
- }
|
|
149
|
|
-
|
|
150
|
|
- /** 单场景:统计 -> 生成 Excel -> 上传附件 -> 更新记录。 */
|
|
151
|
563
|
private void syncOneScenario(JdyRiskProperties.Scenario s, Context ctx, Map<String, Object> result) {
|
|
152
|
|
- JdyRiskProperties.Qx qx = props.getQx();
|
|
|
564
|
+ JdyRiskProperties.Qx qx = this.props.getQx();
|
|
153
|
565
|
QxApi qxApi = ctx.qxApi;
|
|
154
|
566
|
String token = ctx.token;
|
|
155
|
567
|
JiandaoYunApi jdy = ctx.jdy;
|
|
156
|
568
|
JSONArray allRecords = ctx.allRecords;
|
|
157
|
569
|
try {
|
|
158
|
|
- String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
570
|
+ JSONArray widgets;
|
|
159
|
571
|
JSONArray rows;
|
|
160
|
572
|
long count;
|
|
161
|
|
- if ("scenario7".equals(type)) {
|
|
162
|
|
- rows = buildScenario7Rows(jdy, s);
|
|
|
573
|
+ String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
574
|
+ Biz sceneBiz = JdyRiskStatisticsService.bizOf(s);
|
|
|
575
|
+ JdyExcelExportService.setLookup(this.buildLookupMap(jdy, s));
|
|
|
576
|
+ String extraHeader = null;
|
|
|
577
|
+ List<String> extraValues = null;
|
|
|
578
|
+ List<JdyExcelExportService.SheetSpec> customSheets = null;
|
|
|
579
|
+ if (JdyRiskStatisticsService.isCustomSheetType(type)) {
|
|
|
580
|
+ MultiResult mr = this.customSheets(jdy, s);
|
|
|
581
|
+ count = mr.count;
|
|
|
582
|
+ customSheets = mr.sheets;
|
|
|
583
|
+ rows = new JSONArray();
|
|
|
584
|
+ widgets = new JSONArray();
|
|
|
585
|
+ } else if ("scenario7".equals(type)) {
|
|
|
586
|
+ rows = this.buildScenario7Rows(jdy, s);
|
|
163
|
587
|
count = rows.size();
|
|
|
588
|
+ widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
|
589
|
+ } else if ("scenario11".equals(type)) {
|
|
|
590
|
+ Built11 b = this.buildScenario11(jdy, s);
|
|
|
591
|
+ rows = b.excelRows;
|
|
|
592
|
+ count = b.count;
|
|
|
593
|
+ widgets = b.excelWidgets;
|
|
|
594
|
+ } else if (JdyRiskStatisticsService.isDbType(type)) {
|
|
|
595
|
+ BuiltDb db = this.buildDbRows(s);
|
|
|
596
|
+ rows = db.rows;
|
|
|
597
|
+ count = db.count;
|
|
|
598
|
+ widgets = db.widgets;
|
|
|
599
|
+ extraHeader = "\u539f\u56e0";
|
|
|
600
|
+ extraValues = db.reasons;
|
|
|
601
|
+ } else if (JdyRiskStatisticsService.isReasonType(type)) {
|
|
|
602
|
+ BuiltReason br = this.buildReasonRows(jdy, s);
|
|
|
603
|
+ rows = br.rows;
|
|
|
604
|
+ count = br.count;
|
|
|
605
|
+ widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
|
606
|
+ extraHeader = "\u539f\u56e0";
|
|
|
607
|
+ extraValues = br.reasons;
|
|
164
|
608
|
} else {
|
|
165
|
|
- JSONArray all = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
166
|
|
- rows = filterScope(all, s);
|
|
167
|
|
- count = count(s, rows);
|
|
|
609
|
+ String sortField;
|
|
|
610
|
+ rows = this.buildScopeRows(jdy, s);
|
|
|
611
|
+ count = this.count(s, rows);
|
|
|
612
|
+ widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
|
613
|
+ if (!"scenario10".equals(type)) {
|
|
|
614
|
+ extraHeader = "scenario4".equals(type) || "scenario6".equals(type) || "scenario8".equals(type) ? "\u9884\u8b66\u4f9b\u5e94\u5546" : ("scenario5".equals(type) || "scenario9".equals(type) ? "\u9884\u8b66\u5de5\u7a0b\u5e08" : "\u7b5b\u9009\u7ed3\u679c");
|
|
|
615
|
+ extraValues = this.buildExtraValues(s, rows);
|
|
|
616
|
+ }
|
|
|
617
|
+ if (s.isOnlyWarnRows()) {
|
|
|
618
|
+ rows = this.filterWarnRows(s, rows);
|
|
|
619
|
+ extraValues = this.buildExtraValues(s, rows);
|
|
|
620
|
+ }
|
|
|
621
|
+ String string = sortField = s.getGroupField() != null && !s.getGroupField().isEmpty() ? s.getGroupField() : s.getExtraField();
|
|
|
622
|
+ if (sortField != null && !sortField.isEmpty()) {
|
|
|
623
|
+ JdyRiskStatisticsService.sortRows(rows, sortField);
|
|
|
624
|
+ if (extraHeader != null) {
|
|
|
625
|
+ extraValues = this.buildExtraValues(s, rows);
|
|
|
626
|
+ }
|
|
|
627
|
+ }
|
|
168
|
628
|
}
|
|
169
|
629
|
result.put(s.getId(), count);
|
|
170
|
|
- log.info("场景[{}] 命中={} (参与统计{}条)", s.getId(), count, rows.size());
|
|
171
|
|
-
|
|
172
|
|
- JSONArray widgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
173
|
|
- String extraHeader = null;
|
|
174
|
|
- List<String> extraValues = null;
|
|
175
|
|
- if (!"scenario7".equals(type)) {
|
|
176
|
|
- if ("scenario4".equals(type) || "scenario6".equals(type) || "scenario8".equals(type)) {
|
|
177
|
|
- extraHeader = "预警供应商";
|
|
178
|
|
- } else if ("scenario5".equals(type) || "scenario9".equals(type)) {
|
|
179
|
|
- extraHeader = "预警工程师";
|
|
|
630
|
+ log.info("\u573a\u666f[{}] \u547d\u4e2d={} (\u53c2\u4e0e\u7edf\u8ba1{}\u6761)", new Object[]{s.getId(), count, rows.size()});
|
|
|
631
|
+ boolean skipAttach = (JdyRiskStatisticsService.isReasonType(type) || JdyRiskStatisticsService.isCustomSheetType(type) || JdyRiskStatisticsService.isDbType(type)) && count == 0L;
|
|
|
632
|
+ String fileId = null;
|
|
|
633
|
+ String fileName = null;
|
|
|
634
|
+ long size = 0L;
|
|
|
635
|
+ if (skipAttach) {
|
|
|
636
|
+ log.info("\u573a\u666f[{}] \u547d\u4e2d0\u6761\uff0c\u8df3\u8fc7 Excel \u751f\u6210\u4e0e\u9644\u4ef6\u4e0a\u4f20\uff0c\u4ec5\u56de\u5199\u8ba1\u6570", (Object)s.getId());
|
|
|
637
|
+ } else {
|
|
|
638
|
+ String path;
|
|
|
639
|
+ fileName = JdyExcelExportService.nowFileName();
|
|
|
640
|
+ if (customSheets != null) {
|
|
|
641
|
+ path = this.excelExportService.exportSheets(fileName, customSheets);
|
|
180
|
642
|
} else {
|
|
181
|
|
- extraHeader = "筛选结果";
|
|
|
643
|
+ HashSet<String> percentFields = s.getPercentFields().isEmpty() ? null : new HashSet<String>(s.getPercentFields());
|
|
|
644
|
+ Biz sheetBiz = sceneBiz;
|
|
|
645
|
+ String sheetName = sheetBiz != null ? sheetBiz.sceneTitle : s.getName();
|
|
|
646
|
+ path = this.excelExportService.exportRows(widgets, rows, extraHeader, extraValues, fileName, sheetName, percentFields);
|
|
182
|
647
|
}
|
|
183
|
|
- extraValues = buildExtraValues(s, rows);
|
|
184
|
|
- }
|
|
185
|
|
- String fileName = JdyExcelExportService.nowFileName();
|
|
186
|
|
- String path = excelExportService.exportRows(widgets, rows, extraHeader, extraValues, fileName);
|
|
187
|
|
- if (path == null || path.startsWith("FAIL")) {
|
|
188
|
|
- throw new IllegalStateException("Excel 导出失败: " + path);
|
|
|
648
|
+ if (path == null || path.startsWith("FAIL")) {
|
|
|
649
|
+ throw new IllegalStateException("Excel \u5bfc\u51fa\u5931\u8d25: " + path);
|
|
|
650
|
+ }
|
|
|
651
|
+ fileId = qxApi.uploadFile(token, new File(path), fileName);
|
|
|
652
|
+ size = new File(path).length();
|
|
189
|
653
|
}
|
|
190
|
|
-
|
|
191
|
|
- String fileId = qxApi.uploadFile(token, new File(path), fileName);
|
|
192
|
|
-
|
|
|
654
|
+ long now = this.now().toInstant().toEpochMilli();
|
|
193
|
655
|
String syncCode = s.getSyncCode();
|
|
194
|
|
- JSONObject rec = findRecordBySyncCode(allRecords, syncCode);
|
|
195
|
|
- if (rec == null) {
|
|
196
|
|
- log.warn("按 syncCode={} 未查到记录,跳过写回", syncCode);
|
|
197
|
|
- return;
|
|
198
|
|
- }
|
|
199
|
|
- rec.put(qx.getCountField(), count);
|
|
200
|
|
- if (qx.getAttachField() != null && !qx.getAttachField().isEmpty()) {
|
|
201
|
|
- JSONObject rel = new JSONObject();
|
|
202
|
|
- rel.put("id", fileId);
|
|
203
|
|
- rel.put("dataTitle", fileName);
|
|
204
|
|
- rec.put(qx.getAttachField(), rel);
|
|
205
|
|
- rec.put(qx.getAttachField() + "Id", fileId);
|
|
206
|
|
- }
|
|
207
|
|
- qxApi.updateData(token, qx.getAppId(), qx.getUpdateCode(), rec);
|
|
208
|
|
- log.info("写回成功: syncCode={} id={} {}={} 附件={}", syncCode, rec.getString("id"),
|
|
209
|
|
- qx.getCountField(), count, fileName);
|
|
210
|
|
- } catch (Exception e) {
|
|
211
|
|
- log.error("场景[{}] 写回失败", s.getId(), e);
|
|
|
656
|
+ JSONObject todayRec = this.findTodayRecord(allRecords, s, sceneBiz, qx.getTimeField());
|
|
|
657
|
+ if (todayRec != null) {
|
|
|
658
|
+ todayRec.put(qx.getCountField(), (Object)count);
|
|
|
659
|
+ JdyRiskStatisticsService.setTimeFields(todayRec, qx, now);
|
|
|
660
|
+ if (!skipAttach && qx.getAttachField() != null && !qx.getAttachField().isEmpty()) {
|
|
|
661
|
+ todayRec.put(qx.getAttachField(), (Object)this.buildAttach(fileId, fileName, size));
|
|
|
662
|
+ todayRec.put(qx.getAttachField() + "Id", (Object)fileId);
|
|
|
663
|
+ }
|
|
|
664
|
+ qxApi.updateData(token, qx.getAppId(), qx.getUpdateCode(), todayRec);
|
|
|
665
|
+ log.info("\u5f53\u5929\u5df2\u5b58\u5728\u2192\u66f4\u65b0\u6210\u529f: syncCode={} id={} {}={} \u9644\u4ef6={}", new Object[]{syncCode, todayRec.getString("id"), qx.getCountField(), count, fileName});
|
|
|
666
|
+ } else {
|
|
|
667
|
+ JSONObject addBody;
|
|
|
668
|
+ JSONObject template = this.findRecordBySyncCode(allRecords, s, sceneBiz);
|
|
|
669
|
+ if (template != null) {
|
|
|
670
|
+ addBody = this.cloneTemplate(template, qx, syncCode, count, now, fileId, fileName, size, skipAttach);
|
|
|
671
|
+ log.info("\u5f53\u5929\u65e0\u6570\u636e\u2192\u4ee5[{}]\u73b0\u6709\u8bb0\u5f55\u4e3a\u6a21\u677f\u65b0\u589e", (Object)syncCode);
|
|
|
672
|
+ } else {
|
|
|
673
|
+ Biz biz = sceneBiz;
|
|
|
674
|
+ if (biz == null) {
|
|
|
675
|
+ throw new IllegalStateException("\u672a\u914d\u7f6e\u8be5\u573a\u666f\u7684\u65b0\u589e\u4e1a\u52a1\u6570\u636e(\u6a21\u677f): " + syncCode);
|
|
|
676
|
+ }
|
|
|
677
|
+ addBody = this.buildAddBody(biz, qx, syncCode, count, now, fileId, fileName, size);
|
|
|
678
|
+ }
|
|
|
679
|
+ String newId = qxApi.addData(token, qx.getAppId(), qx.getAddCode(), addBody);
|
|
|
680
|
+ log.info("\u5f53\u5929\u65e0\u6570\u636e\u2192\u65b0\u589e\u6210\u529f: syncCode={} newId={} {}={} \u9644\u4ef6={}", new Object[]{syncCode, newId, qx.getCountField(), count, fileName});
|
|
|
681
|
+ }
|
|
|
682
|
+ }
|
|
|
683
|
+ catch (Exception e) {
|
|
|
684
|
+ log.error("\u573a\u666f[{}] \u5199\u56de\u5931\u8d25", (Object)s.getId(), (Object)e);
|
|
212
|
685
|
result.put(s.getId() + "_error", e.getMessage());
|
|
213
|
686
|
}
|
|
214
|
687
|
}
|
|
215
|
688
|
|
|
216
|
|
- /* ==================== 范围过滤 ==================== */
|
|
217
|
|
-
|
|
218
|
|
- /** 按场景统计周期过滤数据:全量 / 当月 / 当季度 / 当年 / 上月。 */
|
|
219
|
689
|
private JSONArray filterScope(JSONArray all, JdyRiskProperties.Scenario s) {
|
|
220
|
|
- if (!s.isMonthOnly() && !s.isQuarterOnly() && !s.isYearOnly() && !s.isPrevMonthOnly()) {
|
|
|
690
|
+ ZonedDateTime hmEnd;
|
|
|
691
|
+ ZonedDateTime hmStart;
|
|
|
692
|
+ if (!(s.isMonthOnly() || s.isQuarterOnly() || s.isPrevQuarterOnly() || s.isYearOnly() || s.isPrevMonthOnly() || s.isPrevThreeMonths() || s.isHalfMonthOnly())) {
|
|
221
|
693
|
return all;
|
|
222
|
694
|
}
|
|
223
|
|
- ZonedDateTime now = ZonedDateTime.now(ZONE);
|
|
224
|
|
- ZonedDateTime qStart = quarterStart(now);
|
|
225
|
|
- ZonedDateTime qEnd = qStart.plusMonths(3);
|
|
|
695
|
+ ZonedDateTime now = this.now();
|
|
|
696
|
+ ZonedDateTime qStart = JdyRiskStatisticsService.quarterStart(now);
|
|
|
697
|
+ ZonedDateTime qEnd = qStart.plusMonths(3L);
|
|
|
698
|
+ ZonedDateTime pqStart = qStart.minusMonths(3L);
|
|
226
|
699
|
ZonedDateTime yStart = now.withDayOfYear(1).truncatedTo(ChronoUnit.DAYS);
|
|
227
|
|
- ZonedDateTime pmStart = now.minusMonths(1).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
|
700
|
+ ZonedDateTime pmStart = now.minusMonths(1L).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
228
|
701
|
ZonedDateTime pmEnd = now.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
|
702
|
+ ZonedDateTime p3Start = now.minusMonths(3L).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
|
703
|
+ ZonedDateTime monthStart = now.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
|
704
|
+ if (now.getDayOfMonth() < 16) {
|
|
|
705
|
+ hmStart = monthStart.minusMonths(1L).plusDays(15L);
|
|
|
706
|
+ hmEnd = monthStart;
|
|
|
707
|
+ } else {
|
|
|
708
|
+ hmStart = monthStart;
|
|
|
709
|
+ hmEnd = monthStart.plusDays(15L);
|
|
|
710
|
+ }
|
|
229
|
711
|
String month = now.format(MONTH_FMT);
|
|
230
|
712
|
JSONArray out = new JSONArray();
|
|
231
|
|
- for (int i = 0; i < all.size(); i++) {
|
|
|
713
|
+ for (int i = 0; i < all.size(); ++i) {
|
|
232
|
714
|
JSONObject row = all.getJSONObject(i);
|
|
233
|
|
- ZonedDateTime dt = parseTime(row.getString(s.getDateField()));
|
|
234
|
|
- if (dt == null) {
|
|
235
|
|
- continue;
|
|
236
|
|
- }
|
|
|
715
|
+ ZonedDateTime dt = JdyRiskStatisticsService.parseTime(row.getString(s.getDateField()));
|
|
|
716
|
+ if (dt == null) continue;
|
|
237
|
717
|
boolean keep = false;
|
|
238
|
718
|
if (s.isQuarterOnly()) {
|
|
239
|
719
|
keep = !dt.isBefore(qStart) && dt.isBefore(qEnd);
|
|
|
720
|
+ } else if (s.isPrevQuarterOnly()) {
|
|
|
721
|
+ keep = !dt.isBefore(pqStart) && dt.isBefore(qStart);
|
|
240
|
722
|
} else if (s.isYearOnly()) {
|
|
241
|
723
|
keep = !dt.isBefore(yStart) && !dt.isAfter(now);
|
|
|
724
|
+ } else if (s.isHalfMonthOnly()) {
|
|
|
725
|
+ keep = !dt.isBefore(hmStart) && dt.isBefore(hmEnd);
|
|
242
|
726
|
} else if (s.isPrevMonthOnly()) {
|
|
243
|
727
|
keep = !dt.isBefore(pmStart) && dt.isBefore(pmEnd);
|
|
|
728
|
+ } else if (s.isPrevThreeMonths()) {
|
|
|
729
|
+ keep = !dt.isBefore(p3Start) && dt.isBefore(pmEnd);
|
|
244
|
730
|
} else if (s.isMonthOnly()) {
|
|
245
|
731
|
keep = month.equals(dt.format(MONTH_FMT));
|
|
246
|
732
|
}
|
|
247
|
|
- if (keep) {
|
|
248
|
|
- out.add(row);
|
|
249
|
|
- }
|
|
|
733
|
+ if (!keep) continue;
|
|
|
734
|
+ out.add((Object)row);
|
|
250
|
735
|
}
|
|
251
|
736
|
return out;
|
|
252
|
737
|
}
|
|
253
|
738
|
|
|
254
|
|
- /* ==================== 计数 ==================== */
|
|
255
|
|
-
|
|
256
|
739
|
private long count(JdyRiskProperties.Scenario s, JSONArray rows) {
|
|
257
|
|
- String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
258
|
|
- switch (type) {
|
|
259
|
|
- case "scenario1":
|
|
260
|
|
- return countScenario1(s, rows);
|
|
261
|
|
- case "scenario2":
|
|
262
|
|
- return countScenario2(s, rows);
|
|
263
|
|
- case "scenario3":
|
|
264
|
|
- return countScenario3(s, rows);
|
|
265
|
|
- case "scenario4":
|
|
266
|
|
- case "scenario5":
|
|
267
|
|
- return countGroupByUp(s, rows);
|
|
268
|
|
- case "scenario6":
|
|
269
|
|
- return warningGroupsByCount(s, rows).size();
|
|
270
|
|
- case "scenario8":
|
|
271
|
|
- case "scenario9":
|
|
272
|
|
- return warningGroupsByRatio(s, rows).size();
|
|
273
|
|
- default:
|
|
274
|
|
- throw new IllegalStateException("未知场景类型: " + s.getType());
|
|
275
|
|
- }
|
|
276
|
|
- }
|
|
277
|
|
-
|
|
278
|
|
- /** 场景1:总计>=5 且 差值>=1 且 flowState=进行中。 */
|
|
|
740
|
+ String type;
|
|
|
741
|
+ switch (type = s.getType() == null ? "" : s.getType().toLowerCase()) {
|
|
|
742
|
+ case "scenario1": {
|
|
|
743
|
+ return this.countScenario1(s, rows);
|
|
|
744
|
+ }
|
|
|
745
|
+ case "scenario2": {
|
|
|
746
|
+ return this.countScenario2(s, rows);
|
|
|
747
|
+ }
|
|
|
748
|
+ case "scenario3": {
|
|
|
749
|
+ return this.countScenario3(s, rows);
|
|
|
750
|
+ }
|
|
|
751
|
+ case "scenario4":
|
|
|
752
|
+ case "scenario5": {
|
|
|
753
|
+ return this.countGroupByUp(s, rows);
|
|
|
754
|
+ }
|
|
|
755
|
+ case "scenario6": {
|
|
|
756
|
+ return this.warningGroupsByCount(s, rows).size();
|
|
|
757
|
+ }
|
|
|
758
|
+ case "scenario8":
|
|
|
759
|
+ case "scenario9": {
|
|
|
760
|
+ return this.warningGroupsByRatio(s, rows).size();
|
|
|
761
|
+ }
|
|
|
762
|
+ case "scenario10": {
|
|
|
763
|
+ return rows.size();
|
|
|
764
|
+ }
|
|
|
765
|
+ }
|
|
|
766
|
+ throw new IllegalStateException("\u672a\u77e5\u573a\u666f\u7c7b\u578b: " + s.getType());
|
|
|
767
|
+ }
|
|
|
768
|
+
|
|
279
|
769
|
private long countScenario1(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
280
|
|
- long hit = 0;
|
|
281
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
770
|
+ long hit = 0L;
|
|
|
771
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
282
|
772
|
JSONObject row = data.getJSONObject(i);
|
|
283
|
|
- double total = num(row, s.getTotalField());
|
|
284
|
|
- double diff = num(row, s.getDiffField());
|
|
|
773
|
+ double total = JdyRiskStatisticsService.num(row, s.getTotalField());
|
|
|
774
|
+ double diff = JdyRiskStatisticsService.num(row, s.getDiffField());
|
|
285
|
775
|
Integer flow = row.getInteger("flowState");
|
|
286
|
|
- if (total >= 5 && diff >= 1 && flow != null && flow == s.getInProgressState()) {
|
|
287
|
|
- hit++;
|
|
288
|
|
- }
|
|
|
776
|
+ if (!(total >= 5.0) || !(diff >= 1.0) || flow == null || flow.intValue() != s.getInProgressState()) continue;
|
|
|
777
|
+ ++hit;
|
|
289
|
778
|
}
|
|
290
|
779
|
return hit;
|
|
291
|
780
|
}
|
|
292
|
781
|
|
|
293
|
|
- /** 场景2:按供应商分组,SI数量/问题数量合计>60% 且 合计>=5 的供应商个数。 */
|
|
294
|
782
|
private long countScenario2(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
295
|
|
- Map<String, double[]> byGroup = new LinkedHashMap<>();
|
|
296
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
783
|
+ LinkedHashMap<String, double[]> byGroup = new LinkedHashMap<String, double[]>();
|
|
|
784
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
297
|
785
|
JSONObject row = data.getJSONObject(i);
|
|
298
|
|
- String group = orEmpty(row.getString(s.getGroupField()));
|
|
299
|
|
- double qty = num(row, s.getQtyField());
|
|
|
786
|
+ String group = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
|
787
|
+ double qty = JdyRiskStatisticsService.num(row, s.getQtyField());
|
|
300
|
788
|
double[] agg = byGroup.computeIfAbsent(group, k -> new double[2]);
|
|
301
|
|
- agg[0] += qty;
|
|
302
|
|
- if ("SI".equalsIgnoreCase(row.getString(s.getSiField()))) {
|
|
303
|
|
- agg[1] += qty;
|
|
304
|
|
- }
|
|
|
789
|
+ agg[0] = agg[0] + qty;
|
|
|
790
|
+ if (!"SI".equalsIgnoreCase(row.getString(s.getSiField()))) continue;
|
|
|
791
|
+ agg[1] = agg[1] + qty;
|
|
305
|
792
|
}
|
|
306
|
|
- long hit = 0;
|
|
|
793
|
+ long hit = 0L;
|
|
307
|
794
|
for (double[] agg : byGroup.values()) {
|
|
308
|
|
- if (agg[0] >= 5 && (agg[1] / agg[0]) > 0.6) {
|
|
309
|
|
- hit++;
|
|
310
|
|
- }
|
|
|
795
|
+ if (!(agg[0] >= 5.0) || !(agg[1] / agg[0] > 0.6)) continue;
|
|
|
796
|
+ ++hit;
|
|
311
|
797
|
}
|
|
312
|
798
|
return hit;
|
|
313
|
799
|
}
|
|
314
|
800
|
|
|
315
|
|
- /** 场景3:SI占比>60% 且 总问题数>=5 的行数(工程师个数)。 */
|
|
316
|
801
|
private long countScenario3(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
317
|
|
- long hit = 0;
|
|
318
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
802
|
+ long hit = 0L;
|
|
|
803
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
319
|
804
|
JSONObject row = data.getJSONObject(i);
|
|
320
|
|
- double total = num(row, s.getTotalField());
|
|
321
|
|
- double ratio = num(row, s.getRatioField());
|
|
322
|
|
- if (total >= 5 && ratio > 0.6) {
|
|
323
|
|
- hit++;
|
|
324
|
|
- }
|
|
|
805
|
+ double total = JdyRiskStatisticsService.num(row, s.getTotalField());
|
|
|
806
|
+ double ratio = JdyRiskStatisticsService.num(row, s.getRatioField());
|
|
|
807
|
+ if (!(total >= 5.0) || !(ratio > 0.6)) continue;
|
|
|
808
|
+ ++hit;
|
|
325
|
809
|
}
|
|
326
|
810
|
return hit;
|
|
327
|
811
|
}
|
|
328
|
812
|
|
|
329
|
|
- /** 场景4/5:升级不含排除值且非空,按分组计数,分组次数 >= minCount 的命中分组个数。 */
|
|
330
|
813
|
private long countGroupByUp(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
331
|
|
- return warningGroupsByUp(s, data).size();
|
|
|
814
|
+ return this.warningGroupsByUp(s, data).size();
|
|
332
|
815
|
}
|
|
333
|
816
|
|
|
334
|
|
- /** 场景4/5:命中分组集合(升级不含排除值且非空,分组计数 >= minCount)。 */
|
|
335
|
817
|
private Set<String> warningGroupsByUp(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
336
|
|
- Map<String, Integer> counts = new LinkedHashMap<>();
|
|
337
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
818
|
+ LinkedHashMap<String, Integer> counts = new LinkedHashMap<String, Integer>();
|
|
|
819
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
338
|
820
|
JSONObject row = data.getJSONObject(i);
|
|
339
|
|
- if (isUpHit(s, row)) {
|
|
340
|
|
- String g = orEmpty(row.getString(s.getGroupField()));
|
|
341
|
|
- counts.merge(g, 1, Integer::sum);
|
|
342
|
|
- }
|
|
|
821
|
+ if (!this.isUpHit(s, row)) continue;
|
|
|
822
|
+ String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
|
823
|
+ counts.merge(g, 1, Integer::sum);
|
|
343
|
824
|
}
|
|
344
|
825
|
int threshold = Math.max(1, s.getMinCount());
|
|
345
|
|
- Set<String> warn = new LinkedHashSet<>();
|
|
346
|
|
- for (Map.Entry<String, Integer> e : counts.entrySet()) {
|
|
347
|
|
- if (e.getValue() >= threshold) {
|
|
348
|
|
- warn.add(e.getKey());
|
|
349
|
|
- }
|
|
|
826
|
+ LinkedHashSet<String> warn = new LinkedHashSet<String>();
|
|
|
827
|
+ for (Map.Entry e : counts.entrySet()) {
|
|
|
828
|
+ if ((Integer)e.getValue() < threshold) continue;
|
|
|
829
|
+ warn.add((String)e.getKey());
|
|
350
|
830
|
}
|
|
351
|
831
|
return warn;
|
|
352
|
832
|
}
|
|
353
|
833
|
|
|
354
|
|
- /** 场景6:按分组字段计数,分组次数 >= minCount 的命中分组集合。 */
|
|
355
|
834
|
private Set<String> warningGroupsByCount(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
356
|
|
- Map<String, Integer> counts = new LinkedHashMap<>();
|
|
357
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
835
|
+ LinkedHashMap<String, Integer> counts = new LinkedHashMap<String, Integer>();
|
|
|
836
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
358
|
837
|
JSONObject row = data.getJSONObject(i);
|
|
359
|
|
- String g = orEmpty(row.getString(s.getGroupField()));
|
|
|
838
|
+ String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
360
|
839
|
counts.merge(g, 1, Integer::sum);
|
|
361
|
840
|
}
|
|
362
|
841
|
int threshold = Math.max(1, s.getMinCount());
|
|
363
|
|
- Set<String> warn = new LinkedHashSet<>();
|
|
364
|
|
- for (Map.Entry<String, Integer> e : counts.entrySet()) {
|
|
365
|
|
- if (e.getValue() >= threshold) {
|
|
366
|
|
- warn.add(e.getKey());
|
|
367
|
|
- }
|
|
|
842
|
+ LinkedHashSet<String> warn = new LinkedHashSet<String>();
|
|
|
843
|
+ for (Map.Entry e : counts.entrySet()) {
|
|
|
844
|
+ if ((Integer)e.getValue() < threshold) continue;
|
|
|
845
|
+ warn.add((String)e.getKey());
|
|
368
|
846
|
}
|
|
369
|
847
|
return warn;
|
|
370
|
848
|
}
|
|
371
|
849
|
|
|
372
|
|
- /** 场景8/9:按分组字段,flagField==flagValue 的条数 / 总条数 > ratioThreshold 的命中分组集合。 */
|
|
373
|
850
|
private Set<String> warningGroupsByRatio(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
374
|
|
- Map<String, int[]> byGroup = new LinkedHashMap<>(); // [总数, 命中数]
|
|
375
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
851
|
+ LinkedHashMap<String, int[]> byGroup = new LinkedHashMap<String, int[]>();
|
|
|
852
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
376
|
853
|
JSONObject row = data.getJSONObject(i);
|
|
377
|
|
- String g = orEmpty(row.getString(s.getGroupField()));
|
|
|
854
|
+ String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
378
|
855
|
int[] agg = byGroup.computeIfAbsent(g, k -> new int[2]);
|
|
379
|
|
- agg[0]++;
|
|
380
|
|
- if (s.getFlagValue() != null && s.getFlagValue().equalsIgnoreCase(row.getString(s.getFlagField()))) {
|
|
381
|
|
- agg[1]++;
|
|
382
|
|
- }
|
|
|
856
|
+ agg[0] = agg[0] + 1;
|
|
|
857
|
+ if (s.getFlagValue() == null || !s.getFlagValue().equalsIgnoreCase(row.getString(s.getFlagField()))) continue;
|
|
|
858
|
+ agg[1] = agg[1] + 1;
|
|
383
|
859
|
}
|
|
384
|
|
- Set<String> warn = new LinkedHashSet<>();
|
|
|
860
|
+ LinkedHashSet<String> warn = new LinkedHashSet<String>();
|
|
385
|
861
|
double th = s.getRatioThreshold();
|
|
386
|
|
- for (Map.Entry<String, int[]> e : byGroup.entrySet()) {
|
|
387
|
|
- int[] agg = e.getValue();
|
|
388
|
|
- if (agg[0] > 0 && ((double) agg[1] / agg[0]) > th) {
|
|
389
|
|
- warn.add(e.getKey());
|
|
390
|
|
- }
|
|
|
862
|
+ for (Map.Entry e : byGroup.entrySet()) {
|
|
|
863
|
+ int[] agg = (int[])e.getValue();
|
|
|
864
|
+ if (agg[0] <= 0 || !((double)agg[1] / (double)agg[0] > th)) continue;
|
|
|
865
|
+ warn.add((String)e.getKey());
|
|
391
|
866
|
}
|
|
392
|
867
|
return warn;
|
|
393
|
868
|
}
|
|
394
|
869
|
|
|
395
|
|
- /**
|
|
396
|
|
- * 场景7:多表关联 + 超期过滤(分批流式,防大表 OOM)。
|
|
397
|
|
- * <p>① 收集排除表单的条码集合;② 流式遍历主表:条码命中排除集合则丢弃;③ 剩余按入库时间超过 maxAgeDays 天保留。
|
|
398
|
|
- */
|
|
399
|
870
|
private JSONArray buildScenario7Rows(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
400
|
|
- Set<String> exclude = new LinkedHashSet<>();
|
|
|
871
|
+ Instant lowerCutoff;
|
|
|
872
|
+ Instant cutoff;
|
|
|
873
|
+ LinkedHashSet exclude = new LinkedHashSet();
|
|
401
|
874
|
for (JdyRiskProperties.ExcludeForm ef : s.getExcludeForms()) {
|
|
402
|
|
- if (ef == null || ef.getEntryId() == null || ef.getBarcodeField() == null) {
|
|
403
|
|
- continue;
|
|
404
|
|
- }
|
|
405
|
|
- final JdyRiskProperties.ExcludeForm cur = ef;
|
|
406
|
|
- jdy.forEachPage(props.getApiKey(), s.getAppId(), cur.getEntryId(),
|
|
407
|
|
- java.util.Collections.singletonList(cur.getBarcodeField()), page -> {
|
|
408
|
|
- for (int i = 0; i < page.size(); i++) {
|
|
|
875
|
+ if (ef == null || ef.getEntryId() == null || ef.getBarcodeField() == null) continue;
|
|
|
876
|
+ JdyRiskProperties.ExcludeForm cur = ef;
|
|
|
877
|
+ this.forEachPageCached(jdy, s.getAppId(), cur.getEntryId(), Collections.singletonList(cur.getBarcodeField()), page -> {
|
|
|
878
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
409
|
879
|
String b = page.getJSONObject(i).getString(cur.getBarcodeField());
|
|
410
|
|
- if (b != null && !b.trim().isEmpty()) {
|
|
411
|
|
- exclude.add(b.trim());
|
|
412
|
|
- }
|
|
|
880
|
+ if (b == null || b.trim().isEmpty()) continue;
|
|
|
881
|
+ exclude.add(b.trim());
|
|
413
|
882
|
}
|
|
414
|
883
|
});
|
|
415
|
|
- log.info("场景7 排除来源 entry={} 累计条码={}", ef.getEntryId(), exclude.size());
|
|
|
884
|
+ log.info("\u573a\u666f7 \u6392\u9664\u6765\u6e90 entry={} \u7d2f\u8ba1\u6761\u7801={}", (Object)ef.getEntryId(), (Object)exclude.size());
|
|
|
885
|
+ }
|
|
|
886
|
+ if (s.isMonthlyOverdueIncremental()) {
|
|
|
887
|
+ ZonedDateTime prevMonthEnd = this.now().withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS).minusDays(1L);
|
|
|
888
|
+ ZonedDateTime prevRef = prevMonthEnd.minusMonths(1L);
|
|
|
889
|
+ cutoff = prevMonthEnd.minusDays(Math.max(0, s.getMaxAgeDays())).toInstant();
|
|
|
890
|
+ lowerCutoff = prevRef.minusDays(Math.max(0, s.getMaxAgeDays())).toInstant();
|
|
|
891
|
+ log.info("\u573a\u666f7 \u6309\u6708\u589e\u91cf\uff1a\u53c2\u8003\u4e0a\u6708\u672b={} cutoff={} \u4e0a\u6b21\u7a97\u53e3\u8d77\u70b9={}", new Object[]{prevMonthEnd.format(DAY_FMT), cutoff, lowerCutoff});
|
|
|
892
|
+ } else {
|
|
|
893
|
+ cutoff = this.now().minusDays(Math.max(0, s.getMaxAgeDays())).toInstant();
|
|
|
894
|
+ lowerCutoff = null;
|
|
416
|
895
|
}
|
|
417
|
|
-
|
|
418
|
|
- java.time.Instant cutoff = ZonedDateTime.now(ZONE)
|
|
419
|
|
- .minusDays(Math.max(0, s.getMaxAgeDays())).toInstant();
|
|
420
|
896
|
JSONArray kept = new JSONArray();
|
|
421
|
|
- final int[] scanned = {0};
|
|
422
|
|
- jdy.forEachPage(props.getApiKey(), s.getAppId(), s.getEntryId(), s.getFields(), page -> {
|
|
423
|
|
- for (int i = 0; i < page.size(); i++) {
|
|
424
|
|
- scanned[0]++;
|
|
|
897
|
+ int[] scanned = new int[]{0};
|
|
|
898
|
+ this.forEachPageCached(jdy, s.getAppId(), s.getEntryId(), s.getFields(), page -> {
|
|
|
899
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
900
|
+ Instant in;
|
|
|
901
|
+ ZonedDateTime inTime;
|
|
|
902
|
+ scanned[0] = scanned[0] + 1;
|
|
425
|
903
|
JSONObject row = page.getJSONObject(i);
|
|
426
|
904
|
String barcode = row.getString(s.getBarcodeField());
|
|
427
|
|
- if (barcode != null && exclude.contains(barcode.trim())) {
|
|
428
|
|
- continue; // 条码在出库/抵扣表中出现 → 过滤掉
|
|
429
|
|
- }
|
|
430
|
|
- ZonedDateTime inTime = parseTime(row.getString(s.getDateField()));
|
|
431
|
|
- if (inTime == null) {
|
|
432
|
|
- continue;
|
|
433
|
|
- }
|
|
434
|
|
- if (inTime.toInstant().isBefore(cutoff)) {
|
|
435
|
|
- kept.add(row); // 入库时间超过 maxAgeDays 天
|
|
436
|
|
- }
|
|
|
905
|
+ if (barcode != null && exclude.contains(barcode.trim()) || (inTime = JdyRiskStatisticsService.parseTime(row.getString(s.getDateField()))) == null || !(in = inTime.toInstant()).isBefore(cutoff) || lowerCutoff != null && in.isBefore(lowerCutoff)) continue;
|
|
|
906
|
+ kept.add((Object)row);
|
|
437
|
907
|
}
|
|
438
|
908
|
});
|
|
439
|
|
- log.info("场景7 主表扫描={}条, 过滤后保留={}条 (排除条码={}, 超期阈值={}天)",
|
|
440
|
|
- scanned[0], kept.size(), exclude.size(), s.getMaxAgeDays());
|
|
|
909
|
+ log.info("\u573a\u666f7 \u4e3b\u8868\u626b\u63cf={}\u6761, \u8fc7\u6ee4\u540e\u4fdd\u7559={}\u6761 (\u6392\u9664\u6761\u7801={}, \u8d85\u671f\u9608\u503c={}\u5929)", new Object[]{scanned[0], kept.size(), exclude.size(), s.getMaxAgeDays()});
|
|
441
|
910
|
return kept;
|
|
442
|
911
|
}
|
|
443
|
912
|
|
|
444
|
|
- /** 场景2:命中供应商集合(SI数量/问题数量合计>60% 且 合计>=5)。 */
|
|
445
|
|
- private Set<String> warningSuppliers2(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
446
|
|
- Map<String, double[]> byGroup = new LinkedHashMap<>();
|
|
447
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
448
|
|
- JSONObject row = data.getJSONObject(i);
|
|
449
|
|
- String group = orEmpty(row.getString(s.getGroupField()));
|
|
450
|
|
- double qty = num(row, s.getQtyField());
|
|
451
|
|
- double[] agg = byGroup.computeIfAbsent(group, k -> new double[2]);
|
|
452
|
|
- agg[0] += qty;
|
|
453
|
|
- if ("SI".equalsIgnoreCase(row.getString(s.getSiField()))) {
|
|
454
|
|
- agg[1] += qty;
|
|
|
913
|
+ private JSONArray filterByAbsThreshold(JdyRiskProperties.Scenario s, JSONArray rows) {
|
|
|
914
|
+ JSONArray out = new JSONArray();
|
|
|
915
|
+ for (int i = 0; i < rows.size(); ++i) {
|
|
|
916
|
+ JSONObject row = rows.getJSONObject(i);
|
|
|
917
|
+ if (!(Math.abs(JdyRiskStatisticsService.num(row, s.getDiffField())) > s.getAbsThreshold())) continue;
|
|
|
918
|
+ out.add((Object)row);
|
|
|
919
|
+ }
|
|
|
920
|
+ return out;
|
|
|
921
|
+ }
|
|
|
922
|
+
|
|
|
923
|
+ private JSONArray buildScopeRows(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
924
|
+ String type;
|
|
|
925
|
+ JSONArray all = this.listAllDataCached(jdy, s.getAppId(), s.getEntryId());
|
|
|
926
|
+ JSONArray scoped = this.filterScope(all, s);
|
|
|
927
|
+ String string = type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
928
|
+ if ("scenario10".equals(type)) {
|
|
|
929
|
+ return this.filterByAbsThreshold(s, scoped);
|
|
|
930
|
+ }
|
|
|
931
|
+ return scoped;
|
|
|
932
|
+ }
|
|
|
933
|
+
|
|
|
934
|
+ private Built11 buildScenario11(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
935
|
+ JSONArray aWidgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
|
936
|
+ JSONArray aRows = this.listAllDataCached(jdy, s.getAppId(), s.getEntryId());
|
|
|
937
|
+ JSONArray bWidgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getCompareEntryId());
|
|
|
938
|
+ JSONArray bRows = this.listAllDataCached(jdy, s.getAppId(), s.getCompareEntryId());
|
|
|
939
|
+ Set<String> cSet = new LinkedHashSet<String>();
|
|
|
940
|
+ for (JdyRiskProperties.ExcludeForm ef : s.getExcludeForms()) {
|
|
|
941
|
+ if (ef == null || ef.getEntryId() == null || ef.getBarcodeField() == null) continue;
|
|
|
942
|
+ final JdyRiskProperties.ExcludeForm cur = ef;
|
|
|
943
|
+ jdy.forEachPage(this.props.getApiKey(), s.getAppId(), ((JdyRiskProperties.ExcludeForm)((Object)cur)).getEntryId(), Collections.singletonList(((JdyRiskProperties.ExcludeForm)((Object)cur)).getBarcodeField()), page -> {
|
|
|
944
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
945
|
+ String b = page.getJSONObject(i).getString(cur.getBarcodeField());
|
|
|
946
|
+ if (b == null || b.trim().isEmpty()) continue;
|
|
|
947
|
+ cSet.add(b.trim());
|
|
|
948
|
+ }
|
|
|
949
|
+ });
|
|
|
950
|
+ }
|
|
|
951
|
+ Map<String, List<JSONObject>> aMap = JdyRiskStatisticsService.groupByBarcode(aRows, s.getBarcodeField());
|
|
|
952
|
+ Map<String, List<JSONObject>> bMap = JdyRiskStatisticsService.groupByBarcode(bRows, s.getCompareBarcodeField());
|
|
|
953
|
+ for (String k : cSet) {
|
|
|
954
|
+ aMap.remove(k);
|
|
|
955
|
+ bMap.remove(k);
|
|
|
956
|
+ }
|
|
|
957
|
+ for (String k : new ArrayList<String>(aMap.keySet())) {
|
|
|
958
|
+ List<JSONObject> bl = bMap.get(k);
|
|
|
959
|
+ if (bl == null) continue;
|
|
|
960
|
+ List<JSONObject> al = aMap.get(k);
|
|
|
961
|
+ int common = Math.min(al.size(), bl.size());
|
|
|
962
|
+ for (int i2 = 0; i2 < common; ++i2) {
|
|
|
963
|
+ al.remove(al.size() - 1);
|
|
|
964
|
+ bl.remove(bl.size() - 1);
|
|
455
|
965
|
}
|
|
|
966
|
+ if (al.isEmpty()) {
|
|
|
967
|
+ aMap.remove(k);
|
|
|
968
|
+ }
|
|
|
969
|
+ if (!bl.isEmpty()) continue;
|
|
|
970
|
+ bMap.remove(k);
|
|
456
|
971
|
}
|
|
457
|
|
- Set<String> warn = new LinkedHashSet<>();
|
|
458
|
|
- for (Map.Entry<String, double[]> e : byGroup.entrySet()) {
|
|
459
|
|
- double[] agg = e.getValue();
|
|
460
|
|
- if (agg[0] >= 5 && (agg[1] / agg[0]) > 0.6) {
|
|
461
|
|
- warn.add(e.getKey());
|
|
|
972
|
+ JSONArray excelRows = new JSONArray();
|
|
|
973
|
+ long pos = 0L;
|
|
|
974
|
+ long neg = 0L;
|
|
|
975
|
+ for (Map.Entry<String, List<JSONObject>> e : aMap.entrySet()) {
|
|
|
976
|
+ for (JSONObject row : e.getValue()) {
|
|
|
977
|
+ row.put("__type", (Object)"\u6b63");
|
|
|
978
|
+ excelRows.add((Object)row);
|
|
|
979
|
+ ++pos;
|
|
462
|
980
|
}
|
|
463
|
981
|
}
|
|
464
|
|
- return warn;
|
|
|
982
|
+ for (Map.Entry<String, List<JSONObject>> e : bMap.entrySet()) {
|
|
|
983
|
+ for (JSONObject row : e.getValue()) {
|
|
|
984
|
+ row.put("__type", (Object)"\u8d1f");
|
|
|
985
|
+ excelRows.add((Object)row);
|
|
|
986
|
+ ++neg;
|
|
|
987
|
+ }
|
|
|
988
|
+ }
|
|
|
989
|
+ JSONArray widgets = new JSONArray();
|
|
|
990
|
+ widgets.add((Object)JdyRiskStatisticsService.syntheticWidget("__type", "\u7c7b\u578b(\u6b63/\u8d1f)"));
|
|
|
991
|
+ for (int i = 0; i < aWidgets.size(); ++i) {
|
|
|
992
|
+ widgets.add((Object)aWidgets.getJSONObject(i));
|
|
|
993
|
+ }
|
|
|
994
|
+ for (int i = 0; i < bWidgets.size(); ++i) {
|
|
|
995
|
+ widgets.add((Object)bWidgets.getJSONObject(i));
|
|
|
996
|
+ }
|
|
|
997
|
+ Built11 built = new Built11();
|
|
|
998
|
+ built.count = pos + neg;
|
|
|
999
|
+ built.excelRows = excelRows;
|
|
|
1000
|
+ built.excelWidgets = widgets;
|
|
|
1001
|
+ log.info("\u573a\u666f11 A={}\u6761 B={}\u6761 C\u6761\u7801={} -> \u6b63={} \u8d1f={} \u9884\u8b66\u6570\u91cf={}", new Object[]{aRows.size(), bRows.size(), cSet.size(), pos, neg, built.count});
|
|
|
1002
|
+ return built;
|
|
|
1003
|
+ }
|
|
|
1004
|
+
|
|
|
1005
|
+ private static boolean isDbType(String type) {
|
|
|
1006
|
+ return "scenario33".equals(type) || "scenario34".equals(type) || "scenario35".equals(type);
|
|
|
1007
|
+ }
|
|
|
1008
|
+
|
|
|
1009
|
+ private static boolean isReasonType(String type) {
|
|
|
1010
|
+ return "scenario12".equals(type) || "scenario13".equals(type) || "scenario14".equals(type) || "scenario15".equals(type) || "scenario16".equals(type) || "scenario17".equals(type) || "scenario18".equals(type) || "scenario19".equals(type) || "scenario20".equals(type) || "scenario21".equals(type) || "scenario23".equals(type) || "scenario24".equals(type) || "scenario25".equals(type) || "scenario26".equals(type) || "scenario27".equals(type) || "scenario29".equals(type);
|
|
465
|
1011
|
}
|
|
466
|
1012
|
|
|
467
|
1013
|
/**
|
|
468
|
|
- * Excel 最右附加列的值(各场景统一):
|
|
469
|
|
- * 命中/预警的行显示对应名称,其余为空。
|
|
470
|
|
- * 取值优先级:extra-field > group-field > 「命中」。
|
|
|
1014
|
+ * 设备域场景20/21/22:直接查询人大金仓表,取「未处理/未处置」数据。
|
|
|
1015
|
+ * <p>Excel 首列固定为「原因」(表头红色),内容为「处理状态为未处理/未处置」。</p>
|
|
471
|
1016
|
*/
|
|
472
|
|
- private List<String> buildExtraValues(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
|
1017
|
+ private BuiltDb buildDbRows(JdyRiskProperties.Scenario s) {
|
|
473
|
1018
|
String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
474
|
|
- Set<String> warnGroups = null;
|
|
475
|
|
- if ("scenario2".equals(type)) {
|
|
476
|
|
- warnGroups = warningSuppliers2(s, data);
|
|
477
|
|
- } else if ("scenario4".equals(type) || "scenario5".equals(type)) {
|
|
478
|
|
- warnGroups = warningGroupsByUp(s, data);
|
|
479
|
|
- } else if ("scenario6".equals(type)) {
|
|
480
|
|
- warnGroups = warningGroupsByCount(s, data);
|
|
481
|
|
- } else if ("scenario8".equals(type) || "scenario9".equals(type)) {
|
|
482
|
|
- warnGroups = warningGroupsByRatio(s, data);
|
|
|
1019
|
+ JdyRiskProperties.Kingbase kb = this.props.getKingbase();
|
|
|
1020
|
+ KingbaseRiskDao dao = new KingbaseRiskDao(kb.getUrl(), kb.getUsername(), kb.getPassword(), kb.getDriverClass());
|
|
|
1021
|
+ String table = requireIdent(s.getTable(), "table");
|
|
|
1022
|
+ String handleField = requireIdent(s.getHandleField(), "handle-field");
|
|
|
1023
|
+
|
|
|
1024
|
+ List<String> columns = new ArrayList<String>();
|
|
|
1025
|
+ if (s.getColumns() != null) {
|
|
|
1026
|
+ for (String c : s.getColumns()) {
|
|
|
1027
|
+ if (c != null && !c.trim().isEmpty()) {
|
|
|
1028
|
+ columns.add(requireIdent(c, "columns"));
|
|
|
1029
|
+ }
|
|
|
1030
|
+ }
|
|
483
|
1031
|
}
|
|
484
|
|
- List<String> values = new ArrayList<>();
|
|
485
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
486
|
|
- JSONObject row = data.getJSONObject(i);
|
|
|
1032
|
+ String select = columns.isEmpty() ? "*" : String.join(", ", columns);
|
|
|
1033
|
+ StringBuilder sql = new StringBuilder("SELECT ").append(select).append(" FROM ").append(table).append(" WHERE ");
|
|
|
1034
|
+ List<Object> params = new ArrayList<Object>();
|
|
|
1035
|
+
|
|
|
1036
|
+ List<String> handleValues = s.getHandleValues();
|
|
|
1037
|
+ if (handleValues == null || handleValues.isEmpty()) {
|
|
|
1038
|
+ handleValues = Arrays.asList("\u672a\u5904\u7406", "\u672a\u5904\u7f6e");
|
|
|
1039
|
+ }
|
|
|
1040
|
+ sql.append(handleField).append(" IN (");
|
|
|
1041
|
+ for (int i = 0; i < handleValues.size(); i++) {
|
|
|
1042
|
+ if (i > 0) {
|
|
|
1043
|
+ sql.append(",");
|
|
|
1044
|
+ }
|
|
|
1045
|
+ sql.append("?");
|
|
|
1046
|
+ params.add(handleValues.get(i));
|
|
|
1047
|
+ }
|
|
|
1048
|
+ sql.append(")");
|
|
|
1049
|
+
|
|
|
1050
|
+ String periodDesc;
|
|
|
1051
|
+ if ("scenario33".equals(type)) {
|
|
|
1052
|
+ YearMonth dataMonth = YearMonth.from(this.now()).minusMonths(1L);
|
|
|
1053
|
+ String yf = requireIdent(s.getStatYearField(), "stat-year-field");
|
|
|
1054
|
+ String mf = requireIdent(s.getStatMonthField(), "stat-month-field");
|
|
|
1055
|
+ sql.append(" AND ").append(yf).append(" = ? AND ").append(mf).append(" = ?");
|
|
|
1056
|
+ params.add(String.valueOf(dataMonth.getYear()));
|
|
|
1057
|
+ params.add(String.format(Locale.ROOT, "%02d", dataMonth.getMonthValue()));
|
|
|
1058
|
+ sql.append(" ORDER BY ").append(yf).append(" DESC, ").append(mf).append(" DESC");
|
|
|
1059
|
+ periodDesc = dataMonth.toString();
|
|
|
1060
|
+ } else {
|
|
|
1061
|
+ String timeField = requireIdent(s.getDateField(), "date-field");
|
|
|
1062
|
+ ZonedDateTime n = this.now();
|
|
|
1063
|
+ ZonedDateTime start;
|
|
|
1064
|
+ ZonedDateTime end;
|
|
|
1065
|
+ if ("scenario34".equals(type)) {
|
|
|
1066
|
+ ZonedDateTime monthStart = n.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
|
1067
|
+ int day = n.getDayOfMonth();
|
|
|
1068
|
+ if (day == 11 || day <= 10) {
|
|
|
1069
|
+ start = monthStart;
|
|
|
1070
|
+ end = monthStart.plusDays(10L);
|
|
|
1071
|
+ periodDesc = "1-10";
|
|
|
1072
|
+ } else if (day == 21 || day <= 20) {
|
|
|
1073
|
+ start = monthStart.plusDays(10L);
|
|
|
1074
|
+ end = monthStart.plusDays(20L);
|
|
|
1075
|
+ periodDesc = "11-20";
|
|
|
1076
|
+ } else {
|
|
|
1077
|
+ start = monthStart.plusDays(20L);
|
|
|
1078
|
+ end = monthStart.plusMonths(1L);
|
|
|
1079
|
+ periodDesc = "21-end";
|
|
|
1080
|
+ }
|
|
|
1081
|
+ } else {
|
|
|
1082
|
+ ZonedDateTime currentMonthStart = n.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
|
1083
|
+ start = currentMonthStart.minusMonths(1L);
|
|
|
1084
|
+ end = currentMonthStart;
|
|
|
1085
|
+ periodDesc = YearMonth.from(start).toString();
|
|
|
1086
|
+ }
|
|
|
1087
|
+ LocalDate capDate = this.backfillEndDate.get();
|
|
|
1088
|
+ if (capDate != null) {
|
|
|
1089
|
+ ZonedDateTime capEnd = ZonedDateTime.of(capDate.plusDays(1L), LocalTime.MIDNIGHT, ZONE);
|
|
|
1090
|
+ if (end.isAfter(capEnd)) {
|
|
|
1091
|
+ end = capEnd;
|
|
|
1092
|
+ }
|
|
|
1093
|
+ }
|
|
|
1094
|
+ DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
1095
|
+ sql.append(" AND ").append(timeField).append(" >= ? AND ").append(timeField).append(" < ?");
|
|
|
1096
|
+ params.add(start.format(fmt));
|
|
|
1097
|
+ params.add(end.format(fmt));
|
|
|
1098
|
+ sql.append(" ORDER BY ").append(timeField).append(" DESC");
|
|
|
1099
|
+ periodDesc = start.format(DAY_FMT) + " ~ " + end.minusSeconds(1L).format(DAY_FMT);
|
|
|
1100
|
+ }
|
|
|
1101
|
+
|
|
|
1102
|
+ List<Map<String, Object>> data = dao.query(sql.toString(), params);
|
|
|
1103
|
+ BuiltDb built = new BuiltDb();
|
|
|
1104
|
+ List<String> displayColumns = new ArrayList<String>(columns);
|
|
|
1105
|
+ for (Map<String, Object> r : data) {
|
|
|
1106
|
+ JSONObject row = new JSONObject();
|
|
|
1107
|
+ row.putAll(r);
|
|
|
1108
|
+ built.rows.add(row);
|
|
|
1109
|
+ if (displayColumns.isEmpty()) {
|
|
|
1110
|
+ displayColumns.addAll(r.keySet());
|
|
|
1111
|
+ }
|
|
|
1112
|
+ built.reasons.add("\u5904\u7406\u72b6\u6001\u4e3a" + statusLabel(s, r.get(handleField.toLowerCase())));
|
|
|
1113
|
+ }
|
|
|
1114
|
+ JSONArray widgets = new JSONArray();
|
|
|
1115
|
+ for (String c : displayColumns) {
|
|
|
1116
|
+ String label = s.getColumnLabels() == null ? null : s.getColumnLabels().get(c);
|
|
|
1117
|
+ if (label == null || label.isEmpty()) {
|
|
|
1118
|
+ label = c;
|
|
|
1119
|
+ }
|
|
|
1120
|
+ widgets.add(syntheticWidget(c, label));
|
|
|
1121
|
+ }
|
|
|
1122
|
+ built.widgets = widgets;
|
|
|
1123
|
+ built.count = built.rows.size();
|
|
|
1124
|
+ log.info("\u573a\u666f[{}] \u91d1\u4ed3\u67e5\u8be2 table={} \u7edf\u8ba1\u671f={} \u672a\u5904\u7406\u547d\u4e2d={}\u6761",
|
|
|
1125
|
+ new Object[]{s.getId(), table, periodDesc, built.count});
|
|
|
1126
|
+ return built;
|
|
|
1127
|
+ }
|
|
|
1128
|
+
|
|
|
1129
|
+ /** 状态码转中文:如过磅表 is_handled=3 -> 未处理。 */
|
|
|
1130
|
+ private static String statusLabel(JdyRiskProperties.Scenario s, Object raw) {
|
|
|
1131
|
+ if (raw == null) {
|
|
|
1132
|
+ return "";
|
|
|
1133
|
+ }
|
|
|
1134
|
+ String v = String.valueOf(raw).trim();
|
|
|
1135
|
+ Map<String, String> labels = s.getHandleValueLabels();
|
|
|
1136
|
+ if (labels != null) {
|
|
|
1137
|
+ String lb = labels.get(v);
|
|
|
1138
|
+ if (lb != null && !lb.isEmpty()) {
|
|
|
1139
|
+ return lb;
|
|
|
1140
|
+ }
|
|
|
1141
|
+ }
|
|
|
1142
|
+ return v;
|
|
|
1143
|
+ }
|
|
|
1144
|
+
|
|
|
1145
|
+ /** 校验 SQL 标识符(表名/列名只能来自配置,禁止拼接任意字符串)。 */
|
|
|
1146
|
+ private static String requireIdent(String value, String name) {
|
|
|
1147
|
+ if (value == null || value.trim().isEmpty()) {
|
|
|
1148
|
+ throw new IllegalStateException("\u573a\u666f\u7f3a\u5c11\u914d\u7f6e: " + name);
|
|
|
1149
|
+ }
|
|
|
1150
|
+ String v = value.trim();
|
|
|
1151
|
+ if (!v.matches("[A-Za-z_][A-Za-z0-9_]*")) {
|
|
|
1152
|
+ throw new IllegalStateException("\u975e\u6cd5\u7684\u6570\u636e\u5e93\u6807\u8bc6\u7b26(" + name + "): " + v);
|
|
|
1153
|
+ }
|
|
|
1154
|
+ return v;
|
|
|
1155
|
+ }
|
|
|
1156
|
+
|
|
|
1157
|
+ /*
|
|
|
1158
|
+ * WARNING - void declaration
|
|
|
1159
|
+ */
|
|
|
1160
|
+ private BuiltReason buildReasonRows(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1161
|
+ JSONArray all = this.listAllDataCached(jdy, s.getAppId(), s.getEntryId());
|
|
|
1162
|
+ JSONArray scoped = this.filterScope(all, s);
|
|
|
1163
|
+ String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
1164
|
+ BuiltReason built = new BuiltReason();
|
|
|
1165
|
+ long explicitCount = -1L;
|
|
|
1166
|
+ if ("scenario12".equals(type)) {
|
|
|
1167
|
+ int n = 0;
|
|
|
1168
|
+ for (JdyRiskProperties.Pair p : s.getPairs()) {
|
|
|
1169
|
+ ++n;
|
|
|
1170
|
+ if (p == null || p.getPersonField() == null || p.getSignField() == null) continue;
|
|
|
1171
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1172
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1173
|
+ if (!JdyRiskStatisticsService.hasValue(row, p.getPersonField()) || JdyRiskStatisticsService.hasValue(row, p.getSignField())) continue;
|
|
|
1174
|
+ row.put("__reason_" + n, (Object)("\u53c2\u4e0e\u4eba\u5458" + n + "\u672a\u7b7e\u5b57\u786e\u8ba4"));
|
|
|
1175
|
+ }
|
|
|
1176
|
+ }
|
|
|
1177
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1178
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1179
|
+ ArrayList<String> arrayList = new ArrayList<String>();
|
|
|
1180
|
+ for (int k2 = 1; k2 <= n; ++k2) {
|
|
|
1181
|
+ Object r = row.get((Object)("__reason_" + k2));
|
|
|
1182
|
+ if (r == null) continue;
|
|
|
1183
|
+ arrayList.add(String.valueOf(r));
|
|
|
1184
|
+ row.remove((Object)("__reason_" + k2));
|
|
|
1185
|
+ }
|
|
|
1186
|
+ if (arrayList.isEmpty()) continue;
|
|
|
1187
|
+ built.rows.add((Object)row);
|
|
|
1188
|
+ built.reasons.add(String.join((CharSequence)"\u3001", arrayList));
|
|
|
1189
|
+ }
|
|
|
1190
|
+ } else if ("scenario13".equals(type)) {
|
|
|
1191
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1192
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1193
|
+ if (JdyRiskStatisticsService.num(row, s.getDurationField()) <= s.getDurationThreshold()) continue;
|
|
|
1194
|
+ ArrayList<String> reasons = new ArrayList<String>();
|
|
|
1195
|
+ if (s.getAbnormalValue() != null && s.getAbnormalValue().equals(row.getString(s.getAbnormalField()))) {
|
|
|
1196
|
+ reasons.add("\u5b58\u5728\u5f02\u5e38\u51fa\u95e8");
|
|
|
1197
|
+ }
|
|
|
1198
|
+ if (!JdyRiskStatisticsService.hasValue(row, s.getReasonField())) {
|
|
|
1199
|
+ reasons.add("\u5f02\u5e38\u539f\u56e0\u8bf4\u660e\u4e3a\u7a7a");
|
|
|
1200
|
+ }
|
|
|
1201
|
+ if (reasons.isEmpty()) continue;
|
|
|
1202
|
+ built.rows.add((Object)row);
|
|
|
1203
|
+ built.reasons.add(String.join((CharSequence)"\u3001", reasons));
|
|
|
1204
|
+ }
|
|
|
1205
|
+ } else if ("scenario14".equals(type)) {
|
|
|
1206
|
+ LinkedHashMap<String, Integer> counts = new LinkedHashMap<String, Integer>();
|
|
|
1207
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1208
|
+ String g = JdyRiskStatisticsService.orEmpty(scoped.getJSONObject(i).getString(s.getGroupField()));
|
|
|
1209
|
+ counts.merge(g, 1, Integer::sum);
|
|
|
1210
|
+ }
|
|
|
1211
|
+ int threshold = Math.max(1, s.getMinCount());
|
|
|
1212
|
+ long hitGroups = 0L;
|
|
|
1213
|
+ for (Map.Entry e : counts.entrySet()) {
|
|
|
1214
|
+ if ((Integer)e.getValue() < threshold) continue;
|
|
|
1215
|
+ ++hitGroups;
|
|
|
1216
|
+ }
|
|
|
1217
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1218
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1219
|
+ String string = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
|
1220
|
+ Integer c = (Integer)counts.get(string);
|
|
|
1221
|
+ if (c == null || c < threshold) continue;
|
|
|
1222
|
+ built.rows.add((Object)row);
|
|
|
1223
|
+ built.reasons.add("\u540c\u4e00\u4f9b\u5e94\u5546[" + string + "]\u51fa\u73b0" + c + "\u6b21");
|
|
|
1224
|
+ }
|
|
|
1225
|
+ explicitCount = hitGroups;
|
|
|
1226
|
+ } else if ("scenario15".equals(type)) {
|
|
|
1227
|
+ Map<String, String> labels = this.widgetLabels(jdy, s);
|
|
|
1228
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1229
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1230
|
+ if (!JdyRiskStatisticsService.flowStateMatches(s, row)) continue;
|
|
|
1231
|
+ ArrayList<String> arrayList = new ArrayList<String>();
|
|
|
1232
|
+ for (JdyRiskProperties.PhotoRule r : s.getPhotoRules()) {
|
|
|
1233
|
+ if (r == null || r.getFlagField() == null || r.getPhotoField() == null || r.getFlagValue() == null || !r.getFlagValue().equals(row.getString(r.getFlagField())) || JdyRiskStatisticsService.hasValue(row, r.getPhotoField())) continue;
|
|
|
1234
|
+ String lb = r.getLabel();
|
|
|
1235
|
+ if (lb == null || lb.isEmpty()) {
|
|
|
1236
|
+ lb = labels.getOrDefault(r.getPhotoField(), r.getPhotoField());
|
|
|
1237
|
+ }
|
|
|
1238
|
+ arrayList.add(lb + "\u4e3a\u7a7a");
|
|
|
1239
|
+ }
|
|
|
1240
|
+ if (arrayList.isEmpty()) continue;
|
|
|
1241
|
+ built.rows.add((Object)row);
|
|
|
1242
|
+ built.reasons.add(String.join((CharSequence)"\u3001", arrayList));
|
|
|
1243
|
+ }
|
|
|
1244
|
+ } else if ("scenario16".equals(type)) {
|
|
|
1245
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1246
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1247
|
+ String v = row.getString(s.getFlagField());
|
|
|
1248
|
+ if (v == null || !s.getFlagValues().contains(v) || JdyRiskStatisticsService.hasValue(row, s.getReasonField())) continue;
|
|
|
1249
|
+ built.rows.add((Object)row);
|
|
|
1250
|
+ built.reasons.add(v + "\u4e14\u672a\u586b\u5199\u8d85\u9884\u7b97\u539f\u56e0");
|
|
|
1251
|
+ }
|
|
|
1252
|
+ } else if ("scenario17".equals(type)) {
|
|
|
1253
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1254
|
+ long days;
|
|
|
1255
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1256
|
+ if (!JdyRiskStatisticsService.flowStateMatches(s, row) || !JdyRiskStatisticsService.hasValue(row, s.getPlanField()) || !JdyRiskStatisticsService.hasValue(row, s.getActualField())) continue;
|
|
|
1257
|
+ ZonedDateTime plan = JdyRiskStatisticsService.parseTime(row.getString(s.getPlanField()));
|
|
|
1258
|
+ ZonedDateTime zonedDateTime = JdyRiskStatisticsService.parseTime(row.getString(s.getActualField()));
|
|
|
1259
|
+ if (plan == null || zonedDateTime == null || (days = ChronoUnit.DAYS.between(plan.toLocalDate(), zonedDateTime.toLocalDate())) <= (long)s.getOverdueDays()) continue;
|
|
|
1260
|
+ built.rows.add((Object)row);
|
|
|
1261
|
+ built.reasons.add("\u65bd\u5de5\u5b8c\u6210\u65e5\u671f\u8d85\u8fc7\u8ba1\u5212\u5b8c\u6210\u65f6\u95f4" + days + "\u5929");
|
|
|
1262
|
+ }
|
|
|
1263
|
+ } else if ("scenario18".equals(type)) {
|
|
|
1264
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1265
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1266
|
+ String v = row.getString(s.getFlagField());
|
|
|
1267
|
+ if (v == null || !s.getFlagValues().contains(v) || JdyRiskStatisticsService.hasValue(row, s.getReasonField())) continue;
|
|
|
1268
|
+ built.rows.add((Object)row);
|
|
|
1269
|
+ built.reasons.add("\u5f53\u6708\u65bd\u5de5\u5355\u4f4d\u672a\u63d0\u4ea4\u5ba1\u8ba1\u8d44\u6599\u4e14\u539f\u56e0\u8bf4\u660e\u4e3a\u7a7a");
|
|
|
1270
|
+ }
|
|
|
1271
|
+ } else if ("scenario19".equals(type)) {
|
|
|
1272
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1273
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1274
|
+ String v = row.getString(s.getFlagField());
|
|
|
1275
|
+ if (v == null || !s.getFlagValues().contains(v)) continue;
|
|
|
1276
|
+ built.rows.add((Object)row);
|
|
|
1277
|
+ built.reasons.add("\u4e09\u4e2a\u6708\u5185\u5df2\u63d0\u62a5\u76f8\u4f3c\u9879\u76ee");
|
|
|
1278
|
+ }
|
|
|
1279
|
+ } else if ("scenario20".equals(type)) {
|
|
|
1280
|
+ JSONArray flagged = JdyRiskStatisticsService.filterByFlag(scoped, s);
|
|
|
1281
|
+ ArrayList<JSONObject> ordered = new ArrayList<JSONObject>();
|
|
|
1282
|
+ for (int i = 0; i < flagged.size(); ++i) {
|
|
|
1283
|
+ ordered.add(flagged.getJSONObject(i));
|
|
|
1284
|
+ }
|
|
|
1285
|
+ JdyRiskStatisticsService.sortByDateDesc(ordered, s.getDateField());
|
|
|
1286
|
+ long hits = 0L;
|
|
|
1287
|
+ for (JSONObject current : ordered) {
|
|
|
1288
|
+ ZonedDateTime zonedDateTime = JdyRiskStatisticsService.parseTime(current.getString(s.getDateField()));
|
|
|
1289
|
+ JSONObject prev = this.findPreviousRefuel(all, s, current, zonedDateTime);
|
|
|
1290
|
+ double d = JdyRiskStatisticsService.num(current, s.getEndKmField());
|
|
|
1291
|
+ double d2 = prev != null ? JdyRiskStatisticsService.num(prev, s.getEndKmField()) : 0.0;
|
|
|
1292
|
+ double fuel = JdyRiskStatisticsService.num(current, s.getFuelAmountField());
|
|
|
1293
|
+ if (prev == null || d <= 0.0 || d2 <= 0.0 || fuel <= 0.0 || d <= d2) {
|
|
|
1294
|
+ log.warn("\u573a\u666f[{}] \u8df3\u8fc7\u4e00\u6761\uff1a\u4e0a\u6b21\u8bb0\u5f55\u7f3a\u5931\u6216\u7ed3\u675f\u516c\u91cc\u6570/\u91cc\u7a0b\u5dee\u65e0\u6548", (Object)s.getId());
|
|
|
1295
|
+ continue;
|
|
|
1296
|
+ }
|
|
|
1297
|
+ double cons = fuel / (d - d2) * 100.0;
|
|
|
1298
|
+ if (!(cons < s.getMinValue()) && !(cons > s.getMaxValue())) continue;
|
|
|
1299
|
+ built.rows.add((Object)current);
|
|
|
1300
|
+ built.reasons.add(String.format(Locale.ROOT, "\u767e\u516c\u91cc\u6cb9\u8017%.2fL\uff0c\u8d85\u51fa\u6b63\u5e38\u8303\u56f4[%.0f,%.0f]\uff08\u672c\u6b21\u7ec8%.0f/\u4e0a\u6b21\u7ec8%.0f\uff09", cons, s.getMinValue(), s.getMaxValue(), d, d2));
|
|
|
1301
|
+ if (s.isIncludePreviousRow()) {
|
|
|
1302
|
+ built.rows.add((Object)prev);
|
|
|
1303
|
+ built.reasons.add("\u4e0a\u6b21\u7528\u8f66\uff08\u5bf9\u6bd4\uff09");
|
|
|
1304
|
+ }
|
|
|
1305
|
+ ++hits;
|
|
|
1306
|
+ }
|
|
|
1307
|
+ explicitCount = hits;
|
|
|
1308
|
+ } else if ("scenario21".equals(type)) {
|
|
|
1309
|
+ JSONArray flagged = JdyRiskStatisticsService.filterByFlag(scoped, s);
|
|
|
1310
|
+ Map<String, Map<String, Double>> monthTotals = new LinkedHashMap<String, Map<String, Double>>();
|
|
|
1311
|
+ Map<String, JSONArray> monthRows = new LinkedHashMap<String, JSONArray>();
|
|
|
1312
|
+ int i0 = 0;
|
|
|
1313
|
+ while (i0 < flagged.size()) {
|
|
|
1314
|
+ JSONObject row = flagged.getJSONObject(i0);
|
|
|
1315
|
+ ZonedDateTime t = JdyRiskStatisticsService.parseTime(row.getString(s.getDateField()));
|
|
|
1316
|
+ if (t != null) {
|
|
|
1317
|
+ String string = t.format(MONTH_FMT);
|
|
|
1318
|
+ monthRows.computeIfAbsent(string, k -> new JSONArray()).add((Object)row);
|
|
|
1319
|
+ Map<String, Double> totals = monthTotals.computeIfAbsent(string, k -> new LinkedHashMap<String, Double>());
|
|
|
1320
|
+ for (String string3 : s.getCompanyFields()) {
|
|
|
1321
|
+ totals.merge(string3, JdyRiskStatisticsService.num(row, string3), Double::sum);
|
|
|
1322
|
+ }
|
|
|
1323
|
+ }
|
|
|
1324
|
+ ++i0;
|
|
|
1325
|
+ }
|
|
|
1326
|
+ if (monthTotals.size() >= 3) {
|
|
|
1327
|
+ List<String> months = new ArrayList<String>(monthTotals.keySet());
|
|
|
1328
|
+ months.sort(null);
|
|
|
1329
|
+ if (months.size() > 3) {
|
|
|
1330
|
+ months = months.subList(months.size() - 3, months.size());
|
|
|
1331
|
+ }
|
|
|
1332
|
+ Set<String> common = null;
|
|
|
1333
|
+ for (String string : months) {
|
|
|
1334
|
+ Set<String> bottom = JdyRiskStatisticsService.bottomCompanyFields(monthTotals.get(string), s.getBottomCount());
|
|
|
1335
|
+ if (common == null) {
|
|
|
1336
|
+ common = new LinkedHashSet<String>(bottom);
|
|
|
1337
|
+ continue;
|
|
|
1338
|
+ }
|
|
|
1339
|
+ common.retainAll(bottom);
|
|
|
1340
|
+ }
|
|
|
1341
|
+ if (common == null) {
|
|
|
1342
|
+ common = new LinkedHashSet<String>();
|
|
|
1343
|
+ }
|
|
|
1344
|
+ if (!common.isEmpty()) {
|
|
|
1345
|
+ Map<String, String> labels = this.widgetLabels(jdy, s);
|
|
|
1346
|
+ ArrayList<String> arrayList2 = new ArrayList<String>();
|
|
|
1347
|
+ for (String string : common) {
|
|
|
1348
|
+ arrayList2.add(labels.getOrDefault(string, string));
|
|
|
1349
|
+ }
|
|
|
1350
|
+ String reason = "\u8fde\u7eed" + months.size() + "\u4e2a\u6708\u6392\u540d\u5012\u6570\u524d" + s.getBottomCount() + "\uff1a" + String.join((CharSequence)"\u3001", arrayList2);
|
|
|
1351
|
+ ArrayList<JSONObject> arrayList3 = new ArrayList<JSONObject>();
|
|
|
1352
|
+ for (String string : months) {
|
|
|
1353
|
+ JSONArray arr = (JSONArray)monthRows.get(string);
|
|
|
1354
|
+ if (arr == null) continue;
|
|
|
1355
|
+ for (int i = 0; i < arr.size(); ++i) {
|
|
|
1356
|
+ arrayList3.add(arr.getJSONObject(i));
|
|
|
1357
|
+ }
|
|
|
1358
|
+ }
|
|
|
1359
|
+ JdyRiskStatisticsService.sortByDateDesc(arrayList3, s.getDateField());
|
|
|
1360
|
+ for (JSONObject jSONObject : arrayList3) {
|
|
|
1361
|
+ built.rows.add((Object)jSONObject);
|
|
|
1362
|
+ built.reasons.add(reason);
|
|
|
1363
|
+ }
|
|
|
1364
|
+ explicitCount = common.size();
|
|
|
1365
|
+ }
|
|
|
1366
|
+ } else {
|
|
|
1367
|
+ log.warn("\u573a\u666f[{}] \u8fd1\u4e09\u4e2a\u6708\u6570\u636e\u4e0d\u8db3\uff08{}\u4e2a\u6708\uff09\uff0c\u8df3\u8fc7", (Object)s.getId(), (Object)monthTotals.size());
|
|
|
1368
|
+ }
|
|
|
1369
|
+ } else if ("scenario23".equals(type)) {
|
|
|
1370
|
+ LinkedHashMap<String, double[]> agg = new LinkedHashMap<String, double[]>();
|
|
|
1371
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1372
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1373
|
+ String string = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
|
1374
|
+ double[] a = agg.computeIfAbsent(string, k -> new double[2]);
|
|
|
1375
|
+ a[0] = a[0] + JdyRiskStatisticsService.num(row, s.getScoreField());
|
|
|
1376
|
+ a[1] = a[1] + 1.0;
|
|
|
1377
|
+ }
|
|
|
1378
|
+ LinkedHashSet hit = new LinkedHashSet();
|
|
|
1379
|
+ for (Map.Entry entry : agg.entrySet()) {
|
|
|
1380
|
+ if (!(((double[])entry.getValue())[1] > 0.0) || !(((double[])entry.getValue())[0] / ((double[])entry.getValue())[1] < s.getAvgThreshold())) continue;
|
|
|
1381
|
+ hit.add(entry.getKey());
|
|
|
1382
|
+ }
|
|
|
1383
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1384
|
+ JSONObject jSONObject = scoped.getJSONObject(i);
|
|
|
1385
|
+ String g = JdyRiskStatisticsService.orEmpty(jSONObject.getString(s.getGroupField()));
|
|
|
1386
|
+ if (!hit.contains(g)) continue;
|
|
|
1387
|
+ double[] a = (double[])agg.get(g);
|
|
|
1388
|
+ built.rows.add((Object)jSONObject);
|
|
|
1389
|
+ built.reasons.add("\u4f9b\u5e94\u5546[" + g + "]\u5e73\u5747\u5206" + String.format(Locale.ROOT, "%.2f", a[0] / a[1]) + "<" + s.getAvgThreshold());
|
|
|
1390
|
+ }
|
|
|
1391
|
+ explicitCount = hit.size();
|
|
|
1392
|
+ } else if ("scenario24".equals(type)) {
|
|
|
1393
|
+ Map<String, List<JSONObject>> byMonth = new LinkedHashMap<String, List<JSONObject>>();
|
|
|
1394
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1395
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1396
|
+ ZonedDateTime zonedDateTime = JdyRiskStatisticsService.parseTime(row.getString(s.getDateField()));
|
|
|
1397
|
+ if (zonedDateTime == null) continue;
|
|
|
1398
|
+ byMonth.computeIfAbsent(zonedDateTime.format(MONTH_FMT), k -> new ArrayList<JSONObject>()).add(row);
|
|
|
1399
|
+ }
|
|
|
1400
|
+ List<String> months = new ArrayList<String>(byMonth.keySet());
|
|
|
1401
|
+ months.sort(null);
|
|
|
1402
|
+ long hitMonths = 0L;
|
|
|
1403
|
+ for (String m : months) {
|
|
|
1404
|
+ List<JSONObject> list = byMonth.get(m);
|
|
|
1405
|
+ int total = list.size();
|
|
|
1406
|
+ int n = 0;
|
|
|
1407
|
+ for (JSONObject jSONObject : list) {
|
|
|
1408
|
+ ZonedDateTime plan = JdyRiskStatisticsService.parseTime(jSONObject.getString(s.getPlanField()));
|
|
|
1409
|
+ ZonedDateTime act = JdyRiskStatisticsService.parseTime(jSONObject.getString(s.getActualField()));
|
|
|
1410
|
+ if (plan == null || act == null || ChronoUnit.DAYS.between(plan.toLocalDate(), act.toLocalDate()) <= (long)s.getLagDays()) continue;
|
|
|
1411
|
+ ++n;
|
|
|
1412
|
+ }
|
|
|
1413
|
+ if (total < s.getMinMonthCount() || total > s.getMaxMonthCount() || n < s.getMinLagCount()) continue;
|
|
|
1414
|
+ String string = m + " \u6708\u5ea6\u9879\u76ee\u6570" + total + "\uff08\u8303\u56f4" + s.getMinMonthCount() + "-" + s.getMaxMonthCount() + "\uff09\uff0c\u6ede\u540e\u9879\u76ee" + n + "\u4e2a\u2265" + s.getMinLagCount();
|
|
|
1415
|
+ for (JSONObject r : list) {
|
|
|
1416
|
+ built.rows.add((Object)r);
|
|
|
1417
|
+ built.reasons.add(string);
|
|
|
1418
|
+ }
|
|
|
1419
|
+ ++hitMonths;
|
|
|
1420
|
+ }
|
|
|
1421
|
+ explicitCount = hitMonths;
|
|
|
1422
|
+ } else if ("scenario25".equals(type)) {
|
|
|
1423
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1424
|
+ double price;
|
|
|
1425
|
+ double d;
|
|
|
1426
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1427
|
+ double budget = JdyRiskStatisticsService.num(row, s.getBudgetField());
|
|
|
1428
|
+ if (budget <= 0.0 || !JdyRiskStatisticsService.hasValue(row, s.getPriceField()) || !((d = (budget - (price = JdyRiskStatisticsService.num(row, s.getPriceField()))) / budget) >= s.getDeviationThreshold())) continue;
|
|
|
1429
|
+ built.rows.add((Object)row);
|
|
|
1430
|
+ built.reasons.add(String.format(Locale.ROOT, "\u504f\u79bb\u7387%.2f%%\u2265%.0f%%\uff08\u9884\u7b97%.2f/\u4e2d\u9009%.2f\uff09", d * 100.0, s.getDeviationThreshold() * 100.0, budget, price));
|
|
|
1431
|
+ }
|
|
|
1432
|
+ explicitCount = built.rows.size();
|
|
|
1433
|
+ } else if ("scenario26".equals(type)) {
|
|
|
1434
|
+ JSONArray flagged = JdyRiskStatisticsService.filterByFlag(scoped, s);
|
|
|
1435
|
+ int threshold = Math.max(1, s.getMinCount());
|
|
|
1436
|
+ if (flagged.size() >= threshold) {
|
|
|
1437
|
+ String reason = "\u672c\u5b63\u5ea6\u7d27\u6025\u91c7\u8d2d" + flagged.size() + "\u6b21\u2265" + threshold;
|
|
|
1438
|
+ int i0 = 0;
|
|
|
1439
|
+ while (i0 < flagged.size()) {
|
|
|
1440
|
+ built.rows.add((Object)flagged.getJSONObject(i0));
|
|
|
1441
|
+ built.reasons.add(reason);
|
|
|
1442
|
+ ++i0;
|
|
|
1443
|
+ }
|
|
|
1444
|
+ }
|
|
|
1445
|
+ explicitCount = flagged.size();
|
|
|
1446
|
+ } else if ("scenario27".equals(type)) {
|
|
|
1447
|
+ int[] a;
|
|
|
1448
|
+ LinkedHashMap<String, int[]> byDept = new LinkedHashMap<String, int[]>();
|
|
|
1449
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1450
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1451
|
+ String string = JdyRiskStatisticsService.toDisplayName(row.get((Object)s.getGroupField()));
|
|
|
1452
|
+ if (string == null || string.isEmpty()) {
|
|
|
1453
|
+ string = "(\u7a7a)";
|
|
|
1454
|
+ }
|
|
|
1455
|
+ a = byDept.computeIfAbsent(string, k -> new int[2]);
|
|
|
1456
|
+ a[0] = a[0] + 1;
|
|
|
1457
|
+ if (s.getFlagValues().isEmpty() || !s.getFlagValues().contains(row.getString(s.getFlagField()))) continue;
|
|
|
1458
|
+ a[1] = a[1] + 1;
|
|
|
1459
|
+ }
|
|
|
1460
|
+ LinkedHashSet hitDept = new LinkedHashSet();
|
|
|
1461
|
+ for (Map.Entry entry : byDept.entrySet()) {
|
|
|
1462
|
+ a = (int[])entry.getValue();
|
|
|
1463
|
+ if (a[0] <= 0 || !((double)a[1] / (double)a[0] >= s.getRatioThreshold())) continue;
|
|
|
1464
|
+ hitDept.add(entry.getKey());
|
|
|
1465
|
+ }
|
|
|
1466
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1467
|
+ JSONObject jSONObject = scoped.getJSONObject(i);
|
|
|
1468
|
+ String dept = JdyRiskStatisticsService.toDisplayName(jSONObject.get((Object)s.getGroupField()));
|
|
|
1469
|
+ if (dept == null || dept.isEmpty()) {
|
|
|
1470
|
+ dept = "(\u7a7a)";
|
|
|
1471
|
+ }
|
|
|
1472
|
+ if (!hitDept.contains(dept) || s.getFlagValues().isEmpty() || !s.getFlagValues().contains(jSONObject.getString(s.getFlagField()))) continue;
|
|
|
1473
|
+ int[] a2 = (int[])byDept.get(dept);
|
|
|
1474
|
+ built.rows.add((Object)jSONObject);
|
|
|
1475
|
+ built.reasons.add(String.format(Locale.ROOT, "\u90e8\u95e8[%s]\u5408\u540c\u5f02\u5e38\u53d8\u66f4\u7387=%.1f%%\u2265%.0f%%\uff08%d/%d\uff09", dept, (double)a2[1] / (double)a2[0] * 100.0, s.getRatioThreshold() * 100.0, a2[1], a2[0]));
|
|
|
1476
|
+ }
|
|
|
1477
|
+ explicitCount = hitDept.size();
|
|
|
1478
|
+ } else if ("scenario29".equals(type)) {
|
|
|
1479
|
+ for (int i = 0; i < scoped.size(); ++i) {
|
|
|
1480
|
+ long days;
|
|
|
1481
|
+ JSONObject row = scoped.getJSONObject(i);
|
|
|
1482
|
+ if (!JdyRiskStatisticsService.hasValue(row, s.getDateField()) || !JdyRiskStatisticsService.hasValue(row, s.getStartField())) continue;
|
|
|
1483
|
+ ZonedDateTime start = JdyRiskStatisticsService.parseTime(row.getString(s.getStartField()));
|
|
|
1484
|
+ ZonedDateTime zonedDateTime = JdyRiskStatisticsService.parseTime(row.getString(s.getDateField()));
|
|
|
1485
|
+ if (start == null || zonedDateTime == null || (days = ChronoUnit.DAYS.between(start.toLocalDate(), zonedDateTime.toLocalDate())) <= (long)s.getThresholdDays()) continue;
|
|
|
1486
|
+ built.rows.add((Object)row);
|
|
|
1487
|
+ built.reasons.add("\u6d41\u7a0b\u7ed3\u675f\u65f6\u95f4-\u6d41\u7a0b\u5f00\u59cb\u65f6\u95f4=" + days + "\u5929");
|
|
|
1488
|
+ }
|
|
|
1489
|
+ explicitCount = built.rows.size();
|
|
|
1490
|
+ }
|
|
|
1491
|
+ built.count = explicitCount >= 0L ? explicitCount : (long)built.rows.size();
|
|
|
1492
|
+ log.info("\u573a\u666f[{}] \u5468\u671f\u5185={}\u6761, \u547d\u4e2d={}\u6761", new Object[]{s.getId(), scoped.size(), built.count});
|
|
|
1493
|
+ return built;
|
|
|
1494
|
+ }
|
|
|
1495
|
+
|
|
|
1496
|
+ private static boolean isCustomSheetType(String type) {
|
|
|
1497
|
+ return "scenario22".equals(type) || "scenario28".equals(type) || "scenario30".equals(type) || "scenario31".equals(type) || "scenario32".equals(type);
|
|
|
1498
|
+ }
|
|
|
1499
|
+
|
|
|
1500
|
+ private MultiResult customSheets(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1501
|
+ String type;
|
|
|
1502
|
+ String string = type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
1503
|
+ if ("scenario22".equals(type)) {
|
|
|
1504
|
+ return this.buildS28(jdy, s);
|
|
|
1505
|
+ }
|
|
|
1506
|
+ if ("scenario28".equals(type)) {
|
|
|
1507
|
+ return this.buildS29(jdy, s);
|
|
|
1508
|
+ }
|
|
|
1509
|
+ if ("scenario30".equals(type)) {
|
|
|
1510
|
+ return this.buildTopSupplier(jdy, s, true);
|
|
|
1511
|
+ }
|
|
|
1512
|
+ if ("scenario31".equals(type)) {
|
|
|
1513
|
+ return this.buildTopSupplier(jdy, s, false);
|
|
|
1514
|
+ }
|
|
|
1515
|
+ if ("scenario32".equals(type)) {
|
|
|
1516
|
+ return this.buildS32(jdy, s);
|
|
|
1517
|
+ }
|
|
|
1518
|
+ throw new IllegalStateException("\u672a\u77e5\u591aSheet\u573a\u666f\u7c7b\u578b: " + type);
|
|
|
1519
|
+ }
|
|
|
1520
|
+
|
|
|
1521
|
+ private static JSONArray filterByMonth(JSONArray rows, String dateField, String month) {
|
|
|
1522
|
+ JSONArray out = new JSONArray();
|
|
|
1523
|
+ for (int i = 0; i < rows.size(); ++i) {
|
|
|
1524
|
+ JSONObject row = rows.getJSONObject(i);
|
|
|
1525
|
+ ZonedDateTime t = JdyRiskStatisticsService.parseTime(row.getString(dateField));
|
|
|
1526
|
+ if (t == null || !month.equals(t.format(MONTH_FMT))) continue;
|
|
|
1527
|
+ out.add((Object)row);
|
|
|
1528
|
+ }
|
|
|
1529
|
+ return out;
|
|
|
1530
|
+ }
|
|
|
1531
|
+
|
|
|
1532
|
+ private static double sumNum(JSONArray rows, String field) {
|
|
|
1533
|
+ double s = 0.0;
|
|
|
1534
|
+ for (int i = 0; i < rows.size(); ++i) {
|
|
|
1535
|
+ s += JdyRiskStatisticsService.num(rows.getJSONObject(i), field);
|
|
|
1536
|
+ }
|
|
|
1537
|
+ return s;
|
|
|
1538
|
+ }
|
|
|
1539
|
+
|
|
|
1540
|
+ private static List<String> repeat(String v, int n) {
|
|
|
1541
|
+ ArrayList<String> list = new ArrayList<String>();
|
|
|
1542
|
+ for (int i = 0; i < n; ++i) {
|
|
|
1543
|
+ list.add(v);
|
|
|
1544
|
+ }
|
|
|
1545
|
+ return list;
|
|
|
1546
|
+ }
|
|
|
1547
|
+
|
|
|
1548
|
+ private static String fmtNum(double v) {
|
|
|
1549
|
+ if (Math.abs(v - Math.rint(v)) < 1.0E-9) {
|
|
|
1550
|
+ return String.valueOf((long)Math.rint(v));
|
|
|
1551
|
+ }
|
|
|
1552
|
+ return String.format(Locale.ROOT, "%.2f", v);
|
|
|
1553
|
+ }
|
|
|
1554
|
+
|
|
|
1555
|
+ private long[] queryMes(String startDate, String endDate) {
|
|
|
1556
|
+ long[] out = new long[2];
|
|
|
1557
|
+ JdyRiskProperties.Mes mes = this.props.getMes();
|
|
|
1558
|
+ if (mes == null || mes.getUrl() == null || mes.getUrl().isEmpty()) {
|
|
|
1559
|
+ log.warn("\u672a\u914d\u7f6e jdy-risk.mes.*\uff0cMES \u6570\u91cf\u6309 0 \u5904\u7406");
|
|
|
1560
|
+ return out;
|
|
|
1561
|
+ }
|
|
|
1562
|
+ String sql = "SELECT CASE NVL(c.SITES_CODE,'')||NVL(c.SITES_SUB_SEQ,'') WHEN 'HA1781' THEN 'YQ' WHEN 'HA2781' THEN 'EQ' END AS K, COUNT(DISTINCT c.VIN_CODE) AS VINCNT FROM MESHFMID.CAR_PRC_SEQ_V c WHERE c.SITES_DT >= ? AND c.SITES_DT < ? AND NVL(c.SITES_CODE,'')||NVL(c.SITES_SUB_SEQ,'') IN ('HA1781','HA2781') GROUP BY CASE NVL(c.SITES_CODE,'')||NVL(c.SITES_SUB_SEQ,'') WHEN 'HA1781' THEN 'YQ' WHEN 'HA2781' THEN 'EQ' END";
|
|
|
1563
|
+ try {
|
|
|
1564
|
+ Class.forName("oracle.jdbc.OracleDriver");
|
|
|
1565
|
+ try (Connection conn = DriverManager.getConnection(mes.getUrl(), mes.getUsername(), mes.getPassword());
|
|
|
1566
|
+ PreparedStatement ps = conn.prepareStatement(sql);){
|
|
|
1567
|
+ ps.setDate(1, Date.valueOf(startDate));
|
|
|
1568
|
+ ps.setDate(2, Date.valueOf(endDate));
|
|
|
1569
|
+ try (ResultSet rs = ps.executeQuery();){
|
|
|
1570
|
+ while (rs.next()) {
|
|
|
1571
|
+ String k = rs.getString(1);
|
|
|
1572
|
+ long v = rs.getLong(2);
|
|
|
1573
|
+ if ("YQ".equals(k)) {
|
|
|
1574
|
+ out[0] = v;
|
|
|
1575
|
+ continue;
|
|
|
1576
|
+ }
|
|
|
1577
|
+ if (!"EQ".equals(k)) continue;
|
|
|
1578
|
+ out[1] = v;
|
|
|
1579
|
+ }
|
|
|
1580
|
+ }
|
|
|
1581
|
+ }
|
|
|
1582
|
+ log.info("MES \u67e5\u8be2 {}~{} : \u4e00\u671f={} \u4e8c\u671f={}", new Object[]{startDate, endDate, out[0], out[1]});
|
|
|
1583
|
+ }
|
|
|
1584
|
+ catch (Exception e) {
|
|
|
1585
|
+ log.error("MES \u67e5\u8be2\u5931\u8d25: {}", (Object)e.getMessage(), (Object)e);
|
|
|
1586
|
+ }
|
|
|
1587
|
+ return out;
|
|
|
1588
|
+ }
|
|
|
1589
|
+
|
|
|
1590
|
+ private MultiResult buildS28(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1591
|
+ ZonedDateTime now = this.now();
|
|
|
1592
|
+ ZonedDateTime start = now.minusMonths(1L).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
|
1593
|
+ String month = start.format(MONTH_FMT);
|
|
|
1594
|
+ String startDate = start.toLocalDate().toString();
|
|
|
1595
|
+ String endDate = now.withDayOfMonth(1).toLocalDate().toString();
|
|
|
1596
|
+ JSONArray settleRows = JdyRiskStatisticsService.filterByMonth(this.listAllDataCached(jdy, s.getAppId(), s.getEntryId()), s.getDateField(), month);
|
|
|
1597
|
+ double settle = JdyRiskStatisticsService.sumNum(settleRows, s.getQtyField());
|
|
|
1598
|
+ JSONArray partsRows = JdyRiskStatisticsService.filterByMonth(this.listAllDataCached(jdy, s.getAppId(), s.getSecondEntryId()), s.getSecondDateField(), month);
|
|
|
1599
|
+ double parts = JdyRiskStatisticsService.sumNum(partsRows, s.getSecondQtyField());
|
|
|
1600
|
+ long[] mes = this.queryMes(startDate, endDate);
|
|
|
1601
|
+ long down = mes[0] + mes[1];
|
|
|
1602
|
+ double diff = settle - (double)down - parts;
|
|
|
1603
|
+ MultiResult r = new MultiResult();
|
|
|
1604
|
+ long l = r.count = Math.abs(diff) > 1.0E-6 ? 1L : 0L;
|
|
|
1605
|
+ if (r.count > 0L) {
|
|
|
1606
|
+ String reason = "\u6708\u5ea6\u7ed3\u7b97\u6570\u91cf" + JdyRiskStatisticsService.fmtNum(settle) + "-\u4e0b\u7ebf\u8f66\u8f86\u6570\u91cf" + down + "-\u6563\u4ef6\u6570\u91cf" + JdyRiskStatisticsService.fmtNum(parts) + "=" + JdyRiskStatisticsService.fmtNum(diff) + "\u22600";
|
|
|
1607
|
+ JdyExcelExportService.SheetSpec sh1 = new JdyExcelExportService.SheetSpec();
|
|
|
1608
|
+ sh1.sheetName = "\u6708\u5ea6\u7ed3\u7b97\u6570\u91cf";
|
|
|
1609
|
+ sh1.topText = "\u901a\u8fc7MES\u7cfb\u7edf\u67e5\u8be2\u5230\u7684\u4e00\u671f-\u603b\u88c5\u51fa\u53e3\u70b9\u6570\u91cf\uff1a" + mes[0] + "\u548c\u4e8c\u671f-\u603b\u88c5\u6700\u7ec8\u4e8c\u51fa\u53e3\u70b9\u6570\u91cf\uff1a" + mes[1];
|
|
|
1610
|
+ sh1.widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
|
1611
|
+ sh1.rows = settleRows;
|
|
|
1612
|
+ sh1.extraHeader = "\u539f\u56e0";
|
|
|
1613
|
+ sh1.extraValues = JdyRiskStatisticsService.repeat(reason, settleRows.size());
|
|
|
1614
|
+ JdyExcelExportService.SheetSpec sh2 = new JdyExcelExportService.SheetSpec();
|
|
|
1615
|
+ sh2.sheetName = "\u6708\u5ea6\u6563\u4ef6\u6570\u91cf";
|
|
|
1616
|
+ sh2.widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getSecondEntryId());
|
|
|
1617
|
+ sh2.rows = partsRows;
|
|
|
1618
|
+ sh2.extraHeader = "\u539f\u56e0";
|
|
|
1619
|
+ sh2.extraValues = JdyRiskStatisticsService.repeat("\u6563\u4ef6\u6570\u91cf\u5408\u8ba1" + JdyRiskStatisticsService.fmtNum(parts), partsRows.size());
|
|
|
1620
|
+ r.sheets.add(sh1);
|
|
|
1621
|
+ r.sheets.add(sh2);
|
|
|
1622
|
+ }
|
|
|
1623
|
+ log.info("\u573a\u666f28 \u6708\u4efd={} \u7ed3\u7b97={} \u4e0b\u7ebf(MES)={} \u6563\u4ef6={} \u5dee={}", new Object[]{month, JdyRiskStatisticsService.fmtNum(settle), down, JdyRiskStatisticsService.fmtNum(parts), JdyRiskStatisticsService.fmtNum(diff)});
|
|
|
1624
|
+ return r;
|
|
|
1625
|
+ }
|
|
|
1626
|
+
|
|
|
1627
|
+ private MultiResult buildS29(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1628
|
+ ZonedDateTime now = this.now();
|
|
|
1629
|
+ ZonedDateTime start = now.minusMonths(1L).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
|
1630
|
+ String month = start.format(MONTH_FMT);
|
|
|
1631
|
+ JSONArray secondAll = this.listAllDataCached(jdy, s.getAppId(), s.getSecondEntryId());
|
|
|
1632
|
+ JSONArray secondRows = JdyRiskStatisticsService.filterByMonth(secondAll, s.getSecondDateField(), month);
|
|
|
1633
|
+ double secondSum = JdyRiskStatisticsService.sumNum(secondRows, s.getSecondQtyField());
|
|
|
1634
|
+ ArrayList<long[]> ranges = new ArrayList<long[]>();
|
|
|
1635
|
+ for (int i = 0; i < secondRows.size(); ++i) {
|
|
|
1636
|
+ JSONObject row = secondRows.getJSONObject(i);
|
|
|
1637
|
+ ZonedDateTime ps = JdyRiskStatisticsService.parseTime(row.getString(s.getPeriodStartField()));
|
|
|
1638
|
+ ZonedDateTime pe = JdyRiskStatisticsService.parseTime(row.getString(s.getPeriodEndField()));
|
|
|
1639
|
+ if (ps == null || pe == null) continue;
|
|
|
1640
|
+ ranges.add(new long[]{ps.toInstant().toEpochMilli(), pe.toInstant().toEpochMilli()});
|
|
|
1641
|
+ }
|
|
|
1642
|
+ JSONArray mainAll = this.listAllDataCached(jdy, s.getAppId(), s.getEntryId());
|
|
|
1643
|
+ JSONArray mainRows = new JSONArray();
|
|
|
1644
|
+ if (!ranges.isEmpty()) {
|
|
|
1645
|
+ block1: for (int i = 0; i < mainAll.size(); ++i) {
|
|
|
1646
|
+ JSONObject row = mainAll.getJSONObject(i);
|
|
|
1647
|
+ ZonedDateTime t = JdyRiskStatisticsService.parseTime(row.getString(s.getDateField()));
|
|
|
1648
|
+ if (t == null) continue;
|
|
|
1649
|
+ long ms = t.toInstant().toEpochMilli();
|
|
|
1650
|
+ for (long[] rg : ranges) {
|
|
|
1651
|
+ if (ms < rg[0] || ms > rg[1]) continue;
|
|
|
1652
|
+ mainRows.add((Object)row);
|
|
|
1653
|
+ continue block1;
|
|
|
1654
|
+ }
|
|
|
1655
|
+ }
|
|
|
1656
|
+ } else {
|
|
|
1657
|
+ mainRows = JdyRiskStatisticsService.filterByMonth(mainAll, s.getDateField(), month);
|
|
|
1658
|
+ }
|
|
|
1659
|
+ double mainSum = JdyRiskStatisticsService.sumNum(mainRows, s.getQtyField());
|
|
|
1660
|
+ double diff = mainSum - secondSum;
|
|
|
1661
|
+ MultiResult r = new MultiResult();
|
|
|
1662
|
+ long l = r.count = Math.abs(diff) > 1.0E-6 ? 1L : 0L;
|
|
|
1663
|
+ if (r.count > 0L) {
|
|
|
1664
|
+ String reason = "\u5408\u80a5\u5e93\u5b9e\u6536\u6570\u91cf\u5408\u8ba1" + JdyRiskStatisticsService.fmtNum(mainSum) + "\u2260\u59d4\u5916\u7535\u6cf3\u7ed3\u7b97\u6570\u91cf\u5408\u8ba1" + JdyRiskStatisticsService.fmtNum(secondSum);
|
|
|
1665
|
+ JdyExcelExportService.SheetSpec sh1 = new JdyExcelExportService.SheetSpec();
|
|
|
1666
|
+ sh1.sheetName = "\u5408\u80a5\u5e93\u6bcf\u65e5\u6536\u8d27";
|
|
|
1667
|
+ sh1.widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
|
1668
|
+ sh1.rows = mainRows;
|
|
|
1669
|
+ sh1.extraHeader = "\u539f\u56e0";
|
|
|
1670
|
+ sh1.extraValues = JdyRiskStatisticsService.repeat(reason, mainRows.size());
|
|
|
1671
|
+ JdyExcelExportService.SheetSpec sh2 = new JdyExcelExportService.SheetSpec();
|
|
|
1672
|
+ sh2.sheetName = "\u59d4\u5916\u7535\u6cf3\u6708\u5ea6\u7ed3\u7b97";
|
|
|
1673
|
+ sh2.widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getSecondEntryId());
|
|
|
1674
|
+ sh2.rows = secondRows;
|
|
|
1675
|
+ sh2.extraHeader = "\u539f\u56e0";
|
|
|
1676
|
+ sh2.extraValues = JdyRiskStatisticsService.repeat("\u59d4\u5916\u7535\u6cf3\u7ed3\u7b97\u6570\u91cf\u5408\u8ba1" + JdyRiskStatisticsService.fmtNum(secondSum), secondRows.size());
|
|
|
1677
|
+ r.sheets.add(sh1);
|
|
|
1678
|
+ r.sheets.add(sh2);
|
|
|
1679
|
+ }
|
|
|
1680
|
+ log.info("\u573a\u666f29 \u6708\u4efd={} \u5b9e\u6536={} \u7535\u6cf3\u7ed3\u7b97={} \u5dee={}", new Object[]{month, JdyRiskStatisticsService.fmtNum(mainSum), JdyRiskStatisticsService.fmtNum(secondSum), JdyRiskStatisticsService.fmtNum(diff)});
|
|
|
1681
|
+ return r;
|
|
|
1682
|
+ }
|
|
|
1683
|
+
|
|
|
1684
|
+ private MultiResult buildTopSupplier(JiandaoYunApi jdy, JdyRiskProperties.Scenario s, boolean amountMode) {
|
|
|
1685
|
+ Map<String, Double> sumBySupplier;
|
|
|
1686
|
+ String month = this.prevMonth();
|
|
|
1687
|
+ Map<String, String> relMap = this.loadRelMap(jdy, s);
|
|
|
1688
|
+ Map<String, Double> qtyBySupplier = new LinkedHashMap<String, Double>();
|
|
|
1689
|
+ Map<String, Map<String, Double>> qtyBySupplierPart = new LinkedHashMap<String, Map<String, Double>>();
|
|
|
1690
|
+ int[] scanned = new int[]{0};
|
|
|
1691
|
+ int[] matched = new int[]{0};
|
|
|
1692
|
+ int[] unmatched = new int[]{0};
|
|
|
1693
|
+ this.forEachPageCached(jdy, s.getAppId(), s.getEntryId(), Collections.singletonList(s.getSubformField()), page -> {
|
|
|
1694
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
1695
|
+ JSONArray subs = page.getJSONObject(i).getJSONArray(s.getSubformField());
|
|
|
1696
|
+ if (subs == null || subs.isEmpty()) continue;
|
|
|
1697
|
+ for (int j = 0; j < subs.size(); ++j) {
|
|
|
1698
|
+ JSONObject sub = subs.getJSONObject(j);
|
|
|
1699
|
+ scanned[0] = scanned[0] + 1;
|
|
|
1700
|
+ ZonedDateTime d = JdyRiskStatisticsService.parseTime(sub.getString(s.getSubDateField()));
|
|
|
1701
|
+ if (d == null || !month.equals(d.format(MONTH_FMT))) continue;
|
|
|
1702
|
+ String part = JdyRiskStatisticsService.normalizePart(sub.getString(s.getSubPartField()));
|
|
|
1703
|
+ String supplier = (String)relMap.get(part);
|
|
|
1704
|
+ if (supplier == null || supplier.isEmpty()) {
|
|
|
1705
|
+ unmatched[0] = unmatched[0] + 1;
|
|
|
1706
|
+ continue;
|
|
|
1707
|
+ }
|
|
|
1708
|
+ matched[0] = matched[0] + 1;
|
|
|
1709
|
+ double qty = JdyRiskStatisticsService.num(sub, s.getSubQtyField());
|
|
|
1710
|
+ qtyBySupplier.merge(supplier, qty, Double::sum);
|
|
|
1711
|
+ if (!amountMode) continue;
|
|
|
1712
|
+ qtyBySupplierPart.computeIfAbsent(supplier, k -> new LinkedHashMap<String, Double>()).merge(part, qty, Double::sum);
|
|
|
1713
|
+ }
|
|
|
1714
|
+ }
|
|
|
1715
|
+ });
|
|
|
1716
|
+ if (amountMode) {
|
|
|
1717
|
+ sumBySupplier = new LinkedHashMap<String, Double>();
|
|
|
1718
|
+ if (!qtyBySupplierPart.isEmpty()) {
|
|
|
1719
|
+ Map<String, Double> costMap = this.loadCostMap(jdy, s);
|
|
|
1720
|
+ for (Map.Entry<String, Map<String, Double>> se : qtyBySupplierPart.entrySet()) {
|
|
|
1721
|
+ double amount = 0.0;
|
|
|
1722
|
+ for (Map.Entry<String, Double> pe : se.getValue().entrySet()) {
|
|
|
1723
|
+ Double cost = costMap.get(pe.getKey());
|
|
|
1724
|
+ amount += (Double)pe.getValue() * (cost == null ? 0.0 : cost);
|
|
|
1725
|
+ }
|
|
|
1726
|
+ sumBySupplier.put(se.getKey(), amount);
|
|
|
1727
|
+ }
|
|
|
1728
|
+ }
|
|
|
1729
|
+ } else {
|
|
|
1730
|
+ sumBySupplier = qtyBySupplier;
|
|
|
1731
|
+ }
|
|
|
1732
|
+ List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(sumBySupplier.entrySet());
|
|
|
1733
|
+ list.sort((a, b) -> Double.compare(b.getValue(), a.getValue()));
|
|
|
1734
|
+ int topN = Math.max(1, s.getTopCount());
|
|
|
1735
|
+ if (list.size() > topN) {
|
|
|
1736
|
+ list = new ArrayList<Map.Entry<String, Double>>(list.subList(0, topN));
|
|
|
1737
|
+ }
|
|
|
1738
|
+ MultiResult r = new MultiResult();
|
|
|
1739
|
+ r.count = list.size();
|
|
|
1740
|
+ if (!list.isEmpty()) {
|
|
|
1741
|
+ JSONArray rows = new JSONArray();
|
|
|
1742
|
+ ArrayList<String> reasons = new ArrayList<String>();
|
|
|
1743
|
+ for (Map.Entry<String, Double> e : list) {
|
|
|
1744
|
+ String reason;
|
|
|
1745
|
+ JSONObject row = new JSONObject();
|
|
|
1746
|
+ row.put("supplier", e.getKey());
|
|
|
1747
|
+ if (amountMode) {
|
|
|
1748
|
+ double amt = (Double)e.getValue();
|
|
|
1749
|
+ row.put("amount", (Object)JdyRiskStatisticsService.fmtAmount(amt));
|
|
|
1750
|
+ reason = "\u603b\u91d1\u989d" + JdyRiskStatisticsService.fmtAmount(amt) + "\u5143";
|
|
|
1751
|
+ } else {
|
|
|
1752
|
+ double qty = (Double)e.getValue();
|
|
|
1753
|
+ row.put("qty", (Object)JdyRiskStatisticsService.fmtNum(qty));
|
|
|
1754
|
+ reason = "\u9000\u8d27\u603b\u6570\u91cf" + JdyRiskStatisticsService.fmtNum(qty);
|
|
|
1755
|
+ }
|
|
|
1756
|
+ rows.add((Object)row);
|
|
|
1757
|
+ reasons.add(reason);
|
|
|
1758
|
+ }
|
|
|
1759
|
+ JdyExcelExportService.SheetSpec sh = new JdyExcelExportService.SheetSpec();
|
|
|
1760
|
+ Biz biz = JdyRiskStatisticsService.bizOf(s);
|
|
|
1761
|
+ sh.sheetName = biz != null ? biz.sceneTitle : s.getName();
|
|
|
1762
|
+ sh.widgets = new JSONArray();
|
|
|
1763
|
+ sh.widgets.add((Object)JdyRiskStatisticsService.syntheticWidget("supplier", "\u4f9b\u5e94\u5546\u540d\u79f0"));
|
|
|
1764
|
+ if (amountMode) {
|
|
|
1765
|
+ sh.widgets.add((Object)JdyRiskStatisticsService.syntheticWidget("amount", "\u9000\u8d27\u603b\u91d1\u989d(\u5143)"));
|
|
|
1766
|
+ } else {
|
|
|
1767
|
+ sh.widgets.add((Object)JdyRiskStatisticsService.syntheticWidget("qty", "\u9000\u8d27\u603b\u6570\u91cf"));
|
|
|
1768
|
+ }
|
|
|
1769
|
+ sh.rows = rows;
|
|
|
1770
|
+ sh.extraHeader = "\u539f\u56e0";
|
|
|
1771
|
+ sh.extraValues = reasons;
|
|
|
1772
|
+ r.sheets.add(sh);
|
|
|
1773
|
+ }
|
|
|
1774
|
+ log.info("\u573a\u666f[{}] \u6708\u4efd={} \u9000\u8d27\u660e\u7ec6\u884c={} \u5df2\u5339\u914d\u4f9b\u5e94\u5546={} \u672a\u5339\u914d={} TOP{}=>{}", new Object[]{s.getId(), month, scanned[0], matched[0], unmatched[0], topN, r.count});
|
|
|
1775
|
+ return r;
|
|
|
1776
|
+ }
|
|
|
1777
|
+
|
|
|
1778
|
+ private MultiResult buildS32(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1779
|
+ String month = this.prevMonth();
|
|
|
1780
|
+ JSONArray indicatorWidgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
|
1781
|
+ JSONArray indicatorRows = this.cachedRows(jdy, s.getAppId(), s.getEntryId(), JdyRiskStatisticsService.widgetFieldNames(indicatorWidgets));
|
|
|
1782
|
+ JSONObject indicator = null;
|
|
|
1783
|
+ String wantCode = JdyRiskStatisticsService.normalizeCode(s.getWarehouseCode());
|
|
|
1784
|
+ for (int i = 0; i < indicatorRows.size(); ++i) {
|
|
|
1785
|
+ JSONObject row = indicatorRows.getJSONObject(i);
|
|
|
1786
|
+ if (!wantCode.equals(JdyRiskStatisticsService.normalizeCode(row.get((Object)s.getIndicatorCodeField())))) continue;
|
|
|
1787
|
+ if (indicator == null) {
|
|
|
1788
|
+ indicator = row;
|
|
|
1789
|
+ continue;
|
|
|
1790
|
+ }
|
|
|
1791
|
+ log.warn("\u573a\u666f[{}] \u5e93\u623f\u7f16\u7801={} \u5728\u5e93\u5b58\u6307\u6807\u5212\u5206\u4e2d\u5b58\u5728\u591a\u6761\uff0c\u4f7f\u7528\u7b2c\u4e00\u6761", (Object)s.getId(), (Object)wantCode);
|
|
|
1792
|
+ }
|
|
|
1793
|
+ MultiResult r = new MultiResult();
|
|
|
1794
|
+ if (indicator == null) {
|
|
|
1795
|
+ log.warn("\u573a\u666f[{}] \u5e93\u5b58\u6307\u6807\u5212\u5206\u672a\u627e\u5230\u5e93\u623f\u7f16\u7801={}", (Object)s.getId(), (Object)wantCode);
|
|
|
1796
|
+ return r;
|
|
|
1797
|
+ }
|
|
|
1798
|
+ double target = JdyRiskStatisticsService.num(indicator, s.getIndicatorTargetField());
|
|
|
1799
|
+ Set<String> aixin = this.loadAixinSet(jdy, s);
|
|
|
1800
|
+ Map<String, Double> costMap = this.loadCostMap(jdy, s);
|
|
|
1801
|
+ JSONArray stockWidgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getStockEntryId());
|
|
|
1802
|
+ JSONArray stocks = this.loadStockByWarehouse(jdy, s).get(wantCode);
|
|
|
1803
|
+ if (stocks == null) {
|
|
|
1804
|
+ stocks = new JSONArray();
|
|
|
1805
|
+ }
|
|
|
1806
|
+ JSONArray sheetRows = new JSONArray();
|
|
|
1807
|
+ double total = 0.0;
|
|
|
1808
|
+ int matchedRows = 0;
|
|
|
1809
|
+ int excludedAixin = 0;
|
|
|
1810
|
+ int missingCost = 0;
|
|
|
1811
|
+ for (int i = 0; i < stocks.size(); ++i) {
|
|
|
1812
|
+ JSONObject row = stocks.getJSONObject(i);
|
|
|
1813
|
+ ZonedDateTime m = JdyRiskStatisticsService.parseTime(row.getString(s.getStockMonthField()));
|
|
|
1814
|
+ if (m == null || !month.equals(m.format(MONTH_FMT)) || !wantCode.equals(JdyRiskStatisticsService.normalizeCode(row.get((Object)s.getStockWarehouseField())))) continue;
|
|
|
1815
|
+ String part = JdyRiskStatisticsService.normalizePart(row.getString(s.getStockPartField()));
|
|
|
1816
|
+ if (!aixin.isEmpty() && aixin.contains(part)) {
|
|
|
1817
|
+ ++excludedAixin;
|
|
|
1818
|
+ continue;
|
|
|
1819
|
+ }
|
|
|
1820
|
+ double qty = JdyRiskStatisticsService.num(row, s.getStockQtyField());
|
|
|
1821
|
+ Double cost = costMap.get(part);
|
|
|
1822
|
+ if (cost == null) {
|
|
|
1823
|
+ ++missingCost;
|
|
|
1824
|
+ cost = 0.0;
|
|
|
1825
|
+ }
|
|
|
1826
|
+ total += qty * cost;
|
|
|
1827
|
+ ++matchedRows;
|
|
|
1828
|
+ JSONObject copy = new JSONObject();
|
|
|
1829
|
+ copy.putAll((Map)row);
|
|
|
1830
|
+ copy.put("__cost", costMap.containsKey(part) ? cost : "");
|
|
|
1831
|
+ sheetRows.add((Object)copy);
|
|
|
1832
|
+ }
|
|
|
1833
|
+ double totalWan = total / 10000.0;
|
|
|
1834
|
+ boolean abnormal = totalWan > target;
|
|
|
1835
|
+ r.count = abnormal ? 1L : 0L;
|
|
|
1836
|
+ log.info("\u573a\u666f[{}] \u6708\u4efd={} \u5e93\u623f={} \u5e93\u5b58\u884c={} \u6392\u9664\u7231\u4fe1={} \u7f3a\u6210\u672c={} \u5408\u8ba1={}\u4e07\u5143 \u6307\u6807={}\u4e07\u5143 \u5f02\u5e38={}", new Object[]{s.getId(), month, wantCode, matchedRows, excludedAixin, missingCost, JdyRiskStatisticsService.fmtAmount(totalWan), JdyRiskStatisticsService.fmtNum(target), abnormal});
|
|
|
1837
|
+ if (abnormal) {
|
|
|
1838
|
+ String reason = "\u5e93\u5b58\u73b0\u6709\u91cf\u8ba1\u7b97\u603b\u91d1\u989d" + JdyRiskStatisticsService.fmtAmount(totalWan) + "\u4e07\u5143>\u5185\u63a7\u6307\u6807" + JdyRiskStatisticsService.fmtNum(target) + "\u4e07\u5143";
|
|
|
1839
|
+ JdyExcelExportService.SheetSpec sh1 = new JdyExcelExportService.SheetSpec();
|
|
|
1840
|
+ sh1.sheetName = "\u5e93\u5b58\u73b0\u6709\u91cf";
|
|
|
1841
|
+ sh1.widgets = JdyRiskStatisticsService.insertCostWidget(stockWidgets, s.getStockQtyField());
|
|
|
1842
|
+ sh1.rows = sheetRows;
|
|
|
1843
|
+ sh1.extraHeader = "\u539f\u56e0";
|
|
|
1844
|
+ sh1.extraValues = JdyRiskStatisticsService.repeat(reason, sheetRows.size());
|
|
|
1845
|
+ JdyExcelExportService.SheetSpec sh2 = new JdyExcelExportService.SheetSpec();
|
|
|
1846
|
+ sh2.sheetName = "\u5e93\u5b58\u6307\u6807\u5212\u5206";
|
|
|
1847
|
+ sh2.widgets = indicatorWidgets;
|
|
|
1848
|
+ JSONArray indRows = new JSONArray();
|
|
|
1849
|
+ indRows.add((Object)indicator);
|
|
|
1850
|
+ sh2.rows = indRows;
|
|
|
1851
|
+ sh2.extraHeader = "\u539f\u56e0";
|
|
|
1852
|
+ sh2.extraValues = JdyRiskStatisticsService.repeat(reason, 1);
|
|
|
1853
|
+ r.sheets.add(sh1);
|
|
|
1854
|
+ r.sheets.add(sh2);
|
|
|
1855
|
+ }
|
|
|
1856
|
+ return r;
|
|
|
1857
|
+ }
|
|
|
1858
|
+
|
|
|
1859
|
+ private JSONArray cachedRows(JiandaoYunApi jdy, String appId, String entryId, List<String> fields) {
|
|
|
1860
|
+ String key = "rows|" + entryId + "|" + (fields == null ? "*" : String.join((CharSequence)",", fields));
|
|
|
1861
|
+ return this.cached(key, () -> {
|
|
|
1862
|
+ JSONArray arr = new JSONArray();
|
|
|
1863
|
+ jdy.forEachPage(this.props.getApiKey(), appId, entryId, fields, arg_0 -> ((JSONArray)arr).addAll(arg_0));
|
|
|
1864
|
+ log.info("\u52a0\u8f7d\u7b80\u9053\u4e91\u8868 {} \u5171 {} \u6761\uff08\u7f13\u5b58{}\u5c0f\u65f6\uff09", new Object[]{entryId, arr.size(), 6L});
|
|
|
1865
|
+ return arr;
|
|
|
1866
|
+ });
|
|
|
1867
|
+ }
|
|
|
1868
|
+
|
|
|
1869
|
+ private Map<String, JSONArray> loadStockByWarehouse(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1870
|
+ String month = this.prevMonth();
|
|
|
1871
|
+ LinkedHashSet<String> codes = new LinkedHashSet<String>();
|
|
|
1872
|
+ for (JdyRiskProperties.Scenario x : this.props.getScenarios()) {
|
|
|
1873
|
+ String type = x.getType() == null ? "" : x.getType().toLowerCase();
|
|
|
1874
|
+ if (!"scenario32".equals(type) || !JdyRiskStatisticsService.hasText(x.getWarehouseCode())) continue;
|
|
|
1875
|
+ codes.add(JdyRiskStatisticsService.normalizeCode(x.getWarehouseCode()));
|
|
|
1876
|
+ }
|
|
|
1877
|
+ String key = "stock|" + s.getAppId() + "|" + s.getStockEntryId() + "|" + month + "|" + String.join((CharSequence)",", codes);
|
|
|
1878
|
+ return this.cached(key, () -> {
|
|
|
1879
|
+ JSONArray widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getStockEntryId());
|
|
|
1880
|
+ List<String> fields = JdyRiskStatisticsService.widgetFieldNames(widgets);
|
|
|
1881
|
+ Map<String, JSONArray> map = new HashMap<String, JSONArray>();
|
|
|
1882
|
+ int[] scanned = new int[]{0};
|
|
|
1883
|
+ jdy.forEachPage(this.props.getApiKey(), s.getAppId(), s.getStockEntryId(), fields, page -> {
|
|
|
1884
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
1885
|
+ String wh;
|
|
|
1886
|
+ scanned[0] = scanned[0] + 1;
|
|
|
1887
|
+ JSONObject row = page.getJSONObject(i);
|
|
|
1888
|
+ ZonedDateTime t = JdyRiskStatisticsService.parseTime(row.getString(s.getStockMonthField()));
|
|
|
1889
|
+ if (t == null || !month.equals(t.format(MONTH_FMT)) || !codes.contains(wh = JdyRiskStatisticsService.normalizeCode(row.get((Object)s.getStockWarehouseField())))) continue;
|
|
|
1890
|
+ map.computeIfAbsent(wh, k -> new JSONArray()).add((Object)row);
|
|
|
1891
|
+ }
|
|
|
1892
|
+ });
|
|
|
1893
|
+ int kept = 0;
|
|
|
1894
|
+ for (JSONArray arr : map.values()) {
|
|
|
1895
|
+ kept += arr.size();
|
|
|
1896
|
+ }
|
|
|
1897
|
+ log.info("\u52a0\u8f7d\u5e93\u5b58\u73b0\u6709\u91cf\u8868 \u626b\u63cf={} \u6761\uff0c\u4fdd\u7559\u4e0a\u6708({})\u76ee\u6807\u5e93\u623f={} \u6761\uff08\u7f13\u5b58{}\u5c0f\u65f6\uff09", new Object[]{scanned[0], month, kept, 6L});
|
|
|
1898
|
+ JdyRiskStatisticsService.logHeap("\u5e93\u5b58\u8868\u73b0\u6709\u91cf\u52a0\u8f7d\u540e");
|
|
|
1899
|
+ return map;
|
|
|
1900
|
+ });
|
|
|
1901
|
+ }
|
|
|
1902
|
+
|
|
|
1903
|
+ private Map<String, Double> loadCostMap(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1904
|
+ if (!(JdyRiskStatisticsService.hasText(s.getCostEntryId()) && JdyRiskStatisticsService.hasText(s.getCostCodeField()) && JdyRiskStatisticsService.hasText(s.getCostValueField()))) {
|
|
|
1905
|
+ return Collections.emptyMap();
|
|
|
1906
|
+ }
|
|
|
1907
|
+ String key = "cost|" + s.getCostEntryId() + "|" + s.getCostCodeField() + "|" + s.getCostValueField();
|
|
|
1908
|
+ return this.cached(key, () -> {
|
|
|
1909
|
+ HashMap map = new HashMap();
|
|
|
1910
|
+ List<String> fields = Arrays.asList(s.getCostCodeField(), s.getCostValueField());
|
|
|
1911
|
+ jdy.forEachPage(this.props.getApiKey(), s.getAppId(), s.getCostEntryId(), fields, page -> {
|
|
|
1912
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
1913
|
+ JSONObject row = page.getJSONObject(i);
|
|
|
1914
|
+ String code = JdyRiskStatisticsService.normalizePart(row.getString(s.getCostCodeField()));
|
|
|
1915
|
+ Object raw = row.get((Object)s.getCostValueField());
|
|
|
1916
|
+ if (code.isEmpty() || raw == null) continue;
|
|
|
1917
|
+ double v = JdyRiskStatisticsService.toDouble(raw);
|
|
|
1918
|
+ Double old = (Double)map.get(code);
|
|
|
1919
|
+ if (old != null && !(v > 0.0) && !(old <= 0.0)) continue;
|
|
|
1920
|
+ map.put(code, v);
|
|
|
1921
|
+ }
|
|
|
1922
|
+ });
|
|
|
1923
|
+ log.info("\u52a0\u8f7d\u5df2\u51bb\u7ed3\u6807\u51c6\u6210\u672c {} \u6761\uff08\u7f13\u5b58{}\u5c0f\u65f6\uff09", (Object)map.size(), (Object)6L);
|
|
|
1924
|
+ JdyRiskStatisticsService.logHeap("\u6210\u672c\u8868\u52a0\u8f7d\u540e");
|
|
|
1925
|
+ return map;
|
|
|
1926
|
+ });
|
|
|
1927
|
+ }
|
|
|
1928
|
+
|
|
|
1929
|
+ private Map<String, String> loadRelMap(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1930
|
+ if (!JdyRiskStatisticsService.hasText(s.getRelEntryId()) || !JdyRiskStatisticsService.hasText(s.getRelPartField())) {
|
|
|
1931
|
+ return Collections.emptyMap();
|
|
|
1932
|
+ }
|
|
|
1933
|
+ String key = "rel|" + s.getRelEntryId() + "|" + s.getRelPartField() + "|" + s.getRelSupplierField();
|
|
|
1934
|
+ return this.cached(key, () -> {
|
|
|
1935
|
+ Map<String, Rel> tmp = new HashMap<String, Rel>();
|
|
|
1936
|
+ ArrayList<String> fields = new ArrayList<String>();
|
|
|
1937
|
+ fields.add(s.getRelPartField());
|
|
|
1938
|
+ if (JdyRiskStatisticsService.hasText(s.getRelSupplierField())) {
|
|
|
1939
|
+ fields.add(s.getRelSupplierField());
|
|
|
1940
|
+ }
|
|
|
1941
|
+ if (JdyRiskStatisticsService.hasText(s.getRelEnableField())) {
|
|
|
1942
|
+ fields.add(s.getRelEnableField());
|
|
|
1943
|
+ }
|
|
|
1944
|
+ if (JdyRiskStatisticsService.hasText(s.getRelTimeField())) {
|
|
|
1945
|
+ fields.add(s.getRelTimeField());
|
|
|
1946
|
+ }
|
|
|
1947
|
+ jdy.forEachPage(this.props.getApiKey(), s.getAppId(), s.getRelEntryId(), fields, page -> {
|
|
|
1948
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
1949
|
+ Rel cur;
|
|
|
1950
|
+ ZonedDateTime t;
|
|
|
1951
|
+ JSONObject row = page.getJSONObject(i);
|
|
|
1952
|
+ String part = JdyRiskStatisticsService.normalizePart(row.getString(s.getRelPartField()));
|
|
|
1953
|
+ String supplier = row.getString(s.getRelSupplierField());
|
|
|
1954
|
+ if (part.isEmpty() || supplier == null || supplier.trim().isEmpty()) continue;
|
|
|
1955
|
+ boolean enabled = !JdyRiskStatisticsService.hasText(s.getRelEnableField()) || JdyRiskStatisticsService.isEnabledValue(row.get((Object)s.getRelEnableField()));
|
|
|
1956
|
+ long time = 0L;
|
|
|
1957
|
+ if (JdyRiskStatisticsService.hasText(s.getRelTimeField()) && (t = JdyRiskStatisticsService.parseTime(row.getString(s.getRelTimeField()))) != null) {
|
|
|
1958
|
+ time = t.toInstant().toEpochMilli();
|
|
|
1959
|
+ }
|
|
|
1960
|
+ if ((cur = (Rel)tmp.get(part)) == null) {
|
|
|
1961
|
+ tmp.put(part, new Rel(supplier, enabled, time));
|
|
|
1962
|
+ continue;
|
|
|
1963
|
+ }
|
|
|
1964
|
+ if (enabled && !cur.enabled) {
|
|
|
1965
|
+ tmp.put(part, new Rel(supplier, enabled, time));
|
|
|
1966
|
+ continue;
|
|
|
1967
|
+ }
|
|
|
1968
|
+ if (enabled != cur.enabled || time <= cur.time) continue;
|
|
|
1969
|
+ tmp.put(part, new Rel(supplier, enabled, time));
|
|
|
1970
|
+ }
|
|
|
1971
|
+ });
|
|
|
1972
|
+ HashMap map = new HashMap();
|
|
|
1973
|
+ for (Map.Entry<String, Rel> e : tmp.entrySet()) {
|
|
|
1974
|
+ if (!e.getValue().enabled) continue;
|
|
|
1975
|
+ map.put(e.getKey(), e.getValue().supplier);
|
|
|
1976
|
+ }
|
|
|
1977
|
+ log.info("\u52a0\u8f7d\u96f6\u4ef6\u4f9b\u5e94\u5546\u5173\u7cfb {} \u6761\u542f\u7528\u8bb0\u5f55\uff08\u7f13\u5b58{}\u5c0f\u65f6\uff09", (Object)map.size(), (Object)6L);
|
|
|
1978
|
+ return map;
|
|
|
1979
|
+ });
|
|
|
1980
|
+ }
|
|
|
1981
|
+
|
|
|
1982
|
+ private Set<String> loadAixinSet(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
1983
|
+ if (!JdyRiskStatisticsService.hasText(s.getAixinEntryId()) || !JdyRiskStatisticsService.hasText(s.getAixinPartField())) {
|
|
|
1984
|
+ return Collections.emptySet();
|
|
|
1985
|
+ }
|
|
|
1986
|
+ String key = "aixin|" + s.getAixinEntryId() + "|" + s.getAixinPartField();
|
|
|
1987
|
+ return this.cached(key, () -> {
|
|
|
1988
|
+ HashSet set = new HashSet();
|
|
|
1989
|
+ jdy.forEachPage(this.props.getApiKey(), s.getAppId(), s.getAixinEntryId(), Collections.singletonList(s.getAixinPartField()), page -> {
|
|
|
1990
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
1991
|
+ String part = JdyRiskStatisticsService.normalizePart(page.getJSONObject(i).getString(s.getAixinPartField()));
|
|
|
1992
|
+ if (part.isEmpty()) continue;
|
|
|
1993
|
+ set.add(part);
|
|
|
1994
|
+ }
|
|
|
1995
|
+ });
|
|
|
1996
|
+ log.info("\u52a0\u8f7d\u6307\u6807\u5916\u7231\u4fe1\u5e93\u5b58 {} \u6761\uff08\u7f13\u5b58{}\u5c0f\u65f6\uff09", (Object)set.size(), (Object)6L);
|
|
|
1997
|
+ return set;
|
|
|
1998
|
+ });
|
|
|
1999
|
+ }
|
|
|
2000
|
+
|
|
|
2001
|
+ private static List<String> widgetFieldNames(JSONArray widgets) {
|
|
|
2002
|
+ ArrayList<String> fields = new ArrayList<String>();
|
|
|
2003
|
+ for (int i = 0; i < widgets.size(); ++i) {
|
|
|
2004
|
+ String name = widgets.getJSONObject(i).getString("name");
|
|
|
2005
|
+ if (name == null || name.isEmpty()) continue;
|
|
|
2006
|
+ fields.add(name);
|
|
|
2007
|
+ }
|
|
|
2008
|
+ return fields;
|
|
|
2009
|
+ }
|
|
|
2010
|
+
|
|
|
2011
|
+ private static JSONArray insertCostWidget(JSONArray widgets, String afterField) {
|
|
|
2012
|
+ JSONArray out = new JSONArray();
|
|
|
2013
|
+ boolean inserted = false;
|
|
|
2014
|
+ for (int i = 0; i < widgets.size(); ++i) {
|
|
|
2015
|
+ JSONObject w = widgets.getJSONObject(i);
|
|
|
2016
|
+ out.add((Object)w);
|
|
|
2017
|
+ if (afterField == null || !afterField.equals(w.getString("name"))) continue;
|
|
|
2018
|
+ out.add((Object)JdyRiskStatisticsService.syntheticWidget("__cost", "\u6210\u672c"));
|
|
|
2019
|
+ inserted = true;
|
|
|
2020
|
+ }
|
|
|
2021
|
+ if (!inserted) {
|
|
|
2022
|
+ out.add((Object)JdyRiskStatisticsService.syntheticWidget("__cost", "\u6210\u672c"));
|
|
|
2023
|
+ }
|
|
|
2024
|
+ return out;
|
|
|
2025
|
+ }
|
|
|
2026
|
+
|
|
|
2027
|
+ private static boolean hasText(String s) {
|
|
|
2028
|
+ return s != null && !s.trim().isEmpty();
|
|
|
2029
|
+ }
|
|
|
2030
|
+
|
|
|
2031
|
+ private String prevMonth() {
|
|
|
2032
|
+ return this.now().minusMonths(1L).format(MONTH_FMT);
|
|
|
2033
|
+ }
|
|
|
2034
|
+
|
|
|
2035
|
+ private static String normalizePart(String v) {
|
|
|
2036
|
+ return v == null ? "" : v.trim().toUpperCase(Locale.ROOT);
|
|
|
2037
|
+ }
|
|
|
2038
|
+
|
|
|
2039
|
+ private static String normalizeCode(Object v) {
|
|
|
2040
|
+ double d;
|
|
|
2041
|
+ if (v == null) {
|
|
|
2042
|
+ return "";
|
|
|
2043
|
+ }
|
|
|
2044
|
+ if (v instanceof Number && (d = ((Number)v).doubleValue()) == Math.rint(d)) {
|
|
|
2045
|
+ return String.valueOf((long)d);
|
|
|
2046
|
+ }
|
|
|
2047
|
+ String s = String.valueOf(v).trim();
|
|
|
2048
|
+ if (s.endsWith(".0")) {
|
|
|
2049
|
+ s = s.substring(0, s.length() - 2);
|
|
|
2050
|
+ }
|
|
|
2051
|
+ return s;
|
|
|
2052
|
+ }
|
|
|
2053
|
+
|
|
|
2054
|
+ private static boolean isEnabledValue(Object v) {
|
|
|
2055
|
+ if (v == null) {
|
|
|
2056
|
+ return false;
|
|
|
2057
|
+ }
|
|
|
2058
|
+ String s = String.valueOf(v).trim();
|
|
|
2059
|
+ return "Y".equalsIgnoreCase(s) || "\u662f".equals(s) || "YES".equalsIgnoreCase(s) || "TRUE".equalsIgnoreCase(s) || "1".equals(s) || "\u542f\u7528".equals(s);
|
|
|
2060
|
+ }
|
|
|
2061
|
+
|
|
|
2062
|
+ private static double toDouble(Object v) {
|
|
|
2063
|
+ if (v == null) {
|
|
|
2064
|
+ return 0.0;
|
|
|
2065
|
+ }
|
|
|
2066
|
+ if (v instanceof Number) {
|
|
|
2067
|
+ return ((Number)v).doubleValue();
|
|
|
2068
|
+ }
|
|
|
2069
|
+ try {
|
|
|
2070
|
+ return Double.parseDouble(String.valueOf(v));
|
|
|
2071
|
+ }
|
|
|
2072
|
+ catch (NumberFormatException e) {
|
|
|
2073
|
+ return 0.0;
|
|
|
2074
|
+ }
|
|
|
2075
|
+ }
|
|
|
2076
|
+
|
|
|
2077
|
+ private static String fmtAmount(double v) {
|
|
|
2078
|
+ return String.format(Locale.ROOT, "%.2f", v);
|
|
|
2079
|
+ }
|
|
|
2080
|
+
|
|
|
2081
|
+ private static void logHeap(String tag) {
|
|
|
2082
|
+ Runtime r = Runtime.getRuntime();
|
|
|
2083
|
+ long used = (r.totalMemory() - r.freeMemory()) / 1024L / 1024L;
|
|
|
2084
|
+ long max = r.maxMemory() / 1024L / 1024L;
|
|
|
2085
|
+ log.info("{} \u5806\u5185\u5b58 used={}MB / max={}MB", new Object[]{tag, used, max});
|
|
|
2086
|
+ }
|
|
|
2087
|
+
|
|
|
2088
|
+ private static boolean flowStateMatches(JdyRiskProperties.Scenario s, JSONObject row) {
|
|
|
2089
|
+ Integer want = s.getFlowStateValue();
|
|
|
2090
|
+ if (want == null) {
|
|
|
2091
|
+ return true;
|
|
|
2092
|
+ }
|
|
|
2093
|
+ Integer f = row.getInteger("flowState");
|
|
|
2094
|
+ return f != null && f.equals(want);
|
|
|
2095
|
+ }
|
|
|
2096
|
+
|
|
|
2097
|
+ private Map<String, String> widgetLabels(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
2098
|
+ LinkedHashMap<String, String> m = new LinkedHashMap<String, String>();
|
|
|
2099
|
+ JSONArray ws = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
|
|
|
2100
|
+ for (int i = 0; i < ws.size(); ++i) {
|
|
|
2101
|
+ JSONObject w = ws.getJSONObject(i);
|
|
|
2102
|
+ String n = w.getString("name");
|
|
|
2103
|
+ String l = w.getString("label");
|
|
|
2104
|
+ if (n == null || l == null) continue;
|
|
|
2105
|
+ m.put(n, l);
|
|
|
2106
|
+ }
|
|
|
2107
|
+ return m;
|
|
|
2108
|
+ }
|
|
|
2109
|
+
|
|
|
2110
|
+ private static boolean hasValue(JSONObject row, String field) {
|
|
|
2111
|
+ if (field == null) {
|
|
|
2112
|
+ return false;
|
|
|
2113
|
+ }
|
|
|
2114
|
+ Object v = row.get((Object)field);
|
|
|
2115
|
+ if (v == null) {
|
|
|
2116
|
+ return false;
|
|
|
2117
|
+ }
|
|
|
2118
|
+ if (v instanceof String) {
|
|
|
2119
|
+ return !((String)v).trim().isEmpty();
|
|
|
2120
|
+ }
|
|
|
2121
|
+ if (v instanceof JSONObject) {
|
|
|
2122
|
+ JSONObject o = (JSONObject)v;
|
|
|
2123
|
+ return !o.isEmpty() && (o.getString("name") == null || !o.getString("name").trim().isEmpty());
|
|
|
2124
|
+ }
|
|
|
2125
|
+ if (v instanceof JSONArray) {
|
|
|
2126
|
+ return !((JSONArray)v).isEmpty();
|
|
|
2127
|
+ }
|
|
|
2128
|
+ return true;
|
|
|
2129
|
+ }
|
|
|
2130
|
+
|
|
|
2131
|
+ private static void sortByDateDesc(List<JSONObject> list, String dateField) {
|
|
|
2132
|
+ list.sort((a, b) -> {
|
|
|
2133
|
+ ZonedDateTime ta = JdyRiskStatisticsService.parseTime(a.getString(dateField));
|
|
|
2134
|
+ ZonedDateTime tb = JdyRiskStatisticsService.parseTime(b.getString(dateField));
|
|
|
2135
|
+ if (ta == null && tb == null) {
|
|
|
2136
|
+ return 0;
|
|
|
2137
|
+ }
|
|
|
2138
|
+ if (ta == null) {
|
|
|
2139
|
+ return 1;
|
|
|
2140
|
+ }
|
|
|
2141
|
+ if (tb == null) {
|
|
|
2142
|
+ return -1;
|
|
|
2143
|
+ }
|
|
|
2144
|
+ return tb.compareTo(ta);
|
|
|
2145
|
+ });
|
|
|
2146
|
+ }
|
|
|
2147
|
+
|
|
|
2148
|
+ private JSONObject findPreviousRefuel(JSONArray all, JdyRiskProperties.Scenario s, JSONObject current, ZonedDateTime curTime) {
|
|
|
2149
|
+ if (curTime == null) {
|
|
|
2150
|
+ return null;
|
|
|
2151
|
+ }
|
|
|
2152
|
+ String flagVal = s.getFlagValues().isEmpty() ? "\u662f" : s.getFlagValues().get(0);
|
|
|
2153
|
+ Integer wantFlow = s.getFlowStateValue();
|
|
|
2154
|
+ JSONObject best = null;
|
|
|
2155
|
+ ZonedDateTime bestT = null;
|
|
|
2156
|
+ for (int i = 0; i < all.size(); ++i) {
|
|
|
2157
|
+ ZonedDateTime t;
|
|
|
2158
|
+ Integer f;
|
|
|
2159
|
+ JSONObject row = all.getJSONObject(i);
|
|
|
2160
|
+ if (row == current || !flagVal.equals(row.getString(s.getFlagField())) || wantFlow != null && ((f = row.getInteger("flowState")) == null || !f.equals(wantFlow)) || (t = JdyRiskStatisticsService.parseTime(row.getString(s.getDateField()))) == null || !t.isBefore(curTime) || bestT != null && !t.isAfter(bestT)) continue;
|
|
|
2161
|
+ best = row;
|
|
|
2162
|
+ bestT = t;
|
|
|
2163
|
+ }
|
|
|
2164
|
+ return best;
|
|
|
2165
|
+ }
|
|
|
2166
|
+
|
|
|
2167
|
+ private static JSONArray filterByFlag(JSONArray rows, JdyRiskProperties.Scenario s) {
|
|
|
2168
|
+ String f = s.getFlagField();
|
|
|
2169
|
+ if (f == null || f.isEmpty() || s.getFlagValues().isEmpty()) {
|
|
|
2170
|
+ return rows;
|
|
|
2171
|
+ }
|
|
|
2172
|
+ JSONArray out = new JSONArray();
|
|
|
2173
|
+ for (int i = 0; i < rows.size(); ++i) {
|
|
|
2174
|
+ JSONObject row = rows.getJSONObject(i);
|
|
|
2175
|
+ if (!s.getFlagValues().contains(row.getString(f))) continue;
|
|
|
2176
|
+ out.add((Object)row);
|
|
|
2177
|
+ }
|
|
|
2178
|
+ return out;
|
|
|
2179
|
+ }
|
|
|
2180
|
+
|
|
|
2181
|
+ private static Set<String> bottomCompanyFields(Map<String, Double> totals, int n) {
|
|
|
2182
|
+ LinkedHashSet<String> bottom = new LinkedHashSet<String>();
|
|
|
2183
|
+ if (totals == null || totals.isEmpty() || n <= 0) {
|
|
|
2184
|
+ return bottom;
|
|
|
2185
|
+ }
|
|
|
2186
|
+ ArrayList<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(totals.entrySet());
|
|
|
2187
|
+ list.sort((a, b) -> Double.compare((Double)a.getValue(), (Double)b.getValue()));
|
|
|
2188
|
+ double cutoff = (Double)((Map.Entry)list.get(Math.min(n, list.size()) - 1)).getValue();
|
|
|
2189
|
+ for (Map.Entry entry : list) {
|
|
|
2190
|
+ if (!((Double)entry.getValue() <= cutoff)) continue;
|
|
|
2191
|
+ bottom.add((String)entry.getKey());
|
|
|
2192
|
+ }
|
|
|
2193
|
+ return bottom;
|
|
|
2194
|
+ }
|
|
|
2195
|
+
|
|
|
2196
|
+ private static double startKm(JSONObject row, JdyRiskProperties.Scenario s) {
|
|
|
2197
|
+ Object o;
|
|
|
2198
|
+ double v = JdyRiskStatisticsService.num(row, s.getStartKmField());
|
|
|
2199
|
+ if (v > 0.0) {
|
|
|
2200
|
+ return v;
|
|
|
2201
|
+ }
|
|
|
2202
|
+ if (s.getSubformField() != null && s.getSubformStartField() != null && (o = row.get((Object)s.getSubformField())) instanceof JSONArray) {
|
|
|
2203
|
+ JSONArray arr = (JSONArray)o;
|
|
|
2204
|
+ double max = 0.0;
|
|
|
2205
|
+ for (int i = 0; i < arr.size(); ++i) {
|
|
|
2206
|
+ double sv;
|
|
|
2207
|
+ Object it = arr.get(i);
|
|
|
2208
|
+ if (!(it instanceof JSONObject) || !((sv = JdyRiskStatisticsService.num((JSONObject)it, s.getSubformStartField())) > max)) continue;
|
|
|
2209
|
+ max = sv;
|
|
|
2210
|
+ }
|
|
|
2211
|
+ return max;
|
|
|
2212
|
+ }
|
|
|
2213
|
+ return 0.0;
|
|
|
2214
|
+ }
|
|
|
2215
|
+
|
|
|
2216
|
+ private static JSONObject syntheticWidget(String name, String label) {
|
|
|
2217
|
+ JSONObject w = new JSONObject();
|
|
|
2218
|
+ w.put("name", (Object)name);
|
|
|
2219
|
+ w.put("label", (Object)label);
|
|
|
2220
|
+ return w;
|
|
|
2221
|
+ }
|
|
|
2222
|
+
|
|
|
2223
|
+ private static Map<String, List<JSONObject>> groupByBarcode(JSONArray rows, String field) {
|
|
|
2224
|
+ LinkedHashMap<String, List<JSONObject>> map = new LinkedHashMap<String, List<JSONObject>>();
|
|
|
2225
|
+ for (int i = 0; i < rows.size(); ++i) {
|
|
|
2226
|
+ JSONObject row = rows.getJSONObject(i);
|
|
|
2227
|
+ String b = row.getString(field);
|
|
|
2228
|
+ if (b == null || b.trim().isEmpty()) continue;
|
|
|
2229
|
+ map.computeIfAbsent(b.trim(), k -> new ArrayList()).add(row);
|
|
|
2230
|
+ }
|
|
|
2231
|
+ return map;
|
|
|
2232
|
+ }
|
|
|
2233
|
+
|
|
|
2234
|
+ private Set<String> warningSuppliers2(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
|
2235
|
+ LinkedHashMap<String, double[]> byGroup = new LinkedHashMap<String, double[]>();
|
|
|
2236
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
|
2237
|
+ JSONObject row = data.getJSONObject(i);
|
|
|
2238
|
+ String group = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
|
2239
|
+ double qty = JdyRiskStatisticsService.num(row, s.getQtyField());
|
|
|
2240
|
+ double[] agg = byGroup.computeIfAbsent(group, k -> new double[2]);
|
|
|
2241
|
+ agg[0] = agg[0] + qty;
|
|
|
2242
|
+ if (!"SI".equalsIgnoreCase(row.getString(s.getSiField()))) continue;
|
|
|
2243
|
+ agg[1] = agg[1] + qty;
|
|
|
2244
|
+ }
|
|
|
2245
|
+ LinkedHashSet<String> warn = new LinkedHashSet<String>();
|
|
|
2246
|
+ for (Map.Entry e : byGroup.entrySet()) {
|
|
|
2247
|
+ double[] agg = (double[])e.getValue();
|
|
|
2248
|
+ if (!(agg[0] >= 5.0) || !(agg[1] / agg[0] > 0.6)) continue;
|
|
|
2249
|
+ warn.add((String)e.getKey());
|
|
|
2250
|
+ }
|
|
|
2251
|
+ return warn;
|
|
|
2252
|
+ }
|
|
|
2253
|
+
|
|
|
2254
|
+ private List<String> buildExtraValues(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
|
2255
|
+ String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
2256
|
+ Set<String> warnGroups = null;
|
|
|
2257
|
+ Map<String, Double> ratio2 = null;
|
|
|
2258
|
+ if ("scenario2".equals(type)) {
|
|
|
2259
|
+ ratio2 = this.supplierRatio2(s, data);
|
|
|
2260
|
+ warnGroups = ratio2.keySet();
|
|
|
2261
|
+ } else if ("scenario4".equals(type) || "scenario5".equals(type)) {
|
|
|
2262
|
+ warnGroups = this.warningGroupsByUp(s, data);
|
|
|
2263
|
+ } else if ("scenario6".equals(type)) {
|
|
|
2264
|
+ warnGroups = this.warningGroupsByCount(s, data);
|
|
|
2265
|
+ } else if ("scenario8".equals(type) || "scenario9".equals(type)) {
|
|
|
2266
|
+ ratio2 = this.groupRatioByFlag(s, data);
|
|
|
2267
|
+ warnGroups = ratio2.keySet();
|
|
|
2268
|
+ }
|
|
|
2269
|
+ ArrayList<String> values = new ArrayList<String>();
|
|
|
2270
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
|
2271
|
+ JSONObject row = data.getJSONObject(i);
|
|
487
|
2272
|
String v = "";
|
|
488
|
2273
|
if ("scenario1".equals(type)) {
|
|
489
|
|
- v = rowHitScenario1(s, row) ? displayName(s, row) : "";
|
|
|
2274
|
+ v = this.rowHitScenario1(s, row) ? this.displayName(s, row) : "";
|
|
490
|
2275
|
} else if ("scenario3".equals(type)) {
|
|
491
|
|
- v = rowHitScenario3(s, row) ? displayName(s, row) : "";
|
|
|
2276
|
+ v = this.rowHitScenario3(s, row) ? this.displayName(s, row) : "";
|
|
|
2277
|
+ } else if (ratio2 != null) {
|
|
|
2278
|
+ Double rr = ratio2.get(JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField())));
|
|
|
2279
|
+ v = rr != null ? this.displayName(s, row) + "(" + String.format("%.1f%%", rr * 100.0) + ")" : "";
|
|
492
|
2280
|
} else if (warnGroups != null) {
|
|
493
|
|
- String g = orEmpty(row.getString(s.getGroupField()));
|
|
494
|
|
- v = warnGroups.contains(g) ? displayName(s, row) : "";
|
|
|
2281
|
+ String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
|
2282
|
+ v = warnGroups.contains(g) ? this.displayName(s, row) : "";
|
|
495
|
2283
|
}
|
|
496
|
2284
|
values.add(v);
|
|
497
|
2285
|
}
|
|
498
|
2286
|
return values;
|
|
499
|
2287
|
}
|
|
500
|
2288
|
|
|
|
2289
|
+ private Map<String, Double> supplierRatio2(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
|
2290
|
+ double[] agg;
|
|
|
2291
|
+ LinkedHashMap<String, double[]> byGroup = new LinkedHashMap<String, double[]>();
|
|
|
2292
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
|
2293
|
+ JSONObject row = data.getJSONObject(i);
|
|
|
2294
|
+ String group = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
|
2295
|
+ agg = byGroup.computeIfAbsent(group, k -> new double[2]);
|
|
|
2296
|
+ double qty = JdyRiskStatisticsService.num(row, s.getQtyField());
|
|
|
2297
|
+ agg[0] = agg[0] + qty;
|
|
|
2298
|
+ if (!"SI".equalsIgnoreCase(row.getString(s.getSiField()))) continue;
|
|
|
2299
|
+ agg[1] = agg[1] + qty;
|
|
|
2300
|
+ }
|
|
|
2301
|
+ LinkedHashMap<String, Double> out = new LinkedHashMap<String, Double>();
|
|
|
2302
|
+ for (Map.Entry e : byGroup.entrySet()) {
|
|
|
2303
|
+ agg = (double[])e.getValue();
|
|
|
2304
|
+ if (!(agg[0] >= 5.0) || !(agg[1] / agg[0] > 0.6)) continue;
|
|
|
2305
|
+ out.put((String)e.getKey(), agg[1] / agg[0]);
|
|
|
2306
|
+ }
|
|
|
2307
|
+ return out;
|
|
|
2308
|
+ }
|
|
|
2309
|
+
|
|
|
2310
|
+ private Map<String, Double> groupRatioByFlag(JdyRiskProperties.Scenario s, JSONArray data) {
|
|
|
2311
|
+ LinkedHashMap<String, int[]> byGroup = new LinkedHashMap<String, int[]>();
|
|
|
2312
|
+ for (int i = 0; i < data.size(); ++i) {
|
|
|
2313
|
+ JSONObject row = data.getJSONObject(i);
|
|
|
2314
|
+ String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
|
|
|
2315
|
+ int[] agg = byGroup.computeIfAbsent(g, k -> new int[2]);
|
|
|
2316
|
+ agg[0] = agg[0] + 1;
|
|
|
2317
|
+ if (s.getFlagValue() == null || !s.getFlagValue().equalsIgnoreCase(row.getString(s.getFlagField()))) continue;
|
|
|
2318
|
+ agg[1] = agg[1] + 1;
|
|
|
2319
|
+ }
|
|
|
2320
|
+ LinkedHashMap<String, Double> out = new LinkedHashMap<String, Double>();
|
|
|
2321
|
+ double th = s.getRatioThreshold();
|
|
|
2322
|
+ for (Map.Entry e : byGroup.entrySet()) {
|
|
|
2323
|
+ int[] agg = (int[])e.getValue();
|
|
|
2324
|
+ if (agg[0] <= 0 || !((double)agg[1] / (double)agg[0] > th)) continue;
|
|
|
2325
|
+ out.put((String)e.getKey(), (double)agg[1] / (double)agg[0]);
|
|
|
2326
|
+ }
|
|
|
2327
|
+ return out;
|
|
|
2328
|
+ }
|
|
|
2329
|
+
|
|
501
|
2330
|
private String displayName(JdyRiskProperties.Scenario s, JSONObject row) {
|
|
|
2331
|
+ Map<String, String> lk;
|
|
|
2332
|
+ Object v;
|
|
502
|
2333
|
if (s.getExtraField() != null && !s.getExtraField().isEmpty()) {
|
|
503
|
|
- return orEmpty(row.getString(s.getExtraField()));
|
|
|
2334
|
+ v = row.get((Object)s.getExtraField());
|
|
|
2335
|
+ } else if (s.getGroupField() != null && !s.getGroupField().isEmpty()) {
|
|
|
2336
|
+ v = row.get((Object)s.getGroupField());
|
|
|
2337
|
+ } else {
|
|
|
2338
|
+ return "\u547d\u4e2d";
|
|
|
2339
|
+ }
|
|
|
2340
|
+ if (v instanceof String && (lk = JdyExcelExportService.currentLookup()) != null && lk.containsKey(v)) {
|
|
|
2341
|
+ return lk.get(v);
|
|
|
2342
|
+ }
|
|
|
2343
|
+ return JdyRiskStatisticsService.toDisplayName(v);
|
|
|
2344
|
+ }
|
|
|
2345
|
+
|
|
|
2346
|
+ private Map<String, String> buildLookupMap(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
|
|
|
2347
|
+ LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
|
|
2348
|
+ if (s.getLookupEntryId() == null || s.getLookupEntryId().isEmpty() || s.getLookupNameField() == null || s.getLookupNameField().isEmpty()) {
|
|
|
2349
|
+ return map;
|
|
|
2350
|
+ }
|
|
|
2351
|
+ jdy.forEachPage(this.props.getApiKey(), s.getAppId(), s.getLookupEntryId(), Collections.singletonList(s.getLookupNameField()), page -> {
|
|
|
2352
|
+ for (int i = 0; i < page.size(); ++i) {
|
|
|
2353
|
+ JSONObject r = page.getJSONObject(i);
|
|
|
2354
|
+ String id = r.getString("_id");
|
|
|
2355
|
+ String name = r.getString(s.getLookupNameField());
|
|
|
2356
|
+ if (id == null || name == null) continue;
|
|
|
2357
|
+ map.put(id, name);
|
|
|
2358
|
+ }
|
|
|
2359
|
+ });
|
|
|
2360
|
+ log.info("\u573a\u666f[{}] \u5173\u8054\u8868 {} \u6620\u5c04 {} \u6761", new Object[]{s.getId(), s.getLookupEntryId(), map.size()});
|
|
|
2361
|
+ return map;
|
|
|
2362
|
+ }
|
|
|
2363
|
+
|
|
|
2364
|
+ private static void sortRows(JSONArray rows, String field) {
|
|
|
2365
|
+ ArrayList<JSONObject> list = new ArrayList<JSONObject>();
|
|
|
2366
|
+ for (int i = 0; i < rows.size(); ++i) {
|
|
|
2367
|
+ list.add(rows.getJSONObject(i));
|
|
504
|
2368
|
}
|
|
505
|
|
- if (s.getGroupField() != null && !s.getGroupField().isEmpty()) {
|
|
506
|
|
- return orEmpty(row.getString(s.getGroupField()));
|
|
|
2369
|
+ list.sort((a, b) -> JdyRiskStatisticsService.toDisplayName(a.get((Object)field)).compareTo(JdyRiskStatisticsService.toDisplayName(b.get((Object)field))));
|
|
|
2370
|
+ rows.clear();
|
|
|
2371
|
+ for (JSONObject o : list) {
|
|
|
2372
|
+ rows.add((Object)o);
|
|
507
|
2373
|
}
|
|
508
|
|
- return "命中";
|
|
|
2374
|
+ }
|
|
|
2375
|
+
|
|
|
2376
|
+ private static String toDisplayName(Object v) {
|
|
|
2377
|
+ if (v == null) {
|
|
|
2378
|
+ return "";
|
|
|
2379
|
+ }
|
|
|
2380
|
+ if (v instanceof JSONObject) {
|
|
|
2381
|
+ JSONObject o = (JSONObject)v;
|
|
|
2382
|
+ String n = o.getString("dataTitle");
|
|
|
2383
|
+ if (n == null || n.isEmpty()) {
|
|
|
2384
|
+ n = o.getString("name");
|
|
|
2385
|
+ }
|
|
|
2386
|
+ return n == null ? "" : n;
|
|
|
2387
|
+ }
|
|
|
2388
|
+ if (v instanceof JSONArray) {
|
|
|
2389
|
+ JSONArray arr = (JSONArray)v;
|
|
|
2390
|
+ StringBuilder sb = new StringBuilder();
|
|
|
2391
|
+ for (int i = 0; i < arr.size(); ++i) {
|
|
|
2392
|
+ String n = JdyRiskStatisticsService.toDisplayName(arr.get(i));
|
|
|
2393
|
+ if (n.isEmpty()) continue;
|
|
|
2394
|
+ if (sb.length() > 0) {
|
|
|
2395
|
+ sb.append(",");
|
|
|
2396
|
+ }
|
|
|
2397
|
+ sb.append(n);
|
|
|
2398
|
+ }
|
|
|
2399
|
+ return sb.toString();
|
|
|
2400
|
+ }
|
|
|
2401
|
+ String s = String.valueOf(v);
|
|
|
2402
|
+ return "null".equals(s) ? "" : s;
|
|
|
2403
|
+ }
|
|
|
2404
|
+
|
|
|
2405
|
+ private JSONArray filterWarnRows(JdyRiskProperties.Scenario s, JSONArray rows) {
|
|
|
2406
|
+ String type = s.getType() == null ? "" : s.getType().toLowerCase();
|
|
|
2407
|
+ Set<String> warnGroups = null;
|
|
|
2408
|
+ if ("scenario2".equals(type)) {
|
|
|
2409
|
+ warnGroups = this.warningSuppliers2(s, rows);
|
|
|
2410
|
+ } else if ("scenario4".equals(type) || "scenario5".equals(type)) {
|
|
|
2411
|
+ warnGroups = this.warningGroupsByUp(s, rows);
|
|
|
2412
|
+ } else if ("scenario8".equals(type) || "scenario9".equals(type)) {
|
|
|
2413
|
+ warnGroups = this.warningGroupsByRatio(s, rows);
|
|
|
2414
|
+ }
|
|
|
2415
|
+ JSONArray out = new JSONArray();
|
|
|
2416
|
+ for (int i = 0; i < rows.size(); ++i) {
|
|
|
2417
|
+ JSONObject row = rows.getJSONObject(i);
|
|
|
2418
|
+ boolean keep = warnGroups != null ? warnGroups.contains(JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()))) : ("scenario3".equals(type) ? this.rowHitScenario3(s, row) : ("scenario1".equals(type) ? this.rowHitScenario1(s, row) : true));
|
|
|
2419
|
+ if (!keep) continue;
|
|
|
2420
|
+ out.add((Object)row);
|
|
|
2421
|
+ }
|
|
|
2422
|
+ return out;
|
|
509
|
2423
|
}
|
|
510
|
2424
|
|
|
511
|
2425
|
private boolean rowHitScenario1(JdyRiskProperties.Scenario s, JSONObject row) {
|
|
512
|
|
- double total = num(row, s.getTotalField());
|
|
513
|
|
- double diff = num(row, s.getDiffField());
|
|
|
2426
|
+ double total = JdyRiskStatisticsService.num(row, s.getTotalField());
|
|
|
2427
|
+ double diff = JdyRiskStatisticsService.num(row, s.getDiffField());
|
|
514
|
2428
|
Integer flow = row.getInteger("flowState");
|
|
515
|
|
- return total >= 5 && diff >= 1 && flow != null && flow == s.getInProgressState();
|
|
|
2429
|
+ return total >= 5.0 && diff >= 1.0 && flow != null && flow.intValue() == s.getInProgressState();
|
|
516
|
2430
|
}
|
|
517
|
2431
|
|
|
518
|
2432
|
private boolean rowHitScenario3(JdyRiskProperties.Scenario s, JSONObject row) {
|
|
519
|
|
- double total = num(row, s.getTotalField());
|
|
520
|
|
- double ratio = num(row, s.getRatioField());
|
|
521
|
|
- return total >= 5 && ratio > 0.6;
|
|
|
2433
|
+ double total = JdyRiskStatisticsService.num(row, s.getTotalField());
|
|
|
2434
|
+ double ratio = JdyRiskStatisticsService.num(row, s.getRatioField());
|
|
|
2435
|
+ return total >= 5.0 && ratio > 0.6;
|
|
522
|
2436
|
}
|
|
523
|
2437
|
|
|
524
|
|
- /** 升级字段是否命中:非空 且 不在排除值内。 */
|
|
525
|
2438
|
private boolean isUpHit(JdyRiskProperties.Scenario s, JSONObject row) {
|
|
526
|
2439
|
String up = row.getString(s.getUpField());
|
|
527
|
2440
|
if (up == null || up.trim().isEmpty()) {
|
|
...
|
...
|
@@ -529,38 +2442,179 @@ public class JdyRiskStatisticsService { |
|
529
|
2442
|
}
|
|
530
|
2443
|
if (s.getExcludeValues() != null) {
|
|
531
|
2444
|
for (String ex : s.getExcludeValues()) {
|
|
532
|
|
- if (ex != null && ex.equalsIgnoreCase(up.trim())) {
|
|
533
|
|
- return false;
|
|
534
|
|
- }
|
|
|
2445
|
+ if (ex == null || !ex.equalsIgnoreCase(up.trim())) continue;
|
|
|
2446
|
+ return false;
|
|
535
|
2447
|
}
|
|
536
|
2448
|
}
|
|
537
|
2449
|
return true;
|
|
538
|
2450
|
}
|
|
539
|
2451
|
|
|
540
|
|
- /* ==================== 工具 ==================== */
|
|
|
2452
|
+ private JSONObject findTodayRecord(JSONArray records, JdyRiskProperties.Scenario s, Biz biz, String timeField) {
|
|
|
2453
|
+ if (records == null || s == null || timeField == null || timeField.isEmpty()) {
|
|
|
2454
|
+ return null;
|
|
|
2455
|
+ }
|
|
|
2456
|
+ String today = this.now().format(DAY_FMT);
|
|
|
2457
|
+ for (JSONObject r : this.candidates(records, s, biz)) {
|
|
|
2458
|
+ Long t = r.getLong(timeField);
|
|
|
2459
|
+ if (t == null || !Instant.ofEpochMilli(t).atZone(ZONE).format(DAY_FMT).equals(today)) continue;
|
|
|
2460
|
+ return r;
|
|
|
2461
|
+ }
|
|
|
2462
|
+ return null;
|
|
|
2463
|
+ }
|
|
|
2464
|
+
|
|
|
2465
|
+ private JSONObject buildAttach(String fileId, String fileName, long size) {
|
|
|
2466
|
+ JSONObject rel = new JSONObject();
|
|
|
2467
|
+ rel.put("uid", (Object)fileId);
|
|
|
2468
|
+ rel.put("name", (Object)fileName);
|
|
|
2469
|
+ rel.put("size", (Object)size);
|
|
|
2470
|
+ rel.put("fileId", (Object)fileId);
|
|
|
2471
|
+ rel.put("status", (Object)"done");
|
|
|
2472
|
+ rel.put("id", (Object)fileId);
|
|
|
2473
|
+ rel.put("dataTitle", (Object)fileName);
|
|
|
2474
|
+ return rel;
|
|
|
2475
|
+ }
|
|
|
2476
|
+
|
|
|
2477
|
+ private static void setTimeFields(JSONObject rec, JdyRiskProperties.Qx qx, long now) {
|
|
|
2478
|
+ if (qx.getTimeField() != null && !qx.getTimeField().isEmpty()) {
|
|
|
2479
|
+ rec.put(qx.getTimeField(), (Object)now);
|
|
|
2480
|
+ }
|
|
|
2481
|
+ if (qx.getTimeField2() != null && !qx.getTimeField2().isEmpty()) {
|
|
|
2482
|
+ rec.put(qx.getTimeField2(), (Object)now);
|
|
|
2483
|
+ }
|
|
|
2484
|
+ }
|
|
|
2485
|
+
|
|
|
2486
|
+ private JSONObject cloneTemplate(JSONObject template, JdyRiskProperties.Qx qx, String syncCode, long count, long now, String fileId, String fileName, long size, boolean skipAttach) {
|
|
|
2487
|
+ JSONObject body = new JSONObject();
|
|
|
2488
|
+ body.putAll((Map)template);
|
|
|
2489
|
+ body.remove((Object)"id");
|
|
|
2490
|
+ body.remove((Object)"corpCode");
|
|
|
2491
|
+ body.remove((Object)"createdBy");
|
|
|
2492
|
+ body.remove((Object)"updatedBy");
|
|
|
2493
|
+ body.remove((Object)"createdAt");
|
|
|
2494
|
+ body.remove((Object)"updatedAt");
|
|
|
2495
|
+ body.put(qx.getCountField(), (Object)count);
|
|
|
2496
|
+ body.put("syncCode", (Object)syncCode);
|
|
|
2497
|
+ JdyRiskStatisticsService.setTimeFields(body, qx, now);
|
|
|
2498
|
+ String af = qx.getAttachField();
|
|
|
2499
|
+ if (af != null && !af.isEmpty()) {
|
|
|
2500
|
+ if (skipAttach || fileId == null) {
|
|
|
2501
|
+ body.remove((Object)af);
|
|
|
2502
|
+ body.remove((Object)(af + "Id"));
|
|
|
2503
|
+ } else {
|
|
|
2504
|
+ body.put(af, (Object)this.buildAttach(fileId, fileName, size));
|
|
|
2505
|
+ body.put(af + "Id", (Object)fileId);
|
|
|
2506
|
+ }
|
|
|
2507
|
+ }
|
|
|
2508
|
+ return body;
|
|
|
2509
|
+ }
|
|
541
|
2510
|
|
|
542
|
|
- /** 在启效记录中按 syncCode 匹配(重复时取第一条并告警)。 */
|
|
543
|
|
- private JSONObject findRecordBySyncCode(JSONArray records, String syncCode) {
|
|
544
|
|
- if (records == null || syncCode == null || syncCode.isEmpty()) {
|
|
|
2511
|
+ private JSONObject buildAddBody(Biz biz, JdyRiskProperties.Qx qx, String syncCode, long count, long now, String fileId, String fileName, long size) {
|
|
|
2512
|
+ JSONObject unit = new JSONObject();
|
|
|
2513
|
+ unit.put("dataTitle", (Object)biz.unitTitle);
|
|
|
2514
|
+ unit.put("id", (Object)biz.unitId);
|
|
|
2515
|
+ JSONObject leader = new JSONObject();
|
|
|
2516
|
+ leader.put("dataTitle", (Object)biz.leaderTitle);
|
|
|
2517
|
+ leader.put("id", (Object)biz.leaderId);
|
|
|
2518
|
+ JSONObject scene = new JSONObject();
|
|
|
2519
|
+ scene.put("id", (Object)biz.sceneId);
|
|
|
2520
|
+ scene.put("dataTitle", (Object)biz.sceneTitle);
|
|
|
2521
|
+ scene.put("faomis", (Object)biz.domain);
|
|
|
2522
|
+ scene.put("xxwbzf", (Object)biz.businessLine);
|
|
|
2523
|
+ scene.put("qdbuhp", (Object)unit);
|
|
|
2524
|
+ scene.put("pofmup", (Object)leader);
|
|
|
2525
|
+ if (biz.sceneMemberId != null) {
|
|
|
2526
|
+ JSONObject member = new JSONObject();
|
|
|
2527
|
+ member.put("dataTitle", (Object)biz.sceneMemberTitle);
|
|
|
2528
|
+ member.put("id", (Object)biz.sceneMemberId);
|
|
|
2529
|
+ scene.put("jiaplm", (Object)member);
|
|
|
2530
|
+ }
|
|
|
2531
|
+ if (biz.sivnbu != null) {
|
|
|
2532
|
+ scene.put("lwpfsp", (Object)biz.sivnbu);
|
|
|
2533
|
+ }
|
|
|
2534
|
+ if (biz.ilecyn != null) {
|
|
|
2535
|
+ scene.put("vikuzx", (Object)biz.ilecyn);
|
|
|
2536
|
+ }
|
|
|
2537
|
+ JSONObject body = new JSONObject();
|
|
|
2538
|
+ body.put("miidqb", (Object)scene);
|
|
|
2539
|
+ body.put("miidqbId", (Object)biz.sceneId);
|
|
|
2540
|
+ body.put("gyxwbd", (Object)biz.domain);
|
|
|
2541
|
+ body.put("wifxkb", (Object)biz.businessLine);
|
|
|
2542
|
+ if (biz.sivnbu != null) {
|
|
|
2543
|
+ body.put("sivnbu", (Object)biz.sivnbu);
|
|
|
2544
|
+ }
|
|
|
2545
|
+ if (biz.ilecyn != null) {
|
|
|
2546
|
+ body.put("ilecyn", (Object)biz.ilecyn);
|
|
|
2547
|
+ }
|
|
|
2548
|
+ body.put("gnzuoi", (Object)unit);
|
|
|
2549
|
+ body.put("gnzuoiId", (Object)biz.unitId);
|
|
|
2550
|
+ body.put("khexbl", (Object)leader);
|
|
|
2551
|
+ body.put("khexblId", (Object)biz.leaderId);
|
|
|
2552
|
+ JdyRiskStatisticsService.setTimeFields(body, qx, now);
|
|
|
2553
|
+ body.put("sxhuzf", (Object)"1");
|
|
|
2554
|
+ body.put(qx.getCountField(), (Object)count);
|
|
|
2555
|
+ body.put("syncCode", (Object)syncCode);
|
|
|
2556
|
+ if (biz.jetcalId != null) {
|
|
|
2557
|
+ JSONObject jet = new JSONObject();
|
|
|
2558
|
+ jet.put("dataTitle", (Object)biz.jetcalTitle);
|
|
|
2559
|
+ jet.put("id", (Object)biz.jetcalId);
|
|
|
2560
|
+ body.put("jetcal", (Object)jet);
|
|
|
2561
|
+ body.put("jetcalId", (Object)biz.jetcalId);
|
|
|
2562
|
+ }
|
|
|
2563
|
+ if (biz.zawlah != null) {
|
|
|
2564
|
+ body.put("zawlah", (Object)biz.zawlah);
|
|
|
2565
|
+ }
|
|
|
2566
|
+ if (fileId != null && qx.getAttachField() != null && !qx.getAttachField().isEmpty()) {
|
|
|
2567
|
+ body.put(qx.getAttachField(), (Object)this.buildAttach(fileId, fileName, size));
|
|
|
2568
|
+ body.put(qx.getAttachField() + "Id", (Object)fileId);
|
|
|
2569
|
+ }
|
|
|
2570
|
+ return body;
|
|
|
2571
|
+ }
|
|
|
2572
|
+
|
|
|
2573
|
+ private JSONObject findRecordBySyncCode(JSONArray records, JdyRiskProperties.Scenario s, Biz biz) {
|
|
|
2574
|
+ List<JSONObject> list = this.candidates(records, s, biz);
|
|
|
2575
|
+ if (list.isEmpty()) {
|
|
545
|
2576
|
return null;
|
|
546
|
2577
|
}
|
|
547
|
|
- JSONObject found = null;
|
|
548
|
|
- for (int i = 0; i < records.size(); i++) {
|
|
|
2578
|
+ if (list.size() > 1) {
|
|
|
2579
|
+ log.warn("syncCode={} \u573a\u666f={} \u5b58\u5728\u591a\u6761\u8bb0\u5f55\uff08id={} \u4e0e id={}\uff09\uff0c\u4f7f\u7528\u7b2c\u4e00\u6761", new Object[]{s.getSyncCode(), biz != null ? biz.sceneId : "", list.get(0).getString("id"), list.get(1).getString("id")});
|
|
|
2580
|
+ }
|
|
|
2581
|
+ return list.get(0);
|
|
|
2582
|
+ }
|
|
|
2583
|
+
|
|
|
2584
|
+ private List<JSONObject> candidates(JSONArray records, JdyRiskProperties.Scenario s, Biz biz) {
|
|
|
2585
|
+ ArrayList<JSONObject> byCode = new ArrayList<JSONObject>();
|
|
|
2586
|
+ ArrayList<JSONObject> byScene = new ArrayList<JSONObject>();
|
|
|
2587
|
+ if (records == null || s == null || s.getSyncCode() == null) {
|
|
|
2588
|
+ return byCode;
|
|
|
2589
|
+ }
|
|
|
2590
|
+ for (int i = 0; i < records.size(); ++i) {
|
|
549
|
2591
|
JSONObject r = records.getJSONObject(i);
|
|
550
|
|
- if (syncCode.equals(r.getString("syncCode"))) {
|
|
551
|
|
- if (found == null) {
|
|
552
|
|
- found = r;
|
|
553
|
|
- } else {
|
|
554
|
|
- log.warn("syncCode={} 存在多条记录(id={} 与 id={}),使用第一条",
|
|
555
|
|
- syncCode, found.getString("id"), r.getString("id"));
|
|
556
|
|
- }
|
|
557
|
|
- }
|
|
|
2592
|
+ if (!s.getSyncCode().equals(r.getString("syncCode"))) continue;
|
|
|
2593
|
+ byCode.add(r);
|
|
|
2594
|
+ if (!JdyRiskStatisticsService.sceneMatches(r, biz)) continue;
|
|
|
2595
|
+ byScene.add(r);
|
|
558
|
2596
|
}
|
|
559
|
|
- return found;
|
|
|
2597
|
+ if (biz != null && biz.sceneId != null && !byScene.isEmpty()) {
|
|
|
2598
|
+ return byScene;
|
|
|
2599
|
+ }
|
|
|
2600
|
+ if (byCode.size() > 1 && biz != null && biz.sceneId != null) {
|
|
|
2601
|
+ log.warn("syncCode={} \u5b58\u5728 {} \u6761\u8bb0\u5f55\u4e14\u65e0\u5339\u914d\u573a\u666f {}\uff0c\u4e3a\u907f\u514d\u8bef\u66f4\u65b0\u5c06\u65b0\u589e\u5904\u7406", new Object[]{s.getSyncCode(), byCode.size(), biz.sceneId});
|
|
|
2602
|
+ return new ArrayList<JSONObject>();
|
|
|
2603
|
+ }
|
|
|
2604
|
+ return byCode;
|
|
|
2605
|
+ }
|
|
|
2606
|
+
|
|
|
2607
|
+ private static boolean sceneMatches(JSONObject r, Biz biz) {
|
|
|
2608
|
+ if (biz == null || biz.sceneId == null) {
|
|
|
2609
|
+ return true;
|
|
|
2610
|
+ }
|
|
|
2611
|
+ JSONObject scene = r.getJSONObject("miidqb");
|
|
|
2612
|
+ String id = scene != null ? scene.getString("id") : r.getString("miidqbId");
|
|
|
2613
|
+ return biz.sceneId.equals(id);
|
|
560
|
2614
|
}
|
|
561
|
2615
|
|
|
562
|
2616
|
private static ZonedDateTime quarterStart(ZonedDateTime now) {
|
|
563
|
|
- int qStartMonth = ((now.getMonthValue() - 1) / 3) * 3 + 1;
|
|
|
2617
|
+ int qStartMonth = (now.getMonthValue() - 1) / 3 * 3 + 1;
|
|
564
|
2618
|
return now.withMonth(qStartMonth).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
|
|
565
|
2619
|
}
|
|
566
|
2620
|
|
|
...
|
...
|
@@ -570,30 +2624,199 @@ public class JdyRiskStatisticsService { |
|
570
|
2624
|
}
|
|
571
|
2625
|
try {
|
|
572
|
2626
|
return Instant.parse(iso).atZone(ZONE);
|
|
573
|
|
- } catch (Exception e) {
|
|
|
2627
|
+ }
|
|
|
2628
|
+ catch (Exception e) {
|
|
574
|
2629
|
return null;
|
|
575
|
2630
|
}
|
|
576
|
2631
|
}
|
|
577
|
2632
|
|
|
578
|
2633
|
private static double num(JSONObject row, String field) {
|
|
579
|
2634
|
if (field == null) {
|
|
580
|
|
- return 0d;
|
|
|
2635
|
+ return 0.0;
|
|
581
|
2636
|
}
|
|
582
|
|
- Object v = row.get(field);
|
|
|
2637
|
+ Object v = row.get((Object)field);
|
|
583
|
2638
|
if (v == null) {
|
|
584
|
|
- return 0d;
|
|
|
2639
|
+ return 0.0;
|
|
585
|
2640
|
}
|
|
586
|
2641
|
if (v instanceof Number) {
|
|
587
|
|
- return ((Number) v).doubleValue();
|
|
|
2642
|
+ return ((Number)v).doubleValue();
|
|
588
|
2643
|
}
|
|
589
|
2644
|
try {
|
|
590
|
2645
|
return Double.parseDouble(String.valueOf(v));
|
|
591
|
|
- } catch (NumberFormatException e) {
|
|
592
|
|
- return 0d;
|
|
|
2646
|
+ }
|
|
|
2647
|
+ catch (NumberFormatException e) {
|
|
|
2648
|
+ return 0.0;
|
|
593
|
2649
|
}
|
|
594
|
2650
|
}
|
|
595
|
2651
|
|
|
596
|
2652
|
private static String orEmpty(String s) {
|
|
597
|
|
- return (s == null || s.isEmpty()) ? "(空)" : s;
|
|
|
2653
|
+ return s == null || s.isEmpty() ? "(\u7a7a)" : s;
|
|
|
2654
|
+ }
|
|
|
2655
|
+
|
|
|
2656
|
+ static {
|
|
|
2657
|
+ BIZ.put("SYNC0001", new Biz("1", "\u4f9b\u5e94\u5546\u7ee9\u6548\u8bc4\u4ef7", "B97s4IjzEBCqYE6162N", "\u6280\u672f\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "ltgYjvQ4Hz4sdq5BA4j", "26MY3mis\u7ef4\u4fee"));
|
|
|
2658
|
+ BIZ.put("SYNC0002", new Biz("1", "\u751f\u4ea7\u8fc7\u7a0b\u8d28\u91cf\u7d22\u8d54\u7ba1\u7406\u4e1a\u52a1\u7ebf", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "ilKV2ucowXkCZLmcRbI", "\u8d23\u4efb\u5224\u5b9aSI-\u4f9b\u5e94\u5546"));
|
|
|
2659
|
+ BIZ.put("SYNC0003", new Biz("1", "\u751f\u4ea7\u8fc7\u7a0b\u8d28\u91cf\u7d22\u8d54\u7ba1\u7406\u4e1a\u52a1\u7ebf", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "Mqn0b2FMTbJPzw5yf2L", "\u8d23\u4efb\u5224\u5b9aSI-\u5de5\u7a0b\u5e08"));
|
|
|
2660
|
+ BIZ.put("SYNC0004", new Biz("1", "\u751f\u4ea7\u8fc7\u7a0b\u8d28\u91cf\u7d22\u8d54\u7ba1\u7406\u4e1a\u52a1\u7ebf", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "JXpTEimiPxT9OyUCdOs", "CR\u7533\u8bc9-\u4f9b\u5e94\u5546"));
|
|
|
2661
|
+ BIZ.put("SYNC0005", new Biz("1", "\u751f\u4ea7\u8fc7\u7a0b\u8d28\u91cf\u7d22\u8d54\u7ba1\u7406\u4e1a\u52a1\u7ebf", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "8UPj3nt0Sx9uZS6dgVF", "CR\u7533\u8bc9-\u5de5\u7a0b\u5e08"));
|
|
|
2662
|
+ BIZ.put("SYNC0006", new Biz("1", "\u4e09\u5305\u7d22\u8d54\u7ba1\u7406", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "J15qNYvHMzMRf9e6RZe", "\u4f9b\u5e94\u5546\u7d22\u8d54\u7387"));
|
|
|
2663
|
+ BIZ.put("SYNC0007", new Biz("1", "\u4e09\u5305\u7d22\u8d54\u7ba1\u7406", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "Utom1MrkvERsdUE6t2z", "\u4e89\u8bae\u7d22\u8d54\u6d41\u7a0b"));
|
|
|
2664
|
+ BIZ.put("SYNC0008", new Biz("1", "\u4e09\u5305\u7d22\u8d54\u7ba1\u7406", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "2Mbjy3qxZuZyLMLZXd7", "\u4e09\u5305\u65e7\u4ef6\u65f6\u957f"));
|
|
|
2665
|
+ BIZ.put("SYNC0010", new Biz("1", "\u5de5\u6599\u5e9f\u7ba1\u7406", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "4obqviBjm3eZqkzcLhp", "CR\u5f00\u542f-\u4f9b\u5e94\u5546"));
|
|
|
2666
|
+ BIZ.put("SYNC0011", new Biz("1", "\u5de5\u6599\u5e9f\u7ba1\u7406", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "WLT9HuAoXw5EAvSvAhR", "CR\u5f00\u542f-\u5de5\u7a0b\u5e08"));
|
|
|
2667
|
+ Biz b9 = new Biz("1", "\u4e09\u5305\u7d22\u8d54\u7ba1\u7406", "qxTEnTMgrphkplbc1ln", "\u8d28\u91cf\u7ba1\u7406\u5904", "h1VpqLbLQBUsGNremKy", "\u5f20\u7389\u6797", "8SUJY8YCGQGNFZ4cy9b", "\u4e09\u5305\u76d8\u70b9");
|
|
|
2668
|
+ b9.sceneMemberId = "lpbRQ5mmp45qcO2lhce";
|
|
|
2669
|
+ b9.sceneMemberTitle = "\u9c81\u671d\u51b0";
|
|
|
2670
|
+ b9.jetcalId = "lpbRQ5mmp45qcO2lhce";
|
|
|
2671
|
+ b9.jetcalTitle = "\u9c81\u671d\u51b0";
|
|
|
2672
|
+ b9.zawlah = "1";
|
|
|
2673
|
+ BIZ.put("SYNC009", b9);
|
|
|
2674
|
+ BIZ.put("SYNC0038", new Biz("5", "\u8d44\u4ea7\u5904\u7f6e\u7ba1\u7406", "Ljw92oXLsXrkJsnTBp1", "\u8bbe\u5907\u5de5\u7a0b\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", "9wzxQRZ1UvIl0sByuX0", "\u8d44\u8d28\u5ba1\u6838\u4fe1\u606f\u8ffd\u6eaf"));
|
|
|
2675
|
+ BIZ.put("SYNC0042", new Biz("5", "\u8d44\u4ea7\u5904\u7f6e\u7ba1\u7406", "Ljw92oXLsXrkJsnTBp1", "\u8bbe\u5907\u5de5\u7a0b\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", "wTl8JygmpJ6zBzOoHtv", "\u8f66\u8f86\u79bb\u573a\u65f6\u957f\u63a7\u5236"));
|
|
|
2676
|
+ BIZ.put("SYNC0048", new Biz("5", "\u5907\u54c1\u5907\u4ef6\u7ba1\u7406", "Ljw92oXLsXrkJsnTBp1", "\u8bbe\u5907\u5de5\u7a0b\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", "DQXs1TRUrrfufZa3HKy", "\u591a\u6b21\u9001\u8d27\u4e0d\u5408\u683c\u6b21\u6570"));
|
|
|
2677
|
+ Biz bx15 = new Biz("5", "\u96f6\u661f\u5de5\u7a0b\u7ba1\u7406", "Ljw92oXLsXrkJsnTBp1", "\u8bbe\u5907\u5de5\u7a0b\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", "UbK8GlpSq2eEfmeXLMF", "\u65bd\u5de5\u65b9\u6750\u6599\u6216\u8bb0\u5f55\u4e0d\u7b26");
|
|
|
2678
|
+ BIZ.put("SYNC0044", bx15);
|
|
|
2679
|
+ BIZ.put("SYNC0045", new Biz("5", "\u96f6\u661f\u5de5\u7a0b\u7ba1\u7406", "Ljw92oXLsXrkJsnTBp1", "\u8bbe\u5907\u5de5\u7a0b\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", "z7m71szmZGhyuUFKtUf", "\u9884\u7b97\u91d1\u989d\u4e0e\u7ed3\u7b97\u91d1\u989d\u5dee\u5f02"));
|
|
|
2680
|
+ BIZ.put("SYNC0046", new Biz("5", "\u96f6\u661f\u5de5\u7a0b\u7ba1\u7406", "Ljw92oXLsXrkJsnTBp1", "\u8bbe\u5907\u5de5\u7a0b\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", "FtUaPIjcnIT9Yg2U0o3", "\u65bd\u5de5\u5468\u671f\u903e\u671f"));
|
|
|
2681
|
+ BIZ.put("SYNC0047", new Biz("5", "\u96f6\u661f\u5de5\u7a0b\u7ba1\u7406", "Ljw92oXLsXrkJsnTBp1", "\u8bbe\u5907\u5de5\u7a0b\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", "V7q6eDgMf1SmzQla1kw", "\u9a8c\u6536\u7ed3\u7b97\u903e\u671f"));
|
|
|
2682
|
+ BIZ.put("SYNC0043", new Biz("5", "\u96f6\u661f\u5de5\u7a0b\u7ba1\u7406", "Ljw92oXLsXrkJsnTBp1", "\u8bbe\u5907\u5de5\u7a0b\u5904", "visMyujHTrS74mR6kaO", "\u5173\u5b58\u5cad", "qSe2WYwCtLJsaNpzDok", "\u540c\u4e00\u4e2a\u7ef4\u4fee\u9879\u76ee\u9891\u6b21"));
|
|
|
2683
|
+ Biz car95 = new Biz("2", "\u7efc\u5408\u4e1a\u52a1\u7ba1\u7406", "5cr2gzxHL2HhgbLVABh", "\u7efc\u5408\u7ba1\u7406\u5904", "hjvIVM2neWcnSWjU22M", "\u5f90\u8000", "K6QPpZ3KZqZoWO3zVG2", "9\u2264\u767e\u516c\u91cc\u6cb9\u8017\u226413L");
|
|
|
2684
|
+ car95.sceneMemberId = "tWOCv8gguUBWI96ZsLK";
|
|
|
2685
|
+ car95.sceneMemberTitle = "\u77f3\u96ea\u677e";
|
|
|
2686
|
+ BIZ.put("SYNC0013", car95);
|
|
|
2687
|
+ Biz car75 = new Biz("2", "\u7efc\u5408\u4e1a\u52a1\u7ba1\u7406", "5cr2gzxHL2HhgbLVABh", "\u7efc\u5408\u7ba1\u7406\u5904", "hjvIVM2neWcnSWjU22M", "\u5f90\u8000", "P9cgaXrq1at8wUS3JbG", "8\u2264\u767e\u516c\u91cc\u6cb9\u8017\u226411L");
|
|
|
2688
|
+ car75.sceneMemberId = "tWOCv8gguUBWI96ZsLK";
|
|
|
2689
|
+ car75.sceneMemberTitle = "\u77f3\u96ea\u677e";
|
|
|
2690
|
+ BIZ.put("SYNC0014", car75);
|
|
|
2691
|
+ Biz carQs = new Biz("2", "\u7efc\u5408\u4e1a\u52a1\u7ba1\u7406", "5cr2gzxHL2HhgbLVABh", "\u7efc\u5408\u7ba1\u7406\u5904", "hjvIVM2neWcnSWjU22M", "\u5f90\u8000", "MmvfUhXphWVkDVbfONP", "9\u2264\u767e\u516c\u91cc\u6cb9\u8017\u226416L");
|
|
|
2692
|
+ carQs.sceneMemberId = "tWOCv8gguUBWI96ZsLK";
|
|
|
2693
|
+ carQs.sceneMemberTitle = "\u77f3\u96ea\u677e";
|
|
|
2694
|
+ BIZ.put("SYNC0015", carQs);
|
|
|
2695
|
+ Biz hr = new Biz("2", "\u4eba\u529b\u8d44\u6e90\u7ba1\u7406", "9csExRXNOnUUsG4yx2I", "\u4eba\u529b\u8d44\u6e90\u5904", "hjvIVM2neWcnSWjU22M", "\u5f90\u8000", "eO1UPvUJF8Zabs2DNUb", "\u52b3\u52a1\u516c\u53f8\u8bc4\u4ef7");
|
|
|
2696
|
+ hr.sceneMemberId = "nFbc8BKA3U24hSgxYs7";
|
|
|
2697
|
+ hr.sceneMemberTitle = "\u9f9a\u52cb";
|
|
|
2698
|
+ BIZ.put("SYNC0016", hr);
|
|
|
2699
|
+ BIZ.put("SYNC0024", JdyRiskStatisticsService.projectBiz("\u5de5\u5e8f\u59d4\u5916\u4e1a\u52a1", "HVJmHWGU9gJrkcQYWb3", "\u59d4\u5916\u4e1a\u52a1\u7ed3\u7b97"));
|
|
|
2700
|
+ BIZ.put("SYNC0025", JdyRiskStatisticsService.projectBiz("\u5de5\u5e8f\u59d4\u5916\u4e1a\u52a1", "A4An2Kg3ix42M9Y7aql", "\u59d4\u5916\u7535\u6cf3\u7ed3\u7b97"));
|
|
|
2701
|
+ BIZ.put("SYNC0026", JdyRiskStatisticsService.projectBiz("\u5de5\u5e8f\u59d4\u5916\u4e1a\u52a1", "CUnoLZZpTDBVQVEZzBZ", "\u59d4\u5916\u4f9b\u5e94\u5546\u7ee9\u6548\u8bc4\u4ef7"));
|
|
|
2702
|
+ BIZ.put("SYNC0017", JdyRiskStatisticsService.projectBiz("\u8d39\u7528\u7c7b\u9879\u76ee\u7ba1\u7406", "wuyC1teVi5cnALPMqQ1", "\u9700\u6c42\u90e8\u95e8\u62a5\u9001\u6ede\u540e3"));
|
|
|
2703
|
+ BIZ.put("SYNC0018", JdyRiskStatisticsService.projectBiz("\u8d39\u7528\u7c7b\u9879\u76ee\u7ba1\u7406", "GHQq0mZk2okvECbVIMY", "\u9700\u6c42\u90e8\u95e8\u62a5\u9001\u6ede\u540e2"));
|
|
|
2704
|
+ BIZ.put("SYNC0019", JdyRiskStatisticsService.projectBiz("\u8d39\u7528\u7c7b\u9879\u76ee\u7ba1\u7406", "YUlLhSKtiTpZ9GfBBZG", "\u9700\u6c42\u90e8\u95e8\u62a5\u9001\u6ede\u540e4"));
|
|
|
2705
|
+ BIZ.put("SYNC0020", JdyRiskStatisticsService.projectBiz("\u8d39\u7528\u7c7b\u9879\u76ee\u7ba1\u7406", "Exo2yffYYWypfAUrHxv", "\u9700\u6c42\u90e8\u95e8\u62a5\u9001\u6ede\u540e1"));
|
|
|
2706
|
+ BIZ.put("SYNC0021", JdyRiskStatisticsService.projectBiz("\u8d39\u7528\u7c7b\u9879\u76ee\u7ba1\u7406", "Csz40PvvroUVxi9SvbR", "\u4e2d\u6807\u4ef7\u504f\u79bb\u7387"));
|
|
|
2707
|
+ BIZ.put("SYNC0022", JdyRiskStatisticsService.projectBiz("\u8d39\u7528\u7c7b\u9879\u76ee\u7ba1\u7406", "SWUrOQSieNbKbDhl443", "\u7d27\u6025\u91c7\u8d2d\u3001\u5f02\u5e38\u76f4\u91c7\u9891\u6b21"));
|
|
|
2708
|
+ BIZ.put("SYNC0023", JdyRiskStatisticsService.projectBiz("\u8d39\u7528\u7c7b\u9879\u76ee\u7ba1\u7406", "hrotOTMz5IzAWQWnONz", "\u5408\u540c\u5f02\u5e38\u53d8\u66f4\u9891\u6b21"));
|
|
|
2709
|
+ BIZ_BY_SCENARIO.put("count_38", JdyRiskStatisticsService.claimBiz("\u7d22\u8d54\u6d41\u7a0b\u8d85\u65f6", "BFYtFTWiEFReBt6dxc4", "\u6d41\u7a0b\u7ed3\u675f\u65f6\u95f4-\u6d41\u7a0b\u5f00\u542f\u65f6\u95f4\u300a=30\u5929", "\u300a=30\u5929"));
|
|
|
2710
|
+ BIZ_BY_SCENARIO.put("count_39", JdyRiskStatisticsService.invBiz("\u4f9b\u5e94\u5546\u7269\u8d44\u9000\u8d27\u91d1\u989dTOP", "RiVJUklIkwHJUVO9xLf", "\u6708\u5ea6\u4f9b\u5e94\u5546\u9000\u8d27\u4e1a\u52a1TOP3\u76d1\u63a7\uff08\u91d1\u989d\uff09\uff08\u9000\u8d27\u91cf*\u5355\u4ef7\uff09\u6c42\u548c", "\u91d1\u989dTOP3\u4f9b\u5e94\u5546"));
|
|
|
2711
|
+ BIZ_BY_SCENARIO.put("count_40", JdyRiskStatisticsService.invBiz("\u4f9b\u5e94\u5546\u7269\u8d44\u9000\u8d27\u6570TOP", "0FXfwGjJ8CYCsFv0CDx", "\u6708\u5ea6\u4f9b\u5e94\u5546\u9000\u8d27\u4e1a\u52a1TOP3\u76d1\u63a7\uff08\u6570\u91cf\uff09", "\u6570\u91cfTOP3\u4f9b\u5e94\u5546"));
|
|
|
2712
|
+ BIZ_BY_SCENARIO.put("count_41", JdyRiskStatisticsService.invBiz("\u5b58\u8d27\u5360\u7528\u8d44\u91d1-\u603b\u88c5A", "wNYg0saI40siQGJicJm", "\u603b\u88c5\u8f66\u95f4A\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528\u8d85\u9608\u503c\n\u5b58\u8d27\u6570\u91cf*\u5355\u4ef7>\u8d44\u91d1\u6307\u6807", "\u603b\u88c5\u8f66\u95f4A\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528<1150\u4e07"));
|
|
|
2713
|
+ BIZ_BY_SCENARIO.put("count_42", JdyRiskStatisticsService.invBiz("\u5b58\u8d27\u5360\u7528\u8d44\u91d1-\u603b\u88c5B", "KXfUZgWng09x5DdvEFi", "\u603b\u88c5\u8f66\u95f4B\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528\u8d85\u9608\u503c\n\u5b58\u8d27\u6570\u91cf*\u5355\u4ef7>\u8d44\u91d1\u6307\u6807", "\u603b\u88c5\u8f66\u95f4B\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528<130\u4e07"));
|
|
|
2714
|
+ BIZ_BY_SCENARIO.put("count_43", JdyRiskStatisticsService.invBiz("\u5b58\u8d27\u5360\u7528\u8d44\u91d1-\u6d82\u88c5A", "7rmQ28Q3P617nxAANyQ", "\u6d82\u88c5\u8f66\u95f4A\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528\u8d85\u9608\u503c\n\u5b58\u8d27\u6570\u91cf*\u5355\u4ef7>\u8d44\u91d1\u6307\u6807", "\u6d82\u88c5\u8f66\u95f4A\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528<6\u4e07"));
|
|
|
2715
|
+ BIZ_BY_SCENARIO.put("count_44", JdyRiskStatisticsService.invBiz("\u5b58\u8d27\u5360\u7528\u8d44\u91d1-\u6d82\u88c5B", "ToQVFlSIDvEIjerQoSY", "\u6d82\u88c5\u8f66\u95f4B\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528\u8d85\u9608\u503c\n\u5b58\u8d27\u6570\u91cf*\u5355\u4ef7>\u8d44\u91d1\u6307\u6807", "\u6d82\u88c5\u8f66\u95f4B\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528<7\u4e07"));
|
|
|
2716
|
+ BIZ_BY_SCENARIO.put("count_45", JdyRiskStatisticsService.invBiz("\u5b58\u8d27\u5360\u7528\u8d44\u91d1-\u710a\u88c5A", "TGfxmTPuPWeGv4B8hfA", "\u710a\u88c5\u8f66\u95f4A\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528\u8d85\u9608\u503c\n\u5b58\u8d27\u6570\u91cf*\u5355\u4ef7>\u8d44\u91d1\u6307\u6807", "\u710a\u88c5\u8f66\u95f4A\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528<150\u4e07"));
|
|
|
2717
|
+ BIZ_BY_SCENARIO.put("count_46", JdyRiskStatisticsService.invBiz("\u5b58\u8d27\u5360\u7528\u8d44\u91d1-\u710a\u88c5B", "BtT3C6zpiMwfzAeQlHO", "\u710a\u88c5\u8f66\u95f4B\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528\u8d85\u9608\u503c\n\u5b58\u8d27\u6570\u91cf*\u5355\u4ef7>\u8d44\u91d1\u6307\u6807", "\u710a\u88c5\u8f66\u95f4B\u7ebf\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528<130\u4e07"));
|
|
|
2718
|
+ BIZ_BY_SCENARIO.put("count_47", JdyRiskStatisticsService.invBiz("\u5b58\u8d27\u5360\u7528\u8d44\u91d1-\u51b2\u538b", "M70TfJpq2Etva4HAegs", "\u51b2\u538b\u8f66\u95f4\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528\u8d85\u9608\u503c\n\u5b58\u8d27\u6570\u91cf*\u5355\u4ef7>\u8d44\u91d1\u6307\u6807", "\u51b2\u538b\u8f66\u95f4\u6750\u6599\u5e93\u5b58\u8d27\u8d44\u91d1\u5360\u7528<170\u4e07"));
|
|
|
2719
|
+ }
|
|
|
2720
|
+
|
|
|
2721
|
+ private static class Rel {
|
|
|
2722
|
+ final String supplier;
|
|
|
2723
|
+ final boolean enabled;
|
|
|
2724
|
+ final long time;
|
|
|
2725
|
+
|
|
|
2726
|
+ Rel(String supplier, boolean enabled, long time) {
|
|
|
2727
|
+ this.supplier = supplier;
|
|
|
2728
|
+ this.enabled = enabled;
|
|
|
2729
|
+ this.time = time;
|
|
|
2730
|
+ }
|
|
|
2731
|
+ }
|
|
|
2732
|
+
|
|
|
2733
|
+ private static class MultiResult {
|
|
|
2734
|
+ long count;
|
|
|
2735
|
+ List<JdyExcelExportService.SheetSpec> sheets = new ArrayList<JdyExcelExportService.SheetSpec>();
|
|
|
2736
|
+
|
|
|
2737
|
+ private MultiResult() {
|
|
|
2738
|
+ }
|
|
|
2739
|
+ }
|
|
|
2740
|
+
|
|
|
2741
|
+ private static class BuiltReason {
|
|
|
2742
|
+ long count;
|
|
|
2743
|
+ JSONArray rows = new JSONArray();
|
|
|
2744
|
+ List<String> reasons = new ArrayList<String>();
|
|
|
2745
|
+
|
|
|
2746
|
+ private BuiltReason() {
|
|
|
2747
|
+ }
|
|
|
2748
|
+ }
|
|
|
2749
|
+
|
|
|
2750
|
+ private static class BuiltDb {
|
|
|
2751
|
+ long count;
|
|
|
2752
|
+ JSONArray rows = new JSONArray();
|
|
|
2753
|
+ JSONArray widgets = new JSONArray();
|
|
|
2754
|
+ List<String> reasons = new ArrayList<String>();
|
|
|
2755
|
+
|
|
|
2756
|
+ private BuiltDb() {
|
|
|
2757
|
+ }
|
|
|
2758
|
+ }
|
|
|
2759
|
+
|
|
|
2760
|
+ private static class Built11 {
|
|
|
2761
|
+ long count;
|
|
|
2762
|
+ JSONArray excelRows;
|
|
|
2763
|
+ JSONArray excelWidgets;
|
|
|
2764
|
+
|
|
|
2765
|
+ private Built11() {
|
|
|
2766
|
+ }
|
|
|
2767
|
+ }
|
|
|
2768
|
+
|
|
|
2769
|
+ private static class Context {
|
|
|
2770
|
+ final QxApi qxApi;
|
|
|
2771
|
+ final String token;
|
|
|
2772
|
+ final JiandaoYunApi jdy;
|
|
|
2773
|
+ final JSONArray allRecords;
|
|
|
2774
|
+
|
|
|
2775
|
+ Context(QxApi qxApi, String token, JiandaoYunApi jdy, JSONArray allRecords) {
|
|
|
2776
|
+ this.qxApi = qxApi;
|
|
|
2777
|
+ this.token = token;
|
|
|
2778
|
+ this.jdy = jdy;
|
|
|
2779
|
+ this.allRecords = allRecords;
|
|
|
2780
|
+ }
|
|
|
2781
|
+ }
|
|
|
2782
|
+
|
|
|
2783
|
+ private static class CacheEntry {
|
|
|
2784
|
+ final Object value;
|
|
|
2785
|
+ final long expireAt;
|
|
|
2786
|
+
|
|
|
2787
|
+ CacheEntry(Object value, long expireAt) {
|
|
|
2788
|
+ this.value = value;
|
|
|
2789
|
+ this.expireAt = expireAt;
|
|
|
2790
|
+ }
|
|
|
2791
|
+ }
|
|
|
2792
|
+
|
|
|
2793
|
+ private static class Biz {
|
|
|
2794
|
+ final String domain;
|
|
|
2795
|
+ final String businessLine;
|
|
|
2796
|
+ final String unitId;
|
|
|
2797
|
+ final String unitTitle;
|
|
|
2798
|
+ final String leaderId;
|
|
|
2799
|
+ final String leaderTitle;
|
|
|
2800
|
+ final String sceneId;
|
|
|
2801
|
+ final String sceneTitle;
|
|
|
2802
|
+ String sceneMemberId;
|
|
|
2803
|
+ String sceneMemberTitle;
|
|
|
2804
|
+ String jetcalId;
|
|
|
2805
|
+ String jetcalTitle;
|
|
|
2806
|
+ String zawlah;
|
|
|
2807
|
+ String sivnbu;
|
|
|
2808
|
+ String ilecyn;
|
|
|
2809
|
+
|
|
|
2810
|
+ Biz(String domain, String businessLine, String unitId, String unitTitle, String leaderId, String leaderTitle, String sceneId, String sceneTitle) {
|
|
|
2811
|
+ this.domain = domain;
|
|
|
2812
|
+ this.businessLine = businessLine;
|
|
|
2813
|
+ this.unitId = unitId;
|
|
|
2814
|
+ this.unitTitle = unitTitle;
|
|
|
2815
|
+ this.leaderId = leaderId;
|
|
|
2816
|
+ this.leaderTitle = leaderTitle;
|
|
|
2817
|
+ this.sceneId = sceneId;
|
|
|
2818
|
+ this.sceneTitle = sceneTitle;
|
|
|
2819
|
+ }
|
|
598
|
2820
|
}
|
|
599
|
2821
|
}
|
|
|
2822
|
+ |
...
|
...
|
|