package com.mosty.bkzx.remote;

import com.alibaba.fastjson.JSON;
import com.mosty.base.model.dto.base.GetSsbmDto;
import com.mosty.base.model.dto.base.SysDeptDTO;
import com.mosty.base.feign.service.MostyBaseFeignService;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *  调用部门信息远程适配层
 * @author kevin
 * @date 2022/7/6 10:37 上午
 * @since 1.0.0
 */
@Slf4j
@Service
@AllArgsConstructor
public class TbBaseAdaptRemoteService {

    private final MostyBaseFeignService mostyBaseFeignService;

    /**
     * 根据部门编码查询部门信息
     * @param orgCode 部门编码
     * @return 部门信息
     */
    public SysDeptDTO getDeptByOrgCode(String orgCode) {
        if (StringUtils.isBlank(orgCode)) {
            return null;
        }
        ResponseResult<SysDeptDTO> responseResult = mostyBaseFeignService.getDeptByOrgCode(orgCode);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("调用部门编码查询部门信息异常 responseResult = {}", JSON.toJSONString(responseResult));
            return null;
        }
        return responseResult.getData();
    }
    // 获取权限查询条件
    public String getSsbm(String ssbmdm, String isChild) {
        GetSsbmDto dto = new GetSsbmDto(ssbmdm, isChild);
        ResponseResult<String> responseResult = mostyBaseFeignService.getSsbm(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("获取权限查询条件异常 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("获取权限查询条件异常");
        }
        return responseResult.getData();
    }

    public String downloadBaes64(String id) {
        if (StringUtils.isBlank(id)) {
            return null;
        }
        ResponseResult<String> responseResult = mostyBaseFeignService.downloadBaes64(id);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询URl异常 responseResult = {}", JSON.toJSONString(responseResult));
            return null;
        }
        return responseResult.getData();
    }
}
