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.BpmExecuteNodeMiddle;
import com.ruoyi.execution.produce.dispersed.service.IBpmExecuteNodeMiddleService;
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/middle")
public class BpmExecuteNodeMiddleController extends BaseController {
    @Autowired
    private IBpmExecuteNodeMiddleService bpmExecuteNodeMiddleService;

    /**
     * 查询执行流程用户、节点关联脚本中间列表
     */
    @PreAuthorize("@ss.hasPermi('system:middle:list')")
    @GetMapping("/list")
    public TableDataInfo list(BpmExecuteNodeMiddle bpmExecuteNodeMiddle) {
        startPage();
        List<BpmExecuteNodeMiddle> list = bpmExecuteNodeMiddleService.selectBpmExecuteNodeMiddleList(bpmExecuteNodeMiddle);
        return getDataTable(list);
    }

    /**
     * 导出执行流程用户、节点关联脚本中间列表
     */
    @PreAuthorize("@ss.hasPermi('system:middle:export')")
    @Log(title = "执行流程用户、节点关联脚本中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BpmExecuteNodeMiddle bpmExecuteNodeMiddle) {
        List<BpmExecuteNodeMiddle> list = bpmExecuteNodeMiddleService.selectBpmExecuteNodeMiddleList(bpmExecuteNodeMiddle);
        ExcelUtil<BpmExecuteNodeMiddle> util = new ExcelUtil<BpmExecuteNodeMiddle>(BpmExecuteNodeMiddle.class);
        util.exportExcel(response, list, "执行流程用户、节点关联脚本中间数据");
    }

    /**
     * 获取执行流程用户、节点关联脚本中间详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:middle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bpmExecuteNodeMiddleService.selectBpmExecuteNodeMiddleById(id));
    }

    /**
     * 新增执行流程用户、节点关联脚本中间
     */
    @PreAuthorize("@ss.hasPermi('system:middle:add')")
    @Log(title = "执行流程用户、节点关联脚本中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BpmExecuteNodeMiddle bpmExecuteNodeMiddle) {
        return toAjax(bpmExecuteNodeMiddleService.insertBpmExecuteNodeMiddle(bpmExecuteNodeMiddle));
    }

    /**
     * 修改执行流程用户、节点关联脚本中间
     */
    @PreAuthorize("@ss.hasPermi('system:middle:edit')")
    @Log(title = "执行流程用户、节点关联脚本中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BpmExecuteNodeMiddle bpmExecuteNodeMiddle) {
        return toAjax(bpmExecuteNodeMiddleService.updateBpmExecuteNodeMiddle(bpmExecuteNodeMiddle));
    }

    /**
     * 删除执行流程用户、节点关联脚本中间
     */
    @PreAuthorize("@ss.hasPermi('system:middle:remove')")
    @Log(title = "执行流程用户、节点关联脚本中间", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bpmExecuteNodeMiddleService.deleteBpmExecuteNodeMiddleByIds(ids));
    }
}
