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.entity.TeacherSalaryComplaints;
import com.ym.mec.biz.dal.page.TeacherSalaryModifyQueryInfo;
import com.ym.mec.biz.service.TeacherSalaryComplaintsService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.page.QueryInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("teacherSalaryComplaints")
@Api(tags = "老师课酬申诉")
@RestController
public class TeacherSalaryComplaintsController extends BaseController {

    @Autowired
    private TeacherSalaryComplaintsService teacherSalaryComplaintsService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "申述列表")
    @RequestMapping("/queryPage")
    public Object queryPage(TeacherSalaryModifyQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            throw new BizException("用户信息获取失败");
        }
        queryInfo.setTeacherId(sysUser.getId());
        return succeed(teacherSalaryComplaintsService.queryPage(queryInfo));
    }

    @ApiOperation(value = "课酬申述")
    @RequestMapping("/add")
    public Object add(TeacherSalaryComplaints complaints){
        return succeed(teacherSalaryComplaintsService.add(complaints));
    }

    @ApiOperation(value = "获取当月未处理申述")
    @RequestMapping("/findByMonth")
    public Object findByMonth(String salarySettlementMonth){
        return succeed(teacherSalaryComplaintsService.findByMonth(salarySettlementMonth));
    }

    @ApiOperation(value = "获取申述")
    @RequestMapping("/get")
    public Object get(Long id){
        return succeed(teacherSalaryComplaintsService.get(id));
    }

    @ApiOperation(value = "撤销当月未处理申述")
    @RequestMapping("/repealComplaints")
    public Object repealComplaints(String salarySettlementMonth){
        teacherSalaryComplaintsService.repealComplaints(salarySettlementMonth);
        return succeed();
    }
}
