Browse Source

3.1.0-开始计算接口调用

xiaof 3 years ago
parent
commit
d2310455d2

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

@@ -9,4 +9,6 @@ import com.qmth.distributed.print.business.entity.TBSyncTask;
 public interface DataSyncReportService {
 public interface DataSyncReportService {
 
 
     void syncGradeBatch(GradeBatch gradeBatch, TBSyncTask tbSyncTask);
     void syncGradeBatch(GradeBatch gradeBatch, TBSyncTask tbSyncTask);
+
+    void startCalc(GradeBatch gradeBatch, TBSyncTask tbSyncTask);
 }
 }

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

@@ -57,8 +57,8 @@ public interface GradeBatchService extends IService<GradeBatch> {
     /**
     /**
      * 创建Txt文件
      * 创建Txt文件
      *
      *
-     * @param batchId   批次id
+     * @param gradeBatch   批次id
      * @param exception 异常
      * @param exception 异常
      */
      */
-    void createTxt(Long batchId, String exception);
+    void createTxt(GradeBatch gradeBatch, String exception);
 }
 }

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

@@ -23,6 +23,7 @@ import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * 同步服务类
  * 同步服务类
@@ -116,4 +117,41 @@ public class DataSyncReportServiceImpl implements DataSyncReportService {
             tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), null, status, result, errorMessage);
             tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), null, status, result, errorMessage);
         }
         }
     }
     }
+
+    @Async
+    @Override
+    public void startCalc(GradeBatch gradeBatch, TBSyncTask tbSyncTask) {
+        // 同步初始参数
+        TaskResultEnum result = null;
+        TaskStatusEnum status;
+        String errorMessage = null;
+        Long schoolId = tbSyncTask.getSchoolId();
+        try {
+            // 同步中
+            status = TaskStatusEnum.RUNNING;
+            tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), null, status, null, null);
+
+            QueryWrapper<GradeBatchPaper> queryWrapper = new QueryWrapper<>();
+            queryWrapper.lambda().eq(GradeBatchPaper::getBatchId, gradeBatch.getId());
+            List<GradeBatchPaper> gradeBatchPaperList = gradeBatchPaperService.list(queryWrapper);
+            if (gradeBatchPaperList.isEmpty()) {
+                throw ExceptionResultEnum.ERROR.exception("没有可分析的课程");
+            }
+
+            List<String> courseCodes = gradeBatchPaperList.stream().map(m -> m.getPaperNumber() + m.getPaperType()).collect(Collectors.toList());
+            teachCloudReportTaskUtils.startCalc(schoolId, gradeBatch.getThirdExamId(), courseCodes);
+            // 任务结果
+            result = TaskResultEnum.SUCCESS;
+        } catch (Exception e) {
+            result = TaskResultEnum.ERROR;
+            errorMessage = e.getMessage();
+
+            // 生成txt
+            gradeBatchService.createTxt(gradeBatch, errorMessage);
+        } finally {
+            // 同步结束
+            status = TaskStatusEnum.FINISH;
+            tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), null, status, result, errorMessage);
+        }
+    }
 }
 }

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

@@ -279,9 +279,8 @@ public class GradeBatchServiceImpl extends ServiceImpl<GradeBatchMapper, GradeBa
     }
     }
 
 
     @Override
     @Override
-    public void createTxt(Long batchId,String exception) {
+    public void createTxt(GradeBatch gradeBatch,String exception) {
         final String TXT_PREFIX = ".txt";
         final String TXT_PREFIX = ".txt";
-        GradeBatch gradeBatch = this.getById(batchId);
         if (Objects.isNull(gradeBatch)){
         if (Objects.isNull(gradeBatch)){
             throw ExceptionResultEnum.ERROR.exception("批次不存在");
             throw ExceptionResultEnum.ERROR.exception("批次不存在");
         }
         }

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

@@ -57,7 +57,7 @@ public class GradePaperServiceImpl extends ServiceImpl<GradePaperMapper, GradePa
                 .eq(GradeModuleDefine::getPaperType, paperType));
                 .eq(GradeModuleDefine::getPaperType, paperType));
 
 
         GradePaperDefineResult gradePaperDefineResult = new GradePaperDefineResult();
         GradePaperDefineResult gradePaperDefineResult = new GradePaperDefineResult();
