package cn.ezhizao.project.system.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.system.domain.SysVersionMenu;
import cn.ezhizao.project.system.service.ISysVersionMenuService;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 版本菜单Controller
 *
 * @author ruoyi
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/system/versionMenu")
public class SysVersionMenuController extends BaseController
{
    @Resource
    private ISysVersionMenuService sysVersionMenuService;

    /**
     * 查询版本菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:versionMenu:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVersionMenu sysVersionMenu) throws NoSuchFieldException, IllegalAccessException
    {
//        setTenantId(sysVersionMenu);
        startPage();
        List<SysVersionMenu> list = sysVersionMenuService.getList(sysVersionMenu);
        return getDataTable(list);
    }

    /**
     * 导出版本菜单列表
     */
    @PreAuthorize("@ss.hasPermi('system:versionMenu:export')")
    @Log(title = "版本菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVersionMenu sysVersionMenu) throws NoSuchFieldException, IllegalAccessException
    {
//        setTenantId(sysVersionMenu);
        List<SysVersionMenu> list = sysVersionMenuService.getList(sysVersionMenu);
        ExcelUtil<SysVersionMenu> util = new ExcelUtil<SysVersionMenu>(SysVersionMenu.class);
        util.exportExcel(response, list, "版本菜单数据");
    }

    /**
     * 获取版本菜单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:versionMenu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysVersionMenuService.getById(id));
    }

    /**
     * 新增版本菜单
     */
    @PreAuthorize("@ss.hasPermi('system:versionMenu:add')")
    @Log(title = "版本菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVersionMenu sysVersionMenu) throws NoSuchFieldException, IllegalAccessException
    {
//        setTenantId(sysVersionMenu);
        return toAjax(sysVersionMenuService.save(sysVersionMenu));
    }

    /**
     * 修改版本菜单
     */
    @PreAuthorize("@ss.hasPermi('system:versionMenu:edit')")
    @Log(title = "版本菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVersionMenu sysVersionMenu) throws NoSuchFieldException, IllegalAccessException
    {
//        setTenantId(sysVersionMenu);
        return toAjax(sysVersionMenuService.updateById(sysVersionMenu));
    }

    /**
     * 删除版本菜单
     */
    @PreAuthorize("@ss.hasPermi('system:versionMenu:remove')")
    @Log(title = "版本菜单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(sysVersionMenuService.removeBatchByIds(ids));
    }
}
