package com.willalp.web.controller.clockingin;

import com.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.common.enums.BusinessType;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.vacation.domain.HsVacationRule;
import com.willalp.vacation.service.IHsVacationRuleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 假期规则Controller
 *
 * @author willalp
 * @date 2023-03-19
 */
@RestController
@RequestMapping("/clocking/rule")
public class HsVacationRuleController extends BaseController
{
    @Resource
    private IHsVacationRuleService hsVacationRuleService;

    /**
     * 查询假期规则列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsVacationRule hsVacationRule)
    {
        startPage();
        List<HsVacationRule> list = hsVacationRuleService.selectHsVacationRuleList(hsVacationRule);
        return getDataTable(list);
    }

    /**
     * 导出假期规则列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:rule:export')")
    @Log(title = "假期规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsVacationRule hsVacationRule)
    {
        List<HsVacationRule> list = hsVacationRuleService.selectHsVacationRuleList(hsVacationRule);
        ExcelUtil<HsVacationRule> util = new ExcelUtil<HsVacationRule>(HsVacationRule.class);
        return util.exportExcel(list, "假期规则数据");
    }

    /**
     * 获取假期规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('clocking:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsVacationRuleService.getById(id));
    }

    /**
     * 新增假期规则
     */
    @PreAuthorize("@ss.hasPermi('clocking:rule:add')")
    @Log(title = "假期规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsVacationRule hsVacationRule)
    {
        hsVacationRule.setCreateBy(SecurityUtils.getUsername());
        hsVacationRule.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsVacationRuleService.save(hsVacationRule));
    }

    /**
     * 修改假期规则
     */
    @PreAuthorize("@ss.hasPermi('clocking:rule:edit')")
    @Log(title = "假期规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsVacationRule hsVacationRule)
    {
        hsVacationRule.setUpdateBy(SecurityUtils.getUsername());
        hsVacationRule.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsVacationRuleService.updateById(hsVacationRule));
    }

    /**
     * 删除假期规则
     */
    @PreAuthorize("@ss.hasPermi('clocking:rule:remove')")
    @Log(title = "假期规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsVacationRuleService.removeByIds(Arrays.asList(ids)));
    }
}
