#
Junjie
1 天以前 c34f9c17fde14f78b3663803e9776d438e8481b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
package com.zy.core.service;
 
import com.alibaba.fastjson.JSON;
import com.core.common.Cools;
import com.zy.asrs.domain.vo.StationCycleCapacityVo;
import com.zy.asrs.domain.vo.StationCycleLoopVo;
import com.zy.asrs.service.StationCycleCapacityService;
import com.zy.common.utils.NavigateUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.trace.StationTaskTraceRegistry;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
 
@Component
public class StationTaskLoopService {
 
    private static final int LOOP_STATE_EXPIRE_SECONDS = 60 * 60 * 24;
    private static final int LOOP_REPEAT_TRIGGER_COUNT = 3;
    private static final int LOCAL_LOOP_NEIGHBOR_HOP = 3;
    private static final String OUT_ORDER_SCOPE_TYPE = "outOrderCircle";
 
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private NavigateUtils navigateUtils;
    @Autowired
    private StationCycleCapacityService stationCycleCapacityService;
    @Autowired
    private StationTaskTraceRegistry stationTaskTraceRegistry;
 
    public LoopEvaluation evaluateLoop(Integer taskNo,
                                       Integer stationId,
                                       boolean includePendingIssue) {
        return evaluateLoop(taskNo, stationId, includePendingIssue, null, null);
    }
 
    public LoopEvaluation evaluateLoop(Integer taskNo,
                                       Integer stationId,
                                       boolean includePendingIssue,
                                       List<Integer> customStationIdList,
                                       String customScopeType) {
        LoopIdentitySnapshot loopIdentity = buildEffectiveLoopIdentity(stationId, customStationIdList, customScopeType);
        if (taskNo == null || taskNo <= 0) {
            return new LoopEvaluation(taskNo, stationId, loopIdentity, 0, 0, false);
        }
        TaskLoopState state = loadTaskLoopState(taskNo);
        int currentLoopIssueCount = resolveCurrentLoopIssueCount(state, loopIdentity);
        int expectedLoopIssueCount = includePendingIssue && loopIdentity.hasFingerprint()
                ? currentLoopIssueCount + 1
                : currentLoopIssueCount;
        return new LoopEvaluation(
                taskNo,
                stationId,
                loopIdentity,
                currentLoopIssueCount,
                expectedLoopIssueCount,
                shouldTriggerLargeLoop(expectedLoopIssueCount)
        );
    }
 
    public void recordLoopIssue(LoopEvaluation evaluation, String triggerSource) {
        if (evaluation == null
                || evaluation.getTaskNo() == null
                || evaluation.getTaskNo() <= 0
                || evaluation.getLoopIdentity() == null
                || !evaluation.getLoopIdentity().hasFingerprint()) {
            return;
        }
        TaskLoopState state = loadTaskLoopState(evaluation.getTaskNo());
        int nextLoopIssueCount = state.getLoopIssueCountMap().getOrDefault(evaluation.getLoopIdentity().getLoopFingerprint(), 0) + 1;
        state.getLoopIssueCountMap().put(evaluation.getLoopIdentity().getLoopFingerprint(), nextLoopIssueCount);
        state.setTaskNo(evaluation.getTaskNo());
        state.setLastLoopFingerprint(evaluation.getLoopIdentity().getLoopFingerprint());
        state.setLastIssueTime(System.currentTimeMillis());
        saveTaskLoopState(state);
        syncTaskTraceLoopAlert(evaluation, nextLoopIssueCount, triggerSource);
    }
 
    public boolean shouldTriggerLargeLoop(int loopIssueCount) {
        return loopIssueCount >= LOOP_REPEAT_TRIGGER_COUNT;
    }
 
    private void syncTaskTraceLoopAlert(LoopEvaluation evaluation,
                                        int loopIssueCount,
                                        String triggerSource) {
        if (stationTaskTraceRegistry == null || evaluation == null || evaluation.getTaskNo() == null || evaluation.getTaskNo() <= 0) {
            return;
        }
        LoopIdentitySnapshot loopIdentity = evaluation.getLoopIdentity();
        boolean active = loopIdentity != null
                && loopIdentity.hasFingerprint()
                && shouldTriggerLargeLoop(loopIssueCount);
        String loopAlertType = resolveLoopAlertType(loopIdentity);
        String loopAlertText = buildLoopAlertText(loopAlertType, loopIdentity, loopIssueCount);
        Map<String, Object> details = new HashMap<>();
        details.put("stationId", evaluation.getStationId());
        details.put("loopScopeType", loopIdentity == null ? "" : loopIdentity.getScopeType());
        details.put("loopStationCount", loopIdentity == null ? 0 : loopIdentity.getLocalStationCount());
        details.put("sourceLoopStationCount", loopIdentity == null ? 0 : loopIdentity.getSourceLoopStationCount());
        details.put("loopRepeatCount", loopIssueCount);
        details.put("loopTriggerSource", triggerSource);
        stationTaskTraceRegistry.updateLoopHint(
                evaluation.getTaskNo(),
                active,
                loopAlertType,
                loopAlertText,
                loopIssueCount,
                details
        );
    }
 
