package com.cico.nest.lcdp.boot.core.qxsd.application.schedule.job;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.cico.nest.lcdp.boot.core.qxsd.domain.gateway.EventGateway;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.EventDetailMapper;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.dataobject.EventDetailDO;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 同步事件--任务(前一天的数据)
 * @author zws
 * @date 2024/8/21
 */

@Component
public class SyncEventJob {

    @Resource
    private EventDetailMapper eventDetailMapper;

    @Resource
    private EventGateway eventGateway;

    //@Scheduled(cron = "0 * * * * ? " )
    public void execute(){
        /**
         * 前一天的开始时间结束时间
         */
        Date yesterday = new Date();
        Date beginDate = DateUtil.beginOfDay(yesterday);
        Date endDate = DateUtil.endOfDay(yesterday);
        List<EventDetailDO> detailDOList = eventGateway.syncEventDetailList(beginDate,endDate);
        if(CollUtil.isNotEmpty(detailDOList)){
            eventDetailMapper.insertBatch(detailDOList);
        }
    }


}
