Showing
13 changed files
with
2909 additions
and
115 deletions
| 1 | 1 | # ============================================================================= |
| 2 | -# 风险场景统计配置(外显配置,放在 jar 运行目录,Spring Boot 自动加载) | |
| 3 | -# 修改本文件后无需重新打包,重启应用即可生效。 | |
| 4 | -# | |
| 5 | -# 新增场景:复制一段 jdy-risk.scenarios[n].xxx,n 递增,按场景类型填字段: | |
| 6 | -# type=scenario1:全量,满足 总计>=5 且 差值>=1 且 flowState=in-progress-state | |
| 7 | -# 需填 total-field / diff-field / in-progress-state | |
| 8 | -# type=scenario2:当月,按 group-field 分组,SI数量/问题数量合计>60% 且 合计>=5 的分组数 | |
| 9 | -# 需填 date-field / group-field / si-field / qty-field / month-only | |
| 10 | -# type=scenario3:当月,SI占比>60% 且 总问题数>=5 的行数 | |
| 11 | -# 需填 date-field / total-field / ratio-field / month-only | |
| 12 | -# 每个场景的 sync-code 对应启效目标记录的 syncCode,统计结果写入 qx.count-field 字段。 | |
| 2 | +# Risk scenario configuration (external; loaded by Spring Boot from the run dir) | |
| 3 | +# After editing, just restart the app (no repackaging needed). | |
| 4 | +# IMPORTANT: .properties is read as ISO-8859-1. Do NOT put raw Chinese here; | |
| 5 | +# use \uXXXX escapes for any Chinese value. Comments kept ASCII on purpose. | |
| 13 | 6 | # ============================================================================= |
| 14 | 7 | |
| 15 | -# ---------- 简道云(长安) ---------- | |
| 8 | +# ---------- Jiandaoyun (Changan) ---------- | |
| 16 | 9 | jdy-risk.host=https://jdy.changan.com.cn/api |
| 17 | 10 | jdy-risk.api-key=lOnr4ms8jfc0gbCwVYS7YtbYQXjBFq979Cc06BcC866427b2a7aAd054598Bc7bB |
| 18 | 11 | |
| 19 | -# ---------- 启效(QX) 写回目标 ---------- | |
| 12 | +# ---------- QX write-back target ---------- | |
| 20 | 13 | jdy-risk.qx.base-url=https://hfca.uat3.qgutech.com |
| 21 | 14 | jdy-risk.qx.username=15077901670 |
| 22 | 15 | jdy-risk.qx.password=000000 |
| ... | ... | @@ -25,13 +18,16 @@ jdy-risk.qx.app-id=sEOSZ8EPwdrzJB41amD |
| 25 | 18 | jdy-risk.qx.query-code=ilr3ne7bPage |
| 26 | 19 | jdy-risk.qx.sync-query-param=pcqqjoquery |
| 27 | 20 | jdy-risk.qx.update-code=11a41Update |
| 21 | +jdy-risk.qx.add-code=11a41Add | |
| 28 | 22 | jdy-risk.qx.count-field=chcbxt |
| 29 | 23 | jdy-risk.qx.attach-field=hciwkz |
| 30 | 24 | jdy-risk.qx.time-field=bswivu |
| 25 | +# second date field updated together with warning time (only if present) | |
| 26 | +jdy-risk.qx.time-field-2=dgqshv | |
| 31 | 27 | |
| 32 | -# ---------- 场景1:3mis 风险监控(全量) ---------- | |
| 28 | +# ---------- Scenario 1: 3mis (all data) ---------- | |
| 33 | 29 | jdy-risk.scenarios[0].id=count_1 |
| 34 | -jdy-risk.scenarios[0].name=3mis风险监控 | |
| 30 | +jdy-risk.scenarios[0].name=scene1 | |
| 35 | 31 | jdy-risk.scenarios[0].type=scenario1 |
| 36 | 32 | jdy-risk.scenarios[0].sync-code=SYNC0001 |
| 37 | 33 | jdy-risk.scenarios[0].app-id=65fd5c0e0d1f1a7ae4f038ec |
| ... | ... | @@ -41,9 +37,9 @@ jdy-risk.scenarios[0].diff-field=_widget_1768888148019 |
| 41 | 37 | jdy-risk.scenarios[0].in-progress-state=0 |
| 42 | 38 | jdy-risk.scenarios[0].month-only=false |
| 43 | 39 | |
| 44 | -# ---------- 场景2:供应商 SI 占比风险监控(当月,按供应商分组) ---------- | |
| 40 | +# ---------- Scenario 2: supplier SI ratio (prev month) ---------- | |
| 45 | 41 | jdy-risk.scenarios[1].id=count_2 |
| 46 | -jdy-risk.scenarios[1].name=供应商SI占比风险监控 | |
| 42 | +jdy-risk.scenarios[1].name=scene2 | |
| 47 | 43 | jdy-risk.scenarios[1].type=scenario2 |
| 48 | 44 | jdy-risk.scenarios[1].sync-code=SYNC0002 |
| 49 | 45 | jdy-risk.scenarios[1].app-id=65f8060f8666b8a5d1b98d57 |
| ... | ... | @@ -53,10 +49,11 @@ jdy-risk.scenarios[1].group-field=_widget_1778638131431 |
| 53 | 49 | jdy-risk.scenarios[1].si-field=_widget_1778638131430 |
| 54 | 50 | jdy-risk.scenarios[1].qty-field=_widget_1778638131418 |
| 55 | 51 | jdy-risk.scenarios[1].prev-month-only=true |
| 52 | +jdy-risk.scenarios[1].only-warn-rows=true | |
| 56 | 53 | |
| 57 | -# ---------- 场景3:工程师 SI 占比风险监控(当月) ---------- | |
| 54 | +# ---------- Scenario 3: engineer SI ratio (prev month) ---------- | |
| 58 | 55 | jdy-risk.scenarios[2].id=count_3 |
| 59 | -jdy-risk.scenarios[2].name=工程师SI占比风险监控 | |
| 56 | +jdy-risk.scenarios[2].name=scene3 | |
| 60 | 57 | jdy-risk.scenarios[2].type=scenario3 |
| 61 | 58 | jdy-risk.scenarios[2].sync-code=SYNC0003 |
| 62 | 59 | jdy-risk.scenarios[2].app-id=65f8060f8666b8a5d1b98d57 |
| ... | ... | @@ -66,10 +63,12 @@ jdy-risk.scenarios[2].total-field=_widget_1780039427422 |
| 66 | 63 | jdy-risk.scenarios[2].ratio-field=_widget_1780039778663 |
| 67 | 64 | jdy-risk.scenarios[2].prev-month-only=true |
| 68 | 65 | jdy-risk.scenarios[2].extra-field=_widget_1780039427417 |
| 66 | +jdy-risk.scenarios[2].only-warn-rows=true | |
| 67 | +jdy-risk.scenarios[2].percent-fields[0]=_widget_1780039778663 | |
| 69 | 68 | |
| 70 | -# ---------- 场景4:CR导出-按供应商(升级不含QR/空白,当季度) ---------- | |
| 69 | +# ---------- Scenario 4: CR upgrade - supplier (prev quarter) ---------- | |
| 71 | 70 | jdy-risk.scenarios[3].id=count_4 |
| 72 | -jdy-risk.scenarios[3].name=供应商升级风险监控 | |
| 71 | +jdy-risk.scenarios[3].name=scene4 | |
| 73 | 72 | jdy-risk.scenarios[3].type=scenario4 |
| 74 | 73 | jdy-risk.scenarios[3].sync-code=SYNC0004 |
| 75 | 74 | jdy-risk.scenarios[3].app-id=65f8060f8666b8a5d1b98d57 |
| ... | ... | @@ -81,9 +80,9 @@ jdy-risk.scenarios[3].exclude-values[0]=QR |
| 81 | 80 | jdy-risk.scenarios[3].min-count=3 |
| 82 | 81 | jdy-risk.scenarios[3].prev-quarter-only=true |
| 83 | 82 | |
| 84 | -# ---------- 场景5:CR导出-按IQ工程师(升级不含QR/空白,当季度) ---------- | |
| 83 | +# ---------- Scenario 5: CR upgrade - engineer (prev quarter) ---------- | |
| 85 | 84 | jdy-risk.scenarios[4].id=count_5 |
| 86 | -jdy-risk.scenarios[4].name=工程师升级风险监控 | |
| 85 | +jdy-risk.scenarios[4].name=scene5 | |
| 87 | 86 | jdy-risk.scenarios[4].type=scenario5 |
| 88 | 87 | jdy-risk.scenarios[4].sync-code=SYNC0005 |
| 89 | 88 | jdy-risk.scenarios[4].app-id=65f8060f8666b8a5d1b98d57 |
| ... | ... | @@ -94,10 +93,11 @@ jdy-risk.scenarios[4].up-field=_widget_1752543725813 |
| 94 | 93 | jdy-risk.scenarios[4].exclude-values[0]=QR |
| 95 | 94 | jdy-risk.scenarios[4].min-count=3 |
| 96 | 95 | jdy-risk.scenarios[4].prev-quarter-only=true |
| 96 | +jdy-risk.scenarios[4].only-warn-rows=true | |
| 97 | 97 | |
| 98 | -# ---------- 场景6:三包索赔申诉台账-经销商(当年,次数>=3) ---------- | |
| 98 | +# ---------- Scenario 6: dealer repeated claims (current year) ---------- | |
| 99 | 99 | jdy-risk.scenarios[5].id=count_6 |
| 100 | -jdy-risk.scenarios[5].name=经销商三包索赔风险监控 | |
| 100 | +jdy-risk.scenarios[5].name=scene6 | |
| 101 | 101 | jdy-risk.scenarios[5].type=scenario6 |
| 102 | 102 | jdy-risk.scenarios[5].sync-code=SYNC0007 |
| 103 | 103 | jdy-risk.scenarios[5].app-id=65f8060f8666b8a5d1b98d57 |
| ... | ... | @@ -107,9 +107,9 @@ jdy-risk.scenarios[5].group-field=_widget_1753429694911 |
| 107 | 107 | jdy-risk.scenarios[5].min-count=3 |
| 108 | 108 | jdy-risk.scenarios[5].year-only=true |
| 109 | 109 | |
| 110 | -# ---------- 场景7:三包库房进库-超期未处理(180天,排除已出库/已抵扣) ---------- | |
| 110 | +# ---------- Scenario 7: 3bao warehouse overdue (180 days) ---------- | |
| 111 | 111 | jdy-risk.scenarios[6].id=count_7 |
| 112 | -jdy-risk.scenarios[6].name=三包库房超期未处理风险监控 | |
| 112 | +jdy-risk.scenarios[6].name=scene7 | |
| 113 | 113 | jdy-risk.scenarios[6].type=scenario7 |
| 114 | 114 | jdy-risk.scenarios[6].sync-code=SYNC0008 |
| 115 | 115 | jdy-risk.scenarios[6].app-id=65f8060f8666b8a5d1b98d57 |
| ... | ... | @@ -117,7 +117,6 @@ jdy-risk.scenarios[6].entry-id=686b6f72fcb3f02a8ffc8fcd |
| 117 | 117 | jdy-risk.scenarios[6].barcode-field=_widget_1751871346824 |
| 118 | 118 | jdy-risk.scenarios[6].date-field=_widget_1751871346820 |
| 119 | 119 | jdy-risk.scenarios[6].max-age-days=180 |
| 120 | -# 主表只取这几列(经销商代码/经销商名称/入库时间/条码),减小传输 | |
| 121 | 120 | jdy-risk.scenarios[6].fields[0]=_widget_1751871346816 |
| 122 | 121 | jdy-risk.scenarios[6].fields[1]=_widget_1751871346817 |
| 123 | 122 | jdy-risk.scenarios[6].fields[2]=_widget_1751871346820 |
| ... | ... | @@ -127,9 +126,9 @@ jdy-risk.scenarios[6].exclude-forms[0].barcode-field=_widget_1751871441626 |
| 127 | 126 | jdy-risk.scenarios[6].exclude-forms[1].entry-id=686b781c11159446bb2583fc |
| 128 | 127 | jdy-risk.scenarios[6].exclude-forms[1].barcode-field=_widget_1751873565337 |
| 129 | 128 | |
| 130 | -# ---------- 场景8:料废登记台账-供应商(上月,未开CR占比>70%) ---------- | |
| 129 | +# ---------- Scenario 8: material-waste - supplier CR ratio (prev month) ---------- | |
| 131 | 130 | jdy-risk.scenarios[7].id=count_8 |
| 132 | -jdy-risk.scenarios[7].name=供应商未开CR风险监控 | |
| 131 | +jdy-risk.scenarios[7].name=scene8 | |
| 133 | 132 | jdy-risk.scenarios[7].type=scenario8 |
| 134 | 133 | jdy-risk.scenarios[7].sync-code=SYNC0010 |
| 135 | 134 | jdy-risk.scenarios[7].app-id=65f8060f8666b8a5d1b98d57 |
| ... | ... | @@ -140,10 +139,14 @@ jdy-risk.scenarios[7].flag-field=_widget_1769502015250 |
| 140 | 139 | jdy-risk.scenarios[7].flag-value=\u5426 |
| 141 | 140 | jdy-risk.scenarios[7].ratio-threshold=0.7 |
| 142 | 141 | jdy-risk.scenarios[7].prev-month-only=true |
| 142 | +jdy-risk.scenarios[7].only-warn-rows=true | |
| 143 | +jdy-risk.scenarios[7].lookup-field=_widget_1783921957534 | |
| 144 | +jdy-risk.scenarios[7].lookup-entry-id=6a545b1cc641f0ad493bd9df | |
| 145 | +jdy-risk.scenarios[7].lookup-name-field=_widget_1783913697901 | |
| 143 | 146 | |
| 144 | -# ---------- 场景9:料废登记台账-工程师(上月,未开CR占比>70%) ---------- | |
| 147 | +# ---------- Scenario 9: material-waste - engineer CR ratio (prev month) ---------- | |
| 145 | 148 | jdy-risk.scenarios[8].id=count_9 |
| 146 | -jdy-risk.scenarios[8].name=工程师未开CR风险监控 | |
| 149 | +jdy-risk.scenarios[8].name=scene9 | |
| 147 | 150 | jdy-risk.scenarios[8].type=scenario9 |
| 148 | 151 | jdy-risk.scenarios[8].sync-code=SYNC0011 |
| 149 | 152 | jdy-risk.scenarios[8].app-id=65f8060f8666b8a5d1b98d57 |
| ... | ... | @@ -154,18 +157,255 @@ jdy-risk.scenarios[8].flag-field=_widget_1769502015250 |
| 154 | 157 | jdy-risk.scenarios[8].flag-value=\u5426 |
| 155 | 158 | jdy-risk.scenarios[8].ratio-threshold=0.7 |
| 156 | 159 | jdy-risk.scenarios[8].prev-month-only=true |
| 160 | +jdy-risk.scenarios[8].only-warn-rows=true | |
| 161 | +jdy-risk.scenarios[8].lookup-field=_widget_1783921957534 | |
| 162 | +jdy-risk.scenarios[8].lookup-entry-id=6a545b1cc641f0ad493bd9df | |
| 163 | +jdy-risk.scenarios[8].lookup-name-field=_widget_1783913697901 | |
| 164 | + | |
| 165 | +# ---------- Scenario 10: claim-rate difference (current month) ---------- | |
| 166 | +jdy-risk.scenarios[9].id=count_10 | |
| 167 | +jdy-risk.scenarios[9].name=scene10 | |
| 168 | +jdy-risk.scenarios[9].type=scenario10 | |
| 169 | +jdy-risk.scenarios[9].sync-code=SYNC0006 | |
| 170 | +jdy-risk.scenarios[9].app-id=65f8060f8666b8a5d1b98d57 | |
| 171 | +jdy-risk.scenarios[9].entry-id=695f08df7680113783af422c | |
| 172 | +jdy-risk.scenarios[9].date-field=_widget_1767835871184 | |
| 173 | +jdy-risk.scenarios[9].diff-field=_widget_1767835871192 | |
| 174 | +jdy-risk.scenarios[9].abs-threshold=0.05 | |
| 175 | +jdy-risk.scenarios[9].month-only=true | |
| 176 | +jdy-risk.scenarios[9].percent-fields[0]=_widget_1767835871192 | |
| 177 | + | |
| 178 | +# ---------- Scenario 11: 3bao stocktake barcode diff (all data) ---------- | |
| 179 | +jdy-risk.scenarios[10].id=count_11 | |
| 180 | +jdy-risk.scenarios[10].name=scene11 | |
| 181 | +jdy-risk.scenarios[10].type=scenario11 | |
| 182 | +jdy-risk.scenarios[10].sync-code=SYNC009 | |
| 183 | +jdy-risk.scenarios[10].app-id=65f8060f8666b8a5d1b98d57 | |
| 184 | +jdy-risk.scenarios[10].entry-id=6ab4d9abd87880e5d89e137c | |
| 185 | +jdy-risk.scenarios[10].barcode-field=_widget_1790237099873 | |
| 186 | +jdy-risk.scenarios[10].compare-entry-id=6ab4dc5ff51dec2d82337f32 | |
| 187 | +jdy-risk.scenarios[10].compare-barcode-field=_widget_1790237791434 | |
| 188 | +jdy-risk.scenarios[10].exclude-forms[0].entry-id=686b781c11159446bb2583fc | |
| 189 | +jdy-risk.scenarios[10].exclude-forms[0].barcode-field=_widget_1751873565337 | |
| 190 | + | |
| 191 | +# ---------- Scenario 12: confidential agreement - missing signature (current year, SYNC0034) ---------- | |
| 192 | +jdy-risk.scenarios[11].id=count_12 | |
| 193 | +jdy-risk.scenarios[11].name=scene12 | |
| 194 | +jdy-risk.scenarios[11].type=scenario12 | |
| 195 | +jdy-risk.scenarios[11].sync-code=SYNC0034 | |
| 196 | +jdy-risk.scenarios[11].app-id=662b1048948f7cc7d489bdd4 | |
| 197 | +jdy-risk.scenarios[11].entry-id=69d6eccd53a601ab7f2d05ec | |
| 198 | +jdy-risk.scenarios[11].date-field=_widget_1775780546733 | |
| 199 | +jdy-risk.scenarios[11].year-only=true | |
| 200 | +jdy-risk.scenarios[11].pairs[0].person-field=_widget_1775693007217 | |
| 201 | +jdy-risk.scenarios[11].pairs[0].sign-field=_widget_1775693007223 | |
| 202 | +jdy-risk.scenarios[11].pairs[1].person-field=_widget_1775693007219 | |
| 203 | +jdy-risk.scenarios[11].pairs[1].sign-field=_widget_1775693007225 | |
| 204 | +jdy-risk.scenarios[11].pairs[2].person-field=_widget_1775693007218 | |
| 205 | +jdy-risk.scenarios[11].pairs[2].sign-field=_widget_1775693007226 | |
| 206 | +jdy-risk.scenarios[11].pairs[3].person-field=_widget_1775693007220 | |
| 207 | +jdy-risk.scenarios[11].pairs[3].sign-field=_widget_1775693007227 | |
| 208 | +jdy-risk.scenarios[11].pairs[4].person-field=_widget_1775693007221 | |
| 209 | +jdy-risk.scenarios[11].pairs[4].sign-field=_widget_1775693007228 | |
| 210 | + | |
| 211 | +# ---------- Scenario 13: weighing - stay time anomaly (prev month, SYNC0042) ---------- | |
| 212 | +jdy-risk.scenarios[12].id=count_13 | |
| 213 | +jdy-risk.scenarios[12].name=scene13 | |
| 214 | +jdy-risk.scenarios[12].type=scenario13 | |
| 215 | +jdy-risk.scenarios[12].sync-code=SYNC0042 | |
| 216 | +jdy-risk.scenarios[12].app-id=662b1048948f7cc7d489bdd4 | |
| 217 | +jdy-risk.scenarios[12].entry-id=6aa3a551b26cc791596892dc | |
| 218 | +jdy-risk.scenarios[12].date-field=_widget_1789109585493 | |
| 219 | +jdy-risk.scenarios[12].prev-month-only=true | |
| 220 | +jdy-risk.scenarios[12].duration-field=_widget_1789109585495 | |
| 221 | +jdy-risk.scenarios[12].duration-threshold=10 | |
| 222 | +jdy-risk.scenarios[12].abnormal-field=_widget_1791451544499 | |
| 223 | +jdy-risk.scenarios[12].abnormal-value=\u5b58\u5728\u5f02\u5e38 | |
| 224 | +jdy-risk.scenarios[12].reason-field=_widget_1789464764187 | |
| 225 | + | |
| 226 | +# ---------- Scenario 14: unqualified material - same supplier >=3/year (SYNC0048) ---------- | |
| 227 | +jdy-risk.scenarios[13].id=count_14 | |
| 228 | +jdy-risk.scenarios[13].name=scene14 | |
| 229 | +jdy-risk.scenarios[13].type=scenario14 | |
| 230 | +jdy-risk.scenarios[13].sync-code=SYNC0048 | |
| 231 | +jdy-risk.scenarios[13].app-id=662b1048948f7cc7d489bdd4 | |
| 232 | +jdy-risk.scenarios[13].entry-id=6a0bace9e162c4f1abdbcf70 | |
| 233 | +jdy-risk.scenarios[13].date-field=_widget_1779150058654 | |
| 234 | +jdy-risk.scenarios[13].year-only=true | |
| 235 | +jdy-risk.scenarios[13].group-field=_widget_1779150058655 | |
| 236 | +jdy-risk.scenarios[13].min-count=3 | |
| 237 | + | |
| 238 | +# ---------- Scenario 15: maintenance - missing conditional photos (prev month, SYNC0044) ---------- | |
| 239 | +jdy-risk.scenarios[14].id=count_15 | |
| 240 | +jdy-risk.scenarios[14].name=scene15 | |
| 241 | +jdy-risk.scenarios[14].type=scenario15 | |
| 242 | +jdy-risk.scenarios[14].sync-code=SYNC0044 | |
| 243 | +jdy-risk.scenarios[14].app-id=662b1048948f7cc7d489bdd4 | |
| 244 | +jdy-risk.scenarios[14].entry-id=69d758c153a601ab7f51c1f9 | |
| 245 | +jdy-risk.scenarios[14].date-field=updateTime | |
| 246 | +jdy-risk.scenarios[14].prev-month-only=true | |
| 247 | +jdy-risk.scenarios[14].flow-state-value=1 | |
| 248 | +jdy-risk.scenarios[14].photo-rules[0].flag-field=_widget_1776388345381 | |
| 249 | +jdy-risk.scenarios[14].photo-rules[0].photo-field=_widget_1776388345389 | |
| 250 | +jdy-risk.scenarios[14].photo-rules[1].flag-field=_widget_1776388345383 | |
| 251 | +jdy-risk.scenarios[14].photo-rules[1].photo-field=_widget_1776388345391 | |
| 252 | +jdy-risk.scenarios[14].photo-rules[2].flag-field=_widget_1776388345385 | |
| 253 | +jdy-risk.scenarios[14].photo-rules[2].photo-field=_widget_1776388345393 | |
| 254 | + | |
| 255 | +# ---------- Scenario 16: budget accuracy - over budget without reason (current month, SYNC0045) ---------- | |
| 256 | +jdy-risk.scenarios[15].id=count_16 | |
| 257 | +jdy-risk.scenarios[15].name=scene16 | |
| 258 | +jdy-risk.scenarios[15].type=scenario16 | |
| 259 | +jdy-risk.scenarios[15].sync-code=SYNC0045 | |
| 260 | +jdy-risk.scenarios[15].app-id=662b1048948f7cc7d489bdd4 | |
| 261 | +jdy-risk.scenarios[15].entry-id=6a0d247a6532e2088f09f939 | |
| 262 | +jdy-risk.scenarios[15].date-field=createTime | |
| 263 | +jdy-risk.scenarios[15].month-only=true | |
| 264 | +jdy-risk.scenarios[15].flag-field=_widget_1779777375824 | |
| 265 | +jdy-risk.scenarios[15].flag-values[0]=\u9ad8\u9884\u7b97 | |
| 266 | +jdy-risk.scenarios[15].flag-values[1]=\u4f4e\u9884\u7b97 | |
| 267 | +jdy-risk.scenarios[15].reason-field=_widget_1788772233922 | |
| 268 | + | |
| 269 | +# ---------- Scenario 17: maintenance overdue >15 days (prev month by updateTime, SYNC0046) ---------- | |
| 270 | +jdy-risk.scenarios[16].id=count_17 | |
| 271 | +jdy-risk.scenarios[16].name=scene17 | |
| 272 | +jdy-risk.scenarios[16].type=scenario17 | |
| 273 | +jdy-risk.scenarios[16].sync-code=SYNC0046 | |
| 274 | +jdy-risk.scenarios[16].app-id=662b1048948f7cc7d489bdd4 | |
| 275 | +jdy-risk.scenarios[16].entry-id=69d758c153a601ab7f51c1f9 | |
| 276 | +jdy-risk.scenarios[16].date-field=updateTime | |
| 277 | +jdy-risk.scenarios[16].prev-month-only=true | |
| 278 | +jdy-risk.scenarios[16].flow-state-value=1 | |
| 279 | +jdy-risk.scenarios[16].plan-field=_widget_1776388345379 | |
| 280 | +jdy-risk.scenarios[16].actual-field=_widget_1776388345403 | |
| 281 | +jdy-risk.scenarios[16].overdue-days=15 | |
| 282 | + | |
| 283 | +# ---------- Scenario 18: auto reminder - audit docs not submitted (current month, SYNC0047) ---------- | |
| 284 | +jdy-risk.scenarios[17].id=count_18 | |
| 285 | +jdy-risk.scenarios[17].name=scene18 | |
| 286 | +jdy-risk.scenarios[17].type=scenario18 | |
| 287 | +jdy-risk.scenarios[17].sync-code=SYNC0047 | |
| 288 | +jdy-risk.scenarios[17].app-id=662b1048948f7cc7d489bdd4 | |
| 289 | +jdy-risk.scenarios[17].entry-id=6a28b64fe398b52f22b43c7b | |
| 290 | +jdy-risk.scenarios[17].date-field=_widget_1781145540776 | |
| 291 | +jdy-risk.scenarios[17].month-only=true | |
| 292 | +jdy-risk.scenarios[17].flag-field=_widget_1781053009425 | |
| 293 | +jdy-risk.scenarios[17].flag-values[0]=\u672a\u63d0\u4ea4 | |
| 294 | +jdy-risk.scenarios[17].reason-field=_widget_1791798454553 | |
| 295 | + | |
| 296 | +# ---------- Scenario 19: repeated similar project within 3 months (prev month, SYNC0043) ---------- | |
| 297 | +jdy-risk.scenarios[18].id=count_19 | |
| 298 | +jdy-risk.scenarios[18].name=scene19 | |
| 299 | +jdy-risk.scenarios[18].type=scenario19 | |
| 300 | +jdy-risk.scenarios[18].sync-code=SYNC0043 | |
| 301 | +jdy-risk.scenarios[18].app-id=662b1048948f7cc7d489bdd4 | |
| 302 | +jdy-risk.scenarios[18].entry-id=6ad0719e22f52b6b8f7d7891 | |
| 303 | +jdy-risk.scenarios[18].date-field=createTime | |
| 304 | +jdy-risk.scenarios[18].prev-month-only=true | |
| 305 | +jdy-risk.scenarios[18].flag-field=_widget_1792045471473 | |
| 306 | +jdy-risk.scenarios[18].flag-values[0]=\u662f | |
| 307 | + | |
| 308 | +# ---------- Scenario 23: CS95 fuel consumption (prev month, SYNC0013) ---------- | |
| 309 | +jdy-risk.scenarios[19].id=count_23 | |
| 310 | +jdy-risk.scenarios[19].name=scene23 | |
| 311 | +jdy-risk.scenarios[19].type=scenario20 | |
| 312 | +jdy-risk.scenarios[19].sync-code=SYNC0013 | |
| 313 | +jdy-risk.scenarios[19].app-id=6630634752eab8bdecbaee7d | |
| 314 | +jdy-risk.scenarios[19].entry-id=695df62e76801137838d4785 | |
| 315 | +jdy-risk.scenarios[19].date-field=_widget_1767769739507 | |
| 316 | +jdy-risk.scenarios[19].prev-month-only=true | |
| 317 | +jdy-risk.scenarios[19].flow-state-value=1 | |
| 318 | +jdy-risk.scenarios[19].flag-field=_widget_1779093489906 | |
| 319 | +jdy-risk.scenarios[19].flag-values[0]=\u662f | |
| 320 | +jdy-risk.scenarios[19].fuel-amount-field=_widget_1779093489909 | |
| 321 | +jdy-risk.scenarios[19].start-km-field=_widget_1767770394897 | |
| 322 | +jdy-risk.scenarios[19].subform-field=_widget_1779416742773 | |
| 323 | +jdy-risk.scenarios[19].subform-start-field=_widget_1779932645938 | |
| 324 | +jdy-risk.scenarios[19].min-value=9 | |
| 325 | +jdy-risk.scenarios[19].max-value=13 | |
| 326 | +jdy-risk.scenarios[19].include-previous-row=true | |
| 327 | + | |
| 328 | +# ---------- Scenario 24: CS75 fuel consumption (prev month, SYNC0014) ---------- | |
| 329 | +jdy-risk.scenarios[20].id=count_24 | |
| 330 | +jdy-risk.scenarios[20].name=scene24 | |
| 331 | +jdy-risk.scenarios[20].type=scenario20 | |
| 332 | +jdy-risk.scenarios[20].sync-code=SYNC0014 | |
| 333 | +jdy-risk.scenarios[20].app-id=6630634752eab8bdecbaee7d | |
| 334 | +jdy-risk.scenarios[20].entry-id=695df62e76801137838d4785 | |
| 335 | +jdy-risk.scenarios[20].date-field=_widget_1767769739507 | |
| 336 | +jdy-risk.scenarios[20].prev-month-only=true | |
| 337 | +jdy-risk.scenarios[20].flow-state-value=1 | |
| 338 | +jdy-risk.scenarios[20].flag-field=_widget_1779093489911 | |
| 339 | +jdy-risk.scenarios[20].flag-values[0]=\u662f | |
| 340 | +jdy-risk.scenarios[20].fuel-amount-field=_widget_1779093489913 | |
| 341 | +jdy-risk.scenarios[20].start-km-field=_widget_1767918395737 | |
| 342 | +jdy-risk.scenarios[20].subform-field=_widget_1779416742817 | |
| 343 | +jdy-risk.scenarios[20].subform-start-field=_widget_1779416742834 | |
| 344 | +jdy-risk.scenarios[20].min-value=8 | |
| 345 | +jdy-risk.scenarios[20].max-value=11 | |
| 346 | +jdy-risk.scenarios[20].include-previous-row=true | |
| 347 | + | |
| 348 | +# ---------- Scenario 25: Transit fuel consumption (prev month, SYNC0015; Excel has current + previous) ---------- | |
| 349 | +jdy-risk.scenarios[21].id=count_25 | |
| 350 | +jdy-risk.scenarios[21].name=scene25 | |
| 351 | +jdy-risk.scenarios[21].type=scenario20 | |
| 352 | +jdy-risk.scenarios[21].sync-code=SYNC0015 | |
| 353 | +jdy-risk.scenarios[21].app-id=6630634752eab8bdecbaee7d | |
| 354 | +jdy-risk.scenarios[21].entry-id=695df62e76801137838d4785 | |
| 355 | +jdy-risk.scenarios[21].date-field=_widget_1767769739507 | |
| 356 | +jdy-risk.scenarios[21].prev-month-only=true | |
| 357 | +jdy-risk.scenarios[21].flow-state-value=1 | |
| 358 | +jdy-risk.scenarios[21].flag-field=_widget_1779093489926 | |
| 359 | +jdy-risk.scenarios[21].flag-values[0]=\u662f | |
| 360 | +jdy-risk.scenarios[21].fuel-amount-field=_widget_1779093489925 | |
| 361 | +jdy-risk.scenarios[21].start-km-field=_widget_1767921522987 | |
| 362 | +jdy-risk.scenarios[21].subform-field=_widget_1779416742867 | |
| 363 | +jdy-risk.scenarios[21].subform-start-field=_widget_1779416742869 | |
| 364 | +jdy-risk.scenarios[21].min-value=9 | |
| 365 | +jdy-risk.scenarios[21].max-value=16 | |
| 366 | +jdy-risk.scenarios[21].include-previous-row=true | |
| 367 | + | |
| 368 | +# ---------- Scenario 26: labor company evaluation - bottom 3 for 3 consecutive months (SYNC0016) ---------- | |
| 369 | +jdy-risk.scenarios[22].id=count_26 | |
| 370 | +jdy-risk.scenarios[22].name=scene26 | |
| 371 | +jdy-risk.scenarios[22].type=scenario21 | |
| 372 | +jdy-risk.scenarios[22].sync-code=SYNC0016 | |
| 373 | +jdy-risk.scenarios[22].app-id=689eb35228eeda25cbb2084e | |
| 374 | +jdy-risk.scenarios[22].entry-id=69c4f27622c92f4b21be8d7e | |
| 375 | +jdy-risk.scenarios[22].date-field=_widget_1774514807959 | |
| 376 | +jdy-risk.scenarios[22].prev-three-months=true | |
| 377 | +jdy-risk.scenarios[22].flag-field=_widget_1792396908333 | |
| 378 | +jdy-risk.scenarios[22].flag-values[0]=\u662f | |
| 379 | +jdy-risk.scenarios[22].bottom-count=3 | |
| 380 | +jdy-risk.scenarios[22].company-fields[0]=_widget_1774514807956 | |
| 381 | +jdy-risk.scenarios[22].company-fields[1]=_widget_1774581058600 | |
| 382 | +jdy-risk.scenarios[22].company-fields[2]=_widget_1774581058602 | |
| 383 | +jdy-risk.scenarios[22].company-fields[3]=_widget_1774581058603 | |
| 384 | +jdy-risk.scenarios[22].company-fields[4]=_widget_1774581058604 | |
| 385 | +jdy-risk.scenarios[22].company-fields[5]=_widget_1774581058605 | |
| 386 | +jdy-risk.scenarios[22].company-fields[6]=_widget_1774581058606 | |
| 387 | +jdy-risk.scenarios[22].company-fields[7]=_widget_1774581058601 | |
| 388 | + | |
| 389 | +# ---------- Risk scenario scheduled tasks ---------- | |
| 390 | +jdy-risk.schedule.enabled=true | |
| 391 | +jdy-risk.schedule.s12-cron=0 0 3 1 * ? | |
| 392 | +jdy-risk.schedule.s13-cron=0 0 3 10 * ? | |
| 393 | +jdy-risk.schedule.s14-cron=0 0 3 20 12 ? | |
| 394 | +jdy-risk.schedule.s15-cron=0 0 3 1 * ? | |
| 395 | +jdy-risk.schedule.s16-cron=0 0 23 * * ? | |
| 396 | +jdy-risk.schedule.s17-cron=0 0 3 1 * ? | |
| 397 | +jdy-risk.schedule.s18-cron=0 0 23 * * ? | |
| 398 | +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 * ? | |
| 402 | +jdy-risk.schedule.s26-cron=0 0 1 1 * ? | |
| 157 | 403 | |
| 158 | 404 | # ============================================================================= |
| 159 | -# 表单同步配置(简道云表单结构/数据 -> 启效指定应用) | |
| 160 | -# 结构同步接口:POST /api/jdy/form/sync-structure | |
| 161 | -# 数据同步接口:POST /api/jdy/form/sync-data(当月数据,当天已存在则先删当天再同步) | |
| 162 | -# 新增表单:复制一段 jdy-form-sync.forms[n].xxx,n 递增 | |
| 405 | +# Form sync configuration | |
| 163 | 406 | # ============================================================================= |
| 164 | 407 | jdy-form-sync.jdy.host=https://jdy.changan.com.cn/api |
| 165 | 408 | jdy-form-sync.jdy.api-key=lOnr4ms8jfc0gbCwVYS7YtbYQXjBFq979Cc06BcC866427b2a7aAd054598Bc7bB |
| 166 | -# 可选:指定同步月份(yyyy-MM)用于补数/测试;留空=当前自然月(仅 month-only=true 时生效) | |
| 167 | -# jdy-form-sync.month=2026-08 | |
| 168 | -# Excel 导出目录(相对 jar 运行目录) | |
| 169 | 409 | jdy-form-sync.export-dir=./export |
| 170 | 410 | |
| 171 | 411 | jdy-form-sync.qx.base-url=https://hfca.uat3.qgutech.com |
| ... | ... | @@ -173,17 +413,34 @@ jdy-form-sync.qx.username=15077901670 |
| 173 | 413 | jdy-form-sync.qx.password=000000 |
| 174 | 414 | jdy-form-sync.qx.corp-code=hfca |
| 175 | 415 | jdy-form-sync.qx.app-id=sEOSZ8EPwdrzJB41amD |
| 176 | -jdy-form-sync.qx.app-name=风险预警平台 | |
| 416 | +jdy-form-sync.qx.app-name=\u98ce\u9669\u9884\u8b66\u5e73\u53f0 | |
| 177 | 417 | |
| 178 | -# 待同步表单:3mis争议件大于确定件(合肥长安_技术处) | |
| 179 | -# 注意:表单名默认从简道云接口取(避免 .properties 的 ISO-8859-1 中文乱码),此处不写中文名 | |
| 180 | 418 | jdy-form-sync.forms[0].app-id=65fd5c0e0d1f1a7ae4f038ec |
| 181 | 419 | jdy-form-sync.forms[0].entry-id=696f1754f141344a6b794f9c |
| 182 | 420 | jdy-form-sync.forms[0].fun-code=misDispute |
| 183 | -# 已有模型 id:填了则原地更新(不新建)。首次同步可留空 | |
| 184 | 421 | jdy-form-sync.forms[0].model-id=P1Vgt89QvFStKh7rDzl |
| 185 | -# 日期字段(用于「当月」过滤):简道云 日期时间 | |
| 186 | 422 | jdy-form-sync.forms[0].date-field=_widget_1773622123700 |
| 187 | -# 是否只同步当月;false=同步全部数据(本表单改为全量) | |
| 188 | 423 | jdy-form-sync.forms[0].month-only=false |
| 189 | 424 | |
| 425 | +# ============================================================================= | |
| 426 | +# Employee sync (biphr_ddm_empinfo_v -> QX employee form) | |
| 427 | +# ============================================================================= | |
| 428 | +emp-sync.kb.host=10.144.201.35 | |
| 429 | +emp-sync.kb.port=54321 | |
| 430 | +emp-sync.kb.database=qixiao-apaas | |
| 431 | +emp-sync.kb.username=qixiaoadmin | |
| 432 | +emp-sync.kb.password=Qx@20260821.com | |
| 433 | +emp-sync.kb.table=biphr_ddm_empinfo_v | |
| 434 | +emp-sync.kb.driver-class=com.kingbase8.Driver | |
| 435 | +emp-sync.kb.filter=level_2_dept = '\u5408\u80a5\u957f\u5b89\u6c7d\u8f66\u6709\u9650\u516c\u53f8' OR level_3_dept IN ('\u5408\u80a5\u7814\u7a76\u9662','\u5408\u80a5\u957f\u5b89\u91c7\u8d2d\u5904') | |
| 436 | + | |
| 437 | +emp-sync.qx.base-url=https://hfca.uat3.qgutech.com | |
| 438 | +emp-sync.qx.username=15077901670 | |
| 439 | +emp-sync.qx.password=000000 | |
| 440 | +emp-sync.qx.corp-code=hfca | |
| 441 | +emp-sync.qx.app-id=qrpUxHu55xJ3eQWFqEU | |
| 442 | +emp-sync.qx.page-code=j47lx0e4Page | |
| 443 | +emp-sync.qx.update-code=53e93Update | |
| 444 | +emp-sync.qx.add-code=53e93Add | |
| 445 | + | |
| 446 | +emp-sync.limit=0 | ... | ... |
| ... | ... | @@ -62,6 +62,13 @@ |
| 62 | 62 | <version>${poi.version}</version> |
| 63 | 63 | </dependency> |
| 64 | 64 | |
| 65 | + <!-- 人大金仓(KingbaseES) JDBC 驱动(读员工信息) --> | |
| 66 | + <dependency> | |
| 67 | + <groupId>cn.com.kingbase</groupId> | |
| 68 | + <artifactId>kingbase8</artifactId> | |
| 69 | + <version>8.6.0.jre7</version> | |
| 70 | + </dependency> | |
| 71 | + | |
| 65 | 72 | <!-- 简化代码 --> |
| 66 | 73 | <dependency> |
| 67 | 74 | <groupId>org.projectlombok</groupId> | ... | ... |
| ... | ... | @@ -301,6 +301,18 @@ public class QxApi { |
| 301 | 301 | log.info("更新成功: id={}", dataId); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | + /** 新增一条业务数据(新增接口,body 即字段)。 */ | |
| 305 | + public String addData(String token, String appId, String code, JSONObject body) { | |
| 306 | + log.info("新增业务数据: {}", code); | |
| 307 | + JSONObject resp = JsonHttpUtils.postJson2Obj( | |
| 308 | + baseUrl + "/qx-api/qx-apaas-run/ar/" + appId + "/" + code, | |
| 309 | + JsonHttpUtils.token(token), body); | |
| 310 | + if (!Boolean.TRUE.equals(resp.getBoolean("success"))) { | |
| 311 | + throw new IllegalStateException("新增数据失败: " + resp); | |
| 312 | + } | |
| 313 | + return resp.getString("data"); | |
| 314 | + } | |
| 315 | + | |
| 304 | 316 | private static String urlEncode(String s) { |
| 305 | 317 | try { |
| 306 | 318 | return java.net.URLEncoder.encode(s == null ? "" : s, "UTF-8"); |
| ... | ... | @@ -321,7 +333,25 @@ public class QxApi { |
| 321 | 333 | ? fileName.substring(fileName.lastIndexOf('.')) : ""; |
| 322 | 334 | String checkUrl = baseUrl + "/qx-api/qgyun-service-fs-manager/file/checkFile" |
| 323 | 335 | + "?fileMd5=" + md5 + "&publicFile=false&fileExt=" + urlEncode(ext); |
| 324 | - JSONObject check = JsonHttpUtils.getJson2Obj(checkUrl, JsonHttpUtils.token(token)); | |
| 336 | + JSONObject check = null; | |
| 337 | + RuntimeException lastEx = null; | |
| 338 | + for (int attempt = 1; attempt <= 5; attempt++) { | |
| 339 | + try { | |
| 340 | + check = JsonHttpUtils.getJson2Obj(checkUrl, JsonHttpUtils.token(token)); | |
| 341 | + break; | |
| 342 | + } catch (RuntimeException ex) { | |
| 343 | + lastEx = ex; | |
| 344 | + log.warn("checkFile 异常({}),{}ms 后重试(第{}次)", ex.getMessage(), 3000L * attempt, attempt); | |
| 345 | + try { | |
| 346 | + Thread.sleep(3000L * attempt); | |
| 347 | + } catch (InterruptedException ignored) { | |
| 348 | + Thread.currentThread().interrupt(); | |
| 349 | + } | |
| 350 | + } | |
| 351 | + } | |
| 352 | + if (check == null) { | |
| 353 | + throw lastEx != null ? lastEx : new IllegalStateException("checkFile 失败"); | |
| 354 | + } | |
| 325 | 355 | if (Boolean.TRUE.equals(check.getBoolean("success"))) { |
| 326 | 356 | String existId = check.getString("msg"); |
| 327 | 357 | if (existId != null && !existId.isEmpty()) { | ... | ... |
| 1 | +package com.qgutech.qgyun.apaas.sync.jdy.config; | |
| 2 | + | |
| 3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 员工信息同步配置(人大金仓 biphr_ddm_empinfo_v -> 启效员工信息表单)。 | |
| 7 | + * <p> | |
| 8 | + * 对应 application.properties 的 emp-sync 段。 | |
| 9 | + * 用途:把人大金仓的员工信息,按「员工编号(gh)」同步到启效员工信息表单(存在则更新、不存在则新增)。 | |
| 10 | + */ | |
| 11 | +@ConfigurationProperties(prefix = "emp-sync") | |
| 12 | +public class EmpSyncProperties { | |
| 13 | + | |
| 14 | + /** 人大金仓(Kingbase)数据源配置。 */ | |
| 15 | + private Kb kb = new Kb(); | |
| 16 | + | |
| 17 | + /** 启效(QX)目标配置。 */ | |
| 18 | + private Qx qx = new Qx(); | |
| 19 | + | |
| 20 | + /** 单次同步最多处理多少条(0=不限制,用于全量)。 */ | |
| 21 | + private int limit = 0; | |
| 22 | + | |
| 23 | + /** 是否 dry-run(true=只打印不写入)。 */ | |
| 24 | + private boolean dryRun = false; | |
| 25 | + | |
| 26 | + public Kb getKb() { | |
| 27 | + return kb; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public void setKb(Kb kb) { | |
| 31 | + this.kb = kb; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public Qx getQx() { | |
| 35 | + return qx; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public void setQx(Qx qx) { | |
| 39 | + this.qx = qx; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public int getLimit() { | |
| 43 | + return limit; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void setLimit(int limit) { | |
| 47 | + this.limit = limit; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public boolean isDryRun() { | |
| 51 | + return dryRun; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public void setDryRun(boolean dryRun) { | |
| 55 | + this.dryRun = dryRun; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** 人大金仓连接配置。 */ | |
| 59 | + public static class Kb { | |
| 60 | + private String host = "10.144.201.35"; | |
| 61 | + private int port = 54321; | |
| 62 | + private String database; | |
| 63 | + private String username; | |
| 64 | + private String password; | |
| 65 | + /** 员工信息表名 */ | |
| 66 | + private String table = "biphr_ddm_empinfo_v"; | |
| 67 | + /** 可选 WHERE 过滤条件(不含 WHERE 关键字),只同步命中的行 */ | |
| 68 | + private String filter; | |
| 69 | + /** JDBC 驱动类 */ | |
| 70 | + private String driverClass = "com.kingbase8.Driver"; | |
| 71 | + /** 可选:直接指定完整 JDBC url(填了则忽略 host/port/database) */ | |
| 72 | + private String url; | |
| 73 | + | |
| 74 | + public String jdbcUrl() { | |
| 75 | + if (url != null && !url.isEmpty()) { | |
| 76 | + return url; | |
| 77 | + } | |
| 78 | + return "jdbc:kingbase8://" + host + ":" + port + "/" + database; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public String getHost() { | |
| 82 | + return host; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public void setHost(String host) { | |
| 86 | + this.host = host; | |
| 87 | + } | |
| 88 | + | |
| 89 | + public int getPort() { | |
| 90 | + return port; | |
| 91 | + } | |
| 92 | + | |
| 93 | + public void setPort(int port) { | |
| 94 | + this.port = port; | |
| 95 | + } | |
| 96 | + | |
| 97 | + public String getDatabase() { | |
| 98 | + return database; | |
| 99 | + } | |
| 100 | + | |
| 101 | + public void setDatabase(String database) { | |
| 102 | + this.database = database; | |
| 103 | + } | |
| 104 | + | |
| 105 | + public String getUsername() { | |
| 106 | + return username; | |
| 107 | + } | |
| 108 | + | |
| 109 | + public void setUsername(String username) { | |
| 110 | + this.username = username; | |
| 111 | + } | |
| 112 | + | |
| 113 | + public String getPassword() { | |
| 114 | + return password; | |
| 115 | + } | |
| 116 | + | |
| 117 | + public void setPassword(String password) { | |
| 118 | + this.password = password; | |
| 119 | + } | |
| 120 | + | |
| 121 | + public String getTable() { | |
| 122 | + return table; | |
| 123 | + } | |
| 124 | + | |
| 125 | + public void setTable(String table) { | |
| 126 | + this.table = table; | |
| 127 | + } | |
| 128 | + | |
| 129 | + public String getFilter() { | |
| 130 | + return filter; | |
| 131 | + } | |
| 132 | + | |
| 133 | + public void setFilter(String filter) { | |
| 134 | + this.filter = filter; | |
| 135 | + } | |
| 136 | + | |
| 137 | + public String getDriverClass() { | |
| 138 | + return driverClass; | |
| 139 | + } | |
| 140 | + | |
| 141 | + public void setDriverClass(String driverClass) { | |
| 142 | + this.driverClass = driverClass; | |
| 143 | + } | |
| 144 | + | |
| 145 | + public String getUrl() { | |
| 146 | + return url; | |
| 147 | + } | |
| 148 | + | |
| 149 | + public void setUrl(String url) { | |
| 150 | + this.url = url; | |
| 151 | + } | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** 启效(QX)员工信息表单配置。 */ | |
| 155 | + public static class Qx { | |
| 156 | + private String baseUrl; | |
| 157 | + private String username; | |
| 158 | + private String password; | |
| 159 | + private String corpCode = "hfca"; | |
| 160 | + /** 员工信息所在应用 appId */ | |
| 161 | + private String appId; | |
| 162 | + /** 分页查询接口 code */ | |
| 163 | + private String pageCode = "j47lx0e4Page"; | |
| 164 | + /** 更新接口 code */ | |
| 165 | + private String updateCode = "53e93Update"; | |
| 166 | + /** 新增接口 code */ | |
| 167 | + private String addCode = "53e93Add"; | |
| 168 | + | |
| 169 | + public String getBaseUrl() { | |
| 170 | + return baseUrl; | |
| 171 | + } | |
| 172 | + | |
| 173 | + public void setBaseUrl(String baseUrl) { | |
| 174 | + this.baseUrl = baseUrl; | |
| 175 | + } | |
| 176 | + | |
| 177 | + public String getUsername() { | |
| 178 | + return username; | |
| 179 | + } | |
| 180 | + | |
| 181 | + public void setUsername(String username) { | |
| 182 | + this.username = username; | |
| 183 | + } | |
| 184 | + | |
| 185 | + public String getPassword() { | |
| 186 | + return password; | |
| 187 | + } | |
| 188 | + | |
| 189 | + public void setPassword(String password) { | |
| 190 | + this.password = password; | |
| 191 | + } | |
| 192 | + | |
| 193 | + public String getCorpCode() { | |
| 194 | + return corpCode; | |
| 195 | + } | |
| 196 | + | |
| 197 | + public void setCorpCode(String corpCode) { | |
| 198 | + this.corpCode = corpCode; | |
| 199 | + } | |
| 200 | + | |
| 201 | + public String getAppId() { | |
| 202 | + return appId; | |
| 203 | + } | |
| 204 | + | |
| 205 | + public void setAppId(String appId) { | |
| 206 | + this.appId = appId; | |
| 207 | + } | |
| 208 | + | |
| 209 | + public String getPageCode() { | |
| 210 | + return pageCode; | |
| 211 | + } | |
| 212 | + | |
| 213 | + public void setPageCode(String pageCode) { | |
| 214 | + this.pageCode = pageCode; | |
| 215 | + } | |
| 216 | + | |
| 217 | + public String getUpdateCode() { | |
| 218 | + return updateCode; | |
| 219 | + } | |
| 220 | + | |
| 221 | + public void setUpdateCode(String updateCode) { | |
| 222 | + this.updateCode = updateCode; | |
| 223 | + } | |
| 224 | + | |
| 225 | + public String getAddCode() { | |
| 226 | + return addCode; | |
| 227 | + } | |
| 228 | + | |
| 229 | + public void setAddCode(String addCode) { | |
| 230 | + this.addCode = addCode; | |
| 231 | + } | |
| 232 | + } | |
| 233 | +} | ... | ... |
| ... | ... | @@ -26,6 +26,9 @@ public class JdyRiskProperties { |
| 26 | 26 | /** 场景清单 */ |
| 27 | 27 | private List<Scenario> scenarios = new ArrayList<>(); |
| 28 | 28 | |
| 29 | + /** 定时任务(设备域场景12/13 按月抓取) */ | |
| 30 | + private Schedule schedule = new Schedule(); | |
| 31 | + | |
| 29 | 32 | public String getHost() { |
| 30 | 33 | return host; |
| 31 | 34 | } |
| ... | ... | @@ -58,6 +61,148 @@ public class JdyRiskProperties { |
| 58 | 61 | this.scenarios = scenarios; |
| 59 | 62 | } |
| 60 | 63 | |
| 64 | + public Schedule getSchedule() { | |
| 65 | + return schedule; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public void setSchedule(Schedule schedule) { | |
| 69 | + this.schedule = schedule; | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** 定时任务配置。 */ | |
| 73 | + public static class Schedule { | |
| 74 | + /** 是否启用设备域场景12/13定时任务 */ | |
| 75 | + private boolean enabled = false; | |
| 76 | + /** 场景12(SYNC0034)抓取 cron:默认每月1号 03:00 */ | |
| 77 | + private String s12Cron = "0 0 3 1 * ?"; | |
| 78 | + /** 场景13(SYNC0042)抓取 cron:默认每月10号 03:00 */ | |
| 79 | + private String s13Cron = "0 0 3 10 * ?"; | |
| 80 | + /** 场景14(SYNC0048)抓取 cron:默认每年12月20日 03:00 */ | |
| 81 | + private String s14Cron = "0 0 3 20 12 ?"; | |
| 82 | + /** 场景15(SYNC0044)抓取 cron:默认每月1号 03:00 */ | |
| 83 | + private String s15Cron = "0 0 3 1 * ?"; | |
| 84 | + /** 场景16(SYNC0045)抓取 cron:默认每天 23:00(方法内判断「月末」才执行) */ | |
| 85 | + private String s16Cron = "0 0 23 * * ?"; | |
| 86 | + /** 场景17(SYNC0046)抓取 cron:默认每月1号 03:00 */ | |
| 87 | + private String s17Cron = "0 0 3 1 * ?"; | |
| 88 | + /** 场景18(SYNC0047)抓取 cron:默认每天 23:00(方法内判断「月末」才执行) */ | |
| 89 | + private String s18Cron = "0 0 23 * * ?"; | |
| 90 | + /** 场景19(SYNC0043)抓取 cron:默认每月1号 01:00 */ | |
| 91 | + private String s19Cron = "0 0 1 1 * ?"; | |
| 92 | + /** 场景23(SYNC0013)抓取 cron:默认每月1号 01:00 */ | |
| 93 | + private String s23Cron = "0 0 1 1 * ?"; | |
| 94 | + /** 场景24(SYNC0014)抓取 cron:默认每月1号 01:00 */ | |
| 95 | + private String s24Cron = "0 0 1 1 * ?"; | |
| 96 | + /** 场景25(SYNC0015)抓取 cron:默认每月1号 01:00 */ | |
| 97 | + private String s25Cron = "0 0 1 1 * ?"; | |
| 98 | + /** 场景26(SYNC0016)抓取 cron:默认每月1号 01:00 */ | |
| 99 | + private String s26Cron = "0 0 1 1 * ?"; | |
| 100 | + | |
| 101 | + public boolean isEnabled() { | |
| 102 | + return enabled; | |
| 103 | + } | |
| 104 | + | |
| 105 | + public void setEnabled(boolean enabled) { | |
| 106 | + this.enabled = enabled; | |
| 107 | + } | |
| 108 | + | |
| 109 | + public String getS12Cron() { | |
| 110 | + return s12Cron; | |
| 111 | + } | |
| 112 | + | |
| 113 | + public void setS12Cron(String s12Cron) { | |
| 114 | + this.s12Cron = s12Cron; | |
| 115 | + } | |
| 116 | + | |
| 117 | + public String getS13Cron() { | |
| 118 | + return s13Cron; | |
| 119 | + } | |
| 120 | + | |
| 121 | + public void setS13Cron(String s13Cron) { | |
| 122 | + this.s13Cron = s13Cron; | |
| 123 | + } | |
| 124 | + | |
| 125 | + public String getS14Cron() { | |
| 126 | + return s14Cron; | |
| 127 | + } | |
| 128 | + | |
| 129 | + public void setS14Cron(String s14Cron) { | |
| 130 | + this.s14Cron = s14Cron; | |
| 131 | + } | |
| 132 | + | |
| 133 | + public String getS15Cron() { | |
| 134 | + return s15Cron; | |
| 135 | + } | |
| 136 | + | |
| 137 | + public void setS15Cron(String s15Cron) { | |
| 138 | + this.s15Cron = s15Cron; | |
| 139 | + } | |
| 140 | + | |
| 141 | + public String getS16Cron() { | |
| 142 | + return s16Cron; | |
| 143 | + } | |
| 144 | + | |
| 145 | + public void setS16Cron(String s16Cron) { | |
| 146 | + this.s16Cron = s16Cron; | |
| 147 | + } | |
| 148 | + | |
| 149 | + public String getS17Cron() { | |
| 150 | + return s17Cron; | |
| 151 | + } | |
| 152 | + | |
| 153 | + public void setS17Cron(String s17Cron) { | |
| 154 | + this.s17Cron = s17Cron; | |
| 155 | + } | |
| 156 | + | |
| 157 | + public String getS18Cron() { | |
| 158 | + return s18Cron; | |
| 159 | + } | |
| 160 | + | |
| 161 | + public void setS18Cron(String s18Cron) { | |
| 162 | + this.s18Cron = s18Cron; | |
| 163 | + } | |
| 164 | + | |
| 165 | + public String getS19Cron() { | |
| 166 | + return s19Cron; | |
| 167 | + } | |
| 168 | + | |
| 169 | + public void setS19Cron(String s19Cron) { | |
| 170 | + this.s19Cron = s19Cron; | |
| 171 | + } | |
| 172 | + | |
| 173 | + public String getS23Cron() { | |
| 174 | + return s23Cron; | |
| 175 | + } | |
| 176 | + | |
| 177 | + public void setS23Cron(String s23Cron) { | |
| 178 | + this.s23Cron = s23Cron; | |
| 179 | + } | |
| 180 | + | |
| 181 | + public String getS24Cron() { | |
| 182 | + return s24Cron; | |
| 183 | + } | |
| 184 | + | |
| 185 | + public void setS24Cron(String s24Cron) { | |
| 186 | + this.s24Cron = s24Cron; | |
| 187 | + } | |
| 188 | + | |
| 189 | + public String getS25Cron() { | |
| 190 | + return s25Cron; | |
| 191 | + } | |
| 192 | + | |
| 193 | + public void setS25Cron(String s25Cron) { | |
| 194 | + this.s25Cron = s25Cron; | |
| 195 | + } | |
| 196 | + | |
| 197 | + public String getS26Cron() { | |
| 198 | + return s26Cron; | |
| 199 | + } | |
| 200 | + | |
| 201 | + public void setS26Cron(String s26Cron) { | |
| 202 | + this.s26Cron = s26Cron; | |
| 203 | + } | |
| 204 | + } | |
| 205 | + | |
| 61 | 206 | /** 启效(QX)写回目标配置。 */ |
| 62 | 207 | public static class Qx { |
| 63 | 208 | /** 启效环境地址,如 https://hfca.uat3.qgutech.com */ |
| ... | ... | @@ -73,12 +218,16 @@ public class JdyRiskProperties { |
| 73 | 218 | private String syncQueryParam; |
| 74 | 219 | /** 更新接口 code(如 11a41Update) */ |
| 75 | 220 | private String updateCode; |
| 221 | + /** 新增接口 code(如 11a41Add) */ | |
| 222 | + private String addCode; | |
| 76 | 223 | /** 写回数量的字段编号(如 chcbxt) */ |
| 77 | 224 | private String countField; |
| 78 | 225 | /** 附件字段编号(如 hciwkz);配置了则把简道云数据 Excel 作为附件写入(关联ID字段自动取 {attachField}Id) */ |
| 79 | 226 | private String attachField; |
| 80 | 227 | /** 预警时间字段编号(如 bswivu);配置了则每次同步写入「当次跑任务的系统时间」 */ |
| 81 | 228 | private String timeField; |
| 229 | + /** 第二个随预警时间一起更新的日期字段(如 dgqshv,可为空) */ | |
| 230 | + private String timeField2; | |
| 82 | 231 | |
| 83 | 232 | public String getBaseUrl() { |
| 84 | 233 | return baseUrl; |
| ... | ... | @@ -144,6 +293,14 @@ public class JdyRiskProperties { |
| 144 | 293 | this.updateCode = updateCode; |
| 145 | 294 | } |
| 146 | 295 | |
| 296 | + public String getAddCode() { | |
| 297 | + return addCode; | |
| 298 | + } | |
| 299 | + | |
| 300 | + public void setAddCode(String addCode) { | |
| 301 | + this.addCode = addCode; | |
| 302 | + } | |
| 303 | + | |
| 147 | 304 | public String getCountField() { |
| 148 | 305 | return countField; |
| 149 | 306 | } |
| ... | ... | @@ -167,6 +324,14 @@ public class JdyRiskProperties { |
| 167 | 324 | public void setTimeField(String timeField) { |
| 168 | 325 | this.timeField = timeField; |
| 169 | 326 | } |
| 327 | + | |
| 328 | + public String getTimeField2() { | |
| 329 | + return timeField2; | |
| 330 | + } | |
| 331 | + | |
| 332 | + public void setTimeField2(String timeField2) { | |
| 333 | + this.timeField2 = timeField2; | |
| 334 | + } | |
| 170 | 335 | } |
| 171 | 336 | |
| 172 | 337 | /** |
| ... | ... | @@ -228,8 +393,16 @@ public class JdyRiskProperties { |
| 228 | 393 | private String flagValue; |
| 229 | 394 | /** 比率阈值(scenario8/9,默认 0.7) */ |
| 230 | 395 | private double ratioThreshold = 0.7; |
| 231 | - /** 条码字段 code(scenario7,主表) */ | |
| 396 | + /** 绝对值阈值(scenario10:|字段| > absThreshold 才算命中,默认 0.05=5%) */ | |
| 397 | + private double absThreshold = 0.05; | |
| 398 | + /** 条码字段 code(scenario7 主表 / scenario11 表A:系统库存明细) */ | |
| 232 | 399 | private String barcodeField; |
| 400 | + /** 需对比的表 B(scenario11:三包库房实际盘点数量)entry_id */ | |
| 401 | + private String compareEntryId; | |
| 402 | + /** 表 B 条码字段 code */ | |
| 403 | + private String compareBarcodeField; | |
| 404 | + /** 表 B 展示字段 list */ | |
| 405 | + private List<String> compareFields = new ArrayList<>(); | |
| 233 | 406 | /** 需要排除的条码来源表单(scenario7) */ |
| 234 | 407 | private List<ExcludeForm> excludeForms = new ArrayList<>(); |
| 235 | 408 | /** 超期天数(scenario7:入库时间距今超过该天数才保留,默认 180) */ |
| ... | ... | @@ -238,9 +411,243 @@ public class JdyRiskProperties { |
| 238 | 411 | private List<String> fields = new ArrayList<>(); |
| 239 | 412 | /** Excel 附加列取值的字段 code(为空时 scenario1 默认写「命中」) */ |
| 240 | 413 | private String extraField; |
| 414 | + /** Excel 中需按百分数(1位小数)显示的字段 code 列表 */ | |
| 415 | + private List<String> percentFields = new ArrayList<>(); | |
| 416 | + /** Excel 是否只保留「命中/预警」的行(其他行不导出) */ | |
| 417 | + private boolean onlyWarnRows = false; | |
| 418 | + /** 关联字段 code(其值为关联表的 _id,需映射成名称) */ | |
| 419 | + private String lookupField; | |
| 420 | + /** 关联表 entry_id(用于取 id->名称 映射) */ | |
| 421 | + private String lookupEntryId; | |
| 422 | + /** 关联表里存名称的字段 code */ | |
| 423 | + private String lookupNameField; | |
| 241 | 424 | /** 写回启效目标记录的 syncCode(如 SYNC0001) */ |
| 242 | 425 | private String syncCode; |
| 243 | 426 | |
| 427 | + /** 停留时长字段 code(scenario13) */ | |
| 428 | + private String durationField; | |
| 429 | + /** 停留时长阈值(分钟,scenario13:> 该值才算异常,默认 10) */ | |
| 430 | + private double durationThreshold = 10; | |
| 431 | + /** 是否存在异常出门字段 code(scenario13) */ | |
| 432 | + private String abnormalField; | |
| 433 | + /** 是否存在异常出门的命中取值(scenario13,如「存在异常」) */ | |
| 434 | + private String abnormalValue; | |
| 435 | + /** 异常原因说明字段 code(scenario13,为空也算异常) */ | |
| 436 | + private String reasonField; | |
| 437 | + /** | |
| 438 | + * 人员/签字配对列表(scenario12):人员字段有值但对应签字字段为空则命中。 | |
| 439 | + * 原因列文案按顺序生成「参与人员N未签字确认」(N 从 1 开始)。 | |
| 440 | + */ | |
| 441 | + private List<Pair> pairs = new ArrayList<>(); | |
| 442 | + /** 流程状态命中值(scenario15/17,「流转完成」对应的 flowState,如 1) */ | |
| 443 | + private Integer flowStateValue; | |
| 444 | + /** 条件照片校验规则列表(scenario15) */ | |
| 445 | + private List<PhotoRule> photoRules = new ArrayList<>(); | |
| 446 | + /** 命中取值集合(scenario16/18,如 高预算/低预算 或 未提交) */ | |
| 447 | + private List<String> flagValues = new ArrayList<>(); | |
| 448 | + /** 计划完成时间字段 code(scenario17) */ | |
| 449 | + private String planField; | |
| 450 | + /** 施工完成日期字段 code(scenario17) */ | |
| 451 | + private String actualField; | |
| 452 | + /** 逾期天数阈值(scenario17,实际-计划 > 该天数则命中,默认 15) */ | |
| 453 | + private int overdueDays = 15; | |
| 454 | + /** 加油量字段 code(scenario20,百公里油耗) */ | |
| 455 | + private String fuelAmountField; | |
| 456 | + /** 起始公里数字段 code(scenario20) */ | |
| 457 | + private String startKmField; | |
| 458 | + /** 非连续用车子表单字段 code(scenario20,主字段为空时取子表单起始公里数最大值) */ | |
| 459 | + private String subformField; | |
| 460 | + /** 子表单内起始公里数字段 code(scenario20) */ | |
| 461 | + private String subformStartField; | |
| 462 | + /** 正常范围下限(scenario20,含) */ | |
| 463 | + private double minValue; | |
| 464 | + /** 正常范围上限(scenario20,含) */ | |
| 465 | + private double maxValue; | |
| 466 | + /** Excel 是否同时导出「上次用车」对比行(scenario25 全顺) */ | |
| 467 | + private boolean includePreviousRow = false; | |
| 468 | + /** 是否统计「本月前三个月」(不含本月,scenario21) */ | |
| 469 | + private boolean prevThreeMonths = false; | |
| 470 | + /** 参评公司列字段 code 列表(scenario21,每月按这些列汇总得分) */ | |
| 471 | + private List<String> companyFields = new ArrayList<>(); | |
| 472 | + /** 倒数取前 N 名(scenario21,默认 3) */ | |
| 473 | + private int bottomCount = 3; | |
| 474 | + | |
| 475 | + public boolean isPrevThreeMonths() { | |
| 476 | + return prevThreeMonths; | |
| 477 | + } | |
| 478 | + | |
| 479 | + public void setPrevThreeMonths(boolean prevThreeMonths) { | |
| 480 | + this.prevThreeMonths = prevThreeMonths; | |
| 481 | + } | |
| 482 | + | |
| 483 | + public List<String> getCompanyFields() { | |
| 484 | + return companyFields; | |
| 485 | + } | |
| 486 | + | |
| 487 | + public void setCompanyFields(List<String> companyFields) { | |
| 488 | + this.companyFields = companyFields; | |
| 489 | + } | |
| 490 | + | |
| 491 | + public int getBottomCount() { | |
| 492 | + return bottomCount; | |
| 493 | + } | |
| 494 | + | |
| 495 | + public void setBottomCount(int bottomCount) { | |
| 496 | + this.bottomCount = bottomCount; | |
| 497 | + } | |
| 498 | + | |
| 499 | + public String getFuelAmountField() { | |
| 500 | + return fuelAmountField; | |
| 501 | + } | |
| 502 | + | |
| 503 | + public void setFuelAmountField(String fuelAmountField) { | |
| 504 | + this.fuelAmountField = fuelAmountField; | |
| 505 | + } | |
| 506 | + | |
| 507 | + public String getStartKmField() { | |
| 508 | + return startKmField; | |
| 509 | + } | |
| 510 | + | |
| 511 | + public void setStartKmField(String startKmField) { | |
| 512 | + this.startKmField = startKmField; | |
| 513 | + } | |
| 514 | + | |
| 515 | + public String getSubformField() { | |
| 516 | + return subformField; | |
| 517 | + } | |
| 518 | + | |
| 519 | + public void setSubformField(String subformField) { | |
| 520 | + this.subformField = subformField; | |
| 521 | + } | |
| 522 | + | |
| 523 | + public String getSubformStartField() { | |
| 524 | + return subformStartField; | |
| 525 | + } | |
| 526 | + | |
| 527 | + public void setSubformStartField(String subformStartField) { | |
| 528 | + this.subformStartField = subformStartField; | |
| 529 | + } | |
| 530 | + | |
| 531 | + public double getMinValue() { | |
| 532 | + return minValue; | |
| 533 | + } | |
| 534 | + | |
| 535 | + public void setMinValue(double minValue) { | |
| 536 | + this.minValue = minValue; | |
| 537 | + } | |
| 538 | + | |
| 539 | + public double getMaxValue() { | |
| 540 | + return maxValue; | |
| 541 | + } | |
| 542 | + | |
| 543 | + public void setMaxValue(double maxValue) { | |
| 544 | + this.maxValue = maxValue; | |
| 545 | + } | |
| 546 | + | |
| 547 | + public boolean isIncludePreviousRow() { | |
| 548 | + return includePreviousRow; | |
| 549 | + } | |
| 550 | + | |
| 551 | + public void setIncludePreviousRow(boolean includePreviousRow) { | |
| 552 | + this.includePreviousRow = includePreviousRow; | |
| 553 | + } | |
| 554 | + | |
| 555 | + public Integer getFlowStateValue() { | |
| 556 | + return flowStateValue; | |
| 557 | + } | |
| 558 | + | |
| 559 | + public void setFlowStateValue(Integer flowStateValue) { | |
| 560 | + this.flowStateValue = flowStateValue; | |
| 561 | + } | |
| 562 | + | |
| 563 | + public List<PhotoRule> getPhotoRules() { | |
| 564 | + return photoRules; | |
| 565 | + } | |
| 566 | + | |
| 567 | + public void setPhotoRules(List<PhotoRule> photoRules) { | |
| 568 | + this.photoRules = photoRules; | |
| 569 | + } | |
| 570 | + | |
| 571 | + public List<String> getFlagValues() { | |
| 572 | + return flagValues; | |
| 573 | + } | |
| 574 | + | |
| 575 | + public void setFlagValues(List<String> flagValues) { | |
| 576 | + this.flagValues = flagValues; | |
| 577 | + } | |
| 578 | + | |
| 579 | + public String getPlanField() { | |
| 580 | + return planField; | |
| 581 | + } | |
| 582 | + | |
| 583 | + public void setPlanField(String planField) { | |
| 584 | + this.planField = planField; | |
| 585 | + } | |
| 586 | + | |
| 587 | + public String getActualField() { | |
| 588 | + return actualField; | |
| 589 | + } | |
| 590 | + | |
| 591 | + public void setActualField(String actualField) { | |
| 592 | + this.actualField = actualField; | |
| 593 | + } | |
| 594 | + | |
| 595 | + public int getOverdueDays() { | |
| 596 | + return overdueDays; | |
| 597 | + } | |
| 598 | + | |
| 599 | + public void setOverdueDays(int overdueDays) { | |
| 600 | + this.overdueDays = overdueDays; | |
| 601 | + } | |
| 602 | + | |
| 603 | + public String getDurationField() { | |
| 604 | + return durationField; | |
| 605 | + } | |
| 606 | + | |
| 607 | + public void setDurationField(String durationField) { | |
| 608 | + this.durationField = durationField; | |
| 609 | + } | |
| 610 | + | |
| 611 | + public double getDurationThreshold() { | |
| 612 | + return durationThreshold; | |
| 613 | + } | |
| 614 | + | |
| 615 | + public void setDurationThreshold(double durationThreshold) { | |
| 616 | + this.durationThreshold = durationThreshold; | |
| 617 | + } | |
| 618 | + | |
| 619 | + public String getAbnormalField() { | |
| 620 | + return abnormalField; | |
| 621 | + } | |
| 622 | + | |
| 623 | + public void setAbnormalField(String abnormalField) { | |
| 624 | + this.abnormalField = abnormalField; | |
| 625 | + } | |
| 626 | + | |
| 627 | + public String getAbnormalValue() { | |
| 628 | + return abnormalValue; | |
| 629 | + } | |
| 630 | + | |
| 631 | + public void setAbnormalValue(String abnormalValue) { | |
| 632 | + this.abnormalValue = abnormalValue; | |
| 633 | + } | |
| 634 | + | |
| 635 | + public String getReasonField() { | |
| 636 | + return reasonField; | |
| 637 | + } | |
| 638 | + | |
| 639 | + public void setReasonField(String reasonField) { | |
| 640 | + this.reasonField = reasonField; | |
| 641 | + } | |
| 642 | + | |
| 643 | + public List<Pair> getPairs() { | |
| 644 | + return pairs; | |
| 645 | + } | |
| 646 | + | |
| 647 | + public void setPairs(List<Pair> pairs) { | |
| 648 | + this.pairs = pairs; | |
| 649 | + } | |
| 650 | + | |
| 244 | 651 | public String getId() { |
| 245 | 652 | return id; |
| 246 | 653 | } |
| ... | ... | @@ -409,6 +816,14 @@ public class JdyRiskProperties { |
| 409 | 816 | this.ratioThreshold = ratioThreshold; |
| 410 | 817 | } |
| 411 | 818 | |
| 819 | + public double getAbsThreshold() { | |
| 820 | + return absThreshold; | |
| 821 | + } | |
| 822 | + | |
| 823 | + public void setAbsThreshold(double absThreshold) { | |
| 824 | + this.absThreshold = absThreshold; | |
| 825 | + } | |
| 826 | + | |
| 412 | 827 | public String getBarcodeField() { |
| 413 | 828 | return barcodeField; |
| 414 | 829 | } |
| ... | ... | @@ -417,6 +832,30 @@ public class JdyRiskProperties { |
| 417 | 832 | this.barcodeField = barcodeField; |
| 418 | 833 | } |
| 419 | 834 | |
| 835 | + public String getCompareEntryId() { | |
| 836 | + return compareEntryId; | |
| 837 | + } | |
| 838 | + | |
| 839 | + public void setCompareEntryId(String compareEntryId) { | |
| 840 | + this.compareEntryId = compareEntryId; | |
| 841 | + } | |
| 842 | + | |
| 843 | + public String getCompareBarcodeField() { | |
| 844 | + return compareBarcodeField; | |
| 845 | + } | |
| 846 | + | |
| 847 | + public void setCompareBarcodeField(String compareBarcodeField) { | |
| 848 | + this.compareBarcodeField = compareBarcodeField; | |
| 849 | + } | |
| 850 | + | |
| 851 | + public List<String> getCompareFields() { | |
| 852 | + return compareFields; | |
| 853 | + } | |
| 854 | + | |
| 855 | + public void setCompareFields(List<String> compareFields) { | |
| 856 | + this.compareFields = compareFields; | |
| 857 | + } | |
| 858 | + | |
| 420 | 859 | public List<ExcludeForm> getExcludeForms() { |
| 421 | 860 | return excludeForms; |
| 422 | 861 | } |
| ... | ... | @@ -473,6 +912,46 @@ public class JdyRiskProperties { |
| 473 | 912 | this.extraField = extraField; |
| 474 | 913 | } |
| 475 | 914 | |
| 915 | + public List<String> getPercentFields() { | |
| 916 | + return percentFields; | |
| 917 | + } | |
| 918 | + | |
| 919 | + public void setPercentFields(List<String> percentFields) { | |
| 920 | + this.percentFields = percentFields; | |
| 921 | + } | |
| 922 | + | |
| 923 | + public boolean isOnlyWarnRows() { | |
| 924 | + return onlyWarnRows; | |
| 925 | + } | |
| 926 | + | |
| 927 | + public void setOnlyWarnRows(boolean onlyWarnRows) { | |
| 928 | + this.onlyWarnRows = onlyWarnRows; | |
| 929 | + } | |
| 930 | + | |
| 931 | + public String getLookupField() { | |
| 932 | + return lookupField; | |
| 933 | + } | |
| 934 | + | |
| 935 | + public void setLookupField(String lookupField) { | |
| 936 | + this.lookupField = lookupField; | |
| 937 | + } | |
| 938 | + | |
| 939 | + public String getLookupEntryId() { | |
| 940 | + return lookupEntryId; | |
| 941 | + } | |
| 942 | + | |
| 943 | + public void setLookupEntryId(String lookupEntryId) { | |
| 944 | + this.lookupEntryId = lookupEntryId; | |
| 945 | + } | |
| 946 | + | |
| 947 | + public String getLookupNameField() { | |
| 948 | + return lookupNameField; | |
| 949 | + } | |
| 950 | + | |
| 951 | + public void setLookupNameField(String lookupNameField) { | |
| 952 | + this.lookupNameField = lookupNameField; | |
| 953 | + } | |
| 954 | + | |
| 476 | 955 | public String getSyncCode() { |
| 477 | 956 | return syncCode; |
| 478 | 957 | } |
| ... | ... | @@ -505,4 +984,72 @@ public class JdyRiskProperties { |
| 505 | 984 | this.barcodeField = barcodeField; |
| 506 | 985 | } |
| 507 | 986 | } |
| 987 | + | |
| 988 | + /** scenario15:条件照片校验规则(条件字段命中 flagValue 时,照片字段不能为空)。 */ | |
| 989 | + public static class PhotoRule { | |
| 990 | + /** 条件字段 code(如 是否有隐蔽工程) */ | |
| 991 | + private String flagField; | |
| 992 | + /** 条件命中值(默认「是」) */ | |
| 993 | + private String flagValue = "是"; | |
| 994 | + /** 需为非空的照片字段 code */ | |
| 995 | + private String photoField; | |
| 996 | + /** 原因文案(为空时自动取照片字段的表单标题 + 「为空」) */ | |
| 997 | + private String label; | |
| 998 | + | |
| 999 | + public String getFlagField() { | |
| 1000 | + return flagField; | |
| 1001 | + } | |
| 1002 | + | |
| 1003 | + public void setFlagField(String flagField) { | |
| 1004 | + this.flagField = flagField; | |
| 1005 | + } | |
| 1006 | + | |
| 1007 | + public String getFlagValue() { | |
| 1008 | + return flagValue; | |
| 1009 | + } | |
| 1010 | + | |
| 1011 | + public void setFlagValue(String flagValue) { | |
| 1012 | + this.flagValue = flagValue; | |
| 1013 | + } | |
| 1014 | + | |
| 1015 | + public String getPhotoField() { | |
| 1016 | + return photoField; | |
| 1017 | + } | |
| 1018 | + | |
| 1019 | + public void setPhotoField(String photoField) { | |
| 1020 | + this.photoField = photoField; | |
| 1021 | + } | |
| 1022 | + | |
| 1023 | + public String getLabel() { | |
| 1024 | + return label; | |
| 1025 | + } | |
| 1026 | + | |
| 1027 | + public void setLabel(String label) { | |
| 1028 | + this.label = label; | |
| 1029 | + } | |
| 1030 | + } | |
| 1031 | + | |
| 1032 | + /** scenario12:人员字段与对应的手写签字确认字段配对。 */ | |
| 1033 | + public static class Pair { | |
| 1034 | + /** 参与人员字段 code */ | |
| 1035 | + private String personField; | |
| 1036 | + /** 对应的手写签字确认字段 code */ | |
| 1037 | + private String signField; | |
| 1038 | + | |
| 1039 | + public String getPersonField() { | |
| 1040 | + return personField; | |
| 1041 | + } | |
| 1042 | + | |
| 1043 | + public void setPersonField(String personField) { | |
| 1044 | + this.personField = personField; | |
| 1045 | + } | |
| 1046 | + | |
| 1047 | + public String getSignField() { | |
| 1048 | + return signField; | |
| 1049 | + } | |
| 1050 | + | |
| 1051 | + public void setSignField(String signField) { | |
| 1052 | + this.signField = signField; | |
| 1053 | + } | |
| 1054 | + } | |
| 508 | 1055 | } | ... | ... |
| ... | ... | @@ -9,6 +9,6 @@ import org.springframework.scheduling.annotation.EnableScheduling; |
| 9 | 9 | */ |
| 10 | 10 | @Configuration |
| 11 | 11 | @EnableScheduling |
| 12 | -@EnableConfigurationProperties({JdySyncProperties.class, JdyRiskProperties.class, JdyFormSyncProperties.class}) | |
| 12 | +@EnableConfigurationProperties({JdySyncProperties.class, JdyRiskProperties.class, JdyFormSyncProperties.class, EmpSyncProperties.class}) | |
| 13 | 13 | public class JdySyncConfig { |
| 14 | 14 | } | ... | ... |
| 1 | +package com.qgutech.qgyun.apaas.sync.jdy.controller; | |
| 2 | + | |
| 3 | +import com.qgutech.qgyun.apaas.sync.jdy.service.EmpSyncService; | |
| 4 | +import lombok.extern.slf4j.Slf4j; | |
| 5 | +import org.springframework.web.bind.annotation.PostMapping; | |
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 8 | +import org.springframework.web.bind.annotation.RestController; | |
| 9 | + | |
| 10 | +import javax.annotation.Resource; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 员工信息同步接口(人大金仓 -> 启效员工信息表单)。 | |
| 14 | + */ | |
| 15 | +@Slf4j | |
| 16 | +@RestController | |
| 17 | +@RequestMapping("/api/emp") | |
| 18 | +public class EmpSyncController { | |
| 19 | + | |
| 20 | + @Resource | |
| 21 | + private EmpSyncService empSyncService; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 第一步:启效已存在人员按姓名匹配人大金仓,回填员工编号(gh)。 | |
| 25 | + * 例:POST /api/emp/sync/gh?dryRun=true | |
| 26 | + */ | |
| 27 | + @PostMapping("/sync/gh") | |
| 28 | + public String syncGh(@RequestParam(required = false) Boolean dryRun) { | |
| 29 | + return empSyncService.syncGhByName(Boolean.TRUE.equals(dryRun)); | |
| 30 | + } | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 第二步:按员工编号(gh)全量同步,已存在更新、不存在新增。 | |
| 34 | + * 例:POST /api/emp/sync/all?dryRun=true&limit=100&offset=0 | |
| 35 | + */ | |
| 36 | + @PostMapping("/sync/all") | |
| 37 | + public String syncAll(@RequestParam(required = false) Boolean dryRun, | |
| 38 | + @RequestParam(required = false) Integer limit, | |
| 39 | + @RequestParam(required = false) Integer offset) { | |
| 40 | + boolean dr = dryRun != null ? dryRun : false; | |
| 41 | + int lim = limit != null ? limit : 0; | |
| 42 | + int off = offset != null ? offset : 0; | |
| 43 | + return empSyncService.syncAll(dr, lim, off); | |
| 44 | + } | |
| 45 | +} | ... | ... |
| 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.ResultSet; | |
| 8 | +import java.sql.ResultSetMetaData; | |
| 9 | +import java.sql.SQLException; | |
| 10 | +import java.sql.Statement; | |
| 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> | |
| 19 | + * KingbaseES 兼容 PostgreSQL 协议,使用官方 kingbase8 驱动。 | |
| 20 | + */ | |
| 21 | +@Slf4j | |
| 22 | +public class KingbaseEmpDao { | |
| 23 | + | |
| 24 | + private final String url; | |
| 25 | + private final String username; | |
| 26 | + private final String password; | |
| 27 | + private final String table; | |
| 28 | + private final String filter; | |
| 29 | + private final String driverClass; | |
| 30 | + | |
| 31 | + public KingbaseEmpDao(String url, String username, String password, String table, String filter, String driverClass) { | |
| 32 | + this.url = url; | |
| 33 | + this.username = username; | |
| 34 | + this.password = password; | |
| 35 | + this.table = table; | |
| 36 | + this.filter = filter; | |
| 37 | + this.driverClass = driverClass; | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * 读取整表指定列,返回每行一个 Map(列名 -> 原始值,未做类型转换)。 | |
| 42 | + * | |
| 43 | + * @param columns 需要读取的列(小写,固定常量,不做用户输入) | |
| 44 | + */ | |
| 45 | + public List<Map<String, Object>> findAll(List<String> columns) { | |
| 46 | + if (columns == null || columns.isEmpty()) { | |
| 47 | + throw new IllegalArgumentException("columns 不能为空"); | |
| 48 | + } | |
| 49 | + StringBuilder select = new StringBuilder(); | |
| 50 | + for (int i = 0; i < columns.size(); i++) { | |
| 51 | + if (i > 0) { | |
| 52 | + select.append(", "); | |
| 53 | + } | |
| 54 | + select.append(columns.get(i)); | |
| 55 | + } | |
| 56 | + String sql = "SELECT " + select + " FROM " + table | |
| 57 | + + (filter != null && !filter.trim().isEmpty() ? " WHERE " + filter : ""); | |
| 58 | + log.info("人大金仓查询: {}", sql); | |
| 59 | + List<Map<String, Object>> rows = new ArrayList<>(); | |
| 60 | + try { | |
| 61 | + Class.forName(driverClass); | |
| 62 | + } catch (ClassNotFoundException e) { | |
| 63 | + throw new IllegalStateException("加载 Kingbase JDBC 驱动失败: " + driverClass, e); | |
| 64 | + } | |
| 65 | + try (Connection conn = DriverManager.getConnection(url, username, password); | |
| 66 | + Statement st = conn.createStatement(); | |
| 67 | + ResultSet rs = st.executeQuery(sql)) { | |
| 68 | + ResultSetMetaData md = rs.getMetaData(); | |
| 69 | + int n = md.getColumnCount(); | |
| 70 | + while (rs.next()) { | |
| 71 | + Map<String, Object> row = new LinkedHashMap<>(n * 2); | |
| 72 | + for (int i = 1; i <= n; i++) { | |
| 73 | + row.put(md.getColumnLabel(i).toLowerCase(), rs.getObject(i)); | |
| 74 | + } | |
| 75 | + rows.add(row); | |
| 76 | + } | |
| 77 | + log.info("人大金仓读取完成: {} 行 (表={})", rows.size(), table); | |
| 78 | + return rows; | |
| 79 | + } catch (SQLException e) { | |
| 80 | + throw new RuntimeException("读取人大金仓失败: " + e.getMessage(), e); | |
| 81 | + } | |
| 82 | + } | |
| 83 | +} | ... | ... |
| 1 | +package com.qgutech.qgyun.apaas.sync.jdy.service; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSONArray; | |
| 4 | +import com.alibaba.fastjson.JSONObject; | |
| 5 | +import com.qgutech.qgyun.apaas.sync.jdy.api.QxApi; | |
| 6 | +import com.qgutech.qgyun.apaas.sync.jdy.config.EmpSyncProperties; | |
| 7 | +import com.qgutech.qgyun.apaas.sync.jdy.db.KingbaseEmpDao; | |
| 8 | +import lombok.extern.slf4j.Slf4j; | |
| 9 | +import org.springframework.stereotype.Service; | |
| 10 | + | |
| 11 | +import java.util.ArrayList; | |
| 12 | +import java.util.Arrays; | |
| 13 | +import java.util.HashMap; | |
| 14 | +import java.util.HashSet; | |
| 15 | +import java.util.LinkedHashMap; | |
| 16 | +import java.util.LinkedHashSet; | |
| 17 | +import java.util.List; | |
| 18 | +import java.util.Map; | |
| 19 | +import java.util.Set; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * 员工信息同步(人大金仓 biphr_ddm_empinfo_v -> 启效员工信息表单)。 | |
| 23 | + * <p> | |
| 24 | + * 第一步 {@link #syncGhByName}:查出启效已存在人员,按姓名匹配人大金仓员工,回填员工编号(gh); | |
| 25 | + * 第二步 {@link #syncAll}:按员工编号(gh)同步全部字段,已存在则更新、不存在则新增。 | |
| 26 | + * <p> | |
| 27 | + * 字段映射与值转换:日期转毫秒时间戳;性别/政治面貌按数据字典转文本码;平台单位(dw)、平台用户(zzyh)暂不同步。 | |
| 28 | + */ | |
| 29 | +@Slf4j | |
| 30 | +@Service | |
| 31 | +public class EmpSyncService { | |
| 32 | + | |
| 33 | + /** 字段映射:{启效 fieldKey, 人大金仓列, 转换类型}。 */ | |
| 34 | + private static final String[][] FIELD_MAP = { | |
| 35 | + {"xm", "emp_name", "STR"}, // 姓名 | |
| 36 | + {"gh", "emp_id", "STR"}, // 员工编号 | |
| 37 | + {"xb", "gender", "GENDER"}, // 性别 | |
| 38 | + {"xjziqy", "employment_type", "STR"}, // 用工形式 | |
| 39 | + {"gzsj", "work_start_date", "DATE"}, // 参加工作日期 | |
| 40 | + {"cchycx", "hire_date", "DATE"}, // 入职日期 | |
| 41 | + {"kiflui", "years_of_service", "NUM"}, // 服务年限 | |
| 42 | + {"zzmm", "political_status", "POL"}, // 政治面貌 | |
| 43 | + {"dpksnb", "entry_reason", "STR"}, // 进厂原因 | |
| 44 | + {"fevepq", "highest_technical_title", "STR"}, // 最高技术职称 | |
| 45 | + {"fllqfd", "title_level", "STR"}, // 职称级别 | |
| 46 | + {"kahdlq", "company_seniority_start_date", "DATE"}, // 本企业司龄开始时间 | |
| 47 | + {"jholak", "skill_level", "STR"}, // 技能等级 | |
| 48 | + {"zw", "job_grade", "STR"}, // 职级 | |
| 49 | + {"jnafyx", "professional_level", "STR"}, // 专业等级 | |
| 50 | + {"cfbzme", "certified_major", "STR"}, // 认证专业 | |
| 51 | + {"csny", "birth_date", "DATE"}, // 出生日期 | |
| 52 | + {"iibeao", "age", "NUM"}, // 年龄 | |
| 53 | + {"ihkmfw", "birth_place", "STR"}, // 出生地 | |
| 54 | + {"wywvtj", "ancestral_home", "STR"}, // 祖籍 | |
| 55 | + {"fmogfx", "marital_status", "STR"}, // 婚姻状况 | |
| 56 | + {"vijlcl", "nationality", "STR"}, // 国籍 | |
| 57 | + {"oflpgg", "ethnic_group", "STR"}, // 民族 | |
| 58 | + {"vnzxms", "former_name", "STR"}, // 曾用名 | |
| 59 | + {"qajljq", "household_type", "STR"}, // 户口性质 | |
| 60 | + {"iplaqo", "household_location", "STR"}, // 户籍所在地 | |
| 61 | + {"zgxl", "highest_education", "STR"}, // 最高学历 | |
| 62 | + {"mzguwx", "school_name", "STR"}, // 学校 | |
| 63 | + {"bnovfe", "first_major", "STR"}, // 第一专业 | |
| 64 | + {"zwxpwy", "second_major", "STR"}, // 第二专业 | |
| 65 | + {"mvmiiu", "children_count", "NUM"}, // 子女数量 | |
| 66 | + {"ujpifj", "job_start_date", "DATE"}, // 岗位开始日期 | |
| 67 | + {"quampb", "level_1_dept", "STR"}, // 一级部门 | |
| 68 | + {"cwjkjf", "level_2_dept", "STR"}, // 二级部门 | |
| 69 | + {"tcsxvn", "level_3_dept", "STR"}, // 三级部门 | |
| 70 | + {"llgyiw", "level_4_dept", "STR"}, // 四级部门 | |
| 71 | + {"iiokqq", "level_5_dept", "STR"}, // 五级部门 | |
| 72 | + {"tseiyg", "level_6_dept", "STR"}, // 六级部门 | |
| 73 | + {"syihaj", "level_7_dept", "STR"}, // 七级部门 | |
| 74 | + {"nsamnf", "position_family", "STR"}, // 岗位族 | |
| 75 | + {"vbfdeh", "position_full_name", "STR"}, // 岗位全称 | |
| 76 | + {"pqauhs", "position_value", "STR"}, // 岗位价值 | |
| 77 | + {"sjaugh", "position_category", "STR"}, // 岗类 | |
| 78 | + {"judvdv", "position_name", "STR"}, // 岗位名称 | |
| 79 | + {"wivkxo", "duty_full_name", "STR"}, // 职务全称 | |
| 80 | + {"egiikb", "duty_type", "STR"}, // 职务类型 | |
| 81 | + {"ywtyqd", "job_title", "STR"}, // 职务 | |
| 82 | + {"vnlwsa", "position_level", "STR"} // 岗级 | |
| 83 | + }; | |
| 84 | + | |
| 85 | + private final EmpSyncProperties props; | |
| 86 | + | |
| 87 | + public EmpSyncService(EmpSyncProperties props) { | |
| 88 | + this.props = props; | |
| 89 | + } | |
| 90 | + | |
| 91 | + /** 第一步:启效已存在人员按姓名匹配,回填员工编号(gh)。 */ | |
| 92 | + public String syncGhByName(boolean dryRun) { | |
| 93 | + QxApi qx = new QxApi(props.getQx().getBaseUrl()); | |
| 94 | + String token = login(qx); | |
| 95 | + List<Map<String, Object>> kbRows = dao().findAll(Arrays.asList("emp_id", "emp_name")); | |
| 96 | + | |
| 97 | + Map<String, Set<String>> nameToEmpIds = new HashMap<>(); | |
| 98 | + for (Map<String, Object> row : kbRows) { | |
| 99 | + String name = str(row.get("emp_name")); | |
| 100 | + String empId = str(row.get("emp_id")); | |
| 101 | + if (name == null || empId == null) { | |
| 102 | + continue; | |
| 103 | + } | |
| 104 | + nameToEmpIds.computeIfAbsent(name, k -> new LinkedHashSet<>()).add(empId); | |
| 105 | + } | |
| 106 | + log.info("人大金仓员工 {} 条, 不同姓名 {} 个", kbRows.size(), nameToEmpIds.size()); | |
| 107 | + | |
| 108 | + JSONArray qxAll = qx.pageAll(token, props.getQx().getAppId(), props.getQx().getPageCode()); | |
| 109 | + log.info("启效现有员工 {} 条", qxAll.size()); | |
| 110 | + | |
| 111 | + int updated = 0; | |
| 112 | + int skipHasGh = 0; | |
| 113 | + int skipNotFound = 0; | |
| 114 | + int skipAmbiguous = 0; | |
| 115 | + int fail = 0; | |
| 116 | + List<String> ambiguousSamples = new ArrayList<>(); | |
| 117 | + for (int i = 0; i < qxAll.size(); i++) { | |
| 118 | + JSONObject rec = qxAll.getJSONObject(i); | |
| 119 | + String xm = str(rec.getString("xm")); | |
| 120 | + String gh = str(rec.getString("gh")); | |
| 121 | + if (gh != null) { | |
| 122 | + skipHasGh++; | |
| 123 | + continue; | |
| 124 | + } | |
| 125 | + Set<String> ids = xm == null ? null : nameToEmpIds.get(xm); | |
| 126 | + if (ids == null || ids.isEmpty()) { | |
| 127 | + skipNotFound++; | |
| 128 | + continue; | |
| 129 | + } | |
| 130 | + if (ids.size() > 1) { | |
| 131 | + skipAmbiguous++; | |
| 132 | + if (ambiguousSamples.size() < 20) { | |
| 133 | + ambiguousSamples.add(xm + "(" + ids.size() + "人)"); | |
| 134 | + } | |
| 135 | + continue; | |
| 136 | + } | |
| 137 | + String empId = ids.iterator().next(); | |
| 138 | + rec.put("gh", empId); | |
| 139 | + if (!dryRun) { | |
| 140 | + try { | |
| 141 | + qx.updateData(token, props.getQx().getAppId(), props.getQx().getUpdateCode(), rec); | |
| 142 | + } catch (Exception e) { | |
| 143 | + fail++; | |
| 144 | + log.error("回填 gh 失败: xm={} gh={} err={}", xm, empId, e.getMessage()); | |
| 145 | + continue; | |
| 146 | + } | |
| 147 | + } | |
| 148 | + updated++; | |
| 149 | + } | |
| 150 | + String summary = "第一步(按姓名回填gh) ok=" + updated + " 已有gh跳过=" + skipHasGh | |
| 151 | + + " 未匹配=" + skipNotFound + " 重名歧义跳过=" + skipAmbiguous + " 失败=" + fail | |
| 152 | + + (dryRun ? " [dry-run]" : ""); | |
| 153 | + log.info("{}", summary); | |
| 154 | + if (!ambiguousSamples.isEmpty()) { | |
| 155 | + log.warn("重名歧义示例: {}", ambiguousSamples); | |
| 156 | + } | |
| 157 | + return summary; | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** 第二步:按员工编号(gh) 全量同步,已存在更新、不存在新增。offset/limit 用于分批与断点续跑。 */ | |
| 161 | + public String syncAll(boolean dryRun, int limit, int offset) { | |
| 162 | + QxApi qx = new QxApi(props.getQx().getBaseUrl()); | |
| 163 | + String token = login(qx); | |
| 164 | + | |
| 165 | + JSONArray qxAll = qx.pageAll(token, props.getQx().getAppId(), props.getQx().getPageCode()); | |
| 166 | + Map<String, JSONObject> ghToRec = new HashMap<>(); | |
| 167 | + int dupGh = 0; | |
| 168 | + for (int i = 0; i < qxAll.size(); i++) { | |
| 169 | + JSONObject rec = qxAll.getJSONObject(i); | |
| 170 | + String gh = str(rec.getString("gh")); | |
| 171 | + if (gh == null) { | |
| 172 | + continue; | |
| 173 | + } | |
| 174 | + JSONObject prev = ghToRec.put(gh, rec); | |
| 175 | + if (prev != null) { | |
| 176 | + dupGh++; | |
| 177 | + log.warn("启效存在重复员工编号 gh={} (id={},{})", gh, prev.getString("id"), rec.getString("id")); | |
| 178 | + } | |
| 179 | + } | |
| 180 | + log.info("启效现有员工 {} 条, 有工号 {} 条", qxAll.size(), ghToRec.size()); | |
| 181 | + | |
| 182 | + List<Map<String, Object>> kbRows = dao().findAll(kbColumns()); | |
| 183 | + log.info("人大金仓员工 {} 条", kbRows.size()); | |
| 184 | + | |
| 185 | + int updated = 0; | |
| 186 | + int added = 0; | |
| 187 | + int skipNoGh = 0; | |
| 188 | + int fail = 0; | |
| 189 | + int idx = 0; | |
| 190 | + for (Map<String, Object> row : kbRows) { | |
| 191 | + if (idx++ < offset) { | |
| 192 | + continue; | |
| 193 | + } | |
| 194 | + String empId = str(row.get("emp_id")); | |
| 195 | + if (empId == null) { | |
| 196 | + skipNoGh++; | |
| 197 | + continue; | |
| 198 | + } | |
| 199 | + if (limit > 0 && updated + added >= limit) { | |
| 200 | + log.info("达到 limit={},停止", limit); | |
| 201 | + break; | |
| 202 | + } | |
| 203 | + Map<String, Object> mapped = buildMapped(row); | |
| 204 | + JSONObject existing = ghToRec.get(empId); | |
| 205 | + try { | |
| 206 | + if (existing != null) { | |
| 207 | + JSONObject body = new JSONObject(); | |
| 208 | + body.putAll(existing); | |
| 209 | + body.putAll(mapped); | |
| 210 | + if (!dryRun) { | |
| 211 | + qx.updateData(token, props.getQx().getAppId(), props.getQx().getUpdateCode(), body); | |
| 212 | + } | |
| 213 | + updated++; | |
| 214 | + } else { | |
| 215 | + JSONObject body = new JSONObject(); | |
| 216 | + body.putAll(mapped); | |
| 217 | + if (!dryRun) { | |
| 218 | + qx.addData(token, props.getQx().getAppId(), props.getQx().getAddCode(), body); | |
| 219 | + } | |
| 220 | + added++; | |
| 221 | + } | |
| 222 | + } catch (Exception e) { | |
| 223 | + fail++; | |
| 224 | + log.error("同步失败: gh={} xm={} err={}", empId, mapped.get("xm"), e.getMessage()); | |
| 225 | + continue; | |
| 226 | + } | |
| 227 | + if ((updated + added) % 500 == 0) { | |
| 228 | + log.info("进度: 更新={} 新增={} 失败={}", updated, added, fail); | |
| 229 | + } | |
| 230 | + } | |
| 231 | + String summary = "第二步(按gh全量同步) 更新=" + updated + " 新增=" + added | |
| 232 | + + " 无工号跳过=" + skipNoGh + " 启效重复工号=" + dupGh + " 失败=" + fail | |
| 233 | + + (dryRun ? " [dry-run]" : ""); | |
| 234 | + log.info("{}", summary); | |
| 235 | + return summary; | |
| 236 | + } | |
| 237 | + | |
| 238 | + private String login(QxApi qx) { | |
| 239 | + return qx.login(props.getQx().getUsername(), props.getQx().getPassword(), props.getQx().getCorpCode()); | |
| 240 | + } | |
| 241 | + | |
| 242 | + private KingbaseEmpDao dao() { | |
| 243 | + EmpSyncProperties.Kb kb = props.getKb(); | |
| 244 | + return new KingbaseEmpDao(kb.jdbcUrl(), kb.getUsername(), kb.getPassword(), kb.getTable(), | |
| 245 | + kb.getFilter(), kb.getDriverClass()); | |
| 246 | + } | |
| 247 | + | |
| 248 | + /** 按映射把一行人大金仓数据转为启效字段(fieldKey -> 值)。 */ | |
| 249 | + private Map<String, Object> buildMapped(Map<String, Object> row) { | |
| 250 | + Map<String, Object> body = new LinkedHashMap<>(); | |
| 251 | + for (String[] f : FIELD_MAP) { | |
| 252 | + body.put(f[0], transform(f[2], row.get(f[1]))); | |
| 253 | + } | |
| 254 | + return body; | |
| 255 | + } | |
| 256 | + | |
| 257 | + /** 收集需要从人大金仓读取的列(去重)。 */ | |
| 258 | + private List<String> kbColumns() { | |
| 259 | + List<String> cols = new ArrayList<>(); | |
| 260 | + for (String[] f : FIELD_MAP) { | |
| 261 | + if (!cols.contains(f[1])) { | |
| 262 | + cols.add(f[1]); | |
| 263 | + } | |
| 264 | + } | |
| 265 | + return cols; | |
| 266 | + } | |
| 267 | + | |
| 268 | + private Object transform(String kind, Object v) { | |
| 269 | + switch (kind) { | |
| 270 | + case "DATE": | |
| 271 | + return toEpochMs(v); | |
| 272 | + case "NUM": | |
| 273 | + return toNumber(v); | |
| 274 | + case "GENDER": | |
| 275 | + return mapGender(v); | |
| 276 | + case "POL": | |
| 277 | + return mapPolitics(v); | |
| 278 | + default: | |
| 279 | + return str(v); | |
| 280 | + } | |
| 281 | + } | |
| 282 | + | |
| 283 | + private static String str(Object v) { | |
| 284 | + if (v == null) { | |
| 285 | + return null; | |
| 286 | + } | |
| 287 | + String s = String.valueOf(v).trim(); | |
| 288 | + return s.isEmpty() ? null : s; | |
| 289 | + } | |
| 290 | + | |
| 291 | + private static Object toEpochMs(Object v) { | |
| 292 | + if (v == null) { | |
| 293 | + return null; | |
| 294 | + } | |
| 295 | + if (v instanceof java.util.Date) { | |
| 296 | + return ((java.util.Date) v).getTime(); | |
| 297 | + } | |
| 298 | + if (v instanceof Number) { | |
| 299 | + return ((Number) v).longValue(); | |
| 300 | + } | |
| 301 | + String s = str(v); | |
| 302 | + if (s == null) { | |
| 303 | + return null; | |
| 304 | + } | |
| 305 | + try { | |
| 306 | + return java.time.LocalDate.parse(s.length() > 10 ? s.substring(0, 10) : s) | |
| 307 | + .atStartOfDay(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli(); | |
| 308 | + } catch (Exception e) { | |
| 309 | + return null; | |
| 310 | + } | |
| 311 | + } | |
| 312 | + | |
| 313 | + private static Object toNumber(Object v) { | |
| 314 | + if (v == null) { | |
| 315 | + return null; | |
| 316 | + } | |
| 317 | + if (v instanceof Number) { | |
| 318 | + return v; | |
| 319 | + } | |
| 320 | + String s = str(v); | |
| 321 | + if (s == null) { | |
| 322 | + return null; | |
| 323 | + } | |
| 324 | + try { | |
| 325 | + return Long.valueOf(s); | |
| 326 | + } catch (NumberFormatException e) { | |
| 327 | + try { | |
| 328 | + return Double.valueOf(s); | |
| 329 | + } catch (NumberFormatException ex) { | |
| 330 | + return null; | |
| 331 | + } | |
| 332 | + } | |
| 333 | + } | |
| 334 | + | |
| 335 | + /** 性别:文本 1=男 2=女 3=未知。 */ | |
| 336 | + private static String mapGender(Object v) { | |
| 337 | + String s = str(v); | |
| 338 | + if (s == null) { | |
| 339 | + return null; | |
| 340 | + } | |
| 341 | + if ("1".equals(s) || "男".equals(s)) { | |
| 342 | + return "1"; | |
| 343 | + } | |
| 344 | + if ("2".equals(s) || "女".equals(s)) { | |
| 345 | + return "2"; | |
| 346 | + } | |
| 347 | + return "3"; | |
| 348 | + } | |
| 349 | + | |
| 350 | + /** 政治面貌:文本 1=党员 2=中国共产党预备党员 3=群众。 */ | |
| 351 | + private static String mapPolitics(Object v) { | |
| 352 | + String s = str(v); | |
| 353 | + if (s == null) { | |
| 354 | + return null; | |
| 355 | + } | |
| 356 | + if (s.contains("预备")) { | |
| 357 | + return "2"; | |
| 358 | + } | |
| 359 | + if (s.contains("党员")) { | |
| 360 | + return "1"; | |
| 361 | + } | |
| 362 | + if (s.contains("群众")) { | |
| 363 | + return "3"; | |
| 364 | + } | |
| 365 | + return s; | |
| 366 | + } | |
| 367 | +} | ... | ... |
| ... | ... | @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; |
| 8 | 8 | import org.apache.poi.ss.usermodel.Cell; |
| 9 | 9 | import org.apache.poi.ss.usermodel.CellStyle; |
| 10 | 10 | import org.apache.poi.ss.usermodel.Font; |
| 11 | +import org.apache.poi.ss.usermodel.IndexedColors; | |
| 11 | 12 | import org.apache.poi.ss.usermodel.Row; |
| 12 | 13 | import org.apache.poi.ss.usermodel.Sheet; |
| 13 | 14 | import org.apache.poi.ss.usermodel.Workbook; |
| ... | ... | @@ -35,6 +36,21 @@ public class JdyExcelExportService { |
| 35 | 36 | private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai"); |
| 36 | 37 | private static final DateTimeFormatter TS = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| 37 | 38 | |
| 39 | + /** 当前线程的关联映射(关联字段值 id -> 中文名称);由风险服务在导出前设置。 */ | |
| 40 | + private static final ThreadLocal<java.util.Map<String, String>> LOOKUP = new ThreadLocal<>(); | |
| 41 | + | |
| 42 | + public static void setLookup(java.util.Map<String, String> map) { | |
| 43 | + if (map == null || map.isEmpty()) { | |
| 44 | + LOOKUP.remove(); | |
| 45 | + } else { | |
| 46 | + LOOKUP.set(map); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + | |
| 50 | + public static java.util.Map<String, String> currentLookup() { | |
| 51 | + return LOOKUP.get(); | |
| 52 | + } | |
| 53 | + | |
| 38 | 54 | private final JdyFormSyncProperties props; |
| 39 | 55 | |
| 40 | 56 | public JdyExcelExportService(JdyFormSyncProperties props) { |
| ... | ... | @@ -110,10 +126,27 @@ public class JdyExcelExportService { |
| 110 | 126 | */ |
| 111 | 127 | public String exportRows(JSONArray widgets, JSONArray rows, String extraHeader, |
| 112 | 128 | List<String> extraValues, String fileName) { |
| 129 | + return exportRows(widgets, rows, extraHeader, extraValues, fileName, null); | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * 导出指定行到 Excel(供风险场景附件用),可在最右增加一列,并指定 sheet 名。 | |
| 134 | + */ | |
| 135 | + public String exportRows(JSONArray widgets, JSONArray rows, String extraHeader, | |
| 136 | + List<String> extraValues, String fileName, String sheetName) { | |
| 137 | + return exportRows(widgets, rows, extraHeader, extraValues, fileName, sheetName, null); | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * 导出指定行到 Excel(供风险场景附件用),可在最右增加一列,并指定 sheet 名与百分数列。 | |
| 142 | + */ | |
| 143 | + public String exportRows(JSONArray widgets, JSONArray rows, String extraHeader, | |
| 144 | + List<String> extraValues, String fileName, String sheetName, | |
| 145 | + java.util.Set<String> percentFields) { | |
| 113 | 146 | try { |
| 114 | 147 | File dir = exportDir(); |
| 115 | 148 | File outFile = new File(dir, fileName); |
| 116 | - writeWorkbook(widgets, rows, extraHeader, extraValues, outFile); | |
| 149 | + writeWorkbook(widgets, rows, extraHeader, extraValues, outFile, sheetName, percentFields); | |
| 117 | 150 | log.info("导出 Excel: {} ({} 条)", outFile.getAbsolutePath(), rows.size()); |
| 118 | 151 | return outFile.getAbsolutePath(); |
| 119 | 152 | } catch (Exception e) { |
| ... | ... | @@ -124,45 +157,70 @@ public class JdyExcelExportService { |
| 124 | 157 | |
| 125 | 158 | private void writeWorkbook(JSONArray widgets, JSONArray data, String extraHeader, |
| 126 | 159 | List<String> extraValues, File outFile) throws Exception { |
| 160 | + writeWorkbook(widgets, data, extraHeader, extraValues, outFile, null, null); | |
| 161 | + } | |
| 162 | + | |
| 163 | + private void writeWorkbook(JSONArray widgets, JSONArray data, String extraHeader, | |
| 164 | + List<String> extraValues, File outFile, String sheetName) throws Exception { | |
| 165 | + writeWorkbook(widgets, data, extraHeader, extraValues, outFile, sheetName, null); | |
| 166 | + } | |
| 167 | + | |
| 168 | + private void writeWorkbook(JSONArray widgets, JSONArray data, String extraHeader, | |
| 169 | + List<String> extraValues, File outFile, String sheetName, | |
| 170 | + java.util.Set<String> percentFields) throws Exception { | |
| 127 | 171 | try (Workbook wb = new XSSFWorkbook()) { |
| 128 | - Sheet sheet = wb.createSheet("数据"); | |
| 172 | + Sheet sheet = wb.createSheet(safeSheetName(sheetName)); | |
| 129 | 173 | CellStyle headerStyle = wb.createCellStyle(); |
| 130 | 174 | Font bold = wb.createFont(); |
| 131 | 175 | bold.setBold(true); |
| 132 | 176 | headerStyle.setFont(bold); |
| 133 | 177 | |
| 134 | 178 | Row header = sheet.createRow(0); |
| 179 | + boolean hasExtra = extraHeader != null && !extraHeader.isEmpty(); | |
| 180 | + Font redFont = wb.createFont(); | |
| 181 | + redFont.setBold(true); | |
| 182 | + redFont.setColor(IndexedColors.RED.getIndex()); | |
| 183 | + CellStyle extraHeaderStyle = wb.createCellStyle(); | |
| 184 | + extraHeaderStyle.setFont(redFont); | |
| 185 | + int offset = 0; | |
| 186 | + if (hasExtra) { | |
| 187 | + Cell cell = header.createCell(0); | |
| 188 | + cell.setCellValue(extraHeader); | |
| 189 | + cell.setCellStyle(extraHeaderStyle); | |
| 190 | + offset = 1; | |
| 191 | + } | |
| 135 | 192 | for (int c = 0; c < widgets.size(); c++) { |
| 136 | 193 | JSONObject w = widgets.getJSONObject(c); |
| 137 | 194 | String label = w.getString("label"); |
| 138 | 195 | if (label == null || label.isEmpty()) { |
| 139 | 196 | label = w.getString("widgetName"); |
| 140 | 197 | } |
| 141 | - Cell cell = header.createCell(c); | |
| 198 | + Cell cell = header.createCell(c + offset); | |
| 142 | 199 | cell.setCellValue(label); |
| 143 | 200 | cell.setCellStyle(headerStyle); |
| 144 | 201 | } |
| 145 | - boolean hasExtra = extraHeader != null && !extraHeader.isEmpty(); | |
| 146 | - if (hasExtra) { | |
| 147 | - Cell cell = header.createCell(widgets.size()); | |
| 148 | - cell.setCellValue(extraHeader); | |
| 149 | - cell.setCellStyle(headerStyle); | |
| 150 | - } | |
| 151 | 202 | |
| 152 | 203 | for (int r = 0; r < data.size(); r++) { |
| 153 | 204 | JSONObject rec = data.getJSONObject(r); |
| 154 | 205 | Row row = sheet.createRow(r + 1); |
| 155 | - for (int c = 0; c < widgets.size(); c++) { | |
| 156 | - String code = widgets.getJSONObject(c).getString("name"); | |
| 157 | - row.createCell(c).setCellValue(formatValue(rec.get(code))); | |
| 158 | - } | |
| 159 | 206 | if (hasExtra) { |
| 160 | - String v = (extraValues != null && r < extraValues.size() && extraValues.get(r) != null) | |
| 207 | + String ev = (extraValues != null && r < extraValues.size() && extraValues.get(r) != null) | |
| 161 | 208 | ? extraValues.get(r) : ""; |
| 162 | - row.createCell(widgets.size()).setCellValue(v); | |
| 209 | + row.createCell(0).setCellValue(ev); | |
| 210 | + } | |
| 211 | + for (int c = 0; c < widgets.size(); c++) { | |
| 212 | + String code = widgets.getJSONObject(c).getString("name"); | |
| 213 | + Object v = rec.get(code); | |
| 214 | + String val; | |
| 215 | + if (percentFields != null && percentFields.contains(code) && v instanceof Number) { | |
| 216 | + val = String.format("%.1f%%", ((Number) v).doubleValue() * 100); | |
| 217 | + } else { | |
| 218 | + val = formatValue(v); | |
| 219 | + } | |
| 220 | + row.createCell(c + offset).setCellValue(val); | |
| 163 | 221 | } |
| 164 | 222 | } |
| 165 | - for (int c = 0; c <= widgets.size(); c++) { | |
| 223 | + for (int c = 0; c < widgets.size() + offset; c++) { | |
| 166 | 224 | sheet.setColumnWidth(c, 20 * 256); |
| 167 | 225 | } |
| 168 | 226 | try (OutputStream os = new FileOutputStream(outFile)) { |
| ... | ... | @@ -202,6 +260,18 @@ public class JdyExcelExportService { |
| 202 | 260 | return null; |
| 203 | 261 | } |
| 204 | 262 | |
| 263 | + /** Excel sheet 名:非法字符替换、去空、限 31 字符,默认「数据」。 */ | |
| 264 | + private static String safeSheetName(String name) { | |
| 265 | + if (name == null || name.trim().isEmpty()) { | |
| 266 | + return "数据"; | |
| 267 | + } | |
| 268 | + String s = name.replaceAll("[\\\\/:*?\\[\\]]", "_").trim(); | |
| 269 | + if (s.length() > 31) { | |
| 270 | + s = s.substring(0, 31); | |
| 271 | + } | |
| 272 | + return s; | |
| 273 | + } | |
| 274 | + | |
| 205 | 275 | /** 值格式化:时间->北京时间字符串;用户对象->name;数组->逗号连接。 */ |
| 206 | 276 | private String formatValue(Object v) { |
| 207 | 277 | if (v == null) { |
| ... | ... | @@ -231,6 +301,10 @@ public class JdyExcelExportService { |
| 231 | 301 | return sb.toString(); |
| 232 | 302 | } |
| 233 | 303 | String s = String.valueOf(v); |
| 304 | + java.util.Map<String, String> lk = LOOKUP.get(); | |
| 305 | + if (lk != null && lk.containsKey(s)) { | |
| 306 | + return lk.get(s); | |
| 307 | + } | |
| 234 | 308 | if (s.matches("\\d{4}-\\d{2}-\\d{2}T.*")) { |
| 235 | 309 | try { |
| 236 | 310 | return Instant.parse(s).atZone(ZONE).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); | ... | ... |
| ... | ... | @@ -31,6 +31,111 @@ public class JdyRiskStatisticsService { |
| 31 | 31 | |
| 32 | 32 | private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai"); |
| 33 | 33 | private static final DateTimeFormatter MONTH_FMT = DateTimeFormatter.ofPattern("yyyy-MM"); |
| 34 | + private static final DateTimeFormatter DAY_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | |
| 35 | + | |
| 36 | + /** 固定业务数据(新增时使用):key = syncCode。 */ | |
| 37 | + private static final Map<String, Biz> BIZ = new LinkedHashMap<>(); | |
| 38 | + | |
| 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); | |
| 108 | + } | |
| 109 | + | |
| 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; | |
| 126 | + | |
| 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; | |
| 137 | + } | |
| 138 | + } | |
| 34 | 139 | |
| 35 | 140 | private final JdyRiskProperties props; |
| 36 | 141 | private final JdyExcelExportService excelExportService; |
| ... | ... | @@ -49,9 +154,12 @@ public class JdyRiskStatisticsService { |
| 49 | 154 | String type = s.getType() == null ? "" : s.getType().toLowerCase(); |
| 50 | 155 | if ("scenario7".equals(type)) { |
| 51 | 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); | |
| 52 | 161 | } else { |
| 53 | - JSONArray all = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId()); | |
| 54 | - JSONArray rows = filterScope(all, s); | |
| 162 | + JSONArray rows = buildScopeRows(jdy, s); | |
| 55 | 163 | result.put(s.getId(), count(s, rows)); |
| 56 | 164 | } |
| 57 | 165 | } catch (Exception e) { |
| ... | ... | @@ -100,9 +208,12 @@ public class JdyRiskStatisticsService { |
| 100 | 208 | String type = s.getType() == null ? "" : s.getType().toLowerCase(); |
| 101 | 209 | if ("scenario7".equals(type)) { |
| 102 | 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); | |
| 103 | 215 | } else { |
| 104 | - JSONArray all = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId()); | |
| 105 | - result.put(s.getId(), count(s, filterScope(all, s))); | |
| 216 | + result.put(s.getId(), count(s, buildScopeRows(jdy, s))); | |
| 106 | 217 | } |
| 107 | 218 | } catch (Exception e) { |
| 108 | 219 | result.put(s.getId(), "ERROR: " + e.getMessage()); |
| ... | ... | @@ -156,60 +267,112 @@ public class JdyRiskStatisticsService { |
| 156 | 267 | JSONArray allRecords = ctx.allRecords; |
| 157 | 268 | try { |
| 158 | 269 | String type = s.getType() == null ? "" : s.getType().toLowerCase(); |
| 270 | + JdyExcelExportService.setLookup(buildLookupMap(jdy, s)); | |
| 159 | 271 | JSONArray rows; |
| 272 | + JSONArray widgets; | |
| 160 | 273 | long count; |
| 274 | + String extraHeader = null; | |
| 275 | + List<String> extraValues = null; | |
| 161 | 276 | if ("scenario7".equals(type)) { |
| 162 | 277 | rows = buildScenario7Rows(jdy, s); |
| 163 | 278 | count = rows.size(); |
| 279 | + widgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId()); | |
| 280 | + } else if ("scenario11".equals(type)) { | |
| 281 | + Built11 b = buildScenario11(jdy, s); | |
| 282 | + rows = b.excelRows; | |
| 283 | + count = b.count; | |
| 284 | + widgets = b.excelWidgets; | |
| 285 | + } else if (isReasonType(type)) { | |
| 286 | + BuiltReason br = buildReasonRows(jdy, s); | |
| 287 | + rows = br.rows; | |
| 288 | + count = br.count; | |
| 289 | + widgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId()); | |
| 290 | + extraHeader = "原因"; | |
| 291 | + extraValues = br.reasons; | |
| 164 | 292 | } else { |
| 165 | - JSONArray all = jdy.listAllData(props.getApiKey(), s.getAppId(), s.getEntryId()); | |
| 166 | - rows = filterScope(all, s); | |
| 293 | + rows = buildScopeRows(jdy, s); | |
| 167 | 294 | count = count(s, rows); |
| 295 | + widgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId()); | |
| 296 | + 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); | |
| 305 | + } | |
| 306 | + if (s.isOnlyWarnRows()) { | |
| 307 | + rows = filterWarnRows(s, rows); | |
| 308 | + extraValues = buildExtraValues(s, rows); | |
| 309 | + } | |
| 310 | + // 按名称(分组字段,其次附加列字段)排序,方便阅读 | |
| 311 | + String sortField = s.getGroupField() != null && !s.getGroupField().isEmpty() | |
| 312 | + ? s.getGroupField() : s.getExtraField(); | |
| 313 | + if (sortField != null && !sortField.isEmpty()) { | |
| 314 | + sortRows(rows, sortField); | |
| 315 | + if (extraHeader != null) { | |
| 316 | + extraValues = buildExtraValues(s, rows); | |
| 317 | + } | |
| 318 | + } | |
| 168 | 319 | } |
| 169 | 320 | result.put(s.getId(), count); |
| 170 | 321 | log.info("场景[{}] 命中={} (参与统计{}条)", s.getId(), count, rows.size()); |
| 171 | 322 | |
| 172 | - JSONArray widgets = jdy.listWidgets(props.getApiKey(), s.getAppId(), s.getEntryId()); | |
| 173 | - String extraHeader = null; | |
| 174 | - List<String> extraValues = null; | |
| 175 | - if (!"scenario7".equals(type)) { | |
| 176 | - if ("scenario4".equals(type) || "scenario6".equals(type) || "scenario8".equals(type)) { | |
| 177 | - extraHeader = "预警供应商"; | |
| 178 | - } else if ("scenario5".equals(type) || "scenario9".equals(type)) { | |
| 179 | - extraHeader = "预警工程师"; | |
| 180 | - } else { | |
| 181 | - extraHeader = "筛选结果"; | |
| 323 | + // 设备域场景:命中 0 条时不生成 Excel、不上传附件(仍回写计数) | |
| 324 | + boolean skipAttach = isReasonType(type) && count == 0; | |
| 325 | + String fileId = null; | |
| 326 | + String fileName = null; | |
| 327 | + long size = 0; | |
| 328 | + if (skipAttach) { | |
| 329 | + log.info("场景[{}] 命中0条,跳过 Excel 生成与附件上传,仅回写计数", s.getId()); | |
| 330 | + } else { | |
| 331 | + java.util.Set<String> percentFields = s.getPercentFields().isEmpty() | |
| 332 | + ? null : new java.util.HashSet<>(s.getPercentFields()); | |
| 333 | + 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); | |
| 337 | + if (path == null || path.startsWith("FAIL")) { | |
| 338 | + throw new IllegalStateException("Excel 导出失败: " + path); | |
| 182 | 339 | } |
| 183 | - extraValues = buildExtraValues(s, rows); | |
| 184 | - } | |
| 185 | - String fileName = JdyExcelExportService.nowFileName(); | |
| 186 | - String path = excelExportService.exportRows(widgets, rows, extraHeader, extraValues, fileName); | |
| 187 | - if (path == null || path.startsWith("FAIL")) { | |
| 188 | - throw new IllegalStateException("Excel 导出失败: " + path); | |
| 340 | + fileId = qxApi.uploadFile(token, new File(path), fileName); | |
| 341 | + size = new File(path).length(); | |
| 189 | 342 | } |
| 190 | 343 | |
| 191 | - String fileId = qxApi.uploadFile(token, new File(path), fileName); | |
| 192 | - | |
| 344 | + long now = System.currentTimeMillis(); | |
| 193 | 345 | String syncCode = s.getSyncCode(); |
| 194 | - JSONObject rec = findRecordBySyncCode(allRecords, syncCode); | |
| 195 | - if (rec == null) { | |
| 196 | - log.warn("按 syncCode={} 未查到记录,跳过写回", syncCode); | |
| 197 | - return; | |
| 198 | - } | |
| 199 | - rec.put(qx.getCountField(), count); | |
| 200 | - if (qx.getTimeField() != null && !qx.getTimeField().isEmpty()) { | |
| 201 | - rec.put(qx.getTimeField(), System.currentTimeMillis()); // 预警时间 = 当次跑任务系统时间 | |
| 202 | - } | |
| 203 | - if (qx.getAttachField() != null && !qx.getAttachField().isEmpty()) { | |
| 204 | - JSONObject rel = new JSONObject(); | |
| 205 | - rel.put("id", fileId); | |
| 206 | - rel.put("dataTitle", fileName); | |
| 207 | - rec.put(qx.getAttachField(), rel); | |
| 208 | - rec.put(qx.getAttachField() + "Id", fileId); | |
| 209 | - } | |
| 210 | - qxApi.updateData(token, qx.getAppId(), qx.getUpdateCode(), rec); | |
| 211 | - log.info("写回成功: syncCode={} id={} {}={} 附件={}", syncCode, rec.getString("id"), | |
| 212 | - qx.getCountField(), count, fileName); | |
| 346 | + | |
| 347 | + // 当天(预警日期)已有该场景数据 → 更新;否则 → 新增 | |
| 348 | + JSONObject todayRec = findTodayRecord(allRecords, syncCode, qx.getTimeField()); | |
| 349 | + if (todayRec != null) { | |
| 350 | + todayRec.put(qx.getCountField(), count); | |
| 351 | + setTimeFields(todayRec, qx, now); | |
| 352 | + if (!skipAttach && qx.getAttachField() != null && !qx.getAttachField().isEmpty()) { | |
| 353 | + todayRec.put(qx.getAttachField(), buildAttach(fileId, fileName, size)); | |
| 354 | + todayRec.put(qx.getAttachField() + "Id", fileId); | |
| 355 | + } | |
| 356 | + qxApi.updateData(token, qx.getAppId(), qx.getUpdateCode(), todayRec); | |
| 357 | + log.info("当天已存在→更新成功: syncCode={} id={} {}={} 附件={}", syncCode, | |
| 358 | + todayRec.getString("id"), qx.getCountField(), count, fileName); | |
| 359 | + } else { | |
| 360 | + JSONObject template = findRecordBySyncCode(allRecords, syncCode); | |
| 361 | + JSONObject addBody; | |
| 362 | + if (template != null) { | |
| 363 | + addBody = cloneTemplate(template, qx, syncCode, count, now, fileId, fileName, size, skipAttach); | |
| 364 | + log.info("当天无数据→以[{}]现有记录为模板新增", syncCode); | |
| 365 | + } else { | |
| 366 | + Biz biz = BIZ.get(syncCode); | |
| 367 | + if (biz == null) { | |
| 368 | + throw new IllegalStateException("未配置该场景的新增业务数据(模板): " + syncCode); | |
| 369 | + } | |
| 370 | + addBody = buildAddBody(biz, qx, syncCode, count, now, fileId, fileName, size); | |
| 371 | + } | |
| 372 | + String newId = qxApi.addData(token, qx.getAppId(), qx.getAddCode(), addBody); | |
| 373 | + log.info("当天无数据→新增成功: syncCode={} newId={} {}={} 附件={}", syncCode, | |
| 374 | + newId, qx.getCountField(), count, fileName); | |
| 375 | + } | |
| 213 | 376 | } catch (Exception e) { |
| 214 | 377 | log.error("场景[{}] 写回失败", s.getId(), e); |
| 215 | 378 | result.put(s.getId() + "_error", e.getMessage()); |
| ... | ... | @@ -221,7 +384,7 @@ public class JdyRiskStatisticsService { |
| 221 | 384 | /** 按场景统计周期过滤数据:全量 / 当月 / 当季度 / 上一季度 / 当年 / 上月。 */ |
| 222 | 385 | private JSONArray filterScope(JSONArray all, JdyRiskProperties.Scenario s) { |
| 223 | 386 | if (!s.isMonthOnly() && !s.isQuarterOnly() && !s.isPrevQuarterOnly() |
| 224 | - && !s.isYearOnly() && !s.isPrevMonthOnly()) { | |
| 387 | + && !s.isYearOnly() && !s.isPrevMonthOnly() && !s.isPrevThreeMonths()) { | |
| 225 | 388 | return all; |
| 226 | 389 | } |
| 227 | 390 | ZonedDateTime now = ZonedDateTime.now(ZONE); |
| ... | ... | @@ -231,6 +394,7 @@ public class JdyRiskStatisticsService { |
| 231 | 394 | ZonedDateTime yStart = now.withDayOfYear(1).truncatedTo(ChronoUnit.DAYS); |
| 232 | 395 | ZonedDateTime pmStart = now.minusMonths(1).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS); |
| 233 | 396 | ZonedDateTime pmEnd = now.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS); |
| 397 | + ZonedDateTime p3Start = now.minusMonths(3).withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS); | |
| 234 | 398 | String month = now.format(MONTH_FMT); |
| 235 | 399 | JSONArray out = new JSONArray(); |
| 236 | 400 | for (int i = 0; i < all.size(); i++) { |
| ... | ... | @@ -248,6 +412,8 @@ public class JdyRiskStatisticsService { |
| 248 | 412 | keep = !dt.isBefore(yStart) && !dt.isAfter(now); |
| 249 | 413 | } else if (s.isPrevMonthOnly()) { |
| 250 | 414 | keep = !dt.isBefore(pmStart) && dt.isBefore(pmEnd); |
| 415 | + } else if (s.isPrevThreeMonths()) { | |
| 416 | + keep = !dt.isBefore(p3Start) && dt.isBefore(pmEnd); | |
| 251 | 417 | } else if (s.isMonthOnly()) { |
| 252 | 418 | keep = month.equals(dt.format(MONTH_FMT)); |
| 253 | 419 | } |
| ... | ... | @@ -277,6 +443,8 @@ public class JdyRiskStatisticsService { |
| 277 | 443 | case "scenario8": |
| 278 | 444 | case "scenario9": |
| 279 | 445 | return warningGroupsByRatio(s, rows).size(); |
| 446 | + case "scenario10": | |
| 447 | + return rows.size(); | |
| 280 | 448 | default: |
| 281 | 449 | throw new IllegalStateException("未知场景类型: " + s.getType()); |
| 282 | 450 | } |
| ... | ... | @@ -448,6 +616,589 @@ public class JdyRiskStatisticsService { |
| 448 | 616 | return kept; |
| 449 | 617 | } |
| 450 | 618 | |
| 619 | + /** scenario10:保留 |diffField| > absThreshold 的行(Excel 也只放这些行)。 */ | |
| 620 | + private JSONArray filterByAbsThreshold(JdyRiskProperties.Scenario s, JSONArray rows) { | |
| 621 | + JSONArray out = new JSONArray(); | |
| 622 | + for (int i = 0; i < rows.size(); i++) { | |
| 623 | + JSONObject row = rows.getJSONObject(i); | |
| 624 | + if (Math.abs(num(row, s.getDiffField())) > s.getAbsThreshold()) { | |
| 625 | + out.add(row); | |
| 626 | + } | |
| 627 | + } | |
| 628 | + return out; | |
| 629 | + } | |
| 630 | + | |
| 631 | + /** 取场景参与统计的行:全量/周期过滤 + scenario10 的阈值过滤(scenario7 另走流式)。 */ | |
| 632 | + 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(); | |
| 636 | + if ("scenario10".equals(type)) { | |
| 637 | + return filterByAbsThreshold(s, scoped); | |
| 638 | + } | |
| 639 | + return scoped; | |
| 640 | + } | |
| 641 | + | |
| 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 | + 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<>(); | |
| 661 | + for (JdyRiskProperties.ExcludeForm ef : s.getExcludeForms()) { | |
| 662 | + if (ef == null || ef.getEntryId() == null || ef.getBarcodeField() == null) { | |
| 663 | + continue; | |
| 664 | + } | |
| 665 | + 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 | + }); | |
| 675 | + } | |
| 676 | + | |
| 677 | + Map<String, List<JSONObject>> aMap = groupByBarcode(aRows, s.getBarcodeField()); | |
| 678 | + Map<String, List<JSONObject>> bMap = groupByBarcode(bRows, s.getCompareBarcodeField()); | |
| 679 | + for (String k : cSet) { | |
| 680 | + aMap.remove(k); | |
| 681 | + bMap.remove(k); | |
| 682 | + } | |
| 683 | + for (String k : new ArrayList<>(aMap.keySet())) { | |
| 684 | + List<JSONObject> bl = bMap.get(k); | |
| 685 | + if (bl == null) { | |
| 686 | + continue; | |
| 687 | + } | |
| 688 | + List<JSONObject> al = aMap.get(k); | |
| 689 | + int common = Math.min(al.size(), bl.size()); | |
| 690 | + for (int i = 0; i < common; i++) { | |
| 691 | + al.remove(al.size() - 1); | |
| 692 | + bl.remove(bl.size() - 1); | |
| 693 | + } | |
| 694 | + if (al.isEmpty()) { | |
| 695 | + aMap.remove(k); | |
| 696 | + } | |
| 697 | + if (bl.isEmpty()) { | |
| 698 | + bMap.remove(k); | |
| 699 | + } | |
| 700 | + } | |
| 701 | + | |
| 702 | + JSONArray excelRows = new JSONArray(); | |
| 703 | + long pos = 0; | |
| 704 | + long neg = 0; | |
| 705 | + for (Map.Entry<String, List<JSONObject>> e : aMap.entrySet()) { | |
| 706 | + for (JSONObject row : e.getValue()) { | |
| 707 | + row.put("__type", "正"); | |
| 708 | + excelRows.add(row); | |
| 709 | + pos++; | |
| 710 | + } | |
| 711 | + } | |
| 712 | + for (Map.Entry<String, List<JSONObject>> e : bMap.entrySet()) { | |
| 713 | + for (JSONObject row : e.getValue()) { | |
| 714 | + row.put("__type", "负"); | |
| 715 | + excelRows.add(row); | |
| 716 | + neg++; | |
| 717 | + } | |
| 718 | + } | |
| 719 | + | |
| 720 | + JSONArray widgets = new JSONArray(); | |
| 721 | + widgets.add(syntheticWidget("__type", "类型(正/负)")); | |
| 722 | + for (int i = 0; i < aWidgets.size(); i++) { | |
| 723 | + widgets.add(aWidgets.getJSONObject(i)); | |
| 724 | + } | |
| 725 | + for (int i = 0; i < bWidgets.size(); i++) { | |
| 726 | + widgets.add(bWidgets.getJSONObject(i)); | |
| 727 | + } | |
| 728 | + | |
| 729 | + Built11 built = new Built11(); | |
| 730 | + built.count = pos + neg; | |
| 731 | + built.excelRows = excelRows; | |
| 732 | + built.excelWidgets = widgets; | |
| 733 | + log.info("场景11 A={}条 B={}条 C条码={} -> 正={} 负={} 预警数量={}", | |
| 734 | + aRows.size(), bRows.size(), cSet.size(), pos, neg, built.count); | |
| 735 | + return built; | |
| 736 | + } | |
| 737 | + | |
| 738 | + /** scenario12/13 结果:命中数 + 仅命中行 + 原因列(与命中行一一对应)。 */ | |
| 739 | + private static class BuiltReason { | |
| 740 | + long count; | |
| 741 | + JSONArray rows = new JSONArray(); | |
| 742 | + List<String> reasons = new ArrayList<>(); | |
| 743 | + } | |
| 744 | + | |
| 745 | + 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); | |
| 751 | + } | |
| 752 | + | |
| 753 | + /** | |
| 754 | + * scenario12 / scenario13:先按统计周期过滤,再逐条判定异常并生成「原因」。 | |
| 755 | + * <ul> | |
| 756 | + * <li>scenario12:参与人员N有值但对应手写签字确认为空 → 命中,原因「参与人员N未签字确认」</li> | |
| 757 | + * <li>scenario13:停留时长>阈值 且(是否异常=异常值 或 异常原因说明为空)→ 命中</li> | |
| 758 | + * </ul> | |
| 759 | + */ | |
| 760 | + 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); | |
| 763 | + String type = s.getType() == null ? "" : s.getType().toLowerCase(); | |
| 764 | + BuiltReason built = new BuiltReason(); | |
| 765 | + long explicitCount = -1; | |
| 766 | + if ("scenario12".equals(type)) { | |
| 767 | + int n = 0; | |
| 768 | + 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++) { | |
| 774 | + JSONObject row = scoped.getJSONObject(i); | |
| 775 | + if (hasValue(row, p.getPersonField()) && !hasValue(row, p.getSignField())) { | |
| 776 | + row.put("__reason_" + n, "参与人员" + n + "未签字确认"); | |
| 777 | + } | |
| 778 | + } | |
| 779 | + } | |
| 780 | + for (int i = 0; i < scoped.size(); i++) { | |
| 781 | + 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)); | |
| 793 | + } | |
| 794 | + } | |
| 795 | + } else if ("scenario13".equals(type)) { | |
| 796 | + for (int i = 0; i < scoped.size(); i++) { | |
| 797 | + JSONObject row = scoped.getJSONObject(i); | |
| 798 | + if (num(row, s.getDurationField()) <= s.getDurationThreshold()) { | |
| 799 | + continue; | |
| 800 | + } | |
| 801 | + List<String> reasons = new ArrayList<>(); | |
| 802 | + if (s.getAbnormalValue() != null && s.getAbnormalValue().equals(row.getString(s.getAbnormalField()))) { | |
| 803 | + reasons.add("存在异常出门"); | |
| 804 | + } | |
| 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)); | |
| 811 | + } | |
| 812 | + } | |
| 813 | + } 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())); | |
| 818 | + counts.merge(g, 1, Integer::sum); | |
| 819 | + } | |
| 820 | + 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 | + } | |
| 826 | + } | |
| 827 | + for (int i = 0; i < scoped.size(); i++) { | |
| 828 | + 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 | + } | |
| 835 | + } | |
| 836 | + explicitCount = hitGroups; | |
| 837 | + } else if ("scenario15".equals(type)) { | |
| 838 | + // 流转完成 + 条件为「是」时对应照片不能为空 | |
| 839 | + Map<String, String> labels = widgetLabels(jdy, s); | |
| 840 | + for (int i = 0; i < scoped.size(); i++) { | |
| 841 | + JSONObject row = scoped.getJSONObject(i); | |
| 842 | + if (!flowStateMatches(s, row)) { | |
| 843 | + continue; | |
| 844 | + } | |
| 845 | + List<String> reasons = new ArrayList<>(); | |
| 846 | + 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 + "为空"); | |
| 857 | + } | |
| 858 | + } | |
| 859 | + if (!reasons.isEmpty()) { | |
| 860 | + built.rows.add(row); | |
| 861 | + built.reasons.add(String.join("、", reasons)); | |
| 862 | + } | |
| 863 | + } | |
| 864 | + } else if ("scenario16".equals(type)) { | |
| 865 | + // 是否超出预算∈{高预算,低预算} 且 未填写超预算原因 | |
| 866 | + for (int i = 0; i < scoped.size(); i++) { | |
| 867 | + JSONObject row = scoped.getJSONObject(i); | |
| 868 | + 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 | + } | |
| 873 | + } | |
| 874 | + } else if ("scenario17".equals(type)) { | |
| 875 | + // 流转完成 + 施工完成日期超过计划完成时间 overdueDays 天 | |
| 876 | + for (int i = 0; i < scoped.size(); i++) { | |
| 877 | + 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 | + } | |
| 894 | + } | |
| 895 | + } else if ("scenario18".equals(type)) { | |
| 896 | + // 当月施工单位未提交审计资料 且 原因说明为空 | |
| 897 | + for (int i = 0; i < scoped.size(); i++) { | |
| 898 | + JSONObject row = scoped.getJSONObject(i); | |
| 899 | + 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 | + } | |
| 904 | + } | |
| 905 | + } else if ("scenario19".equals(type)) { | |
| 906 | + // 三个月内是否已提报相似项目 = 是 → 命中 | |
| 907 | + for (int i = 0; i < scoped.size(); i++) { | |
| 908 | + JSONObject row = scoped.getJSONObject(i); | |
| 909 | + String v = row.getString(s.getFlagField()); | |
| 910 | + if (v != null && s.getFlagValues().contains(v)) { | |
| 911 | + built.rows.add(row); | |
| 912 | + built.reasons.add("三个月内已提报相似项目"); | |
| 913 | + } | |
| 914 | + } | |
| 915 | + } 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++) { | |
| 920 | + ordered.add(flagged.getJSONObject(i)); | |
| 921 | + } | |
| 922 | + sortByDateDesc(ordered, s.getDateField()); | |
| 923 | + long hits = 0; | |
| 924 | + 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()); | |
| 932 | + continue; | |
| 933 | + } | |
| 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++; | |
| 945 | + } | |
| 946 | + } | |
| 947 | + explicitCount = hits; | |
| 948 | + } 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; | |
| 958 | + } | |
| 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); | |
| 964 | + } | |
| 965 | + } | |
| 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()); | |
| 971 | + } | |
| 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 | + } | |
| 980 | + } | |
| 981 | + if (common == null) { | |
| 982 | + common = new LinkedHashSet<>(); | |
| 983 | + } | |
| 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)); | |
| 989 | + } | |
| 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 | + } | |
| 1000 | + } | |
| 1001 | + sortByDateDesc(ordered, s.getDateField()); | |
| 1002 | + for (JSONObject row : ordered) { | |
| 1003 | + built.rows.add(row); | |
| 1004 | + built.reasons.add(reason); | |
| 1005 | + } | |
| 1006 | + explicitCount = common.size(); | |
| 1007 | + } | |
| 1008 | + } else { | |
| 1009 | + log.warn("场景[{}] 近三个月数据不足({}个月),跳过", s.getId(), monthTotals.size()); | |
| 1010 | + } | |
| 1011 | + } | |
| 1012 | + built.count = explicitCount >= 0 ? explicitCount : built.rows.size(); | |
| 1013 | + log.info("场景[{}] 周期内={}条, 命中={}条", s.getId(), scoped.size(), built.count); | |
| 1014 | + return built; | |
| 1015 | + } | |
| 1016 | + | |
| 1017 | + /** flowState 是否命中配置值(未配置则视为命中)。 */ | |
| 1018 | + private static boolean flowStateMatches(JdyRiskProperties.Scenario s, JSONObject row) { | |
| 1019 | + Integer want = s.getFlowStateValue(); | |
| 1020 | + if (want == null) { | |
| 1021 | + return true; | |
| 1022 | + } | |
| 1023 | + Integer f = row.getInteger("flowState"); | |
| 1024 | + return f != null && f.equals(want); | |
| 1025 | + } | |
| 1026 | + | |
| 1027 | + /** 表单字段 code -> 标题 映射(用于生成原因文案)。 */ | |
| 1028 | + 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++) { | |
| 1032 | + JSONObject w = ws.getJSONObject(i); | |
| 1033 | + String n = w.getString("name"); | |
| 1034 | + String l = w.getString("label"); | |
| 1035 | + if (n != null && l != null) { | |
| 1036 | + m.put(n, l); | |
| 1037 | + } | |
| 1038 | + } | |
| 1039 | + return m; | |
| 1040 | + } | |
| 1041 | + | |
| 1042 | + /** 判断字段是否有值(null / 空字符串 / 空对象 / 空数组 视为无值)。 */ | |
| 1043 | + private static boolean hasValue(JSONObject row, String field) { | |
| 1044 | + if (field == null) { | |
| 1045 | + return false; | |
| 1046 | + } | |
| 1047 | + Object v = row.get(field); | |
| 1048 | + if (v == null) { | |
| 1049 | + return false; | |
| 1050 | + } | |
| 1051 | + if (v instanceof String) { | |
| 1052 | + return !((String) v).trim().isEmpty(); | |
| 1053 | + } | |
| 1054 | + if (v instanceof JSONObject) { | |
| 1055 | + JSONObject o = (JSONObject) v; | |
| 1056 | + return !o.isEmpty() && (o.getString("name") != null ? !o.getString("name").trim().isEmpty() : true); | |
| 1057 | + } | |
| 1058 | + if (v instanceof JSONArray) { | |
| 1059 | + return !((JSONArray) v).isEmpty(); | |
| 1060 | + } | |
| 1061 | + return true; | |
| 1062 | + } | |
| 1063 | + | |
| 1064 | + /** 按日期字段倒序(最新在前)就地排序;无效日期排到最后。 */ | |
| 1065 | + private static void sortByDateDesc(List<JSONObject> list, String dateField) { | |
| 1066 | + list.sort((a, b) -> { | |
| 1067 | + ZonedDateTime ta = parseTime(a.getString(dateField)); | |
| 1068 | + ZonedDateTime tb = parseTime(b.getString(dateField)); | |
| 1069 | + if (ta == null && tb == null) { | |
| 1070 | + return 0; | |
| 1071 | + } | |
| 1072 | + if (ta == null) { | |
| 1073 | + return 1; | |
| 1074 | + } | |
| 1075 | + if (tb == null) { | |
| 1076 | + return -1; | |
| 1077 | + } | |
| 1078 | + return tb.compareTo(ta); | |
| 1079 | + }); | |
| 1080 | + } | |
| 1081 | + | |
| 1082 | + /** | |
| 1083 | + * 在全部历史数据中找该车「上一笔加油记录」:flag-field == flag-values[0]、flowState 命中、 | |
| 1084 | + * 且用车开始时间早于当前记录,取时间最近的一条。 | |
| 1085 | + */ | |
| 1086 | + private JSONObject findPreviousRefuel(JSONArray all, JdyRiskProperties.Scenario s, | |
| 1087 | + JSONObject current, ZonedDateTime curTime) { | |
| 1088 | + if (curTime == null) { | |
| 1089 | + return null; | |
| 1090 | + } | |
| 1091 | + String flagVal = s.getFlagValues().isEmpty() ? "是" : s.getFlagValues().get(0); | |
| 1092 | + Integer wantFlow = s.getFlowStateValue(); | |
| 1093 | + JSONObject best = null; | |
| 1094 | + ZonedDateTime bestT = null; | |
| 1095 | + for (int i = 0; i < all.size(); i++) { | |
| 1096 | + 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 | + } | |
| 1117 | + } | |
| 1118 | + return best; | |
| 1119 | + } | |
| 1120 | + | |
| 1121 | + /** 仅保留 flag-field 取值属于 flag-values 的行;未配置则原样返回。 */ | |
| 1122 | + private static JSONArray filterByFlag(JSONArray rows, JdyRiskProperties.Scenario s) { | |
| 1123 | + String f = s.getFlagField(); | |
| 1124 | + if (f == null || f.isEmpty() || s.getFlagValues().isEmpty()) { | |
| 1125 | + return rows; | |
| 1126 | + } | |
| 1127 | + JSONArray out = new JSONArray(); | |
| 1128 | + for (int i = 0; i < rows.size(); i++) { | |
| 1129 | + JSONObject row = rows.getJSONObject(i); | |
| 1130 | + if (s.getFlagValues().contains(row.getString(f))) { | |
| 1131 | + out.add(row); | |
| 1132 | + } | |
| 1133 | + } | |
| 1134 | + return out; | |
| 1135 | + } | |
| 1136 | + | |
| 1137 | + /** | |
| 1138 | + * 取得分最低的 N 家公司(第 N 名并列的也一并计入)。 | |
| 1139 | + */ | |
| 1140 | + private static Set<String> bottomCompanyFields(Map<String, Double> totals, int n) { | |
| 1141 | + Set<String> bottom = new LinkedHashSet<>(); | |
| 1142 | + if (totals == null || totals.isEmpty() || n <= 0) { | |
| 1143 | + return bottom; | |
| 1144 | + } | |
| 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 | + } | |
| 1152 | + } | |
| 1153 | + return bottom; | |
| 1154 | + } | |
| 1155 | + | |
| 1156 | + /** 起始公里数:主字段 >0 直接用;否则取「非连续用车」子表单起始公里数的最大值。 */ | |
| 1157 | + private static double startKm(JSONObject row, JdyRiskProperties.Scenario s) { | |
| 1158 | + double v = num(row, s.getStartKmField()); | |
| 1159 | + if (v > 0) { | |
| 1160 | + return v; | |
| 1161 | + } | |
| 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; | |
| 1177 | + } | |
| 1178 | + } | |
| 1179 | + return 0; | |
| 1180 | + } | |
| 1181 | + | |
| 1182 | + private static JSONObject syntheticWidget(String name, String label) { | |
| 1183 | + JSONObject w = new JSONObject(); | |
| 1184 | + w.put("name", name); | |
| 1185 | + w.put("label", label); | |
| 1186 | + return w; | |
| 1187 | + } | |
| 1188 | + | |
| 1189 | + 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++) { | |
| 1192 | + JSONObject row = rows.getJSONObject(i); | |
| 1193 | + 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); | |
| 1198 | + } | |
| 1199 | + return map; | |
| 1200 | + } | |
| 1201 | + | |
| 451 | 1202 | /** 场景2:命中供应商集合(SI数量/问题数量合计>60% 且 合计>=5)。 */ |
| 452 | 1203 | private Set<String> warningSuppliers2(JdyRiskProperties.Scenario s, JSONArray data) { |
| 453 | 1204 | Map<String, double[]> byGroup = new LinkedHashMap<>(); |
| ... | ... | @@ -479,14 +1230,17 @@ public class JdyRiskStatisticsService { |
| 479 | 1230 | private List<String> buildExtraValues(JdyRiskProperties.Scenario s, JSONArray data) { |
| 480 | 1231 | String type = s.getType() == null ? "" : s.getType().toLowerCase(); |
| 481 | 1232 | Set<String> warnGroups = null; |
| 1233 | + Map<String, Double> ratio2 = null; | |
| 482 | 1234 | if ("scenario2".equals(type)) { |
| 483 | - warnGroups = warningSuppliers2(s, data); | |
| 1235 | + ratio2 = supplierRatio2(s, data); | |
| 1236 | + warnGroups = ratio2.keySet(); | |
| 484 | 1237 | } else if ("scenario4".equals(type) || "scenario5".equals(type)) { |
| 485 | 1238 | warnGroups = warningGroupsByUp(s, data); |
| 486 | 1239 | } else if ("scenario6".equals(type)) { |
| 487 | 1240 | warnGroups = warningGroupsByCount(s, data); |
| 488 | 1241 | } else if ("scenario8".equals(type) || "scenario9".equals(type)) { |
| 489 | - warnGroups = warningGroupsByRatio(s, data); | |
| 1242 | + ratio2 = groupRatioByFlag(s, data); | |
| 1243 | + warnGroups = ratio2.keySet(); | |
| 490 | 1244 | } |
| 491 | 1245 | List<String> values = new ArrayList<>(); |
| 492 | 1246 | for (int i = 0; i < data.size(); i++) { |
| ... | ... | @@ -496,6 +1250,9 @@ public class JdyRiskStatisticsService { |
| 496 | 1250 | v = rowHitScenario1(s, row) ? displayName(s, row) : ""; |
| 497 | 1251 | } else if ("scenario3".equals(type)) { |
| 498 | 1252 | v = rowHitScenario3(s, row) ? displayName(s, row) : ""; |
| 1253 | + } 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) + ")" : ""; | |
| 499 | 1256 | } else if (warnGroups != null) { |
| 500 | 1257 | String g = orEmpty(row.getString(s.getGroupField())); |
| 501 | 1258 | v = warnGroups.contains(g) ? displayName(s, row) : ""; |
| ... | ... | @@ -505,14 +1262,165 @@ public class JdyRiskStatisticsService { |
| 505 | 1262 | return values; |
| 506 | 1263 | } |
| 507 | 1264 | |
| 1265 | + /** 场景2:命中供应商 -> SI占比。 */ | |
| 1266 | + 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++) { | |
| 1269 | + 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 | + } | |
| 1284 | + } | |
| 1285 | + return out; | |
| 1286 | + } | |
| 1287 | + | |
| 1288 | + /** 场景8/9:命中分组 -> 未开CR占比。 */ | |
| 1289 | + 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++) { | |
| 1292 | + JSONObject row = data.getJSONObject(i); | |
| 1293 | + String g = orEmpty(row.getString(s.getGroupField())); | |
| 1294 | + 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 | + } | |
| 1299 | + } | |
| 1300 | + Map<String, Double> out = new LinkedHashMap<>(); | |
| 1301 | + 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 | + } | |
| 1307 | + } | |
| 1308 | + return out; | |
| 1309 | + } | |
| 1310 | + | |
| 508 | 1311 | private String displayName(JdyRiskProperties.Scenario s, JSONObject row) { |
| 1312 | + Object v; | |
| 509 | 1313 | if (s.getExtraField() != null && !s.getExtraField().isEmpty()) { |
| 510 | - return orEmpty(row.getString(s.getExtraField())); | |
| 1314 | + v = row.get(s.getExtraField()); | |
| 1315 | + } else if (s.getGroupField() != null && !s.getGroupField().isEmpty()) { | |
| 1316 | + v = row.get(s.getGroupField()); | |
| 1317 | + } else { | |
| 1318 | + return "命中"; | |
| 511 | 1319 | } |
| 512 | - if (s.getGroupField() != null && !s.getGroupField().isEmpty()) { | |
| 513 | - return orEmpty(row.getString(s.getGroupField())); | |
| 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 | + } | |
| 1325 | + } | |
| 1326 | + return toDisplayName(v); | |
| 1327 | + } | |
| 1328 | + | |
| 1329 | + /** 构建关联表 id->名称 映射(用于把关联字段的 id 显示成中文名)。 */ | |
| 1330 | + 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()) { | |
| 1334 | + return map; | |
| 1335 | + } | |
| 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()); | |
| 1348 | + return map; | |
| 1349 | + } | |
| 1350 | + | |
| 1351 | + /** 按指定字段的显示名升序排序(就地)。 */ | |
| 1352 | + private static void sortRows(JSONArray rows, String field) { | |
| 1353 | + List<JSONObject> list = new ArrayList<>(); | |
| 1354 | + for (int i = 0; i < rows.size(); i++) { | |
| 1355 | + list.add(rows.getJSONObject(i)); | |
| 1356 | + } | |
| 1357 | + list.sort((a, b) -> toDisplayName(a.get(field)).compareTo(toDisplayName(b.get(field)))); | |
| 1358 | + rows.clear(); | |
| 1359 | + for (JSONObject o : list) { | |
| 1360 | + rows.add(o); | |
| 514 | 1361 | } |
| 515 | - return "命中"; | |
| 1362 | + } | |
| 1363 | + | |
| 1364 | + /** 取值转显示名:对象取 dataTitle/name,数组连接,其余转字符串。 */ private static String toDisplayName(Object v) { | |
| 1365 | + if (v == null) { | |
| 1366 | + return ""; | |
| 1367 | + } | |
| 1368 | + if (v instanceof JSONObject) { | |
| 1369 | + JSONObject o = (JSONObject) v; | |
| 1370 | + String n = o.getString("dataTitle"); | |
| 1371 | + if (n == null || n.isEmpty()) { | |
| 1372 | + n = o.getString("name"); | |
| 1373 | + } | |
| 1374 | + return n == null ? "" : n; | |
| 1375 | + } | |
| 1376 | + if (v instanceof JSONArray) { | |
| 1377 | + JSONArray arr = (JSONArray) v; | |
| 1378 | + 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 | + } | |
| 1384 | + if (sb.length() > 0) { | |
| 1385 | + sb.append(","); | |
| 1386 | + } | |
| 1387 | + sb.append(n); | |
| 1388 | + } | |
| 1389 | + return sb.toString(); | |
| 1390 | + } | |
| 1391 | + String s = String.valueOf(v); | |
| 1392 | + return "null".equals(s) ? "" : s; | |
| 1393 | + } | |
| 1394 | + | |
| 1395 | + /** 仅保留「命中/预警」的行(用于 Excel)。 */ | |
| 1396 | + private JSONArray filterWarnRows(JdyRiskProperties.Scenario s, JSONArray rows) { | |
| 1397 | + String type = s.getType() == null ? "" : s.getType().toLowerCase(); | |
| 1398 | + Set<String> warnGroups = null; | |
| 1399 | + if ("scenario2".equals(type)) { | |
| 1400 | + warnGroups = warningSuppliers2(s, rows); | |
| 1401 | + } else if ("scenario4".equals(type) || "scenario5".equals(type)) { | |
| 1402 | + warnGroups = warningGroupsByUp(s, rows); | |
| 1403 | + } else if ("scenario8".equals(type) || "scenario9".equals(type)) { | |
| 1404 | + warnGroups = warningGroupsByRatio(s, rows); | |
| 1405 | + } | |
| 1406 | + JSONArray out = new JSONArray(); | |
| 1407 | + for (int i = 0; i < rows.size(); i++) { | |
| 1408 | + 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 | + } | |
| 1422 | + } | |
| 1423 | + return out; | |
| 516 | 1424 | } |
| 517 | 1425 | |
| 518 | 1426 | private boolean rowHitScenario1(JdyRiskProperties.Scenario s, JSONObject row) { |
| ... | ... | @@ -546,6 +1454,135 @@ public class JdyRiskStatisticsService { |
| 546 | 1454 | |
| 547 | 1455 | /* ==================== 工具 ==================== */ |
| 548 | 1456 | |
| 1457 | + /** 找「同一 syncCode 且 预警日期(时间字段)为当天」的记录;无则返回 null。 */ | |
| 1458 | + private JSONObject findTodayRecord(JSONArray records, String syncCode, String timeField) { | |
| 1459 | + if (records == null || syncCode == null || timeField == null || timeField.isEmpty()) { | |
| 1460 | + return null; | |
| 1461 | + } | |
| 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 | + } | |
| 1468 | + Long t = r.getLong(timeField); | |
| 1469 | + if (t != null && Instant.ofEpochMilli(t).atZone(ZONE).format(DAY_FMT).equals(today)) { | |
| 1470 | + return r; | |
| 1471 | + } | |
| 1472 | + } | |
| 1473 | + return null; | |
| 1474 | + } | |
| 1475 | + | |
| 1476 | + /** 构造附件关联对象。 */ | |
| 1477 | + private JSONObject buildAttach(String fileId, String fileName, long size) { | |
| 1478 | + 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); | |
| 1486 | + return rel; | |
| 1487 | + } | |
| 1488 | + | |
| 1489 | + /** | |
| 1490 | + * 写入预警时间字段,并同步写入预警年份字段(time-field-2,如 dgqshv)。 | |
| 1491 | + * <p>dgqshv 为 QxDate(format=YYYY),取其=预警时间同一时刻,显示年份即预警时间所在年份。</p> | |
| 1492 | + */ | |
| 1493 | + private static void setTimeFields(JSONObject rec, JdyRiskProperties.Qx qx, long now) { | |
| 1494 | + if (qx.getTimeField() != null && !qx.getTimeField().isEmpty()) { | |
| 1495 | + rec.put(qx.getTimeField(), now); | |
| 1496 | + } | |
| 1497 | + if (qx.getTimeField2() != null && !qx.getTimeField2().isEmpty()) { | |
| 1498 | + rec.put(qx.getTimeField2(), now); | |
| 1499 | + } | |
| 1500 | + } | |
| 1501 | + | |
| 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) { | |
| 1509 | + 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); | |
| 1520 | + String af = qx.getAttachField(); | |
| 1521 | + if (af != null && !af.isEmpty()) { | |
| 1522 | + if (skipAttach || fileId == null) { | |
| 1523 | + body.remove(af); | |
| 1524 | + body.remove(af + "Id"); | |
| 1525 | + } else { | |
| 1526 | + body.put(af, buildAttach(fileId, fileName, size)); | |
| 1527 | + body.put(af + "Id", fileId); | |
| 1528 | + } | |
| 1529 | + } | |
| 1530 | + return body; | |
| 1531 | + } | |
| 1532 | + | |
| 1533 | + /** 组装新增请求体:固定业务数据 + 计数 + 附件 + 预警时间 + 同步编号。 */ | |
| 1534 | + private JSONObject buildAddBody(Biz biz, JdyRiskProperties.Qx qx, String syncCode, | |
| 1535 | + long count, long now, String fileId, String fileName, long size) { | |
| 1536 | + JSONObject unit = new JSONObject(); | |
| 1537 | + unit.put("dataTitle", biz.unitTitle); | |
| 1538 | + unit.put("id", biz.unitId); | |
| 1539 | + JSONObject leader = new JSONObject(); | |
| 1540 | + leader.put("dataTitle", biz.leaderTitle); | |
| 1541 | + leader.put("id", biz.leaderId); | |
| 1542 | + 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); | |
| 1549 | + if (biz.sceneMemberId != null) { | |
| 1550 | + JSONObject member = new JSONObject(); | |
| 1551 | + member.put("dataTitle", biz.sceneMemberTitle); | |
| 1552 | + member.put("id", biz.sceneMemberId); | |
| 1553 | + scene.put("jiaplm", member); | |
| 1554 | + } | |
| 1555 | + | |
| 1556 | + 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); | |
| 1569 | + if (biz.jetcalId != null) { | |
| 1570 | + 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); | |
| 1575 | + } | |
| 1576 | + if (biz.zawlah != null) { | |
| 1577 | + body.put("zawlah", biz.zawlah); | |
| 1578 | + } | |
| 1579 | + 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); | |
| 1582 | + } | |
| 1583 | + return body; | |
| 1584 | + } | |
| 1585 | + | |
| 549 | 1586 | /** 在启效记录中按 syncCode 匹配(重复时取第一条并告警)。 */ |
| 550 | 1587 | private JSONObject findRecordBySyncCode(JSONArray records, String syncCode) { |
| 551 | 1588 | if (records == null || syncCode == null || syncCode.isEmpty()) { | ... | ... |
| 1 | 1 | package com.qgutech.qgyun.apaas.sync.jdy.task; |
| 2 | 2 | |
| 3 | +import com.qgutech.qgyun.apaas.sync.jdy.config.JdyRiskProperties; | |
| 3 | 4 | import com.qgutech.qgyun.apaas.sync.jdy.config.JdySyncProperties; |
| 5 | +import com.qgutech.qgyun.apaas.sync.jdy.service.JdyRiskStatisticsService; | |
| 4 | 6 | import com.qgutech.qgyun.apaas.sync.jdy.service.JdyToQxSyncService; |
| 5 | 7 | import lombok.extern.slf4j.Slf4j; |
| 6 | 8 | import org.springframework.scheduling.annotation.Scheduled; |
| ... | ... | @@ -10,7 +12,8 @@ import javax.annotation.Resource; |
| 10 | 12 | import java.util.List; |
| 11 | 13 | |
| 12 | 14 | /** |
| 13 | - * 简道云 -> 启效 每日定时同步任务。 | |
| 15 | + * 简道云 -> 启效 定时同步任务。 | |
| 16 | + * <p>含:每日表单同步、设备域场景12(每月1号)/场景13(每月10号)风险统计回写。</p> | |
| 14 | 17 | */ |
| 15 | 18 | @Slf4j |
| 16 | 19 | @Component |
| ... | ... | @@ -22,6 +25,12 @@ public class JdySyncScheduledTask { |
| 22 | 25 | @Resource |
| 23 | 26 | private JdySyncProperties props; |
| 24 | 27 | |
| 28 | + @Resource | |
| 29 | + private JdyRiskStatisticsService riskService; | |
| 30 | + | |
| 31 | + @Resource | |
| 32 | + private JdyRiskProperties riskProps; | |
| 33 | + | |
| 25 | 34 | @Scheduled(cron = "${jdy-sync.cron:0 0 2 * * ?}") |
| 26 | 35 | public void dailySync() { |
| 27 | 36 | if (!props.isEnabled()) { |
| ... | ... | @@ -32,4 +41,108 @@ public class JdySyncScheduledTask { |
| 32 | 41 | List<String> result = syncService.syncAll(); |
| 33 | 42 | result.forEach(r -> log.info("同步结果: {}", r)); |
| 34 | 43 | } |
| 44 | + | |
| 45 | + /** 设备域场景12(SYNC0034):每月1号抓取当年数据。 */ | |
| 46 | + @Scheduled(cron = "${jdy-risk.schedule.s12-cron:0 0 3 1 * ?}") | |
| 47 | + public void monthlySyncS12() { | |
| 48 | + if (!riskProps.getSchedule().isEnabled()) { | |
| 49 | + log.info("jdy-risk.schedule.enabled=false,跳过场景12定时抓取"); | |
| 50 | + return; | |
| 51 | + } | |
| 52 | + log.info("========== 定时抓取 设备域场景12(SYNC0034) =========="); | |
| 53 | + log.info("场景12结果: {}", riskService.countAndSyncOne("SYNC0034")); | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** 设备域场景13(SYNC0042):每月10号抓取上月数据。 */ | |
| 57 | + @Scheduled(cron = "${jdy-risk.schedule.s13-cron:0 0 3 10 * ?}") | |
| 58 | + public void monthlySyncS13() { | |
| 59 | + if (!riskProps.getSchedule().isEnabled()) { | |
| 60 | + log.info("jdy-risk.schedule.enabled=false,跳过场景13定时抓取"); | |
| 61 | + return; | |
| 62 | + } | |
| 63 | + log.info("========== 定时抓取 设备域场景13(SYNC0042) =========="); | |
| 64 | + log.info("场景13结果: {}", riskService.countAndSyncOne("SYNC0042")); | |
| 65 | + } | |
| 66 | + | |
| 67 | + /** 设备域场景14(SYNC0048):每年12月20日抓取当年数据。 */ | |
| 68 | + @Scheduled(cron = "${jdy-risk.schedule.s14-cron:0 0 3 20 12 ?}") | |
| 69 | + public void yearlySyncS14() { | |
| 70 | + run("场景14", "SYNC0048"); | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** 设备域场景15(SYNC0044):每月1号抓取上月数据。 */ | |
| 74 | + @Scheduled(cron = "${jdy-risk.schedule.s15-cron:0 0 3 1 * ?}") | |
| 75 | + public void monthlySyncS15() { | |
| 76 | + run("场景15", "SYNC0044"); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** 设备域场景16(SYNC0045):每月最后一天23点抓取当月数据(每天23点触发,月末才执行)。 */ | |
| 80 | + @Scheduled(cron = "${jdy-risk.schedule.s16-cron:0 0 23 * * ?}") | |
| 81 | + public void monthlySyncS16() { | |
| 82 | + if (!isLastDayOfMonth()) { | |
| 83 | + log.info("非月末,跳过场景16定时抓取"); | |
| 84 | + return; | |
| 85 | + } | |
| 86 | + run("场景16", "SYNC0045"); | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** 设备域场景17(SYNC0046):每月1号抓取上月数据(以更新日期)。 */ | |
| 90 | + @Scheduled(cron = "${jdy-risk.schedule.s17-cron:0 0 3 1 * ?}") | |
| 91 | + public void monthlySyncS17() { | |
| 92 | + run("场景17", "SYNC0046"); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** 设备域场景18(SYNC0047):每月最后一天23点抓取当月数据(每天23点触发,月末才执行)。 */ | |
| 96 | + @Scheduled(cron = "${jdy-risk.schedule.s18-cron:0 0 23 * * ?}") | |
| 97 | + public void monthlySyncS18() { | |
| 98 | + if (!isLastDayOfMonth()) { | |
| 99 | + log.info("非月末,跳过场景18定时抓取"); | |
| 100 | + return; | |
| 101 | + } | |
| 102 | + run("场景18", "SYNC0047"); | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** 设备域场景19(SYNC0043):每月1号1点抓取上月数据。 */ | |
| 106 | + @Scheduled(cron = "${jdy-risk.schedule.s19-cron:0 0 1 1 * ?}") | |
| 107 | + public void monthlySyncS19() { | |
| 108 | + run("场景19", "SYNC0043"); | |
| 109 | + } | |
| 110 | + | |
| 111 | + /** 管理域场景23(SYNC0013 CS95 油耗):每月1号1点抓上月数据。 */ | |
| 112 | + @Scheduled(cron = "${jdy-risk.schedule.s23-cron:0 0 1 1 * ?}") | |
| 113 | + public void monthlySyncS23() { | |
| 114 | + run("场景23", "SYNC0013"); | |
| 115 | + } | |
| 116 | + | |
| 117 | + /** 管理域场景24(SYNC0014 CS75 油耗):每月1号1点抓上月数据。 */ | |
| 118 | + @Scheduled(cron = "${jdy-risk.schedule.s24-cron:0 0 1 1 * ?}") | |
| 119 | + public void monthlySyncS24() { | |
| 120 | + run("场景24", "SYNC0014"); | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** 管理域场景25(SYNC0015 全顺 油耗):每月1号1点抓上月数据。 */ | |
| 124 | + @Scheduled(cron = "${jdy-risk.schedule.s25-cron:0 0 1 1 * ?}") | |
| 125 | + public void monthlySyncS25() { | |
| 126 | + run("场景25", "SYNC0015"); | |
| 127 | + } | |
| 128 | + | |
| 129 | + /** 场景26(SYNC0016 劳务公司评价):每月1号1点抓本月前三个月数据。 */ | |
| 130 | + @Scheduled(cron = "${jdy-risk.schedule.s26-cron:0 0 1 1 * ?}") | |
| 131 | + public void monthlySyncS26() { | |
| 132 | + run("场景26", "SYNC0016"); | |
| 133 | + } | |
| 134 | + | |
| 135 | + private static boolean isLastDayOfMonth() { | |
| 136 | + java.time.LocalDate now = java.time.LocalDate.now(java.time.ZoneId.of("Asia/Shanghai")); | |
| 137 | + return now.getDayOfMonth() == now.lengthOfMonth(); | |
| 138 | + } | |
| 139 | + | |
| 140 | + private void run(String label, String syncCode) { | |
| 141 | + if (!riskProps.getSchedule().isEnabled()) { | |
| 142 | + log.info("jdy-risk.schedule.enabled=false,跳过{}定时抓取", label); | |
| 143 | + return; | |
| 144 | + } | |
| 145 | + log.info("========== 定时抓取 设备域{}({}) ==========", label, syncCode); | |
| 146 | + log.info("{}结果: {}", label, riskService.countAndSyncOne(syncCode)); | |
| 147 | + } | |
| 35 | 148 | } | ... | ... |