package com.mortals.xhx.feign.device;

import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.device.DeviceMsgReqPdu;
import com.mortals.xhx.common.pdu.device.DevicePdu;
import com.mortals.xhx.feign.IFeign;
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.*;

import java.util.List;

/**
 * 设备 消息 Feign接口
 *
 * @author zxfei
 * @date 2023-02-25
 */
@FeignClient(name = "device-manager", path = "/m", fallbackFactory = DeviceFeignFallbackFactory.class)
public interface IDeviceMessageFeign extends IFeign {


    /**
     * 设备消息通知
     *
     * @param devicePdu
     * @return
     */
    @PostMapping(value = "/api/callbackByProduct")
    Rest<String> callbackByProduct(@RequestBody DeviceMsgReqPdu devicePdu);


}


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

            @Override
            public Rest<String> callbackByProduct(DeviceMsgReqPdu devicePdu) {
                return Rest.fail("发送消息失败，请稍后再试!");
            }
        };
    }
}








