Browse Source

3.0.1-同步

xiaof 3 years ago
parent
commit
df07c7549e
13 changed files with 239 additions and 41 deletions
  1. 2 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/ExamPaperStructureStatusEnum.java
  2. 2 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/DataSyncService.java
  3. 6 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamPaperGroupMarkerService.java
  4. 6 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamPaperGroupService.java
  5. 126 11
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java
  6. 7 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPaperGroupMarkerServiceImpl.java
  7. 7 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPaperGroupServiceImpl.java
  8. 3 3
      distributed-print/src/main/resources/application-test.properties
  9. 12 2
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/stmms/GroupDTO.java
  10. 9 19
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/stmms/GroupDetailDTO.java
  11. 54 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/stmms/PicConfig.java
  12. 0 2
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/AttachmentCommonServiceImpl.java
  13. 5 4
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/StmmsUtils.java

+ 2 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/ExamPaperStructureStatusEnum.java

@@ -17,6 +17,8 @@ public enum ExamPaperStructureStatusEnum {
     ANSWER_FINISH("标答同步成功"),
     OBJECTIVE_FINISH("客观题结构同步成功"),
     SUBJECTIVE_FINISH("主观题结构同步成功"),
+    GROUP_FINISH("分组同步成功"),
+    MARKER_FINISH("绑定评卷员同步成功"),
     FINISH("结束");
 
     ExamPaperStructureStatusEnum(String desc) {

+ 2 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/DataSyncService.java

@@ -1,5 +1,6 @@
 package com.qmth.distributed.print.business.service;
 
+import com.qmth.distributed.print.business.bean.marking.EvaluationParameters;
 import com.qmth.distributed.print.business.bean.params.SyncDataParam;
 import com.qmth.distributed.print.business.entity.ExamPaperStructure;
 
@@ -17,4 +18,5 @@ public interface DataSyncService {
 
     void syncPaperStructure(ExamPaperStructure examPaperStructure);
 
+    void syncPaperStructureAndGroup(ExamPaperStructure examPaperStructure);
 }

+ 6 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamPaperGroupMarkerService.java

@@ -27,4 +27,10 @@ public interface ExamPaperGroupMarkerService extends IService<ExamPaperGroupMark
      * @param groupIdSet 分组idSet
      */
     void deleteExamPaperGroupMarkerService(Set<Long> groupIdSet);
+
+    /**
+     * 查询评卷员
+     * @param id 分组Id
+     */
+    List<ExamPaperGroupMarker> listByGroupId(Long id);
 }

+ 6 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamPaperGroupService.java

@@ -26,4 +26,10 @@ public interface ExamPaperGroupService extends IService<ExamPaperGroup> {
      * @param examPaperStructureId 试卷结构id
      */
     void deleteExamPaperGroupInfo(Long examPaperStructureId);
+
+    /**
+     * 查询分组
+     * @param id 试卷结构表id
+     */
+    List<ExamPaperGroup> listByExamPaperStructureId(Long id);
 }

+ 126 - 11
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java

@@ -9,12 +9,15 @@ import com.qmth.distributed.print.business.bean.dto.ExamPaperObjectiveStructureD
 import com.qmth.distributed.print.business.bean.dto.ExamPaperSubjectiveStructureDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamCardDto;
 import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
+import com.qmth.distributed.print.business.bean.marking.EvaluationParameters;
 import com.qmth.distributed.print.business.bean.params.SyncDataParam;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
 import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.service.*;
+import com.qmth.teachcloud.common.bean.dto.stmms.GroupDetailDTO;
+import com.qmth.teachcloud.common.bean.dto.stmms.QuestionBaseDTO;
 import com.qmth.teachcloud.common.bean.dto.stmms.QuestionDTO;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
@@ -33,10 +36,10 @@ import com.qmth.teachcloud.common.util.ServletUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import java.io.*;
 import java.util.*;
 import java.util.concurrent.ExecutorService;
@@ -51,34 +54,40 @@ public class DataSyncServiceImpl implements DataSyncService {
 
     private final static Logger log = LoggerFactory.getLogger(DataSyncServiceImpl.class);
 
-    @Autowired
+    @Resource
     private ExamPrintPlanService examPrintPlanService;
 
-    @Autowired
+    @Resource
     private TBSyncTaskService tbSyncTaskService;
 
-    @Autowired
+    @Resource
     private ExamStudentService examStudentService;
 
-    @Autowired
+    @Resource
     private ExamDetailService examDetailService;
 
-    @Autowired
+    @Resource
     private ExamCardService examCardService;
 
-    @Autowired
+    @Resource
     private ExamPaperStructureService examPaperStructureService;
 
-    @Autowired
+    @Resource
     private SysConfigService sysConfigService;
 
-    @Autowired
+    @Resource
     private TeachcloudCommonService teachcloudCommonService;
 
-    @Autowired
+    @Resource
     private BasicAttachmentService basicAttachmentService;
 
-    @Autowired
+    @Resource
+    private ExamPaperGroupService examPaperGroupService;
+
+    @Resource
+    private ExamPaperGroupMarkerService examPaperGroupMarkerService;
+
+    @Resource
     StmmsUtils stmmsUtils;
 
     ExecutorService executorService = Executors.newFixedThreadPool(5);
@@ -159,6 +168,11 @@ public class DataSyncServiceImpl implements DataSyncService {
         executorService.execute(syncStructure(examPaperStructure));
     }
 
+    @Override
+    public void syncPaperStructureAndGroup(ExamPaperStructure examPaperStructure) {
+        executorService.execute(syncPaperStructureAndGroup1(examPaperStructure));
+    }
+
     /**
      * 同步基础信息
      *
@@ -198,6 +212,24 @@ public class DataSyncServiceImpl implements DataSyncService {
         };
     }
 
+    /**
+     * 同步试卷结构信息
+     *
+     * @param evaluationParameters
+     * @return
+     */
+    private TimerTask syncPaperStructureAndGroup1(ExamPaperStructure examPaperStructure) {
+        return new TimerTask() {
+            @Override
+            public void run() {
+                SysConfig sysConfig = sysConfigService.getByKey("sys.sync.enable");
+                if (sysConfig != null && "true".equals(sysConfig.getConfigValue())) {
+                    doSyncStructureAndGroup(examPaperStructure);
+                }
+            }
+        };
+    }
+
     public void doSyncStructure(ExamPaperStructure examPaperStructure) {
         // 开始同步
         examPaperStructureService.updateStatusById(examPaperStructure.getId(), ExamPaperStructureStatusEnum.START_SYNC);
@@ -312,6 +344,89 @@ public class DataSyncServiceImpl implements DataSyncService {
         }
     }
 
+    public void doSyncStructureAndGroup(ExamPaperStructure examPaperStructure) {
+        // 开始同步
+        examPaperStructureService.updateStatusById(examPaperStructure.getId(), ExamPaperStructureStatusEnum.START_SYNC);
+        ExamPaperStructureStatusEnum status = ExamPaperStructureStatusEnum.UPLOAD_FINISH;
+        try {
+            String paperTypes = examPaperStructure.getPaperType();
+            if (StringUtils.isBlank(paperTypes)) {
+                throw ExceptionResultEnum.ERROR.exception("没有可同步的试卷类型");
+            }
+
+            Long schoolId = examPaperStructure.getSchoolId();
+            // 云阅卷考试ID
+            String examId = String.valueOf(examPaperStructure.getThirdRelateId());
+            // 科目代码(课程代码+卷型+课程序号)
+            String subjectCode = examPaperStructure.getCourseCode().concat(examPaperStructure.getPaperType()).concat(examPaperStructure.getSequence());
+
+            // 同步主观题
+            String subjectiveStructure = examPaperStructure.getSubjectiveStructure();
+            if (StringUtils.isNotBlank(subjectiveStructure)) {
+                List<JSONObject> subjectiveJsons = JSONObject.parseArray(subjectiveStructure, JSONObject.class);
+                List<QuestionDTO> syncSubjectiveStructureDatas = subjectiveJsons.stream().map(m -> {
+                    QuestionDTO syncStructureData = new QuestionDTO();
+                    syncStructureData.setMainNumber(m.getInteger("mainNumber"));
+                    syncStructureData.setSubNumber(m.getString("subNumber"));
+                    syncStructureData.setMainTitle(m.getString("mainTitle"));
+                    syncStructureData.setTotalScore(m.getDouble("totalScore"));
+                    return syncStructureData;
+                }).collect(Collectors.toList());
+
+                stmmsUtils.syncPaperStructure(schoolId, examId, subjectCode, false, null, syncSubjectiveStructureDatas);
+            }
+//            status = ExamPaperStructureStatusEnum.FINISH;
+
+            // 同步分组
+            int countGroup = stmmsUtils.countGroup(schoolId, examId, subjectCode);
+            // 如果存在分组,先删掉
+            if (countGroup > 0) {
+                stmmsUtils.deleteGroup(schoolId, examId, subjectCode);
+            }
+            List<ExamPaperGroup> examPaperGroups = examPaperGroupService.listByExamPaperStructureId(examPaperStructure.getId());
+            if (!CollectionUtils.isEmpty(examPaperGroups)) {
+                List<GroupDetailDTO> groupDetailDTOS = new ArrayList<>();
+                for (ExamPaperGroup examPaperGroup : examPaperGroups) {
+                    GroupDetailDTO groupDetailDTO = new GroupDetailDTO();
+                    groupDetailDTO.setNumber(examPaperGroup.getGroupNumber());
+                    groupDetailDTO.setPicList(null);
+//                    groupDetailDTO.setDoubleRate();
+//                    groupDetailDTO.setArbitrateThreshold(examPaperGroup.getArbitrateThreshold());
+                    groupDetailDTO.setScorePolicy(examPaperGroup.getScorePolicy().getValue());
+//                    groupDetailDTO.setEnableAllZero();
+                    groupDetailDTO.setMarkMode("");
+                    String questionsString = examPaperGroup.getQuestionInfo();
+                    if (StringUtils.isNotBlank(questionsString)) {
+                        List<JSONObject> jsonObjects = JSONObject.parseArray(questionsString, JSONObject.class);
+                        List<QuestionBaseDTO> questionBaseDTOS = jsonObjects.stream().map(m -> {
+                            QuestionBaseDTO questionBaseDTO = new QuestionBaseDTO();
+                            questionBaseDTO.setMainNumber(m.getInteger("mainNumber"));
+                            questionBaseDTO.setSubNumber(m.getString("subNumber"));
+                            return questionBaseDTO;
+                        }).collect(Collectors.toList());
+                        groupDetailDTO.setQuestions(questionBaseDTOS);
+                    }
+                    groupDetailDTOS.add(groupDetailDTO);
+                }
+                stmmsUtils.saveMarkerGroup(schoolId, examId, subjectCode, 0, groupDetailDTOS);
+            }
+
+            // 同步绑定评卷员
+            for (ExamPaperGroup examPaperGroup : examPaperGroups) {
+                List<ExamPaperGroupMarker> examPaperGroupMarkers = examPaperGroupMarkerService.listByGroupId(examPaperGroup.getId());
+                for (ExamPaperGroupMarker examPaperGroupMarker : examPaperGroupMarkers) {
+                    stmmsUtils.saveMarkerGroup(schoolId, examId, subjectCode, examPaperGroup.getGroupNumber(), examPaperGroupMarker.getLoginName());
+                }
+            }
+
+        } catch (ApiException e) {
+            throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
+        } finally {
+            examPaperStructure.setStatus(status);
+            examPaperStructureService.updateById(examPaperStructure);
+        }
+    }
+
     /**
      * 同步核心方法
      *

+ 7 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPaperGroupMarkerServiceImpl.java

@@ -41,4 +41,11 @@ public class ExamPaperGroupMarkerServiceImpl extends ServiceImpl<ExamPaperGroupM
             this.remove(new QueryWrapper<ExamPaperGroupMarker>().lambda().in(ExamPaperGroupMarker::getGroupId, groupIdSet));
         }
     }
+
+    @Override
+    public List<ExamPaperGroupMarker> listByGroupId(Long id) {
+        QueryWrapper<ExamPaperGroupMarker> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(ExamPaperGroupMarker::getGroupId, id);
+        return this.baseMapper.selectList(queryWrapper);
+    }
 }

+ 7 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPaperGroupServiceImpl.java

@@ -81,4 +81,11 @@ public class ExamPaperGroupServiceImpl extends ServiceImpl<ExamPaperGroupMapper,
         // 删除分组信息
         this.removeByIds(groupIdSet);
     }
+
+    @Override
+    public List<ExamPaperGroup> listByExamPaperStructureId(Long id) {
+        QueryWrapper<ExamPaperGroup> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(ExamPaperGroup::getExamPaperStructureId, id);
+        return this.baseMapper.selectList(queryWrapper);
+    }
 }

+ 3 - 3
distributed-print/src/main/resources/application-test.properties

@@ -149,11 +149,11 @@ sync.config.structureUrl=/api/exam/paper/save
 # \uFFFD\u00FB\uFFFD\u036C\uFFFD\uFFFD
 sync.config.userSaveUrl=/api/user/external/save
 #????????
-sync.config.groupSaveUrl=/api/exam/group/save
+sync.config.groupSaveUrl=/api/exam/mark_group/save
 #????????
-sync.config.groupCountUrl=/api/exam/group/count
+sync.config.groupCountUrl=/api/exam/mark_group/count
 #????????
-sync.config.groupDeleteUrl=/api/exam/group/delete
+sync.config.groupDeleteUrl=/api/exam/mark_group/delete
 #???????
 sync.config.markerSaveUrl=/api/exam/marker/save
 

+ 12 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/stmms/GroupDTO.java

@@ -3,10 +3,12 @@ package com.qmth.teachcloud.common.bean.dto.stmms;
 import java.util.List;
 
 public class GroupDTO {
-
+    //是 考试ID
     private Integer examId;
-
+    //是 科目代码
     private String subjectCode;
+    //是 试评数量
+    private Integer trialCount;
 
     List<GroupDetailDTO> groups;
 
@@ -26,6 +28,14 @@ public class GroupDTO {
         this.subjectCode = subjectCode;
     }
 
+    public Integer getTrialCount() {
+        return trialCount;
+    }
+
+    public void setTrialCount(Integer trialCount) {
+        this.trialCount = trialCount;
+    }
+
     public List<GroupDetailDTO> getGroups() {
         return groups;
     }

+ 9 - 19
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/stmms/GroupDetailDTO.java

@@ -6,15 +6,13 @@ public class GroupDetailDTO {
     //是 分组序号
     private Integer number;
     //否
-    private String picList;
+    private List<PicConfig> picList;
     //是 双评比例 0关闭,1开启
-    private Integer doubleRate;
+    private Double doubleRate;
     //否 仲裁阈值 开启双评是必填
-    private Integer arbitrateThreshold;
+    private Double arbitrateThreshold;
     //否 合分策略 开启双评是必填 AVG("平均分", 1), MAX("最高分", 2), MIN("最低分", 3)
     private Integer scorePolicy;
-    //是 试评数量
-    private Integer trialCount;
     //否 允许全零分
     private Boolean enableAllZero;
     //否 评卷模式  COMMON("普通"), TRACK("轨迹")
@@ -30,27 +28,27 @@ public class GroupDetailDTO {
         this.number = number;
     }
 
-    public String getPicList() {
+    public List<PicConfig> getPicList() {
         return picList;
     }
 
-    public void setPicList(String picList) {
+    public void setPicList(List<PicConfig> picList) {
         this.picList = picList;
     }
 
-    public Integer getDoubleRate() {
+    public Double getDoubleRate() {
         return doubleRate;
     }
 
-    public void setDoubleRate(Integer doubleRate) {
+    public void setDoubleRate(Double doubleRate) {
         this.doubleRate = doubleRate;
     }
 
-    public Integer getArbitrateThreshold() {
+    public Double getArbitrateThreshold() {
         return arbitrateThreshold;
     }
 
-    public void setArbitrateThreshold(Integer arbitrateThreshold) {
+    public void setArbitrateThreshold(Double arbitrateThreshold) {
         this.arbitrateThreshold = arbitrateThreshold;
     }
 
@@ -62,14 +60,6 @@ public class GroupDetailDTO {
         this.scorePolicy = scorePolicy;
     }
 
-    public Integer getTrialCount() {
-        return trialCount;
-    }
-
-    public void setTrialCount(Integer trialCount) {
-        this.trialCount = trialCount;
-    }
-
     public Boolean getEnableAllZero() {
         return enableAllZero;
     }

+ 54 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/stmms/PicConfig.java

@@ -0,0 +1,54 @@
+package com.qmth.teachcloud.common.bean.dto.stmms;
+
+public class PicConfig {
+    //i图片序号
+    private Integer i;
+    //x左上角X坐标
+    private Integer x;
+    //x左上角y坐标
+    private Integer y;
+    //w裁切区宽度
+    private Integer w;
+    //h裁切区高度
+    private Integer h;
+
+    public Integer getI() {
+        return i;
+    }
+
+    public void setI(Integer i) {
+        this.i = i;
+    }
+
+    public Integer getX() {
+        return x;
+    }
+
+    public void setX(Integer x) {
+        this.x = x;
+    }
+
+    public Integer getY() {
+        return y;
+    }
+
+    public void setY(Integer y) {
+        this.y = y;
+    }
+
+    public Integer getW() {
+        return w;
+    }
+
+    public void setW(Integer w) {
+        this.w = w;
+    }
+
+    public Integer getH() {
+        return h;
+    }
+
+    public void setH(Integer h) {
+        this.h = h;
+    }
+}

+ 0 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/AttachmentCommonServiceImpl.java

@@ -259,8 +259,6 @@ public class AttachmentCommonServiceImpl implements AttachmentCommonService {
 
             br.close();
             outStream.close();
-        } catch (FileNotFoundException e) {
-            log.error(SystemConstant.LOG_ERROR, e);
         } catch (IOException e) {
             log.error(SystemConstant.LOG_ERROR, e);
         }

+ 5 - 4
teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/StmmsUtils.java

@@ -23,6 +23,7 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileInputStream;
+import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -304,7 +305,7 @@ public class StmmsUtils {
      * @param subjectCode 科目代码
      * @param groups      试卷结构JSON
      */
-    public boolean saveGroup(Long schoolId, String examId, String subjectCode, List<GroupDetailDTO> groups) {
+    public boolean saveMarkerGroup(Long schoolId, String examId, String subjectCode, Integer trialCount, List<GroupDetailDTO> groups) {
         String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
         String groupSaveUrl = dictionaryConfig.syncDataDomain().getGroupSaveUrl();
         validUrl(hostUrl, groupSaveUrl);
@@ -314,6 +315,7 @@ public class StmmsUtils {
             GroupDTO groupDTO = new GroupDTO();
             groupDTO.setExamId(Integer.valueOf(validParam(examId, null, true, "考试ID")));
             groupDTO.setSubjectCode(validParam(subjectCode, null, true, "科目代码"));
+            groupDTO.setTrialCount(Integer.valueOf(validParam(String.valueOf(trialCount), "0", true, "试评数量")));
             groupDTO.setGroups(validGroupParam(groups));
 
             String jsonData = JSONObject.toJSONString(groupDTO);
@@ -552,13 +554,12 @@ public class StmmsUtils {
     private List<GroupDetailDTO> validGroupParam(List<GroupDetailDTO> groups) {
         for (GroupDetailDTO group : groups) {
             validParam(String.valueOf(group.getNumber()), null, true, "分组序号");
-            validParam(group.getPicList(), null, true, "小题号");
+//            validParam(group.getPicList(), null, true, "小题号");
             validParam(String.valueOf(group.getDoubleRate()), "0", true, "双评比例");
-            if ("1".equals(String.valueOf(group.getDoubleRate()))) {
+            if (new BigDecimal(1).compareTo(BigDecimal.valueOf(group.getDoubleRate())) == 0) {
                 validParam(String.valueOf(group.getArbitrateThreshold()), "0", true, "仲裁阈值");
                 validParam(String.valueOf(group.getScorePolicy()), "AVG", true, "合分策略");
             }
-            validParam(String.valueOf(group.getTrialCount()), "0", true, "试评数量");
             // 允许全零分、评卷模式非必填
             /*validParam(group.getEnableAllZero(), false, false, "允许全零分");
             validParam(group.getMarkMode(), "", false, "评卷模式");*/