mirror of https://github.com/ZhongFuCheng3y/austin
parent
f2973035bb
commit
c1ff4f3a94
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.java3y.austin.service.deduplication.build;
|
||||
|
||||
import com.java3y.austin.service.deduplication.DeduplicationConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author huskey
|
||||
* @date 2022/1/18
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class BuilderFactory {
|
||||
|
||||
|
||||
private Map<String, Builder> builderFactory = new HashMap<>(4);
|
||||
|
||||
@Autowired
|
||||
private Builder contentDeduplicationBuilder;
|
||||
|
||||
@Autowired
|
||||
private Builder frequencyDeduplicationBuilder;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
builderFactory.put(DeduplicationConstants.CONTENT_DEDUPLICATION, contentDeduplicationBuilder);
|
||||
builderFactory.put(DeduplicationConstants.FREQUENCY_DEDUPLICATION, frequencyDeduplicationBuilder);
|
||||
}
|
||||
|
||||
|
||||
public Builder select(String key) {
|
||||
return builderFactory.get(key);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue