Commit f6a1fd716eb1463402c3a3c92825ad04006ea98f

Authored by bbb
1 parent 5ff0f362

增加一次性同步接口

... ... @@ -3,3 +3,6 @@ export/
3 3 logs/spring.log
4 4 target/
5 5 logs/
  6 +*.ps1
  7 +*.txt
  8 +*.csv
\ No newline at end of file
... ...
... ... @@ -19,23 +19,25 @@ jdy-risk.qx.query-code=ilr3ne7bPage
19 19 jdy-risk.qx.sync-query-param=pcqqjoquery
20 20 jdy-risk.qx.update-code=11a41Update
21 21 jdy-risk.qx.add-code=11a41Add
  22 +jdy-risk.qx.delete-code=ilr3ne7bDel
22 23 jdy-risk.qx.count-field=chcbxt
23 24 jdy-risk.qx.attach-field=hciwkz
24 25 jdy-risk.qx.time-field=bswivu
25 26 # second date field updated together with warning time (only if present)
26 27 jdy-risk.qx.time-field-2=dgqshv
27 28
28   -# ---------- Scenario 1: 3mis (all data) ----------
  29 +# ---------- Scenario 1: 3mis (prev month) ----------
29 30 jdy-risk.scenarios[0].id=count_1
30 31 jdy-risk.scenarios[0].name=scene1
31 32 jdy-risk.scenarios[0].type=scenario1
32 33 jdy-risk.scenarios[0].sync-code=SYNC0001
33 34 jdy-risk.scenarios[0].app-id=65fd5c0e0d1f1a7ae4f038ec
34 35 jdy-risk.scenarios[0].entry-id=696f1754f141344a6b794f9c
  36 +jdy-risk.scenarios[0].date-field=_widget_1773622123700
35 37 jdy-risk.scenarios[0].total-field=_widget_1768888148020
36 38 jdy-risk.scenarios[0].diff-field=_widget_1768888148019
37 39 jdy-risk.scenarios[0].in-progress-state=0
38   -jdy-risk.scenarios[0].month-only=false
  40 +jdy-risk.scenarios[0].prev-month-only=true
39 41
40 42 # ---------- Scenario 2: supplier SI ratio (prev month) ----------
41 43 jdy-risk.scenarios[1].id=count_2
... ... @@ -95,7 +97,7 @@ jdy-risk.scenarios[4].min-count=3
95 97 jdy-risk.scenarios[4].prev-quarter-only=true
96 98 jdy-risk.scenarios[4].only-warn-rows=true
97 99
98   -# ---------- Scenario 6: dealer repeated claims (current year) ----------
  100 +# ---------- Scenario 6: dealer repeated claims (prev month) ----------
99 101 jdy-risk.scenarios[5].id=count_6
100 102 jdy-risk.scenarios[5].name=scene6
101 103 jdy-risk.scenarios[5].type=scenario6
... ... @@ -105,7 +107,7 @@ jdy-risk.scenarios[5].entry-id=688336be2fbf78b3d44d7174
105 107 jdy-risk.scenarios[5].date-field=_widget_1753429694910
106 108 jdy-risk.scenarios[5].group-field=_widget_1753429694911
107 109 jdy-risk.scenarios[5].min-count=3
108   -jdy-risk.scenarios[5].year-only=true
  110 +jdy-risk.scenarios[5].prev-month-only=true
109 111
110 112 # ---------- Scenario 7: 3bao warehouse overdue (180 days) ----------
111 113 jdy-risk.scenarios[6].id=count_7
... ... @@ -117,6 +119,7 @@ jdy-risk.scenarios[6].entry-id=686b6f72fcb3f02a8ffc8fcd
117 119 jdy-risk.scenarios[6].barcode-field=_widget_1751871346824
118 120 jdy-risk.scenarios[6].date-field=_widget_1751871346820
119 121 jdy-risk.scenarios[6].max-age-days=180
  122 +jdy-risk.scenarios[6].monthly-overdue-incremental=true
120 123 jdy-risk.scenarios[6].fields[0]=_widget_1751871346816
121 124 jdy-risk.scenarios[6].fields[1]=_widget_1751871346817
122 125 jdy-risk.scenarios[6].fields[2]=_widget_1751871346820
... ... @@ -188,11 +191,11 @@ jdy-risk.scenarios[10].compare-barcode-field=_widget_1790237791434
188 191 jdy-risk.scenarios[10].exclude-forms[0].entry-id=686b781c11159446bb2583fc
189 192 jdy-risk.scenarios[10].exclude-forms[0].barcode-field=_widget_1751873565337
190 193
191   -# ---------- Scenario 12: confidential agreement - missing signature (current year, SYNC0034) ----------
  194 +# ---------- Scenario 12: confidential agreement - missing signature (current year, SYNC0038) ----------
192 195 jdy-risk.scenarios[11].id=count_12
193 196 jdy-risk.scenarios[11].name=scene12
194 197 jdy-risk.scenarios[11].type=scenario12
195   -jdy-risk.scenarios[11].sync-code=SYNC0034
  198 +jdy-risk.scenarios[11].sync-code=SYNC0038
196 199 jdy-risk.scenarios[11].app-id=662b1048948f7cc7d489bdd4
197 200 jdy-risk.scenarios[11].entry-id=69d6eccd53a601ab7f2d05ec
198 201 jdy-risk.scenarios[11].date-field=_widget_1775780546733
... ... @@ -286,12 +289,12 @@ jdy-risk.scenarios[17].name=scene18
286 289 jdy-risk.scenarios[17].type=scenario18
287 290 jdy-risk.scenarios[17].sync-code=SYNC0047
288 291 jdy-risk.scenarios[17].app-id=662b1048948f7cc7d489bdd4
289   -jdy-risk.scenarios[17].entry-id=6a28b64fe398b52f22b43c7b
290   -jdy-risk.scenarios[17].date-field=_widget_1781145540776
  292 +jdy-risk.scenarios[17].entry-id=6aced5f5a8deddb8f92a9a1b
  293 +jdy-risk.scenarios[17].date-field=_widget_1791940252731
291 294 jdy-risk.scenarios[17].month-only=true
292   -jdy-risk.scenarios[17].flag-field=_widget_1781053009425
  295 +jdy-risk.scenarios[17].flag-field=_widget_1791940252732
293 296 jdy-risk.scenarios[17].flag-values[0]=\u672a\u63d0\u4ea4
294   -jdy-risk.scenarios[17].reason-field=_widget_1791798454553
  297 +jdy-risk.scenarios[17].reason-field=_widget_1791940252734
295 298
296 299 # ---------- Scenario 19: repeated similar project within 3 months (prev month, SYNC0043) ----------
297 300 jdy-risk.scenarios[18].id=count_19
... ... @@ -313,12 +316,13 @@ jdy-risk.scenarios[19].sync-code=SYNC0013
313 316 jdy-risk.scenarios[19].app-id=6630634752eab8bdecbaee7d
314 317 jdy-risk.scenarios[19].entry-id=695df62e76801137838d4785
315 318 jdy-risk.scenarios[19].date-field=_widget_1767769739507
316   -jdy-risk.scenarios[19].prev-month-only=true
  319 +jdy-risk.scenarios[19].half-month-only=true
317 320 jdy-risk.scenarios[19].flow-state-value=1
318 321 jdy-risk.scenarios[19].flag-field=_widget_1779093489906
319 322 jdy-risk.scenarios[19].flag-values[0]=\u662f
320 323 jdy-risk.scenarios[19].fuel-amount-field=_widget_1779093489909
321 324 jdy-risk.scenarios[19].start-km-field=_widget_1767770394897
  325 +jdy-risk.scenarios[19].end-km-field=_widget_1767770394898
322 326 jdy-risk.scenarios[19].subform-field=_widget_1779416742773
323 327 jdy-risk.scenarios[19].subform-start-field=_widget_1779932645938
324 328 jdy-risk.scenarios[19].min-value=9
... ... @@ -333,12 +337,13 @@ jdy-risk.scenarios[20].sync-code=SYNC0014
333 337 jdy-risk.scenarios[20].app-id=6630634752eab8bdecbaee7d
334 338 jdy-risk.scenarios[20].entry-id=695df62e76801137838d4785
335 339 jdy-risk.scenarios[20].date-field=_widget_1767769739507
336   -jdy-risk.scenarios[20].prev-month-only=true
  340 +jdy-risk.scenarios[20].half-month-only=true
337 341 jdy-risk.scenarios[20].flow-state-value=1
338 342 jdy-risk.scenarios[20].flag-field=_widget_1779093489911
339 343 jdy-risk.scenarios[20].flag-values[0]=\u662f
340 344 jdy-risk.scenarios[20].fuel-amount-field=_widget_1779093489913
341 345 jdy-risk.scenarios[20].start-km-field=_widget_1767918395737
  346 +jdy-risk.scenarios[20].end-km-field=_widget_1767918395742
342 347 jdy-risk.scenarios[20].subform-field=_widget_1779416742817
343 348 jdy-risk.scenarios[20].subform-start-field=_widget_1779416742834
344 349 jdy-risk.scenarios[20].min-value=8
... ... @@ -353,12 +358,13 @@ jdy-risk.scenarios[21].sync-code=SYNC0015
353 358 jdy-risk.scenarios[21].app-id=6630634752eab8bdecbaee7d
354 359 jdy-risk.scenarios[21].entry-id=695df62e76801137838d4785
355 360 jdy-risk.scenarios[21].date-field=_widget_1767769739507
356   -jdy-risk.scenarios[21].prev-month-only=true
  361 +jdy-risk.scenarios[21].half-month-only=true
357 362 jdy-risk.scenarios[21].flow-state-value=1
358 363 jdy-risk.scenarios[21].flag-field=_widget_1779093489926
359 364 jdy-risk.scenarios[21].flag-values[0]=\u662f
360 365 jdy-risk.scenarios[21].fuel-amount-field=_widget_1779093489925
361 366 jdy-risk.scenarios[21].start-km-field=_widget_1767921522987
  367 +jdy-risk.scenarios[21].end-km-field=_widget_1767921522988
362 368 jdy-risk.scenarios[21].subform-field=_widget_1779416742867
363 369 jdy-risk.scenarios[21].subform-start-field=_widget_1779416742869
364 370 jdy-risk.scenarios[21].min-value=9
... ... @@ -386,8 +392,485 @@ jdy-risk.scenarios[22].company-fields[5]=_widget_1774581058605
386 392 jdy-risk.scenarios[22].company-fields[6]=_widget_1774581058606
387 393 jdy-risk.scenarios[22].company-fields[7]=_widget_1774581058601
388 394
  395 +# ---------- Scene 30: outsourced supplier avg score < 70 (year to date, SYNC0026) ----------
  396 +jdy-risk.scenarios[23].id=count_30
  397 +jdy-risk.scenarios[23].name=scene30
  398 +jdy-risk.scenarios[23].type=scenario23
  399 +jdy-risk.scenarios[23].sync-code=SYNC0026
  400 +jdy-risk.scenarios[23].app-id=6920308e1f3cd4a6f2d84ad7
  401 +jdy-risk.scenarios[23].entry-id=6a5ee84a23d9fee897a66f77
  402 +jdy-risk.scenarios[23].date-field=_widget_1784604746508
  403 +jdy-risk.scenarios[23].year-only=true
  404 +jdy-risk.scenarios[23].group-field=_widget_1784604746504
  405 +jdy-risk.scenarios[23].score-field=_widget_1784604746509
  406 +jdy-risk.scenarios[23].avg-threshold=70
  407 +
  408 +# ---------- Scene 31: month count <=3 and lag >=1 (prev quarter, SYNC0017) ----------
  409 +jdy-risk.scenarios[24].id=count_31
  410 +jdy-risk.scenarios[24].name=scene31
  411 +jdy-risk.scenarios[24].type=scenario24
  412 +jdy-risk.scenarios[24].sync-code=SYNC0017
  413 +jdy-risk.scenarios[24].app-id=6a335614b872e2fd8e9abbe0
  414 +jdy-risk.scenarios[24].entry-id=6a38e2205f7b92cf7e36bdfe
  415 +jdy-risk.scenarios[24].date-field=_widget_1786946231912
  416 +jdy-risk.scenarios[24].prev-quarter-only=true
  417 +jdy-risk.scenarios[24].plan-field=_widget_1786952804322
  418 +jdy-risk.scenarios[24].actual-field=_widget_1786946231912
  419 +jdy-risk.scenarios[24].lag-days=31
  420 +jdy-risk.scenarios[24].min-month-count=0
  421 +jdy-risk.scenarios[24].max-month-count=3
  422 +jdy-risk.scenarios[24].min-lag-count=1
  423 +
  424 +# ---------- Scene 32: 3<count<=5 and lag >=2 (prev quarter, SYNC0018) ----------
  425 +jdy-risk.scenarios[25].id=count_32
  426 +jdy-risk.scenarios[25].name=scene32
  427 +jdy-risk.scenarios[25].type=scenario24
  428 +jdy-risk.scenarios[25].sync-code=SYNC0018
  429 +jdy-risk.scenarios[25].app-id=6a335614b872e2fd8e9abbe0
  430 +jdy-risk.scenarios[25].entry-id=6a38e2205f7b92cf7e36bdfe
  431 +jdy-risk.scenarios[25].date-field=_widget_1786946231912
  432 +jdy-risk.scenarios[25].prev-quarter-only=true
  433 +jdy-risk.scenarios[25].plan-field=_widget_1786952804322
  434 +jdy-risk.scenarios[25].actual-field=_widget_1786946231912
  435 +jdy-risk.scenarios[25].lag-days=31
  436 +jdy-risk.scenarios[25].min-month-count=4
  437 +jdy-risk.scenarios[25].max-month-count=5
  438 +jdy-risk.scenarios[25].min-lag-count=2
  439 +
  440 +# ---------- Scene 33: 5<count<=10 and lag >=3 (prev quarter, SYNC0019) ----------
  441 +jdy-risk.scenarios[26].id=count_33
  442 +jdy-risk.scenarios[26].name=scene33
  443 +jdy-risk.scenarios[26].type=scenario24
  444 +jdy-risk.scenarios[26].sync-code=SYNC0019
  445 +jdy-risk.scenarios[26].app-id=6a335614b872e2fd8e9abbe0
  446 +jdy-risk.scenarios[26].entry-id=6a38e2205f7b92cf7e36bdfe
  447 +jdy-risk.scenarios[26].date-field=_widget_1786946231912
  448 +jdy-risk.scenarios[26].prev-quarter-only=true
  449 +jdy-risk.scenarios[26].plan-field=_widget_1786952804322
  450 +jdy-risk.scenarios[26].actual-field=_widget_1786946231912
  451 +jdy-risk.scenarios[26].lag-days=31
  452 +jdy-risk.scenarios[26].min-month-count=6
  453 +jdy-risk.scenarios[26].max-month-count=10
  454 +jdy-risk.scenarios[26].min-lag-count=3
  455 +
  456 +# ---------- Scene 34: count>10 and lag >=4 (prev quarter, SYNC0020) ----------
  457 +jdy-risk.scenarios[27].id=count_34
  458 +jdy-risk.scenarios[27].name=scene34
  459 +jdy-risk.scenarios[27].type=scenario24
  460 +jdy-risk.scenarios[27].sync-code=SYNC0020
  461 +jdy-risk.scenarios[27].app-id=6a335614b872e2fd8e9abbe0
  462 +jdy-risk.scenarios[27].entry-id=6a38e2205f7b92cf7e36bdfe
  463 +jdy-risk.scenarios[27].date-field=_widget_1786946231912
  464 +jdy-risk.scenarios[27].prev-quarter-only=true
  465 +jdy-risk.scenarios[27].plan-field=_widget_1786952804322
  466 +jdy-risk.scenarios[27].actual-field=_widget_1786946231912
  467 +jdy-risk.scenarios[27].lag-days=31
  468 +jdy-risk.scenarios[27].min-month-count=11
  469 +jdy-risk.scenarios[27].max-month-count=2147483647
  470 +jdy-risk.scenarios[27].min-lag-count=4
  471 +
  472 +# ---------- Scene 35: deviation (budget - winner)/budget >= 40% (prev quarter, SYNC0021) ----------
  473 +jdy-risk.scenarios[28].id=count_35
  474 +jdy-risk.scenarios[28].name=scene35
  475 +jdy-risk.scenarios[28].type=scenario25
  476 +jdy-risk.scenarios[28].sync-code=SYNC0021
  477 +jdy-risk.scenarios[28].app-id=6a335614b872e2fd8e9abbe0
  478 +jdy-risk.scenarios[28].entry-id=6a38e2205f7b92cf7e36bdfe
  479 +jdy-risk.scenarios[28].date-field=_widget_1786946231912
  480 +jdy-risk.scenarios[28].prev-quarter-only=true
  481 +jdy-risk.scenarios[28].budget-field=_widget_1787898949072
  482 +jdy-risk.scenarios[28].price-field=_widget_1787898949352
  483 +jdy-risk.scenarios[28].deviation-threshold=0.4
  484 +
  485 +# ---------- Scene 36: urgent purchase frequency >= 2/quarter (prev quarter, SYNC0022) ----------
  486 +jdy-risk.scenarios[29].id=count_36
  487 +jdy-risk.scenarios[29].name=scene36
  488 +jdy-risk.scenarios[29].type=scenario26
  489 +jdy-risk.scenarios[29].sync-code=SYNC0022
  490 +jdy-risk.scenarios[29].app-id=6a335614b872e2fd8e9abbe0
  491 +jdy-risk.scenarios[29].entry-id=6a38e2205f7b92cf7e36bdfe
  492 +jdy-risk.scenarios[29].date-field=_widget_1786946231912
  493 +jdy-risk.scenarios[29].prev-quarter-only=true
  494 +jdy-risk.scenarios[29].flag-field=_widget_1787898948974
  495 +jdy-risk.scenarios[29].flag-values[0]=\u662f
  496 +jdy-risk.scenarios[29].min-count=2
  497 +
  498 +# ---------- Scene 37: contract change ratio by dept >= 10% (year, SYNC0023) ----------
  499 +jdy-risk.scenarios[30].id=count_37
  500 +jdy-risk.scenarios[30].name=scene37
  501 +jdy-risk.scenarios[30].type=scenario27
  502 +jdy-risk.scenarios[30].sync-code=SYNC0023
  503 +jdy-risk.scenarios[30].app-id=6a335614b872e2fd8e9abbe0
  504 +jdy-risk.scenarios[30].entry-id=6a38e2205f7b92cf7e36bdfe
  505 +jdy-risk.scenarios[30].date-field=_widget_1786946231912
  506 +jdy-risk.scenarios[30].year-only=true
  507 +jdy-risk.scenarios[30].group-field=_widget_1783666105578
  508 +jdy-risk.scenarios[30].flag-field=_widget_1787898949294
  509 +jdy-risk.scenarios[30].flag-values[0]=\u662f
  510 +jdy-risk.scenarios[30].ratio-threshold=0.10
  511 +
  512 +# ---------- Scene 28: assembly outsourcing settlement vs MES vs parts (prev month, SYNC0024) ----------
  513 +jdy-risk.scenarios[31].id=count_28
  514 +jdy-risk.scenarios[31].name=scene28
  515 +jdy-risk.scenarios[31].type=scenario22
  516 +jdy-risk.scenarios[31].sync-code=SYNC0024
  517 +jdy-risk.scenarios[31].app-id=6920308e1f3cd4a6f2d84ad7
  518 +jdy-risk.scenarios[31].entry-id=6a618c9323d9fee897f8ce78
  519 +jdy-risk.scenarios[31].date-field=_widget_1784777875854
  520 +jdy-risk.scenarios[31].qty-field=_widget_1784777875857
  521 +jdy-risk.scenarios[31].second-entry-id=6a618d14c0fa67afd96b121c
  522 +jdy-risk.scenarios[31].second-date-field=_widget_1784778004826
  523 +jdy-risk.scenarios[31].second-qty-field=_widget_1784778004829
  524 +
  525 +# ---------- Scene 29: Hefei warehouse receipt vs electrophoresis settlement (prev month, SYNC0025) ----------
  526 +jdy-risk.scenarios[32].id=count_29
  527 +jdy-risk.scenarios[32].name=scene29
  528 +jdy-risk.scenarios[32].type=scenario28
  529 +jdy-risk.scenarios[32].sync-code=SYNC0025
  530 +jdy-risk.scenarios[32].app-id=6920308e1f3cd4a6f2d84ad7
  531 +jdy-risk.scenarios[32].entry-id=69b0cefeebedeb1dbecca68d
  532 +jdy-risk.scenarios[32].date-field=_widget_1773195006402
  533 +jdy-risk.scenarios[32].qty-field=_widget_1773195006403
  534 +jdy-risk.scenarios[32].second-entry-id=6a6074bb23d9fee897d951e1
  535 +jdy-risk.scenarios[32].second-date-field=_widget_1784706253892
  536 +jdy-risk.scenarios[32].second-qty-field=_widget_1773195006403
  537 +jdy-risk.scenarios[32].period-start-field=_widget_1784706253893
  538 +jdy-risk.scenarios[32].period-end-field=_widget_1784706253894
  539 +
  540 +# ---------- Scene 38: claim process overdue > 30 days (prev month by end time, SYNC0036) ----------
  541 +jdy-risk.scenarios[33].id=count_38
  542 +jdy-risk.scenarios[33].name=scene38
  543 +jdy-risk.scenarios[33].type=scenario29
  544 +jdy-risk.scenarios[33].sync-code=SYNC0036
  545 +jdy-risk.scenarios[33].app-id=67dbb0e3045ce7a6eb1c0724
  546 +jdy-risk.scenarios[33].entry-id=67e6516a7d1f5a7bf76d63b4
  547 +jdy-risk.scenarios[33].date-field=_widget_1784547121026
  548 +jdy-risk.scenarios[33].start-field=_widget_1743147378939
  549 +jdy-risk.scenarios[33].threshold-days=30
  550 +jdy-risk.scenarios[33].prev-month-only=true
  551 +
  552 +# ---------- Scene 39: return amount TOP3 supplier (prev month, SYNC0027) ----------
  553 +jdy-risk.scenarios[34].id=count_39
  554 +jdy-risk.scenarios[34].name=scene39
  555 +jdy-risk.scenarios[34].type=scenario30
  556 +jdy-risk.scenarios[34].sync-code=SYNC0027
  557 +jdy-risk.scenarios[34].app-id=67bbd034121d45bf2beb0b37
  558 +jdy-risk.scenarios[34].entry-id=6a66fec4d8d61cd5201ce214
  559 +jdy-risk.scenarios[34].subform-field=_widget_1785134788742
  560 +jdy-risk.scenarios[34].sub-part-field=_widget_1785134788744
  561 +jdy-risk.scenarios[34].sub-qty-field=_widget_1785134788745
  562 +jdy-risk.scenarios[34].sub-date-field=_widget_1785134788746
  563 +jdy-risk.scenarios[34].rel-entry-id=6a670697bccb96b113bb8dec
  564 +jdy-risk.scenarios[34].rel-part-field=_widget_1785136791804
  565 +jdy-risk.scenarios[34].rel-supplier-field=_widget_1785136791807
  566 +jdy-risk.scenarios[34].rel-enable-field=_widget_1785136791808
  567 +jdy-risk.scenarios[34].rel-time-field=_widget_1785136791809
  568 +jdy-risk.scenarios[34].cost-entry-id=6a670ae91c55b87fcd211c5e
  569 +jdy-risk.scenarios[34].cost-code-field=_widget_1785137897089
  570 +jdy-risk.scenarios[34].cost-value-field=_widget_1785137897094
  571 +jdy-risk.scenarios[34].top-count=3
  572 +
  573 +# ---------- Scene 40: return quantity TOP3 supplier (prev month, SYNC0028) ----------
  574 +jdy-risk.scenarios[35].id=count_40
  575 +jdy-risk.scenarios[35].name=scene40
  576 +jdy-risk.scenarios[35].type=scenario31
  577 +jdy-risk.scenarios[35].sync-code=SYNC0028
  578 +jdy-risk.scenarios[35].app-id=67bbd034121d45bf2beb0b37
  579 +jdy-risk.scenarios[35].entry-id=6a66fec4d8d61cd5201ce214
  580 +jdy-risk.scenarios[35].subform-field=_widget_1785134788742
  581 +jdy-risk.scenarios[35].sub-part-field=_widget_1785134788744
  582 +jdy-risk.scenarios[35].sub-qty-field=_widget_1785134788745
  583 +jdy-risk.scenarios[35].sub-date-field=_widget_1785134788746
  584 +jdy-risk.scenarios[35].rel-entry-id=6a670697bccb96b113bb8dec
  585 +jdy-risk.scenarios[35].rel-part-field=_widget_1785136791804
  586 +jdy-risk.scenarios[35].rel-supplier-field=_widget_1785136791807
  587 +jdy-risk.scenarios[35].rel-enable-field=_widget_1785136791808
  588 +jdy-risk.scenarios[35].rel-time-field=_widget_1785136791809
  589 +jdy-risk.scenarios[35].top-count=3
  590 +
  591 +# ---------- Scene 41: stock amount vs indicator - assembly 88013131 (SYNC0029) ----------
  592 +jdy-risk.scenarios[36].id=count_41
  593 +jdy-risk.scenarios[36].name=scene41
  594 +jdy-risk.scenarios[36].type=scenario32
  595 +jdy-risk.scenarios[36].sync-code=SYNC0029
  596 +jdy-risk.scenarios[36].app-id=67bbd034121d45bf2beb0b37
  597 +jdy-risk.scenarios[36].entry-id=6a670eaab0cfb7d56e1ad94c
  598 +jdy-risk.scenarios[36].indicator-code-field=_widget_1785138858238
  599 +jdy-risk.scenarios[36].indicator-target-field=_widget_1785138858240
  600 +jdy-risk.scenarios[36].stock-entry-id=6ad9d06e9813efd5d7d5c5bc
  601 +jdy-risk.scenarios[36].stock-month-field=_widget_1793087125262
  602 +jdy-risk.scenarios[36].stock-part-field=_widget_1792659566889
  603 +jdy-risk.scenarios[36].stock-qty-field=_widget_1792659566891
  604 +jdy-risk.scenarios[36].stock-warehouse-field=_widget_1792659566894
  605 +jdy-risk.scenarios[36].cost-entry-id=6a670ae91c55b87fcd211c5e
  606 +jdy-risk.scenarios[36].cost-code-field=_widget_1785137897089
  607 +jdy-risk.scenarios[36].cost-value-field=_widget_1785137897094
  608 +jdy-risk.scenarios[36].aixin-entry-id=6a670f5f9a2a280f6edf4a43
  609 +jdy-risk.scenarios[36].aixin-part-field=_widget_1785139039673
  610 +jdy-risk.scenarios[36].warehouse-code=88013131
  611 +jdy-risk.scenarios[36].prev-month-only=true
  612 +
  613 +# ---------- Scene 42: stock amount vs indicator - assembly phase2 4020068131 (SYNC0030) ----------
  614 +jdy-risk.scenarios[37].id=count_42
  615 +jdy-risk.scenarios[37].name=scene42
  616 +jdy-risk.scenarios[37].type=scenario32
  617 +jdy-risk.scenarios[37].sync-code=SYNC0030
  618 +jdy-risk.scenarios[37].app-id=67bbd034121d45bf2beb0b37
  619 +jdy-risk.scenarios[37].entry-id=6a670eaab0cfb7d56e1ad94c
  620 +jdy-risk.scenarios[37].indicator-code-field=_widget_1785138858238
  621 +jdy-risk.scenarios[37].indicator-target-field=_widget_1785138858240
  622 +jdy-risk.scenarios[37].stock-entry-id=6ad9d06e9813efd5d7d5c5bc
  623 +jdy-risk.scenarios[37].stock-month-field=_widget_1793087125262
  624 +jdy-risk.scenarios[37].stock-part-field=_widget_1792659566889
  625 +jdy-risk.scenarios[37].stock-qty-field=_widget_1792659566891
  626 +jdy-risk.scenarios[37].stock-warehouse-field=_widget_1792659566894
  627 +jdy-risk.scenarios[37].cost-entry-id=6a670ae91c55b87fcd211c5e
  628 +jdy-risk.scenarios[37].cost-code-field=_widget_1785137897089
  629 +jdy-risk.scenarios[37].cost-value-field=_widget_1785137897094
  630 +jdy-risk.scenarios[37].aixin-entry-id=6a670f5f9a2a280f6edf4a43
  631 +jdy-risk.scenarios[37].aixin-part-field=_widget_1785139039673
  632 +jdy-risk.scenarios[37].warehouse-code=4020068131
  633 +jdy-risk.scenarios[37].prev-month-only=true
  634 +
  635 +# ---------- Scene 43: stock amount vs indicator - paint 88012131 (SYNC0031) ----------
  636 +jdy-risk.scenarios[38].id=count_43
  637 +jdy-risk.scenarios[38].name=scene43
  638 +jdy-risk.scenarios[38].type=scenario32
  639 +jdy-risk.scenarios[38].sync-code=SYNC0031
  640 +jdy-risk.scenarios[38].app-id=67bbd034121d45bf2beb0b37
  641 +jdy-risk.scenarios[38].entry-id=6a670eaab0cfb7d56e1ad94c
  642 +jdy-risk.scenarios[38].indicator-code-field=_widget_1785138858238
  643 +jdy-risk.scenarios[38].indicator-target-field=_widget_1785138858240
  644 +jdy-risk.scenarios[38].stock-entry-id=6ad9d06e9813efd5d7d5c5bc
  645 +jdy-risk.scenarios[38].stock-month-field=_widget_1793087125262
  646 +jdy-risk.scenarios[38].stock-part-field=_widget_1792659566889
  647 +jdy-risk.scenarios[38].stock-qty-field=_widget_1792659566891
  648 +jdy-risk.scenarios[38].stock-warehouse-field=_widget_1792659566894
  649 +jdy-risk.scenarios[38].cost-entry-id=6a670ae91c55b87fcd211c5e
  650 +jdy-risk.scenarios[38].cost-code-field=_widget_1785137897089
  651 +jdy-risk.scenarios[38].cost-value-field=_widget_1785137897094
  652 +jdy-risk.scenarios[38].warehouse-code=88012131
  653 +jdy-risk.scenarios[38].prev-month-only=true
  654 +
  655 +# ---------- Scene 44: stock amount vs indicator - paint phase2 4020067131 (SYNC0032) ----------
  656 +jdy-risk.scenarios[39].id=count_44
  657 +jdy-risk.scenarios[39].name=scene44
  658 +jdy-risk.scenarios[39].type=scenario32
  659 +jdy-risk.scenarios[39].sync-code=SYNC0032
  660 +jdy-risk.scenarios[39].app-id=67bbd034121d45bf2beb0b37
  661 +jdy-risk.scenarios[39].entry-id=6a670eaab0cfb7d56e1ad94c
  662 +jdy-risk.scenarios[39].indicator-code-field=_widget_1785138858238
  663 +jdy-risk.scenarios[39].indicator-target-field=_widget_1785138858240
  664 +jdy-risk.scenarios[39].stock-entry-id=6ad9d06e9813efd5d7d5c5bc
  665 +jdy-risk.scenarios[39].stock-month-field=_widget_1793087125262
  666 +jdy-risk.scenarios[39].stock-part-field=_widget_1792659566889
  667 +jdy-risk.scenarios[39].stock-qty-field=_widget_1792659566891
  668 +jdy-risk.scenarios[39].stock-warehouse-field=_widget_1792659566894
  669 +jdy-risk.scenarios[39].cost-entry-id=6a670ae91c55b87fcd211c5e
  670 +jdy-risk.scenarios[39].cost-code-field=_widget_1785137897089
  671 +jdy-risk.scenarios[39].cost-value-field=_widget_1785137897094
  672 +jdy-risk.scenarios[39].warehouse-code=4020067131
  673 +jdy-risk.scenarios[39].prev-month-only=true
  674 +
  675 +# ---------- Scene 45: stock amount vs indicator - weld 88011131 (SYNC0033) ----------
  676 +jdy-risk.scenarios[40].id=count_45
  677 +jdy-risk.scenarios[40].name=scene45
  678 +jdy-risk.scenarios[40].type=scenario32
  679 +jdy-risk.scenarios[40].sync-code=SYNC0033
  680 +jdy-risk.scenarios[40].app-id=67bbd034121d45bf2beb0b37
  681 +jdy-risk.scenarios[40].entry-id=6a670eaab0cfb7d56e1ad94c
  682 +jdy-risk.scenarios[40].indicator-code-field=_widget_1785138858238
  683 +jdy-risk.scenarios[40].indicator-target-field=_widget_1785138858240
  684 +jdy-risk.scenarios[40].stock-entry-id=6ad9d06e9813efd5d7d5c5bc
  685 +jdy-risk.scenarios[40].stock-month-field=_widget_1793087125262
  686 +jdy-risk.scenarios[40].stock-part-field=_widget_1792659566889
  687 +jdy-risk.scenarios[40].stock-qty-field=_widget_1792659566891
  688 +jdy-risk.scenarios[40].stock-warehouse-field=_widget_1792659566894
  689 +jdy-risk.scenarios[40].cost-entry-id=6a670ae91c55b87fcd211c5e
  690 +jdy-risk.scenarios[40].cost-code-field=_widget_1785137897089
  691 +jdy-risk.scenarios[40].cost-value-field=_widget_1785137897094
  692 +jdy-risk.scenarios[40].warehouse-code=88011131
  693 +jdy-risk.scenarios[40].prev-month-only=true
  694 +
  695 +# ---------- Scene 46: stock amount vs indicator - weld phase2 4020066131 (SYNC0034) ----------
  696 +jdy-risk.scenarios[41].id=count_46
  697 +jdy-risk.scenarios[41].name=scene46
  698 +jdy-risk.scenarios[41].type=scenario32
  699 +jdy-risk.scenarios[41].sync-code=SYNC0034
  700 +jdy-risk.scenarios[41].app-id=67bbd034121d45bf2beb0b37
  701 +jdy-risk.scenarios[41].entry-id=6a670eaab0cfb7d56e1ad94c
  702 +jdy-risk.scenarios[41].indicator-code-field=_widget_1785138858238
  703 +jdy-risk.scenarios[41].indicator-target-field=_widget_1785138858240
  704 +jdy-risk.scenarios[41].stock-entry-id=6ad9d06e9813efd5d7d5c5bc
  705 +jdy-risk.scenarios[41].stock-month-field=_widget_1793087125262
  706 +jdy-risk.scenarios[41].stock-part-field=_widget_1792659566889
  707 +jdy-risk.scenarios[41].stock-qty-field=_widget_1792659566891
  708 +jdy-risk.scenarios[41].stock-warehouse-field=_widget_1792659566894
  709 +jdy-risk.scenarios[41].cost-entry-id=6a670ae91c55b87fcd211c5e
  710 +jdy-risk.scenarios[41].cost-code-field=_widget_1785137897089
  711 +jdy-risk.scenarios[41].cost-value-field=_widget_1785137897094
  712 +jdy-risk.scenarios[41].warehouse-code=4020066131
  713 +jdy-risk.scenarios[41].prev-month-only=true
  714 +
  715 +# ---------- Scene 47: stock amount vs indicator - stamping 88014131 (SYNC0035) ----------
  716 +jdy-risk.scenarios[42].id=count_47
  717 +jdy-risk.scenarios[42].name=scene47
  718 +jdy-risk.scenarios[42].type=scenario32
  719 +jdy-risk.scenarios[42].sync-code=SYNC0035
  720 +jdy-risk.scenarios[42].app-id=67bbd034121d45bf2beb0b37
  721 +jdy-risk.scenarios[42].entry-id=6a670eaab0cfb7d56e1ad94c
  722 +jdy-risk.scenarios[42].indicator-code-field=_widget_1785138858238
  723 +jdy-risk.scenarios[42].indicator-target-field=_widget_1785138858240
  724 +jdy-risk.scenarios[42].stock-entry-id=6ad9d06e9813efd5d7d5c5bc
  725 +jdy-risk.scenarios[42].stock-month-field=_widget_1793087125262
  726 +jdy-risk.scenarios[42].stock-part-field=_widget_1792659566889
  727 +jdy-risk.scenarios[42].stock-qty-field=_widget_1792659566891
  728 +jdy-risk.scenarios[42].stock-warehouse-field=_widget_1792659566894
  729 +jdy-risk.scenarios[42].cost-entry-id=6a670ae91c55b87fcd211c5e
  730 +jdy-risk.scenarios[42].cost-code-field=_widget_1785137897089
  731 +jdy-risk.scenarios[42].cost-value-field=_widget_1785137897094
  732 +jdy-risk.scenarios[42].warehouse-code=88014131
  733 +jdy-risk.scenarios[42].prev-month-only=true
  734 +
  735 +# ---------- Scene 20: waste warning stat - unhandled (Kingbase, SYNC0039) ----------
  736 +jdy-risk.scenarios[43].id=count_20
  737 +jdy-risk.scenarios[43].name=scene20
  738 +jdy-risk.scenarios[43].type=scenario33
  739 +jdy-risk.scenarios[43].sync-code=SYNC0039
  740 +jdy-risk.scenarios[43].table=biz_waste_warn_stat
  741 +jdy-risk.scenarios[43].handle-field=handle_status
  742 +jdy-risk.scenarios[43].handle-values[0]=\u672a\u5904\u7406
  743 +jdy-risk.scenarios[43].handle-values[1]=\u672a\u5904\u7f6e
  744 +jdy-risk.scenarios[43].stat-year-field=stat_year
  745 +jdy-risk.scenarios[43].stat-month-field=stat_month
  746 +jdy-risk.scenarios[43].columns[0]=org_name
  747 +jdy-risk.scenarios[43].columns[1]=category_name
  748 +jdy-risk.scenarios[43].columns[2]=stat_year
  749 +jdy-risk.scenarios[43].columns[3]=stat_month
  750 +jdy-risk.scenarios[43].columns[4]=waste_weight
  751 +jdy-risk.scenarios[43].columns[5]=erp_finish_qty
  752 +jdy-risk.scenarios[43].columns[6]=weigh_weight
  753 +jdy-risk.scenarios[43].columns[7]=over_weight
  754 +jdy-risk.scenarios[43].columns[8]=warn_threshold
  755 +jdy-risk.scenarios[43].columns[9]=actual_ratio
  756 +jdy-risk.scenarios[43].columns[10]=handle_status
  757 +jdy-risk.scenarios[43].columns[11]=is_alarm
  758 +jdy-risk.scenarios[43].columns[12]=warn_notice_user
  759 +jdy-risk.scenarios[43].columns[13]=create_time
  760 +jdy-risk.scenarios[43].columns[14]=dispose_user
  761 +jdy-risk.scenarios[43].columns[15]=dispose_time
  762 +jdy-risk.scenarios[43].columns[16]=fill_reason
  763 +jdy-risk.scenarios[43].column-labels.org_name=\u5355\u4f4d\u540d\u79f0
  764 +jdy-risk.scenarios[43].column-labels.category_name=\u5e9f\u6599\u7c7b\u522b
  765 +jdy-risk.scenarios[43].column-labels.stat_year=\u7edf\u8ba1\u5e74
  766 +jdy-risk.scenarios[43].column-labels.stat_month=\u7edf\u8ba1\u6708
  767 +jdy-risk.scenarios[43].column-labels.waste_weight=\u5e9f\u6599\u91cd\u91cf
  768 +jdy-risk.scenarios[43].column-labels.erp_finish_qty=ERP\u5b8c\u5de5\u6570\u91cf
  769 +jdy-risk.scenarios[43].column-labels.weigh_weight=\u8fc7\u78c5\u91cd\u91cf
  770 +jdy-risk.scenarios[43].column-labels.over_weight=\u8d85\u51fa\u91cd\u91cf
  771 +jdy-risk.scenarios[43].column-labels.warn_threshold=\u9884\u8b66\u9608\u503c
  772 +jdy-risk.scenarios[43].column-labels.actual_ratio=\u5b9e\u9645\u6bd4\u4f8b
  773 +jdy-risk.scenarios[43].column-labels.handle_status=\u5904\u7406\u72b6\u6001
  774 +jdy-risk.scenarios[43].column-labels.is_alarm=\u662f\u5426\u62a5\u8b66
  775 +jdy-risk.scenarios[43].column-labels.warn_notice_user=\u9884\u8b66\u901a\u77e5\u4eba
  776 +jdy-risk.scenarios[43].column-labels.create_time=\u521b\u5efa\u65f6\u95f4
  777 +jdy-risk.scenarios[43].column-labels.dispose_user=\u5904\u7406\u4eba
  778 +jdy-risk.scenarios[43].column-labels.dispose_time=\u5904\u7406\u65f6\u95f4
  779 +jdy-risk.scenarios[43].column-labels.fill_reason=\u586b\u5199\u539f\u56e0
  780 +
  781 +# ---------- Scene 21: weight record - unhandled (Kingbase, SYNC0040) ----------
  782 +jdy-risk.scenarios[44].id=count_21
  783 +jdy-risk.scenarios[44].name=scene21
  784 +jdy-risk.scenarios[44].type=scenario34
  785 +jdy-risk.scenarios[44].sync-code=SYNC0040
  786 +jdy-risk.scenarios[44].table=biz_weight_record
  787 +jdy-risk.scenarios[44].date-field=weight_time
  788 +jdy-risk.scenarios[44].handle-field=is_handled
  789 +jdy-risk.scenarios[44].handle-values[0]=3
  790 +jdy-risk.scenarios[44].handle-values[1]=\u672a\u5904\u7406
  791 +jdy-risk.scenarios[44].handle-values[2]=\u672a\u5904\u7f6e
  792 +jdy-risk.scenarios[44].handle-value-labels.3=\u672a\u5904\u7406
  793 +jdy-risk.scenarios[44].columns[0]=weight_serial_no
  794 +jdy-risk.scenarios[44].columns[1]=delivery_unit
  795 +jdy-risk.scenarios[44].columns[2]=tare_weight
  796 +jdy-risk.scenarios[44].columns[3]=net_weight
  797 +jdy-risk.scenarios[44].columns[4]=unit
  798 +jdy-risk.scenarios[44].columns[5]=weight_time
  799 +jdy-risk.scenarios[44].columns[6]=deviation_weight
  800 +jdy-risk.scenarios[44].columns[7]=plate_no
  801 +jdy-risk.scenarios[44].columns[8]=base_weight
  802 +jdy-risk.scenarios[44].columns[9]=is_handled
  803 +jdy-risk.scenarios[44].columns[10]=warn_value
  804 +jdy-risk.scenarios[44].columns[11]=org_code
  805 +jdy-risk.scenarios[44].column-labels.weight_serial_no=\u8fc7\u78c5\u6d41\u6c34\u53f7
  806 +jdy-risk.scenarios[44].column-labels.delivery_unit=\u9001\u8d27\u5355\u4f4d
  807 +jdy-risk.scenarios[44].column-labels.tare_weight=\u76ae\u91cd
  808 +jdy-risk.scenarios[44].column-labels.net_weight=\u51c0\u91cd
  809 +jdy-risk.scenarios[44].column-labels.unit=\u5355\u4f4d
  810 +jdy-risk.scenarios[44].column-labels.weight_time=\u8fc7\u78c5\u65f6\u95f4
  811 +jdy-risk.scenarios[44].column-labels.deviation_weight=\u504f\u5dee\u91cd\u91cf
  812 +jdy-risk.scenarios[44].column-labels.plate_no=\u8f66\u724c\u53f7
  813 +jdy-risk.scenarios[44].column-labels.base_weight=\u57fa\u51c6\u91cd\u91cf
  814 +jdy-risk.scenarios[44].column-labels.is_handled=\u5904\u7406\u72b6\u6001
  815 +jdy-risk.scenarios[44].column-labels.warn_value=\u9884\u8b66\u503c
  816 +jdy-risk.scenarios[44].column-labels.org_code=\u5355\u4f4d\u7f16\u7801
  817 +
  818 +# ---------- Scene 22: transport weight exception - unhandled (Kingbase, SYNC0041) ----------
  819 +jdy-risk.scenarios[45].id=count_22
  820 +jdy-risk.scenarios[45].name=scene22
  821 +jdy-risk.scenarios[45].type=scenario35
  822 +jdy-risk.scenarios[45].sync-code=SYNC0041
  823 +jdy-risk.scenarios[45].table=biz_weight_trans_exception
  824 +jdy-risk.scenarios[45].date-field=weight_time
  825 +jdy-risk.scenarios[45].handle-field=is_handled
  826 +jdy-risk.scenarios[45].handle-values[0]=\u672a\u5904\u7406
  827 +jdy-risk.scenarios[45].handle-values[1]=\u672a\u5904\u7f6e
  828 +jdy-risk.scenarios[45].columns[0]=org_name
  829 +jdy-risk.scenarios[45].columns[1]=transport_unit
  830 +jdy-risk.scenarios[45].columns[2]=tare_weight
  831 +jdy-risk.scenarios[45].columns[3]=net_weight
  832 +jdy-risk.scenarios[45].columns[4]=deviation_weight
  833 +jdy-risk.scenarios[45].columns[5]=weight_time
  834 +jdy-risk.scenarios[45].columns[6]=plate_no
  835 +jdy-risk.scenarios[45].columns[7]=material_name
  836 +jdy-risk.scenarios[45].columns[8]=lower_limit
  837 +jdy-risk.scenarios[45].columns[9]=is_handled
  838 +jdy-risk.scenarios[45].columns[10]=exception_desc
  839 +jdy-risk.scenarios[45].column-labels.org_name=\u5355\u4f4d\u540d\u79f0
  840 +jdy-risk.scenarios[45].column-labels.transport_unit=\u8fd0\u8f93\u5355\u4f4d
  841 +jdy-risk.scenarios[45].column-labels.tare_weight=\u76ae\u91cd
  842 +jdy-risk.scenarios[45].column-labels.net_weight=\u51c0\u91cd
  843 +jdy-risk.scenarios[45].column-labels.deviation_weight=\u504f\u5dee\u91cd\u91cf
  844 +jdy-risk.scenarios[45].column-labels.weight_time=\u8fc7\u78c5\u65f6\u95f4
  845 +jdy-risk.scenarios[45].column-labels.plate_no=\u8f66\u724c\u53f7
  846 +jdy-risk.scenarios[45].column-labels.material_name=\u7269\u6599\u540d\u79f0
  847 +jdy-risk.scenarios[45].column-labels.lower_limit=\u4e0b\u9650\u503c
  848 +jdy-risk.scenarios[45].column-labels.is_handled=\u5904\u7406\u72b6\u6001
  849 +jdy-risk.scenarios[45].column-labels.exception_desc=\u5f02\u5e38\u8bf4\u660e
  850 +
  851 +# ---------- Customer Kingbase ES DB (device domain scenes 20/21/22) ----------
  852 +jdy-risk.kingbase.url=jdbc:kingbase8://10.144.201.35:54321/qixiao-apaas
  853 +jdy-risk.kingbase.username=qixiaoadmin
  854 +jdy-risk.kingbase.password=Qx@20260821.com
  855 +jdy-risk.kingbase.driver-class=com.kingbase8.Driver
  856 +
  857 +# ---------- Customer MES middle DB (Oracle, scene 28) ----------
  858 +jdy-risk.mes.url=jdbc:oracle:thin:@//10.144.200.229:1521/HFMESMID
  859 +jdy-risk.mes.username=ZHIOP_MES
  860 +jdy-risk.mes.password=ZHIOP_MES@2026
  861 +
389 862 # ---------- Risk scenario scheduled tasks ----------
390 863 jdy-risk.schedule.enabled=true
  864 +jdy-risk.schedule.s1-cron=0 0 3 20 * ?
  865 +jdy-risk.schedule.s2-cron=0 0 3 5 * ?
  866 +jdy-risk.schedule.s3-cron=0 0 3 5 * ?
  867 +jdy-risk.schedule.s4-cron=0 0 3 5 1,4,7,10 ?
  868 +jdy-risk.schedule.s5-cron=0 0 3 5 1,4,7,10 ?
  869 +jdy-risk.schedule.s6-cron=0 0 23 * * ?
  870 +jdy-risk.schedule.s7-cron=0 0 3 5 * ?
  871 +jdy-risk.schedule.s8-cron=0 0 3 5 * ?
  872 +jdy-risk.schedule.s9-cron=0 0 3 5 * ?
  873 +jdy-risk.schedule.s10-cron=0 0 3 5 * ?
391 874 jdy-risk.schedule.s12-cron=0 0 3 1 * ?
392 875 jdy-risk.schedule.s13-cron=0 0 3 10 * ?
393 876 jdy-risk.schedule.s14-cron=0 0 3 20 12 ?
... ... @@ -396,10 +879,33 @@ jdy-risk.schedule.s16-cron=0 0 23 * * ?
396 879 jdy-risk.schedule.s17-cron=0 0 3 1 * ?
397 880 jdy-risk.schedule.s18-cron=0 0 23 * * ?
398 881 jdy-risk.schedule.s19-cron=0 0 1 1 * ?
399   -jdy-risk.schedule.s23-cron=0 0 1 1 * ?
400   -jdy-risk.schedule.s24-cron=0 0 1 1 * ?
401   -jdy-risk.schedule.s25-cron=0 0 1 1 * ?
  882 +jdy-risk.schedule.s20-cron=0 0 1 12 * ?
  883 +jdy-risk.schedule.s21a-cron=0 0 1 11 * ?
  884 +jdy-risk.schedule.s21b-cron=0 0 1 21 * ?
  885 +jdy-risk.schedule.s21c-cron=0 0 23 * * ?
  886 +jdy-risk.schedule.s22-cron=0 0 1 1 * ?
  887 +jdy-risk.schedule.s23-cron=0 0 1 1,16 * ?
  888 +jdy-risk.schedule.s24-cron=0 0 1 1,16 * ?
  889 +jdy-risk.schedule.s25-cron=0 0 1 1,16 * ?
402 890 jdy-risk.schedule.s26-cron=0 0 1 1 * ?
  891 +jdy-risk.schedule.s30-cron=0 0 23 * * ?
  892 +jdy-risk.schedule.s31-cron=0 0 1 1 1,4,7,10 ?
  893 +jdy-risk.schedule.s32-cron=0 0 1 1 1,4,7,10 ?
  894 +jdy-risk.schedule.s33-cron=0 0 1 1 1,4,7,10 ?
  895 +jdy-risk.schedule.s34-cron=0 0 1 1 1,4,7,10 ?
  896 +jdy-risk.schedule.s35-cron=0 0 1 1 1,4,7,10 ?
  897 +jdy-risk.schedule.s36-cron=0 0 1 1 1,4,7,10 ?
  898 +jdy-risk.schedule.s37-cron=0 0 23 31 12 ?
  899 +jdy-risk.schedule.s38-cron=0 0 3 10 * ?
  900 +jdy-risk.schedule.s39-cron=0 0 3 5 * ?
  901 +jdy-risk.schedule.s40-cron=0 0 3 5 * ?
  902 +jdy-risk.schedule.s41-cron=0 0 3 5 * ?
  903 +jdy-risk.schedule.s42-cron=0 0 3 5 * ?
  904 +jdy-risk.schedule.s43-cron=0 0 3 5 * ?
  905 +jdy-risk.schedule.s44-cron=0 0 3 5 * ?
  906 +jdy-risk.schedule.s45-cron=0 0 3 5 * ?
  907 +jdy-risk.schedule.s46-cron=0 0 3 5 * ?
  908 +jdy-risk.schedule.s47-cron=0 0 3 5 * ?
403 909
404 910 # =============================================================================
405 911 # Form sync configuration
... ...
... ... @@ -69,6 +69,13 @@
69 69 <version>8.6.0.jre7</version>
70 70 </dependency>
71 71
  72 + <!-- Oracle JDBC 驱动(场景28 对接客户 MES 中间库) -->
  73 + <dependency>
  74 + <groupId>com.oracle.database.jdbc</groupId>
  75 + <artifactId>ojdbc8</artifactId>
  76 + <version>19.22.0.0</version>
  77 + </dependency>
  78 +
72 79 <!-- 简化代码 -->
73 80 <dependency>
74 81 <groupId>org.projectlombok</groupId>
... ...
... ... @@ -3,7 +3,9 @@ package com.qgutech.qgyun.apaas.sync.jdy.config;
3 3 import org.springframework.boot.context.properties.ConfigurationProperties;
4 4
5 5 import java.util.ArrayList;
  6 +import java.util.LinkedHashMap;
