Commit fddb530f by fudahua

feat:批量发送消息接口

parent 0c8ebb86
...@@ -17,6 +17,29 @@ public class NoticeMessageQDTO implements Serializable { ...@@ -17,6 +17,29 @@ public class NoticeMessageQDTO implements Serializable {
private int messageType; private int messageType;
private String templateCode; private String templateCode;
private Map<String, String> contentMap; private Map<String, String> contentMap;
public NoticeMessageQDTO() {
}
/**
* 发送队列需要序列化的字段
*
* @param enterpriseId
* @param clerkId
* @param optTargetId
* @param messageType
* @param contentMap
* @param extendContent
*/
public NoticeMessageQDTO(String enterpriseId, String clerkId, String optTargetId, int messageType, Map<String, String> contentMap, Map<String, Object> extendContent) {
this.enterpriseId = enterpriseId;
this.clerkId = clerkId;
this.optTargetId = optTargetId;
this.messageType = messageType;
this.contentMap = contentMap;
this.extendContent = extendContent;
}
/** /**
* 拓展内容 * 拓展内容
*/ */
......
...@@ -5,9 +5,12 @@ import com.gic.commons.util.GICMQClientUtil; ...@@ -5,9 +5,12 @@ import com.gic.commons.util.GICMQClientUtil;
import com.gic.haoban.manage.api.dto.notify.qdto.NoticeMessageQDTO; import com.gic.haoban.manage.api.dto.notify.qdto.NoticeMessageQDTO;
import com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum; import com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum;
import com.gic.mq.sdk.GicMQClient; import com.gic.mq.sdk.GicMQClient;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
...@@ -58,6 +61,43 @@ public class NoticeMessageUtil { ...@@ -58,6 +61,43 @@ public class NoticeMessageUtil {
} }
} }
/**
* 发送消息
*
* @param list
*/
public static void sendNoticeMessageBatch(List<NoticeMessageQDTO> list) {
if (CollectionUtils.isEmpty(list)) {
logger.info("没有哦需要发送的消息");
return;
}
List<String> ret = new ArrayList<String>();
for (NoticeMessageQDTO noticeMessageQDTO : list) {
String retStr = JSONObject.toJSONString(noticeMessageQDTO);
if (StringUtils.isAnyBlank(noticeMessageQDTO.getEnterpriseId(), noticeMessageQDTO.getClerkId())) {
logger.info("参数不存在:{}", retStr);
throw new RuntimeException("必传参数没传:" + noticeMessageQDTO.getClerkId());
}
NoticeMessageTypeEnum messageTypeEnum = NoticeMessageTypeEnum.getByType(noticeMessageQDTO.getMessageType());
if (messageTypeEnum == null) {
logger.info("类型不存在:{}", retStr);
throw new RuntimeException("消息类型不存在");
}
ret.add(retStr);
logger.info("发送消息单条:{}", retStr);
}
logger.info("批量发送消息:{}", ret.size());
GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try {
clientInstance.sendBatchMessages(NOTICE_MESSAGE, ret);
} catch (Exception e) {
logger.info("发送消息异常:{}", e);
}
}
/** /**
* 发送消息 使用staffId发送 * 发送消息 使用staffId发送
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment