commit
b9a20115d7
@ -0,0 +1,37 @@
|
|||||||
|
package com.java3y.austin.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 去重类型枚举
|
||||||
|
* @author 3y
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@ToString
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum DeduplicationType {
|
||||||
|
|
||||||
|
CONTENT(10, "N分钟相同内容去重"),
|
||||||
|
FREQUENCY(20, "一天内N次相同渠道去重"),
|
||||||
|
;
|
||||||
|
private Integer code;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取去重渠道的列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<Integer> getDeduplicationList() {
|
||||||
|
ArrayList<Integer> result = new ArrayList<>();
|
||||||
|
for (DeduplicationType value : DeduplicationType.values()) {
|
||||||
|
result.add(value.getCode());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.java3y.austin.service.deduplication;
|
||||||
|
|
||||||
|
import com.java3y.austin.service.deduplication.build.Builder;
|
||||||
|
import com.java3y.austin.service.deduplication.service.DeduplicationService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huskey
|
||||||
|
* @date 2022/1/18
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class DeduplicationHolder {
|
||||||
|
|
||||||
|
private Map<Integer, Builder> builderHolder = new HashMap<>(4);
|
||||||
|
private Map<Integer, DeduplicationService> serviceHolder = new HashMap<>(4);
|
||||||
|
|
||||||
|
public Builder selectBuilder(Integer key) {
|
||||||
|
return builderHolder.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeduplicationService selectService(Integer key) {
|
||||||
|
return serviceHolder.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putBuilder(Integer key, Builder builder) {
|
||||||
|
builderHolder.put(key, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putService(Integer key, DeduplicationService service) {
|
||||||
|
serviceHolder.put(key, service);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.java3y.austin.service.deduplication.build;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.java3y.austin.domain.DeduplicationParam;
|
||||||
|
import com.java3y.austin.domain.TaskInfo;
|
||||||
|
import com.java3y.austin.service.deduplication.DeduplicationHolder;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 3y
|
||||||
|
* @date 2022/1/19
|
||||||
|
*/
|
||||||
|
public abstract class AbstractDeduplicationBuilder implements Builder {
|
||||||
|
|
||||||
|
protected Integer deduplicationType;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DeduplicationHolder deduplicationHolder;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
deduplicationHolder.putBuilder(deduplicationType, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeduplicationParam getParamsFromConfig(Integer key, String duplicationConfig, TaskInfo taskInfo) {
|
||||||
|
JSONObject object = JSONObject.parseObject(duplicationConfig);
|
||||||
|
if (object == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
DeduplicationParam deduplicationParam = JSONObject.parseObject(object.getString(CONFIG_PRE + key), DeduplicationParam.class);
|
||||||
|
if (deduplicationParam == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
deduplicationParam.setTaskInfo(taskInfo);
|
||||||
|
return deduplicationParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.java3y.austin.service.deduplication.build;
|
||||||
|
|
||||||
|
import com.java3y.austin.domain.DeduplicationParam;
|
||||||
|
import com.java3y.austin.domain.TaskInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author luohaojie
|
||||||
|
* @date 2022/1/18
|
||||||
|
*/
|
||||||
|
public interface Builder {
|
||||||
|
|
||||||
|
String CONFIG_PRE = "deduplication_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据配置构建去重参数
|
||||||
|
*
|
||||||
|
* @param deduplication
|
||||||
|
* @param taskInfo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
DeduplicationParam build(String deduplication, TaskInfo taskInfo);
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.java3y.austin.service.deduplication.build;
|
||||||
|
|
||||||
|
import com.java3y.austin.domain.DeduplicationParam;
|
||||||
|
import com.java3y.austin.domain.TaskInfo;
|
||||||
|
import com.java3y.austin.enums.AnchorState;
|
||||||
|
import com.java3y.austin.enums.DeduplicationType;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huskey
|
||||||
|
* @date 2022/1/18
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ContentDeduplicationBuilder extends AbstractDeduplicationBuilder implements Builder {
|
||||||
|
|
||||||
|
public ContentDeduplicationBuilder() {
|
||||||
|
deduplicationType = DeduplicationType.CONTENT.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeduplicationParam build(String deduplication, TaskInfo taskInfo) {
|
||||||
|
DeduplicationParam deduplicationParam = getParamsFromConfig(deduplicationType, deduplication, taskInfo);
|
||||||
|
if (deduplication == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
deduplicationParam.setAnchorState(AnchorState.CONTENT_DEDUPLICATION);
|
||||||
|
return deduplicationParam;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.java3y.austin.service.deduplication.build;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.java3y.austin.domain.DeduplicationParam;
|
||||||
|
import com.java3y.austin.domain.TaskInfo;
|
||||||
|
import com.java3y.austin.enums.AnchorState;
|
||||||
|
import com.java3y.austin.enums.DeduplicationType;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huskey
|
||||||
|
* @date 2022/1/18
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class FrequencyDeduplicationBuilder extends AbstractDeduplicationBuilder implements Builder {
|
||||||
|
public FrequencyDeduplicationBuilder() {
|
||||||
|
deduplicationType = DeduplicationType.FREQUENCY.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeduplicationParam build(String deduplication, TaskInfo taskInfo) {
|
||||||
|
DeduplicationParam deduplicationParam = getParamsFromConfig(deduplicationType, deduplication, taskInfo);
|
||||||
|
if (deduplicationParam == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
deduplicationParam.setDeduplicationTime((DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000);
|
||||||
|
deduplicationParam.setAnchorState(AnchorState.RULE_DEDUPLICATION);
|
||||||
|
return deduplicationParam;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.java3y.austin.service.deduplication.service;
|
||||||
|
|
||||||
|
import com.java3y.austin.domain.DeduplicationParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author huskey
|
||||||
|
* @date 2022/1/18
|
||||||
|
*/
|
||||||
|
public interface DeduplicationService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 去重
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
void deduplication(DeduplicationParam param);
|
||||||
|
}
|
Loading…
Reference in new issue