6 7 import java.util.List;
  8 +import java.util.Map;
7 9
8 10 /**
9 11 * 风险场景统计配置。
... ... @@ -23,6 +25,12 @@ public class JdyRiskProperties {
23 25 /** 启效(QX)写回配置(把统计结果更新到目标应用表单) */
24 26 private Qx qx = new Qx();
25 27
  28 + /** 客户 MES 中间库(Oracle,场景28) */
  29 + private Mes mes = new Mes();
  30 +
  31 + /** 客户内网人大金仓(KingbaseES)数据库(设备域场景20/21/22) */
  32 + private Kingbase kingbase = new Kingbase();
  33 +
26 34 /** 场景清单 */
27 35 private List<Scenario> scenarios = new ArrayList<>();
28 36
... ... @@ -61,6 +69,22 @@ public class JdyRiskProperties {
61 69 this.scenarios = scenarios;
62 70 }
63 71
  72 + public Mes getMes() {
  73 + return mes;
  74 + }
  75 +
  76 + public void setMes(Mes mes) {
  77 + this.mes = mes;
  78 + }
  79 +
  80 + public Kingbase getKingbase() {
  81 + return kingbase;
  82 + }
  83 +
  84 + public void setKingbase(Kingbase kingbase) {
  85 + this.kingbase = kingbase;
  86 + }
  87 +
