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.page.CourseSalaryQueryInfo4Web;
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.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));
    }

}
