Explorar o código

多媒体阅卷前端逻辑调整;兼容将来在线考试平台对数据结构

luoshi %!s(int64=4) %!d(string=hai) anos
pai
achega
1cf3c0f326

+ 173 - 173
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/mark/model/MarkStepDTO.java

@@ -1,173 +1,173 @@
-package cn.com.qmth.stmms.biz.mark.model;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang3.StringUtils;
-
-public class MarkStepDTO implements Serializable {
-
-    private static final long serialVersionUID = 3542801746602688750L;
-
-    private String questionNumber;
-
-    private int blockId;
-
-    private int number;
-
-    private String title;
-
-    private boolean hasLevel;
-
-    private double totalScore;
-
-    private double max;
-
-    private double min;
-
-    private double defaultScore;
-
-    private double interval;
-
-    private double[] scoreList;
-
-    private String remark;
-
-    private List<TrackDTO> trackList = new ArrayList<TrackDTO>();
-
-    public String getQuestionNumber() {
-        return questionNumber;
-    }
-
-    public void setQuestionNumber(String questionNumber) {
-        this.questionNumber = questionNumber;
-    }
-
-    public double[] getScoreArray() {
-        return scoreList;
-    }
-
-    public double[] getScoreList() {
-        return scoreList;
-    }
-
-    public void setScoreList(double[] scoreList) {
-        this.scoreList = scoreList;
-    }
-
-    public void setScoreList(String scoreListValue) {
-        String[] values = StringUtils.split(StringUtils.trimToEmpty(scoreListValue), ",");
-        if (values != null && values.length > 0) {
-            List<Double> list = new ArrayList<Double>(values.length);
-            for (String value : values) {
-                try {
-                    list.add(Double.valueOf(value));
-                } catch (Exception e) {
-                    continue;
-                }
-            }
-            int length = list.size();
-            if (length > 0) {
-                double[] array = new double[length];
-                for (int i = 0; i < length; i++) {
-                    array[i] = list.get(i);
-                }
-                this.scoreList = array;
-            }
-        }
-    }
-
-    public int getBlockId() {
-        return blockId;
-    }
-
-    public void setBlockId(int blockId) {
-        this.blockId = blockId;
-    }
-
-    public int getNumber() {
-        return number;
-    }
-
-    public void setNumber(int number) {
-        this.number = number;
-    }
-
-    public boolean isHasLevel() {
-        return hasLevel;
-    }
-
-    public void setHasLevel(boolean hasLevel) {
-        this.hasLevel = hasLevel;
-    }
-
-    public double getTotalScore() {
-        return totalScore;
-    }
-
-    public void setTotalScore(double totalScore) {
-        this.totalScore = totalScore;
-    }
-
-    public double getMax() {
-        return max;
-    }
-
-    public void setMax(double max) {
-        this.max = max;
-    }
-
-    public double getMin() {
-        return min;
-    }
-
-    public void setMin(double min) {
-        this.min = min;
-    }
-
-    public double getDefaultScore() {
-        return defaultScore;
-    }
-
-    public void setDefaultScore(double defaultScore) {
-        this.defaultScore = defaultScore;
-    }
-
-    public String getRemark() {
-        return remark;
-    }
-
-    public void setRemark(String remark) {
-        this.remark = remark;
-    }
-
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public double getInterval() {
-        return interval;
-    }
-
-    public void setInterval(double interval) {
-        this.interval = interval;
-    }
-
-    public List<TrackDTO> getTrackList() {
-        return trackList;
-    }
-
-    public void setTrackList(List<TrackDTO> trackList) {
-        this.trackList = trackList;
-    }
-
-    public void addTrack(TrackDTO track) {
-        this.trackList.add(track);
-    }
-
-}
+package cn.com.qmth.stmms.biz.mark.model;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class MarkStepDTO implements Serializable {
+
+    private static final long serialVersionUID = 3542801746602688750L;
+
+    private String questionNumber;
+
+    private int mainNumber;
+
+    private int subNumber;
+
+    private int number;
+
+    private String title;
+
+    private double totalScore;
+
+    private double max;
+
+    private double min;
+
+    private double defaultScore;
+
+    private double interval;
+
+    private double[] scoreList;
+
+    private String remark;
+
+    private List<TrackDTO> trackList = new ArrayList<TrackDTO>();
+
+    public String getQuestionNumber() {
+        return questionNumber;
+    }
+
+    public void setQuestionNumber(String questionNumber) {
+        this.questionNumber = questionNumber;
+    }
+
+    public double[] getScoreArray() {
+        return scoreList;
+    }
+
+    public double[] getScoreList() {
+        return scoreList;
+    }
+
+    public void setScoreList(double[] scoreList) {
+        this.scoreList = scoreList;
+    }
+
+    public void setScoreList(String scoreListValue) {
+        String[] values = StringUtils.split(StringUtils.trimToEmpty(scoreListValue), ",");
+        if (values != null && values.length > 0) {
+            List<Double> list = new ArrayList<Double>(values.length);
+            for (String value : values) {
+                try {
+                    list.add(Double.valueOf(value));
+                } catch (Exception e) {
+                    continue;
+                }
+            }
+            int length = list.size();
+            if (length > 0) {
+                double[] array = new double[length];
+                for (int i = 0; i < length; i++) {
+                    array[i] = list.get(i);
+                }
+                this.scoreList = array;
+            }
+        }
+    }
+
+    public int getMainNumber() {
+        return mainNumber;
+    }
+
+    public void setMainNumber(int mainNumber) {
+        this.mainNumber = mainNumber;
+    }
+
+    public int getSubNumber() {
+        return subNumber;
+    }
+
+    public void setSubNumber(int subNumber) {
+        this.subNumber = subNumber;
+    }
+
+    public int getNumber() {
+        return number;
+    }
+
+    public void setNumber(int number) {
+        this.number = number;
+    }
+
+    public double getTotalScore() {
+        return totalScore;
+    }
+
+    public void setTotalScore(double totalScore) {
+        this.totalScore = totalScore;
+    }
+
+    public double getMax() {
+        return max;
+    }
+
+    public void setMax(double max) {
+        this.max = max;
+    }
+
+    public double getMin() {
+        return min;
+    }
+
+    public void setMin(double min) {
+        this.min = min;
+    }
+
+    public double getDefaultScore() {
+        return defaultScore;
+    }
+
+    public void setDefaultScore(double defaultScore) {
+        this.defaultScore = defaultScore;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public double getInterval() {
+        return interval;
+    }
+
+    public void setInterval(double interval) {
+        this.interval = interval;
+    }
+
+    public List<TrackDTO> getTrackList() {
+        return trackList;
+    }
+
+    public void setTrackList(List<TrackDTO> trackList) {
+        this.trackList = trackList;
+    }
+
+    public void addTrack(TrackDTO track) {
+        this.trackList.add(track);
+    }
+
+}

+ 2 - 2
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/mark/service/Impl/TaskServiceImpl.java

@@ -251,12 +251,12 @@ public class TaskServiceImpl implements TaskService {
     private MarkStepDTO buildStep(int number, ExamQuestion question) {
         MarkStepDTO step = new MarkStepDTO();
         step.setQuestionNumber(question.getQuestionNumber());
-        step.setBlockId(question.getMainNumber());
+        step.setMainNumber(question.getMainNumber());
+        step.setSubNumber(question.getSubNumber());
         step.setNumber(number);
         step.setTitle(question.getMainTitle() + "-" + question.getSubNumber());
         step.setTotalScore(question.getTotalScore());
         step.setDefaultScore(0d);
-        step.setHasLevel(false);
         step.setMax(question.getTotalScore());
         step.setMin(0d);
         step.setInterval(question.getIntervalScore());

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

@@ -70,9 +70,9 @@ public class DataSyncThread implements Runnable {
 
     public static final String SIZE = "size";
 
-    public DataSyncThread(DataSync dataSync, Integer pageSize, LockService lockService,
-            DataSyncService dataSyncService, ExamService examService, ExamStudentService studentService,
-            ExamSubjectService subjectService, FileService fileService) {
+    public DataSyncThread(DataSync dataSync, Integer pageSize, LockService lockService, DataSyncService dataSyncService,
+            ExamService examService, ExamStudentService studentService, ExamSubjectService subjectService,
+            FileService fileService) {
         this.dataSync = dataSync;
         this.lockService = lockService;
         this.dataSyncService = dataSyncService;
@@ -117,8 +117,9 @@ public class DataSyncThread implements Runnable {
                 JSONObject paperJson = JSONObject.fromObject(paperResult);
                 String paper = paperJson.getString("subjectivePaper");
                 byte[] paperData = paper.getBytes(StandardCharsets.UTF_8);
-                fileService.uploadPaper(new ByteArrayInputStream(paperData), BinaryUtil.encodeMD5(paperData),
-                        exam.getId(), subjectCode, FormatType.JSON);
+                fileService
+                        .uploadPaper(new ByteArrayInputStream(paperData), BinaryUtil.encodeMD5(paperData), exam.getId(),
+                                subjectCode, FormatType.JSON);
                 // 获取考生
                 Long startId = 0L;
                 ExamSubject examSubject = subjectService.find(exam.getId(), subjectCode);
@@ -166,6 +167,7 @@ public class DataSyncThread implements Runnable {
                         examStudent.setSubjectCode(subjectCode);
                         examStudent.setSubjectName(subjectName);
                         examStudent.setExamNumber(student.getString("examNumber"));
+                        examStudent.setSecretNumber(examStudent.getExamNumber());
                         examStudent.setPaperType(null);
 
                         examStudent.setSchoolId(exam.getSchoolId());
@@ -182,7 +184,6 @@ public class DataSyncThread implements Runnable {
                         examStudent.setAnswers(null);
                         examStudent.setBatchCode(null);
                         examStudent.setUploadTime(now);
-                        examStudent.setSecretNumber(examStudent.getExamNumber());
                         list.add(examStudent);
 
                         String answerJson = student.getString(SUBJECTIVES);

+ 5 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/api/controller/FileController.java

@@ -157,6 +157,11 @@ public class FileController extends BaseApiController {
         ExamStudent student = validateExamStudent(examId, examNumber);
         try {
             fileService.uploadJson(file.getInputStream(), md5, examId, student.getSecretNumber());
+            student.setUpload(true);
+            student.setAbsent(false);
+            student.setBatchCode(StringUtils.EMPTY);
+            student.setAnswers(StringUtils.EMPTY);
+            saveUploadStudent(student);
         } catch (Exception e) {
             log.error("json upload error", e);
             throw ApiException.FILE_UPLOAD_ERROR.replaceMessage("json upload error: " + e.getMessage());

+ 36 - 27
stmms-web/src/main/webapp/static/mark-json/js/json-loader.js

@@ -17,32 +17,41 @@ 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 answerUrl = this.jsonServer + task.jsonUrl;
-         var paperUrl = this.jsonServer + task.paperUrl;
-         $.ajax({  
-             type:"GET",  
-             url:paperUrl,  
-             dataType:"json",  
-             success:function(data){
-	             task.paperData = data;
-             },
-             error:function () {
-                 console.log('json load error:' + url);
-                 callback('json load error');
-             }
-         });
-         $.ajax({  
-             type:"GET",  
-             url:answerUrl,  
-             dataType:"json",  
-             success:function(data){
-	             task.jsonData = data;
-	             callback();
-             },
-             error:function () {
-                 console.log('json load error:' + url);
-                 callback('json load error');
-             }
-         });
+        let promises = []
+        promises.push(new Promise((resolve, reject) => {
+            $.ajax({
+                type: "GET",
+                url: self.jsonServer + task.paperUrl,
+                dataType: "json",
+                success: function (data) {
+                    task.paperData = data
+                    resolve()
+                },
+                error: function () {
+                    console.log('paper load error:' + self.jsonServer + task.paperUrl);
+                    reject('paper load error');
+                }
+            });
+        }))
+        promises.push(new Promise((resolve, reject) => {
+            $.ajax({
+                type: "GET",
+                url: self.jsonServer + task.jsonUrl,
+                dataType: "json",
+                success: function (data) {
+                    task.jsonData = data;
+                    resolve();
+                },
+                error: function () {
+                    console.log('json load error:' + self.jsonServer + task.jsonUrl);
+                    reject('json load error');
+                }
+            });
+        }))
+        Promise.all(promises).then(() => {
+            callback()
+        }).catch(error => {
+            callback(error)
+        })
     }
 }

+ 74 - 30
stmms-web/src/main/webapp/static/mark-json/js/json-view.js

@@ -40,24 +40,16 @@ JsonView.prototype.init = function () {
 }
 
 JsonView.prototype.render = function () {
-    if (this.task != undefined && this.task.jsonData != undefined) {
-        let questionNumbers = {};
+    if (this.task != undefined) {
         this.task.markStepList.forEach(step => {
-            questionNumbers[step.questionNumber] = true;
-        });
-
-        let questions = this.task.jsonData || [];
-        let paperqQuestions = this.task.paperData || [];
-        for (var j in questions) {
-        	var question = questions[j];
-        	var paperQuestion = paperqQuestions[j];
-            // 按题号过滤
-            if (questionNumbers[question.mainNumber + "." + question.subNumber] === true) {
+            let question = this.findQuestion(step.mainNumber, step.subNumber, this.task.paperData)
+            let jsons = this.findJson(step.mainNumber, step.subNumber, this.task.jsonData)
+            if (question != undefined && jsons.length > 0) {
                 let numberTitle = {
                     "blocks": [{
                         "type": "text",
                         "param": {"bold": true},
-                        "value": "题号:" + question.mainNumber + "-" + question.subNumber
+                        "value": "题号:" + step.mainNumber + "-" + step.subNumber
                     }]
                 };
                 let bodyTitle = {
@@ -78,7 +70,7 @@ JsonView.prototype.render = function () {
                             "italic": true,
                             "danger": true
                         },
-                        "value": "(字数统计:" + this.textCount(question.studentAnswer) + ")"
+                        "value": "(字数统计:" + this.textCount(jsons) + ")"
                     }]
                 };
                 let standardTitle = {
@@ -90,16 +82,19 @@ JsonView.prototype.render = function () {
                 };
                 $(renderSection(numberTitle)).appendTo(this.holder);
                 $(renderSection(bodyTitle)).appendTo(this.holder);
-                if(question.parentBody!=null && question.parentBody!=undefined){
-					$(renderRichText(question.parentBody)).appendTo(this.holder); 
-				}
+                if (question.parentBody != null && question.parentBody != undefined) {
+                    $(renderRichText(question.parentBody)).appendTo(this.holder);
+                }
                 $(renderRichText(question.body)).appendTo(this.holder);
                 $(renderSection(answerTitle)).appendTo(this.holder);
-                $(renderRichText(question.studentAnswer)).appendTo(this.holder);
+                jsons.forEach(data => {
+                    $(renderRichText(data.answer)).appendTo(this.holder);
+                })
                 $(renderSection(standardTitle)).appendTo(this.holder);
                 $(renderRichText(question.answer)).appendTo(this.holder);
             }
-        }
+        });
+
         if (this.viewer != undefined) {
             this.viewer.destroy();
         }
@@ -110,18 +105,67 @@ JsonView.prototype.render = function () {
     }
 }
 
-JsonView.prototype.textCount = function (jsonBody) {
-    let sections = jsonBody.sections || [];
-    let count = 0;
-    sections.forEach(section => {
-        let blocks = section.blocks || [];
-        blocks.forEach(block => {
-            if (block.type === 'text' && block.value != undefined) {
-                count += block.value.length;
-            }
-        });
-    });
+JsonView.prototype.textCount = function (jsons) {
+    jsons = Array.isArray(jsons) ? jsons : []
+    let count = 0
+    jsons.forEach(data => {
+        count += this.jsonTextCount(data.answer)
+    })
     return count;
 }
 
+JsonView.prototype.jsonTextCount = function (jsonData) {
+    let count = 0
+    if (Array.isArray(jsonData)) {
+        for (let i in jsonData) {
+            count += this.jsonTextCount(jsonData[i])
+        }
+    } else {
+        let sections = Array.isArray(jsonData.sections) ? jsonData.sections : [];
+        sections.forEach(section => {
+            let blocks = Array.isArray(section.blocks) ? section.blocks : [];
+            blocks.forEach(block => {
+                if (block.type === 'text' && block.value != undefined) {
+                    count += block.value.length;
+                }
+            });
+        });
+    }
+    return count
+}
+
+JsonView.prototype.findJson = function (mainNumber, subNumber, jsonData) {
+    jsonData = Array.isArray(jsonData) ? jsonData : {}
+    let result = []
+    for (let i in jsonData) {
+        if (jsonData[i].mainNumber === mainNumber && jsonData[i].subNumber === subNumber) {
+            result.push(jsonData[i])
+        }
+    }
+    return result
+}
+
+JsonView.prototype.findQuestion = function (mainNumber, subNumber, paperData) {
+    paperData = paperData || {}
+    if (Array.isArray(paperData.details)) {
+        for (let i in paperData.details) {
+            let detail = paperData.details[i]
+            if (detail.number === mainNumber && Array.isArray(detail.questions)) {
+                for (let j in detail.questions) {
+                    if (detail.questions[j].number === subNumber) {
+                        return detail.questions[j]
+                    }
+                }
+            }
+        }
+    } else if (Array.isArray(paperData.questions)) {
+        for (let j in paperData.questions) {
+            if (paperData.questions[j].mainNumber === mainNumber && paperData.questions[j].subNumber === subNumber) {
+                return paperData.questions[j]
+            }
+        }
+    }
+    return undefined
+}
+
 JsonView.prototype.holder_dom = '<div class="rich-text"></div>';

+ 36 - 30
stmms-web/src/main/webapp/static/rich-text/js/render.js

@@ -1,54 +1,60 @@
-const _richText_text_styles_ = ['bold', 'underline', 'italic', 'danger', 'sup', 'sub'];
+const _richText_text_styles_ = ['bold', 'underline', 'italic', 'danger', 'sup', 'sub']
 
 function renderRichText(body) {
-    let sections = body.sections || [];
-    let nodes = [];
-    sections.forEach(section => {
-        nodes.push(renderSection(section));
-    });
-    return nodes;
+    let nodes = []
+    if (Array.isArray(body)) {
+        body.forEach(part => {
+            nodes.push(renderRichText(part))
+        })
+    } else {
+        let sections = Array.isArray(body.sections) ? body.selectNode() : []
+        sections.forEach(section => {
+            nodes.push(renderSection(section))
+        })
+    }
+    return nodes
 }
 
 function renderSection(section) {
-    let blocks = section.blocks || [];
-//    let inline = blocks.length > 1;
-    let node = document.createElement('p');
+    let blocks = Array.isArray(section.blocks) ? section.blocks : []
+    let inline = blocks.length > 1
+    let node = document.createElement('p')
     blocks.forEach(block => {
-        node.appendChild(renderBlock(block, true));
-    });
-    return node;
+        node.appendChild(renderBlock(block, inline))
+    })
+    return node
 }
 
 function renderBlock(block, inline) {
-    let container = document.createElement('span');
-    let type = '';
+    let container = document.createElement('span')
+    let type = ''
     if (block.type === 'text') {
-        type = 'text';
+        type = 'text'
         if (block.param != undefined) {
             _richText_text_styles_.forEach(style => {
                 if (block.param[style] === true) {
-                    type += ' ' + style;
+                    type += ' ' + style
                 }
             })
         }
-        container.textContent = block.value;
+        container.textContent = block.value
     } else if (block.type === 'image') {
-        type = 'image loading';
+        type = 'image loading'
         if (inline === true) {
-            type += ' inline';
+            type += ' inline'
         }
-        let img = container.appendChild(new Image());
-        img.src = block.value;
+        let img = container.appendChild(new Image())
+        img.src = block.value
         img.onload = function () {
-            this.parentNode.className = this.parentNode.className.replace(/loading/g, '');
+            this.parentNode.className = this.parentNode.className.replace(/loading/g, '')
         }
     } else if (block.type === 'audio') {
-        type = 'audio';
-        let audio = container.appendChild(new Audio());
-        audio.src = block.value;
-        audio.controls = true;
-        audio.setAttribute("type", "audio/mpeg");
+        type = 'audio'
+        let audio = container.appendChild(new Audio())
+        audio.src = block.value
+        audio.controls = true
+        audio.setAttribute("type", "audio/mpeg")
     }
-    container.className = type;
-    return container;
+    container.className = type
+    return container
 }