| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -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.conditions.update.LambdaUpdateWrapper; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import com.baomidou.mybatisplus.core.toolkit.IdWorker; | 
					 | 
					 | 
					 | 
					import com.baomidou.mybatisplus.core.toolkit.IdWorker; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
					 | 
					 | 
					 | 
					import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import com.google.common.collect.Lists; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import com.hnac.hzims.common.utils.DateUtil; | 
					 | 
					 | 
					 | 
					import com.hnac.hzims.common.utils.DateUtil; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import com.hnac.hzims.message.MessageConstants; | 
					 | 
					 | 
					 | 
					import com.hnac.hzims.message.MessageConstants; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import com.hnac.hzims.message.config.MessageFactory; | 
					 | 
					 | 
					 | 
					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.IMessagePushRecordService; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import com.hnac.hzims.message.service.IMessageService; | 
					 | 
					 | 
					 | 
					import com.hnac.hzims.message.service.IMessageService; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import com.hnac.hzims.message.service.IMessageTemplateService; | 
					 | 
					 | 
					 | 
					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.biz.model.ReturnT; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import com.xxl.job.core.handler.annotation.XxlJob; | 
					 | 
					 | 
					 | 
					import com.xxl.job.core.handler.annotation.XxlJob; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import com.xxl.job.core.log.XxlJobLogger; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import lombok.AllArgsConstructor; | 
					 | 
					 | 
					 | 
					import lombok.AllArgsConstructor; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import lombok.RequiredArgsConstructor; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import lombok.extern.slf4j.Slf4j; | 
					 | 
					 | 
					 | 
					import lombok.extern.slf4j.Slf4j; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import org.springblade.core.tool.utils.CollectionUtil; | 
					 | 
					 | 
					 | 
					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 org.springframework.stereotype.Component; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.time.LocalDate; | 
					 | 
					 | 
					 | 
					import java.time.LocalDate; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -29,6 +37,7 @@ import java.util.*; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.stream.Collectors; | 
					 | 
					 | 
					 | 
					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_MESSAGE_BY_NOTICE; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import static com.hnac.hzims.message.constants.XxlJobConstants.PUSH_APP_MESSAGE; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					/** | 
					 | 
					 | 
					 | 
					/** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * @ClassName MessagePushSchedule | 
					 | 
					 | 
					 | 
					 * @ClassName MessagePushSchedule | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -38,18 +47,21 @@ import static com.hnac.hzims.message.constants.XxlJobConstants.PUSH_MESSAGE_BY_N | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 * @Version 4.0 | 
					 | 
					 | 
					 | 
					 * @Version 4.0 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 **/ | 
					 | 
					 | 
					 | 
					 **/ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					@Component | 
					 | 
					 | 
					 | 
					@Component | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					@AllArgsConstructor | 
					 | 
					 | 
					 | 
					@RequiredArgsConstructor | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					@Slf4j | 
					 | 
					 | 
					 | 
					@Slf4j | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					public class MessagePushSchedule { | 
					 | 
					 | 
					 | 
					public class MessagePushSchedule { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						private final IMessageTemplateService templateService; | 
					 | 
					 | 
					 | 
						private final IMessageTemplateService templateService; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						private final IMessagePushRecordService recordService; | 
					 | 
					 | 
					 | 
						private final IMessagePushRecordService recordService; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						private final MessageStrategy messageStrategy; | 
					 | 
					 | 
					 | 
						private final MessageStrategy messageStrategy; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						private final RedisTemplate redisTemplate; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						@Value("${hzims.message.redis-key.app-push}") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
						private String appPushRedisKey; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						@XxlJob(PUSH_MESSAGE_BY_NOTICE) | 
					 | 
					 | 
					 | 
						@XxlJob(PUSH_MESSAGE_BY_NOTICE) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						public ReturnT pushSmsMessageByNotice(String params) { | 
					 | 
					 | 
					 | 
						public ReturnT pushSmsMessageByNotice(String params) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							// 获取消息模板
 | 
					 | 
					 | 
					 | 
							// 获取消息模板
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							List<MessageTemplateEntity> templateList = templateService.list(); | 
					 | 
					 | 
					 | 
							List<MessageTemplateEntity> templateList = templateService.list(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							LocalDateTime now = LocalDateTime.now(); | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							templateList.forEach(template -> { | 
					 | 
					 | 
					 | 
							templateList.forEach(template -> { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								LocalDateTime endTime = DateUtil.plus(LocalDateTime.now(), messageStrategy.getConcentrateDuration(), messageStrategy.getConcentrateUnit()); | 
					 | 
					 | 
					 | 
								LocalDateTime endTime = DateUtil.plus(LocalDateTime.now(), messageStrategy.getConcentrateDuration(), messageStrategy.getConcentrateUnit()); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								endTime = DateUtil.plus(endTime, template.getAdvanceDuration(), template.getAdvanceTimeUnit()); | 
					 | 
					 | 
					 | 
								endTime = DateUtil.plus(endTime, template.getAdvanceDuration(), template.getAdvanceTimeUnit()); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -67,6 +79,45 @@ public class MessagePushSchedule { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							return ReturnT.SUCCESS; | 
					 | 
					 | 
					 | 
							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 | 
					 | 
					 | 
					 | 
						/** @Author hx | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @Description 消息集中推送 | 
					 | 
					 | 
					 | 
						 * @Description 消息集中推送 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						 * @Date 2023/4/4 15:31 | 
					 | 
					 | 
					 | 
						 * @Date 2023/4/4 15:31 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |