|
@@ -1,11 +1,15 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.service.impl;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import javax.transaction.Transactional;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.UrlUtil;
|
|
@@ -103,15 +107,12 @@ public class StudentServiceImpl implements StudentService {
|
|
|
throw new StatusException("B-160012", "身份证号不能为空");
|
|
|
}
|
|
|
|
|
|
- StudentEntity student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber,
|
|
|
- rootOrgId);
|
|
|
+ StudentEntity student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
|
|
|
|
|
|
String studentCode = studentInfo.getStudentCode();
|
|
|
if (StringUtils.isNotBlank(studentCode)) {
|
|
|
- StudentEntity studentByCode = studentRepo.findByStudentCodeAndRootOrgId(studentCode,
|
|
|
- rootOrgId);
|
|
|
- if (null != studentByCode
|
|
|
- && (!studentByCode.getIdentityNumber().equalsIgnoreCase(identityNumber))) {
|
|
|
+ StudentEntity studentByCode = studentRepo.findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
|
|
|
+ if (null != studentByCode && (!studentByCode.getIdentityNumber().equalsIgnoreCase(identityNumber))) {
|
|
|
throw new StatusException("B-160008", "学号被占用. 学号: " + studentCode);
|
|
|
}
|
|
|
|
|
@@ -132,8 +133,7 @@ public class StudentServiceImpl implements StudentService {
|
|
|
student = new StudentEntity();
|
|
|
student.setEnable(true);
|
|
|
if (identityNumber.matches("[0-9a-zA-Z]{6,}")) {
|
|
|
- student.setPassword(
|
|
|
- StringUtils.substring(identityNumber, -6, identityNumber.length()));
|
|
|
+ student.setPassword(StringUtils.substring(identityNumber, -6, identityNumber.length()));
|
|
|
} else {
|
|
|
student.setPassword(BasicConsts.DEFAULT_PASSWORD);
|
|
|
}
|
|
@@ -194,13 +194,12 @@ public class StudentServiceImpl implements StudentService {
|
|
|
*
|
|
|
* @author WANGWEI
|
|
|
*
|
|
|
- * @see
|
|
|
- * cn.com.qmth.examcloud.core.basic.service.StudentService#getStudentInfo(
|
|
|
+ * @see cn.com.qmth.examcloud.core.basic.service.StudentService#getStudentInfo(
|
|
|
* java.lang.Long, java.lang.String, java.lang.String, java.lang.String)
|
|
|
*/
|
|
|
@Override
|
|
|
- public StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber,
|
|
|
- String studentCode, String securityPhone) {
|
|
|
+ public StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber, String studentCode,
|
|
|
+ String securityPhone) {
|
|
|
|
|
|
if (null == rootOrgId) {
|
|
|
throw new StatusException("B-160250", "rootOrgId is null");
|
|
@@ -226,8 +225,7 @@ public class StudentServiceImpl implements StudentService {
|
|
|
}
|
|
|
|
|
|
if (count > 1) {
|
|
|
- throw new StatusException("B-160210",
|
|
|
- "参数过多,只需要[studentId,identityNumber,studentCode,securityPhone]中的一个");
|
|
|
+ throw new StatusException("B-160210", "参数过多,只需要[studentId,identityNumber,studentCode,securityPhone]中的一个");
|
|
|
}
|
|
|
|
|
|
if (null == s) {
|
|
@@ -269,40 +267,61 @@ public class StudentServiceImpl implements StudentService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int unbindStudentCodeByStudentCode(Long rootOrgId, String studentCode) {
|
|
|
+ public List<Long> unbindStudentCode(Long rootOrgId, String studentCode, String identityNumber) {
|
|
|
|
|
|
- StudentEntity studentEntity = studentRepo.findByStudentCodeAndRootOrgId(studentCode,
|
|
|
- rootOrgId);
|
|
|
+ if (null == rootOrgId) {
|
|
|
+ throw new StatusException("B-120001", "rootOrgId is null");
|
|
|
+ }
|
|
|
|
|
|
- if (null == studentEntity) {
|
|
|
- return 0;
|
|
|
+ List<StudentEntity> studentList = Lists.newArrayList();
|
|
|
+
|
|
|
+ StudentEntity s1 = null;
|
|
|
+ StudentEntity s2 = null;
|
|
|
+ if (null != studentCode) {
|
|
|
+ s1 = studentRepo.findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
|
|
|
+ if (null != s1) {
|
|
|
+ studentList.add(s1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != identityNumber) {
|
|
|
+ s2 = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
|
|
|
+ if (null != s2) {
|
|
|
+ if (null == s1 || !s1.getId().equals(s2.getId())) {
|
|
|
+ studentList.add(s2);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- studentEntity.setStudentCode(null);
|
|
|
- StudentEntity saved = studentRepo.save(studentEntity);
|
|
|
+ List<Long> studentIdList = Lists.newArrayList();
|
|
|
|
|
|
- SyncStudentReq req = new SyncStudentReq();
|
|
|
- req.setEnable(saved.getEnable());
|
|
|
- req.setId(saved.getId());
|
|
|
- req.setIdentityNumber(saved.getIdentityNumber());
|
|
|
- req.setName(saved.getName());
|
|
|
+ for (StudentEntity cur : studentList) {
|
|
|
+ cur.setStudentCode(null);
|
|
|
+ StudentEntity saved = studentRepo.save(cur);
|
|
|
+ studentIdList.add(saved.getId());
|
|
|
|
|
|
- req.setOrgId(saved.getOrgId());
|
|
|
- OrgEntity org = orgRepo.findOne(saved.getOrgId());
|
|
|
- req.setOrgCode(org.getCode());
|
|
|
- req.setOrgName(org.getName());
|
|
|
+ SyncStudentReq req = new SyncStudentReq();
|
|
|
+ req.setEnable(saved.getEnable());
|
|
|
+ req.setId(saved.getId());
|
|
|
+ req.setIdentityNumber(saved.getIdentityNumber());
|
|
|
+ req.setName(saved.getName());
|
|
|
+
|
|
|
+ req.setOrgId(saved.getOrgId());
|
|
|
+ OrgEntity org = orgRepo.findOne(saved.getOrgId());
|
|
|
+ req.setOrgCode(org.getCode());
|
|
|
+ req.setOrgName(org.getName());
|
|
|
|
|
|
- req.setPhoneNumber(saved.getPhoneNumber());
|
|
|
- req.setPhotoPath(saved.getPhotoPath());
|
|
|
- req.setRootOrgId(saved.getRootOrgId());
|
|
|
- req.setSecurityPhone(saved.getSecurityPhone());
|
|
|
- req.setStudentCode(saved.getStudentCode());
|
|
|
+ req.setPhoneNumber(saved.getPhoneNumber());
|
|
|
+ req.setPhotoPath(saved.getPhotoPath());
|
|
|
+ req.setRootOrgId(saved.getRootOrgId());
|
|
|
+ req.setSecurityPhone(saved.getSecurityPhone());
|
|
|
+ req.setStudentCode(saved.getStudentCode());
|
|
|
|
|
|
- req.setSyncType("update");
|
|
|
+ req.setSyncType("update");
|
|
|
|
|
|
- dataSyncCloudService.syncStudent(req);
|
|
|
+ dataSyncCloudService.syncStudent(req);
|
|
|
+ }
|
|
|
|
|
|
- return 1;
|
|
|
+ return studentIdList;
|
|
|
}
|
|
|
|
|
|
}
|