package com.koobietech.eas.controller;

import com.github.pagehelper.PageHelper;
import com.koobietech.eas.common.result.JsonPageResult;
import com.koobietech.eas.common.result.JsonResult;
import com.koobietech.eas.common.result.PageData;
import com.koobietech.eas.mbg.model.EasSysPermission;
import com.koobietech.eas.service.EasSysPermissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@Tag(name = "权限模块")
@RequestMapping("/permission")
public class EasSysPermissionController {

    @Resource
    EasSysPermissionService easSysPermissionService;

    @PostMapping("/query")
    @Operation(summary = "查询权限", description = "根据参数查询基本权限表信息")
    public JsonPageResult query(@RequestBody(required = false) EasSysPermission permission,
                                @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageData ret = easSysPermissionService.query(permission);
        return JsonPageResult.data(ret);
    }

    @PostMapping("/add")
    @Operation(summary = "添加权限", description = "录入权限表基本信息")
    public JsonResult add(@RequestBody EasSysPermission permission) {
        Boolean ret = easSysPermissionService.add(permission);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除权限", description = "删除权限表数据根据ID")
    public JsonResult delete(@RequestParam Integer id) {
        Boolean ret = easSysPermissionService.delete(id);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }

    @PutMapping("/update")
    @Operation(summary = "更新权限", description = "更新权限表信息")
    public JsonResult update(@RequestBody EasSysPermission permission) {
        Boolean ret = easSysPermissionService.update(permission);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }
}
