76 lines
2.1 KiB
Java
76 lines
2.1 KiB
Java
|
|
package com.newyetai.usercenter.notice.service;
|
||
|
|
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
import org.slf4j.Logger;
|
||
|
|
import org.slf4j.LoggerFactory;
|
||
|
|
|
||
|
|
import com.newyetai.common.AlitaResult;
|
||
|
|
import com.newyetai.common.freemarker.util.FreeMarkerTemplateUtils;
|
||
|
|
import com.newyetai.mq.consumer.handler.ITopicMqHandler;
|
||
|
|
import com.newyetai.mq.dto.TopicMqMessage;
|
||
|
|
import com.newyetai.mq.util.MqSendUtils;
|
||
|
|
import com.newyetai.security.util.MockUtils;
|
||
|
|
import com.newyetai.usercenter.notice.constant.NoticeChannelTypeEnum;
|
||
|
|
import com.newyetai.usercenter.notice.dto.NoticeSendRecordDTO;
|
||
|
|
import com.newyetai.usercenter.notice.util.NoticeSendRecordUtils;
|
||
|
|
import com.newyetai.usercenter.userprod.constant.UcMqSelfConstants;
|
||
|
|
|
||
|
|
public interface INoticeChannelProvider extends ITopicMqHandler<NoticeSendRecordDTO>{
|
||
|
|
|
||
|
|
Logger LOGGER = LoggerFactory.getLogger(INoticeChannelProvider.class);
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
* @return {@link NoticeChannelTypeEnum}
|
||
|
|
* @author sr on 2021-01-04
|
||
|
|
*/
|
||
|
|
Integer getChannelType();
|
||
|
|
|
||
|
|
default String format(String contentTemplate, Map<String, Object> contentParamDataMap) {
|
||
|
|
return FreeMarkerTemplateUtils.formatString(contentTemplate, contentParamDataMap);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 发送(保存发送记录+明细+处理真实通道消息发送)
|
||
|
|
*
|
||
|
|
* @param noticeSendRecordDTO
|
||
|
|
* @author sr on 2021-02-19
|
||
|
|
*/
|
||
|
|
void send(NoticeSendRecordDTO noticeSendRecordDTO);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 异步,发送mq
|
||
|
|
*
|
||
|
|
* @param noticeSendRecordDTO
|
||
|
|
* @return
|
||
|
|
* @author sr on 2021-02-19
|
||
|
|
*/
|
||
|
|
default AlitaResult<?> asyncDeal(NoticeSendRecordDTO noticeSendRecordDTO) {
|
||
|
|
return MqSendUtils.send(
|
||
|
|
getRoutingKey(),
|
||
|
|
noticeSendRecordDTO);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* mq routingKey: {@link UcMqSelfConstants}.ROUTING_KEY_NOTICE_CHANNEL_DEAL_PREFIX_channelType
|
||
|
|
*/
|
||
|
|
default String getRoutingKey() {
|
||
|
|
return NoticeSendRecordUtils.getNoticeChannelDealKey(getChannelType());
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 接收异步mq消息,处理send
|
||
|
|
*/
|
||
|
|
default void onMessage(TopicMqMessage<NoticeSendRecordDTO> message) {
|
||
|
|
try {
|
||
|
|
// mock用户
|
||
|
|
MockUtils.mockPlatUser();
|
||
|
|
send(message.getData());
|
||
|
|
} catch (Exception e) {
|
||
|
|
LOGGER.info("notice channel deal error:{}", e);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|