package com.sundot.airport.web.controller.attendance;

import com.sundot.airport.attendance.domain.AttendanceCheckRecord;
import com.sundot.airport.attendance.service.IAttendanceCheckRecordService;
import com.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.core.page.TableDataInfo;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 打卡记录Controller
 *
 * @author wangchong
 * @date 2025-07-10
 */
@RestController
@RequestMapping("/attendance/checkRecord")
public class AttendanceCheckRecordController extends BaseController {
    @Autowired
    private IAttendanceCheckRecordService attendanceCheckRecordService;

    /**
     * 查询打卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('attendance:checkRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(AttendanceCheckRecord attendanceCheckRecord) {
        startPage();
        List<AttendanceCheckRecord> list = attendanceCheckRecordService.selectAttendanceCheckRecordList(attendanceCheckRecord);
        return getDataTable(list);
    }

    /**
     * 导出打卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('attendance:checkRecord:export')")
    @Log(title = "打卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendanceCheckRecord attendanceCheckRecord) {
        List<AttendanceCheckRecord> list = attendanceCheckRecordService.selectAttendanceCheckRecordList(attendanceCheckRecord);
        ExcelUtil<AttendanceCheckRecord> util = new ExcelUtil<AttendanceCheckRecord>(AttendanceCheckRecord.class);
        util.exportExcel(response, list, "打卡记录数据");
    }

    /**
     * 获取打卡记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('attendance:checkRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(attendanceCheckRecordService.selectAttendanceCheckRecordById(id));
    }

    /**
     * 新增打卡记录
     */
    @PreAuthorize("@ss.hasPermi('attendance:checkRecord:add')")
    @Log(title = "打卡记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttendanceCheckRecord attendanceCheckRecord) {
        return toAjax(attendanceCheckRecordService.insertAttendanceCheckRecord(attendanceCheckRecord));
    }

    /**
     * 修改打卡记录
     */
    @PreAuthorize("@ss.hasPermi('attendance:checkRecord:edit')")
    @Log(title = "打卡记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttendanceCheckRecord attendanceCheckRecord) {
        return toAjax(attendanceCheckRecordService.updateAttendanceCheckRecord(attendanceCheckRecord));
    }

    /**
     * 删除打卡记录
     */
    @PreAuthorize("@ss.hasPermi('attendance:checkRecord:remove')")
    @Log(title = "打卡记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(attendanceCheckRecordService.deleteAttendanceCheckRecordByIds(ids));
    }
}
