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.HsFlowConditionModel;
import com.willalp.flow.service.IHsFlowConditionModelService;
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-14
 */
@RestController
@RequestMapping("/flow/flowCondition")
public class HsFlowConditionModelController extends BaseController {
    @Resource
    private IHsFlowConditionModelService hsFlowConditionModelService;

    /**
     * 查询流程条件组件列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowCondition:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsFlowConditionModel hsFlowConditionModel) {
        startPage();
        List<HsFlowConditionModel> list = hsFlowConditionModelService.selectHsFlowConditionModelList(hsFlowConditionModel);
        return getDataTable(list);
    }

    /**
     * 导出流程条件组件列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flowCondition:export')")
    @Log(title = "流程条件组件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsFlowConditionModel hsFlowConditionModel) {
        List<HsFlowConditionModel> list = hsFlowConditionModelService.selectHsFlowConditionModelList(hsFlowConditionModel);
        ExcelUtil<HsFlowConditionModel> util = new ExcelUtil<HsFlowConditionModel>(HsFlowConditionModel.class);
        return util.exportExcel(list, "流程条件组件数据");
    }

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

    /**
     * 新增流程条件组件
     */
    @PreAuthorize("@ss.hasPermi('flow:flowCondition:add')")
    @Log(title = "流程条件组件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsFlowConditionModel hsFlowConditionModel) {
        return toAjax(hsFlowConditionModelService.save(hsFlowConditionModel));
    }

    /**
     * 修改流程条件组件
     */
    @PreAuthorize("@ss.hasPermi('flow:flowCondition:edit')")
    @Log(title = "流程条件组件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsFlowConditionModel hsFlowConditionModel) {
        return toAjax(hsFlowConditionModelService.updateById(hsFlowConditionModel));
    }

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