Sfoglia il codice sorgente

学生总数统计

xiatian 5 anni fa
parent
commit
8c63dc6411

+ 126 - 15
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/job/StudentTotalCountTask.java

@@ -1,9 +1,30 @@
 package cn.com.qmth.examcloud.task.service.job;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
+import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
+import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
+import cn.com.qmth.examcloud.core.basic.api.request.CountStudentReq;
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgsReq;
+import cn.com.qmth.examcloud.core.basic.api.response.CountStudentResp;
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgsResp;
+import cn.com.qmth.examcloud.core.oe.admin.api.OeExamStudentCloudService;
+import cn.com.qmth.examcloud.core.oe.admin.api.request.GetExamStudentCountReq;
+import cn.com.qmth.examcloud.core.oe.admin.api.response.GetExamStudentCountResp;
+import cn.com.qmth.examcloud.core.reports.api.ExamDataCloudService;
 import cn.com.qmth.examcloud.core.reports.api.StudentTotalCountCloudService;
+import cn.com.qmth.examcloud.core.reports.api.request.SaveExamDataReq;
+import cn.com.qmth.examcloud.core.reports.api.request.SaveStudentTotalCountReq;
+import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
+import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamsReq;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamsResp;
 import cn.com.qmth.examcloud.web.task.AbstractTask;
 import cn.com.qmth.examcloud.web.task.ScheduleJob;
 import cn.com.qmth.examcloud.web.task.TaskTracker;
@@ -11,19 +32,109 @@ import cn.com.qmth.examcloud.web.task.TaskTracker;
 @Component("studentTotalCountTask")
 public class StudentTotalCountTask extends AbstractTask {
 
-	@Autowired
-	StudentTotalCountCloudService studentTotalCountCloudService;
-
-	@Autowired
-	TaskTracker TaskTracker;
-	
-	@Override
-	public void run(ScheduleJob scheduleJob) throws Exception {
-		studentTotalCountCloudService.compute();
-	}
-
-	@Override
-	public TaskTracker getTaskTracker() {
-		return TaskTracker;
-	}
+    @Autowired
+    private OeExamStudentCloudService oeExamStudentCloudService;
+
+    @Autowired
+    private ExamCloudService examCloudService;
+
+    @Autowired
+    private ExamDataCloudService examDataCloudService;
+
+    @Autowired
+    StudentTotalCountCloudService studentTotalCountCloudService;
+
+    @Autowired
+    private OrgCloudService orgCloudService;
+
+    @Autowired
+    private StudentCloudService studentCloudService;
+
+    @Autowired
+    TaskTracker TaskTracker;
+
+    @Override
+    public void run(ScheduleJob scheduleJob) throws Exception {
+        GetOrgsReq orgsreq = new GetOrgsReq();
+        Long orgStartId = 0L;
+        orgsreq.setWithoutParentId(true);
+        orgsreq.setEnable(true);
+        for (;;) {
+            orgsreq.setStart(orgStartId);
+            GetOrgsResp orgRes = orgCloudService.getOrgs(orgsreq);
+            if (CollectionUtils.isEmpty(orgRes.getOrgBeanList())) {
+                break;
+            }
+            for (OrgBean org : orgRes.getOrgBeanList()) {
+                computeStudentTotalCount(org.getId());
+                computeExamData(org.getId());
+            }
+            orgStartId = orgRes.getNext();
+        }
+    }
+
+    private void computeStudentTotalCount(Long rootOrgId) {
+        CountStudentReq csr = new CountStudentReq();
+        csr.setRootOrgId(rootOrgId);
+        CountStudentResp csres = studentCloudService.countStudent(csr);
+        Long totalCount = 0L;
+        if (csres.getCount() != null) {
+            totalCount = csres.getCount();
+        }
+        SaveStudentTotalCountReq req = new SaveStudentTotalCountReq();
+        req.setRootOrgId(rootOrgId);
+        req.setCount(totalCount.intValue());
+        studentTotalCountCloudService.save(req);
+    }
+
+    private void computeExamData(Long rootOrgId) {
+        GetExamsReq req = new GetExamsReq();
+        Long startId = 0L;
+        req.setRootOrgId(rootOrgId);
+        req.setEnable(true);
+        for (;;) {
+            req.setStart(startId);
+            GetExamsResp res = examCloudService.getExams(req);
+            if (CollectionUtils.isEmpty(res.getExamBeanList())) {
+                break;
+            }
+            for (ExamBean exam : res.getExamBeanList()) {
+                computeExamData(exam, rootOrgId);
+            }
+            startId = res.getNext();
+        }
+    }
+
+    private void computeExamData(ExamBean exam, Long rootOrgId) {
+        Long planCount = 0l;
+        Long compCount = 0l;
+        GetExamStudentCountReq req = new GetExamStudentCountReq();
+        List<Long> eids = new ArrayList<Long>();
+        eids.add(exam.getId());
+        req.setExamIdList(eids);
+        GetExamStudentCountResp res = oeExamStudentCloudService.getExamStudentCount(req);
+        if (CollectionUtils.isNotEmpty(res.getCountList())) {
+            planCount = res.getCountList().get(0).getCount();
+        }
+        req.setFinishedExam(true);
+        res = oeExamStudentCloudService.getExamStudentCount(req);
+        if (CollectionUtils.isNotEmpty(res.getCountList())) {
+            compCount = res.getCountList().get(0).getCount();
+        }
+        SaveExamDataReq sreq = new SaveExamDataReq();
+        sreq.setEndTime(exam.getEndTime());
+        sreq.setStartTime(exam.getBeginTime());
+        sreq.setExamId(exam.getId());
+        sreq.setExamName(exam.getName());
+        sreq.setExamType(exam.getExamType());
+        sreq.setRootOrgId(exam.getRootOrgId());
+        sreq.setPlanCount(planCount.intValue());
+        sreq.setCompleteCount(compCount.intValue());
+        examDataCloudService.save(sreq);
+    }
+
+    @Override
+    public TaskTracker getTaskTracker() {
+        return TaskTracker;
+    }
 }