64 88 public Schedule getSchedule() {
65 89 return schedule;
66 90 }
... ... @@ -73,6 +97,23 @@ public class JdyRiskProperties {
73 97 public static class Schedule {
74 98 /** 是否启用设备域场景12/13定时任务 */
75 99 private boolean enabled = false;
  100 + /** 场景1(SYNC0001)抓取 cron:默认每月20号 03:00,抓上月数据 */
  101 + private String s1Cron = "0 0 3 20 * ?";
  102 + /** 质量域场景2/3(SYNC0002/0003):每月5号抓上月 */
  103 + private String s2Cron = "0 0 3 5 * ?";
  104 + private String s3Cron = "0 0 3 5 * ?";
  105 + /** 质量域场景4/5(SYNC0004/0005):1/4/7/10月5号抓上一季度 */
  106 + private String s4Cron = "0 0 3 5 1,4,7,10 ?";
  107 + private String s5Cron = "0 0 3 5 1,4,7,10 ?";
  108 + /** 质量域场景6(SYNC0006):每月最后一天23点抓当月(每天23点触发,月末执行) */
  109 + private String s6Cron = "0 0 23 * * ?";
  110 + /** 质量域场景7(SYNC0007):每月5号抓上月 */
  111 + private String s7Cron = "0 0 3 5 * ?";
  112 + /** 质量域场景8(SYNC0008):每月5号,按上月末增量统计超期 */
  113 + private String s8Cron = "0 0 3 5 * ?";
  114 + /** 质量域场景9/10(SYNC0010/0011):每月5号抓上月 */
  115 + private String s9Cron = "0 0 3 5 * ?";
  116 + private String s10Cron = "0 0 3 5 * ?";
76 117 /** 场景12(SYNC0034)抓取 cron:默认每月1号 03:00 */
77 118 private String s12Cron = "0 0 3 1 * ?";
78 119 /** 场景13(SYNC0042)抓取 cron:默认每月10号 03:00 */
... ... @@ -89,6 +130,16 @@ public class JdyRiskProperties {
89 130 private String s18Cron = "0 0 23 * * ?";
90 131 /** 场景19(SYNC0043)抓取 cron:默认每月1号 01:00 */
91 132 private String s19Cron = "0 0 1 1 * ?";
  133 + /** 场景20(SYNC0039 废料预警,人大金仓):默认每月12号 01:00 抓上月 */
  134 + private String s20Cron = "0 0 1 12 * ?";
  135 + /** 场景21(SYNC0040 过磅记录,人大金仓):每月11号 01:00 抓1-10号 */
  136 + private String s21aCron = "0 0 1 11 * ?";
  137 + /** 场景21:每月21号 01:00 抓11-20号 */
  138 + private String s21bCron = "0 0 1 21 * ?";
  139 + /** 场景21:每月最后一天 23:00 抓21号-月底(每天23点触发,月末执行) */
  140 + private String s21cCron = "0 0 23 * * ?";
  141 + /** 场景22(SYNC0041 运输异常,人大金仓):默认每月1号 01:00 抓上月 */
  142 + private String s22Cron = "0 0 1 1 * ?";
92 143 /** 场景23(SYNC0013)抓取 cron:默认每月1号 01:00 */
93 144 private String s23Cron = "0 0 1 1 * ?";
94 145 /** 场景24(SYNC0014)抓取 cron:默认每月1号 01:00 */
... ... @@ -97,6 +148,33 @@ public class JdyRiskProperties {
97 148 private String s25Cron = "0 0 1 1 * ?";
98 149 /** 场景26(SYNC0016)抓取 cron:默认每月1号 01:00 */
99 150 private String s26Cron = "0 0 1 1 * ?";
  151 + /** 场景28/29/30:每月最后一天23点(每天23点触发,月末执行) */
  152 + private String s28Cron = "0 0 23 * * ?";
  153 + private String s29Cron = "0 0 23 * * ?";
  154 + private String s30Cron = "0 0 23 * * ?";
  155 + /** 场景31~36:每季度首月1号01:00(1/4/7/10月) */
  156 + private String s31Cron = "0 0 1 1 1,4,7,10 ?";
  157 + private String s32Cron = "0 0 1 1 1,4,7,10 ?";
  158 + private String s33Cron = "0 0 1 1 1,4,7,10 ?";
  159 + private String s34Cron = "0 0 1 1 1,4,7,10 ?";
  160 + private String s35Cron = "0 0 1 1 1,4,7,10 ?";
  161 + private String s36Cron = "0 0 1 1 1,4,7,10 ?";
  162 + /** 场景37:每年12月31日23:00 */
  163 + private String s37Cron = "0 0 23 31 12 ?";
  164 + /** 场景38(SYNC0036):每月10号抓上月 */
  165 + private String s38Cron = "0 0 3 10 * ?";
  166 + /** 场景39(SYNC0027):每月5号抓上月 */
  167 + private String s39Cron = "0 0 3 5 * ?";
  168 + /** 场景40(SYNC0028):每月5号抓上月 */
  169 + private String s40Cron = "0 0 3 5 * ?";
  170 + /** 场景41~47(SYNC0029~SYNC0035):每月5号抓上月 */
  171 + private String s41Cron = "0 0 3 5 * ?";
  172 + private String s42Cron = "0 0 3 5 * ?";
  173 + private String s43Cron = "0 0 3 5 * ?";
  174 + private String s44Cron = "0 0 3 5 * ?";
  175 + private String s45Cron = "0 0 3 5 * ?";
  176 + private String s46Cron = "0 0 3 5 * ?";
  177 + private String s47Cron = "0 0 3 5 * ?";
100 178
101 179 public boolean isEnabled() {
102 180 return enabled;
... ... @@ -106,6 +184,33 @@ public class JdyRiskProperties {
106 184 this.enabled = enabled;
107 185 }
108 186
  187 + public String getS1Cron() {
  188 + return s1Cron;
  189 + }
  190 +
  191 + public void setS1Cron(String s1Cron) {
  192 + this.s1Cron = s1Cron;
  193 + }
  194 +
  195 + public String getS2Cron() { return s2Cron; }
  196 + public void setS2Cron(String v) { this.s2Cron = v; }
  197 + public String getS3Cron() { return s3Cron; }
  198 + public void setS3Cron(String v) { this.s3Cron = v; }
  199 + public String getS4Cron() { return s4Cron; }
  200 + public void setS4Cron(String v) { this.s4Cron = v; }
  201 + public String getS5Cron() { return s5Cron; }
  202 + public void setS5Cron(String v) { this.s5Cron = v; }
  203 + public String getS6Cron() { return s6Cron; }
  204 + public void setS6Cron(String v) { this.s6Cron = v; }
  205 + public String getS7Cron() { return s7Cron; }
  206 + public void setS7Cron(String v) { this.s7Cron = v; }
  207 + public String getS8Cron() { return s8Cron; }
  208 + public void setS8Cron(String v) { this.s8Cron = v; }
  209 + public String getS9Cron() { return s9Cron; }
  210 + public void setS9Cron(String v) { this.s9Cron = v; }
  211 + public String getS10Cron() { return s10Cron; }
  212 + public void setS10Cron(String v) { this.s10Cron = v; }
  213 +
109 214 public String getS12Cron() {
110 215 return s12Cron;
111 216 }
... ... @@ -170,6 +275,17 @@ public class JdyRiskProperties {
170 275 this.s19Cron = s19Cron;
171 276 }
172 277
  278 + public String getS20Cron() { return s20Cron; }
  279 + public void setS20Cron(String v) { this.s20Cron = v; }
  280 + public String getS21aCron() { return s21aCron; }
  281 + public void setS21aCron(String v) { this.s21aCron = v; }
  282 + public String getS21bCron() { return s21bCron; }
  283 + public void setS21bCron(String v) { this.s21bCron = v; }
  284 + public String getS21cCron() { return s21cCron; }
  285 + public void setS21cCron(String v) { this.s21cCron = v; }
  286 + public String getS22Cron() { return s22Cron; }
  287 + public void setS22Cron(String v) { this.s22Cron = v; }
  288 +
173 289 public String getS23Cron() {
174 290 return s23Cron;
175 291 }
... ... @@ -201,6 +317,78 @@ public class JdyRiskProperties {
201 317 public void setS26Cron(String s26Cron) {
202 318 this.s26Cron = s26Cron;
203 319 }
  320 +
  321 + public String getS28Cron() { return s28Cron; }
  322 + public void setS28Cron(String v) { this.s28Cron = v; }
  323 + public String getS29Cron() { return s29Cron; }
  324 + public void setS29Cron(String v) { this.s29Cron = v; }
  325 + public String getS30Cron() { return s30Cron; }
  326 + public void setS30Cron(String v) { this.s30Cron = v; }
  327 + public String getS31Cron() { return s31Cron; }
  328 + public void setS31Cron(String v) { this.s31Cron = v; }
  329 + public String getS32Cron() { return s32Cron; }
  330 + public void setS32Cron(String v) { this.s32Cron = v; }
  331 + public String getS33Cron() { return s33Cron; }
  332 + public void setS33Cron(String v) { this.s33Cron = v; }
  333 + public String getS34Cron() { return s34Cron; }
  334 + public void setS34Cron(String v) { this.s34Cron = v; }
  335 + public String getS35Cron() { return s35Cron; }
  336 + public void setS35Cron(String v) { this.s35Cron = v; }
  337 + public String getS36Cron() { return s36Cron; }
  338 + public void setS36Cron(String v) { this.s36Cron = v; }
  339 + public String getS37Cron() { return s37Cron; }
  340 + public void setS37Cron(String v) { this.s37Cron = v; }
  341 + public String getS38Cron() { return s38Cron; }
  342 + public void setS38Cron(String v) { this.s38Cron = v; }
  343 + public String getS39Cron() { return s39Cron; }
  344 + public void setS39Cron(String v) { this.s39Cron = v; }
  345 + public String getS40Cron() { return s40Cron; }
  346 + public void setS40Cron(String v) { this.s40Cron = v; }
  347 + public String getS41Cron() { return s41Cron; }
  348 + public void setS41Cron(String v) { this.s41Cron = v; }
  349 + public String getS42Cron() { return s42Cron; }
  350 + public void setS42Cron(String v) { this.s42Cron = v; }
  351 + public String getS43Cron() { return s43Cron; }
  352 + public void setS43Cron(String v) { this.s43Cron = v; }
  353 + public String getS44Cron() { return s44Cron; }
  354 + public void setS44Cron(String v) { this.s44Cron = v; }
  355 + public String getS45Cron() { return s45Cron; }
  356 + public void setS45Cron(String v) { this.s45Cron = v; }
  357 + public String getS46Cron() { return s46Cron; }
  358 + public void setS46Cron(String v) { this.s46Cron = v; }
  359 + public String getS47Cron() { return s47Cron; }
  360 + public void setS47Cron(String v) { this.s47Cron = v; }
  361 + }
  362 +
  363 + /** 客户 MES 中间库连接配置(Oracle)。 */
  364 + public static class Mes {
  365 + private String url;
  366 + private String username;
  367 + private String password;
  368 +
  369 + public String getUrl() { return url; }
  370 + public void setUrl(String url) { this.url = url; }
  371 + public String getUsername() { return username; }
  372 + public void setUsername(String username) { this.username = username; }
  373 + public String getPassword() { return password; }
  374 + public void setPassword(String password) { this.password = password; }
  375 + }
  376 +
  377 + /** 客户内网人大金仓(KingbaseES)数据库连接配置(设备域场景20/21/22)。 */
  378 + public static class Kingbase {
  379 + private String url = "jdbc:kingbase8://10.144.201.35:54321/qixiao-apaas";
  380 + private String username = "qixiaoadmin";
  381 + private String password = "Qx@20260821.com";
  382 + private String driverClass = "com.kingbase8.Driver";
  383 +
  384 + public String getUrl() { return url; }
  385 + public void setUrl(String url) { this.url = url; }
  386 + public String getUsername() { return username; }
  387 + public void setUsername(String username) { this.username = username; }
  388 + public String getPassword() { return password; }
  389 + public void setPassword(String password) { this.password = password; }
  390 + public String getDriverClass() { return driverClass; }
  391 + public void setDriverClass(String driverClass) { this.driverClass = driverClass; }
204 392 }
205 393
206 394 /** 启效(QX)写回目标配置。 */
... ... @@ -220,6 +408,8 @@ public class JdyRiskProperties {
220 408 private String updateCode;
221 409 /** 新增接口 code(如 11a41Add) */
222 410 private String addCode;
  411 + /** 删除接口 code(如 ilr3ne7bDel,历史回补清库用) */
  412 + private String deleteCode;
223 413 /** 写回数量的字段编号(如 chcbxt) */
224 414 private String countField;
225 415 /** 附件字段编号(如 hciwkz);配置了则把简道云数据 Excel 作为附件写入(关联ID字段自动取 {attachField}Id) */
... ... @@ -301,6 +491,14 @@ public class JdyRiskProperties {
301 491 this.addCode = addCode;
302 492 }
303 493
  494 + public String getDeleteCode() {
  495 + return deleteCode;
  496 + }
  497 +
  498 + public void setDeleteCode(String deleteCode) {
  499 + this.deleteCode = deleteCode;
  500 + }
  501 +
304 502 public String getCountField() {
305 503 return countField;
306 504 }
... ... @@ -381,6 +579,11 @@ public class JdyRiskProperties {
381 579 private boolean yearOnly = false;
382 580 /** 是否仅统计上个月(scenario8/9) */
383 581 private boolean prevMonthOnly = false;
  582 + /**
  583 + * 是否按半月统计(scenario20):
  584 + * 16号执行=当月1号~15号;1号执行=上月16号~上月底。
  585 + */
  586 + private boolean halfMonthOnly = false;
384 587 /** 「升级」字段 code(scenario4/5) */
385 588 private String upField;
386 589 /** 「升级」需排除的取值(scenario4/5,空白始终排除);如 [QR] */
... ... @@ -407,6 +610,11 @@ public class JdyRiskProperties {
407 610 private List<ExcludeForm> excludeForms = new ArrayList<>();
408 611 /** 超期天数(scenario7:入库时间距今超过该天数才保留,默认 180) */
409 612 private int maxAgeDays = 180;
  613 + /**
  614 + * scenario7:按月增量统计超期。参考「上个月最后一天」,保留入库时间距其超过 maxAgeDays 天、
  615 + * 且不在上次运行窗口内的数据(避免每月重复预警)。
  616 + */
  617 + private boolean monthlyOverdueIncremental = false;
410 618 /** 只取这些字段列(scenario7:主表只拉需要的列,减小传输;空=全字段) */
411 619 private List<String> fields = new ArrayList<>();
412 620 /** Excel 附加列取值的字段 code(为空时 scenario1 默认写「命中」) */
... ... @@ -455,6 +663,8 @@ public class JdyRiskProperties {
455 663 private String fuelAmountField;
456 664 /** 起始公里数字段 code(scenario20) */
457 665 private String startKmField;
  666 + /** 结束公里数字段 code(scenario20,油耗=加油量/(本次结束-上次结束)*100) */
  667 + private String endKmField;
458 668 /** 非连续用车子表单字段 code(scenario20,主字段为空时取子表单起始公里数最大值) */
459 669 private String subformField;
460 670 /** 子表单内起始公里数字段 code(scenario20) */
... ... @@ -471,6 +681,235 @@ public class JdyRiskProperties {
471 681 private List<String> companyFields = new ArrayList<>();
472 682 /** 倒数取前 N 名(scenario21,默认 3) */
473 683 private int bottomCount = 3;
  684 + /** 评价得分字段 code(scenario23) */
  685 + private String scoreField;
  686 + /** 平均分阈值(scenario23,低于该值为异常,默认 70) */
  687 + private double avgThreshold = 70;
  688 + /** 月度项目数下限(含,scenario24) */
  689 + private int minMonthCount;
  690 + /** 月度项目数上限(含,scenario24) */
  691 + private int maxMonthCount;
  692 + /** 滞后项目数阈值(scenario24,>= 该值为异常) */
  693 + private int minLagCount;
  694 + /** 滞后判定天数(scenario24/25:实际-计划 > 该天数,默认 31) */
  695 + private int lagDays = 31;
  696 + /** 预算字段 code(scenario25) */
  697 + private String budgetField;
  698 + /** 中选价格字段 code(scenario25) */
  699 + private String priceField;
  700 + /** 偏离率阈值(scenario25,默认 0.4=40%) */
  701 + private double deviationThreshold = 0.4;
  702 +
  703 + public String getScoreField() {
  704 + return scoreField;
  705 + }
  706 +
  707 + public void setScoreField(String scoreField) {
  708 + this.scoreField = scoreField;
  709 + }
  710 +
  711 + public double getAvgThreshold() {
  712 + return avgThreshold;
  713 + }
  714 +
  715 + public void setAvgThreshold(double avgThreshold) {
  716 + this.avgThreshold = avgThreshold;
  717 + }
  718 +
  719 + public int getMinMonthCount() {
  720 + return minMonthCount;
  721 + }
  722 +
  723 + public void setMinMonthCount(int minMonthCount) {
  724 + this.minMonthCount = minMonthCount;
  725 + }
  726 +
  727 + public int getMaxMonthCount() {
  728 + return maxMonthCount;
  729 + }
  730 +
  731 + public void setMaxMonthCount(int maxMonthCount) {
  732 + this.maxMonthCount = maxMonthCount;
  733 + }
  734 +
  735 + public int getMinLagCount() {
  736 + return minLagCount;
  737 + }
  738 +
  739 + public void setMinLagCount(int minLagCount) {
  740 + this.minLagCount = minLagCount;
  741 + }
  742 +
  743 + public int getLagDays() {
  744 + return lagDays;
  745 + }
  746 +
  747 + public void setLagDays(int lagDays) {
  748 + this.lagDays = lagDays;
  749 + }
  750 +
  751 + public String getBudgetField() {
  752 + return budgetField;
  753 + }
  754 +
  755 + public void setBudgetField(String budgetField) {
  756 + this.budgetField = budgetField;
  757 + }
  758 +
  759 + public String getPriceField() {
  760 + return priceField;
  761 + }
  762 +
  763 + public void setPriceField(String priceField) {
  764 + this.priceField = priceField;
  765 + }
  766 +
  767 + public double getDeviationThreshold() {
  768 + return deviationThreshold;
  769 + }
  770 +
  771 + public void setDeviationThreshold(double deviationThreshold) {
  772 + this.deviationThreshold = deviationThreshold;
  773 + }
  774 +
  775 + /** 第二个简道云表单 entry_id(scenario22/28:散件/电泳表) */
  776 + private String secondEntryId;
  777 + /** 第二表单日期字段(scenario22:生产月份;scenario28:结算账期) */
  778 + private String secondDateField;
  779 + /** 第二表单数量字段(scenario22/28) */
  780 + private String secondQtyField;
  781 + /** 第二表单账期开始日期字段(scenario28) */
  782 + private String periodStartField;
  783 + /** 第二表单账期结束日期字段(scenario28) */
  784 + private String periodEndField;
  785 +
  786 + /** 流程开始时间字段(scenario29,如“提出时间”) */
  787 + private String startField;
  788 + /** 超时天数阈值(scenario29,默认30天) */
  789 + private int thresholdDays = 30;
  790 + /** 退货明细子表单字段(scenario30/31) */
  791 + private String subPartField;
  792 + private String subQtyField;
  793 + private String subDateField;
  794 + /** 零件供应商关系表(scenario30/31) */
  795 + private String relEntryId;
  796 + private String relPartField;
  797 + private String relSupplierField;
  798 + private String relEnableField;
  799 + private String relTimeField;
  800 + /** 已冻结标准成本表(scenario30/32) */
  801 + private String costEntryId;
  802 + private String costCodeField;
  803 + private String costValueField;
  804 + /** 取前N名(scenario30/31,默认3) */
  805 + private int topCount = 3;
  806 + /** 库存指标划分表字段(scenario32) */
  807 + private String indicatorCodeField;
  808 + private String indicatorTargetField;
  809 + /** 库存现有量表(scenario32) */
  810 + private String stockEntryId;
  811 + private String stockMonthField;
  812 + private String stockPartField;
  813 + private String stockQtyField;
  814 + private String stockWarehouseField;
  815 + /** 指标外爱信库存表(scenario32,可选) */
  816 + private String aixinEntryId;
  817 + private String aixinPartField;
  818 + /** 库房编码(scenario32) */
  819 + private String warehouseCode;
  820 +
  821 + /** 人大金仓表名(scenario33/34/35,如 biz_waste_warn_stat) */
  822 + private String table;
  823 + /** 处理状态字段(scenario33/34/35,如 handle_status / is_handled) */
  824 + private String handleField;
  825 + /** 视为「未处理」的状态取值(scenario33/34/35) */
  826 + private List<String> handleValues = new ArrayList<>();
  827 + /** 状态码 -> 中文显示(scenario34:3=未处理) */
  828 + private Map<String, String> handleValueLabels = new LinkedHashMap<>();
  829 + /** 统计年份字段(scenario33,如 stat_year) */
  830 + private String statYearField;
  831 + /** 统计月份字段(scenario33,如 stat_month) */
  832 + private String statMonthField;
  833 + /** Excel 导出列(按配置顺序;空则取表全部列) */
  834 + private List<String> columns = new ArrayList<>();
  835 + /** Excel 列中文表头:列名 -> 标题 */
  836 + private Map<String, String> columnLabels = new LinkedHashMap<>();
  837 +
  838 + public String getStartField() { return startField; }
  839 + public void setStartField(String v) { this.startField = v; }
  840 + public int getThresholdDays() { return thresholdDays; }
  841 + public void setThresholdDays(int v) { this.thresholdDays = v; }
  842 + public String getSubPartField() { return subPartField; }
  843 + public void setSubPartField(String v) { this.subPartField = v; }
  844 + public String getSubQtyField() { return subQtyField; }
  845 + public void setSubQtyField(String v) { this.subQtyField = v; }
  846 + public String getSubDateField() { return subDateField; }
  847 + public void setSubDateField(String v) { this.subDateField = v; }
  848 + public String getRelEntryId() { return relEntryId; }
  849 + public void setRelEntryId(String v) { this.relEntryId = v; }
  850 + public String getRelPartField() { return relPartField; }
  851 + public void setRelPartField(String v) { this.relPartField = v; }
  852 + public String getRelSupplierField() { return relSupplierField; }
  853 + public void setRelSupplierField(String v) { this.relSupplierField = v; }
  854 + public String getRelEnableField() { return relEnableField; }
  855 + public void setRelEnableField(String v) { this.relEnableField = v; }
  856 + public String getRelTimeField() { return relTimeField; }
  857 + public void setRelTimeField(String v) { this.relTimeField = v; }
  858 + public String getCostEntryId() { return costEntryId; }
  859 + public void setCostEntryId(String v) { this.costEntryId = v; }
  860 + public String getCostCodeField() { return costCodeField; }
  861 + public void setCostCodeField(String v) { this.costCodeField = v; }
  862 + public String getCostValueField() { return costValueField; }
  863 + public void setCostValueField(String v) { this.costValueField = v; }
  864 + public int getTopCount() { return topCount; }
  865 + public void setTopCount(int v) { this.topCount = v; }
  866 + public String getIndicatorCodeField() { return indicatorCodeField; }
  867 + public void setIndicatorCodeField(String v) { this.indicatorCodeField = v; }
  868 + public String getIndicatorTargetField() { return indicatorTargetField; }
  869 + public void setIndicatorTargetField(String v) { this.indicatorTargetField = v; }
  870 + public String getStockEntryId() { return stockEntryId; }
  871 + public void setStockEntryId(String v) { this.stockEntryId = v; }
  872 + public String getStockMonthField() { return stockMonthField; }
  873 + public void setStockMonthField(String v) { this.stockMonthField = v; }
  874 + public String getStockPartField() { return stockPartField; }
  875 + public void setStockPartField(String v) { this.stockPartField = v; }
  876 + public String getStockQtyField() { return stockQtyField; }
  877 + public void setStockQtyField(String v) { this.stockQtyField = v; }
  878 + public String getStockWarehouseField() { return stockWarehouseField; }
  879 + public void setStockWarehouseField(String v) { this.stockWarehouseField = v; }
  880 + public String getAixinEntryId() { return aixinEntryId; }
  881 + public void setAixinEntryId(String v) { this.aixinEntryId = v; }
  882 + public String getAixinPartField() { return aixinPartField; }
  883 + public void setAixinPartField(String v) { this.aixinPartField = v; }
  884 + public String getWarehouseCode() { return warehouseCode; }
  885 + public void setWarehouseCode(String v) { this.warehouseCode = v; }
  886 + public String getTable() { return table; }
  887 + public void setTable(String v) { this.table = v; }
  888 + public String getHandleField() { return handleField; }
  889 + public void setHandleField(String v) { this.handleField = v; }
  890 + public List<String> getHandleValues() { return handleValues; }
  891 + public void setHandleValues(List<String> v) { this.handleValues = v; }
  892 + public Map<String, String> getHandleValueLabels() { return handleValueLabels; }
  893 + public void setHandleValueLabels(Map<String, String> v) { this.handleValueLabels = v; }
  894 + public String getStatYearField() { return statYearField; }
  895 + public void setStatYearField(String v) { this.statYearField = v; }
  896 + public String getStatMonthField() { return statMonthField; }
  897 + public void setStatMonthField(String v) { this.statMonthField = v; }
  898 + public List<String> getColumns() { return columns; }
  899 + public void setColumns(List<String> v) { this.columns = v; }
  900 + public Map<String, String> getColumnLabels() { return columnLabels; }
  901 + public void setColumnLabels(Map<String, String> v) { this.columnLabels = v; }
  902 +
  903 + public String getSecondEntryId() { return secondEntryId; }
  904 + public void setSecondEntryId(String v) { this.secondEntryId = v; }
  905 + public String getSecondDateField() { return secondDateField; }
  906 + public void setSecondDateField(String v) { this.secondDateField = v; }
  907 + public String getSecondQtyField() { return secondQtyField; }
  908 + public void setSecondQtyField(String v) { this.secondQtyField = v; }
  909 + public String getPeriodStartField() { return periodStartField; }
  910 + public void setPeriodStartField(String v) { this.periodStartField = v; }
  911 + public String getPeriodEndField() { return periodEndField; }
  912 + public void setPeriodEndField(String v) { this.periodEndField = v; }
474 913
475 914 public boolean isPrevThreeMonths() {
476 915 return prevThreeMonths;
... ... @@ -512,6 +951,14 @@ public class JdyRiskProperties {
512 951 this.startKmField = startKmField;
513 952 }
514 953
  954 + public String getEndKmField() {
  955 + return endKmField;
  956 + }
  957 +
  958 + public void setEndKmField(String endKmField) {
  959 + this.endKmField = endKmField;
  960 + }
  961 +
515 962 public String getSubformField() {
516 963 return subformField;
517 964 }
... ... @@ -792,6 +1239,14 @@ public class JdyRiskProperties {
792 1239 this.prevMonthOnly = prevMonthOnly;
793 1240 }
794 1241
  1242 + public boolean isHalfMonthOnly() {
  1243 + return halfMonthOnly;
  1244 + }
  1245 +
  1246 + public void setHalfMonthOnly(boolean halfMonthOnly) {
  1247 + this.halfMonthOnly = halfMonthOnly;
  1248 + }
  1249 +
795 1250 public String getFlagField() {
796 1251 return flagField;
797 1252 }
... ... @@ -872,6 +1327,14 @@ public class JdyRiskProperties {
872 1327 this.maxAgeDays = maxAgeDays;
873 1328 }
874 1329
  1330 + public boolean isMonthlyOverdueIncremental() {
  1331 + return monthlyOverdueIncremental;
  1332 + }
  1333 +
  1334 + public void setMonthlyOverdueIncremental(boolean monthlyOverdueIncremental) {
  1335 + this.monthlyOverdueIncremental = monthlyOverdueIncremental;
  1336 + }
  1337 +
875 1338 public List<String> getFields() {
876 1339 return fields;
877 1340 }
... ...
... ... @@ -6,9 +6,13 @@ import org.springframework.web.bind.annotation.GetMapping;
6 6 import org.springframework.web.bind.annotation.PathVariable;
7 7 import org.springframework.web.bind.annotation.PostMapping;
8 8 import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestParam;
9 10 import org.springframework.web.bind.annotation.RestController;
10 11
11 12 import javax.annotation.Resource;
  13 +import java.util.Arrays;
  14 +import java.util.ArrayList;
  15 +import java.util.List;
12 16 import java.util.Map;
13 17
14 18 /**
... ... @@ -69,4 +73,63 @@ public class JdyRiskController {
69 73 public Map<String, Object> syncOneGet(@PathVariable String scenarioId) {
70 74 return riskService.countAndSyncOne(scenarioId);
71 75 }
  76 +
  77 + /**
  78 + * 一次性历史回补。参数:from/to=数据月份(yyyy-MM);scenarioIds=逗号分隔的 count_x/syncCode(空=全部);
  79 + * dryRun=true 只统计不写回;wipe=true 先清掉本次范围内的旧记录。
  80 + * 例:/api/jdy/risk/backfill?from=2026-01&to=2026-10&dryRun=true
  81 + */
  82 + @PostMapping("/backfill")
  83 + public Map<String, Object> backfill(@RequestParam(required = false, defaultValue = "2026-01") String from,
  84 + @RequestParam(required = false, defaultValue = "2026-10") String to,
  85 + @RequestParam(required = false) String scenarioIds,
  86 + @RequestParam(required = false, defaultValue = "true") boolean dryRun,
  87 + @RequestParam(required = false, defaultValue = "false") boolean wipe,
  88 + @RequestParam(required = false) String toDate) {
  89 + return riskService.backfill(from, to, parseIds(scenarioIds), dryRun, wipe, toDate);
  90 + }
  91 +
  92 + @GetMapping("/backfill")
  93 + public Map<String, Object> backfillGet(@RequestParam(required = false, defaultValue = "2026-01") String from,
  94 + @RequestParam(required = false, defaultValue = "2026-10") String to,
  95 + @RequestParam(required = false) String scenarioIds,
  96 + @RequestParam(required = false, defaultValue = "true") boolean dryRun,
  97 + @RequestParam(required = false, defaultValue = "false") boolean wipe,
  98 + @RequestParam(required = false) String toDate) {
  99 + return riskService.backfill(from, to, parseIds(scenarioIds), dryRun, wipe, toDate);
  100 + }
  101 +
  102 + /**
  103 + * 设备域场景20/21/22(人大金仓)一键历史回补:默认同步 2026-01-01 ~ 2026-10-30。
  104 + * 例:/api/jdy/risk/backfill-db?fromDate=2026-01-01&toDate=2026-10-30&dryRun=false
  105 + */
  106 + @PostMapping("/backfill-db")
  107 + public Map<String, Object> backfillDb(@RequestParam(required = false, defaultValue = "2026-01-01") String fromDate,
  108 + @RequestParam(required = false, defaultValue = "2026-10-30") String toDate,
  109 + @RequestParam(required = false, defaultValue = "true") boolean dryRun,
  110 + @RequestParam(required = false, defaultValue = "false") boolean wipe) {
  111 + return riskService.backfillDb(fromDate, toDate, dryRun, wipe);
  112 + }
  113 +
  114 + @GetMapping("/backfill-db")
  115 + public Map<String, Object> backfillDbGet(@RequestParam(required = false, defaultValue = "2026-01-01") String fromDate,
  116 + @RequestParam(required = false, defaultValue = "2026-10-30") String toDate,
  117 + @RequestParam(required = false, defaultValue = "true") boolean dryRun,
  118 + @RequestParam(required = false, defaultValue = "false") boolean wipe) {
  119 + return riskService.backfillDb(fromDate, toDate, dryRun, wipe);
  120 + }
  121 +
  122 + private static List<String> parseIds(String scenarioIds) {
  123 + List<String> ids = new ArrayList<>();
  124 + if (scenarioIds == null || scenarioIds.trim().isEmpty()) {
  125 + return ids;
  126 + }
  127 + for (String id : Arrays.asList(scenarioIds.split(","))) {
  128 + String v = id.trim();
  129 + if (!v.isEmpty()) {
  130 + ids.add(v);
  131 + }
  132 + }
  133 + return ids;
  134 + }
72 135 }
... ...
  1 +package com.qgutech.qgyun.apaas.sync.jdy.db;
  2 +
  3 +import lombok.extern.slf4j.Slf4j;
  4 +
  5 +import java.sql.Connection;
  6 +import java.sql.DriverManager;
  7 +import java.sql.PreparedStatement;
  8 +import java.sql.ResultSet;
  9 +import java.sql.ResultSetMetaData;
  10 +import java.sql.SQLException;
  11 +import java.util.ArrayList;
  12 +import java.util.LinkedHashMap;
  13 +import java.util.List;
  14 +import java.util.Map;
  15 +
  16 +/**
  17 + * 人大金仓(KingbaseES)风险场景数据读取 DAO(JDBC 直连)。
  18 + * <p>用于设备域场景20/21/22:直接查询客户内网金仓库(KingbaseES 兼容 PostgreSQL 协议)。</p>
  19 + */
  20 +@Slf4j
  21 +public class KingbaseRiskDao {
  22 +
  23 + private final String url;
  24 + private final String username;
  25 + private final String password;
  26 + private final String driverClass;
  27 +
  28 + public KingbaseRiskDao(String url, String username, String password, String driverClass) {
  29 + this.url = url;
  30 + this.username = username;
  31 + this.password = password;
  32 + this.driverClass = driverClass == null || driverClass.trim().isEmpty()
  33 + ? "com.kingbase8.Driver" : driverClass.trim();
  34 + }
  35 +
  36 + /**
  37 + * 执行查询,返回每行一个 Map(列名小写 -> 原始值)。
  38 + *
  39 + * @param sql 已拼装好的 SQL(表名/列名来自配置,值走占位符)
  40 + * @param params 占位符参数
  41 + */
  42 + public List<Map<String, Object>> query(String sql, List<Object> params) {
  43 + log.info("人大金仓场景查询: {}", sql);
  44 + List<Map<String, Object>> rows = new ArrayList<>();
  45 + try {
  46 + Class.forName(driverClass);
  47 + } catch (ClassNotFoundException e) {
  48 + throw new IllegalStateException("加载 Kingbase JDBC 驱动失败: " + driverClass, e);
  49 + }
  50 + try (Connection conn = DriverManager.getConnection(url, username, password);
  51 + PreparedStatement ps = conn.prepareStatement(sql)) {
  52 + if (params != null) {
  53 + for (int i = 0; i < params.size(); i++) {
  54 + ps.setObject(i + 1, params.get(i));
  55 + }
  56 + }
  57 + try (ResultSet rs = ps.executeQuery()) {
  58 + ResultSetMetaData md = rs.getMetaData();
  59 + int n = md.getColumnCount();
  60 + while (rs.next()) {
  61 + Map<String, Object> row = new LinkedHashMap<>(n * 2);
  62 + for (int i = 1; i <= n; i++) {
  63 + row.put(md.getColumnLabel(i).toLowerCase(), rs.getObject(i));
  64 + }
  65 + rows.add(row);
  66 + }
  67 + }
  68 + log.info("人大金仓读取完成: {} 条", rows.size());
  69 + return rows;
  70 + } catch (SQLException e) {
  71 + throw new RuntimeException("查询人大金仓失败: " + e.getMessage(), e);
  72 + }
  73 + }
  74 +}
... ...
... ... @@ -155,6 +155,102 @@ public class JdyExcelExportService {
155 155 }
156 156 }
157 157
  158 + /** 多 Sheet 导出规格。 */
  159 + public static class SheetSpec {
  160 + public String sheetName;
  161 + public String topText;
  162 + public JSONArray widgets;
  163 + public JSONArray rows;
  164 + public String extraHeader;
  165 + public List<String> extraValues;
  166 + public java.util.Set<String> percentFields;
  167 + }
  168 +
  169 + /** 导出多个 Sheet 到同一个 xlsx;每个 Sheet 可在首行放一段说明文字(topText)。 */
  170 + public String exportSheets(String fileName, List<SheetSpec> sheets) {
  171 + try {
  172 + File dir = exportDir();
  173 + File outFile = new File(dir, fileName);
  174 + try (Workbook wb = new XSSFWorkbook()) {
  175 + for (SheetSpec spec : sheets) {
  176 + writeOneSheet(wb, spec == null ? new SheetSpec() : spec);
  177 + }
  178 + try (OutputStream os = new FileOutputStream(outFile)) {
  179 + wb.write(os);
  180 + }
  181 + }
  182 + log.info("导出 Excel(多sheet): {} ({} sheet)", outFile.getAbsolutePath(), sheets.size());
  183 + return outFile.getAbsolutePath();
  184 + } catch (Exception e) {
  185 + log.error("导出 Excel(多sheet) 失败: {}", fileName, e);
  186 + return "FAIL " + fileName + " : " + e.getMessage();
  187 + }
  188 + }
  189 +
  190 + private void writeOneSheet(Workbook wb, SheetSpec spec) {
  191 + Sheet sheet = wb.createSheet(safeSheetName(spec.sheetName));
  192 + int rowIdx = 0;
  193 + if (spec.topText != null && !spec.topText.isEmpty()) {
  194 + Row top = sheet.createRow(0);
  195 + top.createCell(0).setCellValue(spec.topText);
  196 + rowIdx = 1;
  197 + }
  198 + CellStyle headerStyle = wb.createCellStyle();
  199 + Font bold = wb.createFont();
  200 + bold.setBold(true);
  201 + headerStyle.setFont(bold);
  202 + Font redFont = wb.createFont();
  203 + redFont.setBold(true);
  204 + redFont.setColor(IndexedColors.RED.getIndex());
  205 + CellStyle extraHeaderStyle = wb.createCellStyle();
  206 + extraHeaderStyle.setFont(redFont);
  207 +
  208 + JSONArray widgets = spec.widgets == null ? new JSONArray() : spec.widgets;
  209 + JSONArray rows = spec.rows == null ? new JSONArray() : spec.rows;
  210 + int offset = 0;
  211 + Row header = sheet.createRow(rowIdx);
  212 + if (spec.extraHeader != null && !spec.extraHeader.isEmpty()) {
  213 + Cell cell = header.createCell(0);
  214 + cell.setCellValue(spec.extraHeader);
  215 + cell.setCellStyle(extraHeaderStyle);
  216 + offset = 1;
  217 + }
  218 + for (int c = 0; c < widgets.size(); c++) {
  219 + JSONObject w = widgets.getJSONObject(c);
  220 + String label = w.getString("label");
  221 + if (label == null || label.isEmpty()) {
  222 + label = w.getString("widgetName");
  223 + }
  224 + Cell cell = header.createCell(c + offset);
  225 + cell.setCellValue(label);
  226 + cell.setCellStyle(headerStyle);
  227 + }
  228 + rowIdx++;
  229 + for (int r = 0; r < rows.size(); r++) {
  230 + JSONObject rec = rows.getJSONObject(r);
  231 + Row row = sheet.createRow(rowIdx + r);
  232 + if (offset == 1) {
  233 + String ev = (spec.extraValues != null && r < spec.extraValues.size() && spec.extraValues.get(r) != null)
  234 + ? spec.extraValues.get(r) : "";
  235 + row.createCell(0).setCellValue(ev);
  236 + }
  237 + for (int c = 0; c < widgets.size(); c++) {
  238 + String code = widgets.getJSONObject(c).getString("name");
  239 + Object v = rec.get(code);
  240 + String val;
  241 + if (spec.percentFields != null && spec.percentFields.contains(code) && v instanceof Number) {
  242 + val = String.format("%.1f%%", ((Number) v).doubleValue() * 100);
  243 + } else {
  244 + val = formatValue(v);
  245 + }
  246 + row.createCell(c + offset).setCellValue(val);
  247 + }
  248 + }
  249 + for (int c = 0; c < widgets.size() + offset; c++) {
  250 + sheet.setColumnWidth(c, 20 * 256);
  251 + }
  252 + }
  253 +
158 254 private void writeWorkbook(JSONArray widgets, JSONArray data, String extraHeader,
159 255 List<String> extraValues, File outFile) throws Exception {
160 256 writeWorkbook(widgets, data, extraHeader, extraValues, outFile, null, null);
... ...
  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,404 +15,705 @@ 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>();
  60 + private final JdyRiskProperties props;
  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 + }
35 83
36   - /** 固定业务数据(新增时使用):key = syncCode。 */
37   - private static final Map<String, Biz> BIZ = new LinkedHashMap<>();
  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 + }
38 106
39   - static {
40   - BIZ.put("SYNC0001", new Biz("1", "供应商绩效评价", "B97s4IjzEBCqYE6162N", "技术处",
41   - "h1VpqLbLQBUsGNremKy", "张玉林", "ltgYjvQ4Hz4sdq5BA4j", "26MY3mis维修"));
42   - BIZ.put("SYNC0002", new Biz("1", "生产过程质量索赔管理业务线", "qxTEnTMgrphkplbc1ln", "质量管理处",
43   - "h1VpqLbLQBUsGNremKy", "张玉林", "ilKV2ucowXkCZLmcRbI", "责任判定SI-供应商"));
44   - BIZ.put("SYNC0003", new Biz("1", "生产过程质量索赔管理业务线", "qxTEnTMgrphkplbc1ln", "质量管理处",
45   - "h1VpqLbLQBUsGNremKy", "张玉林", "Mqn0b2FMTbJPzw5yf2L", "责任判定SI-工程师"));
46   - BIZ.put("SYNC0004", new Biz("1", "生产过程质量索赔管理业务线", "qxTEnTMgrphkplbc1ln", "质量管理处",
47   - "h1VpqLbLQBUsGNremKy", "张玉林", "JXpTEimiPxT9OyUCdOs", "CR申诉-供应商"));
48   - BIZ.put("SYNC0005", new Biz("1", "生产过程质量索赔管理业务线", "qxTEnTMgrphkplbc1ln", "质量管理处",
49   - "h1VpqLbLQBUsGNremKy", "张玉林", "8UPj3nt0Sx9uZS6dgVF", "CR申诉-工程师"));
50   - BIZ.put("SYNC0006", new Biz("1", "三包索赔管理", "qxTEnTMgrphkplbc1ln", "质量管理处",
51   - "h1VpqLbLQBUsGNremKy", "张玉林", "J15qNYvHMzMRf9e6RZe", "供应商索赔率"));
52   - BIZ.put("SYNC0007", new Biz("1", "三包索赔管理", "qxTEnTMgrphkplbc1ln", "质量管理处",
53   - "h1VpqLbLQBUsGNremKy", "张玉林", "Utom1MrkvERsdUE6t2z", "争议索赔流程"));
54   - BIZ.put("SYNC0008", new Biz("1", "三包索赔管理", "qxTEnTMgrphkplbc1ln", "质量管理处",
55   - "h1VpqLbLQBUsGNremKy", "张玉林", "2Mbjy3qxZuZyLMLZXd7", "三包旧件时长"));
56   - BIZ.put("SYNC0010", new Biz("1", "工料废管理", "qxTEnTMgrphkplbc1ln", "质量管理处",
57   - "h1VpqLbLQBUsGNremKy", "张玉林", "4obqviBjm3eZqkzcLhp", "CR开启-供应商"));
58   - BIZ.put("SYNC0011", new Biz("1", "工料废管理", "qxTEnTMgrphkplbc1ln", "质量管理处",
59   - "h1VpqLbLQBUsGNremKy", "张玉林", "WLT9HuAoXw5EAvSvAhR", "CR开启-工程师"));
60   - Biz b9 = new Biz("1", "三包索赔管理", "qxTEnTMgrphkplbc1ln", "质量管理处",
61   - "h1VpqLbLQBUsGNremKy", "张玉林", "8SUJY8YCGQGNFZ4cy9b", "三包盘点");
62   - b9.sceneMemberId = "lpbRQ5mmp45qcO2lhce";
63   - b9.sceneMemberTitle = "鲁朝冰";
64   - b9.jetcalId = "lpbRQ5mmp45qcO2lhce";
65   - b9.jetcalTitle = "鲁朝冰";
66   - b9.zawlah = "1";
67   - BIZ.put("SYNC009", b9);
68   - // 设备域:资产处置管理 / 设备工程处 / 关存岭
69   - BIZ.put("SYNC0034", new Biz("5", "资产处置管理", "Ljw92oXLsXrkJsnTBp1", "设备工程处",
70   - "visMyujHTrS74mR6kaO", "关存岭", "9wzxQRZ1UvIl0sByuX0", "资质审核信息追溯"));
71   - BIZ.put("SYNC0042", new Biz("5", "资产处置管理", "Ljw92oXLsXrkJsnTBp1", "设备工程处",
72   - "visMyujHTrS74mR6kaO", "关存岭", "wTl8JygmpJ6zBzOoHtv", "车辆离场时长控制"));
73   - BIZ.put("SYNC0048", new Biz("5", "备品备件管理", "Ljw92oXLsXrkJsnTBp1", "设备工程处",
74   - "visMyujHTrS74mR6kaO", "关存岭", "DQXs1TRUrrfufZa3HKy", "多次送货不合格次数"));
75   - Biz bx15 = new Biz("5", "零星工程管理", "Ljw92oXLsXrkJsnTBp1", "设备工程处",
76   - "visMyujHTrS74mR6kaO", "关存岭", "UbK8GlpSq2eEfmeXLMF", "施工方材料或记录不符");
77   - BIZ.put("SYNC0044", bx15);
78   - BIZ.put("SYNC0045", new Biz("5", "零星工程管理", "Ljw92oXLsXrkJsnTBp1", "设备工程处",
79   - "visMyujHTrS74mR6kaO", "关存岭", "z7m71szmZGhyuUFKtUf", "预算金额与结算金额差异"));
80   - BIZ.put("SYNC0046", new Biz("5", "零星工程管理", "Ljw92oXLsXrkJsnTBp1", "设备工程处",
81   - "visMyujHTrS74mR6kaO", "关存岭", "FtUaPIjcnIT9Yg2U0o3", "施工周期逾期"));
82   - BIZ.put("SYNC0047", new Biz("5", "零星工程管理", "Ljw92oXLsXrkJsnTBp1", "设备工程处",
83   - "visMyujHTrS74mR6kaO", "关存岭", "V7q6eDgMf1SmzQla1kw", "验收结算逾期"));
84   - BIZ.put("SYNC0043", new Biz("5", "零星工程管理", "Ljw92oXLsXrkJsnTBp1", "设备工程处",
85   - "visMyujHTrS74mR6kaO", "关存岭", "qSe2WYwCtLJsaNpzDok", "同一个维修项目频次"));
86   - // 管理域:综合业务管理 / 综合管理处 / 徐耀 / 场景成员=石雪松
87   - Biz car95 = new Biz("2", "综合业务管理", "5cr2gzxHL2HhgbLVABh", "综合管理处",
88   - "hjvIVM2neWcnSWjU22M", "徐耀", "K6QPpZ3KZqZoWO3zVG2", "9≤百公里油耗≤13L");
89   - car95.sceneMemberId = "tWOCv8gguUBWI96ZsLK";
90   - car95.sceneMemberTitle = "石雪松";
91   - BIZ.put("SYNC0013", car95);
92   - Biz car75 = new Biz("2", "综合业务管理", "5cr2gzxHL2HhgbLVABh", "综合管理处",
93   - "hjvIVM2neWcnSWjU22M", "徐耀", "P9cgaXrq1at8wUS3JbG", "8≤百公里油耗≤11L");
94   - car75.sceneMemberId = "tWOCv8gguUBWI96ZsLK";
95   - car75.sceneMemberTitle = "石雪松";
96   - BIZ.put("SYNC0014", car75);
97   - Biz carQs = new Biz("2", "综合业务管理", "5cr2gzxHL2HhgbLVABh", "综合管理处",
98   - "hjvIVM2neWcnSWjU22M", "徐耀", "MmvfUhXphWVkDVbfONP", "9≤百公里油耗≤16L");
99   - carQs.sceneMemberId = "tWOCv8gguUBWI96ZsLK";
100   - carQs.sceneMemberTitle = "石雪松";
101   - BIZ.put("SYNC0015", carQs);
102   - // 人力资源域:人力资源管理 / 人力资源处 / 徐耀 / 场景成员=龚勋
103   - Biz hr = new Biz("2", "人力资源管理", "9csExRXNOnUUsG4yx2I", "人力资源处",
104   - "hjvIVM2neWcnSWjU22M", "徐耀", "eO1UPvUJF8Zabs2DNUb", "劳务公司评价");
105   - hr.sceneMemberId = "nFbc8BKA3U24hSgxYs7";
106   - hr.sceneMemberTitle = "龚勋";
107   - BIZ.put("SYNC0016", hr);
  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;
108 116 }
109 117
110   - /** 新增时的固定业务数据。 */
111   - private static class Biz {
112   - final String domain;
113   - final String businessLine;
114   - final String unitId;
115   - final String unitTitle;
116   - final String leaderId;
117   - final String leaderTitle;
118   - final String sceneId;
119   - final String sceneTitle;
120   - // 可选字段(个别场景用)
121   - String sceneMemberId;
122   - String sceneMemberTitle;
123   - String jetcalId;
124   - String jetcalTitle;
125   - String zawlah;
  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 + }
126 128
127   - Biz(String domain, String businessLine, String unitId, String unitTitle,
128   - String leaderId, String leaderTitle, String sceneId, String sceneTitle) {
129   - this.domain = domain;
130   - this.businessLine = businessLine;
131   - this.unitId = unitId;
132   - this.unitTitle = unitTitle;
133   - this.leaderId = leaderId;
134   - this.leaderTitle = leaderTitle;
135   - this.sceneId = sceneId;
136   - this.sceneTitle = sceneTitle;
  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";
137 144 }
  145 + return b;
138 146 }
139 147
140   - private final JdyRiskProperties props;
141   - private final JdyExcelExportService excelExportService;
  148 + private ZonedDateTime now() {
  149 + ZonedDateTime r = this.referenceNow.get();
  150 + return r != null ? r : ZonedDateTime.now(ZONE);
  151 + }
142 152
143 153 public JdyRiskStatisticsService(JdyRiskProperties props, JdyExcelExportService excelExportService) {
144 154 this.props = props;
145 155 this.excelExportService = excelExportService;
146 156 }
147 157
148   - /** 只统计,返回 {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 +
149 169 public Map<String, Object> countAll() {
150   - Map<String, Object> result = new LinkedHashMap<>();
151   - JiandaoYunApi jdy = new JiandaoYunApi(props.getHost());
152   - 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()) {
153 173 try {
154   - String type = s.getType() == null ? "" : s.getType().toLowerCase();
155   - if ("scenario7".equals(type)) {
156   - result.put(s.getId(), buildScenario7Rows(jdy, s).size());
157   - } else if ("scenario11".equals(type)) {
158   - result.put(s.getId(), buildScenario11(jdy, s).count);
159   - } else if (isReasonType(type)) {
160   - result.put(s.getId(), buildReasonRows(jdy, s).count);
161   - } else {
162   - JSONArray rows = buildScopeRows(jdy, s);
163   - result.put(s.getId(), count(s, rows));
164   - }
165   - } catch (Exception e) {
166   - 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);
167 178 result.put(s.getId(), "ERROR: " + e.getMessage());
168 179 }
169 180 }
170 181 return result;
171 182 }
172 183
173   - /** 统计全部场景并按 syncCode 把计数 + Excel 附件写回启效。 */
174 184 public Map<String, Object> countAndSync() {
175   - log.info("========== 开始风险场景统计并写回启效(全部 {} 个场景) ==========", props.getScenarios().size());
176   - Map<String, Object> result = new LinkedHashMap<>();
177   - Context ctx = context();
178   - for (JdyRiskProperties.Scenario s : props.getScenarios()) {
179   - 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);
180 190 }
181   - log.info("========== 风险场景统计并写回完成 ==========");
  191 + log.info("========== \u98ce\u9669\u573a\u666f\u7edf\u8ba1\u5e76\u5199\u56de\u5b8c\u6210 ==========");
182 192 return result;
183 193 }
184 194
185   - /** 只处理单个场景(参数为场景 id 如 count_1,或 syncCode 如 SYNC0001)。 */
186 195 public Map<String, Object> countAndSyncOne(String scenarioId) {
187   - Map<String, Object> result = new LinkedHashMap<>();
188   - JdyRiskProperties.Scenario s = findScenario(scenarioId);
  196 + LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
  197 + JdyRiskProperties.Scenario s = this.findScenario(scenarioId);
189 198 if (s == null) {
190   - result.put("error", "场景不存在: " + scenarioId);
  199 + result.put("error", "\u573a\u666f\u4e0d\u5b58\u5728: " + scenarioId);
191 200 return result;
192 201 }
193   - log.info("========== 开始单场景统计并写回: {} ==========", scenarioId);
194   - 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);
195 204 return result;
196 205 }
197 206
198   - /** 只统计单个场景(不写回)。 */
199 207 public Map<String, Object> countOne(String scenarioId) {
200   - Map<String, Object> result = new LinkedHashMap<>();
201   - JdyRiskProperties.Scenario s = findScenario(scenarioId);
  208 + LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
  209 + JdyRiskProperties.Scenario s = this.findScenario(scenarioId);
202 210 if (s == null) {
203   - result.put("error", "场景不存在: " + scenarioId);
  211 + result.put("error", "\u573a\u666f\u4e0d\u5b58\u5728: " + scenarioId);
204 212 return result;
205 213 }
206   - JiandaoYunApi jdy = new JiandaoYunApi(props.getHost());
  214 + JiandaoYunApi jdy = new JiandaoYunApi(this.props.getHost());
207 215 try {
208   - String type = s.getType() == null ? "" : s.getType().toLowerCase();
209   - if ("scenario7".equals(type)) {
210   - result.put(s.getId(), buildScenario7Rows(jdy, s).size());
211   - } else if ("scenario11".equals(type)) {
212   - result.put(s.getId(), buildScenario11(jdy, s).count);
213   - } else if (isReasonType(type)) {
214   - result.put(s.getId(), buildReasonRows(jdy, s).count);
215   - } else {
216   - result.put(s.getId(), count(s, buildScopeRows(jdy, s)));
217   - }
218   - } catch (Exception e) {
  216 + result.put(s.getId(), this.countOneInternal(jdy, s));
  217 + }
  218 + catch (Exception e) {
219 219 result.put(s.getId(), "ERROR: " + e.getMessage());
220 220 }
221 221 return result;
222 222 }
223 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 +
224 542 private JdyRiskProperties.Scenario findScenario(String scenarioId) {
225 543 if (scenarioId == null) {
226 544 return null;
227 545 }
228   - for (JdyRiskProperties.Scenario s : props.getScenarios()) {
229   - if (scenarioId.equals(s.getId()) || scenarioId.equals(s.getSyncCode())) {
230   - return s;
231   - }
  546 + for (JdyRiskProperties.Scenario s : this.props.getScenarios()) {
  547 + if (!scenarioId.equals(s.getId()) && !scenarioId.equals(s.getSyncCode())) continue;
  548 + return s;
232 549 }
233 550 return null;
234 551 }
235 552
236   - /** 登录启效并一次性拉取全部记录(本地按 syncCode 匹配)。 */
237 553 private Context context() {
238   - JdyRiskProperties.Qx qx = props.getQx();
  554 + JdyRiskProperties.Qx qx = this.props.getQx();
239 555 QxApi qxApi = new QxApi(qx.getBaseUrl());
240 556 String token = qxApi.login(qx.getUsername(), qx.getPassword(), qx.getCorpCode());
241   - JiandaoYunApi jdy = new JiandaoYunApi(props.getHost());
  557 + JiandaoYunApi jdy = new JiandaoYunApi(this.props.getHost());
242 558 JSONArray allRecords = qxApi.pageAll(token, qx.getAppId(), qx.getQueryCode());
243   - 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());
244 560 return new Context(qxApi, token, jdy, allRecords);
245 561 }
246 562
247   - private static class Context {
248   - final QxApi qxApi;
249   - final String token;
250   - final JiandaoYunApi jdy;
251   - final JSONArray allRecords;
252   -
253   - Context(QxApi qxApi, String token, JiandaoYunApi jdy, JSONArray allRecords) {
254   - this.qxApi = qxApi;
255   - this.token = token;
256   - this.jdy = jdy;
257   - this.allRecords = allRecords;
258   - }
259   - }
260   -
261   - /** 单场景:统计 -> 生成 Excel -> 上传附件 -> 更新记录。 */
262 563 private void syncOneScenario(JdyRiskProperties.Scenario s, Context ctx, Map<String, Object> result) {
263   - JdyRiskProperties.Qx qx = props.getQx();
  564 + JdyRiskProperties.Qx qx = this.props.getQx();
264 565 QxApi qxApi = ctx.qxApi;
265 566 String token = ctx.token;
266 567 JiandaoYunApi jdy = ctx.jdy;
267 568 JSONArray allRecords = ctx.allRecords;
268 569 try {
269   - String type = s.getType() == null ? "" : s.getType().toLowerCase();
270   - JdyExcelExportService.setLookup(buildLookupMap(jdy, s));
271   - JSONArray rows;
272 570 JSONArray widgets;
  571 + JSONArray rows;
273 572 long count;
  573 + String type = s.getType() == null ? "" : s.getType().toLowerCase();
  574 + Biz sceneBiz = JdyRiskStatisticsService.bizOf(s);
  575 + JdyExcelExportService.setLookup(this.buildLookupMap(jdy, s));
274 576 String extraHeader = null;
275 577 List<String> extraValues = null;
276   - if ("scenario7".equals(type)) {
277   - rows = buildScenario7Rows(jdy, s);
  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);
278 587 count = rows.size();
279   - widgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId());
  588 + widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
280 589 } else if ("scenario11".equals(type)) {
281   - Built11 b = buildScenario11(jdy, s);
  590 + Built11 b = this.buildScenario11(jdy, s);
282 591 rows = b.excelRows;
283 592 count = b.count;
284 593 widgets = b.excelWidgets;
285   - } else if (isReasonType(type)) {
286   - BuiltReason br = buildReasonRows(jdy, s);
  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);
287 603 rows = br.rows;
288 604 count = br.count;
289   - widgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId());
290   - extraHeader = "原因";
  605 + widgets = jdy.listWidgets(this.props.getApiKey(), s.getAppId(), s.getEntryId());
  606 + extraHeader = "\u539f\u56e0";
291 607 extraValues = br.reasons;
292 608 } else {
293   - rows = buildScopeRows(jdy, s);
294   - count = count(s, rows);
295   - widgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId());
  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());
296 613 if (!"scenario10".equals(type)) {
297   - if ("scenario4".equals(type) || "scenario6".equals(type) || "scenario8".equals(type)) {
298   - extraHeader = "预警供应商";
299   - } else if ("scenario5".equals(type) || "scenario9".equals(type)) {
300   - extraHeader = "预警工程师";
301   - } else {
302   - extraHeader = "筛选结果";
303   - }
304   - extraValues = buildExtraValues(s, rows);
  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);
305 616 }
306 617 if (s.isOnlyWarnRows()) {
307   - rows = filterWarnRows(s, rows);
308   - extraValues = buildExtraValues(s, rows);
  618 + rows = this.filterWarnRows(s, rows);
  619 + extraValues = this.buildExtraValues(s, rows);
309 620 }
310   - // 按名称(分组字段,其次附加列字段)排序,方便阅读
311   - String sortField = s.getGroupField() != null && !s.getGroupField().isEmpty()
312   - ? s.getGroupField() : s.getExtraField();
  621 + String string = sortField = s.getGroupField() != null && !s.getGroupField().isEmpty() ? s.getGroupField() : s.getExtraField();
313 622 if (sortField != null && !sortField.isEmpty()) {
314   - sortRows(rows, sortField);
  623 + JdyRiskStatisticsService.sortRows(rows, sortField);
315 624 if (extraHeader != null) {
316   - extraValues = buildExtraValues(s, rows);
  625 + extraValues = this.buildExtraValues(s, rows);
317 626 }
318 627 }
319 628 }
320 629 result.put(s.getId(), count);
321   - log.info("场景[{}] 命中={} (参与统计{}条)", s.getId(), count, rows.size());
322   -
323   - // 设备域场景:命中 0 条时不生成 Excel、不上传附件(仍回写计数)
324   - boolean skipAttach = isReasonType(type) && count == 0;
  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;
