Browse Source

update refresh

deason 6 years ago
parent
commit
548a8a96a5

+ 11 - 4
examcloud-core-print-provider/src/main/java/cn/com/qmth/examcloud/core/print/api/controller/CourseStatisticController.java

@@ -10,6 +10,7 @@ package cn.com.qmth.examcloud.core.print.api.controller;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.print.common.Result;
 import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
+import cn.com.qmth.examcloud.core.print.service.bean.common.RefreshInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticQuery;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticRefreshReq;
@@ -17,10 +18,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import static cn.com.qmth.examcloud.core.print.common.Result.success;
 
@@ -50,4 +48,13 @@ public class CourseStatisticController extends ControllerSupport {
         return success();
     }
 
+    @GetMapping("/refresh/check")
+    @ApiOperation(value = "检查课程统计任务是否正在刷新中")
+    public Result refreshCheck(@RequestParam(required = false) Boolean reset) {
+        if (reset != null) {
+            RefreshInfo.coursesRefreshing = reset;
+        }
+        return success(RefreshInfo.coursesRefreshing);
+    }
+
 }

+ 11 - 4
examcloud-core-print-provider/src/main/java/cn/com/qmth/examcloud/core/print/api/controller/PrintingProjectStatisticController.java

@@ -10,14 +10,12 @@ package cn.com.qmth.examcloud.core.print.api.controller;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.print.common.Result;
 import cn.com.qmth.examcloud.core.print.service.PrintingProjectStatisticService;
+import cn.com.qmth.examcloud.core.print.service.bean.common.RefreshInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.printingprojectstatistic.PrintingProjectStatisticInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import static cn.com.qmth.examcloud.core.print.common.Result.success;
 
@@ -47,4 +45,13 @@ public class PrintingProjectStatisticController extends ControllerSupport {
         return success();
     }
 
+    @GetMapping("/refresh/check")
+    @ApiOperation(value = "检查项目统计任务是否正在刷新中")
+    public Result refreshCheck(@RequestParam(required = false) Boolean reset) {
+        if (reset != null) {
+            RefreshInfo.projectRefreshing = reset;
+        }
+        return success(RefreshInfo.projectRefreshing);
+    }
+
 }

+ 26 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/bean/common/RefreshInfo.java

@@ -0,0 +1,26 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-12-20 13:32:18.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.print.service.bean.common;
+
+/**
+ * @author: fengdesheng
+ * @since: 2018/12/20
+ */
+public class RefreshInfo {
+
+    /**
+     * 是否项目统计刷新中
+     */
+    public static boolean projectRefreshing = false;
+
+    /**
+     * 是否课程统计刷新中
+     */
+    public static boolean coursesRefreshing = false;
+
+}

+ 37 - 20
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CourseStatisticServiceImpl.java

@@ -7,6 +7,7 @@
 
 package cn.com.qmth.examcloud.core.print.service.impl;
 
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.core.print.common.jpa.OrderBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
@@ -21,6 +22,7 @@ import cn.com.qmth.examcloud.core.print.service.StatisticService;
 import cn.com.qmth.examcloud.core.print.service.bean.common.CourseInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.common.ExamCourseInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.common.ExamInfo;
