package org.springblade.modules.publishevent.listener;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import org.springblade.common.utils.hangxin.HangxinUtil;
import org.springblade.common.utils.hangxin.bean.HangxinResultBean;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.modules.desk.entity.Notice;
import org.springblade.modules.publishevent.event.HangxinNoticeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@AllArgsConstructor
public class NoticeListener implements ApplicationListener<HangxinNoticeEvent> {

	private HangxinUtil hangxinUtil;

	private BladeLogger logger;

	@EventListener
	@Async
	public void onNoticeEvent(HangxinNoticeEvent noticeEvent){
		logger.info("onNoticeEvent", JSONUtil.toJsonStr(noticeEvent));
		Notice notice = noticeEvent.getNotice();
		HangxinResultBean hangxinResultBean = hangxinUtil.sendMsg(notice.getTargetEhrs(), "提示進度", notice.getTitle());
	}

	@Override
	@EventListener
	@Async
	public void onApplicationEvent(HangxinNoticeEvent noticeEvent) {
		/*
		logger.info("onApplicationEvent", JSONUtil.toJsonStr(noticeEvent));
		Notice notice = noticeEvent.getNotice();
		HangxinResultBean hangxinResultBean = hangxinUtil.sendMsg(notice.getTargetEhrs(), "提示進度", notice.getTitle());*/
	}
}
