Pārlūkot izejas kodu

MySQL锁等待超时

chenshudong 2 nedēļas atpakaļ
vecāks
revīzija
e5bd299a7f

+ 41 - 50
airport-ledger/src/main/java/com/sundot/airport/ledger/service/impl/LedgerSyncServiceImpl.java

@@ -2,6 +2,7 @@ package com.sundot.airport.ledger.service.impl;
2 2
 
3 3
 import cn.hutool.core.util.StrUtil;
4 4
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
5
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
5 6
 import com.sundot.airport.common.core.domain.entity.SysDept;
6 7
 import com.sundot.airport.common.core.domain.entity.SysUser;
7 8
 import com.sundot.airport.common.enums.LedgerSyncFlagEnum;
@@ -192,6 +193,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
192 193
         ScoreIndicator lv2 = getIndicator(IND_SUPERVISION_L2);
193 194
         int ins = 0, skip = 0;
194 195
         for (LedgerSupervisionProblem row : list) {
196
+            LambdaUpdateWrapper<LedgerSupervisionProblem> uw = new LambdaUpdateWrapper<>();
197
+            uw.eq(LedgerSupervisionProblem::getId, row.getId())
198
+                    .set(LedgerSupervisionProblem::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
199
+            supervisionMapper.update(null, uw);
195 200
             String src = "supervision_problem:" + row.getId();
196 201
             if (existsBySrc(src)) { skip++; continue; }
197 202
             if (!hasName(row.getInspectedName())) { skip++; continue; }
@@ -211,11 +216,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
211 216
             scoreEventMapper.insert(e);
212 217
             ins++;
213 218
         }
214
-        // 分批更新 sync_flag,避免锁等待超时
215
-        int updatedRows;
216
-        do {
217
-            updatedRows = supervisionMapper.updateSyncFlag();
218
-        } while (updatedRows > 0);
219 219
         return new SyncResult(ins, skip, "");
220 220
     }
221 221
 
@@ -228,6 +228,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
228 228
         ScoreIndicator lv2 = getIndicator(IND_INTERCEPT_L2);
229 229
         int ins = 0, skip = 0;
230 230
         for (LedgerRealtimeInterception row : list) {
231
+            LambdaUpdateWrapper<LedgerRealtimeInterception> uw = new LambdaUpdateWrapper<>();
232
+            uw.eq(LedgerRealtimeInterception::getId, row.getId())
233
+                    .set(LedgerRealtimeInterception::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
234
+            interceptionMapper.update(null, uw);
231 235
             String src = "realtime_interception:" + row.getId();
232 236
             if (existsBySrc(src)) { skip++; continue; }
233 237
             if (!hasName(row.getInspectorName())) { skip++; continue; }
@@ -253,11 +257,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
253 257
             scoreEventMapper.insert(e);
254 258
             ins++;
255 259
         }
256
-        // 分批更新 sync_flag,避免锁等待超时
257
-        int updatedRows;
258
-        do {
259
-            updatedRows = interceptionMapper.updateSyncFlag();
260
-        } while (updatedRows > 0);
261 260
         return new SyncResult(ins, skip, "");
262 261
     }
263 262
 
@@ -270,6 +269,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
270 269
         ScoreIndicator lv2 = getIndicator(IND_SECTEST_L2);
271 270
         int ins = 0, skip = 0;
272 271
         for (LedgerSecurityTest row : list) {
272
+            LambdaUpdateWrapper<LedgerSecurityTest> uw = new LambdaUpdateWrapper<>();
273
+            uw.eq(LedgerSecurityTest::getId, row.getId())
274
+                    .set(LedgerSecurityTest::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
275
+            securityTestMapper.update(null, uw);
273 276
             String src = "security_test:" + row.getId();
274 277
             if (existsBySrc(src)) { skip++; continue; }
275 278
             if (!"未通过".equals(row.getTestResult())) { skip++; continue; }
@@ -289,11 +292,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
289 292
             scoreEventMapper.insert(e);
290 293
             ins++;
291 294
         }
292
-        // 分批更新 sync_flag,避免锁等待超时
293
-        int updatedRows;
294
-        do {
295
-            updatedRows = securityTestMapper.updateSyncFlag();
296
-        } while (updatedRows > 0);
297 295
         return new SyncResult(ins, skip, "");
298 296
     }
