xiatian 2 年 前
コミット
53a6d64271

+ 17 - 1
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/controller/RandomPaperController.java

@@ -12,12 +12,15 @@ import cn.com.qmth.examcloud.api.commons.enums.DataRuleType;
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
 import cn.com.qmth.examcloud.api.commons.security.bean.UserDataRule;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.core.questions.api.request.GetRandomPaperReq;
+import cn.com.qmth.examcloud.core.questions.api.response.GetRandomPaperResp;
 import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperQuestionViewQuery;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperDomain;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperListVo;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperQuery;
 import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructInfo;
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultPaper;
 import cn.com.qmth.examcloud.web.security.DataRule;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.Api;
@@ -78,5 +81,18 @@ public class RandomPaperController extends ControllerSupport {
 		return randomPaperService.saveRandomPaper(domain);
 	}
 	
-	
+	@ApiOperation(value = "获取随机试卷")
+	@PostMapping("create")
+	public GetRandomPaperResp getRandomPaper(GetRandomPaperReq req) {
+    	if (StringUtils.isBlank(req.getRandomPaperId())) {
+            throw new StatusException("RandomPaperId is null");
+        }
+    	if (req.getPlayTime()==null) {
+            throw new StatusException("PlayTime is null");
+        }
+    	GetRandomPaperResp res=new GetRandomPaperResp();
+    	DefaultPaper defaultPaper=randomPaperService.getRandomPaper(req.getRandomPaperId(),req.getPlayTime());
+    	res.setDefaultPaper(defaultPaper);
+		return res;
+	}
 }

+ 20 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/RandomPaperServiceImpl.java

@@ -14,6 +14,8 @@ import javax.annotation.Resource;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.bson.types.ObjectId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
@@ -82,6 +84,7 @@ import cn.com.qmth.examcloud.web.redis.RedisClient;
 
 @Service
 public class RandomPaperServiceImpl implements RandomPaperService {
+	private static final Logger log = LoggerFactory.getLogger(RandomPaperService.class);
 	private static int cacheTimeOut = 2 * 60 * 60;
 	@Autowired
 	private MongoTemplate mongoTemplate;
@@ -906,8 +909,14 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 
 	@Override
 	public DefaultPaper getRandomPaper(String randomPaperId, Integer playTime) {
+		log.warn("开始抽卷");
+		long d1=System.currentTimeMillis();
 		RandomPaperCache rp = getByCache(randomPaperId);
+		long d2=System.currentTimeMillis();
+		log.warn("获取抽卷模板耗时(ms):"+(d2-d1));
 		PaperStruct ps = paperStructService.getByCache(rp.getPaperStructId());
+		long d3=System.currentTimeMillis();
+		log.warn("获取组卷结构耗时(ms):"+(d3-d2));
 		CreateDefaultPaperParam param = new CreateDefaultPaperParam();
 		param.setFullyObjective(true);
 		param.setRp(rp);
@@ -920,6 +929,7 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 			if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
 				int detailNumber = 0;
 				for (PaperDetailStruct ds : ps.getPaperDetailStructs()) {
+					long f1=System.currentTimeMillis();
 					DefaultQuestionGroup detail = new DefaultQuestionGroup();
 					details.add(detail);
 					detail.setGroupName(ds.getName());
@@ -935,12 +945,17 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 							createUnitByBlueProp(param);
 						}
 					}
+					long f2=System.currentTimeMillis();
+					log.warn("蓝图抽卷一个大题耗时(ms):"+(f2-f1));
 				}
 			}
+			long d4=System.currentTimeMillis();
+			log.warn("蓝图抽卷耗时(ms):"+(d4-d3));
 		} else if (PaperStructType.EXACT.equals(ps.getPaperStrucType())) {
 			if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
 				int detailNumber = 0;
 				for (PaperDetailStruct ds : ps.getPaperDetailStructs()) {
+					long f1=System.currentTimeMillis();
 					DefaultQuestionGroup detail = new DefaultQuestionGroup();
 					details.add(detail);
 					detail.setGroupName(ds.getName());
@@ -957,10 +972,15 @@ public class RandomPaperServiceImpl implements RandomPaperService {
 						param.setUs(us);
 						createUnitByExact(param);
 					}
+					long f2=System.currentTimeMillis();
+					log.warn("精确抽卷一个大题耗时(ms):"+(f2-f1));
 				}
 			}
+			long d4=System.currentTimeMillis();
+			log.warn("精确抽卷耗时(ms):"+(d4-d3));
 		}
 		paper.setFullyObjective(param.getFullyObjective());
+		log.warn("结束抽卷");
 		return paper;
 	}