浏览代码

加入批次和批次科目更新

wangliang 3 年之前
父节点
当前提交
2f05963f42

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/GradeBatch.java

@@ -56,6 +56,17 @@ public class GradeBatch extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "报告路径")
     private String reportFilePath;
 
+    @ApiModelProperty(value = "回调时间")
+    private Long notifyTime;
+
+    public Long getNotifyTime() {
+        return notifyTime;
+    }
+
+    public void setNotifyTime(Long notifyTime) {
+        this.notifyTime = notifyTime;
+    }
+
     public BigDecimal getProgress() {
         return progress;
     }

+ 48 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/NotifyApiController.java

@@ -1,18 +1,25 @@
 package com.qmth.distributed.print.api;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.bean.result.CalculateNotifyResult;
+import com.qmth.distributed.print.business.entity.GradeBatch;
+import com.qmth.distributed.print.business.entity.GradeBatchPaper;
+import com.qmth.distributed.print.business.service.GradeBatchPaperService;
+import com.qmth.distributed.print.business.service.GradeBatchService;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.enums.GradeAnalyzePaperStatusEnum;
 import com.qmth.teachcloud.common.util.*;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -43,10 +50,17 @@ public class NotifyApiController {
     @Resource
     DictionaryConfig dictionaryConfig;
 
+    @Resource
+    GradeBatchService gradeBatchService;
+
+    @Resource
+    GradeBatchPaperService gradeBatchPaperService;
+
     @ApiOperation(value = "教研分析进度回调")
     @ApiResponses({@ApiResponse(code = 200, message = "教研分析进度回调", response = CalculateNotifyResult.class)})
     @RequestMapping(value = "/analysis/progress", method = RequestMethod.POST)
     @Aac(auth = BOOL.FALSE)
+    @Transactional
     public Result analysisProgress(@ApiParam(value = "接收教研分析回调数据", required = true) @RequestBody String result) throws UnsupportedEncodingException {
         try {
             log.info("analysis_progress,result:{}", result);
@@ -66,6 +80,7 @@ public class NotifyApiController {
             if (!Objects.equals(localSign, sign)) {
                 throw ExceptionResultEnum.ERROR.exception("签名不匹配");
             }
+
             CalculateNotifyResult calculateNotifyResult = JSONObject.toJavaObject(JSONObject.parseObject(decodeJson), CalculateNotifyResult.class);
             List<String> courseCodeList = new ArrayList<>();
             courseCodeList.addAll(calculateNotifyResult.getCourseCode().keySet());
@@ -73,7 +88,39 @@ public class NotifyApiController {
 
             String source = Base64Util.encode(ShaUtils.sha1(calculateNotifyResult.getExamId() + courseCodeList.toString()));
             log.info("source:{}", source);
-            //TODO 更新grade_batch(状态和进度)和grade_batch_paper(状态)
+
+            QueryWrapper<GradeBatch> gradeBatchQueryWrapper = new QueryWrapper<>();
+            gradeBatchQueryWrapper.lambda().eq(GradeBatch::getThirdExamId, calculateNotifyResult.getExamId())
+                    .eq(GradeBatch::getSource, source);
+            GradeBatch gradeBatch = gradeBatchService.getOne(gradeBatchQueryWrapper);
+            Optional.ofNullable(gradeBatch).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("批次数据为空"));
+
+            if (Objects.isNull(gradeBatch.getNotifyTime()) ||
+                    (Objects.nonNull(gradeBatch.getNotifyTime())
+                            && gradeBatch.getNotifyTime().longValue() >= calculateNotifyResult.getTime().longValue())) {
+                if (Objects.nonNull(calculateNotifyResult.getStatus())) {
+                    gradeBatch.setStatus(GradeAnalyzePaperStatusEnum.valueOf(calculateNotifyResult.getStatus()));
+                }
+                gradeBatch.setProgress(calculateNotifyResult.getProgress());
+                gradeBatch.setNotifyTime(System.currentTimeMillis());
+                gradeBatchService.updateById(gradeBatch);
+
+                QueryWrapper<GradeBatchPaper> gradeBatchPaperQueryWrapper = new QueryWrapper<>();
+                gradeBatchPaperQueryWrapper.lambda().eq(GradeBatchPaper::getBatchId, gradeBatch.getId());
+
+                List<GradeBatchPaper> gradeBatchPaperList = new ArrayList<>();
+                calculateNotifyResult.getCourseCode().forEach((k, v) -> {
+                    gradeBatchPaperQueryWrapper.lambda().eq(GradeBatchPaper::getPaperNumber, k)
+                            .eq(GradeBatchPaper::getEnable, true);
+                    GradeBatchPaper gradeBatchPaper = gradeBatchPaperService.getOne(gradeBatchPaperQueryWrapper);
+                    Optional.ofNullable(gradeBatchPaper).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("批次科目[" + k + "]数据为空"));
+
+                    gradeBatchPaper.setStatus(v);
+                    gradeBatchPaper.setUpdateTime(System.currentTimeMillis());
+                    gradeBatchPaperList.add(gradeBatchPaper);
+                });
+                gradeBatchPaperService.updateBatchById(gradeBatchPaperList);
+            }
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             if (e instanceof ApiException) {

+ 0 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/TSAuthController.java

@@ -166,7 +166,6 @@ public class TSAuthController {
                     2022052700001L + "G"));//试卷编号+卷型
             String source = Base64Util.encode(ShaUtils.sha1(map.get("examId") + map.get("courseCode").toString()));
             log.info("source:{}", source);
-            //TODO 更新grade_batch source
             String accessToken = SignatureEntity.build(SignatureType.SECRET, SystemConstant.METHOD, dictionaryConfig.reportOpenDomain().getCalculateApi(), timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
             String result = HttpUtil.postJson(dictionaryConfig.reportOpenDomain().getHostUrl() + dictionaryConfig.reportOpenDomain().getCalculateApi(), JacksonUtil.parseJson(map), accessToken, timestamp);
             if (Objects.nonNull(result)) {

+ 0 - 2
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/templete/strategy/CourseCodeSyncTaskService.java

@@ -44,7 +44,6 @@ public class CourseCodeSyncTaskService extends CalculateTaskTemplate {
         tbSyncTask.setStatus(TaskStatusEnum.DATA_VALID);
         updateProgress(calculateParams);
 
-        //TODO 此处加校验数据具体逻辑方法,推荐service方法然后加@Transactional注解
         analyzeDataCheckService.analyzeDataCheck(calculateParams);
     }
 
@@ -67,7 +66,6 @@ public class CourseCodeSyncTaskService extends CalculateTaskTemplate {
 //        tbSyncTask.setObj(jsonObject.toJSONString());
 //        updateProgress(calculateParams);
 
-        //TODO 此处加计算数据具体逻辑方法,推荐service方法然后加@Transactional注解
         analyzeDataCalculateService.dataCalculateStart(calculateParams);
     }
 }