package com.cn.fdapfe.biz.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.cn.fdapfe.common.annotation.Log;
import com.cn.fdapfe.common.core.controller.BaseController;
import com.cn.fdapfe.common.core.domain.AjaxResult;
import com.cn.fdapfe.common.enums.BusinessType;
import com.cn.fdapfe.biz.domain.WorkflowNode;
import com.cn.fdapfe.biz.service.IWorkflowNodeService;
import com.cn.fdapfe.common.utils.poi.ExcelUtil;
import com.cn.fdapfe.common.core.page.TableDataInfo;

/**
 * 流程节点Controller
 * 
 * @author Allen
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/workflow/node")
public class WorkflowNodeController extends BaseController
{
    @Autowired
    private IWorkflowNodeService workflowNodeService;

    /**
     * 查询流程节点列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:node:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkflowNode workflowNode)
    {
        startPage();
        List<WorkflowNode> list = workflowNodeService.selectWorkflowNodeList(workflowNode);
        return getDataTable(list);
    }

    /**
     * 导出流程节点列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:node:export')")
    @Log(title = "流程节点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkflowNode workflowNode)
    {
        List<WorkflowNode> list = workflowNodeService.selectWorkflowNodeList(workflowNode);
        ExcelUtil<WorkflowNode> util = new ExcelUtil<WorkflowNode>(WorkflowNode.class);
        util.exportExcel(response, list, "流程节点数据");
    }

    /**
     * 获取流程节点详细信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:node:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workflowNodeService.selectWorkflowNodeById(id));
    }

    /**
     * 新增流程节点
     */
    @PreAuthorize("@ss.hasPermi('workflow:node:add')")
    @Log(title = "流程节点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkflowNode workflowNode)
    {
        return toAjax(workflowNodeService.insertWorkflowNode(workflowNode));
    }

    /**
     * 修改流程节点
     */
    @PreAuthorize("@ss.hasPermi('workflow:node:edit')")
    @Log(title = "流程节点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkflowNode workflowNode)
    {
        return toAjax(workflowNodeService.updateWorkflowNode(workflowNode));
    }

    /**
     * 删除流程节点
     */
    @PreAuthorize("@ss.hasPermi('workflow:node:remove')")
    @Log(title = "流程节点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workflowNodeService.deleteWorkflowNodeByIds(ids));
    }
}
