#363 新用户风险视频过滤

Scalone
supeng scala 1 commity/ów z algorithm/feature_20250919_supeng_optimize_recommend_risk_filter do algorithm/master 1 dzień temu

+ 63 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/config/MidRedisTemplateConfig.java

@@ -0,0 +1,63 @@
+package com.tzld.piaoquan.recommend.server.config;
+
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+@Configuration
+public class MidRedisTemplateConfig {
+
+    @Bean("midRedisPool")
+    @ConfigurationProperties(prefix = "spring.mid-redis.lettuce.pool")
+    public GenericObjectPoolConfig<LettucePoolingClientConfiguration> midRedisPool() {
+        return new GenericObjectPoolConfig<>();
+    }
+
+    @Bean("midRedisConfig")
+    @ConfigurationProperties(prefix = "spring.mid-redis")
+    public RedisStandaloneConfiguration midRedisConfig() {
+        return new RedisStandaloneConfiguration();
+    }
+
+    @Bean("midRedisFactory")
+    @Primary
+    public LettuceConnectionFactory factory(@Qualifier("midRedisPool") GenericObjectPoolConfig<LettucePoolingClientConfiguration> midRedisPool,
+                                            @Qualifier("midRedisConfig") RedisStandaloneConfiguration midRedisConfig) {
+        LettuceClientConfiguration lettuceClientConfiguration =
+                LettucePoolingClientConfiguration.builder().poolConfig(midRedisPool).build();
+        return new LettuceConnectionFactory(midRedisConfig, lettuceClientConfiguration);
+    }
+
+    @Bean(name = "midRedisTemplate")
+    public RedisTemplate<String, String> getRedisTemplate(@Qualifier("midRedisFactory") RedisConnectionFactory factory) {
+        return buildRedisTemplateByString(factory);
+    }
+
+    /**
+     * 构建redisTemplate 使用string序列化
+     *
+     * @param factory
+     * @return
+     */
+    private RedisTemplate<String, String> buildRedisTemplateByString(RedisConnectionFactory factory) {
+        RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
+        redisTemplate.setConnectionFactory(factory);
+        // key的序列化类型 保证可读性
+        redisTemplate.setKeySerializer(new StringRedisSerializer());
+        redisTemplate.setValueSerializer(new StringRedisSerializer());
+        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
+        return redisTemplate;
+    }
+
+}

+ 63 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/config/UserRedisTemplateConfig.java

@@ -0,0 +1,63 @@
+package com.tzld.piaoquan.recommend.server.config;
+
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+@Configuration
+public class UserRedisTemplateConfig {
+
+    @Bean("userRedisPool")
+    @ConfigurationProperties(prefix = "spring.user-redis.lettuce.pool")
+    public GenericObjectPoolConfig<LettucePoolingClientConfiguration> userRedisPool() {
+        return new GenericObjectPoolConfig<>();
+    }
+
+    @Bean("userRedisConfig")
+    @ConfigurationProperties(prefix = "spring.user-redis")
+    public RedisStandaloneConfiguration userRedisConfig() {
+        return new RedisStandaloneConfiguration();
+    }
+
+    @Bean("userRedisFactory")
+    @Primary
+    public LettuceConnectionFactory factory(@Qualifier("userRedisPool") GenericObjectPoolConfig<LettucePoolingClientConfiguration> userRedisPool,
+                                            @Qualifier("userRedisConfig") RedisStandaloneConfiguration userRedisConfig) {
+        LettuceClientConfiguration lettuceClientConfiguration =
+                LettucePoolingClientConfiguration.builder().poolConfig(userRedisPool).build();
+        return new LettuceConnectionFactory(userRedisConfig, lettuceClientConfiguration);
+    }
+
+    @Bean(name = "userRedisTemplate")
+    public RedisTemplate<String, String> getRedisTemplate(@Qualifier("userRedisFactory") RedisConnectionFactory factory) {
+        return buildRedisTemplateByString(factory);
+    }
+
+    /**
+     * 构建redisTemplate 使用string序列化
+     *
+     * @param factory
+     * @return
+     */
+    private RedisTemplate<String, String> buildRedisTemplateByString(RedisConnectionFactory factory) {
+        RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
+        redisTemplate.setConnectionFactory(factory);
+        // key的序列化类型 保证可读性
+        redisTemplate.setKeySerializer(new StringRedisSerializer());
+        redisTemplate.setValueSerializer(new StringRedisSerializer());
+        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
+        return redisTemplate;
+    }
+
+}

