deason 1 year ago
parent
commit
0f2a14cb0e

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

@@ -2,11 +2,15 @@ package com.qmth.exam.reserve.cache.impl;
 
 import com.qmth.exam.reserve.cache.CacheConstants;
 import com.qmth.exam.reserve.cache.RedisClient;
+import com.qmth.exam.reserve.service.ExamSiteService;
+import com.qmth.exam.reserve.service.StudentApplyService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.concurrent.TimeUnit;
+
 @Component
 public class ApplyTaskCacheService implements CacheConstants {
 
@@ -15,6 +19,12 @@ public class ApplyTaskCacheService implements CacheConstants {
     @Autowired
     private RedisClient redisClient;
 
+    @Autowired
+    private ExamSiteService examSiteService;
+
+    @Autowired
+    private StudentApplyService studentApplyService;
+
     /**
      * 获取某考点某时段的“可预约总量”
      */
@@ -24,22 +34,35 @@ public class ApplyTaskCacheService implements CacheConstants {
         if (value != null) {
             return value;
         }
-        // todo
-        return 1;
+
+        // 当前考点当前时段容量 = 当前考点总容量
+        value = examSiteService.countExamSiteCapacityById(examSiteId);
+        redisClient.set(cacheKey, value, 1, TimeUnit.DAYS);
+
+        return value;
     }
 
     /**
      * 获取某考点某时段的“已预约数量”
      */
     public int getApplyFinishCount(Long examSiteId, Long timePeriodId) {
-        return 0;
+        String cacheKey = String.format(CACHE_APPLY_FINISH, examSiteId, timePeriodId);
+        Integer value = redisClient.get(cacheKey, Integer.class);
+        if (value != null) {
+            return value;
+        }
+
+        value = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriodId);
+        redisClient.set(cacheKey, value, 1, TimeUnit.DAYS);
+
+        return value;
     }
 
     /**
      * 累加 某考点某时段的“已预约数量”
      */
     public void increaseApplyFinishCount(Long examSiteId, Long timePeriodId) {
-
+        // redisClient.getRedissonClient().getAtomicLong(cacheKey);
     }
 
     /**

+ 3 - 0
src/main/java/com/qmth/exam/reserve/dao/ExamSiteDao.java

@@ -2,7 +2,10 @@ package com.qmth.exam.reserve.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.qmth.exam.reserve.entity.ExamSiteEntity;
+import org.apache.ibatis.annotations.Param;
 
 public interface ExamSiteDao extends BaseMapper<ExamSiteEntity> {
 
+    Integer countExamSiteCapacityById(@Param("examSiteId") Long examSiteId);
+
 }

+ 7 - 6
src/main/java/com/qmth/exam/reserve/dao/StudentApplyDao.java

@@ -1,9 +1,5 @@
 package com.qmth.exam.reserve.dao;
 
-import java.util.List;
-
-import org.apache.ibatis.annotations.Param;
-
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -12,20 +8,25 @@ import com.qmth.exam.reserve.bean.apply.TicketInfo;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyReq;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyVO;
 import com.qmth.exam.reserve.entity.StudentApplyEntity;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 public interface StudentApplyDao extends BaseMapper<StudentApplyEntity> {
 
     IPage<StudentApplyVO> page(Page<StudentApplyVO> page, @Param(value = "req") StudentApplyReq req);
 
     Integer getHaveApplyCount(@Param(value = "examSiteIds") List<Long> examSiteIds,
-            @Param(value = "cancel") Boolean cancel);
+                              @Param(value = "cancel") Boolean cancel);
 
     List<ApplyVO> getStudentApplyList(@Param("studentId") Long studentId, @Param("cancel") Boolean cancel);
 
+    Integer countApplyFinishForExamSiteAndTimePeriod(@Param("examSiteId") Long examSiteId, @Param("timePeriodId") Long timePeriodId);
+
     TicketInfo getStudentApplyTicket(@Param("applyId") Long applyId);
 
     List<StudentApplyEntity> listTimePeriod(@Param(value = "timePeriodIds") List<Long> timePeriodIds,
-            @Param(value = "cancel") Boolean cancel);
+                                            @Param(value = "cancel") Boolean cancel);
 
     List<StudentApplyVO> listStudentApply(@Param("timePeriodId") Long timePeriodId, @Param("roomId") Long roomId);
 

+ 2 - 0
src/main/java/com/qmth/exam/reserve/service/ExamSiteService.java

@@ -13,4 +13,6 @@ public interface ExamSiteService extends IService<ExamSiteEntity> {
 
     List<ExamSiteInfo> getExamSiteListForStudent(Long categoryId);
 
+    int countExamSiteCapacityById(Long examSiteId);
+
 }

+ 2 - 0
src/main/java/com/qmth/exam/reserve/service/StudentApplyService.java

@@ -26,4 +26,6 @@ public interface StudentApplyService extends IService<StudentApplyEntity> {
 
     File downloadSignIn(Long teachingId, Long agentId);
 
+    int countApplyFinishForExamSiteAndTimePeriod(Long examSiteId, Long timePeriodId);
+
 }

+ 10 - 0
src/main/java/com/qmth/exam/reserve/service/impl/ExamSiteServiceImpl.java

@@ -56,4 +56,14 @@ public class ExamSiteServiceImpl extends ServiceImpl<ExamSiteDao, ExamSiteEntity
         return list;
     }
 
+    /**
+     * 获取当前考点总容量
+     */
+    @Override
+    public int countExamSiteCapacityById(Long examSiteId) {
+        // 当前考点总容量 = ∑考场机房容量
+        Integer capacity = baseMapper.countExamSiteCapacityById(examSiteId);
+        return capacity != null ? capacity : 0;
+    }
+
 }

+ 9 - 0
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -808,4 +808,13 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return fileList;
     }
 
+    /**
+     * 获取某考点某时段的“已预约数量”
+     */
+    @Override
+    public int countApplyFinishForExamSiteAndTimePeriod(Long examSiteId, Long timePeriodId) {
+        Integer value = baseMapper.countApplyFinishForExamSiteAndTimePeriod(examSiteId,timePeriodId);
+        return value != null ? value : 0;
+    }
+
 }

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

@@ -2,4 +2,11 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.exam.reserve.dao.ExamSiteDao">
 
+    <select id="countExamSiteCapacityById" resultType="java.lang.Integer">
+        select sum(capacity)
+        from t_exam_room
+        where exam_site_id = #{examSiteId}
+          and enable = 1
+    </select>
+
 </mapper>

+ 8 - 0
src/main/resources/mapper/StudentApplyMapper.xml

@@ -46,6 +46,14 @@
         </foreach>
     </select>
 
+    <select id="countApplyFinishForExamSiteAndTimePeriod" resultType="java.lang.Integer">
+        select count(1)
+        from t_student_apply
+        where exam_site_id = #{examSiteId}
+          and time_period_id = #{timePeriodId}
+          and cancel = 0
+    </select>
+
     <select id="getStudentApplyList" resultType="com.qmth.exam.reserve.bean.apply.ApplyVO">
         select sa.id applyId,sa.cancel,sa.ticket_number,
         sa.time_period_id,tp.start_time timePeriodStart,tp.end_time timePeriodEnd,