package com.playlet.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.playlet.common.annotation.Log;
import com.playlet.common.enums.BusinessType;
import com.playlet.system.domain.PlayletPlatformFlow;
import com.playlet.system.service.IPlayletPlatformFlowService;
import com.playlet.common.core.controller.BaseController;
import com.playlet.common.core.domain.AjaxResult;
import com.playlet.common.utils.poi.ExcelUtil;
import com.playlet.common.core.page.TableDataInfo;

/**
 * 挂载操作流程Controller
 *
 * @author ruoyi
 * @date 2024-04-14
 */
@Controller
@RequestMapping("/system/playlet/flow")
public class PlayletPlatformFlowController extends BaseController
{
    private String prefix = "system/playlet/flow";

    @Autowired
    private IPlayletPlatformFlowService playletPlatformFlowService;

    @RequiresPermissions("playlet:flow:view")
    @GetMapping()
    public String flow()
    {
        return prefix + "/flow";
    }

    /**
     * 查询挂载操作流程列表
     */
    @RequiresPermissions("playlet:flow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletPlatformFlow playletPlatformFlow)
    {
        startPage();
        List<PlayletPlatformFlow> list = playletPlatformFlowService.selectPlayletPlatformFlowList(playletPlatformFlow);
        return getDataTable(list);
    }

    /**
     * 导出挂载操作流程列表
     */
    @RequiresPermissions("playlet:flow:export")
    @Log(title = "挂载操作流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletPlatformFlow playletPlatformFlow)
    {
        List<PlayletPlatformFlow> list = playletPlatformFlowService.selectPlayletPlatformFlowList(playletPlatformFlow);
        ExcelUtil<PlayletPlatformFlow> util = new ExcelUtil<PlayletPlatformFlow>(PlayletPlatformFlow.class);
        return util.exportExcel(list, "挂载操作流程数据");
    }

    /**
     * 新增挂载操作流程
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存挂载操作流程
     */
    @RequiresPermissions("playlet:flow:add")
    @Log(title = "挂载操作流程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletPlatformFlow playletPlatformFlow)
    {
        return toAjax(playletPlatformFlowService.insertPlayletPlatformFlow(playletPlatformFlow));
    }

    /**
     * 修改挂载操作流程
     */
    @RequiresPermissions("playlet:flow:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PlayletPlatformFlow playletPlatformFlow = playletPlatformFlowService.selectPlayletPlatformFlowById(id);
        mmap.put("playletPlatformFlow", playletPlatformFlow);
        return prefix + "/edit";
    }

    /**
     * 修改保存挂载操作流程
     */
    @RequiresPermissions("playlet:flow:edit")
    @Log(title = "挂载操作流程", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletPlatformFlow playletPlatformFlow)
    {
        return toAjax(playletPlatformFlowService.updatePlayletPlatformFlow(playletPlatformFlow));
    }

    /**
     * 删除挂载操作流程
     */
    @RequiresPermissions("playlet:flow:remove")
    @Log(title = "挂载操作流程", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(playletPlatformFlowService.deletePlayletPlatformFlowByIds(ids));
    }
}
