|
@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.service.core.service;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -9,12 +10,14 @@ import org.springframework.data.domain.Example;
|
|
|
import org.springframework.data.domain.ExampleMatcher;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import cn.com.qmth.examcloud.common.util.ErrorMsg;
|
|
|
import cn.com.qmth.examcloud.service.core.entity.Student;
|
|
|
import cn.com.qmth.examcloud.service.core.entity.User;
|
|
|
+import cn.com.qmth.examcloud.service.core.enums.LoginType;
|
|
|
import cn.com.qmth.examcloud.service.core.enums.UserScope;
|
|
|
import cn.com.qmth.examcloud.service.core.enums.UserType;
|
|
|
import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
|
|
@@ -31,6 +34,8 @@ public class StudentService {
|
|
|
StudentRepo studentRepo;
|
|
|
@Autowired
|
|
|
UserRepo userRepo;
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
|
|
|
private static final String JPG = ".jpg";
|
|
|
|
|
@@ -87,11 +92,27 @@ public class StudentService {
|
|
|
|
|
|
public Student save(Student student) {
|
|
|
if(student.getUser()==null || null==student.getUser().getId()){
|
|
|
+ //先判断是否有该学生,
|
|
|
+ Student domain = studentRepo.findByUserRootOrgIdAndStudentCode(student.getUser().getRootOrgId(), student.getStudentCode());
|
|
|
+ if(domain!=null){//学号查找不为空,更新身份证号
|
|
|
+ domain.setIdentityNumber(student.getIdentityNumber());
|
|
|
+ domain.setUpdateTime(new Date());
|
|
|
+ return studentRepo.save(domain);
|
|
|
+ }
|
|
|
+ Student entity = studentRepo.findByIdentityNumber(student.getIdentityNumber());
|
|
|
+ if(entity!=null){//身份证查找不为空,更新学号
|
|
|
+ entity.setStudentCode(student.getStudentCode());
|
|
|
+ entity.setUpdateTime(new Date());
|
|
|
+ return studentRepo.save(entity);
|
|
|
+ }
|
|
|
+ //新建用户和学生
|
|
|
User user=new User(student.getName(), UserScope.ORG, student.getUser().getRootOrgId(), student.getUser().getOrgId(), UserType.STUDENT);
|
|
|
String password = null;
|
|
|
if(!StringUtils.isEmpty(student.getStudentCode())){//学号后6位
|
|
|
+ user.setLoginName(student.getStudentCode());
|
|
|
password = student.getStudentCode().substring(student.getStudentCode().length()-6, student.getStudentCode().length());
|
|
|
- }else{
|
|
|
+ }else{//身份证号后6位
|
|
|
+ user.setLoginName(student.getIdentityNumber());
|
|
|
password = student.getIdentityNumber().substring(student.getIdentityNumber().length()-6,student.getIdentityNumber().length());
|
|
|
}
|
|
|
user.setPassword(password);
|
|
@@ -101,4 +122,26 @@ public class StudentService {
|
|
|
return studentRepo.save(student);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 二级登录
|
|
|
+ * @param orgId
|
|
|
+ * @param loginName
|
|
|
+ * @param password
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResponseEntity<?> login(long orgId,String loginName,
|
|
|
+ String password,LoginType loginType){
|
|
|
+ Student student = null;
|
|
|
+ if(LoginType.STUDENT_CODE.equals(loginType)){
|
|
|
+ student = studentRepo.findByUserRootOrgIdAndStudentCode(orgId, loginName);
|
|
|
+ }
|
|
|
+ if(LoginType.IDENTITY_NUMBER.equals(loginType)){
|
|
|
+ student = studentRepo.findByIdentityNumber(loginName);
|
|
|
+ }
|
|
|
+ if(student != null){
|
|
|
+ userService.loginProcess(student.getUser(),password);
|
|
|
+ }
|
|
|
+ return userService.loginProcess(null, password);
|
|
|
+ }
|
|
|
+
|
|
|
}
|