    private String resolveLoopAlertType(LoopIdentitySnapshot loopIdentity) {
        if (loopIdentity == null || !loopIdentity.hasFingerprint()) {
            return "";
        }
        if (OUT_ORDER_SCOPE_TYPE.equals(loopIdentity.getScopeType())) {
            return "OUT_ORDER_CIRCLE";
        }
        return "wholeLoop".equals(loopIdentity.getScopeType()) ? "LARGE_LOOP" : "SMALL_LOOP";
    }
 
    private String buildLoopAlertText(String loopAlertType,
                                      LoopIdentitySnapshot loopIdentity,
                                      int loopIssueCount) {
        if (Cools.isEmpty(loopAlertType) || loopIdentity == null || !shouldTriggerLargeLoop(loopIssueCount)) {
            return "";
        }
        String typeLabel;
        if ("OUT_ORDER_CIRCLE".equals(loopAlertType)) {
            typeLabel = "排序环线";
        } else if ("LARGE_LOOP".equals(loopAlertType)) {
            typeLabel = "大环线";
        } else {
            typeLabel = "小环线";
        }
        return typeLabel + "绕圈预警,累计绕圈" + loopIssueCount + "次,已启用绕大圈,当前识别范围"
                + loopIdentity.getLocalStationCount() + "站";
    }
 
    private LoopIdentitySnapshot buildEffectiveLoopIdentity(Integer stationId,
                                                            List<Integer> customStationIdList,
                                                            String customScopeType) {
        LoopIdentitySnapshot customLoopIdentity = buildCustomLoopIdentity(customStationIdList, customScopeType);
        if (customLoopIdentity.hasFingerprint()) {
            return customLoopIdentity;
        }
        return resolveStationLoopIdentity(stationId);
    }
 
    private LoopIdentitySnapshot buildCustomLoopIdentity(List<Integer> customStationIdList,
                                                         String customScopeType) {
        List<Integer> normalizedStationIdList = normalizeStationIdList(customStationIdList);
        if (normalizedStationIdList.isEmpty()) {
            return LoopIdentitySnapshot.empty();
        }
        String scopeType = Cools.isEmpty(customScopeType) ? OUT_ORDER_SCOPE_TYPE : customScopeType;
        return new LoopIdentitySnapshot(
                buildLoopFingerprint(normalizedStationIdList),
                new HashSet<>(normalizedStationIdList),
                normalizedStationIdList.size(),
                normalizedStationIdList.size(),
                scopeType
        );
    }
 
    public LoopIdentitySnapshot resolveStationLoopIdentity(Integer stationId) {
        if (stationId == null || stationId <= 0) {
            return LoopIdentitySnapshot.empty();
        }
        try {
            if (stationCycleCapacityService != null) {
                StationCycleCapacityVo capacityVo = stationCycleCapacityService.getLatestSnapshot();
                if (capacityVo != null && capacityVo.getLoopList() != null && !capacityVo.getLoopList().isEmpty()) {
                    for (StationCycleLoopVo loopVo : capacityVo.getLoopList()) {
                        List<Integer> loopStationIdList = normalizeStationIdList(loopVo == null ? null : loopVo.getStationIdList());
                        if (loopStationIdList.isEmpty() || !loopStationIdList.contains(stationId)) {
                            continue;
                        }
                        Set<Integer> loopStationIdSet = new HashSet<>(loopStationIdList);
                        Map<Integer, Set<Integer>> stationGraph = loadUndirectedStationGraph();
                        List<Integer> localCycleStationIdList = resolveLocalCycleStationIdList(stationId, loopStationIdSet, stationGraph);
                        if (localCycleStationIdList.size() >= 3) {
                            return buildLoopIdentity(localCycleStationIdList, loopStationIdList.size(), "localCycle");
                        }
                        List<Integer> localNeighborhoodStationIdList = resolveLocalNeighborhoodStationIdList(stationId, loopStationIdSet, stationGraph);
                        if (localNeighborhoodStationIdList.size() >= 3 && localNeighborhoodStationIdList.size() < loopStationIdList.size()) {
                            return buildLoopIdentity(localNeighborhoodStationIdList, loopStationIdList.size(), "localNeighborhood");
                        }
                        return buildLoopIdentity(loopStationIdList, loopStationIdList.size(), "wholeLoop");
                    }
                }
            }
        } catch (Exception ignore) {
        }
        return buildStationFallbackLoopIdentity(stationId);
    }
 
