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 = "info-publish-manager", path = "/infopublish", fallbackFactory = InfoDeviceFeignFallbackFactory.class)
public interface IInfoPublishDeviceFeign extends IFeign {


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

}


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

            @Override
            public Rest<String> deviceCall(DeviceReq deviceReq) {
                return Rest.fail();
            }
        };
    }
}








