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.files.domain.PersonnelHireApproval;
import com.willalp.files.service.IPersonnelHireApprovalService;
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-14
 */
@RestController
@RequestMapping("/clocking/personnelApproval")
public class PersonnelHireApprovalController extends BaseController
{
    @Resource
    private IPersonnelHireApprovalService personnelHireApprovalService;

    /**
     * 查询员工入流程审批记录列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:personnelApproval:list')")
    @GetMapping("/list")
    public TableDataInfo list(PersonnelHireApproval personnelHireApproval)
    {
        startPage();
        List<PersonnelHireApproval> list = personnelHireApprovalService.selectPersonnelHireApprovalList(personnelHireApproval);
        return getDataTable(list);
    }

    /**
     * 导出员工入流程审批记录列表
     */
    @PreAuthorize("@ss.hasPermi('clocking:personnelApproval:export')")
    @Log(title = "员工入流程审批记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PersonnelHireApproval personnelHireApproval)
    {
        List<PersonnelHireApproval> list = personnelHireApprovalService.selectPersonnelHireApprovalList(personnelHireApproval);
        ExcelUtil<PersonnelHireApproval> util = new ExcelUtil<PersonnelHireApproval>(PersonnelHireApproval.class);
        return util.exportExcel(list, "员工入流程审批记录数据");
    }

    /**
     * 获取员工入流程审批记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('clocking:personnelApproval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(personnelHireApprovalService.getById(id));
    }

    /**
     * 新增员工入流程审批记录
     */
    @PreAuthorize("@ss.hasPermi('clocking:personnelApproval:add')")
    @Log(title = "员工入流程审批记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonnelHireApproval personnelHireApproval)
    {
        personnelHireApproval.setCreateBy(SecurityUtils.getUsername());
        personnelHireApproval.setCreateTime(DateUtils.getNowDate());
        return toAjax(personnelHireApprovalService.save(personnelHireApproval));
    }

    /**
     * 修改员工入流程审批记录
     */
    @PreAuthorize("@ss.hasPermi('clocking:personnelApproval:edit')")
    @Log(title = "员工入流程审批记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonnelHireApproval personnelHireApproval)
    {
        personnelHireApproval.setUpdateBy(SecurityUtils.getUsername());
        personnelHireApproval.setUpdateTime(DateUtils.getNowDate());
        return toAjax(personnelHireApprovalService.updateById(personnelHireApproval));
    }

    /**
     * 删除员工入流程审批记录
     */
    @PreAuthorize("@ss.hasPermi('clocking:personnelApproval:remove')")
    @Log(title = "员工入流程审批记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(personnelHireApprovalService.removeByIds(Arrays.asList(ids)));
    }
}