299 297
 
@@ -306,6 +304,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
306 304
         ScoreIndicator lv2 = getIndicator(IND_UNSAFE_L2);
307 305
         int ins = 0, skip = 0;
308 306
         for (LedgerUnsafeEvent row : list) {
307
+            LambdaUpdateWrapper<LedgerUnsafeEvent> uw = new LambdaUpdateWrapper<>();
308
+            uw.eq(LedgerUnsafeEvent::getId, row.getId())
309
+                    .set(LedgerUnsafeEvent::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
310
+            unsafeEventMapper.update(null, uw);
309 311
             String src = "unsafe_event:" + row.getId();
310 312
             if (existsBySrc(src)) { skip++; continue; }
311 313
             if (!hasName(row.getResponsibleName())) { skip++; continue; }
@@ -325,11 +327,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
325 327
             scoreEventMapper.insert(e);
326 328
             ins++;
327 329
         }
328
-        // 分批更新 sync_flag,避免锁等待超时
329
-        int updatedRows;
330
-        do {
331
-            updatedRows = unsafeEventMapper.updateSyncFlag();
332
-        } while (updatedRows > 0);
333 330
         return new SyncResult(ins, skip, "");
334 331
     }
335 332
 
@@ -342,6 +339,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
342 339
         ScoreIndicator lv2 = getIndicator(IND_SEIZURE_L2);
343 340
         int ins = 0, skip = 0;
344 341
         for (LedgerSeizureStats row : list) {
342
+            LambdaUpdateWrapper<LedgerSeizureStats> uw = new LambdaUpdateWrapper<>();
343
+            uw.eq(LedgerSeizureStats::getId, row.getId())
344
+                    .set(LedgerSeizureStats::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
345
+            seizureMapper.update(null, uw);
345 346
             String src = "seizure_stats:" + row.getId();
346 347
             if (existsBySrc(src)) { skip++; continue; }
347 348
             if (!hasName(row.getInspectorName())) { skip++; continue; }
@@ -358,11 +359,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
358 359
             scoreEventMapper.insert(e);
359 360
             ins++;
360 361
         }
361
-        // 分批更新 sync_flag,避免锁等待超时
362
-        int updatedRows;
363
-        do {
364
-            updatedRows = seizureMapper.updateSyncFlag();
365
-        } while (updatedRows > 0);
366 362
         return new SyncResult(ins, skip, "");
367 363
     }
368 364
 
@@ -379,6 +375,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
379 375
         ScoreIndicator lv2 = getIndicator(IND_SEIZURE_L2);
380 376
         int ins = 0, skip = 0;
381 377
         for (LedgerRewardApproval row : list) {
378
+            LambdaUpdateWrapper<LedgerRewardApproval> uw = new LambdaUpdateWrapper<>();
379
+            uw.eq(LedgerRewardApproval::getId, row.getId())
380
+                    .set(LedgerRewardApproval::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
381
+            rewardApprovalMapper.update(null, uw);
382 382
             String src = "reward_approval:" + row.getId();
383 383
             if (existsBySrc(src)) { skip++; continue; }
384 384
             if (!hasName(row.getPersonName())) { skip++; continue; }
@@ -395,11 +395,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
395 395
             scoreEventMapper.insert(e);
396 396
             ins++;
397 397
         }
398
-        // 分批更新 sync_flag,避免锁等待超时
399
-        int updatedRows;
400
-        do {
401
-            updatedRows = rewardApprovalMapper.updateSyncFlag();
402
-        } while (updatedRows > 0);
403 398
         return new SyncResult(ins, skip, "");
404 399
     }
405 400
 
@@ -412,6 +407,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
412 407
         ScoreIndicator lv2 = getIndicator(IND_SVCPATROL_L2);
