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("未查询到相关用户,短信推送失败!"); } }