package com.xhpc.common.api.factory;

import com.xhpc.common.api.PileOrderService;
import com.xhpc.common.core.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author yuyang
 * @date 2021/8/15 16:55
 */
@Component
public class PileOrderFallbackFactory implements FallbackFactory<PileOrderService> {

    private static final Logger logger = LoggerFactory.getLogger(PileOrderFallbackFactory.class);

    @Override
    public PileOrderService create(Throwable cause) {

        logger.error("订单服务调用失败：{}//fallback",cause.getMessage());
        return new PileOrderService() {
            @Override
            public R pileStartup(String orderNo, Integer status, String remark) {

                return R.fail(3886,"桩启动回调接口失败:" + cause.getMessage());
            }

            @Override
            public R pileStop(String orderNo, Integer status, String remark) {

                return R.fail(3886,"桩停止回调接口失败:" + cause.getMessage());
            }

            @Override
            public R pileEndOrder(String orderNo) {

                return R.fail(3886,"桩订单结束回调接口失败:" + cause.getMessage());
            }

            @Override
            public R pileRimeOrder(String orderNo) {

                return R.fail(3886,"桩实时订单回调接口失败:" + cause.getMessage());
            }

            @Override
            public R abnormalOrder(String orderNo) {
                return R.fail(3886,"订单异常回调接口失败:" + cause.getMessage());
            }

            @Override
            public R pileStartUpBy3rd(String internetSerialNumber, String driverId, Integer chargingAmt, String plateNum, Integer status, String connectorId) {
                return R.fail(3886,"互联网订单启动失败:" + cause.getMessage());
            }

            @Override
            public R pileVin(String serialNumber, String vinNumber) {
                return R.fail(3886,"VIN码启动失败:" + cause.getMessage());
            }

            /**
             * 桩订单实时订单BMS回调接口
             *
             * @param orderNo 订单号
             * @return
             */
            @Override
            public R pileRimeOrderBms(String orderNo) {
                return R.fail("充电过程 BMS 需求与充电机输出失败:" + cause.getMessage());
            }

            /**
             * soc达到系统设置值
             *
             * @param orderNo 订单号
             * @param soc
             * @return
             */
            @Override
            public R constantSoc(String orderNo, String soc) {
                return R.fail("soc达到系统设置值输出失败:" + cause.getMessage());
            }

            @Override
            public R cycStartUp(Long userId, String serialNumber, Integer type, Integer source, BigDecimal money, String phone, String PlateNum) {
                return R.fail("川逸充启动充电失败:" + cause.getMessage());
            }

            @Override
            public R getXhpcPlaceholderOrderTime(String gunNumber) {
                return R.fail("枪占位费计算失败:" + cause.getMessage());
            }

            @Override
            public R getPlaceholderIDs(String[] stationIDs) {
                return R.fail("枪占位费查询失败:" + cause.getMessage());
            }

            @Override
            public R getReturnGunRecord(String serialNumber, String startTime, String endTime) {
                return R.fail("归枪记录:" + cause.getMessage());
            }
        };
    }

}
