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.FsMenu;
import com.fs.store.service.IFsMenuService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 用户端菜单管理Controller
 * 
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/menu")
public class FsMenuController extends BaseController
{
    @Autowired
    private IFsMenuService fsMenuService;

    /**
     * 查询用户端菜单管理列表
     */
    @PreAuthorize("@ss.hasPermi('store:menu:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsMenu fsMenu)
    {
        startPage();
        List<FsMenu> list = fsMenuService.selectFsMenuList(fsMenu);
        return getDataTable(list);
    }

    /**
     * 导出用户端菜单管理列表
     */
    @PreAuthorize("@ss.hasPermi('store:menu:export')")
    @Log(title = "用户端菜单管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsMenu fsMenu)
    {
        List<FsMenu> list = fsMenuService.selectFsMenuList(fsMenu);
        ExcelUtil<FsMenu> util = new ExcelUtil<FsMenu>(FsMenu.class);
        return util.exportExcel(list, "menu");
    }

    /**
     * 获取用户端菜单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:menu:query')")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable("menuId") Long menuId)
    {
        return AjaxResult.success(fsMenuService.selectFsMenuById(menuId));
    }

    /**
     * 新增用户端菜单管理
     */
    @PreAuthorize("@ss.hasPermi('store:menu:add')")
    @Log(title = "用户端菜单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsMenu fsMenu)
    {
        return toAjax(fsMenuService.insertFsMenu(fsMenu));
    }

    /**
     * 修改用户端菜单管理
     */
    @PreAuthorize("@ss.hasPermi('store:menu:edit')")
    @Log(title = "用户端菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsMenu fsMenu)
    {
        return toAjax(fsMenuService.updateFsMenu(fsMenu));
    }

    /**
     * 删除用户端菜单管理
     */
    @PreAuthorize("@ss.hasPermi('store:menu:remove')")
    @Log(title = "用户端菜单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public AjaxResult remove(@PathVariable Long[] menuIds)
    {
        return toAjax(fsMenuService.deleteFsMenuByIds(menuIds));
    }
}
