package com.ruoyi.web.controller.kaoqin;

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

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

/**
 * 考勤规则配置Controller
 * 
 * @author boman
 * @date 2023-02-02
 */
@RestController
@RequestMapping("/kaoqin/config")
public class KaoqinConfigController extends BaseController
{
    @Autowired
    private IKaoqinConfigService kaoqinConfigService;

    /**
     * 查询考勤规则配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(KaoqinConfig kaoqinConfig)
    {
        startPage();
        List<KaoqinConfig> list = kaoqinConfigService.selectKaoqinConfigList(kaoqinConfig);
        return getDataTable(list);
    }

    /**
     * 导出考勤规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('kaoqin:config:export')")
    @Log(title = "考勤规则配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KaoqinConfig kaoqinConfig)
    {
        List<KaoqinConfig> list = kaoqinConfigService.selectKaoqinConfigList(kaoqinConfig);
        ExcelUtil<KaoqinConfig> util = new ExcelUtil<KaoqinConfig>(KaoqinConfig.class);
        util.exportExcel(response, list, "考勤规则配置数据");
    }

    /**
     * 获取考勤规则配置详细信息
     */
    @GetMapping(value = "/{kaoqinId}")
    public AjaxResult getInfo(@PathVariable("kaoqinId") Long kaoqinId)
    {
        return AjaxResult.success(kaoqinConfigService.selectKaoqinConfigByKaoqinId(kaoqinId));
    }

    /**
     * 新增考勤规则配置
     */
    @Log(title = "考勤规则配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KaoqinConfig kaoqinConfig)
    {
        return toAjaxKaoQin(kaoqinConfigService.insertKaoqinConfig(kaoqinConfig));
    }

    /**
     * 修改考勤规则配置
     */
    @Log(title = "考勤规则配置", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody KaoqinConfig kaoqinConfig)
    {
        return toAjax(kaoqinConfigService.updateKaoqinConfig(kaoqinConfig));
    }

    /**
     * 删除考勤规则配置
     */
    @Log(title = "考勤规则配置", businessType = BusinessType.DELETE)
    @GetMapping(value = "/delete/{kaoqinIds}")
    public AjaxResult remove(@PathVariable Long[] kaoqinIds)
    {
        return toAjax(kaoqinConfigService.deleteKaoqinConfigByKaoqinIds(kaoqinIds));
    }
}
