|
@@ -1,82 +1,174 @@
|
|
|
-package cn.com.qmth.examcloud.task.service.producer;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordForMarkingCloudService;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordForMarkingBean;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.request.FindExamRecordForMarkingInfoReq;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.response.FindExamRecordForMarkingInfoResp;
|
|
|
-import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
-import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
-import cn.com.qmth.examcloud.task.base.multithread.Producer;
|
|
|
-import cn.com.qmth.examcloud.task.service.dto.MarkWorkCreateItemsDto;
|
|
|
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
-
|
|
|
-public class MarkWorkCreateItemsProducer extends Producer {
|
|
|
-
|
|
|
- private ExamRecordForMarkingCloudService examRecordForMarkingCloudService = SpringContextHolder
|
|
|
- .getBean(ExamRecordForMarkingCloudService.class);
|
|
|
-
|
|
|
-
|
|
|
- private static final Logger LOG = LoggerFactory.getLogger(MarkWorkCreateItemsProducer.class);
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void produce(Map<String, Object> param) throws Exception {
|
|
|
- Long examId = (Long) param.get("examId");
|
|
|
- Long workId = (Long) param.get("workId");
|
|
|
- Long batchSize = 50L;
|
|
|
- SysPropertyCacheBean spc = CacheHelper.getSysProperty("marking.rpc.saveMarkItems.batchSize");
|
|
|
- if (spc != null && spc.getValue() != null) {
|
|
|
- batchSize = (Long) spc.getValue();
|
|
|
- }
|
|
|
-
|
|
|
- FindExamRecordForMarkingInfoReq markingReq = new FindExamRecordForMarkingInfoReq();
|
|
|
- markingReq.setExamId(examId);
|
|
|
- markingReq.setBatchNum(workId + "");
|
|
|
- FindExamRecordForMarkingInfoResp markingResp = examRecordForMarkingCloudService
|
|
|
- .findExamRecordForMarkingInfo(markingReq);
|
|
|
- List<ExamRecordForMarkingBean> examRecordForMarkingBeanList = markingResp.getExamRecordForMarkingBeanList();
|
|
|
- if(examRecordForMarkingBeanList!=null&&examRecordForMarkingBeanList.size()>0) {
|
|
|
- List<String> result=duplicateRemoval(examRecordForMarkingBeanList);
|
|
|
- LOG.info("创建评卷工作评分项,试卷套数:" + result.size());
|
|
|
- subListDispose(result, workId, batchSize);
|
|
|
- }else {
|
|
|
- LOG.info("创建评卷工作评分项,试卷套数:0");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private List<String> duplicateRemoval(List<ExamRecordForMarkingBean> list){
|
|
|
- Set<String> set=new HashSet<String>();
|
|
|
- for(ExamRecordForMarkingBean bean:list) {
|
|
|
- set.add(bean.getBasePaperId());
|
|
|
- }
|
|
|
- List<String> result = new ArrayList<>(set);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- private void subListDispose(List<String> list, Long workId, Long batchSize) throws InterruptedException {
|
|
|
- if (list.size() <= batchSize) {
|
|
|
- // 生产需处理的数据
|
|
|
- offer(new MarkWorkCreateItemsDto(list, workId));
|
|
|
- } else {
|
|
|
- int size = list.size();
|
|
|
- int len = batchSize.intValue();
|
|
|
- int count = (size + len - 1) / len;
|
|
|
-
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
- List<String> subList = list.subList(i * len,
|
|
|
- ((i + 1) * len > size ? size : len * (i + 1)));
|
|
|
- // 生产需处理的数据
|
|
|
- offer(new MarkWorkCreateItemsDto(subList, workId));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+package cn.com.qmth.examcloud.task.service.producer;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.CallType;
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordForMarkingCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordForMarkingBean;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.request.FindExamRecordForMarkingInfoReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.response.FindExamRecordForMarkingInfoResp;
|
|
|
+import cn.com.qmth.examcloud.core.questions.api.ExtractConfigCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.api.bean.ExtractConfigBean;
|
|
|
+import cn.com.qmth.examcloud.core.questions.api.bean.ExtractConfigDetailBean;
|
|
|
+import cn.com.qmth.examcloud.core.questions.api.request.GetExtractConfigBeanReq;
|
|
|
+import cn.com.qmth.examcloud.core.questions.api.response.GetExtractConfigBeanResp;
|
|
|
+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.GetExamReq;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.response.GetExamResp;
|
|
|
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
|
+import cn.com.qmth.examcloud.support.enums.MarkingType;
|
|
|
+import cn.com.qmth.examcloud.support.enums.MarkingWorkType;
|
|
|
+import cn.com.qmth.examcloud.task.base.multithread.Producer;
|
|
|
+import cn.com.qmth.examcloud.task.service.dto.MarkWorkCreateItemsDto;
|
|
|
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
+
|
|
|
+public class MarkWorkCreateItemsProducer extends Producer {
|
|
|
+
|
|
|
+ private ExamRecordForMarkingCloudService examRecordForMarkingCloudService = SpringContextHolder
|
|
|
+ .getBean(ExamRecordForMarkingCloudService.class);
|
|
|
+
|
|
|
+ private ExamCloudService examCloudService = SpringContextHolder.getBean(ExamCloudService.class);
|
|
|
+
|
|
|
+ private ExtractConfigCloudService extractConfigCloudService = SpringContextHolder
|
|
|
+ .getBean(ExtractConfigCloudService.class);
|
|
|
+
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(MarkWorkCreateItemsProducer.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void produce(Map<String, Object> param) throws Exception {
|
|
|
+ Long examId = (Long) param.get("examId");
|
|
|
+ Long workId = (Long) param.get("workId");
|
|
|
+ Long batchSize = 50L;
|
|
|
+ SysPropertyCacheBean spc = CacheHelper.getSysProperty("marking.rpc.saveMarkItems.batchSize");
|
|
|
+ if (spc != null && spc.getValue() != null) {
|
|
|
+ batchSize = (Long) spc.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ GetExamReq getExamReq = new GetExamReq();
|
|
|
+ getExamReq.setId(examId);
|
|
|
+ GetExamResp getExamResp = examCloudService.getExam(getExamReq);
|
|
|
+ ExamBean examBean = getExamResp.getExamBean();
|
|
|
+
|
|
|
+ if (ExamType.ONLINE.name().equals(examBean.getExamType()) && checkIsAnyTimeMark(examId)) {
|
|
|
+ // 在线考试且是随考随阅的,从调卷规则和考试记录合并拉取所有试卷。因为调卷规则随时会修改
|
|
|
+ List<String> result = getAllBasePaperIdsForAnyTimeMark(workId, examId);
|
|
|
+ if (CollectionUtils.isNotEmpty(result)) {
|
|
|
+ LOG.info("创建评卷工作评分项,试卷套数:" + result.size());
|
|
|
+ subListDispose(result, workId, batchSize);
|
|
|
+ } else {
|
|
|
+ LOG.info("创建评卷工作评分项,试卷套数:0");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ FindExamRecordForMarkingInfoReq markingReq = new FindExamRecordForMarkingInfoReq();
|
|
|
+ markingReq.setExamId(examId);
|
|
|
+ markingReq.setBatchNum(workId + "");
|
|
|
+ FindExamRecordForMarkingInfoResp markingResp = examRecordForMarkingCloudService
|
|
|
+ .findExamRecordForMarkingInfo(markingReq);
|
|
|
+ List<ExamRecordForMarkingBean> examRecordForMarkingBeanList = markingResp.getExamRecordForMarkingBeanList();
|
|
|
+ if (examRecordForMarkingBeanList != null && examRecordForMarkingBeanList.size() > 0) {
|
|
|
+ List<String> result = duplicateRemoval(examRecordForMarkingBeanList);
|
|
|
+ LOG.info("创建评卷工作评分项,试卷套数:" + result.size());
|
|
|
+ subListDispose(result, workId, batchSize);
|
|
|
+ } else {
|
|
|
+ LOG.info("创建评卷工作评分项,试卷套数:0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getAllBasePaperIdsForAnyTimeMark(Long workId, Long examId) {
|
|
|
+ Set<String> basePaperIds = new HashSet<>();
|
|
|
+ GetExtractConfigBeanReq req = new GetExtractConfigBeanReq();
|
|
|
+ req.setExamId(examId);
|
|
|
+ GetExtractConfigBeanResp res = extractConfigCloudService.getExtractConfigBean(req);
|
|
|
+ if (CollectionUtils.isNotEmpty(res.getData())) {
|
|
|
+ for (ExtractConfigBean ec : res.getData()) {
|
|
|
+ boolean randomPaper = CallType.RANDOM_PAPER.equals(ec.getCallType());
|
|
|
+ if (!randomPaper) {
|
|
|
+ for (ExtractConfigDetailBean ecb : ec.getDetails()) {
|
|
|
+ basePaperIds.add(ecb.getPaperId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FindExamRecordForMarkingInfoReq markingReq = new FindExamRecordForMarkingInfoReq();
|
|
|
+ markingReq.setExamId(examId);
|
|
|
+ markingReq.setBatchNum(workId + "");
|
|
|
+ FindExamRecordForMarkingInfoResp markingResp = examRecordForMarkingCloudService
|
|
|
+ .findExamRecordForMarkingInfo(markingReq);
|
|
|
+ List<ExamRecordForMarkingBean> examRecordForMarkingBeanList = markingResp.getExamRecordForMarkingBeanList();
|
|
|
+ if (examRecordForMarkingBeanList != null && examRecordForMarkingBeanList.size() > 0) {
|
|
|
+ for (ExamRecordForMarkingBean bean : examRecordForMarkingBeanList) {
|
|
|
+ basePaperIds.add(bean.getBasePaperId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new ArrayList<>(basePaperIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> duplicateRemoval(List<ExamRecordForMarkingBean> list) {
|
|
|
+ Set<String> set = new HashSet<String>();
|
|
|
+ for (ExamRecordForMarkingBean bean : list) {
|
|
|
+ set.add(bean.getBasePaperId());
|
|
|
+ }
|
|
|
+ List<String> result = new ArrayList<>(set);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkIsAnyTimeMark(Long examId) {
|
|
|
+ ExamPropertyCacheBean mt = CacheHelper.getExamProperty(examId, ExamProperties.MARKING_TYPE.name());
|
|
|
+ if (mt == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!MarkingType.ALL.name().equals(mt.getValue())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ ExamPropertyCacheBean es = CacheHelper.getExamProperty(examId, ExamProperties.MARKING_WORK_TYPE.name());
|
|
|
+ if (es == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (MarkingWorkType.ANYTIME.name().equals(es.getValue())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // private List<String> duplicateRemoval(List<ExamRecordForMarkingBean>
|
|
|
+ // list) {
|
|
|
+ // Set<String> set = new HashSet<String>();
|
|
|
+ // for (ExamRecordForMarkingBean bean : list) {
|
|
|
+ // set.add(bean.getBasePaperId());
|
|
|
+ // }
|
|
|
+ // List<String> result = new ArrayList<>(set);
|
|
|
+ // return result;
|
|
|
+ // }
|
|
|
+
|
|
|
+ private void subListDispose(List<String> list, Long workId, Long batchSize) throws InterruptedException {
|
|
|
+ if (list.size() <= batchSize) {
|
|
|
+ // 生产需处理的数据
|
|
|
+ offer(new MarkWorkCreateItemsDto(list, workId));
|
|
|
+ } else {
|
|
|
+ int size = list.size();
|
|
|
+ int len = batchSize.intValue();
|
|
|
+ int count = (size + len - 1) / len;
|
|
|
+
|
|
|
+ for (int i = 0; i < count; i++) {
|
|
|
+ List<String> subList = list.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
|
|
|
+ // 生产需处理的数据
|
|
|
+ offer(new MarkWorkCreateItemsDto(subList, workId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|