package org.dromara.erp.task;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.erp.service.IErpOrderService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * ERP 订单状态同步定时任务
 * <p>
 * 每分钟执行一次，将 ERP 系统中的订单状态同步到本地订单表
 *
 * @author Antigravity
 */
@Slf4j
@RequiredArgsConstructor
@Component
public class ErpOrderSyncTask {

    private final IErpOrderService erpOrderService;

    /**
     * 每 60 秒同步一次 ERP 订单状态
     */
    @Scheduled(fixedRate = 60000)
    public void syncOrderStatus() {
        log.debug("[定时任务] 开始同步 ERP 订单状态...");
        try {
            erpOrderService.syncErpOrderStatus();
        } catch (Exception e) {
            log.error("[定时任务] ERP 订单状态同步异常: {}", e.getMessage(), e);
        }
    }

}
