package com.hw.mes.api.factory;

import com.hw.common.core.domain.R;
import com.hw.mes.api.RemoteMesService;
import com.hw.mes.api.domain.MesBaseBarcodeInfo;
import com.hw.mes.api.domain.MesBaseMaterialInfo;
import com.hw.mes.api.domain.MesBaseStationInfo;
import com.hw.mes.api.domain.vo.MesBaseMaterialInfoVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteMesFallbackFactory implements FallbackFactory<RemoteMesService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteMesFallbackFactory.class);

    @Override
    public RemoteMesService create(final Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteMesService() {
            @Override
            public R<MesBaseBarcodeInfo> getBarcode(String barcodeInfo, String source) {
                return R.fail("获取条码信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<MesBaseMaterialInfo>> getMaterialsByMaterialIds(MesBaseMaterialInfoVo mesBaseMaterialInfo, String source) {
                return R.fail("获取物料信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<MesBaseStationInfo>> getStations(String source) {
                return R.fail("获取工位列表信息失败:" + throwable.getMessage());
            }

            @Override
            public R<MesBaseBarcodeInfo> getBarcodeByBindBarcode(String bindBarcode, String source) {
                return R.fail("获取绑定条码信息失败:" + throwable.getMessage());
            }
        };
    }
}
