Procházet zdrojové kódy

考场预约设置

haogh před 2 měsíci
rodič
revize
047ff4fd2f
19 změnil soubory, kde provedl 657 přidání a 49 odebrání
  1. 15 46
      install/mysql/upgrade/update.sql
  2. 5 0
      src/main/java/com/qmth/exam/reserve/bean/Constants.java
  3. 3 0
      src/main/java/com/qmth/exam/reserve/bean/timeperiod/TimePeriodExamSiteBean.java
  4. 3 0
      src/main/java/com/qmth/exam/reserve/bean/timeperiod/TimePeriodExamSiteInfo.java
  5. 46 0
      src/main/java/com/qmth/exam/reserve/controller/admin/TimePeriodExamRoomController.java
  6. 16 0
      src/main/java/com/qmth/exam/reserve/controller/admin/TimePeriodExamSiteController.java
  7. 2 0
      src/main/java/com/qmth/exam/reserve/dao/TimePeriodDao.java
  8. 8 0
      src/main/java/com/qmth/exam/reserve/dao/TimePeriodExamRoomDao.java
  9. 34 0
      src/main/java/com/qmth/exam/reserve/entity/TimePeriodExamRoomEntity.java
  10. 3 1
      src/main/java/com/qmth/exam/reserve/enums/EventType.java
  11. 1 0
      src/main/java/com/qmth/exam/reserve/service/SystemPropertyService.java
  12. 16 0
      src/main/java/com/qmth/exam/reserve/service/TimePeriodExamRoomService.java
  13. 2 0
      src/main/java/com/qmth/exam/reserve/service/TimePeriodService.java
  14. 5 0
      src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java
  15. 65 0
      src/main/java/com/qmth/exam/reserve/service/impl/SystemPropertyServiceImpl.java
  16. 373 0
      src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamRoomServiceImpl.java
  17. 35 2
      src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamSiteServiceImpl.java
  18. 5 0
      src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodServiceImpl.java
  19. 20 0
      src/main/resources/mapper/TimePeriodMapper.xml

+ 15 - 46
install/mysql/upgrade/update.sql

@@ -1,49 +1,18 @@
-ALTER TABLE t_category
-    ADD COLUMN self_apply_enable bit(1) NULL DEFAULT 1 COMMENT '针对教学点,是否开启考生自主预约';
+-- v1.0.2 sql更新
 
 
-CREATE TABLE t_async_task
-(
-    id               bigint       NOT NULL AUTO_INCREMENT,
-    create_time      bigint       NOT NULL COMMENT '创建时间',
-    update_time      bigint       NOT NULL COMMENT '更新时间',
-    operate_id       bigint       NOT NULL COMMENT '操作人ID',
-    type             varchar(50)  NOT NULL COMMENT '任务类型',
-    status           varchar(10)  NOT NULL COMMENT '执行状态任务状态,INIT:未开始,RUNNING:进行中,FINISH:已完成',
-    result           varchar(10)  NULL COMMENT '执行结果,SUCCESS:成功,ERROR:失败',
-    import_file_name varchar(100) NULL COMMENT '导入文件名称',
-    import_file_path varchar(500) NULL COMMENT '导入文件路径',
-    export_file_path varchar(500) NULL COMMENT '导出文件路径',
-    summary          text         NULL COMMENT '执行摘要',
-    PRIMARY KEY (id),
-    INDEX IDX_01 (type),
-    INDEX IDX_02 (status),
-    INDEX IDX_03 (result)
-) COMMENT = '异步任务表';
-
-CREATE TABLE t_student_course
-(
-    id          bigint      NOT NULL AUTO_INCREMENT,
-    create_time bigint      NOT NULL COMMENT '创建时间',
-    update_time bigint      NOT NULL COMMENT '更新时间',
-    student_id  bigint      NOT NULL COMMENT '考生ID',
-    course_code varchar(20) NOT NULL COMMENT '科目代码',
-    course_name varchar(50) NULL COMMENT '科目名称',
-    PRIMARY KEY (id),
-    UNIQUE INDEX IDX_01 (course_code, student_id),
-    INDEX IDX_02 (student_id)
-) COMMENT = '考生科目表';
+insert into t_system_property(org_id, prop_key, prop_value, create_time, update_time)
+values (1, 'APPLY_SWITCH', '1', unix_timestamp() * 1000, unix_timestamp() * 1000);
 
 
-CREATE TABLE t_time_period_exam_site
+CREATE TABLE `t_time_period_exam_room`
 (
 (
-    id             bigint NOT NULL AUTO_INCREMENT,
-    create_time    bigint NOT NULL COMMENT '创建时间',
-    update_time    bigint NOT NULL COMMENT '更新时间',
-    operate_id     bigint NOT NULL COMMENT '操作人',
-    exam_site_id   bigint NOT NULL COMMENT '考点ID',
-    time_period_id bigint NOT NULL COMMENT '预约时段ID',
-    enable         bit(1) NOT NULL COMMENT '是否开启',
-    PRIMARY KEY (id),
-    UNIQUE INDEX IDX_01 (exam_site_id, time_period_id),
-    INDEX IDX_02 (time_period_id)
-) COMMENT = '考点预约时段表';
-
+    `id`             bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
+    `create_time`    bigint NOT NULL COMMENT '创建时间',
+    `update_time`    bigint NOT NULL COMMENT '更新时间',
+    `exam_room_id`   bigint NOT NULL COMMENT '考场ID',
+    `time_period_id` bigint NOT NULL COMMENT '预约时段ID',
+    `enable`         bit(1) NULL DEFAULT NULL COMMENT '是否开启',
+    `operate_id`     bigint NULL DEFAULT NULL COMMENT '操作人',
+    PRIMARY KEY (`id`) USING BTREE,
+    UNIQUE INDEX `IDX_01` (`exam_room_id`, `time_period_id`) USING BTREE,
+    INDEX `IDX_02` (`exam_room_id`) USING BTREE
+) COMMENT = '考场开启时段表';

+ 5 - 0
src/main/java/com/qmth/exam/reserve/bean/Constants.java

@@ -54,4 +54,9 @@ public interface Constants {
      */
      */
     long FILE_SIZE_LIMIT = 500 * 1024;
     long FILE_SIZE_LIMIT = 500 * 1024;
 
 
+    /**
+     * 预约开关
+     */
+    String APPLY_SWITCH = "APPLY_SWITCH";
+
 }
 }

+ 3 - 0
src/main/java/com/qmth/exam/reserve/bean/timeperiod/TimePeriodExamSiteBean.java

@@ -31,6 +31,9 @@ public class TimePeriodExamSiteBean implements IModel {
     @ApiModelProperty("考点ID")
     @ApiModelProperty("考点ID")
     private Long examSiteId;
     private Long examSiteId;
 
 
+    @ApiModelProperty("考场ID")
+    private Long examRoomId;
+
     @Override
     @Override
     public boolean equals(Object o) {
     public boolean equals(Object o) {
         if (this == o)
         if (this == o)

+ 3 - 0
src/main/java/com/qmth/exam/reserve/bean/timeperiod/TimePeriodExamSiteInfo.java

@@ -22,4 +22,7 @@ public class TimePeriodExamSiteInfo implements IModel {
 
 
     @ApiModelProperty("是否开启")
     @ApiModelProperty("是否开启")
     private Boolean enable;
     private Boolean enable;
+
+    @ApiModelProperty("是否可编辑")
+    private Boolean editable;
 }
 }

+ 46 - 0
src/main/java/com/qmth/exam/reserve/controller/admin/TimePeriodExamRoomController.java

@@ -0,0 +1,46 @@
+package com.qmth.exam.reserve.controller.admin;
+
+import com.qmth.boot.api.annotation.Aac;
+import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.exam.reserve.bean.login.LoginUser;
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
+import com.qmth.exam.reserve.controller.BaseController;
+import com.qmth.exam.reserve.service.TimePeriodExamRoomService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RestController
+@Api(tags = "【管理端】考场预约设置相关接口")
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/admin/time/period/exam/room")
+@Aac(strict = false, auth = true)
+public class TimePeriodExamRoomController extends BaseController {
+
+    @Autowired
+    private TimePeriodExamRoomService timePeriodExamRoomService;
+
+
+    @ApiOperation(value = "日期时段列表")
+    @PostMapping(value = "/detail/list")
+    public List<TimePeriodExamSiteVo> ListDetail(@ApiParam("考场ID") @RequestParam(required = false) Long examRoomId) {
+        if(examRoomId == null) {
+            return new ArrayList<>();
+        }
+        LoginUser loginUser = curLoginUser();
+        return timePeriodExamRoomService.ListDetail(loginUser, examRoomId);
+    }
+
+    @ApiOperation(value = "考场预约时段编辑")
+    @PostMapping(value = "/save")
+    public void save(@ApiParam("考点ID") @RequestParam(required = true) Long examRoomId, @RequestBody List<TimePeriodExamSiteReq> timePeriodExamRoomList) {
+        LoginUser loginUser = this.curLoginUser();
+        timePeriodExamRoomService.save(loginUser.getId(), examRoomId, timePeriodExamRoomList);
+    }
+
+}

+ 16 - 0
src/main/java/com/qmth/exam/reserve/controller/admin/TimePeriodExamSiteController.java

@@ -2,10 +2,13 @@ package com.qmth.exam.reserve.controller.admin;
 
 
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.boot.core.exception.StatusException;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
 import com.qmth.exam.reserve.controller.BaseController;
 import com.qmth.exam.reserve.controller.BaseController;
+import com.qmth.exam.reserve.enums.Role;
+import com.qmth.exam.reserve.service.SystemPropertyService;
 import com.qmth.exam.reserve.service.TimePeriodExamSiteService;
 import com.qmth.exam.reserve.service.TimePeriodExamSiteService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
@@ -26,6 +29,9 @@ public class TimePeriodExamSiteController extends BaseController {
     @Autowired
     @Autowired
     private TimePeriodExamSiteService timePeriodExamSiteService;
     private TimePeriodExamSiteService timePeriodExamSiteService;
 
 
+    @Autowired
+    private SystemPropertyService systemPropertyService;
+
     @ApiOperation(value = "时段区间列表")
     @ApiOperation(value = "时段区间列表")
     @PostMapping(value = "/list")
     @PostMapping(value = "/list")
     public List<String> list(@ApiParam("预约任务ID") @RequestParam(required = false) Long taskId) {
     public List<String> list(@ApiParam("预约任务ID") @RequestParam(required = false) Long taskId) {
@@ -47,4 +53,14 @@ public class TimePeriodExamSiteController extends BaseController {
         LoginUser loginUser = this.curLoginUser();
         LoginUser loginUser = this.curLoginUser();
         timePeriodExamSiteService.save(loginUser.getId(), examSiteId, timePeriodExamSiteList);
         timePeriodExamSiteService.save(loginUser.getId(), examSiteId, timePeriodExamSiteList);
     }
     }
+
+    @ApiOperation(value = "自主预约统一控制")
+    @PostMapping(value = "/switch/enable")
+    public void enableSwitch(@ApiParam("开关状态") @RequestParam Boolean status) {
+        LoginUser loginUser = this.curLoginUser();
+        if (!loginUser.getRole().equals(Role.ADMIN)) {
+            throw new StatusException("无权限");
+        }
+        systemPropertyService.enableSwitch(loginUser.getId(), status);
+    }
 }
 }

+ 2 - 0
src/main/java/com/qmth/exam/reserve/dao/TimePeriodDao.java

@@ -16,4 +16,6 @@ public interface TimePeriodDao extends BaseMapper<TimePeriodEntity> {
     List<TimePeriodExamSiteBean> listTimePeriodByExamSiteId(@Param("taskId") Long taskId, @Param("examSiteId") Long examSiteId);
     List<TimePeriodExamSiteBean> listTimePeriodByExamSiteId(@Param("taskId") Long taskId, @Param("examSiteId") Long examSiteId);
 
 
     List<TimePeriodExamSiteBean> listTimePeriodByTask(@Param("taskId") Long taskId);
     List<TimePeriodExamSiteBean> listTimePeriodByTask(@Param("taskId") Long taskId);
+
+    List<TimePeriodExamSiteBean> listTimePeriodByExamRoomId(@Param("taskId") Long taskId, @Param("examRoomId") Long examRoomId);
 }
 }

+ 8 - 0
src/main/java/com/qmth/exam/reserve/dao/TimePeriodExamRoomDao.java

@@ -0,0 +1,8 @@
+package com.qmth.exam.reserve.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.exam.reserve.entity.TimePeriodExamRoomEntity;
+
+public interface TimePeriodExamRoomDao extends BaseMapper<TimePeriodExamRoomEntity> {
+
+}

+ 34 - 0
src/main/java/com/qmth/exam/reserve/entity/TimePeriodExamRoomEntity.java

@@ -0,0 +1,34 @@
+package com.qmth.exam.reserve.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.qmth.exam.reserve.entity.base.BaseEntity;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+@TableName("t_time_period_exam_room")
+public class TimePeriodExamRoomEntity extends BaseEntity {
+
+    private static final long serialVersionUID = 3582968112249023750L;
+
+    /**
+     * 考场ID
+     */
+    private Long examRoomId;
+
+    /**
+     * 预约时段ID
+     */
+    private Long timePeriodId;
+
+    /**
+     * 是否开启
+     */
+    private Boolean enable;
+
+    /**
+     * 操作人ID
+     */
+    private Long operateId;
+}

+ 3 - 1
src/main/java/com/qmth/exam/reserve/enums/EventType.java

@@ -19,7 +19,9 @@ public enum EventType {
 
 
     MODIFY_APPLY_NUMBER("修改预约次数"),
     MODIFY_APPLY_NUMBER("修改预约次数"),
 
 
-    DELETE_STUDENT("删除考生");
+    DELETE_STUDENT("删除考生"),
+
+    APPLY_SWITCH("预约开关控制");
 
 
     private String name;
     private String name;
 
 

+ 1 - 0
src/main/java/com/qmth/exam/reserve/service/SystemPropertyService.java

@@ -7,4 +7,5 @@ public interface SystemPropertyService extends IService<SystemPropertyEntity> {
 
 
     SystemPropertyEntity findByPropKey(Long orgId, String propKey);
     SystemPropertyEntity findByPropKey(Long orgId, String propKey);
 
 
+    void enableSwitch(Long userId, Boolean status);
 }
 }

+ 16 - 0
src/main/java/com/qmth/exam/reserve/service/TimePeriodExamRoomService.java

@@ -0,0 +1,16 @@
+package com.qmth.exam.reserve.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.exam.reserve.bean.login.LoginUser;
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
+import com.qmth.exam.reserve.entity.TimePeriodExamRoomEntity;
+
+import java.util.List;
+
+public interface TimePeriodExamRoomService extends IService<TimePeriodExamRoomEntity> {
+
+    List<TimePeriodExamSiteVo> ListDetail(LoginUser loginUser, Long examRoomId);
+
+    void save(Long userId, Long examRoomId, List<TimePeriodExamSiteReq> timePeriodExamSiteList);
+}

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

@@ -18,4 +18,6 @@ public interface TimePeriodService extends IService<TimePeriodEntity> {
     List<TimePeriodExamSiteBean> listTimePeriodByExamSiteId(Long taskId, Long examSiteId);
     List<TimePeriodExamSiteBean> listTimePeriodByExamSiteId(Long taskId, Long examSiteId);
 
 
     List<TimePeriodExamSiteBean> listTimePeriodByTask(Long taskId);
     List<TimePeriodExamSiteBean> listTimePeriodByTask(Long taskId);
+
+    List<TimePeriodExamSiteBean> listTimePeriodByExamRoomId(Long taskId, Long examRoomId);
 }
 }

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

