Browse Source

优化处理丢弃题型试题

tags/正式3.9.0
王宁 1 year ago
parent
commit
b00b0804d1

+ 3
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/mapper/question/ZQuestionUpdateMapper.java View File

22
     List<TSubjectQuestiontype> listSubjectQtype(@Param("level")Integer level,@Param("subjectid")String subjectid);
22
     List<TSubjectQuestiontype> listSubjectQtype(@Param("level")Integer level,@Param("subjectid")String subjectid);
23
 
23
 
24
     List<TSubject> listSubjects();
24
     List<TSubject> listSubjects();
25
+
26
+    //修改原试题状态
27
+    void updateBatchQuestionState(@Param("questionids")List<String> questionids);
25
 }
28
 }

+ 43
- 33
sstudy/src/main/java/com/xhkjedu/sstudy/service/question/ZQuestionUpdateService.java View File

42
     private QuestionPointMapper questionPointMapper;
42
     private QuestionPointMapper questionPointMapper;
43
 
43
 
44
     /**
44
     /**
45
-     * @Description  处理万幸填空阅读理解
45
+     * @Description 处理万幸填空阅读理解
46
      * @Param []
46
      * @Param []
47
      * @Return void
47
      * @Return void
48
      * @Author wn
48
      * @Author wn
49
      * @Date 2022/8/17 8:52
49
      * @Date 2022/8/17 8:52
50
      **/
50
      **/
51
     @Transactional(rollbackFor = Exception.class)
51
     @Transactional(rollbackFor = Exception.class)
