package com.ruoyi.frequency.block.controller;

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.frequency.block.entity.Block;
import com.ruoyi.frequency.block.service.BlockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 拉黑Controller
 * 
 * @author liwenlong
 * @date 2023-07-22
 */
@RestController
@RequestMapping("/frequency/block")
public class BlockController extends BaseController
{
    @Autowired
    private BlockService blockService;

    /**
     * 查询拉黑列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:block:list')")
    @GetMapping("/list")
    public TableDataInfo list(Block block)
    {
        startPage();
        List<Block> list = blockService.selectBlockList(block);
        return getDataTable(list);
    }

    /**
     * 导出拉黑列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:block:export')")
    @Log(title = "拉黑", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Block block)
    {
        List<Block> list = blockService.selectBlockList(block);
        ExcelUtil<Block> util = new ExcelUtil<Block>(Block.class);
        return util.exportExcel(list, "拉黑数据");
    }

    /**
     * 获取拉黑详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:block:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(blockService.selectBlockById(id));
    }

    /**
     * 新增拉黑
     */
    @PreAuthorize("@ss.hasPermi('frequency:block:add')")
    @Log(title = "拉黑", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Block block)
    {
        return toAjax(blockService.insertBlock(block));
    }

    /**
     * 修改拉黑
     */
    @PreAuthorize("@ss.hasPermi('frequency:block:edit')")
    @Log(title = "拉黑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Block block)
    {
        return toAjax(blockService.updateBlock(block));
    }

    /**
     * 删除拉黑
     */
    @PreAuthorize("@ss.hasPermi('frequency:block:remove')")
    @Log(title = "拉黑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blockService.deleteBlockByIds(ids));
    }
}
