+ * key: md5(templateId + templateId + content) + *
+ * 相同的内容相同的模板短时间内发给同一个人 + * + * @param taskInfo + * @return + */ + @Override + public String deduplicationSingleKey(TaskInfo taskInfo, String receiver) { + return DigestUtil.md5Hex(taskInfo.getMessageTemplateId() + receiver + + JSON.toJSONString(taskInfo.getContentModel())); + } +} diff --git a/austin-handler/src/main/java/com/java3y/austin/service/deduplication/DeduplicationRuleService.java b/austin-handler/src/main/java/com/java3y/austin/service/deduplication/DeduplicationRuleService.java new file mode 100644 index 0000000..971fd20 --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/service/deduplication/DeduplicationRuleService.java @@ -0,0 +1,42 @@ +package com.java3y.austin.service.deduplication; + +import cn.hutool.core.date.DateUtil; +import com.java3y.austin.domain.DeduplicationParam; +import com.java3y.austin.domain.TaskInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; + +/** + * @author 3y + * @date 2021/12/12 + * 去重服务 + */ +@Service +public class DeduplicationRuleService { + + @Autowired + private ContentAbstractDeduplicationService contentDeduplicationService; + + @Autowired + private FrequencyDeduplicationService frequencyDeduplicationService; + + + public void duplication(TaskInfo taskInfo) { + + // 文案去重 + DeduplicationParam contentParams = DeduplicationParam.builder() + .deduplicationTime(300L).countNum(1).taskInfo(taskInfo) + .build(); + contentDeduplicationService.deduplication(contentParams); + + // 运营总规则去重(一天内用户收到最多同一个渠道的消息次数) + Long seconds = (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000; + DeduplicationParam businessParams = DeduplicationParam.builder() + .deduplicationTime(seconds).countNum(5).taskInfo(taskInfo) + .build(); + frequencyDeduplicationService.deduplication(businessParams); + } + +} diff --git a/austin-handler/src/main/java/com/java3y/austin/service/deduplication/FrequencyDeduplicationService.java b/austin-handler/src/main/java/com/java3y/austin/service/deduplication/FrequencyDeduplicationService.java new file mode 100644 index 0000000..c135f46 --- /dev/null +++ b/austin-handler/src/main/java/com/java3y/austin/service/deduplication/FrequencyDeduplicationService.java @@ -0,0 +1,35 @@ +package com.java3y.austin.service.deduplication; + +import cn.hutool.core.util.StrUtil; +import com.java3y.austin.domain.TaskInfo; +import org.springframework.stereotype.Service; + +/** + * @author 3y + * @date 2021/12/12 + * 频次去重服务 + */ +@Service +public class FrequencyDeduplicationService extends AbstractDeduplicationService { + + private static final String PREFIX = "FRE"; + + /** + * 业务规则去重 构建key + *
+ * key : receiver + templateId + sendChannel + *
+ * 一天内一个用户只能收到某个渠道的消息 N 次
+ *
+ * @param taskInfo
+ * @param receiver
+ * @return
+ */
+ @Override
+ public String deduplicationSingleKey(TaskInfo taskInfo, String receiver) {
+ return PREFIX + StrUtil.C_UNDERLINE
+ + receiver + StrUtil.C_UNDERLINE
+ + taskInfo.getMessageTemplateId() + StrUtil.C_UNDERLINE
+ + taskInfo.getSendChannel();
+ }
+}
diff --git a/austin-support/pom.xml b/austin-support/pom.xml
index 9fc1cff..59ff73b 100644
--- a/austin-support/pom.xml
+++ b/austin-support/pom.xml
@@ -57,6 +57,12 @@