|
@@ -1,23 +1,28 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.service.impl;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
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 com.google.common.collect.Maps;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.util.UrlUtil;
|
|
|
import cn.com.qmth.examcloud.core.basic.base.constants.BasicConsts;
|
|
|
import cn.com.qmth.examcloud.core.basic.base.constants.PropKeys;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.StudentCodeRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.StudentCodeEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.StudentService;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.UserService;
|
|
@@ -39,6 +44,9 @@ public class StudentServiceImpl implements StudentService {
|
|
|
@Autowired
|
|
|
UserRepo userRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ StudentCodeRepo studentCodeRepo;
|
|
|
+
|
|
|
@Autowired
|
|
|
UserService userService;
|
|
|
|
|
@@ -112,20 +120,6 @@ public class StudentServiceImpl implements StudentService {
|
|
|
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))) {
|
|
|
- throw new StatusException("160008", "学号被占用. 学号: " + studentCode);
|
|
|
- }
|
|
|
-
|
|
|
- if (null != student && null != student.getStudentCode()
|
|
|
- && (!studentCode.equalsIgnoreCase(student.getStudentCode()))) {
|
|
|
- throw new StatusException("160005", "身份证号已关联学号");
|
|
|
- }
|
|
|
- }
|
|
|
long updateTime = 0L;
|
|
|
if (null != student) {
|
|
|
if (null != student.getUpdateTime()) {
|
|
@@ -143,17 +137,15 @@ public class StudentServiceImpl implements StudentService {
|
|
|
} else {
|
|
|
student.setPassword(BasicConsts.DEFAULT_PASSWORD);
|
|
|
}
|
|
|
+
|
|
|
+ student.setRootOrgId(rootOrgId);
|
|
|
+ student.setIdentityNumber(identityNumber);
|
|
|
}
|
|
|
|
|
|
- student.setRootOrgId(rootOrgId);
|
|
|
- student.setIdentityNumber(identityNumber);
|
|
|
student.setOrgId(org.getId());
|
|
|
- if (StringUtils.isNotBlank(studentCode)) {
|
|
|
- student.setStudentCode(studentCode);
|
|
|
- }
|
|
|
if (null != studentInfo.getName()) {
|
|
|
if (StringUtils.isBlank(studentInfo.getName())) {
|
|
|
- throw new StatusException("160006", "姓名不能为空");
|
|
|
+ throw new StatusException("160006", "姓名不能为空串");
|
|
|
}
|
|
|
student.setName(studentInfo.getName());
|
|
|
}
|
|
@@ -171,6 +163,46 @@ public class StudentServiceImpl implements StudentService {
|
|
|
}
|
|
|
StudentEntity saved = studentRepo.saveAndFlush(student);
|
|
|
|
|
|
+ List<String> studentCodeList = studentInfo.getStudentCodeList();
|
|
|
+ if (CollectionUtils.isNotEmpty(studentCodeList)) {
|
|
|
+
|
|
|
+ if (5 < studentCodeList.size()) {
|
|
|
+ throw new StatusException("160019", "身份证绑定的学号数量不能超过5个");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String studentCode : studentCodeList) {
|
|
|
+ StudentCodeEntity studentCodeEntity = studentCodeRepo
|
|
|
+ .findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
|
|
|
+
|
|
|
+ if (null != studentCodeEntity) {
|
|
|
+ if (!studentCodeEntity.getIdentityNumber().equalsIgnoreCase(identityNumber)) {
|
|
|
+ throw new StatusException("160008", "学号被占用. 学号: " + studentCode);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ studentCodeEntity = new StudentCodeEntity();
|
|
|
+ studentCodeEntity.setIdentityNumber(identityNumber);
|
|
|
+ studentCodeEntity.setRootOrgId(rootOrgId);
|
|
|
+ studentCodeEntity.setStudentCode(studentCode);
|
|
|
+ studentCodeEntity.setStudentId(saved.getId());
|
|
|
+
|
|
|
+ studentCodeRepo.save(studentCodeEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<StudentCodeEntity> studentCodeEntityList = studentCodeRepo
|
|
|
+ .findByStudentId(saved.getId());
|
|
|
+
|
|
|
+ if (5 < studentCodeEntityList.size()) {
|
|
|
+ throw new StatusException("160018", "身份证绑定的学号数量不能超过5个");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> lastStudentCodeList = Lists.newArrayList();
|
|
|
+ for (StudentCodeEntity cur : studentCodeEntityList) {
|
|
|
+ lastStudentCodeList.add(cur.getStudentCode());
|
|
|
+ }
|
|
|
+
|
|
|
// 同步操作
|
|
|
if (updateTime != saved.getUpdateTime().getTime()) {
|
|
|
SyncStudentReq req = new SyncStudentReq();
|
|
@@ -185,7 +217,7 @@ public class StudentServiceImpl implements StudentService {
|
|
|
req.setPhotoPath(saved.getPhotoPath());
|
|
|
req.setRootOrgId(saved.getRootOrgId());
|
|
|
req.setSecurityPhone(saved.getSecurityPhone());
|
|
|
- req.setStudentCode(saved.getStudentCode());
|
|
|
+ req.setStudentCodeList(lastStudentCodeList);
|
|
|
|
|
|
req.setSyncType("update");
|
|
|
|
|
@@ -218,13 +250,20 @@ public class StudentServiceImpl implements StudentService {
|
|
|
count++;
|
|
|
s = GlobalHelper.getEntity(studentRepo, studentId, StudentEntity.class);
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(identityNumber)) {
|
|
|
count++;
|
|
|
s = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(studentCode)) {
|
|
|
count++;
|
|
|
- s = studentRepo.findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
|
|
|
+
|
|
|
+ StudentCodeEntity studentCodeEntity = studentCodeRepo
|
|
|
+ .findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
|
|
|
+ if (null != studentCodeEntity) {
|
|
|
+ s = GlobalHelper.getEntity(studentRepo, studentCodeEntity.getStudentId(),
|
|
|
+ StudentEntity.class);
|
|
|
+ }
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(securityPhone)) {
|
|
|
count++;
|
|
@@ -269,7 +308,14 @@ public class StudentServiceImpl implements StudentService {
|
|
|
OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, s.getRootOrgId(), OrgEntity.class);
|
|
|
info.setRootOrgName(rootOrg.getName());
|
|
|
info.setSecurityPhone(s.getSecurityPhone());
|
|
|
- info.setStudentCode(s.getStudentCode());
|
|
|
+
|
|
|
+ List<StudentCodeEntity> studentCodeEntityList = studentCodeRepo.findByStudentId(s.getId());
|
|
|
+
|
|
|
+ List<String> studentCodeList = Lists.newArrayList();
|
|
|
+ for (StudentCodeEntity cur : studentCodeEntityList) {
|
|
|
+ studentCodeList.add(cur.getStudentCode());
|
|
|
+ }
|
|
|
+ info.setStudentCodeList(studentCodeList);
|
|
|
|
|
|
return info;
|
|
|
}
|
|
@@ -281,48 +327,80 @@ public class StudentServiceImpl implements StudentService {
|
|
|
throw new StatusException("120001", "rootOrgId is null");
|
|
|
}
|
|
|
|
|
|
+ // 更新的学生集合
|
|
|
List<StudentEntity> studentList = Lists.newArrayList();
|
|
|
+ // 解绑的学号集合
|
|
|
+ Map<Long, List<String>> unboundStudentCodeMap = Maps.newHashMap();
|
|
|
|
|
|
StudentEntity s1 = null;
|
|
|
StudentEntity s2 = null;
|
|
|
if (null != studentCode) {
|
|
|
- s1 = studentRepo.findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
|
|
|
- if (null != s1) {
|
|
|
+ StudentCodeEntity sc = studentCodeRepo.findByStudentCodeAndRootOrgId(studentCode,
|
|
|
+ rootOrgId);
|
|
|
+ if (null != sc) {
|
|
|
+ studentCodeRepo.delete(sc);
|
|
|
+ s1 = GlobalHelper.getEntity(studentRepo, sc.getStudentId(), StudentEntity.class);
|
|
|
studentList.add(s1);
|
|
|
+ List<String> unboundStudentCodeList = Lists.newArrayList();
|
|
|
+ unboundStudentCodeList.add(sc.getStudentCode());
|
|
|
+ unboundStudentCodeMap.put(s1.getId(), unboundStudentCodeList);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if (null != identityNumber) {
|
|
|
s2 = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
|
|
|
if (null != s2) {
|
|
|
if (null == s1 || !s1.getId().equals(s2.getId())) {
|
|
|
studentList.add(s2);
|
|
|
}
|
|
|
+
|
|
|
+ List<StudentCodeEntity> scList = studentCodeRepo.findByStudentId(s2.getId());
|
|
|
+ studentCodeRepo.deleteAll(scList);
|
|
|
+
|
|
|
+ List<String> unboundStudentCodeList = unboundStudentCodeMap.get(s2.getId());
|
|
|
+ if (null == unboundStudentCodeList) {
|
|
|
+ unboundStudentCodeList = Lists.newArrayList();
|
|
|
+ unboundStudentCodeMap.put(s2.getId(), unboundStudentCodeList);
|
|
|
+ }
|
|
|
+ for (StudentCodeEntity cur : scList) {
|
|
|
+ unboundStudentCodeList.add(cur.getStudentCode());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
List<Long> studentIdList = Lists.newArrayList();
|
|
|
|
|
|
for (StudentEntity cur : studentList) {
|
|
|
- cur.setStudentCode(null);
|
|
|
- StudentEntity saved = studentRepo.saveAndFlush(cur);
|
|
|
- studentIdList.add(saved.getId());
|
|
|
+ studentIdList.add(cur.getId());
|
|
|
|
|
|
SyncStudentReq req = new SyncStudentReq();
|
|
|
- req.setEnable(saved.getEnable());
|
|
|
- req.setId(saved.getId());
|
|
|
- req.setIdentityNumber(saved.getIdentityNumber());
|
|
|
- req.setName(saved.getName());
|
|
|
+ req.setEnable(cur.getEnable());
|
|
|
+ req.setId(cur.getId());
|
|
|
+ req.setIdentityNumber(cur.getIdentityNumber());
|
|
|
+ req.setName(cur.getName());
|
|
|
|
|
|
- req.setOrgId(saved.getOrgId());
|
|
|
- OrgEntity org = GlobalHelper.getEntity(orgRepo, saved.getOrgId(), OrgEntity.class);
|
|
|
+ req.setOrgId(cur.getOrgId());
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, cur.getOrgId(), OrgEntity.class);
|
|
|
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(cur.getPhoneNumber());
|
|
|
+ req.setPhotoPath(cur.getPhotoPath());
|
|
|
+ req.setRootOrgId(cur.getRootOrgId());
|
|
|
+ req.setSecurityPhone(cur.getSecurityPhone());
|
|
|
+
|
|
|
+ List<StudentCodeEntity> studentCodeEntityList = studentCodeRepo
|
|
|
+ .findByStudentId(cur.getId());
|
|
|
+
|
|
|
+ List<String> lastStudentCodeList = Lists.newArrayList();
|
|
|
+ for (StudentCodeEntity sc : studentCodeEntityList) {
|
|
|
+ lastStudentCodeList.add(sc.getStudentCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ req.setStudentCodeList(lastStudentCodeList);
|
|
|
+
|
|
|
+ List<String> unboundStudentCodeList = unboundStudentCodeMap.get(cur.getId());
|
|
|
+ req.setUnboundStudentCodeList(unboundStudentCodeList);
|
|
|
|
|
|
req.setSyncType("update");
|
|
|
|
|
@@ -332,6 +410,45 @@ public class StudentServiceImpl implements StudentService {
|
|
|
return studentIdList;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void unbindSecurityPhone(Long studentId) {
|
|
|
+
|
|
|
+ StudentEntity s = GlobalHelper.getEntity(studentRepo, studentId, StudentEntity.class);
|
|
|
+ if (null == s) {
|
|
|
+ throw new StatusException("450110", "学生不存在");
|
|
|
+ }
|
|
|
+ s.setSecurityPhone(null);
|
|
|
+ StudentEntity saved = studentRepo.save(s);
|
|
|
+
|
|
|
+ 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 = GlobalHelper.getEntity(orgRepo, saved.getOrgId(), OrgEntity.class);
|
|
|
+ req.setOrgCode(org.getCode());
|
|
|
+ req.setOrgName(org.getName());
|
|
|
+
|
|
|
+ req.setPhoneNumber(saved.getPhoneNumber());
|
|
|
+ req.setPhotoPath(saved.getPhotoPath());
|
|
|
+ req.setRootOrgId(saved.getRootOrgId());
|
|
|
+ req.setSecurityPhone(saved.getSecurityPhone());
|
|
|
+
|
|
|
+ List<StudentCodeEntity> studentCodeEntityList = studentCodeRepo
|
|
|
+ .findByStudentId(saved.getId());
|
|
|
+ List<String> lastStudentCodeList = Lists.newArrayList();
|
|
|
+ for (StudentCodeEntity sc : studentCodeEntityList) {
|
|
|
+ lastStudentCodeList.add(sc.getStudentCode());
|
|
|
+ }
|
|
|
+ req.setStudentCodeList(lastStudentCodeList);
|
|
|
+
|
|
|
+ req.setSyncType("update");
|
|
|
+
|
|
|
+ dataSyncCloudService.syncStudent(req);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean hasBeBound(String securityPhone) {
|
|
|
|