소스 검색

Merge branch 'ocpm_bid_engine_scores' into test

# Conflicts:
#	ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/ScoreThresholdPredictModel.java
gufengshou1 1 년 전
부모
커밋
ba4fd148a2

+ 0 - 206
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/redis/AdOwnRedisHelper.java

@@ -1,206 +0,0 @@
-package com.tzld.piaoquan.ad.engine.commons.redis;
-
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
-
-import javax.annotation.Resource;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-@Component
-public class AdOwnRedisHelper {
-
-    private final static Logger log = LoggerFactory.getLogger(AdOwnRedisHelper.class);
-
-    private final static Long AD_FILTER_DEFAULT_EXPIRE_TIME = 30L * 24 * 60 * 60; // 排除人群(广告、计划)默认设置30天,单位秒
-    private final static Long AD_FILTER_DELAY_QUEUE_EXPIRETIME = 5L * 60 * 1000; // 排除人群优化默认设置5分钟,单位毫秒
-    private final static Long AD_FILTER_DEFAULT_USER_BEHAVIOR_EXPIRETIME = 1L * 24 * 60 * 60; // 排除人群优化默认设置1天,单位秒
-    @Resource(name = "adOwnRedisTemplate")
-    private RedisTemplate<String, String> adOwnRedisTemplate;
-
-
-    public boolean containsKey(String key) {
-        return adOwnRedisTemplate.hasKey(key);
-    }
-
-    public String getString(String key) {
-        Object obj = adOwnRedisTemplate.opsForValue().get(key);
-        return Objects.isNull(obj) ? null : obj.toString();
-    }
-
-    public Long getLong(String key) {
-        long longVal = 0L;
-        Object obj = adOwnRedisTemplate.opsForValue().get(key);
-        if (Objects.nonNull(obj)) {
-            try {
-                longVal = Long.parseLong(obj.toString());
-            } catch (Exception e) {
-                e.printStackTrace();
-                return longVal;
-            }
-
-        }
-        return longVal;
-    }
-
-    public void setValueWithExpire(String key, String value, Date date) {
-        long expireTime;
-        if (date != null) {
-            expireTime = (date.getTime() - System.currentTimeMillis()) / 1000;
-            if (expireTime < 0) { // 过期时间有问题,或者小于当前时间
-                expireTime = AD_FILTER_DEFAULT_USER_BEHAVIOR_EXPIRETIME;
-            }
-        } else {
-            expireTime = AD_FILTER_DEFAULT_USER_BEHAVIOR_EXPIRETIME;
-        }
-        adOwnRedisTemplate.opsForValue().set(key, value, expireTime, TimeUnit.SECONDS);
-    }
-
-    public void setIncrementValue(String key, long value, Date date) {
-        Long expireTime;
-        if (date != null) {
-            expireTime = (date.getTime() - System.currentTimeMillis()) / 1000;
-            // 过期时间有问题,或者小于当前时间
-            if (expireTime < 0) {
-                expireTime = AD_FILTER_DEFAULT_EXPIRE_TIME;
-            }
-        } else { // date为null
-            expireTime = AD_FILTER_DEFAULT_EXPIRE_TIME;
-        }
-        // 只在第一次进行设置过期时间
-        if (!containsKey(key)) {
-            adOwnRedisTemplate.opsForValue().increment(key, value);
-            adOwnRedisTemplate.expire(key, expireTime, TimeUnit.SECONDS);
-        } else {
-            adOwnRedisTemplate.opsForValue().increment(key, value);
-        }
-    }
-
-    public void setIncrementValue(String key, double value, Date date) {
-        Long expireTime;
-        if (date != null) {
-            expireTime = (date.getTime() - System.currentTimeMillis()) / 1000;
-            // 过期时间有问题,或者小于当前时间
-            if (expireTime < 0) {
-                expireTime = AD_FILTER_DEFAULT_EXPIRE_TIME;
-            }
-        } else { // date为null
-            expireTime = AD_FILTER_DEFAULT_EXPIRE_TIME;
-        }
-        // 只在第一次进行设置过期时间
-        if (!containsKey(key)) {
-            adOwnRedisTemplate.opsForValue().increment(key, value);
-            adOwnRedisTemplate.expire(key, expireTime, TimeUnit.SECONDS);
-        } else {
-            adOwnRedisTemplate.opsForValue().increment(key, value);
-        }
-    }
-
-    public int getInteger(String key) {
-        Object obj = adOwnRedisTemplate.opsForValue().get(key);
-        if (Objects.isNull(obj)) {
-            return 0;
-        }
-        return Integer.valueOf(obj.toString());
-    }
-
-    public void putDelayQueueMsg(String key, String value) {
-        adOwnRedisTemplate.opsForZSet().add(key, value, System.currentTimeMillis() + AD_FILTER_DELAY_QUEUE_EXPIRETIME);
-    }
-
-    public Set<String> processDelayQueue(String key) {
-        long currentTimeMillis = System.currentTimeMillis();
-        Set<String> values = adOwnRedisTemplate.opsForZSet().rangeByScore(key, 0, currentTimeMillis);
-        if (!CollectionUtils.isEmpty(values)) {
-            adOwnRedisTemplate.opsForZSet().removeRangeByScore(key, 0, currentTimeMillis);
-        }
-        return values;
-    }
-
-    public void addVal(String key, String val) {
-        adOwnRedisTemplate.opsForValue().set(key, val);
-    }
-
-    public Double zScore(String key, String value) {
-        return adOwnRedisTemplate.opsForZSet().score(key, value);
-    }
-
-    public Long getKeyExpire(String key) {
-        return adOwnRedisTemplate.getExpire(key, TimeUnit.SECONDS);
-    }
-
-    public void expire(String key, Long time) {
-        adOwnRedisTemplate.expire(key, time, TimeUnit.SECONDS);
-    }
-
-    public Long countExistingKeys(List<String> keys) {
-        return adOwnRedisTemplate.countExistingKeys(keys);
-    }
-
-    public boolean del(String key) {
-        return adOwnRedisTemplate.delete(key);
-    }
-
-    public boolean set(String key, String value, long time) {
-        try {
-            if (time > 0) {
-                adOwnRedisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
-            } else {
-                adOwnRedisTemplate.opsForValue().set(key, value);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    /**
-     * Redis 分布式锁
-     *
-     * @param key        锁键
-     * @param value      锁值,可以为随机数或者 UUID 等唯一标识符
-     * @param expireTime 锁过期时间,单位为秒
-     * @return true:获取锁成功,false:获取锁失败
-     */
-    public boolean tryLock(String key, String value, long expireTime) {
-        Boolean result = adOwnRedisTemplate.opsForValue().setIfAbsent(key, value, expireTime, TimeUnit.SECONDS);
-        if (result != null && result) {
-            // 获取锁成功
-            return true;
-        }
-        return false;
-    }
-
-    public void listLeftPush(String key, String value) {
-        adOwnRedisTemplate.opsForList().leftPush(key, value);
-
-    }
-
-    public String listRightPop(String key) {
-        return adOwnRedisTemplate.opsForList().rightPop(key);
-    }
-
-    public Double getDouble(String key) {
-        String val = adOwnRedisTemplate.opsForValue().get(key);
-        if (StringUtils.isNotBlank(val)) {
-            return Double.valueOf(val);
-        }
-        return null;
-    }
-
-    public String get(String key) {
-        String val = adOwnRedisTemplate.opsForValue().get(key);
-        if (StringUtils.isNotBlank(val)) {
-            return val;
-        }
-        return null;
-    }
-}

+ 0 - 291
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/redis/RedisHelper.java

@@ -1,291 +0,0 @@
-package com.tzld.piaoquan.ad.engine.commons.redis;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.data.redis.connection.RedisStringCommands;
-import org.springframework.data.redis.core.RedisCallback;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.types.Expiration;
-import org.springframework.data.redis.serializer.RedisSerializer;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author ehlxr
- */
-@Component
-public class RedisHelper {
-    private static final Logger log = LoggerFactory.getLogger(RedisHelper.class);
-
-    /**
-     * 解锁 lua 脚本
-     */
-    // public static final String UNLOCK = "if (redis.call('get', KEYS[1]) == ARGV[1]) then" +
-    //         " return redis.call('del', KEYS[1]);" +
-    //         "else" +
-    //         " return 0;" +
-    //         "end";
-    /**
-     * 锁前缀
-     */
-    private static final String LOCK_PREFIX = "LOCK_";
-
-    /**
-     * 每次重试间隔时间 (毫秒)
-     */
-    // private static final int DEFAULT_RETRY_INTERVAL = 100;
-    private static RedisTemplate<String, String> redisTemplate;
-
-    /**
-     * 加锁
-     *
-     * @param timeout 毫秒
-     */
-    // public static Boolean lock(String key, String lockId, long timeout) {
-    //     return redisTemplate.opsForValue().setIfAbsent(LOCK_PREFIX + key, lockId, timeout, TimeUnit.MILLISECONDS);
-    // }
-
-    /**
-     * 重试加锁
-     *
-     * @param interval 重试间隔时间
-     */
-    // public static Boolean tryLock(String key, String lockId, long timeout, int interval) {
-    //     if (interval <= 0) {
-    //         interval = DEFAULT_RETRY_INTERVAL;
-    //     }
-    //     while (timeout >= 0) {
-    //         if (lock(key, lockId, timeout)) {
-    //             return true;
-    //         }
-    //         try {
-    //             TimeUnit.MILLISECONDS.sleep(interval);
-    //         } catch (Exception e) {
-    //             log.error("tryLock error key {} lockId {}", key, lockId, e);
-    //         }
-    //         timeout -= interval;
-    //     }
-    //     return false;
-    // }
-
-    // public static Boolean tryLock(String key, String lockId, long timeout) {
-    //     return tryLock(key, lockId, timeout, 0);
-    // }
-
-    /**
-     * 解锁
-     */
-    // public static Boolean unlock(String key, String lockId) {
-    //     String lockKey = LOCK_PREFIX + key;
-    //     DefaultRedisScript<Long> script = new DefaultRedisScript<>();
-    //     script.setResultType(Long.class);
-    //     script.setScriptSource(new StaticScriptSource(UNLOCK));
-    //
-    //     Object result = redisTemplate.execute(script, Collections.singletonList(lockKey), lockId);
-    //     if (Objects.isNull(result)) {
-    //         return null;
-    //     }
-    //     return Objects.equals(1L, Long.valueOf(result.toString()));
-    // }
-    @Autowired
-    public void setRedisTemplate(@Qualifier("redisTemplate") RedisTemplate<String, String> redisTemplate) {
-        RedisHelper.redisTemplate = redisTemplate;
-    }
-
-    public Object get(String key) {
-        return key == null ? null : redisTemplate.opsForValue().get(key);
-    }
-
-    public boolean set(String key, String value, long time) {
-        try {
-            if (time > 0) {
-                redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
-            } else {
-                set(key, value);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    public boolean set(String key, String value) {
-        try {
-            redisTemplate.opsForValue().set(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
-
-    // public Long decr(String key, long delta) {
-    //     if (delta < 0) {
-    //         throw new RuntimeException("递减因子必须大于0");
-    //     }
-    //     return redisTemplate.opsForValue().increment(key, -delta);
-    // }
-
-    public Long incr(String key, long delta) {
-        if (delta < 0) {
-            throw new RuntimeException("递增因子必须大于0");
-        }
-        return redisTemplate.opsForValue().increment(key, delta);
-    }
-
-    // public void expire(String key, long time) {
-    //     try {
-    //         if (time > 0) {
-    //             redisTemplate.expire(key, time, TimeUnit.SECONDS);
-    //         }
-    //     } catch (Exception e) {
-    //         e.printStackTrace();
-    //     }
-    // }
-
-    /**
-     * 根据value从一个set中查询,是否存在
-     *
-     * @param key   键
-     * @param value 值
-     * @return true 存在 false不存在
-     */
-    public Boolean sIsMember(String key, Object value) {
-        try {
-            return redisTemplate.opsForSet().isMember(key, value);
-        } catch (Exception e) {
-            log.error("set has key error", e);
-            return false;
-        }
-    }
-
-    /**
-     * 将数据放入set缓存
-     *
-     * @param key    键
-     * @param values 值 可以是多个
-     */
-    public void sSet(String key, String... values) {
-        try {
-            redisTemplate.opsForSet().add(key, values);
-        } catch (Exception e) {
-            log.error("set add is error", e);
-        }
-    }
-
-    // public void sRemove(String key, Object... values) {
-    //     try {
-    //         redisTemplate.opsForSet().remove(key, values);
-    //     } catch (Exception e) {
-    //         log.error("set remove is error", e);
-    //     }
-    // }
-
-    public void leftPushAll(String key, List<String> value) {
-        try {
-            redisTemplate.opsForList().leftPushAll(key, value);
-        } catch (Exception e) {
-            log.error("list left push all error", e);
-        }
-    }
-
-    /**
-     * 获取list缓存的内容
-     *
-     * @param key   键
-     * @param start 开始
-     * @param end   结束 0 到 -1代表所有值
-     */
-    public List<String> lGet(String key, long start, long end) {
-        try {
-            return redisTemplate.opsForList().range(key, start, end);
-        } catch (Exception e) {
-            log.error("RedisUtils.lGet.is.error.key={},start={},end={}", key, start, end, e);
-            return null;
-        }
-    }
-
-    /**
-     * 获取list缓存的长度
-     */
-    public Long lGetListSize(String key) {
-        try {
-            return redisTemplate.opsForList().size(key);
-        } catch (Exception e) {
-            log.error("get list size error", e);
-            return 0L;
-        }
-    }
-
-    // public Map<String, String> getHashEntries(String key) {
-    //     try {
-    //         return redisTemplate.<String, String>opsForHash().entries(key);
-    //     } catch (Exception e) {
-    //         log.error("get hash entry error", e);
-    //         return null;
-    //     }
-    // }
-
-    /**
-     * 获取某个元素的分数
-     */
-    public Double zScore(String key, String value) {
-        return redisTemplate.opsForZSet().score(key, value);
-    }
-
-    // public Long zRemove(String value, String key) {
-    //     return redisTemplate.opsForZSet().remove(key, value);
-    // }
-
-    /**
-     * 批量添加
-     */
-    // public static void batchSet(Map<String, String> map) {
-    //     redisTemplate.opsForValue().multiSet(map);
-    // }
-
-    /**
-     * 批量添加 并且设置失效时间
-     */
-    public static int batchSetOrExpire(Map<String, String> map, Long seconds) {
-        RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
-        return redisTemplate.executePipelined((RedisCallback<String>) connection -> {
-            map.forEach((key, value) -> {
-                byte[] keySeria = serializer.serialize(key);
-                byte[] valueSeria = serializer.serialize(value);
-                if (keySeria == null || valueSeria == null) {
-                    return;
-                }
-                connection.set(keySeria, valueSeria, Expiration.seconds(seconds), RedisStringCommands.SetOption.UPSERT);
-            });
-            return null;
-        }, serializer).size();
-    }
-
-    public void put(String key, String value) {
-        redisTemplate.opsForValue().set(key, value);
-    }
-
-    public void expire(String key, long day) {
-        redisTemplate.expire(key, day, TimeUnit.DAYS);
-    }
-
-    public boolean SetContain(String key, String value) {
-        return redisTemplate.opsForSet().isMember(key, value);
-    }
-
-    // public static List<String> batchGet(List<String> list) {
-    //     List<String> objectList = redisTemplate.opsForValue().multiGet(list);
-    //     return objectList;
-    // }
-
-    // public static void batchDelete(List<String> list) {
-    //     redisTemplate.delete(list);
-    // }
-}

+ 0 - 37
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/redis/RedisTemplateConfig.java

@@ -33,41 +33,6 @@ public class RedisTemplateConfig {
         return new GenericObjectPoolConfig<>();
         return new GenericObjectPoolConfig<>();
     }
     }
 
 
-    @Bean
-    @ConfigurationProperties(prefix = "spring.redis")
-    public RedisStandaloneConfiguration redisConfig() {
-        return new RedisStandaloneConfiguration();
-    }
-
-    @Bean("factory")
-    @Primary
-    public LettuceConnectionFactory factory(GenericObjectPoolConfig<LettucePoolingClientConfiguration> config, RedisStandaloneConfiguration redisConfig) {
-        LettuceClientConfiguration lettuceClientConfiguration = LettucePoolingClientConfiguration.builder().poolConfig(config).build();
-        return new LettuceConnectionFactory(redisConfig, lettuceClientConfiguration);
-    }
-
-    @Bean(name = "redisTemplate")
-    public RedisTemplate<String, String> getRedisTemplate(@Qualifier("factory") RedisConnectionFactory factory) {
-        return buildRedisTemplateByString(factory);
-    }
-
-    @Bean
-    @ConfigurationProperties(prefix = "spring.redis-ad")
-    public RedisStandaloneConfiguration adOwnRedisConfig() {
-        return new RedisStandaloneConfiguration();
-    }
-
-    @Bean("adOwnFactory")
-    public LettuceConnectionFactory pushCenterFactory(GenericObjectPoolConfig<LettucePoolingClientConfiguration> config, RedisStandaloneConfiguration adOwnRedisConfig) {
-        LettuceClientConfiguration lettuceClientConfiguration = LettucePoolingClientConfiguration.builder().poolConfig(config).build();
-        return new LettuceConnectionFactory(adOwnRedisConfig, lettuceClientConfiguration);
-    }
-
-    @Bean(name = "adOwnRedisTemplate")
-    public RedisTemplate<String, String> getPushCenterRedisTemplate(@Qualifier("adOwnFactory") RedisConnectionFactory pushCenterFactory) {
-        return buildRedisTemplateByString(pushCenterFactory);
-    }
-
     @Bean(name = "algorithmRedisTemplate")
     @Bean(name = "algorithmRedisTemplate")
     public RedisTemplate<String, String> getAlgorithmRedisTemplate(@Qualifier("algorithmRedisFactory") RedisConnectionFactory algorithmRedisFactory) {
     public RedisTemplate<String, String> getAlgorithmRedisTemplate(@Qualifier("algorithmRedisFactory") RedisConnectionFactory algorithmRedisFactory) {
         return buildRedisTemplateByString(algorithmRedisFactory);
         return buildRedisTemplateByString(algorithmRedisFactory);
@@ -85,8 +50,6 @@ public class RedisTemplateConfig {
         return new LettuceConnectionFactory(algorithmRedisConfig, lettuceClientConfiguration);
         return new LettuceConnectionFactory(algorithmRedisConfig, lettuceClientConfiguration);
     }
     }
 
 
-
-
     /**
     /**
      * 构建redisTemplate 使用string序列化
      * 构建redisTemplate 使用string序列化
      *
      *

+ 0 - 16
ad-engine-server/src/main/resources/application-dev.yml

@@ -26,22 +26,6 @@ spring:
       #username: wx2023_ad
       #username: wx2023_ad
       #password: wx2023_adP@assword1234
       #password: wx2023_adP@assword1234
 
 
-  redis:
-    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
-    port: 6379
-    password: Wqsd@2019
-    timeout: 1000
-    lettuce:
-      pool:
-        max-active: 8
-        max-wait: -1
-        max-idle: 8
-        min-idle: 0
-  redis-ad:
-    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
-    port: 6379
-    password: Wqsd@2019
-    timeout: 1000
   redis-algorithm:
   redis-algorithm:
 #    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
 #    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
     hostName: r-bp1fogs2mflr1ybfot.redis.rds.aliyuncs.com
     hostName: r-bp1fogs2mflr1ybfot.redis.rds.aliyuncs.com

+ 0 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/containner/RoiPredictParamContainer.java

@@ -1,7 +1,6 @@
 package com.tzld.piaoquan.ad.engine.service.predict.containner;
 package com.tzld.piaoquan.ad.engine.service.predict.containner;
 
 
 import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
 import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
-import com.tzld.piaoquan.ad.engine.commons.redis.RedisHelper;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;