deason преди 6 години
родител
ревизия
2f68c57b59

+ 50 - 21
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CoursePaperServiceImpl.java

@@ -74,31 +74,60 @@ public class CoursePaperServiceImpl implements CoursePaperService {
     }
 
     @Override
-    public void syncCoursePaper(CoursePaper info) {
-        Check.isNull(info.getOrgId(), "学校ID不能为空!");
-        Check.isNull(info.getExamId(), "考试ID不能为空!");
-        Check.isNull(info.getCourseId(), "课程ID不能为空!");
-        Check.isEmpty(info.getCourseCode(), "课程代码不能为空!");
-        Check.isEmpty(info.getCourseName(), "课程名称不能为空!");
-        Check.isNull(info.getPaperId(), "试卷ID不能为空!");
-        Check.isEmpty(info.getPaperName(), "试卷名称不能为空!");
-        Check.isNull(info.getPaperP(), "试卷页数不能为空!");
-        Check.isBlank(info.getPaperFileUrl(), "试卷文件地址不能为空!");
-        Check.isBlank(info.getAnswerFileUrl(), "答案文件地址不能为空!");
-
-        CoursePaper coursePaper = coursePaperRepository.findByExamIdAndPaperId(info.getExamId(), info.getPaperId());
-        if (coursePaper != null) {
+    public void syncCoursePaper(CoursePaper coursePaper) {
+        Check.isNull(coursePaper.getOrgId(), "学校ID不能为空!");
+        Check.isNull(coursePaper.getExamId(), "考试ID不能为空!");
+        Check.isNull(coursePaper.getCourseId(), "课程ID不能为空!");
+        Check.isEmpty(coursePaper.getCourseCode(), "课程代码不能为空!");
+        Check.isEmpty(coursePaper.getCourseName(), "课程名称不能为空!");
+        Check.isNull(coursePaper.getPaperId(), "试卷ID不能为空!");
+        Check.isEmpty(coursePaper.getPaperName(), "试卷名称不能为空!");
+        Check.isNull(coursePaper.getPaperP(), "试卷页数不能为空!");
+        Check.isBlank(coursePaper.getPaperFileUrl(), "试卷文件地址不能为空!");
+        Check.isBlank(coursePaper.getAnswerFileUrl(), "答案文件地址不能为空!");
+
+        CoursePaper oldCoursePaper = coursePaperRepository.findByExamIdAndPaperId(coursePaper.getExamId(), coursePaper.getPaperId());
+        if (oldCoursePaper != null) {
             //存在则修改
-            coursePaper.setPaperName(info.getPaperName());
-            coursePaper.setPaperP(info.getPaperP());
-            coursePaper.setPaperFileUrl(info.getPaperFileUrl());
-            coursePaper.setAnswerFileUrl(info.getAnswerFileUrl());
-            coursePaperRepository.save(coursePaper);
+            oldCoursePaper.setPaperName(coursePaper.getPaperName());
+            oldCoursePaper.setPaperP(coursePaper.getPaperP());
+            oldCoursePaper.setPaperFileUrl(coursePaper.getPaperFileUrl());
+            oldCoursePaper.setAnswerFileUrl(coursePaper.getAnswerFileUrl());
+            coursePaperRepository.save(oldCoursePaper);
             return;
         }
-
         //否则新增
-        coursePaperRepository.save(info);
+        coursePaperRepository.save(coursePaper);
+
+        //保存试卷结构
+        //todo
+
+
+        //如果当前考试课程"只有一种试卷类型"且"未分配试卷",则默认分配该试卷
+        SearchBuilder searches = new SearchBuilder()
+                .eq("orgId", coursePaper.getOrgId())
+                .eq("examId", coursePaper.getExamId())
+                .eq("courseId", coursePaper.getCourseId());
+        Specification<CourseStatistic> spec = SpecUtils.buildSearchers(CourseStatistic.class, searches.build());
+        List<CourseStatistic> statistics = courseStatisticRepository.findAll(spec);
+        if (statistics == null || statistics.isEmpty()) {
+            return;
+        }
+        for (CourseStatistic statistic : statistics) {
+            if (PaperStatus.已有.getIndex() == statistic.getPaperStatus()) {
+                //跳过已分配的
+                continue;
+            }
+            if (statistics.size() == 1) {
+                //只有一种试卷类型,则默认分配
+                statistic.setCoursePaper(coursePaper);
+                statistic.setPaperStatus(PaperStatus.已有.getIndex());
+                break;
+            }
+            //否则,分配状态改为"未指定"
+            statistic.setPaperStatus(PaperStatus.未指定.getIndex());
+        }
+        courseStatisticRepository.save(statistics);
     }
 
     @Override

+ 1 - 1
examcloud-core-print-starter/src/main/resources/application-dev.properties

@@ -16,7 +16,7 @@ spring.application.name=EC-CORE-PRINT
 eureka.client.serviceUrl.defaultZone=http://eureka-host:1111/eureka/
 # upyun config
 upyun.operator=examcloud
-upyun.psw=examcloud123456
+upyun.psw=ecs87863577!@#
 upyun.bucket=exam-cloud-test
 upyun.bucketUrl=https://v0.api.upyun.com/exam-cloud-test
 upyun.fileUrl=https://ecs-test-static.qmth.com.cn

+ 1 - 1
examcloud-core-print-starter/src/main/resources/application-prod.properties

@@ -16,7 +16,7 @@ spring.application.name=EC-CORE-PRINT
 eureka.client.serviceUrl.defaultZone=http://eureka-host:1111/eureka/
 # upyun config
 upyun.operator=examcloud
-upyun.psw=examcloud123456
+upyun.psw=ecs87863577!@#
 upyun.bucket=exam-cloud
 upyun.bucketUrl=https://v0.api.upyun.com/exam-cloud
 upyun.fileUrl=https://ecs-static.qmth.com.cn

+ 1 - 1
examcloud-core-print-starter/src/main/resources/application-test.properties

@@ -16,7 +16,7 @@ spring.application.name=EC-CORE-PRINT
 eureka.client.serviceUrl.defaultZone=http://eureka-host:1111/eureka/
 # upyun config
 upyun.operator=examcloud
-upyun.psw=examcloud123456
+upyun.psw=ecs87863577!@#
 upyun.bucket=exam-cloud-test
 upyun.bucketUrl=https://v0.api.upyun.com/exam-cloud-test
 upyun.fileUrl=https://ecs-test-static.qmth.com.cn

+ 16 - 0
examcloud-core-print-starter/src/test/java/cn/com/qmth/examcloud/core/print/test/CoursePaperServiceTest.java

@@ -7,6 +7,7 @@
 
 package cn.com.qmth.examcloud.core.print.test;
 
+import cn.com.qmth.examcloud.core.print.entity.CoursePaper;
 import cn.com.qmth.examcloud.core.print.service.CoursePaperService;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,5 +36,20 @@ public class CoursePaperServiceTest extends BaseTest {
         coursePaperService.allotAllCoursePaper(orgId, examId);
     }
 
+    @Test
+    public void syncCoursePaperTest() throws Exception {
+        CoursePaper coursePaper = new CoursePaper();
+        coursePaper.setOrgId(1L);
+        coursePaper.setExamId(1L);
+        coursePaper.setCourseId(1L);
+        coursePaper.setCourseCode("123456");
+        coursePaper.setCourseName("测试课程");
+        coursePaper.setPaperId("abc");
+        coursePaper.setPaperName("测试试卷");
+        coursePaper.setPaperP(5);
+        coursePaper.setPaperFileUrl("aaa");
+        coursePaper.setAnswerFileUrl("bbb");
+        coursePaperService.syncCoursePaper(coursePaper);
+    }
 
 }