Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java
#	hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java
zhongwei
yang_shj 1 year ago
parent
commit
c348460059
  1. 3
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/constants/XxlJobConstants.java
  2. 72
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/SmsImmediatelyPushDTO.java
  3. 11
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java
  4. 5
      hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java
  5. 2
      hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java
  6. 7
      hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java
  7. 18
      hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java
  8. 55
      hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java
  9. 13
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java
  10. 18
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java
  11. 25
      hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java
  12. 6
      hzims-service/message/src/main/resources/application.yml

3
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/constants/XxlJobConstants.java

@ -12,4 +12,7 @@ public interface XxlJobConstants {
/**消息中心消息按通知人分时段集中推送**/
String PUSH_MESSAGE_BY_NOTICE = "pushMessageByNotice";
/**推送APP消息**/
String PUSH_APP_MESSAGE = "pushAppMessage";
}

72
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/dto/SmsImmediatelyPushDTO.java

@ -0,0 +1,72 @@
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 javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Map;
/**
* @ClassName SmsImmediatelyPushDTO
* @description: 短信即时推送请求内容
* @author: hx
* @create: 2023-08-09 08:46
* @Version 4.0
**/
@Data
@EqualsAndHashCode
@ApiModel("短信即时推送请求内容")
public class SmsImmediatelyPushDTO 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 pusher;
@ApiModelProperty(value = "创建用户")
private Long createUser;
@ApiModelProperty(value = "租户ID")
private String tenantId;
@ApiModelProperty("短信推送资源编码")
@NotNull
private String resourceCode;
@ApiModelProperty("短信推送填充内容")
@NotNull
private Map<String,String> params;
}

11
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/IMessageClient.java

@ -28,6 +28,8 @@ public interface IMessageClient {
String PLAN_SEND_MESSAGE = API_PREFIX + "/planSendMessage";
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";
/**
* 推送消息短信
*
@ -64,4 +66,13 @@ public interface IMessageClient {
*/
@PostMapping(value = SEND_APP_AND_WS_MSG,consumes = "application/json; charset=UTF-8")
R<Boolean> sendAppAndWsMsgByUsers(@RequestBody BusinessMessageDTO request);
/**
* 发送即时推送短信消息
* @param smsImmediatelyPushDTO 即时推送短信消息体
* @return
*/
@PostMapping(SEND_SMS_IMMEDIATELY_MSG)
R<Boolean> sendSmsImmediatelyMsg(@RequestBody SmsImmediatelyPushDTO smsImmediatelyPushDTO);
}

5
hzims-service-api/message-api/src/main/java/com/hnac/hzims/message/fegin/MessageClientFallback.java

@ -41,4 +41,9 @@ public class MessageClientFallback implements IMessageClient {
public R<Boolean> sendAppAndWsMsgByUsers(BusinessMessageDTO request) {
return R.fail("调用失败!");
}
@Override
public R<Boolean> sendSmsImmediatelyMsg(SmsImmediatelyPushDTO smsImmediatelyPushDTO) {
return R.fail("调用失败!");
}
}

2
hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpMonitorServiceImpl.java

@ -952,7 +952,7 @@ public class FdpMonitorServiceImpl extends BaseServiceImpl<FdpMonitorMapper, Fdp
}
return R.success("暂无数据,请稍后重试");
}
return R.fail("智能诊断接口异常,请联系管理员");
return R.fail(fdpHttpResponseVo.getMessage());
}

7
hzims-service/message/src/main/java/com/hnac/hzims/message/controller/MessagePushRecordController.java

@ -114,4 +114,11 @@ public class MessagePushRecordController extends BladeController {
List<UnreadMessageVO> personalUnreadMessage = messagePushRecordService.getPersonalAppUnreadMessage();
return R.data(personalUnreadMessage);
}
@PostMapping("/sendMessage")
@ApiOperation("消息推送")
@ApiOperationSupport(order = 10)
public R sendMessage(@RequestBody MessagePushRecordEntity request) {
return R.status(messagePushRecordService.saveAndSend(request));
}
}

18
hzims-service/message/src/main/java/com/hnac/hzims/message/fegin/MessageClient.java

