|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|