package com.diagbot.facade;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.diagbot.client.TranServiceClient;
import com.diagbot.dto.DoctorInfoDTO;
import com.diagbot.dto.RespDTO;
import com.diagbot.entity.DoctorInfo;
import com.diagbot.exception.CommonErrorCode;
import com.diagbot.exception.CommonException;
import com.diagbot.vo.DoctorInfoVO;

/**
 * @Description:
 * @author: wangyu
 * @time: 2018/11/19 19:49
 */
@Component
public class DoctorInfoFacade {
    @Autowired
    private TranServiceClient tranServiceClient;
    /**
     * 获取医生信息
     *
     * @param doctorInfoVo
     * @return
     */
    public List<DoctorInfoDTO> getDoctorInfo(DoctorInfoVO doctorInfoVo) {
        RespDTO<List<DoctorInfoDTO>> doctorInfoDTOList = tranServiceClient.getDoctorInfo(doctorInfoVo);
        if (doctorInfoDTOList == null
                || !CommonErrorCode.OK.getCode().equals(doctorInfoDTOList.code)) {
            throw new CommonException(CommonErrorCode.RPC_ERROR,
                    "获取医生信息失败");
        }
        return doctorInfoDTOList.data;
    }
    
    /**
     * 根据ids获取医生信息map
     * @param ids 医生ids
     * @return 医生信息
     */
    public Map<Long, DoctorInfo> doctorInfoMapByIds(List<Long> ids) {
    	 RespDTO<Map<Long, DoctorInfo>> retData = tranServiceClient.doctorInfoMapByIds(ids);
         if (retData == null
                 || !CommonErrorCode.OK.getCode().equals(retData.code)) {
             throw new CommonException(CommonErrorCode.RPC_ERROR,
                     "获取医生信息失败");
         }
         return retData.data;
    }
    
}
