Browse Source

尚未开启预约任务,限制登录

deason 1 year ago
parent
commit
25a5e898d0

+ 9 - 6
src/main/java/com/qmth/exam/reserve/bean/login/LoginUser.java

@@ -14,12 +14,6 @@ public class LoginUser implements AccessEntity, IModel {
 
     private static final long serialVersionUID = 8254087838589213068L;
 
-    @ApiModelProperty(value = "学校ID")
-    private Long orgId;
-
-    @ApiModelProperty(value = "教学点ID")
-    private Long categoryId;
-
     @ApiModelProperty(value = "用户ID")
     private Long id;
 
@@ -32,6 +26,15 @@ public class LoginUser implements AccessEntity, IModel {
     @ApiModelProperty(value = "角色")
     private Role role;
 
+    @ApiModelProperty(value = "学校ID")
+    private Long orgId;
+
+    @ApiModelProperty(value = "教学点ID")
+    private Long categoryId;
+
+    @ApiModelProperty(value = "预约任务ID")
+    private Long applyTaskId;
+
     @ApiModelProperty(value = "微信OID")
     private String openId;
 

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

@@ -7,7 +7,7 @@ import com.qmth.exam.reserve.entity.StudentEntity;
 
 public interface StudentService extends IService<StudentEntity> {
 
-    StudentEntity findByStudentCode(Long orgId, String studentCode);
+    StudentEntity findByStudentCode(Long applyTaskId, String studentCode);
 
     StudentEntity findByOpenIdAndUid(String openId, String uid);
 

+ 30 - 7
src/main/java/com/qmth/exam/reserve/service/impl/AuthServiceImpl.java

@@ -1,18 +1,22 @@
 package com.qmth.exam.reserve.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.core.security.annotation.AuthorizationComponent;
 import com.qmth.boot.core.security.service.AuthorizationService;
 import com.qmth.boot.tools.signature.SignatureType;
 import com.qmth.boot.tools.uuid.FastUUID;
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.login.LoginReq;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.login.WechatLoginReq;
 import com.qmth.exam.reserve.cache.CacheConstants;
 import com.qmth.exam.reserve.cache.LoginSessionManager;
+import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 import com.qmth.exam.reserve.entity.StudentEntity;
 import com.qmth.exam.reserve.entity.UserEntity;
 import com.qmth.exam.reserve.enums.Role;
+import com.qmth.exam.reserve.service.ApplyTaskService;
 import com.qmth.exam.reserve.service.AuthService;
 import com.qmth.exam.reserve.service.StudentService;
 import com.qmth.exam.reserve.service.UserService;
@@ -38,6 +42,9 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
     @Autowired
     private StudentService studentService;
 
+    @Autowired
+    private ApplyTaskService applyTaskService;
+
     @Override
     public LoginUser userLogin(LoginReq req) {
         if (StringUtils.isBlank(req.getAccount())) {
@@ -61,11 +68,11 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
 
         LoginUser loginUser = new LoginUser();
         loginUser.setId(user.getId());
-        loginUser.setOrgId(user.getOrgId());
-        loginUser.setCategoryId(user.getCategoryId());
         loginUser.setAccount(user.getLoginName());
         loginUser.setName(user.getName());
         loginUser.setRole(user.getRole());
+        loginUser.setOrgId(user.getOrgId());
+        loginUser.setCategoryId(user.getCategoryId());
 
         loginUser.setSessionId(CacheConstants.CACHE_USER_LOGIN + user.getId());
         loginUser.setToken(FastUUID.get());
@@ -85,8 +92,14 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
             throw new StatusException("登录密码不能为空");
         }
 
+        // 获取当前启用的预约任务
+        CurrentApplyTaskVO curApplyTask = applyTaskService.currentApplyTask(req.getOrgId());
+        if (curApplyTask == null) {
+            throw new StatusException("尚未开启预约任务");
+        }
+
         log.debug("[STUDENT_LOGIN] verifying, account:{}", req.getAccount());
-        StudentEntity student = studentService.findByStudentCode(req.getOrgId(), req.getAccount());
+        StudentEntity student = studentService.findByStudentCode(curApplyTask.getTaskId(), req.getAccount());
         if (student == null) {
             throw new StatusException("登录用户不存在");
         }
@@ -98,11 +111,12 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
 
         LoginUser loginUser = new LoginUser();
         loginUser.setId(student.getId());
-        loginUser.setOrgId(student.getOrgId());
-        loginUser.setCategoryId(student.getCategoryId());
         loginUser.setAccount(student.getStudentCode());
         loginUser.setName(student.getName());
         loginUser.setRole(Role.STUDENT);
+        loginUser.setOrgId(student.getOrgId());
+        loginUser.setCategoryId(student.getCategoryId());
+        loginUser.setApplyTaskId(student.getApplyTaskId());
         loginUser.setOpenId(student.getOpenId());
 
         loginUser.setSessionId(CacheConstants.CACHE_STUDENT_LOGIN + student.getId());
@@ -125,13 +139,22 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
             throw new StatusException("登录用户不存在");
         }
 
+        LambdaQueryWrapper<ApplyTaskEntity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.select(ApplyTaskEntity::getEnable);
+        wrapper.eq(ApplyTaskEntity::getId, student.getApplyTaskId());
+        ApplyTaskEntity curApplyTask = applyTaskService.getOne(wrapper);
+        if (curApplyTask == null || !curApplyTask.getEnable()) {
+            throw new StatusException("尚未开启预约任务");
+        }
+
         LoginUser loginUser = new LoginUser();
         loginUser.setId(student.getId());
-        loginUser.setOrgId(student.getOrgId());
-        loginUser.setCategoryId(student.getCategoryId());
         loginUser.setAccount(student.getStudentCode());
         loginUser.setName(student.getName());
         loginUser.setRole(Role.STUDENT);
+        loginUser.setOrgId(student.getOrgId());
+        loginUser.setCategoryId(student.getCategoryId());
+        loginUser.setApplyTaskId(student.getApplyTaskId());
         loginUser.setOpenId(student.getOpenId());
 
         loginUser.setSessionId(CacheConstants.CACHE_STUDENT_LOGIN + student.getId());

+ 5 - 4
src/main/java/com/qmth/exam/reserve/service/impl/StudentServiceImpl.java

@@ -21,16 +21,17 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
     private static final Logger log = LoggerFactory.getLogger(StudentServiceImpl.class);
 
     @Override
-    public StudentEntity findByStudentCode(Long orgId, String studentCode) {
+    public StudentEntity findByStudentCode(Long applyTaskId, String studentCode) {
         if (StringUtils.isEmpty(studentCode)) {
             throw new StatusException("学号不能为空");
         }
+        if (applyTaskId == null) {
+            throw new StatusException("预约任务ID不能为空");
+        }
 
         LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(StudentEntity::getStudentCode, studentCode);
-        if (orgId != null) {
-            wrapper.eq(StudentEntity::getOrgId, orgId);
-        }
+        wrapper.eq(StudentEntity::getApplyTaskId, applyTaskId);
 
         return baseMapper.selectOne(wrapper);
     }