ting.yin 5 년 전
부모
커밋
be7659c98e

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

@@ -42,12 +42,21 @@ public class DataSync implements Serializable {
     @Column(name = "next_id", nullable = false)
     private Long nextId;
 
-    @Column(name = "url", nullable = false)
-    private String url;
+    @Column(name = "student_url", nullable = false)
+    private String studentUrl;
+
+    @Column(name = "app_id", nullable = false)
+    private String appId;
+
+    @Column(name = "secret_key", nullable = false)
+    private String secretKey;
 
     @Column(name = "finished", nullable = false)
     private boolean finished;
 
+    @Column(name = "subject_url", nullable = false)
+    private String subjectUrl;
+
     public Integer getExamId() {
         return examId;
     }
@@ -112,12 +121,12 @@ public class DataSync implements Serializable {
         this.nextId = nextId;
     }
 
-    public String getUrl() {
-        return url;
+    public String getStudentUrl() {
+        return studentUrl;
     }
 
-    public void setUrl(String url) {
-        this.url = url;
+    public void setStudentUrl(String studentUrl) {
+        this.studentUrl = studentUrl;
     }
 
     public boolean isFinished() {
@@ -128,4 +137,28 @@ public class DataSync implements Serializable {
         this.finished = finished;
     }
 
+    public String getSubjectUrl() {
+        return subjectUrl;
+    }
+
+    public void setSubjectUrl(String subjectUrl) {
+        this.subjectUrl = subjectUrl;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public String getSecretKey() {
+        return secretKey;
+    }
+
+    public void setSecretKey(String secretKey) {
+        this.secretKey = secretKey;
+    }
+
 }

+ 34 - 16
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/DataSyncController.java

@@ -14,14 +14,18 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.task.AsyncTaskExecutor;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
 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.admin.utils.SessionExamUtils;
+import cn.com.qmth.stmms.admin.utils.UpyunConfig;
 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;
@@ -87,39 +91,53 @@ public class DataSyncController extends BaseExamController {
     @Value("${file.root}")
     private String baseDir;
 
-    @RequestMapping
-    public ModelAndView index(HttpServletRequest request) {
-        int examId = getSessionExamId(request);
+    @Autowired
+    private UpyunConfig config;
+
+    @RequestMapping()
+    public ModelAndView index(HttpServletRequest request, @RequestParam Integer examId) {
+        if (examId != null) {
+            SessionExamUtils.setExamId(request, examId);
+        }
+        examId = getSessionExamId(request);
+
+        DataSync dataSync = dataSyncService.findByExamId(examId);
+        if (dataSync == null) {
+            dataSync = new DataSync();
+            dataSync.setExamId(examId);
+            dataSync.setRootOrgId(rootOrgId);
+            dataSync.setStudentUrl("http://" + host + ":" + port + studentUri);
+            dataSync.setSubjectUrl("http://" + host + ":" + port + subjectUri);
+            dataSync.setAppId(appId);
+            dataSync.setSecretKey(secretKey);
+        }
         ModelAndView view = new ModelAndView("modules/exam/dataSync");
         view.addObject("running", lockService.isLocked(LockType.DATA_SYNC, examId));
-        view.addObject("host", host);
-        view.addObject("port", port);
-        view.addObject("rootOrgId", rootOrgId);
-        view.addObject("subjectUri", subjectUri);
-        view.addObject("studentUri", studentUri);
+        view.addObject("exam", examService.findById(examId));
+        view.addObject("dataSync", dataSync);
         return view;
     }
 
-    @RequestMapping(value = "/start", method = RequestMethod.POST)
+    @RequestMapping(value = "/save", method = RequestMethod.POST)
     @RoleRequire(Role.SCHOOL_ADMIN)
-    public ModelAndView sync1(HttpServletRequest request, DataSync dataSync) {
+    public String save(HttpServletRequest request, DataSync dataSync) {
         int examId = getSessionExamId(request);
         if (lockService.trylock(LockType.DATA_SYNC, examId)) {
-            DataSyncThread thread = new DataSyncThread(dataSync, secretKey, appId, pageSize, baseDir, lockService,
+            DataSyncThread thread = new DataSyncThread(dataSync, pageSize, baseDir, config, lockService,
                     dataSyncService, examService, studentService);
             taskExecutor.submit(thread);
         }
-        return new ModelAndView("redirect:/admin/exam/dataSync");
+        return "redirect:/admin/exam-list";
     }
 
-    @RequestMapping(value = "/export", method = RequestMethod.POST)
+    @RequestMapping(value = "/{cloudExamId}/export", method = RequestMethod.GET)
     @RoleRequire(Role.SCHOOL_ADMIN)
-    public ModelAndView exportFile(String url, HttpServletRequest request, HttpServletResponse response,
-            RedirectAttributes redirectAttributes) {
+    public ModelAndView exportFile(@PathVariable Long cloudExamId, HttpServletRequest request,
+            HttpServletResponse response, RedirectAttributes redirectAttributes) {
         int examId = getSessionExamId(request);
         DataSync sync = dataSyncService.findByExamId(examId);
-        List<SubjectiveQuestionDTO> list = getPaperStruct(url, sync.getCloudExamId());
         try {
+            List<SubjectiveQuestionDTO> list = getPaperStruct(sync.getSubjectUrl(), cloudExamId);
             new ExportExcel("主观题数据", SubjectiveQuestionDTO.class, 2).setDataList(list).write(response, "主观题数据.xlsx")
                     .dispose();
             return null;

+ 0 - 1
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/ExamController.java

@@ -160,7 +160,6 @@ public class ExamController extends BaseExamController {
     @RequestMapping("/exam-view/{examId}")
     public String view(Model model, HttpServletRequest request, @PathVariable Integer examId) {
         SessionExamUtils.setExamId(request, examId);
-
         Exam exam = examService.findById(examId);
         long studentCount = examStudentService.countByExamId(exam.getId());
         long subjectCount = examSubjectService.count(examId);

+ 2 - 3
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/ProblemTypeController.java

@@ -19,11 +19,11 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
+import cn.com.qmth.stmms.admin.utils.SessionExamUtils;
 import cn.com.qmth.stmms.biz.mark.model.ProblemType;
 import cn.com.qmth.stmms.biz.mark.service.ProblemHistoryService;
 import cn.com.qmth.stmms.biz.mark.service.ProblemTypeService;
 import cn.com.qmth.stmms.common.domain.WebUser;
-import cn.com.qmth.stmms.common.session.model.StmmsSession;
 import cn.com.qmth.stmms.common.utils.RequestUtils;
 
 @Controller
@@ -41,8 +41,7 @@ public class ProblemTypeController extends BaseExamController {
     @RequestMapping
     public String list(HttpServletRequest request, Model model, @RequestParam(required = false) Integer examId) {
         if (examId != null) {
-            StmmsSession session = RequestUtils.getSession(request);
-            session.setParameter("examId", examId.toString());
+            SessionExamUtils.setExamId(request, examId);
         }
         examId = getSessionExamId(request);
         List<ProblemType> list = problemService.findByExamId(examId);

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

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import cn.com.qmth.stmms.admin.utils.HttpUtil;
+import cn.com.qmth.stmms.admin.utils.UpyunConfig;
 import cn.com.qmth.stmms.biz.exam.model.DataSync;
 import cn.com.qmth.stmms.biz.exam.model.Exam;
 import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
@@ -41,6 +42,8 @@ public class DataSyncThread implements Runnable {
 
     private String baseDir;
 
+    private UpyunConfig config;
+
     private HttpUtil subjectHttp;
 
     private HttpUtil studentHttp;
@@ -61,7 +64,7 @@ public class DataSyncThread implements Runnable {
 
     public static final String SIZE = "size";
 
-    public DataSyncThread(DataSync dataSync, String secretKey, String appId, Integer pageSize, String baseDir,
+    public DataSyncThread(DataSync dataSync, Integer pageSize, String baseDir, UpyunConfig config,
             LockService lockService, DataSyncService dataSyncService, ExamService examService,
             ExamStudentService studentService) {
         this.dataSync = dataSync;
@@ -71,8 +74,11 @@ public class DataSyncThread implements Runnable {
         this.studentService = studentService;
         this.pageSize = pageSize;
         this.baseDir = baseDir;
-        this.subjectHttp = new HttpUtil(dataSync.getUrl(), secretKey, appId, dataSync.getRootOrgId());
-        this.studentHttp = new HttpUtil(dataSync.getUrl(), secretKey, appId, dataSync.getRootOrgId());
+        this.config = config;
+        this.subjectHttp = new HttpUtil(dataSync.getSubjectUrl(), dataSync.getSecretKey(), dataSync.getAppId(),
+                dataSync.getRootOrgId());
+        this.studentHttp = new HttpUtil(dataSync.getStudentUrl(), dataSync.getSecretKey(), dataSync.getAppId(),
+                dataSync.getRootOrgId());
     }
 
     @Override
@@ -86,7 +92,7 @@ public class DataSyncThread implements Runnable {
                 sync = dataSync;
             }
             JSONObject datas = new JSONObject();
-            datas.accumulate("examId", dataSync.getCloudExamId());
+            datas.accumulate("examId", sync.getCloudExamId());
             String subjectResult = subjectHttp.httpAction(null, datas.toString());
             JSONObject subjectJson = JSONObject.fromObject(subjectResult);
             JSONArray subjectArray = subjectJson.getJSONArray(PAPER_STRUCT);
@@ -115,7 +121,7 @@ public class DataSyncThread implements Runnable {
                     for (int j = 0; j < studentArray.size(); j++) {
                         JSONObject student = studentArray.getJSONObject(i);
                         ExamStudent examStudent = new ExamStudent();
-                        examStudent.setExamId(dataSync.getExamId());
+                        examStudent.setExamId(sync.getExamId());
                         examStudent.setStudentCode(student.getString("studentCode"));
                         examStudent.setName(student.getString("name"));
                         examStudent.setCollege(DEFAULT_NULL);
@@ -138,22 +144,25 @@ public class DataSyncThread implements Runnable {
                         list.add(examStudent);
 
                         String answerJson = student.getString("subjectives");
-                        File file = new File(baseDir
-                                + PictureUrlBuilder.getAnswerJson(exam.getId(), subjectCode, null,
+                        File file = new File(new File(baseDir, config.getMediaBucket()),
+                                PictureUrlBuilder.getAnswerJson(exam.getId(), subjectCode, null,
                                         examStudent.getExamNumber()));
+                        if (!file.exists()) {
+                            file.createNewFile();
+                        }
                         FileOutputStream fos = new FileOutputStream(file);
                         fos.write(answerJson.getBytes());
                         fos.close();
                     }
                     studentService.batchSave(list);
-                    dataSync.setUpdateTime(new Date());
-                    dataSync.setNextId(nextId);
-                    dataSync.setSubjectCode(subjectCode);
-                    dataSyncService.save(dataSync);
+                    sync.setUpdateTime(new Date());
+                    sync.setNextId(nextId);
+                    sync.setSubjectCode(subjectCode);
+                    dataSyncService.save(sync);
                 }
             }
-            dataSync.setFinished(true);
-            dataSyncService.save(dataSync);
+            sync.setFinished(true);
+            dataSyncService.save(sync);
         } catch (Exception e) {
             log.error("data sync exception for examId=" + dataSync.getExamId(), e);
         } finally {

+ 14 - 11
stmms-web/src/main/java/cn/com/qmth/stmms/admin/utils/HttpUtil.java

@@ -187,21 +187,24 @@ public class HttpUtil {
     }
 
     public static void main(String[] args) {
-        HttpUtil subjectHttp = new HttpUtil(
-                "http://ecs-test.qmth.com.cn:8007/api/exchange/outer/question/getSubjectivePaperStruct", "123456",
-                "11", "17128");
         JSONObject json = new JSONObject();
-        json.accumulate("examId", 57);
-        String subjectJson = subjectHttp.httpAction(null, json.toString());
-        System.out.println(subjectJson);
+        json.accumulate("examId", 672);
 
+        // HttpUtil subjectHttp = new HttpUtil(
+        // "http://iepcc-ps.ecs.qmth.com.cn:80/api/exchange/outer/question/getSubjectivePaperStruct",
+        // "Fu234234CK!fsd9f0", "EPCC", "16923");
+        // String subjectJson = subjectHttp.httpAction(null, json.toString());
+        // System.out.println(subjectJson);
+
+        long start = System.currentTimeMillis();
         HttpUtil studentHttp = new HttpUtil(
-                "http://ecs-test.qmth.com.cn:8007/api/exchange/outer/question/getSubjectiveQuestion", "123456", "11",
-                "17128");
-        json.accumulate("subjectCode", "CSKC");
+                "http://iepcc-ps.ecs.qmth.com.cn:80/api/exchange/outer/question/getSubjectiveQuestion",
+                "Fu234234CK!fsd9f0", "EPCC", "16923");
+        json.accumulate("subjectCode", "B149");
         json.accumulate("startId", 0);
-        json.accumulate("size", 50);
+        json.accumulate("size", 2);
         String studentJson = studentHttp.httpAction(null, json.toString());
-        System.out.println(studentJson);
+        long end = System.currentTimeMillis();
+        System.out.println(end - start + ":" + studentJson);
     }
 }

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

@@ -7,9 +7,6 @@
 	<%@include file="/WEB-INF/views/include/head.jsp" %>
 	<script type="text/javascript">
 		$(document).ready(function() {
-			$("#name").focus();
-			var pictureConfig = '${pictureConfig}';
-			window.localStorage.setItem("pictureConfig",pictureConfig);
 			$("#inputForm").validate({
 				submitHandler: function(form){
 					loading('正在提交,请稍等...');
@@ -33,53 +30,60 @@
 		<li><a href="${ctx}/admin/exam-list">考试列表</a></li>
 		<li class="active"><a href="##">数据同步</a></li>
 	</ul><br/>
-	<form:form id="inputForm" modelAttribute="exam" action="${ctx}/admin/exam/data/sync" method="post" class="form-horizontal">
-		<form:hidden path="id"/>
+	<form:form id="inputForm" modelAttribute="dataSync" action="${ctx}/admin/exam/data/sync/save" method="post" class="form-horizontal">
+		<form:hidden path="examId"/>
 		<tags:message content="${message}"/>
 		<div class="control-group">
 			<label class="control-label">考试名称</label>
 			<div class="controls">
-				<form:input path="name" htmlEscape="false" maxlength="200" class="required"/>
+				${exam.name}
 			</div>
 		</div>
 		<div class="control-group">
-			<label class="control-label">类型</label>
+			<label class="control-label">机构ID</label>
 			<div class="controls">
-				<select class="input-small" name="type" disabled="disabled" id="examType">
-                	 <option value="${exam.type.value}">${exam.type.name}</option>
-            	</select>
+				<input name="rootOrgId" value="${dataSync.rootOrgId }" class="required"/>
 			</div>
 		</div>
 		<div class="control-group">
-			<label class="control-label">强制标记</label>
+			<label class="control-label">appId</label>
 			<div class="controls">
-				<input name="forceSpecialTag" type="checkbox" <c:if test="${exam.forceSpecialTag}">checked</c:if>/>
+				<input name="appId" value="${dataSync.appId }" class="required"/>
 			</div>
 		</div>
 		<div class="control-group">
-			<label class="control-label">及格分</label>
+			<label class="control-label">密钥</label>
 			<div class="controls">
-				<input name="passScore" type="number" value="${exam.passScore }"class="required" oninput="if(value<0)value=0"/>
+				<input name="secretKey" value="${dataSync.secretKey }" class="required"/>
 			</div>
 		</div>
 		<div class="control-group">
-			<label class="control-label">优秀分</label>
+			<label class="control-label">云平台考试ID</label>
 			<div class="controls">
-				<input name="excellentScore" type="number" value="${exam.excellentScore }" class="required" oninput="if(value<0)value=0"/>
+				<input name="cloudExamId" value="${dataSync.cloudExamId }" class="required"/>
 			</div>
 		</div>
 		<div class="control-group">
-			<label class="control-label">状态</label>
+			<label class="control-label">考生接口地址</label>
 			<div class="controls">
-				<select class="input-small" name="StatusValue">
-                <c:forEach items="${statusList}" var="item">
-                	 <option value="${item.value}" <c:if test="${item.value==exam.status.value}">selected</c:if>>${item.name}</option>
-                </c:forEach>
-            </select>
+				<textarea name="studentUrl" class="input-xxlarge required">${dataSync.studentUrl }</textarea>
 			</div>
 		</div>
+		<div class="control-group">
+			<label class="control-label">试卷结构接口地址</label>
+			<div class="controls">
+				<textarea name="subjectUrl" class="input-xxlarge required">${dataSync.subjectUrl }</textarea>
+			</div>
+		</div>
+
 		<div class="form-actions">
-			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
+			<c:if test="${!dataSync.finished || running }">
+			<input id="btnSubmit" class="btn btn-primary" type="submit" value="开始同步"/>
+			</c:if>
+			<c:if test="${dataSync.cloudExamId!=null }">
+			&nbsp;
+			<a href="${ctx}/admin/exam/data/sync/${dataSync.cloudExamId }/export">下载试卷结构</a>
+			</c:if>
 			&nbsp;
 			<a href="${ctx}/admin/exam-list" class="btn"/>返回</a>
 		</div>

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

@@ -55,8 +55,11 @@
     				<a href="${ctx}/admin/exam-view/${exam.id}">详情</a>
     				<c:if test="${web_user.schoolAdmin==true}">
     				&nbsp;
-    				<a href="${ctx}/admin/exam-edit/${exam.id}">编辑</a>
-    				<a href="${ctx}/admin/exam/problem/type?examId=${exam.id}">问题卷分类</a>
+    					<a href="${ctx}/admin/exam-edit/${exam.id}">编辑</a>
+    					<a href="${ctx}/admin/exam/problem/type?examId=${exam.id}">问题卷分类</a>
+    					<c:if test="${exam.type=='MULTI_MEDIA'}">
+    					<a href="${ctx}/admin/exam/data/sync?examId=${exam.id}">数据同步</a>
+    					</c:if>
     				</c:if>
 				</td>
 			</tr>

+ 3 - 0
stmms-web/src/main/webapp/WEB-INF/views/modules/exam/scoreList.jsp

@@ -95,7 +95,10 @@
 		<c:forEach items="${query.result}" var="student">
 			<tr>
 				<td>
+				<c:if test="${examType=='MULTI_MEDIA'}">${student.examNumber}</c:if>
+				<c:if test="${examType!='MULTI_MEDIA'}">
 				<a href="##" class="detail-link" data-exam-number="${student.examNumber}">${student.examNumber}</a>
+				</c:if>
 				</td>
 				<td>${student.name}</td>
 				<td>${student.studentCode}</td>

+ 3 - 1
stmms-web/src/main/webapp/WEB-INF/views/modules/exam/studentList.jsp

@@ -101,7 +101,7 @@
 			<input type="text" name="batchCode" value="${query.batchCode}" maxlength="30" class="input-small"/>
 			<br><br>
 			&nbsp;<input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
-			<c:if test="${web_user.schoolAdmin==true}">
+			<c:if test="${web_user.schoolAdmin==true && examType!='MULTI_MEDIA'}">
 			&nbsp;<a href="${ctx}/admin/exam/student/add" class="btn btn-primary">添加</a>
 			&nbsp;<input id="btnImport" class="btn" type="button" value="导入"/>
 			&nbsp;<div class="btn-group">
@@ -201,9 +201,11 @@
 				<td>
 				    <c:if test="${web_user.schoolAdmin==true}">
     				<a href="${ctx}/admin/exam/student/update?id=${student.id}">修改</a>
+    				<c:if test="${examType!='MULTI_MEDIA'}">
 					&nbsp;
     				<a href="${ctx}/admin/exam/student/delete?id=${student.id}" onclick="return confirmx('确认要删除该考生吗?', this.href)">删除</a>
 					</c:if>
+					</c:if>
 				</td>
 			</tr>
 		</c:forEach>

+ 14 - 8
stmms-web/src/main/webapp/static/mark-json/js/json-loader.js

@@ -17,13 +17,19 @@ JsonLoader.prototype.build = function (task, callback) {
 //         var result = '[{"mainNumber": 2,"subNumber": 10,"body": {"sections": [{ "blocks":[{"type": "text","value": "我是题目我是题目我是题目"}]}]},"answer": {"sections": [{"blocks":[{"type": "image","value": "https://ecs-test-static.qmth.com.cn/oe-answer-file/3/8/20/3_8_20_15748452889591137.jpeg"}]},{"blocks":[{"type": "audio","value": "https://ecs-test-static.qmth.com.cn/oe-answer-file/3/8/19/3_8_19_15748452552644264.mp3"}]}]},"studentAnswer": {"sections": [{"blocks":[{"type": "image","value": "https://ecs-test-static.qmth.com.cn/oe-answer-file/3/8/20/3_8_20_15748452889591137.jpeg"},{"type": "image","value": "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1582709869784&di=39683b1330bd09bebd93c95fe925ca70&imgtype=0&src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn10108%2F170%2Fw600h370%2F20190222%2Fd6de-htknpmh2595255.jpg"},{"type": "text","value": "我是答案答案daan"}]}]}}]';
 //         task.jsonData = JSON.parse(result);
 //         callback();
-        var url = this.jsonServer + task.jsonUrl;
-        $.get(url, function (result) {
-            task.jsonData = JSON.parse(result);
-            callback();
-        }).error(function () {
-            console.log('json load error:' + url);
-            callback('json load error');
-        });
+         var url = this.jsonServer + task.jsonUrl;
+         $.ajax({  
+             type:"GET",  
+             url:url,  
+             dataType:"json",  
+             success:function(data){
+	             task.jsonData = data;
+	             callback();
+             },
+             error:function () {
+                 console.log('json load error:' + url);
+                 callback('json load error');
+             }
+         });
     }
 }

+ 3 - 1
stmms-web/src/main/webapp/static/mark-new/js/modules/mark-board.js

@@ -26,7 +26,9 @@ function MarkBoard(option) {
         this.initByTask(context.task);
     });
     this.markControl.on('history.submit.success', this, function (event, context, eventObject) {
-        this.initByTask(context.task);
+    	if(context.task != undefined){
+    		this.initByTask(context.task);
+    	}
     });
     this.markControl.on('mark.focus.change', this, function (event, context, eventObject) {
         this.onFocusChange();