diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/invalid/Create.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/invalid/Create.java new file mode 100644 index 0000000..292a407 --- /dev/null +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/invalid/Create.java @@ -0,0 +1,7 @@ +package com.hnac.hzims.common.invalid; + +import javax.validation.groups.Default; + +public interface Create extends Default { + +} diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/invalid/Update.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/invalid/Update.java new file mode 100644 index 0000000..195a8c4 --- /dev/null +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/invalid/Update.java @@ -0,0 +1,7 @@ +package com.hnac.hzims.common.invalid; + +import javax.validation.groups.Default; + +public interface Update extends Default { + +} diff --git a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/BusinessMessageDTO.java b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/BusinessMessageDTO.java index b3d8d4c..17e566b 100644 --- a/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/BusinessMessageDTO.java +++ b/hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/BusinessMessageDTO.java @@ -2,6 +2,8 @@ package com.hnac.hzims.message.dto; import com.baomidou.mybatisplus.annotation.TableField; import com.fasterxml.jackson.annotation.JsonFormat; +import com.hnac.hzims.common.invalid.Create; +import com.hnac.hzims.common.invalid.Update; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -11,6 +13,7 @@ import org.springblade.core.mp.support.SqlCondition; import org.springblade.core.tool.utils.DateUtil; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.time.LocalDate; @@ -28,33 +31,33 @@ import java.time.LocalDateTime; @EqualsAndHashCode public class BusinessMessageDTO implements Serializable { @ApiModelProperty(value = "机构ID",required = true) - @NotNull(message = "机构ID不能为空") + @NotNull(message = "机构ID不能为空",groups = {Create.class}) private Long deptId; @ApiModelProperty("机构名称") private String deptName; @ApiModelProperty(value = "业务关键字",required = true) - @NotNull(message = "业务关键字不能为空") + @NotBlank(message = "业务关键字不能为空",groups = {Create.class}) private String businessKey; @ApiModelProperty(value = "业务分类。系统通知:system,事务消息:business,日常提醒:dailyRemind,巡检消息:inspect",required = true) - @NotNull(message = "业务分类不能为空") + @NotBlank(message = "业务分类不能为空",groups = {Create.class}) private String businessClassify; @ApiModelProperty("业务任务ID") @QueryField(condition = SqlCondition.EQUAL) private Long taskId; - @NotNull + @NotBlank(message = "内容不能为空",groups = {Create.class}) @ApiModelProperty(value = "内容") private String content; - @NotNull + @NotBlank(message = "主题不能为空",groups = {Create.class}) @ApiModelProperty(value = "主题") private String subject; - @NotNull + @NotBlank(message = "推送用户不能为空",groups = {Create.class}) @ApiModelProperty(value = "推送用户") private String userIds; 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 30bd4ed..ee26429 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 @@ -91,6 +91,9 @@ public class MessagePushRecordEntity extends MessageTemplateEntity { @ApiModelProperty(value = "响应说明") private String respondRemark; + @ApiModelProperty("推送失败结果") + private String faultResult; + @ApiModelProperty("查询开始时间") @DateTimeFormat(pattern = DateUtil.PATTERN_DATE) @JsonFormat(pattern = DateUtil.PATTERN_DATE) diff --git a/hzims-service-api/pom.xml b/hzims-service-api/pom.xml index 745a48f..e3ec04e 100644 --- a/hzims-service-api/pom.xml +++ b/hzims-service-api/pom.xml @@ -33,6 +33,10 @@ + com.hnac.hzims + hzims-biz-common + + org.springblade blade-starter-mybatis diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessageController.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessageController.java index 89a171d..8067449 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessageController.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessageController.java @@ -81,14 +81,4 @@ public class MessageController extends BladeController { return messageService.send(wsPushDto); } - @GetMapping("/sendByUsers") - @ApiOperation("发送APP消息(多人)") - @ApiOperationSupport(order=5) - public R sendByUsers(@ApiParam("消息主题") String subject, - @ApiParam("消息内容") String content, - @ApiParam("用户ID列表") String userIds, - @ApiParam("租户ID") String tenantId) throws Exception { - PushMessageServiceImpl messageService = SpringUtil.getBean(PushMessageServiceImpl.class); - return R.status(messageService.sendByUsers(subject,content, Func.toStrList(",",userIds),tenantId)); - } } 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 2f59dc8..a11c276 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 @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; +import com.hnac.hzims.common.invalid.Create; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.dto.*; import com.hnac.hzims.message.entity.MessagePushRecordEntity; @@ -27,6 +28,7 @@ import org.springblade.system.feign.ISysClient; import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; import org.springframework.util.Assert; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; @@ -146,37 +148,8 @@ public class MessageClient extends BladeController implements IMessageClient{ @Override @PostMapping(value = SEND_APP_AND_WS_MSG , produces="application/json; charset=UTF-8") - public R sendAppAndWsMsgByUsers(@RequestBody BusinessMessageDTO request) { - // 保存消息记录 - List pushRecords = Func.toLongList(request.getUserIds()).stream().flatMap(userId -> { - long messageId = IdWorker.getId(); - return Lists.newArrayList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH).stream().map(messageType -> { - MessagePushRecordEntity record = BeanUtil.copy(request, MessagePushRecordEntity.class); - 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.setPushType(MessageConstants.IMMEDIATELY); - record.setAccount(userId.toString()); - record.setPlanTime(LocalDateTime.now()); - record.setType(messageType); - record.setCreateDept(record.getDeptId()); - record.setStatus(MessageConstants.NOT_PUSH); - return record; - }); - }).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); - } - else { - return R.data(false); - } + public R sendAppAndWsMsgByUsers(@RequestBody @Validated(Create.class) BusinessMessageDTO request) { + return R.status(recordService.sendAppAndWsMsgByUsers(request)); } @Override diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java index 7d95c29..0990bda 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; +import com.hnac.hzims.common.constant.CommonConstant; import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.config.MessageFactory; @@ -16,12 +17,14 @@ import com.hnac.hzims.message.service.IMessagePushRecordService; import com.hnac.hzims.message.service.IMessageService; import com.hnac.hzims.message.service.IMessageTemplateService; import com.hnac.hzims.message.service.impl.PushMessageServiceImpl; +import com.hnac.hzinfo.core.push.model.PushResponse; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +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.SpringUtil; @@ -93,18 +96,27 @@ public class MessagePushSchedule { .collect(Collectors.groupingBy(MessagePushRecordEntity::getSubject)); listMap.forEach((subject,list) -> { try { - boolean pushFlag = pushMessageService.sendByUsers( - subject, - list.stream().map(MessagePushRecordEntity::getContent).collect(Collectors.joining("\r\n")), - Lists.newArrayList(pusher.toString()), - "200000" - ); - if(pushFlag) { - XxlJobLogger.log("消息推送失败,subject为"+subject+";list为:"+JSON.toJSONString(list)); - } + String content = list.stream().map(MessagePushRecordEntity::getContent).collect(Collectors.joining("\r\n")); + ArrayList pushers = Lists.newArrayList(pusher.toString()); + R androidPush = pushMessageService.sendAndroidMsg(subject, content, pushers, CommonConstant.TENANT_ID); + R iosPush = pushMessageService.sendIOSMsg(subject, content, pushers, CommonConstant.TENANT_ID); LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate() - .set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) .in(MessagePushRecordEntity::getId, list.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList())); + String faultResult = ""; + if(!androidPush.isSuccess()) { + updateWrapper.set(MessagePushRecordEntity::getStatus,MessageConstants.PUSH_FAILED); + faultResult += "ANDROID消息推送失败,推送结果为:"+androidPush.getMsg()+";"; + XxlJobLogger.log("ANDROID消息推送失败,subject为"+subject+";list为:"+JSON.toJSONString(list)); + } + if(!iosPush.isSuccess()) { + updateWrapper.set(MessagePushRecordEntity::getStatus,MessageConstants.PUSH_FAILED); + faultResult += "IOS消息推送失败,推送结果为:"+androidPush.getMsg()+";"; + XxlJobLogger.log("IOS消息推送失败,subject为"+subject+";list为:"+JSON.toJSONString(list)); + } + else { + updateWrapper.set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS); + } + updateWrapper.set(MessagePushRecordEntity::getFaultResult,faultResult); recordService.update(updateWrapper); } catch (Exception e) { throw new RuntimeException(e); 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 5de3c86..ac8a05a 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 @@ -105,21 +105,6 @@ public interface IMessagePushRecordService extends BaseService records); - /** - * App多人推送消息 - * @param request 消息内容 - * @param records 消息记录 - * @return 推送结果 - */ - Boolean sendAppMsgByUsers(BusinessMessageDTO request,List records); - - /** - * web多人推送消息 - * @param request 消息记录 - * @return 推送结果 - */ - Boolean sendWsMsgByUsers(List request); - Boolean sendMailMsgByUsers(List request); @@ -136,4 +121,20 @@ public interface IMessagePushRecordService extends BaseService implements IMessagePushRecordService { private final MprNoAurhScopeMapper noAurhScopeMapper; private final IMessageService smsMessageService; + private final ISysClient sysClient; + private final RedisTemplate redisTemplate; + @Value("${hzims.message.redis-key.app-push}") + private String appPushRedisKey; @Override public List list(MessagePushRecordEntity request) { @@ -94,14 +107,13 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpllambdaUpdate() - .set(MessagePushRecordEntity::getStatus,MessageConstants.PUSH_SUCCESS) - .set(MessagePushRecordEntity::getPushTime,LocalDateTime.now()) - .eq(MessagePushRecordEntity::getId,record.getId()) - ); + SmsMessageServiceImpl smsService = SpringUtil.getBean(SmsMessageServiceImpl.class); + if(this.saveOrUpdate(record)) { + R sendResult = smsService.sendSmsByRecord(record); + if(sendResult.isSuccess()) { + record.setStatus(MessageConstants.PUSH_SUCCESS); + record.setPushTime(LocalDateTime.now()); + } + else { + record.setStatus(MessageConstants.PUSH_FAILED); + record.setFaultResult(sendResult.getMsg()); + } + this.updateById(record); + } + return true; + } + + /** + * 推送APP即时消息 + * @param record 消息记录 + * @return 推送结果 + */ + private Boolean sendAppImmediatelyMsg(MessagePushRecordEntity record) { + if(this.saveOrUpdate(record)) { + PushMessageServiceImpl pushService = SpringUtil.getBean(PushMessageServiceImpl.class); + if(pushService.send(record)) { + record.setStatus(MessageConstants.PUSH_SUCCESS); + record.setPushTime(LocalDateTime.now()); + } + else { + record.setStatus(MessageConstants.PUSH_FAILED); } + this.updateById(record); } return true; } + private Boolean sendWsImmediatelyMsg(MessagePushRecordEntity record) { + if(this.saveOrUpdate(record)) { + WebsocketServiceImpl wsService = SpringUtil.getBean(WebsocketServiceImpl.class); + if(wsService.send(record)) { + record.setStatus(MessageConstants.PUSH_SUCCESS); + record.setPushTime(LocalDateTime.now()); + } + else { + record.setStatus(MessageConstants.PUSH_FAILED); + } + this.updateById(record); + } + return true; + } + + + @Override + public Boolean sendImmediatelyMSg(MessagePushRecordEntity record) { + Assert.isTrue(MessageConstants.IMMEDIATELY.equals(record.getPushType()),() -> { + throw new ServiceException("该消息记录推送类型错误,只能为即时推送!"); + }); + switch(record.getType()) { + case MessageConstants.APP_PUSH: + return this.sendAppImmediatelyMsg(record); + case MessageConstants.WX_PUSH: + break; + case MessageConstants.WS_PUSH: + return this.sendWsImmediatelyMsg(record); + case MessageConstants.SMS_PUSH: + return this.sendSmsImmediatelyMsg(record); + default: + break; + } + return true; + } + + @Override + public Boolean sendAppAndWsMsgByUsers(BusinessMessageDTO request) { + // 保存消息记录 + List pushRecords = Func.toLongList(request.getUserIds()).stream().flatMap(userId -> { + long messageId = IdWorker.getId(); + return Lists.newArrayList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH).stream().map(messageType -> { + MessagePushRecordEntity record = BeanUtil.copy(request, MessagePushRecordEntity.class); + 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.setPushType(MessageConstants.IMMEDIATELY); + record.setAccount(userId.toString()); + record.setPlanTime(LocalDateTime.now()); + record.setType(messageType); + record.setCreateDept(record.getDeptId()); + record.setStatus(MessageConstants.NOT_PUSH); + return record; + }); + }).collect(Collectors.toList()); + if(this.saveBatch(pushRecords)) { + // 推送消息 + WebsocketServiceImpl wsMessageService = SpringUtil.getBean(WebsocketServiceImpl.class); + pushRecords.forEach(record -> { + if(MessageConstants.APP_PUSH.equals(record.getType())) { + // APP消息存入redis中进行消费 + redisTemplate.opsForList().leftPush(appPushRedisKey.concat(":").concat(record.getPusher()), record); + } else if (MessageConstants.WS_PUSH.equals(record.getType())) { + // WEB消息调用接口直接进行推送 + if(wsMessageService.send(record)) { + record.setPushTime(LocalDateTime.now()); + record.setStatus(MessageConstants.PUSH_SUCCESS); + } + else { + record.setStatus(MessageConstants.PUSH_FAILED); + } + this.updateById(record); + } + + }); + return true; + } + return false; + } + + /** + * 根据机构ID获取机构名称 + * @param deptId 机构ID + * @return 机构名称 + */ + private String getDeptNameById(Long deptId) { + return Optional.ofNullable(sysClient.getDeptName(deptId)).filter(r -> r.isSuccess()).map(R::getData).orElse(null); + } /** * 推送成功失败统计 @@ -408,40 +529,6 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl records) { - PushMessageServiceImpl service = SpringUtil.getBean(PushMessageServiceImpl.class); - try { - boolean sendFlag = service.sendByUsers(request.getSubject(), request.getContent(), Arrays.asList(request.getUserIds().split(",")), request.getTenantId()); - if (sendFlag) { - return this.update(Wrappers.lambdaUpdate() - .set(MessagePushRecordEntity::getPushTime, LocalDateTime.now()) - .set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS) - .in(MessagePushRecordEntity::getId, records.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList())) - ); - } - return false; - } catch (Exception e) { - throw new ServiceException(e.getMessage()); - } - } - - @Override - public Boolean sendWsMsgByUsers(List request) { - WebsocketServiceImpl service = SpringUtil.getBean(WebsocketServiceImpl.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) - .in(MessagePushRecordEntity::getId, record.getId()) - ); - } - }); - return true; - } - - @Override public Boolean sendMailMsgByUsers(List request) { MailMessageServiceImpl service = SpringUtil.getBean(MailMessageServiceImpl.class); request.forEach(record -> { diff --git a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java index fcc7621..79ee3ed 100644 --- a/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java +++ b/hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java @@ -33,6 +33,7 @@ import org.springframework.util.Assert; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.FutureTask; import java.util.concurrent.atomic.AtomicReference; @@ -99,13 +100,6 @@ public class PushMessageServiceImpl implements IMessageService { // App消息推送因腾讯云推送限制同一标签一段时间内无法推送多条消息,现将app推送改造成由redis定时推送 Long pushResult = redisTemplate.opsForList().leftPush(appPushRedisKey.concat(":").concat(request.getPusher()), request); return Func.isNotEmpty(pushResult); -// String tenantId = Func.isNotEmpty(AuthUtil.getTenantId()) ? AuthUtil.getTenantId() : request.getTenantId(); -// try { -// return this.sendByUsers(request.getSubject(), request.getContent(), Func.toStrList(",",request.getPusher()),tenantId); -// } -// catch (Exception e) { -// throw new ServiceException(e.getMessage()); -// } } /** @@ -116,33 +110,51 @@ public class PushMessageServiceImpl implements IMessageService { * @param tenantId 租户ID * @return */ - public boolean sendByUsers(String subject, String content, List userIds,String tenantId) throws Exception { - // 安卓推送 - FutureTask androidPush = new FutureTask<>(() -> { - PushInfoVO pushInfoVO = new PushInfoVO(); - PushPlatform pushPlatform = PushPlatform.newBuilder().addPlatformType(PlatformType.Android).build(); - PushAudience pushAudience = PushAudience.newBuilder().addPushAudienceType(PushAudienceType.TAG, userIds).build(); - PushInfo pushInfo = new PushInfo("ops-push-android", subject, content,"", null, pushPlatform, pushAudience); - pushInfoVO.setPushInfo(pushInfo); - pushInfoVO.setTenantId(tenantId); - R pushResult = pushClient.tenantPush(pushInfoVO); - return pushResult.isSuccess(); - }); - appMessagePushExecutor.submit(new Thread(androidPush,"安卓推送")); +// public boolean sendByUsers(String subject, String content, List userIds,String tenantId) throws Exception { +// // 安卓推送 +// FutureTask androidPush = new FutureTask<>(() -> this.sendAndroidMsg(subject,content,userIds,tenantId)); +// appMessagePushExecutor.submit(new Thread(androidPush,"安卓推送")); +// +// // IOS推送 +// FutureTask iosPush = new FutureTask<>(() -> this.sendIOSMsg(subject,content,userIds,tenantId)); +// appMessagePushExecutor.submit(new Thread(iosPush,"ios推送")); +// +// return androidPush.get() && iosPush.get(); +// } - // IOS推送 - FutureTask iosPush = new FutureTask<>(() -> { - PushInfoVO pushInfoVO = new PushInfoVO(); - PushPlatform pushPlatform = PushPlatform.newBuilder().addPlatformType(PlatformType.IOS).build(); - PushAudience pushAudience = PushAudience.newBuilder().addPushAudienceType(PushAudienceType.TAG, userIds).build(); - PushInfo pushInfo = new PushInfo("ops-push-ios", subject, content,"", null, pushPlatform, pushAudience); - pushInfoVO.setPushInfo(pushInfo); - pushInfoVO.setTenantId(tenantId); - R pushResult = pushClient.tenantPush(pushInfoVO); - return pushResult.isSuccess(); - }); - appMessagePushExecutor.submit(new Thread(iosPush,"ios推送")); + /** + * 发送APP安卓消息 + * @param subject 消息主题 + * @param content 消息内容 + * @param userIds 发送人员 + * @param tenantId 租户ID + * @return 推送结果 + */ + public R sendAndroidMsg(String subject,String content,List userIds,String tenantId) { + PushInfoVO pushInfoVO = new PushInfoVO(); + PushPlatform pushPlatform = PushPlatform.newBuilder().addPlatformType(PlatformType.Android).build(); + PushAudience pushAudience = PushAudience.newBuilder().addPushAudienceType(PushAudienceType.TAG, userIds).build(); + PushInfo pushInfo = new PushInfo("ops-push-android", subject, content,"", null, pushPlatform, pushAudience); + pushInfoVO.setPushInfo(pushInfo); + pushInfoVO.setTenantId(tenantId); + return pushClient.tenantPush(pushInfoVO); + } - return androidPush.get() && iosPush.get(); + /** + * 发送IOS安卓消息 + * @param subject 消息主题 + * @param content 消息内容 + * @param userIds 发送人员 + * @param tenantId 租户ID + * @return 推送结果 + */ + public R sendIOSMsg(String subject,String content,List userIds,String tenantId) { + PushInfoVO pushInfoVO = new PushInfoVO(); + PushPlatform pushPlatform = PushPlatform.newBuilder().addPlatformType(PlatformType.IOS).build(); + PushAudience pushAudience = PushAudience.newBuilder().addPushAudienceType(PushAudienceType.TAG, userIds).build(); + PushInfo pushInfo = new PushInfo("ops-push-ios", subject, content,"", null, pushPlatform, pushAudience); + pushInfoVO.setPushInfo(pushInfo); + pushInfoVO.setTenantId(tenantId); + return pushClient.tenantPush(pushInfoVO); } } 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 73927f5..29bdb30 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 @@ -66,4 +66,13 @@ public class SmsMessageServiceImpl implements IMessageService { return response.getData().isSuccess(); } } + + 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()) + ); + } } diff --git a/hzims-service/message/src/main/resources/db/1.0.0.sql b/hzims-service/message/src/main/resources/db/1.0.0.sql index 074148b..eefbcc2 100644 --- a/hzims-service/message/src/main/resources/db/1.0.0.sql +++ b/hzims-service/message/src/main/resources/db/1.0.0.sql @@ -7,82 +7,82 @@ ALTER TABLE `hzims_message`.`hzims_mail_config` ADD COLUMN `DURATION` mediumint( ALTER TABLE `hzims_message`.`hzims_mail_config` ADD COLUMN `TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '时间单位' AFTER `DURATION`; CREATE TABLE `hzims_message`.`hzims_message_push_record` ( - `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', - `TASK_ID` bigint(20) NOT NULL COMMENT '消息类型', - `TEMPLATE_ID` bigint(20) NULL DEFAULT NULL COMMENT '消息模板ID', - `PUSHER` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '推送人', - `PUSHER_NAME` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '推送人名称', - `CONTENT` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '内容', - `PLAN_TIME` datetime(0) NULL DEFAULT NULL COMMENT '计划推送时间', - `PUSH_TIME` datetime(0) NULL DEFAULT NULL COMMENT '实际推送时间', - `TYPE` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '消息类型', - `BUSINESS_KEY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务关键字', - `BUSINESS_CLASSIFY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务分类。系统通知:system,事务消息:business,日常提醒:dailyRemind,巡检消息:inspect', - `SUBJECT` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主题', - `CONCENTRATED_DURATION` mediumint(9) NULL DEFAULT NULL COMMENT '集中推送时长', - `CONCENTRATED_TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '集中推送单位', - `ADVANCE_DURATION` mediumint(9) NULL DEFAULT NULL COMMENT '提前推送时长', - `ADVANCE_TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '提前推送单位', - `TENANT_ID` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '租户ID', - `CREATE_DEPT` bigint(20) NULL DEFAULT NULL COMMENT '创建单位', - `CREATE_USER` bigint(20) NOT NULL COMMENT '创建人', - `CREATE_TIME` datetime(0) NOT NULL COMMENT '创建时间', - `UPDATE_USER` bigint(20) NULL DEFAULT NULL COMMENT '修改人', - `UPDATE_TIME` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', - `STATUS` tinyint(4) NULL DEFAULT 0 COMMENT '业务状态(0 未推送,1 推送成功,2 推送失败,3 已确认)', - `IS_DELETED` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除 0-正常 1-删除', - `RESPOND_TIME` datetime(0) NULL DEFAULT NULL COMMENT '响应时间', - `RESPOND_REMARK` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '响应说明', - `RESOURCE_CODE` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '资源编码', - `ACCOUNT` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '推送账号:手机号,邮箱', - `DEPT_ID` bigint(20) NULL DEFAULT NULL COMMENT '机构ID', - `DEPT_NAME` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机构ID', - `MESSAGE_ID` bigint(20) NULL DEFAULT NULL COMMENT '消息ID', - `PUSH_TYPE` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '推送类型,0:即时推送,1:计划推送', - `SMS_PARAM` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '阿里云短信模板参数', - PRIMARY KEY (`ID`) USING BTREE + `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `TASK_ID` bigint(20) NOT NULL COMMENT '消息类型', + `TEMPLATE_ID` bigint(20) NULL DEFAULT NULL COMMENT '消息模板ID', + `PUSHER` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '推送人', + `PUSHER_NAME` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '推送人名称', + `CONTENT` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '内容', + `PLAN_TIME` datetime(0) NULL DEFAULT NULL COMMENT '计划推送时间', + `PUSH_TIME` datetime(0) NULL DEFAULT NULL COMMENT '实际推送时间', + `TYPE` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '消息类型', + `BUSINESS_KEY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务关键字', + `BUSINESS_CLASSIFY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务分类。系统通知:system,事务消息:business,日常提醒:dailyRemind,巡检消息:inspect', + `SUBJECT` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主题', + `CONCENTRATED_DURATION` mediumint(9) NULL DEFAULT NULL COMMENT '集中推送时长', + `CONCENTRATED_TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '集中推送单位', + `ADVANCE_DURATION` mediumint(9) NULL DEFAULT NULL COMMENT '提前推送时长', + `ADVANCE_TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '提前推送单位', + `TENANT_ID` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '租户ID', + `CREATE_DEPT` bigint(20) NULL DEFAULT NULL COMMENT '创建单位', + `CREATE_USER` bigint(20) NOT NULL COMMENT '创建人', + `CREATE_TIME` datetime(0) NOT NULL COMMENT '创建时间', + `UPDATE_USER` bigint(20) NULL DEFAULT NULL COMMENT '修改人', + `UPDATE_TIME` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', + `STATUS` tinyint(4) NULL DEFAULT 0 COMMENT '业务状态(0 未推送,1 推送成功,2 推送失败,3 已确认)', + `IS_DELETED` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除 0-正常 1-删除', + `RESPOND_TIME` datetime(0) NULL DEFAULT NULL COMMENT '响应时间', + `RESPOND_REMARK` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '响应说明', + `RESOURCE_CODE` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '资源编码', + `ACCOUNT` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '推送账号:手机号,邮箱', + `DEPT_ID` bigint(20) NULL DEFAULT NULL COMMENT '机构ID', + `DEPT_NAME` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机构ID', + `MESSAGE_ID` bigint(20) NULL DEFAULT NULL COMMENT '消息ID', + `PUSH_TYPE` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '推送类型,0:即时推送,1:计划推送', + `SMS_PARAM` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '阿里云短信模板参数', + PRIMARY KEY (`ID`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '消息推送记录' ROW_FORMAT = Dynamic; CREATE TABLE `hzims_message`.`hzims_message_template` ( - `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '消息类型', - `TYPE` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主键ID', - `BUSINESS_KEY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务关键字', - `BUSINESS_CLASSIFY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务分类。系统通知:system,事务消息:business,日常提醒:dailyRemind,巡检消息:inspect', - `SUBJECT` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主题', - `CONCENTRATED_DURATION` mediumint(9) NULL DEFAULT NULL COMMENT '集中推送时长', - `CONCENTRATED_TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '集中推送单位', - `ADVANCE_DURATION` mediumint(9) NULL DEFAULT NULL COMMENT '提前推送时长', - `ADVANCE_TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '提前推送单位', - `TENANT_ID` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '租户ID', - `CREATE_DEPT` bigint(20) NULL DEFAULT NULL COMMENT '创建单位', - `CREATE_USER` bigint(20) NOT NULL COMMENT '创建人', - `CREATE_TIME` datetime(0) NOT NULL COMMENT '创建时间', - `UPDATE_USER` bigint(20) NULL DEFAULT NULL COMMENT '修改人', - `UPDATE_TIME` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', - `STATUS` tinyint(4) NULL DEFAULT NULL COMMENT '业务状态', - `IS_DELETED` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除 0-正常 1-删除', - PRIMARY KEY (`ID`) USING BTREE + `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '消息类型', + `TYPE` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主键ID', + `BUSINESS_KEY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务关键字', + `BUSINESS_CLASSIFY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务分类。系统通知:system,事务消息:business,日常提醒:dailyRemind,巡检消息:inspect', + `SUBJECT` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '主题', + `CONCENTRATED_DURATION` mediumint(9) NULL DEFAULT NULL COMMENT '集中推送时长', + `CONCENTRATED_TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '集中推送单位', + `ADVANCE_DURATION` mediumint(9) NULL DEFAULT NULL COMMENT '提前推送时长', + `ADVANCE_TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '提前推送单位', + `TENANT_ID` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '租户ID', + `CREATE_DEPT` bigint(20) NULL DEFAULT NULL COMMENT '创建单位', + `CREATE_USER` bigint(20) NOT NULL COMMENT '创建人', + `CREATE_TIME` datetime(0) NOT NULL COMMENT '创建时间', + `UPDATE_USER` bigint(20) NULL DEFAULT NULL COMMENT '修改人', + `UPDATE_TIME` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', + `STATUS` tinyint(4) NULL DEFAULT NULL COMMENT '业务状态', + `IS_DELETED` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除 0-正常 1-删除', + PRIMARY KEY (`ID`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '消息推送模板' ROW_FORMAT = Dynamic; ALTER TABLE `hzims_message`.`hzims_push_config` MODIFY COLUMN `TIME_UNIT` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '时间单位' AFTER `DURATION`; CREATE TABLE `hzims_message`.`hzims_push_message` ( - `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', - `MESSAGE_TYPE` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '消息类型', - `BUSINESS_KEY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务key值', - `MESSAGE_CONTENT` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '消息推送内容体', - `IS_PUSH` tinyint(4) NULL DEFAULT 0 COMMENT '是否推送', - `IS_SUCCESS` tinyint(4) NULL DEFAULT NULL COMMENT '是否推送', - `PUSH_TIME` datetime(0) NULL DEFAULT NULL COMMENT '推送时间', - `TENANT_ID` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '租户ID', - `CREATE_DEPT` bigint(20) NULL DEFAULT NULL COMMENT '创建单位', - `CREATE_USER` bigint(20) NOT NULL COMMENT '创建人', - `CREATE_TIME` datetime(0) NOT NULL COMMENT '创建时间', - `UPDATE_USER` bigint(20) NULL DEFAULT NULL COMMENT '修改人', - `UPDATE_TIME` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', - `STATUS` tinyint(4) NULL DEFAULT NULL COMMENT '业务状态', - `IS_DELETED` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除 0-正常 1-删除', - PRIMARY KEY (`ID`) USING BTREE + `ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', + `MESSAGE_TYPE` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '消息类型', + `BUSINESS_KEY` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务key值', + `MESSAGE_CONTENT` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '消息推送内容体', + `IS_PUSH` tinyint(4) NULL DEFAULT 0 COMMENT '是否推送', + `IS_SUCCESS` tinyint(4) NULL DEFAULT NULL COMMENT '是否推送', + `PUSH_TIME` datetime(0) NULL DEFAULT NULL COMMENT '推送时间', + `TENANT_ID` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '租户ID', + `CREATE_DEPT` bigint(20) NULL DEFAULT NULL COMMENT '创建单位', + `CREATE_USER` bigint(20) NOT NULL COMMENT '创建人', + `CREATE_TIME` datetime(0) NOT NULL COMMENT '创建时间', + `UPDATE_USER` bigint(20) NULL DEFAULT NULL COMMENT '修改人', + `UPDATE_TIME` datetime(0) NULL DEFAULT NULL COMMENT '修改时间', + `STATUS` tinyint(4) NULL DEFAULT NULL COMMENT '业务状态', + `IS_DELETED` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除 0-正常 1-删除', + PRIMARY KEY (`ID`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; ALTER TABLE `hzims_message`.`hzims_sms_config` MODIFY COLUMN `CONTENT_VARIABLES` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '短信模板参数变量定义' AFTER `IS_DELETED`; diff --git a/hzims-service/message/src/main/resources/db/1.0.1.sql b/hzims-service/message/src/main/resources/db/1.0.1.sql new file mode 100644 index 0000000..ac22225 --- /dev/null +++ b/hzims-service/message/src/main/resources/db/1.0.1.sql @@ -0,0 +1,2 @@ +alter table `hzims_message_push_record` add column `fault_result` varchar(1000) comment '推送失败信息'; +alter table `hzims_message_push_record` MODIFY `TASK_ID` BIGINT(20) NULL; \ No newline at end of file