|
@@ -2,6 +2,11 @@ package com.qmth.cqb.paper.service;
|
|
|
|
|
|
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
import com.qmth.cqb.paper.dao.PaperRepo;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -11,6 +16,7 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import com.qmth.cqb.paper.model.Paper;
|
|
|
import com.qmth.cqb.paper.model.ImportPaperSearchCondition;
|
|
@@ -31,7 +37,10 @@ public class ImportPaperService {
|
|
|
@Autowired
|
|
|
PaperRepo paperRepo;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ PaperDetailService paperDetailService;
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 查询所有已导入试卷
|
|
|
* @param searchCondition
|
|
@@ -42,12 +51,35 @@ public class ImportPaperService {
|
|
|
public PagingAndSortingResponse<Paper> findAll(ImportPaperSearchCondition searchCondition,int curPage,int pageSize){
|
|
|
Paper importPaper = new Paper();
|
|
|
BeanUtils.copyProperties(searchCondition,importPaper);
|
|
|
- ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("paperName", startsWith());
|
|
|
- Page<Paper> importPaperList = paperRepo.findAll(Example.of(importPaper,matcher),new PageRequest(curPage-1,pageSize));
|
|
|
+ if(searchCondition.getCourseId() != null){
|
|
|
+ Map<String,String> param = new HashMap<String,String>();
|
|
|
+ param.put("courseId", searchCondition.getCourseId());
|
|
|
+ importPaper.setParams(param);
|
|
|
+ }
|
|
|
+ Page<Paper> importPaperList = paperRepo.findAll(Example.of(importPaper),new PageRequest(curPage-1,pageSize));
|
|
|
return new PagingAndSortingResponse<Paper>(importPaperList.getNumber(),importPaperList.getSize(),
|
|
|
importPaperList.getTotalPages(),importPaperList.getTotalElements(),importPaperList.getContent());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询所有已导入试卷
|
|
|
+ * @param searchCondition
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<Paper> getImportPapersByCourseId(String courseId,int curPage,int pageSize){
|
|
|
+ Paper importPaper = new Paper();
|
|
|
+ if(!StringUtils.isEmpty(courseId)){
|
|
|
+ Map<String,String> param = new HashMap<String,String>();
|
|
|
+ param.put("courseId", courseId);
|
|
|
+ importPaper.setParams(param);
|
|
|
+ }
|
|
|
+ Page<Paper> importPaperList = paperRepo.findAll(Example.of(importPaper),new PageRequest(curPage-1,pageSize));
|
|
|
+ return importPaperList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 按ID查询导入试卷
|
|
|
* @param paperId
|
|
@@ -68,12 +100,23 @@ public class ImportPaperService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除导入试卷
|
|
|
+ * 批量删除导入试卷
|
|
|
* @param paperId
|
|
|
* @return
|
|
|
*/
|
|
|
- public void deleteImportPaper(String paperId){
|
|
|
- paperRepo.delete(paperId);
|
|
|
+ public void deleteImportPaper(String[] paperIds){
|
|
|
+ //需要同时删除paperDetail,paperdetailUnit
|
|
|
+ Iterable<Paper> papers = new ArrayList<Paper>();
|
|
|
+ List<String> ids = new ArrayList<String>();
|
|
|
+ for(int i=0;i<paperIds.length;i++){
|
|
|
+ ids.add(paperIds[i]);
|
|
|
+ }
|
|
|
+ papers = paperRepo.findAll(ids);
|
|
|
+ for(Paper paper:papers){
|
|
|
+ paperDetailService.deletePaperDetailsByPaper(paper);
|
|
|
+ }
|
|
|
+ paperRepo.delete(papers);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|