package com.willalp.web.controller.clockingin;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
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.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.enums.BusinessType;
import com.willalp.clockingin.domain.HsPnsVacateTime;
import com.willalp.clockingin.service.IHsPnsVacateTimeService;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 请假时间记录Controller
 *
 * @author willalp
 * @date 2022-05-10
 */
@RestController
@RequestMapping("/clockingin/time")
public class HsPnsVacateTimeController extends BaseController
{
    @Resource
    private IHsPnsVacateTimeService hsPnsVacateTimeService;

    /**
     * 查询请假时间记录列表
     */
    @PreAuthorize("@ss.hasPermi('clockingin:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsPnsVacateTime hsPnsVacateTime)
    {
        startPage();
        List<HsPnsVacateTime> list = hsPnsVacateTimeService.selectHsPnsVacateTimeList(hsPnsVacateTime);
        return getDataTable(list);
    }

    /**
     * 导出请假时间记录列表
     */
    @PreAuthorize("@ss.hasPermi('clockingin:time:export')")
    @Log(title = "请假时间记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsPnsVacateTime hsPnsVacateTime)
    {
        List<HsPnsVacateTime> list = hsPnsVacateTimeService.selectHsPnsVacateTimeList(hsPnsVacateTime);
        ExcelUtil<HsPnsVacateTime> util = new ExcelUtil<HsPnsVacateTime>(HsPnsVacateTime.class);
        return util.exportExcel(list, "请假时间记录数据");
    }

    /**
     * 获取请假时间记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('clockingin:time:query')")
    @GetMapping(value = "/{vacateId}")
    public AjaxResult getInfo(@PathVariable("vacateId") String vacateId)
    {
        return AjaxResult.success(hsPnsVacateTimeService.getById(vacateId));
    }

    /**
     * 新增请假时间记录
     */
    @PreAuthorize("@ss.hasPermi('clockingin:time:add')")
    @Log(title = "请假时间记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsPnsVacateTime hsPnsVacateTime)
    {
        hsPnsVacateTime.setCreateBy(SecurityUtils.getUsername());
        hsPnsVacateTime.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsPnsVacateTimeService.save(hsPnsVacateTime));
    }

    /**
     * 修改请假时间记录
     */
    @PreAuthorize("@ss.hasPermi('clockingin:time:edit')")
    @Log(title = "请假时间记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsPnsVacateTime hsPnsVacateTime)
    {
        hsPnsVacateTime.setUpdateBy(SecurityUtils.getUsername());
        hsPnsVacateTime.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsPnsVacateTimeService.updateById(hsPnsVacateTime));
    }

    /**
     * 删除请假时间记录
     */
    @PreAuthorize("@ss.hasPermi('clockingin:time:remove')")
    @Log(title = "请假时间记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vacateIds}")
    public AjaxResult remove(@PathVariable String[] vacateIds)
    {
        return toAjax(hsPnsVacateTimeService.removeByIds(Arrays.asList(vacateIds)));
    }
}
