|
@@ -1,5 +1,6 @@
|
|
|
package cn.com.qmth.examcloud.core.questions.service.impl;
|
|
|
|
|
|
+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.base.Constants;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.Model;
|
|
@@ -12,10 +13,13 @@ import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Example;
|
|
|
-import org.springframework.data.domain.ExampleMatcher;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
+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 org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Date;
|
|
@@ -32,6 +36,9 @@ public class CoursePropertyServiceImpl implements CoursePropertyService {
|
|
|
@Autowired
|
|
|
private CoursePropertyRepo coursePropertyRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
@Override
|
|
|
public List<CourseProperty> findAllByOrgId(Long orgId) {
|
|
|
return coursePropertyRepo.findByOrgId(orgId);
|
|
@@ -73,47 +80,57 @@ public class CoursePropertyServiceImpl implements CoursePropertyService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<CourseProperty> findList(CoursePropertyDto dto, Pageable pageable) {
|
|
|
- CourseProperty params = new CourseProperty();
|
|
|
+ public Page<CourseProperty> findList(CoursePropertyDto dto, Pageable pageable, UserDataRule userDataRule) {
|
|
|
+ if (userDataRule.assertEmptyQueryResult()) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+
|
|
|
+ Query query = new Query();
|
|
|
|
|
|
if (dto.getOrgId() != null) {
|
|
|
- params.setOrgId(dto.getOrgId());
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(dto.getOrgId()));
|
|
|
}
|
|
|
|
|
|
if (dto.getCourseId() != null) {
|
|
|
- params.setCourseId(dto.getCourseId());
|
|
|
+ if (!userDataRule.getRefIds().contains(dto.getCourseId())) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
+ query.addCriteria(Criteria.where("courseId").is(dto.getCourseId()));
|
|
|
+ } else {
|
|
|
+ if (userDataRule.assertNeedQueryRefIds()) {
|
|
|
+ query.addCriteria(Criteria.where("courseId").in(userDataRule.getRefIds()));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (dto.getEnable() != null) {
|
|
|
- params.setEnable(dto.getEnable());
|
|
|
+ if (StringUtils.isNotBlank(dto.getName())) {
|
|
|
+ query.addCriteria(Criteria.where("name").regex(dto.getName().trim()));
|
|
|
}
|
|
|
|
|
|
- Example<CourseProperty> query;
|
|
|
- if (!StringUtils.isEmpty(dto.getName())) {
|
|
|
- params.setName(dto.getName());
|
|
|
-
|
|
|
- ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("name", match -> match.contains());
|
|
|
-
|
|
|
- query = Example.of(params, matcher);
|
|
|
- } else {
|
|
|
- query = Example.of(params);
|
|
|
+ if (dto.getEnable() != null) {
|
|
|
+ query.addCriteria(Criteria.where("enable").is(dto.getEnable()));
|
|
|
}
|
|
|
|
|
|
- Page<CourseProperty> page = coursePropertyRepo.findAll(query, pageable);
|
|
|
+ long total = mongoTemplate.count(query, CourseProperty.class);
|
|
|
+ if (total == 0) {
|
|
|
+ return Page.empty();
|
|
|
+ }
|
|
|
|
|
|
- List<CourseProperty> list = page.getContent();
|
|
|
- if (CollectionUtils.isEmpty(list)) {
|
|
|
- return page;
|
|
|
+ query.with(Sort.by(new Sort.Order(Sort.Direction.DESC, "updateTime")));
|
|
|
+ query.skip(pageable.getOffset());
|
|
|
+ query.limit(pageable.getPageSize());
|
|
|
+ List<CourseProperty> courseProperties = mongoTemplate.find(query, CourseProperty.class);
|
|
|
+ if (CollectionUtils.isEmpty(courseProperties)) {
|
|
|
+ return Page.empty();
|
|
|
}
|
|
|
|
|
|
- for (CourseProperty courseProperty : list) {
|
|
|
+ for (CourseProperty courseProperty : courseProperties) {
|
|
|
CourseCacheBean course = CacheHelper.getCourse(courseProperty.getCourseId());
|
|
|
if (course != null) {
|
|
|
courseProperty.setCourseName(course.getName());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return page;
|
|
|
+ return new PageImpl<>(courseProperties, pageable, total);
|
|
|
}
|
|
|
|
|
|
@Override
|