package com.xunmei.system.api;

import com.xunmei.common.core.constant.SecurityConstants;
import com.xunmei.common.core.constant.ServiceNameConstants;
import com.xunmei.common.core.domain.IdName;
import com.xunmei.common.core.domain.R;
import com.xunmei.common.core.vo.IdNameVo;
import com.xunmei.system.api.Eto.OrgListByTypesConditionEto;
import com.xunmei.system.api.domain.SysOrg;
import com.xunmei.system.api.factory.RemoteOrgFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@FeignClient(contextId = "remoteOrgService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteOrgFallbackFactory.class)
public interface RemoteOrgService {
    /**
     * 通过用户名查询用户信息
     *
     * @param source 请求来源
     * @return 结果
     */
    @GetMapping("/org/list/nopage")
    R<List<SysOrg>> getAllOrg(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/dept/selectCheckSubOrgIdList")
    List<Long> selectCheckSubOrgIdList(@RequestParam("orgId") Long orgId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/dept/selectSysOrgById")
    SysOrg selectSysOrgById(@RequestParam("id") Long id, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 查询第一级机构
     * @param source
     * @return
     */
    @GetMapping("/org/selectSysOrgByParentId")
    List<SysOrg> selectSysOrgByParentId(@RequestParam("id")Long id,@RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    @GetMapping("/dept/get/{orgId}")
    SysOrg selectOrgById(@PathVariable("orgId") Long orgId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/dept/listByIds")
    R<List<SysOrg>> listByIds(List<Long> ids, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/dept/findListByOrgType")
    R<List<Long>> findListByOrgType(Integer execOrgType, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/org/sync/batch")
    R<Boolean> batchSaveSyncOrg(@RequestBody List<SysOrg> orgList, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/dept/findListByOrgTypes")
    R<List<SysOrg>> listByTypes(@RequestBody OrgListByTypesConditionEto eto);

    @GetMapping("/dept/top")
    SysOrg selectTopOrg(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/dept/selectByOrgType/{orgType}")
    List<SysOrg> selectByOrgType(@PathVariable("orgType") Integer orgType, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/dept/selectOrgByIdList")
    List<SysOrg> selectOrgByIdList(List<Long> orgList, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/dept/getSysOrgByUserId/{userId}")
    SysOrg getSysOrgByUserId(@PathVariable("userId") Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 获取机构及其上级机构的id列表
     * @param orgId
     * @return
     */
    @GetMapping("/org/getUpOrgs/{orgId}")
    List<Long> getUpOrgs(@PathVariable("orgId") Long orgId);
    @GetMapping("/list/findAllOrg")
    List<SysOrg> findAllOrg(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 获取机构及父级机构的名称
     * @param ids
     * @return
     */
    @GetMapping("/org/getParentNames")
    List<IdNameVo> getParentName(List<Long> ids);
}
