wangwei 5 سال پیش
والد
کامیت
5af88e6092

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

@@ -613,7 +613,8 @@ public class ExamController extends ControllerSupport {
 
 		if (copyOrgSettings) {
 			List<ExamSpecialSettingsEntity> orgSettingsList = examSpecialSettingsRepo
-					.findAllByExamIdAndCourseIdIsNullAndOrgIdIsNotNull(srcExam.getId());
+					.findAllByExamIdAndCourseIdIsNullAndStudentIdIsNullAndOrgIdIsNotNull(
+							srcExam.getId());
 
 			for (ExamSpecialSettingsEntity cur : orgSettingsList) {
 
@@ -634,7 +635,7 @@ public class ExamController extends ControllerSupport {
 					DynamicEnum de = manager.getById(curOrgProp.getKeyId());
 					map.put(de.getName(), curOrgProp.getValue());
 				}
-				info.setOrgProperties(orgProperties);
+				info.setProperties(orgProperties);
 
 				examService.saveExamSpecialSettings(info);
 
@@ -1051,7 +1052,7 @@ public class ExamController extends ControllerSupport {
 		if (null == properties) {
 			properties = Maps.newHashMap();
 		}
-		info.setOrgProperties(domain.getProperties());
+		info.setProperties(domain.getProperties());
 
 		ExamSpecialSettingsEntity ret = examService.saveExamSpecialSettings(info);
 		return ret;
@@ -1089,7 +1090,7 @@ public class ExamController extends ControllerSupport {
 		List<Object[]> datas = Lists.newArrayList();
 
 		List<ExamSpecialSettingsEntity> orgSettingsList = examSpecialSettingsRepo
-				.findAllByExamIdAndCourseIdIsNullAndOrgIdIsNotNull(examId);
+				.findAllByExamIdAndCourseIdIsNullAndStudentIdIsNullAndOrgIdIsNotNull(examId);
 		Set<Long> orgIdSet = Sets.newHashSet();
 		for (ExamSpecialSettingsEntity cur : orgSettingsList) {
 			orgIdSet.add(cur.getOrgId());
@@ -1148,7 +1149,7 @@ public class ExamController extends ControllerSupport {
 
 		DiskFileItem item = (DiskFileItem) file.getFileItem();
 		File storeLocation = item.getStoreLocation();
-		List<Map<String, Object>> failRecords = examService.importExamSpecialSettings(examId,
+		List<Map<String, Object>> failRecords = examService.importExamOrgSettings(examId,
 				storeLocation);
 		Map<String, Object> map = Maps.newHashMap();
 		map.put("hasError", CollectionUtils.isNotEmpty(failRecords));
@@ -1220,7 +1221,8 @@ public class ExamController extends ControllerSupport {
 
 		examOrgPropertyRepo.deleteByExamId(examId);
 
-		examSpecialSettingsRepo.deleteByExamIdAndOrgIdIsNotNullAndCourseIdIsNull(examId);
+		examSpecialSettingsRepo
+				.deleteByExamIdAndOrgIdIsNotNullAndCourseIdIsNullAndStudentIdIsNull(examId);
 	}
 
 	/**

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

@@ -228,7 +228,7 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 		Long orgId = req.getOrgId();
 		if (null != orgId) {
 			ExamSpecialSettingsEntity examOrgEntity = examSpecialSettingsRepo
-					.findByExamIdAndOrgIdAndCourseIdIsNull(exam.getId(), orgId);
+					.findByExamIdAndOrgIdAndCourseIdIsNullAndStudentIdIsNull(exam.getId(), orgId);
 			if (null != examOrgEntity) {
 				if (null != examOrgEntity.getBeginTime()) {
 					bean.setBeginTime(examOrgEntity.getBeginTime());

+ 7 - 4
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamSpecialSettingsRepo.java

@@ -18,11 +18,14 @@ public interface ExamSpecialSettingsRepo
 			QueryByExampleExecutor<ExamSpecialSettingsEntity>,
 			JpaSpecificationExecutor<ExamSpecialSettingsEntity> {
 
-	ExamSpecialSettingsEntity findByExamIdAndOrgIdAndCourseIdIsNull(Long examId, Long orgId);
+	ExamSpecialSettingsEntity findByExamIdAndOrgIdAndCourseIdIsNullAndStudentIdIsNull(Long examId,
+			Long orgId);
 
-	List<ExamSpecialSettingsEntity> findAllByExamIdAndOrgIdIsNullAndCourseIdIsNull(Long examId);
+	ExamSpecialSettingsEntity findAllByExamIdAndOrgIdIsNullAndCourseIdIsNullAndStudentIdIsNull(
+			Long examId);
 
-	List<ExamSpecialSettingsEntity> findAllByExamIdAndCourseIdIsNullAndOrgIdIsNotNull(Long examId);
+	List<ExamSpecialSettingsEntity> findAllByExamIdAndCourseIdIsNullAndStudentIdIsNullAndOrgIdIsNotNull(
+			Long examId);
 
 	@Transactional
 	@Modifying
@@ -30,5 +33,5 @@ public interface ExamSpecialSettingsRepo
 	void updateExamEnableByExamId(@Param("examId") long examId,
 			@Param("examEnable") Boolean examEnable);
 
-	void deleteByExamIdAndOrgIdIsNotNullAndCourseIdIsNull(Long examId);
+	void deleteByExamIdAndOrgIdIsNotNullAndCourseIdIsNullAndStudentIdIsNull(Long examId);
 }

+ 20 - 1
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamSpecialSettingsEntity.java

@@ -18,7 +18,12 @@ import cn.com.qmth.examcloud.api.commons.enums.ExamType;
 import cn.com.qmth.examcloud.web.jpa.JpaEntity;
 
 /**
- * 考试--特殊设置
+ * 考试--特殊设置<br>
+ * orgId,courseId,studentId仅有一个可以不为空<br>
+ * 考试维度: orgId==null && courseId==null && studentId==null<br>
+ * 机构维度: orgId!=null && courseId==null && studentId==null<br>
+ * 学生维度: orgId==null && courseId==null && studentId!=null<br>
+ * 课程维度: orgId==null && courseId!=null && studentId ==null<br>
  *
  * @author WANGWEI
  * @date 2018年5月16日
@@ -53,6 +58,12 @@ public class ExamSpecialSettingsEntity extends JpaEntity {
 	@Column(nullable = true)
 	private Long orgId;
 
+	/**
+	 * 学生ID
+	 */
+	@Column(nullable = true)
+	private Long studentId;
+
 	/**
 	 * 顶级机构ID
 	 */
@@ -170,4 +181,12 @@ public class ExamSpecialSettingsEntity extends JpaEntity {
 		this.examEnable = examEnable;
 	}
 
+	public Long getStudentId() {
+		return studentId;
+	}
+
+	public void setStudentId(Long studentId) {
+		this.studentId = studentId;
+	}
+
 }

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

@@ -56,7 +56,7 @@ public interface ExamService {
 	 * @param file
 	 * @return
 	 */
-	List<Map<String, Object>> importExamSpecialSettings(Long examId, File file);
+	List<Map<String, Object>> importExamOrgSettings(Long examId, File file);
 
 	/**
 	 * 查询考试属性

+ 31 - 5
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/bean/ExamSpecialSettingsInfo.java

@@ -33,6 +33,16 @@ public class ExamSpecialSettingsInfo implements JsonSerializable {
 	 */
 	private Long orgId;
 
+	/**
+	 * 学生ID
+	 */
+	private Long studentId;
+
+	/**
+	 * 课程ID
+	 */
+	private Long courseId;
+
 	/**
 	 * 考试批次开始时间
 	 */
@@ -48,7 +58,7 @@ public class ExamSpecialSettingsInfo implements JsonSerializable {
 	 */
 	private Boolean examLimit;
 
-	private Map<String, String> orgProperties;
+	private Map<String, String> properties;
 
 	public Long getId() {
 		return id;
@@ -82,6 +92,22 @@ public class ExamSpecialSettingsInfo implements JsonSerializable {
 		this.orgId = orgId;
 	}
 
+	public Long getStudentId() {
+		return studentId;
+	}
+
+	public void setStudentId(Long studentId) {
+		this.studentId = studentId;
+	}
+
+	public Long getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
+	}
+
 	public Date getBeginTime() {
 		return beginTime;
 	}
@@ -106,12 +132,12 @@ public class ExamSpecialSettingsInfo implements JsonSerializable {
 		this.examLimit = examLimit;
 	}
 
-	public Map<String, String> getOrgProperties() {
-		return orgProperties;
+	public Map<String, String> getProperties() {
+		return properties;
 	}
 
-	public void setOrgProperties(Map<String, String> orgProperties) {
-		this.orgProperties = orgProperties;
+	public void setProperties(Map<String, String> properties) {
+		this.properties = properties;
 	}
 
 }

+ 1 - 1
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/cache/ExamOrgSettingsCache.java

@@ -48,7 +48,7 @@ public class ExamOrgSettingsCache extends RandomObjectRedisCache<ExamOrgSettings
 		bean.setExamLimit(exam.getExamLimit());
 
 		ExamSpecialSettingsEntity examOrgEntity = examSpecialSettingsRepo
-				.findByExamIdAndOrgIdAndCourseIdIsNull(exam.getId(), orgId);
+				.findByExamIdAndOrgIdAndCourseIdIsNullAndStudentIdIsNull(exam.getId(), orgId);
 		if (null != examOrgEntity) {
 			if (null != examOrgEntity.getBeginTime()) {
 				bean.setBeginTime(examOrgEntity.getBeginTime());

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

@@ -430,10 +430,13 @@ public class ExamServiceImpl implements ExamService {
 
 		ExamSpecialSettingsEntity examSpecialSettingsEntity = null;
 
+		Long rootOrgId = examSpecialInfo.getRootOrgId();
 		Long examId = examSpecialInfo.getExamId();
 		Date beginTime = examSpecialInfo.getBeginTime();
 		Date endTime = examSpecialInfo.getEndTime();
 		Long orgId = examSpecialInfo.getOrgId();
+		Long studentId = examSpecialInfo.getStudentId();
+		Long courseId = examSpecialInfo.getCourseId();
 
 		// 上锁
 		Object[] locker = new Object[]{"E_EXAM_SPECIAL_SETTINGS", examId};
@@ -447,29 +450,28 @@ public class ExamServiceImpl implements ExamService {
 
 		if (null == examSpecialInfo.getId()) {
 			// 机构特殊设置
-			if (null != orgId) {
+			if (null != orgId && null == courseId && null == studentId) {
 				examSpecialSettingsEntity = examSpecialSettingsRepo
-						.findByExamIdAndOrgIdAndCourseIdIsNull(examSpecialInfo.getExamId(),
-								examSpecialInfo.getOrgId());
+						.findByExamIdAndOrgIdAndCourseIdIsNullAndStudentIdIsNull(
+								examSpecialInfo.getExamId(), examSpecialInfo.getOrgId());
+			}
+			// 学生特殊设置
+			else if (null == orgId && null == courseId && null != studentId) {
+
+			}
+			// 课程特殊设置
+			else if (null == orgId && null != courseId && null == studentId) {
+
 			}
 			// 考试设置
-			else {
-				List<ExamSpecialSettingsEntity> all = examSpecialSettingsRepo
-						.findAllByExamIdAndOrgIdIsNullAndCourseIdIsNull(
+			else if (null == orgId && null == courseId && null == studentId) {
+				examSpecialSettingsEntity = examSpecialSettingsRepo
+						.findAllByExamIdAndOrgIdIsNullAndCourseIdIsNullAndStudentIdIsNull(
 								examSpecialInfo.getExamId());
-				// 容错
-				if (CollectionUtils.isNotEmpty(all)) {
-					for (int i = 0; i < all.size(); i++) {
-						ExamSpecialSettingsEntity cur = all.get(i);
-						if (0 == i) {
-							examSpecialSettingsEntity = cur;
-						} else {
-							examSpecialSettingsRepo.delete(cur);
-						}
-					}
-				}
-
+			} else {
+				throw new StatusException("001501", "参数错误");
 			}
+
 			if (null == examSpecialSettingsEntity) {
 				examSpecialSettingsEntity = new ExamSpecialSettingsEntity();
 			}
@@ -481,24 +483,29 @@ public class ExamServiceImpl implements ExamService {
 			}
 		}
 
-		examSpecialSettingsEntity.setBeginTime(examSpecialInfo.getBeginTime());
-		examSpecialSettingsEntity.setEndTime(examSpecialInfo.getEndTime());
-		examSpecialSettingsEntity.setRootOrgId(examSpecialInfo.getRootOrgId());
-		examSpecialSettingsEntity.setExamId(examSpecialInfo.getExamId());
-		examSpecialSettingsEntity.setOrgId(examSpecialInfo.getOrgId());
+		examSpecialSettingsEntity.setRootOrgId(rootOrgId);
+		examSpecialSettingsEntity.setExamId(examId);
 		examSpecialSettingsEntity.setExamType(examEntity.getExamType());
 		examSpecialSettingsEntity.setExamEnable(examEntity.getEnable());
+
+		examSpecialSettingsEntity.setOrgId(orgId);
+		examSpecialSettingsEntity.setCourseId(courseId);
+		examSpecialSettingsEntity.setStudentId(studentId);
+
+		examSpecialSettingsEntity.setBeginTime(examSpecialInfo.getBeginTime());
+		examSpecialSettingsEntity.setEndTime(examSpecialInfo.getEndTime());
+
 		Boolean examLimit = examSpecialInfo.getExamLimit();
 		examLimit = null == examLimit ? false : examLimit;
 		examSpecialSettingsEntity.setExamLimit(examLimit);
 
 		ExamSpecialSettingsEntity saved = examSpecialSettingsRepo.save(examSpecialSettingsEntity);
 
-		Map<String, String> orgProperties = examSpecialInfo.getOrgProperties();
+		Map<String, String> props = examSpecialInfo.getProperties();
 
-		if (null != orgProperties) {
+		if (null != props) {
 			Map<DynamicEnum, String> map = checkAndGetExamProperties(examEntity.getRootOrgId(),
-					orgProperties);
+					props);
 
 			for (Entry<DynamicEnum, String> entry : map.entrySet()) {
 				DynamicEnum de = entry.getKey();
@@ -508,17 +515,30 @@ public class ExamServiceImpl implements ExamService {
 				} else {
 					value = value.trim();
 				}
-				ExamOrgPropertyEntity entity = examOrgPropertyRepo.findByExamIdAndOrgIdAndKeyId(
-						saved.getExamId(), saved.getOrgId(), de.getId());
-				if (null == entity) {
-					entity = new ExamOrgPropertyEntity();
-					entity.setExamId(saved.getExamId());
-					entity.setOrgId(saved.getOrgId());
-					entity.setKeyId(de.getId());
+
+				// 机构特殊设置
+				if (null != orgId && null == courseId && null == studentId) {
+					ExamOrgPropertyEntity entity = examOrgPropertyRepo.findByExamIdAndOrgIdAndKeyId(
+							saved.getExamId(), saved.getOrgId(), de.getId());
+					if (null == entity) {
+						entity = new ExamOrgPropertyEntity();
+						entity.setExamId(saved.getExamId());
+						entity.setOrgId(saved.getOrgId());
+						entity.setKeyId(de.getId());
+					}
+					entity.setValue(value);
+
+					examOrgPropertyRepo.save(entity);
+				}
+				// 学生特殊设置
+				else if (null == orgId && null == courseId && null != studentId) {
+
+				}
+				// 课程特殊设置
+				else if (null == orgId && null != courseId && null == studentId) {
+
 				}
-				entity.setValue(value);
 
-				examOrgPropertyRepo.save(entity);
 			}
 		}
 
@@ -548,7 +568,7 @@ public class ExamServiceImpl implements ExamService {
 	}
 
 	@Override
-	public List<Map<String, Object>> importExamSpecialSettings(Long examId, File file) {
+	public List<Map<String, Object>> importExamOrgSettings(Long examId, File file) {
 
 		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		List<String[]> lineList = null;
@@ -661,7 +681,8 @@ public class ExamServiceImpl implements ExamService {
 
 		for (ExamSpecialSettingsEntity cur : specialSettingsList) {
 			ExamSpecialSettingsEntity query = examSpecialSettingsRepo
-					.findByExamIdAndOrgIdAndCourseIdIsNull(examId, cur.getOrgId());
+					.findByExamIdAndOrgIdAndCourseIdIsNullAndStudentIdIsNull(examId,
+							cur.getOrgId());
 
 			if (null != query) {
 				query.setExamType(examEntity.getExamType());