413 408
         int ins = 0, skip = 0;
414 409
         for (LedgerServicePatrol row : list) {
410
+            LambdaUpdateWrapper<LedgerServicePatrol> uw = new LambdaUpdateWrapper<>();
411
+            uw.eq(LedgerServicePatrol::getId, row.getId())
412
+                    .set(LedgerServicePatrol::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
413
+            servicePatrolMapper.update(null, uw);
415 414
             String src = "service_patrol:" + row.getId();
416 415
             if (existsBySrc(src)) { skip++; continue; }
417 416
             if (!hasName(row.getInspectedName())) { skip++; continue; }
@@ -430,11 +429,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
430 429
             scoreEventMapper.insert(e);
431 430
             ins++;
432 431
         }
433
-        // 分批更新 sync_flag,避免锁等待超时
434
-        int updatedRows;
435
-        do {
436
-            updatedRows = servicePatrolMapper.updateSyncFlag();
437
-        } while (updatedRows > 0);
438 432
         return new SyncResult(ins, skip, "");
439 433
     }
440 434
 
@@ -447,6 +441,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
447 441
         ScoreIndicator lv2 = getIndicator(IND_COMPLAINT_L2);
448 442
         int ins = 0, skip = 0;
449 443
         for (LedgerComplaint row : list) {
444
+            LambdaUpdateWrapper<LedgerComplaint> uw = new LambdaUpdateWrapper<>();
445
+            uw.eq(LedgerComplaint::getId, row.getId())
446
+                    .set(LedgerComplaint::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
447
+            complaintMapper.update(null, uw);
450 448
             String src = "complaint:" + row.getId();
451 449
             if (existsBySrc(src)) { skip++; continue; }
452 450
             if (!hasName(row.getResponsibleName())) { skip++; continue; }
@@ -458,11 +456,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
458 456
             scoreEventMapper.insert(e);
459 457
             ins++;
460 458
         }
461
-        // 分批更新 sync_flag,避免锁等待超时
462
-        int updatedRows;
463
-        do {
464
-            updatedRows = complaintMapper.updateSyncFlag();
465
-        } while (updatedRows > 0);
466 459
         return new SyncResult(ins, skip, "");
467 460
     }
468 461
 
@@ -476,6 +469,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
476 469
         ScoreIndicator lv3 = getIndicator(IND_TYPCASE_L3);
477 470
         int ins = 0, skip = 0;
478 471
         for (LedgerTerminalBonus row : list) {
472
+            LambdaUpdateWrapper<LedgerTerminalBonus> uw = new LambdaUpdateWrapper<>();
473
+            uw.eq(LedgerTerminalBonus::getId, row.getId())
474
+                    .set(LedgerTerminalBonus::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
475
+            terminalBonusMapper.update(null, uw);
479 476
             String src = "terminal_bonus:" + row.getId();
480 477
             if (existsBySrc(src)) { skip++; continue; }
481 478
             if (!hasName(row.getPersonName())) { skip++; continue; }
@@ -487,11 +484,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
487 484
             scoreEventMapper.insert(e);
488 485
             ins++;
489 486
         }
490
-        // 分批更新 sync_flag,避免锁等待超时
491
-        int updatedRows;
492
-        do {
493
-            updatedRows = terminalBonusMapper.updateSyncFlag();
494
-        } while (updatedRows > 0);
495 487
         return new SyncResult(ins, skip, "");
496 488
     }
497 489
 
@@ -504,6 +496,10 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
504 496
         ScoreIndicator lv2 = getIndicator(IND_EXAM_L2);
505 497
         int ins = 0, skip = 0;
