use of org.hzero.boot.message.entity.Receiver in project choerodon-asgard by open-hand.
the class NoticeServiceImpl method sendSagaFailNotice.
@Override
@Async("notify-executor")
public void sendSagaFailNotice(SagaInstanceDTO instance) {
// 捕获异常,以免影响saga一致性
try {
// 构建消息对象
MessageSender messageSender = new MessageSender();
// 消息code
messageSender.setMessageCode(BusinessTypeCode.SAGA_INSTANCE_FAIL.value());
// 默认为0L,都填0L,可不填写
messageSender.setTenantId(0L);
// 消息参数 消息模板中${projectName}
Map<String, String> argsMap = new HashMap<>();
argsMap.put("sagaInstanceId", instance.getId().toString());
argsMap.put("sagaCode", instance.getSagaCode());
argsMap.put("level", instance.getLevel());
User user = iamFeignClient.queryInfo(instance.getCreatedBy()).getBody();
// 接收者
List<Receiver> receiverList = new ArrayList<>();
Receiver receiver = new Receiver();
receiver.setUserId(user.getId());
// 发送邮件消息时 必填
receiver.setEmail(user.getEmail());
// 发送短信消息 必填
receiver.setPhone(user.getPhone());
// 必填
receiver.setTargetUserTenantId(user.getOrganizationId());
argsMap.put("userName", user.getRealName());
receiverList.add(receiver);
messageSender.setReceiverAddressList(receiverList);
messageSender.setArgs(argsMap);
Map<String, Object> objectMap = new HashMap<>();
// 发送组织层和项目层消息时必填 当前组织id
addSourceId(objectMap, instance.getLevel(), instance.getSourceId());
messageSender.setAdditionalInformation(objectMap);
messageClient.async().sendMessage(messageSender);
} catch (Exception e) {
LOGGER.error("saga instance fail send notice fail", e);
}
}
use of org.hzero.boot.message.entity.Receiver in project choerodon-asgard by open-hand.
the class NoticeServiceImpl method sendSagaFailNoticeForVindicator.
@Override
@Async("notify-executor")
public void sendSagaFailNoticeForVindicator(SagaInstanceDTO instance) {
try {
if (mapEvent.containsKey(instance.getSagaCode())) {
List<User> userList = baseServiceClientOperator.listVindicators();
if (!CollectionUtils.isEmpty(userList)) {
Map<String, String> argsMap = new HashMap<>();
argsMap.put("instanceId", instance.getId().toString());
switch(instance.getSagaCode()) {
case IAM_CREATE_ORG_USER:
case IAM_CREATE_USER:
case IAM_CREATE_PROJECT:
Organization organization = baseServiceClientOperator.queryTenantById(instance.getSourceId());
argsMap.put("organizationName", organization.getTenantName());
break;
default:
}
MessageSender messageSender = new MessageSender();
messageSender.setArgs(argsMap);
messageSender.setMessageCode(mapEvent.get(instance.getSagaCode()));
messageSender.setTenantId(0L);
List<Receiver> receiverList = userList.stream().map(t -> {
Receiver receiver = new Receiver();
receiver.setUserId(t.getId());
receiver.setEmail(t.getEmail());
receiver.setPhone(t.getPhone());
receiver.setTargetUserTenantId(Objects.requireNonNull(t.getOrganizationId(), "receiver tenant id can't be null"));
return receiver;
}).collect(Collectors.toList());
Map<String, Object> objectMap = new HashMap<>();
// 发送组织层和项目层消息时必填 当前组织id
addSourceId(objectMap, instance.getLevel(), instance.getSourceId());
messageSender.setAdditionalInformation(objectMap);
messageSender.setReceiverAddressList(receiverList);
messageClient.async().sendMessage(messageSender);
}
}
} catch (Exception e) {
LOGGER.error("saga instance fail send notice fail for vindicator create event", e);
}
}
use of org.hzero.boot.message.entity.Receiver in project choerodon-message by open-hand.
the class RelSendMessageC7nServiceImpl method filterReceiver.
private void filterReceiver(MessageSender messageSender, String messageType) {
TemplateServer templateServer = templateServerService.getTemplateServer(messageSender.getTenantId(), messageSender.getMessageCode());
Long tempServerId = templateServer.getTempServerId();
Long projectId = null;
Long envId = null;
String eventName = null;
if (!CollectionUtils.isEmpty(messageSender.getAdditionalInformation()) && !ObjectUtils.isEmpty(messageSender.getAdditionalInformation().get(MessageAdditionalType.PARAM_PROJECT_ID.getTypeName()))) {
projectId = Long.valueOf(String.valueOf(messageSender.getAdditionalInformation().get(MessageAdditionalType.PARAM_PROJECT_ID.getTypeName())));
}
if (!CollectionUtils.isEmpty(messageSender.getAdditionalInformation()) && !ObjectUtils.isEmpty(messageSender.getAdditionalInformation().get(MessageAdditionalType.PARAM_ENV_ID.getTypeName()))) {
envId = Long.valueOf(String.valueOf(messageSender.getAdditionalInformation().get(MessageAdditionalType.PARAM_ENV_ID.getTypeName())));
}
if (!CollectionUtils.isEmpty(messageSender.getAdditionalInformation()) && !ObjectUtils.isEmpty(messageSender.getAdditionalInformation().get(MessageAdditionalType.PARAM_EVENT_NAME.getTypeName()))) {
eventName = String.valueOf(messageSender.getAdditionalInformation().get(MessageAdditionalType.PARAM_EVENT_NAME.getTypeName()));
}
List<Receiver> receiverList = messageSender.getReceiverAddressList();
if (messageType.equals(HmsgConstant.MessageType.WEB) || messageType.equals(HmsgConstant.MessageType.EMAIL)) {
receiveFilter(receiverList, tempServerId, projectId, messageType);
}
// 如果项目层未启动 则不发送 接受者为null
if ((messageType.equals(HmsgConstant.MessageType.WEB) || messageType.equals(HmsgConstant.MessageType.EMAIL) || messageType.equals(HmsgConstant.MessageType.SMS)) && messageSettingC7nMapper.selectProjectMessage().contains(messageSender.getMessageCode())) {
// 项目层设置未开启
if (!projectFilter(messageSender, projectId, envId, eventName, messageType)) {
receiverList.clear();
}
}
}
use of org.hzero.boot.message.entity.Receiver in project choerodon-message by open-hand.
the class C7nWebSendServiceImpl method sendMessage.
@Override
public Message sendMessage(Long organizationId, MessageSender messageSender) {
Message message = super.sendMessage(organizationId, messageSender);
String marshalByJackson = JsonHelper.marshalByJackson(message);
LOGGER.info(">>>>>>>>>>>>>marshalByJackson:{}>>", marshalByJackson);
// 推送给前端
/**
* {
* "objectVersionNumber": 3,
* "_token": "HuFIjmaG4cz+TpuCS5HbgArigzGiq+XyrilqFCmujSs3G2VY1/eO0IX8Et2UIAxgOiUxFDmdWD6PviC57nxvmNeCOUuFWjf4X3X/Z8v1uqsy/0KBqoGc9k47eOFR8J0R",
* "messageId": 182536898873528320,
* "tenantId": 0,
* "messageTypeCode": "WEB",
* "templateCode": "DISABLE_ORGANIZATION.WEB",
* "lang": "zh_CN",
* "subject": "组织停用",
* "content": "<p>您好,</p><p>您所在的组织:nyintel 已被停用。</p>",
* "sendFlag": 1,
* "transactionId": 182536915520720896,
* "plainContent": "<p>您好,</p><p>您所在的组织:nyintel 已被停用。</p>",
* "templateEditType": "RT"
* }
*/
// 获得消息的接收者
List<Receiver> receiverAddressList = messageSender.getReceiverAddressList();
PopMessageVO popMessageVO = new PopMessageVO();
popMessageVO.setContent(message.getContent());
popMessageVO.setTitle(message.getSubject());
popMessageVO.setMessageId(message.getMessageId());
// 推送给前端
receiverAddressList.forEach(receiver -> {
socketSendHelper.sendByUserId(receiver.getUserId(), "choerodon-pop-ups", JsonHelper.marshalByJackson(popMessageVO));
});
return message;
}
use of org.hzero.boot.message.entity.Receiver in project agile-service by open-hand.
the class SiteMsgUtil method sendProjectReport.
@Async
public void sendProjectReport(Long projectId, List<ProjectReportReceiverDTO> receiverList, String html) {
// 获取接收人, 抄送人
Map<String, List<ProjectReportReceiverDTO>> group = receiverList.stream().collect(Collectors.groupingBy(ProjectReportReceiverDTO::getType));
List<Long> toList = group.get(ProjectReportReceiverDTO.TYPE_RECEIVER).stream().map(ProjectReportReceiverDTO::getReceiverId).collect(Collectors.toList());
Assert.notNull(toList, BaseConstants.ErrorCode.DATA_NOT_EXISTS);
List<Long> ccList = group.getOrDefault(ProjectReportReceiverDTO.TYPE_CC, Collections.emptyList()).stream().map(ProjectReportReceiverDTO::getReceiverId).collect(Collectors.toList());
List<Receiver> toReceiver = new ArrayList<>();
List<Receiver> ccReceiver = new ArrayList<>();
handleReceiver(toReceiver, toList);
Assert.isTrue(CollectionUtils.isNotEmpty(toList), BaseConstants.ErrorCode.DATA_NOT_EXISTS);
handleReceiver(ccReceiver, ccList);
// 设置参数
Map<String, String> argsMap = new HashMap<>();
argsMap.put("data", html);
// 设置sender
MessageSender sender = new MessageSender();
sender.setMessageCode("PROJECT_REPORT");
sender.setTenantId(ConvertUtil.getOrganizationId(projectId));
sender.setReceiverAddressList(toReceiver);
// 额外参数
Map<String, Object> objectMap = new HashMap<>();
objectMap.put(MessageAdditionalType.PARAM_PROJECT_ID.getTypeName(), projectId);
sender.setAdditionalInformation(objectMap);
sender.setCcList(ccReceiver.stream().map(Receiver::getEmail).collect(Collectors.toList()));
sender.setArgs(argsMap);
messageClient.async().sendMessage(sender);
}
Aggregations