package com.fs.store.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.store.domain.FsLevel;
import com.fs.store.service.IFsLevelService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 设置用户等级Controller
 * 
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/level")
public class FsLevelController extends BaseController
{
    @Autowired
    private IFsLevelService fsLevelService;

    /**
     * 查询设置用户等级列表
     */
    @PreAuthorize("@ss.hasPermi('store:level:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsLevel fsLevel)
    {
        startPage();
        List<FsLevel> list = fsLevelService.selectFsLevelList(fsLevel);
        return getDataTable(list);
    }

    /**
     * 导出设置用户等级列表
     */
    @PreAuthorize("@ss.hasPermi('store:level:export')")
    @Log(title = "设置用户等级", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsLevel fsLevel)
    {
        List<FsLevel> list = fsLevelService.selectFsLevelList(fsLevel);
        ExcelUtil<FsLevel> util = new ExcelUtil<FsLevel>(FsLevel.class);
        return util.exportExcel(list, "level");
    }

    /**
     * 获取设置用户等级详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:level:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsLevelService.selectFsLevelById(id));
    }

    /**
     * 新增设置用户等级
     */
    @PreAuthorize("@ss.hasPermi('store:level:add')")
    @Log(title = "设置用户等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsLevel fsLevel)
    {
        return toAjax(fsLevelService.insertFsLevel(fsLevel));
    }

    /**
     * 修改设置用户等级
     */
    @PreAuthorize("@ss.hasPermi('store:level:edit')")
    @Log(title = "设置用户等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsLevel fsLevel)
    {
        return toAjax(fsLevelService.updateFsLevel(fsLevel));
    }

    /**
     * 删除设置用户等级
     */
    @PreAuthorize("@ss.hasPermi('store:level:remove')")
    @Log(title = "设置用户等级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsLevelService.deleteFsLevelByIds(ids));
    }
}
