Commit 900c8e20683f095413e3244216f233d3a68d964a
Merge branch 'minhang_2024_04' of http://61.169.120.202:8888/panzhaov5/bsth_cont…
…rol into minhang_2024_04
Showing
1 changed file
with
40 additions
and
33 deletions
src/main/java/com/bsth/service/schedule/impl/SchedulePlanServiceImpl.java
| @@ -88,43 +88,50 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im | @@ -88,43 +88,50 @@ public class SchedulePlanServiceImpl extends BServiceImpl<SchedulePlan, Long> im | ||
| 88 | @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | 88 | @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) |
| 89 | public SchedulePlan save(SchedulePlan schedulePlan) { | 89 | public SchedulePlan save(SchedulePlan schedulePlan) { |
| 90 | ReentrantLock lineXLatch = getLineXLatch(schedulePlan.getXl().getId()); | 90 | ReentrantLock lineXLatch = getLineXLatch(schedulePlan.getXl().getId()); |
| 91 | + | ||
| 91 | try { | 92 | try { |
| 92 | - if (lineXLatch.tryLock(1, TimeUnit.SECONDS)) { | ||
| 93 | - // pre、如果排班的数据之前已经有了,删除之前的数据 | ||
| 94 | - Date startPre = new Date(); | ||
| 95 | - scheduleRuleService.deleteSchedulePlanInfo( | ||
| 96 | - schedulePlan.getXl().getLineCode(), | ||
| 97 | - schedulePlan.getScheduleFromTime(), | ||
| 98 | - schedulePlan.getScheduleToTime()); | ||
| 99 | - Date endPre = new Date(); | ||
| 100 | - logger.info("删除数据 {} ms --->", endPre.getTime() - startPre.getTime()); | ||
| 101 | - | ||
| 102 | - // core、生成排班计划 | ||
| 103 | - DroolsSchedulePlan droolsSchedulePlan = new DroolsSchedulePlan( | ||
| 104 | - schedulePlan, | ||
| 105 | - lineRepository, scheduleRule1FlatRepository, | ||
| 106 | - ttInfoRepository, ttInfoDetailRepository, | ||
| 107 | - carConfigInfoRepository, employeeConfigInfoRepository, | ||
| 108 | - rerunRuleRepository, businessRepository, | ||
| 109 | - scheduleRuleService, | ||
| 110 | - preKBase, coreKBase, | ||
| 111 | - logger | ||
| 112 | - ); | ||
| 113 | - droolsSchedulePlan.generatePlan(); | ||
| 114 | - | ||
| 115 | - return new SchedulePlan(); | ||
| 116 | - } else { | ||
| 117 | - throw new ScheduleException("当前线路正在排班,请稍后再操作..."); | ||
| 118 | - } | ||
| 119 | - } catch (Exception exp) { | ||
| 120 | - throw new RuntimeException(exp); | ||
| 121 | - } finally { | ||
| 122 | - try { | ||
| 123 | - lineXLatch.unlock(); | ||
| 124 | - } catch (Exception exp2) { | 93 | + if (lineXLatch.tryLock(10, TimeUnit.SECONDS)) { |
| 94 | + try { | ||
| 95 | + // pre、如果排班的数据之前已经有了,删除之前的数据 | ||
| 96 | + Date startPre = new Date(); | ||
| 97 | + scheduleRuleService.deleteSchedulePlanInfo( | ||
| 98 | + schedulePlan.getXl().getLineCode(), | ||
| 99 | + schedulePlan.getScheduleFromTime(), | ||
| 100 | + schedulePlan.getScheduleToTime()); | ||
| 101 | + Date endPre = new Date(); | ||
| 102 | + logger.info("删除数据 {} ms --->", endPre.getTime() - startPre.getTime()); | ||
| 103 | + | ||
| 104 | + // core、生成排班计划 | ||
| 105 | + DroolsSchedulePlan droolsSchedulePlan = new DroolsSchedulePlan( | ||
| 106 | + schedulePlan, | ||
| 107 | + lineRepository, scheduleRule1FlatRepository, | ||
| 108 | + ttInfoRepository, ttInfoDetailRepository, | ||
| 109 | + carConfigInfoRepository, employeeConfigInfoRepository, | ||
| 110 | + rerunRuleRepository, businessRepository, | ||
| 111 | + scheduleRuleService, | ||
| 112 | + preKBase, coreKBase, | ||
| 113 | + logger | ||
| 114 | + ); | ||
| 115 | + droolsSchedulePlan.generatePlan(); | ||
| 116 | + | ||
| 117 | + return new SchedulePlan(); | ||
| 118 | + | ||
| 119 | + } catch (Exception exp) { | ||
| 120 | + throw new RuntimeException(exp); | ||
| 121 | + | ||
| 122 | + } finally { | ||
| 123 | + lineXLatch.unlock(); | ||
| 124 | + } | ||
| 125 | 125 | ||
| 126 | + } else { | ||
| 127 | + throw new RuntimeException("当前线路[" + schedulePlan.getXl().getName() + "]正在排班,请稍后再操作..."); | ||
| 126 | } | 128 | } |
| 129 | + } catch (InterruptedException exp) { | ||
| 130 | + // 如果线程在等待期间被中断 | ||
| 131 | + System.err.println(Thread.currentThread().getName() + " 在等待锁时被中断。"); | ||
| 132 | + Thread.currentThread().interrupt(); // 重新中断线程 | ||
| 127 | 133 | ||
| 134 | + throw new RuntimeException(exp); | ||
| 128 | } | 135 | } |
| 129 | 136 | ||
| 130 | } | 137 | } |