|
@@ -2,14 +2,19 @@ package com.yaoxiang.diagnosis.service;
|
|
|
|
|
|
import com.yaoxiang.diagnosis.dao.IssueDao;
|
|
|
import com.yaoxiang.diagnosis.entity.Issue;
|
|
|
+import com.yaoxiang.diagnosis.entity.IssueLite;
|
|
|
+import com.yaoxiang.diagnosis.entity.IssueOption;
|
|
|
+import com.yaoxiang.diagnosis.entity.IssuePaper;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class IssueService {
|
|
|
|
|
@@ -20,7 +25,7 @@ public class IssueService {
|
|
|
private IssueOptionService issueOptionService;
|
|
|
|
|
|
@Resource
|
|
|
- private IssueMindService issueMindService;
|
|
|
+ private IssueLiteService issueLiteService;
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean adds(List<Issue> list) {
|
|
@@ -28,7 +33,7 @@ public class IssueService {
|
|
|
for (Issue issue : data) {
|
|
|
issueOptionService.adds(issue.getId(), issue.getOptions());
|
|
|
if (issue.getSection() > 1) {
|
|
|
- issueMindService.adds(issue.getMinds());
|
|
|
+ issueLiteService.adds(issue.getLites());
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
@@ -43,7 +48,7 @@ public class IssueService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 删除模块一
|
|
|
+ * 删除模块一的某个章节
|
|
|
*
|
|
|
* @param subjectId 科目Id
|
|
|
* @param chapterId 章节Id
|
|
@@ -66,13 +71,12 @@ public class IssueService {
|
|
|
*/
|
|
|
private boolean delete(Long subjectId, String grade, int section) {
|
|
|
|
|
|
- List<Issue> list = issueDao.findBySubjectIdAndGrade(subjectId, grade);
|
|
|
+ List<Issue> list = issueDao.findBySubjectIdAndGradeAndSection(subjectId, grade, section);
|
|
|
|
|
|
if (section != 1) {
|
|
|
- issueMindService.delete(subjectId, grade);
|
|
|
- }else {
|
|
|
+ issueLiteService.delete(subjectId, grade, section);
|
|
|
+ } else {
|
|
|
issueOptionService.deleteByIssueIds(list.stream().map(Issue::getId).collect(Collectors.toList()));
|
|
|
- issueDao.deleteAll(list);
|
|
|
}
|
|
|
|
|
|
issueDao.deleteAll(list);
|
|
@@ -80,6 +84,65 @@ public class IssueService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ public List<Issue> listAll(IssuePaper paper) {
|
|
|
+ Long subjectId = paper.getSubjectId();
|
|
|
+ List<Long> chapterIds = Arrays.stream(paper.getChapterIds().split(",")).map(Long::valueOf).collect(Collectors.toList());
|
|
|
+ List<Issue> list1 = listWithOption(subjectId, chapterIds);
|
|
|
+
|
|
|
+ List<Issue> list2 = listWithLite(subjectId, paper.getGrade2(), 2);
|
|
|
+
|
|
|
+ List<Issue> list3 = listWithLite(subjectId, paper.getGrade3(), 3);
|
|
|
+
|
|
|
+ List<Issue> result = new ArrayList<>();
|
|
|
+ result.addAll(list1);
|
|
|
+ result.addAll(list2);
|
|
|
+ result.addAll(list3);
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Issue> listWithOption(Long subjectId, List<Long> chapterIds) {
|
|
|
+ List<Issue> list = list(subjectId, chapterIds);
|
|
|
+ List<IssueOption> options = issueOptionService.findByIssueIds(list.stream().map(Issue::getId).collect(Collectors.toList()));
|
|
|
+ options.sort(Comparator.comparing(IssueOption::getIssueId));
|
|
|
+ Map<Long, List<IssueOption>> group = options.stream().collect(Collectors.groupingBy(IssueOption::getIssueId));
|
|
|
+ for (Issue issue : list) {
|
|
|
+ issue.setOptions(group.getOrDefault(issue.getId(), new ArrayList<>()));
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Issue> listWithLite(Long subjectId, String grade, int section) {
|
|
|
+ List<Issue> list = list(subjectId, grade, section);
|
|
|
+ List<IssueLite> lites2 = issueLiteService.listAll(list.stream().map(Issue::getId).collect(Collectors.toList()));
|
|
|
+ Map<Long, List<IssueLite>> group2 = lites2.stream().collect(Collectors.groupingBy(IssueLite::getIssueId));
|
|
|
+ for (Issue issue : list) {
|
|
|
+ issue.setLites(group2.getOrDefault(issue.getId(), new ArrayList<>()));
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取模块一
|
|
|
+ *
|
|
|
+ * @param subjectId 科目Id
|
|
|
+ * @param chapterIds 章节Id列表
|
|
|
+ * @return 题目
|
|
|
+ */
|
|
|
+ public List<Issue> list(Long subjectId, List<Long> chapterIds) {
|
|
|
+ return issueDao.findBySubjectIdAndChapterIdIn(subjectId, chapterIds);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取模块二三
|
|
|
+ *
|
|
|
+ * @param subjectId 科目Id
|
|
|
+ * @param grade 年级
|
|
|
+ * @param section 模块
|
|
|
+ * @return 题目
|
|
|
+ */
|
|
|
+ public List<Issue> list(Long subjectId, String grade, int section) {
|
|
|
+ return issueDao.findBySubjectIdAndGradeAndSection(subjectId, grade, section);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
}
|