package com.ruoyi.web.controller.manage;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manage.domain.ChannelNumber;
import com.ruoyi.manage.service.IChannelNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 通道管理Controller
 *
 * @author boman
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/manage/channelNumber")
public class ChannelNumberController extends BaseController {
    @Autowired
    private IChannelNumberService channelNumberService;

    /**
     * 查询通道管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:channelNumber:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelNumber channelNumber) {
        startPage();
        List<ChannelNumber> list = channelNumberService.selectChannelNumberList(channelNumber);
        return getDataTable(list);
    }

    /**
     * 导出通道管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:channelNumber:export')")
    @Log(title = "通道管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChannelNumber channelNumber) {
        List<ChannelNumber> list = channelNumberService.selectChannelNumberList(channelNumber);
        ExcelUtil<ChannelNumber> util = new ExcelUtil<ChannelNumber>(ChannelNumber.class);
        util.exportExcel(response, list, "通道管理数据");
    }

    /**
     * 获取通道管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:channelNumber:query')")
    @GetMapping(value = "/{channelId}")
    public AjaxResult getInfo(@PathVariable("channelId") Long channelId) {
        return success(channelNumberService.selectChannelNumberByChannelId(channelId));
    }

    /**
     * 新增通道管理
     */
    @PreAuthorize("@ss.hasPermi('manage:channelNumber:add')")
    @Log(title = "通道管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelNumber channelNumber) {
        return toAjax(channelNumberService.insertChannelNumber(channelNumber));
    }

    /**
     * 修改通道管理
     */
    @PreAuthorize("@ss.hasPermi('manage:channelNumber:edit')")
    @Log(title = "通道管理", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ChannelNumber channelNumber) {
        return toAjax(channelNumberService.updateChannelNumber(channelNumber));
    }

    /**
     * 删除通道管理
     */
    @PreAuthorize("@ss.hasPermi('manage:channelNumber:remove')")
    @Log(title = "通道管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{channelIds}")
    public AjaxResult remove(@PathVariable Long[] channelIds) {
        return toAjax(channelNumberService.deleteChannelNumberByChannelIds(channelIds));
    }
}