52
-    public void saveQuestions() throws Exception{
53
-        //需要处理试题的科目
52
+    public void saveQuestions() throws Exception {
53
+        // 需要处理试题的科目
54
         List<TSubject> subjects = zQuestionUpdateMapper.listSubjects();
54
         List<TSubject> subjects = zQuestionUpdateMapper.listSubjects();
55
-        if(N_Utils.isListEmpty(subjects)){
55
+
56
+        if (N_Utils.isListEmpty(subjects)) {
56
             throw new Exception("无需要处理试题");
57
             throw new Exception("无需要处理试题");
57
         }
58
         }
58
-        for(TSubject s : subjects){
59
-            List<TSubjectQuestiontype> qtypelist = zQuestionUpdateMapper.listSubjectQtype(s.getLevel(),s.getSubjectid());
59
+        for (TSubject s : subjects) {
60
+            List<TSubjectQuestiontype> qtypelist = zQuestionUpdateMapper.listSubjectQtype(s.getLevel(), s.getSubjectid());
60
             Map<Integer, TSubjectQuestiontype> tmap = new TreeMap();
61
             Map<Integer, TSubjectQuestiontype> tmap = new TreeMap();
61
-            if(N_Utils.isListEmpty(qtypelist)){
62
+            if (N_Utils.isListEmpty(qtypelist)) {
62
                 throw new Exception(s.getSubjectname() + "未设置题型");
63
                 throw new Exception(s.getSubjectname() + "未设置题型");
63
             }
64
             }
64
-            for(TSubjectQuestiontype t : qtypelist){
65
-                tmap.put(t.getCtype(),t);
65
+            for (TSubjectQuestiontype t : qtypelist) {
66
+                if(!tmap.containsKey(t.getCtype())){
67
+                    tmap.put(t.getCtype(), t);
68
+                }
66
             }
69
             }
67
 
70
 
68
-            List<QuestionVo> list = zQuestionUpdateMapper.listQuestions(s.getLevel(),s.getSubjectid());
71
+            List<QuestionVo> list = zQuestionUpdateMapper.listQuestions(s.getLevel(), s.getSubjectid());
69
 
72
 
70
             List<TQuestion> questions = new ArrayList<>();
73
             List<TQuestion> questions = new ArrayList<>();
71
             List<TQuestionDirector> directors = new ArrayList<>();
74
             List<TQuestionDirector> directors = new ArrayList<>();
72
             List<TQuestionPoint> points = new ArrayList<>();
75
             List<TQuestionPoint> points = new ArrayList<>();
76
+            List<String> questionids = new ArrayList<>();
73
             int timestamp = N_Utils.getSecondTimestamp();
77
             int timestamp = N_Utils.getSecondTimestamp();
74
-            for(int k=0;k<list.size();k++){
78
+            for (int k = 0; k < list.size(); k++) {
75
 //            System.out.println("第几题:"+(k+1));
79
 //            System.out.println("第几题:"+(k+1));
76
-                QuestionVo qvo=list.get(k);
80
+                QuestionVo qvo = list.get(k);
77
                 TQuestion q = new TQuestion();
81
                 TQuestion q = new TQuestion();
78
                 String qid = StudyUtil.getId();
82
                 String qid = StudyUtil.getId();
79
 
83
 
80
-                //处理子题
84
+                // 处理子题
81
                 String qoption = qvo.getQoption();
85
                 String qoption = qvo.getQoption();
82
                 String qanswer = qvo.getQanswer();
86
                 String qanswer = qvo.getQanswer();
83
                 List<Map> optionlist = JSON.parseArray(qoption, Map.class);
87
                 List<Map> optionlist = JSON.parseArray(qoption, Map.class);
84
-                List<String> answerlist = JSON.parseArray(qanswer,String.class);
88
+                List<String> answerlist = JSON.parseArray(qanswer, String.class);
85
 
89
 
86
                 q.setQuestionid(qid);
90
                 q.setQuestionid(qid);
87
                 q.setQstem(qvo.getQstem());
91
                 q.setQstem(qvo.getQstem());
104
                 q.setCreatetime(timestamp);
108
                 q.setCreatetime(timestamp);
105
                 q.setBelong(qvo.getBelong());
109
                 q.setBelong(qvo.getBelong());
106
                 q.setSchoolid(qvo.getSchoolid());
110
                 q.setSchoolid(qvo.getSchoolid());
107
-                if(qvo.getCtype() == 7 || qvo.getCtype() == 8 ){
108
-                    TSubjectQuestiontype st = tmap.get(16);
111
+                TSubjectQuestiontype st = null;
112
+                if (qvo.getCtype() == 7 || qvo.getCtype() == 8) {
113
+                    st = tmap.get(16);
109
                     q.setCtype(16);
114
                     q.setCtype(16);
110
-                    q.setQtypeid(st.getQtypeid());
111
-                    q.setQtypename(st.getQtypename());
115
+
112
                 }
116
                 }
113
-                if(qvo.getCtype() == 10){
114
-                    TSubjectQuestiontype st = tmap.get(17);
117
+                if (qvo.getCtype() == 10) {
118
+                    st = tmap.get(17);
115
                     q.setCtype(17);
119
                     q.setCtype(17);
116
-                    q.setQtypeid(st.getQtypeid());
117
-                    q.setQtypename(st.getQtypename());
118
                 }
120
                 }
119
-                questions.add(q);//母题
121
+
122
+                if(st == null){
123
+                    throw new Exception("未设置题型:"+ s.getSubjectname() + ":"+qvo.getQuestionid());
124
+                }
125
+
126
+                q.setQtypeid(st.getQtypeid());
127
+                q.setQtypename(st.getQtypename());
128
+                questions.add(q);// 母题
120
 
129
 
121
                 List<PointVo> pointVoList = qvo.getPoints();
130
                 List<PointVo> pointVoList = qvo.getPoints();
122
-                for(PointVo pointVo:pointVoList){
131
+                for (PointVo pointVo : pointVoList) {
123
                     TQuestionPoint tp = new TQuestionPoint();
132
                     TQuestionPoint tp = new TQuestionPoint();
124
                     tp.setQpid(StudyUtil.getId());
133
                     tp.setQpid(StudyUtil.getId());
125
                     tp.setQuestionid(qid);
134
                     tp.setQuestionid(qid);
129
                     points.add(tp);
138
                     points.add(tp);
130
                 }
139
                 }
131
                 List<DirectorVo> directorVoList = qvo.getDirectors();
140
                 List<DirectorVo> directorVoList = qvo.getDirectors();
132
-                for(DirectorVo d : directorVoList){
141
+                for (DirectorVo d : directorVoList) {
133
                     TQuestionDirector td = new TQuestionDirector();
142
                     TQuestionDirector td = new TQuestionDirector();
134
                     td.setQdid(StudyUtil.getId());
143
                     td.setQdid(StudyUtil.getId());
135
                     td.setQuestionid(qid);
144
                     td.setQuestionid(qid);
141
                 }
150
                 }
142
 
151
 
143
 
152
 
144
-                for(int i=0;i<optionlist.size();i++){
153
+                for (int i = 0; i < optionlist.size(); i++) {
145
                     Map map = optionlist.get(i);
154
                     Map map = optionlist.get(i);
146
                     String sqstem = map.get("sqstem").toString();
155
                     String sqstem = map.get("sqstem").toString();
147
                     String sqoptions = map.get("sqoptions").toString();
156
                     String sqoptions = map.get("sqoptions").toString();
148
                     String sanswer = answerlist.get(i);
157
                     String sanswer = answerlist.get(i);
149
                     List<String> sanswerlist = new ArrayList<>();
158
                     List<String> sanswerlist = new ArrayList<>();
150
                     sanswerlist.add(sanswer);
159
                     sanswerlist.add(sanswer);
151
-                    Double sscore = getDivide(qvo.getScore(),optionlist.size());
160
+                    Double sscore = getDivide(qvo.getScore(), optionlist.size());
152
 
161
 
153
                     TQuestion sq = new TQuestion();
162
                     TQuestion sq = new TQuestion();
154
                     sq.setQuestionid(StudyUtil.getId());
163
                     sq.setQuestionid(StudyUtil.getId());
163
                     sq.setCount(0);
172
                     sq.setCount(0);
164
                     sq.setQlevel(3);
173
                     sq.setQlevel(3);
165
                     sq.setSnum(0);
174
                     sq.setSnum(0);
166
-                    sq.setSorder(i+1);
175
+                    sq.setSorder(i + 1);
167
                     sq.setQstate(1);
176
                     sq.setQstate(1);
168
                     sq.setHashear(0);
177
                     sq.setHashear(0);
169
                     sq.setSource(qvo.getSource());
178
                     sq.setSource(qvo.getSource());
175
                     sq.setBelong(qvo.getBelong());
184
                     sq.setBelong(qvo.getBelong());
176
                     sq.setSchoolid(qvo.getSchoolid());
185
                     sq.setSchoolid(qvo.getSchoolid());
177
 
186
 
178
-                    TSubjectQuestiontype st = tmap.get(1);
187
+                    TSubjectQuestiontype st1 = tmap.get(1);
179
                     sq.setCtype(1);
188
                     sq.setCtype(1);
180
-                    sq.setQtypeid(st.getQtypeid());
181
-                    sq.setQtypename(st.getQtypename());
189
+                    sq.setQtypeid(st1.getQtypeid());
190
+                    sq.setQtypename(st1.getQtypename());
182
 
191
 
183
                     questions.add(sq);
192
                     questions.add(sq);
184
                 }
193
                 }
194
+                questionids.add(qvo.getQuestionid());
185
             }
195
             }
186
 
196
 
187
             questionMapper.saveBathQuestion(questions);
197
             questionMapper.saveBathQuestion(questions);
188
             questionDirectorMapper.batchSave(directors);
198
             questionDirectorMapper.batchSave(directors);
189
             questionPointMapper.batchSave(points);
199
             questionPointMapper.batchSave(points);
200
+            zQuestionUpdateMapper.updateBatchQuestionState(questionids);
190
         }
201
         }
191
 
202
 
192
-
193
     }
203
     }
