ting.yin 4 年之前
父節點
當前提交
76a0c9b801

+ 3 - 3
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/exam/model/DataSync.java

@@ -45,7 +45,7 @@ public class DataSync implements Serializable {
     private String rootOrgId;
 
     @Column(name = "cloud_exam_id", nullable = false)
-    private Long cloudExamId;
+    private String cloudExamId;
 
     @Column(name = "subject_code")
     private String subjectCode;
@@ -114,11 +114,11 @@ public class DataSync implements Serializable {
         this.rootOrgId = rootOrgId;
     }
 
-    public Long getCloudExamId() {
+    public String getCloudExamId() {
         return cloudExamId;
     }
 
-    public void setCloudExamId(Long cloudExamId) {
+    public void setCloudExamId(String cloudExamId) {
         this.cloudExamId = cloudExamId;
     }
 

+ 40 - 24
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/DataSyncController.java

@@ -1,20 +1,11 @@
 package cn.com.qmth.stmms.admin.exam;
 
-import cn.com.qmth.stmms.admin.dto.SubjectiveQuestionDTO;
-import cn.com.qmth.stmms.admin.thread.DataSyncThread;
-import cn.com.qmth.stmms.admin.utils.HttpUtil;
-import cn.com.qmth.stmms.biz.exam.model.DataSync;
-import cn.com.qmth.stmms.biz.exam.service.*;
-import cn.com.qmth.stmms.biz.file.service.FileService;
-import cn.com.qmth.stmms.biz.lock.LockService;
-import cn.com.qmth.stmms.common.annotation.Logging;
-import cn.com.qmth.stmms.common.annotation.RoleRequire;
-import cn.com.qmth.stmms.common.enums.ExamSource;
-import cn.com.qmth.stmms.common.enums.LockType;
-import cn.com.qmth.stmms.common.enums.LogType;
-import cn.com.qmth.stmms.common.enums.Role;
-import cn.com.qmth.stmms.common.utils.ExportExcel;
-import cn.com.qmth.stmms.common.utils.RequestUtils;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 
@@ -31,11 +22,27 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import java.util.ArrayList;
-import java.util.List;
+import cn.com.qmth.stmms.admin.dto.SubjectiveQuestionDTO;
+import cn.com.qmth.stmms.admin.thread.DataSyncThread;
+import cn.com.qmth.stmms.admin.thread.OnlineExamThread;
+import cn.com.qmth.stmms.admin.utils.HttpUtil;
+import cn.com.qmth.stmms.biz.exam.model.DataSync;
+import cn.com.qmth.stmms.biz.exam.service.DataSyncService;
+import cn.com.qmth.stmms.biz.exam.service.ExamQuestionService;
+import cn.com.qmth.stmms.biz.exam.service.ExamService;
+import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
+import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
+import cn.com.qmth.stmms.biz.exam.service.MarkGroupService;
+import cn.com.qmth.stmms.biz.file.service.FileService;
+import cn.com.qmth.stmms.biz.lock.LockService;
+import cn.com.qmth.stmms.common.annotation.Logging;
+import cn.com.qmth.stmms.common.annotation.RoleRequire;
+import cn.com.qmth.stmms.common.enums.ExamSource;
+import cn.com.qmth.stmms.common.enums.LockType;
+import cn.com.qmth.stmms.common.enums.LogType;
+import cn.com.qmth.stmms.common.enums.Role;
+import cn.com.qmth.stmms.common.utils.ExportExcel;
+import cn.com.qmth.stmms.common.utils.RequestUtils;
 
 @Controller
 @RequestMapping("/admin/exam/data/sync")
@@ -68,6 +75,9 @@ public class DataSyncController extends BaseExamController {
     @Autowired
     private FileService fileService;
 
+    @Autowired
+    private MarkGroupService groupService;
+
     @Value("${qmth.examcloud.host}")
     private String host;
 
@@ -124,9 +134,15 @@ public class DataSyncController extends BaseExamController {
     public String save(HttpServletRequest request, DataSync dataSync, RedirectAttributes redirectAttributes) {
         int examId = getSessionExamId(request);
         if (lockService.trylock(LockType.DATA_SYNC, examId)) {
-            DataSyncThread thread = new DataSyncThread(dataSync, pageSize, lockService, dataSyncService, examService,
-                    studentService, subjectService, fileService);
-            taskExecutor.submit(thread);
+            if (dataSync.getSource().equals(ExamSource.EXAM_CLOUD)) {
+                DataSyncThread thread = new DataSyncThread(dataSync, pageSize, lockService, dataSyncService,
+                        examService, studentService, subjectService, fileService);
+                taskExecutor.submit(thread);
+            } else if (dataSync.getSource().equals(ExamSource.ONLINE_EXAM)) {
+                OnlineExamThread thread = new OnlineExamThread(dataSync, lockService, dataSyncService, examService,
+                        studentService, subjectService, questionService, groupService, fileService);
+                taskExecutor.submit(thread);
+            }
         }
         dataSync = dataSyncService.findByExamId(examId);
         if (lockService.isLocked(LockType.DATA_SYNC, examId) || (dataSync != null && dataSync.isFinished())) {
@@ -162,7 +178,7 @@ public class DataSyncController extends BaseExamController {
         HttpUtil subjectHttp = new HttpUtil(sync.getSubjectUrl(), sync.getAccessKey(), sync.getAppId(),
                 sync.getRootOrgId());
         JSONObject datas = new JSONObject();
-        datas.accumulate("examId", sync.getCloudExamId());
+        datas.accumulate("examId", Long.parseLong(sync.getCloudExamId()));
         String subjectResult = subjectHttp.httpAction(null, datas.toString());
         JSONObject subjectJson = JSONObject.fromObject(subjectResult);
 

+ 1 - 1
stmms-web/src/main/java/cn/com/qmth/stmms/admin/thread/DataSyncThread.java

@@ -99,7 +99,7 @@ public class DataSyncThread implements Runnable {
         log.info("start data sync for examId=" + dataSync.getExamId());
         try {
             JSONObject datas = new JSONObject();
-            datas.accumulate("examId", dataSync.getCloudExamId());
+            datas.accumulate("examId", Long.parseLong(dataSync.getCloudExamId()));
             String subjectResult = subjectHttp.httpAction(null, datas.toString());
             JSONObject subjectJson = JSONObject.fromObject(subjectResult);
             // 考试返回错误,无法创建阅卷

+ 25 - 5
stmms-web/src/main/java/cn/com/qmth/stmms/admin/thread/OnlineExamThread.java

@@ -86,7 +86,7 @@ public class OnlineExamThread implements Runnable {
 
     public static final String FILTER = "filter";
 
-    public OnlineExamThread(DataSync dataSync, String host, LockService lockService, DataSyncService dataSyncService,
+    public OnlineExamThread(DataSync dataSync, LockService lockService, DataSyncService dataSyncService,
             ExamService examService, ExamStudentService studentService, ExamSubjectService subjectService,
             ExamQuestionService questionService, MarkGroupService groupService, FileService fileService) {
         this.dataSync = dataSync;
@@ -98,9 +98,9 @@ public class OnlineExamThread implements Runnable {
         this.questionService = questionService;
         this.groupService = groupService;
         this.fileService = fileService;
-        this.studentHttp = new OnlineExamHttpUtil(dataSync.getAccessKey(), dataSync.getAccessSecret(), host,
+        this.studentHttp = new OnlineExamHttpUtil(dataSync.getAccessKey(), dataSync.getAccessSecret(),
                 dataSync.getStudentUrl());
-        this.subjectPaperHttp = new OnlineExamHttpUtil(dataSync.getAccessKey(), dataSync.getAccessSecret(), host,
+        this.subjectPaperHttp = new OnlineExamHttpUtil(dataSync.getAccessKey(), dataSync.getAccessSecret(),
                 dataSync.getSubjectPaperUrl());
     }
 
@@ -145,7 +145,7 @@ public class OnlineExamThread implements Runnable {
                         datas.put(FILTER, "subjective");
                         String paperResult = subjectPaperHttp.httpAction(null, datas);
                         JSONObject paperJson = JSONObject.fromObject(paperResult);
-                        String subjectCode = paperJson.getString("paperId");
+                        String subjectCode = paperJson.getString(ID);
                         String paper = paperJson.getString("details");
                         byte[] paperData = paper.getBytes(StandardCharsets.UTF_8);
                         fileService.uploadPaper(new ByteArrayInputStream(paperData), BinaryUtil.encodeMD5(paperData),
@@ -160,6 +160,7 @@ public class OnlineExamThread implements Runnable {
                         byte[] jsonData = answerJson.getBytes(StandardCharsets.UTF_8);
                         fileService.uploadJson(new ByteArrayInputStream(jsonData), BinaryUtil.encodeMD5(jsonData),
                                 exam.getId(), examStudent.getSecretNumber());
+                        studentService.save(examStudent);
                         subjectService.updateUploadCount(exam.getId(), subjectCode,
                                 (int) studentService.countUploadedByExamIdAndSubjectCode(exam.getId(), subjectCode));
                     }
@@ -246,7 +247,24 @@ public class OnlineExamThread implements Runnable {
                 JSONObject sub = qArray.getJSONObject(j);
                 JSONArray subJson = sub.getJSONArray("subQuestions");
                 if (!subJson.isEmpty()) {
-
+                    for (int k = 0; k < subJson.size(); k++) {
+                        JSONObject question = subJson.getJSONObject(j);
+                        ExamQuestion q = new ExamQuestion();
+                        q.setExamId(examId);
+                        q.setSubjectCode(subjectCode);
+                        q.setPaperType("#");
+                        q.setObjective(false);
+                        q.setMainNumber(mainNumber);
+                        String subNumber = sub.getString("number") + "_" + question.getString("number");
+                        q.setSubNumber(subNumber);
+                        q.setMainTitle(mainTitle);
+                        q.setGroupNumber(1);
+                        double score = question.getDouble("score");
+                        q.setTotalScore(score);
+                        q.setIntervalScore(0.5);
+                        totalScore = totalScore + score;
+                        list.add(q);
+                    }
                 } else {
                     ExamQuestion q = new ExamQuestion();
                     q.setExamId(examId);
@@ -270,6 +288,8 @@ public class OnlineExamThread implements Runnable {
         MarkGroup group = new MarkGroup(examId, subjectCode, 1, null, totalScore, 0d, null, null,
                 MarkMode.COMMON.toString(), 0, false, false, null);
         groupService.save(group);
+        subjectService.updateScore(examId, subjectCode, false, totalScore);
+        ;
         return subject;
     }
 }

+ 12 - 18
stmms-web/src/main/java/cn/com/qmth/stmms/admin/utils/OnlineExamHttpUtil.java

@@ -9,6 +9,7 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.net.ssl.HttpsURLConnection;
@@ -38,18 +39,15 @@ public class OnlineExamHttpUtil {
 
     public static final String AUTH = "Authorization";
 
-    protected String host = null;
-
     protected String uri = null;
 
     protected String accessKey = null;
 
     protected String accessSecret = null;
 
-    public OnlineExamHttpUtil(String accessKey, String accessSecret, String host, String uri) {
+    public OnlineExamHttpUtil(String accessKey, String accessSecret, String uri) {
         this.accessKey = accessKey;
         this.accessSecret = accessSecret;
-        this.host = host;
         this.uri = uri;
     }
 
@@ -70,7 +68,7 @@ public class OnlineExamHttpUtil {
         try {
 
             // 获取链接
-            URL url = new URL(host + uri);
+            URL url = new URL(uri);
             conn = (HttpsURLConnection) url.openConnection();
 
             conn.setRequestMethod(METHOD_POST);
@@ -205,23 +203,19 @@ public class OnlineExamHttpUtil {
     }
 
     public static void main(String[] args) throws IOException {
-        // Map<String, Object> datas = new HashMap<String, Object>();
-        // datas.put("examId", "62209205889142784");
-        // datas.put("examId", "71613103238311936");
-        // String url =
-        // "https://test1.online-exam-test.cn/api/open/exam/course/query";
+        Map<String, Object> datas = new HashMap<String, Object>();
+        datas.put("examId", "99513313280946176");
+        String url = "/api/open/exam/course/query";
         // OnlineExamHttpUtil subjectHttp = new OnlineExamHttpUtil("123456",
-        // "123", url);
+        // "123", "https://m01.online-exam-test.cn", url);
         // String subjectJson = subjectHttp.httpAction(null, datas);
         // System.out.println(subjectJson);
 
-        // datas.put("courseCode", "A0001");
-        // url =
-        // "https://test1.online-exam-test.cn/api/open/exam/record/need_mark";
-        // OnlineExamHttpUtil studentHttp = new OnlineExamHttpUtil("123456",
-        // "123", url);
-        // String studentJson = studentHttp.httpAction(null, datas);
-        // System.out.println(studentJson);
+        datas.put("courseCode", "A0002");
+        OnlineExamHttpUtil studentHttp = new OnlineExamHttpUtil("123456", "123",
+                "https://m01.online-exam-test.cn/api/open/exam/record/need_mark");
+        String studentJson = studentHttp.httpAction(null, datas);
+        System.out.println(studentJson);
 
         // datas.put("id", "62212585906769920");
         // url = "https://test1.online-exam-test.cn/api/open/exam/paper/detail";

+ 17 - 5
stmms-web/src/main/java/cn/com/qmth/stmms/common/controller/BaseController.java

@@ -247,6 +247,18 @@ public class BaseController {
                 }
             }
         });
+        // ExamSource 类型转换
+        binder.registerCustomEditor(ExamSource.class, new PropertyEditorSupport() {
+
+            @Override
+            public void setAsText(String text) {
+                try {
+                    setValue(ExamSource.findByValue(Integer.valueOf(text)));
+                } catch (Exception e) {
+                    setValue(null);
+                }
+            }
+        });
         // SubjectiveStatus 类型转换
         binder.registerCustomEditor(SubjectiveStatus.class, new PropertyEditorSupport() {
 
@@ -265,8 +277,8 @@ public class BaseController {
     protected boolean saveUploadStudent(ExamStudent student) {
         ExamStudent old = studentService.findById(student.getId());
         if (!student.isAbsent()) {// 正考
-            List<MarkGroup> groupList = groupService
-                    .findByExamAndSubjectAndStatus(student.getExamId(), student.getSubjectCode(), MarkStatus.FINISH);
+            List<MarkGroup> groupList = groupService.findByExamAndSubjectAndStatus(student.getExamId(),
+                    student.getSubjectCode(), MarkStatus.FINISH);
             for (MarkGroup markGroup : groupList) {
                 groupService.updateStatus(student.getExamId(), student.getSubjectCode(), markGroup.getNumber(),
                         MarkStatus.FORMAL, MarkStatus.FINISH);
@@ -295,9 +307,9 @@ public class BaseController {
     private void calculateObjectiveScore(ExamStudent student) {
         ScoreCalculateUtil util = ScoreCalculateUtil.instance(student);
 
-        ScoreInfo info = util.calculate(questionService
-                .findByExamAndSubjectAndObjectiveAndPaperType(student.getExamId(), student.getSubjectCode(), true,
-                        student.getPaperType()), null);
+        ScoreInfo info = util.calculate(
+                questionService.findByExamAndSubjectAndObjectiveAndPaperType(student.getExamId(),
+                        student.getSubjectCode(), true, student.getPaperType()), null);
 
         student.setObjectiveScore(info.getObjectiveScore());
         student.setScoreList(info.getScoreList(), true);

+ 16 - 5
stmms-web/src/main/webapp/WEB-INF/views/modules/exam/dataSync.jsp

@@ -40,6 +40,17 @@
 			</div>
 		</div>
 		<div class="control-group">
+			<label class="control-label">同步来源</label>
+			<div class="controls">
+				<select class="input-small" name="source" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if> id="source">
+	            	<c:forEach items="${sourceList}" var="item">
+	                    <option value="${item.value}"
+	                            <c:if test="${item.value==dataSync.source.value}">selected</c:if>>${item.name}</option>
+	                </c:forEach>
+            	</select>
+			</div>
+		</div>
+<%-- 		<div class="control-group">
 			<label class="control-label">机构ID</label>
 			<div class="controls">
 				<input name="rootOrgId" value="${dataSync.rootOrgId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
@@ -50,15 +61,15 @@
 			<div class="controls">
 				<input name="appId" value="${dataSync.appId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
 			</div>
-		</div>
+		</div> 
 		<div class="control-group">
 			<label class="control-label">密钥</label>
 			<div class="controls">
-				<input name="secretKey" value="${dataSync.secretKey }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
+				<input name="accessKey" value="${dataSync.accessKey }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
 			</div>
-		</div>
+		</div>--%>
 		<div class="control-group">
-			<label class="control-label">云平台考试ID</label>
+			<label class="control-label">考试ID</label>
 			<div class="controls">
 				<input name="cloudExamId" value="${dataSync.cloudExamId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
 			</div>
@@ -75,7 +86,7 @@
 				<textarea name="subjectUrl" class="input-xxlarge required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>>${dataSync.subjectUrl }</textarea>
 			</div>
 		</div>
-		<c:if test="${dataSync.cloudExamId!=null }">
+		<c:if test="${dataSync.cloudExamId!=null && dataSync.source=='EXAM_CLOUD'}">
 		<div class="control-group">
 			<label class="control-label">试卷结构</label>
 			<div class="controls">