package com.yida.data.school.index.controller;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.entity.school.EduSchoolMenu;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.index.service.EduSchoolMenuService;
import com.yida.data.school.vo.index.MenuInfoVO;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * Controller
 *
 * @author zhanghaijun
 * @date 2021-07-19 17:21:58
 */
@Api(tags = "校园主页-菜单")
@Slf4j
@RestController
@RequestMapping("/index/menu")
@RequiredArgsConstructor
public class EduSchoolMenuController {

    private final EduSchoolMenuService eduSchoolMenuService;

    @ApiOperation("查询菜单")
    @GetMapping("/listMenu")
    public ResultBean<List<MenuInfoVO>> listMenu(@ApiParam("学校id") Long schoolId,
                                                 @ApiParam("0-家长，1-教师") Integer type) {
        if (schoolId == null) {
            CurrentUser currentUser = FebsUtil.getCurrentUser();
            schoolId = currentUser.getDeptId();
        }
        return ResultBean.buildSuccess(eduSchoolMenuService.listMenu(schoolId, type));
    }

    @ApiOperation("新增、修改菜单")
    @PostMapping("/saveMenu")
    public ResultBean saveMenu(@RequestBody EduSchoolMenu menu) {
        if (menu.getSchoolId() == null) {
            menu.setSchoolId(FebsUtil.getCurrentUser().getDeptId());
        }
        eduSchoolMenuService.saveMenu(menu);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除菜单")
    @PostMapping("/delMenuBatch")
    public ResultBean delMenuBatch(@RequestBody List<Long> ids) {
        eduSchoolMenuService.delMenuBatch(ids);
        return ResultBean.buildSuccess();
    }
}
