瀏覽代碼

处理试题题型问题

tags/正式版本
王宁 2 年之前
父節點
當前提交
2fd5d5c629

+ 9
- 8
sstudy/src/main/java/com/xhkjedu/sstudy/controller/question/ZQuestionUpdateController.java 查看文件

@@ -1,11 +1,8 @@
1 1
 package com.xhkjedu.sstudy.controller.question;
2 2
 
3
-import com.xhkjedu.sstudy.model.question.TQuestion;
4 3
 import com.xhkjedu.sstudy.service.question.ZQuestionUpdateService;
5
-import com.xhkjedu.utils.N_Utils;
6 4
 import com.xhkjedu.vo.ResultVo;
7
-import org.springframework.web.bind.annotation.PostMapping;
8
-import org.springframework.web.bind.annotation.RequestBody;
5
+import org.springframework.web.bind.annotation.GetMapping;
9 6
 import org.springframework.web.bind.annotation.RequestMapping;
10 7
 import org.springframework.web.bind.annotation.RestController;
11 8
 
@@ -22,9 +19,13 @@ public class ZQuestionUpdateController {
22 19
     @Resource
23 20
     private ZQuestionUpdateService zQuestionUpdateService;
24 21
 
25
-    @PostMapping("/up")
26
-    public ResultVo updateQuestionType(@RequestBody TQuestion question) {
27
-        zQuestionUpdateService.saveQuestions();
28
-        return new ResultVo(0, "处理成功");
22
+    @GetMapping("/up")
23
+    public ResultVo updateQuestionType() {
24
+       try {
25
+            zQuestionUpdateService.saveQuestions();
26
+            return new ResultVo(0, "处理成功");
27
+        }catch (Exception e){
28
+            return new ResultVo(1,"处理失败:"+e.getMessage());
29
+        }
29 30
     }
30 31
 }

+ 8
- 1
sstudy/src/main/java/com/xhkjedu/sstudy/mapper/question/ZQuestionUpdateMapper.java 查看文件

@@ -2,7 +2,10 @@ package com.xhkjedu.sstudy.mapper.question;
2 2
 
3 3
 import com.xhkjedu.sstudy.base.TkMapper;
4 4
 import com.xhkjedu.sstudy.model.question.TQuestion;
5
+import com.xhkjedu.sstudy.model.subjectbook.TSubject;
6
+import com.xhkjedu.sstudy.model.subjectbook.TSubjectQuestiontype;
5 7
 import com.xhkjedu.sstudy.vo.question.QuestionVo;
8
+import org.apache.ibatis.annotations.Param;
6 9
 import org.springframework.stereotype.Repository;
7 10
 
8 11
 import java.util.List;
@@ -14,5 +17,9 @@ import java.util.List;
14 17
  **/
15 18
 @Repository
16 19
 public interface ZQuestionUpdateMapper extends TkMapper<TQuestion> {
17
-    List<QuestionVo> listQuestions();
20
+    List<QuestionVo> listQuestions(@Param("level")Integer level,@Param("subjectid")String subjectid);
21
+
22
+    List<TSubjectQuestiontype> listSubjectQtype(@Param("level")Integer level,@Param("subjectid")String subjectid);
23
+
24
+    List<TSubject> listSubjects();
18 25
 }

+ 136
- 112
sstudy/src/main/java/com/xhkjedu/sstudy/service/question/ZQuestionUpdateService.java 查看文件

@@ -8,6 +8,8 @@ import com.xhkjedu.sstudy.mapper.question.ZQuestionUpdateMapper;
8 8
 import com.xhkjedu.sstudy.model.question.TQuestion;
9 9
 import com.xhkjedu.sstudy.model.question.TQuestionDirector;
10 10
 import com.xhkjedu.sstudy.model.question.TQuestionPoint;
11
+import com.xhkjedu.sstudy.model.subjectbook.TSubject;
12
+import com.xhkjedu.sstudy.model.subjectbook.TSubjectQuestiontype;
11 13
 import com.xhkjedu.sstudy.utils.StudyUtil;
12 14
 import com.xhkjedu.sstudy.vo.question.QuestionVo;
13 15
 import com.xhkjedu.sstudy.vo.subjectbook.DirectorVo;
@@ -17,11 +19,11 @@ import org.springframework.stereotype.Service;
17 19
 import org.springframework.transaction.annotation.Transactional;
18 20
 
19 21
 import javax.annotation.Resource;
20
-import java.lang.reflect.Type;
21 22
 import java.math.BigDecimal;
22 23
 import java.util.ArrayList;
23 24
 import java.util.List;
24 25
 import java.util.Map;
26
+import java.util.TreeMap;
25 27
 
26 28
 /**
27 29
  * @Description
@@ -47,123 +49,145 @@ public class ZQuestionUpdateService {
47 49
      * @Date 2022/8/17 8:52
48 50
      **/
49 51
     @Transactional(rollbackFor = Exception.class)
50
-    public void saveQuestions(){
51
-        List<QuestionVo> list = zQuestionUpdateMapper.listQuestions();
52
-
53
-        List<TQuestion> questions = new ArrayList<>();
54
-        List<TQuestionDirector> directors = new ArrayList<>();
55
-        List<TQuestionPoint> points = new ArrayList<>();
56
-        int timestamp = N_Utils.getSecondTimestamp();
57
-        for(int k=0;k<list.size();k++){
58
-//            System.out.println("第几题:"+(k+1));
59
-            QuestionVo qvo=list.get(k);
60
-            TQuestion q = new TQuestion();
61
-            String qid = StudyUtil.getId();
62
-
63
-            //处理子题
64
-            String qoption = qvo.getQoption();
65
-            String qanswer = qvo.getQanswer();
66
-            List<Map> optionlist = JSON.parseArray(qoption, Map.class);
67
-            List<String> answerlist = JSON.parseArray(qanswer,String.class);
68
-
69
-            q.setQuestionid(qid);
70
-            q.setQstem(qvo.getQstem());
71
-            q.setQstemtxt(qvo.getQstemtxt());
72
-            q.setQanalyze(qvo.getQanalyze());
73
-            q.setScore(qvo.getScore());
74
-            q.setComplexity(qvo.getComplexity());
75
-            q.setSubjectid(qvo.getSubjectid());
76
-            q.setCount(qvo.getCount());
77
-            q.setQlevel(2);
78
-            q.setSnum(optionlist.size());
79
-            q.setSorder(0);
80
-            q.setQstate(1);
81
-            q.setSource(qvo.getSource());
82
-            q.setYear(qvo.getYear());
83
-            q.setRegion(qvo.getRegion());
84
-            q.setSchoolname(qvo.getSchoolname());
85
-            q.setCreateid(qvo.getCreateid());
86
-            q.setCreatetime(timestamp);
87
-            q.setBelong(qvo.getBelong());
88
-            q.setSchoolid(qvo.getSchoolid());
89
-            if(qvo.getCtype() == 7 || qvo.getCtype() == 8 ){
90
-                q.setCtype(16);
91
-                q.setQtypeid("1QEQRU9B74");
92
-                q.setQtypename("完形填空(复合)");
93
-            }
94
-            if(qvo.getCtype() == 10){
95
-                q.setCtype(17);
96
-                q.setQtypeid("1QEQRV3BG1");
97
-                q.setQtypename("任务型阅读(复合)");
98
-            }
99
-            questions.add(q);//母题
100
-
101
-            List<PointVo> pointVoList = qvo.getPoints();
102
-            for(PointVo pointVo:pointVoList){
103
-                TQuestionPoint tp = new TQuestionPoint();
104
-                tp.setQpid(StudyUtil.getId());
105
-                tp.setQuestionid(qid);
106
-                tp.setPointid(pointVo.getPointid());
107
-                tp.setCreateid(qvo.getCreateid());
108
-                tp.setCreatetime(timestamp);
109
-                points.add(tp);
52
+    public void saveQuestions() throws Exception{
53
+        //需要处理试题的科目
54
+        List<TSubject> subjects = zQuestionUpdateMapper.listSubjects();
55
+        if(N_Utils.isListEmpty(subjects)){
56
+            throw new Exception("无需要处理试题");
57
+        }
58
+        for(TSubject s : subjects){
59
+            List<TSubjectQuestiontype> qtypelist = zQuestionUpdateMapper.listSubjectQtype(s.getLevel(),s.getSubjectid());
60
+            Map<Integer, TSubjectQuestiontype> tmap = new TreeMap();
61
+            if(N_Utils.isListEmpty(qtypelist)){
62
+                throw new Exception(s.getSubjectname() + "未设置题型");
110 63
             }
111
-            List<DirectorVo> directorVoList = qvo.getDirectors();
112
-            for(DirectorVo d : directorVoList){
113
-                TQuestionDirector td = new TQuestionDirector();
114
-                td.setQdid(StudyUtil.getId());
115
-                td.setQuestionid(qid);
116
-                td.setLsbid(d.getLsbid());
117
-                td.setDirectorid(d.getDirectorid());
118
-                td.setCreateid(qvo.getCreateid());
119
-                td.setCreatetime(timestamp);
120
-                directors.add(td);
64
+            for(TSubjectQuestiontype t : qtypelist){
65
+                tmap.put(t.getCtype(),t);
121 66
             }
122 67
 
68
+            List<QuestionVo> list = zQuestionUpdateMapper.listQuestions(s.getLevel(),s.getSubjectid());
69
+
70
+            List<TQuestion> questions = new ArrayList<>();
71
+            List<TQuestionDirector> directors = new ArrayList<>();
72
+            List<TQuestionPoint> points = new ArrayList<>();
73
+            int timestamp = N_Utils.getSecondTimestamp();
74
+            for(int k=0;k<list.size();k++){
75
+//            System.out.println("第几题:"+(k+1));
76
+                QuestionVo qvo=list.get(k);
77
+                TQuestion q = new TQuestion();
78
+                String qid = StudyUtil.getId();
79
+
80
+                //处理子题
81
+                String qoption = qvo.getQoption();
82
+                String qanswer = qvo.getQanswer();
83
+                List<Map> optionlist = JSON.parseArray(qoption, Map.class);
84
+                List<String> answerlist = JSON.parseArray(qanswer,String.class);
85
+
86
+                q.setQuestionid(qid);
87
+                q.setQstem(qvo.getQstem());
88
+                q.setQstemtxt(qvo.getQstemtxt());
89
+                q.setQanalyze(qvo.getQanalyze());
90
+                q.setScore(qvo.getScore());
91
+                q.setComplexity(qvo.getComplexity());
92
+                q.setSubjectid(qvo.getSubjectid());
93
+                q.setCount(qvo.getCount());
94
+                q.setQlevel(2);
95
+                q.setSnum(optionlist.size());
96
+                q.setSorder(0);
97
+                q.setQstate(1);
98
+                q.setSource(qvo.getSource());
99
+                q.setYear(qvo.getYear());
100
+                q.setRegion(qvo.getRegion());
101
+                q.setSchoolname(qvo.getSchoolname());
102
+                q.setCreateid(qvo.getCreateid());
103
+                q.setCreatetime(timestamp);
104
+                q.setBelong(qvo.getBelong());
105
+                q.setSchoolid(qvo.getSchoolid());
106
+                if(qvo.getCtype() == 7 || qvo.getCtype() == 8 ){
107
+                    TSubjectQuestiontype st = tmap.get(16);
108
+                    q.setCtype(16);
109
+                    q.setQtypeid(st.getQtypeid());
110
+                    q.setQtypename(st.getQtypename());
111
+                }
112
+                if(qvo.getCtype() == 10){
113
+                    TSubjectQuestiontype st = tmap.get(17);
114
+                    q.setCtype(17);
115
+                    q.setQtypeid(st.getQtypeid());
116
+                    q.setQtypename(st.getQtypename());
117
+                }
118
+                questions.add(q);//母题
123 119
 
124
-            for(int i=0;i<optionlist.size();i++){
125
-                Map map = optionlist.get(i);
126
-                String sqstem = map.get("sqstem").toString();
127
-                String sqoptions = map.get("sqoptions").toString();
128
-                String sanswer = answerlist.get(i);
129
-                List<String> sanswerlist = new ArrayList<>();
130
-                sanswerlist.add(sanswer);
131
-                Double sscore = getDivide(qvo.getScore(),optionlist.size());
132
-
133
-                TQuestion sq = new TQuestion();
134
-                sq.setQuestionid(StudyUtil.getId());
135
-                sq.setQuestionpid(qid);
136
-                sq.setQstem(sqstem);
137
-                sq.setQstemtxt(sqstem);
138
-                sq.setQoption(sqoptions);
139
-                sq.setQanswer(JSON.toJSONString(sanswerlist));
140
-                sq.setScore(sscore);
141
-                sq.setComplexity(qvo.getComplexity());
142
-                sq.setSubjectid(qvo.getSubjectid());
143
-                sq.setCount(0);
144
-                sq.setQlevel(3);
145
-                sq.setSnum(0);
146
-                sq.setSorder(i+1);
147
-                sq.setQstate(1);
148
-                sq.setSource(qvo.getSource());
149
-                sq.setYear(qvo.getYear());
150
-                sq.setRegion(qvo.getRegion());
151
-                sq.setSchoolname(qvo.getSchoolname());
152
-                sq.setCreateid(qvo.getCreateid());
153
-                sq.setCreatetime(timestamp);
154
-                sq.setBelong(qvo.getBelong());
155
-                sq.setSchoolid(qvo.getSchoolid());
156
-                sq.setCtype(1);
157
-                sq.setQtypeid("1NJCIQ");
158
-                sq.setQtypename("单选题");
159
-
160
-                questions.add(sq);
120
+                List<PointVo> pointVoList = qvo.getPoints();
121
+                for(PointVo pointVo:pointVoList){
122
+                    TQuestionPoint tp = new TQuestionPoint();
123
+                    tp.setQpid(StudyUtil.getId());
124
+                    tp.setQuestionid(qid);
125
+                    tp.setPointid(pointVo.getPointid());
126
+                    tp.setCreateid(qvo.getCreateid());
127
+                    tp.setCreatetime(timestamp);
128
+                    points.add(tp);
129
+                }
130
+                List<DirectorVo> directorVoList = qvo.getDirectors();
131
+                for(DirectorVo d : directorVoList){
132
+                    TQuestionDirector td = new TQuestionDirector();
133
+                    td.setQdid(StudyUtil.getId());
134
+                    td.setQuestionid(qid);
135
+                    td.setLsbid(d.getLsbid());
136
+                    td.setDirectorid(d.getDirectorid());
137
+                    td.setCreateid(qvo.getCreateid());
138
+                    td.setCreatetime(timestamp);
139
+                    directors.add(td);
140
+                }
141
+
142
+
143
+                for(int i=0;i<optionlist.size();i++){
144
+                    Map map = optionlist.get(i);
145
+                    String sqstem = map.get("sqstem").toString();
146
+                    String sqoptions = map.get("sqoptions").toString();
147
+                    String sanswer = answerlist.get(i);
148
+                    List<String> sanswerlist = new ArrayList<>();
149
+                    sanswerlist.add(sanswer);
150
+                    Double sscore = getDivide(qvo.getScore(),optionlist.size());
151
+
152
+                    TQuestion sq = new TQuestion();
153
+                    sq.setQuestionid(StudyUtil.getId());
154
+                    sq.setQuestionpid(qid);
155
+                    sq.setQstem(sqstem);
156
+                    sq.setQstemtxt(sqstem);
157
+                    sq.setQoption(sqoptions);
158
+                    sq.setQanswer(JSON.toJSONString(sanswerlist));
159
+                    sq.setScore(sscore);
160
+                    sq.setComplexity(qvo.getComplexity());
161
+                    sq.setSubjectid(qvo.getSubjectid());
162
+                    sq.setCount(0);
163
+                    sq.setQlevel(3);
164
+                    sq.setSnum(0);
165
+                    sq.setSorder(i+1);
166
+                    sq.setQstate(1);
167
+                    sq.setSource(qvo.getSource());
168
+                    sq.setYear(qvo.getYear());
169
+                    sq.setRegion(qvo.getRegion());
170
+                    sq.setSchoolname(qvo.getSchoolname());
171
+                    sq.setCreateid(qvo.getCreateid());
172
+                    sq.setCreatetime(timestamp);
173
+                    sq.setBelong(qvo.getBelong());
174
+                    sq.setSchoolid(qvo.getSchoolid());
175
+
176
+                    TSubjectQuestiontype st = tmap.get(1);
177
+                    sq.setCtype(1);
178
+                    sq.setQtypeid(st.getQtypeid());
179
+                    sq.setQtypename(st.getQtypename());
180
+
181
+                    questions.add(sq);
182
+                }
161 183
             }
184
+
185
+            questionMapper.saveBathQuestion(questions);
186
+            questionDirectorMapper.batchSave(directors);
187
+            questionPointMapper.batchSave(points);
162 188
         }
163
-        
164
-        questionMapper.saveBathQuestion(questions);
165
-        questionDirectorMapper.batchSave(directors);
166
-        questionPointMapper.batchSave(points);
189
+
190
+
167 191
     }
168 192
 
169 193
     private Double getDivide(Double score,Integer num){

+ 18
- 1
sstudy/src/main/resources/mapper/question/ZQuestionUpdateMapper.xml 查看文件

@@ -51,7 +51,24 @@
51 51
         q.createid,q.schoolid ,qd.directorid,qd.lsbid
52 52
         from t_question q
53 53
         left join t_question_director qd on q.questionid=qd.questionid
54
-        where q.qstate=1 and q.ctype in (7,8,10)
54
+        left join t_subject s on q.subjectid=s.subjectid
55
+        where s.level=#{level} and q.qstate=1 and s.subjectid=#{subjectid} and q.ctype in (7,8,10)
55 56
     </select>
56 57
 
58
+    <!--获取指定学段的ctype为1,16,17的值-->
59
+    <select id="listSubjectQtype" resultType="com.xhkjedu.sstudy.model.subjectbook.TSubjectQuestiontype">
60
+        select q.qtypeid,q.qtypename,q.ctype from t_subject_questiontype q
61
+        left join t_subject s on q.subjectid=s.subjectid
62
+        where s.level=#{level} and q.belong=1 and s.subjectid=#{subjectid} and q.ctype in (1,16,17)
63
+    </select>
64
+
65
+    <!--需要处理的科目的题型-->
66
+    <select id="listSubjects" resultType="com.xhkjedu.sstudy.model.subjectbook.TSubject">
67
+        select s.subjectid,s.subjectname,s.level from t_question q
68
+         left join t_subject s on q.subjectid=s.subjectid
69
+        where q.qstate=1 and q.ctype in (7,8,10) group by s.subjectid
70
+    </select>
71
+
72
+
73
+
57 74
 </mapper>

+ 0
- 7
sstudy/src/test/java/com/xhkjedu/sstudy/SstudyApplicationTests.java 查看文件

@@ -1,20 +1,13 @@
1 1
 package com.xhkjedu.sstudy;
2 2
 
3
-import com.xhkjedu.sstudy.service.question.ZQuestionUpdateService;
4 3
 import org.junit.jupiter.api.Test;
5
-import org.springframework.beans.factory.annotation.Autowired;
6 4
 import org.springframework.boot.test.context.SpringBootTest;
7 5
 
8
-import javax.annotation.Resource;
9
-
10 6
 @SpringBootTest
11 7
 class SstudyApplicationTests {
12
-    @Resource
13
-    private ZQuestionUpdateService zQuestionUpdateService;
14 8
 
15 9
     @Test
16 10
     void contextLoads() {
17
-        zQuestionUpdateService.saveQuestions();
18 11
     }
19 12
 
20 13
 }

Loading…
取消
儲存