Browse Source

试题、资源列表sharenum获取完善

tags/正式3.11.0
雍文秀 1 year ago
parent
commit
8308cad3e6

+ 14
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/controller/resource/ResourceController.java View File

@@ -165,6 +165,13 @@ public class ResourceController {
165 165
         return new ResultVo(0,"更新下载次数成功");
166 166
     }
167 167
 
168
+    /**
169
+     * @Description 我的空间(网页、app端)
170
+     * @Date 2023/9/1 15:39
171
+     * @Author YWX
172
+     * @Param [tResource]
173
+     * @Return com.xhkjedu.vo.ResultVo
174
+     **/
168 175
     @PostMapping("/my_list")
169 176
     public ResultVo myList(@RequestBody TResource tResource) {
170 177
         Integer page = tResource.getPage();
@@ -179,6 +186,13 @@ public class ResourceController {
179 186
         return new ResultVo(0,"获取教师备课资源列表成功",pageResult);
180 187
     }
181 188
 
189
+    /**
190
+     * @Description 我的空间(课堂端)
191
+     * @Date 2023/9/1 15:38
192
+     * @Author YWX
193
+     * @Param [tResource]
194
+     * @Return com.xhkjedu.vo.ResultVo
195
+     **/
182 196
     @PostMapping("/my_list2")
183 197
     public ResultVo myList2(@RequestBody TResource tResource) {
184 198
         Integer createid = tResource.getCreateid();

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

@@ -101,4 +101,7 @@ public interface QuestionMapper extends TkMapper<TQuestion> {
101 101
     //更新分享过伙伴校试题的时间
102 102
     void batchUpdateTime(@Param("list") List<Integer> schoolIds, @Param("shareqid") String shareqid
103 103
             ,@Param("timestamp") int timestamp);
104
+
105
+    //试题是否分享过
106
+    List<Map<String, String>> listShareNumByIds(@Param("shareqids") String shareqids);
104 107
 }

+ 3
- 0
sstudy/src/main/java/com/xhkjedu/sstudy/mapper/resource/ResourceMapper.java View File

@@ -87,4 +87,7 @@ public interface ResourceMapper extends TkMapper<TResource> {
87 87
     //更新分享过伙伴校资源的时间
88 88
     void batchUpdateTime(@Param("list") List<Integer> schoolIds,@Param("resourceid") String resourceid
89 89
             ,@Param("timestamp") int timestamp);
90
+
91
+    //资源是否分享过
92
+    List<Map<String, String>> listShareNumByIds(@Param("shareqids") String shareqids);
90 93
 }

+ 46
- 5
sstudy/src/main/java/com/xhkjedu/sstudy/service/question/QuestionService.java View File

@@ -15,7 +15,6 @@ import com.xhkjedu.sstudy.vo.subjectbook.DirectorVo;
15 15
 import com.xhkjedu.utils.N_Utils;
16 16
 import com.xhkjedu.vo.ResultVo;
17 17
 import org.springframework.beans.BeanUtils;
18
-import org.springframework.scheduling.annotation.Async;
19 18
 import org.springframework.stereotype.Service;
20 19
 import org.springframework.transaction.annotation.Transactional;
21 20
 import org.springframework.util.CollectionUtils;
@@ -89,7 +88,16 @@ public class QuestionService {
89 88
 
90 89
     //获取列表
91 90
     public List <Map<String, Object>> findAll(TQuestion question) {
92
-        return questionMapper.findAll(question);
91
+        List<Map<String, Object>> list = questionMapper.findAll(question);
92
+        Integer schoolid = question.getSchoolid();
93
+        if(N_Utils.isEmptyInteger(schoolid)) return list;
94
+        String shareqids = list.stream().filter(m -> schoolid.equals(m.get("schoolid")) && !m.get("belong").equals(10))
95
+                               .map(m -> m.get("questionid").toString()).collect(Collectors.joining("','"));
96
+        List<Map<String, String>> shareList = questionMapper.listShareNumByIds(shareqids);
97
+        for (Map<String, Object> map : list) {
98
+            setShareNum(shareList, map);
99
+        }
100
+        return list;
93 101
     }
94 102
 
95 103
     /**
@@ -272,15 +280,49 @@ public class QuestionService {
272 280
         List<Map<String, Object>> list = questionMapper.listForSelect(question);
273 281
         String questionids = list.stream().filter(m -> m.get("qlevel").toString().equals("2")).map(
274 282
                 m -> m.get("questionid").toString()).collect(Collectors.joining("','"));
283
+        boolean rtn = false;
284
+        List<Map<String, String>> sonList;
275 285
         if (N_Utils.isNotEmpty(questionids)) {
276
-            List<Map<String, String>> sonList = questionMapper.listSonQuestionForSelect(questionids);
277
-            for (Map<String, Object> map : list) {
286
+            sonList = questionMapper.listSonQuestionForSelect(questionids);
287
+            rtn = true;
288
+        } else {
289
+            sonList = null;
290
+        }
291
+
292
+        Integer createid = question.getCreateid();
293
+        String shareqids = list.stream().filter(m -> createid.equals(m.get("createid")) && !m.get("belong").equals(10))
294
+                               .map(m -> m.get("questionid").toString()).collect(Collectors.joining("','"));
295
+        List<Map<String, String>> shareList = questionMapper.listShareNumByIds(shareqids);
296
+        for (Map<String, Object> map : list) {
297
+            setShareNum(shareList, map);
298
+            if (rtn) {
278 299
                 setSonQList(sonList, map);
279 300
             }
280 301
         }
281 302
         return list;
282 303
     }
283 304
 
305
+    /**
306
+     * @Description 试题是否分享过
307
+     * @Date 2023/9/1 14:28
308
+     * @Author YWX
309
+     * @Param [shareList, map]
310
+     * @Return void
311
+     **/
312
+    private void setShareNum(List<Map<String, String>> shareList, Map<String, Object> map) {
313
+        Object shareqid = map.get("questionid");
314
+        Object sharenum = 0;
315
+        if (N_Utils.isListNotEmpty(shareList)) {
316
+            for (Map<String, String> s : shareList) {
317
+                if (s.get("shareqid").equals(shareqid)) {
318
+                    sharenum = s.get("sharenum");
319
+                    break;
320
+                }
321
+            }
322
+        }
323
+        map.put("sharenum", sharenum);
324
+    }
325
+
284 326
     /**
285 327
      * @Description 处理试题子题
286 328
      * @Date 2023/8/16 8:38
@@ -288,7 +330,6 @@ public class QuestionService {
288 330
      * @Param [sonList, map]
289 331
      * @Return void
290 332
      **/
291
-    @Async("asyncPoolTaskExecutor")
292 333
     public void setSonQList(List<Map<String, String>> sonList, Map<String, Object> map) {
293 334
         if (map.get("qlevel").toString().equals("2")) {
294 335
             Object questionid = map.get("questionid");

+ 38
- 2
sstudy/src/main/java/com/xhkjedu/sstudy/service/resource/ResourceService.java View File

@@ -147,7 +147,16 @@ public class ResourceService {
147 147
 
148 148
     //获取列表
149 149
     public List <Map> findAll(TResource tResource) {
150
-        return resourceMapper.findAll(tResource);
150
+        List<Map> list = resourceMapper.findAll(tResource);
151
+        Integer schoolid = tResource.getSchoolid();
152
+        if(N_Utils.isEmptyInteger(schoolid)) return list;
153
+        String shareqids = list.stream().filter(m -> schoolid.equals(m.get("schoolid")) && !m.get("belong").equals(10))
154
+                               .map(m -> m.get("resourceid").toString()).collect(Collectors.joining("','"));
155
+        List<Map<String, String>> shareList = resourceMapper.listShareNumByIds(shareqids);
156
+        for (Map map : list) {
157
+            setShareNum(shareList, map);
158
+        }
159
+        return list;
151 160
     }
152 161
 
153 162
     //分享
@@ -230,7 +239,34 @@ public class ResourceService {
230 239
      * @return java.util.List<com.xhkjedu.model.resource.TResource>
231 240
      **/
232 241
     public List<Map> listMyResource(TResource resource) {
233
-        return resourceMapper.listMyResource(resource);
242
+        List<Map> list = resourceMapper.listMyResource(resource);
243
+        String shareqids = list.stream().map(m -> m.get("resourceid").toString()).collect(Collectors.joining("','"));
244
+        List<Map<String, String>> shareList = resourceMapper.listShareNumByIds(shareqids);
245
+        for (Map map : list) {
246
+            setShareNum(shareList, map);
247
+        }
248
+        return list;
249
+    }
250
+
251
+    /**
252
+     * @Description 资源是否分享过
253
+     * @Date 2023/9/1 15:12
254
+     * @Author YWX
255
+     * @Param [shareList, map]
256
+     * @Return void
257
+     **/
258
+    private void setShareNum(List<Map<String, String>> shareList, Map<String, Object> map) {
259
+        Object shareqid = map.get("resourceid");
260
+        Object sharenum = 0;
261
+        if (N_Utils.isListNotEmpty(shareList)) {
262
+            for (Map<String, String> s : shareList) {
263
+                if (s.get("resourcepid").equals(shareqid)) {
264
+                    sharenum = s.get("sharenum");
265
+                    break;
266
+                }
267
+            }
268
+        }
269
+        map.put("sharenum", sharenum);
234 270
     }
235 271
 
236 272
     /**

+ 6
- 1
sstudy/src/main/resources/mapper/question/QuestionMapper.xml View File

@@ -199,7 +199,6 @@
199 199
         select q.questionid,q.score,q.complexity,q.qstem,q.qstemtxt,q.qoption,q.qanswer,q.qanalyze
200 200
         ,q.qtypeid,q.qtypename,q.count,q.ctype,q.source,q.year,q.region,q.schoolname
201 201
         ,q.qlevel,q.hearfile,q.hashear,q.belong,q.createid,q.schoolid
202
-        ,(select count(*) from t_question q2 where q2.shareqid=q.questionid and q2.qstate=1 and q.schoolid=#{question.schoolid})sharenum
203 202
         from t_question q
204 203
         <if test="question.pointid!=null and question.pointid!='0'.toString() and question.pointid!=''">
205 204
             left join t_question_point qp on q.questionid = qp.questionid
@@ -265,6 +264,12 @@
265 264
         and q.qlevel &lt; 3
266 265
         group by q.questionid order by q.createtime desc
267 266
     </select>
267
+    <!--试题是否分享过-->
268
+    <select id="listShareNumByIds" resultType="java.util.Map">
269
+        select shareqid,count(*) as sharenum
270
+        from t_question where qstate=1 and shareqid in('${shareqids}')
271
+        group by shareqid
272
+    </select>
268 273
 
269 274
     <select id="listSonQuestionForSelect" resultType="java.util.Map">
270 275
         select q.questionid,q.questionpid,q.score,q.complexity,q.qstem,q.qstemtxt,q.qoption,q.qanswer,q.qanalyze

+ 6
- 2
sstudy/src/main/resources/mapper/resource/ResourceMapper.xml View File

@@ -14,7 +14,6 @@
14 14
         rd.directorid,r.resourceclass,r.resourcetype,r.readcount,r.downcount,r.pdfurl,r.converted,r.resourcecover
15 15
         ,r.comm,r.duration,r.resourcesize,r.mp4code,r.createid,r.belong,r.schoolid
16 16
         ,r.resourcegrade,r.source,r.year,r.region,r.schoolname
17
-        ,(select count(*) from t_resource r2 where r2.resourcepid=r.resourceid and r.resourcestate=1)sharenum
18 17
         from t_resource r left join t_user u on u.userid=r.createid
19 18
         left join t_resource_director rd on r.resourceid=rd.resourceid
20 19
         <if test="resource.belong!=null and resource.belong==5">
@@ -89,7 +88,6 @@
89 88
         select r.resourceid,r.resourcename,r.createtime,r.suffix,u.username createname,r.resourceurl,rd.lsbid,
90 89
         rd.directorid,r.resourceclass,r.resourcetype,r.readcount,r.downcount,r.pdfurl,r.converted,r.resourcecover
91 90
         ,r.comm,r.duration,r.resourcesize,r.mp4code
92
-        ,(select count(*) from t_resource r2 where r2.resourcepid=r.resourceid and r.resourcestate=1)sharenum
93 91
         from t_resource r left join t_user u on u.userid=r.createid
94 92
         left join t_resource_director rd on r.resourceid=rd.resourceid
95 93
         where r.resourcestate=1 and r.level=#{resource.level} and r.createid=#{resource.createid}
@@ -110,6 +108,12 @@
110 108
         </if>
111 109
         order by r.createtime desc,r.resourcename,r.resourceid
112 110
     </select>
111
+    <!--资源是否分享过-->
112
+    <select id="listShareNumByIds" resultType="java.util.Map">
113
+        select resourcepid,count(*) as sharenum
114
+        from t_resource where resourcestate=1 and resourcepid in('${shareqids}')
115
+        group by resourcepid
116
+    </select>
113 117
 
114 118
     <!--详情-->
115 119
     <resultMap id="resourceResult" type="com.xhkjedu.sstudy.vo.resource.ResourceVo">

Loading…
Cancel
Save