@ -154,6 +154,7 @@ public class MessageClient extends BladeController implements IMessageClient{
record.setPlanTime(LocalDateTime.now());
record.setType(messageType);
record.setCreateDept(record.getDeptId());
record.setStatus(MessageConstants.NOT_PUSH);
return record;
});
}).collect(Collectors.toList());
@ -171,4 +172,21 @@ public class MessageClient extends BladeController implements IMessageClient{
}
}
@Override
@PostMapping(SEND_SMS_IMMEDIATELY_MSG)
public R<Boolean> sendSmsImmediatelyMsg(@RequestBody SmsImmediatelyPushDTO smsImmediatelyPushDTO) {
MessagePushRecordEntity record = BeanUtil.copy(smsImmediatelyPushDTO,MessagePushRecordEntity.class);
record.setMessageId(IdWorker.getId());
String pusherName = Optional.ofNullable(smsImmediatelyPushDTO.getPusher()).map(Func::toLong).map(UserCache::getUser).map(User::getName).orElse(null);
record.setPusherName(pusherName);
record.setPushType(MessageConstants.IMMEDIATELY);
record.setPlanTime(LocalDateTime.now());
record.setType(MessageConstants.SMS_PUSH);
record.setCreateDept(record.getDeptId());
record.setUpdateUser(smsImmediatelyPushDTO.getCreateUser());
record.setStatus(MessageConstants.NOT_PUSH);
record.setSmsParam(JSON.toJSONString(smsImmediatelyPushDTO.getParams()));
return R.data(recordService.sendSmsImmediatelyMsg(record));
}
}