@@ -455,6 +455,11 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 if(apply.getAgentTimeList() == null || apply.getAgentTimeList().isEmpty()) {
                 if(apply.getAgentTimeList() == null || apply.getAgentTimeList().isEmpty()) {
                     apply.setAgentTimeList(agentTimeList);
                     apply.setAgentTimeList(agentTimeList);
                     applyList.add(apply);
                     applyList.add(apply);
+
+                    //导入预考模版中填满的情况 如果有错误,加入到错误记录中(bug解决)
+                    if(msg.length() > 0) {
+                        failRecords.add(newError(i + 1, msg.toString()));
+                    }
                 }
                 }
 
 
 
 

+ 65 - 0
src/main/java/com/qmth/exam/reserve/service/impl/SystemPropertyServiceImpl.java

@@ -2,11 +2,18 @@ package com.qmth.exam.reserve.service.impl;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.Constants;
+import com.qmth.exam.reserve.bean.org.OrgInfo;
+import com.qmth.exam.reserve.cache.impl.OrgCacheService;
 import com.qmth.exam.reserve.dao.SystemPropertyDao;
 import com.qmth.exam.reserve.dao.SystemPropertyDao;
 import com.qmth.exam.reserve.entity.SystemPropertyEntity;
 import com.qmth.exam.reserve.entity.SystemPropertyEntity;
+import com.qmth.exam.reserve.enums.EventType;
+import com.qmth.exam.reserve.service.OperateLogService;
 import com.qmth.exam.reserve.service.SystemPropertyService;
 import com.qmth.exam.reserve.service.SystemPropertyService;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 @Service
 @Service
@@ -14,6 +21,12 @@ public class SystemPropertyServiceImpl extends ServiceImpl<SystemPropertyDao, Sy
 
 
     private static final Logger log = LoggerFactory.getLogger(SystemPropertyServiceImpl.class);
     private static final Logger log = LoggerFactory.getLogger(SystemPropertyServiceImpl.class);
 
 