325 632 String fileId = null;
326 633 String fileName = null;
327   - long size = 0;
  634 + long size = 0L;
328 635 if (skipAttach) {
329   - log.info("场景[{}] 命中0条,跳过 Excel 生成与附件上传,仅回写计数", s.getId());
  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());
330 637 } else {
331   - java.util.Set<String> percentFields = s.getPercentFields().isEmpty()
332   - ? null : new java.util.HashSet<>(s.getPercentFields());
  638 + String path;
333 639 fileName = JdyExcelExportService.nowFileName();
334   - Biz sheetBiz = BIZ.get(s.getSyncCode());
335   - String sheetName = sheetBiz != null ? sheetBiz.sceneTitle : s.getName();
336   - String path = excelExportService.exportRows(widgets, rows, extraHeader, extraValues, fileName, sheetName, percentFields);
  640 + if (customSheets != null) {
  641 + path = this.excelExportService.exportSheets(fileName, customSheets);
  642 + } else {
  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);
  647 + }
337 648 if (path == null || path.startsWith("FAIL")) {
338   - throw new IllegalStateException("Excel 导出失败: " + path);
  649 + throw new IllegalStateException("Excel \u5bfc\u51fa\u5931\u8d25: " + path);
339 650 }
340 651 fileId = qxApi.uploadFile(token, new File(path), fileName);
341 652 size = new File(path).length();
342 653 }
343   -
344   - long now = System.currentTimeMillis();
  654 + long now = this.now().toInstant().toEpochMilli();
345 655 String syncCode = s.getSyncCode();
346   -
347   - // 当天(预警日期)已有该场景数据 → 更新;否则 → 新增
348   - JSONObject todayRec = findTodayRecord(allRecords, syncCode, qx.getTimeField());
  656 + JSONObject todayRec = this.findTodayRecord(allRecords, s, sceneBiz, qx.getTimeField());
349 657 if (todayRec != null) {
350   - todayRec.put(qx.getCountField(), count);
351   - setTimeFields(todayRec, qx, now);
  658 + todayRec.put(qx.getCountField(), (Object)count);
  659 + JdyRiskStatisticsService.setTimeFields(todayRec, qx, now);
352 660 if (!skipAttach && qx.getAttachField() != null && !qx.getAttachField().isEmpty()) {
353   - todayRec.put(qx.getAttachField(), buildAttach(fileId, fileName, size));
354   - todayRec.put(qx.getAttachField() + "Id", fileId);
  661 + todayRec.put(qx.getAttachField(), (Object)this.buildAttach(fileId, fileName, size));
  662 + todayRec.put(qx.getAttachField() + "Id", (Object)fileId);
355 663 }
356 664 qxApi.updateData(token, qx.getAppId(), qx.getUpdateCode(), todayRec);
357   - log.info("当天已存在→更新成功: syncCode={} id={} {}={} 附件={}", syncCode,
358   - todayRec.getString("id"), qx.getCountField(), count, fileName);
  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});
359 666 } else {
360   - JSONObject template = findRecordBySyncCode(allRecords, syncCode);
361 667 JSONObject addBody;
  668 + JSONObject template = this.findRecordBySyncCode(allRecords, s, sceneBiz);
362 669 if (template != null) {
363   - addBody = cloneTemplate(template, qx, syncCode, count, now, fileId, fileName, size, skipAttach);
364   - log.info("当天无数据→以[{}]现有记录为模板新增", syncCode);
  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);
365 672 } else {
366   - Biz biz = BIZ.get(syncCode);
  673 + Biz biz = sceneBiz;
367 674 if (biz == null) {
368   - throw new IllegalStateException("未配置该场景的新增业务数据(模板): " + syncCode);
  675 + throw new IllegalStateException("\u672a\u914d\u7f6e\u8be5\u573a\u666f\u7684\u65b0\u589e\u4e1a\u52a1\u6570\u636e(\u6a21\u677f): " + syncCode);
369 676 }
370   - addBody = buildAddBody(biz, qx, syncCode, count, now, fileId, fileName, size);
  677 + addBody = this.buildAddBody(biz, qx, syncCode, count, now, fileId, fileName, size);
371 678 }
372 679 String newId = qxApi.addData(token, qx.getAppId(), qx.getAddCode(), addBody);
373   - log.info("当天无数据→新增成功: syncCode={} newId={} {}={} 附件={}", syncCode,
374   - newId, qx.getCountField(), count, fileName);
  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});
375 681 }
376   - } catch (Exception e) {
377   - log.error("场景[{}] 写回失败", s.getId(), e);
  682 + }
  683 + catch (Exception e) {
  684 + log.error("\u573a\u666f[{}] \u5199\u56de\u5931\u8d25", (Object)s.getId(), (Object)e);
378 685 result.put(s.getId() + "_error", e.getMessage());
379 686 }
380 687 }
381 688
382   - /* ==================== 范围过滤 ==================== */
383   -
384   - /** 按场景统计周期过滤数据:全量 / 当月 / 当季度 / 上一季度 / 当年 / 上月。 */
385 689 private JSONArray filterScope(JSONArray all, JdyRiskProperties.Scenario s) {
386   - if (!s.isMonthOnly() && !s.isQuarterOnly() && !s.isPrevQuarterOnly()
387   - && !s.isYearOnly() && !s.isPrevMonthOnly() && !s.isPrevThreeMonths()) {
  690 + ZonedDateTime hmEnd;
  691 + ZonedDateTime hmStart;
  692 + if (!(s.isMonthOnly() || s.isQuarterOnly() || s.isPrevQuarterOnly() || s.isYearOnly() || s.isPrevMonthOnly() || s.isPrevThreeMonths() || s.isHalfMonthOnly())) {
388 693 return all;
389 694 }
390   - ZonedDateTime now = ZonedDateTime.now(ZONE);
391   - ZonedDateTime qStart = quarterStart(now);
392   - ZonedDateTime qEnd = qStart.plusMonths(3);
393   - ZonedDateTime pqStart = qStart.minusMonths(3);
  695 + ZonedDateTime now = this.now();
  696 + ZonedDateTime qStart = JdyRiskStatisticsService.quarterStart(now);
  697 + ZonedDateTime qEnd = qStart.plusMonths(3L);
  698 + ZonedDateTime pqStart = qStart.minusMonths(3L);
394 699 ZonedDateTime yStart = now.withDayOfYear(1).truncatedTo(ChronoUnit.DAYS);
395   - ZonedDateTime pmStart = now.minusMonths(1).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
  700 + ZonedDateTime pmStart = now.minusMonths(1L).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
396 701 ZonedDateTime pmEnd = now.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
397   - ZonedDateTime p3Start = now.minusMonths(3).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 + }
398 711 String month = now.format(MONTH_FMT);
399 712 JSONArray out = new JSONArray();
400   - for (int i = 0; i < all.size(); i++) {
  713 + for (int i = 0; i < all.size(); ++i) {
401 714 JSONObject row = all.getJSONObject(i);
402   - ZonedDateTime dt = parseTime(row.getString(s.getDateField()));
403   - if (dt == null) {
404   - continue;
405   - }
  715 + ZonedDateTime dt = JdyRiskStatisticsService.parseTime(row.getString(s.getDateField()));
  716 + if (dt == null) continue;
406 717 boolean keep = false;
407 718 if (s.isQuarterOnly()) {
408 719 keep = !dt.isBefore(qStart) && dt.isBefore(qEnd);
... ... @@ -410,6 +721,8 @@ public class JdyRiskStatisticsService {
410 721 keep = !dt.isBefore(pqStart) && dt.isBefore(qStart);
411 722 } else if (s.isYearOnly()) {
412 723 keep = !dt.isBefore(yStart) && !dt.isAfter(now);
  724 + } else if (s.isHalfMonthOnly()) {
  725 + keep = !dt.isBefore(hmStart) && dt.isBefore(hmEnd);
413 726 } else if (s.isPrevMonthOnly()) {
414 727 keep = !dt.isBefore(pmStart) && dt.isBefore(pmEnd);
415 728 } else if (s.isPrevThreeMonths()) {
... ... @@ -417,604 +730,1361 @@ public class JdyRiskStatisticsService {
417 730 } else if (s.isMonthOnly()) {
418 731 keep = month.equals(dt.format(MONTH_FMT));
419 732 }
420   - if (keep) {
421   - out.add(row);
422   - }
  733 + if (!keep) continue;
  734 + out.add((Object)row);
423 735 }
424 736 return out;
425 737 }
426 738
427   - /* ==================== 计数 ==================== */
428   -
429 739 private long count(JdyRiskProperties.Scenario s, JSONArray rows) {
430   - String type = s.getType() == null ? "" : s.getType().toLowerCase();
431   - switch (type) {
432   - case "scenario1":
433   - return countScenario1(s, rows);
434   - case "scenario2":
435   - return countScenario2(s, rows);
436   - case "scenario3":
437   - return countScenario3(s, rows);
438   - case "scenario4":
439   - case "scenario5":
440   - return countGroupByUp(s, rows);
441   - case "scenario6":
442   - return warningGroupsByCount(s, rows).size();
443   - case "scenario8":
444   - case "scenario9":
445   - return warningGroupsByRatio(s, rows).size();
446   - case "scenario10":
  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": {
447 763 return rows.size();
448   - default:
449   - throw new IllegalStateException("未知场景类型: " + s.getType());
  764 + }
450 765 }
  766 + throw new IllegalStateException("\u672a\u77e5\u573a\u666f\u7c7b\u578b: " + s.getType());
451 767 }
452 768
453   - /** 场景1:总计>=5 且 差值>=1 且 flowState=进行中。 */
454 769 private long countScenario1(JdyRiskProperties.Scenario s, JSONArray data) {
455   - long hit = 0;
456   - for (int i = 0; i < data.size(); i++) {
  770 + long hit = 0L;
  771 + for (int i = 0; i < data.size(); ++i) {
457 772 JSONObject row = data.getJSONObject(i);
458   - double total = num(row, s.getTotalField());
459   - double diff = num(row, s.getDiffField());
  773 + double total = JdyRiskStatisticsService.num(row, s.getTotalField());
  774 + double diff = JdyRiskStatisticsService.num(row, s.getDiffField());
460 775 Integer flow = row.getInteger("flowState");
461   - if (total >= 5 && diff >= 1 && flow != null && flow == s.getInProgressState()) {
462   - hit++;
463   - }
  776 + if (!(total >= 5.0) || !(diff >= 1.0) || flow == null || flow.intValue() != s.getInProgressState()) continue;
  777 + ++hit;
464 778 }
465 779 return hit;
466 780 }
467 781
468   - /** 场景2:按供应商分组,SI数量/问题数量合计>60% 且 合计>=5 的供应商个数。 */
469 782 private long countScenario2(JdyRiskProperties.Scenario s, JSONArray data) {
470   - Map<String, double[]> byGroup = new LinkedHashMap<>();
471   - 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) {
472 785 JSONObject row = data.getJSONObject(i);
473   - String group = orEmpty(row.getString(s.getGroupField()));
474   - double qty = num(row, s.getQtyField());
  786 + String group = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
  787 + double qty = JdyRiskStatisticsService.num(row, s.getQtyField());
475 788 double[] agg = byGroup.computeIfAbsent(group, k -> new double[2]);
476   - agg[0] += qty;
477   - if ("SI".equalsIgnoreCase(row.getString(s.getSiField()))) {
478   - agg[1] += qty;
479   - }
  789 + agg[0] = agg[0] + qty;
  790 + if (!"SI".equalsIgnoreCase(row.getString(s.getSiField()))) continue;
  791 + agg[1] = agg[1] + qty;
480 792 }
481   - long hit = 0;
  793 + long hit = 0L;
482 794 for (double[] agg : byGroup.values()) {
483   - if (agg[0] >= 5 && (agg[1] / agg[0]) > 0.6) {
484   - hit++;
485   - }
  795 + if (!(agg[0] >= 5.0) || !(agg[1] / agg[0] > 0.6)) continue;
  796 + ++hit;
486 797 }
487 798 return hit;
488 799 }
489 800
490   - /** 场景3:SI占比>60% 且 总问题数>=5 的行数(工程师个数)。 */
491 801 private long countScenario3(JdyRiskProperties.Scenario s, JSONArray data) {
492   - long hit = 0;
493   - for (int i = 0; i < data.size(); i++) {
  802 + long hit = 0L;
  803 + for (int i = 0; i < data.size(); ++i) {
494 804 JSONObject row = data.getJSONObject(i);
495   - double total = num(row, s.getTotalField());
496   - double ratio = num(row, s.getRatioField());
497   - if (total >= 5 && ratio > 0.6) {
498   - hit++;
499   - }
  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;
500 809 }
501 810 return hit;
502 811 }
503 812
504   - /** 场景4/5:升级不含排除值且非空,按分组计数,分组次数 >= minCount 的命中分组个数。 */
505 813 private long countGroupByUp(JdyRiskProperties.Scenario s, JSONArray data) {
506   - return warningGroupsByUp(s, data).size();
  814 + return this.warningGroupsByUp(s, data).size();
507 815 }
508 816
509   - /** 场景4/5:命中分组集合(升级不含排除值且非空,分组计数 >= minCount)。 */
510 817 private Set<String> warningGroupsByUp(JdyRiskProperties.Scenario s, JSONArray data) {
511   - Map<String, Integer> counts = new LinkedHashMap<>();
512   - 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) {
513 820 JSONObject row = data.getJSONObject(i);
514   - if (isUpHit(s, row)) {
515   - String g = orEmpty(row.getString(s.getGroupField()));
516   - counts.merge(g, 1, Integer::sum);
517   - }
  821 + if (!this.isUpHit(s, row)) continue;
  822 + String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
  823 + counts.merge(g, 1, Integer::sum);
518 824 }
519 825 int threshold = Math.max(1, s.getMinCount());
520   - Set<String> warn = new LinkedHashSet<>();
521   - for (Map.Entry<String, Integer> e : counts.entrySet()) {
522   - if (e.getValue() >= threshold) {
523   - warn.add(e.getKey());
524   - }
  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());
525 830 }
526 831 return warn;
527 832 }
528 833
529   - /** 场景6:按分组字段计数,分组次数 >= minCount 的命中分组集合。 */
530 834 private Set<String> warningGroupsByCount(JdyRiskProperties.Scenario s, JSONArray data) {
531   - Map<String, Integer> counts = new LinkedHashMap<>();
532   - 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) {
533 837 JSONObject row = data.getJSONObject(i);
534   - String g = orEmpty(row.getString(s.getGroupField()));
  838 + String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
535 839 counts.merge(g, 1, Integer::sum);
536 840 }
537 841 int threshold = Math.max(1, s.getMinCount());
538   - Set<String> warn = new LinkedHashSet<>();
539   - for (Map.Entry<String, Integer> e : counts.entrySet()) {
540   - if (e.getValue() >= threshold) {
541   - warn.add(e.getKey());
542   - }
  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());
543 846 }
544 847 return warn;
545 848 }
546 849
547   - /** 场景8/9:按分组字段,flagField==flagValue 的条数 / 总条数 > ratioThreshold 的命中分组集合。 */
548 850 private Set<String> warningGroupsByRatio(JdyRiskProperties.Scenario s, JSONArray data) {
549   - Map<String, int[]> byGroup = new LinkedHashMap<>(); // [总数, 命中数]
550   - 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) {
551 853 JSONObject row = data.getJSONObject(i);
552   - String g = orEmpty(row.getString(s.getGroupField()));
  854 + String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
553 855 int[] agg = byGroup.computeIfAbsent(g, k -> new int[2]);
554   - agg[0]++;
555   - if (s.getFlagValue() != null && s.getFlagValue().equalsIgnoreCase(row.getString(s.getFlagField()))) {
556   - agg[1]++;
557   - }
  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;
558 859 }
559   - Set<String> warn = new LinkedHashSet<>();
  860 + LinkedHashSet<String> warn = new LinkedHashSet<String>();
560 861 double th = s.getRatioThreshold();
561   - for (Map.Entry<String, int[]> e : byGroup.entrySet()) {
562   - int[] agg = e.getValue();
563   - if (agg[0] > 0 && ((double) agg[1] / agg[0]) > th) {
564   - warn.add(e.getKey());
565   - }
  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());
