package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.enums.CourseStatusEnum;
import com.ym.mec.biz.dal.page.CourseSalaryQueryInfo4Web;
import com.ym.mec.biz.dal.page.TeacherIncomeQueryInfo;
import com.ym.mec.biz.service.CourseScheduleTeacherSalaryService;
import com.ym.mec.biz.service.TeacherCourseRewardService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Joburgess
 * @Date 2020/4/15
 */
@RequestMapping("courseScheduleTeacherSalary")
@Api(tags = "课酬服务")
@RestController
public class CourseScheduleTeacherSalaryController extends BaseController {

    @Autowired
    private CourseScheduleTeacherSalaryService courseScheduleTeacherSalaryService;

    @Autowired
    private SysUserFeignService sysUserFeignService;

    @Autowired
    private TeacherCourseRewardService teacherCourseRewardService;

    @ApiOperation(value = "确定教师指定月份的课酬")
    @PostMapping("confirmTeacherMonthSalary")
    public HttpResponseResult confirmTeacherMonthSalary(String month){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        courseScheduleTeacherSalaryService.confirmTeacherMonthSalary(sysUser.getId(), month);
        return succeed();
    }

    @ApiOperation(value = "获取老师指定月份课酬信息")
    @GetMapping("findTeacherSettlementCourseSalarys")
    public HttpResponseResult findTeacherSettlementCourseSalarys(CourseSalaryQueryInfo4Web queryInfo) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        queryInfo.setTeacherId(sysUser.getId());
        return succeed(courseScheduleTeacherSalaryService.findTeacherSettlementCourseSalarys(queryInfo));
    }

    @ApiOperation(value = "获取教师指定年份每月的课酬")
    @GetMapping("findTeacherYearSalarys")
    public HttpResponseResult findTeacherYearSalarys(String year){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        return succeed(courseScheduleTeacherSalaryService.findTeacherYearSalarys(sysUser.getId(), year));
    }

    @ApiOperation(value = "分页查询结转奖励")
    @GetMapping("/findTeacherRewards")
    public HttpResponseResult findTeacherRewards(CourseSalaryQueryInfo4Web queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        queryInfo.setTeacherId(sysUser.getId());
        return succeed(teacherCourseRewardService.findTeacherRewards(queryInfo));
    }

    @ApiOperation(value = "获取教师收入总览")
    @GetMapping("/getTeacherSalaryOverview")
    public HttpResponseResult getTeacherSalaryOverview(TeacherIncomeQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        queryInfo.setTeacherId(sysUser.getId());
        queryInfo.setCourseStatus(CourseStatusEnum.OVER);
        return succeed(courseScheduleTeacherSalaryService.getTeacherSalaryOverview(queryInfo));
    }

    @ApiOperation(value = "查询教师课酬记录")
    @GetMapping("/queryTeacherIncomeList")
    public HttpResponseResult queryTeacherIncomeList(TeacherIncomeQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        queryInfo.setTeacherId(sysUser.getId());
        queryInfo.setCourseStatus(CourseStatusEnum.OVER);
        if(StringUtils.isBlank(queryInfo.getStartDay())){
            queryInfo.setStartDay("2021-03-01");
        }
        return succeed(courseScheduleTeacherSalaryService.queryTeacherIncomeList(queryInfo));
    }

    @ApiOperation(value = "收入统计")
    @GetMapping("/teacherIncomeStat")
    public HttpResponseResult teacherIncomeStat(Integer year, Integer month){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        return succeed(courseScheduleTeacherSalaryService.teacherIncomeStat(sysUser.getId(), year, month));
    }

    @ApiOperation(value = "收入统计")
    @GetMapping("/teacherIncomeStatNew")
    public HttpResponseResult teacherIncomeStatNew(Integer year, Integer month){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed("用户信息获取失败");
        }
        return succeed(courseScheduleTeacherSalaryService.teacherIncomeStatNew(sysUser.getId(), year, month));
    }

}
