package com.mortals.xhx.feign;

import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.DeviceReq;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 设备 Feign接口
 *
 * @author zxfei
 * @date 2023-02-25
 */
@FeignClient(name = "fill-manager", path = "/fm", fallbackFactory = FillDeviceFeignFallbackFactory.class)
public interface IFillDeviceFeign extends IFeign {



    /**
     * 设备回调
     *
     * @param deviceReq
     * @return
     */
    @PostMapping(value = "/api/device/callback")
    Rest<String> deviceCall(@RequestBody DeviceReq deviceReq);

}


@Slf4j
@Component
class FillDeviceFeignFallbackFactory implements FallbackFactory<IFillDeviceFeign> {
    @Override
    public IFillDeviceFeign create(Throwable t) {
        return new IFillDeviceFeign() {

            @Override
            public Rest<String> deviceCall(DeviceReq deviceReq) {
                return Rest.fail("访问异常");
            }
        };
    }
}








