yangdamao 2 vuotta sitten
vanhempi
commit
d97e075910

+ 28 - 11
zhongzheng-api/src/main/java/com/zhongzheng/controller/bank/QuestionController.java

@@ -23,9 +23,11 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 题库题目Controller
@@ -111,17 +113,32 @@ public class QuestionController extends BaseController {
         ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
         bo.setUserId(loginUser.getUser().getUserId());
         List<GoodsUserQuestionVo> list = iQuestionService.listUserFreeUnionBuyGoodsList(bo);
-        for (GoodsUserQuestionVo g : list) {
-            UserExamRecordQueryBo userExamRecordQueryBo = new UserExamRecordQueryBo();
-            userExamRecordQueryBo.setOrderGoodsId(g.getOrderGoodsId());
-            userExamRecordQueryBo.setUserId(loginUser.getUser().getUserId());
-            Long doNum = iUserExamRecordService.selectDoNum(userExamRecordQueryBo);
-            Long totalNum = iGoodsService.getQuestionNum(g.getGoodsId());
-            g.setDoNum(doNum);
-            g.setTotalNum(totalNum);
+        if (!CollectionUtils.isEmpty(list)){
+            for (GoodsUserQuestionVo g : list) {
+                UserExamRecordQueryBo userExamRecordQueryBo = new UserExamRecordQueryBo();
+                userExamRecordQueryBo.setOrderGoodsId(g.getOrderGoodsId());
+                userExamRecordQueryBo.setUserId(loginUser.getUser().getUserId());
+                Long doNum = iUserExamRecordService.selectDoNum(userExamRecordQueryBo);
+                Long totalNum = iGoodsService.getQuestionNum(g.getGoodsId());
+                g.setDoNum(doNum);
+                g.setTotalNum(totalNum);
+            }
+
             //试卷类型
-            List<ExamPaperVo> paperVos = iExamPaperService.getGoodsExamPaper(g.getGoodsId());
-            g.setPaperVos(paperVos);
+            List<ExamPaperVo> paperVos = iExamPaperService.getGoodsExamPaperByGoodsIds(list.stream().map(GoodsUserQuestionVo::getGoodsId).collect(Collectors.toList()));
+            if (!CollectionUtils.isEmpty(paperVos)){
+                Map<Long, List<ExamPaperVo>> map = paperVos.stream().collect(Collectors.groupingBy(ExamPaperVo::getGoodsId));
+                map.forEach((k,v) -> {
+                    ArrayList<ExamPaperVo> vos = v.stream().collect(Collectors.collectingAndThen(Collectors
+                            .toCollection(() -> new TreeSet<>(Comparator.comparing(item -> item.getPaperId()))), ArrayList::new));
+                    map.put(k,vos);
+                });
+                list.forEach(goods -> {
+                    if (map.containsKey(goods.getGoodsId())){
+                        goods.setPaperVos(map.get(goods.getGoodsId()));
+                    }
+                });
+            }
         }
         return getDataTable(list);
     }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/exam/mapper/ExamPaperMapper.java

@@ -3,6 +3,7 @@ package com.zhongzheng.modules.exam.mapper;
 import com.zhongzheng.modules.exam.domain.ExamPaper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.zhongzheng.modules.exam.vo.ExamPaperVo;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -14,4 +15,6 @@ import java.util.List;
  */
 public interface ExamPaperMapper extends BaseMapper<ExamPaper> {
     List<ExamPaperVo> getGoodsExamPaper(Long goodsId);
+
+    List<ExamPaperVo> getGoodsExamPaperByGoodsIds(@Param("goodsIds") List<Long> goodsIds);
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/exam/service/IExamPaperService.java

@@ -51,4 +51,7 @@ public interface IExamPaperService extends IService<ExamPaper> {
 	Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
 
 	List<ExamPaperVo> getGoodsExamPaper(Long goodsId);
+
+	List<ExamPaperVo> getGoodsExamPaperByGoodsIds(List<Long> goodsId);
+
 }

+ 5 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/exam/service/impl/ExamPaperServiceImpl.java

@@ -128,4 +128,9 @@ public class ExamPaperServiceImpl extends ServiceImpl<ExamPaperMapper, ExamPaper
     public List<ExamPaperVo> getGoodsExamPaper(Long goodsId) {
         return this.baseMapper.getGoodsExamPaper(goodsId);
     }
+
+    @Override
+    public List<ExamPaperVo> getGoodsExamPaperByGoodsIds(List<Long> goodsId) {
+        return this.baseMapper.getGoodsExamPaperByGoodsIds(goodsId);
+    }
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/exam/vo/ExamPaperVo.java

@@ -40,4 +40,7 @@ public class ExamPaperVo {
 	@Excel(name = "编码SJ")
 	@ApiModelProperty("编码SJ")
 	private String encoder;
+
+	@ApiModelProperty("商品ID")
+	private Long goodsId;
 }

+ 50 - 0
zhongzheng-system/src/main/resources/mapper/modules/exam/ExamPaperMapper.xml

@@ -61,4 +61,54 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           AND e.exam_paper_id IS NOT NULL AND ep.`status` != -1
     </select>
 
+    <select id="getGoodsExamPaperByGoodsIds" parameterType="java.lang.Long" resultType="com.zhongzheng.modules.exam.vo.ExamPaperVo">
+        SELECT
+            ep.paper_id,
+            ga.goods_id,
+            ep.paper_name
+        FROM goods_attached ga
+                 LEFT JOIN question_module_chapter qmc ON ga.major_id = qmc.module_exam_id
+                 LEFT JOIN question_chapter_exam qce ON qmc.chapter_exam_id = qce.chapter_exam_id
+                 LEFT JOIN exam e ON qce.exam_id = e.exam_id
+                 LEFT JOIN exam_paper ep ON e.exam_paper_id = ep.paper_id
+        WHERE ga.type = 1
+        <if test="goodsIds != null and goodsIds.size()!=0 ">
+            AND ga.goods_id in
+            <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        UNION ALL
+        SELECT
+            ep.paper_id,
+            ga.goods_id,
+            ep.paper_name
+        FROM goods_attached ga
+                 LEFT JOIN question_chapter_exam qce ON ga.major_id = qce.chapter_exam_id
+                 LEFT JOIN exam e ON qce.exam_id = e.exam_id
+                 LEFT JOIN exam_paper ep ON e.exam_paper_id = ep.paper_id
+        WHERE ga.type = 2
+        <if test="goodsIds != null and goodsIds.size()!=0 ">
+            AND ga.goods_id in
+            <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        UNION ALL
+        SELECT
+            ep.paper_id,
+            ga.goods_id,
+            ep.paper_name
+        FROM goods_attached ga
+                 LEFT JOIN exam e ON ga.major_id = e.exam_id
+                 LEFT JOIN exam_paper ep ON e.exam_paper_id = ep.paper_id
+        WHERE ga.type = 3
+        <if test="goodsIds != null and goodsIds.size()!=0 ">
+            AND ga.goods_id in
+            <foreach collection="goodsIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+    </select>
+
 </mapper>