Sfoglia il codice sorgente

刷题知识点及总量统计

mingfu 3 settimane fa
parent
commit
d99067bfe6

+ 27 - 9
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontExamController.java

@@ -4,28 +4,32 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.dz.service.IDzControlService;
 import com.ruoyi.enums.PaperType;
 import com.ruoyi.learn.domain.AnswerSheet;
+import com.ruoyi.mxjb.domain.MxjbContants;
 import com.ruoyi.system.service.ISysUserService;
+import com.ruoyi.web.domain.PaperDto;
+import com.ruoyi.web.service.CacheService;
 import com.ruoyi.web.service.ExamService;
 import com.ruoyi.web.service.PaperService;
+import com.ruoyi.web.service.SyTestMajorService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Map;
+
 @RestController
 @RequestMapping("/front/exam")
 @Api(tags = "前台-学习-考试练习")
 public class FrontExamController {
-    private final IDzControlService controlService;
-    private final ISysUserService sysUserService;
     private final ExamService examService;
-    private final PaperService paperService;
+    private final SyTestMajorService syTestMajorService;
+    private final CacheService cacheService;
 
-    public FrontExamController(IDzControlService controlService, ISysUserService sysUserService, ExamService examService, PaperService paperService) {
-        this.controlService = controlService;
-        this.sysUserService = sysUserService;
+    public FrontExamController(ExamService examService, SyTestMajorService syTestMajorService, CacheService cacheService) {
         this.examService = examService;
-        this.paperService = paperService;
+        this.syTestMajorService = syTestMajorService;
+        this.cacheService = cacheService;
     }
 
     // 试卷: 真题卷,批次测试卷,自组卷, 生成考试记录
@@ -33,9 +37,17 @@ public class FrontExamController {
     // 组卷: 知识点 错题 必刷题 实时组卷后才生成记录
     @ApiOperation("01 开卷")
     @PostMapping(value = "openExaminee")
-    public AjaxResult openExaminee(@ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed,
-                                   @ApiParam("考卷类型PaperType") @RequestParam PaperType paperType,
+    public AjaxResult openExaminee(@ApiParam("0默认1价值2职业3知识") @RequestParam(required = false) Integer testType,
+                                   @ApiParam("定向") @RequestParam(defaultValue = "false") boolean directed,
+                                   @ApiParam("考卷类型PaperType") @RequestParam(required = false) PaperType paperType,
                                    @ApiParam("考卷类型关联ID") @RequestParam Long relateId) {
+        if(null != testType && testType > 0) {
+            PaperDto paperDto = syTestMajorService.loadPaperByTestMajorTypeId(testType);
+            Map<String, String> stateMap = cacheService.selectDictDataMapByType(MxjbContants.StateTypeExaminee);
+            paperDto.setStateStr(stateMap.get(String.valueOf(paperDto.getState())));
+            paperDto.calculateAllow();
+            return AjaxResult.success(paperDto);
+        }
         return AjaxResult.success(examService.openExaminee(directed, paperType, relateId));
     }
 
@@ -63,6 +75,12 @@ public class FrontExamController {
         return AjaxResult.success();
     }
 
+    @ApiOperation("02 原交卷,测试")
+    @PostMapping(value = "commitTestPaper")
+    public AjaxResult commitExamineePaper(@RequestBody PaperDto paperDto) {
+        return syTestMajorService.saveTestPaper(paperDto);
+    }
+
     /*@ApiOperation("02 答题")
     @PostMapping(value = "commitExamineeQuestion")
     public AjaxResult commitExamineeQuestion(@RequestBody PaperDto paperDto) {

+ 13 - 19
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontStudentController.java

@@ -28,6 +28,7 @@ import com.ruoyi.learn.service.ILearnPlanService;
 import com.ruoyi.learn.service.ILearnPlanStudyService;
 import com.ruoyi.sy.service.ISyMajorService;
 import com.ruoyi.system.service.ISysUserService;
+import com.ruoyi.web.service.LearnStatService;
 import com.ruoyi.web.service.LearnTeacherService;
 import com.ruoyi.web.service.StudentService;
 import io.swagger.annotations.Api;
@@ -60,9 +61,10 @@ public class FrontStudentController extends BaseController {
     private final StudentService studentService;
     private final IDzSubjectService dzSubjectService;
     private final LearnTeacherService learnTeacherService;
+    private final LearnStatService learnStatService;
 
     public FrontStudentController(IDzControlService dzControlService, IAEnrollUniversityService universityService, ISyMajorService syMajorService, ISysUserService sysUserService,
-                                  ILearnPlanService learnPlanService, ILearnPlanStudyService learnPlanStudyService, IAMarjorPlanService marjorPlanService, ILearnDirectedKnowledgeService learnDirectedKnowledgeService, StudentService studentService, IDzSubjectService dzSubjectService, LearnTeacherService learnTeacherService) {
+                                  ILearnPlanService learnPlanService, ILearnPlanStudyService learnPlanStudyService, IAMarjorPlanService marjorPlanService, ILearnDirectedKnowledgeService learnDirectedKnowledgeService, StudentService studentService, IDzSubjectService dzSubjectService, LearnTeacherService learnTeacherService, LearnStatService learnStatService) {
         this.dzControlService = dzControlService;
         this.universityService = universityService;
         this.syMajorService = syMajorService;
@@ -74,6 +76,7 @@ public class FrontStudentController extends BaseController {
         this.studentService = studentService;
         this.dzSubjectService = dzSubjectService;
         this.learnTeacherService = learnTeacherService;
+        this.learnStatService = learnStatService;
     }
 
     @ApiOperation("02 全部科目")
@@ -306,8 +309,7 @@ public class FrontStudentController extends BaseController {
     @GetMapping("record/knowledge")
     public TableDataInfo getRecordKnowledge()
     {
-        JSONObject data = JSONObject.of("name", "", "directed", true, "rate", 82, "total", 1470);
-        List<JSONObject> list = Lists.newArrayList(data);
+        List<JSONObject> list = learnStatService.getRecordKnowledge(SecurityUtils.getUserId());
         return getDataTable(list);
     }
 
@@ -345,28 +347,20 @@ public class FrontStudentController extends BaseController {
 
     @ApiOperation("55 记录-计划刷题")
     @GetMapping("record/planStudy")
-    public AjaxResult getRecordPlanStudy(Integer year, Integer monthSeq, Integer weekSeq)
+    public AjaxResult getRecordPlanStudy(@ApiParam String reportMonth)
     {
-        JSONObject result = new JSONObject();
-        result.put("total", 140);
-        result.put("rate", 85);
-        result.put("studyDays", 3);
-        JSONObject data = JSONObject.of("date", "2025.09.03", "study", "90", "rate", "80", "pass", true);
-        List<JSONObject> list = Lists.newArrayList(data);
-        result.put("list", list);
-        return AjaxResult.success(result);
+        try {
+            Date date = DateUtils.parseDate(reportMonth, "yyyy-MM-dd");
+            return AjaxResult.success(learnStatService.getRecordPlanStudy(SecurityUtils.getUserId(), date));
+        } catch (ParseException e) {
+            throw new ValidationException("日期格式错误");
+        }
     }
 
     @ApiOperation("56 记录-视频学习")
     @GetMapping("record/video")
     public AjaxResult getRecordVideo()
     {
-        JSONObject result = new JSONObject();
-        result.put("total", 98);
-        result.put("study", 759);
-        JSONObject data = JSONObject.of("name", "充分条件", "date", "2025.09.11", "study", "02:46");
-        List<JSONObject> list = Lists.newArrayList(data);
-        result.put("list", list);
-        return AjaxResult.success(result);
+        return AjaxResult.success(learnStatService.getRecordVideo(SecurityUtils.getUserId()));
     }
 }

+ 76 - 0
ie-admin/src/main/java/com/ruoyi/web/service/LearnStatService.java

@@ -0,0 +1,76 @@
+package com.ruoyi.web.service;
+
+import cn.hutool.core.lang.Dict;
+import com.alibaba.fastjson2.JSONObject;
+import com.alibaba.fastjson2.util.DateUtils;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.learn.domain.LearnStudent;
+import com.ruoyi.learn.mapper.LearnAnswerMapper;
+import com.ruoyi.learn.service.ILearnStudentService;
+import com.ruoyi.mingxue.mapper.CustomerVideoWatchesMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@Service
+public class LearnStatService {
+    private final CustomerVideoWatchesMapper customerVideoWatchesMapper;
+    private final LearnAnswerMapper answerMapper;
+    private final ILearnStudentService learnStudentService;
+    private final LearnTeacherService learnTeacherService;
+
+    public LearnStatService(CustomerVideoWatchesMapper customerVideoWatchesMapper, LearnAnswerMapper answerMapper, LearnTeacherService learnTeacherService, ILearnStudentService learnStudentService, LearnTeacherService learnTeacherService1) {
+        this.customerVideoWatchesMapper = customerVideoWatchesMapper;
+        this.answerMapper = answerMapper;
+        this.learnStudentService = learnStudentService;
+        this.learnTeacherService = learnTeacherService1;
+    }
+
+    public List<JSONObject> getRecordKnowledge(Long studentId) {
+        LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(studentId);
+        Set<Long> knowledgeIdSet = null != learnStudent ? learnTeacherService.getKnowledgeIdSet(new Long[] { learnStudent.getMajorPlanId() }) : Sets.newHashSet(0L);
+        List<JSONObject> list = answerMapper.selectKnowledgeStats(Dict.create().set("studentId", studentId).set("knowIds", knowledgeIdSet));
+        list.forEach(o -> {
+            o.put("directed", "1".equals(o.get("directed")));
+        });
+        return list;
+    }
+
+    public JSONObject getRecordVideo(Long studentId) {
+        Map cond = Dict.create().set("studentId", studentId);
+        JSONObject header = customerVideoWatchesMapper.selectLearnStatsHeader(cond);
+        JSONObject result = new JSONObject();
+        result.put("total", header.getIntValue("total"));
+        result.put("study", header.getIntValue("value"));
+        List<JSONObject> list = Lists.newArrayList();
+        customerVideoWatchesMapper.selectLearnStatsDetail(cond).stream().forEach(s -> {
+            JSONObject data = JSONObject.of("name", s.getString("name"), "date", DateUtils.format(s.getDate("time"), "yyyy-MM-dd"), "study", s.getString("value"));
+            list.add(data);
+        });
+        result.put("list", list);
+        return result;
+    }
+
+    public JSONObject getRecordPlanStudy(Long studentId, Date date) {
+        Map cond = Dict.create().set("studentId", studentId).set("date", date);
+        JSONObject header = answerMapper.selectQuestionStatsHeader(cond);
+        JSONObject result = new JSONObject();
+        result.put("total", header.getIntValue("total"));
+        result.put("rate", header.getIntValue("rate"));
+        result.put("studyDays", header.getIntValue("time"));
+        List<JSONObject> list = Lists.newArrayList();
+        answerMapper.selectQuestionStatsDetail(cond).stream().forEach(s -> {
+            JSONObject data = JSONObject.of("date", DateUtils.format(s.getDate("time"), "yyyy-MM-dd"), "study", s.getString("value"), "rate", s.getString("rate"));
+            list.add(data);
+        });
+        result.put("list", list);
+        return result;
+
+
+    }
+}

+ 7 - 0
ie-system/src/main/java/com/ruoyi/learn/mapper/LearnAnswerMapper.java

@@ -1,6 +1,9 @@
 package com.ruoyi.learn.mapper;
 
 import java.util.List;
+import java.util.Map;
+
+import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.learn.domain.LearnAnswer;
 
 /**
@@ -11,6 +14,10 @@ import com.ruoyi.learn.domain.LearnAnswer;
  */
 public interface LearnAnswerMapper 
 {
+    List<JSONObject> selectKnowledgeStats(Map cond);
+    JSONObject selectQuestionStatsHeader(Map cond);
+    List<JSONObject> selectQuestionStatsDetail(Map cond);
+
     /**
      * 查询答卷答案
      * 

+ 4 - 0
ie-system/src/main/java/com/ruoyi/mingxue/mapper/CustomerVideoWatchesMapper.java

@@ -1,5 +1,6 @@
 package com.ruoyi.mingxue.mapper;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.mingxue.domain.CustomerVideoWatches;
 
 import java.util.List;
@@ -13,6 +14,9 @@ import java.util.Map;
  */
 public interface CustomerVideoWatchesMapper
 {
+    JSONObject selectLearnStatsHeader(Map cond);
+    List<JSONObject> selectLearnStatsDetail(Map cond);
+
     /**
      * 查询客户观看视频记录
      *

+ 24 - 0
ie-system/src/main/resources/mapper/learn/LearnAnswerMapper.xml

@@ -27,6 +27,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select answer_id, examinee_id, student_id, question_id, seq, knowledge_id, answer, correct, duration, count, state, score_level, score, score_rate, isMark, isNotKnow, create_time, update_time from learn_answer
     </sql>
 
+    <select id="selectKnowledgeStats" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
+        SELECT a.`knowledge_id` id , kt.`name`, a.`knowledge_id` IN <foreach item="id" collection="knowIds" open="(" separator="," close=")">#{id}</foreach> AS directed
+        , COUNT(*) total, SUM(IF(a.`state` = 1, 1, 0)) `value`, round(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*)) rate
+        FROM `learn_answer` a
+        JOIN `learn_knowledge_tree` kt ON a.`knowledge_id` = kt.`id`
+        WHERE a.`student_id` = #{studentId} and date(a.create_time) = date(#{date})
+        GROUP BY a.`knowledge_id`, directed
+        order by directed desc, rate desc, a.`knowledge_id`
+    </select>
+
+    <select id="selectQuestionStatsHeader" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
+        SELECT COUNT(*) total, SUM(IF(a.`state` = 1, 1, 0)) `value`, round(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*)) rate, COUNT(DISTINCT DATE(a.create_time)) `time`
+          FROM `learn_answer` a
+          WHERE a.`student_id` = #{studentId} and DATE_FORMAT(a.`create_time`, '%Y%m') = DATE_FORMAT(#{date}, '%Y%m')
+    </select>
+
+    <select id="selectQuestionStatsDetail" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
+        SELECT DATE(a.create_time) `time`, COUNT(*) total, SUM(IF(a.`state` = 1, 1, 0)) `value`, round(SUM(IF(a.`state` = 1, 1, 0)) * 100 / COUNT(*)) rate
+          FROM `learn_answer` a
+         WHERE a.`student_id` = #{studentId} and DATE_FORMAT(a.`create_time`, '%Y%m') = DATE_FORMAT(#{date}, '%Y%m')
+         GROUP BY DATE(a.create_time)
+         order by DATE(a.create_time) desc
+    </select>
+
     <select id="selectLearnAnswerList" parameterType="LearnAnswer" resultMap="LearnAnswerResult">
         <include refid="selectLearnAnswerVo"/>
         <where>  

+ 14 - 0
ie-system/src/main/resources/mapper/mingxue/CustomerVideoWatchesMapper.xml

@@ -23,6 +23,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select id, customerCode, section_id, duration, percent, course, title, pict, comment, time ,type from b_customer_video_watches
     </sql>
 
+    <select id="selectLearnStatsHeader" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
+        SELECT COUNT(*) total , round(SUM(vw.`duration` * vw.`percent` / 100.0)) `value`
+        FROM `b_customer_video_watches` vw
+        WHERE vw.`customerCode` = #{studentId}
+    </select>
+
+    <select id="selectLearnStatsDetail" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
+        SELECT vw.`title` `name`, date(vw.`time`) `time`, round(vw.`duration` * vw.`percent` / 100.0) `value`
+        FROM `b_customer_video_watches` vw
+        WHERE vw.`customerCode` = #{studentId}
+        group by date(vw.`time`)
+        order by date(vw.`time`) desc
+    </select>
+
     <select id="selectCustomerVideoWatchesList" parameterType="CustomerVideoWatches" resultMap="CustomerVideoWatchesResult">
         <include refid="selectCustomerVideoWatchesVo"/>
         <where>