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.HsFlowModel;
import com.willalp.flow.service.IHsFlowModelService;
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/flowModel")
public class HsFlowModelController extends BaseController
{
    @Resource
    private IHsFlowModelService hsFlowModelService;

    /**
     * 查询流程模型列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowModel:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsFlowModel hsFlowModel)
    {
        startPage();
        List<HsFlowModel> list = hsFlowModelService.selectHsFlowModelList(hsFlowModel);
        return getDataTable(list);
    }

    /**
     * 导出流程模型列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowModel:export')")
    @Log(title = "流程模型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsFlowModel hsFlowModel)
    {
        List<HsFlowModel> list = hsFlowModelService.selectHsFlowModelList(hsFlowModel);
        ExcelUtil<HsFlowModel> util = new ExcelUtil<HsFlowModel>(HsFlowModel.class);
        return util.exportExcel(list, "流程模型数据");
    }

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

    /**
     * 新增流程模型
     */
    @PreAuthorize("@ss.hasPermi('flow:flowModel:add')")
    @Log(title = "流程模型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsFlowModel hsFlowModel)
    {
        hsFlowModel.setCreateBy(SecurityUtils.getUsername());
        hsFlowModel.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsFlowModelService.save(hsFlowModel));
    }

    /**
     * 修改流程模型
     */
    @PreAuthorize("@ss.hasPermi('flow:flowModel:edit')")
    @Log(title = "流程模型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsFlowModel hsFlowModel)
    {
        hsFlowModel.setUpdateBy(SecurityUtils.getUsername());
        hsFlowModel.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsFlowModelService.updateById(hsFlowModel));
    }

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