+    @Autowired
+    private OrgCacheService orgCacheService;
+
+    @Autowired
+    private OperateLogService operateLogService;
+
     @Override
     @Override
     public SystemPropertyEntity findByPropKey(Long orgId, String propKey) {
     public SystemPropertyEntity findByPropKey(Long orgId, String propKey) {
         LambdaQueryWrapper<SystemPropertyEntity> wrapper = new LambdaQueryWrapper<>();
         LambdaQueryWrapper<SystemPropertyEntity> wrapper = new LambdaQueryWrapper<>();
@@ -24,4 +37,56 @@ public class SystemPropertyServiceImpl extends ServiceImpl<SystemPropertyDao, Sy
         return baseMapper.selectOne(wrapper);
         return baseMapper.selectOne(wrapper);
     }
     }
 
 
+    @Override
+    public void enableSwitch(Long userId, Boolean status) {
+        if (status == null) {
+            log.error("[enableSwitch] 参数不能为空");
+            throw new StatusException("参数不能为空");
+        }
+        // 获取当前机构信息
+        OrgInfo org = orgCacheService.currentOrg();
+        if (org == null) {
+            log.warn("[enableSwitch] 当前机构不存在");
+            throw new StatusException("当前机构不存在");
+        }
+
+        try {
+            // 更新或插入系统属性
+            updateOrInsertSystemProperty(org.getOrgId(), status);
+
+            // 记录操作日志
+            operateLogService.insertOperateLog(userId, EventType.APPLY_SWITCH, status ? "启用" : "禁用");
+        } catch (Exception e) {
+            log.error("[enableSwitch] 操作失败: orgId={}, propKey={}, status={}", org.getOrgId(), Constants.APPLY_SWITCH, status, e);
+            throw new RuntimeException("操作失败", e);
+        }
+    }
+
+    private void updateOrInsertSystemProperty(Long orgId, Boolean status) {
+        LambdaQueryWrapper<SystemPropertyEntity> lw = new LambdaQueryWrapper<>();
+        lw.eq(SystemPropertyEntity::getOrgId, orgId);
+        lw.eq(SystemPropertyEntity::getPropKey, Constants.APPLY_SWITCH);
+
+        SystemPropertyEntity systemProperty = baseMapper.selectOne(lw);
+
+        String targetValue = status ? "1" : "0";
+
+        if (systemProperty == null) {
+            // 插入新记录
+            SystemPropertyEntity entity = new SystemPropertyEntity();
+            entity.setOrgId(orgId);
+            entity.setPropKey(Constants.APPLY_SWITCH);
+            entity.setPropValue(targetValue);
+            baseMapper.insert(entity);
+        } else {
+            // 如果当前值与目标值不同,则更新
+            if (!systemProperty.getPropValue().equals(targetValue)) {
+                systemProperty.setPropValue(targetValue);
+                baseMapper.updateById(systemProperty);
+            }
+        }
+    }
+
+
+
 }
 }

+ 373 - 0
src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamRoomServiceImpl.java

