package com.ruoyi.web.controller.system;

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

/**
 * 节假日，需每年手动更新Controller
 * 
 * @author ruoyi
 * @date 2023-03-04
 */
@RestController
@RequestMapping("/system/holiday")
public class SysHolidayController extends BaseController
{
    @Autowired
    private ISysHolidayService sysHolidayService;

    /**
     * 查询节假日，需每年手动更新列表
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysHoliday sysHoliday)
    {
        startPage();
        List<SysHoliday> list = sysHolidayService.selectSysHolidayList(sysHoliday);
        return getDataTable(list);
    }

    /**
     * 导出节假日，需每年手动更新列表
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:export')")
    @Log(title = "节假日，需每年手动更新", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysHoliday sysHoliday)
    {
        List<SysHoliday> list = sysHolidayService.selectSysHolidayList(sysHoliday);
        ExcelUtil<SysHoliday> util = new ExcelUtil<SysHoliday>(SysHoliday.class);
        util.exportExcel(response, list, "节假日，需每年手动更新数据");
    }

    /**
     * 获取节假日，需每年手动更新详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysHolidayService.selectSysHolidayById(id));
    }

    /**
     * 新增节假日，需每年手动更新
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:add')")
    @Log(title = "节假日，需每年手动更新", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysHoliday sysHoliday)
    {
        return toAjax(sysHolidayService.insertSysHoliday(sysHoliday));
    }

    /**
     * 修改节假日，需每年手动更新
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:edit')")
    @Log(title = "节假日，需每年手动更新", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysHoliday sysHoliday)
    {
        return toAjax(sysHolidayService.updateSysHoliday(sysHoliday));
    }

    /**
     * 删除节假日，需每年手动更新
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:remove')")
    @Log(title = "节假日，需每年手动更新", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysHolidayService.deleteSysHolidayByIds(ids));
    }
}
