소스 검색

getStudentMaps

deason 4 년 전
부모
커밋
3b9dba13d6

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

@@ -1,41 +1,12 @@
 package cn.com.qmth.examcloud.core.basic.api.provider;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.criteria.Predicate;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import com.google.common.collect.Lists;
-
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.util.ByteUtil;
 import cn.com.qmth.examcloud.commons.util.SHA256;
 import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
 import cn.com.qmth.examcloud.core.basic.api.bean.StudentBean;
-import cn.com.qmth.examcloud.core.basic.api.request.CountStudentReq;
-import cn.com.qmth.examcloud.core.basic.api.request.GetStudentListByIdsReq;
-import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
-import cn.com.qmth.examcloud.core.basic.api.request.SaveStudentReq;
-import cn.com.qmth.examcloud.core.basic.api.request.UnbindStudentCodeReq;
-import cn.com.qmth.examcloud.core.basic.api.request.UpdatePasswordReq;
-import cn.com.qmth.examcloud.core.basic.api.request.UpdateStudentStatusReq;
-import cn.com.qmth.examcloud.core.basic.api.response.CountStudentResp;
-import cn.com.qmth.examcloud.core.basic.api.response.GetStudentListByIdsResp;
-import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
-import cn.com.qmth.examcloud.core.basic.api.response.SaveStudentResp;
-import cn.com.qmth.examcloud.core.basic.api.response.UnbindStudentCodeResp;
-import cn.com.qmth.examcloud.core.basic.api.response.UpdatePasswordResp;
-import cn.com.qmth.examcloud.core.basic.api.response.UpdateStudentStatusResp;
+import cn.com.qmth.examcloud.core.basic.api.request.*;
+import cn.com.qmth.examcloud.core.basic.api.response.*;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
 import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
@@ -46,8 +17,24 @@ import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
 import cn.com.qmth.examcloud.core.basic.service.cache.StudentCache;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
+import com.google.common.collect.Lists;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.persistence.criteria.Predicate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * {@link StatusException} 状态码范围:056XXX<br>
@@ -274,7 +261,7 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
         resp.setCount(count);
         return resp;
     }
-    
+
     @ApiOperation(value = "根据ID获取学生集合")
     @PostMapping("getStudentListByIds")
     @Override
@@ -292,21 +279,10 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
 
         List<StudentBean> list = Lists.newArrayList();
         for (StudentEntity student : studentEntityList) {
-        	StudentBean studentBean = new StudentBean();
-            studentBean.setId(student.getId());
-            studentBean.setName(student.getName());
-            studentBean.setIdentityNumber(student.getIdentityNumber());
-            studentBean.setRootOrgId(student.getRootOrgId());
-            studentBean.setOrgId(student.getOrgId());
-            studentBean.setPhoneNumber(student.getPhoneNumber());
-            studentBean.setPhotoPath(student.getPhotoPath());
-            studentBean.setRemark(student.getRemark());
-            studentBean.setSecurityPhone(student.getSecurityPhone());
-
-            if (!studentBean.getRootOrgId().equals(rootOrgId)) {
+            if (!student.getRootOrgId().equals(rootOrgId)) {
                 throw new StatusException("500", "params error");
             }
-            list.add(studentBean);
+            list.add(toStudentBean(student));
         }
 
         GetStudentListByIdsResp resp = new GetStudentListByIdsResp();
@@ -315,4 +291,34 @@ public class StudentCloudServiceProvider extends ControllerSupport implements St
         return resp;
     }
 
