package com.vctgo.system.controller;

import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.vctgo.system.domain.SysConfigPermission;
import com.vctgo.system.service.ISysConfigPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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 com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;

import java.util.List;

/**
 * 权限架构--系统基础配置Controller
 *
 * @author caesar
 * @date 2023-10-08
 */
@Api(tags = "权限架构--系统配置", value = "权限架构--系统配置")
@RestController
@RequestMapping("/common/permission")
public class SysConfigPermissionController extends BaseController {
    @Autowired
    private ISysConfigPermissionService sysConfigPermissionService;

    /**
     * 查询权限架构--系统基础配置分页列表
     */
    @ApiOperation(value = "查询权限架构--系统基础配置分页列表")
    @RequiresPermissions("common:permission:page")
    @GetMapping("/page")
    public AjaxResult page(SysConfigPermission sysConfigPermission) {
        IPage<SysConfigPermission> pageList = sysConfigPermissionService.selectSysConfigPermissionPage(sysConfigPermission);
        return AjaxResult.success(pageList);
    }

    /**
     * 导出权限架构--系统基础配置列表
     */
    @ApiOperation(value = "导出权限架构--系统基础配置分页列表")
    @RequiresPermissions("common:permission:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysConfigPermission sysConfigPermission) {
        List<SysConfigPermission> list = sysConfigPermissionService.selectSysConfigPermissionList(sysConfigPermission);
        ExcelUtil<SysConfigPermission> util = new ExcelUtil<SysConfigPermission>(SysConfigPermission.class);
        util.exportExcel(response, list, "权限架构--系统基础配置数据");
    }

    /**
     * 获取权限架构--系统基础配置详细信息
     */
    @ApiOperation(value = "获取权限架构--系统基础配置详细信息")
    @RequiresPermissions("common:permission:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success((sysConfigPermissionService.selectSysConfigPermissionById(id)));
    }

    /**
     * 新增权限架构--系统基础配置
     */
    @ApiOperation(value = "新增权限架构--系统基础配置")
    @RequiresPermissions("common:permission:add")
    @PostMapping
    public AjaxResult add(@RequestBody SysConfigPermission sysConfigPermission) {
        return toAjax(sysConfigPermissionService.insertSysConfigPermission(sysConfigPermission));
    }

    /**
     * 修改权限架构--系统基础配置
     */
    @ApiOperation(value = "修改权限架构--系统基础配置")
    @RequiresPermissions("common:permission:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SysConfigPermission sysConfigPermission) {
        return toAjax(sysConfigPermissionService.updateSysConfigPermission(sysConfigPermission));
    }

    /**
     * 逻辑删除权限架构--系统基础配置
     */
    @ApiOperation(value = "逻辑删除权限架构--系统基础配置")
    @RequiresPermissions("common:permission:abandon")
    @PutMapping("/abandon/{ids}")
    public AjaxResult abandon(@PathVariable Long[] ids) {
        return toAjax(sysConfigPermissionService.logicalDeleteSysConfigPermissionByIds(ids));
    }

    /**
     * 物理删除权限架构--系统基础配置
     */
    @ApiOperation(value = "物理删除权限架构--系统基础配置")
    @RequiresPermissions("common:permission:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysConfigPermissionService.deleteSysConfigPermissionByIds(ids));
    }
}