+ 429 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/repository/WxUserInfo.java

@@ -0,0 +1,429 @@
+package com.tzld.piaoquan.recommend.server.repository;
+
+import lombok.Data;
+import scala.Int;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.util.Date;
+
+/**
+ * @author supeng
+ */
+@Data
+@Entity
+@Table(name = "wx_user_info")
+public class WxUserInfo {
+
+//    @Id
+//    private Long id;
+//
+//    private Long uid;
+//
+//    private String unionId;
+//    private String avatar_url;
+//    private String nick_name;
+//    private String longvideo_avatar_url;
+//    private String longvideo_nick_name;
+//    private Long idols;
+//    private Long fans;
+//    private Integer videos;
+//    private Integer favorite;
+//    private Long favoriteds;
+//    private Long reported_count;
+//    private Long play_count;
+//    private Long play_count_total;
+//    private Long share_moment_count;
+//    private Long share_friend_count;
+//    private Long video_share_friend_count;
+//    private Long video_share_friend_count_total;
+//    private Long video_share_moment_count;
+//    private Long video_share_moment_count_total;
+//    private Long last_load_fans_timestamp;
+//    private Long last_load_idol_msg_timestamp;
+//    private Integer form;
+//    private String open_id;
+//    private String pc_open_id;
+//    private String qingqu_app_open_id;
+//    private String smile_open_id;
+//    private String short_open_id;
+//    private String surprise_open_id;
+//    private String appid;
+//    private Date gmt_create;
+//    private Date gmt_modified;
+//    private Date last_login_datetime;
+//    private Long gmt_create_timestamp;
+//    private Long gmt_modified_timestamp;
+//    private Long last_login_timestamp;
+//    private Long last_operation_timestamp;
+//    private Integer version;
+//    private Integer status;
+//    private Integer recommend_status;
+//    private Integer m_recommend_weight;
+//    private Integer tag_count;
+//    private Integer user_type;
+//    private Integer search_status;
+
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.id
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    @Id
+    private Long id;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.uid
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long uid;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.union_id
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String unionId;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.avatar_url
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String avatarUrl;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.nick_name
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String nickName;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.longvideo_avatar_url
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String longvideoAvatarUrl;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.longvideo_nick_name
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String longvideoNickName;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.idols
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long idols;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.fans
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long fans;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.videos
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer videos;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.favorite
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer favorite;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.favoriteds
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long favoriteds;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.reported_count
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long reportedCount;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.play_count
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long playCount;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.play_count_total
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long playCountTotal;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.share_moment_count
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long shareMomentCount;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.share_friend_count
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long shareFriendCount;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.video_share_friend_count
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long videoShareFriendCount;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.video_share_friend_count_total
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long videoShareFriendCountTotal;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.video_share_moment_count
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long videoShareMomentCount;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.video_share_moment_count_total
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long videoShareMomentCountTotal;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.last_load_fans_timestamp
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long lastLoadFansTimestamp;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.last_load_idol_msg_timestamp
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long lastLoadIdolMsgTimestamp;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.form
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer form;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.open_id
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String openId;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.pc_open_id
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String pcOpenId;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.qingqu_app_open_id
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String qingquAppOpenId;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.smile_open_id
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String smileOpenId;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.short_open_id
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String shortOpenId;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.surprise_open_id
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String surpriseOpenId;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.appid
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private String appid;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.gmt_create
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Date gmtCreate;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.gmt_modified
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Date gmtModified;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.last_login_datetime
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Date lastLoginDatetime;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.gmt_create_timestamp
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long gmtCreateTimestamp;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.gmt_modified_timestamp
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long gmtModifiedTimestamp;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.last_login_timestamp
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long lastLoginTimestamp;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.last_operation_timestamp
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Long lastOperationTimestamp;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.version
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer version;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.status
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer status;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.recommend_status
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer recommendStatus;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.m_recommend_weight
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer mRecommendWeight;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.tag_count
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer tagCount;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.user_type
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer userType;
+
+    /**
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column wx_user_info.search_status
+     *
+     * @mbggenerated Thu Jan 24 16:09:21 CST 2019
+     */
+    private Integer searchStatus;
+}

+ 12 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/repository/WxUserInfoRepository.java

