package com.xisc.pm.infra.feign.fallback;

import com.xisc.pm.common.dto.ProductionPlanningApiDTO;
import com.xisc.pm.infra.feign.SmApiFeign;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @date 2024/10/18 16:21
 * @description
 */
@Component
public class SmApiFeignFallbackFactory implements FallbackFactory<SmApiFeign> {
    private static final Logger LOGGER = LoggerFactory.getLogger(SmApiFeignFallbackFactory.class);

    @Override
    public SmApiFeign create(Throwable cause) {
        return new SmApiFeign() {
            @Override
            public ResponseEntity<String> productionPlanningApi(Long organizationId, List<ProductionPlanningApiDTO> requestList) {
                // 记录异常堆栈跟踪信息以进行故障排除
                LOGGER.error("eventExecute-error: {}", ExceptionUtils.getStackTrace(cause));
                // 返回HTTP 500状态码表示服务器错误
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
            }

            @Override
            public ResponseEntity<String> heatRetracted(Long organizationId, List<String> ponoList) {
                LOGGER.error("eventExecute-error: {}", ExceptionUtils.getStackTrace(cause));
                // 返回HTTP 500状态码表示服务器错误
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
            }
        };
    }
}
