From 943c1d3b4ddcd7d9008f69140ad8b40c272aa8c1 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 12 Jun 2024 08:34:16 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=A7=A3=E5=86=B3=E5=9B=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=89=8B=E6=9C=BA=E5=8F=B7=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E8=BD=AE=E8=AF=A2=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=AF=BC=E8=87=B4resource=E6=9C=8D=E5=8A=A1=E7=86=94?= =?UTF-8?q?=E6=96=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hnac/hzims/message/fegin/MessageClient.java | 5 +--- .../hzims/message/service/IMessageService.java | 4 +-- .../service/impl/MailMessageServiceImpl.java | 8 +++++- .../service/impl/SmsMessageServiceImpl.java | 29 ++++++++++++++-------- 4 files changed, 29 insertions(+), 17 deletions(-) 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 c605947..4259974 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 @@ -179,9 +179,6 @@ public class MessageClient extends BladeController implements IMessageClient{ try { for (Long pushId : Func.toLongList(",", smsImmediatelyPushDTO.getPusher())) { User user = UserCache.getUser(pushId); - if (ObjectUtil.isEmpty(user)||ObjectUtil.isEmpty(user.getPhone())){ - continue; - } MessagePushRecordEntity record = BeanUtil.copy(smsImmediatelyPushDTO, MessagePushRecordEntity.class); record.setMessageId(IdWorker.getId()); record.setPusherName(user.getRealName()); @@ -199,7 +196,7 @@ public class MessageClient extends BladeController implements IMessageClient{ record.setSmsParam(JSON.toJSONString(params)); Boolean flag = recordService.sendSmsImmediatelyMsg(record); if (!flag) { - log.error("短信推送失败,参数:" + record.toString()); + log.error("短信推送失败,参数:{}", JSON.toJSONString(record)); } } return R.data(true); diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessageService.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessageService.java index 184e7c7..0c5a7d1 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessageService.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessageService.java @@ -35,9 +35,9 @@ public interface IMessageService { if(ObjectUtil.isNotEmpty(user)) { switch(type) { case MAIL_PUSH: - return Func.isNotEmpty(user.getEmail()) ? user.getEmail() : Long.toString(pusher); + return user.getEmail(); case SMS_PUSH: - return Func.isNotEmpty(user.getPhone()) ? user.getPhone() : Long.toString(pusher); + return user.getPhone(); default: break; } 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 414d532..53dc85f 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 @@ -13,12 +13,14 @@ import lombok.extern.slf4j.Slf4j; 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.Func; 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; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; import org.springframework.web.multipart.MultipartFile; import javax.mail.MessagingException; @@ -79,6 +81,10 @@ public class MailMessageServiceImpl implements IMessageService { @Override public boolean send(MessagePushRecordEntity request) { + String account = getAccountByPusher(Long.parseLong(request.getPusher()), request.getType()); + Assert.isTrue(Func.isNotEmpty(account) && StringUtil.isNotBlank(account) , () -> { + throw new ServiceException("未查询到相关用户,邮件推送失败!"); + }); // 创建复杂有限发送对象 MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper messageHelper; @@ -87,7 +93,7 @@ public class MailMessageServiceImpl implements IMessageService { // 设置发件人邮箱(若配置默认邮箱则不用再设置) messageHelper.setFrom(fromAccount); // 设置收件人邮箱 - messageHelper.setTo(getAccountByPusher(Long.parseLong(request.getPusher()),request.getType())); + messageHelper.setTo(account); // 设置抄报人邮箱(可以不填写) if(StringUtil.isNotBlank(request.getCcAccount())) { messageHelper.setCc(request.getCcAccount()); diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/SmsMessageServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/SmsMessageServiceImpl.java index 29bdb30..be5d801 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/SmsMessageServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/SmsMessageServiceImpl.java @@ -15,6 +15,7 @@ import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.sms.model.SmsResponse; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; import org.springblade.resource.feign.ISmsClient; import org.springframework.stereotype.Service; import org.springframework.util.Assert; @@ -48,11 +49,15 @@ public class SmsMessageServiceImpl implements IMessageService { @Override public boolean send(MessagePushRecordEntity request) { + String account = this.getAccountByPusher(Long.parseLong(request.getPusher()), request.getType()); + Assert.isTrue(Func.isNotEmpty(account) && StringUtil.isNotBlank(account) ,() -> { + throw new ServiceException("未查询到相关用户,短信推送失败!"); + }); R response = smsClient.sendMessage( - Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId(), - request.getResourceCode(), - request.getSmsParam(), - this.getAccountByPusher(Long.parseLong(request.getPusher()),request.getType()) + Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId(), + request.getResourceCode(), + request.getSmsParam(), + account ); if(ObjectUtils.isEmpty(response.getData())) { Assert.isTrue(response.isSuccess(), () -> { @@ -68,11 +73,15 @@ public class SmsMessageServiceImpl implements IMessageService { } public R sendSmsByRecord(MessagePushRecordEntity request) { - return smsClient.sendMessage( - Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId(), - request.getResourceCode(), - request.getSmsParam(), - this.getAccountByPusher(Long.parseLong(request.getPusher()),request.getType()) - ); + String account = this.getAccountByPusher(Long.parseLong(request.getPusher()), request.getType()); + if(Func.isNotEmpty(account) && StringUtil.isNotBlank(account)) { + return smsClient.sendMessage( + Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId(), + request.getResourceCode(), + request.getSmsParam(), + account + ); + } + return R.fail("未查询到相关用户,短信推送失败!"); } }