package com.ruoyi.web.service;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.mxjb.domain.MxjbStudyStat;
import com.ruoyi.mxjb.mapper.MxjbStudyMapper;
import com.ruoyi.system.mapper.SysLogininforMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudyService {
    private final MxjbStudyMapper mxjbStudyMapper;

    public StudyService(MxjbStudyMapper mxjbStudyMapper) {
        this.mxjbStudyMapper = mxjbStudyMapper;
    }

    public Map getUserStats() {
        Map cond = new HashMap();
        cond.put("userId", SecurityUtils.getUserId());
        MxjbStudyStat loginStat = mxjbStudyMapper.selectStudyLoginStatByStudent(cond);

        cond.put("customerCode", String.valueOf(SecurityUtils.getUserId()));
        MxjbStudyStat quesStat = mxjbStudyMapper.selectStudyQuestionTotal(cond);

        cond.put("types", Lists.newArrayList(2));
        MxjbStudyStat videoStat = mxjbStudyMapper.selectStudyVideoTotal(cond);


        Map<String, Object> dataMap = Maps.newHashMap();
        dataMap.put("numExercise", quesStat.getCount());
        dataMap.put("timeVideo", null != videoStat ? (videoStat.getVideoAvgTime() + 59) / 60 : 0);
        dataMap.put("timeVideoUnit", "分钟");
        dataMap.put("numLogin", null != loginStat ? loginStat.getCount() : 0);
        return dataMap;
    }
}
