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.HsFlowExamples;
import com.willalp.flow.service.IHsFlowExamplesService;
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/flowExamples")
public class HsFlowExamplesController extends BaseController
{
    @Resource
    private IHsFlowExamplesService hsFlowExamplesService;

    /**
     * 查询流程实例列表
     */
    @PreAuthorize("@ss.hasPermi('pns:flowExamples:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsFlowExamples hsFlowExamples)
    {
        startPage();
        List<HsFlowExamples> list = hsFlowExamplesService.selectHsFlowExamplesList(hsFlowExamples);
        return getDataTable(list);
    }

    /**
     * 导出流程实例列表
     */
    @PreAuthorize("@ss.hasPermi('pns:flowExamples:export')")
    @Log(title = "流程实例", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsFlowExamples hsFlowExamples)
    {
        List<HsFlowExamples> list = hsFlowExamplesService.selectHsFlowExamplesList(hsFlowExamples);
        ExcelUtil<HsFlowExamples> util = new ExcelUtil<HsFlowExamples>(HsFlowExamples.class);
        return util.exportExcel(list, "流程实例数据");
    }

    /**
     * 获取流程实例详细信息
     */
    @PreAuthorize("@ss.hasPermi('pns:flowExamples:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsFlowExamplesService.getById(id));
    }

    /**
     * 新增流程实例
     */
    @PreAuthorize("@ss.hasPermi('pns:flowExamples:add')")
    @Log(title = "流程实例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsFlowExamples hsFlowExamples)
    {
        hsFlowExamples.setCreateBy(SecurityUtils.getUsername());
        hsFlowExamples.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsFlowExamplesService.save(hsFlowExamples));
    }

    /**
     * 修改流程实例
     */
    @PreAuthorize("@ss.hasPermi('pns:flowExamples:edit')")
    @Log(title = "流程实例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsFlowExamples hsFlowExamples)
    {
        hsFlowExamples.setUpdateBy(SecurityUtils.getUsername());
        hsFlowExamples.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsFlowExamplesService.updateById(hsFlowExamples));
    }

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