566 866 }
567 867 return warn;
568 868 }
569 869
570   - /**
571   - * 场景7:多表关联 + 超期过滤(分批流式,防大表 OOM)。
572   - * <p>① 收集排除表单的条码集合;② 流式遍历主表:条码命中排除集合则丢弃;③ 剩余按入库时间超过 maxAgeDays 天保留。
573   - */
574 870 private JSONArray buildScenario7Rows(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
575   - Set<String> exclude = new LinkedHashSet<>();
  871 + Instant lowerCutoff;
  872 + Instant cutoff;
  873 + LinkedHashSet exclude = new LinkedHashSet();
576 874 for (JdyRiskProperties.ExcludeForm ef : s.getExcludeForms()) {
577   - if (ef == null || ef.getEntryId() == null || ef.getBarcodeField() == null) {
578   - continue;
579   - }
580   - final JdyRiskProperties.ExcludeForm cur = ef;
581   - jdy.forEachPage(props.getApiKey(), s.getAppId(), cur.getEntryId(),
582   - java.util.Collections.singletonList(cur.getBarcodeField()), page -> {
583   - 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) {
584 879 String b = page.getJSONObject(i).getString(cur.getBarcodeField());
585   - if (b != null && !b.trim().isEmpty()) {
586   - exclude.add(b.trim());
587   - }
  880 + if (b == null || b.trim().isEmpty()) continue;
  881 + exclude.add(b.trim());
588 882 }
589 883 });
590   - 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;
591 895 }
592   -
593   - java.time.Instant cutoff = ZonedDateTime.now(ZONE)
594   - .minusDays(Math.max(0, s.getMaxAgeDays())).toInstant();
595 896 JSONArray kept = new JSONArray();
596   - final int[] scanned = {0};
597   - jdy.forEachPage(props.getApiKey(), s.getAppId(), s.getEntryId(), s.getFields(), page -> {
598   - for (int i = 0; i < page.size(); i++) {
599   - 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;
600 903 JSONObject row = page.getJSONObject(i);
601 904 String barcode = row.getString(s.getBarcodeField());
602   - if (barcode != null && exclude.contains(barcode.trim())) {
603   - continue; // 条码在出库/抵扣表中出现 → 过滤掉
604   - }
605   - ZonedDateTime inTime = parseTime(row.getString(s.getDateField()));
606   - if (inTime == null) {
607   - continue;
608   - }
609   - if (inTime.toInstant().isBefore(cutoff)) {
610   - kept.add(row); // 入库时间超过 maxAgeDays 天
611   - }
  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);
612 907 }
613 908 });
614   - log.info("场景7 主表扫描={}条, 过滤后保留={}条 (排除条码={}, 超期阈值={}天)",
615   - 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()});
616 910 return kept;
617 911 }
618 912
619   - /** scenario10:保留 |diffField| > absThreshold 的行(Excel 也只放这些行)。 */
620 913 private JSONArray filterByAbsThreshold(JdyRiskProperties.Scenario s, JSONArray rows) {
621 914 JSONArray out = new JSONArray();
622   - for (int i = 0; i < rows.size(); i++) {
  915 + for (int i = 0; i < rows.size(); ++i) {
623 916 JSONObject row = rows.getJSONObject(i);
624   - if (Math.abs(num(row, s.getDiffField())) > s.getAbsThreshold()) {
625   - out.add(row);
626   - }
  917 + if (!(Math.abs(JdyRiskStatisticsService.num(row, s.getDiffField())) > s.getAbsThreshold())) continue;
  918 + out.add((Object)row);
627 919 }
628 920 return out;
629 921 }
630 922
631   - /** 取场景参与统计的行:全量/周期过滤 + scenario10 的阈值过滤(scenario7 另走流式)。 */
632 923 private JSONArray buildScopeRows(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
633   - JSONArray all = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId());
634   - JSONArray scoped = filterScope(all, s);
635   - String type = s.getType() == null ? "" : s.getType().toLowerCase();
  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();
636 928 if ("scenario10".equals(type)) {
637   - return filterByAbsThreshold(s, scoped);
  929 + return this.filterByAbsThreshold(s, scoped);
638 930 }
639 931 return scoped;
640 932 }
641 933
642   - /** scenario11 结果:命中数 + Excel 行 + 合成列。 */
643   - private static class Built11 {
644   - long count;
645   - JSONArray excelRows;
646   - JSONArray excelWidgets;
647   - }
648   -
649   - /**
650   - * scenario11:A(系统库存明细) 与 B(实盘) 的条码集合运算。
651   - * ①A、B 都去掉 C(三包抵扣) 命中的条码;②A、B 去掉两边相同的条码;
652   - * ③A 剩余=正、B 剩余=负,预警数量=正+负;Excel 记录两边剩余明细。
653   - */
654 934 private Built11 buildScenario11(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
655   - JSONArray aWidgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId());
656   - JSONArray aRows = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId());
657   - JSONArray bWidgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getCompareEntryId());
658   - JSONArray bRows = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getCompareEntryId());
659   -
660   - Set<String> cSet = new LinkedHashSet<>();
  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>();
661 940 for (JdyRiskProperties.ExcludeForm ef : s.getExcludeForms()) {
662   - if (ef == null || ef.getEntryId() == null || ef.getBarcodeField() == null) {
663   - continue;
664   - }
  941 + if (ef == null || ef.getEntryId() == null || ef.getBarcodeField() == null) continue;
665 942 final JdyRiskProperties.ExcludeForm cur = ef;
666   - jdy.forEachPage(props.getApiKey(), s.getAppId(), cur.getEntryId(),
667   - java.util.Collections.singletonList(cur.getBarcodeField()), page -> {
668   - for (int i = 0; i < page.size(); i++) {
669   - String b = page.getJSONObject(i).getString(cur.getBarcodeField());
670   - if (b != null && !b.trim().isEmpty()) {
671   - cSet.add(b.trim());
672   - }
673   - }
674   - });
  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 + });
675 950 }
676   -
677   - Map<String, List<JSONObject>> aMap = groupByBarcode(aRows, s.getBarcodeField());
678   - Map<String, List<JSONObject>> bMap = groupByBarcode(bRows, s.getCompareBarcodeField());
  951 + Map<String, List<JSONObject>> aMap = JdyRiskStatisticsService.groupByBarcode(aRows, s.getBarcodeField());
  952 + Map<String, List<JSONObject>> bMap = JdyRiskStatisticsService.groupByBarcode(bRows, s.getCompareBarcodeField());
679 953 for (String k : cSet) {
680 954 aMap.remove(k);
681 955 bMap.remove(k);
682 956 }
683   - for (String k : new ArrayList<>(aMap.keySet())) {
  957 + for (String k : new ArrayList<String>(aMap.keySet())) {
684 958 List<JSONObject> bl = bMap.get(k);
685   - if (bl == null) {
686   - continue;
687   - }
  959 + if (bl == null) continue;
688 960 List<JSONObject> al = aMap.get(k);
689 961 int common = Math.min(al.size(), bl.size());
690   - for (int i = 0; i < common; i++) {
  962 + for (int i2 = 0; i2 < common; ++i2) {
691 963 al.remove(al.size() - 1);
692 964 bl.remove(bl.size() - 1);
693 965 }
694 966 if (al.isEmpty()) {
695 967 aMap.remove(k);
696 968 }
697   - if (bl.isEmpty()) {
698   - bMap.remove(k);
699   - }
  969 + if (!bl.isEmpty()) continue;
  970 + bMap.remove(k);
700 971 }
701   -
702 972 JSONArray excelRows = new JSONArray();
703   - long pos = 0;
704   - long neg = 0;
  973 + long pos = 0L;
  974 + long neg = 0L;
705 975 for (Map.Entry<String, List<JSONObject>> e : aMap.entrySet()) {
706 976 for (JSONObject row : e.getValue()) {
707   - row.put("__type", "正");
708   - excelRows.add(row);
709   - pos++;
  977 + row.put("__type", (Object)"\u6b63");
  978 + excelRows.add((Object)row);
  979 + ++pos;
710 980 }
711 981 }
712 982 for (Map.Entry<String, List<JSONObject>> e : bMap.entrySet()) {
713 983 for (JSONObject row : e.getValue()) {
714   - row.put("__type", "负");
715   - excelRows.add(row);
716   - neg++;
  984 + row.put("__type", (Object)"\u8d1f");
  985 + excelRows.add((Object)row);
  986 + ++neg;
717 987 }
718 988 }
719   -
720 989 JSONArray widgets = new JSONArray();
721   - widgets.add(syntheticWidget("__type", "类型(正/负)"));
722   - for (int i = 0; i < aWidgets.size(); i++) {
723   - widgets.add(aWidgets.getJSONObject(i));
  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));
724 993 }
725   - for (int i = 0; i < bWidgets.size(); i++) {
726   - widgets.add(bWidgets.getJSONObject(i));
  994 + for (int i = 0; i < bWidgets.size(); ++i) {
  995 + widgets.add((Object)bWidgets.getJSONObject(i));
727 996 }
728   -
729 997 Built11 built = new Built11();
730 998 built.count = pos + neg;
731 999 built.excelRows = excelRows;
732 1000 built.excelWidgets = widgets;
733   - log.info("场景11 A={}条 B={}条 C条码={} -> 正={} 负={} 预警数量={}",
734   - aRows.size(), bRows.size(), cSet.size(), pos, neg, built.count);
  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});
735 1002 return built;
736 1003 }
737 1004
738   - /** scenario12/13 结果:命中数 + 仅命中行 + 原因列(与命中行一一对应)。 */
739   - private static class BuiltReason {
740   - long count;
741   - JSONArray rows = new JSONArray();
742   - List<String> reasons = new ArrayList<>();
  1005 + private static boolean isDbType(String type) {
  1006 + return "scenario33".equals(type) || "scenario34".equals(type) || "scenario35".equals(type);
743 1007 }
744 1008
745 1009 private static boolean isReasonType(String type) {
746   - return "scenario12".equals(type) || "scenario13".equals(type)
747   - || "scenario14".equals(type) || "scenario15".equals(type)
748   - || "scenario16".equals(type) || "scenario17".equals(type)
749   - || "scenario18".equals(type) || "scenario19".equals(type)
750   - || "scenario20".equals(type) || "scenario21".equals(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);
751 1011 }
752 1012
753 1013 /**
754   - * scenario12 / scenario13:先按统计周期过滤,再逐条判定异常并生成「原因」。
755   - * <ul>
756   - * <li>scenario12:参与人员N有值但对应手写签字确认为空 → 命中,原因「参与人员N未签字确认」</li>
757   - * <li>scenario13:停留时长&gt;阈值 且(是否异常=异常值 或 异常原因说明为空)→ 命中</li>
758   - * </ul>
  1014 + * 设备域场景20/21/22:直接查询人大金仓表,取「未处理/未处置」数据。
  1015 + * <p>Excel 首列固定为「原因」(表头红色),内容为「处理状态为未处理/未处置」。</p>
  1016 + */
  1017 + private BuiltDb buildDbRows(JdyRiskProperties.Scenario s) {
  1018 + String type = s.getType() == null ? "" : s.getType().toLowerCase();
  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 + }
  1031 + }
  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
759 1159 */
760 1160 private BuiltReason buildReasonRows(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
761   - JSONArray all = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId());
762   - JSONArray scoped = filterScope(all, s);
  1161 + JSONArray all = this.listAllDataCached(jdy, s.getAppId(), s.getEntryId());
  1162 + JSONArray scoped = this.filterScope(all, s);
763 1163 String type = s.getType() == null ? "" : s.getType().toLowerCase();
764 1164 BuiltReason built = new BuiltReason();
765   - long explicitCount = -1;
  1165 + long explicitCount = -1L;
766 1166 if ("scenario12".equals(type)) {
767 1167 int n = 0;
768 1168 for (JdyRiskProperties.Pair p : s.getPairs()) {
769   - n++;
770   - if (p == null || p.getPersonField() == null || p.getSignField() == null) {
771   - continue;
772   - }
773   - for (int i = 0; i < scoped.size(); i++) {
  1169 + ++n;
  1170 + if (p == null || p.getPersonField() == null || p.getSignField() == null) continue;
  1171 + for (int i = 0; i < scoped.size(); ++i) {
774 1172 JSONObject row = scoped.getJSONObject(i);
775   - if (hasValue(row, p.getPersonField()) && !hasValue(row, p.getSignField())) {
776   - row.put("__reason_" + n, "参与人员" + n + "未签字确认");
777   - }
  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"));
778 1175 }
779 1176 }
780   - for (int i = 0; i < scoped.size(); i++) {
  1177 + for (int i = 0; i < scoped.size(); ++i) {
781 1178 JSONObject row = scoped.getJSONObject(i);
782   - List<String> miss = new ArrayList<>();
783   - for (int k = 1; k <= n; k++) {
784   - Object r = row.get("__reason_" + k);
785   - if (r != null) {
786   - miss.add(String.valueOf(r));
787   - row.remove("__reason_" + k);
788   - }
789   - }
790   - if (!miss.isEmpty()) {
791   - built.rows.add(row);
792   - built.reasons.add(String.join("、", miss));
  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));
793 1185 }
  1186 + if (arrayList.isEmpty()) continue;
  1187 + built.rows.add((Object)row);
  1188 + built.reasons.add(String.join((CharSequence)"\u3001", arrayList));
794 1189 }
795 1190 } else if ("scenario13".equals(type)) {
796   - for (int i = 0; i < scoped.size(); i++) {
  1191 + for (int i = 0; i < scoped.size(); ++i) {
797 1192 JSONObject row = scoped.getJSONObject(i);
798   - if (num(row, s.getDurationField()) <= s.getDurationThreshold()) {
799   - continue;
800   - }
801   - List<String> reasons = new ArrayList<>();
  1193 + if (JdyRiskStatisticsService.num(row, s.getDurationField()) <= s.getDurationThreshold()) continue;
  1194 + ArrayList<String> reasons = new ArrayList<String>();
802 1195 if (s.getAbnormalValue() != null && s.getAbnormalValue().equals(row.getString(s.getAbnormalField()))) {
803   - reasons.add("存在异常出门");
  1196 + reasons.add("\u5b58\u5728\u5f02\u5e38\u51fa\u95e8");
804 1197 }
805   - if (!hasValue(row, s.getReasonField())) {
806   - reasons.add("异常原因说明为空");
807   - }
808   - if (!reasons.isEmpty()) {
809   - built.rows.add(row);
810   - built.reasons.add(String.join("、", reasons));
  1198 + if (!JdyRiskStatisticsService.hasValue(row, s.getReasonField())) {
  1199 + reasons.add("\u5f02\u5e38\u539f\u56e0\u8bf4\u660e\u4e3a\u7a7a");
811 1200 }
  1201 + if (reasons.isEmpty()) continue;
  1202 + built.rows.add((Object)row);
  1203 + built.reasons.add(String.join((CharSequence)"\u3001", reasons));
812 1204 }
813 1205 } else if ("scenario14".equals(type)) {
814   - // 按分组(供应商名称)当年计数,命中分组的全部行导出
815   - Map<String, Integer> counts = new LinkedHashMap<>();
816   - for (int i = 0; i < scoped.size(); i++) {
817   - String g = orEmpty(scoped.getJSONObject(i).getString(s.getGroupField()));
  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()));
818 1209 counts.merge(g, 1, Integer::sum);
819 1210 }
820 1211 int threshold = Math.max(1, s.getMinCount());
821   - long hitGroups = 0;
822   - for (Map.Entry<String, Integer> e : counts.entrySet()) {
823   - if (e.getValue() >= threshold) {
824   - hitGroups++;
825   - }
  1212 + long hitGroups = 0L;
  1213 + for (Map.Entry e : counts.entrySet()) {
  1214 + if ((Integer)e.getValue() < threshold) continue;
  1215 + ++hitGroups;
826 1216 }
827   - for (int i = 0; i < scoped.size(); i++) {
  1217 + for (int i = 0; i < scoped.size(); ++i) {
828 1218 JSONObject row = scoped.getJSONObject(i);
829   - String g = orEmpty(row.getString(s.getGroupField()));
830   - Integer c = counts.get(g);
831   - if (c != null && c >= threshold) {
832   - built.rows.add(row);
833   - built.reasons.add("同一供应商[" + g + "]出现" + c + "次");
834   - }
  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");
835 1224 }
836 1225 explicitCount = hitGroups;
837 1226 } else if ("scenario15".equals(type)) {
838   - // 流转完成 + 条件为「是」时对应照片不能为空
839   - Map<String, String> labels = widgetLabels(jdy, s);
840   - for (int i = 0; i < scoped.size(); i++) {
  1227 + Map<String, String> labels = this.widgetLabels(jdy, s);
  1228 + for (int i = 0; i < scoped.size(); ++i) {
841 1229 JSONObject row = scoped.getJSONObject(i);
842   - if (!flowStateMatches(s, row)) {
843   - continue;
844   - }
845   - List<String> reasons = new ArrayList<>();
  1230 + if (!JdyRiskStatisticsService.flowStateMatches(s, row)) continue;
  1231 + ArrayList<String> arrayList = new ArrayList<String>();
846 1232 for (JdyRiskProperties.PhotoRule r : s.getPhotoRules()) {
847   - if (r == null || r.getFlagField() == null || r.getPhotoField() == null) {
848   - continue;
849   - }
850   - if (r.getFlagValue() != null && r.getFlagValue().equals(row.getString(r.getFlagField()))
851   - && !hasValue(row, r.getPhotoField())) {
852   - String lb = r.getLabel();
853   - if (lb == null || lb.isEmpty()) {
854   - lb = labels.getOrDefault(r.getPhotoField(), r.getPhotoField());
855   - }
856   - reasons.add(lb + "为空");
  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());
857 1237 }
  1238 + arrayList.add(lb + "\u4e3a\u7a7a");
858 1239 }
859   - if (!reasons.isEmpty()) {
860   - built.rows.add(row);
861   - built.reasons.add(String.join("、", reasons));
862   - }
  1240 + if (arrayList.isEmpty()) continue;
  1241 + built.rows.add((Object)row);
  1242 + built.reasons.add(String.join((CharSequence)"\u3001", arrayList));
863 1243 }
864 1244 } else if ("scenario16".equals(type)) {
865   - // 是否超出预算∈{高预算,低预算} 且 未填写超预算原因
866   - for (int i = 0; i < scoped.size(); i++) {
  1245 + for (int i = 0; i < scoped.size(); ++i) {
867 1246 JSONObject row = scoped.getJSONObject(i);
868 1247 String v = row.getString(s.getFlagField());
869   - if (v != null && s.getFlagValues().contains(v) && !hasValue(row, s.getReasonField())) {
870   - built.rows.add(row);
871   - built.reasons.add(v + "且未填写超预算原因");
872   - }
  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");
873 1251 }
874 1252 } else if ("scenario17".equals(type)) {
875   - // 流转完成 + 施工完成日期超过计划完成时间 overdueDays 天
876   - for (int i = 0; i < scoped.size(); i++) {
  1253 + for (int i = 0; i < scoped.size(); ++i) {
  1254 + long days;
877 1255 JSONObject row = scoped.getJSONObject(i);
878   - if (!flowStateMatches(s, row)) {
879   - continue;
880   - }
881   - if (!hasValue(row, s.getPlanField()) || !hasValue(row, s.getActualField())) {
882   - continue;
883   - }
884   - ZonedDateTime plan = parseTime(row.getString(s.getPlanField()));
885   - ZonedDateTime actual = parseTime(row.getString(s.getActualField()));
886   - if (plan == null || actual == null) {
887   - continue;
888   - }
889   - long days = ChronoUnit.DAYS.between(plan.toLocalDate(), actual.toLocalDate());
890   - if (days > s.getOverdueDays()) {
891   - built.rows.add(row);
892   - built.reasons.add("施工完成日期超过计划完成时间" + days + "天");
893   - }
  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");
894 1262 }
895 1263 } else if ("scenario18".equals(type)) {
896   - // 当月施工单位未提交审计资料 且 原因说明为空
897   - for (int i = 0; i < scoped.size(); i++) {
  1264 + for (int i = 0; i < scoped.size(); ++i) {
898 1265 JSONObject row = scoped.getJSONObject(i);
899 1266 String v = row.getString(s.getFlagField());
900   - if (v != null && s.getFlagValues().contains(v) && !hasValue(row, s.getReasonField())) {
901   - built.rows.add(row);
902   - built.reasons.add("当月施工单位未提交审计资料且原因说明为空");
903   - }
  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");
904 1270 }
905 1271 } else if ("scenario19".equals(type)) {
906   - // 三个月内是否已提报相似项目 = 是 → 命中
907   - for (int i = 0; i < scoped.size(); i++) {
  1272 + for (int i = 0; i < scoped.size(); ++i) {
908 1273 JSONObject row = scoped.getJSONObject(i);
909 1274 String v = row.getString(s.getFlagField());
910   - if (v != null && s.getFlagValues().contains(v)) {
911   - built.rows.add(row);
912   - built.reasons.add("三个月内已提报相似项目");
913   - }
  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");
914 1278 }
915 1279 } else if ("scenario20".equals(type)) {
916   - // 百公里油耗:上月每一条加油记录逐条计算,与全部历史中该车上一笔加油记录比较
917   - JSONArray flagged = filterByFlag(scoped, s);
918   - List<JSONObject> ordered = new ArrayList<>();
919   - for (int i = 0; i < flagged.size(); i++) {
  1280 + JSONArray flagged = JdyRiskStatisticsService.filterByFlag(scoped, s);
  1281 + ArrayList<JSONObject> ordered = new ArrayList<JSONObject>();
  1282 + for (int i = 0; i < flagged.size(); ++i) {
920 1283 ordered.add(flagged.getJSONObject(i));
921 1284 }
922   - sortByDateDesc(ordered, s.getDateField());
923   - long hits = 0;
  1285 + JdyRiskStatisticsService.sortByDateDesc(ordered, s.getDateField());
  1286 + long hits = 0L;
924 1287 for (JSONObject current : ordered) {
925   - ZonedDateTime curTime = parseTime(current.getString(s.getDateField()));
926   - JSONObject prev = findPreviousRefuel(all, s, current, curTime);
927   - double curStart = startKm(current, s);
928   - double prevStart = prev != null ? startKm(prev, s) : 0;
929   - double fuel = num(current, s.getFuelAmountField());
930   - if (prev == null || curStart <= 0 || prevStart <= 0 || fuel <= 0 || curStart <= prevStart) {
931   - log.warn("场景[{}] 跳过一条:上次记录缺失或起始公里数/里程差无效", s.getId());
  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());
932 1295 continue;
933 1296 }
934   - double cons = fuel / (curStart - prevStart) * 100;
935   - if (cons < s.getMinValue() || cons > s.getMaxValue()) {
936   - built.rows.add(current);
937   - built.reasons.add(String.format(java.util.Locale.ROOT,
938   - "百公里油耗%.2fL,超出正常范围[%.0f,%.0f](本次起%.0f/上次起%.0f)",
939   - cons, s.getMinValue(), s.getMaxValue(), curStart, prevStart));
940   - if (s.isIncludePreviousRow()) {
941   - built.rows.add(prev);
942   - built.reasons.add("上次用车(对比)");
943   - }
944   - hits++;
  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");
945 1304 }
  1305 + ++hits;
946 1306 }
947 1307 explicitCount = hits;
948 1308 } else if ("scenario21".equals(type)) {
949   - // 近三个月:每月按公司列汇总得分,取倒数 bottomCount 名;连续三个月都在倒三 → 异常
950   - JSONArray flagged = filterByFlag(scoped, s);
951   - Map<String, Map<String, Double>> monthTotals = new LinkedHashMap<>();
952   - Map<String, JSONArray> monthRows = new LinkedHashMap<>();
953   - for (int i = 0; i < flagged.size(); i++) {
954   - JSONObject row = flagged.getJSONObject(i);
955   - ZonedDateTime t = parseTime(row.getString(s.getDateField()));
956   - if (t == null) {
957   - continue;
  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);
958 1340 }
959   - String m = t.format(MONTH_FMT);
960   - monthRows.computeIfAbsent(m, k -> new JSONArray()).add(row);
961   - Map<String, Double> totals = monthTotals.computeIfAbsent(m, k -> new LinkedHashMap<>());
962   - for (String f : s.getCompanyFields()) {
963   - totals.merge(f, num(row, f), Double::sum);
  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);
964 1727 }
965 1728 }
966   - if (monthTotals.size() >= 3) {
967   - List<String> months = new ArrayList<>(monthTotals.keySet());
968   - months.sort(null);
969   - if (months.size() > 3) {
970   - months = months.subList(months.size() - 3, months.size());
  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);
971 1755 }
972   - Set<String> common = null;
973   - for (String m : months) {
974   - Set<String> bottom = bottomCompanyFields(monthTotals.get(m), s.getBottomCount());
975   - if (common == null) {
976   - common = new LinkedHashSet<>(bottom);
977   - } else {
978   - common.retainAll(bottom);
979   - }
  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);
980 1891 }
981   - if (common == null) {
982   - common = new LinkedHashSet<>();
  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);
983 1921 }
984   - if (!common.isEmpty()) {
985   - Map<String, String> labels = widgetLabels(jdy, s);
986   - List<String> abnormalNames = new ArrayList<>();
987   - for (String f : common) {
988   - abnormalNames.add(labels.getOrDefault(f, f));
  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();
989 1959 }
990   - String reason = "连续" + months.size() + "个月排名倒数前" + s.getBottomCount() + ":"
991   - + String.join("、", abnormalNames);
992   - List<JSONObject> ordered = new ArrayList<>();
993   - for (String m : months) {
994   - JSONArray arr = monthRows.get(m);
995   - if (arr != null) {
996   - for (int i = 0; i < arr.size(); i++) {
997   - ordered.add(arr.getJSONObject(i));
998   - }
999   - }
  1960 + if ((cur = (Rel)tmp.get(part)) == null) {
  1961 + tmp.put(part, new Rel(supplier, enabled, time));
  1962 + continue;
1000 1963 }
1001   - sortByDateDesc(ordered, s.getDateField());
1002   - for (JSONObject row : ordered) {
1003   - built.rows.add(row);
1004   - built.reasons.add(reason);
  1964 + if (enabled && !cur.enabled) {
  1965 + tmp.put(part, new Rel(supplier, enabled, time));
  1966 + continue;
1005 1967 }
1006   - explicitCount = common.size();
  1968 + if (enabled != cur.enabled || time <= cur.time) continue;
  1969 + tmp.put(part, new Rel(supplier, enabled, time));
1007 1970 }
1008   - } else {
1009   - log.warn("场景[{}] 近三个月数据不足({}个月),跳过", s.getId(), monthTotals.size());
  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);
1010 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);
1011 2007 }
1012   - built.count = explicitCount >= 0 ? explicitCount : built.rows.size();
1013   - log.info("场景[{}] 周期内={}条, 命中={}条", s.getId(), scoped.size(), built.count);
1014   - return built;
  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});
