package com.centreproject.system.service.sync.impl;

import com.centreproject.common.websocket.MyWebSocketHandler;
import com.centreproject.system.service.sync.impl.KpiDailyParkRevenueSyncService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;

import java.util.concurrent.Executor;

/**
 * 国籍同步服务
 * @author zhonglei.xu
 */
@Service
@RequiredArgsConstructor
public class KpiVisitorCountryBreakDownSyncService {
    private final Logger logger = LoggerFactory.getLogger(KpiDailyParkRevenueSyncService.class);
    private final Executor virtualThreadExecutor;
    private final MyWebSocketHandler myWebSocketHandler;


    public void startSync(String traceId, Long jobId) {
        // 使用虚拟线程执行同步任务
        virtualThreadExecutor.execute(() -> {
            MDC.put("traceId", traceId);
            try {
                syncData(traceId, jobId);
            } finally {
                MDC.clear();
            }
        });
    }

    private void syncData(String traceId, Long jobId) {
        try{
            // 日志开始
            logger.info("【国籍分布数据同步】开始同步数据");
            // 4. 发送WebSocket通知
//            createWebSocketData(mergedData);
        }catch(Exception e){
            logger.error("同步数据失败", e);
            throw e;
        }
    }
}
