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.flow.domain.BizLeaveImg;
import com.willalp.flow.service.IBizLeaveImgService;
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 2022-10-19
 */
@RestController
@RequestMapping("/flow/leavenImg")
public class BizLeaveImgController extends BaseController
{
    @Resource
    private IBizLeaveImgService bizLeaveImgService;



    /**
     * 根据请假表单ID查询请假记录图像信息列表
     */
    @PreAuthorize("@ss.hasPermi('flow:leavenImg:list')")
    @GetMapping("/getBizLeaveImg")
    public AjaxResult getById(BizLeaveImg bizLeaveImg)
    {
        return AjaxResult.success(bizLeaveImgService.selectBizLeaveImgList(bizLeaveImg));
    }


    /**
     * 查询请假记录图像信息列表
     */
    @PreAuthorize("@ss.hasPermi('flow:leavenImg:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizLeaveImg bizLeaveImg)
    {
        startPage();
        List<BizLeaveImg> list = bizLeaveImgService.selectBizLeaveImgList(bizLeaveImg);
        return getDataTable(list);
    }

    /**
     * 导出请假记录图像信息列表
     */
    @PreAuthorize("@ss.hasPermi('flow:leavenImg:export')")
    @Log(title = "请假记录图像信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizLeaveImg bizLeaveImg)
    {
        List<BizLeaveImg> list = bizLeaveImgService.selectBizLeaveImgList(bizLeaveImg);
        ExcelUtil<BizLeaveImg> util = new ExcelUtil<BizLeaveImg>(BizLeaveImg.class);
        return util.exportExcel(list, "请假记录图像信息数据");
    }

    /**
     * 获取请假记录图像信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:leavenImg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(bizLeaveImgService.getById(id));
    }

    /**
     * 新增请假记录图像信息
     */
    @PreAuthorize("@ss.hasPermi('flow:leavenImg:add')")
    @Log(title = "请假记录图像信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizLeaveImg bizLeaveImg)
    {
        bizLeaveImg.setCreateBy(SecurityUtils.getUsername());
        bizLeaveImg.setCreateTime(DateUtils.getNowDate());
        return toAjax(bizLeaveImgService.save(bizLeaveImg));
    }

    /**
     * 修改请假记录图像信息
     */
    @PreAuthorize("@ss.hasPermi('flow:leavenImg:edit')")
    @Log(title = "请假记录图像信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizLeaveImg bizLeaveImg)
    {
        bizLeaveImg.setUpdateBy(SecurityUtils.getUsername());
        bizLeaveImg.setUpdateTime(DateUtils.getNowDate());
        return toAjax(bizLeaveImgService.updateById(bizLeaveImg));
    }

    /**
     * 删除请假记录图像信息
     */
    @PreAuthorize("@ss.hasPermi('flow:leavenImg:remove')")
    @Log(title = "请假记录图像信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bizLeaveImgService.removeByIds(Arrays.asList(ids)));
    }
}