@@ -0,0 +1,373 @@
+package com.qmth.exam.reserve.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
+import com.qmth.exam.reserve.bean.examsite.ExamSiteCacheBean;
+import com.qmth.exam.reserve.bean.login.LoginUser;
+import com.qmth.exam.reserve.bean.org.OrgInfo;
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteBean;
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteInfo;
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
+import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
+import com.qmth.exam.reserve.cache.impl.ExamSiteCacheService;
+import com.qmth.exam.reserve.cache.impl.OrgCacheService;
+import com.qmth.exam.reserve.dao.TimePeriodExamRoomDao;
+import com.qmth.exam.reserve.entity.ExamRoomEntity;
+import com.qmth.exam.reserve.entity.TimePeriodEntity;
+import com.qmth.exam.reserve.entity.TimePeriodExamRoomEntity;
+import com.qmth.exam.reserve.enums.Role;
+import com.qmth.exam.reserve.service.ExamRoomService;
+import com.qmth.exam.reserve.service.TimePeriodExamRoomService;
+import com.qmth.exam.reserve.service.TimePeriodService;
+import com.qmth.exam.reserve.util.DateUtil;
+import com.qmth.exam.reserve.util.UnionUtil;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Service
+public class TimePeriodExamRoomServiceImpl extends ServiceImpl<TimePeriodExamRoomDao, TimePeriodExamRoomEntity> implements TimePeriodExamRoomService {
+
+    private static final Logger log = LoggerFactory.getLogger(TimePeriodExamRoomServiceImpl.class);
+
+
+    @Autowired
+    private ApplyTaskCacheService applyTaskCacheService;
+
+    @Autowired
+    private OrgCacheService orgCacheService;
+
+    @Autowired
+    private TimePeriodService timePeriodService;
+
+    @Autowired
+    private ExamSiteCacheService examSiteCacheService;
+
+    @Autowired
+    private ExamRoomService examRoomService;
+
+
+    @Override
+    public List<TimePeriodExamSiteVo> ListDetail(LoginUser loginUser, Long examRoomId) {
+        //获取当前机构
+        OrgInfo org = orgCacheService.currentOrg();
+        if (org == null) {
+            log.warn("[考场排班设置列表]未找到当前机构");
+            return Collections.emptyList();
+        }
+
+        //判断考场是否存在
+        ExamRoomEntity examRoom = examRoomService.getById(examRoomId);
+        if (examRoom == null) {
+            log.warn("[考场排班设置列表]未找到考场:{}", examRoomId);
+            return Collections.emptyList();
+        }
+
+        //教学点管理员权限限制
+        ExamSiteCacheBean examSite = examSiteCacheService.getExamSiteById(examRoom.getExamSiteId());
+        if (examSite == null) {
+            log.warn("[考场排班设置列表]考场:{}未找到所属考点", examRoomId);
+            return Collections.emptyList();
+        }
+        if (loginUser.getRole().equals(Role.TEACHING) && !loginUser.getCategoryId().equals(examSite.getCategoryId())) {
+            return Collections.emptyList();
+        }
+
+        //获取当前任务
+        CurrentApplyTaskVO curApplyTask = applyTaskCacheService.currentApplyTask(org.getOrgId());
+        if (curApplyTask == null) {
+            log.warn("[考场排班设置列表]机构:{},当前未有启用的任务", org.getOrgId());
+            return Collections.emptyList();
+        }
+
+        // 所有的预约日期
+        List<String> dateList = timePeriodService.listTimePeriodDate(curApplyTask.getTaskId());
+        if (CollectionUtils.isEmpty(dateList)) {
+            log.warn("[考场排班设置列表]当前任务:{}未设置预约日期", curApplyTask.getTaskId());
+            return Collections.emptyList();
+        }
+
+        //教学点管理员设置的所有的考点时段
+        List<TimePeriodExamSiteBean> timePeriodExamRoomList = timePeriodService.listTimePeriodByExamRoomId(curApplyTask.getTaskId(), examRoomId);
+        //学校管理员设置的所有预约时段
+        List<TimePeriodExamSiteBean> timePeriodList = timePeriodService.listTimePeriodByTask(curApplyTask.getTaskId());
+        List<TimePeriodExamSiteBean> resultList;
+        if (CollectionUtils.isEmpty(timePeriodExamRoomList)) {
+            resultList = timePeriodList;
+        } else {
+            //取并集
+            resultList = UnionUtil.unionByAttribute(timePeriodExamRoomList, timePeriodList, TimePeriodExamSiteBean::getTimePeriodId);
+        }
+
+        //按日期封装
+        List<TimePeriodExamSiteVo> list = new ArrayList<>();
+        for (String date : dateList) {
+            TimePeriodExamSiteVo timePeriodVo = new TimePeriodExamSiteVo();
+            timePeriodVo.setDateStr(getDateStr(date));
+            timePeriodVo.setTimePeriodList(filterTimePeriod(date, resultList, curApplyTask.getAllowApplyCancelDays()));
+            list.add(timePeriodVo);
+        }
+        return list;
+    }
+
+    private String getDateStr(String date) {
+        if (StringUtils.isEmpty(date)) {
+            return "";
+        }
+        String[] dateArr = date.split("-");
+        if (dateArr.length != 3) {
+            return "";
+        }
+        return dateArr[1] + "月" + dateArr[2] + "日";
+    }
+
+
+    private List<TimePeriodExamSiteInfo> filterTimePeriod(String date, List<TimePeriodExamSiteBean> timePeriodList, Integer canCancelDay) {
+        // 参数校验
+        if (timePeriodList == null || date == null || canCancelDay == null || canCancelDay < 0) {
+            return new ArrayList<>();
+        }
+
+        List<TimePeriodExamSiteInfo> resultList = new ArrayList<>();
+
+        // 过滤符合条件的时间段
+        List<TimePeriodExamSiteBean> filteredTimePeriodList = timePeriodList.stream()
+                .filter(item -> DateUtil.getShortDateByLongTime(item.getStartTime()).equals(date))
+                .sorted(Comparator.comparing(TimePeriodExamSiteBean::getStartTime))
+                .collect(Collectors.toList());
+
+        // 计算可取消时间范围
+        Long longToday = DateUtil.getLongTimeByDate(DateUtil.formatShortSplitDateString(new Date()) + " 00:00:00");
+        Date today = new Date(longToday);
+        Date otherDay = DateUtil.addValues(today, Calendar.DAY_OF_MONTH, canCancelDay);
+        long longOtherDay = DateUtil.getLongTimeByDate(DateUtil.formatShortSplitDateString(otherDay) + " 23:59:59");
+
+        // 当前时间
+        long now = System.currentTimeMillis();
+
+        for (TimePeriodExamSiteBean time : filteredTimePeriodList) {
+            // 检查时间是否有效
+            if (time.getStartTime() == null || time.getEndTime() == null) {
+                continue; // 跳过无效时间段
+            }
+
+            TimePeriodExamSiteInfo bean = new TimePeriodExamSiteInfo();
+            bean.setId(time.getId());
+            bean.setTimePeriodId(time.getTimePeriodId());
+            bean.setEnable(time.getEnable());
+            bean.setTimePeriodStr(DateUtil.getStartToEndTime(time.getStartTime(), time.getEndTime()));
+
+            // 判断是否可编辑
+            boolean isEditable = isTimeEditable(now, time.getEndTime(), longOtherDay, time.getStartTime());
+            bean.setEditable(isEditable);
+
+            resultList.add(bean);
+        }
+
+        return resultList;
+    }
+
+    private boolean isTimeEditable(long now, long endTime, long longOtherDay, long startTime) {
+        return !(endTime < now || startTime < longOtherDay);
+    }
+
+    @Transactional(isolation = Isolation.READ_COMMITTED)
+    @Override
+    public void save(Long userId, Long examRoomId, List<TimePeriodExamSiteReq> timePeriodExamRoomList) {
+        if (CollectionUtils.isEmpty(timePeriodExamRoomList)) {
+            log.warn("[考场排班设置]时间段列表为空");
+            throw new StatusException("保存失败,时间段列表为空");
+        }
+
+        try {
+            // 获取当前机构
+            OrgInfo org = orgCacheService.currentOrg();
+            if (org == null) {
+                log.warn("[考场排班设置]未找到当前机构");
+                throw new StatusException("保存失败,未找到当前机构");
+            }
+
+            // 获取当前任务
+            CurrentApplyTaskVO curApplyTask = applyTaskCacheService.currentApplyTask(org.getOrgId());
+            if (curApplyTask == null) {
+                log.warn("[考场排班设置]机构:{},当前未有启用的任务", org.getOrgId());
+                throw new StatusException("保存失败,未有启用的任务");
+            }
+
+            // 校验考场信息
+            ExamRoomEntity examRoom = examRoomService.getById(examRoomId);
+            if (examRoom == null) {
+                log.warn("[考场排班设置]未找到考场:{}", examRoomId);
+                throw new StatusException("保存失败,未找到考场");
+            }
+            if (!examRoom.getEnable()) {
+                log.warn("[考场排班设置]考场已被禁用:{}", examRoomId);
+                throw new StatusException("保存失败,考场已被禁用");
+            }
+
+            // 校验考点信息
+            ExamSiteCacheBean examSiteCacheBean = examSiteCacheService.getExamSiteById(examRoom.getExamSiteId());
+            if (examSiteCacheBean == null) {
+                log.warn("[考场排班设置]未找到考点:{}", examRoom.getExamSiteId());
+                throw new StatusException("保存失败,未找到考点");
+            }
+
+            // 获取考场对应的所有时段
+            List<TimePeriodExamSiteBean> timePeriodList = timePeriodService.listTimePeriodByExamRoomId(curApplyTask.getTaskId(), examRoomId);
+
+            // 时段Map
+            Map<Long, TimePeriodExamSiteBean> timePeriodMap = timePeriodList.stream()
+                    .collect(Collectors.toMap(TimePeriodExamSiteBean::getId, tp -> tp));
+
+            List<TimePeriodExamRoomEntity> timePeriodExamRoomEntityList = new ArrayList<>(timePeriodExamRoomList.size());
+
+            if (CollectionUtils.isEmpty(timePeriodList)) {
+                //是否可编辑判断
+                List<Long> listTimePeriodIds = timePeriodExamRoomList.stream()
+                        .filter(item -> !item.getEnable())
+                        .map(TimePeriodExamSiteReq::getTimePeriodId)
+                        .collect(Collectors.toList());
+                canEdit(listTimePeriodIds, curApplyTask);
+                handleFirstTimeSave(userId, examRoomId, timePeriodExamRoomList, timePeriodExamRoomEntityList, examRoom);
+            } else {
+                handleUpdateOrSave(userId, examRoomId, timePeriodExamRoomList, timePeriodExamRoomEntityList, timePeriodMap, examRoom, curApplyTask);
+            }
+        } catch (Exception e) {
+            log.error("[考场排班设置]保存失败,原因:{}", e.getMessage(), e);
+            throw new StatusException(e.getMessage());
+        }
+    }
+
+    // 校验是否可编辑
+    private void canEdit(List<Long> timePeriodExamRoomList, CurrentApplyTaskVO curApplyTask) {
+        if (CollectionUtils.isNotEmpty(timePeriodExamRoomList)) {
+            Long longToday = DateUtil.getLongTimeByDate(DateUtil.formatShortSplitDateString(new Date()) + " 00:00:00");
+            Date today = new Date(longToday);
+            Date otherDay = DateUtil.addValues(today, Calendar.DAY_OF_MONTH, curApplyTask.getAllowApplyCancelDays());
+            long longOtherDay = DateUtil.getLongTimeByDate(DateUtil.formatShortSplitDateString(otherDay) + " 23:59:59");
+            // 当前时间
+            long now = System.currentTimeMillis();
+            List<TimePeriodEntity> timePeriodEntities = timePeriodService.listByIds(timePeriodExamRoomList);
+            Map<Long, TimePeriodEntity> timePeriodEntityMap = timePeriodEntities.stream()
+                    .collect(Collectors.toMap(TimePeriodEntity::getId, tpe -> tpe));
+
+            for (Long timePeriodId : timePeriodExamRoomList) {
+                TimePeriodEntity timePeriod = timePeriodEntityMap.get(timePeriodId);
+                if (!isTimeEditable(now, timePeriod.getEndTime(), longOtherDay, timePeriod.getStartTime())) {
+                    throw new StatusException("保存失败," + DateUtil.getShortDateByLongTime(timePeriod.getStartTime()) + "可编辑时间范围已过");
+                }
+            }
+        }
+    }
+
+    private void handleFirstTimeSave(Long userId, Long examRoomId, List<TimePeriodExamSiteReq> timePeriodExamRoomList,
+            List<TimePeriodExamRoomEntity> timePeriodExamRoomEntityList, ExamRoomEntity examRoom) {
+        timePeriodExamRoomList.forEach(item -> {
+            TimePeriodExamRoomEntity entity = createTimePeriodExamRoomEntity(item, examRoomId, userId);
+            timePeriodExamRoomEntityList.add(entity);
+        });
+
+        saveBatch(timePeriodExamRoomEntityList);
+        //刷新缓存
+        refreshDisableTimePeriodCache(timePeriodExamRoomEntityList, examRoom);
+    }
+
+    private void handleUpdateOrSave(Long userId, Long examRoomId, List<TimePeriodExamSiteReq> timePeriodExamRoomList,
+            List<TimePeriodExamRoomEntity> timePeriodExamRoomEntityList,
+            Map<Long, TimePeriodExamSiteBean> timePeriodMap, ExamRoomEntity examRoom, CurrentApplyTaskVO curApplyTask) {
+        List<TimePeriodExamRoomEntity> toBeSaveList = new ArrayList<>();
+        List<TimePeriodExamRoomEntity> toBeUpdateList = new ArrayList<>();
+
+        timePeriodExamRoomList.forEach(item -> {
+            TimePeriodExamRoomEntity entity = createTimePeriodExamRoomEntity(item, examRoomId, userId);
+            timePeriodExamRoomEntityList.add(entity);
+
+            if (item.getId() == null) {
+                toBeSaveList.add(entity);
+            } else {
+                toBeUpdateList.add(entity);
+            }
+        });
+
+        List<Long> resultList = new ArrayList<>();
+        for(TimePeriodExamRoomEntity item : toBeSaveList) {
+            resultList.add(item.getTimePeriodId());
+        }
+        for (TimePeriodExamRoomEntity item : toBeUpdateList) {
+            TimePeriodExamSiteBean timePeriod = timePeriodMap.get(item.getId());
+            if(timePeriod != null && !timePeriod.getEnable().equals(item.getEnable())) {
+                resultList.add(item.getTimePeriodId());
+            }
+        }
+        canEdit(resultList, curApplyTask);
+
+        saveOrUpdateBatch(timePeriodExamRoomEntityList);
+
+        //新增的记录,刷新缓存,只考虑禁用的情况
+        refreshDisableTimePeriodCache(toBeSaveList, examRoom);
+        //更新的记录,刷新缓存
+        refreshUpdatedTimePeriodCache(toBeUpdateList, timePeriodMap, examRoom);
+    }
+
+
+    private TimePeriodExamRoomEntity createTimePeriodExamRoomEntity(TimePeriodExamSiteReq item, Long examRoomId, Long userId) {
+        TimePeriodExamRoomEntity entity = new TimePeriodExamRoomEntity();
+        BeanUtils.copyProperties(item, entity);
+        entity.setExamRoomId(examRoomId);
+        entity.setOperateId(userId);
+        return entity;
+    }
+
+    private void refreshDisableTimePeriodCache(List<TimePeriodExamRoomEntity> disableList, ExamRoomEntity examRoom) {
+        disableList.stream()
+                .filter(item -> !item.getEnable())
+                .forEach(item -> {
+                    // TODO 更新容量缓存,缺失 timePeriodId 参数
+                  /*  applyTaskCacheService.refreshApplyAvailableCountCache(
+                            examRoom.getExamSiteId(),
+                            examRoom.getCapacity(),
+                            0
+                    );*/
+                });
+    }
+
+    private void refreshUpdatedTimePeriodCache(List<TimePeriodExamRoomEntity> updateList,
+            Map<Long, TimePeriodExamSiteBean> timePeriodMap,
+            ExamRoomEntity examRoom) {
+        updateList.forEach(item -> {
+            TimePeriodExamSiteBean timePeriod = timePeriodMap.get(item.getId());
+            //由启用变为禁用,缓存容量=-考场的容量
+            if (timePeriod != null && Boolean.TRUE.equals(timePeriod.getEnable()) && !item.getEnable()) {
+                // TODO 更新容量缓存,缺失 timePeriodId 参数
+               /* applyTaskCacheService.refreshApplyAvailableCountCache(
+                        examRoom.getExamSiteId(),
+                        examRoom.getCapacity(),
+                        0
+                );*/
+            }
+
+            //由禁用变为启用,缓存容量=+考场的容量
+            if (timePeriod != null && Boolean.FALSE.equals(timePeriod.getEnable()) && item.getEnable()) {
+                // TODO 更新容量缓存,缺失 timePeriodId 参数
+                /*applyTaskCacheService.refreshApplyAvailableCountCache(
+                        examRoom.getExamSiteId(),
+                        0,
+                        examRoom.getCapacity()
+                );*/
+            }
+
+        });
+    }
+
+}

