|
@@ -0,0 +1,101 @@
|
|
|
|
+package cn.com.qmth.examcloud.core.questions.service.impl;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.UserCloudService;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.GetUserReq;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.GetUserResp;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.Model;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.bean.randompaper.RandomPaperListVo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.bean.randompaper.RandomPaperQuery;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.PaperStructRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperStruct;
|
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
|
|
|
|
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
|
|
+
|
|
|
|
+public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PaperStructRepo paperStructRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserCloudService userCloudService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Page<RandomPaperListVo> getPage(RandomPaperQuery req) {
|
|
|
|
+ if (req.getUd().assertEmptyQueryResult()) {
|
|
|
|
+ return Page.empty();
|
|
|
|
+ }
|
|
|
|
+ Query query = new Query();
|
|
|
|
+
|
|
|
|
+ query.addCriteria(Criteria.where("rootOrgId").is(req.getRootOrgId()));
|
|
|
|
+
|
|
|
|
+ if (req.getUd().assertNeedQueryRefIds()) {
|
|
|
|
+ query.addCriteria(Criteria.where("courseId").in(req.getUd().getRefIds()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
|
+
|
|
|
|
+ if (req.getEnable() != null) {
|
|
|
|
+ query.addCriteria(Criteria.where("enable").is(req.getEnable()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (req.getCourseId() != null) {
|
|
|
|
+ query.addCriteria(Criteria.where("courseId").is(req.getCourseId()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNoneBlank(req.getName())) {
|
|
|
|
+ String paperName = CommonUtils.escapeExprSpecialWord(req.getName());
|
|
|
|
+ query.addCriteria(Criteria.where("name").regex(".*?\\.*" + paperName + ".*"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ long total = this.mongoTemplate.count(query, Paper.class);
|
|
|
|
+ if (total == 0) {
|
|
|
|
+ return Page.empty();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PageRequest pageable = PageRequest.of(req.getPageNumber() - 1, req.getPageSize());
|
|
|
|
+ query.with(Sort.by(Sort.Order.desc("creationDate")));
|
|
|
|
+ query.skip(pageable.getOffset());
|
|
|
|
+ query.limit(pageable.getPageSize());
|
|
|
|
+
|
|
|
|
+ List<RandomPaperListVo> paperList = this.mongoTemplate.find(query, RandomPaperListVo.class, "randomPaper");
|
|
|
|
+ if (CollectionUtils.isEmpty(paperList)) {
|
|
|
|
+ return Page.empty();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (RandomPaperListVo vo : paperList) {
|
|
|
|
+ CourseCacheBean course = CacheHelper.getCourse(req.getRootOrgId());
|
|
|
|
+ vo.setCourseCode(course.getCode());
|
|
|
|
+ vo.setCourseName(course.getName());
|
|
|
|
+ vo.setPaperStructTypeStr(vo.getPaperStructType().getName());
|
|
|
|
+ PaperStruct paperStruct = Model.of(paperStructRepo.findById(vo.getPaperStructId()));
|
|
|
|
+ vo.setPaperStructName(paperStruct.getName());
|
|
|
|
+ vo.setEnableStr(vo.getEnable()?"启用":"禁用");
|
|
|
|
+ GetUserReq ureq=new GetUserReq();
|
|
|
|
+ ureq.setUserId(vo.getUpdateBy());
|
|
|
|
+ GetUserResp ures=userCloudService.getUser(ureq);
|
|
|
|
+ vo.setUpdateByName(ures.getUserBean().getDisplayName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new PageImpl<>(paperList, pageable, total);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|