package cn.minestar.agriculture.controller;

import cn.minestar.agriculture.entity.WxMiniMenu;
import cn.minestar.agriculture.service.IWxMiniMenuService;
import cn.minestar.agriculture.vo.WxMiniMenuVo;
import cn.minestar.common.annotation.Log;
import cn.minestar.common.core.domain.AjaxResult;
import cn.minestar.common.enums.BusinessType;
import cn.minestar.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author www.minestar.cn/
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/weixin/api/ma/agriculture/menu")
public class WxMiniMenuController
{
    @Autowired
    private IWxMiniMenuService wxMiniMenuService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:menu:list')")
    @GetMapping("/list")
    public AjaxResult list(WxMiniMenu wxMiniMenu)
    {
        List<WxMiniMenuVo> menus = wxMiniMenuService.selectWxMiniMenuTreeByUserId(wxMiniMenu);
        return AjaxResult.success(menus);
    }

//    @GetMapping("/list")
//    public AjaxResult queryMenus(WxMiniMenu wxMiniMenu)
//    {
//        List<WxMiniMenuVo> menus = wxMiniMenuService.selectWxMiniMenuTreeByUserId(wxMiniMenu);
//        return AjaxResult.success(menus);
//    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:menu:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxMiniMenu wxMiniMenu)
    {
        List<WxMiniMenuVo> list = wxMiniMenuService.selectWxMiniMenuTreeByUserId(wxMiniMenu);
        ExcelUtil<WxMiniMenuVo> util = new ExcelUtil<WxMiniMenuVo>(WxMiniMenuVo.class);
        return util.exportExcel(list, "menu");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:menu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxMiniMenuService.selectWxMiniMenuById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:menu:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxMiniMenu wxMiniMenu)
    {
        return AjaxResult.success(wxMiniMenuService.insertWxMiniMenu(wxMiniMenu));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:menu:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxMiniMenu wxMiniMenu)
    {
        return AjaxResult.success(wxMiniMenuService.updateWxMiniMenu(wxMiniMenu));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:menu:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return AjaxResult.success(wxMiniMenuService.deleteWxMiniMenuByIds(ids));
    }
}