+ 35 - 2
src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodExamSiteServiceImpl.java

@@ -2,16 +2,21 @@ package com.qmth.exam.reserve.service.impl;
 
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.core.exception.StatusException;
+import com.qmth.exam.reserve.bean.Constants;
 import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo;
 import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodInfo;
 import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodQuery;
 import com.qmth.exam.reserve.bean.apply.ExamSiteTimePeriodQuery;
+import com.qmth.exam.reserve.bean.org.OrgInfo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteBean;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteBean;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteInfo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteInfo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteReq;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
 import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteVo;
+import com.qmth.exam.reserve.cache.impl.OrgCacheService;
 import com.qmth.exam.reserve.dao.TimePeriodExamSiteDao;
 import com.qmth.exam.reserve.dao.TimePeriodExamSiteDao;
 import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 import com.qmth.exam.reserve.entity.ApplyTaskEntity;
+import com.qmth.exam.reserve.entity.SystemPropertyEntity;
 import com.qmth.exam.reserve.entity.TimePeriodExamSiteEntity;
 import com.qmth.exam.reserve.entity.TimePeriodExamSiteEntity;
 import com.qmth.exam.reserve.service.ApplyTaskService;
 import com.qmth.exam.reserve.service.ApplyTaskService;
+import com.qmth.exam.reserve.service.SystemPropertyService;
 import com.qmth.exam.reserve.service.TimePeriodExamSiteService;
 import com.qmth.exam.reserve.service.TimePeriodExamSiteService;
 import com.qmth.exam.reserve.service.TimePeriodService;
 import com.qmth.exam.reserve.service.TimePeriodService;
 import com.qmth.exam.reserve.util.DateUtil;
 import com.qmth.exam.reserve.util.DateUtil;
