package org.dromara.task;
import lombok.extern.slf4j.Slf4j;
import org.dromara.domain.SenEvents;
import org.dromara.domain.SenEventsMedia;
import org.dromara.domain.SenFlowDetail;
import org.dromara.mapper.SenEventsMapper;
import org.dromara.mapper.SenEventsMediaMapper;
import org.dromara.mapper.SenFlowDetailMapper;
import org.dromara.mapper.SenMonitorTaskMapper;
import lombok.RequiredArgsConstructor;
import java.util.Date;
import java.util.List;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@RequiredArgsConstructor
public class EventTask {
    private final SenMonitorTaskMapper taskMapper;
    private final SenEventsMapper eventMapper;
    private final SenFlowDetailMapper flowMapper;
    private final SenEventsMediaMapper eventsMediaMapper;

    @Scheduled(cron = "0 0/30 * * * ?")
//    @Scheduled(cron = "0 15 10 ? * *")
//    @Scheduled(cron = "*/10 * * * * *")
    public void AiToEventJob() {
        List<SenEvents> taskList = taskMapper.selectScheduledTask();
        for (SenEvents event : taskList) {
            boolean flag = eventMapper.insert(event)>0;
            if(flag){
                SenEventsMedia senEventsMedia = new SenEventsMedia();
                senEventsMedia.setEventId(event.getId());
                senEventsMedia.setMediaType("1");
                senEventsMedia.setFileName("event"+event.getEventType()+"_image.png");
                senEventsMedia.setFilePath("/static/event"+event.getEventType()+".png");
                senEventsMedia.setCreateTime(new Date());
                eventsMediaMapper.insert(senEventsMedia);
            }
        }
        List<SenFlowDetail> flowList = taskMapper.selectFlowTask();
        for (SenFlowDetail flowDetail : flowList) {
            flowMapper.insert(flowDetail);
        }
    }

}