|
@@ -1,176 +1,206 @@
|
|
|
-package com.qmth.cqb.paper.service;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
-import com.qmth.cqb.paper.dao.QuesTypeNameRepo;
|
|
|
-import com.qmth.cqb.paper.dto.QuesNameDto;
|
|
|
-import com.qmth.cqb.paper.model.*;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.*;
|
|
|
-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 com.qmth.cqb.paper.dao.PaperStructRepo;
|
|
|
-import com.qmth.cqb.paper.dto.PaperDetailUnitStructDto;
|
|
|
-import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
-import com.qmth.cqb.utils.CommonUtils;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
-
|
|
|
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
|
|
|
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by songyue on 16/12/28.
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class PaperStructService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PaperStructRepo paperStructRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- QuesTypeNameRepo quesTypeNameRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MongoTemplate mongoTemplate;
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取所有试卷结构(分页)
|
|
|
- *
|
|
|
- * @param searchInfo
|
|
|
- * @param curPage
|
|
|
- * @param pageSize
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo, int curPage, int pageSize) {
|
|
|
- formatSearchInfo(searchInfo);
|
|
|
- PaperStruct paperStruct = BeanCopierUtil.copyProperties(searchInfo, PaperStruct.class);
|
|
|
- formatPaperStruct(paperStruct);
|
|
|
- ExampleMatcher matcher = ExampleMatcher.matching()
|
|
|
- .withMatcher("name",contains())
|
|
|
- .withMatcher("creator",contains())
|
|
|
- .withMatcher("orgId",exact())
|
|
|
- .withIgnoreNullValues();
|
|
|
- return paperStructRepo.findAll(Example.of(paperStruct, matcher), new PageRequest(curPage - 1, pageSize));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取所有试卷结构(分页)
|
|
|
- * @param searchInfo
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo) {
|
|
|
- Query query = new Query();
|
|
|
- if(StringUtils.isNotBlank(searchInfo.getCourseNo())){
|
|
|
- query.addCriteria(Criteria.where("courseNo")
|
|
|
- .in("",searchInfo.getCourseNo()));
|
|
|
- }
|
|
|
- query.addCriteria(Criteria.where("orgId").is(searchInfo.getOrgId()));
|
|
|
- query.with(new Sort(new Sort.Order(Sort.Direction.DESC,"createTime")));
|
|
|
- List<PaperStruct> paperList = this.mongoTemplate.find(query, PaperStruct.class);
|
|
|
- return paperList;
|
|
|
- }
|
|
|
-
|
|
|
- public void formatSearchInfo(PaperStructSearchInfo searchInfo) {
|
|
|
- if (StringUtils.isEmpty(searchInfo.getName())) {
|
|
|
- searchInfo.setName(null);
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(searchInfo.getCreator())) {
|
|
|
- searchInfo.setCreator(null);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void formatPaperStruct(PaperStruct paperStruct) {
|
|
|
- paperStruct.setCreateTime(null);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存试卷结构
|
|
|
- *
|
|
|
- * @param paperStruct
|
|
|
- * @return
|
|
|
- */
|
|
|
- public PaperStruct save(PaperStruct paperStruct, AccessUser user) {
|
|
|
- if (StringUtils.isNotBlank(paperStruct.getId())) {
|
|
|
- PaperStruct oldPaperStruct = paperStructRepo.findOne(paperStruct.getId());
|
|
|
- PaperStruct rps = null;
|
|
|
- if (oldPaperStruct != null && !paperStruct.getName().equals(oldPaperStruct.getName())) {// 那么就是更新操作
|
|
|
- rps = this.checkNameUnique(paperStruct.getName(), user.getRootOrgId().toString());
|
|
|
- }
|
|
|
- if (rps != null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
- List<PaperDetailStruct> paperDetailStructs = paperStruct.getPaperDetailStructs();
|
|
|
- int number = 0;
|
|
|
- for (PaperDetailStruct paperDetailStruct : paperDetailStructs) {
|
|
|
- List oldStructs = paperDetailStruct.getPaperDetailUnitStructs();
|
|
|
- if (oldStructs != null && oldStructs.size() > 0) {
|
|
|
- oldStructs.clear();
|
|
|
- }
|
|
|
- List<PaperDetailUnitStruct> unitStructs = new ArrayList<PaperDetailUnitStruct>();
|
|
|
-
|
|
|
- for (PaperDetailUnitStructDto unitStructDto : paperDetailStruct.getUnitStructs()) {
|
|
|
- for (int i = 0; i < unitStructDto.getCount(); i++) {
|
|
|
- ++number;
|
|
|
- PaperDetailUnitStruct unitStruct = new PaperDetailUnitStruct();
|
|
|
- unitStruct.setScore(unitStructDto.getScore());
|
|
|
- unitStruct.setId(String.valueOf(number));
|
|
|
- unitStruct.setNumber(number);
|
|
|
- unitStruct.setQuestionType(unitStructDto.getQuestionType());
|
|
|
- unitStruct.setQuesNames(unitStructDto.getQuesNames());
|
|
|
- unitStructs.add(unitStruct);
|
|
|
- }
|
|
|
- }
|
|
|
- paperDetailStruct.setPaperDetailUnitStructs(unitStructs);
|
|
|
- }
|
|
|
- paperStruct.setDetailCount(paperDetailStructs.size());
|
|
|
- paperStruct.setDetailUnitCount(paperDetailStructs.stream().mapToInt(PaperDetailStruct::getDetailCount).sum());
|
|
|
- paperStruct.setOrgId(user.getRootOrgId().toString());
|
|
|
- paperStruct.setCreator(user.getName());
|
|
|
- paperStruct.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
- return paperStructRepo.save(paperStruct);
|
|
|
- }
|
|
|
-
|
|
|
- public PaperStruct checkNameUnique(String name, String orgId) {
|
|
|
- PaperStruct paperTemp = new PaperStruct();
|
|
|
- paperTemp.setCreateTime(null);
|
|
|
- paperTemp.setName(name.trim());
|
|
|
- paperTemp.setOrgId(orgId);
|
|
|
- PaperStruct paperStruct = paperStructRepo.findOne(Example.of(paperTemp));
|
|
|
- return paperStruct;
|
|
|
- }
|
|
|
-
|
|
|
- public List<QuesNameDto> getQuesNameList(String orgId,
|
|
|
- String courseNo,
|
|
|
- QuesStructType quesType) {
|
|
|
- List<QuesNameDto> quesNameList = new ArrayList<>();
|
|
|
- List<QuesTypeName> quesTypeNames = new ArrayList<>();
|
|
|
- if (StringUtils.isEmpty(courseNo)) {
|
|
|
- quesTypeNames = quesTypeNameRepo.findQuesName(orgId, quesType);
|
|
|
- } else {
|
|
|
- quesTypeNames = quesTypeNameRepo.findQuesName(orgId, courseNo, quesType);
|
|
|
- }
|
|
|
-
|
|
|
- quesNameList = quesTypeNames.stream()
|
|
|
- .map(QuesTypeName::getQuesNames)
|
|
|
- .flatMap(Collection::stream)
|
|
|
- .distinct()
|
|
|
- .map(this::getQuesName)
|
|
|
- .collect(Collectors.toList());
|
|
|
- return quesNameList;
|
|
|
- }
|
|
|
-
|
|
|
- private QuesNameDto getQuesName(String name){
|
|
|
- return new QuesNameDto(name,name);
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+package com.qmth.cqb.paper.service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
+
|
|
|
+import com.qmth.cqb.paper.dao.QuesTypeNameRepo;
|
|
|
+import com.qmth.cqb.paper.dto.QuesNameDto;
|
|
|
+import com.qmth.cqb.paper.model.*;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.*;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.domain.Sort.Order;
|
|
|
+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 com.qmth.cqb.paper.dao.PaperStructRepo;
|
|
|
+import com.qmth.cqb.paper.dto.PaperDetailUnitStructDto;
|
|
|
+import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
+import com.qmth.cqb.utils.CommonUtils;
|
|
|
+import com.qmth.cqb.utils.enums.PaperType;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
|
|
|
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by songyue on 16/12/28.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PaperStructService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PaperStructRepo paperStructRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ QuesTypeNameRepo quesTypeNameRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有试卷结构(分页)
|
|
|
+ *
|
|
|
+ * @param searchInfo
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo, int curPage, int pageSize) {
|
|
|
+ /*formatSearchInfo(searchInfo);
|
|
|
+ PaperStruct paperStruct = BeanCopierUtil.copyProperties(searchInfo, PaperStruct.class);
|
|
|
+ formatPaperStruct(paperStruct);
|
|
|
+ ExampleMatcher matcher = ExampleMatcher.matching()
|
|
|
+ .withMatcher("name",contains())
|
|
|
+ .withMatcher("creator",contains())
|
|
|
+ .withMatcher("orgId",exact())
|
|
|
+ .withIgnoreNullValues();
|
|
|
+ return paperStructRepo.findAll(Example.of(paperStruct, matcher), new PageRequest(curPage - 1, pageSize));*/
|
|
|
+
|
|
|
+ //create by weiwenhai
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(searchInfo.getOrgId()));
|
|
|
+ if(StringUtils.isNotBlank(searchInfo.getName())){
|
|
|
+ query.addCriteria(Criteria.where("name").regex(".*?\\" +searchInfo.getName() + ".*"));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(searchInfo.getCreator())){
|
|
|
+ query.addCriteria(Criteria.where("creator").regex(".*?\\" +searchInfo.getCreator() + ".*"));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(searchInfo.getCourseNo())){
|
|
|
+ if(!searchInfo.getCourseNo().equals("ALL")){
|
|
|
+ query.addCriteria(Criteria.where("courseNo").is(searchInfo.getCourseNo()));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ query.addCriteria(Criteria.where("courseNo").is(""));
|
|
|
+ }
|
|
|
+ long count = this.mongoTemplate.count(query, PaperStruct.class);
|
|
|
+ query.with(new Sort(new Order(Direction.DESC,"createTime")));
|
|
|
+ query.limit(pageSize);
|
|
|
+ query.skip((curPage - 1) * pageSize);
|
|
|
+ List<PaperStruct> paperList = this.mongoTemplate.find(query, PaperStruct.class);
|
|
|
+ return new PageImpl<PaperStruct>(paperList, new PageRequest(curPage - 1, pageSize), count);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有试卷结构(分页)
|
|
|
+ * @param searchInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<PaperStruct> getPaperStructs(PaperStructSearchInfo searchInfo) {
|
|
|
+ Query query = new Query();
|
|
|
+ if(StringUtils.isNotBlank(searchInfo.getCourseNo())){
|
|
|
+ query.addCriteria(Criteria.where("courseNo")
|
|
|
+ .in("",searchInfo.getCourseNo()));
|
|
|
+ }
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(searchInfo.getOrgId()));
|
|
|
+ query.with(new Sort(new Sort.Order(Sort.Direction.DESC,"createTime")));
|
|
|
+ List<PaperStruct> paperList = this.mongoTemplate.find(query, PaperStruct.class);
|
|
|
+ return paperList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void formatSearchInfo(PaperStructSearchInfo searchInfo) {
|
|
|
+ if (StringUtils.isEmpty(searchInfo.getName())) {
|
|
|
+ searchInfo.setName(null);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(searchInfo.getCreator())) {
|
|
|
+ searchInfo.setCreator(null);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(searchInfo.getCourseNo())) {
|
|
|
+ searchInfo.setCourseNo(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void formatPaperStruct(PaperStruct paperStruct) {
|
|
|
+ paperStruct.setCreateTime(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存试卷结构
|
|
|
+ *
|
|
|
+ * @param paperStruct
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PaperStruct save(PaperStruct paperStruct, AccessUser user) {
|
|
|
+ if (StringUtils.isNotBlank(paperStruct.getId())) {
|
|
|
+ PaperStruct oldPaperStruct = paperStructRepo.findOne(paperStruct.getId());
|
|
|
+ PaperStruct rps = null;
|
|
|
+ if (oldPaperStruct != null && !paperStruct.getName().equals(oldPaperStruct.getName())) {// 那么就是更新操作
|
|
|
+ rps = this.checkNameUnique(paperStruct.getName(), user.getRootOrgId().toString());
|
|
|
+ }
|
|
|
+ if (rps != null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PaperDetailStruct> paperDetailStructs = paperStruct.getPaperDetailStructs();
|
|
|
+ int number = 0;
|
|
|
+ for (PaperDetailStruct paperDetailStruct : paperDetailStructs) {
|
|
|
+ List oldStructs = paperDetailStruct.getPaperDetailUnitStructs();
|
|
|
+ if (oldStructs != null && oldStructs.size() > 0) {
|
|
|
+ oldStructs.clear();
|
|
|
+ }
|
|
|
+ List<PaperDetailUnitStruct> unitStructs = new ArrayList<PaperDetailUnitStruct>();
|
|
|
+
|
|
|
+ for (PaperDetailUnitStructDto unitStructDto : paperDetailStruct.getUnitStructs()) {
|
|
|
+ for (int i = 0; i < unitStructDto.getCount(); i++) {
|
|
|
+ ++number;
|
|
|
+ PaperDetailUnitStruct unitStruct = new PaperDetailUnitStruct();
|
|
|
+ unitStruct.setScore(unitStructDto.getScore());
|
|
|
+ unitStruct.setId(String.valueOf(number));
|
|
|
+ unitStruct.setNumber(number);
|
|
|
+ unitStruct.setQuestionType(unitStructDto.getQuestionType());
|
|
|
+ unitStruct.setQuesNames(unitStructDto.getQuesNames());
|
|
|
+ unitStructs.add(unitStruct);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ paperDetailStruct.setPaperDetailUnitStructs(unitStructs);
|
|
|
+ }
|
|
|
+ paperStruct.setDetailCount(paperDetailStructs.size());
|
|
|
+ paperStruct.setDetailUnitCount(paperDetailStructs.stream().mapToInt(PaperDetailStruct::getDetailCount).sum());
|
|
|
+ paperStruct.setOrgId(user.getRootOrgId().toString());
|
|
|
+ paperStruct.setCreator(user.getName());
|
|
|
+ paperStruct.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
+ return paperStructRepo.save(paperStruct);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PaperStruct checkNameUnique(String name, String orgId) {
|
|
|
+ PaperStruct paperTemp = new PaperStruct();
|
|
|
+ paperTemp.setCreateTime(null);
|
|
|
+ paperTemp.setName(name.trim());
|
|
|
+ paperTemp.setOrgId(orgId);
|
|
|
+ PaperStruct paperStruct = paperStructRepo.findOne(Example.of(paperTemp));
|
|
|
+ return paperStruct;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<QuesNameDto> getQuesNameList(String orgId,
|
|
|
+ String courseNo,
|
|
|
+ QuesStructType quesType) {
|
|
|
+ List<QuesNameDto> quesNameList = new ArrayList<>();
|
|
|
+ List<QuesTypeName> quesTypeNames = new ArrayList<>();
|
|
|
+ if (StringUtils.isEmpty(courseNo)) {
|
|
|
+ quesTypeNames = quesTypeNameRepo.findQuesName(orgId, quesType);
|
|
|
+ } else {
|
|
|
+ quesTypeNames = quesTypeNameRepo.findQuesName(orgId, courseNo, quesType);
|
|
|
+ }
|
|
|
+
|
|
|
+ quesNameList = quesTypeNames.stream()
|
|
|
+ .map(QuesTypeName::getQuesNames)
|
|
|
+ .flatMap(Collection::stream)
|
|
|
+ .distinct()
|
|
|
+ .map(this::getQuesName)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return quesNameList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private QuesNameDto getQuesName(String name){
|
|
|
+ return new QuesNameDto(name,name);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|