506 498
         for (LedgerExamScore row : list) {
499
+            LambdaUpdateWrapper<LedgerExamScore> uw = new LambdaUpdateWrapper<>();
500
+            uw.eq(LedgerExamScore::getId, row.getId())
501
+                    .set(LedgerExamScore::getSyncFlag, LedgerSyncFlagEnum.ONE.getCode());
502
+            examScoreMapper.update(null, uw);
507 503
             String src = "exam_score:" + row.getId();
508 504
             if (existsBySrc(src)) { skip++; continue; }
509 505
             if (!hasName(row.getPersonName())) { skip++; continue; }
@@ -523,11 +519,6 @@ public class LedgerSyncServiceImpl implements ILedgerSyncService {
523 519
             scoreEventMapper.insert(e);
524 520
             ins++;
525 521
         }
526
-        // 分批更新 sync_flag,避免锁等待超时
527
-        int updatedRows;
528
-        do {
529
-            updatedRows = examScoreMapper.updateSyncFlag();
530
-        } while (updatedRows > 0);
531 522
         return new SyncResult(ins, skip, "");
532 523
     }
533 524
 

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerComplaintMapper.xml

@@ -60,6 +60,5 @@
60 60
         update ledger_complaint
61 61
         set sync_flag = '1'
62 62
         where sync_flag = '0'
63
-        limit 1000
64 63
     </update>
65 64
 </mapper>

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerExamScoreMapper.xml

@@ -52,6 +52,5 @@
52 52
         update ledger_exam_score
53 53
         set sync_flag = '1'
54 54
         where sync_flag = '0'
55
-        limit 1000
56 55
     </update>
57 56
 </mapper>

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerRealtimeInterceptionMapper.xml

@@ -66,7 +66,6 @@
66 66
         update ledger_realtime_interception
67 67
         set sync_flag = '1'
68 68
         where sync_flag = '0'
69
-        limit 1000
70 69
     </update>
71 70
 
72 71
     <select id="realtimeInterceptionItem"

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerRewardApprovalMapper.xml

@@ -56,6 +56,5 @@
56 56
         update ledger_reward_approval
57 57
         set sync_flag = '1'
58 58
         where sync_flag = '0'
59
-        limit 1000
60 59
     </update>
61 60
 </mapper>

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerSecurityTestMapper.xml

@@ -69,7 +69,6 @@
69 69
         update ledger_security_test
70 70
         set sync_flag = '1'
71 71
         where sync_flag = '0'
72
-        limit 1000
73 72
     </update>
74 73
 
75 74
     <select id="securityTestItemClassification"

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerSeizureStatsMapper.xml

@@ -80,7 +80,6 @@
80 80
         update ledger_seizure_stats
81 81
         set sync_flag = '1'
82 82
         where sync_flag = '0'
83
-        limit 1000
84 83
     </update>
85 84
 
86 85
     <select id="countByInspectorAndDateRange" resultType="int">

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerServicePatrolMapper.xml

@@ -70,6 +70,5 @@
70 70
         update ledger_service_patrol
71 71
         set sync_flag = '1'
72 72
         where sync_flag = '0'
73
-        limit 1000
74 73
     </update>
75 74
 </mapper>

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerSupervisionProblemMapper.xml

@@ -72,7 +72,6 @@
72 72
         update ledger_supervision_problem
73 73
         set sync_flag = '1'
74 74
         where sync_flag = '0'
75
-        limit 1000
76 75
     </update>
77 76
 
78 77
     <select id="supervisionProblemPosition"

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerTerminalBonusMapper.xml

@@ -54,6 +54,5 @@
54 54
         update ledger_terminal_bonus
55 55
         set sync_flag = '1'
56 56
         where sync_flag = '0'
57
-        limit 1000
58 57
     </update>
59 58
 </mapper>

+ 0 - 1
airport-ledger/src/main/resources/mapper/ledger/LedgerUnsafeEventMapper.xml

@@ -63,7 +63,6 @@
63 63
         update ledger_unsafe_event
64 64
         set sync_flag = '1'
65 65
         where sync_flag = '0'
66
-        limit 1000
67 66
     </update>
68 67
 
69 68
     <select id="countSeizureStatsItem" parameterType="com.sundot.airport.ledger.domain.vo.CountQueryReqVO" resultType="com.sundot.airport.ledger.domain.vo.UnsafeItemVO">