Преглед на файлове

多媒体下修复下载试卷结构;接口获取后生成任务问题

ting.yin преди 5 години
родител
ревизия
01c319257d

+ 12 - 8
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/DataSyncController.java

@@ -9,12 +9,13 @@ import javax.servlet.http.HttpServletResponse;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 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;
@@ -42,6 +43,8 @@ import cn.com.qmth.stmms.common.utils.ExportExcel;
 @RequestMapping("/admin/exam/data/sync")
 public class DataSyncController extends BaseExamController {
 
+    protected static Logger log = LoggerFactory.getLogger(DataSyncController.class);
+
     @Autowired
     private ExamSubjectService subjectService;
 
@@ -124,7 +127,7 @@ public class DataSyncController extends BaseExamController {
         int examId = getSessionExamId(request);
         if (lockService.trylock(LockType.DATA_SYNC, examId)) {
             DataSyncThread thread = new DataSyncThread(dataSync, pageSize, baseDir, config, lockService,
-                    dataSyncService, examService, studentService);
+                    dataSyncService, examService, studentService, subjectService);
             taskExecutor.submit(thread);
         }
         DataSync sync = dataSyncService.findByExamId(examId);
@@ -136,21 +139,22 @@ public class DataSyncController extends BaseExamController {
         return "redirect:/admin/exam-list";
     }
 
-    @RequestMapping(value = "/{cloudExamId}/export", method = RequestMethod.GET)
+    @RequestMapping(value = "/export", method = RequestMethod.GET)
     @RoleRequire(Role.SCHOOL_ADMIN)
-    public ModelAndView exportFile(@PathVariable Long cloudExamId, HttpServletRequest request,
-            HttpServletResponse response, RedirectAttributes redirectAttributes) {
+    public ModelAndView exportFile(HttpServletRequest request, HttpServletResponse response,
+            RedirectAttributes redirectAttributes) {
         int examId = getSessionExamId(request);
         DataSync sync = dataSyncService.findByExamId(examId);
         try {
-            List<SubjectiveQuestionDTO> list = getPaperStruct(sync.getSubjectUrl(), cloudExamId);
+            List<SubjectiveQuestionDTO> list = getPaperStruct(sync.getSubjectUrl(), sync.getCloudExamId());
             new ExportExcel("主观题数据", SubjectiveQuestionDTO.class, 2).setDataList(list).write(response, "主观题数据.xlsx")
                     .dispose();
             return null;
         } catch (Exception e) {
+            log.error("export sync subject:", e);
             addMessage(redirectAttributes, "导出数据失败!失败信息:" + e.getMessage());
         }
-        return new ModelAndView("redirect:/admin/exam");
+        return new ModelAndView("redirect:/admin/exam/sync?examId=" + examId);
     }
 
     private List<SubjectiveQuestionDTO> getPaperStruct(String url, Long cloudExamId) {
@@ -166,7 +170,7 @@ public class DataSyncController extends BaseExamController {
             JSONObject subject = subjectArray.getJSONObject(i);
             JSONArray questionArray = subject.getJSONArray("questions");
             for (int j = 0; j < questionArray.size(); j++) {
-                JSONObject question = questionArray.getJSONObject(i);
+                JSONObject question = questionArray.getJSONObject(j);
                 SubjectiveQuestionDTO questionDTO = new SubjectiveQuestionDTO();
                 questionDTO.setSubjectCode(subject.getString("subjectCode"));
                 questionDTO.setSubjectName(subject.getString("subjectName"));

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

@@ -20,6 +20,7 @@ import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
 import cn.com.qmth.stmms.biz.exam.service.DataSyncService;
 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.lock.LockService;
 import cn.com.qmth.stmms.common.enums.LockType;
 import cn.com.qmth.stmms.common.utils.PictureUrlBuilder;
@@ -32,6 +33,8 @@ public class DataSyncThread implements Runnable {
 
     private ExamStudentService studentService;
 
+    private ExamSubjectService subjectService;
+
     private ExamService examService;
 
     private LockService lockService;
@@ -66,12 +69,13 @@ public class DataSyncThread implements Runnable {
 
     public DataSyncThread(DataSync dataSync, Integer pageSize, String baseDir, UpyunConfig config,
             LockService lockService, DataSyncService dataSyncService, ExamService examService,
-            ExamStudentService studentService) {
+            ExamStudentService studentService, ExamSubjectService subjectService) {
         this.dataSync = dataSync;
         this.lockService = lockService;
         this.dataSyncService = dataSyncService;
         this.examService = examService;
         this.studentService = studentService;
+        this.subjectService = subjectService;
         this.pageSize = pageSize;
         this.baseDir = baseDir;
         this.config = config;
@@ -134,6 +138,7 @@ public class DataSyncThread implements Runnable {
                         JSONObject student = studentArray.getJSONObject(j);
                         ExamStudent examStudent = new ExamStudent();
                         examStudent.setExamId(sync.getExamId());
+
                         examStudent.setStudentCode(student.getString("studentCode"));
                         examStudent.setName(student.getString("name"));
                         examStudent.setCollege(DEFAULT_NULL);
@@ -171,7 +176,11 @@ public class DataSyncThread implements Runnable {
                         fos.write(answerJson.getBytes());
                         fos.close();
                     }
-                    studentService.batchSave(list);
+                    int count = studentService.batchSave(list);
+                    if (count > 0) {
+                        subjectService.updateUploadCount(exam.getId(), subjectCode,
+                                (int) studentService.countUploadedByExamIdAndSubjectCode(exam.getId(), subjectCode));
+                    }
                     sync.setUpdateTime(new Date());
                     sync.setNextId(nextId);
                     sync.setSubjectCode(subjectCode);

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

@@ -42,44 +42,44 @@
 		<div class="control-group">
 			<label class="control-label">机构ID</label>
 			<div class="controls">
-				<input name="rootOrgId" value="${dataSync.rootOrgId }" class="required"/>
+				<input name="rootOrgId" value="${dataSync.rootOrgId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
 			</div>
 		</div>
 		<div class="control-group">
 			<label class="control-label">appId</label>
 			<div class="controls">
-				<input name="appId" value="${dataSync.appId }" class="required"/>
+				<input name="appId" value="${dataSync.appId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
 			</div>
 		</div>
 		<div class="control-group">
 			<label class="control-label">密钥</label>
 			<div class="controls">
-				<input name="secretKey" value="${dataSync.secretKey }" class="required"/>
+				<input name="secretKey" value="${dataSync.secretKey }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
 			</div>
 		</div>
 		<div class="control-group">
 			<label class="control-label">云平台考试ID</label>
 			<div class="controls">
-				<input name="cloudExamId" value="${dataSync.cloudExamId }" class="required"/>
+				<input name="cloudExamId" value="${dataSync.cloudExamId }" class="required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>/>
 			</div>
 		</div>
 		<div class="control-group">
 			<label class="control-label">考生接口地址</label>
 			<div class="controls">
-				<textarea name="studentUrl" class="input-xxlarge required">${dataSync.studentUrl }</textarea>
+				<textarea name="studentUrl" class="input-xxlarge required" <c:if test="${dataSync.cloudExamId!=null }">readonly</c:if>>${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>
+				<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 }">
 		<div class="control-group">
 			<label class="control-label">试卷结构</label>
 			<div class="controls">
-				<a href="${ctx}/admin/exam/data/sync/${dataSync.cloudExamId }/export">下载</a>
+				<a href="${ctx}/admin/exam/data/sync/export">下载</a>
 			</div>
 		</div>
 		</c:if>