|
@@ -161,38 +161,61 @@ public class PaperServiceImpl implements PaperService {
|
|
|
* 查询所有已导入试卷
|
|
|
*/
|
|
|
public Page<Paper> getImportPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize, UserDataRule userDataRule, boolean skipRule) {
|
|
|
+ // todo userDataRule
|
|
|
+
|
|
|
Query query = new Query();
|
|
|
+
|
|
|
query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
+
|
|
|
query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
+
|
|
|
query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(paperSearchInfo.getCourseNo())) {
|
|
|
query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(paperSearchInfo.getSpecialtyNo())) {
|
|
|
- query.addCriteria(Criteria.where("specialty.code").is(paperSearchInfo.getSpecialtyNo()));
|
|
|
- }
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(paperSearchInfo.getLevel())) {
|
|
|
query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isNoneBlank(paperSearchInfo.getName())) {
|
|
|
String paperName = CommonUtils.escapeExprSpecialWord(paperSearchInfo.getName());
|
|
|
query.addCriteria(Criteria.where("name").regex(".*?\\.*" + paperName + ".*"));
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isNoneBlank(paperSearchInfo.getCreator())) {
|
|
|
String creator = CommonUtils.escapeExprSpecialWord(paperSearchInfo.getCreator());
|
|
|
query.addCriteria(Criteria.where("creator").regex(".*?\\.*" + creator + ".*"));
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isNoneBlank(paperSearchInfo.getLastModifyName())) {
|
|
|
String lastModifyName = CommonUtils.escapeExprSpecialWord(paperSearchInfo.getLastModifyName());
|
|
|
query.addCriteria(Criteria.where("lastModifyName").regex(".*?\\.*" + lastModifyName + ".*"));
|
|
|
}
|
|
|
- long count = this.mongoTemplate.count(query, Paper.class);
|
|
|
- query.with(Sort.by(new Order(Direction.DESC, "createTime")));
|
|
|
- query.limit(pageSize);
|
|
|
- query.skip((curPage - 1L) * pageSize);
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(paperSearchInfo.getSpecialtyNo())) {
|
|
|
+ query.addCriteria(Criteria.where("specialty.code").is(paperSearchInfo.getSpecialtyNo()));
|
|
|
+ }
|
|
|
+
|
|
|
+ long total = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ if (total == 0) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ PageRequest pageable = PageRequest.of(curPage - 1, pageSize);
|
|
|
+ query.with(Sort.by(Sort.Order.desc("createTime")));
|
|
|
+ query.skip(pageable.getOffset());
|
|
|
+ query.limit(pageable.getPageSize());
|
|
|
+
|
|
|
List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
- setPaperQuesCountAndScore(paperList);
|
|
|
- return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), count);
|
|
|
+ if (CollectionUtils.isEmpty(paperList)) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ setPaperQuesCountAndScore(paperList);// todo 待优化
|
|
|
+
|
|
|
+ return new PageImpl<>(paperList, pageable, total);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -216,11 +239,15 @@ public class PaperServiceImpl implements PaperService {
|
|
|
if (StringUtil.isNotBlank(paperSearchInfo.getCourseNo())) {
|
|
|
query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
}
|
|
|
- long totalNumber = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ long total = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ if (total == 0) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
query.limit(pageSize);
|
|
|
query.skip((curPage - 1L) * pageSize);
|
|
|
List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
- return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), totalNumber);
|
|
|
+ return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), total);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -342,13 +369,18 @@ public class PaperServiceImpl implements PaperService {
|
|
|
String lastModifyName = CommonUtils.escapeExprSpecialWord(paperSearchInfo.getLastModifyName());
|
|
|
query.addCriteria(Criteria.where("lastModifyName").regex(".*?\\.*" + lastModifyName + ".*"));
|
|
|
}
|
|
|
- long count = this.mongoTemplate.count(query, Paper.class);
|
|
|
+
|
|
|
+ long total = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ if (total == 0) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
query.with(Sort.by(new Order(Direction.DESC, "createTime")));
|
|
|
query.limit(pageSize);
|
|
|
query.skip((curPage - 1L) * pageSize);
|
|
|
List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
setPaperQuesCountAndScore(paperList);
|
|
|
- return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), count);
|
|
|
+ return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), total);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -376,13 +408,18 @@ public class PaperServiceImpl implements PaperService {
|
|
|
String lastModifyName = CommonUtils.escapeExprSpecialWord(paperSearchInfo.getLastModifyName());
|
|
|
query.addCriteria(Criteria.where("lastModifyName").regex(".*?\\.*" + lastModifyName + ".*"));
|
|
|
}
|
|
|
- long count = this.mongoTemplate.count(query, Paper.class);
|
|
|
+
|
|
|
+ long total = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ if (total == 0) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
query.with(Sort.by(new Order(Direction.DESC, "createTime")));
|
|
|
query.limit(pageSize);
|
|
|
query.skip((curPage - 1L) * pageSize);
|
|
|
List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
setPaperQuesCountAndScore(paperList);
|
|
|
- return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), count);
|
|
|
+ return new PageImpl<Paper>(paperList, PageRequest.of(curPage - 1, pageSize), total);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1102,7 +1139,12 @@ public class PaperServiceImpl implements PaperService {
|
|
|
query.addCriteria(Criteria.where("paperType").is(paperType));
|
|
|
query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
query.addCriteria(Criteria.where("id").nin(selectedIds));
|
|
|
+
|
|
|
long total = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ if (total == 0) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
query.with(Sort.by(new Order(Direction.DESC, "createTime")));
|
|
|
query.limit(pageSize);
|
|
|
query.skip((curPage - 1L) * pageSize);
|