|
@@ -1,6 +1,7 @@
|
|
|
package cn.com.qmth.examcloud.core.questions.service;
|
|
|
|
|
|
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.core.basic.api.CourseCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetCourseReq;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetCourseResp;
|
|
@@ -14,6 +15,7 @@ import cn.com.qmth.examcloud.core.questions.dao.entity.*;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.dto.CoursePropertyNumberDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PaperDetailUnitStructDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.QuesNameDto;
|
|
|
+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;
|
|
@@ -57,25 +59,23 @@ public class PaperStructService {
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
- public Page<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo, int curPage, int pageSize) {
|
|
|
+ public Page<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo, int curPage, int pageSize, UserDataRule userDataRule) {
|
|
|
+ // if (userDataRule.assertEmptyQueryResult()) {
|
|
|
+ // return Page.empty();
|
|
|
+ // }
|
|
|
+
|
|
|
Query query = new Query();
|
|
|
query.addCriteria(Criteria.where("orgId").is(searchInfo.getOrgId()));
|
|
|
query.addCriteria(Criteria.where("type").is(searchInfo.getType()));
|
|
|
- if (StringUtils.isNotBlank(searchInfo.getName())) {
|
|
|
- String paperStructName = CommonUtils.escapeExprSpecialWord(searchInfo.getName());
|
|
|
- query.addCriteria(Criteria.where("name").regex(".*?" + paperStructName + ".*"));
|
|
|
- }
|
|
|
- if (StringUtils.isNotBlank(searchInfo.getCreator())) {
|
|
|
- String userName = CommonUtils.escapeExprSpecialWord(searchInfo.getCreator());
|
|
|
- query.addCriteria(Criteria.where("creator").regex(".*?" + userName + ".*"));
|
|
|
- }
|
|
|
- //判断试卷结构
|
|
|
- if (searchInfo.getType().equals("EXACT")) {
|
|
|
+
|
|
|
+ // 判断试卷结构
|
|
|
+ if (PaperStructType.EXACT.getName().equals(searchInfo.getType())) {
|
|
|
if (StringUtils.isNotBlank(searchInfo.getCourseNo())) {
|
|
|
- if (!searchInfo.getCourseNo().equals("ALL")) {
|
|
|
+ if (!"ALL".equals(searchInfo.getCourseNo())) {
|
|
|
query.addCriteria(Criteria.where("courseNo").is(searchInfo.getCourseNo()));
|
|
|
}
|
|
|
} else {
|
|
|
+ // “公用”情况
|
|
|
query.addCriteria(Criteria.where("courseNo").is(""));
|
|
|
}
|
|
|
} else {
|
|
@@ -84,27 +84,44 @@ public class PaperStructService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- long count = this.mongoTemplate.count(query, PaperStruct.class);
|
|
|
+ if (StringUtils.isNotBlank(searchInfo.getName())) {
|
|
|
+ String paperStructName = CommonUtils.escapeExprSpecialWord(searchInfo.getName());
|
|
|
+ query.addCriteria(Criteria.where("name").regex(".*?" + paperStructName + ".*"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(searchInfo.getCreator())) {
|
|
|
+ String userName = CommonUtils.escapeExprSpecialWord(searchInfo.getCreator());
|
|
|
+ query.addCriteria(Criteria.where("creator").regex(".*?" + userName + ".*"));
|
|
|
+ }
|
|
|
+
|
|
|
+ long total = this.mongoTemplate.count(query, PaperStruct.class);
|
|
|
+ if (total == 0) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ PageRequest pageable = PageRequest.of(curPage - 1, pageSize);
|
|
|
query.with(Sort.by(Sort.Order.desc("createTime")));
|
|
|
- query.limit(pageSize);
|
|
|
- query.skip((curPage - 1L) * pageSize);
|
|
|
+ query.skip(pageable.getOffset());
|
|
|
+ query.limit(pageable.getPageSize());
|
|
|
|
|
|
- List<PaperStruct> paperList = this.mongoTemplate.find(query, PaperStruct.class);
|
|
|
- //远程调用rmi,查询课程名称
|
|
|
- if (paperList != null && paperList.size() > 0) {
|
|
|
- for (PaperStruct paperStruct : paperList) {
|
|
|
- if (StringUtils.isBlank(paperStruct.getCourseNo())) {
|
|
|
- paperStruct.setCourseName("公用");
|
|
|
- } else {
|
|
|
- GetCourseReq req = new GetCourseReq();
|
|
|
- req.setRootOrgId(Long.valueOf(paperStruct.getOrgId()));
|
|
|
- req.setCode(paperStruct.getCourseNo());
|
|
|
- GetCourseResp resp = courseCloudService.getCourse(req);
|
|
|
- paperStruct.setCourseName(resp.getCourseBean().getName());
|
|
|
- }
|
|
|
+ List<PaperStruct> paperStructs = this.mongoTemplate.find(query, PaperStruct.class);
|
|
|
+ if (CollectionUtils.isEmpty(paperStructs)) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (PaperStruct paperStruct : paperStructs) {
|
|
|
+ if (StringUtils.isBlank(paperStruct.getCourseNo())) {
|
|
|
+ paperStruct.setCourseName("公用");
|
|
|
+ } else {
|
|
|
+ GetCourseReq req = new GetCourseReq();
|
|
|
+ req.setRootOrgId(Long.valueOf(paperStruct.getOrgId()));
|
|
|
+ req.setCode(paperStruct.getCourseNo());
|
|
|
+ GetCourseResp resp = courseCloudService.getCourse(req);
|
|
|
+ paperStruct.setCourseName(resp.getCourseBean().getName());
|
|
|
}
|
|
|
}
|
|
|
- return new PageImpl<PaperStruct>(paperList, PageRequest.of(curPage - 1, pageSize), count);
|
|
|
+
|
|
|
+ return new PageImpl<>(paperStructs, pageable, total);
|
|
|
}
|
|
|
|
|
|
/**
|