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.poi.ExcelUtil;
import com.willalp.flow.domain.HsFlowBase;
import com.willalp.flow.service.IHsFlowBaseService;
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/flowBase")
public class HsFlowBaseController extends BaseController
{
    @Resource
    private IHsFlowBaseService hsFlowBaseService;

    /**
     * 查询流程基础模型列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowBase:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsFlowBase hsFlowBase)
    {
        startPage();
        List<HsFlowBase> list = hsFlowBaseService.selectHsFlowBaseList(hsFlowBase);
        return getDataTable(list);
    }

    /**
     * 导出流程基础模型列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowBase:export')")
    @Log(title = "流程基础模型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsFlowBase hsFlowBase)
    {
        List<HsFlowBase> list = hsFlowBaseService.selectHsFlowBaseList(hsFlowBase);
        ExcelUtil<HsFlowBase> util = new ExcelUtil<HsFlowBase>(HsFlowBase.class);
        return util.exportExcel(list, "流程基础模型数据");
    }

    /**
     * 获取流程基础模型详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:flowBase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsFlowBaseService.getById(id));
    }

    /**
     * 新增流程基础模型
     */
    @PreAuthorize("@ss.hasPermi('flow:flowBase:add')")
    @Log(title = "流程基础模型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsFlowBase hsFlowBase)
    {
        return toAjax(hsFlowBaseService.save(hsFlowBase));
    }

    /**
     * 修改流程基础模型
     */
    @PreAuthorize("@ss.hasPermi('flow:flowBase:edit')")
    @Log(title = "流程基础模型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsFlowBase hsFlowBase)
    {
        return toAjax(hsFlowBaseService.updateById(hsFlowBase));
    }

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