Pārlūkot izejas kodu

3.1.0-同步教研分析

xiaof 3 gadi atpakaļ
vecāks
revīzija
91d2367eda
15 mainītis faili ar 450 papildinājumiem un 18 dzēšanām
  1. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/GradePaperDimensionMapper.java
  2. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/GradePaperStructMapper.java
  3. 12 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/DataSyncReportService.java
  4. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/GradePaperDimensionService.java
  5. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/GradePaperStructService.java
  6. 2 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/OpenApiService.java
  7. 106 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncReportServiceImpl.java
  8. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradePaperDimensionServiceImpl.java
  9. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradePaperStructServiceImpl.java
  10. 15 9
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/OpenApiServiceImpl.java
  11. 11 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TBSyncTaskServiceImpl.java
  12. 40 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncTeachCloudReportService.java
  13. 22 1
      distributed-print/src/main/java/com/qmth/distributed/print/api/GradeBatchController.java
  14. 2 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/enums/PushTypeEnum.java
  15. 234 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/TeachCloudReportTaskUtils.java

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/GradePaperDimensionMapper.java

@@ -27,7 +27,7 @@ public interface GradePaperDimensionMapper extends BaseMapper<GradePaperDimensio
      */
     List<GradePaperDimensionResult> findGradePaperDimensionList(@Param("paperNumber") String paperNumber,@Param("paperType") String paperType,@Param("schoolId") Long schoolId);
 
-    PaperDimension findBySchoolIdAndPaperNumberAndPaperType(@Param("schoolId") Long schoolId, @Param("paperNumber") String paperNumber, @Param("paperType") String paperType);
+    List<PaperDimension> findBySchoolIdAndPaperNumberAndPaperType(@Param("schoolId") Long schoolId, @Param("paperNumber") String paperNumber, @Param("paperType") String paperType);
 
 
 }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/GradePaperStructMapper.java

@@ -27,5 +27,5 @@ public interface GradePaperStructMapper extends BaseMapper<GradePaperStruct> {
      */
     List<GradePaperStructResult> findStructByGradePaper(@Param("schoolId") Long schoolId, @Param("paperNumber") String paperNumber, @Param("paperType") String paperType);
 
-    PaperStructure findBySchoolIdAndPaperNumberAndPaperType(@Param("schoolId") Long schoolId, @Param("paperNumber") String paperNumber, @Param("paperType") String paperType);
+    List<PaperStructure> findBySchoolIdAndPaperNumberAndPaperType(@Param("schoolId") Long schoolId, @Param("paperNumber") String paperNumber, @Param("paperType") String paperType);
 }

+ 12 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/DataSyncReportService.java

@@ -0,0 +1,12 @@
+package com.qmth.distributed.print.business.service;
+
+import com.qmth.distributed.print.business.entity.GradeBatch;
+import com.qmth.distributed.print.business.entity.TBSyncTask;
+
+/**
+ * 同步数据到云阅卷 服务类
+ */
+public interface DataSyncReportService {
+
+    void syncGradeBatch(GradeBatch gradeBatch, TBSyncTask tbSyncTask);
+}

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/GradePaperDimensionService.java

@@ -83,5 +83,5 @@ public interface GradePaperDimensionService extends IService<GradePaperDimension
      */
     List<SecondDimensionResult> findSecondDimensionList(String paperNumber, String paperType, DimensionEnum dimensionType, SysUser requestUser);
 
-    PaperDimension findBySchoolIdAndPaperNumberAndPaperType(Long schoolId, String paperNumber, String paperType);
+    List<PaperDimension> findBySchoolIdAndPaperNumberAndPaperType(Long schoolId, String paperNumber, String paperType);
 }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/GradePaperStructService.java

@@ -60,5 +60,5 @@ public interface GradePaperStructService extends IService<GradePaperStruct> {
      */
     void exportGradePaperStructTemplate(String paperNumber, String paperType, SysUser requestUser) throws Exception;
 
-    PaperStructure findBySchoolIdAndPaperNumberAndPaperType(Long schoolId, String paperNumber, String paperType);
+    List<PaperStructure> findBySchoolIdAndPaperNumberAndPaperType(Long schoolId, String paperNumber, String paperType);
 }

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

