Browse Source

添加考试可选择日期

haogh 1 year ago
parent
commit
a3abb30af1

+ 18 - 0
src/main/java/com/qmth/exam/reserve/bean/stdapply/SignInVO.java

@@ -0,0 +1,18 @@
+package com.qmth.exam.reserve.bean.stdapply;
+
+import com.qmth.exam.reserve.bean.IModel;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class SignInVO implements IModel {
+
+    private static final long serialVersionUID = -1447534034452847584L;
+
+    @ApiModelProperty("可打印签到表的日期")
+    private Long examDate;
+
+}

+ 19 - 7
src/main/java/com/qmth/exam/reserve/controller/admin/StudentApplyController.java

@@ -24,6 +24,7 @@ import com.qmth.boot.core.collection.PageResult;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
+import com.qmth.exam.reserve.bean.stdapply.SignInVO;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyReq;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyVO;
 import com.qmth.exam.reserve.controller.BaseController;
@@ -78,6 +79,10 @@ public class StudentApplyController extends BaseController {
     @ApiOperation(value = "考生预约名单详情分页")
     @PostMapping(value = "/std/page")
     public PageResult<StudentApplyVO> page(@RequestBody StudentApplyReq req) {
+        LoginUser user = this.curLoginUser();
+        if (user.getRole().equals(Role.TEACHING)) {
+            req.setTeachingId(user.getCategoryId());
+        }
         return studentApplyService.page(req);
     }
 
@@ -96,8 +101,8 @@ public class StudentApplyController extends BaseController {
 
     @ApiOperation(value = "导入预考")
     @PostMapping(value = "/import")
-    public Map<String, Object> importPreExamStd(@ApiParam("教学点ID") @RequestParam Long teachingId,
-            @ApiParam("教学点所在的层级") @RequestParam Integer level, @RequestParam MultipartFile file) {
+    public Map<String, Object> importPreExamStd(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId,
+            @ApiParam("教学点所在的层级") @RequestParam(required = false) Integer level, @RequestParam MultipartFile file) {
         LoginUser user = this.curLoginUser();
         if (!Role.TEACHING.equals(user.getRole())) {
             throw new StatusException("没有权限");
@@ -135,7 +140,7 @@ public class StudentApplyController extends BaseController {
 
     @ApiOperation(value = "打印签到表")
     @PostMapping(value = "/std/auto/sign/in/print")
-    public void printSignIn(@ApiParam("教学点ID") @RequestParam Long teachingId,
+    public void printSignIn(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId,
             @ApiParam("考点ID") @RequestParam(required = false) Long agentId) {
         LoginUser user = this.curLoginUser();
         if (Role.ADMIN.equals(user.getRole()) && teachingId == null) {
@@ -149,14 +154,21 @@ public class StudentApplyController extends BaseController {
         signInZip.delete();
     }
 
+    @Aac(strict = false, auth = false)
     @ApiOperation(value = "自动排考")
     @PostMapping(value = "/std/auto/layout")
     public void autoLayout(@ApiParam("教学点ID") @RequestParam Long teachingId) {
-        LoginUser user = this.curLoginUser();
-        if (!Role.ADMIN.equals(user.getRole())) {
-            throw new StatusException("没有权限");
-        }
+        // LoginUser user = this.curLoginUser();
+        // if (!Role.ADMIN.equals(user.getRole())) {
+        // throw new StatusException("没有权限");
+        // }
         studentApplyService.autoLayout(teachingId);
     }
 
+    @ApiOperation(value = "可打印签到表的日期")
+    @PostMapping(value = "/sign/in/date")
+    public List<SignInVO> listSignInDate(@ApiParam("预约任务ID") @RequestParam(required = false) Long taskId) {
+        return studentApplyService.listSignInDate(taskId);
+    }
+
 }

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

@@ -8,6 +8,7 @@ import java.util.Map;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.boot.core.collection.PageResult;
 import com.qmth.exam.reserve.bean.login.LoginUser;
+import com.qmth.exam.reserve.bean.stdapply.SignInVO;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyReq;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyVO;
 import com.qmth.exam.reserve.entity.StudentApplyEntity;
@@ -28,4 +29,6 @@ public interface StudentApplyService extends IService<StudentApplyEntity> {
 
     int countApplyFinishForExamSiteAndTimePeriod(Long examSiteId, Long timePeriodId);
 
+    List<SignInVO> listSignInDate(Long taskId);
+
 }

+ 58 - 1
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -3,13 +3,19 @@ package com.qmth.exam.reserve.service.impl;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -40,6 +46,7 @@ import com.qmth.boot.tools.io.ZipWriter;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.AgentAndTimeVO;
 import com.qmth.exam.reserve.bean.stdapply.MaterialTitleInfo;
+import com.qmth.exam.reserve.bean.stdapply.SignInVO;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyReq;
 import com.qmth.exam.reserve.bean.stdapply.StudentApplyVO;
 import com.qmth.exam.reserve.bean.stdapply.StudentImportVO;
@@ -554,11 +561,12 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 if (studentApplyLock.tryLock()) {
                     baseMapper.insert(studentApply);
                     insertApplyList.add(studentApply);
+                    studentApplyLock.unlock();
                 } else {
                     log.warn("获取锁失败,不允许同一个考生同时操作预约!lockKey:{}", studentApplyLockKey);
                 }
                 num++;
-                if (toApplyNum - (studentApplyList.size() + 1) == 0) {
+                if (student.getApplyNumber() - (studentApplyList.size() + 1) == 0) {
                     iterator.remove();
                     student.setApplyFinished(true);
                     this.studentService.updateById(student);
@@ -846,4 +854,53 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return value != null ? value : 0;
     }
 
+    @Override
+    public List<SignInVO> listSignInDate(Long taskId) {
+        List<SignInVO> signInList = new ArrayList<>();
+        ApplyTaskEntity task = null;
+        if (taskId == null) {
+            task = applyTaskService.getById(taskId);
+        } else {
+            task = getApplyTask();
+        }
+        List<TimePeriodEntity> timePeriodList = listTimePeroid(task.getId());
+        if (timePeriodList.isEmpty()) {
+            throw new StatusException("未配置考试时段");
+        }
+        TimePeriodEntity time = timePeriodList.get(0);
+        List<TimePeriodEntity> noCancelTimePeroidList = listNoCancelApplyTimePeroid(timePeriodList,
+                task.getAllowApplyCancelDays());
+        if (noCancelTimePeroidList.isEmpty()) {
+            throw new StatusException("未到可以取消预约的时间");
+        }
+        LinkedHashMap<LocalDate, LocalDate> map = groupTimestampsByDay(noCancelTimePeroidList);
+        long between = ChronoUnit.DAYS.between(LocalDate.now(), map.entrySet().iterator().next().getKey());
+        for (long i = 0; i < between; i++) {
+            LocalDate day = LocalDate.now().plusDays(i);
+            long epochMilli = day.plusDays(1).atStartOfDay(ZoneId.systemDefault()).minusSeconds(1).toInstant()
+                    .toEpochMilli();
+            // 判断是否在考试时段内
+            if (epochMilli >= time.getStartTime()) {
+                map.put(day, day);
+            }
+        }
+        for (Entry<LocalDate, LocalDate> entry : map.entrySet()) {
+            SignInVO signIn = new SignInVO();
+            signIn.setExamDate(entry.getKey().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());
+            signInList.add(signIn);
+        }
+        Collections.sort(signInList, Comparator.comparing(SignInVO::getExamDate));
+        return signInList;
+    }
+
+    private LinkedHashMap<LocalDate, LocalDate> groupTimestampsByDay(List<TimePeriodEntity> timeList) {
+        LinkedHashMap<LocalDate, LocalDate> map = new LinkedHashMap<>();
+        for (TimePeriodEntity time : timeList) {
+            Instant instant = Instant.ofEpochMilli(time.getStartTime());
+            LocalDate date = instant.atZone(ZoneId.systemDefault()).toLocalDate();
+            map.putIfAbsent(date, date);
+        }
+        return map;
+    }
+
 }

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

@@ -65,6 +65,7 @@ public class StudentImportTaskServiceImpl extends ServiceImpl<StudentImportTaskD
         studentTask.setStatus(ImportStatus.RUNNING.toString());
         studentTask.setFilePath(filePath);
         studentTaskService.save(studentTask);
+        // TODO 原始文件上传到OSS
         asyncImportService.asyncImportStudent(studentTask, task.getOrgId(), lineList);
     }
 

+ 2 - 2
src/main/resources/mapper/StudentApplyMapper.xml

@@ -30,10 +30,10 @@
             and s.name like concat('%',#{req.name},'%')
         </if>
         <if test="req.identityNumber != null and req.identityNumber !=''">
-            and s.identity_number=#{req.identityNumber}
+            and s.identity_number like concat('%',#{req.identityNumber},'%')
         </if>
         <if test="req.studentCode != null and req.studentCode !=''">
-            and s.student_code=#{req.studentCode}
+            and s.student_code like concat('%',#{req.studentCode},'%')
         </if>
         order by a.id
     </select>