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.HsFlowTask;
import com.willalp.flow.service.IHsFlowTaskService;
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-12
 */
@RestController
@RequestMapping("/flow/flowTask")
public class HsFlowTaskController extends BaseController
{
    @Resource
    private IHsFlowTaskService hsFlowTaskService;

    /**
     * 查询流程任务列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsFlowTask hsFlowTask)
    {
        startPage();
        List<HsFlowTask> list = hsFlowTaskService.selectHsFlowTaskList(hsFlowTask);
        return getDataTable(list);
    }

    /**
     * 导出流程任务列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowTask:export')")
    @Log(title = "流程任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsFlowTask hsFlowTask)
    {
        List<HsFlowTask> list = hsFlowTaskService.selectHsFlowTaskList(hsFlowTask);
        ExcelUtil<HsFlowTask> util = new ExcelUtil<HsFlowTask>(HsFlowTask.class);
        return util.exportExcel(list, "流程任务数据");
    }

    /**
     * 获取流程任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:flowTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsFlowTaskService.getById(id));
    }

    /**
     * 新增流程任务
     */
    @PreAuthorize("@ss.hasPermi('flow:flowTask:add')")
    @Log(title = "流程任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsFlowTask hsFlowTask)
    {
        hsFlowTask.setCreateBy(SecurityUtils.getUsername());
        hsFlowTask.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsFlowTaskService.save(hsFlowTask));
    }

    /**
     * 修改流程任务
     */
    @PreAuthorize("@ss.hasPermi('flow:flowTask:edit')")
    @Log(title = "流程任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsFlowTask hsFlowTask)
    {
        hsFlowTask.setUpdateBy(SecurityUtils.getUsername());
        hsFlowTask.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsFlowTaskService.updateById(hsFlowTask));
    }

    /**
     * 删除流程任务
     */
    @PreAuthorize("@ss.hasPermi('flow:flowTask:remove')")
    @Log(title = "流程任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsFlowTaskService.removeByIds(Arrays.asList(ids)));
    }
}
