package com.reptileclient.jlifeapp.service.impl;

import cn.hutool.core.date.DateUtil;
import com.reptileclient.jlifeapp.service.RetryService;
import com.reptileclient.jlifeapp.util.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;

import java.util.Map;

/**
 * @author fuxubing
 */
@Service
public class RetryServiceImpl implements RetryService {
    private static final Logger logger = LoggerFactory.getLogger(RetryServiceImpl.class);

    @Retryable(value = RestClientException.class, backoff = @Backoff(delay = 5000L, multiplier = 2))
    @Override
    public Map<String, Object> requestPost(String token, String parmJson, String url) {
        logger.info("发起远程API请求: {},请求地址:{}", DateUtil.now(), url);
        return HttpUtil.request(token, parmJson, url);
    }
}
