wangliang 3 жил өмнө
parent
commit
95dd606931

+ 75 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/CalculateNotifyResult.java

@@ -0,0 +1,75 @@
+package com.qmth.distributed.print.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @Description: 计算回调结果
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2022/6/7
+ */
+public class CalculateNotifyResult implements Serializable {
+
+    @ApiModelProperty(value = "考试id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long examId;
+
+    @ApiModelProperty(value = "课程编码,一个分析试卷的唯一标识")
+    private List<String> courseCode;
+
+    @ApiModelProperty(value = "进度")
+    private BigDecimal progress;
+
+    @ApiModelProperty(value = "任务状态")
+    private String status;
+
+    @ApiModelProperty(value = "时间戳")
+    private Long time;
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public List<String> getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(List<String> courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public BigDecimal getProgress() {
+        return progress;
+    }
+
+    public void setProgress(BigDecimal progress) {
+        this.progress = progress;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public Long getTime() {
+        return time;
+    }
+
+    public void setTime(Long time) {
+        this.time = time;
+    }
+}

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

@@ -8,6 +8,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * <p>
@@ -46,6 +47,39 @@ public class GradeBatch extends BaseEntity implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long thirdExamId;
 
+    @ApiModelProperty(value = "原始数据")
+    private String source;
+
+    @ApiModelProperty(value = "进度")
+    private BigDecimal progress;
+
+    @ApiModelProperty(value = "报告路径")
+    private String reportFilePath;
+
+    public BigDecimal getProgress() {
+        return progress;
+    }
+
+    public void setProgress(BigDecimal progress) {
+        this.progress = progress;
+    }
+
+    public String getReportFilePath() {
+        return reportFilePath;
+    }
+
+    public void setReportFilePath(String reportFilePath) {
+        this.reportFilePath = reportFilePath;
+    }
+
+    public String getSource() {
+        return source;
+    }
+
+    public void setSource(String source) {
+        this.source = source;
+    }
+
     public Long getSchoolId() {
         return schoolId;
     }

+ 31 - 15
distributed-print/src/main/java/com/qmth/distributed/print/api/NotifyApiController.java

@@ -1,8 +1,11 @@
 package com.qmth.distributed.print.api;
 
+import com.alibaba.fastjson.JSONObject;
 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.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
@@ -42,29 +45,42 @@ public class NotifyApiController {
     DictionaryConfig dictionaryConfig;
 
     @ApiOperation(value = "教研分析进度回调")
-    @ApiResponses({@ApiResponse(code = 200, message = "教研分析进度回调", response = Object.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "教研分析进度回调", response = CalculateNotifyResult.class)})
     @RequestMapping(value = "/analysis/progress", method = RequestMethod.POST)
     @Aac(auth = BOOL.FALSE)
     public Result analysisProgress(@ApiParam(value = "接收教研分析回调数据", required = true) @RequestBody String result) throws UnsupportedEncodingException {
-        log.info("analysis_progress,result:{}", result);
-        String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
-        log.info("analysis_progress decodeJson:{}", decodeJson);
+        try {
+            log.info("analysis_progress,result:{}", result);
+            String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
+            log.info("analysis_progress decodeJson:{}", decodeJson);
 
-        String callbackPwd = dictionaryConfig.printOpenDomain().getCallbackPwd();
-        Optional.ofNullable(callbackPwd).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("配置文件回调密码为空"));
+            String callbackPwd = dictionaryConfig.printOpenDomain().getCallbackPwd();
+            Optional.ofNullable(callbackPwd).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("配置文件回调密码为空"));
 
-        String sign = ServletUtil.getRequestAuthorization();
-        Optional.ofNullable(sign).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("签名为空"));
-        log.info("sign:{}", sign);
+            String sign = ServletUtil.getRequestAuthorization();
+            Optional.ofNullable(sign).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("签名为空"));
+            log.info("sign:{}", sign);
 
-        String localSign = URLEncoder.encode(Base64Util.encode(ShaUtils.sha1(callbackPwd + decodeJson)), SystemConstant.CHARSET_NAME);
-        log.info("localSign:{}", localSign);
+            String localSign = URLEncoder.encode(Base64Util.encode(ShaUtils.sha1(callbackPwd + decodeJson)), SystemConstant.CHARSET_NAME);
+            log.info("localSign:{}", localSign);
 
-        if (!Objects.equals(localSign, sign)) {
-            throw ExceptionResultEnum.ERROR.exception("签名不匹配");
+            if (!Objects.equals(localSign, sign)) {
+                throw ExceptionResultEnum.ERROR.exception("签名不匹配");
+            }
+            CalculateNotifyResult calculateNotifyResult = JSONObject.toJavaObject(JSONObject.parseObject(decodeJson), CalculateNotifyResult.class);
+            String source = Base64Util.encode(ShaUtils.sha1(calculateNotifyResult.getExamId() + calculateNotifyResult.getCourseCode().toString()));
+            log.info("source:{}", source);
+            //TODO 此处加批次数据状态更新service方法
+            //更新grade_batch(状态和进度)和grade_batch_paper(状态)
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            //todo 生成txt文件
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
         }
-
-        //TODO 此处加批次数据状态更新service方法
         return ResultUtil.ok(System.currentTimeMillis());
     }
 }

