消息模板设置 夜间屏蔽,次日推送

pull/6/head
3y 3 years ago
parent b57d512a70
commit 43bb7f8368

@ -113,7 +113,7 @@ curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"co
- [x] 接入实时流计算平台Flink实时日志数据根据用户维度和消息模板维度清洗至Redis
- [x] 通过AMIS低代码平台接入echarts图表展示实时聚合后的数据
- [x] 优雅停机、动态线程池参数配置
- [ ] 企业微信渠道接入
- [x] 企业微信渠道接入
- [ ] 钉钉渠道接入
- [ ] 优化代码
- [ ] 接入微信服务号渠道
@ -123,9 +123,9 @@ curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"co
**近期更新时间**2022年3月15
**近期更新时间**2022年3月22
**近期更新功能**企业微信渠道接入(未完成)
**近期更新功能**夜间屏蔽次日推送消息(未完成)
## 项目交流

@ -55,6 +55,11 @@ public class TaskInfo {
*/
private Integer msgType;
/**
*
*/
private Integer shieldType;
/**
*
* message_templatecontentJSON()

@ -0,0 +1,28 @@
package com.java3y.austin.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
/**
*
*
* @author 3y
*/
@Getter
@ToString
@AllArgsConstructor
public enum ShieldType {
NIGHT_NO_SHIELD(10, "夜间不屏蔽"),
NIGHT_SHIELD(20, "夜间屏蔽"),
NIGHT_SHIELD_BUT_NEXT_DAY_SEND(30, "夜间屏蔽(次日早上9点发送)");
private Integer code;
private String description;
}

@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
/**
*
*
* @author 3y
*/
@Service
@ -27,7 +27,7 @@ public class CronTaskHandler {
private DtpExecutor dtpExecutor = CronAsyncThreadPoolConfig.getXxlCronExecutor();
/**
* austin
* austin
*/
@XxlJob("austinJob")
public void execute() {

@ -0,0 +1,54 @@
package com.java3y.austin.cron.handler;
import cn.hutool.core.util.StrUtil;
import com.google.common.base.Throwables;
import com.java3y.austin.support.config.SupportThreadPoolConfig;
import com.java3y.austin.support.utils.KafkaUtils;
import com.java3y.austin.support.utils.RedisUtils;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
*
*
* example:austin19
*
* @author 3y
*/
@Service
@Slf4j
public class NightShieldLazyPendingHandler {
private static final String NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY = "night_shield_send";
@Autowired
private KafkaUtils kafkaUtils;
@Value("${austin.business.topic.name}")
private String topicName;
@Autowired
private RedisUtils redisUtils;
/**
* (9)
*/
@XxlJob("nightShieldLazyJob")
public void execute() {
log.info("NightShieldLazyPendingHandler#execute!");
SupportThreadPoolConfig.getPendingSingleThreadPool().execute(() -> {
while (redisUtils.lLen(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY) > 0) {
String taskInfo = redisUtils.lPop(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY);
if (StrUtil.isNotBlank(taskInfo)) {
try {
kafkaUtils.send(topicName, taskInfo);
} catch (Exception e) {
log.error("nightShieldLazyJob send kafka fail! e:{},params:{}", Throwables.getStackTraceAsString(e), taskInfo);
}
}
}
});
}
}

@ -6,6 +6,7 @@ import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.handler.deduplication.DeduplicationRuleService;
import com.java3y.austin.handler.discard.DiscardMessageService;
import com.java3y.austin.handler.handler.HandlerHolder;
import com.java3y.austin.handler.shield.ShieldService;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
@ -38,6 +39,9 @@ public class Task implements Runnable {
@Autowired
private DiscardMessageService discardMessageService;
@Autowired
private ShieldService shieldService;
private TaskInfo taskInfo;
@ -48,14 +52,17 @@ public class Task implements Runnable {
if (discardMessageService.isDiscard(taskInfo)) {
return;
}
// 1. 屏蔽消息
shieldService.shield(taskInfo);
// 1.平台通用去重
deduplicationRuleService.duplication(taskInfo);
// 2.平台通用去重
if (CollUtil.isNotEmpty(taskInfo.getReceiver())) {
deduplicationRuleService.duplication(taskInfo);
}
// 2. 真正发送消息
// 3. 真正发送消息
if (CollUtil.isNotEmpty(taskInfo.getReceiver())) {
handlerHolder.route(taskInfo.getSendChannel())
.doHandler(taskInfo);
handlerHolder.route(taskInfo.getSendChannel()).doHandler(taskInfo);
}
}

@ -0,0 +1,14 @@
package com.java3y.austin.handler.shield;
import com.java3y.austin.common.domain.TaskInfo;
/**
*
*
* @author 3y
*/
public interface ShieldService {
void shield(TaskInfo taskInfo);
}

@ -0,0 +1,63 @@
package com.java3y.austin.handler.shield.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.enums.ShieldType;
import com.java3y.austin.handler.shield.ShieldService;
import com.java3y.austin.support.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashSet;
/**
*
*/
@Service
@Slf4j
public class ShieldServiceImpl implements ShieldService {
private static final String NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY = "night_shield_send";
@Autowired
private RedisUtils redisUtils;
@Override
public void shield(TaskInfo taskInfo) {
/**
* example:austin19
* ( )
*/
if (isNight() && isNightShieldType(taskInfo.getShieldType())) {
if (ShieldType.NIGHT_SHIELD_BUT_NEXT_DAY_SEND.getCode().equals(taskInfo.getShieldType())) {
redisUtils.lPush(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY, JSON.toJSONString(taskInfo), (DateUtil.offsetDay(new Date(), 1).getTime()) / 1000);
}
taskInfo.setReceiver(new HashSet<>());
}
}
/**
* code
*/
private boolean isNightShieldType(Integer code) {
if (ShieldType.NIGHT_SHIELD.getCode().equals(code)
|| ShieldType.NIGHT_SHIELD_BUT_NEXT_DAY_SEND.getCode().equals(code)) {
return true;
}
return false;
}
/**
* < 8 ()
* @return
*/
private boolean isNight() {
return Integer.valueOf(DateFormatUtils.format(new Date(), "HH")) < 8;
}
}

@ -77,6 +77,7 @@ public class AssembleAction implements BusinessProcess {
.sendChannel(messageTemplate.getSendChannel())
.templateType(messageTemplate.getTemplateType())
.msgType(messageTemplate.getMsgType())
.shieldType(messageTemplate.getShieldType())
.sendAccount(messageTemplate.getSendAccount())
.contentModel(getContentModelValue(messageTemplate, messageParam)).build();

@ -75,6 +75,11 @@ public class MessageTemplate implements Serializable {
*/
private Integer templateType;
/**
*
*/
private Integer shieldType;
/**
*
*/

@ -90,6 +90,48 @@ public class RedisUtils {
}
}
/**
* lpush
*
*/
public void lPush(String key, String value, Long seconds) {
try {
redisTemplate.executePipelined((RedisCallback<String>) connection -> {
connection.lPush(key.getBytes(), value.getBytes());
connection.expire(key.getBytes(), seconds);
return null;
});
} catch (Exception e) {
log.error("RedisUtils#pipelineSetEx fail! e:{}", Throwables.getStackTraceAsString(e));
}
}
/**
* lLen
*
*/
public Long lLen(String key) {
try {
return redisTemplate.opsForList().size(key);
} catch (Exception e) {
log.error("RedisUtils#pipelineSetEx fail! e:{}", Throwables.getStackTraceAsString(e));
}
return 0L;
}
/**
* lPop
*
*/
public String lPop(String key) {
try {
return redisTemplate.opsForList().leftPop(key);
} catch (Exception e) {
log.error("RedisUtils#pipelineSetEx fail! e:{}", Throwables.getStackTraceAsString(e));
}
return "";
}
/**
* pipeline key-value
*

@ -37,7 +37,7 @@
<maven.compiler.source>${target.java.version}</maven.compiler.source>
<maven.compiler.target>${target.java.version}</maven.compiler.target>
<log4j.version>2.17.1</log4j.version>
<weixin-java-mp>4.1.0</weixin-java-mp>
<weixin-java>4.1.0</weixin-java>
</properties>
<dependencyManagement>
@ -157,7 +157,7 @@
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>${weixin-java-mp}</version>
<version>${weixin-java}</version>
</dependency>
<!--动态线程池引入-->
@ -171,7 +171,7 @@
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-cp</artifactId>
<version>${weixin-java-mp}</version>
<version>${weixin-java}</version>
</dependency>
</dependencies>

@ -17,6 +17,7 @@ CREATE TABLE `message_template`
`send_channel` tinyint(4) NOT NULL DEFAULT '0' COMMENT '消息发送渠道10.IM 20.Push 30.短信 40.Email 50.公众号 60.小程序 70.企业微信',
`template_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '10.运营类 20.技术类接口调用',
`msg_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '10.通知类消息 20.营销类消息 30.验证码类消息',
`shield_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '10.夜间不屏蔽 20.夜间屏蔽 30.夜间屏蔽(次日早上9点发送)',
`msg_content` varchar(600) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '消息内容 占位符用{$var}表示',
`send_account` tinyint(4) NOT NULL DEFAULT '0' COMMENT '发送账号 一个渠道下可存在多个账号',
`creator` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '创建者',

Loading…
Cancel
Save