+import cn.com.qmth.examcloud.core.print.service.bean.common.RefreshInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.*;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -38,6 +40,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static cn.com.qmth.examcloud.core.print.common.Constants.PRT_CODE_500;
+
 /**
  * @author: fengdesheng
  * @since: 2018/10/17
@@ -112,29 +116,42 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         Check.isNull(req.getOrgId(), "学校ID不能为空!");
         Check.isNull(req.getExamId(), "考试ID不能为空!");
 
-        //待刷新的课程列表
-        List<ExamCourseInfo> examCourses;
-
-        boolean needClear = false;//是否清除多余课程
-        List<CourseStatisticRefreshReq.Course> courses = req.getCourses();
-        if (courses == null || courses.size() == 0) {
-            //未选择课程时,则统计当前考试下的所有课程
-            examCourses = statisticService.findExamCourseAndPaperTypes(req.getOrgId(), req.getExamId());
-            needClear = true;
-        } else {
-            //否则,统计已选择的课程
-            examCourses = new ArrayList<>();
-            for (CourseStatisticRefreshReq.Course course : courses) {
-                if (course.getCourseId() == null || StringUtils.isBlank(course.getPaperType())) {
-                    continue;
+        if (RefreshInfo.coursesRefreshing) {
+            throw new StatusException(PRT_CODE_500, "尚有课程统计任务正在刷新中,请稍后再刷新!");
+        }
+
+        //目前限定仅一个刷新任务可执行
+        RefreshInfo.coursesRefreshing = true;
+        try {
+            //待刷新的课程列表
+            List<ExamCourseInfo> examCourses;
+
+            boolean needClear = false;//是否清除多余课程
+            List<CourseStatisticRefreshReq.Course> courses = req.getCourses();
+            if (courses == null || courses.size() == 0) {
+                //未选择课程时,则统计当前考试下的所有课程
+                examCourses = statisticService.findExamCourseAndPaperTypes(req.getOrgId(), req.getExamId());
+                needClear = true;
+            } else {
+                //否则,统计已选择的课程
+                examCourses = new ArrayList<>();
+                for (CourseStatisticRefreshReq.Course course : courses) {
+                    if (course.getCourseId() == null || StringUtils.isBlank(course.getPaperType())) {
+                        continue;
+                    }
+                    examCourses.add(new ExamCourseInfo(req.getOrgId(), req.getExamId(), course.getCourseId(), course.getPaperType()));
                 }
-                examCourses.add(new ExamCourseInfo(req.getOrgId(), req.getExamId(), course.getCourseId(), course.getPaperType()));
             }
-        }
 
-        //获取当前考试下已有的课程统计信息
-        Map<String, CourseStatistic> oldCourseStatisticMaps = this.getCourseStatisticMaps(req.getOrgId(), req.getExamId());
-        this.syncCourseStatistics(examCourses, oldCourseStatisticMaps, needClear);
+            //获取当前考试下已有的课程统计信息
+            Map<String, CourseStatistic> oldCourseStatisticMaps = this.getCourseStatisticMaps(req.getOrgId(), req.getExamId());
+            this.syncCourseStatistics(examCourses, oldCourseStatisticMaps, needClear);
+        } catch (StatusException e) {
+            throw e;//状态异常则直接抛出
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+        RefreshInfo.coursesRefreshing = false;
     }
 
     @Override

+ 18 - 4
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/PrintingProjectStatisticServiceImpl.java

@@ -20,6 +20,7 @@ import cn.com.qmth.examcloud.core.print.service.PrintingProjectService;
 import cn.com.qmth.examcloud.core.print.service.PrintingProjectStatisticService;
 import cn.com.qmth.examcloud.core.print.service.StatisticService;
 import cn.com.qmth.examcloud.core.print.service.bean.common.ExamCourseInfo;
+import cn.com.qmth.examcloud.core.print.service.bean.common.RefreshInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticLessInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticRefreshReq;
 import cn.com.qmth.examcloud.core.print.service.bean.printingproject.PrintingProjectLessInfo;
@@ -80,10 +81,23 @@ public class PrintingProjectStatisticServiceImpl implements PrintingProjectStati
             throw new StatusException(PRT_CODE_500, "当前项目不存在!");
         }
 
-        //刷新课程统计
-        courseStatisticService.refreshCourseStatistic(new CourseStatisticRefreshReq(orgId, examId));
-        //执行项目统计
-        this.doStatistic(Lists.newArrayList(new PrintingProjectLessInfo(orgId, examId, project.getId())));
+        if (RefreshInfo.projectRefreshing) {
+            throw new StatusException(PRT_CODE_500, "尚有项目统计任务正在刷新中,请稍后再刷新!");
+        }
+
+        //目前限定仅一个刷新任务可执行
+        RefreshInfo.projectRefreshing = true;
+        try {
+            //刷新课程统计
+            courseStatisticService.refreshCourseStatistic(new CourseStatisticRefreshReq(orgId, examId));
+            //执行项目统计
+            this.doStatistic(Lists.newArrayList(new PrintingProjectLessInfo(orgId, examId, project.getId())));
+        } catch (StatusException e) {
+            throw e;//状态异常则直接抛出
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+        RefreshInfo.projectRefreshing = false;
     }
 
     @Override

+ 2 - 0
examcloud-core-print-starter/src/main/resources/security-exclusions.conf

@@ -26,8 +26,10 @@
 #[${$rmp.ctrl.print}/printing/project][/exam/list][POST]
 [${$rmp.ctrl.print}/printing/project/statistic][/{orgId}/{examId}][POST]
 [${$rmp.ctrl.print}/printing/project/statistic][/refresh/{orgId}/{examId}][POST]
+[${$rmp.ctrl.print}/printing/project/statistic][/refresh/check][GET]
 [${$rmp.ctrl.print}/course/statistic][/list][POST]
 [${$rmp.ctrl.print}/course/statistic][/refresh][POST]
+[${$rmp.ctrl.print}/course/statistic][/refresh/check][GET]
 
 [${$rmp.ctrl.print}/project/backup/setting][/{projectId}][POST]
 [${$rmp.ctrl.print}/project/backup/setting][/save][POST]