package com.ruoyi.frequency.level.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.level.entity.Level;
import com.ruoyi.frequency.level.service.LevelService;
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-10-19
 */
@RestController
@RequestMapping("/frequency/level")
public class LevelController extends BaseController
{
    @Autowired
    private LevelService levelService;

    /**
     * 查询等级列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:level:list')")
    @PostMapping("/list")
    public TableDataInfo<Level> list(@RequestBody Level level)
    {
        startPage();
        List<Level> list = levelService.selectLevelList(level);
        return getDataTable(list);
    }

    /**
     * 导出等级列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:level:export')")
    @Log(title = "等级", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Level level)
    {
        List<Level> list = levelService.selectLevelList(level);
        ExcelUtil<Level> util = new ExcelUtil<Level>(Level.class);
        return util.exportExcel(list, "等级数据");
    }

    /**
     * 获取等级详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:level:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Level> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(levelService.selectLevelById(id));
    }

    /**
     * 新增等级
     */
    @PreAuthorize("@ss.hasPermi('frequency:level:add')")
    @Log(title = "等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Level level)
    {
        return toAjax(levelService.insertLevel(level));
    }

    /**
     * 修改等级
     */
    @PreAuthorize("@ss.hasPermi('frequency:level:edit')")
    @Log(title = "等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Level level)
    {
        return toAjax(levelService.updateLevel(level));
    }

    /**
     * 删除等级
     */
    @PreAuthorize("@ss.hasPermi('frequency:level:remove')")
    @Log(title = "等级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(levelService.deleteLevelByIds(ids));
    }
}
