package com.ruoyi.frequency.shield.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.shield.entity.Shield;
import com.ruoyi.frequency.shield.service.ShieldService;
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/shield")
public class ShieldController extends BaseController
{
    @Autowired
    private ShieldService shieldService;

    /**
     * 查询屏蔽用户列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:shield:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shield shield)
    {
        startPage();
        List<Shield> list = shieldService.selectShieldList(shield);
        return getDataTable(list);
    }

    /**
     * 导出屏蔽用户列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:shield:export')")
    @Log(title = "屏蔽用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Shield shield)
    {
        List<Shield> list = shieldService.selectShieldList(shield);
        ExcelUtil<Shield> util = new ExcelUtil<Shield>(Shield.class);
        return util.exportExcel(list, "屏蔽用户数据");
    }

    /**
     * 获取屏蔽用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:shield:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(shieldService.selectShieldById(id));
    }

    /**
     * 新增屏蔽用户
     */
    @PreAuthorize("@ss.hasPermi('frequency:shield:add')")
    @Log(title = "屏蔽用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shield shield)
    {
        return toAjax(shieldService.insertShield(shield));
    }

    /**
     * 修改屏蔽用户
     */
    @PreAuthorize("@ss.hasPermi('frequency:shield:edit')")
    @Log(title = "屏蔽用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shield shield)
    {
        return toAjax(shieldService.updateShield(shield));
    }

    /**
     * 删除屏蔽用户
     */
    @PreAuthorize("@ss.hasPermi('frequency:shield:remove')")
    @Log(title = "屏蔽用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shieldService.deleteShieldByIds(ids));
    }
}
