he2802 vor 4 Jahren
Ursprung
Commit
e159fc85e1

+ 9 - 36
zhongzheng-api/src/main/java/com/zhongzheng/controller/bank/QuestionSimulateController.java

@@ -3,11 +3,14 @@ package com.zhongzheng.controller.bank;
 import java.util.List;
 import java.util.Arrays;
 
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.framework.web.service.WxTokenService;
 import com.zhongzheng.modules.bank.bo.QuestionSimulateAddBo;
 import com.zhongzheng.modules.bank.bo.QuestionSimulateEditBo;
 import com.zhongzheng.modules.bank.bo.QuestionSimulateQueryBo;
 import com.zhongzheng.modules.bank.service.IQuestionSimulateService;
 import com.zhongzheng.modules.bank.vo.QuestionSimulateVo;
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
 import lombok.RequiredArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -42,11 +45,12 @@ public class QuestionSimulateController extends BaseController {
 
     private final IQuestionSimulateService iQuestionSimulateService;
 
+    private final WxTokenService wxTokenService;
+
     /**
      * 查询模拟题库列表
      */
     @ApiOperation("查询模拟题库列表")
-    @PreAuthorize("@ss.hasPermi('system:simulate:list')")
     @GetMapping("/list")
     public TableDataInfo<QuestionSimulateVo> list(QuestionSimulateQueryBo bo) {
         startPage();
@@ -60,42 +64,11 @@ public class QuestionSimulateController extends BaseController {
      * 获取模拟题库详细信息
      */
     @ApiOperation("获取模拟题库详细信息")
-    @PreAuthorize("@ss.hasPermi('system:simulate:query')")
-    @GetMapping("/{simulateId}")
-    public AjaxResult<QuestionSimulateVo> getInfo(@PathVariable("simulateId" ) Long simulateId) {
-        return AjaxResult.success(iQuestionSimulateService.queryById(simulateId));
+    @GetMapping("/{bankId}")
+    public AjaxResult getInfo(@PathVariable("bankId" ) Long bankId) {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        return AjaxResult.success(iQuestionSimulateService.queryByBankId(bankId,loginUser.getUser().getUserId()));
     }
 
-    /**
-     * 新增模拟题库
-     */
-    @ApiOperation("新增模拟题库")
-    @PreAuthorize("@ss.hasPermi('system:simulate:add')")
-    @Log(title = "模拟题库", businessType = BusinessType.INSERT)
-    @PostMapping()
-    public AjaxResult<Void> add(@RequestBody QuestionSimulateAddBo bo) {
-        return toAjax(iQuestionSimulateService.insertByAddBo(bo) ? 1 : 0);
-    }
 
-    /**
-     * 修改模拟题库
-     */
-    @ApiOperation("修改模拟题库")
-    @PreAuthorize("@ss.hasPermi('system:simulate:edit')")
-    @Log(title = "模拟题库", businessType = BusinessType.UPDATE)
-    @PutMapping()
-    public AjaxResult<Void> edit(@RequestBody QuestionSimulateEditBo bo) {
-        return toAjax(iQuestionSimulateService.updateByEditBo(bo) ? 1 : 0);
-    }
-
-    /**
-     * 删除模拟题库
-     */
-    @ApiOperation("删除模拟题库")
-    @PreAuthorize("@ss.hasPermi('system:simulate:remove')")
-    @Log(title = "模拟题库" , businessType = BusinessType.DELETE)
-    @DeleteMapping("/{simulateIds}")
-    public AjaxResult<Void> remove(@PathVariable Long[] simulateIds) {
-        return toAjax(iQuestionSimulateService.deleteWithValidByIds(Arrays.asList(simulateIds), true) ? 1 : 0);
-    }
 }

+ 1 - 1
zhongzheng-api/src/main/java/com/zhongzheng/controller/collect/CollectQuestionController.java

@@ -42,7 +42,7 @@ import io.swagger.annotations.ApiOperation;
 @Api(value = "收藏题目控制器", tags = {"收藏题目管理"})
 @RequiredArgsConstructor(onConstructor_ = @Autowired)
 @RestController
-@RequestMapping("/system/question")
+@RequestMapping("/collect/question")
 public class CollectQuestionController extends BaseController {
 
     private final ICollectQuestionService iCollectQuestionService;

+ 2 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/IQuestionSimulateService.java

@@ -9,6 +9,7 @@ import com.zhongzheng.modules.bank.vo.QuestionSimulateVo;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 模拟题库Service接口
@@ -23,7 +24,7 @@ public interface IQuestionSimulateService extends IService<QuestionSimulate> {
 	 */
 	QuestionSimulateVo queryById(Long simulateId);
 
-	QuestionSimulateVo queryByBankId(Long simulateId);
+	Map<String,Object> queryByBankId(Long bandId,Long userId);
 
 	/**
 	 * 查询列表

+ 38 - 11
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionSimulateServiceImpl.java

@@ -51,54 +51,69 @@ public class QuestionSimulateServiceImpl extends ServiceImpl<QuestionSimulateMap
     }
 
     @Override
-    public QuestionSimulateVo queryByBankId(Long simulateId) {
+    public Map<String,Object> queryByBankId(Long bandId,Long userId) {
         Map<String,Object> param = new HashMap<>();
-        Long bandId = 2L;
         param.put("bandId",bandId);
         ExamConfigVo vo = examConfigMapper.selectBankExamConfig(param);
         if(vo==null){
             throw new CustomException("该题库暂不支持模拟考试");
         }
-        Long bank_section_id = 9L;
         //抽选单选题
         Map<String,Object> param1 = new HashMap<>();
-        param1.put("bankSectionId",bank_section_id);
+        param1.put("bankId",bandId);
         param1.put("type",1);
         param1.put("num",vo.getSingleChoiceNum());
+        List<QuestionVo> listToatl = new ArrayList<>();
         List<QuestionVo> list1 = questionMapper.selectQuestionSimulateList(param1);
         String type1_ids ="";
+        if(list1.size()<vo.getSingleChoiceNum()){
+            throw new CustomException("题库单选题数不足");
+        }
         for (QuestionVo s : list1) {
             type1_ids += s.getQuestionId()+",";
+            listToatl.add(s);
         }
         //抽选多选题
         Map<String,Object> param2 = new HashMap<>();
-        param2.put("bankSectionId",bank_section_id);
+        param2.put("bankId",bandId);
         param2.put("type",2);
-        param2.put("num",vo.getSingleChoiceNum());
+        param2.put("num",vo.getMultipleChoiceNum());
         List<QuestionVo> list2 = questionMapper.selectQuestionSimulateList(param2);
         String type2_ids ="";
+        if(list2.size()<vo.getMultipleChoiceNum()){
+            throw new CustomException("题库多选题数不足");
+        }
         for (QuestionVo s : list2) {
             type2_ids += s.getQuestionId()+",";
+            listToatl.add(s);
         }
         //抽选判断题
         Map<String,Object> param3 = new HashMap<>();
-        param3.put("bankSectionId",bank_section_id);
+        param3.put("bankId",bandId);
         param3.put("type",3);
-        param3.put("num",vo.getSingleChoiceNum());
+        param3.put("num",vo.getJudgmentNum());
         List<QuestionVo> list3 = questionMapper.selectQuestionSimulateList(param3);
         String type3_ids ="";
+        if(list3.size()<vo.getJudgmentNum()){
+            throw new CustomException("题库判断题数不足");
+        }
         for (QuestionVo s : list3) {
             type3_ids += s.getQuestionId()+",";
+            listToatl.add(s);
         }
         //抽选案例题
         Map<String,Object> param4 = new HashMap<>();
-        param4.put("bankSectionId",bank_section_id);
+        param4.put("bankId",bandId);
         param4.put("type",4);
-        param4.put("num",vo.getSingleChoiceNum());
+        param4.put("num",vo.getCaseNum());
         List<QuestionVo> list4 = questionMapper.selectQuestionSimulateList(param4);
         String type4_ids ="";
+        if(list4.size()<vo.getCaseNum()){
+            throw new CustomException("题库案例题数不足");
+        }
         for (QuestionVo s : list4) {
             type4_ids += s.getQuestionId()+",";
+            listToatl.add(s);
         }
         QuestionSimulateAddBo bo = new QuestionSimulateAddBo();
         bo.setBankId(bandId);
@@ -106,8 +121,20 @@ public class QuestionSimulateServiceImpl extends ServiceImpl<QuestionSimulateMap
         bo.setType2Ids(type2_ids);
         bo.setType3Ids(type3_ids);
         bo.setType4Ids(type4_ids);
+        bo.setUserId(userId);
+        bo.setExamConfigId(vo.getId());
         this.insertByAddBo(bo);
-        return null;
+        QuestionSimulate add = BeanUtil.toBean(bo, QuestionSimulate.class);
+        validEntityBeforeSave(add);
+        add.setCreateTime(DateUtils.getNowTime());
+        add.setUpdateTime(DateUtils.getNowTime());
+        if(!this.save(add)){
+            throw new CustomException("模拟试卷创建失败");
+        }
+        Map<String,Object> result = new HashMap<>();
+        result.put("simulateId",add.getSimulateId());
+        result.put("list",listToatl);
+        return result;
     }
 
     @Override

+ 9 - 3
zhongzheng-system/src/main/resources/mapper/modules/bank/QuestionMapper.xml

@@ -22,11 +22,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectQuestionSimulateList" parameterType="map"  resultMap="QuestionResult">
         SELECT
-            *
+            q.*
         FROM
-            question
+            question_bank qb
+                LEFT JOIN question_bank_chapter qbc
+                          on qb.bank_id = qbc.bank_id
+                LEFT JOIN question_bank_section qbs
+                          on qbc.bank_chapter_id = qbs.bank_chapter_id
+                LEFT JOIN question q
+                          on qbs.bank_section_id = q.bank_section_id
         WHERE
-            bank_section_id = #{bankSectionId}
+            qb.bank_id = #{bankId}
           AND type = #{type}
         ORDER BY
             RAND()