package com.jy.system.controller;

import com.jy.framework.model.annotation.JyLog;
import com.jy.framework.model.base.BaseSelectDto;
import com.jy.framework.model.enums.BusinessType;
import com.jy.framework.model.validation.DeleteGroup;
import com.jy.framework.model.validation.DetailGroup;
import com.jy.system.model.dto.SysMenuDto;
import com.jy.system.model.dto.SysMenuSelectDto;
import com.jy.system.model.vo.SysMenuVo;
import com.jy.system.service.SysMenuService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
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;

/**
 * <p>
 * 菜单 前端控制器
 * </p>
 *
 * @author
 * @since 2024-06-20
 */
@RestController
@RequestMapping("/sysMenu")
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;

    /**
     * 菜单分页
     */
    @GetMapping("/getTree")
    public List<SysMenuVo> getTree(SysMenuSelectDto dto) {
        return sysMenuService.getTree(dto);
    }

    /**
     * 菜单明细
     */
    @GetMapping("/getDetail")
    public SysMenuVo getDetail(@Validated(DetailGroup.class) BaseSelectDto dto) {
        return sysMenuService.getDetail(dto.getId());
    }

    /**
     * 菜单新增
     */
    @JyLog(title = "新增菜单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void add(@RequestBody SysMenuDto dto) {
        sysMenuService.add(dto);
    }

    /**
     * 菜单编辑
     */
    @JyLog(title = "编辑菜单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public void edit(@RequestBody SysMenuDto dto) {
        sysMenuService.edit(dto);
    }

    /**
     * 菜单删除
     */
    @JyLog(title = "删除菜单", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public void delete(@Validated(DeleteGroup.class) @RequestBody BaseSelectDto dto) {
        sysMenuService.delete(dto.getId());
    }

}
