From 4a322070ca1465f94e5aaa96c31bbd3aa1b26fb1 Mon Sep 17 00:00:00 2001 From: flower Date: Mon, 21 Jan 2019 01:19:25 +0800 Subject: [PATCH] =?UTF-8?q?web=20=E8=80=83=E8=AF=95=20=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CmsExaminationController.java | 177 ++++++++++++++++++ .../cms/controller/CmsPracticeController.java | 53 ++++++ .../templates/web/examination/detail.html | 95 ++++++++++ .../templates/web/examination/list.html | 124 ++++++++++++ .../main/resources/templates/web/index.html | 4 +- .../templates/web/practice/detail.html | 95 ++++++++++ .../templates/web/practice/list.html | 83 ++++++++ .../controller/ApiExaminationController.java | 7 +- .../controller/ApiPracticeController.java | 2 +- 9 files changed, 634 insertions(+), 6 deletions(-) create mode 100644 ruoyi-cms/src/main/java/com/ruoyi/cms/controller/CmsExaminationController.java create mode 100644 ruoyi-cms/src/main/java/com/ruoyi/cms/controller/CmsPracticeController.java create mode 100644 ruoyi-cms/src/main/resources/templates/web/examination/detail.html create mode 100644 ruoyi-cms/src/main/resources/templates/web/examination/list.html create mode 100644 ruoyi-cms/src/main/resources/templates/web/practice/detail.html create mode 100644 ruoyi-cms/src/main/resources/templates/web/practice/list.html diff --git a/ruoyi-cms/src/main/java/com/ruoyi/cms/controller/CmsExaminationController.java b/ruoyi-cms/src/main/java/com/ruoyi/cms/controller/CmsExaminationController.java new file mode 100644 index 000000000..4d5b0688f --- /dev/null +++ b/ruoyi-cms/src/main/java/com/ruoyi/cms/controller/CmsExaminationController.java @@ -0,0 +1,177 @@ +package com.ruoyi.cms.controller; + +import com.ruoyi.common.base.AjaxResult; +import com.ruoyi.exam.domain.*; +import com.ruoyi.exam.service.*; +import com.ruoyi.framework.jwt.JwtUtil; +import com.ruoyi.framework.web.exception.base.BaseException; +import com.ruoyi.system.domain.SysUser; +import com.ruoyi.system.service.ISysUserService; +import com.sun.tools.internal.ws.wsdl.document.jaxws.Exception; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.*; + +/** + * Created by flower on 2019/1/21. + */ +@Controller +@RequestMapping("/web") +public class CmsExaminationController { + private String prefix = "web/examination/"; + + @Autowired + private IExamExaminationService examExaminationService; + + @Autowired + private IExamPaperService examPaperService; + + @Autowired + private IExamUserExaminationService examUserExaminationService; + + @Autowired + private ISysUserService sysUserService; + + @Autowired + private IExamExaminationUserService examExaminationUserService; + + @Autowired + private IExamUserExaminationQuestionService examUserExaminationQuestionService; + + @Autowired + private IExamQuestionService examQuestionService; + + @Autowired + private IExamPaperQuestionService examPaperQuestionService; + + @Autowired + private IExamPaperTypeNumberService examPaperTypeNumberService; + + @RequestMapping("/examination") + @GetMapping() + public String list() { + return prefix + "list"; + } + + @RequestMapping("/examination/start/{id}") + @GetMapping() + public String start(@PathVariable String id, ModelMap mmap) { + ExamExamination examExamination = examExaminationService.selectById( id ); + SysUser sysUser = sysUserService.selectUserByLoginName( JwtUtil.getLoginName() ); + Integer userId = Integer.parseInt( sysUser.getUserId().toString() ); + //考试类型 + String type = examExamination.getType(); + //试卷ID + Integer examPaperId = examExamination.getExamPaperId(); + //考试次数 + Integer examNumber = examExamination.getExamNumber(); + //考试时长 + Integer timeLength = examExamination.getTimeLength(); + //考试记录ID + Integer examUserExaminationId = -1; + if(1==1){ + throw new BaseException("已超过" + examNumber + "次考试,"); + } + ExamUserExamination insert = new ExamUserExamination(); + //正式考试 + if (type.equals( "2" )) { + ExamUserExamination examUserExamination = new ExamUserExamination(); + examUserExamination.setVipUserId( userId ); + examUserExamination.setExamPaperId( examPaperId ); + examUserExamination.setExamExaminationId( Integer.parseInt( id ) ); + //考试记录集合 + List userExamination = examUserExaminationService.selectLastOne( examUserExamination ); + // 最后一次考试 + ExamUserExamination last; + + //超过考试次数 + if (userExamination.size() >= examNumber) { + + last = userExamination.get( 0 ); + //最后一次考试已交卷,直接返回 + if (last.getUpdateDate() != null && !last.getUpdateDate().equals( "" )) { + throw new BaseException("已超过" + examNumber + "次考试,"); +// return error( 500, "已超过" + examNumber + "次考试," ); + } else { + // 最后一次考试未交卷,但超过考试时长,直接返回 + if (last.getCreateDate().getTime() + timeLength * 60 * 1000 < new Date().getTime()) { + throw new BaseException( "已超过" + examNumber + "次考试," ); + } + } + + } + + if (userExamination.size() <= 0 //考试次数小于0 + || userExamination.get( 0 ).getUpdateDate() != null //最后一次考试已交卷 + || userExamination.get( 0 ).getCreateDate().getTime() + timeLength * 60 * 1000 < new Date().getTime()//最后一次考试,已超过考过时长 + ) { + insert.setExamExaminationId( Integer.parseInt( id ) ); + insert.setVipUserId( userId ); + insert.setCreateDate( new Date() ); + insert.setExamPaperId( examPaperId ); + insert.setDelFlag( "0" ); + insert.setScore( 0 ); + examUserExaminationService.insertOne( insert ); + examUserExaminationId = insert.getId(); + } else { + examUserExaminationId = userExamination.get( 0 ).getId(); + } + + } + ExamPaper examPaper = examPaperService.selectById(examPaperId); + List data = new ArrayList<>(); + List list = examPaperService.selectQuestionAndItemByPaperId( examPaperId ); + //随机试卷 + if(examPaper.getType().equals("2")){ + Collections.shuffle( list ); + ExamPaperTypeNumber examPaperTypeNumber = new ExamPaperTypeNumber(); + examPaperTypeNumber.setExamPaperId(examPaperId); + List examPaperTypeNumbers = examPaperTypeNumberService.selectList(examPaperTypeNumber); + //三种题型的数量 + int one=0,two=0,three=0; + for (ExamPaperTypeNumber item : examPaperTypeNumbers) { + if(item.getExamQuestionType()==1){ + one = item.getNumber(); + } + if(item.getExamQuestionType()==2){ + two = item.getNumber(); + } + if(item.getExamQuestionType()==3){ + three = item.getNumber(); + } + } + for (ExamQuestionVO item : list) { + if(item.getType().equals("1")&&one>0){ + data.add(item); + one--; + } + if(item.getType().equals("2")&&two>0){ + data.add(item); + two--; + } + if(item.getType().equals("3")&&three>0){ + data.add(item); + three--; + } + } + }else{ + data = list; + } + //是否乱序 + if (examExamination.getQuestionDisorder().equals( "2" )) { + Collections.shuffle( list ); + } + + mmap.put( "data", data ); + mmap.put( "examUserExaminationId", examUserExaminationId ); + mmap.put( "examExamination", examExamination ); + return prefix+"deatil"; + } + + +} diff --git a/ruoyi-cms/src/main/java/com/ruoyi/cms/controller/CmsPracticeController.java b/ruoyi-cms/src/main/java/com/ruoyi/cms/controller/CmsPracticeController.java new file mode 100644 index 000000000..335ded1a6 --- /dev/null +++ b/ruoyi-cms/src/main/java/com/ruoyi/cms/controller/CmsPracticeController.java @@ -0,0 +1,53 @@ +package com.ruoyi.cms.controller; + +import com.ruoyi.exam.domain.ExamQuestionVO; +import com.ruoyi.exam.service.IExamPracticeService; +import com.ruoyi.exam.service.IExamQuestionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +/** + * Created by flower on 2019/1/18. + */ +@Controller +@RequestMapping("/web") +public class CmsPracticeController { + + @Autowired + private IExamPracticeService examPracticeService; + + + @Autowired + private IExamQuestionService examQuestionService; + + + private String prefix = "web/practice/"; + + @RequestMapping("/practice") + @GetMapping() + public String list() { + return prefix + "list"; + } + + @RequestMapping("/practice/start/{id}") + @GetMapping() + public String start(@PathVariable String id, ModelMap mmap) { + HashMap map = new HashMap<>(); + map.put("practiceId", id); + List result = examQuestionService.selectQuestionListByPracticeId(map); + if (map.containsKey("disorder") && map.get("disorder").toString().equals("1")) { + Collections.shuffle(result); + } + mmap.put("data", result); + return prefix + "detail"; + } +} diff --git a/ruoyi-cms/src/main/resources/templates/web/examination/detail.html b/ruoyi-cms/src/main/resources/templates/web/examination/detail.html new file mode 100644 index 000000000..5dcf8b0a8 --- /dev/null +++ b/ruoyi-cms/src/main/resources/templates/web/examination/detail.html @@ -0,0 +1,95 @@ + + + +
+ + +
+ +
+ +
+
+
+
+ +
+
+
+ (单选) + (多选) + (判断) +
+
+ + + [[${item.number}]]: + +
+
+ +
+ +
+ + +
+ + + + +
+ +
+
+
+ + + + + + + + + + + + \ No newline at end of file diff --git a/ruoyi-cms/src/main/resources/templates/web/examination/list.html b/ruoyi-cms/src/main/resources/templates/web/examination/list.html new file mode 100644 index 000000000..97f39cd95 --- /dev/null +++ b/ruoyi-cms/src/main/resources/templates/web/examination/list.html @@ -0,0 +1,124 @@ + + + + + + + +
+ +
+ + + +
+
+
+
+
+ + + + + + +
+ +
+
+
+ + + + + + + + + + + + \ No newline at end of file diff --git a/ruoyi-cms/src/main/resources/templates/web/index.html b/ruoyi-cms/src/main/resources/templates/web/index.html index 14ff9dae5..b68ad9aa5 100644 --- a/ruoyi-cms/src/main/resources/templates/web/index.html +++ b/ruoyi-cms/src/main/resources/templates/web/index.html @@ -31,10 +31,10 @@ 课程
  • - 练习 + 练习
  • - 考试 + 考试
  • diff --git a/ruoyi-cms/src/main/resources/templates/web/practice/detail.html b/ruoyi-cms/src/main/resources/templates/web/practice/detail.html new file mode 100644 index 000000000..5dcf8b0a8 --- /dev/null +++ b/ruoyi-cms/src/main/resources/templates/web/practice/detail.html @@ -0,0 +1,95 @@ + + + +
    + + +
    + +
    + +
    +
    +
    +
    + +
    +
    +
    + (单选) + (多选) + (判断) +
    +
    + + + [[${item.number}]]: + +
    +
    + +
    + +
    + + +
    + + + + +
    + +
    +
    +
    + + + + + + + + + + + + \ No newline at end of file diff --git a/ruoyi-cms/src/main/resources/templates/web/practice/list.html b/ruoyi-cms/src/main/resources/templates/web/practice/list.html new file mode 100644 index 000000000..b4061fdeb --- /dev/null +++ b/ruoyi-cms/src/main/resources/templates/web/practice/list.html @@ -0,0 +1,83 @@ + + + + + + + +
    + +
    + + + +
    +
    +
    +
    +
    + + + + + + +
    + +
    +
    +
    + + + + + + + + + + + + \ No newline at end of file diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ApiExaminationController.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ApiExaminationController.java index 4475f0c25..01c3f6c7e 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ApiExaminationController.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ApiExaminationController.java @@ -60,11 +60,12 @@ public class ApiExaminationController extends BaseController { @GetMapping("/v1/examination/list") public AjaxResult list(ExamExamination examExamination) { - SysUser sysUser = sysUserService.selectUserByLoginName( JwtUtil.getLoginName() ); - +// SysUser sysUser = sysUserService.selectUserByLoginName( JwtUtil.getLoginName() ); +// Map map = new HashMap<>(); map.put( "ination", examExamination ); - map.put( "userId", sysUser.getUserId() ); +// map.put( "userId", sysUser.getUserId() ); + map.put( "userId", 1 ); List list = examExaminationService.selectListFromWeb( map ); AjaxResult success = success( "查询成功" ); success.put( "data", list ); diff --git a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ApiPracticeController.java b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ApiPracticeController.java index 989c07511..ad1f1cf4c 100644 --- a/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ApiPracticeController.java +++ b/ruoyi-exam/src/main/java/com/ruoyi/exam/controller/ApiPracticeController.java @@ -37,7 +37,7 @@ public class ApiPracticeController extends BaseController { * @return */ @GetMapping("/v1/practice/list") - public AjaxResult list(@RequestParam ExamPractice examPractice) { + public AjaxResult list(ExamPractice examPractice) { List list = examPracticeService.selectListFromWeb(examPractice); AjaxResult success = success("查询成功");