Browse Source

完成教师端创建时段考试的任务定时与回调业务

zhaosongshan 7 months ago
parent
commit
3880e2d18f

+ 2 - 1
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/domain/exam/TExamIdParam.java

@@ -17,6 +17,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
 
 /**
  * 考试表Id参数
@@ -30,6 +31,6 @@ public class TExamIdParam {
 
     /** 主键 */
     @ApiModelProperty(value = "主键", required = true)
-    @NotBlank(message = "id不能为空")
+    @NotNull(message = "id不能为空")
     private Integer id;
 }

+ 22 - 17
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/job/task/ExamJobTimerTaskRunner.java

@@ -35,27 +35,32 @@ public class ExamJobTimerTaskRunner implements CommonTimerTaskRunner {
     @Override
     public void action(String jobId) {
         log.info("ExamJobTimerTaskRunner jobId:{} RUN...",jobId);
-        if(jobId != null && !jobId.isEmpty()){
-            JSONObject jb = devJobApi.queryEntity(jobId);
-            if(jb != null && jb.getIntValue("code") == 200){
-                String category = jb.getString("category");
-                JSONObject extJson = jb.getJSONObject("extJson");
-                log.info("ExamJobTimerTaskRunner jobId:{} category:{} extJson:{}",jobId,category,extJson);
-                TExam taskExam = texamMapper.selectById(extJson.getString("id"));
+        try {
+            if(jobId != null && !jobId.isEmpty()){
+                JSONObject jb = devJobApi.queryEntity(jobId);
+                if(jb != null && jb.getIntValue("code") == 200){
+                    String category = jb.getString("category");
+                    JSONObject extJson = jb.getJSONObject("extJson");
+                    log.info("ExamJobTimerTaskRunner jobId:{} category:{} extJson:{}",jobId,category,extJson);
+                    TExam taskExam = texamMapper.selectById(extJson.getString("id"));
 
-                if(category.contains("start")){
-                    taskExam.setExamStatus(1);
-                    texamMapper.updateById(taskExam);
-                }
-                if(category.contains("end")){
-                    taskExam.setExamStatus(2);
-                    texamMapper.updateById(taskExam);
+                    if(category.contains("start")){
+                        taskExam.setExamStatus(1);
+                        texamMapper.updateById(taskExam);
+                    }
+                    if(category.contains("end")){
+                        taskExam.setExamStatus(2);
+                        texamMapper.updateById(taskExam);
+                    }
+                }else{
+                    log.error("ExamJobTimerTaskRunner jobId:{} Query Error", jobId);
                 }
             }else{
-                log.error("ExamJobTimerTaskRunner jobId:{} Query Error", jobId);
+                log.error("ExamJobTimerTaskRunner jobId IS Empty");
             }
-        }else{
-            log.error("ExamJobTimerTaskRunner jobId IS Empty");
+        } catch (Exception e) {
+            log.error("ExamJobTimerTaskRunner  Error:{}", e);
+            e.printStackTrace();
         }
     }
 }

+ 20 - 0
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/service/impl/TExamServiceImpl.java

@@ -187,6 +187,26 @@ public class TExamServiceImpl extends ServiceImpl<TExamMapper, TExam> implements
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void delete(List<TExamIdParam> tExamIdParamList) {
+        List<TExam> dbExamList = this.listByIds(CollStreamUtil.toList(tExamIdParamList, TExamIdParam::getId));
+        List<String> jobIds = new ArrayList<String>();
+        for(TExam dbExam : dbExamList){
+            if(dbExam.getStartJobId() != null){
+                jobIds.add(dbExam.getStartJobId());
+            }
+            if(dbExam.getEndJobId() != null){
+                jobIds.add(dbExam.getEndJobId());
+            }
+        }
+        JSONObject delJobResult = devJobApi.deleteJob(jobIds);
+        if(delJobResult != null && delJobResult.getInteger("code") != null && delJobResult.getIntValue("code") == 200){
+            log.info("任务删除成功!!!");
+        }else{
+            String msg = "";
+            if(delJobResult != null && delJobResult.getString("msg") != null){
+                msg = delJobResult.getString("msg");
+            }
+            log.error("任务删除失败,{}",msg);
+        }
         // 执行删除
         this.removeByIds(CollStreamUtil.toList(tExamIdParamList, TExamIdParam::getId));
     }