package com.ym.mec.web.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dto.TeacherLeaveRecordDto;
import com.ym.mec.biz.dal.entity.TeacherLeaveRecord;
import com.ym.mec.biz.dal.enums.AuditStatusEnum;
import com.ym.mec.biz.service.TeacherLeaveRecordService;
import com.ym.mec.common.controller.BaseController;
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;

@RequestMapping("teacherLeaveRecord")
@Api(tags = "教师请假记录服务")
@RestController
public class TeacherLeaveRecordController extends BaseController {

    @Autowired
    private TeacherLeaveRecordService teacherLeaveRecordService;

    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增教师请假记录")
    @PostMapping("/add")
    public Object add(TeacherLeaveRecord teacherLeaveRecord){
        teacherLeaveRecordService.insert(teacherLeaveRecord);
        return succeed();
    }

    @ApiOperation(value = "分页查询教师请假记录列表")
    @GetMapping("/queryPage")
    public Object queryPage(TeacherLeaveRecordDto queryInfo){
        return succeed(teacherLeaveRecordService.queryPage(queryInfo));
    }

    @ApiOperation(value = "分页查询教师请假记录列表")
    @GetMapping("/queryDetail")
    public Object queryDetail(Long id){
    	
    	TeacherLeaveRecord teacherLeaveRecord = teacherLeaveRecordService.get(id);
    	
    	if(teacherLeaveRecord == null){
    		return failed("参数不正确");
    	}
    	
    	SysUser user = sysUserFeignService.queryUserById(teacherLeaveRecord.getUserId());
    	teacherLeaveRecord.getUser().setUsername(user.getUsername());
    	teacherLeaveRecord.getUser().setId(user.getId());
    	
        return succeed(teacherLeaveRecord);
    }

    @ApiOperation(value = "请假审核")
    @PostMapping("/approve")
    public Object approve(Long id, Integer userId, AuditStatusEnum status, String remark) {
        teacherLeaveRecordService.approve(id,userId,status,remark);
        return succeed();
    }
}
