package com.vctgo.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.system.domain.SysUserTenant;
import com.vctgo.system.service.ISysUserTenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 集团用户可管理园Controller
 *
 * @author caesar
 * @date 2023-10-26
 */
@Api(tags = "集团用户可管理的幼儿园")
@RestController
@RequestMapping("/manage/tenant")
public class SysUserTenantController extends BaseController {
    @Autowired
    private ISysUserTenantService sysUserTenantService;

    /**
     * 查询集团用户可管理园分页列表
     */
    @ApiOperation(value = "查询集团用户可管理园分页列表")
    @RequiresPermissions("process:tenant:page")
    @GetMapping("/page")
    public AjaxResult page(SysUserTenant sysUserTenant) {
        IPage<SysUserTenant> pageList = sysUserTenantService.selectSysUserTenantPage(sysUserTenant);
        return AjaxResult.success(pageList);
    }

    /**
     * 根据用户Id获取当前集团用户可管理的幼儿园列表
     */
    @ApiOperation(value = "根据用户Id获取当前集团用户可管理的幼儿园列表")
    @RequiresPermissions("process:tenant:list")
    @GetMapping("/list")
    public AjaxResult list(SysUserTenant sysUserTenant) {
        return AjaxResult.success(sysUserTenantService.selectSysUserTenantList(sysUserTenant));
    }

    /**
     * 导出集团用户可管理园列表
     */
    @ApiOperation(value = "导出集团用户可管理园列表")
    @RequiresPermissions("process:tenant:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserTenant sysUserTenant) {
        List<SysUserTenant> list = sysUserTenantService.selectSysUserTenantList(sysUserTenant);
        ExcelUtil<SysUserTenant> util = new ExcelUtil<SysUserTenant>(SysUserTenant.class);
//        util.exportExcel(response, list, "集团用户可管理园数据");
    }

    /**
     * 获取集团用户可管理园详细信息
     */
    @ApiOperation(value = "获取集团用户可管理园详细信息")
    @RequiresPermissions("process:tenant:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success((sysUserTenantService.selectSysUserTenantById(id)));
    }

    /**
     * 新增集团用户可管理园
     */
    @Transactional
    @ApiOperation(value = "新增集团用户可管理园")
    @RequiresPermissions("process:tenant:add")
    @PostMapping
    public AjaxResult add(@RequestBody SysUserTenant sysUserTenant) {
        return toAjax(sysUserTenantService.insertSysUserTenant(sysUserTenant));
    }

    /**
     * 批量新增集团用户可管理园
     */
    @ApiOperation(value = "批量新增集团用户可管理园")
    @RequiresPermissions("process:tenant:batch:add")
    @PostMapping("/batch")
    public AjaxResult add(@RequestBody List<SysUserTenant> sysUserTenantList) {
        return toAjax(sysUserTenantService.insertSysUserTenantList(sysUserTenantList));
    }

    /**
     * 修改集团用户可管理园
     */
    @ApiOperation(value = "修改集团用户可管理园")
    @RequiresPermissions("process:tenant:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserTenant sysUserTenant) {
        return toAjax(sysUserTenantService.updateSysUserTenant(sysUserTenant));
    }

    /**
     * 逻辑删除集团用户可管理园
     */
    @ApiOperation(value = "逻辑删除集团用户可管理园")
    @RequiresPermissions("process:tenant:abandon")
    @PutMapping("/abandon/{ids}")
    public AjaxResult abandon(@PathVariable Long[] ids) {
        return toAjax(sysUserTenantService.logicalDeleteSysUserTenantByIds(ids));
    }

    /**
     * 删除集团用户可管理园
     */
    @ApiOperation(value = "删除集团用户可管理园")
//    @RequiresPermissions("process:tenant:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysUserTenantService.deleteSysUserTenantByIds(ids));
    }
}
