浏览代码

题总量可以统计年度总计

mingfu 3 周之前
父节点
当前提交
2cf0c528c7

+ 2 - 7
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontStudentController.java

@@ -347,14 +347,9 @@ public class FrontStudentController extends BaseController {
 
     @ApiOperation("55 记录-计划刷题")
     @GetMapping("record/planStudy")
-    public AjaxResult getRecordPlanStudy(@ApiParam String reportMonth)
+    public AjaxResult getRecordPlanStudy(@ApiParam Integer year, @ApiParam @RequestParam(required = false) Long month)
     {
-        try {
-            Date date = DateUtils.parseDate(reportMonth, "yyyy-MM-dd");
-            return AjaxResult.success(learnStatService.getRecordPlanStudy(SecurityUtils.getUserId(), date));
-        } catch (ParseException e) {
-            throw new ValidationException("日期格式错误");
-        }
+        return AjaxResult.success(learnStatService.getRecordPlanStudy(SecurityUtils.getUserId(), year, month));
     }
 
     @ApiOperation("56 记录-视频学习")

+ 23 - 7
ie-admin/src/main/java/com/ruoyi/web/service/LearnStatService.java

@@ -5,6 +5,7 @@ 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.NumberUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.learn.domain.LearnStudent;
 import com.ruoyi.learn.mapper.LearnAnswerMapper;
@@ -12,10 +13,7 @@ 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;
+import java.util.*;
 
 @Service
 public class LearnStatService {
@@ -33,7 +31,8 @@ public class LearnStatService {
 
     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);
+        Set<Long> knowledgeIdSet = null != learnStudent ? learnTeacherService.getKnowledgeIdSet(new Long[] { learnStudent.getMajorPlanId() }) : Sets.newHashSet();
+        knowledgeIdSet.add(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")));
@@ -56,13 +55,30 @@ public class LearnStatService {
         return result;
     }
 
-    public JSONObject getRecordPlanStudy(Long studentId, Date date) {
-        Map cond = Dict.create().set("studentId", studentId).set("date", date);
+    public JSONObject getRecordPlanStudy(Long studentId, Integer year, Long month) {
+        Date beginDate, endDate;
+        Calendar cal  = Calendar.getInstance();
+        if(NumberUtils.isPositive(month)) {
+            cal.set(year, month.intValue() - 1, 1);
+            beginDate = cal.getTime();
+            cal.add(Calendar.MONTH, 1);
+            endDate = cal.getTime();
+        } else {
+            cal.set(year, 0, 1);
+            beginDate = cal.getTime();
+            cal.add(Calendar.YEAR, 1);
+            endDate = cal.getTime();
+        }
+
+        Map cond = Dict.create().set("studentId", studentId).set("beginDate", beginDate).set("endDate", endDate);
         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"));
+        if(null == month || month.equals(0)) {
+            return result;
+        }
         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"));

+ 4 - 1
ie-admin/src/main/java/com/ruoyi/web/service/LearnTeacherService.java

@@ -355,8 +355,11 @@ public class LearnTeacherService {
 
     public Set<Long> getKnowledgeIdSet(Long[] planIds) {
         Set<Long> knowledgeIdSet = Sets.newHashSet();
-        if(ArrayUtils.isNotEmpty(planIds)) {
+        if(ArrayUtils.isNotEmpty(planIds) && null != planIds[0]) {
             List<AMarjorPlan> planList = marjorPlanMapper.selectAMarjorPlanByIds(planIds);
+            if(CollectionUtils.isEmpty(planList)) {
+                return knowledgeIdSet;
+            }
             AMarjorPlan curr = planList.get(0);
             LearnDirectedKnowledge dkCond = new LearnDirectedKnowledge();
             dkCond.setUniversityId(curr.getUniversityId());

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

@@ -32,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         , 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})
+        WHERE a.`student_id` = #{studentId}
         GROUP BY a.`knowledge_id`, directed
         order by directed desc, rate desc, a.`knowledge_id`
     </select>
@@ -40,13 +40,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <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')
+          WHERE a.`student_id` = #{studentId} and a.`create_time` between #{beginDate} and #{endDate}
     </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')
+         WHERE a.`student_id` = #{studentId} and a.`create_time` between #{beginDate} and #{endDate}
          GROUP BY DATE(a.create_time)
          order by DATE(a.create_time) desc
     </select>

+ 2 - 3
ie-system/src/main/resources/mapper/mingxue/CustomerVideoWatchesMapper.xml

@@ -24,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </sql>
 
     <select id="selectLearnStatsHeader" parameterType="Map" resultType="com.alibaba.fastjson2.JSONObject">
-        SELECT COUNT(*) total , round(SUM(vw.`duration` * vw.`percent` / 100.0)) `value`
+        SELECT COUNT(DISTINCT vw.`title`) total , round(SUM(vw.`duration` * vw.`percent` / 100.0)) `value`
         FROM `b_customer_video_watches` vw
         WHERE vw.`customerCode` = #{studentId}
     </select>
@@ -33,8 +33,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         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
+        order by date(vw.`time`) desc, vw.`title`
     </select>
 
     <select id="selectCustomerVideoWatchesList" parameterType="CustomerVideoWatches" resultMap="CustomerVideoWatchesResult">