package com.bonus.material.work.controller;


import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.material.work.domain.SysWorkflowNode;
import com.bonus.material.work.service.SysWorkflowNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

@Api(tags = "工作流详情表")
@RestController
@RequestMapping("/sysWorkflowNode")
public class SysWorkflowNodeController extends BaseController {


    @Resource
    private SysWorkflowNodeService sysWorkflowNodeService;

    /**
     * 工作流详情列表
     */
    @ApiOperation(value = "工作流详情列表")
    @GetMapping("/list")
    public TableDataInfo list(SysWorkflowNode sysWorkflowNode)
    {
//        try {
            startPage();
            List<SysWorkflowNode> list = sysWorkflowNodeService.selectSysWorkflowNodeList(sysWorkflowNode);
            return getDataTable(list);
//        }catch (Exception e){
//            return getDataTableError(null);
//        }
    }

    /**
     * 新增工作流详情
     */
    @ApiOperation(value = "新增工作流详情")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysWorkflowNode sysWorkflowNode)
    {
        try {
            sysWorkflowNodeService.addSysWorkflowNode(sysWorkflowNode);
            return new AjaxResult(200,"新增成功！");
        }catch (Exception e){
            return error();
        }
    }

    /**
     * 删除工作流详情
     */
    @ApiOperation(value = "删除工作流详情")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody SysWorkflowNode sysWorkflowNode)
    {
        try {
            sysWorkflowNodeService.deleteSysWorkflowNode(sysWorkflowNode);
            return new AjaxResult(200,"删除成功！");
        }catch (Exception e){
            return error();
        }
    }

    /**
     * 修改工作流详情
     */
    @ApiOperation(value = "修改工作流详情")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody SysWorkflowNode sysWorkflowNode)
    {
        try {
            sysWorkflowNodeService.updateSysWorkflowNode(sysWorkflowNode);
            return new AjaxResult(200,"修改成功！");
        }catch (Exception e){
            return error();
        }
    }

    /**
     * 根据任务id查询工作流详情列表
     */
    @ApiOperation(value = "根据任务id查询工作流详情列表")
    @GetMapping("/listByTaskId")
    public TableDataInfo listByTaskId(SysWorkflowNode sysWorkflowNode) {
        if (sysWorkflowNode == null || sysWorkflowNode.getTaskId() == null) {
            throw new RuntimeException("查询参数不能为空");
        }
        try {
            startPage();
            List<SysWorkflowNode> list = sysWorkflowNodeService.listByTaskId(sysWorkflowNode);
            return getDataTable(list);
        }catch (Exception e){
            return getDataTableError(null);
        }
    }
    /**
     * 根据工程id查询工作流详情列表
     */
    @ApiOperation(value = "根据工程id查询工作流详情列表")
    @GetMapping("/listByproId")
    public AjaxResult listByproId(SysWorkflowNode sysWorkflowNode) {
        if (sysWorkflowNode == null || sysWorkflowNode.getProId() == null) {
            throw new RuntimeException("查询参数不能为空");
        }
        try {
            Map<Integer, SysWorkflowNode> integerSysWorkflowNodeMap = sysWorkflowNodeService.listByProId(sysWorkflowNode);
            return AjaxResult.success(integerSysWorkflowNodeMap);
        }catch (Exception e){
            return AjaxResult.error();
        }
    }
}
