package com.ruoyi.web.controller.qinjia;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RecordLeave;
import com.ruoyi.system.service.IRecordLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假记录信息Controller
 * 
 * @author ruoyi
 * @date 2023-02-13
 */
@RestController
@RequestMapping("/system/leave")
public class RecordLeaveController extends BaseController
{
    @Autowired
    private IRecordLeaveService recordLeaveService;

    /**
     * 查询请假记录信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RecordLeave recordLeave)
    {
        startPage();
        List<RecordLeave> list = recordLeaveService.selectRecordLeaveList(recordLeave);
        return getDataTable(list);
    }

    /**
     * 导出请假记录信息列表
     */
    @Log(title = "请假记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordLeave recordLeave)
    {
        List<RecordLeave> list = recordLeaveService.selectRecordLeaveList(recordLeave);
        ExcelUtil<RecordLeave> util = new ExcelUtil<RecordLeave>(RecordLeave.class);
        util.exportExcel(response, list, "请假记录信息数据");
    }

    /**
     * 获取请假记录信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(recordLeaveService.selectRecordLeaveById(id));
    }

    /**
     * 新增请假记录信息
     */
    @Log(title = "请假记录信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordLeave recordLeave)
    {
        return toAjax(recordLeaveService.insertRecordLeave(recordLeave));
    }

    /**
     * 修改请假记录信息
     */
    @PreAuthorize("@ss.hasPermi('system:leave:edit')")
    @Log(title = "请假记录信息", businessType = BusinessType.UPDATE)
    @PostMapping("put")
    public AjaxResult edit(@RequestBody RecordLeave recordLeave)
    {
        return toAjax(recordLeaveService.updateRecordLeave(recordLeave));
    }

    /**
     * 删除请假记录信息
     */
    @PreAuthorize("@ss.hasPermi('system:leave:remove')")
    @Log(title = "请假记录信息", businessType = BusinessType.DELETE)
    @GetMapping(value = "/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recordLeaveService.deleteRecordLeaveByIds(ids));
    }

    /***
     * 请假审核
     * @param id id
     * @param isPass 是否通过 1：不通过，2：通过
     * @return
     */
    @GetMapping(value = "/audit")
    public AjaxResult audit(Long id, String isPass)
    {
        return toAjax(recordLeaveService.audit(id,isPass));
    }
}
