haogh 3 hete
szülő
commit
e573527862

+ 0 - 5
src/main/java/com/qmth/exam/reserve/cache/CacheConstants.java

@@ -102,9 +102,4 @@ public interface CacheConstants {
      */
     String LOCK_ARRANGE_EXAM = "arrange_exam:%s";
 
-    /**
-     * 考点容量变更操作锁
-     * $lock:lock_exam_site_change_capacity:{examSiteId}
-     */
-    String LOCK_EXAM_SITE_CHANGE_CAPACITY = "exam_site_change_capacity:%s";
 }

+ 6 - 6
src/main/java/com/qmth/exam/reserve/cache/impl/ApplyTaskCacheService.java

@@ -234,13 +234,13 @@ public class ApplyTaskCacheService implements CacheConstants {
      * 刷新 某考点某时段的“剩余可约数量”缓存
      */
     public void refreshApplyAvailableCountCache(Long examSiteId, Long timePeriodId, int oldCapacity, int newCapacity) {
-        String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examSiteId);
-        Lock lock = concurrentService.getLock(lockKey);
+       /* String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examSiteId);
+        Lock lock = concurrentService.getLock(lockKey);*/
 
-        try {
+        /*try {
             if (!lock.tryLock()) {
                 throw new RuntimeException("获取锁失败,不允许同时操作!" + lockKey);
-            }
+            }*/
 
             // 新、旧考点容量差额
             int diffCapacity = newCapacity - oldCapacity;
@@ -266,13 +266,13 @@ public class ApplyTaskCacheService implements CacheConstants {
                 log.warn("缓存不存在,初始考点时段剩余可约数量:{} oldCapacity:{} newCapacity:{} finishCount:{} {}",
                         newAvailableCount, oldCapacity, newCapacity, finishCount, cacheKey);
             }
-        } finally {
+      /*  } finally {
             try {
                 lock.unlock();
             } catch (Exception e) {
                 log.warn("解锁失败!lockKey:{} err:{}", lockKey, e.getMessage());
             }
-        }
+        }*/
     }
 
     /**

+ 3 - 19
src/main/java/com/qmth/exam/reserve/service/impl/ExamRoomServiceImpl.java

@@ -94,14 +94,9 @@ public class ExamRoomServiceImpl extends ServiceImpl<ExamRoomDao, ExamRoomEntity
             log.warn("[考场保存]系统自动预约中,不允许修改考场!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
             throw new StatusException("系统正在自动预约中,不允许修改考场");
         }
-        String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, req.getExamSiteId());
-        if (concurrentService.isLocked(lockKey)) {
-            log.warn("[考场保存]考点剩余可约数量更新中,不允许操作修改!lockKey:{}", lockKey);
-            throw new StatusException("系统正在更新可预约数量,请稍后重试");
-        }
 
         //考点容量变更锁
-        String examSiteLockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CHANGE_CAPACITY, req.getExamSiteId());
+        String examSiteLockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, req.getExamSiteId());
         RLock examSiteLock = (RLock) concurrentService.getLock(examSiteLockKey);
 
         try {
@@ -285,14 +280,9 @@ public class ExamRoomServiceImpl extends ServiceImpl<ExamRoomDao, ExamRoomEntity
             throw new StatusException("系统正在自动预约中,不允许启用/禁用考场");
         }
         ExamRoomEntity examRoom = getById(id);
-        String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examRoom.getExamSiteId());
-        if (concurrentService.isLocked(lockKey)) {
-            log.warn("[考场保存]考点剩余可约数量更新中,不允许启用/禁用考场!lockKey:{}", lockKey);
-            throw new StatusException("系统正在更新可预约数量,不允许启用/禁用考场");
-        }
 
         //考点容量变更锁
-        String examSiteLockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CHANGE_CAPACITY, examRoom.getExamSiteId());
+        String examSiteLockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examRoom.getExamSiteId());
         RLock examSiteLock = (RLock) concurrentService.getLock(examSiteLockKey);
 
         try {
@@ -464,14 +454,8 @@ public class ExamRoomServiceImpl extends ServiceImpl<ExamRoomDao, ExamRoomEntity
     }
 
     private void saveRoom(ExamRoomEntity room) {
-        String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, room.getExamSiteId());
-        if (concurrentService.isLocked(lockKey)) {
-            log.warn("[考场导入]考点剩余可约数量更新中,不允许导入考场!lockKey:{}", lockKey);
-            throw new StatusException("系统正在更新可预约数量,不允许导入考场");
-        }
-
         //考点容量变更锁
-        String examSiteLockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CHANGE_CAPACITY, room.getExamSiteId());
+        String examSiteLockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, room.getExamSiteId());
         RLock examSiteLock = (RLock) concurrentService.getLock(examSiteLockKey);
 
         try {

+ 14 - 11
src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamRoomServiceImpl.java

@@ -238,14 +238,14 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
             throw new StatusException("保存失败,未找到考点");
         }
 
-        String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examRoom.getExamSiteId());
+        /*String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examRoom.getExamSiteId());
         if (concurrentService.isLocked(lockKey)) {
             log.warn("[考场排班设置]考点剩余可约数量更新中,不允许操作修改!lockKey:{}", lockKey);
             throw new StatusException("系统正在更新可预约数量,不允许保存");
-        }
+        }*/
 
         //考点容量变更锁
-        String examSiteLockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CHANGE_CAPACITY, examRoom.getExamSiteId());
+        String examSiteLockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examRoom.getExamSiteId());
         RLock examSiteLock = (RLock) concurrentService.getLock(examSiteLockKey);
 
         try {
@@ -343,7 +343,7 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
                         // 关闭之后的剩余容量
                         int remainCount = oldCount - examRoom.getCapacity();
 
-                        log.warn("haveApplyCount:{}, remainCount:{}", haveApplyCount, remainCount);
+                        log.warn("availableCount:{}, oldCount:{}, haveApplyCount:{}, remainCount:{}", availableCount, oldCount, haveApplyCount, remainCount);
 
                         if (haveApplyCount > remainCount) {
                             TimePeriodEntity timePeriod = timePeriodService.getById(toUpdate.getTimePeriodId());
@@ -382,14 +382,17 @@ public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoo
                     int oldCapacity = oldCapacityMap.getOrDefault(timePeriodId, 0);
                     int newCapacity = examSiteService.getExamSiteTimePeriodCapacity(examSiteCacheBean.getExamSiteId(), timePeriodId);
 
-                    log.warn("[考场排班设置] 刷新缓存,timePeriodId:{},oldCapacity:{},newCapacity:{}", timePeriodId, oldCapacity, newCapacity);
 
-                    applyTaskCacheService.refreshApplyAvailableCountCache(
-                            examRoom.getExamSiteId(),
-                            timePeriodId,
-                            oldCapacity,
-                            newCapacity
-                    );
+                    if(oldCapacity != newCapacity) {
+                        log.warn("[考场排班设置] 刷新缓存,timePeriodId:{},oldCapacity:{},newCapacity:{}", timePeriodId, oldCapacity, newCapacity);
+                        applyTaskCacheService.refreshApplyAvailableCountCache(
+                                examRoom.getExamSiteId(),
+                                timePeriodId,
+                                oldCapacity,
+                                newCapacity
+                        );
+                    }
+
                 }
             }
         } catch (Exception e) {

+ 1 - 0
src/main/resources/mapper/ExamSiteMapper.xml

@@ -61,6 +61,7 @@
         WHERE er.ENABLE = 1
           AND er.exam_site_id = #{examSiteId}
           AND (tper.id IS NULL OR tper.ENABLE = 1)
+        for update
     </select>
 
     <update id="updateExamSiteCapacity">