package com.ywt.outpatient.service.batch;

import com.ywt.gapi.Result;
import com.ywt.gapi.ResultCode;
import com.ywt.gapi.system.HospitalDept;
import com.ywt.gapi.system.HospitalDeptListRequest;
import com.ywt.gapi.system.HospitalDeptListResponse;
import com.ywt.gapi.system.SystemService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author daiyihua
 * @create 2023-07-06 15:36
 * @program dispatcher
 * @description sys.proto的公共类
 **/
@Service
public class SystemServiceSrv {

    private final Logger logger = LoggerFactory.getLogger(SystemServiceSrv.class);

    @DubboReference
    private SystemService systemServiceBlockingStub;

    /**
     * 获取医生排班记录
     */
    public List<HospitalDept> getHospitalDeptList(int hospitalId, int subHospitalId) {
        try {
            HospitalDeptListRequest req = HospitalDeptListRequest.newBuilder()
                    .setHospitalId(hospitalId)
                    .setSubHospitalId(subHospitalId)
                    .build();
            HospitalDeptListResponse res = systemServiceBlockingStub.getHospitalDeptList(req);
            Result result = res.getResult();
            if (result.getCode() == ResultCode.SUCCEED) {
                return res.getHospitalDeptListList();
            }
        } catch (Exception e) {
            logger.error("SystemServiceSrv>>getHospitalDeptList({},{}):获取科室信息:{}", hospitalId, subHospitalId, e.getMessage(), e);
        }
        return null;
    }
}