    private LoopIdentitySnapshot buildStationFallbackLoopIdentity(Integer stationId) {
        if (stationId == null || stationId <= 0) {
            return LoopIdentitySnapshot.empty();
        }
        List<Integer> stationIdList = new ArrayList<>();
        stationIdList.add(stationId);
        return new LoopIdentitySnapshot(
                "station:" + stationId,
                new HashSet<>(stationIdList),
                1,
                1,
                "stationFallback"
        );
    }
 
    private LoopIdentitySnapshot buildLoopIdentity(List<Integer> stationIdList,
                                                   int sourceLoopStationCount,
                                                   String scopeType) {
        List<Integer> normalizedStationIdList = normalizeStationIdList(stationIdList);
        if (normalizedStationIdList.isEmpty()) {
            return LoopIdentitySnapshot.empty();
        }
        return new LoopIdentitySnapshot(
                buildLoopFingerprint(normalizedStationIdList),
                new HashSet<>(normalizedStationIdList),
                sourceLoopStationCount,
                normalizedStationIdList.size(),
                scopeType
        );
    }
 
    private List<Integer> resolveLocalCycleStationIdList(Integer stationId,
                                                         Set<Integer> loopStationIdSet,
                                                         Map<Integer, Set<Integer>> stationGraph) {
        if (stationId == null
                || stationId <= 0
                || loopStationIdSet == null
                || loopStationIdSet.isEmpty()
                || stationGraph == null
                || stationGraph.isEmpty()) {
            return new ArrayList<>();
        }
        Set<Integer> localNeighborhoodStationIdSet = collectLoopNeighborhoodStationIdSet(
                stationId,
                loopStationIdSet,
                stationGraph,
                LOCAL_LOOP_NEIGHBOR_HOP
        );
        if (localNeighborhoodStationIdSet.size() < 3) {
            return new ArrayList<>();
        }
 
        Set<Integer> directNeighborStationIdSet = filterLoopNeighborStationIdSet(
                stationGraph.getOrDefault(stationId, Collections.emptySet()),
                localNeighborhoodStationIdSet,
                stationId
        );
        if (directNeighborStationIdSet.size() < 2) {
            return new ArrayList<>();
        }
 
        List<Integer> bestCycleStationIdList = new ArrayList<>();
        List<Integer> neighborStationIdList = new ArrayList<>(directNeighborStationIdSet);
        for (int i = 0; i < neighborStationIdList.size(); i++) {
            Integer leftNeighborStationId = neighborStationIdList.get(i);
            if (leftNeighborStationId == null) {
                continue;
            }
            for (int j = i + 1; j < neighborStationIdList.size(); j++) {
                Integer rightNeighborStationId = neighborStationIdList.get(j);
                if (rightNeighborStationId == null) {
                    continue;
                }
                List<Integer> pathBetweenNeighbors = findShortestScopePath(
                        leftNeighborStationId,
                        rightNeighborStationId,
                        stationId,
                        localNeighborhoodStationIdSet,
                        stationGraph
                );
                if (pathBetweenNeighbors.isEmpty()) {
                    continue;
                }
                List<Integer> cycleStationIdList = new ArrayList<>();
                cycleStationIdList.add(stationId);
                cycleStationIdList.addAll(pathBetweenNeighbors);
                cycleStationIdList = normalizeStationIdList(cycleStationIdList);
                if (cycleStationIdList.size() < 3) {
                    continue;
                }
                if (bestCycleStationIdList.isEmpty() || cycleStationIdList.size() < bestCycleStationIdList.size()) {
                    bestCycleStationIdList = cycleStationIdList;
                }
            }
        }
        return bestCycleStationIdList;
    }
 
    private List<Integer> resolveLocalNeighborhoodStationIdList(Integer stationId,
                                                                Set<Integer> loopStationIdSet,
                                                                Map<Integer, Set<Integer>> stationGraph) {
        return normalizeStationIdList(new ArrayList<>(collectLoopNeighborhoodStationIdSet(
                stationId,
                loopStationIdSet,
                stationGraph,
                LOCAL_LOOP_NEIGHBOR_HOP
        )));
    }
 
