瀏覽代碼

学习计划统计

mingfu 1 月之前
父節點
當前提交
efcc5dcc46

+ 31 - 38
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontStudentController.java

@@ -1,5 +1,8 @@
 package com.ruoyi.web.controller.front;
 
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.LocalDateTimeUtil;
+import cn.hutool.core.lang.Dict;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.google.common.collect.Lists;
@@ -37,7 +40,6 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.validation.ValidationException;
 import java.text.ParseException;
-import java.time.LocalDate;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -181,14 +183,14 @@ public class FrontStudentController extends BaseController {
     @GetMapping("plan")
     public AjaxResult getPlan()
     {
-        return AjaxResult.success(getCurrLearnPlan());
+        return AjaxResult.success(learnPlanService.getCurrLearnPlan());
     }
 
     @ApiOperation("11 保存学习计划")
     @PostMapping("plan")
     public AjaxResult savePlan(@RequestBody LearnPlan plan)
     {
-        LearnPlan curr = getCurrLearnPlan();
+        LearnPlan curr = learnPlanService.getCurrLearnPlan();
         Date today = DateUtils.truncate(new Date(), Calendar.DATE);
         if(null != curr) {
             if(curr.getStatus().equals(1)) {
@@ -218,7 +220,10 @@ public class FrontStudentController extends BaseController {
     @GetMapping("plan/stats")
     public AjaxResult getPlanStats(@ApiParam String reportMonth)
     {
-        LearnPlan curr = getCurrLearnPlan();
+        LearnPlan curr = learnPlanService.getCurrLearnPlan();
+        if(null == curr) {
+            throw new RuntimeException("未配置学习计划");
+        }
         // 统计每天的学习情况, 再汇总
         LearnPlanStudy cond = new LearnPlanStudy();
         cond.setStudentId(SecurityUtils.getLoginUser().getUserId());
@@ -227,48 +232,48 @@ public class FrontStudentController extends BaseController {
         } catch (ParseException e) {
             throw new ValidationException("日期格式错误");
         }
-        List<LearnPlanStudy> studyList = learnPlanStudyService.selectLearnPlanStudyList(cond);
+        List<LearnPlanStudy> studyList = learnPlanStudyService.selectPlanStudyStats(cond);
         Integer doneDay = 0;
         Long videoTimes = 0L;
         Long questionCnt = 0L;
-        Date today = new Date();
-        List<JSONObject> todayStudyList = Lists.newArrayList();
-        JSONObject todayStudy = null;
+        List<Dict> monthStudyList = Lists.newArrayList();
+        Date firstDate = null;
         for(LearnPlanStudy study : studyList) {
             JSONObject planStudy = toStudyStats(study);
-            if(!study.getReportDate().before(today)) { // 今天
-                doneDay++;
+            doneDay++;
+            if(null != study.getVideoTime()) {
                 videoTimes += study.getVideoTime();
-                questionCnt = study.getQuestionCount();
-            } else {
-                todayStudy = planStudy;
             }
-            todayStudyList.add(planStudy);
+            if(null != study.getQuestionCount()) {
+                questionCnt += study.getQuestionCount();
+            }
+            if(null == firstDate) {
+                firstDate = study.getReportDate();
+            }
+            monthStudyList.add(Dict.create().set("date", DateUtil.format(study.getReportDate(), "yyyy-MM-dd")).set("data", planStudy));
         }
 
-        Integer preDay = 0;
-        if(DateUtils.isSameDay(cond.getReportDate(), DateUtils.truncate(curr.getBeginTime(), Calendar.MONTH))) {
-            Calendar cal = Calendar.getInstance();
-            cal.setTime(curr.getBeginTime());
-            preDay = cal.get(Calendar.DAY_OF_MONTH) - 1;
-        }
+        Integer preDay = 0; // 同月的排队计划开始之前的 历史月不好计算,待定 TODO MF
+//        if(DateUtils.isSameDay(DateUtils.truncate(cond.getReportDate(), Calendar.MONTH), DateUtils.truncate(curr.getBeginTime(), Calendar.MONTH))) {
+//            Calendar cal = Calendar.getInstance();
+//            cal.setTime(curr.getBeginTime());
+//            preDay = cal.get(Calendar.DAY_OF_MONTH) - 1;
+//        }
         JSONObject stats = new JSONObject();
         stats.put("doneDay", doneDay);
-        stats.put("unDoneDay", LocalDate.now().getDayOfMonth() - doneDay - preDay);
+        stats.put("undoneDay", LocalDateTimeUtil.of(cond.getReportDate()).getDayOfMonth() - doneDay - preDay);
         stats.put("videoTimes", videoTimes);
         stats.put("questionCnt", questionCnt);
-        stats.put("studyList", todayStudyList);
-        stats.put("today", todayStudy);
-        stats.put("plan", curr);
+        stats.put("studyList", monthStudyList);
         return AjaxResult.success(stats);
     }
 
     private JSONObject toStudyStats(LearnPlanStudy todayStudy) {
         JSONObject study = new JSONObject();
         study.put("questionCnt", todayStudy.getQuestionCount());
-        study.put("videoTime", todayStudy.getVideoTime());
+        study.put("videoTime", todayStudy.getVideoCount());
         study.put("videoTimes", todayStudy.getVideoTime());
-        study.put("rightRate", "0");
+        study.put("rightRate", Math.round((float)(todayStudy.getRightCount() * 100 / todayStudy.getQuestionCount())));
         return study;
     }
 
@@ -339,16 +344,4 @@ public class FrontStudentController extends BaseController {
         result.put("list", list);
         return AjaxResult.success(result);
     }
-
-    private LearnPlan getCurrLearnPlan() {
-        LearnPlan cond = new LearnPlan();
-        cond.setStudentId(SecurityUtils.getLoginUser().getUserId());
-        cond.setStatus(1);
-        List<LearnPlan> planList = learnPlanService.selectLearnPlanList(cond);
-        if(CollectionUtils.isNotEmpty(planList)) {
-            return planList.get(0);
-        }
-        return null;
-    }
-
 }

+ 9 - 1
ie-admin/src/main/java/com/ruoyi/web/service/ExamService.java

@@ -14,6 +14,8 @@ import com.ruoyi.ie.service.IAMarjorPlanService;
 import com.ruoyi.learn.domain.*;
 import com.ruoyi.learn.mapper.*;
 import com.ruoyi.learn.service.ILearnPaperService;
+import com.ruoyi.learn.service.ILearnPlanService;
+import com.ruoyi.learn.service.impl.LearnPlanServiceImpl;
 import com.ruoyi.system.service.ISysUserService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -32,6 +34,7 @@ public class ExamService {
     private final LearnAnswerMapper learnAnswerMapper;
     private final LearnExamineeMapper learnExamineeMapper;
     private final LearnStudentMapper learnStudentMapper;
+    private final ILearnPlanService learnPlanService;
     private Set<PaperType> paperTypeSet = Sets.newHashSet(PaperType.Real, PaperType.Custom, PaperType.Test);
     private final LearnPaperMapper paperMapper;
     private final LearnKnowledgeTreeMapper knowledgeTreeMapper;
@@ -41,7 +44,7 @@ public class ExamService {
     private final IAMarjorPlanService marjorPlanService;
     private final ISysUserService sysUserService;
 
-    public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService, LearnAnswerMapper learnAnswerMapper, LearnExamineeMapper learnExamineeMapper, ISysUserService sysUserService, LearnStudentMapper learnStudentMapper) {
+    public ExamService(LearnPaperMapper paperMapper, LearnKnowledgeTreeMapper knowledgeTreeMapper, LearnExamineeMapper examineeMapper, ILearnPaperService learnPaperService, PaperService paperService, IAMarjorPlanService marjorPlanService, LearnAnswerMapper learnAnswerMapper, LearnExamineeMapper learnExamineeMapper, ISysUserService sysUserService, LearnStudentMapper learnStudentMapper, ILearnPlanService learnPlanService) {
         this.paperMapper = paperMapper;
         this.knowledgeTreeMapper = knowledgeTreeMapper;
         this.examineeMapper = examineeMapper;
@@ -52,6 +55,7 @@ public class ExamService {
         this.learnExamineeMapper = learnExamineeMapper;
         this.sysUserService = sysUserService;
         this.learnStudentMapper = learnStudentMapper;
+        this.learnPlanService = learnPlanService;
     }
 
     /**
@@ -164,6 +168,10 @@ public class ExamService {
             up.setId(answerSheet.getPaperId());
             up.setStatus(PaperStatus.Valid.getVal());
             paperMapper.updateLearnPaper(up);
+
+            if(PaperType.Practice.getVal().equals(exitExaminee.getPaperType())) {
+                learnPlanService.updateLearnPlan(exitExaminee.getStudentId());
+            }
         }
     }
 

+ 4 - 3
ie-admin/src/main/java/com/ruoyi/web/service/PaperService.java

@@ -368,12 +368,13 @@ public class PaperService {
                 knowTypeAssign = new KnowTypeAssign();
                 knowTypeAssign.setKnowId(q.getKnowledgeId());
                 knowTypeAssign.setType(q.getQtpye());
-                knowTypeAssignMap.put(key, knowTypeAssign);
-            }
-            if (1 == index) {
                 knowTypeAssign.total = 0L;
                 knowTypeAssign.exclAssign = 0L;
                 knowTypeAssign.assign = 0L;
+                knowTypeAssign.exclCount = 0L;
+                knowTypeAssignMap.put(key, knowTypeAssign);
+            }
+            if (1 == index) {
                 knowTypeAssign.exclCount = q.getNumber();
             } else {
                 knowTypeAssign.total = q.getNumber() - knowTypeAssign.exclCount;

+ 16 - 6
ie-system/src/main/java/com/ruoyi/learn/domain/LearnPlanStudy.java

@@ -45,6 +45,8 @@ public class LearnPlanStudy extends BaseEntity
     @Excel(name = "完成题数")
     private Long questionCount;
 
+    @Excel(name = "完成题数")
+    private Long rightCount;
 
     /** 完成视频时间 */
     @Excel(name = "完成视频数量")
@@ -56,11 +58,11 @@ public class LearnPlanStudy extends BaseEntity
 
     /** 计划做题数 */
     @Excel(name = "计划做题数")
-    private Long questionPlan;
+    private Integer questionPlan;
 
     /** 计划视频时间 */
     @Excel(name = "计划视频时间")
-    private Long videoPlan;
+    private Integer videoPlan;
 
     public void setId(String id) 
     {
@@ -132,6 +134,14 @@ public class LearnPlanStudy extends BaseEntity
         return questionCount;
     }
 
+    public Long getRightCount() {
+        return rightCount;
+    }
+
+    public void setRightCount(Long rightCount) {
+        this.rightCount = rightCount;
+    }
+
     public Long getVideoCount() {
         return videoCount;
     }
@@ -150,22 +160,22 @@ public class LearnPlanStudy extends BaseEntity
         return videoTime;
     }
 
-    public void setQuestionPlan(Long questionPlan) 
+    public void setQuestionPlan(Integer questionPlan)
     {
         this.questionPlan = questionPlan;
     }
 
-    public Long getQuestionPlan() 
+    public Integer getQuestionPlan()
     {
         return questionPlan;
     }
 
-    public void setVideoPlan(Long videoPlan) 
+    public void setVideoPlan(Integer videoPlan)
     {
         this.videoPlan = videoPlan;
     }
 
-    public Long getVideoPlan() 
+    public Integer getVideoPlan()
     {
         return videoPlan;
     }

+ 4 - 0
ie-system/src/main/java/com/ruoyi/learn/mapper/LearnPlanStudyMapper.java

@@ -1,6 +1,7 @@
 package com.ruoyi.learn.mapper;
 
 import java.util.List;
+
 import com.ruoyi.learn.domain.LearnPlanStudy;
 
 /**
@@ -11,6 +12,9 @@ import com.ruoyi.learn.domain.LearnPlanStudy;
  */
 public interface LearnPlanStudyMapper 
 {
+    public List<LearnPlanStudy> selectQuestionStats(LearnPlanStudy learnPlanStudy);
+    public List<LearnPlanStudy> selectVideoStats(LearnPlanStudy learnPlanStudy);
+
     /**
      * 查询学生计划执行情况
      * 

+ 3 - 0
ie-system/src/main/java/com/ruoyi/learn/service/ILearnPlanService.java

@@ -11,6 +11,9 @@ import com.ruoyi.learn.domain.LearnPlan;
  */
 public interface ILearnPlanService 
 {
+    public void updateLearnPlan(Long studentId);
+    public LearnPlan getCurrLearnPlan();
+
     /**
      * 查询学习计划
      * 

+ 2 - 0
ie-system/src/main/java/com/ruoyi/learn/service/ILearnPlanStudyService.java

@@ -11,6 +11,8 @@ import com.ruoyi.learn.domain.LearnPlanStudy;
  */
 public interface ILearnPlanStudyService 
 {
+    List<LearnPlanStudy> selectPlanStudyStats(LearnPlanStudy learnPlanStudy);
+
     /**
      * 查询学生计划执行情况
      * 

+ 34 - 0
ie-system/src/main/java/com/ruoyi/learn/service/impl/LearnPlanServiceImpl.java

@@ -1,7 +1,13 @@
 package com.ruoyi.learn.service.impl;
 
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.learn.domain.LearnPlanStudy;
+import com.ruoyi.learn.mapper.LearnPlanStudyMapper;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.learn.mapper.LearnPlanMapper;
@@ -19,6 +25,34 @@ public class LearnPlanServiceImpl implements ILearnPlanService
 {
     @Autowired
     private LearnPlanMapper learnPlanMapper;
+    @Autowired
+    private LearnPlanStudyMapper learnPlanStudyMapper;
+
+    public void updateLearnPlan(Long studentId) {
+        LearnPlan curr = getCurrLearnPlan();
+        LearnPlanStudy cond = new LearnPlanStudy();
+        cond.setStudentId(studentId);
+        cond.setPlanId(curr.getId());
+        cond.setReportDate(DateUtils.truncate(new Date(), Calendar.DATE));
+        List<LearnPlanStudy> learnPlanStudyList = learnPlanStudyMapper.selectLearnPlanStudyList(cond);
+        if(CollectionUtils.isEmpty(learnPlanStudyList)) {
+            cond.setQuestionPlan(curr.getQuestionCnt());
+            cond.setVideoPlan(curr.getVideoTime());
+            learnPlanStudyMapper.insertLearnPlanStudy(cond);
+        }
+
+    }
+
+    public LearnPlan getCurrLearnPlan() {
+        LearnPlan cond = new LearnPlan();
+        cond.setStudentId(SecurityUtils.getLoginUser().getUserId());
+        cond.setStatus(1);
+        List<LearnPlan> planList = learnPlanMapper.selectLearnPlanList(cond);
+        if(CollectionUtils.isNotEmpty(planList)) {
+            return planList.get(0);
+        }
+        return null;
+    }
 
     /**
      * 查询学习计划

+ 24 - 0
ie-system/src/main/java/com/ruoyi/learn/service/impl/LearnPlanStudyServiceImpl.java

@@ -1,6 +1,10 @@
 package com.ruoyi.learn.service.impl;
 
+import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 import com.ruoyi.common.utils.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -20,6 +24,26 @@ public class LearnPlanStudyServiceImpl implements ILearnPlanStudyService
     @Autowired
     private LearnPlanStudyMapper learnPlanStudyMapper;
 
+    public List<LearnPlanStudy> selectPlanStudyStats(LearnPlanStudy learnPlanStudy) {
+        Map<Date, LearnPlanStudy> questionMap = learnPlanStudyMapper.selectQuestionStats(learnPlanStudy).stream().collect(Collectors.toMap(LearnPlanStudy::getReportDate, t -> t));
+        Map<Date, LearnPlanStudy> videoMap = learnPlanStudyMapper.selectVideoStats(learnPlanStudy).stream().collect(Collectors.toMap(LearnPlanStudy::getReportDate, t -> t));
+
+        List<LearnPlanStudy> studyList = learnPlanStudyMapper.selectLearnPlanStudyList(learnPlanStudy);
+        for(LearnPlanStudy study : studyList) {
+            LearnPlanStudy question = questionMap.get(study.getReportDate());
+            LearnPlanStudy video = videoMap.get(study.getReportDate());
+            if(null != question) {
+                study.setQuestionCount(question.getQuestionCount());
+                study.setRightCount(question.getRightCount());
+            }
+            if(null != video) {
+                study.setVideoCount(video.getVideoCount());
+                study.setVideoTime(video.getVideoTime());
+            }
+        }
+        return studyList;
+    }
+
     /**
      * 查询学生计划执行情况
      * 

+ 15 - 0
ie-system/src/main/resources/mapper/learn/LearnPlanStudyMapper.xml

@@ -23,6 +23,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select id, student_id, plan_id, month_seq, week_seq, report_date, question_count, video_count, video_time, question_plan, video_plan, update_time from learn_plan_study
     </sql>
 
+    <select id="selectQuestionStats" parameterType="LearnPlanStudy" resultMap="LearnPlanStudyResult">
+        SELECT DATE(a.`create_time`) report_date, COUNT(*) question_count, SUM(IF(state = 1, 1, 0)) rightCount
+        FROM `learn_answer` a
+        WHERE a.`student_id` = #{studentId} AND DATE_FORMAT(a.`create_time`, '%Y%m') = DATE_FORMAT(#{reportDate}, '%Y%m')
+        GROUP BY report_date;
+    </select>
+
+    <select id="selectVideoStats" parameterType="LearnPlanStudy" resultMap="LearnPlanStudyResult">
+        SELECT DATE(vw.`time`) report_date, round(SUM(vw.`duration` * vw.`percent` / 100.0)) video_time, COUNT(DISTINCT vw.`title`) video_count
+        FROM `b_customer_video_watches` vw
+        WHERE vw.`customerCode` = #{studentId} AND DATE_FORMAT(vw.`time`, '%Y%m') = DATE_FORMAT(#{reportDate}, '%Y%m')
+        GROUP BY report_date
+    </select>
+
     <select id="selectLearnPlanStudyList" parameterType="LearnPlanStudy" resultMap="LearnPlanStudyResult">
         <include refid="selectLearnPlanStudyVo"/>
         <where>  
@@ -37,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="questionPlan != null "> and question_plan = #{questionPlan}</if>
             <if test="videoPlan != null "> and video_plan = #{videoPlan}</if>
         </where>
+        order by report_date
     </select>
     
     <select id="selectLearnPlanStudyById" parameterType="String" resultMap="LearnPlanStudyResult">