1015 2086 }
1016 2087
1017   - /** flowState 是否命中配置值(未配置则视为命中)。 */
1018 2088 private static boolean flowStateMatches(JdyRiskProperties.Scenario s, JSONObject row) {
1019 2089 Integer want = s.getFlowStateValue();
1020 2090 if (want == null) {
... ... @@ -1024,48 +2094,44 @@ public class JdyRiskStatisticsService {
1024 2094 return f != null && f.equals(want);
1025 2095 }
1026 2096
1027   - /** 表单字段 code -> 标题 映射(用于生成原因文案)。 */
1028 2097 private Map<String, String> widgetLabels(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
1029   - Map<String, String> m = new LinkedHashMap<>();
1030   - JSONArray ws = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId());
1031   - for (int i = 0; i < ws.size(); i++) {
  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) {
1032 2101 JSONObject w = ws.getJSONObject(i);
1033 2102 String n = w.getString("name");
1034 2103 String l = w.getString("label");
1035   - if (n != null && l != null) {
1036   - m.put(n, l);
1037   - }
  2104 + if (n == null || l == null) continue;
  2105 + m.put(n, l);
1038 2106 }
1039 2107 return m;
1040 2108 }
1041 2109
1042   - /** 判断字段是否有值(null / 空字符串 / 空对象 / 空数组 视为无值)。 */
1043 2110 private static boolean hasValue(JSONObject row, String field) {
1044 2111 if (field == null) {
1045 2112 return false;
1046 2113 }
1047   - Object v = row.get(field);
  2114 + Object v = row.get((Object)field);
1048 2115 if (v == null) {
1049 2116 return false;
1050 2117 }
1051 2118 if (v instanceof String) {
1052   - return !((String) v).trim().isEmpty();
  2119 + return !((String)v).trim().isEmpty();
1053 2120 }
1054 2121 if (v instanceof JSONObject) {
1055   - JSONObject o = (JSONObject) v;
1056   - return !o.isEmpty() && (o.getString("name") != null ? !o.getString("name").trim().isEmpty() : true);
  2122 + JSONObject o = (JSONObject)v;
  2123 + return !o.isEmpty() && (o.getString("name") == null || !o.getString("name").trim().isEmpty());
1057 2124 }
1058 2125 if (v instanceof JSONArray) {
1059   - return !((JSONArray) v).isEmpty();
  2126 + return !((JSONArray)v).isEmpty();
1060 2127 }
1061 2128 return true;
1062 2129 }
1063 2130
1064   - /** 按日期字段倒序(最新在前)就地排序;无效日期排到最后。 */
1065 2131 private static void sortByDateDesc(List<JSONObject> list, String dateField) {
1066 2132 list.sort((a, b) -> {
1067   - ZonedDateTime ta = parseTime(a.getString(dateField));
1068   - ZonedDateTime tb = parseTime(b.getString(dateField));
  2133 + ZonedDateTime ta = JdyRiskStatisticsService.parseTime(a.getString(dateField));
  2134 + ZonedDateTime tb = JdyRiskStatisticsService.parseTime(b.getString(dateField));
1069 2135 if (ta == null && tb == null) {
1070 2136 return 0;
1071 2137 }
... ... @@ -1079,294 +2145,240 @@ public class JdyRiskStatisticsService {
1079 2145 });
1080 2146 }
1081 2147
1082   - /**
1083   - * 在全部历史数据中找该车「上一笔加油记录」:flag-field == flag-values[0]、flowState 命中、
1084   - * 且用车开始时间早于当前记录,取时间最近的一条。
1085   - */
1086   - private JSONObject findPreviousRefuel(JSONArray all, JdyRiskProperties.Scenario s,
1087   - JSONObject current, ZonedDateTime curTime) {
  2148 + private JSONObject findPreviousRefuel(JSONArray all, JdyRiskProperties.Scenario s, JSONObject current, ZonedDateTime curTime) {
1088 2149 if (curTime == null) {
1089 2150 return null;
1090 2151 }
1091   - String flagVal = s.getFlagValues().isEmpty() ? "是" : s.getFlagValues().get(0);
  2152 + String flagVal = s.getFlagValues().isEmpty() ? "\u662f" : s.getFlagValues().get(0);
1092 2153 Integer wantFlow = s.getFlowStateValue();
1093 2154 JSONObject best = null;
1094 2155 ZonedDateTime bestT = null;
1095   - for (int i = 0; i < all.size(); i++) {
  2156 + for (int i = 0; i < all.size(); ++i) {
  2157 + ZonedDateTime t;
  2158 + Integer f;
1096 2159 JSONObject row = all.getJSONObject(i);
1097   - if (row == current) {
1098   - continue;
1099   - }
1100   - if (!flagVal.equals(row.getString(s.getFlagField()))) {
1101   - continue;
1102   - }
1103   - if (wantFlow != null) {
1104   - Integer f = row.getInteger("flowState");
1105   - if (f == null || !f.equals(wantFlow)) {
1106   - continue;
1107   - }
1108   - }
1109   - ZonedDateTime t = parseTime(row.getString(s.getDateField()));
1110   - if (t == null || !t.isBefore(curTime)) {
1111   - continue;
1112   - }
1113   - if (bestT == null || t.isAfter(bestT)) {
1114   - best = row;
1115   - bestT = t;
1116   - }
  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;
1117 2163 }
1118 2164 return best;
1119 2165 }
1120 2166
1121   - /** 仅保留 flag-field 取值属于 flag-values 的行;未配置则原样返回。 */
1122 2167 private static JSONArray filterByFlag(JSONArray rows, JdyRiskProperties.Scenario s) {
1123 2168 String f = s.getFlagField();
1124 2169 if (f == null || f.isEmpty() || s.getFlagValues().isEmpty()) {
1125 2170 return rows;
1126 2171 }
1127 2172 JSONArray out = new JSONArray();
1128   - for (int i = 0; i < rows.size(); i++) {
  2173 + for (int i = 0; i < rows.size(); ++i) {
1129 2174 JSONObject row = rows.getJSONObject(i);
1130   - if (s.getFlagValues().contains(row.getString(f))) {
1131   - out.add(row);
1132   - }
  2175 + if (!s.getFlagValues().contains(row.getString(f))) continue;
  2176 + out.add((Object)row);
1133 2177 }
1134 2178 return out;
1135 2179 }
1136 2180
1137   - /**
1138   - * 取得分最低的 N 家公司(第 N 名并列的也一并计入)。
1139   - */
1140 2181 private static Set<String> bottomCompanyFields(Map<String, Double> totals, int n) {
1141   - Set<String> bottom = new LinkedHashSet<>();
  2182 + LinkedHashSet<String> bottom = new LinkedHashSet<String>();
1142 2183 if (totals == null || totals.isEmpty() || n <= 0) {
1143 2184 return bottom;
1144 2185 }
1145   - List<Map.Entry<String, Double>> list = new ArrayList<>(totals.entrySet());
1146   - list.sort((a, b) -> Double.compare(a.getValue(), b.getValue()));
1147   - double cutoff = list.get(Math.min(n, list.size()) - 1).getValue();
1148   - for (Map.Entry<String, Double> e : list) {
1149   - if (e.getValue() <= cutoff) {
1150   - bottom.add(e.getKey());
1151   - }
  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());
1152 2192 }
1153 2193 return bottom;
1154 2194 }
1155 2195
1156   - /** 起始公里数:主字段 >0 直接用;否则取「非连续用车」子表单起始公里数的最大值。 */
1157 2196 private static double startKm(JSONObject row, JdyRiskProperties.Scenario s) {
1158   - double v = num(row, s.getStartKmField());
1159   - if (v > 0) {
  2197 + Object o;
  2198 + double v = JdyRiskStatisticsService.num(row, s.getStartKmField());
  2199 + if (v > 0.0) {
1160 2200 return v;
1161 2201 }
1162   - if (s.getSubformField() != null && s.getSubformStartField() != null) {
1163   - Object o = row.get(s.getSubformField());
1164   - if (o instanceof JSONArray) {
1165   - JSONArray arr = (JSONArray) o;
1166   - double max = 0;
1167   - for (int i = 0; i < arr.size(); i++) {
1168   - Object it = arr.get(i);
1169   - if (it instanceof JSONObject) {
1170   - double sv = num((JSONObject) it, s.getSubformStartField());
1171   - if (sv > max) {
1172   - max = sv;
1173   - }
1174   - }
1175   - }
1176   - return max;
  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;
1177 2210 }
  2211 + return max;
1178 2212 }
1179   - return 0;
  2213 + return 0.0;
1180 2214 }
1181 2215
1182 2216 private static JSONObject syntheticWidget(String name, String label) {
1183 2217 JSONObject w = new JSONObject();
1184   - w.put("name", name);
1185   - w.put("label", label);
  2218 + w.put("name", (Object)name);
  2219 + w.put("label", (Object)label);
1186 2220 return w;
1187 2221 }
1188 2222
1189 2223 private static Map<String, List<JSONObject>> groupByBarcode(JSONArray rows, String field) {
1190   - Map<String, List<JSONObject>> map = new LinkedHashMap<>();
1191   - for (int i = 0; i < rows.size(); i++) {
  2224 + LinkedHashMap<String, List<JSONObject>> map = new LinkedHashMap<String, List<JSONObject>>();
  2225 + for (int i = 0; i < rows.size(); ++i) {
1192 2226 JSONObject row = rows.getJSONObject(i);
1193 2227 String b = row.getString(field);
1194   - if (b == null || b.trim().isEmpty()) {
1195   - continue;
1196   - }
1197   - map.computeIfAbsent(b.trim(), k -> new ArrayList<>()).add(row);
  2228 + if (b == null || b.trim().isEmpty()) continue;
  2229 + map.computeIfAbsent(b.trim(), k -> new ArrayList()).add(row);
1198 2230 }
1199 2231 return map;
1200 2232 }
1201 2233
1202   - /** 场景2:命中供应商集合(SI数量/问题数量合计>60% 且 合计>=5)。 */
1203 2234 private Set<String> warningSuppliers2(JdyRiskProperties.Scenario s, JSONArray data) {
1204   - Map<String, double[]> byGroup = new LinkedHashMap<>();
1205   - for (int i = 0; i < data.size(); i++) {
  2235 + LinkedHashMap<String, double[]> byGroup = new LinkedHashMap<String, double[]>();
  2236 + for (int i = 0; i < data.size(); ++i) {
1206 2237 JSONObject row = data.getJSONObject(i);
1207   - String group = orEmpty(row.getString(s.getGroupField()));
1208   - double qty = num(row, s.getQtyField());
  2238 + String group = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
  2239 + double qty = JdyRiskStatisticsService.num(row, s.getQtyField());
1209 2240 double[] agg = byGroup.computeIfAbsent(group, k -> new double[2]);
1210   - agg[0] += qty;
1211   - if ("SI".equalsIgnoreCase(row.getString(s.getSiField()))) {
1212   - agg[1] += qty;
1213   - }
  2241 + agg[0] = agg[0] + qty;
  2242 + if (!"SI".equalsIgnoreCase(row.getString(s.getSiField()))) continue;
  2243 + agg[1] = agg[1] + qty;
1214 2244 }
1215   - Set<String> warn = new LinkedHashSet<>();
1216   - for (Map.Entry<String, double[]> e : byGroup.entrySet()) {
1217   - double[] agg = e.getValue();
1218   - if (agg[0] >= 5 && (agg[1] / agg[0]) > 0.6) {
1219   - warn.add(e.getKey());
1220   - }
  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());
1221 2250 }
1222 2251 return warn;
1223 2252 }
1224 2253
1225   - /**
1226   - * Excel 最右附加列的值(各场景统一):
1227   - * 命中/预警的行显示对应名称,其余为空。
1228   - * 取值优先级:extra-field > group-field > 「命中」。
1229   - */
1230 2254 private List<String> buildExtraValues(JdyRiskProperties.Scenario s, JSONArray data) {
1231 2255 String type = s.getType() == null ? "" : s.getType().toLowerCase();
1232 2256 Set<String> warnGroups = null;
1233 2257 Map<String, Double> ratio2 = null;
1234 2258 if ("scenario2".equals(type)) {
1235   - ratio2 = supplierRatio2(s, data);
  2259 + ratio2 = this.supplierRatio2(s, data);
1236 2260 warnGroups = ratio2.keySet();
1237 2261 } else if ("scenario4".equals(type) || "scenario5".equals(type)) {
1238   - warnGroups = warningGroupsByUp(s, data);
  2262 + warnGroups = this.warningGroupsByUp(s, data);
1239 2263 } else if ("scenario6".equals(type)) {
1240   - warnGroups = warningGroupsByCount(s, data);
  2264 + warnGroups = this.warningGroupsByCount(s, data);
1241 2265 } else if ("scenario8".equals(type) || "scenario9".equals(type)) {
1242   - ratio2 = groupRatioByFlag(s, data);
  2266 + ratio2 = this.groupRatioByFlag(s, data);
1243 2267 warnGroups = ratio2.keySet();
1244 2268 }
1245   - List<String> values = new ArrayList<>();
1246   - for (int i = 0; i < data.size(); i++) {
  2269 + ArrayList<String> values = new ArrayList<String>();
  2270 + for (int i = 0; i < data.size(); ++i) {
1247 2271 JSONObject row = data.getJSONObject(i);
1248 2272 String v = "";
1249 2273 if ("scenario1".equals(type)) {
1250   - v = rowHitScenario1(s, row) ? displayName(s, row) : "";
  2274 + v = this.rowHitScenario1(s, row) ? this.displayName(s, row) : "";
1251 2275 } else if ("scenario3".equals(type)) {
1252   - v = rowHitScenario3(s, row) ? displayName(s, row) : "";
  2276 + v = this.rowHitScenario3(s, row) ? this.displayName(s, row) : "";
1253 2277 } else if (ratio2 != null) {
1254   - Double rr = ratio2.get(orEmpty(row.getString(s.getGroupField())));
1255   - v = rr != null ? displayName(s, row) + "(" + String.format("%.1f%%", rr * 100) + ")" : "";
  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) + ")" : "";
1256 2280 } else if (warnGroups != null) {
1257   - String g = orEmpty(row.getString(s.getGroupField()));
1258   - 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) : "";
1259 2283 }
1260 2284 values.add(v);
1261 2285 }
1262 2286 return values;
1263 2287 }
1264 2288
1265   - /** 场景2:命中供应商 -> SI占比。 */
1266 2289 private Map<String, Double> supplierRatio2(JdyRiskProperties.Scenario s, JSONArray data) {
1267   - Map<String, double[]> byGroup = new LinkedHashMap<>();
1268   - for (int i = 0; i < data.size(); i++) {
  2290 + double[] agg;
  2291 + LinkedHashMap<String, double[]> byGroup = new LinkedHashMap<String, double[]>();
  2292 + for (int i = 0; i < data.size(); ++i) {
1269 2293 JSONObject row = data.getJSONObject(i);
1270   - String group = orEmpty(row.getString(s.getGroupField()));
1271   - double[] agg = byGroup.computeIfAbsent(group, k -> new double[2]);
1272   - double qty = num(row, s.getQtyField());
1273   - agg[0] += qty;
1274   - if ("SI".equalsIgnoreCase(row.getString(s.getSiField()))) {
1275   - agg[1] += qty;
1276   - }
1277   - }
1278   - Map<String, Double> out = new LinkedHashMap<>();
1279   - for (Map.Entry<String, double[]> e : byGroup.entrySet()) {
1280   - double[] agg = e.getValue();
1281   - if (agg[0] >= 5 && (agg[1] / agg[0]) > 0.6) {
1282   - out.put(e.getKey(), agg[1] / agg[0]);
1283   - }
  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]);
1284 2306 }
1285 2307 return out;
1286 2308 }
1287 2309
1288   - /** 场景8/9:命中分组 -> 未开CR占比。 */
1289 2310 private Map<String, Double> groupRatioByFlag(JdyRiskProperties.Scenario s, JSONArray data) {
1290   - Map<String, int[]> byGroup = new LinkedHashMap<>();
1291   - for (int i = 0; i < data.size(); i++) {
  2311 + LinkedHashMap<String, int[]> byGroup = new LinkedHashMap<String, int[]>();
  2312 + for (int i = 0; i < data.size(); ++i) {
1292 2313 JSONObject row = data.getJSONObject(i);
1293   - String g = orEmpty(row.getString(s.getGroupField()));
  2314 + String g = JdyRiskStatisticsService.orEmpty(row.getString(s.getGroupField()));
1294 2315 int[] agg = byGroup.computeIfAbsent(g, k -> new int[2]);
1295   - agg[0]++;
1296   - if (s.getFlagValue() != null && s.getFlagValue().equalsIgnoreCase(row.getString(s.getFlagField()))) {
1297   - agg[1]++;
1298   - }
  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;
1299 2319 }
1300   - Map<String, Double> out = new LinkedHashMap<>();
  2320 + LinkedHashMap<String, Double> out = new LinkedHashMap<String, Double>();
1301 2321 double th = s.getRatioThreshold();
1302   - for (Map.Entry<String, int[]> e : byGroup.entrySet()) {
1303   - int[] agg = e.getValue();
1304   - if (agg[0] > 0 && ((double) agg[1] / agg[0]) > th) {
1305   - out.put(e.getKey(), (double) agg[1] / agg[0]);
1306   - }
  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]);
1307 2326 }
1308 2327 return out;
1309 2328 }
1310 2329
1311 2330 private String displayName(JdyRiskProperties.Scenario s, JSONObject row) {
  2331 + Map<String, String> lk;
1312 2332 Object v;
1313 2333 if (s.getExtraField() != null && !s.getExtraField().isEmpty()) {
1314   - v = row.get(s.getExtraField());
  2334 + v = row.get((Object)s.getExtraField());
1315 2335 } else if (s.getGroupField() != null && !s.getGroupField().isEmpty()) {
1316   - v = row.get(s.getGroupField());
  2336 + v = row.get((Object)s.getGroupField());
1317 2337 } else {
1318   - return "命中";
  2338 + return "\u547d\u4e2d";
1319 2339 }
1320   - if (v instanceof String) {
1321   - Map<String, String> lk = JdyExcelExportService.currentLookup();
1322   - if (lk != null && lk.containsKey(v)) {
1323   - return lk.get(v);
1324   - }
  2340 + if (v instanceof String && (lk = JdyExcelExportService.currentLookup()) != null && lk.containsKey(v)) {
  2341 + return lk.get(v);
1325 2342 }
1326   - return toDisplayName(v);
  2343 + return JdyRiskStatisticsService.toDisplayName(v);
1327 2344 }
1328 2345
1329   - /** 构建关联表 id->名称 映射(用于把关联字段的 id 显示成中文名)。 */
1330 2346 private Map<String, String> buildLookupMap(JiandaoYunApi jdy, JdyRiskProperties.Scenario s) {
1331   - Map<String, String> map = new LinkedHashMap<>();
1332   - if (s.getLookupEntryId() == null || s.getLookupEntryId().isEmpty()
1333   - || s.getLookupNameField() == null || s.getLookupNameField().isEmpty()) {
  2347 + LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
  2348 + if (s.getLookupEntryId() == null || s.getLookupEntryId().isEmpty() || s.getLookupNameField() == null || s.getLookupNameField().isEmpty()) {
1334 2349 return map;
1335 2350 }
1336   - jdy.forEachPage(props.getApiKey(), s.getAppId(), s.getLookupEntryId(),
1337   - java.util.Collections.singletonList(s.getLookupNameField()), page -> {
1338   - for (int i = 0; i < page.size(); i++) {
1339   - JSONObject r = page.getJSONObject(i);
1340   - String id = r.getString("_id");
1341   - String name = r.getString(s.getLookupNameField());
1342   - if (id != null && name != null) {
1343   - map.put(id, name);
1344   - }
1345   - }
1346   - });
1347   - log.info("场景[{}] 关联表 {} 映射 {} 条", s.getId(), s.getLookupEntryId(), map.size());
  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()});
1348 2361 return map;
1349 2362 }
1350 2363
1351   - /** 按指定字段的显示名升序排序(就地)。 */
1352 2364 private static void sortRows(JSONArray rows, String field) {
1353   - List<JSONObject> list = new ArrayList<>();
1354   - for (int i = 0; i < rows.size(); i++) {
  2365 + ArrayList<JSONObject> list = new ArrayList<JSONObject>();
  2366 + for (int i = 0; i < rows.size(); ++i) {
1355 2367 list.add(rows.getJSONObject(i));
1356 2368 }
1357   - list.sort((a, b) -> toDisplayName(a.get(field)).compareTo(toDisplayName(b.get(field))));
  2369 + list.sort((a, b) -> JdyRiskStatisticsService.toDisplayName(a.get((Object)field)).compareTo(JdyRiskStatisticsService.toDisplayName(b.get((Object)field))));
1358 2370 rows.clear();
1359 2371 for (JSONObject o : list) {
1360   - rows.add(o);
  2372 + rows.add((Object)o);
1361 2373 }
1362 2374 }
1363 2375
1364   - /** 取值转显示名:对象取 dataTitle/name,数组连接,其余转字符串。 */ private static String toDisplayName(Object v) {
  2376 + private static String toDisplayName(Object v) {
1365 2377 if (v == null) {
1366 2378 return "";
1367 2379 }
1368 2380 if (v instanceof JSONObject) {
1369   - JSONObject o = (JSONObject) v;
  2381 + JSONObject o = (JSONObject)v;
1370 2382 String n = o.getString("dataTitle");
1371 2383 if (n == null || n.isEmpty()) {
1372 2384 n = o.getString("name");
... ... @@ -1374,13 +2386,11 @@ public class JdyRiskStatisticsService {
1374 2386 return n == null ? "" : n;
1375 2387 }
1376 2388 if (v instanceof JSONArray) {
1377   - JSONArray arr = (JSONArray) v;
  2389 + JSONArray arr = (JSONArray)v;
1378 2390 StringBuilder sb = new StringBuilder();
1379   - for (int i = 0; i < arr.size(); i++) {
1380   - String n = toDisplayName(arr.get(i));
1381   - if (n.isEmpty()) {
1382   - continue;
1383   - }
  2391 + for (int i = 0; i < arr.size(); ++i) {
  2392 + String n = JdyRiskStatisticsService.toDisplayName(arr.get(i));
  2393 + if (n.isEmpty()) continue;
1384 2394 if (sb.length() > 0) {
1385 2395 sb.append(",");
1386 2396 }
... ... @@ -1392,51 +2402,39 @@ public class JdyRiskStatisticsService {
1392 2402 return "null".equals(s) ? "" : s;
1393 2403 }
1394 2404
1395   - /** 仅保留「命中/预警」的行(用于 Excel)。 */
1396 2405 private JSONArray filterWarnRows(JdyRiskProperties.Scenario s, JSONArray rows) {
1397 2406 String type = s.getType() == null ? "" : s.getType().toLowerCase();
1398 2407 Set<String> warnGroups = null;
1399 2408 if ("scenario2".equals(type)) {
1400   - warnGroups = warningSuppliers2(s, rows);
  2409 + warnGroups = this.warningSuppliers2(s, rows);
1401 2410 } else if ("scenario4".equals(type) || "scenario5".equals(type)) {
1402   - warnGroups = warningGroupsByUp(s, rows);
  2411 + warnGroups = this.warningGroupsByUp(s, rows);
1403 2412 } else if ("scenario8".equals(type) || "scenario9".equals(type)) {
1404   - warnGroups = warningGroupsByRatio(s, rows);
  2413 + warnGroups = this.warningGroupsByRatio(s, rows);
1405 2414 }
1406 2415 JSONArray out = new JSONArray();
1407   - for (int i = 0; i < rows.size(); i++) {
  2416 + for (int i = 0; i < rows.size(); ++i) {
1408 2417 JSONObject row = rows.getJSONObject(i);
1409   - boolean keep;
1410   - if (warnGroups != null) {
1411   - keep = warnGroups.contains(orEmpty(row.getString(s.getGroupField())));
1412   - } else if ("scenario3".equals(type)) {
1413   - keep = rowHitScenario3(s, row);
1414   - } else if ("scenario1".equals(type)) {
1415   - keep = rowHitScenario1(s, row);
1416   - } else {
1417   - keep = true;
1418   - }
1419   - if (keep) {
1420   - out.add(row);
1421   - }
  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);
1422 2421 }
1423 2422 return out;
1424 2423 }
1425 2424
1426 2425 private boolean rowHitScenario1(JdyRiskProperties.Scenario s, JSONObject row) {
1427   - double total = num(row, s.getTotalField());
1428   - double diff = num(row, s.getDiffField());
  2426 + double total = JdyRiskStatisticsService.num(row, s.getTotalField());
  2427 + double diff = JdyRiskStatisticsService.num(row, s.getDiffField());
1429 2428 Integer flow = row.getInteger("flowState");
1430   - return total >= 5 && diff >= 1 && flow != null && flow == s.getInProgressState();
  2429 + return total >= 5.0 && diff >= 1.0 && flow != null && flow.intValue() == s.getInProgressState();
1431 2430 }
1432 2431
1433 2432 private boolean rowHitScenario3(JdyRiskProperties.Scenario s, JSONObject row) {
1434   - double total = num(row, s.getTotalField());
1435   - double ratio = num(row, s.getRatioField());
1436   - 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;
1437 2436 }
1438 2437
1439   - /** 升级字段是否命中:非空 且 不在排除值内。 */
1440 2438 private boolean isUpHit(JdyRiskProperties.Scenario s, JSONObject row) {
1441 2439 String up = row.getString(s.getUpField());
1442 2440 if (up == null || up.trim().isEmpty()) {
... ... @@ -1444,167 +2442,179 @@ public class JdyRiskStatisticsService {
1444 2442 }
1445 2443 if (s.getExcludeValues() != null) {
1446 2444 for (String ex : s.getExcludeValues()) {
1447   - if (ex != null && ex.equalsIgnoreCase(up.trim())) {
1448   - return false;
1449   - }
  2445 + if (ex == null || !ex.equalsIgnoreCase(up.trim())) continue;
  2446 + return false;
1450 2447 }
1451 2448 }
1452 2449 return true;
1453 2450 }
1454 2451
1455   - /* ==================== 工具 ==================== */
1456   -
1457   - /** 找「同一 syncCode 且 预警日期(时间字段)为当天」的记录;无则返回 null。 */
1458   - private JSONObject findTodayRecord(JSONArray records, String syncCode, String timeField) {
1459   - if (records == null || syncCode == null || timeField == null || timeField.isEmpty()) {
  2452 + private JSONObject findTodayRecord(JSONArray records, JdyRiskProperties.Scenario s, Biz biz, String timeField) {
  2453 + if (records == null || s == null || timeField == null || timeField.isEmpty()) {
1460 2454 return null;
1461 2455 }
1462   - String today = ZonedDateTime.now(ZONE).format(DAY_FMT);
1463   - for (int i = 0; i < records.size(); i++) {
1464   - JSONObject r = records.getJSONObject(i);
1465   - if (!syncCode.equals(r.getString("syncCode"))) {
1466   - continue;
1467   - }
  2456 + String today = this.now().format(DAY_FMT);
  2457 + for (JSONObject r : this.candidates(records, s, biz)) {
1468 2458 Long t = r.getLong(timeField);
1469   - if (t != null && Instant.ofEpochMilli(t).atZone(ZONE).format(DAY_FMT).equals(today)) {
1470   - return r;
1471   - }
  2459 + if (t == null || !Instant.ofEpochMilli(t).atZone(ZONE).format(DAY_FMT).equals(today)) continue;
  2460 + return r;
1472 2461 }
1473 2462 return null;
1474 2463 }
1475 2464
1476   - /** 构造附件关联对象。 */
1477 2465 private JSONObject buildAttach(String fileId, String fileName, long size) {
1478 2466 JSONObject rel = new JSONObject();
1479   - rel.put("uid", fileId);
1480   - rel.put("name", fileName);
1481   - rel.put("size", size);
1482   - rel.put("fileId", fileId);
1483   - rel.put("status", "done");
1484   - rel.put("id", fileId);
1485   - rel.put("dataTitle", fileName);
  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);
1486 2474 return rel;
1487 2475 }
1488 2476
1489   - /**
1490   - * 写入预警时间字段,并同步写入预警年份字段(time-field-2,如 dgqshv)。
1491   - * <p>dgqshv 为 QxDate(format=YYYY),取其=预警时间同一时刻,显示年份即预警时间所在年份。</p>
1492   - */
1493 2477 private static void setTimeFields(JSONObject rec, JdyRiskProperties.Qx qx, long now) {
1494 2478 if (qx.getTimeField() != null && !qx.getTimeField().isEmpty()) {
1495   - rec.put(qx.getTimeField(), now);
  2479 + rec.put(qx.getTimeField(), (Object)now);
1496 2480 }
1497 2481 if (qx.getTimeField2() != null && !qx.getTimeField2().isEmpty()) {
1498   - rec.put(qx.getTimeField2(), now);
  2482 + rec.put(qx.getTimeField2(), (Object)now);
1499 2483 }
1500 2484 }
1501 2485
1502   - /**
1503   - * 以已存在的同 syncCode 记录为模板克隆新增体:
1504   - * 去掉 id 与审计字段,覆盖计数/预警时间/附件,保留其余业务字段(场景关联、单位、领导班子、成员等)。
1505   - */
1506   - private JSONObject cloneTemplate(JSONObject template, JdyRiskProperties.Qx qx, String syncCode,
1507   - long count, long now, String fileId, String fileName,
1508   - long size, boolean skipAttach) {
  2486 + private JSONObject cloneTemplate(JSONObject template, JdyRiskProperties.Qx qx, String syncCode, long count, long now, String fileId, String fileName, long size, boolean skipAttach) {
1509 2487 JSONObject body = new JSONObject();
1510   - body.putAll(template);
1511   - body.remove("id");
1512   - body.remove("corpCode");
1513   - body.remove("createdBy");
1514   - body.remove("updatedBy");
1515   - body.remove("createdAt");
1516   - body.remove("updatedAt");
1517   - body.put(qx.getCountField(), count);
1518   - body.put("syncCode", syncCode);
1519   - setTimeFields(body, qx, now);
  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);
1520 2498 String af = qx.getAttachField();
1521 2499 if (af != null && !af.isEmpty()) {
1522 2500 if (skipAttach || fileId == null) {
1523   - body.remove(af);
1524   - body.remove(af + "Id");
  2501 + body.remove((Object)af);
  2502 + body.remove((Object)(af + "Id"));
1525 2503 } else {
1526   - body.put(af, buildAttach(fileId, fileName, size));
1527   - body.put(af + "Id", fileId);
  2504 + body.put(af, (Object)this.buildAttach(fileId, fileName, size));
  2505 + body.put(af + "Id", (Object)fileId);
1528 2506 }
1529 2507 }
1530 2508 return body;
1531 2509 }
1532 2510
1533   - /** 组装新增请求体:固定业务数据 + 计数 + 附件 + 预警时间 + 同步编号。 */
1534   - private JSONObject buildAddBody(Biz biz, JdyRiskProperties.Qx qx, String syncCode,
1535   - long count, long now, String fileId, String fileName, long size) {
  2511 + private JSONObject buildAddBody(Biz biz, JdyRiskProperties.Qx qx, String syncCode, long count, long now, String fileId, String fileName, long size) {
1536 2512 JSONObject unit = new JSONObject();
1537   - unit.put("dataTitle", biz.unitTitle);
1538   - unit.put("id", biz.unitId);
  2513 + unit.put("dataTitle", (Object)biz.unitTitle);
  2514 + unit.put("id", (Object)biz.unitId);
1539 2515 JSONObject leader = new JSONObject();
1540   - leader.put("dataTitle", biz.leaderTitle);
1541   - leader.put("id", biz.leaderId);
  2516 + leader.put("dataTitle", (Object)biz.leaderTitle);
  2517 + leader.put("id", (Object)biz.leaderId);
1542 2518 JSONObject scene = new JSONObject();
1543   - scene.put("id", biz.sceneId);
1544   - scene.put("dataTitle", biz.sceneTitle);
1545   - scene.put("faomis", biz.domain);
1546   - scene.put("xxwbzf", biz.businessLine);
1547   - scene.put("qdbuhp", unit);
1548   - scene.put("pofmup", leader);
  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);
1549 2525 if (biz.sceneMemberId != null) {
1550 2526 JSONObject member = new JSONObject();
1551   - member.put("dataTitle", biz.sceneMemberTitle);
1552   - member.put("id", biz.sceneMemberId);
1553   - scene.put("jiaplm", member);
  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);
1554 2536 }
1555   -
1556 2537 JSONObject body = new JSONObject();
1557   - body.put("miidqb", scene);
1558   - body.put("miidqbId", biz.sceneId);
1559   - body.put("gyxwbd", biz.domain);
1560   - body.put("wifxkb", biz.businessLine);
1561   - body.put("gnzuoi", unit);
1562   - body.put("gnzuoiId", biz.unitId);
1563   - body.put("khexbl", leader);
1564   - body.put("khexblId", biz.leaderId);
1565   - setTimeFields(body, qx, now); // 预警时间 bswivu + 预警年份 dgqshv
1566   - body.put("sxhuzf", "1"); // 关闭状态默认「待处理」
1567   - body.put(qx.getCountField(), count);
1568   - body.put("syncCode", syncCode);
  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);
1569 2556 if (biz.jetcalId != null) {
1570 2557 JSONObject jet = new JSONObject();
1571   - jet.put("dataTitle", biz.jetcalTitle);
1572   - jet.put("id", biz.jetcalId);
1573   - body.put("jetcal", jet);
1574   - body.put("jetcalId", biz.jetcalId);
  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);
1575 2562 }
1576 2563 if (biz.zawlah != null) {
1577   - body.put("zawlah", biz.zawlah);
  2564 + body.put("zawlah", (Object)biz.zawlah);
1578 2565 }
1579 2566 if (fileId != null && qx.getAttachField() != null && !qx.getAttachField().isEmpty()) {
1580   - body.put(qx.getAttachField(), buildAttach(fileId, fileName, size));
1581   - body.put(qx.getAttachField() + "Id", fileId);
  2567 + body.put(qx.getAttachField(), (Object)this.buildAttach(fileId, fileName, size));
  2568 + body.put(qx.getAttachField() + "Id", (Object)fileId);
1582 2569 }
1583 2570 return body;
1584 2571 }
1585 2572
1586   - /** 在启效记录中按 syncCode 匹配(重复时取第一条并告警)。 */
1587   - private JSONObject findRecordBySyncCode(JSONArray records, String syncCode) {
1588   - if (records == null || syncCode == null || syncCode.isEmpty()) {
  2573 + private JSONObject findRecordBySyncCode(JSONArray records, JdyRiskProperties.Scenario s, Biz biz) {
  2574 + List<JSONObject> list = this.candidates(records, s, biz);
  2575 + if (list.isEmpty()) {
1589 2576 return null;
1590 2577 }
1591   - JSONObject found = null;
1592   - 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) {
1593 2591 JSONObject r = records.getJSONObject(i);
1594   - if (syncCode.equals(r.getString("syncCode"))) {
1595   - if (found == null) {
1596   - found = r;
1597   - } else {
1598   - log.warn("syncCode={} 存在多条记录(id={} 与 id={}),使用第一条",
1599   - syncCode, found.getString("id"), r.getString("id"));
1600   - }
1601   - }
  2592 + if (!s.getSyncCode().equals(r.getString("syncCode"))) continue;
  2593 + byCode.add(r);
  2594 + if (!JdyRiskStatisticsService.sceneMatches(r, biz)) continue;
  2595 + byScene.add(r);
  2596 + }
  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;
1602 2610 }
1603   - return found;
  2611 + JSONObject scene = r.getJSONObject("miidqb");
  2612 + String id = scene != null ? scene.getString("id") : r.getString("miidqbId");
  2613 + return biz.sceneId.equals(id);
1604 2614 }
1605 2615
1606 2616 private static ZonedDateTime quarterStart(ZonedDateTime now) {
1607   - int qStartMonth = ((now.getMonthValue() - 1) / 3) * 3 + 1;
  2617 + int qStartMonth = (now.getMonthValue() - 1) / 3 * 3 + 1;
1608 2618 return now.withMonth(qStartMonth).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS);
1609 2619 }
1610 2620
... ... @@ -1614,30 +2624,199 @@ public class JdyRiskStatisticsService {
1614 2624 }
1615 2625 try {
1616 2626 return Instant.parse(iso).atZone(ZONE);
1617   - } catch (Exception e) {
  2627 + }
  2628 + catch (Exception e) {
1618 2629 return null;
1619 2630 }
1620 2631 }
1621 2632
1622 2633 private static double num(JSONObject row, String field) {
1623 2634 if (field == null) {
1624   - return 0d;
  2635 + return 0.0;
1625 2636 }
1626   - Object v = row.get(field);
  2637 + Object v = row.get((Object)field);
1627 2638 if (v == null) {
1628   - return 0d;
  2639 + return 0.0;
1629 2640 }
1630 2641 if (v instanceof Number) {
1631   - return ((Number) v).doubleValue();
  2642 + return ((Number)v).doubleValue();
1632 2643 }
1633 2644 try {
1634 2645 return Double.parseDouble(String.valueOf(v));
1635   - } catch (NumberFormatException e) {
1636   - return 0d;
  2646 + }
  2647 + catch (NumberFormatException e) {
  2648 + return 0.0;
1637 2649 }
1638 2650 }
1639 2651
1640 2652 private static String orEmpty(String s) {
1641   - 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 + }
1642 2820 }
1643 2821 }
  2822 +
... ...
... ... @@ -42,6 +42,59 @@ public class JdySyncScheduledTask {
42 42 result.forEach(r -> log.info("同步结果: {}", r));
43 43 }
44 44
  45 + /** 质量域场景1(SYNC0001 供应商绩效评价-26MY 3mis维修记录):每月20号抓取上月数据。 */
  46 + @Scheduled(cron = "${jdy-risk.schedule.s1-cron:0 0 3 20 * ?}")
  47 + public void monthlySyncS1() {
  48 + if (!riskProps.getSchedule().isEnabled()) {
  49 + log.info("jdy-risk.schedule.enabled=false,跳过场景1定时抓取");
  50 + return;
  51 + }
  52 + log.info("========== 定时抓取 质量域场景1(SYNC0001) ==========");
  53 + log.info("场景1结果: {}", riskService.countAndSyncOne("SYNC0001"));
  54 + }
  55 +
  56 + /** 质量域场景2(SYNC0002 供应商 SI 占比):每月5号抓上月。 */
  57 + @Scheduled(cron = "${jdy-risk.schedule.s2-cron:0 0 3 5 * ?}")
  58 + public void monthlySyncS2() { runQuality("场景2", "SYNC0002"); }
  59 +
  60 + /** 质量域场景3(SYNC0003 工程师 SI 占比):每月5号抓上月。 */
  61 + @Scheduled(cron = "${jdy-risk.schedule.s3-cron:0 0 3 5 * ?}")
  62 + public void monthlySyncS3() { runQuality("场景3", "SYNC0003"); }
  63 +
  64 + /** 质量域场景4(SYNC0004 CR升级-供应商):1/4/7/10月5号抓上一季度。 */
  65 + @Scheduled(cron = "${jdy-risk.schedule.s4-cron:0 0 3 5 1,4,7,10 ?}")
  66 + public void quarterlySyncS4() { runQuality("场景4", "SYNC0004"); }
  67 +
  68 + /** 质量域场景5(SYNC0005 CR升级-工程师):1/4/7/10月5号抓上一季度。 */
  69 + @Scheduled(cron = "${jdy-risk.schedule.s5-cron:0 0 3 5 1,4,7,10 ?}")
  70 + public void quarterlySyncS5() { runQuality("场景5", "SYNC0005"); }
  71 +
  72 + /** 质量域场景6(SYNC0006 索赔率差值):每月最后一天23点抓当月(每天23点触发,月末执行)。 */
  73 + @Scheduled(cron = "${jdy-risk.schedule.s6-cron:0 0 23 * * ?}")
  74 + public void monthlySyncS6() {
  75 + if (!isLastDayOfMonth()) {
  76 + log.info("非月末,跳过场景6定时抓取");
  77 + return;
  78 + }
  79 + runQuality("场景6", "SYNC0006");
  80 + }
  81 +
  82 + /** 质量域场景7(SYNC0007 经销商三包索赔):每月5号抓上月。 */
  83 + @Scheduled(cron = "${jdy-risk.schedule.s7-cron:0 0 3 5 * ?}")
  84 + public void monthlySyncS7() { runQuality("场景7", "SYNC0007"); }
  85 +
  86 + /** 质量域场景8(SYNC0008 三包库房超期未处理):每月5号,按上月末增量统计超期。 */
  87 + @Scheduled(cron = "${jdy-risk.schedule.s8-cron:0 0 3 5 * ?}")
  88 + public void monthlySyncS8() { runQuality("场景8", "SYNC0008"); }
  89 +
  90 + /** 质量域场景9(SYNC0010 供应商未开CR):每月5号抓上月。 */
  91 + @Scheduled(cron = "${jdy-risk.schedule.s9-cron:0 0 3 5 * ?}")
  92 + public void monthlySyncS9() { runQuality("场景9", "SYNC0010"); }
  93 +
  94 + /** 质量域场景10(SYNC0011 工程师未开CR):每月5号抓上月。 */
  95 + @Scheduled(cron = "${jdy-risk.schedule.s10-cron:0 0 3 5 * ?}")
  96 + public void monthlySyncS10() { runQuality("场景10", "SYNC0011"); }
  97 +
45 98 /** 设备域场景12(SYNC0034):每月1号抓取当年数据。 */
46 99 @Scheduled(cron = "${jdy-risk.schedule.s12-cron:0 0 3 1 * ?}")
47 100 public void monthlySyncS12() {
... ... @@ -108,20 +161,54 @@ public class JdySyncScheduledTask {
108 161 run("场景19", "SYNC0043");
109 162 }
110 163
111   - /** 管理域场景23(SYNC0013 CS95 油耗):每月1号1点抓上月数据。 */
112   - @Scheduled(cron = "${jdy-risk.schedule.s23-cron:0 0 1 1 * ?}")
  164 + /** 设备域场景20(SYNC0039 废料预警,人大金仓):每月12号 01:00 抓上月数据。 */
  165 + @Scheduled(cron = "${jdy-risk.schedule.s20-cron:0 0 1 12 * ?}")
  166 + public void monthlySyncS20() {
  167 + run("场景20", "count_20");
  168 + }
  169 +
  170 + /** 设备域场景21(SYNC0040 过磅记录,人大金仓):每月11号 01:00 抓1-10号数据。 */
  171 + @Scheduled(cron = "${jdy-risk.schedule.s21a-cron:0 0 1 11 * ?}")
  172 + public void monthlySyncS21a() {
  173 + run("场景21", "count_21");
  174 + }
  175 +
  176 + /** 设备域场景21(SYNC0040):每月21号 01:00 抓11-20号数据。 */
  177 + @Scheduled(cron = "${jdy-risk.schedule.s21b-cron:0 0 1 21 * ?}")
  178 + public void monthlySyncS21b() {
  179 + run("场景21", "count_21");
  180 + }
  181 +
  182 + /** 设备域场景21(SYNC0040):每月最后一天 23:00 抓21号至月底数据(每天23点触发,月末执行)。 */
  183 + @Scheduled(cron = "${jdy-risk.schedule.s21c-cron:0 0 23 * * ?}")
  184 + public void monthlySyncS21c() {
  185 + if (!isLastDayOfMonth()) {
  186 + log.info("非月末,跳过场景21(21号至月底)定时抓取");
  187 + return;
  188 + }
  189 + run("场景21", "count_21");
  190 + }
  191 +
  192 + /** 设备域场景22(SYNC0041 运输异常,人大金仓):每月1号 01:00 抓上月数据。 */
  193 + @Scheduled(cron = "${jdy-risk.schedule.s22-cron:0 0 1 1 * ?}")
  194 + public void monthlySyncS22() {
  195 + run("场景22", "count_22");
  196 + }
  197 +
  198 + /** 管理域场景23(SYNC0013 CS95 油耗):每月1号抓上月16号~月底,16号抓当月1号~15号。 */
  199 + @Scheduled(cron = "${jdy-risk.schedule.s23-cron:0 0 1 1,16 * ?}")
113 200 public void monthlySyncS23() {
114 201 run("场景23", "SYNC0013");
115 202 }
116 203
117   - /** 管理域场景24(SYNC0014 CS75 油耗):每月1号1点抓上月数据。 */
118   - @Scheduled(cron = "${jdy-risk.schedule.s24-cron:0 0 1 1 * ?}")
  204 + /** 管理域场景24(SYNC0014 CS75 油耗):每月1号抓上月16号~月底,16号抓当月1号~15号。 */
  205 + @Scheduled(cron = "${jdy-risk.schedule.s24-cron:0 0 1 1,16 * ?}")
119 206 public void monthlySyncS24() {
120 207 run("场景24", "SYNC0014");
121 208 }
122 209
123   - /** 管理域场景25(SYNC0015 全顺 油耗):每月1号1点抓上月数据。 */
124   - @Scheduled(cron = "${jdy-risk.schedule.s25-cron:0 0 1 1 * ?}")
  210 + /** 管理域场景25(SYNC0015 全顺 油耗):每月1号抓上月16号~月底,16号抓当月1号~15号。 */
  211 + @Scheduled(cron = "${jdy-risk.schedule.s25-cron:0 0 1 1,16 * ?}")
125 212 public void monthlySyncS25() {
126 213 run("场景25", "SYNC0015");
127 214 }
... ... @@ -132,11 +219,83 @@ public class JdySyncScheduledTask {
132 219 run("场景26", "SYNC0016");
133 220 }
134 221
  222 + @Scheduled(cron = "${jdy-risk.schedule.s28-cron:0 0 23 * * ?}")
  223 + public void monthlySyncS28() { if (isLastDayOfMonth()) { run("场景28", "SYNC0024"); } }
  224 +
  225 + @Scheduled(cron = "${jdy-risk.schedule.s29-cron:0 0 23 * * ?}")
  226 + public void monthlySyncS29() { if (isLastDayOfMonth()) { run("场景29", "SYNC0025"); } }
  227 +
  228 + @Scheduled(cron = "${jdy-risk.schedule.s30-cron:0 0 23 * * ?}")
  229 + public void monthlySyncS30() { if (isLastDayOfMonth()) { run("场景30", "SYNC0026"); } }
  230 +
  231 + @Scheduled(cron = "${jdy-risk.schedule.s31-cron:0 0 1 1 1,4,7,10 ?}")
  232 + public void quarterlySyncS31() { run("场景31", "SYNC0017"); }
  233 +
  234 + @Scheduled(cron = "${jdy-risk.schedule.s32-cron:0 0 1 1 1,4,7,10 ?}")
  235 + public void quarterlySyncS32() { run("场景32", "SYNC0018"); }
  236 +
  237 + @Scheduled(cron = "${jdy-risk.schedule.s33-cron:0 0 1 1 1,4,7,10 ?}")
  238 + public void quarterlySyncS33() { run("场景33", "SYNC0019"); }
  239 +
  240 + @Scheduled(cron = "${jdy-risk.schedule.s34-cron:0 0 1 1 1,4,7,10 ?}")
  241 + public void quarterlySyncS34() { run("场景34", "SYNC0020"); }
  242 +
  243 + @Scheduled(cron = "${jdy-risk.schedule.s35-cron:0 0 1 1 1,4,7,10 ?}")
  244 + public void quarterlySyncS35() { run("场景35", "SYNC0021"); }
  245 +
  246 + @Scheduled(cron = "${jdy-risk.schedule.s36-cron:0 0 1 1 1,4,7,10 ?}")
  247 + public void quarterlySyncS36() { run("场景36", "SYNC0022"); }
  248 +
  249 + @Scheduled(cron = "${jdy-risk.schedule.s37-cron:0 0 23 31 12 ?}")
  250 + public void yearlySyncS37() { run("场景37", "SYNC0023"); }
  251 +
  252 + /** 场景38(SYNC0036 索赔流程超时):每月10号抓上月。 */
  253 + @Scheduled(cron = "${jdy-risk.schedule.s38-cron:0 0 3 10 * ?}")
  254 + public void monthlySyncS38() { run("场景38", "count_38"); }
  255 +
  256 + /** 场景39/40(SYNC0027/0028 退货TOP3):每月5号抓上月。 */
  257 + @Scheduled(cron = "${jdy-risk.schedule.s39-cron:0 0 3 5 * ?}")
  258 + public void monthlySyncS39() { run("场景39", "count_39"); }
  259 +
  260 + @Scheduled(cron = "${jdy-risk.schedule.s40-cron:0 0 3 5 * ?}")
  261 + public void monthlySyncS40() { run("场景40", "count_40"); }
  262 +
  263 + /** 场景41~47(SYNC0029~SYNC0035 库存资金占用):每月5号抓上月。 */
  264 + @Scheduled(cron = "${jdy-risk.schedule.s41-cron:0 0 3 5 * ?}")
  265 + public void monthlySyncS41() { run("场景41", "count_41"); }
  266 +
  267 + @Scheduled(cron = "${jdy-risk.schedule.s42-cron:0 0 3 5 * ?}")
  268 + public void monthlySyncS42() { run("场景42", "count_42"); }
  269 +
  270 + @Scheduled(cron = "${jdy-risk.schedule.s43-cron:0 0 3 5 * ?}")
  271 + public void monthlySyncS43() { run("场景43", "count_43"); }
  272 +
  273 + @Scheduled(cron = "${jdy-risk.schedule.s44-cron:0 0 3 5 * ?}")
  274 + public void monthlySyncS44() { run("场景44", "count_44"); }
  275 +
  276 + @Scheduled(cron = "${jdy-risk.schedule.s45-cron:0 0 3 5 * ?}")
  277 + public void monthlySyncS45() { run("场景45", "count_45"); }
  278 +
  279 + @Scheduled(cron = "${jdy-risk.schedule.s46-cron:0 0 3 5 * ?}")
  280 + public void monthlySyncS46() { run("场景46", "count_46"); }
  281 +
  282 + @Scheduled(cron = "${jdy-risk.schedule.s47-cron:0 0 3 5 * ?}")
  283 + public void monthlySyncS47() { run("场景47", "count_47"); }
  284 +
135 285 private static boolean isLastDayOfMonth() {
136 286 java.time.LocalDate now = java.time.LocalDate.now(java.time.ZoneId.of("Asia/Shanghai"));
137 287 return now.getDayOfMonth() == now.lengthOfMonth();
138 288 }
139 289
  290 + private void runQuality(String label, String syncCode) {
  291 + if (!riskProps.getSchedule().isEnabled()) {
  292 + log.info("jdy-risk.schedule.enabled=false,跳过{}定时抓取", label);
  293 + return;
  294 + }
  295 + log.info("========== 定时抓取 质量域{}({}) ==========", label, syncCode);
  296 + log.info("{}结果: {}", label, riskService.countAndSyncOne(syncCode));
  297 + }
  298 +
140 299 private void run(String label, String syncCode) {
141 300 if (!riskProps.getSchedule().isEnabled()) {
142 301 log.info("jdy-risk.schedule.enabled=false,跳过{}定时抓取", label);
... ...
1 1 package com.qgutech.qgyun.apaas.sync.jdy.util;
2 2
  3 +import org.apache.http.client.config.RequestConfig;
3 4 import org.apache.http.config.Registry;
4 5 import org.apache.http.config.RegistryBuilder;
5 6 import org.apache.http.conn.socket.ConnectionSocketFactory;
... ... @@ -64,9 +65,15 @@ public class SSLClientCustom {
64 65 * @throws Exception
65 66 */
66 67 public static CloseableHttpClient getHttpClinet() throws Exception {
  68 + RequestConfig requestConfig = RequestConfig.custom()
  69 + .setConnectTimeout(30000)
  70 + .setConnectionRequestTimeout(30000)
  71 + .setSocketTimeout(120000)
  72 + .build();
67 73 CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory)
68 74 .setConnectionManager(poolingHttpClientConnectionManager)
69 75 .setConnectionManagerShared(true)
  76 + .setDefaultRequestConfig(requestConfig)
70 77 .build();
71 78 return httpClient;
72 79 }
... ...