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 = "smart-office-manager", path = "/office", fallbackFactory = OfficeDeviceFeignFallbackFactory.class)
public interface IOfficeDeviceFeign extends IFeign {



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

}


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

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








