xiatian 6 anni fa
parent
commit
7dd87cbd27

+ 51 - 0
examcloud-task-base/src/main/java/cn/com/qmth/examcloud/task/base/util/BatchGetDataUtil.java

@@ -0,0 +1,51 @@
+package cn.com.qmth.examcloud.task.base.util;
+
+import java.util.List;
+
+/**
+ *	多次批量获取数据
+ *	需重写getData方法
+ * @param <R> 结果类
+ * @param <P> 参数类
+ */
+public  class BatchGetDataUtil<R,P> {
+	/**
+	 * @param resultList 全部结果集合
+	 * @param paramList 全部参数集合
+	 * @param batchSize 每批参数数量
+	 */
+	public void getDataForBatch(List<R> resultList,List<P> paramList,int batchSize) {
+		if(resultList==null||paramList==null||paramList.size()==0) {
+			return;
+		}
+		if(paramList.size()<=batchSize) {
+			List<R> temlist = getData(paramList);
+			if(temlist!=null&&temlist.size()>0) {
+				resultList.addAll(temlist);
+			}
+		}else {
+			int size = paramList.size();
+			int len=batchSize;
+			int count = (size + len - 1) / len;
+
+			for (int i = 0; i < count; i++) {
+				List<P> subList = paramList.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
+				List<R> temlist = getData(subList);
+				if(temlist!=null&&temlist.size()>0) {
+					resultList.addAll(temlist);
+				}
+			}
+		}
+	}
+	/**
+	 * 	Need Override
+	 * 	每批获取数据方法
+	 * @param <R>
+	 * @param <P>
+	 * @param paramList 获取每批数据时参数
+	 * @return
+	 */
+	public  List<R> getData(List<P> paramList) {
+		return null;
+	}
+}

+ 105 - 5
examcloud-task-service/src/main/java/cn/com/qmth/examcloud/task/service/impl/ReportsComputeServiceImpl.java

@@ -17,6 +17,14 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
+import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
+import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
+import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
+import cn.com.qmth.examcloud.core.basic.api.request.GetCoursesByIdListReq;
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgsByIdListReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetCoursesByIdListResp;
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgsByIdListResp;
 import cn.com.qmth.examcloud.core.oe.admin.api.ExamStudentDataCloudService;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamStudentDataBean;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamStudentScoreDataBean;
@@ -35,6 +43,11 @@ import cn.com.qmth.examcloud.core.reports.api.request.SaveExamCourseDataReportLi
 import cn.com.qmth.examcloud.core.reports.api.request.SaveExamOrgReportListReq;
 import cn.com.qmth.examcloud.core.reports.api.request.UpdateProjectStatusReq;
 import cn.com.qmth.examcloud.core.reports.api.response.GetProjectInfoBeanResp;
+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.GetExamsByIdListReq;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamsByIdListResp;
+import cn.com.qmth.examcloud.task.base.util.BatchGetDataUtil;
 import cn.com.qmth.examcloud.task.dao.ReportsComputeRepo;
 import cn.com.qmth.examcloud.task.dao.entity.ReportsComputeEntity;
 import cn.com.qmth.examcloud.task.dao.enums.ReportsComputeStatus;
@@ -45,9 +58,15 @@ import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 
 @Service
 public class ReportsComputeServiceImpl implements ReportsComputeService {
+	private final static int batchSize = 100;
 
 	private final static Map<Long, Boolean> jobStopFlag = new HashMap<Long, Boolean>();
-
+	@Autowired
+	private CourseCloudService courseCloudService;
+	@Autowired
+	private ExamCloudService examCloudService;
+	@Autowired
+	private OrgCloudService orgCloudService;
 	@Autowired
 	private ReportsComputeRepo reportsComputeRepo;
 
@@ -194,7 +213,9 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		// 判断任务终止
 		checkIsStoping(et.getId());
 		// 设置中心、课程、考试code和名称
-		// TODO
+		fillOrgNameCode(examOrgReport);
+		fillCourseNameCode(examCourseDataReport);
+		fillExamNameCode(examOrgReport, examCourseDataReport);
 
 		// 判断任务终止
 		checkIsStoping(et.getId());
@@ -224,6 +245,84 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 		examCourseDataReportCloudService.saveExamCourseDataReportList(req2);
 	}
 
