package com.sptg.gateway.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.PageBean;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.permissions.api.dto.OrgDto;
import com.sptg.permissions.api.entity.Organization;
import com.sptg.permissions.api.feigns.OrgFeign;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/grid/permissions")
public class PermissionController {

    private final OrgFeign orgFeign;

    /**
     * 功能描述:查询社区列表
     * @return ResultBean<Organization>
     *
     *
     */
    @GetMapping(value = "/org/getList")
    public List<Organization> getList(){
        OrgDto dto = new OrgDto();
        dto.setFlag(OperationConstant.ONE);
        dto.setOrgType(OperationConstant.FOUR);
        //  暂时获取全部社区数据
        dto.setPosition("0/1/");
        return this.orgFeign.selectListByCondition(dto);
    }

    @GetMapping(value = "/agency/pagingQuery")
    public ResultBean<Page> pagingQuery(OrgDto dto, PageBean<Organization,OrgDto> pageBean){
        //  参数校验
        dto = null == dto ? new OrgDto() : dto;
        dto.setPosition("0/1/");
        dto.setFlag(OperationConstant.ONE);
        dto.setOrgType(OperationConstant.FOUR);
        pageBean.setDto(dto);
        Page<Organization> page = this.orgFeign.pagingQuery(pageBean);
        return new ResultBean<>(ResultEnum.SUCCESS,page);
    }

    @GetMapping(value = "/agency/get/{orgId}")
    public ResultBean<Organization> getOrgById(@PathVariable(value = "orgId") Long orgId){
        Organization org = this.orgFeign.getOrgById(orgId);
        return new ResultBean<>(ResultEnum.SUCCESS,org);
    }
}