55
hzims-service/message/src/main/java/com/hnac/hzims/message/schedule/MessagePushSchedule.java

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.utils.DateUtil;
import com.hnac.hzims.message.MessageConstants;
import com.hnac.hzims.message.config.MessageFactory;
@ -14,11 +15,18 @@ import com.hnac.hzims.message.entity.config.MessageTemplateEntity;
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.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.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
@ -29,6 +37,7 @@ import java.util.*;
import java.util.stream.Collectors;
import static com.hnac.hzims.message.constants.XxlJobConstants.PUSH_MESSAGE_BY_NOTICE;
import static com.hnac.hzims.message.constants.XxlJobConstants.PUSH_APP_MESSAGE;
/**
* @ClassName MessagePushSchedule
@ -38,18 +47,21 @@ import static com.hnac.hzims.message.constants.XxlJobConstants.PUSH_MESSAGE_BY_N
* @Version 4.0
**/
@Component
@AllArgsConstructor
@RequiredArgsConstructor
@Slf4j
public class MessagePushSchedule {
private final IMessageTemplateService templateService;
private final IMessagePushRecordService recordService;
private final MessageStrategy messageStrategy;
private final RedisTemplate redisTemplate;
@Value("${hzims.message.redis-key.app-push}")
private String appPushRedisKey;
@XxlJob(PUSH_MESSAGE_BY_NOTICE)
public ReturnT pushSmsMessageByNotice(String params) {
// 获取消息模板
List<MessageTemplateEntity> templateList = templateService.list();
LocalDateTime now = LocalDateTime.now();
templateList.forEach(template -> {
LocalDateTime endTime = DateUtil.plus(LocalDateTime.now(), messageStrategy.getConcentrateDuration(), messageStrategy.getConcentrateUnit());
endTime = DateUtil.plus(endTime, template.getAdvanceDuration(), template.getAdvanceTimeUnit());
@ -67,6 +79,45 @@ public class MessagePushSchedule {
return ReturnT.SUCCESS;
}
@XxlJob(PUSH_APP_MESSAGE)
public ReturnT pushAppMessage(String params) {
Set<String> appPushKeys = redisTemplate.keys(appPushRedisKey + "*");
PushMessageServiceImpl pushMessageService = SpringUtil.getBean(PushMessageServiceImpl.class);
appPushKeys.forEach(appPushKey -> {
// 从redis-key中拆分出消息推送人
Long pusher = Optional.ofNullable(appPushKey.replace(appPushRedisKey+":","")).map(Func::toLong).orElse(null);
if(Func.isNotEmpty(pusher)) {
List<MessagePushRecordEntity> records = (List<MessagePushRecordEntity>) redisTemplate.opsForList().range(appPushKey,0,-1);
if(CollectionUtil.isNotEmpty(records)) {
Map<String, List<MessagePushRecordEntity>> listMap = records.stream().filter(record -> Func.isNotEmpty(record.getSubject()))
.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));
}
LambdaUpdateWrapper<MessagePushRecordEntity> updateWrapper = Wrappers.<MessagePushRecordEntity>lambdaUpdate()
.set(MessagePushRecordEntity::getStatus, MessageConstants.PUSH_SUCCESS)
.in(MessagePushRecordEntity::getId, list.stream().map(MessagePushRecordEntity::getId).collect(Collectors.toList()));
recordService.update(updateWrapper);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
// redisTemplate.opsForList().remove(appPushKey,0,records);
}
});
return ReturnT.SUCCESS;
}
/** @Author hx
* @Description 消息集中推送
* @Date 2023/4/4 15:31

13
hzims-service/message/src/main/java/com/hnac/hzims/message/service/IMessagePushRecordService.java

@ -105,8 +105,19 @@ public interface IMessagePushRecordService extends BaseService<MessagePushRecord
Boolean sendWxMessageByUser(WxMessageDTO message,List<MessagePushRecordEntity> records);
/**
* App多人推送消息
* @param request 消息内容
* @param records 消息记录
* @return 推送结果
*/
Boolean sendAppMsgByUsers(BusinessMessageDTO request,List<MessagePushRecordEntity> records);
/**
* web多人推送消息
* @param request 消息记录
* @return 推送结果
*/
Boolean sendWsMsgByUsers(List<MessagePushRecordEntity> request);
@ -116,4 +127,6 @@ public interface IMessagePushRecordService extends BaseService<MessagePushRecord
* @return
*/
UserPushStatTypeResponseVo newUserPushStat(MessagePushRecordEntityVo vo);
Boolean sendSmsImmediatelyMsg(MessagePushRecordEntity record);
}

18
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/MessagePushRecordServiceImpl.java

@ -51,6 +51,7 @@ import java.util.stream.Collectors;
public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRecordMapper, MessagePushRecordEntity> implements IMessagePushRecordService {
private final MprNoAurhScopeMapper noAurhScopeMapper;
private final IMessageService smsMessageService;
@Override
public List<MessagePushRecordEntity> list(MessagePushRecordEntity request) {
@ -291,6 +292,23 @@ public class MessagePushRecordServiceImpl extends BaseServiceImpl<MessagePushRec
return pushStatList;
}
@Override
public Boolean sendSmsImmediatelyMsg(MessagePushRecordEntity record) {
// 完善推送Account
record.setAccount(smsMessageService.getAccountByPusher(Long.parseLong(record.getPusher()),record.getType()));
if(this.save(record)) {
if(smsMessageService.send(record)) {
this.update(
Wrappers.<MessagePushRecordEntity>lambdaUpdate()
.set(MessagePushRecordEntity::getStatus,MessageConstants.PUSH_SUCCESS)
.set(MessagePushRecordEntity::getPushTime,LocalDateTime.now())
.eq(MessagePushRecordEntity::getId,record.getId())
);
}
}
return true;
}
/**
* 推送成功失败统计

25
hzims-service/message/src/main/java/com/hnac/hzims/message/service/impl/PushMessageServiceImpl.java

@ -16,6 +16,7 @@ import com.hnac.hzinfo.core.push.model.PushInfo;
import com.hnac.hzinfo.core.push.model.PushPlatform;
import com.hnac.hzinfo.core.push.model.PushResponse;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.secure.utils.AuthUtil;
@ -24,6 +25,8 @@ import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.resource.feign.IPushClient;
import org.springblade.resource.vo.PushInfoVO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
@ -38,12 +41,15 @@ import java.util.concurrent.atomic.AtomicReference;
* @author hx
*/
@Service("pushMessageService")
@AllArgsConstructor
@RequiredArgsConstructor
public class PushMessageServiceImpl implements IMessageService {
private final IPushClient pushClient;
private final BladeLogger logger;
private final ExecutorService appMessagePushExecutor;
private final RedisTemplate redisTemplate;
@Value("${hzims.message.redis-key.app-push}")
private String appPushRedisKey;
@Override
@SaveLog(type = MessageConstants.APP_NAME)
@ -90,13 +96,16 @@ public class PushMessageServiceImpl implements IMessageService {
@Override
public boolean send(MessagePushRecordEntity request) {
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());
}
// 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());
// }
}
/**

6
hzims-service/message/src/main/resources/application.yml

@ -34,3 +34,9 @@ spring:
url: jdbc:mysql://175.6.40.67:5816/dev_hzims_message?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
username: root
password: 123
hzims:
message:
redis-key:
# APP消息推送记录存入redis的key
app-push: hzims:message:appPush

Loading…
Cancel
Save