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

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

import com.ruoyi.wgz.domain.WgzAttendance;
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.WgzAttendanceQueryBo;
import com.ruoyi.wgz.service.IWgzAttendanceService;
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-20
 */
@Api(value = "考勤打卡控制器", tags = {"考勤打卡管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wgz/attendance")
public class WgzAttendanceController extends BaseController {

    private final IWgzAttendanceService iWgzAttendanceService;

    /**
     * 查询考勤打卡列表
     */
    @ApiOperation("查询考勤打卡列表")
    @PreAuthorize("@ss.hasPermi('wgz:attendance:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzAttendance> list(@Validated WgzAttendanceQueryBo bo) {
        return iWgzAttendanceService.queryPageList(bo);
    }

    /**
     * 导出考勤打卡列表
     */
    @ApiOperation("导出考勤打卡列表")
    @PreAuthorize("@ss.hasPermi('wgz:attendance:export')")
    @Log(title = "考勤打卡", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzAttendance> export(@Validated WgzAttendanceQueryBo bo) {
        List<WgzAttendance> list = iWgzAttendanceService.queryList(bo);
        ExcelUtil<WgzAttendance> util = new ExcelUtil<WgzAttendance>(WgzAttendance.class);
        return util.exportExcel(list, "考勤打卡");
    }

    /**
     * 获取考勤打卡详细信息
     */
    @ApiOperation("获取考勤打卡详细信息")
    @PreAuthorize("@ss.hasPermi('wgz:attendance:query')")
    @GetMapping("/{id}")
    public AjaxResult<WgzAttendance> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iWgzAttendanceService.queryById(id));
    }

    /**
     * 新增考勤打卡
     */
    @ApiOperation("新增考勤打卡")
    @PreAuthorize("@ss.hasPermi('wgz:attendance:add')")
    @Log(title = "考勤打卡", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody WgzAttendance bo) {
        return toAjax(iWgzAttendanceService.insert(bo) ? 1 : 0);
    }

    /**
     * 修改考勤打卡
     */
    @ApiOperation("修改考勤打卡")
    @PreAuthorize("@ss.hasPermi('wgz:attendance:edit')")
    @Log(title = "考勤打卡", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody WgzAttendance bo) {
        return toAjax(iWgzAttendanceService.update(bo) ? 1 : 0);
    }

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