package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ss.menu.domain.Menu;
import com.ruoyi.ss.menu.domain.MenuQuery;
import com.ruoyi.ss.menu.domain.MenuVO;
import com.ruoyi.ss.menu.service.IMenuService;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 前端菜单Controller
 *
 * @author qzz
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/system/appMenu")
public class MenuController extends BaseController
{
    @Autowired
    private IMenuService ssMenuService;

    /**
     * 查询前端菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:menu:list')")
    @GetMapping("/list")
    public TableDataInfo list(MenuQuery query)
    {
        startPage();
        startOrderBy();
        List<MenuVO> list = ssMenuService.selectSsMenuList(query);
        return getDataTable(list);
    }

    /**
     * 导出前端菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:menu:export')")
    @Log(title = "前端菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuQuery query)
    {
        List<MenuVO> list = ssMenuService.selectSsMenuList(query);
        ExcelUtil<MenuVO> util = new ExcelUtil<MenuVO>(MenuVO.class);
        util.exportExcel(response, list, "前端菜单数据");
    }

    /**
     * 获取前端菜单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:menu:query')")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable("menuId") Long menuId)
    {
        return success(ssMenuService.selectSsMenuByMenuId(menuId));
    }

    /**
     * 新增前端菜单
     */
    @PreAuthorize("@ss.hasPermi('system:menu:add')")
    @Log(title = "前端菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Menu menu)
    {
        return toAjax(ssMenuService.insertSsMenu(menu));
    }

    /**
     * 修改前端菜单
     */
    @PreAuthorize("@ss.hasPermi('system:menu:edit')")
    @Log(title = "前端菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Menu menu)
    {
        return toAjax(ssMenuService.updateSsMenu(menu));
    }

    /**
     * 删除前端菜单
     */
    @PreAuthorize("@ss.hasPermi('system:menu:remove')")
    @Log(title = "前端菜单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public AjaxResult remove(@PathVariable Long[] menuIds)
    {
        return toAjax(ssMenuService.deleteSsMenuByMenuIds(menuIds));
    }
}