194
 
204
 
195
-    private Double getDivide(Double score,Integer num){
205
+    private Double getDivide(Double score, Integer num) {
196
         BigDecimal score1 = new BigDecimal(score);
206
         BigDecimal score1 = new BigDecimal(score);
197
         BigDecimal num1 = new BigDecimal(num);
207
         BigDecimal num1 = new BigDecimal(num);
198
         BigDecimal divide = score1.divide(num1, 1, BigDecimal.ROUND_FLOOR);
208
         BigDecimal divide = score1.divide(num1, 1, BigDecimal.ROUND_FLOOR);

+ 8
- 0
sstudy/src/main/resources/mapper/question/ZQuestionUpdateMapper.xml View File

69
         where q.qstate=1 and q.ctype in (7,8,10) group by s.subjectid
69
         where q.qstate=1 and q.ctype in (7,8,10) group by s.subjectid
70
     </select>
70
     </select>
71
 
71
 
72
+    <!--更改原试题状态为已删除-->
73
+    <update id="updateBatchQuestionState">
74
+        update t_question set qstate=10 where questionid in
75
+        <foreach collection="questionids" item="questionid" index="index" open="(" close=")" separator=",">
76
+            #{questionid}
77
+        </foreach>
78
+    </update>
79
+
72
 
80
 
73
 
81
 
74
 </mapper>
82
 </mapper>

Loading…
Cancel
Save