+    @Override
+    @PostMapping("getStudentMaps")
+    @ApiOperation(value = "根据ID列表获取学生集合")
+    public GetStudentMapsResp getStudentMaps(@RequestBody GetStudentMapsReq req) {
+        Map<Long, StudentEntity> students = studentService.getStudentMapsByIds(req.getStudentIds());
+
+        Map<Long, StudentBean> studentMaps = new HashMap<>();
+        for (Map.Entry<Long, StudentEntity> entry : students.entrySet()) {
+            studentMaps.put(entry.getKey(), toStudentBean(entry.getValue()));
+        }
+
+        GetStudentMapsResp resp = new GetStudentMapsResp();
+        resp.setStudentMaps(studentMaps);
+        return resp;
+    }
+
+    private StudentBean toStudentBean(StudentEntity entity) {
+        StudentBean bean = new StudentBean();
+        bean.setRootOrgId(entity.getRootOrgId());
+        bean.setOrgId(entity.getOrgId());
+        bean.setId(entity.getId());
+        bean.setName(entity.getName());
+        bean.setIdentityNumber(entity.getIdentityNumber());
+        bean.setSecurityPhone(entity.getSecurityPhone());
+        bean.setPhoneNumber(entity.getPhoneNumber());
+        bean.setPhotoPath(entity.getPhotoPath());
+        bean.setRemark(entity.getRemark());
+        return bean;
+    }
+
 }

+ 51 - 47
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/StudentService.java

@@ -1,10 +1,12 @@
 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;
 
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * 类注释
  *
@@ -14,54 +16,56 @@ import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
  */
 public interface StudentService {
 
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param studentInfo
-	 * @return
-	 */
-	StudentEntity saveStudent(StudentInfo studentInfo);
+    /**
+     * 方法注释
+     *
+     * @param studentInfo
+     * @return
+     * @author WANGWEI
+     */
+    StudentEntity saveStudent(StudentInfo studentInfo);
+
+    /**
+     * 查询
+     *
+     * @param rootOrgId
+     * @param studentId
+     * @param identityNumber
+     * @param studentCode
+     * @param securityPhone
+     * @return
+     * @author WANGWEI
+     */
+    StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber,
+                               String studentCode, String securityPhone);
 
-	/**
-	 * 查询
-	 *
-	 * @author WANGWEI
-	 * @param rootOrgId
-	 * @param studentId
-	 * @param identityNumber
-	 * @param studentCode
-	 * @param securityPhone
-	 * @return
-	 */
-	StudentInfo getStudentInfo(Long rootOrgId, Long studentId, String identityNumber,
-			String studentCode, String securityPhone);
+    /**
+     * 解绑学号
+     *
+     * @param studentCode
+     * @param identityNumber
+     * @author WANGWEI
+     */
+    List<Long> unbindStudentCode(Long rootOrgId, String studentCode, String identityNumber);
 
-	/**
-	 * 解绑学号
-	 *
-	 * @author WANGWEI
-	 * @param studentCode
-	 * @param identityNumber
-	 */
-	List<Long> unbindStudentCode(Long rootOrgId, String studentCode, String identityNumber);
+    /**
+     * 解绑安全手机
+     *
+     * @param studentId
+     * @return
+     * @author WANGWEI
+     */
+    public void unbindSecurityPhone(Long studentId);
 
-	/**
-	 * 解绑安全手机
-	 *
-	 * @author WANGWEI
-	 * @param studentId
-	 * @return
-	 */
-	public void unbindSecurityPhone(Long studentId);
+    /**
+     * 手机号码是否被绑定
+     *
+     * @param securityPhone
+     * @return
+     * @author WANGWEI
+     */
+    Boolean hasBeBound(String securityPhone);
 
-	/**
-	 * 手机号码是否被绑定
-	 *
-	 * @author WANGWEI
-	 * @param securityPhone
-	 * @return
-	 */
-	Boolean hasBeBound(String securityPhone);
+    Map<Long, StudentEntity> getStudentMapsByIds(Set<Long> studentIds);
 
 }

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

@@ -1,18 +1,5 @@
 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.ByteUtil;
 import cn.com.qmth.examcloud.commons.util.SHA256;
