wangwei hace 6 años
padre
commit
0c8bde17e3

+ 27 - 41
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamController.java

@@ -77,7 +77,7 @@ import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseGroupRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseGroupSettingsRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamSpecialSettingsRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
@@ -87,13 +87,13 @@ import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseGroupSettingsEnt
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgPropertyEntity;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
 import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
-import cn.com.qmth.examcloud.core.examwork.service.bean.ExamOrgSettingsInfo;
+import cn.com.qmth.examcloud.core.examwork.service.bean.ExamSpecialSettingsInfo;
 import cn.com.qmth.examcloud.core.examwork.service.impl.ExamServiceImpl;
 import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentServiceImpl;
 import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
@@ -137,7 +137,7 @@ public class ExamController extends ControllerSupport {
 	ExamCourseGroupSettingsRepo examCourseGroupSettingsRepo;
 
 	@Autowired
-	ExamOrgSettingsRepo examOrgSettingsRepo;
+	ExamSpecialSettingsRepo examSpecialSettingsRepo;
 
 	@Autowired
 	ExamCourseGroupRelationRepo examCourseGroupRelationRepo;
@@ -913,26 +913,29 @@ public class ExamController extends ControllerSupport {
 		}
 		validateRootOrgIsolation(examEntity.getRootOrgId());
 
-		Specification<ExamOrgSettingsEntity> specification = (root, query, cb) -> {
+		Specification<ExamSpecialSettingsEntity> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
-
 			predicates.add(cb.equal(root.get("examId"), examOrgDomain.getExamId()));
+			predicates.add(cb.isNull(root.get("courseId")));
 
 			if (null != examOrgDomain.getOrgId()) {
 				predicates.add(cb.equal(root.get("orgId"), examOrgDomain.getOrgId()));
+			} else {
+				predicates.add(cb.isNotNull(root.get("orgId")));
 			}
 
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
 		Pageable pageable = new PageRequest(curPage, pageSize, Sort.Direction.DESC, "updateTime");
-		Page<ExamOrgSettingsEntity> page = examOrgSettingsRepo.findAll(specification, pageable);
+		Page<ExamSpecialSettingsEntity> page = examSpecialSettingsRepo.findAll(specification,
+				pageable);
 
-		Iterator<ExamOrgSettingsEntity> iterator = page.iterator();
+		Iterator<ExamSpecialSettingsEntity> iterator = page.iterator();
 		List<ExamOrgSettingsDomain> domainList = Lists.newArrayList();
 
 		while (iterator.hasNext()) {
-			ExamOrgSettingsEntity next = iterator.next();
+			ExamSpecialSettingsEntity next = iterator.next();
 			ExamOrgSettingsDomain bean = new ExamOrgSettingsDomain();
 			domainList.add(bean);
 
@@ -984,8 +987,8 @@ public class ExamController extends ControllerSupport {
 		StudentBean student = getStudent(accessUser.getUserId());
 		Long orgId = student.getOrgId();
 
-		ExamOrgSettingsEntity examOrgEntity = examOrgSettingsRepo.findByExamIdAndOrgId(examId,
-				orgId);
+		ExamSpecialSettingsEntity examOrgEntity = examSpecialSettingsRepo
+				.findByExamIdAndOrgIdAndCourseIdIsNull(examId, orgId);
 
 		ExamDomain domain = new ExamDomain();
 		domain.setBeginTime(examEntity.getBeginTime());
@@ -1024,7 +1027,7 @@ public class ExamController extends ControllerSupport {
 	 */
 	@ApiOperation(value = "新增考试相关的学习中心设置", notes = "")
 	@PostMapping("examOrgSettings")
-	public ExamOrgSettingsEntity addExamOrgSettings(@RequestBody ExamOrgSettingsDomain domain) {
+	public ExamSpecialSettingsEntity addExamOrgSettings(@RequestBody ExamOrgSettingsDomain domain) {
 		return saveExamOrgSettings(domain);
 	}
 
@@ -1037,7 +1040,8 @@ public class ExamController extends ControllerSupport {
 	 */
 	@ApiOperation(value = "更新考试相关的学习中心设置", notes = "")
 	@PutMapping("examOrgSettings")
-	public ExamOrgSettingsEntity updateExamOrgSettings(@RequestBody ExamOrgSettingsDomain domain) {
+	public ExamSpecialSettingsEntity updateExamOrgSettings(
+			@RequestBody ExamOrgSettingsDomain domain) {
 		return saveExamOrgSettings(domain);
 	}
 
@@ -1048,7 +1052,7 @@ public class ExamController extends ControllerSupport {
 	 * @param domain
 	 * @return
 	 */
-	private ExamOrgSettingsEntity saveExamOrgSettings(ExamOrgSettingsDomain domain) {
+	private ExamSpecialSettingsEntity saveExamOrgSettings(ExamOrgSettingsDomain domain) {
 		Long examId = domain.getExamId();
 
 		ExamEntity examEntity = examRepo.findOne(examId);
@@ -1067,7 +1071,7 @@ public class ExamController extends ControllerSupport {
 		validateRootOrgIsolation(org.getRootId());
 
 		User accessUser = getAccessUser();
-		ExamOrgSettingsInfo info = new ExamOrgSettingsInfo();
+		ExamSpecialSettingsInfo info = new ExamSpecialSettingsInfo();
 		info.setId(domain.getId());
 		info.setBeginTime(domain.getBeginTime());
 		info.setEndTime(domain.getEndTime());
@@ -1082,7 +1086,7 @@ public class ExamController extends ControllerSupport {
 		}
 		info.setProperties(domain.getProperties());
 
-		ExamOrgSettingsEntity ret = examService.saveExamOrgSettings(info);
+		ExamSpecialSettingsEntity ret = examService.saveExamSpecialSettings(info);
 		return ret;
 	}
 
@@ -1118,9 +1122,10 @@ public class ExamController extends ControllerSupport {
 
 		List<Object[]> datas = Lists.newArrayList();
 
-		List<ExamOrgSettingsEntity> orgSettingsList = examOrgSettingsRepo.findAllByExamId(examId);
+		List<ExamSpecialSettingsEntity> orgSettingsList = examSpecialSettingsRepo
+				.findAllByExamIdAndCourseIdIsNullAndOrgIdIsNotNull(examId);
 		Set<Long> orgIdSet = Sets.newHashSet();
-		for (ExamOrgSettingsEntity cur : orgSettingsList) {
+		for (ExamSpecialSettingsEntity cur : orgSettingsList) {
 			orgIdSet.add(cur.getOrgId());
 			OrgBean orgBean = orgMap.get(cur.getOrgId());
 			String examLimit = null == cur.getExamLimit() ? "否" : cur.getExamLimit() ? "否" : "是";
@@ -1181,25 +1186,6 @@ public class ExamController extends ControllerSupport {
 		return map;
 	}
 
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param examId
-	 * @param orgId
-	 */
-	@ApiOperation(value = "删除考试相关的学习中心设置", notes = "")
-	@DeleteMapping("examOrg/{examId}/{orgId}")
-	public void deleteExamOrg(@PathVariable Long examId, @PathVariable Long orgId) {
-		ExamEntity examEntity = examRepo.findOne(examId);
-		if (null == examEntity) {
-			throw new StatusException("E-001250", "examId is wrong");
-		}
-		validateRootOrgIsolation(examEntity.getRootOrgId());
-
-		examOrgSettingsRepo.deleteByExamIdAndOrgId(examId, orgId);
-	}
-
 	@ApiOperation(value = "学习中心禁考", notes = "")
 	@PutMapping("setOrgExamLimited/{ids}")
 	public List<String> setOrgExamLimited(@PathVariable String ids) {
@@ -1207,9 +1193,9 @@ public class ExamController extends ControllerSupport {
 				.collect(Collectors.toList());
 		List<String> ret = Lists.newArrayList();
 		for (Long cur : orgSettingsIds) {
-			ExamOrgSettingsEntity entity = examOrgSettingsRepo.findOne(cur);
+			ExamSpecialSettingsEntity entity = examSpecialSettingsRepo.findOne(cur);
 			entity.setExamLimit(true);
-			examOrgSettingsRepo.save(entity);
+			examSpecialSettingsRepo.save(entity);
 			ret.add(entity.getExamId() + ":" + entity.getOrgId());
 		}
 		return ret;
@@ -1222,9 +1208,9 @@ public class ExamController extends ControllerSupport {
 				.collect(Collectors.toList());
 		List<String> ret = Lists.newArrayList();
 		for (Long cur : orgSettingsIds) {
-			ExamOrgSettingsEntity entity = examOrgSettingsRepo.findOne(cur);
+			ExamSpecialSettingsEntity entity = examSpecialSettingsRepo.findOne(cur);
 			entity.setExamLimit(false);
-			examOrgSettingsRepo.save(entity);
+			examSpecialSettingsRepo.save(entity);
 			ret.add(entity.getExamId() + ":" + entity.getOrgId());
 		}
 		return ret;

+ 5 - 5
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamCloudServiceProvider.java

@@ -32,14 +32,14 @@ import cn.com.qmth.examcloud.commons.web.enums.DataExecutionStatus;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamSpecialSettingsRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
@@ -96,7 +96,7 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 	private ExamServiceImpl examService;
 
 	@Autowired
-	ExamOrgSettingsRepo examOrgSettingsRepo;
+	ExamSpecialSettingsRepo examSpecialSettingsRepo;
 
 	@Autowired
 	ExamRepo examRepo;
@@ -195,8 +195,8 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 
 		Long orgId = req.getOrgId();
 		if (null != orgId) {
-			ExamOrgSettingsEntity examOrgEntity = examOrgSettingsRepo
-					.findByExamIdAndOrgId(exam.getId(), orgId);
+			ExamSpecialSettingsEntity examOrgEntity = examSpecialSettingsRepo
+					.findByExamIdAndOrgIdAndCourseIdIsNull(exam.getId(), orgId);
 			if (null != examOrgEntity) {
 				if (null != examOrgEntity.getBeginTime()) {
 					bean.setBeginTime(examOrgEntity.getBeginTime());

+ 0 - 34
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamOrgSettingsRepo.java

@@ -1,34 +0,0 @@
-package cn.com.qmth.examcloud.core.examwork.dao;
-
-import java.util.List;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-import org.springframework.data.jpa.repository.Modifying;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-import org.springframework.transaction.annotation.Transactional;
-
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
-
-public interface ExamOrgSettingsRepo
-		extends
-			JpaRepository<ExamOrgSettingsEntity, Long>,
-			QueryByExampleExecutor<ExamOrgSettingsEntity>,
-			JpaSpecificationExecutor<ExamOrgSettingsEntity> {
-
-	@Transactional
-	@Modifying
-	@Query("delete from ExamOrgSettingsEntity where examId = ?1")
-	void deleteByExamId(Long examId);
-
-	@Transactional
-	@Modifying
-	@Query("delete from ExamOrgSettingsEntity where examId = ?1 and orgId = ?2")
-	void deleteByExamIdAndOrgId(Long examId, Long orgId);
-
-	ExamOrgSettingsEntity findByExamIdAndOrgId(Long examId, Long orgId);
-
-	List<ExamOrgSettingsEntity> findAllByExamId(Long examId);
-
-}

+ 21 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamSpecialSettingsRepo.java

@@ -0,0 +1,21 @@
+package cn.com.qmth.examcloud.core.examwork.dao;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
+
+public interface ExamSpecialSettingsRepo
+		extends
+			JpaRepository<ExamSpecialSettingsEntity, Long>,
+			QueryByExampleExecutor<ExamSpecialSettingsEntity>,
+			JpaSpecificationExecutor<ExamSpecialSettingsEntity> {
+
+	ExamSpecialSettingsEntity findByExamIdAndOrgIdAndCourseIdIsNull(Long examId, Long orgId);
+
+	List<ExamSpecialSettingsEntity> findAllByExamIdAndCourseIdIsNullAndOrgIdIsNotNull(Long examId);
+
+}

+ 15 - 8
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamOrgSettingsEntity.java → examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamSpecialSettingsEntity.java

@@ -14,16 +14,16 @@ import org.springframework.format.annotation.DateTimeFormat;
 import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
 
 /**
- * 考试--机构特殊设置
+ * 考试--特殊设置
  *
  * @author WANGWEI
  * @date 2018年5月16日
  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  */
 @Entity
-@Table(name = "EC_E_EXAM_ORG_SETTINGS", indexes = {
-		@Index(name = "IDX_E_E_O_S_001001", columnList = "examId,orgId", unique = true)})
-public class ExamOrgSettingsEntity extends JpaEntity {
+@Table(name = "EC_E_EXAM_SPECIAL_SETTINGS", indexes = {
+		@Index(name = "IDX_E_E_S_S_001001", columnList = "examId,courseId,orgId", unique = true)})
+public class ExamSpecialSettingsEntity extends JpaEntity {
 
 	private static final long serialVersionUID = -3335725218626631530L;
 
@@ -38,17 +38,23 @@ public class ExamOrgSettingsEntity extends JpaEntity {
 	private Long examId;
 
 	/**
-	 * 顶级机构ID
+	 * 考试ID
 	 */
-	@Column(nullable = false)
-	private Long rootOrgId;
+	@Column(nullable = true)
+	private Long courseId;
 
 	/**
 	 * 机构ID
 	 */
-	@Column(nullable = false)
+	@Column(nullable = true)
 	private Long orgId;
 
+	/**
+	 * 顶级机构ID
+	 */
+	@Column(nullable = false)
+	private Long rootOrgId;
+
 	/**
 	 * 考试批次开始时间
 	 */
@@ -64,6 +70,7 @@ public class ExamOrgSettingsEntity extends JpaEntity {
 	/**
 	 * 是否禁止考试
 	 */
+	@Column(nullable = false)
 	private Boolean examLimit;
 
 	public Long getId() {

+ 3 - 3
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/ExamService.java

@@ -6,9 +6,9 @@ import java.util.Map;
 
 import cn.com.qmth.examcloud.commons.web.enums.DataExecutionStatus;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
 import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
-import cn.com.qmth.examcloud.core.examwork.service.bean.ExamOrgSettingsInfo;
+import cn.com.qmth.examcloud.core.examwork.service.bean.ExamSpecialSettingsInfo;
 
 /**
  * 类注释
@@ -35,7 +35,7 @@ public interface ExamService {
 	 * @param examInfo
 	 * @return
 	 */
-	ExamOrgSettingsEntity saveExamOrgSettings(ExamOrgSettingsInfo examOrgInfo);
+	ExamSpecialSettingsEntity saveExamSpecialSettings(ExamSpecialSettingsInfo examOrgInfo);
 
 	/**
 	 * 查询机构属性

+ 1 - 1
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/bean/ExamOrgSettingsInfo.java → examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/bean/ExamSpecialSettingsInfo.java

@@ -12,7 +12,7 @@ import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
  * @date 2018年5月16日
  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  */
-public class ExamOrgSettingsInfo implements JsonSerializable {
+public class ExamSpecialSettingsInfo implements JsonSerializable {
 
 	private static final long serialVersionUID = -3335725218626631530L;
 

+ 39 - 35
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamServiceImpl.java

@@ -31,16 +31,17 @@ import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
 import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
 import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgPropertyRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamSpecialSettingsRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamPropertyRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgPropertyEntity;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgSettingsEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamSpecialSettingsEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPropertyEntity;
 import cn.com.qmth.examcloud.core.examwork.service.ExamService;
+import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
 import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
-import cn.com.qmth.examcloud.core.examwork.service.bean.ExamOrgSettingsInfo;
+import cn.com.qmth.examcloud.core.examwork.service.bean.ExamSpecialSettingsInfo;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.task.api.request.SyncExamReq;
 
@@ -57,10 +58,10 @@ public class ExamServiceImpl implements ExamService {
 	ExamRepo examRepo;
 
 	@Autowired
-	ExamStudentServiceImpl examStudentService;
+	ExamStudentService examStudentService;
 
 	@Autowired
-	ExamOrgSettingsRepo examOrgSettingsRepo;
+	ExamSpecialSettingsRepo examSpecialSettingsRepo;
 
 	@Autowired
 	OrgCloudService orgCloudService;
@@ -312,32 +313,35 @@ public class ExamServiceImpl implements ExamService {
 	 * com.qmth.examcloud.core.examwork.service.bean.ExamOrgInfo)
 	 */
 	@Override
-	public ExamOrgSettingsEntity saveExamOrgSettings(ExamOrgSettingsInfo examOrgInfo) {
-		ExamOrgSettingsEntity examOrgEntity = null;
+	public ExamSpecialSettingsEntity saveExamSpecialSettings(
+			ExamSpecialSettingsInfo examSpecialInfo) {
+		ExamSpecialSettingsEntity examOrgEntity = null;
 
-		if (null == examOrgInfo.getId()) {
-			examOrgEntity = examOrgSettingsRepo.findByExamIdAndOrgId(examOrgInfo.getExamId(),
-					examOrgInfo.getOrgId());
+		if (null == examSpecialInfo.getId()) {
+			examOrgEntity = examSpecialSettingsRepo.findByExamIdAndOrgIdAndCourseIdIsNull(
+					examSpecialInfo.getExamId(), examSpecialInfo.getOrgId());
 			if (null == examOrgEntity) {
-				examOrgEntity = new ExamOrgSettingsEntity();
+				examOrgEntity = new ExamSpecialSettingsEntity();
 			}
 		} else {
-			examOrgEntity = examOrgSettingsRepo.findOne(examOrgInfo.getId());
+			examOrgEntity = examSpecialSettingsRepo.findOne(examSpecialInfo.getId());
 			if (null == examOrgEntity) {
 				throw new StatusException("E-001101", "id is wrong");
 			}
 		}
 
-		examOrgEntity.setBeginTime(examOrgInfo.getBeginTime());
-		examOrgEntity.setEndTime(examOrgInfo.getEndTime());
-		examOrgEntity.setRootOrgId(examOrgInfo.getRootOrgId());
-		examOrgEntity.setExamId(examOrgInfo.getExamId());
-		examOrgEntity.setOrgId(examOrgInfo.getOrgId());
-		examOrgEntity.setExamLimit(examOrgInfo.getExamLimit());
+		examOrgEntity.setBeginTime(examSpecialInfo.getBeginTime());
+		examOrgEntity.setEndTime(examSpecialInfo.getEndTime());
+		examOrgEntity.setRootOrgId(examSpecialInfo.getRootOrgId());
+		examOrgEntity.setExamId(examSpecialInfo.getExamId());
+		examOrgEntity.setOrgId(examSpecialInfo.getOrgId());
+		Boolean examLimit = examSpecialInfo.getExamLimit();
+		examLimit = null == examLimit ? false : examLimit;
+		examOrgEntity.setExamLimit(examLimit);
 
-		Map<DynamicEnum, String> map = checkAndGetExamProperties(examOrgInfo.getProperties());
+		Map<DynamicEnum, String> map = checkAndGetExamProperties(examSpecialInfo.getProperties());
 
-		ExamOrgSettingsEntity saved = examOrgSettingsRepo.save(examOrgEntity);
+		ExamSpecialSettingsEntity saved = examSpecialSettingsRepo.save(examOrgEntity);
 
 		for (Entry<DynamicEnum, String> entry : map.entrySet()) {
 			DynamicEnum de = entry.getKey();
@@ -406,7 +410,7 @@ public class ExamServiceImpl implements ExamService {
 
 		List<Map<String, Object>> failRecords = Collections
 				.synchronizedList(new ArrayList<Map<String, Object>>());
-		List<ExamOrgSettingsEntity> orgSettingsList = Lists.newArrayList();
+		List<ExamSpecialSettingsEntity> specialSettingsList = Lists.newArrayList();
 
 		for (int i = 0; i < lineList.size(); i++) {
 			String[] line = lineList.get(i);
@@ -420,9 +424,9 @@ public class ExamServiceImpl implements ExamService {
 			boolean hasError = false;
 			StringBuilder msg = new StringBuilder();
 
-			ExamOrgSettingsEntity orgSettings = new ExamOrgSettingsEntity();
-			orgSettings.setRootOrgId(examEntity.getRootOrgId());
-			orgSettings.setExamId(examId);
+			ExamSpecialSettingsEntity specialSettings = new ExamSpecialSettingsEntity();
+			specialSettings.setRootOrgId(examEntity.getRootOrgId());
+			specialSettings.setExamId(examId);
 
 			String orgId = trimAndNullIfBlank(line[0]);
 			if (StringUtils.isBlank(orgId)) {
@@ -442,7 +446,7 @@ public class ExamServiceImpl implements ExamService {
 						msg.append("  学习中心ID非法");
 						hasError = true;
 					} else {
-						orgSettings.setOrgId(orgIdLong);
+						specialSettings.setOrgId(orgIdLong);
 					}
 				} catch (NumberFormatException e) {
 					msg.append("  学习中心ID必须为整数");
@@ -453,9 +457,9 @@ public class ExamServiceImpl implements ExamService {
 			String examLimit = trimAndNullIfBlank(line[3]);
 			if (StringUtils.isNotBlank(examLimit)) {
 				if (examLimit.equals("是")) {
-					orgSettings.setExamLimit(false);
+					specialSettings.setExamLimit(false);
 				} else if (examLimit.equals("否")) {
-					orgSettings.setExamLimit(true);
+					specialSettings.setExamLimit(true);
 				} else {
 					msg.append("  是否可以开始考试必须为['是','否',空]");
 					hasError = true;
@@ -466,7 +470,7 @@ public class ExamServiceImpl implements ExamService {
 			if (StringUtils.isNotBlank(beginTime)) {
 				try {
 					Date beginDate = DateUtil.parse(beginTime, DatePatterns.ISO);
-					orgSettings.setBeginTime(beginDate);
+					specialSettings.setBeginTime(beginDate);
 				} catch (Exception e) {
 					msg.append("  开始考试时间格式错误. 正确格式为 " + DatePatterns.ISO);
 					hasError = true;
@@ -476,7 +480,7 @@ public class ExamServiceImpl implements ExamService {
 			if (StringUtils.isNotBlank(endTime)) {
 				try {
 					Date endDate = DateUtil.parse(endTime, DatePatterns.ISO);
-					orgSettings.setEndTime(endDate);
+					specialSettings.setEndTime(endDate);
 				} catch (Exception e) {
 					msg.append("  结束考试时间格式错误. 正确格式为 " + DatePatterns.ISO);
 					hasError = true;
@@ -486,7 +490,7 @@ public class ExamServiceImpl implements ExamService {
 			if (hasError) {
 				failRecords.add(newError(i + 1, msg.toString()));
 			} else {
-				orgSettingsList.add(orgSettings);
+				specialSettingsList.add(specialSettings);
 			}
 
 		}
@@ -495,17 +499,17 @@ public class ExamServiceImpl implements ExamService {
 			return failRecords;
 		}
 
-		for (ExamOrgSettingsEntity cur : orgSettingsList) {
-			ExamOrgSettingsEntity query = examOrgSettingsRepo.findByExamIdAndOrgId(examId,
-					cur.getOrgId());
+		for (ExamSpecialSettingsEntity cur : specialSettingsList) {
+			ExamSpecialSettingsEntity query = examSpecialSettingsRepo
+					.findByExamIdAndOrgIdAndCourseIdIsNull(examId, cur.getOrgId());
 
 			if (null != query) {
 				query.setExamLimit(cur.getExamLimit());
 				query.setBeginTime(cur.getBeginTime());
 				query.setEndTime(cur.getEndTime());
-				examOrgSettingsRepo.save(query);
+				examSpecialSettingsRepo.save(query);
 			} else {
-				examOrgSettingsRepo.save(cur);
+				examSpecialSettingsRepo.save(cur);
 			}
 		}
 

+ 370 - 374
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentServiceImpl.java

@@ -1,374 +1,370 @@
-package cn.com.qmth.examcloud.core.examwork.service.impl;
-
-import java.util.List;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
-import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
-import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
-import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
-import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
-import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
-import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
-import cn.com.qmth.examcloud.core.basic.api.bean.StudentBean;
-import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
-import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
-import cn.com.qmth.examcloud.core.basic.api.request.SaveCourseReq;
-import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
-import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
-import cn.com.qmth.examcloud.core.basic.api.response.SaveCourseResp;
-import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntity;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
-import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
-import cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
-import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
-import cn.com.qmth.examcloud.core.oe.admin.api.request.CheckExamIsStartedReq;
-import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
-import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
-import cn.com.qmth.examcloud.task.api.request.SyncExamStudentReq;
-
-/**
- * 考试学生服务类 Created by songyue on 17/1/14.
- */
-@Service
-public class ExamStudentServiceImpl implements ExamStudentService {
-
-	@Autowired
-	ExamStudentRepo examStudentRepo;
-
-	@Autowired
-	ExamRepo examRepo;
-
-	@Autowired
-	ExamOrgSettingsRepo examOrgRepo;
-
-	@Autowired
-	OrgCloudService orgCloudService;
-
-	@Autowired
-	ExamStudentServiceImpl examStudentService;
-
-	@Autowired
-	StudentCloudService studentCloudService;
-
-	@Autowired
-	CourseCloudService courseCloudService;
-
-	@Autowired
-	ExamCourseRelationRepo examCourseRelationRepo;
-
-	@Autowired
-	DataSyncCloudService dataSyncCloudService;
-
-	@Autowired
-	ExamRecordCloudService examRecordCloudService;
-
-	@Autowired
-	ExamPaperTypeRelationRepo examPaperTypeRelationRepo;
-
-	/**
-	 * 是否强制删除考生
-	 *
-	 * @author WANGWEI
-	 * @return
-	 */
-	private boolean forceDeleteExamStudent() {
-		boolean b = PropertiesUtil.getBoolean("$deleteExamStudent.force", false);
-		return b;
-	}
-
-	/**
-	 * 是否开考
-	 *
-	 * @author WANGWEI
-	 * @param examId
-	 * @param StudentId
-	 * @param courseId
-	 * @return
-	 */
-	private boolean isStarted(Long examId, Long StudentId, Long courseId) {
-		CheckExamIsStartedReq checkExamIsStartedReq = new CheckExamIsStartedReq();
-		checkExamIsStartedReq.setExamId(examId);
-		checkExamIsStartedReq.setCourseId(courseId);
-		checkExamIsStartedReq.setStudentId(StudentId);
-		CheckExamIsStartedResp checkExamIsStartedResp = examRecordCloudService
-				.checkExamIsStarted(checkExamIsStartedReq);
-		return checkExamIsStartedResp.getIsStarted();
-	}
-
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param ids
-	 */
-	@Override
-	public void deleteExamStudentsByStudentIds(List<Long> ids) {
-		List<ExamStudentEntity> examStudents = examStudentRepo.findByIdIn(ids);
-
-		for (ExamStudentEntity examStudent : examStudents) {
-			// 网考判断
-			if ((!forceDeleteExamStudent()) && isStarted(examStudent.getExamId(), null, null)) {
-				throw new StatusException("E-150112", examStudent.getName() + "已开始考试,不能删除");
-			}
-			examStudentRepo.delete(examStudent);
-
-			List<ExamStudentEntity> top2 = examStudentRepo.findTop2ByExamIdAndCourseId(
-					examStudent.getExamId(), examStudent.getCourseId());
-			if (1 > top2.size()) {
-				examCourseRelationRepo.deleteByExamIdAndCourseId(examStudent.getExamId(),
-						examStudent.getCourseId());
-			}
-
-			top2 = examStudentRepo.findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
-					examStudent.getCourseId(), examStudent.getPaperType());
-			if (1 > top2.size()) {
-				examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
-						examStudent.getExamId(), examStudent.getCourseId(),
-						examStudent.getPaperType());
-			}
-		}
-
-		for (ExamStudentEntity cur : examStudents) {
-			// 同步操作
-			SyncExamStudentReq req = new SyncExamStudentReq();
-			req.setSyncType("delete");
-			req.setId(cur.getId());
-			req.setCourseId(cur.getId());
-			req.setCourseCode(cur.getCourseCode());
-			req.setCourseName(cur.getCourseName());
-			req.setExamId(cur.getId());
-			req.setStudentId(cur.getStudentId());
-			req.setStudentName(cur.getName());
-			req.setIdentityNumber(cur.getIdentityNumber());
-			req.setStudentCode(cur.getStudentCode());
-			dataSyncCloudService.syncExamStudent(req);
-		}
-
-	}
-
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param examId
-	 */
-	@Override
-	public void deleteExamStudentsByExamId(Long examId) {
-		ExamEntity exam = examRepo.findOne(examId);
-		// 已经开考
-		if ((!forceDeleteExamStudent()) && isStarted(exam.getId(), null, null)) {
-			throw new StatusException("E-150113", "该考试已开始,不能删除");
-		}
-		examStudentRepo.deleteByExamId(examId);
-		examCourseRelationRepo.deleteByExamId(examId);
-		examPaperTypeRelationRepo.deleteByExamId(examId);
-
-		// 同步操作
-		SyncExamStudentReq req = new SyncExamStudentReq();
-		req.setSyncType("deleteByExamId");
-		req.setExamId(examId);
-		dataSyncCloudService.syncExamStudent(req);
-	}
-
-	/*
-	 * 实现
-	 *
-	 * @author WANGWEI
-	 * 
-	 * @see cn.com.qmth.examcloud.core.examwork.service.ExamStudentService#
-	 * saveExamStudent(cn.com.qmth.examcloud.core.examwork.service.bean.
-	 * ExamStudentInfo)
-	 */
-	@Override
-	public ExamStudentInfo saveExamStudent(ExamStudentInfo examStudentInfo) {
-		String paperType = examStudentInfo.getPaperType();
-		if (StringUtils.isBlank(paperType)) {
-			paperType = "X";
-		} else if (!paperType.matches("[A-Z]")) {
-			throw new StatusException("E-100020", "试卷类型必须为一个大写的英文字母");
-		}
-
-		Long rootOrgId = examStudentInfo.getRootOrgId();
-		GetOrgReq getOrgReq = new GetOrgReq();
-		getOrgReq.setOrgId(rootOrgId);
-		GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
-		OrgBean rootOrg = getOrgResp.getOrg();
-		if (null != rootOrg.getParentId()) {
-			throw new StatusException("E-100001", "rootOrgId is wrong");
-		}
-
-		ExamEntity exam = null;
-		Long examId = examStudentInfo.getExamId();
-		String examName = examStudentInfo.getExamName();
-
-		if (null != examId) {
-			exam = examRepo.findOne(examId);
-			if (null == exam) {
-				throw new StatusException("E-100020", "examId is wrong");
-			}
-		} else if (StringUtils.isBlank(examName)) {
-			exam = examRepo.findByNameAndRootOrgId(examName, rootOrgId);
-			if (null == exam) {
-				throw new StatusException("E-100005", "考试不存在");
-			}
-		} else {
-			throw new StatusException("E-100002", "examId & examName are both blank");
-		}
-
-		String identityNumber = examStudentInfo.getIdentityNumber();
-
-		if (StringUtils.isBlank(identityNumber)) {
-			throw new StatusException("E-100003", "identityNumber is null");
-		}
-		GetStudentReq getStudentReq = new GetStudentReq();
-		getStudentReq.setRootOrgId(rootOrgId);
-		getStudentReq.setIdentityNumber(identityNumber);
-		GetStudentResp getStudentResp = studentCloudService.getStudent(getStudentReq);
-
-		StudentBean studentInfo = getStudentResp.getStudentInfo();
-
-		String courseCode = examStudentInfo.getCourseCode();
-		String courseName = examStudentInfo.getCourseName();
-		String courseLevel = examStudentInfo.getCourseLevel();
-
-		SaveCourseReq saveCourseReq = new SaveCourseReq();
-		saveCourseReq.setCourseId(examStudentInfo.getCourseId());
-		saveCourseReq.setCourseCode(courseCode);
-		saveCourseReq.setCourseName(courseName);
-		saveCourseReq.setCourseLevel(courseLevel);
-		saveCourseReq.setRootOrgId(rootOrgId);
-
-		SaveCourseResp saveCourseResp = courseCloudService.saveCourse(saveCourseReq);
-		CourseBean courseBean = saveCourseResp.getCourseBean();
-
-		ExamStudentEntity examStudent = examStudentRepo.findByExamIdAndStudentIdAndCourseId(
-				exam.getId(), studentInfo.getId(), courseBean.getId());
-
-		if (null == examStudent) {
-			examStudent = new ExamStudentEntity();
-			examStudent.setEnable(true);
-		} else {
-			if (!paperType.equals(examStudent.getPaperType())) {
-				List<ExamStudentEntity> top2 = examStudentRepo
-						.findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
-								examStudent.getCourseId(), examStudent.getPaperType());
-				if (2 > top2.size()) {
-					examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
-							examStudent.getExamId(), examStudent.getCourseId(),
-							examStudent.getPaperType());
-				}
-			}
-		}
-
-		examStudent.setInfoCollector(examStudentInfo.getInfoCollector());
-		examStudent.setName(studentInfo.getName());
-		examStudent.setRootOrgId(rootOrgId);
-
-		examStudent.setCourseId(courseBean.getId());
-		examStudent.setCourseName(courseBean.getName());
-		examStudent.setCourseCode(courseBean.getCode());
-		examStudent.setCourseLevel(courseBean.getLevel());
-
-		examStudent.setExamId(exam.getId());
-		examStudent.setIdentityNumber(studentInfo.getIdentityNumber());
-		examStudent.setStudentCode(studentInfo.getStudentCode());
-		examStudent.setPaperType(paperType);
-		examStudent.setStudentId(studentInfo.getId());
-		examStudent.setOrgId(studentInfo.getOrgId());
-		examStudent.setOrgCode(studentInfo.getOrgCode());
-		examStudent.setGrade(examStudentInfo.getGrade());
-		examStudent.setSpecialtyName(examStudentInfo.getSpecialtyName());
-		examStudent.setExamSite(examStudentInfo.getExamSite());
-		examStudent.setRemark(examStudentInfo.getRemark());
-		
-		examStudent.setExt1(examStudentInfo.getExt1());
-		examStudent.setExt2(examStudentInfo.getExt2());
-		examStudent.setExt3(examStudentInfo.getExt3());
-		examStudent.setExt4(examStudentInfo.getExt4());
-		examStudent.setExt5(examStudentInfo.getExt5());
-
-		ExamStudentEntity saved = examStudentRepo.save(examStudent);
-
-		ExamCourseRelationEntity relation = new ExamCourseRelationEntity();
-		relation.setExamId(saved.getExamId());
-		relation.setCourseId(saved.getCourseId());
-		relation.setCourseLevel(saved.getCourseLevel());
-		relation.setCourseCode(courseBean.getCode());
-		relation.setCourseName(saved.getCourseName());
-		relation.setCourseEnable(courseBean.getEnable());
-		examCourseRelationRepo.save(relation);
-
-		ExamPaperTypeRelationEntity pt = new ExamPaperTypeRelationEntity();
-		pt.setCourseId(saved.getCourseId());
-		pt.setExamId(saved.getExamId());
-		pt.setPaperType(saved.getPaperType());
-		examPaperTypeRelationRepo.save(pt);
-
-		// 同步操作
-		SyncExamStudentReq req = new SyncExamStudentReq();
-		req.setSyncType("update");
-		req.setId(saved.getId());
-
-		req.setCourseId(courseBean.getId());
-		req.setCourseCode(courseBean.getCode());
-		req.setCourseLevel(courseBean.getLevel());
-		req.setCourseName(courseBean.getName());
-
-		req.setExamId(exam.getId());
-		req.setExamName(exam.getName());
-
-		req.setRootOrgId(saved.getRootOrgId());
-		req.setStudentId(studentInfo.getId());
-		req.setStudentName(studentInfo.getName());
-		req.setIdentityNumber(saved.getIdentityNumber());
-		req.setStudentCode(saved.getStudentCode());
-		req.setOrgId(studentInfo.getOrgId());
-		req.setOrgName(studentInfo.getOrgName());
-		req.setOrgCode(studentInfo.getOrgCode());
-
-		req.setGrade(saved.getGrade());
-		req.setSpecialtyName(saved.getSpecialtyName());
-		req.setPaperType(saved.getPaperType());
-		req.setRemark(saved.getRemark());
-		req.setInfoCollector(saved.getInfoCollector());
-		req.setExamSite(saved.getExamSite());
-		dataSyncCloudService.syncExamStudent(req);
-
-		ExamStudentInfo ret = new ExamStudentInfo();
-		ret.setId(saved.getId());
-
-		ret.setCourseId(courseBean.getId());
-		ret.setCourseCode(courseBean.getCode());
-		ret.setCourseLevel(courseBean.getLevel());
-		ret.setCourseName(courseBean.getName());
-
-		ret.setExamId(exam.getId());
-		ret.setExamName(exam.getName());
-
-		ret.setRootOrgId(saved.getRootOrgId());
-		ret.setStudentName(studentInfo.getName());
-		ret.setIdentityNumber(saved.getIdentityNumber());
-		ret.setStudentCode(saved.getStudentCode());
-		ret.setOrgId(studentInfo.getOrgId());
-		ret.setOrgName(studentInfo.getOrgName());
-		ret.setOrgCode(studentInfo.getOrgCode());
-
-		ret.setPaperType(saved.getPaperType());
-		ret.setRemark(saved.getRemark());
-		ret.setInfoCollector(saved.getInfoCollector());
-		ret.setExamSite(saved.getExamSite());
-
-		return ret;
-	}
-}
+package cn.com.qmth.examcloud.core.examwork.service.impl;
+
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
+import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
+import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
+import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
+import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
+import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
+import cn.com.qmth.examcloud.core.basic.api.bean.StudentBean;
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
+import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
+import cn.com.qmth.examcloud.core.basic.api.request.SaveCourseReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
+import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
+import cn.com.qmth.examcloud.core.basic.api.response.SaveCourseResp;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamCourseRelationEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntity;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
+import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
+import cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
+import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
+import cn.com.qmth.examcloud.core.oe.admin.api.request.CheckExamIsStartedReq;
+import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
+import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
+import cn.com.qmth.examcloud.task.api.request.SyncExamStudentReq;
+
+/**
+ * 考试学生服务类 Created by songyue on 17/1/14.
+ */
+@Service
+public class ExamStudentServiceImpl implements ExamStudentService {
+
+	@Autowired
+	ExamStudentRepo examStudentRepo;
+
+	@Autowired
+	ExamRepo examRepo;
+
+	@Autowired
+	OrgCloudService orgCloudService;
+
+	@Autowired
+	ExamStudentServiceImpl examStudentService;
+
+	@Autowired
+	StudentCloudService studentCloudService;
+
+	@Autowired
+	CourseCloudService courseCloudService;
+
+	@Autowired
+	ExamCourseRelationRepo examCourseRelationRepo;
+
+	@Autowired
+	DataSyncCloudService dataSyncCloudService;
+
+	@Autowired
+	ExamRecordCloudService examRecordCloudService;
+
+	@Autowired
+	ExamPaperTypeRelationRepo examPaperTypeRelationRepo;
+
+	/**
+	 * 是否强制删除考生
+	 *
+	 * @author WANGWEI
+	 * @return
+	 */
+	private boolean forceDeleteExamStudent() {
+		boolean b = PropertiesUtil.getBoolean("$deleteExamStudent.force", false);
+		return b;
+	}
+
+	/**
+	 * 是否开考
+	 *
+	 * @author WANGWEI
+	 * @param examId
+	 * @param StudentId
+	 * @param courseId
+	 * @return
+	 */
+	private boolean isStarted(Long examId, Long StudentId, Long courseId) {
+		CheckExamIsStartedReq checkExamIsStartedReq = new CheckExamIsStartedReq();
+		checkExamIsStartedReq.setExamId(examId);
+		checkExamIsStartedReq.setCourseId(courseId);
+		checkExamIsStartedReq.setStudentId(StudentId);
+		CheckExamIsStartedResp checkExamIsStartedResp = examRecordCloudService
+				.checkExamIsStarted(checkExamIsStartedReq);
+		return checkExamIsStartedResp.getIsStarted();
+	}
+
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param ids
+	 */
+	@Override
+	public void deleteExamStudentsByStudentIds(List<Long> ids) {
+		List<ExamStudentEntity> examStudents = examStudentRepo.findByIdIn(ids);
+
+		for (ExamStudentEntity examStudent : examStudents) {
+			// 网考判断
+			if ((!forceDeleteExamStudent()) && isStarted(examStudent.getExamId(), null, null)) {
+				throw new StatusException("E-150112", examStudent.getName() + "已开始考试,不能删除");
+			}
+			examStudentRepo.delete(examStudent);
+
+			List<ExamStudentEntity> top2 = examStudentRepo.findTop2ByExamIdAndCourseId(
+					examStudent.getExamId(), examStudent.getCourseId());
+			if (1 > top2.size()) {
+				examCourseRelationRepo.deleteByExamIdAndCourseId(examStudent.getExamId(),
+						examStudent.getCourseId());
+			}
+
+			top2 = examStudentRepo.findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
+					examStudent.getCourseId(), examStudent.getPaperType());
+			if (1 > top2.size()) {
+				examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
+						examStudent.getExamId(), examStudent.getCourseId(),
+						examStudent.getPaperType());
+			}
+		}
+
+		for (ExamStudentEntity cur : examStudents) {
+			// 同步操作
+			SyncExamStudentReq req = new SyncExamStudentReq();
+			req.setSyncType("delete");
+			req.setId(cur.getId());
+			req.setCourseId(cur.getId());
+			req.setCourseCode(cur.getCourseCode());
+			req.setCourseName(cur.getCourseName());
+			req.setExamId(cur.getId());
+			req.setStudentId(cur.getStudentId());
+			req.setStudentName(cur.getName());
+			req.setIdentityNumber(cur.getIdentityNumber());
+			req.setStudentCode(cur.getStudentCode());
+			dataSyncCloudService.syncExamStudent(req);
+		}
+
+	}
+
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param examId
+	 */
+	@Override
+	public void deleteExamStudentsByExamId(Long examId) {
+		ExamEntity exam = examRepo.findOne(examId);
+		// 已经开考
+		if ((!forceDeleteExamStudent()) && isStarted(exam.getId(), null, null)) {
+			throw new StatusException("E-150113", "该考试已开始,不能删除");
+		}
+		examStudentRepo.deleteByExamId(examId);
+		examCourseRelationRepo.deleteByExamId(examId);
+		examPaperTypeRelationRepo.deleteByExamId(examId);
+
+		// 同步操作
+		SyncExamStudentReq req = new SyncExamStudentReq();
+		req.setSyncType("deleteByExamId");
+		req.setExamId(examId);
+		dataSyncCloudService.syncExamStudent(req);
+	}
+
+	/*
+	 * 实现
+	 *
+	 * @author WANGWEI
+	 * 
+	 * @see cn.com.qmth.examcloud.core.examwork.service.ExamStudentService#
+	 * saveExamStudent(cn.com.qmth.examcloud.core.examwork.service.bean.
+	 * ExamStudentInfo)
+	 */
+	@Override
+	public ExamStudentInfo saveExamStudent(ExamStudentInfo examStudentInfo) {
+		String paperType = examStudentInfo.getPaperType();
+		if (StringUtils.isBlank(paperType)) {
+			paperType = "X";
+		} else if (!paperType.matches("[A-Z]")) {
+			throw new StatusException("E-100020", "试卷类型必须为一个大写的英文字母");
+		}
+
+		Long rootOrgId = examStudentInfo.getRootOrgId();
+		GetOrgReq getOrgReq = new GetOrgReq();
+		getOrgReq.setOrgId(rootOrgId);
+		GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
+		OrgBean rootOrg = getOrgResp.getOrg();
+		if (null != rootOrg.getParentId()) {
+			throw new StatusException("E-100001", "rootOrgId is wrong");
+		}
+
+		ExamEntity exam = null;
+		Long examId = examStudentInfo.getExamId();
+		String examName = examStudentInfo.getExamName();
+
+		if (null != examId) {
+			exam = examRepo.findOne(examId);
+			if (null == exam) {
+				throw new StatusException("E-100020", "examId is wrong");
+			}
+		} else if (StringUtils.isBlank(examName)) {
+			exam = examRepo.findByNameAndRootOrgId(examName, rootOrgId);
+			if (null == exam) {
+				throw new StatusException("E-100005", "考试不存在");
+			}
+		} else {
+			throw new StatusException("E-100002", "examId & examName are both blank");
+		}
+
+		String identityNumber = examStudentInfo.getIdentityNumber();
+
+		if (StringUtils.isBlank(identityNumber)) {
+			throw new StatusException("E-100003", "identityNumber is null");
+		}
+		GetStudentReq getStudentReq = new GetStudentReq();
+		getStudentReq.setRootOrgId(rootOrgId);
+		getStudentReq.setIdentityNumber(identityNumber);
+		GetStudentResp getStudentResp = studentCloudService.getStudent(getStudentReq);
+
+		StudentBean studentInfo = getStudentResp.getStudentInfo();
+
+		String courseCode = examStudentInfo.getCourseCode();
+		String courseName = examStudentInfo.getCourseName();
+		String courseLevel = examStudentInfo.getCourseLevel();
+
+		SaveCourseReq saveCourseReq = new SaveCourseReq();
+		saveCourseReq.setCourseId(examStudentInfo.getCourseId());
+		saveCourseReq.setCourseCode(courseCode);
+		saveCourseReq.setCourseName(courseName);
+		saveCourseReq.setCourseLevel(courseLevel);
+		saveCourseReq.setRootOrgId(rootOrgId);
+
+		SaveCourseResp saveCourseResp = courseCloudService.saveCourse(saveCourseReq);
+		CourseBean courseBean = saveCourseResp.getCourseBean();
+
+		ExamStudentEntity examStudent = examStudentRepo.findByExamIdAndStudentIdAndCourseId(
+				exam.getId(), studentInfo.getId(), courseBean.getId());
+
+		if (null == examStudent) {
+			examStudent = new ExamStudentEntity();
+			examStudent.setEnable(true);
+		} else {
+			if (!paperType.equals(examStudent.getPaperType())) {
+				List<ExamStudentEntity> top2 = examStudentRepo
+						.findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
+								examStudent.getCourseId(), examStudent.getPaperType());
+				if (2 > top2.size()) {
+					examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
+							examStudent.getExamId(), examStudent.getCourseId(),
+							examStudent.getPaperType());
+				}
+			}
+		}
+
+		examStudent.setInfoCollector(examStudentInfo.getInfoCollector());
+		examStudent.setName(studentInfo.getName());
+		examStudent.setRootOrgId(rootOrgId);
+
+		examStudent.setCourseId(courseBean.getId());
+		examStudent.setCourseName(courseBean.getName());
+		examStudent.setCourseCode(courseBean.getCode());
+		examStudent.setCourseLevel(courseBean.getLevel());
+
+		examStudent.setExamId(exam.getId());
+		examStudent.setIdentityNumber(studentInfo.getIdentityNumber());
+		examStudent.setStudentCode(studentInfo.getStudentCode());
+		examStudent.setPaperType(paperType);
+		examStudent.setStudentId(studentInfo.getId());
+		examStudent.setOrgId(studentInfo.getOrgId());
+		examStudent.setOrgCode(studentInfo.getOrgCode());
+		examStudent.setGrade(examStudentInfo.getGrade());
+		examStudent.setSpecialtyName(examStudentInfo.getSpecialtyName());
+		examStudent.setExamSite(examStudentInfo.getExamSite());
+		examStudent.setRemark(examStudentInfo.getRemark());
+
+		examStudent.setExt1(examStudentInfo.getExt1());
+		examStudent.setExt2(examStudentInfo.getExt2());
+		examStudent.setExt3(examStudentInfo.getExt3());
+		examStudent.setExt4(examStudentInfo.getExt4());
+		examStudent.setExt5(examStudentInfo.getExt5());
+
+		ExamStudentEntity saved = examStudentRepo.save(examStudent);
+
+		ExamCourseRelationEntity relation = new ExamCourseRelationEntity();
+		relation.setExamId(saved.getExamId());
+		relation.setCourseId(saved.getCourseId());
+		relation.setCourseLevel(saved.getCourseLevel());
+		relation.setCourseCode(courseBean.getCode());
+		relation.setCourseName(saved.getCourseName());
+		relation.setCourseEnable(courseBean.getEnable());
+		examCourseRelationRepo.save(relation);
+
+		ExamPaperTypeRelationEntity pt = new ExamPaperTypeRelationEntity();
+		pt.setCourseId(saved.getCourseId());
+		pt.setExamId(saved.getExamId());
+		pt.setPaperType(saved.getPaperType());
+		examPaperTypeRelationRepo.save(pt);
+
+		// 同步操作
+		SyncExamStudentReq req = new SyncExamStudentReq();
+		req.setSyncType("update");
+		req.setId(saved.getId());
+
+		req.setCourseId(courseBean.getId());
+		req.setCourseCode(courseBean.getCode());
+		req.setCourseLevel(courseBean.getLevel());
+		req.setCourseName(courseBean.getName());
+
+		req.setExamId(exam.getId());
+		req.setExamName(exam.getName());
+
+		req.setRootOrgId(saved.getRootOrgId());
+		req.setStudentId(studentInfo.getId());
+		req.setStudentName(studentInfo.getName());
+		req.setIdentityNumber(saved.getIdentityNumber());
+		req.setStudentCode(saved.getStudentCode());
+		req.setOrgId(studentInfo.getOrgId());
+		req.setOrgName(studentInfo.getOrgName());
+		req.setOrgCode(studentInfo.getOrgCode());
+
+		req.setGrade(saved.getGrade());
+		req.setSpecialtyName(saved.getSpecialtyName());
+		req.setPaperType(saved.getPaperType());
+		req.setRemark(saved.getRemark());
+		req.setInfoCollector(saved.getInfoCollector());
+		req.setExamSite(saved.getExamSite());
+		dataSyncCloudService.syncExamStudent(req);
+
+		ExamStudentInfo ret = new ExamStudentInfo();
+		ret.setId(saved.getId());
+
+		ret.setCourseId(courseBean.getId());
+		ret.setCourseCode(courseBean.getCode());
+		ret.setCourseLevel(courseBean.getLevel());
+		ret.setCourseName(courseBean.getName());
+
+		ret.setExamId(exam.getId());
+		ret.setExamName(exam.getName());
+
+		ret.setRootOrgId(saved.getRootOrgId());
+		ret.setStudentName(studentInfo.getName());
+		ret.setIdentityNumber(saved.getIdentityNumber());
+		ret.setStudentCode(saved.getStudentCode());
+		ret.setOrgId(studentInfo.getOrgId());
+		ret.setOrgName(studentInfo.getOrgName());
+		ret.setOrgCode(studentInfo.getOrgCode());
+
+		ret.setPaperType(saved.getPaperType());
+		ret.setRemark(saved.getRemark());
+		ret.setInfoCollector(saved.getInfoCollector());
+		ret.setExamSite(saved.getExamSite());
+
+		return ret;
+	}
+}