+ 17 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/TSAuthController.java

@@ -1,6 +1,9 @@
 package com.qmth.distributed.print.api;
 
+import cn.hutool.http.HttpStatus;
+import com.alibaba.fastjson.JSONObject;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.boot.api.exception.ApiException;
 import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
 import com.qmth.boot.tools.signature.SignatureEntity;
 import com.qmth.boot.tools.signature.SignatureType;
@@ -8,6 +11,7 @@ import com.qmth.distributed.print.business.service.AuthInfoService;
 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.*;
 import io.swagger.annotations.*;
@@ -160,15 +164,26 @@ public class TSAuthController {
                     2022052700001L + "E",
                     2022052700001L + "F",
                     2022052700001L + "G"));//试卷编号+卷型
+            String source = Base64Util.encode(ShaUtils.sha1(map.get("examId") + map.get("courseCode").toString()));
+            log.info("source:{}", 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)) {
                 log.info("result:{}", JacksonUtil.parseJson(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"));
+                }
             }
+            //TODO 更新grade_batch source
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
-        } finally {
-
+            //TODO 生成txt文件
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
         }
     }
 }

+ 4 - 3
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/templete/strategy/CalculateTaskTemplate.java

@@ -44,11 +44,13 @@ public abstract class CalculateTaskTemplate {
         tbSyncTaskQueryWrapper.lambda().eq(TBSyncTask::getThirdRelateId, calculateParams.getExamId())
                 .eq(TBSyncTask::getSource, source);
         TBSyncTask tbSyncTask = tbSyncTaskService.getOne(tbSyncTaskQueryWrapper);
+        calculateParams.setTbSyncTask(tbSyncTask);
         if (Objects.isNull(tbSyncTask)) {
             tbSyncTask = new TBSyncTask(calculateParams.getSchoolId(), calculateParams.getExamId(), source);
             tbSyncTaskService.save(tbSyncTask);
+        } else if (tbSyncTask.getStatus() == TaskStatusEnum.FINISH && tbSyncTask.getResult() == TaskResultEnum.SUCCESS) {
+            throw ExceptionResultEnum.ERROR.exception("该批次已完成计算");
         }
-        calculateParams.setTbSyncTask(tbSyncTask);
     }
 
     /**
@@ -106,7 +108,6 @@ public abstract class CalculateTaskTemplate {
         TBSyncTask tbSyncTask = calculateParams.getTbSyncTask();
         tbSyncTask.setStatus(TaskStatusEnum.FINISH);
         tbSyncTask.setResult(TaskResultEnum.ERROR);
-        callback(calculateParams);
     }
 
     /**
@@ -123,7 +124,7 @@ public abstract class CalculateTaskTemplate {
         Long time = System.currentTimeMillis();
         JSONObject dataObjectJson = new JSONObject();
         dataObjectJson.put("examId", tbSyncTask.getThirdRelateId());
-        dataObjectJson.put("courseCode", tbSyncTask.getObj());
+        dataObjectJson.put("courseCode", calculateParams.getCourseCode());
         dataObjectJson.put("progress", tbSyncTask.getProgress());
         dataObjectJson.put("status", tbSyncTask.getStatus());
         dataObjectJson.put("time", time);

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

@@ -20,6 +20,12 @@ import java.io.IOException;
 public class CourseCodeSyncTaskService extends CalculateTaskTemplate {
     private final static Logger log = LoggerFactory.getLogger(CourseCodeSyncTaskService.class);
 
+    /**
+     * 数据校验
+     *
+     * @param calculateParams
+     * @throws IOException
+     */
     @Override
     public void dataVaild(CalculateParams calculateParams) throws IOException {
         log.info("CourseCodeSyncTaskService dataVaild come in");
@@ -30,6 +36,12 @@ public class CourseCodeSyncTaskService extends CalculateTaskTemplate {
         //TODO 此处加校验数据具体逻辑方法,推荐service方法然后加@Transactional注解
     }
 
+    /**
+     * 数据计算
+     *
+     * @param calculateParams
+     * @throws IOException
+     */
     @Override
     public void calculate(CalculateParams calculateParams) throws IOException {
         log.info("CourseCodeSyncTaskService calculate come in");