@@ -38,6 +43,12 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
     @Autowired
     @Autowired
     private TimePeriodService timePeriodService;
     private TimePeriodService timePeriodService;
 
 
+    @Autowired
+    private SystemPropertyService systemPropertyService;
+
+    @Autowired
+    private OrgCacheService orgCacheService;
+
     @Override
     @Override
     public List<String> listTimePeriod(Long taskId) {
     public List<String> listTimePeriod(Long taskId) {
         taskId = getTaskId(taskId);
         taskId = getTaskId(taskId);
@@ -56,6 +67,12 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
 
 
     @Override
     @Override
     public List<TimePeriodExamSiteVo> ListDetail(Long examSiteId) {
     public List<TimePeriodExamSiteVo> ListDetail(Long examSiteId) {
+        OrgInfo org = orgCacheService.currentOrg();
+        if (org == null) {
+            log.warn("[考场排班设置列表]未找到当前机构");
+            return Collections.emptyList();
+        }
+
         Long taskId = getTaskId(null);
         Long taskId = getTaskId(null);
         // 所有的预约日期
         // 所有的预约日期
         List<String> dateList = timePeriodService.listTimePeriodDate(taskId);
         List<String> dateList = timePeriodService.listTimePeriodDate(taskId);
@@ -76,10 +93,13 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
 
 
         //按日期封装
         //按日期封装
         List<TimePeriodExamSiteVo> list = new ArrayList<>();
         List<TimePeriodExamSiteVo> list = new ArrayList<>();
+        //获取预约统一开关状态
+        SystemPropertyEntity systemProperty = systemPropertyService.findByPropKey(org.getOrgId(), Constants.APPLY_SWITCH);
+        boolean editable = systemProperty == null || systemProperty.getPropValue() == null || !systemProperty.getPropValue().equals("0");
         for (String date : dateList) {
         for (String date : dateList) {
             TimePeriodExamSiteVo timePeriodVo = new TimePeriodExamSiteVo();
             TimePeriodExamSiteVo timePeriodVo = new TimePeriodExamSiteVo();
             timePeriodVo.setDateStr(getDateStr(date));
             timePeriodVo.setDateStr(getDateStr(date));
-            timePeriodVo.setTimePeriodList(filterTimePeriod(date, resultList));
+            timePeriodVo.setTimePeriodList(filterTimePeriod(date, resultList, editable));
             list.add(timePeriodVo);
             list.add(timePeriodVo);
         }
         }
         return list;
         return list;
@@ -88,6 +108,18 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
     @Override
     @Override
     @Transactional
     @Transactional
     public void save(Long operateId, Long examSiteId, List<TimePeriodExamSiteReq> timePeriodExamSiteList) {
     public void save(Long operateId, Long examSiteId, List<TimePeriodExamSiteReq> timePeriodExamSiteList) {
+        OrgInfo org = orgCacheService.currentOrg();
+        if (org == null) {
+            log.warn("[考场排班设置列表]未找到当前机构");
+            throw new StatusException("保存失败,未找到当前机构");
+        }
+        //获取预约统一开关状态
+        SystemPropertyEntity systemProperty = systemPropertyService.findByPropKey(org.getOrgId(), Constants.APPLY_SWITCH);
+        boolean editable = systemProperty == null || systemProperty.getPropValue() == null || !systemProperty.getPropValue().equals("0");
+        if(!editable) {
+            throw new StatusException("保存失败,预约统一开关已关闭");
+        }
+
         Long taskId = getTaskId(null);
         Long taskId = getTaskId(null);
         //所有的时段
         //所有的时段
         List<TimePeriodExamSiteBean> timePeriodList = timePeriodService.listTimePeriodByExamSiteId(taskId, examSiteId);
         List<TimePeriodExamSiteBean> timePeriodList = timePeriodService.listTimePeriodByExamSiteId(taskId, examSiteId);
@@ -130,7 +162,7 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
         return dateArr[1] + "月" + dateArr[2] + "日";
         return dateArr[1] + "月" + dateArr[2] + "日";
     }
     }
 
 
-    private List<TimePeriodExamSiteInfo> filterTimePeriod(String date, List<TimePeriodExamSiteBean> timePeriodList) {
+    private List<TimePeriodExamSiteInfo> filterTimePeriod(String date, List<TimePeriodExamSiteBean> timePeriodList, boolean editable) {
         List<TimePeriodExamSiteInfo> list = new ArrayList<>();
         List<TimePeriodExamSiteInfo> list = new ArrayList<>();
         List<TimePeriodExamSiteBean> filterTimePerildList = timePeriodList.stream()
         List<TimePeriodExamSiteBean> filterTimePerildList = timePeriodList.stream()
                 .filter(item -> DateUtil.getShortDateByLongTime(item.getStartTime()).equals(date))
                 .filter(item -> DateUtil.getShortDateByLongTime(item.getStartTime()).equals(date))
@@ -147,6 +179,7 @@ public class TimePeriodExamSiteServiceImpl extends ServiceImpl<TimePeriodExamSit
             bean.setTimePeriodId(time.getTimePeriodId());
             bean.setTimePeriodId(time.getTimePeriodId());
             bean.setEnable(time.getEnable());
             bean.setEnable(time.getEnable());
             bean.setTimePeriodStr(DateUtil.getStartToEndTime(time.getStartTime(), time.getEndTime()));
             bean.setTimePeriodStr(DateUtil.getStartToEndTime(time.getStartTime(), time.getEndTime()));
+            bean.setEditable(editable);
             list.add(bean);
             list.add(bean);
         }
         }
         return list;
         return list;

+ 5 - 0
src/main/java/com/qmth/exam/reserve/service/impl/TimePeriodServiceImpl.java

@@ -73,4 +73,9 @@ public class TimePeriodServiceImpl extends ServiceImpl<TimePeriodDao, TimePeriod
         return baseMapper.listTimePeriodByTask(taskId);
         return baseMapper.listTimePeriodByTask(taskId);
     }
     }
 
 
+    @Override
+    public List<TimePeriodExamSiteBean> listTimePeriodByExamRoomId(Long taskId, Long examRoomId) {
+        return baseMapper.listTimePeriodByExamRoomId(taskId, examRoomId);
+    }
+
 }
 }

+ 20 - 0
src/main/resources/mapper/TimePeriodMapper.xml

@@ -52,4 +52,24 @@
           tp.apply_task_id = #{taskId}
           tp.apply_task_id = #{taskId}
         order by tp.start_time
         order by tp.start_time
     </select>
     </select>
+
+    <select id="listTimePeriodByExamRoomId" resultType="com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteBean">
+        SELECT
+        tper.id,
+        tp.id timePeriodId,
+        tp.start_time startTime,
+        tp.end_time endTime,
+        tper.enable,
+        tper.exam_room_id examSiteId
+        FROM
+        t_time_period_exam_room tper,
+        t_time_period tp
+        WHERE
+        tper.time_period_id = tp.id
+        AND tp.apply_task_id = #{taskId}
+        <if test="examRoomId != null">
+            AND tper.exam_room_id = #{examRoomId}
+        </if>
+        order by tp.start_time
+    </select>
 </mapper>
 </mapper>