@@ -33,6 +20,18 @@ import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.task.api.request.SyncStudentReq;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+
+import javax.persistence.criteria.Predicate;
+import javax.transaction.Transactional;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 学生服务类 Created by songyue on 17/1/14.
@@ -40,458 +39,473 @@ import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 @Service
 public class StudentServiceImpl implements StudentService {
 
-	@Autowired
-	StudentRepo studentRepo;
-
-	@Autowired
-	UserRepo userRepo;
-
-	@Autowired
-	StudentCodeRepo studentCodeRepo;
-
-	@Autowired
-	UserService userService;
-
-	@Autowired
-	OrgRepo orgRepo;
-
-	@Autowired
-	OrgServiceImpl orgService;
-
-	@Autowired
-	DataSyncCloudService dataSyncCloudService;
-
-	@Autowired
-	StudentCache studentCache;
-
-	@Autowired
-	OrgCache orgCache;
-
-	/*
-	 * 实现
-	 *
-	 * @author WANGWEI
-	 * 
-	 * @see cn.com.qmth.examcloud.core.basic.service.StudentService#
-	 * insertOrUpdateStudent(cn.com.qmth.examcloud.core.basic.service.bean.
-	 * StudentInfo)
-	 */
-	@Override
-	@Transactional
-	public StudentEntity saveStudent(StudentInfo studentInfo) {
-		Long rootOrgId = studentInfo.getRootOrgId();
-		OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
-
-		if (null == rootOrg || null != rootOrg.getParentId()) {
-			throw new StatusException("160001", "顶级机构错误");
-		}
-
-		String identityNumber = studentInfo.getIdentityNumber();
-		if (StringUtils.isBlank(identityNumber)) {
-			throw new StatusException("160012", "身份证号不能为空");
-		}
-
-		StudentEntity student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber,
-				rootOrgId);
-
-		OrgEntity org = null;
-		if (null != studentInfo.getOrgId()) {
-			org = GlobalHelper.getEntity(orgRepo, studentInfo.getOrgId(), OrgEntity.class);
-			if (null == org) {
-				throw new StatusException("160050", "orgId is wrong");
-			}
-			if (!org.getRootId().equals(rootOrgId)) {
-				throw new StatusException("160051", "orgId is wrong");
-			}
-			if (null == org.getParentId()) {
-				throw new StatusException("160052", "orgId is wrong");
-			}
-			if (!org.getParentId().equals(rootOrgId)) {
-				throw new StatusException("160053", "orgId is wrong");
-			}
-		} else if (StringUtils.isNotBlank(studentInfo.getOrgCode())) {
-			org = orgRepo.findByRootIdAndCode(rootOrgId, studentInfo.getOrgCode());
-			if (null == org) {
-				String orgName = studentInfo.getOrgName();
-				if (StringUtils.isBlank(orgName)) {
-					throw new StatusException("160003", "orgName is blank");
-				}
-				org = new OrgEntity();
-				org.setParentId(rootOrgId);
-				org.setCode(studentInfo.getOrgCode());
-				org.setName(orgName);
-				org.setEnable(true);
-				org.setRootId(rootOrgId);
-				org = orgRepo.save(org);
-			}
-		} else {
-			if (null != student) {
-				org = GlobalHelper.getEntity(orgRepo, student.getOrgId(), OrgEntity.class);
-			} else {
-				org = orgRepo.findByRootIdAndCode(rootOrgId, BasicConsts.DEFAULT_ORG_COEE);
-				if (null == org) {
-					org = new OrgEntity();
-					org.setParentId(rootOrgId);
-					org.setCode(BasicConsts.DEFAULT_ORG_COEE);
-					org.setName(BasicConsts.DEFAULT_ORG_NAME);
-					org.setEnable(true);
-					org.setRootId(rootOrgId);
-					org = orgRepo.save(org);
-				}
-			}
-		}
-
-		long updateTime = 0L;
-		if (null != student) {
-			if (null != student.getUpdateTime()) {
-				updateTime = student.getUpdateTime().getTime();
-			}
-			if (null == student.getEnable()) {
-				student.setEnable(true);
-			}
-		} else {
-			student = new StudentEntity();
-			student.setPasswordWeak(true);
-			student.setEnable(true);
-			String passwd=null;
+    @Autowired
+    StudentRepo studentRepo;
+
+    @Autowired
+    UserRepo userRepo;
+
+    @Autowired
+    StudentCodeRepo studentCodeRepo;
+
+    @Autowired
+    UserService userService;
+
+    @Autowired
+    OrgRepo orgRepo;
+
+    @Autowired
+    OrgServiceImpl orgService;
+
+    @Autowired
+    DataSyncCloudService dataSyncCloudService;
+
+    @Autowired
+    StudentCache studentCache;
+
+    @Autowired
+    OrgCache orgCache;
+
+    /*
+     * 实现
+     *
+     * @author WANGWEI
+     *
+     * @see cn.com.qmth.examcloud.core.basic.service.StudentService#
+     * insertOrUpdateStudent(cn.com.qmth.examcloud.core.basic.service.bean.
+     * StudentInfo)
+     */
+    @Override
+    @Transactional
+    public StudentEntity saveStudent(StudentInfo studentInfo) {
+        Long rootOrgId = studentInfo.getRootOrgId();
+        OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
+
+        if (null == rootOrg || null != rootOrg.getParentId()) {
+            throw new StatusException("160001", "顶级机构错误");
+        }
+
+        String identityNumber = studentInfo.getIdentityNumber();
+        if (StringUtils.isBlank(identityNumber)) {
+            throw new StatusException("160012", "身份证号不能为空");
+        }
+
+        StudentEntity student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber,
+                rootOrgId);
+
+        OrgEntity org = null;
+        if (null != studentInfo.getOrgId()) {
+            org = GlobalHelper.getEntity(orgRepo, studentInfo.getOrgId(), OrgEntity.class);
+            if (null == org) {
+                throw new StatusException("160050", "orgId is wrong");
+            }
+            if (!org.getRootId().equals(rootOrgId)) {
+                throw new StatusException("160051", "orgId is wrong");
+            }
+            if (null == org.getParentId()) {
+                throw new StatusException("160052", "orgId is wrong");
+            }
+            if (!org.getParentId().equals(rootOrgId)) {
+                throw new StatusException("160053", "orgId is wrong");
+            }
+        } else if (StringUtils.isNotBlank(studentInfo.getOrgCode())) {
+            org = orgRepo.findByRootIdAndCode(rootOrgId, studentInfo.getOrgCode());
+            if (null == org) {
+                String orgName = studentInfo.getOrgName();
+                if (StringUtils.isBlank(orgName)) {
+                    throw new StatusException("160003", "orgName is blank");
+                }
+                org = new OrgEntity();
+                org.setParentId(rootOrgId);
+                org.setCode(studentInfo.getOrgCode());
+                org.setName(orgName);
+                org.setEnable(true);
+                org.setRootId(rootOrgId);
+                org = orgRepo.save(org);
+            }
+        } else {
+            if (null != student) {
+                org = GlobalHelper.getEntity(orgRepo, student.getOrgId(), OrgEntity.class);
+            } else {
+                org = orgRepo.findByRootIdAndCode(rootOrgId, BasicConsts.DEFAULT_ORG_COEE);
+                if (null == org) {
+                    org = new OrgEntity();
+                    org.setParentId(rootOrgId);
+                    org.setCode(BasicConsts.DEFAULT_ORG_COEE);
+                    org.setName(BasicConsts.DEFAULT_ORG_NAME);
+                    org.setEnable(true);
+                    org.setRootId(rootOrgId);
+                    org = orgRepo.save(org);
+                }
+            }
+        }
+
+        long updateTime = 0L;
+        if (null != student) {
+            if (null != student.getUpdateTime()) {
+                updateTime = student.getUpdateTime().getTime();
+            }
+            if (null == student.getEnable()) {
+                student.setEnable(true);
+            }
+        } else {
+            student = new StudentEntity();
+            student.setPasswordWeak(true);
+            student.setEnable(true);
+            String passwd = null;
             if (StringUtils.isNotEmpty(identityNumber)
                     && identityNumber.matches("[0-9a-zA-Z]{6,}")) {
-            	passwd=StringUtils.substring(identityNumber, -6, identityNumber.length());
+                passwd = StringUtils.substring(identityNumber, -6, identityNumber.length());
             } else {
-            	passwd=BasicConsts.DEFAULT_PASSWORD;
+                passwd = BasicConsts.DEFAULT_PASSWORD;
             }
             byte[] bytes = SHA256.encode(identityNumber + passwd);
-	        String encodePassword = ByteUtil.toHexAscii(bytes);
-	        student.setPassword(encodePassword);
-
-			student.setRootOrgId(rootOrgId);
-			student.setIdentityNumber(identityNumber);
-		}
-
-		student.setOrgId(org.getId());
-		if (null != studentInfo.getName()) {
-			if (StringUtils.isBlank(studentInfo.getName())) {
-				throw new StatusException("160006", "姓名不能为空串");
-			}
-			student.setName(studentInfo.getName());
-		}
-		if (null != studentInfo.getPhotoPath()) {
-			student.setPhotoPath(studentInfo.getPhotoPath());
-		}
-		if (null != studentInfo.getPhoneNumber()) {
-			student.setPhoneNumber(studentInfo.getPhoneNumber());
-		}
-		if (null != studentInfo.getRemark()) {
-			student.setRemark(studentInfo.getRemark());
-		}
-		if (null != studentInfo.getEnable()) {
-			student.setEnable(studentInfo.getEnable());
-		}
-		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) {
-				if (StringUtils.isBlank(studentCode)) {
-					continue;
-				}
-				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();
-			req.setEnable(saved.getEnable());
-			req.setId(saved.getId());
-			req.setIdentityNumber(saved.getIdentityNumber());
-			req.setName(saved.getName());
-			req.setOrgCode(org.getCode());
-			req.setOrgId(org.getId());
-			req.setOrgName(org.getName());
-			req.setPhoneNumber(saved.getPhoneNumber());
-			req.setPhotoPath(saved.getPhotoPath());
-			req.setRootOrgId(saved.getRootOrgId());
-			req.setSecurityPhone(saved.getSecurityPhone());
-			req.setStudentCodeList(lastStudentCodeList);
-
-			req.setSyncType("update");
-
-			dataSyncCloudService.syncStudent(req);
-		}
-
-		studentCache.remove(saved.getId());
-		orgCache.remove(org.getId());
-
-		return saved;
-	}
-
-	/*
-	 * 实现
-	 *
-	 * @author WANGWEI
-	 * 
-	 * @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) {
-
-		StudentEntity s = null;
-		int count = 0;
-		if (null != studentId) {
-			count++;
-			s = GlobalHelper.getEntity(studentRepo, studentId, StudentEntity.class);
-		} else if (StringUtils.isNotBlank(securityPhone)) {
-			count++;
-			s = studentRepo.findBySecurityPhone(securityPhone);
-		} else if (null == rootOrgId) {
-			throw new StatusException("160250", "rootOrgId is null");
-		}
-
-		if (StringUtils.isNotBlank(identityNumber)) {
-			count++;
-			s = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
-		}
-		if (StringUtils.isNotBlank(studentCode)) {
-			count++;
-
-			StudentCodeEntity studentCodeEntity = studentCodeRepo
-					.findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
-			if (null != studentCodeEntity) {
-				s = GlobalHelper.getEntity(studentRepo, studentCodeEntity.getStudentId(),
-						StudentEntity.class);
-			}
-		}
-
-		if (count > 1) {
-			throw new StatusException("160210",
-					"参数过多,只需要[studentId,identityNumber,studentCode,securityPhone]中的一个");
-		}
-
-		if (null == s) {
-			throw new StatusException("160211", "学生不存在");
-		}
-
-		StudentInfo info = new StudentInfo();
-		info.setId(s.getId());
-		info.setEnable(s.getEnable());
-		info.setIdentityNumber(s.getIdentityNumber());
-		info.setName(s.getName());
-		info.setOrgId(s.getOrgId());
-		if (null != s.getOrgId()) {
-			OrgEntity org = GlobalHelper.getEntity(orgRepo, s.getOrgId(), OrgEntity.class);
-			if (null != org) {
-				info.setOrgCode(org.getCode());
-				info.setOrgName(org.getName());
-			}
-		}
-		info.setPhoneNumber(s.getPhoneNumber());
-
-		if (StringUtils.isNotBlank(s.getPhotoPath())) {
-//			String upyunDomain = PropertyHolder.getString("$upyun.site.1.domain");
-//			if (StringUtils.isBlank(upyunDomain)) {
-//				throw new StatusException("560111",
-//						"property[$upyun.site.1.domain] is not configured");
-//			}
-//			String path = UrlUtil.joinUrl(upyunDomain, "student_base_photo", s.getPhotoPath());
-//			info.setPhotoPath(path);
-			//通用存储
-			info.setPhotoPath(FileStorageUtil.realPath(FileStorageUtil.getIntactPath("student_base_photo", s.getPhotoPath())));
-		}
-
-		info.setRemark(s.getRemark());
-		info.setRootOrgId(s.getRootOrgId());
-		OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, s.getRootOrgId(), OrgEntity.class);
-		info.setRootOrgName(rootOrg.getName());
-		info.setSecurityPhone(s.getSecurityPhone());
-
-		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;
-	}
-
-	@Override
-	public List<Long> unbindStudentCode(Long rootOrgId, String studentCode, String identityNumber) {
-
-		if (null == rootOrgId) {
-			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) {
-			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) {
-			studentIdList.add(cur.getId());
-
-			SyncStudentReq req = new SyncStudentReq();
-			req.setEnable(cur.getEnable());
-			req.setId(cur.getId());
-			req.setIdentityNumber(cur.getIdentityNumber());
-			req.setName(cur.getName());
-
-			req.setOrgId(cur.getOrgId());
-			OrgEntity org = GlobalHelper.getEntity(orgRepo, cur.getOrgId(), OrgEntity.class);
-			req.setOrgCode(org.getCode());
-			req.setOrgName(org.getName());
-
-			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");
-
-			dataSyncCloudService.syncStudent(req);
-		}
-
-		for (Long cur : studentIdList) {
-			studentCache.remove(cur);
-		}
-
-		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);
-
-		studentCache.remove(studentId);
-	}
-
-	@Override
-	public Boolean hasBeBound(String securityPhone) {
-
-		StudentEntity s = studentRepo.findBySecurityPhone(securityPhone);
-		return null != s;
-	}
+            String encodePassword = ByteUtil.toHexAscii(bytes);
+            student.setPassword(encodePassword);
+
+            student.setRootOrgId(rootOrgId);
+            student.setIdentityNumber(identityNumber);
+        }
+
+        student.setOrgId(org.getId());
+        if (null != studentInfo.getName()) {
+            if (StringUtils.isBlank(studentInfo.getName())) {
+                throw new StatusException("160006", "姓名不能为空串");
+            }
+            student.setName(studentInfo.getName());
+        }
+        if (null != studentInfo.getPhotoPath()) {
+            student.setPhotoPath(studentInfo.getPhotoPath());
+        }
+        if (null != studentInfo.getPhoneNumber()) {
+            student.setPhoneNumber(studentInfo.getPhoneNumber());
+        }
+        if (null != studentInfo.getRemark()) {
+            student.setRemark(studentInfo.getRemark());
+        }
+        if (null != studentInfo.getEnable()) {
+            student.setEnable(studentInfo.getEnable());
+        }
+        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) {
+                if (StringUtils.isBlank(studentCode)) {
+                    continue;
+                }
+                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();
+            req.setEnable(saved.getEnable());
+            req.setId(saved.getId());
+            req.setIdentityNumber(saved.getIdentityNumber());
+            req.setName(saved.getName());
+            req.setOrgCode(org.getCode());
+            req.setOrgId(org.getId());
+            req.setOrgName(org.getName());
+            req.setPhoneNumber(saved.getPhoneNumber());
+            req.setPhotoPath(saved.getPhotoPath());
+            req.setRootOrgId(saved.getRootOrgId());
+            req.setSecurityPhone(saved.getSecurityPhone());
+            req.setStudentCodeList(lastStudentCodeList);
+
+            req.setSyncType("update");
+
+            dataSyncCloudService.syncStudent(req);
+        }
+
+        studentCache.remove(saved.getId());
+        orgCache.remove(org.getId());
+
+        return saved;
+    }
+
+    /*
+     * 实现
+     *
+     * @author WANGWEI
+     *
+     * @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) {
+
+        StudentEntity s = null;
+        int count = 0;
+        if (null != studentId) {
+            count++;
+            s = GlobalHelper.getEntity(studentRepo, studentId, StudentEntity.class);
+        } else if (StringUtils.isNotBlank(securityPhone)) {
+            count++;
+            s = studentRepo.findBySecurityPhone(securityPhone);
+        } else if (null == rootOrgId) {
+            throw new StatusException("160250", "rootOrgId is null");
+        }
+
+        if (StringUtils.isNotBlank(identityNumber)) {
+            count++;
+            s = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
+        }
+        if (StringUtils.isNotBlank(studentCode)) {
+            count++;
+
+            StudentCodeEntity studentCodeEntity = studentCodeRepo
+                    .findByStudentCodeAndRootOrgId(studentCode, rootOrgId);
+            if (null != studentCodeEntity) {
+                s = GlobalHelper.getEntity(studentRepo, studentCodeEntity.getStudentId(),
+                        StudentEntity.class);
+            }
+        }
+
+        if (count > 1) {
+            throw new StatusException("160210",
+                    "参数过多,只需要[studentId,identityNumber,studentCode,securityPhone]中的一个");
+        }
+
+        if (null == s) {
+            throw new StatusException("160211", "学生不存在");
+        }
+
+        StudentInfo info = new StudentInfo();
+        info.setId(s.getId());
+        info.setEnable(s.getEnable());
+        info.setIdentityNumber(s.getIdentityNumber());
+        info.setName(s.getName());
+        info.setOrgId(s.getOrgId());
+        if (null != s.getOrgId()) {
+            OrgEntity org = GlobalHelper.getEntity(orgRepo, s.getOrgId(), OrgEntity.class);
+            if (null != org) {
+                info.setOrgCode(org.getCode());
+                info.setOrgName(org.getName());
+            }
+        }
+        info.setPhoneNumber(s.getPhoneNumber());
+
+        if (StringUtils.isNotBlank(s.getPhotoPath())) {
+            //			String upyunDomain = PropertyHolder.getString("$upyun.site.1.domain");
+            //			if (StringUtils.isBlank(upyunDomain)) {
+            //				throw new StatusException("560111",
+            //						"property[$upyun.site.1.domain] is not configured");
+            //			}
+            //			String path = UrlUtil.joinUrl(upyunDomain, "student_base_photo", s.getPhotoPath());
+            //			info.setPhotoPath(path);
+            //通用存储
+            info.setPhotoPath(FileStorageUtil.realPath(FileStorageUtil.getIntactPath("student_base_photo", s.getPhotoPath())));
+        }
+
+        info.setRemark(s.getRemark());
+        info.setRootOrgId(s.getRootOrgId());
+        OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, s.getRootOrgId(), OrgEntity.class);
+        info.setRootOrgName(rootOrg.getName());
+        info.setSecurityPhone(s.getSecurityPhone());
+
+        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;
+    }
+
+    @Override
+    public List<Long> unbindStudentCode(Long rootOrgId, String studentCode, String identityNumber) {
+
+        if (null == rootOrgId) {
+            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) {
+            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) {
+            studentIdList.add(cur.getId());
+
+            SyncStudentReq req = new SyncStudentReq();
+            req.setEnable(cur.getEnable());
+            req.setId(cur.getId());
+            req.setIdentityNumber(cur.getIdentityNumber());
+            req.setName(cur.getName());
+
+            req.setOrgId(cur.getOrgId());
+            OrgEntity org = GlobalHelper.getEntity(orgRepo, cur.getOrgId(), OrgEntity.class);
+            req.setOrgCode(org.getCode());
+            req.setOrgName(org.getName());
+
+            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");
+
+            dataSyncCloudService.syncStudent(req);
+        }
+
+        for (Long cur : studentIdList) {
+            studentCache.remove(cur);
+        }
+
+        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);
+
+        studentCache.remove(studentId);
+    }
+
+    @Override
+    public Boolean hasBeBound(String securityPhone) {
+        StudentEntity s = studentRepo.findBySecurityPhone(securityPhone);
+        return null != s;
+    }
+
+    @Override
+    public Map<Long, StudentEntity> getStudentMapsByIds(Set<Long> studentIds) {
+        if (CollectionUtils.isEmpty(studentIds)) {
+            return new HashMap<>();
+        }
+
+        Specification<StudentEntity> spec = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+            predicates.add(root.get("id").in(studentIds));
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+
+        List<StudentEntity> entities = studentRepo.findAll(spec);
+        return entities.stream().collect(Collectors.toMap(v -> v.getId(), v -> v, (k, v) -> v));
+    }
 
 }