package cn.ezhizao.project.business.workflow.controller;

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.workflow.domain.BizWorkFlow;
import cn.ezhizao.project.business.workflow.service.BizWorkFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zx
 */
@RestController
@Api(tags = "WorkFlow数据接口")
@RequestMapping(value = "/module/workflow")
public class WorkFlowController extends BaseController {
    @Resource
    BizWorkFlowService workFlowService;

    @ApiOperation(value = "根据id查询", notes = "根据id查询")
    @GetMapping("/getById/{id}")
    @ResponseBody
    public AjaxResult getById(@PathVariable Long id) {
        return success(workFlowService.getById(id));
    }

    @ApiOperation(value = "带条件List 分页查询", notes = "带条件List 分页查询")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo getList(@RequestBody BizWorkFlow conditions) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(conditions);
        startPage();
        List<BizWorkFlow> list = workFlowService.getListByBean(conditions);
        return getDataTable(list);
    }

    @ApiOperation("保存")
    @PostMapping("/save")
    @ResponseBody
    public AjaxResult save(@RequestBody BizWorkFlow workFlow) {
        return (workFlow.getId() == null ? workFlowService.save(workFlow) : workFlowService.updateById(workFlow)) ? success(workFlow) : error();
    }

}
