package com.xinelu.manage.controller.scriptinfonode;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.scriptinfonode.ScriptInfoNode;
import com.xinelu.manage.service.scriptinfonode.IScriptInfoNodeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 话术信息节点Controller
 *
 * @author xinelu
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/system/node")
public class ScriptInfoNodeController extends BaseController {
    @Resource
    private IScriptInfoNodeService scriptInfoNodeService;

    /**
     * 查询话术信息节点列表
     */
    @PreAuthorize("@ss.hasPermi('system:node:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScriptInfoNode scriptInfoNode) {
        startPage();
        List<ScriptInfoNode> list = scriptInfoNodeService.selectScriptInfoNodeList(scriptInfoNode);
        return getDataTable(list);
    }

    /**
     * 导出话术信息节点列表
     */
    @PreAuthorize("@ss.hasPermi('system:node:export')")
    @Log(title = "话术信息节点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScriptInfoNode scriptInfoNode) {
        List<ScriptInfoNode> list = scriptInfoNodeService.selectScriptInfoNodeList(scriptInfoNode);
        ExcelUtil<ScriptInfoNode> util = new ExcelUtil<>(ScriptInfoNode.class);
        util.exportExcel(response, list, "话术信息节点数据");
    }

    /**
     * 获取话术信息节点详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:node:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(scriptInfoNodeService.selectScriptInfoNodeById(id));
    }

    /**
     * 新增话术信息节点
     */
    @PreAuthorize("@ss.hasPermi('system:node:add')")
    @Log(title = "话术信息节点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScriptInfoNode scriptInfoNode) {
        return toAjax(scriptInfoNodeService.insertScriptInfoNode(scriptInfoNode));
    }

    /**
     * 修改话术信息节点
     */
    @PreAuthorize("@ss.hasPermi('system:node:edit')")
    @Log(title = "话术信息节点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScriptInfoNode scriptInfoNode) {
        return toAjax(scriptInfoNodeService.updateScriptInfoNode(scriptInfoNode));
    }

    /**
     * 删除话术信息节点
     */
    @PreAuthorize("@ss.hasPermi('system:node:remove')")
    @Log(title = "话术信息节点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(scriptInfoNodeService.deleteScriptInfoNodeByIds(ids));
    }
}
