package com.ruoyi.web.controller.wgz.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.wgz.domain.WgzLeave;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
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.wgz.bo.WgzLeaveQueryBo;
import com.ruoyi.wgz.service.IWgzLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 请假Controller
 *
 * @author ruoyi
 * @date 2025-02-19
 */
@Api(value = "请假控制器", tags = {"请假管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wgz/leave")
public class WgzLeaveController extends BaseController {

    private final IWgzLeaveService iWgzLeaveService;

    /**
     * 查询请假列表
     */
    @ApiOperation("查询请假列表")
    @PreAuthorize("@ss.hasPermi('wgz:leave:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzLeave> list(@Validated WgzLeaveQueryBo bo) {
        return iWgzLeaveService.queryPageList(bo);
    }

    /**
     * 导出请假列表
     */
    @ApiOperation("导出请假列表")
    @PreAuthorize("@ss.hasPermi('wgz:leave:export')")
    @Log(title = "请假", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzLeave> export(@Validated WgzLeaveQueryBo bo) {
        List<WgzLeave> list = iWgzLeaveService.queryList(bo);
        ExcelUtil<WgzLeave> util = new ExcelUtil<WgzLeave>(WgzLeave.class);
        return util.exportExcel(list, "请假");
    }

    /**
     * 获取请假详细信息
     */
    @ApiOperation("获取请假详细信息")
    @PreAuthorize("@ss.hasPermi('wgz:leave:query')")
    @GetMapping("/{id}")
    public AjaxResult<WgzLeave> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iWgzLeaveService.queryById(id));
    }

    /**
     * 新增请假
     */
    @ApiOperation("新增请假")
    @PreAuthorize("@ss.hasPermi('wgz:leave:add')")
    @Log(title = "请假", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody WgzLeave bo) {
        return toAjax(iWgzLeaveService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改请假
     */
    @ApiOperation("修改请假")
    @PreAuthorize("@ss.hasPermi('wgz:leave:edit')")
    @Log(title = "请假", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody WgzLeave bo) {
        return toAjax(iWgzLeaveService.update(bo) ? 1 : 0);
    }

    /**
     * 删除请假
     */
    @ApiOperation("删除请假")
    @PreAuthorize("@ss.hasPermi('wgz:leave:remove')")
    @Log(title = "请假" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iWgzLeaveService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