@@ -0,0 +1,12 @@
+package com.tzld.piaoquan.recommend.server.repository;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface WxUserInfoRepository extends JpaRepository<WxUserInfo, Long> {
+
+    List<WxUserInfo> findByUid(Long uid);
+}

+ 78 - 4
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/RecommendService.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.recommend.server.service;
 
+import com.alibaba.fastjson.JSON;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.base.Stopwatch;
 import com.google.common.base.Strings;
@@ -15,6 +16,8 @@ import com.tzld.piaoquan.recommend.server.gen.recommend.*;
 import com.tzld.piaoquan.recommend.server.model.MachineInfo;
 import com.tzld.piaoquan.recommend.server.model.RecommendParam;
 import com.tzld.piaoquan.recommend.server.model.Video;
+import com.tzld.piaoquan.recommend.server.repository.WxUserInfo;
+import com.tzld.piaoquan.recommend.server.repository.WxUserInfoRepository;
 import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolConstants;
 import com.tzld.piaoquan.recommend.server.service.flowpool.FlowPoolService;
 import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
@@ -41,6 +44,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
+import java.time.Duration;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
@@ -89,6 +93,21 @@ public class RecommendService {
     private Set<Integer> noneUserRiskExcludeAppTypes;
 
     public static final String channelGroupPrefix = "alg_recsys_user_channel_group";
+    /**
+     * wx_user_info 表信息
+     * wx:user:info:%s
+     */
+    private static final String USER_INFO_CACHE_KEY = "wx:user:info:%s";
+    private static final String MID_GENERATE_CACHE_KEY = "mid:generate:timestamp:risk:%s";
+
+    @Autowired
+    private RedisTemplate<String, String> userRedisTemplate;
+
+    @Autowired
+    private RedisTemplate<String, String> midRedisTemplate;
+
+    @Autowired
+    private WxUserInfoRepository wxUserInfoRepository;
 
     private LoadingCache<String, Set<String>> riskUserCache = CacheBuilder.newBuilder()
             .maximumSize(5)
@@ -364,10 +383,13 @@ public class RecommendService {
         // 风险过滤
         if (riskVideoFilterSwitch) {
             //0 4产品之外,hotsencetype 1089进入,没有mid和uid时,推荐返回过滤掉风险视频
-            boolean isNoneUserRisk = (Objects.isNull(noneUserRiskExcludeAppTypes) || !noneUserRiskExcludeAppTypes.contains(param.getAppType()))
-                    && Objects.equals(1089L, request.getHotSceneType())
-                    && (Objects.isNull(param.getUid()) || Objects.equals("0", param.getUid().trim()) || Objects.equals("null", param.getUid().trim()))
-                    && (Objects.isNull(param.getMid()) || Objects.equals("", param.getMid().trim()));
+//            boolean isNoneUserRisk = (Objects.isNull(noneUserRiskExcludeAppTypes) || !noneUserRiskExcludeAppTypes.contains(param.getAppType()))
+//                    && Objects.equals(1089L, request.getHotSceneType())
+//                    && (Objects.isNull(param.getUid()) || Objects.equals("0", param.getUid().trim()) || Objects.equals("null", param.getUid().trim()))
+//                    && (Objects.isNull(param.getMid()) || Objects.equals("", param.getMid().trim()));
+
+            //0 4产品之外,hotsencetype 1089进入,没有mid和uid 或 mid/uid为新用户时,推荐返回过滤掉风险视频
+            boolean isNoneUserRisk = isNoneUserRisk(request, param);
             boolean riskUser = riskScenes.contains(request.getHotSceneType())
                     || riskUserCache.getUnchecked(RedisKeyConstants.Recommend.riskUserUid).contains(param.getUid())
                     || riskUserCache.getUnchecked(RedisKeyConstants.Recommend.riskUserMid).contains(param.getMid())
@@ -410,6 +432,58 @@ public class RecommendService {
         return param;
     }
 
+    private boolean isNoneUserRisk(RecommendRequest request, RecommendParam param) {
+        boolean isNoneUserRisk = false;
+        try {
+            if ((Objects.isNull(noneUserRiskExcludeAppTypes) || !noneUserRiskExcludeAppTypes.contains(param.getAppType()))
+                    && Objects.equals(1089L, request.getHotSceneType())) {
+                if ((Objects.isNull(param.getUid()) || Objects.equals("0", param.getUid().trim()) || Objects.equals("null", param.getUid().trim()))
+                        && (Objects.isNull(param.getMid()) || Objects.equals("", param.getMid().trim()))) {
+                    //无mid/uid时
+                    isNoneUserRisk = true;
+                } else {
+                    if (Objects.nonNull(param.getUid()) && !Objects.equals("0", param.getUid().trim()) && !Objects.equals("null", param.getUid().trim())) {
+                        //有uid
+                        WxUserInfo wxUserInfo = getWxUserInfo(param.getUid());
+                        if (Objects.isNull(wxUserInfo)) {
+                            //有uid,但是未入库,新用户
+                            isNoneUserRisk = true;
+                        }
+                    } else if (Objects.nonNull(param.getMid()) && !Objects.equals("", param.getMid().trim())) {
+                        //有mid
+                        String key = String.format(MID_GENERATE_CACHE_KEY, param.getMid());
+                        if (!Boolean.TRUE.equals(midRedisTemplate.hasKey(key))) {
+                            //不存在则为新用户
+                            isNoneUserRisk = true;
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("isNoneUserRisk error param = {} ", JSON.toJSONString(param), e);
+        }
+        return isNoneUserRisk;
+    }
+
+    private WxUserInfo getWxUserInfo(String uid) {
+        try {
+            String key = String.format(USER_INFO_CACHE_KEY, uid);
+            String userInfo = userRedisTemplate.opsForValue().get(key);
+            if (Objects.nonNull(userInfo)) {
+                return JSON.parseObject(userInfo, WxUserInfo.class);
+            }
+            List<WxUserInfo> list = wxUserInfoRepository.findByUid(Long.parseLong(uid));
+            if (Objects.nonNull(list) && !list.isEmpty()) {
+                WxUserInfo wxUserInfo = list.get(0);
+                userRedisTemplate.opsForValue().set(key, JSON.toJSONString(wxUserInfo), Duration.ofHours(2));
+                return wxUserInfo;
+            }
+        } catch (Exception e) {
+            log.error("getWxUserInfo error uid = {}", uid, e);
+        }
+        return null;
+    }
+
     private List<Video> videoRecommend(RecommendParam param) {
         Stopwatch stopwatch = Stopwatch.createStarted();
         String vid = String.valueOf(param.getVideoId());

+ 2 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/RiskVideoStrategy.java

@@ -5,6 +5,8 @@ import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import com.tzld.piaoquan.recommend.server.common.RedisKeyConstants;
+import com.tzld.piaoquan.recommend.server.repository.WxUserInfo;
+import com.tzld.piaoquan.recommend.server.repository.WxUserInfoRepository;
 import com.tzld.piaoquan.recommend.server.repository.WxVideoTagRel;
 import com.tzld.piaoquan.recommend.server.repository.WxVideoTagRelRepository;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;

+ 22 - 0
recommend-server-service/src/main/resources/application-dev.yml

@@ -71,6 +71,28 @@ spring:
         max-wait: -1
         max-idle: 8
         min-idle: 0
+  user-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
+  mid-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
   data:
     mongodb:
       clusterHost: dds-bp1de4fc73029b241978.mongodb.rds.aliyuncs.com

+ 22 - 0
recommend-server-service/src/main/resources/application-pre.yml

@@ -71,6 +71,28 @@ spring:
         max-wait: -1
         max-idle: 8
         min-idle: 0
+  user-redis:
+    hostName: r-bp134e22e50438f4253.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
+  mid-redis:
+    hostName: r-bp1j1vsznx8h813ddk.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
   data:
     mongodb:
       clusterHost: s-bp14ce206f81b754.mongodb.rds.aliyuncs.com

+ 22 - 0
recommend-server-service/src/main/resources/application-prod.yml

@@ -71,6 +71,28 @@ spring:
         max-wait: -1
         max-idle: 8
         min-idle: 0
+  user-redis:
+    hostName: r-bp134e22e50438f4253.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
+  mid-redis:
+    hostName: r-bp1j1vsznx8h813ddk.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
   data:
     mongodb:
       clusterHost: s-bp14ce206f81b754.mongodb.rds.aliyuncs.com

+ 22 - 0
recommend-server-service/src/main/resources/application-test.yml

@@ -71,6 +71,28 @@ spring:
         max-wait: -1
         max-idle: 8
         min-idle: 0
+  user-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
+  mid-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
   data:
     mongodb:
       clusterHost: dds-bp1de4fc73029b241978.mongodb.rds.aliyuncs.com