package com.friday.distributor.qrtzjob;

import com.alibaba.fastjson.JSON;
import com.friday.base.common.response.DubboResult;
import com.friday.distributor.constant.DistributorConstant;
import com.friday.operation.api.distributor.dto.DataRequest;
import com.friday.operation.api.distributor.service.IDistributorService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;


@Slf4j
@DisallowConcurrentExecution
public class SyncDataJob extends QuartzJobBean {

    @Autowired
    private IDistributorService distributorService;

    @Override
    protected void executeInternal(JobExecutionContext context) {
    	log.info("SyncDataJob--开始，入参{}", JSON.toJSONString(context.getMergedJobDataMap()));
    	DataRequest dataReq = (DataRequest)context.getMergedJobDataMap().get(DistributorConstant.SYNC_DATA_DATA_MAP_KEY);
    	if(dataReq == null) {
    		log.error("SyncDataJob--获取入参失败");
    		return;
    	}
        DubboResult result = this.distributorService.syncData(dataReq);
        log.info("SyncDataJob--结束,结果{}", JSON.toJSONString(result));
    }
}