-        if (Objects.isNull(gradePaper) && Objects.isNull(gradeModuleDefineList)){
+        if (Objects.isNull(gradePaper) && gradeModuleDefineList.isEmpty()){
             return null;
             return null;
         }
         }
         if (Objects.nonNull(gradePaper)) {
         if (Objects.nonNull(gradePaper)) {

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

@@ -37,4 +37,12 @@ public class AsyncTeachCloudReportService {
         dataSyncReportService.syncGradeBatch(gradeBatch, tbSyncTask);
         dataSyncReportService.syncGradeBatch(gradeBatch, tbSyncTask);
     }
     }
 
 
+    /**
+     * 开始计算
+     * @param gradeBatch 分析批次对象
+     */
+    public void startCalc(GradeBatch gradeBatch) {
+        TBSyncTask tbSyncTask = tbSyncTaskService.saveTask(gradeBatch.getSchoolId(), gradeBatch.getId(), PushTypeEnum.CALCULATE);
+        dataSyncReportService.startCalc(gradeBatch, tbSyncTask);
+    }
 }
 }

+ 17 - 0
distributed-print/src/main/java/com/qmth/distributed/print/api/GradeBatchController.java

@@ -124,4 +124,21 @@ public class GradeBatchController {
         asyncTeachCloudReportService.syncGradeBatch(gradeBatch);
         asyncTeachCloudReportService.syncGradeBatch(gradeBatch);
         return ResultUtil.success(true);
         return ResultUtil.success(true);
     }
     }
+
+    /**
+     * 导入考务数据-包含任课老师信息
+     *
+     * @param batchId 批次ID
+     */
+    @ApiOperation(value = "成绩分析批次课程-开始计算")
+    @RequestMapping(value = "/start_calc", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "同步成功", response = EditResult.class)})
+    public Result startCalc(@RequestParam Long batchId) {
+        GradeBatch gradeBatch = gradeBatchService.getById(batchId);
+        if(gradeBatch == null){
+            throw ExceptionResultEnum.ERROR.exception("没有批次信息");
+        }
+        asyncTeachCloudReportService.startCalc(gradeBatch);
+        return ResultUtil.success(true);
+    }
 }
 }

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

@@ -1,6 +1,8 @@
 package com.qmth.teachcloud.common.sync;
 package com.qmth.teachcloud.common.sync;
 
 
+import cn.hutool.http.HttpStatus;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.qmth.boot.api.exception.ApiException;
 import com.qmth.boot.tools.signature.SignatureType;
 import com.qmth.boot.tools.signature.SignatureType;
 import com.qmth.teachcloud.common.SignatureEntityTest;
 import com.qmth.teachcloud.common.SignatureEntityTest;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
@@ -9,6 +11,9 @@ import com.qmth.teachcloud.common.entity.BasicSchool;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.service.CommonCacheService;
 import com.qmth.teachcloud.common.util.HttpKit;
 import com.qmth.teachcloud.common.util.HttpKit;
+import com.qmth.teachcloud.common.util.HttpUtil;
+import com.qmth.teachcloud.common.util.JacksonUtil;
+import com.qmth.teachcloud.common.util.ResultUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
@@ -16,6 +21,7 @@ import org.springframework.stereotype.Component;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Objects;
 
 
@@ -140,6 +146,42 @@ public class TeachCloudReportTaskUtils {
         }
         }
     }
     }
 
 
+    /**
+     * @param schoolId    学校ID
+     * @param examId      考试ID
+     * @param courseCodes 分析试卷的唯一标识
+     */
+    public boolean startCalc(Long schoolId, Long examId, List<String> courseCodes) {
+        String hostUrl = dictionaryConfig.reportOpenDomain().getHostUrl();
+        String saveUrl = dictionaryConfig.reportOpenDomain().getCalculateApi();
+        validUrl(hostUrl, saveUrl);
+        String postUrl = hostUrl.concat(saveUrl);
+        long timestamp = System.currentTimeMillis();
+        try {
+            Map<String, Object> map = new HashMap<>();
+            map.computeIfAbsent("examId", v -> examId);
+            map.computeIfAbsent("courseCode", v -> courseCodes);//试卷编号+卷型
+            String accessToken = createSign(schoolId, timestamp, saveUrl);
+            String result = HttpUtil.postJson(postUrl, JacksonUtil.parseJson(map), accessToken, timestamp);
+            if (Objects.nonNull(result)) {
+                JSONObject jsonObject = JSONObject.parseObject(result);
+                if (Objects.nonNull(jsonObject.get("code")) && jsonObject.getIntValue("code") != HttpStatus.HTTP_OK) {
+                    throw ExceptionResultEnum.ERROR.exception(jsonObject.getString("error"));
+                }
+                return true;
+            }
+            return false;
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return false;
+    }
+
 
 
     /**
     /**
      * http请求头
      * http请求头