package com.xinelu.manage.controller.scriptinfoedge;

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.scriptinfoedge.ScriptInfoEdge;
import com.xinelu.manage.service.scriptinfoedge.IScriptInfoEdgeService;
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/edge")
public class ScriptInfoEdgeController extends BaseController {
    @Resource
    private IScriptInfoEdgeService scriptInfoEdgeService;

    /**
     * 查询话术信息分支列表
     */
    @PreAuthorize("@ss.hasPermi('system:edge:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScriptInfoEdge scriptInfoEdge) {
        startPage();
        List<ScriptInfoEdge> list = scriptInfoEdgeService.selectScriptInfoEdgeList(scriptInfoEdge);
        return getDataTable(list);
    }

    /**
     * 导出话术信息分支列表
     */
    @PreAuthorize("@ss.hasPermi('system:edge:export')")
    @Log(title = "话术信息分支", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScriptInfoEdge scriptInfoEdge) {
        List<ScriptInfoEdge> list = scriptInfoEdgeService.selectScriptInfoEdgeList(scriptInfoEdge);
        ExcelUtil<ScriptInfoEdge> util = new ExcelUtil<>(ScriptInfoEdge.class);
        util.exportExcel(response, list, "话术信息分支数据");
    }

    /**
     * 获取话术信息分支详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:edge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(scriptInfoEdgeService.selectScriptInfoEdgeById(id));
    }

    /**
     * 新增话术信息分支
     */
    @PreAuthorize("@ss.hasPermi('system:edge:add')")
    @Log(title = "话术信息分支", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScriptInfoEdge scriptInfoEdge) {
        return toAjax(scriptInfoEdgeService.insertScriptInfoEdge(scriptInfoEdge));
    }

    /**
     * 修改话术信息分支
     */
    @PreAuthorize("@ss.hasPermi('system:edge:edit')")
    @Log(title = "话术信息分支", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScriptInfoEdge scriptInfoEdge) {
        return toAjax(scriptInfoEdgeService.updateScriptInfoEdge(scriptInfoEdge));
    }

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