package com.ruoyi.execution.produce.dispersed.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.execution.produce.dispersed.enetity.BpmExecuteNode;
import com.ruoyi.execution.produce.dispersed.service.IBpmExecuteNodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 节点执行（记录）Controller
 *
 * @author hzh
 * @date 2023-11-01
 */
@RestController
@RequestMapping("/system/execute/node")
public class BpmExecuteNodeController extends BaseController {
    @Autowired
    private IBpmExecuteNodeService bpmExecuteNodeService;

    /**
     * 查询节点执行（记录）列表
     */
    @PreAuthorize("@ss.hasPermi('system:node:list')")
    @GetMapping("/list")
    public TableDataInfo list(BpmExecuteNode bpmExecuteNode) {
        startPage();
        List<BpmExecuteNode> list = bpmExecuteNodeService.selectBpmExecuteNodeList(bpmExecuteNode);
        return getDataTable(list);
    }

    /**
     * 导出节点执行（记录）列表
     */
    @PreAuthorize("@ss.hasPermi('system:node:export')")
    @Log(title = "节点执行（记录）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BpmExecuteNode bpmExecuteNode) {
        List<BpmExecuteNode> list = bpmExecuteNodeService.selectBpmExecuteNodeList(bpmExecuteNode);
        ExcelUtil<BpmExecuteNode> util = new ExcelUtil<BpmExecuteNode>(BpmExecuteNode.class);
        util.exportExcel(response, list, "节点执行（记录）数据");
    }

    /**
     * 获取节点执行（记录）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:node:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bpmExecuteNodeService.selectBpmExecuteNodeById(id));
    }

    /**
     * 新增节点执行（记录）
     */
    @PreAuthorize("@ss.hasPermi('system:node:add')")
    @Log(title = "节点执行（记录）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BpmExecuteNode bpmExecuteNode) {
        return toAjax(bpmExecuteNodeService.insertBpmExecuteNode(bpmExecuteNode));
    }

    /**
     * 修改节点执行（记录）
     */
    @PreAuthorize("@ss.hasPermi('system:node:edit')")
    @Log(title = "节点执行（记录）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BpmExecuteNode bpmExecuteNode) {
        return toAjax(bpmExecuteNodeService.updateBpmExecuteNode(bpmExecuteNode));
    }

    /**
     * 删除节点执行（记录）
     */
    @PreAuthorize("@ss.hasPermi('system:node:remove')")
    @Log(title = "节点执行（记录）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bpmExecuteNodeService.deleteBpmExecuteNodeByIds(ids));
    }
}