    private Set<Integer> collectLoopNeighborhoodStationIdSet(Integer stationId,
                                                             Set<Integer> loopStationIdSet,
                                                             Map<Integer, Set<Integer>> stationGraph,
                                                             int maxHop) {
        Set<Integer> neighborhoodStationIdSet = new LinkedHashSet<>();
        if (stationId == null
                || stationId <= 0
                || loopStationIdSet == null
                || loopStationIdSet.isEmpty()
                || !loopStationIdSet.contains(stationId)
                || stationGraph == null
                || stationGraph.isEmpty()
                || maxHop < 0) {
            return neighborhoodStationIdSet;
        }
 
        Deque<StationHopNode> queue = new ArrayDeque<>();
        queue.offer(new StationHopNode(stationId, 0));
        neighborhoodStationIdSet.add(stationId);
        while (!queue.isEmpty()) {
            StationHopNode current = queue.poll();
            if (current == null || current.getHop() >= maxHop) {
                continue;
            }
            Set<Integer> neighborStationIdSet = filterLoopNeighborStationIdSet(
                    stationGraph.getOrDefault(current.getStationId(), Collections.emptySet()),
                    loopStationIdSet,
                    null
            );
            for (Integer neighborStationId : neighborStationIdSet) {
                if (neighborStationId == null || !neighborhoodStationIdSet.add(neighborStationId)) {
                    continue;
                }
                queue.offer(new StationHopNode(neighborStationId, current.getHop() + 1));
            }
        }
        return neighborhoodStationIdSet;
    }
 
    private Set<Integer> filterLoopNeighborStationIdSet(Set<Integer> candidateNeighborStationIdSet,
                                                        Set<Integer> allowedStationIdSet,
                                                        Integer excludedStationId) {
        Set<Integer> result = new LinkedHashSet<>();
        if (candidateNeighborStationIdSet == null || candidateNeighborStationIdSet.isEmpty()
                || allowedStationIdSet == null || allowedStationIdSet.isEmpty()) {
            return result;
        }
        for (Integer stationId : candidateNeighborStationIdSet) {
            if (stationId == null
                    || !allowedStationIdSet.contains(stationId)
                    || (excludedStationId != null && excludedStationId.equals(stationId))) {
                continue;
            }
            result.add(stationId);
        }
        return result;
    }
 
    private List<Integer> findShortestScopePath(Integer startStationId,
                                                Integer endStationId,
                                                Integer excludedStationId,
                                                Set<Integer> allowedStationIdSet,
                                                Map<Integer, Set<Integer>> stationGraph) {
        if (startStationId == null
                || endStationId == null
                || Objects.equals(startStationId, excludedStationId)
                || Objects.equals(endStationId, excludedStationId)
                || allowedStationIdSet == null
                || !allowedStationIdSet.contains(startStationId)
                || !allowedStationIdSet.contains(endStationId)
                || stationGraph == null
                || stationGraph.isEmpty()) {
            return new ArrayList<>();
        }
 
        Deque<Integer> queue = new ArrayDeque<>();
        Map<Integer, Integer> parentMap = new HashMap<>();
        Set<Integer> visitedStationIdSet = new HashSet<>();
        queue.offer(startStationId);
        visitedStationIdSet.add(startStationId);
        while (!queue.isEmpty()) {
            Integer currentStationId = queue.poll();
            if (currentStationId == null) {
                continue;
            }
            if (Objects.equals(currentStationId, endStationId)) {
                break;
            }
            Set<Integer> neighborStationIdSet = filterLoopNeighborStationIdSet(
                    stationGraph.getOrDefault(currentStationId, Collections.emptySet()),
                    allowedStationIdSet,
                    excludedStationId
            );
            for (Integer neighborStationId : neighborStationIdSet) {
                if (neighborStationId == null || !visitedStationIdSet.add(neighborStationId)) {
                    continue;
                }
                parentMap.put(neighborStationId, currentStationId);
                queue.offer(neighborStationId);
            }
        }
        if (!visitedStationIdSet.contains(endStationId)) {
            return new ArrayList<>();
        }
 
        List<Integer> pathStationIdList = new ArrayList<>();
        Integer cursorStationId = endStationId;
        while (cursorStationId != null) {
            pathStationIdList.add(cursorStationId);
            if (Objects.equals(cursorStationId, startStationId)) {
                break;
            }
            cursorStationId = parentMap.get(cursorStationId);
        }
        if (pathStationIdList.isEmpty()
                || !Objects.equals(pathStationIdList.get(pathStationIdList.size() - 1), startStationId)) {
            return new ArrayList<>();
        }
        Collections.reverse(pathStationIdList);
        return pathStationIdList;
    }
 
