package com.ruoyi.web.controller.system;

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 boman
 * @date 2023-08-08
 */
@RestController
@RequestMapping("/system/leave")
public class RecordLeaveController extends BaseController
{
    @Autowired
    private IRecordLeaveService recordLeaveService;

    /**
     * 查询请假记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:leave:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordLeave recordLeave)
    {
        List<RecordLeave> list = recordLeaveService.selectRecordLeaveList(recordLeave);
        return getDataTable(list);
    }
    /**
     * app请假记录数量通知
     */
    @PostMapping("/recordLeave")
    public void recordLeave(RecordLeave recordLeave)
    {
        recordLeaveService.selectRecordLeaveNum(recordLeave);
    }

    /**
     * 导出请假记录信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:leave:export')")
    @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, "请假记录信息数据");
    }

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

    /**
     * 新增请假记录信息
     */
    @PreAuthorize("@ss.hasPermi('system:leave:add')")
    @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)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recordLeaveService.deleteRecordLeaveByIds(ids));
    }
}
