Commit 40f4437b by 王祖波

优化通知导购 集中下发的问题

parent b6072e12
...@@ -44,6 +44,20 @@ public class NoticeMessageHandler { ...@@ -44,6 +44,20 @@ public class NoticeMessageHandler {
} }
} }
public void sendMessage(NoticeMessageForm noticeMessageForm,int delay){
logger.info("消息中心发送消息实体:{}", JSONObject.toJSONString(noticeMessageForm));
if (ObjectUtil.isEmpty(noticeMessageForm.getMessageCode()) || ObjectUtil.isEmpty(noticeMessageForm.getMqRouterCode())) {
logger.info("消息中心发送消息实体 messageCode 或 mqRouterCode 不存在");
}
GicMQClient client = GICMQClientUtil.getClientInstance();
try {
client.sendMessage(noticeMessageForm.getMqRouterCode(), JSONObject.toJSONString(noticeMessageForm), delay);
} catch (Exception e) {
logger.error("消息中心发送消息实体发送异常 ", e);
}
}
private int sendDelayValue(boolean delay) { private int sendDelayValue(boolean delay) {
if (!delay) { if (!delay) {
return 0; return 0;
......
...@@ -331,8 +331,11 @@ public class NoticeMessageApiServiceImpl implements NoticeMessageApiService { ...@@ -331,8 +331,11 @@ public class NoticeMessageApiServiceImpl implements NoticeMessageApiService {
return ServiceResponse.failure("-1", "模版枚举不存在"); return ServiceResponse.failure("-1", "模版枚举不存在");
} }
List<String> userIdList = relationList.stream().map(StaffClerkRelationDTO::getClerkId).distinct().collect(Collectors.toList()); List<String> userIdList = relationList.stream().map(StaffClerkRelationDTO::getClerkId).distinct().collect(Collectors.toList());
Integer batchInterval = ApolloUtils.notifyBatchInterval();
List<List<String>> listList = ListUtil.split(userIdList, 1000); List<List<String>> listList = ListUtil.split(userIdList, 1000);
for (List<String> list : listList) { // 优化通知导购 集中下发的问题
for (int i = 0; i < listList.size(); i++) {
int delay = batchInterval * i;
noticeMessageHandler.sendMessage(NoticeMessageForm.builder() noticeMessageHandler.sendMessage(NoticeMessageForm.builder()
.messageCode(noticeMessageTypeEnum.getMessageCode()) .messageCode(noticeMessageTypeEnum.getMessageCode())
.mqRouterCode(noticeMessageTypeEnum.getRouterCode()) .mqRouterCode(noticeMessageTypeEnum.getRouterCode())
...@@ -340,8 +343,8 @@ public class NoticeMessageApiServiceImpl implements NoticeMessageApiService { ...@@ -340,8 +343,8 @@ public class NoticeMessageApiServiceImpl implements NoticeMessageApiService {
.createTime(new Date()) .createTime(new Date())
.enterpriseId(notifyMessageBatchQDTO.getEnterpriseId()) .enterpriseId(notifyMessageBatchQDTO.getEnterpriseId())
.uniqueKey(UniqueIdUtils.uniqueLongHex()) .uniqueKey(UniqueIdUtils.uniqueLongHex())
.userIdList(list) .userIdList(listList.get(i))
.variableMap(variableMap).build()); .variableMap(variableMap).build(),delay);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("发送消息通知失败", e); logger.error("发送消息通知失败", e);
......
...@@ -2,9 +2,13 @@ package com.gic.haoban.manage.service.util; ...@@ -2,9 +2,13 @@ package com.gic.haoban.manage.service.util;
import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService; import com.ctrip.framework.apollo.ConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ApolloUtils { public class ApolloUtils {
private static final Logger log = LoggerFactory.getLogger(ApolloUtils.class);
/** /**
* 旧的调用发送,是否采用新的消息中心开关1:是 0:否 * 旧的调用发送,是否采用新的消息中心开关1:是 0:否
* @return * @return
...@@ -14,4 +18,15 @@ public class ApolloUtils { ...@@ -14,4 +18,15 @@ public class ApolloUtils {
String messageCenterSwitch = config.getProperty("messageCenterSwitch", "0"); String messageCenterSwitch = config.getProperty("messageCenterSwitch", "0");
return "1".equals(messageCenterSwitch); return "1".equals(messageCenterSwitch);
} }
/**
* 导购通知一批次间隔时间
* @return
*/
public static Integer notifyBatchInterval() {
Config config = ConfigService.getAppConfig();
String notifyBatchInterval = config.getProperty("notifyBatchInterval", "30");
log.info("导购通知一批次间隔时间:{}", notifyBatchInterval);
return Integer.parseInt(notifyBatchInterval);
}
} }
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