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.HsVacationSurplus;
import com.willalp.vacation.service.IHsVacationSurplusService;
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/surplus")
public class HsVacationSurplusController extends BaseController
{
    @Resource
    private IHsVacationSurplusService hsVacationSurplusService;

    /**
     * 查询假期剩余列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:surplus:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsVacationSurplus hsVacationSurplus)
    {
        startPage();
        List<HsVacationSurplus> list = hsVacationSurplusService.selectHsVacationSurplusList(hsVacationSurplus);
        return getDataTable(list);
    }

    /**
     * 导出假期剩余列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:surplus:export')")
    @Log(title = "假期剩余", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsVacationSurplus hsVacationSurplus)
    {
        List<HsVacationSurplus> list = hsVacationSurplusService.selectHsVacationSurplusList(hsVacationSurplus);
        ExcelUtil<HsVacationSurplus> util = new ExcelUtil<HsVacationSurplus>(HsVacationSurplus.class);
        return util.exportExcel(list, "假期剩余数据");
    }

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

    /**
     * 新增假期剩余
     */
    @PreAuthorize("@ss.hasPermi('clocking:surplus:add')")
    @Log(title = "假期剩余", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsVacationSurplus hsVacationSurplus)
    {
        hsVacationSurplus.setCreateBy(SecurityUtils.getUsername());
        hsVacationSurplus.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsVacationSurplusService.save(hsVacationSurplus));
    }

    /**
     * 修改假期剩余
     */
    @PreAuthorize("@ss.hasPermi('clocking:surplus:edit')")
    @Log(title = "假期剩余", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsVacationSurplus hsVacationSurplus)
    {
        hsVacationSurplus.setUpdateBy(SecurityUtils.getUsername());
        hsVacationSurplus.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsVacationSurplusService.updateById(hsVacationSurplus));
    }

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