package com.yonge.cooleshow.admin.controller;

import com.microsvc.toolkit.common.response.paging.PageInfo;
import com.microsvc.toolkit.common.response.paging.QueryInfo;
import com.microsvc.toolkit.common.response.template.R;
import com.yonge.cooleshow.biz.dal.service.TenantGroupService;
import com.yonge.cooleshow.biz.dal.wrapper.TenantGroupWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
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;

@Slf4j
@Validated
@RestController
@RequestMapping("/tenantGroup")
@Api(tags = "机构小组表")
public class TenantGroupController {

    @Autowired
    private TenantGroupService tenantGroupService;

    @ApiOperation(value = "查询分页", notes = "机构小组表- 传入 TenantGroupWrapper.TenantGroupQuery")
    @PreAuthorize("@pcs.hasPermissions('tenantGroup/page', {'BACKEND'})")
    @PostMapping("/page")
    public R<PageInfo<TenantGroupWrapper.TenantGroup>> page(@RequestBody TenantGroupWrapper.TenantGroupQuery query) {
        return R.from(QueryInfo.pageInfo(tenantGroupService.selectPage(QueryInfo.getPage(query), query)));
    }

    @ApiOperation(value = "处理机构小组交接", notes = "处理机构小组交接")
    @PreAuthorize("@pcs.hasPermissions('tenantGroup/adjustTenantGroup', {'BACKEND'})")
    @PostMapping("/adjustTenantGroup")
    public R<Boolean> adjustTenantGroup(@RequestBody TenantGroupWrapper.AdjustTenantGroup adjustTenantGroup) {
        return R.from(tenantGroupService.adjustTenantGroup(adjustTenantGroup));
    }

}