package com.ywt.outpatient.service.batch;

import com.ywt.gapi.ResultCode;
import com.ywt.gapi.third.taihe.GetScheduleListRequest;
import com.ywt.gapi.third.taihe.GetScheduleListResponse;
import com.ywt.gapi.third.taihe.Schedule;
import com.ywt.gapi.third.taihe.TaiheService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

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

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

    @DubboReference
    private TaiheService taiheServiceBlockingStub;

    /**
     * 获取医生排班记录
     */
    public List<Schedule> getScheduleList(String serviceDate, String serviceEndDate, String doctorCode, String deptCode, int hospitalId) {
        try {
            GetScheduleListRequest request = GetScheduleListRequest.newBuilder()
                    .setServiceDate(serviceDate)
                    .setServiceEndDate(serviceEndDate)
                    .setDoctorCode(doctorCode)
                    .setDeptCode(deptCode)
                    .setHospitalId(hospitalId)
                    .build();
            GetScheduleListResponse res = taiheServiceBlockingStub.getScheduleList(request);
            logger.error("TaiheServiceSrv>>getScheduleList({},{},{},{},{}, +++ {}, --- {}):获取排班信息:{}",
                    serviceDate, serviceEndDate, doctorCode, deptCode, hospitalId, res.getCode(), res.getMsg(), res.getSchedulesList().size());
            if (res.getCode() == ResultCode.SUCCEED_VALUE) {
                return res.getSchedulesList();
            }
        } catch (Exception e) {
            logger.error("TaiheServiceSrv>>getScheduleList({},{},{},{},{}):获取排班信息:{}",
                    serviceDate, serviceEndDate, doctorCode, deptCode, hospitalId, e.getMessage(), e);
        }
        return null;
    }
}