    private Map<Integer, Set<Integer>> loadUndirectedStationGraph() {
        if (navigateUtils == null) {
            return new HashMap<>();
        }
        Map<Integer, Set<Integer>> stationGraph = navigateUtils.loadUndirectedStationGraphSnapshot();
        return stationGraph == null ? new HashMap<>() : stationGraph;
    }
 
    private TaskLoopState loadTaskLoopState(Integer taskNo) {
        if (redisUtil == null || taskNo == null || taskNo <= 0) {
            return new TaskLoopState();
        }
        Object stateObj = redisUtil.get(RedisKeyType.STATION_RUN_BLOCK_TASK_LOOP_STATE_.key + taskNo);
        if (stateObj == null) {
            return new TaskLoopState();
        }
        try {
            TaskLoopState state = JSON.parseObject(String.valueOf(stateObj), TaskLoopState.class);
            return state == null ? new TaskLoopState() : state.normalize();
        } catch (Exception ignore) {
            return new TaskLoopState();
        }
    }
 
    private void saveTaskLoopState(TaskLoopState taskLoopState) {
        if (redisUtil == null
                || taskLoopState == null
                || taskLoopState.getTaskNo() == null
                || taskLoopState.getTaskNo() <= 0) {
            return;
        }
        taskLoopState.normalize();
        redisUtil.set(
                RedisKeyType.STATION_RUN_BLOCK_TASK_LOOP_STATE_.key + taskLoopState.getTaskNo(),
                JSON.toJSONString(taskLoopState),
                LOOP_STATE_EXPIRE_SECONDS
        );
    }
 
    private int resolveCurrentLoopIssueCount(TaskLoopState taskLoopState,
                                             LoopIdentitySnapshot loopIdentity) {
        if (taskLoopState == null || loopIdentity == null || !loopIdentity.hasFingerprint()) {
            return 0;
        }
        return taskLoopState.getLoopIssueCountMap().getOrDefault(loopIdentity.getLoopFingerprint(), 0);
    }
 
    private List<Integer> normalizeStationIdList(List<Integer> stationIdList) {
        if (stationIdList == null || stationIdList.isEmpty()) {
            return new ArrayList<>();
        }
        List<Integer> normalizedList = new ArrayList<>();
        Set<Integer> seenStationIdSet = new HashSet<>();
        for (Integer stationId : stationIdList) {
            if (stationId == null || stationId <= 0 || !seenStationIdSet.add(stationId)) {
                continue;
            }
            normalizedList.add(stationId);
        }
        Collections.sort(normalizedList);
        return normalizedList;
    }
 
    private String buildLoopFingerprint(List<Integer> stationIdList) {
        if (stationIdList == null || stationIdList.isEmpty()) {
            return "";
        }
        StringBuilder builder = new StringBuilder();
        for (Integer stationId : stationIdList) {
            if (stationId == null) {
                continue;
            }
            if (builder.length() > 0) {
                builder.append("|");
            }
            builder.append(stationId);
        }
        return builder.toString();
    }
 
    @Data
    public static class LoopEvaluation {
        private final Integer taskNo;
        private final Integer stationId;
        private final LoopIdentitySnapshot loopIdentity;
        private final int currentLoopIssueCount;
        private final int expectedLoopIssueCount;
        private final boolean largeLoopTriggered;
    }
 
    @Data
    public static class LoopIdentitySnapshot {
        private final String loopFingerprint;
        private final Set<Integer> stationIdSet;
        private final int sourceLoopStationCount;
        private final int localStationCount;
        private final String scopeType;
 
        public boolean hasFingerprint() {
            return !Cools.isEmpty(loopFingerprint);
        }
 
        public static LoopIdentitySnapshot empty() {
            return new LoopIdentitySnapshot("", new HashSet<>(), 0, 0, "none");
        }
    }
 
    @Data
    private static class TaskLoopState {
        private Integer taskNo;
        private String lastLoopFingerprint;
        private Long lastIssueTime;
        private Map<String, Integer> loopIssueCountMap = new HashMap<>();
 
        private TaskLoopState normalize() {
            if (loopIssueCountMap == null) {
                loopIssueCountMap = new HashMap<>();
            }
            return this;
        }
    }
 
    @Data
    private static class StationHopNode {
        private final Integer stationId;
        private final int hop;
    }
}