+	private void fillOrgNameCode(Map<String, ExamOrgReportBean> examOrgReport) {
+		List<Long> ids = examOrgReport.entrySet().stream().map(dto -> dto.getValue().getOrgId()).distinct()
+				.collect(Collectors.toList());
+		List<OrgBean> orgList = new ArrayList<OrgBean>();
+		GetOrgsByIdListReq req = new GetOrgsByIdListReq();
+		BatchGetDataUtil<OrgBean, Long> tool = new BatchGetDataUtil<OrgBean, Long>() {
+			@Override
+			public List<OrgBean> getData(List<Long> paramList) {
+				req.setOrgIdList(paramList);
+				GetOrgsByIdListResp resp = orgCloudService.getOrgsByIdList(req);
+				return resp.getOrgList();
+			}
+
+		};
+		tool.getDataForBatch(orgList, ids, batchSize);
+		Map<Long, OrgBean> orgMap = orgList.stream()
+				.collect(Collectors.toMap(OrgBean::getId, account -> account, (key1, key2) -> key2));
+		for (ExamOrgReportBean b : examOrgReport.values()) {
+			OrgBean ob = orgMap.get(b.getOrgId());
+			b.setOrgCode(ob.getCode());
+			b.setOrgName(ob.getName());
+		}
+	}
+
+	private void fillCourseNameCode(Map<String, ExamCourseDataReportBean> examCourseDataReport) {
+		List<Long> ids = examCourseDataReport.entrySet().stream().map(dto -> dto.getValue().getCourseId()).distinct()
+				.collect(Collectors.toList());
+		List<CourseBean> courseList = new ArrayList<CourseBean>();
+		GetCoursesByIdListReq req = new GetCoursesByIdListReq();
+		BatchGetDataUtil<CourseBean, Long> tool = new BatchGetDataUtil<CourseBean, Long>() {
+			@Override
+			public List<CourseBean> getData(List<Long> paramList) {
+				req.setCourseIdList(paramList);
+				GetCoursesByIdListResp resp = courseCloudService.getCoursesByIdList(req);
+				return resp.getCourseList();
+			}
+
+		};
+		tool.getDataForBatch(courseList, ids, batchSize);
+		Map<Long, CourseBean> map = courseList.stream()
+				.collect(Collectors.toMap(CourseBean::getId, account -> account, (key1, key2) -> key2));
+		for (ExamCourseDataReportBean b : examCourseDataReport.values()) {
+			CourseBean ob = map.get(b.getCourseId());
+			b.setCourseCode(ob.getCode());
+			b.setCourseName(ob.getName());
+		}
+	}
+
+	private void fillExamNameCode(Map<String, ExamOrgReportBean> examOrgReport,
+			Map<String, ExamCourseDataReportBean> examCourseDataReport) {
+		List<Long> ids = examOrgReport.entrySet().stream().map(dto -> dto.getValue().getExamId()).distinct()
+				.collect(Collectors.toList());
+		List<ExamBean> list = new ArrayList<ExamBean>();
+		GetExamsByIdListReq req = new GetExamsByIdListReq();
+		BatchGetDataUtil<ExamBean, Long> tool = new BatchGetDataUtil<ExamBean, Long>() {
+			@Override
+			public List<ExamBean> getData(List<Long> paramList) {
+				req.setExamIdList(paramList);
+				GetExamsByIdListResp resp = examCloudService.getExamsByIdList(req);
+				return resp.getExamList();
+			}
+
+		};
+		tool.getDataForBatch(list, ids, batchSize);
+		Map<Long, ExamBean> map = list.stream()
+				.collect(Collectors.toMap(ExamBean::getId, account -> account, (key1, key2) -> key2));
+		for (ExamOrgReportBean b : examOrgReport.values()) {
+			ExamBean ob = map.get(b.getExamId());
+			b.setExamCode(ob.getCode());
+			b.setExamName(ob.getName());
+		}
+		for (ExamCourseDataReportBean b : examCourseDataReport.values()) {
+			ExamBean ob = map.get(b.getExamId());
+			b.setExamCode(ob.getCode());
+			b.setExamName(ob.getName());
+		}
+	}
+
 	private Double avgDifficultyDegree(String dataKey, Map<String, Set<String>> basePapers,
 			Map<String, Double> basePapersDegree) {
 		Set<String> set = basePapers.get(dataKey);
@@ -559,11 +658,12 @@ public class ReportsComputeServiceImpl implements ReportsComputeService {
 	@Transactional
 	@Override
 	public void add(Long projectId, Long rootOrgId) {
-		List<ReportsComputeEntity> list=reportsComputeRepo.findByProjectIdAndRootOrgIdAndStatus(projectId,rootOrgId,ReportsComputeStatus.COMPUTING);
-		if(list!=null&&list.size()>0) {
+		List<ReportsComputeEntity> list = reportsComputeRepo.findByProjectIdAndRootOrgIdAndStatus(projectId, rootOrgId,
+				ReportsComputeStatus.COMPUTING);
+		if (list != null && list.size() > 0) {
 			throw new StatusException("10001", "该项目正在计算中");
 		}
-		ReportsComputeEntity e=new ReportsComputeEntity();
+		ReportsComputeEntity e = new ReportsComputeEntity();
 		e.setProjectId(projectId);
 		e.setRootOrgId(rootOrgId);
 		e.setStatus(ReportsComputeStatus.NONE);