package com.ruoyi.app.utils.event;


import com.ruoyi.system.domain.PushMessage;
import com.ruoyi.system.service.IPushMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class PushEventListener  implements ApplicationListener<PushEvent> {

    @Autowired
    private IPushMessageService pushMessageService;

    @Override
    @Async(value = "threadPoolTaskExecutor")
    public void onApplicationEvent(PushEvent event) {
        PushMessage pushMessage = new PushMessage();
        pushMessage.setTitle(event.getTitle());
        pushMessage.setContent(event.getContent());
        pushMessage.setBody(event.getBody());
        pushMessage.setUserId(event.getUserId());
        pushMessage.setTime(new java.util.Date());
        pushMessageService.insertPushMessage(pushMessage);

    }
}
