wangwei 6 anni fa
parent
commit
a41b281f85

+ 1 - 4
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamOrgRepo.java

@@ -1,8 +1,5 @@
 package cn.com.qmth.examcloud.core.examwork.dao;
 
-import java.util.List;
-
-import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -28,6 +25,6 @@ public interface ExamOrgRepo
 	@Query("delete from ExamOrgEntity where examId = ?1 and orgId = ?2")
 	void deleteByExamIdAndOrgId(Long examId, Long orgId);
 
-	List<ExamOrgEntity> findAllByExamIdAndOrgId(Long examId, Long orgId, Pageable pageable);
+	ExamOrgEntity findByExamIdAndOrgId(Long examId, Long orgId);
 
 }

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

@@ -198,11 +198,23 @@ public class ExamServiceImpl implements ExamService {
 	 */
 	@Override
 	public ExamOrgEntity saveExamOrg(ExamOrgInfo examOrgInfo) {
-		ExamOrgEntity examOrgEntity = new ExamOrgEntity();
-		examOrgEntity.setId(examOrgInfo.getId());
+		ExamOrgEntity examOrgEntity = null;
+
+		if (null == examOrgInfo.getId()) {
+			examOrgEntity = examOrgRepo.findByExamIdAndOrgId(examOrgInfo.getExamId(),
+					examOrgInfo.getOrgId());
+			if (null == examOrgEntity) {
+				examOrgEntity = new ExamOrgEntity();
+			}
+		} else {
+			examOrgEntity = examOrgRepo.findOne(examOrgInfo.getId());
+			if (null == examOrgEntity) {
+				throw new StatusException("E-001101", "id is wrong");
+			}
+		}
+
 		examOrgEntity.setBeginTime(examOrgInfo.getBeginTime());
 		examOrgEntity.setEndTime(examOrgInfo.getEndTime());
-		examOrgEntity.setId(examOrgInfo.getId());
 		examOrgEntity.setRootOrgId(examOrgInfo.getRootOrgId());
 		examOrgEntity.setExamId(examOrgInfo.getExamId());
 		examOrgEntity.setOrgId(examOrgInfo.getOrgId());