wangwei 6 жил өмнө
parent
commit
e4724915cb

+ 12 - 18
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/StudentController.java

@@ -79,9 +79,8 @@ public class StudentController extends ControllerSupport {
 	 */
 	@ApiOperation(value = "查询学生分页数据", notes = "分页")
 	@GetMapping("studentPage/{curPage}/{pageSize}")
-	public PageInfo<StudentDomain> getStudentPage(@PathVariable Integer curPage,
-			@PathVariable Integer pageSize, @RequestParam String name,
-			@RequestParam String studentCode, @RequestParam String identityNumber,
+	public PageInfo<StudentDomain> getStudentPage(@PathVariable Integer curPage, @PathVariable Integer pageSize,
+			@RequestParam String name, @RequestParam String studentCode, @RequestParam String identityNumber,
 			@RequestParam(required = false) Long rootOrgId) {
 
 		User accessUser = getAccessUser();
@@ -104,14 +103,12 @@ public class StudentController extends ControllerSupport {
 				predicates.add(cb.like(root.get("studentCode"), toSqlSearchPattern(studentCode)));
 			}
 			if (StringUtils.isNotEmpty(identityNumber)) {
-				predicates.add(
-						cb.like(root.get("identityNumber"), toSqlSearchPattern(identityNumber)));
+				predicates.add(cb.like(root.get("identityNumber"), toSqlSearchPattern(identityNumber)));
 			}
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = new PageRequest(curPage, pageSize,
-				new Sort(Direction.DESC, "updateTime"));
+		PageRequest pageRequest = new PageRequest(curPage, pageSize, new Sort(Direction.DESC, "updateTime"));
 
 		Page<StudentEntity> studentList = studentRepo.findAll(specification, pageRequest);
 
@@ -236,8 +233,7 @@ public class StudentController extends ControllerSupport {
 				throw new StatusException("B-450110", "学生不存在");
 			}
 			String identityNumber = s.getIdentityNumber();
-			if (StringUtils.isNotEmpty(identityNumber)
-					&& identityNumber.matches("[0-9a-zA-Z]{6,}")) {
+			if (StringUtils.isNotEmpty(identityNumber) && identityNumber.matches("[0-9a-zA-Z]{6,}")) {
 				s.setPassword(StringUtils.substring(identityNumber, -6, identityNumber.length()));
 			} else {
 				s.setPassword(BasicConsts.DEFAULT_PASSWORD);
@@ -295,21 +291,19 @@ public class StudentController extends ControllerSupport {
 		User accessUser = getAccessUser();
 		Long rootOrgId = accessUser.getRootOrgId();
 		Long studentId = accessUser.getUserId();
-		StudentInfo studentInfo = studentService.getStudentInfo(rootOrgId, studentId, null, null,
-				null);
+		StudentInfo studentInfo = studentService.getStudentInfo(rootOrgId, studentId, null, null, null);
 		return studentInfo;
 	}
 
 	@ApiOperation(value = "查询学生")
 	@GetMapping("getStudentInfo")
 	public StudentInfo getStudentInfo(@RequestParam(required = false) Long studentId,
-			@RequestParam(required = false) String identityNumber,
-			@RequestParam(required = false) String studentCode,
+			@RequestParam(required = false) String identityNumber, @RequestParam(required = false) String studentCode,
 			@RequestParam(required = false) String securityPhone) {
 		User accessUser = getAccessUser();
 		Long rootOrgId = accessUser.getRootOrgId();
-		StudentInfo studentInfo = studentService.getStudentInfo(rootOrgId, studentId,
-				identityNumber, studentCode, securityPhone);
+		StudentInfo studentInfo = studentService.getStudentInfo(rootOrgId, studentId, identityNumber, studentCode,
+				securityPhone);
 		return studentInfo;
 	}
 
@@ -357,7 +351,7 @@ public class StudentController extends ControllerSupport {
 
 	@ApiOperation(value = "解绑学号", notes = "")
 	@PutMapping("unbindStudentCodeByStudentCode")
-	public int unbindStudentCodeByStudentCode(@RequestParam(required = true) String studentCode,
+	public List<Long> unbindStudentCodeByStudentCode(@RequestParam(required = true) String studentCode,
 			@RequestParam(required = true) Long rootOrgId) {
 
 		if (null == rootOrgId) {
@@ -374,8 +368,8 @@ public class StudentController extends ControllerSupport {
 			throw new StatusException("B-160002", "studentCode is blank");
 		}
 
-		int affected = studentService.unbindStudentCodeByStudentCode(rootOrgId, studentCode);
-		return affected;
+		List<Long> studentIdList = studentService.unbindStudentCode(rootOrgId, studentCode, null);
+		return studentIdList;
 	}
 
 	@ApiOperation(value = "解绑安全手机", notes = "")

+ 5 - 2
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/StudentCloudServiceProvider.java

@@ -1,5 +1,7 @@
 package cn.com.qmth.examcloud.core.basic.api.provider;
 
+import java.util.List;
+
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -152,6 +154,7 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
 	public UnbindStudentCodeResp unbindStudentCode(@RequestBody UnbindStudentCodeReq req) {
 		Long rootOrgId = req.getRootOrgId();
 		String studentCode = req.getStudentCode();
+		String identityNumber = req.getIdentityNumber();
 
 		if (null == rootOrgId) {
 			throw new StatusException("B-160001", "rootOrgId is null");
@@ -160,10 +163,10 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
 			throw new StatusException("B-160002", "studentCode is blank");
 		}
 
-		int affected = studentService.unbindStudentCodeByStudentCode(rootOrgId, studentCode);
+		List<Long> studentIdList = studentService.unbindStudentCode(rootOrgId, studentCode, identityNumber);
 
 		UnbindStudentCodeResp resp = new UnbindStudentCodeResp();
-		resp.setAffected(affected);
+		resp.setStudentIdList(studentIdList);
 
 		return resp;
 	}

+ 6 - 3
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/StudentService.java

@@ -1,5 +1,7 @@
 package cn.com.qmth.examcloud.core.basic.service;
 
+import java.util.List;
+
 import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
 import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
 
@@ -32,15 +34,16 @@ public interface StudentService {
 	 * @param securityPhone
 	 * @return
 	 */
-	StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber,
-			String studentCode, String securityPhone);
+	StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber, String studentCode,
+			String securityPhone);
 
 	/**
 	 * 解绑学号
 	 *
 	 * @author WANGWEI
 	 * @param studentCode
+	 * @param identityNumber
 	 */
-	int unbindStudentCodeByStudentCode(Long rootOrgId, String studentCode);
+	List<Long> unbindStudentCode(Long rootOrgId, String studentCode, String identityNumber);
 
 }

+ 57 - 38
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/StudentServiceImpl.java

@@ -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;
 	}
 
 }