mirror of https://github.com/ZhongFuCheng3y/austin
parent
67429a8ea8
commit
39438f1e9c
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.java3y.austin.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.google.common.base.Throwables;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 3y
|
||||
* @date 2021/12/10
|
||||
* 对Redis的某些操作二次封装
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RedisUtils {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* mGet将结果封装为Map
|
||||
*
|
||||
* @param keys
|
||||
*/
|
||||
public Map<String, String> mGet(List<String> keys) {
|
||||
HashMap<String, String> result = new HashMap<>(keys.size());
|
||||
try {
|
||||
List<String> value = redisTemplate.opsForValue().multiGet(keys);
|
||||
if (CollUtil.isNotEmpty(value)) {
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
result.put(keys.get(i), value.get(i));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("redis mGet fail! e:{}", Throwables.getStackTraceAsString(e));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* pipeline 设置 key-value 并设置过期时间
|
||||
*/
|
||||
public void pipelineSetEX(Map<String, String> keyValues, Long seconds) {
|
||||
try {
|
||||
redisTemplate.executePipelined((RedisCallback<String>) connection -> {
|
||||
for (Map.Entry<String, String> entry : keyValues.entrySet()) {
|
||||
connection.setEx(entry.getKey().getBytes(), seconds,
|
||||
entry.getValue().getBytes());
|
||||
}
|
||||
return null;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("redis pipelineSetEX fail! e:{}", Throwables.getStackTraceAsString(e));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue