package com.yanzhu.manage.controller;

import com.yanzhu.common.core.utils.poi.ExcelUtil;
import com.yanzhu.common.core.web.controller.BaseController;
import com.yanzhu.common.core.web.domain.AjaxResult;
import com.yanzhu.common.core.web.page.TableDataInfo;
import com.yanzhu.common.log.annotation.Log;
import com.yanzhu.common.log.enums.BusinessType;
import com.yanzhu.common.security.annotation.RequiresPermissions;
import com.yanzhu.manage.domain.AttendanceCfg;
import com.yanzhu.manage.domain.BusExamInfo;
import com.yanzhu.manage.service.IAttendanceCfgService;
import com.yanzhu.manage.service.IBusExamInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * 考勤配置Controller
 * 
 * @author yanzhu
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/attendance_cfg")
public class AttendanceCfgController extends BaseController
{
    @Autowired
    private IAttendanceCfgService attendanceCfgService;

    /**
     * 查询考勤配置列表
     */
    @RequiresPermissions("manage:attendance_cfg:list")
    @GetMapping("/list")
    public TableDataInfo list(AttendanceCfg attendanceCfg)
    {
        startPage();
        List<AttendanceCfg> list = attendanceCfgService.selectAttendanceCfgList(attendanceCfg);
        return getDataTable(list);
    }

    /**
     * 导出考勤配置列表
     */
    @RequiresPermissions("manage:attendance_cfg:export")
    @Log(title = "考勤配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AttendanceCfg attendanceCfg)
    {
        List<AttendanceCfg> list = attendanceCfgService.selectAttendanceCfgList(attendanceCfg);
        ExcelUtil<AttendanceCfg> util = new ExcelUtil<AttendanceCfg>(AttendanceCfg.class);
        util.exportExcel(response, list, "考勤配置数据");
    }

    /**
     * 获取考勤配置详细信息
     */
    @RequiresPermissions("manage:attendance_cfg:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(attendanceCfgService.selectAttendanceCfgById(id));
    }

    /**
     * 新增考勤配置
     */
    @RequiresPermissions("manage:attendance_cfg:add")
    @Log(title = "考勤配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttendanceCfg attendanceCfg)
    {
        return toAjax(attendanceCfgService.insertAttendanceCfg(attendanceCfg));
    }

    /**
     * 修改考勤配置
     */
    @RequiresPermissions("manage:attendance_cfg:edit")
    @Log(title = "考勤配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttendanceCfg attendanceCfg)
    {
        return toAjax(attendanceCfgService.updateAttendanceCfg(attendanceCfg));
    }

    /**
     * 删除考勤配置
     */
    @RequiresPermissions("manage:attendance_cfg:remove")
    @Log(title = "考勤配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attendanceCfgService.deleteAttendanceCfgByIds(ids));
    }
}
