diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/MailMessageDTO.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/MailMessageDTO.java new file mode 100644 index 0000000..45566fc --- /dev/null +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/MailMessageDTO.java @@ -0,0 +1,66 @@ +package com.hnac.hzims.message.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; +import org.springframework.web.multipart.MultipartFile; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +@Data +@EqualsAndHashCode +@ApiModel("邮件消息DTO") +public class MailMessageDTO implements Serializable { + + @ApiModelProperty(value = "机构ID",required = true) + @NotNull(message = "机构ID不能为空") + private Long deptId; + + @ApiModelProperty("机构名称") + private String deptName; + + @ApiModelProperty(value = "业务关键字",required = true) + @NotNull(message = "业务关键字不能为空") + private String businessKey; + + @ApiModelProperty(value = "业务分类。系统通知:system,事务消息:business,日常提醒:dailyRemind,巡检消息:inspect",required = true) + @NotNull(message = "业务分类不能为空") + private String businessClassify; + + @ApiModelProperty("业务任务ID") + @QueryField(condition = SqlCondition.EQUAL) + private Long taskId; + + @NotNull + @ApiModelProperty(value = "内容") + private String content; + + @NotNull + @ApiModelProperty(value = "主题") + private String subject; + + @NotNull + @ApiModelProperty(value = "推送用户") + private String userIds; + + @ApiModelProperty(value = "创建用户") + private Long createUser; + + @ApiModelProperty("邮件内容是否为html") + private Boolean isHtml; + + @ApiModelProperty("邮件附件") + private List appendix; + + @ApiModelProperty("抄送账户") + private String ccAccount; + + @ApiModelProperty(value = "租户ID") + private String tenantId; + +} diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/MessagePushRecordEntity.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/MessagePushRecordEntity.java index c64316e..30bd4ed 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/MessagePushRecordEntity.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/entity/MessagePushRecordEntity.java @@ -13,10 +13,12 @@ import org.springblade.core.mp.support.QueryField; import org.springblade.core.mp.support.SqlCondition; import org.springblade.core.tool.utils.DateUtil; import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.multipart.MultipartFile; import javax.validation.constraints.NotNull; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; @Data @ApiModel(value = "消息推送记录",description = "消息推送记录") @@ -101,4 +103,15 @@ public class MessagePushRecordEntity extends MessageTemplateEntity { @TableField(exist = false) private LocalDate endTime; + @ApiModelProperty("是否为html,邮件发送专用") + @TableField(exist = false) + private Boolean isHtml; + + @ApiModelProperty("邮件附件") + @TableField(exist = false) + private List appendix; + + @ApiModelProperty("抄送账户") + @TableField(exist = false) + private String ccAccount; } diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java index 59f5061..1eaad35 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java @@ -29,6 +29,7 @@ public interface IMessageClient { String GET_TEMPLATE_BY_ID = API_PREFIX + "/getMsgTemplateById"; String SEND_APP_AND_WS_MSG = API_PREFIX + "/sendAppAndWsMsgByUsers"; String SEND_SMS_IMMEDIATELY_MSG = API_PREFIX + "/sendSmsImmediatelyMsg"; + String SEND_MAIL_MSG_BY_USERS = API_PREFIX + "/sendMailMsgByUsers"; /** * 推送消息(短信) @@ -67,6 +68,9 @@ public interface IMessageClient { @PostMapping(value = SEND_APP_AND_WS_MSG,consumes = "application/json; charset=UTF-8") R sendAppAndWsMsgByUsers(@RequestBody BusinessMessageDTO request); + @PostMapping(SEND_MAIL_MSG_BY_USERS) + R sendMailMsgByUsers(@RequestBody MailMessageDTO request); + /** * 发送即时推送短信消息 diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java index 82f232c..b68fedd 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java @@ -43,6 +43,11 @@ public class MessageClientFallback implements IMessageClient { } @Override + public R sendMailMsgByUsers(MailMessageDTO request) { + return R.fail("调用失败!"); + } + + @Override public R sendSmsImmediatelyMsg(SmsImmediatelyPushDTO smsImmediatelyPushDTO) { return R.fail("调用失败!"); } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java index c7a93ff..ebfbd6e 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java @@ -167,12 +167,33 @@ public class MessageClient extends BladeController implements IMessageClient{ }).collect(Collectors.toList()); boolean saveResult = recordService.saveBatch(pushRecords); if(saveResult) { - List appRecords = pushRecords.stream().filter(record -> MessageConstants.APP_PUSH.equals(record.getType())).collect(Collectors.toList()); - // 推送消息 - app - Boolean appFlag = recordService.sendAppMsgByUsers(request, appRecords); - // 推送消息 - web - Boolean wsFlag = recordService.sendWsMsgByUsers(new ArrayList<>(CollectionUtils.subtract(pushRecords, appRecords))); - return R.data(appFlag && wsFlag); + return R.status(recordService.sendMailMsgByUsers(pushRecords)); + } + else { + return R.data(false); + } + } + + @Override + @PostMapping(SEND_MAIL_MSG_BY_USERS) + public R sendMailMsgByUsers(@RequestBody MailMessageDTO request) { + // 保存消息记录 + List pushRecords = Func.toLongList(request.getUserIds()).stream().map(userId -> { + MessagePushRecordEntity record = BeanUtil.copy(request, MessagePushRecordEntity.class); + long messageId = IdWorker.getId(); + record.setDeptName(Func.isNotEmpty(record.getDeptName()) ? record.getDeptName() : this.getDeptNameById(record.getDeptId())); + record.setMessageId(messageId); + record.setPusher(userId.toString()); + record.setPusherName(Optional.ofNullable(UserCache.getUser(userId)).map(User::getName).orElse(null)); + record.setType(MessageConstants.MAIL_PUSH); + record.setPushType(MessageConstants.IMMEDIATELY); + record.setPlanTime(LocalDateTime.now()); + record.setCreateDept(record.getDeptId()); + record.setStatus(MessageConstants.NOT_PUSH); + return record; + }).collect(Collectors.toList()); + if(recordService.saveBatch(pushRecords)) { + return R.status(recordService.sendMailMsgByUsers(pushRecords)); } else { return R.data(false); diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java index b6b82a3..5de3c86 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java @@ -120,6 +120,8 @@ public interface IMessagePushRecordService extends BaseService request); + Boolean sendMailMsgByUsers(List request); + /** * 新人员发送统计 diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MailMessageServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MailMessageServiceImpl.java index d0aa1fc..414d532 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MailMessageServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MailMessageServiceImpl.java @@ -14,6 +14,7 @@ import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; @@ -78,7 +79,37 @@ public class MailMessageServiceImpl implements IMessageService { @Override public boolean send(MessagePushRecordEntity request) { - return false; + // 创建复杂有限发送对象 + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper messageHelper; + try { + messageHelper = new MimeMessageHelper(mimeMessage, true); + // 设置发件人邮箱(若配置默认邮箱则不用再设置) + messageHelper.setFrom(fromAccount); + // 设置收件人邮箱 + messageHelper.setTo(getAccountByPusher(Long.parseLong(request.getPusher()),request.getType())); + // 设置抄报人邮箱(可以不填写) + if(StringUtil.isNotBlank(request.getCcAccount())) { + messageHelper.setCc(request.getCcAccount()); + } + // 设置密送人邮箱(可以不填写) + //messageHelper.setBcc("575814158@qq.com"); + // 设置邮件主题 + messageHelper.setSubject(request.getSubject()); + messageHelper.setText(request.getContent(),request.getIsHtml()); + //填充附件 + if(CollectionUtil.isNotEmpty(request.getAppendix())){ + for (MultipartFile appendix : request.getAppendix()) { + messageHelper.addAttachment(appendix.getName(),appendix); + } + } + //发送邮件 + mailSender.send(mimeMessage); + } catch (MessagingException e) { + e.printStackTrace(); + throw new ServiceException(e.getMessage()); + } + return true; } } diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java index 6383485..9825d76 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java @@ -441,6 +441,23 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl request) { + MailMessageServiceImpl service = SpringUtil.getBean(MailMessageServiceImpl.class); + request.forEach(record -> { + boolean sendFlag = service.send(record); + if (sendFlag) { + this.update(Wrappers.lambdaUpdate() + .set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()) + .set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) + .set(MessagePushRecordEntity::getAccount,service.getAccountByPusher(Long.parseLong(record.getPusher()), record.getType())) + .in(MessagePushRecordEntity::getId, record.getId()) + ); + } + }); + return true; + } + /** * 状态 ===> 状态名称 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java index 79997f8..cbf54a9 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationServiceImpl.java @@ -51,6 +51,9 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import java.util.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; import java.util.stream.Collectors; /** @@ -71,6 +74,7 @@ public class StationServiceImpl extends BaseServiceImpl questionClient.submitStationInfo(configVO.getFdpStationType(), req.getCode(), "运维平台推送"), "智能诊断站点推送").start(); - } + FutureTask fdpPush = new FutureTask<>(() -> { + StationPushConfigEntity config = StationPushConfigEntity.builder().stationType(req.getType()).build(); + StationPushConfigVO configVO = stationPushConfigService.getOne(BeanUtil.copy(config, StationPushConfigDTO.class)); + if (ObjectUtil.isNotEmpty(configVO) && configVO.getIsPush()) { + log.info("{}站点开始智能诊断站点推送", req.getCode()); + return questionClient.submitStationInfo(configVO.getFdpStationType(), req.getCode(), "运维平台推送"); + } + return R.success("推送配置未找到相应配置,暂不推送至FDP"); + }); // 如果设备数据来源未选定其他 则进行站点初始化操作 - if (StationConstants.GATHER.equals(req.getDataOrigin()) && !StationConstants.HZ3000_OTHER.equals(req.getDataSource())) { - log.info("{}站点开始数据平台新建项目", req.getCode()); - new Thread(() -> this.instanceProject(req), "数据平台新建项目").start(); + FutureTask dataPush = new FutureTask<>(() -> { + if (StationConstants.GATHER.equals(req.getDataOrigin()) && !StationConstants.HZ3000_OTHER.equals(req.getDataSource())) { + log.info("{}站点开始数据平台新建项目", req.getCode()); + return R.status(this.instanceProject(req)); + } + return R.success("不满足数据平台推送要求,暂不推送至数据平台"); + }); + new Thread(fdpPush,"智能诊断站点推送").start(); + new Thread(dataPush,"数据平台站点推送").start(); + boolean flag; + try { + flag = fdpPush.get().isSuccess() && dataPush.get().isSuccess(); } + catch (ExecutionException e) { + throw new RuntimeException(e); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + Assert.isTrue(flag,() -> { + throw new ServiceException("站点推送数据平台/FDP失败!"); + }); } @Override