package com.ruoyi.web.controller.clock;

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.ClockRecord;
import com.ruoyi.system.service.IClockRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 打卡记录Controller
 *
 * @author ruoyi
 * @date 2024-08-06
 */
@RestController
@RequestMapping("/system/clock")
public class ClockRecordController extends BaseController {
    @Autowired
    private IClockRecordService clockRecordService;

    /**
     * 查询打卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:clock:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClockRecord clockRecord) {
        startPage();
        List<ClockRecord> list = clockRecordService.selectClockRecordList(clockRecord);
        return getDataTable(list);
    }

    /**
     * 查询打卡记录日历形式
     */
    @PreAuthorize("@ss.hasPermi('system:clock:rl')")
    @GetMapping("/rl")
    public AjaxResult rl(ClockRecord clockRecord) {
        return clockRecordService.selectClockRecordListRl(clockRecord);
    }

    /**
     * 导出打卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:clock:export')")
    @Log(title = "打卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClockRecord clockRecord) {
        List<ClockRecord> list = clockRecordService.selectClockRecordList(clockRecord);
        ExcelUtil<ClockRecord> util = new ExcelUtil<ClockRecord>(ClockRecord.class);
        util.exportExcel(response, list, "打卡记录数据");
    }

    /**
     * 获取打卡记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:clock:query')")
    @GetMapping(value = "/{clockId}")
    public AjaxResult getInfo(@PathVariable("clockId") Long clockId) {
        return success(clockRecordService.selectClockRecordByClockId(clockId));
    }

    /**
     * 新增打卡记录
     */
    @PreAuthorize("@ss.hasPermi('system:clock:add')")
    @Log(title = "打卡记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClockRecord clockRecord) {
        return toAjax(clockRecordService.insertClockRecord(clockRecord));
    }

    /**
     * 修改打卡记录
     */
    @PreAuthorize("@ss.hasPermi('system:clock:edit')")
    @Log(title = "打卡记录", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ClockRecord clockRecord) {
        return toAjax(clockRecordService.updateClockRecord(clockRecord));
    }

    /**
     * 删除打卡记录
     */
    @PreAuthorize("@ss.hasPermi('system:clock:remove')")
    @Log(title = "打卡记录", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{clockIds}")
    public AjaxResult remove(@PathVariable Long[] clockIds) {
        return toAjax(clockRecordService.deleteClockRecordByClockIds(clockIds));
    }
}
