package com.yonge.cooleshow.teacher.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
import com.yonge.cooleshow.biz.dal.service.MusicSheetService;
import com.yonge.cooleshow.biz.dal.service.UserAccountRecordService;
import com.yonge.cooleshow.biz.dal.vo.CountVo;
import com.yonge.cooleshow.biz.dal.vo.PianoRoomTimeVo;
import com.yonge.cooleshow.biz.dal.vo.TeacherHomeStatisticalVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * Description 老师课后作业相关接口
 *
 * @author liujunchi
 * @date 2022-04-13
 */
@Api(tags = "老师APP首页接口")
@RestController
@RequestMapping("/home")
public class TeacherHomeController extends BaseController {

    @Resource
    private SysUserFeignService sysUserFeignService;

    @Autowired
    private CourseScheduleService courseScheduleService;

    @Autowired
    private MusicSheetService musicSheetService;

    @Autowired
    private UserAccountRecordService userAccountRecordService;

    @ApiOperation(value = "首页统计数据")
    @GetMapping(value="/count")
    public HttpResponseResult<TeacherHomeStatisticalVo> countTeacherHome() {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null  || sysUser.getId() == null) {
            return failed("用户信息获取失败");
        }

        // 我的课程
        Integer courseSechedule  = courseScheduleService.getWeekNotStart(sysUser.getId());

        // 课后作业
        Integer courseHomework = courseScheduleService.getHomeworkNotDecorate(sysUser.getId());

        // 课后评价
        Integer courseScheduleReplied = courseScheduleService.getNotRepliedCourseSchedule(sysUser.getId());

        // 我的乐谱
        Integer musicSheet = musicSheetService.getTeacherMusicSheetCount(sysUser.getId());

        // 我收到的评价
        Integer studentReplied = courseScheduleService.getWeekStudentRepliedCourseSchedule(sysUser.getId());

        // 我的收入
        BigDecimal decimal = userAccountRecordService.getMonthDecimal(sysUser.getId());


        // 琴房剩余时长
        PianoRoomTimeVo pianoRoomTimeVo = courseScheduleService.selectRemainTime(sysUser.getId());

        TeacherHomeStatisticalVo teacherHomeStatisticalVo = new TeacherHomeStatisticalVo();
        teacherHomeStatisticalVo.setCourseHomework(courseHomework);
        teacherHomeStatisticalVo.setCourseScheduleReplied(courseScheduleReplied);
        teacherHomeStatisticalVo.setCourseSchedule(courseSechedule);
        teacherHomeStatisticalVo.setDecimal(decimal);
        teacherHomeStatisticalVo.setMusicSheet(musicSheet);
        teacherHomeStatisticalVo.setStudentReplied(studentReplied);
        teacherHomeStatisticalVo.setPianoTime(pianoRoomTimeVo.getRemainTime());
        return succeed(teacherHomeStatisticalVo);
    }



}
