Browse Source

修改组合卷返回给前端的数据格式

Feick 3 years ago
parent
commit
4d9164a0b5

+ 17 - 1
src/main/java/com/yaoxiang/diagnosis/entity/Issue.java

@@ -1,5 +1,6 @@
 package com.yaoxiang.diagnosis.entity;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.yaoxiang.diagnosis.issue.BaseIssue;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -44,8 +45,10 @@ public class Issue extends BaseIssue {
     @ApiModelProperty("题目所属模块 1 2 3")
     private Integer section;
 
+    @JsonIgnore
     private String answer;
 
+    @JsonIgnore
     private Integer correctNum;
 
     @CreationTimestamp
@@ -57,13 +60,18 @@ public class Issue extends BaseIssue {
     private Date updatetime;
 
     @Transient
-    @ApiModelProperty("题目选项,模块一二使用,模块三忽略")
+    @ApiModelProperty("题目选项")
     private List<IssueOption> options;
 
+    @JsonIgnore
     @Transient
     @ApiModelProperty("题目小题,模块三使用")
     private List<IssueLite> lites;
 
+    @Transient
+    @ApiModelProperty("材料,模块三用")
+    private String material;
+
     public Long getId() {
         return id;
     }
@@ -177,4 +185,12 @@ public class Issue extends BaseIssue {
     public void setLites(List<IssueLite> lites) {
         this.lites = lites;
     }
+
+    public String getMaterial() {
+        return material;
+    }
+
+    public void setMaterial(String material) {
+        this.material = material;
+    }
 }

+ 2 - 0
src/main/java/com/yaoxiang/diagnosis/service/IssuePaperService.java

@@ -58,6 +58,7 @@ public class IssuePaperService {
         }
         IssuePaper result = optional.get();
         List<Issue> list = issueService.listAll(result);
+
         result.setIssues(list);
         return result;
     }
@@ -74,6 +75,7 @@ public class IssuePaperService {
         if (paper == null) {
             return false;
         }
+        paper.setName(vo.getName());
         paper.setChapterIds(vo.getChapterIds());
         paper.setGrade(vo.getGrade());
         issuePaperRepo.save(paper);

+ 42 - 1
src/main/java/com/yaoxiang/diagnosis/service/IssueService.java

@@ -91,23 +91,64 @@ public class IssueService {
         return true;
     }
 
+    /**
+     * 分别加载各个模块的试题,并返回符合前端展示的格式
+     * @param paper 试题
+     * @return 题目列表
+     */
     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);
+        list1.sort(Comparator.comparingLong(Issue::getId));
+        for (int i = 0; i < list1.size(); i++) {
+            Issue issue = list1.get(i);
+            issue.setNumber(i + 1);
+        }
 
         List<Issue> list2 = listWithOption(subjectId, paper.getGrade(), 2);
+        list2.sort(Comparator.comparingLong(Issue::getNumber));
 
         List<Issue> list3 = listWithLite(subjectId, paper.getGrade(), 3);
+        list3.sort(Comparator.comparingLong(Issue::getNumber));
+        list3 = convertIssue(list3);
 
         List<Issue> result = new ArrayList<>();
         result.addAll(list1);
         result.addAll(list2);
         result.addAll(list3);
+//        result.forEach(it -> {
+//            it.setAnswer(null);
+//            it.setCorrectNum(null);
+//        });
         return result;
 //        return issueDao.findBySubjectIdAndGrade(subjectId, grade);
     }
 
+    private List<Issue> convertIssue(List<Issue> list) {
+        List<Issue> result = new ArrayList<>();
+        for (Issue issue : list) {
+            List<IssueLite> lites = issue.getLites();
+            List<Issue> issues = lites.stream().map(it -> convertIssue(it, issue)).collect(Collectors.toList());
+            result.addAll(issues);
+        }
+        return result;
+    }
+
+    private Issue convertIssue(IssueLite lite, Issue old) {
+        Issue issue = new Issue();
+        issue.setMaterial(old.getContent());
+        issue.setContent(lite.getContent());
+        issue.setAnswer(lite.getAnswer());
+        issue.setOptions(lite.getOptions());
+        issue.setCorrectNum(lite.getCorrectNum());
+        issue.setNumber(lite.getNumber());
+        issue.setGrade(old.getGrade());
+        issue.setSection(old.getSection());
+        issue.setSubjectId(old.getSubjectId());
+        return issue;
+    }
+
     /**
      * 获取模块一题目列表
      *
@@ -159,7 +200,7 @@ public class IssueService {
         Map<Long, List<IssueLite>> group = lites.stream().collect(Collectors.groupingBy(IssueLite::getIssueId));
         for (Issue issue : list) {
             List<IssueLite> liteGroup = group.getOrDefault(issue.getId(), new ArrayList<>());
-            liteGroup.forEach(it -> it.setNumber((it.getNumber() - 1) % liteGroup.size() + 1));
+//            liteGroup.forEach(it -> it.setNumber((it.getNumber() - 1) % liteGroup.size() + 1));
             issue.setLites(liteGroup);
         }
         return list;