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

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

import com.ruoyi.wgz.domain.WgzDailyClock;
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.WgzDailyClockQueryBo;
import com.ruoyi.wgz.service.IWgzDailyClockService;
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-18
 */
@Api(value = "日报打卡控制器", tags = {"日报打卡管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wgz/clock")
public class WgzDailyClockController extends BaseController {

    private final IWgzDailyClockService iWgzDailyClockService;

    /**
     * 查询日报打卡列表
     */
    @ApiOperation("查询日报打卡列表")
    @PreAuthorize("@ss.hasPermi('wgz:clock:list')")
    @GetMapping("/list")
    public TableDataInfo<WgzDailyClock> list(@Validated WgzDailyClockQueryBo bo) {
        return iWgzDailyClockService.queryPageList(bo);
    }

    /**
     * 导出日报打卡列表
     */
    @ApiOperation("导出日报打卡列表")
    @PreAuthorize("@ss.hasPermi('wgz:clock:export')")
    @Log(title = "日报打卡", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<WgzDailyClock> export(@Validated WgzDailyClockQueryBo bo) {
        List<WgzDailyClock> list = iWgzDailyClockService.queryList(bo);
        ExcelUtil<WgzDailyClock> util = new ExcelUtil<WgzDailyClock>(WgzDailyClock.class);
        return util.exportExcel(list, "日报打卡");
    }

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

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

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

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