deason 1 ano atrás
pai
commit
d6594b9cde

+ 22 - 3
src/main/java/com/qmth/exam/reserve/service/impl/AuthServiceImpl.java

@@ -9,8 +9,10 @@ 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.bean.org.OrgInfo;
 import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.cache.impl.LoginSessionManager;
+import com.qmth.exam.reserve.cache.impl.OrgCacheService;
 import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 import com.qmth.exam.reserve.entity.StudentEntity;
 import com.qmth.exam.reserve.entity.UserEntity;
@@ -47,6 +49,9 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
     @Autowired
     private ApplyTaskCacheService applyTaskCacheService;
 
+    @Autowired
+    private OrgCacheService orgCacheService;
+
     @Override
     public LoginUser userLogin(LoginReq req) {
         if (StringUtils.isBlank(req.getAccount())) {
@@ -57,7 +62,14 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
             throw new StatusException("登录密码不能为空");
         }
 
-        log.debug("[USER_LOGIN] verifying, account:{}", req.getAccount());
+        if (req.getOrgId() == null) {
+            OrgInfo org = orgCacheService.currentOrg();
+            if (org != null) {
+                req.setOrgId(org.getOrgId());
+            }
+        }
+
+        log.debug("[USER_LOGIN] verifying... account:{} orgId:{}", req.getAccount(), req.getOrgId());
         UserEntity user = userService.findUserByLoginName(req.getOrgId(), req.getAccount());
         if (user == null) {
             throw new StatusException("登录用户不存在");
@@ -94,12 +106,19 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
             throw new StatusException("登录密码不能为空");
         }
 
+        if (req.getOrgId() == null) {
+            OrgInfo org = orgCacheService.currentOrg();
+            if (org != null) {
+                req.setOrgId(org.getOrgId());
+            }
+        }
+
         CurrentApplyTaskVO curApplyTask = applyTaskCacheService.currentApplyTask(req.getOrgId());
         if (curApplyTask == null) {
             throw new StatusException("尚未开启预约任务");
         }
 
-        log.debug("[STUDENT_LOGIN] verifying, account:{}", req.getAccount());
+        log.debug("[STUDENT_LOGIN] verifying... account:{} orgId:{}", req.getAccount(), req.getOrgId());
         StudentEntity student = studentService.findByStudentCode(curApplyTask.getTaskId(), req.getAccount());
         if (student == null) {
             throw new StatusException("登录用户不存在");
@@ -134,7 +153,7 @@ public class AuthServiceImpl implements AuthorizationService<LoginUser>, AuthSer
             throw new StatusException("微信OID不能为空");
         }
 
-        log.debug("[WECHAT_LOGIN] verifying, openId:{} uid:{}", req.getOpenId(), req.getUid());
+        log.debug("[WECHAT_LOGIN] verifying... openId:{} uid:{}", req.getOpenId(), req.getUid());
         StudentEntity student = studentService.findByOpenIdAndUid(req.getOpenId(), req.getUid());
         if (student == null) {
             throw new StatusException("登录用户不存在");