package com.prolog.eis.schedule;

import com.prolog.eis.common.util.RunTimeHelper;
import com.prolog.eis.core.dto.route.CarryTaskCallbackDto;
import com.prolog.eis.service.core.EisCallBackService;
import com.prolog.eis.service.feign.RouteFeignService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class EisCallBackSchedule {

    private static final Logger LOGGER = LoggerFactory.getLogger(EisCallBackSchedule.class);

    private final RouteFeignService plgFeignRouteClient;

    private final EisCallBackService eisCallBackService;


    @Scheduled(initialDelay = 3000, fixedDelay = 1000)
    public void doCallBack() throws Exception {
        RunTimeHelper.RunDispatch("route产品cb表处理", () -> {
            List<CarryTaskCallbackDto> allCallback = plgFeignRouteClient.getAllCallBack();
            if (!allCallback.isEmpty()) {
                for (CarryTaskCallbackDto carryTaskCallbackDto : allCallback) {
                    try {
                        eisCallBackService.handleCallBackData(carryTaskCallbackDto);
                    } catch (Exception e) {
                        LOGGER.error("回告上游失败:" + e.getMessage());
                    }
                }
            }
        });
    }

}
