Browse Source

学生统计

weifanli 3 năm trước cách đây
mục cha
commit
d1e8d007e2

+ 24 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dto/StudentTotalDto.java

@@ -0,0 +1,24 @@
+package com.yonge.cooleshow.biz.dal.dto;
+
+import com.yonge.cooleshow.biz.dal.entity.StudentTotal;
+import io.swagger.annotations.ApiModel;
+import org.apache.commons.beanutils.BeanUtils;
+
+/**
+ * @Author: liweifan
+ * @Data: 2022-04-11 17:10:23
+ */
+@ApiModel(value = "StudentTotalDto对象", description = "学生统计总表数据传输对象")
+public class StudentTotalDto extends StudentTotal{
+	private static final long serialVersionUID = 1L;
+    
+    public StudentTotalDto buildDto(StudentTotal studentTotal){
+        try {
+            BeanUtils.copyProperties(this,studentTotal);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return this;
+    }
+
+}

+ 112 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/StudentTotal.java

@@ -0,0 +1,112 @@
+package com.yonge.cooleshow.biz.dal.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.Date;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+
+/**
+ * 学生统计总表
+ */
+@TableName("student_total")
+@ApiModel(value = "StudentTotal对象", description = "学生统计总表")
+public class StudentTotal implements Serializable {
+	private static final long serialVersionUID = 1L;
+    @ApiModelProperty("对应user表用户编号 ")
+    @TableId(value = "user_id_", type = IdType.AUTO)
+    private Long userId;
+    @ApiModelProperty("累计练习天数 ")
+	@TableField(value = "exercise_days_")
+    private Integer exerciseDays;
+    @ApiModelProperty("累计练习时长 ")
+	@TableField(value = "exercise_hours_")
+    private Double exerciseHours;
+    @ApiModelProperty("累计评测次数 ")
+	@TableField(value = "testing_num_")
+    private Integer testingNum;
+    @ApiModelProperty("已完成课时数 ")
+	@TableField(value = "finsh_class_hours_")
+    private Integer finshClassHours;
+    @ApiModelProperty("剩余课时数 ")
+	@TableField(value = "unfinsh_class_hours_")
+    private Integer unfinshClassHours;
+    @ApiModelProperty("关注老师数 ")
+	@TableField(value = "star_teacher_num_")
+    private Integer starTeacherNum;
+	@TableField(value = "update_time_")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
+    private Date updateTime;
+
+	public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+    
+	public Integer getExerciseDays() {
+        return exerciseDays;
+    }
+
+    public void setExerciseDays(Integer exerciseDays) {
+        this.exerciseDays = exerciseDays;
+    }
+    
+	public Double getExerciseHours() {
+        return exerciseHours;
+    }
+
+    public void setExerciseHours(Double exerciseHours) {
+        this.exerciseHours = exerciseHours;
+    }
+    
+	public Integer getTestingNum() {
+        return testingNum;
+    }
+
+    public void setTestingNum(Integer testingNum) {
+        this.testingNum = testingNum;
+    }
+    
+	public Integer getFinshClassHours() {
+        return finshClassHours;
+    }
+
+    public void setFinshClassHours(Integer finshClassHours) {
+        this.finshClassHours = finshClassHours;
+    }
+    
+	public Integer getUnfinshClassHours() {
+        return unfinshClassHours;
+    }
+
+    public void setUnfinshClassHours(Integer unfinshClassHours) {
+        this.unfinshClassHours = unfinshClassHours;
+    }
+    
+	public Integer getStarTeacherNum() {
+        return starTeacherNum;
+    }
+
+    public void setStarTeacherNum(Integer starTeacherNum) {
+        this.starTeacherNum = starTeacherNum;
+    }
+    
+	public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+    
+}

+ 39 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mybatis/StudentTotalMapper.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE  mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.yonge.cooleshow.biz.dal.dao.StudentTotalDao">
+	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.StudentTotal">
+            <result column="user_id_" property="userId" />
+	        <result column="exercise_days_" property="exerciseDays" />
+	        <result column="exercise_hours_" property="exerciseHours" />
+	        <result column="testing_num_" property="testingNum" />
+	        <result column="finsh_class_hours_" property="finshClassHours" />
+	        <result column="unfinsh_class_hours_" property="unfinshClassHours" />
+	        <result column="star_teacher_num_" property="starTeacherNum" />
+	        <result column="update_time_" property="updateTime" />
+		</resultMap>  
+    
+    <!-- 表字段 -->
+    <sql id="baseColumns">
+         t.user_id_ as userId
+        , t.exercise_days_ as exerciseDays
+        , t.exercise_hours_ as exerciseHours
+        , t.testing_num_ as testingNum
+        , t.finsh_class_hours_ as finshClassHours
+        , t.unfinsh_class_hours_ as unfinshClassHours
+        , t.star_teacher_num_ as starTeacherNum
+        , t.update_time_ as updateTime
+        </sql> 
+    
+    <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.StudentTotalVo">
+        SELECT
+            <include refid="baseColumns"/>
+        FROM student_total t
+        where t.user_id_ = #{id}
+    </select>
+    
+    <select id="selectPage" resultMap="BaseResultMap">
+		SELECT         
+        	<include refid="baseColumns" />
+		FROM student_total t
+	</select>
+</mapper>

+ 39 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/StudentTotalService.java

@@ -0,0 +1,39 @@
+package com.yonge.cooleshow.biz.dal.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.yonge.cooleshow.biz.dal.vo.StudentTotalVo;
+import com.yonge.cooleshow.biz.dal.dto.search.StudentTotalSearch;
+import com.yonge.cooleshow.biz.dal.entity.StudentTotal;
+
+import java.util.List;
+
+/**
+ * 学生统计总表 服务类
+ * @author liweifan
+ * @date 2022-04-11
+ */
+public interface StudentTotalService extends IService<StudentTotal>  {
+
+	/**
+     * 查询详情
+     * @author liweifan
+ 	 * @date 2022-04-11
+     */
+	StudentTotalVo detail(Long id);
+
+    /**
+     * 分页查询
+     * @author liweifan
+ 	 * @date 2022-04-11
+     */
+    IPage<StudentTotalVo> selectPage(IPage<StudentTotalVo> page, StudentTotalSearch query);
+	/***
+	 * 查询所有学生首页统计数据
+	 * @author liweifan
+	 * @updateTime 2022/3/29 10:53
+	 * @return: java.util.List<com.yonge.cooleshow.biz.dal.vo.StudentTotalVo>
+	 */
+	List<StudentTotal> queryStudentTotal();
+
+}

+ 93 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentTotalServiceImpl.java

@@ -0,0 +1,93 @@
+package com.yonge.cooleshow.biz.dal.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.yonge.cooleshow.biz.dal.dao.CourseScheduleDao;
+import com.yonge.cooleshow.biz.dal.dao.StudentDao;
+import com.yonge.cooleshow.biz.dal.dao.StudentStarDao;
+import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.enums.CacheNameEnum;
+import com.yonge.cooleshow.biz.dal.service.SysConfigService;
+import org.redisson.api.RedissonClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.yonge.cooleshow.biz.dal.entity.StudentTotal;
+import com.yonge.cooleshow.biz.dal.vo.StudentTotalVo;
+import com.yonge.cooleshow.biz.dal.dto.search.StudentTotalSearch;
+import com.yonge.cooleshow.biz.dal.dao.StudentTotalDao;
+import com.yonge.cooleshow.biz.dal.service.StudentTotalService;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+@Service
+public class StudentTotalServiceImpl extends ServiceImpl<StudentTotalDao, StudentTotal> implements StudentTotalService {
+    private final static Logger log = LoggerFactory.getLogger(StudentTotalServiceImpl.class);
+    @Autowired
+    private StudentDao studentDao;
+    @Autowired
+    private StudentStarDao studentStarDao;
+    @Autowired
+    private CourseScheduleDao courseScheduleDao;
+    @Autowired
+    private SysConfigService sysConfigService;
+    @Autowired
+    private RedissonClient redissonClient;
+	@Override
+    public StudentTotalVo detail(Long id) {
+        return baseMapper.detail(id);
+    }
+    
+     @Override
+    public IPage<StudentTotalVo> selectPage(IPage<StudentTotalVo> page, StudentTotalSearch query){
+        return page.setRecords(baseMapper.selectPage(page, query));
+    }
+
+    @Override
+    public List<StudentTotal> queryStudentTotal() {
+        List<Student> students = studentDao.selectList(Wrappers.<Student>emptyWrapper()
+                .select("userId"));
+        //查询关注老师数
+        List<StudentTotalVo> studentStarTotal = studentStarDao.queryStudentTotal();
+        Map<Long, StudentTotalVo> studentStarMap = new HashMap<>();
+        if (!CollectionUtils.isEmpty(studentStarTotal)) {
+            studentStarMap = studentStarTotal.stream().collect(Collectors.toMap(StudentTotalVo::getUserId, o -> o));
+        }
+
+        //查询已上未上课时数
+        List<StudentTotalVo> studentCourseTotal = courseScheduleDao.queryStudentTotal();
+        Map<Long, StudentTotalVo> studentCourseMap = new HashMap<>();
+        if (!CollectionUtils.isEmpty(studentCourseTotal)) {
+            studentCourseMap = studentCourseTotal.stream().collect(Collectors.toMap(StudentTotalVo::getUserId, o -> o));
+        }
+        List<StudentTotal> resultList = new ArrayList<>();
+        for (Student student : students) {
+            StudentTotal studentTotal = new StudentTotal();
+            studentTotal.setUserId(student.getUserId());
+            StudentTotalVo starTotal = studentStarMap.get(student.getUserId());
+            if (null != starTotal) {
+                studentTotal.setStarTeacherNum(starTotal.getStarTeacherNum());
+            }
+            StudentTotalVo courseTotal = studentCourseMap.get(student.getUserId());
+            if (null != courseTotal) {
+                studentTotal.setFinshClassHours(courseTotal.getFinshClassHours());
+                studentTotal.setUnfinshClassHours(courseTotal.getUnfinshClassHours());
+            }
+            //todo 缺少累计练习天数 累计练习时长 累计评测次数
+            resultList.add(studentTotal);
+            redissonClient.getBucket(CacheNameEnum.STUDENT_TOTAL.getRedisKey(studentTotal.getUserId()))
+                    .set(studentTotal);
+        }
+        saveOrUpdateBatch(resultList);
+        return resultList;
+    }
+	
+}