package com.yiqi.crm.controller;

import com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.crm.domain.WxMenu;
import com.yiqi.crm.service.IWxMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 微信菜单管理Controller
 *
 * @author ruoyi
 * @date 2023-08-04
 */
@Api(value = "微信菜单管理")
@RestController
@RequestMapping("/wxManage/menu")
public class WxMenuController extends BaseController {
    @Autowired
    private IWxMenuService wxMenuService;

    /**
     * 查询微信菜单管理列表
     */
    @ApiOperation(value = "查询微信菜单管理列表")
//    @PreAuthorize("@ss.hasPermi('wxManage:wxMenu:list')")
    @GetMapping("/list")
    public AjaxResult list(WxMenu wxMenu) {
        List<WxMenu> list = wxMenuService.selectWxMenuList(wxMenu);
        return success(list);
    }

    /**
     * 查询微信菜单类型列表
     */
    @ApiOperation(value = "查询微信菜单类型列表")
//    @PreAuthorize("@ss.hasPermi('wxManage:wxMenu:list')")
    @GetMapping("/getMenuTypeList")
    public AjaxResult getMenuTypeList() {
        List<WxMenu> list = wxMenuService.getMenuTypeList();
        return success(list);
    }

    /**
     * 导出微信菜单管理列表
     */
    @ApiOperation(value = "导出微信菜单管理列表")
//    @PreAuthorize("@ss.hasPermi('wxManage:wxMenu:export')")
    @Log(title = "微信菜单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxMenu wxMenu) {
        List<WxMenu> list = wxMenuService.selectWxMenuList(wxMenu);
        ExcelUtil<WxMenu> util = new ExcelUtil<WxMenu>(WxMenu.class);
        util.exportExcel(response, list, "微信菜单管理数据");
    }

    /**
     * 获取微信菜单管理详细信息
     */
    @ApiOperation(value = "获取微信菜单管理详细信息")
//    @PreAuthorize("@ss.hasPermi('wxManage:wxMenu:query')")
    @GetMapping(value = "/{wxMenuId}")
    public AjaxResult getInfo(@PathVariable("wxMenuId") Long wxMenuId) {
        return success(wxMenuService.selectWxMenuByWxMenuId(wxMenuId));
    }

    /**
     * 新增微信菜单管理
     */
    @ApiOperation(value = "新增微信菜单管理")
//    @PreAuthorize("@ss.hasPermi('wxManage:wxMenu:add')")
    @Log(title = "微信菜单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxMenu wxMenu) {
        return toAjax(wxMenuService.insertWxMenu(wxMenu));
    }

    /**
     * 修改微信菜单管理
     */
    @ApiOperation(value = "修改微信菜单管理")
//    @PreAuthorize("@ss.hasPermi('wxManage:wxMenu:edit')")
    @Log(title = "微信菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxMenu wxMenu) {
        return toAjax(wxMenuService.updateWxMenu(wxMenu));
    }

    /**
     * 删除微信菜单管理
     */
    @ApiOperation(value = "删除微信菜单管理")
//    @PreAuthorize("@ss.hasPermi('wxManage:wxMenu:remove')")
    @Log(title = "微信菜单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wxMenuIds}")
    public AjaxResult remove(@PathVariable Long[] wxMenuIds) {
        return toAjax(wxMenuService.deleteWxMenuByWxMenuIds(wxMenuIds));
    }

    /**
     * 创建微信菜单-同步
     */
    @GetMapping("/createMenu")
    public AjaxResult createMenu() throws WxErrorException {
        wxMenuService.createMenu();
        return success();
    }
}
