package com.ruoyi.web.controller.kaoqin;

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

import com.ruoyi.system.domain.vo.AttendanceTimeVo;
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.AttendanceTime;
import com.ruoyi.system.service.IAttendanceTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考勤时间设置Controller
 * 
 * @author ruoyi
 * @date 2025-06-25
 */
@RestController
@RequestMapping("/system/time")
public class AttendanceTimeController extends BaseController
{
    @Autowired
    private IAttendanceTimeService attendanceTimeService;

    /**
     * 查询考勤时间设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(AttendanceTime attendanceTime)
    {
        startPage();
        List<AttendanceTime> list = attendanceTimeService.selectAttendanceTimeList(attendanceTime);
        return getDataTable(list);
    }

    /**
     * 导出考勤时间设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:time:export')")
    @Log(title = "考勤时间设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendanceTime attendanceTime)
    {
        List<AttendanceTime> list = attendanceTimeService.selectAttendanceTimeList(attendanceTime);
        ExcelUtil<AttendanceTime> util = new ExcelUtil<AttendanceTime>(AttendanceTime.class);
        util.exportExcel(response, list, "考勤时间设置数据");
    }

    /**
     * 获取考勤时间设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:time:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(attendanceTimeService.selectAttendanceTimeById(id));
    }

    /**
     * 新增考勤时间设置
     */
    @PreAuthorize("@ss.hasPermi('system:time:add')")
    @Log(title = "考勤时间设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttendanceTimeVo attendanceTimeVo)
    {
        return toAjax(attendanceTimeService.insertAttendanceTime(attendanceTimeVo));
    }

    /**
     * 修改考勤时间设置
     */
    @PreAuthorize("@ss.hasPermi('system:time:edit')")
    @Log(title = "考勤时间设置", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody AttendanceTimeVo attendanceTimeVo)
    {
        return toAjax(attendanceTimeService.updateAttendanceTime(attendanceTimeVo));
    }

    /**
     * 删除考勤时间设置
     */
    @PreAuthorize("@ss.hasPermi('system:time:remove')")
    @Log(title = "考勤时间设置", businessType = BusinessType.DELETE)
    @GetMapping(value = "/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attendanceTimeService.deleteAttendanceTimeByIds(ids));
    }
}
