package com.yida.data.school.menu.controller.web;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.menu.EduMenu;
import com.yida.data.school.menu.service.EduMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜谱表 Controller
 *
 * @author ccl
 * @date 2021-09-27 14:22:47
 */
@Api(tags = "菜谱")
@Slf4j
@Validated
@RestController
@RequestMapping("/menu/menu")
@RequiredArgsConstructor
public class EduMenuController {

    private final EduMenuService eduMenuService;

    /**
     * 查询菜单列表数据
     *
     * @param
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/8 17:35
     */
    @ApiOperation("查询菜单列表数据")
    @GetMapping("/findMenuPageList")
    public ResultBean<Page<List<EduMenu>>> findMenuPageList(@ApiParam("菜谱名称") @RequestParam(required = false) String menuName,
                                                            @ApiParam("日期") @RequestParam(required = false) String data,
                                                            @RequestParam(defaultValue = "10") Long pageSize,
                                                            @RequestParam(defaultValue = "1") Long pageNum) {

        Page page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);

        return ResultBean.buildSuccess(eduMenuService.page(page, Wrappers.lambdaQuery(new EduMenu())
                .like(EduMenu::getMenu, menuName)
                .like(EduMenu::getCreateDate, data)));
    }

    /**
     * 保存菜单信息
     * 新增或编辑
     *
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/10 14:23
     */
    @ApiOperation("新增或编辑菜单信息")
    @PostMapping("/saveMenu")
    public ResultBean saveMenu(@RequestBody EduMenu eduMenu) {
        eduMenuService.saveOrUpdate(eduMenu);
        return ResultBean.buildSuccess();
    }

    /**
     * 根据菜单id查询菜单详细信息
     *
     * @param menuId
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/10 15:52
     */
    @ApiOperation("根据菜单id查询菜单详细信息")
    @GetMapping("/findMenu")
    public ResultBean<EduMenu> findMenu(@RequestParam Long menuId) {

        return ResultBean.buildSuccess();
    }

    /**
     * 批量删除菜谱信息
     *
     * @param menuIds
     * @return
     * @Author: ZYJ
     * @Date: 2020/6/10 20:09
     */
    @ApiOperation("批量删除菜谱信息")
    @RequestMapping("/delMenuBatch")
    public ResultBean delMenuBatch(@RequestBody List<Long> menuIds) {

        return ResultBean.buildSuccess();
    }
}