@@ -9,9 +9,9 @@ public interface OpenApiService {
 
     PaperConfig getPaperConfig(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode);
 
-    PaperDimension getPaperDimension(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode);
+    List<PaperDimension> getPaperDimension(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode);
 
-    PaperStructure getPaperStructure(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode);
+    List<PaperStructure> getPaperStructure(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode);
 
     List<PaperEvaluation> getPaperEvaluation(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode);
 

+ 106 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncReportServiceImpl.java

@@ -0,0 +1,106 @@
+package com.qmth.distributed.print.business.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.qmth.distributed.print.business.entity.GradeBatch;
+import com.qmth.distributed.print.business.entity.GradeBatchPaper;
+import com.qmth.distributed.print.business.entity.TBSyncTask;
+import com.qmth.distributed.print.business.enums.GradeAnalyzePaperStatusEnum;
+import com.qmth.distributed.print.business.service.DataSyncReportService;
+import com.qmth.distributed.print.business.service.GradeBatchPaperService;
+import com.qmth.distributed.print.business.service.GradeBatchService;
+import com.qmth.distributed.print.business.service.TBSyncTaskService;
+import com.qmth.teachcloud.common.entity.BasicSemester;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.enums.TaskResultEnum;
+import com.qmth.teachcloud.common.enums.TaskStatusEnum;
+import com.qmth.teachcloud.common.service.BasicSemesterService;
+import com.qmth.teachcloud.common.sync.TeachCloudReportTaskUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 同步服务类
+ */
+@Service
+public class DataSyncReportServiceImpl implements DataSyncReportService {
+
+    private static final Logger log = LoggerFactory.getLogger(DataSyncReportServiceImpl.class);
+
+    @Resource
+    private BasicSemesterService basicSemesterService;
+
+    @Resource
+    private TBSyncTaskService tbSyncTaskService;
+
+    @Resource
+    private GradeBatchService gradeBatchService;
+
+    @Resource
+    private GradeBatchPaperService gradeBatchPaperService;
+
+    @Resource
+    private TeachCloudReportTaskUtils teachCloudReportTaskUtils;
+
+    @Async
+    @Override
+    public void syncGradeBatch(GradeBatch gradeBatch, TBSyncTask tbSyncTask) {
+        // 同步初始参数
+        TaskResultEnum result = null;
+        TaskStatusEnum status;
+        String errorMessage = null;
+        Long schoolId = tbSyncTask.getSchoolId();
+        Long semesterId = gradeBatch.getSemesterId();
+        try {
+            // 同步中
+            status = TaskStatusEnum.RUNNING;
+            tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), null, status, null, null);
+
+            // 同步学期
+            BasicSemester basicSemester = basicSemesterService.getById(semesterId);
+            if (basicSemester == null) {
+                throw ExceptionResultEnum.ERROR.exception("学期不存在");
+            }
+            Long syncSemesterId = teachCloudReportTaskUtils.syncSemester(schoolId, basicSemester.getName(), basicSemester.getStartTime(), basicSemester.getEndTime(), true);
+            if (syncSemesterId <= 0L) {
+                throw ExceptionResultEnum.ERROR.exception("学期同步失败");
+            }
+
+            // 同步考试(分析批次)
+            Long examId = teachCloudReportTaskUtils.syncExam(schoolId, gradeBatch.getThirdExamId(), gradeBatch.getBatchName(), gradeBatch.getBatchTime(), String.valueOf(syncSemesterId), true);
+            if (examId <= 0L) {
+                throw ExceptionResultEnum.ERROR.exception("考试同步失败");
+            }
+
+            // 同步分析课程
+            QueryWrapper<GradeBatchPaper> queryWrapper = new QueryWrapper<>();
+            queryWrapper.lambda().eq(GradeBatchPaper::getBatchId, gradeBatch.getId());
+            List<GradeBatchPaper> gradeBatchPaperList = gradeBatchPaperService.list(queryWrapper);
+            for (GradeBatchPaper gradeBatchPaper : gradeBatchPaperList) {
+                String courseCode = gradeBatchPaper.getPaperNumber() + gradeBatchPaper.getPaperType();
+                teachCloudReportTaskUtils.syncCourse(schoolId, String.valueOf(examId), courseCode, gradeBatchPaper.getPaperName(), gradeBatchPaper.getPaperType(), gradeBatchPaper.getTeachCollegeName(), true);
+            }
+
+            // 更新批次表考试ID、状态
+            UpdateWrapper<GradeBatch> updateWrapper = new UpdateWrapper<>();
+            updateWrapper.lambda().set(GradeBatch::getThirdExamId, examId)
+                    .set(GradeBatch::getStatus, GradeAnalyzePaperStatusEnum.SETTING_GRADE_PAPER_PARAM)
+                    .eq(GradeBatch::getId, gradeBatch.getId());
+            gradeBatchService.update(updateWrapper);
+            // 任务结果
+            result = TaskResultEnum.SUCCESS;
+        } catch (Exception e) {
+            result = TaskResultEnum.ERROR;
+            errorMessage = e.getMessage();
+        } finally {
+            // 同步结束
+            status = TaskStatusEnum.FINISH;
+            tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), null, status, result, errorMessage);
+        }
+    }
+}

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradePaperDimensionServiceImpl.java

@@ -196,7 +196,7 @@ public class GradePaperDimensionServiceImpl extends ServiceImpl<GradePaperDimens
     }
 
     @Override
-    public PaperDimension findBySchoolIdAndPaperNumberAndPaperType(Long schoolId, String paperNumber, String paperType) {
+    public List<PaperDimension> findBySchoolIdAndPaperNumberAndPaperType(Long schoolId, String paperNumber, String paperType) {
         return this.baseMapper.findBySchoolIdAndPaperNumberAndPaperType(schoolId, paperNumber, paperType);
     }
 

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/GradePaperStructServiceImpl.java

@@ -227,7 +227,7 @@ public class GradePaperStructServiceImpl extends ServiceImpl<GradePaperStructMap
     }
 
     @Override
-    public PaperStructure findBySchoolIdAndPaperNumberAndPaperType(Long schoolId, String paperNumber, String paperType) {
+    public List<PaperStructure> findBySchoolIdAndPaperNumberAndPaperType(Long schoolId, String paperNumber, String paperType) {
         return this.baseMapper.findBySchoolIdAndPaperNumberAndPaperType(schoolId, paperNumber, paperType);
     }
 

+ 15 - 9
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/OpenApiServiceImpl.java

@@ -49,6 +49,9 @@ public class OpenApiServiceImpl implements OpenApiService {
     @Resource
     private TSyncExamStudentScoreService tSyncExamStudentScoreService;
 
+    @Resource
+    private GradeBatchStudentService gradeBatchStudentService;
+
     @Override
     public PaperConfig getPaperConfig(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode) {
         GradeBatchPaper gradeBatchPaper = gradeBatchPaperService.findByThirdExamIdAndGradeCourseCode(basicSchool.getId(), thirdExamId, gradeCourseCode);
@@ -59,21 +62,20 @@ public class OpenApiServiceImpl implements OpenApiService {
     }
 
     @Override
-    public PaperDimension getPaperDimension(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode) {
+    public List<PaperDimension> getPaperDimension(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode) {
         GradeBatchPaper gradeBatchPaper = gradeBatchPaperService.findByThirdExamIdAndGradeCourseCode(basicSchool.getId(), thirdExamId, gradeCourseCode);
         if (gradeBatchPaper == null) {
-            return null;
+            return new ArrayList<>();
         }
         return gradePaperDimensionService.findBySchoolIdAndPaperNumberAndPaperType(gradeBatchPaper.getSchoolId(), gradeBatchPaper.getPaperNumber(), gradeBatchPaper.getPaperType());
     }
 
     @Override
-    public PaperStructure getPaperStructure(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode) {
+    public List<PaperStructure> getPaperStructure(BasicSchool basicSchool, String thirdExamId, String gradeCourseCode) {
         GradeBatchPaper gradeBatchPaper = gradeBatchPaperService.findByThirdExamIdAndGradeCourseCode(basicSchool.getId(), thirdExamId, gradeCourseCode);
         if (gradeBatchPaper == null) {
-            return null;
+            return new ArrayList<>();
         }
-
         return gradePaperStructService.findBySchoolIdAndPaperNumberAndPaperType(gradeBatchPaper.getSchoolId(), gradeBatchPaper.getPaperNumber(), gradeBatchPaper.getPaperType());
     }
 
@@ -145,10 +147,14 @@ public class OpenApiServiceImpl implements OpenApiService {
         examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, gradeBatchPaper.getSchoolId())
                 .eq(ExamTask::getPaperNumber, gradeBatchPaper.getPaperNumber());
         ExamTask examTask = examTaskService.getOne(examTaskQueryWrapper);
-        if(examTask == null){
+        if (examTask == null) {
             return examStudentScoreList;
         }
 
+        QueryWrapper<GradeBatchStudent> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(GradeBatchStudent::getBatchId, gradeBatchPaper.getBatchId());
+        List<GradeBatchStudent> gradeBatchStudentList = gradeBatchStudentService.list(queryWrapper);
+
         QueryWrapper<TSyncExamStudentScore> examStudentScoreQueryWrapper = new QueryWrapper<>();
         String subjectCode = examTask.getCourseCode() + gradeBatchPaper.getPaperType() + examTask.getSequence();
         examStudentScoreQueryWrapper.lambda().eq(TSyncExamStudentScore::getSchoolId, gradeBatchPaper.getSchoolId())
@@ -167,9 +173,9 @@ public class OpenApiServiceImpl implements OpenApiService {
             BasicMajor basicMajor = basicMajorService.getById(m.getMajorId());
             examStudentScore.setMajor(basicMajor == null ? null : basicMajor.getName());
             examStudentScore.setClassName(m.getClazzName());
-            examStudentScore.setTeacherName(m.getTeacher());
-            // todo 任课老师code 20220530
-//            examStudentScore.setTeacherCode(m.g);
+            GradeBatchStudent gradeBatchStudent = gradeBatchStudentList.stream().filter(s -> s.getStudentCode().equals(examStudentScore.getStudentCode()) && s.getPaperNumber().equals(examStudentScore.getPaperNumber()) && s.getPaperType().equals(examStudentScore.getPaperType())).findFirst().orElseGet(null);
+            examStudentScore.setTeacherName(gradeBatchStudent != null ? gradeBatchStudent.getTeacherName() : null);
+            examStudentScore.setTeacherCode(gradeBatchStudent != null ? gradeBatchStudent.getTeacherNumber() : null);
             examStudentScore.setStatus(m.getStatus());
             examStudentScore.setTotalScore(m.getTotalScore());
             examStudentScore.setObjectiveScore(m.getObjectiveScore());

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TBSyncTaskServiceImpl.java

@@ -9,8 +9,10 @@ import com.qmth.distributed.print.business.entity.TBSyncTask;
 import com.qmth.distributed.print.business.mapper.TBSyncTaskMapper;
 import com.qmth.distributed.print.business.service.ExamPaperStructureService;
 import com.qmth.distributed.print.business.service.ExamPrintPlanService;
+import com.qmth.distributed.print.business.service.GradeBatchService;
 import com.qmth.distributed.print.business.service.TBSyncTaskService;
 import com.qmth.distributed.print.business.templete.execute.AsyncCloudMarkingTaskService;
+import com.qmth.distributed.print.business.templete.execute.AsyncTeachCloudReportService;
 import com.qmth.teachcloud.common.bean.result.SyncListResult;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.SysUser;
@@ -47,6 +49,12 @@ public class TBSyncTaskServiceImpl extends ServiceImpl<TBSyncTaskMapper, TBSyncT
     @Resource
     TeachcloudCommonService teachcloudCommonService;
 
+    @Resource
+    AsyncTeachCloudReportService asyncTeachCloudReportService;
+
+    @Resource
+    GradeBatchService gradeBatchService;
+
     @Transactional
     @Override
     public TBSyncTask saveTask(Long schoolId, Long objectId, PushTypeEnum type) {
@@ -140,6 +148,9 @@ public class TBSyncTaskServiceImpl extends ServiceImpl<TBSyncTaskMapper, TBSyncT
             case OBJECTIVE_ANSWER_PUSH:
                 asyncCloudMarkingTaskService.syncObjectiveStructure(examPaperStructureService.getById(tbSyncTask.getObjectId()));
                 break;
+            case GRADE_BATCH_PUSH:
+                asyncTeachCloudReportService.syncGradeBatch(gradeBatchService.getById(tbSyncTask.getObjectId()));
+                break;
         }
 
 

+ 40 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncTeachCloudReportService.java

@@ -0,0 +1,40 @@
+package com.qmth.distributed.print.business.templete.execute;
+
+import com.qmth.distributed.print.business.entity.GradeBatch;
+import com.qmth.distributed.print.business.entity.TBSyncTask;
+import com.qmth.distributed.print.business.service.DataSyncReportService;
+import com.qmth.distributed.print.business.service.TBSyncTaskService;
+import com.qmth.teachcloud.common.enums.PushTypeEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * 异步同步教研分析
+ */
+@Service
+public class AsyncTeachCloudReportService {
+
+    private static final Logger log = LoggerFactory.getLogger(AsyncTeachCloudReportService.class);
+
+    @Lazy
+    @Resource
+    private DataSyncReportService dataSyncReportService;
+
+    @Resource
+    private TBSyncTaskService tbSyncTaskService;
+
+    /**
+     * 同步分析批次
+     *
+     * @param gradeBatch 分析批次对象
+     */
+    public void syncGradeBatch(GradeBatch gradeBatch) {
+        TBSyncTask tbSyncTask = tbSyncTaskService.saveTask(gradeBatch.getSchoolId(), gradeBatch.getId(), PushTypeEnum.GRADE_BATCH_PUSH);
+        dataSyncReportService.syncGradeBatch(gradeBatch, tbSyncTask);
+    }
+
+}

+ 22 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/GradeBatchController.java

@@ -5,9 +5,12 @@ import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.distributed.print.business.bean.params.analyze.GradeBatchParam;
 import com.qmth.distributed.print.business.bean.result.EditResult;
+import com.qmth.distributed.print.business.entity.GradeBatch;
 import com.qmth.distributed.print.business.service.GradeBatchService;
+import com.qmth.distributed.print.business.templete.execute.AsyncTeachCloudReportService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.SysUser;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
@@ -42,6 +45,9 @@ public class GradeBatchController {
     @Resource
     private GradeBatchService gradeBatchService;
 
+    @Resource
+    private AsyncTeachCloudReportService asyncTeachCloudReportService;
+
     @ApiOperation(value = "成绩分析批次-查询")
     @RequestMapping(value = "/page", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = Result.class)})
@@ -101,5 +107,20 @@ public class GradeBatchController {
         return ResultUtil.success(true);
     }
 
-    // TODO: 2022/6/2 成绩分析批次推送 
+    /**
+     * 导入考务数据-包含任课老师信息
+     *
+     * @param batchId 批次ID
+     */
+    @ApiOperation(value = "成绩分析批次课程-批次同步")
+    @RequestMapping(value = "/batch_sync", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "同步成功", response = EditResult.class)})
+    public Result batchSync(@RequestParam Long batchId) {
+        GradeBatch gradeBatch = gradeBatchService.getById(batchId);
+        if(gradeBatch == null){
+            throw ExceptionResultEnum.ERROR.exception("没有批次信息");
+        }
+        asyncTeachCloudReportService.syncGradeBatch(gradeBatch);
+        return ResultUtil.success(true);
+    }
 }

+ 2 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/enums/PushTypeEnum.java

@@ -22,6 +22,8 @@ public enum PushTypeEnum {
 
     SCORE_PUSH("成绩推送"),
 
+    GRADE_BATCH_PUSH("分析批次推送"),
+
     CALCULATE("分析计算");
 
     PushTypeEnum(String title) {

+ 234 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/TeachCloudReportTaskUtils.java

@@ -0,0 +1,234 @@
+package com.qmth.teachcloud.common.sync;
+
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.boot.tools.signature.SignatureType;
+import com.qmth.teachcloud.common.SignatureEntityTest;
+import com.qmth.teachcloud.common.config.DictionaryConfig;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.entity.BasicSchool;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.service.CommonCacheService;
+import com.qmth.teachcloud.common.util.HttpKit;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * 同步教研分析接口工具类
+ * <p>
+ * Date: 2021/10/29.
+ */
+@Component
+public class TeachCloudReportTaskUtils {
+    private static final Logger log = LoggerFactory.getLogger(TeachCloudReportTaskUtils.class);
+
+    // 所有请求方法默认为"POST"
+    private static final String POST_METHOD = "POST";
+
+    @Resource
+    private CommonCacheService commonCacheService;
+
+    @Resource
+    private DictionaryConfig dictionaryConfig;
+
+    /**
+     * 学期创建/更新接口
+     *
+     * @param id           学期id
+     * @param semesterName 学期名称
+     * @param startTime    学期开始时间
+     * @param endTime      学期结束时间
+     * @param enable       启用/禁用,ture:启用,false:禁用,默认启用
+     */
+    public Long syncSemester(Long schoolId, String semesterName, Long startTime, Long endTime, Boolean enable) {
+        String hostUrl = dictionaryConfig.reportOpenDomain().getHostUrl();
+        String saveUrl = dictionaryConfig.reportOpenDomain().getSemesterApi();
+        validUrl(hostUrl, saveUrl);
+        String postUrl = hostUrl.concat(saveUrl);
+        //参数
+        Map<String, Object> map = new HashMap<>();
+        map.put("semesterName", validParam(semesterName, null, true, "学期名称"));
+        map.put("startTime", validParam(startTime, null, true, "学期开始时间"));
+        map.put("endTime", validParam(endTime, null, true, "学期结束时间"));
+        map.put("enable", validParam(enable, true, true, "是否启用标记"));
+
+        String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, saveUrl), map, null, null, null);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        if (jsonObject.containsKey("id")) {
+            return Long.valueOf(jsonObject.get("id").toString());
+        } else {
+            throw ExceptionResultEnum.ERROR.exception("学期同步失败");
+        }
+    }
+
+    /**
+     * 考试创建/更新接口
+     *
+     * @param schoolId   学校ID
+     * @param id         考试id
+     * @param examName   考试名称
+     * @param examTime   考试时间
+     * @param semesterId 学期id
+     * @param enable     启用/禁用,ture:启用,false:禁用,默认启用
+     */
+    public Long syncExam(Long schoolId, Long id, String examName, Long examTime, String semesterId, Boolean enable) {
+        String hostUrl = dictionaryConfig.reportOpenDomain().getHostUrl();
+        String saveUrl = dictionaryConfig.reportOpenDomain().getExamApi();
+        validUrl(hostUrl, saveUrl);
+        String postUrl = hostUrl.concat(saveUrl);
+        try {
+            //参数
+            Map<String, Object> map = new HashMap<>();
+            map.put("id", validParam(id, null, true, "考试ID"));
+            map.put("examName", validParam(examName, null, true, "考试名称"));
+            map.put("examTime", validParam(examTime, null, true, "考试时间"));
+            map.put("semesterId", validParam(semesterId, null, true, "学期ID"));
+            map.put("enable", validParam(enable, null, true, "是否启用标记"));
+
+            String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, saveUrl), map, null, null, null);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            if (jsonObject.containsKey("id")) {
+                return Long.valueOf(jsonObject.get("id").toString());
+            } else {
+                throw ExceptionResultEnum.ERROR.exception("考试同步失败");
+            }
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+        }
+    }
+
+    /**
+     * @param schoolId         学校ID
+     * @param examId           考试ID
+     * @param courseCode       分析试卷的唯一标识
+     * @param courseName       分析试卷名称
+     * @param paperType        试卷类型
+     * @param teachCollegeName 开课机构名称
+     * @param enable           是否启用标记
+     */
+    public boolean syncCourse(Long schoolId, String examId, String courseCode, String courseName,
+                              String paperType, String teachCollegeName, Boolean enable) {
+        String hostUrl = dictionaryConfig.reportOpenDomain().getHostUrl();
+        String saveUrl = dictionaryConfig.reportOpenDomain().getCourseEditApi();
+        validUrl(hostUrl, saveUrl);
+        String postUrl = hostUrl.concat(saveUrl);
+        try {
+            //参数
+            Map<String, Object> map = new HashMap<>();
+            map.put("examId", validParam(examId, null, true, "考试ID"));
+            map.put("courseCode", validParam(courseCode, null, true, "分析试卷的唯一标识"));
+            map.put("courseName", validParam(courseName, null, true, "分析试卷名称"));
+            map.put("paperType", validParam(paperType, "#", true, "试卷类型"));
+            map.put("teachCollegeName", validParam(teachCollegeName, null, true, "开课机构名称"));
+            map.put("enable", validParam(enable, null, true, "是否启用标记"));
+
+            String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, saveUrl), map, null, null, null);
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            if (jsonObject.containsKey("success")) {
+                return Boolean.valueOf(jsonObject.get("success").toString());
+            } else {
+                throw ExceptionResultEnum.ERROR.exception("分析课程同步失败");
+            }
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+        }
+    }
+
+
+    /**
+     * http请求头
+     *
+     * @param url 请求URL
+     */
+    private Map<String, String> getHeaders(Long schoolId, String url) {
+        long time = System.currentTimeMillis();
+        Map<String, String> header = new HashMap<>();
+        header.put(SystemConstant.HEADER_AUTHORIZATION, createSign(schoolId, time, url));
+        header.put(SystemConstant.HEADER_TIME, String.valueOf(time));
+        return header;
+    }
+
+    /**
+     * 签名
+     *
+     * @param time 时间戳
+     * @param url  请求URL
+     */
+    private String createSign(Long schoolId, long time, String url) {
+        BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
+        if (basicSchool == null) {
+            throw ExceptionResultEnum.ERROR.exception("学校不存在");
+        }
+        if (!basicSchool.getEnable()) {
+            throw ExceptionResultEnum.ERROR.exception("学校已禁用");
+        }
+
+        return SignatureEntityTest.build(SignatureType.SECRET, POST_METHOD, url, time, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
+    }
+
+    /**
+     * 校验参数值并返回(字符型)
+     *
+     * @param value        参数值
+     * @param defaultValue 默认值
+     * @param require      是否必填(true:是,false:否)
+     * @param name         参数名称
+     */
+    private String validParam(String value, String defaultValue, boolean require, String name) {
+        if (require && StringUtils.isAllBlank(value, defaultValue)) {
+            throw ExceptionResultEnum.ERROR.exception((StringUtils.isBlank(name) ? "" : name) + "值必填");
+        }
+        return StringUtils.isBlank(value) ? defaultValue : value;
+
+    }
+
+    /**
+     * 校验参数值并返回(Long型)
+     *
+     * @param value        参数值
+     * @param defaultValue 默认值
+     * @param require      是否必填(true:是,false:否)
+     * @param name         参数名称
+     */
+    private Long validParam(Long value, Long defaultValue, boolean require, String name) {
+        if (require && Objects.isNull(value) && Objects.isNull(defaultValue)) {
+            throw ExceptionResultEnum.ERROR.exception((StringUtils.isBlank(name) ? "" : name) + "值必填");
+        }
+        return Objects.isNull(value) ? defaultValue : value;
+
+    }
+
+    /**
+     * 校验参数值并返回 (布尔型)
+     *
+     * @param value        参数值
+     * @param defaultValue 默认值
+     * @param require      是否必填
+     * @param name         描述
+     */
+    private Boolean validParam(Boolean value, Boolean defaultValue, Boolean require, String name) {
+        if (require && value == null && defaultValue == null) {
+            throw ExceptionResultEnum.ERROR.exception((StringUtils.isBlank(name) ? "" : name) + "值必填");
+        }
+        return value == null ? defaultValue : value;
+
+    }
+
+    /**
+     * 校验url是否配置
+     *
+     * @param urls URL数组
+     */
+    private void validUrl(String... urls) {
+        if (StringUtils.isAnyBlank(urls)) {
+            throw ExceptionResultEnum.ERROR.exception("云阅卷同步接口未正确配置");
+        }
+    }
+
+}