Ver Fonte

feat: 子包服务同步更新

hidewnd há 1 mês atrás
pai
commit
68301355f3
100 ficheiros alterados com 2632 adições e 1238 exclusões
  1. 12 3
      yt-adage/adage-service/src/main/java/com/ytpm/adage/dao/AdRecordMapper.java
  2. 9 7
      yt-adage/adage-service/src/main/java/com/ytpm/adage/service/impl/AdServiceImpl.java
  3. 17 2
      yt-adage/adage-service/src/main/java/com/ytpm/adage/service/impl/AppUserServiceImpl.java
  4. 2 0
      yt-adage/adage-service/src/main/java/com/ytpm/adage/service/impl/VisitorLoginServiceImpl.java
  5. 108 62
      yt-adage/adage-service/src/main/resources/mapper/AdRecordMapper.xml
  6. 3 1
      yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/controller/VisitorController.java
  7. 12 2
      yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/dao/AdRecordMapper.java
  8. 8 2
      yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/service/impl/AdServiceImpl.java
  9. 15 0
      yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/service/impl/AppUserServiceImpl.java
  10. 2 0
      yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/service/impl/VisitorLoginServiceImpl.java
  11. 48 3
      yt-algebraic/algebraic-service/src/main/resources/mapper/AdRecordMapper.xml
  12. 2 1
      yt-allusion/allusion-service/src/main/java/com/ytpm/allusion/controller/VisitorController.java
  13. 15 0
      yt-allusion/allusion-service/src/main/java/com/ytpm/allusion/service/impl/AppUserServiceImpl.java
  14. 1 0
      yt-answer/answer-service/pom.xml
  15. 3 1
      yt-answer/answer-service/src/main/java/com/ytpm/answer/config/interceptor/HttpInterceptor.java
  16. 14 0
      yt-answer/answer-service/src/main/java/com/ytpm/answer/controller/UserController.java
  17. 2 1
      yt-answer/answer-service/src/main/java/com/ytpm/answer/controller/VisitorController.java
  18. 2 0
      yt-answer/answer-service/src/main/java/com/ytpm/answer/controller/WxController.java
  19. 12 1
      yt-answer/answer-service/src/main/java/com/ytpm/answer/dao/AdRecordMapper.java
  20. 2 0
      yt-answer/answer-service/src/main/java/com/ytpm/answer/dao/AppUserMapper.java
  21. 8 3
      yt-answer/answer-service/src/main/java/com/ytpm/answer/monitor/RedisKeyExpirationListener.java
  22. 6 0
      yt-answer/answer-service/src/main/java/com/ytpm/answer/service/AdService.java
  23. 37 7
      yt-answer/answer-service/src/main/java/com/ytpm/answer/service/impl/AdServiceImpl.java
  24. 15 0
      yt-answer/answer-service/src/main/java/com/ytpm/answer/service/impl/AppUserServiceImpl.java
  25. 50 5
      yt-answer/answer-service/src/main/java/com/ytpm/answer/service/impl/VisitorLoginServiceImpl.java
  26. 112 60
      yt-answer/answer-service/src/main/resources/mapper/AdRecordMapper.xml
  27. 174 136
      yt-answer/answer-service/src/main/resources/mapper/AppUserMapper.xml
  28. 22 20
      yt-answer/answer-service/src/main/resources/mapper/LoginRecordMapper.xml
  29. 1 0
      yt-arena/arena-service/pom.xml
  30. 3 1
      yt-arena/arena-service/src/main/java/com/ytpm/arena/config/interceptor/HttpInterceptor.java
  31. 16 0
      yt-arena/arena-service/src/main/java/com/ytpm/arena/controller/UserController.java
  32. 2 1
      yt-arena/arena-service/src/main/java/com/ytpm/arena/controller/VisitorController.java
  33. 2 0
      yt-arena/arena-service/src/main/java/com/ytpm/arena/controller/WxController.java
  34. 12 1
      yt-arena/arena-service/src/main/java/com/ytpm/arena/dao/AdRecordMapper.java
  35. 2 0
      yt-arena/arena-service/src/main/java/com/ytpm/arena/dao/AppUserMapper.java
  36. 5 2
      yt-arena/arena-service/src/main/java/com/ytpm/arena/monitor/RedisKeyExpirationListener.java
  37. 6 0
      yt-arena/arena-service/src/main/java/com/ytpm/arena/service/AdService.java
  38. 44 8
      yt-arena/arena-service/src/main/java/com/ytpm/arena/service/impl/AdServiceImpl.java
  39. 15 0
      yt-arena/arena-service/src/main/java/com/ytpm/arena/service/impl/AppUserServiceImpl.java
  40. 51 5
      yt-arena/arena-service/src/main/java/com/ytpm/arena/service/impl/VisitorLoginServiceImpl.java
  41. 112 60
      yt-arena/arena-service/src/main/resources/mapper/AdRecordMapper.xml
  42. 174 135
      yt-arena/arena-service/src/main/resources/mapper/AppUserMapper.xml
  43. 22 20
      yt-arena/arena-service/src/main/resources/mapper/LoginRecordMapper.xml
  44. 2 1
      yt-arithmetic/arithmetic-service/src/main/java/com/ytpm/arithmetic/controller/VisitorController.java
  45. 15 0
      yt-arithmetic/arithmetic-service/src/main/java/com/ytpm/arithmetic/service/impl/AppUserServiceImpl.java
  46. 2 1
      yt-calculator/calculator-service/src/main/java/com/ytpm/calculator/controller/VisitorController.java
  47. 15 0
      yt-calculator/calculator-service/src/main/java/com/ytpm/calculator/service/impl/AppUserServiceImpl.java
  48. 1 0
      yt-carp/carp-service/pom.xml
  49. 3 1
      yt-carp/carp-service/src/main/java/com/ytpm/carp/config/interceptor/HttpInterceptor.java
  50. 14 0
      yt-carp/carp-service/src/main/java/com/ytpm/carp/controller/UserController.java
  51. 2 1
      yt-carp/carp-service/src/main/java/com/ytpm/carp/controller/VisitorController.java
  52. 2 0
      yt-carp/carp-service/src/main/java/com/ytpm/carp/controller/WxController.java
  53. 12 1
      yt-carp/carp-service/src/main/java/com/ytpm/carp/dao/AdRecordMapper.java
  54. 2 0
      yt-carp/carp-service/src/main/java/com/ytpm/carp/dao/AppUserMapper.java
  55. 8 3
      yt-carp/carp-service/src/main/java/com/ytpm/carp/monitor/RedisKeyExpirationListener.java
  56. 6 0
      yt-carp/carp-service/src/main/java/com/ytpm/carp/service/AdService.java
  57. 36 7
      yt-carp/carp-service/src/main/java/com/ytpm/carp/service/impl/AdServiceImpl.java
  58. 15 0
      yt-carp/carp-service/src/main/java/com/ytpm/carp/service/impl/AppUserServiceImpl.java
  59. 49 4
      yt-carp/carp-service/src/main/java/com/ytpm/carp/service/impl/VisitorLoginServiceImpl.java
  60. 112 60
      yt-carp/carp-service/src/main/resources/mapper/AdRecordMapper.xml
  61. 174 135
      yt-carp/carp-service/src/main/resources/mapper/AppUserMapper.xml
  62. 23 21
      yt-carp/carp-service/src/main/resources/mapper/LoginRecordMapper.xml
  63. 3 1
      yt-countstep/countstep-service/src/main/java/com/ytpm/countstep/controller/VisitorController.java
  64. 15 0
      yt-countstep/countstep-service/src/main/java/com/ytpm/countstep/service/impl/AppUserServiceImpl.java
  65. 2 1
      yt-diary/diary-service/src/main/java/com/ytpm/diary/controller/VisitorController.java
  66. 1 1
      yt-diary/diary-service/src/main/java/com/ytpm/diary/dao/AdRecordMapper.java
  67. 1 0
      yt-diary/diary-service/src/main/java/com/ytpm/diary/service/impl/AdServiceImpl.java
  68. 15 0
      yt-diary/diary-service/src/main/java/com/ytpm/diary/service/impl/AppUserServiceImpl.java
  69. 1 0
      yt-diary/diary-service/src/main/java/com/ytpm/diary/service/impl/VisitorLoginServiceImpl.java
  70. 1 0
      yt-dtw/dtw-service/pom.xml
  71. 3 1
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/config/interceptor/HttpInterceptor.java
  72. 15 0
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/controller/UserController.java
  73. 2 1
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/controller/VisitorController.java
  74. 2 0
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/controller/WxController.java
  75. 12 1
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/dao/AdRecordMapper.java
  76. 2 0
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/dao/AppUserMapper.java
  77. 8 3
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/monitor/RedisKeyExpirationListener.java
  78. 6 0
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/service/AdService.java
  79. 36 7
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/service/impl/AdServiceImpl.java
  80. 15 0
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/service/impl/AppUserServiceImpl.java
  81. 50 5
      yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/service/impl/VisitorLoginServiceImpl.java
  82. 112 60
      yt-dtw/dtw-service/src/main/resources/mapper/AdRecordMapper.xml
  83. 177 135
      yt-dtw/dtw-service/src/main/resources/mapper/AppUserMapper.xml
  84. 24 23
      yt-dtw/dtw-service/src/main/resources/mapper/LoginRecordMapper.xml
  85. 2 1
      yt-emoticons/emoticons-service/src/main/java/com/ytpm/emoticons/controller/VisitorController.java
  86. 15 0
      yt-emoticons/emoticons-service/src/main/java/com/ytpm/emoticons/service/impl/AppUserServiceImpl.java
  87. 1 0
      yt-funarith/funarith-service/pom.xml
  88. 3 1
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/config/interceptor/HttpInterceptor.java
  89. 15 0
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/controller/UserController.java
  90. 2 1
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/controller/VisitorController.java
  91. 2 0
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/controller/WxController.java
  92. 13 1
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/dao/AdRecordMapper.java
  93. 2 0
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/dao/AppUserMapper.java
  94. 8 3
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/monitor/RedisKeyExpirationListener.java
  95. 6 0
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/service/AdService.java
  96. 36 7
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/service/impl/AdServiceImpl.java
  97. 15 0
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/service/impl/AppUserServiceImpl.java
  98. 50 5
      yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/service/impl/VisitorLoginServiceImpl.java
  99. 112 60
      yt-funarith/funarith-service/src/main/resources/mapper/AdRecordMapper.xml
  100. 174 135
      yt-funarith/funarith-service/src/main/resources/mapper/AppUserMapper.xml

+ 12 - 3
yt-adage/adage-service/src/main/java/com/ytpm/adage/dao/AdRecordMapper.java

@@ -15,10 +15,16 @@ public interface AdRecordMapper {
      * 新增广告记录
      */
     void addOne(YtDyzAdRecord adRecord);
+
+    /**
+     * 保存游客广告记录
+     */
+    void addOneVisitor(YtDyzAdRecord adRecord);
+
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
 
     /**
      * 查询激励视频记录
@@ -45,5 +51,8 @@ public interface AdRecordMapper {
      */
     List<YtDyzAdRecord> getTodayRecord(@Param("appIds")String appIds,@Param("firstDay")String firstDay,@Param("lastDay")String lastDay);
 
-    List<YtDyzAdRecord> selectRecordByIds(@Param("ids") List<String> adRecordIds);
-}
+    /**
+     * 查询指定广告记录
+     */
+    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
+}

+ 9 - 7
yt-adage/adage-service/src/main/java/com/ytpm/adage/service/impl/AdServiceImpl.java

@@ -10,6 +10,7 @@ import com.ytpm.adage.dao.AppUserMapper;
 import com.ytpm.adage.service.AdService;
 import com.ytpm.advertise.enums.AdPlatformTypeEnum;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
@@ -251,18 +252,15 @@ public class AdServiceImpl implements AdService {
         cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),actualMaximum,23,59,59);
         String lastDay = sdf.format(cal.getTime());
         List<YtDyzAdRecord> dyzMonthRecords = adRecordMapper.getTodayRecord(appIds,firstDay,lastDay);
-
         if(CollUtil.isNotEmpty(dyzMonthRecords)){monthRecords.addAll(dyzMonthRecords);}
         records = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),new Date())).collect(Collectors.toList());
 
-        cal = Calendar.getInstance();
+        cal = Calendar.getInstance(); // 获取当前日期时间
         cal.add(Calendar.DATE, -1); // 昨天的日期时间
         Date yest = cal.getTime();
         yestRecords = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),yest)).collect(Collectors.toList());
-
-        if(CollUtil.isNotEmpty(dyzMonthRecords)){monthRecords.addAll(dyzMonthRecords);}
         //广告平台分组
         Map<String, List<YtDyzAdRecord>> networkMap = records.stream().collect(
                 Collectors.groupingBy(YtDyzAdRecord::getNetworkFormId));
@@ -317,19 +315,23 @@ public class AdServiceImpl implements AdService {
         BeanUtils.copyProperties(param, adRecord);
         adRecord.setRecordId(IdUtil.fastSimpleUUID());
         adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
-        adRecordMapper.addOne(adRecord);
+        if (param.getLoginStatus() != null && AdRecordEnum.LOGIN_BEFORE.getCode().equals(param.getLoginStatus())) {
+            adRecordMapper.addOneVisitor(adRecord);
+        } else {
+            adRecordMapper.addOne(adRecord);
+        }
         //修改用户信息, 广告次数+1  总收益 + revenue
         YtDyzUser dyzUser = new YtDyzUser();
         dyzUser.setUserId(user.getUserId());
         dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo())?1:(user.getTotalVideo()+1));
         dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
         appUserMapper.updateUser(dyzUser);
-
         return adRecord.getRecordId();
     }
 
     @Override
     public List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds) {
-        return adRecordMapper.selectRecordByIds(adRecordIds);
+        return adRecordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
     }
+
 }

+ 17 - 2
yt-adage/adage-service/src/main/java/com/ytpm/adage/service/impl/AppUserServiceImpl.java

@@ -53,8 +53,23 @@ public class AppUserServiceImpl implements AppUserService {
     @Override
     @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
-        //处理用户注册或登录更新信息
+        //处理微信用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);
@@ -72,7 +87,7 @@ public class AppUserServiceImpl implements AppUserService {
      */
     private void setExtInfo(YtDyzUser old, String headimgurl) {
         old.setHeadImg(headimgurl);
-            old.setLastQuestionId(questionMapper.getLastQuestionId(old.getUserId()));
+        old.setLastQuestionId(questionMapper.getLastQuestionId(old.getUserId()));
         old.setTodayAnswerCount(questionMapper.getAnswerCount(old.getUserId(),1));
         old.setHistoryAnswerCount(questionMapper.getAnswerCount(old.getUserId(),2));
         old.setAnswerRecordList(questionMapper.getAnswerRecords(old.getUserId()));

+ 2 - 0
yt-adage/adage-service/src/main/java/com/ytpm/adage/service/impl/VisitorLoginServiceImpl.java

@@ -10,6 +10,7 @@ import com.ytpm.adage.dao.LoginRecordMapper;
 import com.ytpm.adage.dao.QuestionMapper;
 import com.ytpm.adage.redis.RedisService;
 import com.ytpm.adage.service.AdService;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzLoginRecord;
@@ -188,6 +189,7 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
                 adRecordParam.setUserId(ytDyzUser.getUserId());
                 adRecordParam.setNickName(ytDyzUser.getNickName());
                 adRecordParam.setAppId(ytDyzUser.getAppId());
+                adRecordParam.setLoginStatus(AdRecordEnum.LOGIN_BEFORE.getCode());
                 String recordId = adService.saveRecordAndChangeUser(adRecordParam, ytDyzUser);
                 adRecordIds.add(recordId);
             }

+ 108 - 62
yt-adage/adage-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -5,46 +5,86 @@
     <insert id="addOne">
         insert into yt_dyz_ad_record
         (
-         record_id,
-         user_id,
-         nick_name,
-         placement_id,
-         ad_source_id,
-         revenue,
-         network_form_id,
-         network_name,
-         network_placement_id,
-         begin_time,
-         finish_time,
-         result_json,
-         ad_source_index,
-         ad_source_type,
-         ecpm,
-         app_id
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
         values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
+    </insert>
+    <insert id="addOneVisitor">
+        insert into yt_dyz_ad_record_visitor
         (
-         #{recordId},
-         #{userId},
-         #{nickName},
-         #{placementId},
-         #{adSourceId},
-         #{revenue},
-         #{networkFormId},
-         #{networkName},
-         #{networkPlacementId},
-         ifnull(#{beginTime}, now()),
-         ifnull(#{finishTime}, now()),
-         #{resultJson},
-         #{adSourceIndex},
-         #{adSourceType},
-         #{ecpm},
-         #{appId}
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
+        values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
     </insert>
     <select id="countByAppIds" resultType="java.lang.Integer">
         select
-            count(record_id)
+        count(record_id)
         from yt_dyz_ad_record
         where ad_source_type = 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -53,48 +93,48 @@
     </select>
     <select id="getByUserId" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id = #{userId}
-          <if test="adsourceType != null and adsourceType!=888">
-              and ad_source_type = #{adsourceType}
-          </if>
+        <if test="adsourceType != null and adsourceType!=888">
+            and ad_source_type = #{adsourceType}
+        </if>
         order by finish_time desc
     </select>
     <select id="getByUserIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id in
-              <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
-                  #{item}
-              </foreach>
+        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
+            #{item}
+        </foreach>
         order by finish_time
     </select>
     <select id="getHourRevenue" resultType="com.ytpm.middle.view.AppRevenueHourVO">
         SELECT
-            HOUR(finish_time) `hour`,
-            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
-            sum( revenue ) revenue
+        HOUR(finish_time) `hour`,
+        DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
+        sum( revenue ) revenue
         FROM
-            yt_dyz_ad_record
+        yt_dyz_ad_record
         WHERE
-            app_id = #{appId}
-            <if test="type != null and type ==1">
-                and DATE(finish_time) = DATE(now())
-            </if>
-            <if test="type != null and type ==2">
-                and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
-            </if>
-            <if test="type != null and type ==3">
-                and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
-            </if>
+        app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(finish_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
         GROUP BY
-            `hour`
+        `hour`
     </select>
     <select id="getRevenueByTime" resultType="java.math.BigDecimal">
         select
-            sum(ar.revenue)
+        sum(ar.revenue)
         from yt_dyz_ad_record ar
         join yt_dyz_user au on ar.user_id = au.user_id
         <where>
@@ -117,16 +157,16 @@
                 </foreach>
             </if>
             <if test="registryTimeBegin != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[>=]]> #{registryTimeBegin}
+                and au.registry_time <![CDATA[>=]]> #{registryTimeBegin}
             </if>
             <if test="registryTimeEnd != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[<=]]> #{registryTimeEnd}
+                and au.registry_time <![CDATA[<=]]> #{registryTimeEnd}
             </if>
         </where>
     </select>
     <select id="getTodayRecord" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
         from yt_dyz_ad_record
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -141,8 +181,14 @@
     </select>
     <select id="selectRecordByIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
-        from yt_dyz_ad_record
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index,
+        revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        <if test="loginStatus != null and loginStatus == 1">
+            from yt_dyz_ad_record_visitor
+        </if>
+        <if test="loginStatus == null or loginStatus != 1">
+            from yt_dyz_ad_record
+        </if>
         where record_id in <foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
     </select>
 </mapper>

+ 3 - 1
yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/controller/VisitorController.java

@@ -3,6 +3,7 @@ package com.ytpm.algebraic.controller;
 import com.ytpm.algebraic.dao.AppUserMapper;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.general.Result;
 import com.ytpm.handle.LoginServiceFactory;
@@ -34,10 +35,11 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 
+
     @ApiOperation("设备在指定时间内注册的渠道")
     @GetMapping("/getDitchCount")
     public int getDitchCount(@RequestParam("deviceId") String deviceId, @RequestParam("hours") Integer hours) {

+ 12 - 2
yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/dao/AdRecordMapper.java

@@ -9,16 +9,23 @@ import org.apache.ibatis.annotations.Param;
 import java.math.BigDecimal;
 import java.util.List;
 
+
 @Mapper
 public interface AdRecordMapper {
     /**
      * 新增广告记录
      */
     void addOne(YtDyzAdRecord adRecord);
+
+    /**
+     * 保存游客广告记录
+     */
+    void addOneVisitor(YtDyzAdRecord adRecord);
+
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
 
     /**
      * 查询激励视频记录
@@ -45,5 +52,8 @@ public interface AdRecordMapper {
      */
     List<YtDyzAdRecord> getTodayRecord(@Param("appIds")String appIds,@Param("firstDay")String firstDay,@Param("lastDay")String lastDay);
 
-    List<YtDyzAdRecord> selectRecordByIds(@Param("ids") List<String> adRecordIds);
+    /**
+     * 查询指定广告记录
+     */
+    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
 }

+ 8 - 2
yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/service/impl/AdServiceImpl.java

@@ -7,6 +7,7 @@ import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import com.ytpm.advertise.enums.AdPlatformTypeEnum;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
@@ -56,6 +57,7 @@ import java.util.stream.Collectors;
 @Service
 @RefreshScope
 public class AdServiceImpl implements AdService {
+
     @Autowired
     private AdRecordMapper adRecordMapper;
     @Autowired
@@ -313,7 +315,11 @@ public class AdServiceImpl implements AdService {
         BeanUtils.copyProperties(param, adRecord);
         adRecord.setRecordId(IdUtil.fastSimpleUUID());
         adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
-        adRecordMapper.addOne(adRecord);
+        if (param.getLoginStatus() != null && AdRecordEnum.LOGIN_BEFORE.getCode().equals(param.getLoginStatus())) {
+            adRecordMapper.addOneVisitor(adRecord);
+        } else {
+            adRecordMapper.addOne(adRecord);
+        }
         //修改用户信息, 广告次数+1  总收益 + revenue
         YtDyzUser dyzUser = new YtDyzUser();
         dyzUser.setUserId(user.getUserId());
@@ -325,7 +331,7 @@ public class AdServiceImpl implements AdService {
 
     @Override
     public List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds) {
-        return adRecordMapper.selectRecordByIds(adRecordIds);
+        return adRecordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
     }
 
 }

+ 15 - 0
yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 2 - 0
yt-algebraic/algebraic-service/src/main/java/com/ytpm/algebraic/service/impl/VisitorLoginServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.algebraic.dao.AppUserMapper;
 import com.ytpm.algebraic.dao.LoginRecordMapper;
 import com.ytpm.algebraic.dao.QuestionMapper;
@@ -188,6 +189,7 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
                 adRecordParam.setUserId(ytDyzUser.getUserId());
                 adRecordParam.setNickName(ytDyzUser.getNickName());
                 adRecordParam.setAppId(ytDyzUser.getAppId());
+                adRecordParam.setLoginStatus(AdRecordEnum.LOGIN_BEFORE.getCode());
                 String recordId = adService.saveRecordAndChangeUser(adRecordParam, ytDyzUser);
                 adRecordIds.add(recordId);
             }

+ 48 - 3
yt-algebraic/algebraic-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -42,6 +42,46 @@
                 #{appId}
             )
     </insert>
+    <insert id="addOneVisitor">
+        insert into yt_dyz_ad_record_visitor
+        (
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
+        )
+        values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
+    </insert>
     <select id="countByAppIds" resultType="java.lang.Integer">
         select
         count(record_id)
@@ -139,11 +179,16 @@
             and finish_time <![CDATA[<=]]> #{lastDay}
         </if>
     </select>
-
     <select id="selectRecordByIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
-        from yt_dyz_ad_record
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index,
+        revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        <if test="loginStatus != null and loginStatus == 1">
+            from yt_dyz_ad_record_visitor
+        </if>
+        <if test="loginStatus == null or loginStatus != 1">
+            from yt_dyz_ad_record
+        </if>
         where record_id in <foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
     </select>
 </mapper>

+ 2 - 1
yt-allusion/allusion-service/src/main/java/com/ytpm/allusion/controller/VisitorController.java

@@ -3,6 +3,7 @@ package com.ytpm.allusion.controller;
 import com.ytpm.allusion.dao.AppUserMapper;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.general.Result;
 import com.ytpm.handle.LoginServiceFactory;
@@ -34,7 +35,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 15 - 0
yt-allusion/allusion-service/src/main/java/com/ytpm/allusion/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 1 - 0
yt-answer/answer-service/pom.xml

@@ -44,6 +44,7 @@
         <dependency>
             <groupId>com.zaxxer</groupId>
             <artifactId>HikariCP</artifactId>
+            <version>${hikar-icp.version}</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 3 - 1
yt-answer/answer-service/src/main/java/com/ytpm/answer/config/interceptor/HttpInterceptor.java

@@ -1,5 +1,6 @@
 package com.ytpm.answer.config.interceptor;
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.ModelAndView;
@@ -8,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
 
+@Slf4j
 @Component
 public class HttpInterceptor implements HandlerInterceptor {
 
@@ -16,7 +18,7 @@ public class HttpInterceptor implements HandlerInterceptor {
                              HttpServletResponse response, Object obj) throws Exception {
         // 获取客户端IP地址
         String clientIp = getClientIp(request);
-        System.out.println("答题达人接收客户端" + clientIp + "发起用户请求");
+        log.error("答题达人接收客户端" + clientIp + "发起用户请求");
         // 可以在这里添加更多的逻辑,比如记录日志等
         return true;
     }

+ 14 - 0
yt-answer/answer-service/src/main/java/com/ytpm/answer/controller/UserController.java

@@ -2,6 +2,7 @@ package com.ytpm.answer.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
 import com.github.pagehelper.PageInfo;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
@@ -23,9 +24,11 @@ import com.ytpm.app.param.AppUserTodayBannedParam;
 import com.ytpm.app.param.YtAppUserListParam;
 import com.ytpm.app.view.HourCountView;
 import com.ytpm.app.view.YtAppUserListView;
+import com.ytpm.feign.RiskFeign;
 import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
+import com.ytpm.general.StatusCode;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import com.ytpm.risk.view.RiskConfigView;
 import com.ytpm.risk.view.RiskTemplateView;
@@ -66,6 +69,8 @@ public class UserController {
     @Autowired
     private RedisService redisService;
 
+    @Autowired
+    private RiskFeign riskFeign;
     /**
      * 根据应用ID查询当月注册用户
      */
@@ -167,6 +172,15 @@ public class UserController {
         user.setTodayAnswerCount(questionMapper.getAnswerCount(userId,1));
         user.setHistoryAnswerCount(questionMapper.getAnswerCount(userId,2));
         user.setAnswerRecordList(questionMapper.getAnswerRecords(userId));
+        Result<?> result = riskFeign.checkAdRisk(user);
+        if (result != null) {
+            user.setIfPowerLimit(false);
+            if (result.getCode() != 200) {
+                if ("766".equals(result.getMessage()) || result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotEmpty(result.getMessage())) {
+                    user.setIfPowerLimit(true);
+                }
+            }
+        }
         return Result.resultObjOk(user);
     }
 

+ 2 - 1
yt-answer/answer-service/src/main/java/com/ytpm/answer/controller/VisitorController.java

@@ -3,6 +3,7 @@ package com.ytpm.answer.controller;
 import com.ytpm.answer.dao.AppUserMapper;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.general.Result;
 import com.ytpm.handle.LoginServiceFactory;
@@ -34,7 +35,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 2 - 0
yt-answer/answer-service/src/main/java/com/ytpm/answer/controller/WxController.java

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSON;
 import com.ytpm.answer.dao.AppUserMapper;
 import com.ytpm.answer.service.AppUserService;
 import com.ytpm.app.enums.AppTypeEnums;
+import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtAppDefaultConfig;
 import com.ytpm.app.model.YtDyzPowerRecord;
 import com.ytpm.app.model.YtDyzUser;
@@ -72,6 +73,7 @@ public class WxController {
         }
         param.setLoginIp(getClientIp(request));
         YtDyzUser old = appUserService.crudForNewTrans(param,wxUserInfo,loginResult);
+        old.setLoginType(LoginType.WX);
         //调用风控服务校验默认风控配置
         old.setRiskCode("313");
         Result<?> result = riskFeign.checkRisk(old);

+ 12 - 1
yt-answer/answer-service/src/main/java/com/ytpm/answer/dao/AdRecordMapper.java

@@ -15,10 +15,16 @@ public interface AdRecordMapper {
      * 新增广告记录
      */
     void addOne(YtDyzAdRecord adRecord);
+
+    /**
+     * 保存游客广告记录
+     */
+    void addOneVisitor(YtDyzAdRecord adRecord);
+
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
 
     /**
      * 查询激励视频记录
@@ -44,4 +50,9 @@ public interface AdRecordMapper {
      * 查询今日广告
      */
     List<YtDyzAdRecord> getTodayRecord(@Param("appIds")String appIds,@Param("firstDay")String firstDay,@Param("lastDay")String lastDay);
+
+    /**
+     * 查询指定广告记录
+     */
+    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
 }

+ 2 - 0
yt-answer/answer-service/src/main/java/com/ytpm/answer/dao/AppUserMapper.java

@@ -90,6 +90,8 @@ public interface AppUserMapper {
      */
     WxDefaultConfig getDefaultConfig(@Param("appType") int appType);
 
+    WxDefaultConfig getDefaultConfigByAppId(@Param("appId") String appId);
+
     /**
      * 根据微信openid查询用户
      */

+ 8 - 3
yt-answer/answer-service/src/main/java/com/ytpm/answer/monitor/RedisKeyExpirationListener.java

@@ -6,6 +6,7 @@ import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.feign.RiskFeign;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.data.redis.connection.Message;
 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
@@ -28,7 +29,8 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
     private AppUserMapper appUserMapper;
     @Resource
     private RiskFeign riskFeign;
-
+    @Value("${spring.application.name:}")
+    private String applicationName;
     /**
      * Creates new {@link } for {@code __keyevent@*__:expired} messages.
      *
@@ -43,8 +45,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
      */
     @Override
     public void onMessage(Message message, byte[] pattern) {
-        String key = String.valueOf(message);
-        log.error("App-Service 发现预定风控用户:{}",key);
+       String key = String.valueOf(message);
+//        log.error("App-Service 发现预定风控用户:{}",key);
+        //        if (!key.endsWith(applicationName)) {
+//            return;
+//        }
         if(key.startsWith("lock_")){
             String[] arr = key.split("_");
             lockUser(arr[1], UserStatusEnum.RISK.getCode());

+ 6 - 0
yt-answer/answer-service/src/main/java/com/ytpm/answer/service/AdService.java

@@ -2,6 +2,8 @@ package com.ytpm.answer.service;
 
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
+import com.ytpm.app.model.YtDyzAdRecord;
+import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.general.Result;
 import com.ytpm.middle.view.DashboardRankingListVO;
@@ -46,4 +48,8 @@ public interface AdService {
      * 查询代理商首页广告数据统计
      */
     List<AgentAdGroupStaticsVO> getAgentProfit(String appIds);
+
+    String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user);
+
+    List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds);
 }

+ 37 - 7
yt-answer/answer-service/src/main/java/com/ytpm/answer/service/impl/AdServiceImpl.java

@@ -4,8 +4,10 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import com.ytpm.advertise.enums.AdPlatformTypeEnum;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
@@ -15,6 +17,7 @@ import com.ytpm.answer.service.AdService;
 import com.ytpm.app.model.YtDyzAdRecord;
 import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
+import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.feign.RiskFeign;
 import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
@@ -27,6 +30,7 @@ import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
 import com.ytpm.middle.view.DashboardRiskVO;
 import com.ytpm.middle.view.UserRankingListVO;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -49,6 +53,7 @@ import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Service
 @RefreshScope
 public class AdServiceImpl implements AdService {
@@ -62,6 +67,7 @@ public class AdServiceImpl implements AdService {
     private String tips;
     @Autowired
     private RiskFeign riskFeign;
+
     /**
      * 保存广告记录
      */
@@ -69,6 +75,7 @@ public class AdServiceImpl implements AdService {
     @Transactional(rollbackFor = Exception.class)
     public Result<?> saveRecord(DyzAdRecordParam param) {
         YtDyzUser user = appUserMapper.selectPrimaryKey(param.getUserId());
+        log.error(StrUtil.format("[saveRecord]:{} ", param.getBeginTime()));
         if(Objects.isNull(user)){
             return Result.resultOk(RepMessage.SAVE_SUCCESS);
         }
@@ -78,9 +85,22 @@ public class AdServiceImpl implements AdService {
         saveRecordAndChangeUser(param, user);
         //调用风控广告校验
         if(AdSourceTypeEnum.rewarded_video.getAdSourceType() == param.getAdSourceType()){
+            WxDefaultConfig config = appUserMapper.getDefaultConfigByAppId(user.getAppId());
+            String format = StrUtil.emptyToDefault(config.getTaskLimitTip(), "当前设备完成任务次数过多,请{}后重试!");
+            user.setPowerLimitTip(format);
             Result<?> result = riskFeign.checkAdRisk(user);
-            if(result.getCode()!=200){
-                return new Result<>(StatusCode.ACCESS_ERR,result.getMessage());
+            if (result.getCode() != 200) {
+                Result<Object> resultObj = new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+                // 766处理
+                if("766".contains(result.getMessage())){
+                    resultObj.setData(result.getMessage());
+                }
+                else if (result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotBlank(result.getMessage())) {
+                    // 体力不再获取处理
+                    resultObj.setMessage(result.getMessage());
+                    resultObj.setData("767");
+                }
+                return resultObj;
             }
         }
         return Result.resultOk(RepMessage.SAVE_SUCCESS);
@@ -232,17 +252,15 @@ public class AdServiceImpl implements AdService {
         cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),actualMaximum,23,59,59);
         String lastDay = sdf.format(cal.getTime());
         List<YtDyzAdRecord> dyzMonthRecords = adRecordMapper.getTodayRecord(appIds,firstDay,lastDay);
-
         if(CollUtil.isNotEmpty(dyzMonthRecords)){monthRecords.addAll(dyzMonthRecords);}
         records = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),new Date())).collect(Collectors.toList());
 
-        cal = Calendar.getInstance();
+        cal = Calendar.getInstance(); // 获取当前日期时间
         cal.add(Calendar.DATE, -1); // 昨天的日期时间
         Date yest = cal.getTime();
         yestRecords = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),yest)).collect(Collectors.toList());
-
         //广告平台分组
         Map<String, List<YtDyzAdRecord>> networkMap = records.stream().collect(
                 Collectors.groupingBy(YtDyzAdRecord::getNetworkFormId));
@@ -287,7 +305,8 @@ public class AdServiceImpl implements AdService {
      *  始终创建新的事务以保障子方法的独立事务
      */
 //    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
-    public void saveRecordAndChangeUser(DyzAdRecordParam param,YtDyzUser user) {
+    @Override
+    public String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user) {
         //增加广告记录
         YtDyzAdRecord adRecord = new YtDyzAdRecord();
         if(Objects.isNull(param.getBeginTime())){
@@ -296,12 +315,23 @@ public class AdServiceImpl implements AdService {
         BeanUtils.copyProperties(param, adRecord);
         adRecord.setRecordId(IdUtil.fastSimpleUUID());
         adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
-        adRecordMapper.addOne(adRecord);
+        if (param.getLoginStatus() != null && AdRecordEnum.LOGIN_BEFORE.getCode().equals(param.getLoginStatus())) {
+            adRecordMapper.addOneVisitor(adRecord);
+        } else {
+            adRecordMapper.addOne(adRecord);
+        }
         //修改用户信息, 广告次数+1  总收益 + revenue
         YtDyzUser dyzUser = new YtDyzUser();
         dyzUser.setUserId(user.getUserId());
         dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo())?1:(user.getTotalVideo()+1));
         dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
         appUserMapper.updateUser(dyzUser);
+        return adRecord.getRecordId();
     }
+
+    @Override
+    public List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds) {
+        return adRecordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
+    }
+
 }

+ 15 - 0
yt-answer/answer-service/src/main/java/com/ytpm/answer/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 50 - 5
yt-answer/answer-service/src/main/java/com/ytpm/answer/service/impl/VisitorLoginServiceImpl.java

@@ -1,30 +1,38 @@
 package com.ytpm.answer.service.impl;
 
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.answer.dao.AppUserMapper;
 import com.ytpm.answer.dao.LoginRecordMapper;
 import com.ytpm.answer.dao.QuestionMapper;
 import com.ytpm.answer.redis.RedisService;
+import com.ytpm.answer.service.AdService;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzLoginRecord;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.app.param.LoginParam;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.constant.StrConstant;
 import com.ytpm.feign.RiskFeign;
+import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.handle.AbstractLoginService;
 import com.ytpm.handle.CommonException;
+import com.ytpm.handle.CustomerException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -48,6 +56,8 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
     private RiskFeign riskFeign;
     @Autowired
     private RedisService redisService;
+    @Autowired
+    private AdService adService;
 
     @Override
     protected WxDefaultConfig getLoginConfig(Integer appType) {
@@ -67,6 +77,20 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         return LoginType.VISITOR;
     }
 
+    @Override
+    protected void updateUserStatus(YtDyzUser ytDyzUser, UserStatusEnum statusEnum, String reason) {
+        if (ytDyzUser != null) {
+            YtDyzUser newUser = new YtDyzUser();
+            newUser.setUserId(ytDyzUser.getUserId());
+            newUser.setUserStatus(statusEnum.getCode());
+            newUser.setRiskReason(reason);
+            if(UserStatusEnum.NORMAL == statusEnum){
+                newUser.setRiskReason("");
+            }
+            appUserMapper.updateUser(newUser);
+        }
+    }
+
     @Override
     protected void validateParams(LoginParam loginParam, HttpServletRequest request) {
 
@@ -142,6 +166,7 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
      */
     @Override
     protected void setExtInfo(YtDyzUser old, Map<String, Object> paramMap) {
+        super.setExtInfo(old, paramMap);
         old.setLastQuestionId(questionMapper.getLastQuestionId(old.getUserId()));
         old.setTodayAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 1));
         old.setHistoryAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 2));
@@ -149,10 +174,30 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         old.setLoginRecordList(loginRecordMapper.getLoginRecords(old.getUserId()));
     }
 
-    @Override
-    protected void beforeDeadWithUserCrud(LoginParam loginParam, YtDyzUser ytDyzUser, Map<String, Object> paramMap) {
-        super.beforeDeadWithUserCrud(loginParam, ytDyzUser, paramMap);
-        // 新增风控 相关广告源记录 ecpm  和预估收益 小于 各自 阈值,登陆返回 301
 
+    // 仅保存登陆时的三条广告信息 并传入登陆实体用于后续 risk风控校验
+    protected void saveVisitorAdRecord(YtDyzUser ytDyzUser, LoginParam loginParam, WxDefaultConfig defaultConfig) {
+        super.saveVisitorAdRecord(ytDyzUser, loginParam, defaultConfig);
+        VisitorLoginParam visitorLoginParam = (VisitorLoginParam) loginParam;
+        List<DyzAdRecordParam> preAdList = visitorLoginParam.getPreAdList();
+        List<String> adRecordIds = new ArrayList<>();
+        if (CollUtil.isNotEmpty(preAdList)) {
+            for (DyzAdRecordParam adRecordParam : preAdList) {
+                if (adRecordParam == null) {
+                    continue;
+                }
+                adRecordParam.setUserId(ytDyzUser.getUserId());
+                adRecordParam.setNickName(ytDyzUser.getNickName());
+                adRecordParam.setAppId(ytDyzUser.getAppId());
+                adRecordParam.setLoginStatus(AdRecordEnum.LOGIN_BEFORE.getCode());
+                String recordId = adService.saveRecordAndChangeUser(adRecordParam, ytDyzUser);
+                adRecordIds.add(recordId);
+            }
+        }
+        if(CollUtil.isEmpty(adRecordIds)) {
+            throw new CustomerException(StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), RepMessage.RISK_VISITOR_LOWER_VALUE));
+        }
+        ytDyzUser.setPreAdRecordList(adService.queryRecordByIds(adRecordIds));
     }
-}
+
+}

+ 112 - 60
yt-answer/answer-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -5,46 +5,86 @@
     <insert id="addOne">
         insert into yt_dyz_ad_record
         (
-         record_id,
-         user_id,
-         nick_name,
-         placement_id,
-         ad_source_id,
-         revenue,
-         network_form_id,
-         network_name,
-         network_placement_id,
-         begin_time,
-         finish_time,
-         result_json,
-         ad_source_index,
-         ad_source_type,
-         ecpm,
-         app_id
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
         values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
+    </insert>
+    <insert id="addOneVisitor">
+        insert into yt_dyz_ad_record_visitor
         (
-         #{recordId},
-         #{userId},
-         #{nickName},
-         #{placementId},
-         #{adSourceId},
-         #{revenue},
-         #{networkFormId},
-         #{networkName},
-         #{networkPlacementId},
-         ifnull(#{beginTime}, now()),
-         ifnull(#{finishTime}, now()),
-         #{resultJson},
-         #{adSourceIndex},
-         #{adSourceType},
-         #{ecpm},
-         #{appId}
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
+        values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
     </insert>
     <select id="countByAppIds" resultType="java.lang.Integer">
         select
-            count(record_id)
+        count(record_id)
         from yt_dyz_ad_record
         where ad_source_type = 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -53,48 +93,48 @@
     </select>
     <select id="getByUserId" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id = #{userId}
-          <if test="adsourceType != null and adsourceType!=888">
-              and ad_source_type = #{adsourceType}
-          </if>
+        <if test="adsourceType != null and adsourceType!=888">
+            and ad_source_type = #{adsourceType}
+        </if>
         order by finish_time desc
     </select>
     <select id="getByUserIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id in
-              <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
-                  #{item}
-              </foreach>
+        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
+            #{item}
+        </foreach>
         order by finish_time
     </select>
     <select id="getHourRevenue" resultType="com.ytpm.middle.view.AppRevenueHourVO">
         SELECT
-            HOUR(finish_time) `hour`,
-            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
-            sum( revenue ) revenue
+        HOUR(finish_time) `hour`,
+        DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
+        sum( revenue ) revenue
         FROM
-            yt_dyz_ad_record
+        yt_dyz_ad_record
         WHERE
-            app_id = #{appId}
-            <if test="type != null and type ==1">
-                and DATE(finish_time) = DATE(now())
-            </if>
-            <if test="type != null and type ==2">
-                and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
-            </if>
-            <if test="type != null and type ==3">
-                and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
-            </if>
+        app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(finish_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
         GROUP BY
-            `hour`
+        `hour`
     </select>
     <select id="getRevenueByTime" resultType="java.math.BigDecimal">
         select
-            sum(ar.revenue)
+        sum(ar.revenue)
         from yt_dyz_ad_record ar
         join yt_dyz_user au on ar.user_id = au.user_id
         <where>
@@ -117,16 +157,16 @@
                 </foreach>
             </if>
             <if test="registryTimeBegin != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[>=]]> #{registryTimeBegin}
+                and au.registry_time <![CDATA[>=]]> #{registryTimeBegin}
             </if>
             <if test="registryTimeEnd != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[<=]]> #{registryTimeEnd}
+                and au.registry_time <![CDATA[<=]]> #{registryTimeEnd}
             </if>
         </where>
     </select>
     <select id="getTodayRecord" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
         from yt_dyz_ad_record
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -139,4 +179,16 @@
             and finish_time <![CDATA[<=]]> #{lastDay}
         </if>
     </select>
+    <select id="selectRecordByIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
+        select
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index,
+        revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        <if test="loginStatus != null and loginStatus == 1">
+            from yt_dyz_ad_record_visitor
+        </if>
+        <if test="loginStatus == null or loginStatus != 1">
+            from yt_dyz_ad_record
+        </if>
+        where record_id in <foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
+    </select>
 </mapper>

+ 174 - 136
yt-answer/answer-service/src/main/resources/mapper/AppUserMapper.xml

@@ -4,70 +4,70 @@
     <insert id="addOne" parameterType="com.ytpm.app.model.YtDyzUser">
         insert into yt_dyz_user
         (
-         user_id,
-         nick_name,
-         head_img,
-         registry_time,
-         last_login_time,
-         last_login_ip,
-         login_days,
-         total_video,
-         total_income,
-         red_packet_balance,
-         red_packet_amount,
-         points_balance,
-         points_total,
-         withdraw_total,
-         sign_days,
-         user_status,
-         risk_reason,
-         wx_open_id,
-         ditch_id,
-         platform_id,
-         app_id,
-         power,
-         phone,
-         phone_json,
-         device_id
+            user_id,
+            nick_name,
+            head_img,
+            registry_time,
+            last_login_time,
+            last_login_ip,
+            login_days,
+            total_video,
+            total_income,
+            red_packet_balance,
+            red_packet_amount,
+            points_balance,
+            points_total,
+            withdraw_total,
+            sign_days,
+            user_status,
+            risk_reason,
+            wx_open_id,
+            ditch_id,
+            platform_id,
+            app_id,
+            power,
+            phone,
+            phone_json,
+            device_id
         )
         values
-        (
-         #{userId},
-         #{nickName},
-         #{headImg},
-         #{registryTime},
-         #{lastLoginTime},
-         #{lastLoginIp},
-         #{loginDays},
-         #{totalVideo},
-         #{totalIncome},
-         #{redPacketBalance},
-         #{redPacketAmount},
-         #{pointsBalance},
-         #{pointsTotal},
-         #{withdrawTotal},
-         #{signDays},
-         #{userStatus},
-         #{riskReason},
-         #{wxOpenId},
-         #{ditchId},
-         #{platformId},
-         #{appId},
-         #{power},
-         #{phone},
-         #{phoneJson},
-         #{deviceId}
-        )
+            (
+                #{userId},
+                #{nickName},
+                #{headImg},
+                #{registryTime},
+                #{lastLoginTime},
+                #{lastLoginIp},
+                #{loginDays},
+                #{totalVideo},
+                #{totalIncome},
+                #{redPacketBalance},
+                #{redPacketAmount},
+                #{pointsBalance},
+                #{pointsTotal},
+                #{withdrawTotal},
+                #{signDays},
+                #{userStatus},
+                #{riskReason},
+                #{wxOpenId},
+                #{ditchId},
+                #{platformId},
+                #{appId},
+                #{power},
+                #{phone},
+                #{phoneJson},
+                #{deviceId}
+            )
     </insert>
     <insert id="addPowerRecord">
         insert into yt_dyz_power_record
         (
-         record_id, user_id, type, remark, add_time
+            record_id, user_id, type, remark, add_time
         )
         values
-        (
-         #{recordId},#{userId},#{type},#{remark},#{addTime}
-        )
+            (
+                #{recordId},#{userId},#{type},#{remark},#{addTime}
+            )
     </insert>
     <insert id="saveAppConfig">
         insert into yt_app_default_config
@@ -151,6 +151,24 @@
             <if test="interstitialIntervalTime != null">
                 interstitial_interval_time = #{interstitialIntervalTime}
             </if>
+            <if test="flowIntervalTime != null">
+                flow_interval_time = #{flowIntervalTime}
+            </if>
+            <if test="taskLimitTip != null">
+                task_limit_tip = #{taskLimitTip}
+            </if>
+            <if test="lowValueTip != null">
+                low_value_tip = #{lowValueTip}
+            </if>
+            <if test="brushTip != null">
+                brush_tip = #{brushTip}
+            </if>
+            <if test="startWaitTime != null">
+                start_wait_time = #{startWaitTime}
+            </if>
+            <if test="canCacheVideo != null">
+                can_cache_video = #{canCacheVideo}
+            </if>
         </set>
         where app_id = #{appId}
     </update>
@@ -234,14 +252,14 @@
     </delete>
     <select id="getYtAppUser" resultType="com.ytpm.app.model.YtDyzUser">
         select
-           user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+            user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where wx_open_id = #{openid}
-        and ditch_id = #{ditchId}
+          and ditch_id = #{ditchId}
     </select>
     <select id="queryAll" resultType="com.ytpm.app.view.YtAppUserListView">
         select
-            user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+        user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where 1 = 1
         <if test="userId != null and userId !=''">
@@ -270,9 +288,9 @@
         </if>
         <if test="appIds != null and appIds != ''">
             and app_id in
-                <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
-                    #{item}
-                </foreach>
+            <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
+                #{item}
+            </foreach>
         </if>
         order by user_id desc
     </select>
@@ -320,37 +338,37 @@
     </resultMap>
     <select id="getUserList" resultMap="UserMap">
         select
-            du.user_id,
-            du.head_img,
-            du.nick_name,
-            du.phone,
-            du.device_id,
-            du.registry_time,
-            du.last_login_time,
-            du.last_login_ip,
-            du.login_days,
-            du.total_video,
-            du.total_income,
-            du.red_packet_balance,
-            du.red_packet_amount,
-            du.points_balance,
-            du.points_total,
-            du.withdraw_total,
-            du.sign_days,
-            du.user_status,
-            du.risk_reason,
-            du.wx_open_id,
-            du.ditch_id,
-            du.app_id,
-            du.platform_id,
-            du.power,
-            lr.record_id,
-            lr.login_time,
-            lr.device_brand,
-            lr. device_model,
-            lr.login_ip,
-            lr.operator,
-            lr.ip_addr
+        du.user_id,
+        du.head_img,
+        du.nick_name,
+        du.phone,
+        du.device_id,
+        du.registry_time,
+        du.last_login_time,
+        du.last_login_ip,
+        du.login_days,
+        du.total_video,
+        du.total_income,
+        du.red_packet_balance,
+        du.red_packet_amount,
+        du.points_balance,
+        du.points_total,
+        du.withdraw_total,
+        du.sign_days,
+        du.user_status,
+        du.risk_reason,
+        du.wx_open_id,
+        du.ditch_id,
+        du.app_id,
+        du.platform_id,
+        du.power,
+        lr.record_id,
+        lr.login_time,
+        lr.device_brand,
+        lr. device_model,
+        lr.login_ip,
+        lr.operator,
+        lr.ip_addr
         from yt_dyz_user du
         left join yt_dyz_login_record lr on du.user_id = lr.user_id
         <where>
@@ -430,14 +448,32 @@
     </select>
     <select id="getDefaultConfig" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id appId, secret, app_id platformAppId, app_key platformAppSecret, app_type,user_path,login_path,ad_path,answer_path,power_path
-                     ,can_simulator,taku_app_id,taku_key,taku_banner_pid,taku_interstitial_pid,taku_reward_pid,taku_native_pid,can_use_adb,can_accumulation,can_use_float,can_use_root,ditch_id,power_wait_time,interstitial_interval_time
+            config_id, config_name, open_id as app_id, secret, app_id as platformAppId, app_key as platformAppSecret,
+            app_type,user_path, login_path,ad_path,answer_path,power_path,can_simulator,
+            taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid,
+            can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_type = #{appType}
     </select>
+    <select id="getDefaultConfigByAppId" resultType="com.ytpm.app.view.WxDefaultConfig">
+        select
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
+        from yt_app_default_config
+        where app_id = #{appId}
+    </select>
     <select id="getSecretByAppId" resultType="java.lang.String">
         select
-           secret
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id = #{appId}
     </select>
@@ -452,13 +488,16 @@
             platform_id
         from yt_dyz_user
         where device_id = #{deviceId}
-        and wx_open_id = #{openid}
+          and wx_open_id = #{openid}
         limit 1
     </select>
     <select id="getConfigByIds" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,answer_path,power_path
-        ,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation, ditch_id, power_wait_time, interstitial_interval_time
+        config_id, config_name, open_id, secret, app_id, app_key, app_type, user_path, login_path, ad_path,
+        answer_path, power_path,taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid,
+        taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,can_simulator,
+        ditch_id, power_wait_time, interstitial_interval_time,
+        low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id in
         <foreach collection="appIds.split(',')" item="item" separator="," open="(" close=")">
@@ -467,7 +506,7 @@
     </select>
     <select id="getAdCount" resultType="java.lang.Integer">
         select
-            sum(total_video)
+        sum(total_video)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -485,11 +524,11 @@
     </select>
     <select id="getAppRanking" resultType="com.ytpm.middle.view.AppRankingListVO">
         SELECT
-            u.app_id,
-            sum( ar.revenue ) totalRevenue
+        u.app_id,
+        sum( ar.revenue ) totalRevenue
         FROM
-            yt_dyz_ad_record ar
-            JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -506,21 +545,21 @@
             </if>
         </where>
         GROUP BY
-            u.app_id
+        u.app_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         LIMIT #{limit}
     </select>
     <select id="getUserRanking" resultType="com.ytpm.middle.view.UserRankingListVO">
         SELECT
-            u.user_id,
-            u.nick_name,
-            u.head_img,
-            u.total_video,
-            sum( ar.revenue ) totalIncome
+        u.user_id,
+        u.nick_name,
+        u.head_img,
+        u.total_video,
+        sum( ar.revenue ) totalIncome
         FROM
-            yt_dyz_ad_record ar
-                JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -538,12 +577,12 @@
         </where>
         GROUP BY ar.user_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         limit #{limit}
     </select>
     <select id="countUserByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -552,7 +591,7 @@
     </select>
     <select id="countRevenueByAppIds" resultType="java.math.BigDecimal">
         select
-            sum(total_income)
+        sum(total_income)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -561,7 +600,7 @@
     </select>
     <select id="countBannedByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where user_status > 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -600,8 +639,8 @@
     </select>
     <select id="countRegistryHour" resultType="com.ytpm.middle.view.AppUserHourVO">
         select
-            DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
-            count(user_id) `count`
+        DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
+        count(user_id) `count`
         from yt_dyz_user
         where app_id = #{appId}
         <if test="type != null and type ==1">
@@ -634,7 +673,7 @@
     </select>
     <select id="queryByUserIds" resultType="com.ytpm.app.model.YtDyzUser">
         select
-            user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
+        user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
         from yt_dyz_user
         where user_id in
         <foreach collection="userIds.split(',')" separator="," item="item"  open="(" close=")">
@@ -662,21 +701,21 @@
     </resultMap>
     <select id="queryTodayUserAd" resultMap="UserAdMap">
         select
-            u.user_id,
-            u.app_id,
-            u.nick_name,
-            ar.record_id,
-            ar.placement_id,
-            ar.ad_source_id,
-            ar.ad_source_type,
-            ar.ad_source_index,
-            ar.revenue,
-            ar.ecpm,
-            ar.network_form_id,
-            ar.network_name,
-            ar.network_placement_id,
-            ar.finish_time,
-            ar.begin_time
+        u.user_id,
+        u.app_id,
+        u.nick_name,
+        ar.record_id,
+        ar.placement_id,
+        ar.ad_source_id,
+        ar.ad_source_type,
+        ar.ad_source_index,
+        ar.revenue,
+        ar.ecpm,
+        ar.network_form_id,
+        ar.network_name,
+        ar.network_placement_id,
+        ar.finish_time,
+        ar.begin_time
         from yt_dyz_ad_record ar
         join yt_dyz_user u on ar.user_id = u.user_id
         where ar.ad_source_type = #{adSourceType} and ar.app_id = #{appId} and ar.user_id in
@@ -700,7 +739,6 @@
             and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(now(),'%Y-%m')
         </if>
     </select>
-
     <select id="countDitch" resultType="java.lang.Integer">
         select
             count( distinct ditch_id)

+ 22 - 20
yt-answer/answer-service/src/main/resources/mapper/LoginRecordMapper.xml

@@ -5,28 +5,30 @@
     <insert id="insertOne" parameterType="com.ytpm.app.model.YtDyzLoginRecord">
         insert into yt_dyz_login_record
         (
-         record_id,
-         user_id,
-         login_time,
-         device_brand,
-         device_model,
-         login_ip,
-         operator,
-         ip_addr,
-         phone_json
+            record_id,
+            user_id,
+            login_time,
+            device_brand,
+            device_model,
+            login_ip,
+            operator,
+            ip_addr,
+            phone_json,
+            login_type
         )
         values
-        (
-         #{recordId},
-         #{userId},
-         #{loginTime},
-         #{deviceBrand},
-         #{deviceModel},
-         #{loginIp},
-         #{operator},
-         #{ipAddr},
-         #{phoneJson}
-         );
+            (
+                #{recordId},
+                #{userId},
+                #{loginTime},
+                #{deviceBrand},
+                #{deviceModel},
+                #{loginIp},
+                #{operator},
+                #{ipAddr},
+                #{phoneJson},
+                #{loginType}
+            );
     </insert>
     <select id="getLoginRecords" resultType="com.ytpm.app.model.YtDyzLoginRecord">
         select

+ 1 - 0
yt-arena/arena-service/pom.xml

@@ -46,6 +46,7 @@
         <dependency>
             <groupId>com.zaxxer</groupId>
             <artifactId>HikariCP</artifactId>
+            <version>${hikar-icp.version}</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 3 - 1
yt-arena/arena-service/src/main/java/com/ytpm/arena/config/interceptor/HttpInterceptor.java

@@ -1,5 +1,6 @@
 package com.ytpm.arena.config.interceptor;
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.ModelAndView;
@@ -8,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
 
+@Slf4j
 @Component
 public class HttpInterceptor implements HandlerInterceptor {
 
@@ -16,7 +18,7 @@ public class HttpInterceptor implements HandlerInterceptor {
                              HttpServletResponse response, Object obj) throws Exception {
         // 获取客户端IP地址
         String clientIp = getClientIp(request);
-        System.out.println("歇后语擂台接收客户端" + clientIp + "发起用户请求");
+        log.error("歇后语擂台接收客户端" + clientIp + "发起用户请求");
         // 可以在这里添加更多的逻辑,比如记录日志等
         return true;
     }

+ 16 - 0
yt-arena/arena-service/src/main/java/com/ytpm/arena/controller/UserController.java

@@ -2,6 +2,7 @@ package com.ytpm.arena.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
 import com.github.pagehelper.PageInfo;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
@@ -14,6 +15,7 @@ import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.*;
 import com.ytpm.app.view.HourCountView;
 import com.ytpm.app.view.YtAppUserListView;
+import com.ytpm.feign.RiskFeign;
 import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
@@ -22,6 +24,7 @@ import com.ytpm.arena.dao.AppUserMapper;
 import com.ytpm.arena.dao.LoginRecordMapper;
 import com.ytpm.arena.dao.QuestionMapper;
 import com.ytpm.arena.redis.RedisService;
+import com.ytpm.general.StatusCode;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import com.ytpm.risk.view.RiskConfigView;
 import com.ytpm.risk.view.RiskTemplateView;
@@ -52,6 +55,10 @@ public class UserController {
 
     @Autowired
     private RedisService redisService;
+
+    @Autowired
+    private RiskFeign riskFeign;
+
     /**
      * 根据应用ID查询当月注册用户
      */
@@ -152,6 +159,15 @@ public class UserController {
         user.setTodayAnswerCount(questionMapper.getAnswerCount(userId,1));
         user.setHistoryAnswerCount(questionMapper.getAnswerCount(userId,2));
         user.setAnswerRecordList(questionMapper.getAnswerRecords(userId));
+        Result<?> result = riskFeign.checkAdRisk(user);
+        if (result != null) {
+            user.setIfPowerLimit(false);
+            if (result.getCode() != 200) {
+                if ("766".equals(result.getMessage()) || result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotEmpty(result.getMessage())) {
+                    user.setIfPowerLimit(true);
+                }
+            }
+        }
         return Result.resultObjOk(user);
     }
 

+ 2 - 1
yt-arena/arena-service/src/main/java/com/ytpm/arena/controller/VisitorController.java

@@ -2,6 +2,7 @@ package com.ytpm.arena.controller;
 
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.arena.dao.AppUserMapper;
 import com.ytpm.general.Result;
@@ -34,7 +35,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 2 - 0
yt-arena/arena-service/src/main/java/com/ytpm/arena/controller/WxController.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.ytpm.app.enums.AppTypeEnums;
+import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtAppDefaultConfig;
 import com.ytpm.app.model.YtDyzPowerRecord;
 import com.ytpm.app.model.YtDyzUser;
@@ -66,6 +67,7 @@ public class WxController {
         }
         param.setLoginIp(getClientIp(request));
         YtDyzUser old = appUserService.crudForNewTrans(param,wxUserInfo,loginResult);
+        old.setLoginType(LoginType.WX);
         //调用风控服务校验默认风控配置
         old.setRiskCode("313");
         Result<?> result = riskFeign.checkRisk(old);

+ 12 - 1
yt-arena/arena-service/src/main/java/com/ytpm/arena/dao/AdRecordMapper.java

@@ -15,10 +15,16 @@ public interface AdRecordMapper {
      * 新增广告记录
      */
     void addOne(YtDyzAdRecord adRecord);
+
+    /**
+     * 保存游客广告记录
+     */
+    void addOneVisitor(YtDyzAdRecord adRecord);
+
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
 
     /**
      * 查询激励视频记录
@@ -44,4 +50,9 @@ public interface AdRecordMapper {
      * 查询今日广告
      */
     List<YtDyzAdRecord> getTodayRecord(@Param("appIds")String appIds,@Param("firstDay")String firstDay,@Param("lastDay")String lastDay);
+
+    /**
+     * 查询指定广告记录
+     */
+    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
 }

+ 2 - 0
yt-arena/arena-service/src/main/java/com/ytpm/arena/dao/AppUserMapper.java

@@ -90,6 +90,8 @@ public interface AppUserMapper {
      */
     WxDefaultConfig getDefaultConfig(@Param("appType") int appType);
 
+    WxDefaultConfig getDefaultConfigByAppId(@Param("appId") String appId);
+
     /**
      * 根据微信openid查询用户
      */

+ 5 - 2
yt-arena/arena-service/src/main/java/com/ytpm/arena/monitor/RedisKeyExpirationListener.java

@@ -44,8 +44,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
      */
     @Override
     public void onMessage(Message message, byte[] pattern) {
-        String key = String.valueOf(message);
-        log.error("App-Service 发现预定风控用户:{}",key);
+       String key = String.valueOf(message);
+//        log.error("App-Service 发现预定风控用户:{}",key);
+        //        if (!key.endsWith(applicationName)) {
+//            return;
+//        }
         if(key.startsWith("lock_")){
             String[] arr = key.split("_");
             lockUser(arr[1], UserStatusEnum.RISK.getCode());

+ 6 - 0
yt-arena/arena-service/src/main/java/com/ytpm/arena/service/AdService.java

@@ -2,6 +2,8 @@ package com.ytpm.arena.service;
 
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
+import com.ytpm.app.model.YtDyzAdRecord;
+import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.general.Result;
 import com.ytpm.middle.view.DashboardRankingListVO;
@@ -46,4 +48,8 @@ public interface AdService {
      * 查询代理商首页广告数据统计
      */
     List<AgentAdGroupStaticsVO> getAgentProfit(String appIds);
+
+    String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user);
+
+    List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds);
 }

+ 44 - 8
yt-arena/arena-service/src/main/java/com/ytpm/arena/service/impl/AdServiceImpl.java

@@ -4,14 +4,17 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import com.ytpm.advertise.enums.AdPlatformTypeEnum;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
 import com.ytpm.app.model.YtDyzAdRecord;
 import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
+import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.feign.RiskFeign;
 import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
@@ -20,6 +23,7 @@ import com.ytpm.arena.dao.AdRecordMapper;
 import com.ytpm.arena.dao.AppUserMapper;
 import com.ytpm.arena.service.AdService;
 import com.ytpm.middle.view.*;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -31,10 +35,18 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Service
 @RefreshScope
 public class AdServiceImpl implements AdService {
@@ -56,6 +68,7 @@ public class AdServiceImpl implements AdService {
     @Transactional(rollbackFor = Exception.class)
     public Result<?> saveRecord(DyzAdRecordParam param) {
         YtDyzUser user = appUserMapper.selectPrimaryKey(param.getUserId());
+        log.error(StrUtil.format("[saveRecord]:{} ", param.getBeginTime()));
         if(Objects.isNull(user)){
             return Result.resultOk(RepMessage.SAVE_SUCCESS);
         }
@@ -65,9 +78,22 @@ public class AdServiceImpl implements AdService {
         saveRecordAndChangeUser(param, user);
         //调用风控广告校验
         if(AdSourceTypeEnum.rewarded_video.getAdSourceType() == param.getAdSourceType()){
+            WxDefaultConfig config = appUserMapper.getDefaultConfigByAppId(user.getAppId());
+            String format = StrUtil.emptyToDefault(config.getTaskLimitTip(), "当前设备完成任务次数过多,请{}后重试!");
+            user.setPowerLimitTip(format);
             Result<?> result = riskFeign.checkAdRisk(user);
-            if(result.getCode()!=200){
-                return new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+            if (result.getCode() != 200) {
+                Result<Object> resultObj = new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+                // 766处理
+                if("766".contains(result.getMessage())){
+                    resultObj.setData(result.getMessage());
+                }
+                else if (result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotBlank(result.getMessage())) {
+                    // 体力不再获取处理
+                    resultObj.setMessage(result.getMessage());
+                    resultObj.setData("767");
+                }
+                return resultObj;
             }
         }
         return Result.resultOk(RepMessage.SAVE_SUCCESS);
@@ -219,17 +245,15 @@ public class AdServiceImpl implements AdService {
         cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),actualMaximum,23,59,59);
         String lastDay = sdf.format(cal.getTime());
         List<YtDyzAdRecord> dyzMonthRecords = adRecordMapper.getTodayRecord(appIds,firstDay,lastDay);
-
         if(CollUtil.isNotEmpty(dyzMonthRecords)){monthRecords.addAll(dyzMonthRecords);}
         records = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),new Date())).collect(Collectors.toList());
 
-        cal = Calendar.getInstance();
+        cal = Calendar.getInstance(); // 获取当前日期时间
         cal.add(Calendar.DATE, -1); // 昨天的日期时间
         Date yest = cal.getTime();
         yestRecords = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),yest)).collect(Collectors.toList());
-
         //广告平台分组
         Map<String, List<YtDyzAdRecord>> networkMap = records.stream().collect(
                 Collectors.groupingBy(YtDyzAdRecord::getNetworkFormId));
@@ -274,7 +298,8 @@ public class AdServiceImpl implements AdService {
      *  始终创建新的事务以保障子方法的独立事务
      */
 //    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
-    public void saveRecordAndChangeUser(DyzAdRecordParam param,YtDyzUser user) {
+    @Override
+    public String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user) {
         //增加广告记录
         YtDyzAdRecord adRecord = new YtDyzAdRecord();
         if(Objects.isNull(param.getBeginTime())){
@@ -283,12 +308,23 @@ public class AdServiceImpl implements AdService {
         BeanUtils.copyProperties(param, adRecord);
         adRecord.setRecordId(IdUtil.fastSimpleUUID());
         adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
-        adRecordMapper.addOne(adRecord);
+        if (param.getLoginStatus() != null && AdRecordEnum.LOGIN_BEFORE.getCode().equals(param.getLoginStatus())) {
+            adRecordMapper.addOneVisitor(adRecord);
+        } else {
+            adRecordMapper.addOne(adRecord);
+        }
         //修改用户信息, 广告次数+1  总收益 + revenue
         YtDyzUser dyzUser = new YtDyzUser();
         dyzUser.setUserId(user.getUserId());
         dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo())?1:(user.getTotalVideo()+1));
         dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
         appUserMapper.updateUser(dyzUser);
+        return adRecord.getRecordId();
     }
+
+    @Override
+    public List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds) {
+        return adRecordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
+    }
+
 }

+ 15 - 0
yt-arena/arena-service/src/main/java/com/ytpm/arena/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 51 - 5
yt-arena/arena-service/src/main/java/com/ytpm/arena/service/impl/VisitorLoginServiceImpl.java

@@ -1,30 +1,38 @@
 package com.ytpm.arena.service.impl;
 
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzLoginRecord;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.app.param.LoginParam;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.arena.dao.AppUserMapper;
 import com.ytpm.arena.dao.LoginRecordMapper;
 import com.ytpm.arena.dao.QuestionMapper;
 import com.ytpm.arena.redis.RedisService;
+import com.ytpm.arena.service.AdService;
 import com.ytpm.constant.StrConstant;
 import com.ytpm.feign.RiskFeign;
+import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.handle.AbstractLoginService;
 import com.ytpm.handle.CommonException;
+import com.ytpm.handle.CustomerException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -34,6 +42,7 @@ import java.util.Map;
  * @date 2025/9/4
  */
 
+
 @Slf4j
 @Component
 public class VisitorLoginServiceImpl extends AbstractLoginService  {
@@ -48,6 +57,8 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
     private RiskFeign riskFeign;
     @Autowired
     private RedisService redisService;
+    @Autowired
+    private AdService adService;
 
     @Override
     protected WxDefaultConfig getLoginConfig(Integer appType) {
@@ -67,6 +78,20 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         return LoginType.VISITOR;
     }
 
+    @Override
+    protected void updateUserStatus(YtDyzUser ytDyzUser, UserStatusEnum statusEnum, String reason) {
+        if (ytDyzUser != null) {
+            YtDyzUser newUser = new YtDyzUser();
+            newUser.setUserId(ytDyzUser.getUserId());
+            newUser.setUserStatus(statusEnum.getCode());
+            newUser.setRiskReason(reason);
+            if(UserStatusEnum.NORMAL == statusEnum){
+                newUser.setRiskReason("");
+            }
+            appUserMapper.updateUser(newUser);
+        }
+    }
+
     @Override
     protected void validateParams(LoginParam loginParam, HttpServletRequest request) {
 
@@ -142,6 +167,7 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
      */
     @Override
     protected void setExtInfo(YtDyzUser old, Map<String, Object> paramMap) {
+        super.setExtInfo(old, paramMap);
         old.setLastQuestionId(questionMapper.getLastQuestionId(old.getUserId()));
         old.setTodayAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 1));
         old.setHistoryAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 2));
@@ -149,10 +175,30 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         old.setLoginRecordList(loginRecordMapper.getLoginRecords(old.getUserId()));
     }
 
-    @Override
-    protected void beforeDeadWithUserCrud(LoginParam loginParam, YtDyzUser ytDyzUser, Map<String, Object> paramMap) {
-        super.beforeDeadWithUserCrud(loginParam, ytDyzUser, paramMap);
-        // 新增风控 相关广告源记录 ecpm  和预估收益 小于 各自 阈值,登陆返回 301
 
+    // 仅保存登陆时的三条广告信息 并传入登陆实体用于后续 risk风控校验
+    protected void saveVisitorAdRecord(YtDyzUser ytDyzUser, LoginParam loginParam, WxDefaultConfig defaultConfig) {
+        super.saveVisitorAdRecord(ytDyzUser, loginParam, defaultConfig);
+        VisitorLoginParam visitorLoginParam = (VisitorLoginParam) loginParam;
+        List<DyzAdRecordParam> preAdList = visitorLoginParam.getPreAdList();
+        List<String> adRecordIds = new ArrayList<>();
+        if (CollUtil.isNotEmpty(preAdList)) {
+            for (DyzAdRecordParam adRecordParam : preAdList) {
+                if (adRecordParam == null) {
+                    continue;
+                }
+                adRecordParam.setUserId(ytDyzUser.getUserId());
+                adRecordParam.setNickName(ytDyzUser.getNickName());
+                adRecordParam.setAppId(ytDyzUser.getAppId());
+                adRecordParam.setLoginStatus(AdRecordEnum.LOGIN_BEFORE.getCode());
+                String recordId = adService.saveRecordAndChangeUser(adRecordParam, ytDyzUser);
+                adRecordIds.add(recordId);
+            }
+        }
+        if(CollUtil.isEmpty(adRecordIds)) {
+            throw new CustomerException(StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), RepMessage.RISK_VISITOR_LOWER_VALUE));
+        }
+        ytDyzUser.setPreAdRecordList(adService.queryRecordByIds(adRecordIds));
     }
-}
+
+}

+ 112 - 60
yt-arena/arena-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -5,46 +5,86 @@
     <insert id="addOne">
         insert into yt_dyz_ad_record
         (
-         record_id,
-         user_id,
-         nick_name,
-         placement_id,
-         ad_source_id,
-         revenue,
-         network_form_id,
-         network_name,
-         network_placement_id,
-         begin_time,
-         finish_time,
-         result_json,
-         ad_source_index,
-         ad_source_type,
-         ecpm,
-         app_id
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
         values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
+    </insert>
+    <insert id="addOneVisitor">
+        insert into yt_dyz_ad_record_visitor
         (
-         #{recordId},
-         #{userId},
-         #{nickName},
-         #{placementId},
-         #{adSourceId},
-         #{revenue},
-         #{networkFormId},
-         #{networkName},
-         #{networkPlacementId},
-         ifnull(#{beginTime}, now()),
-         ifnull(#{finishTime}, now()),
-         #{resultJson},
-         #{adSourceIndex},
-         #{adSourceType},
-         #{ecpm},
-         #{appId}
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
+        values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
     </insert>
     <select id="countByAppIds" resultType="java.lang.Integer">
         select
-            count(record_id)
+        count(record_id)
         from yt_dyz_ad_record
         where ad_source_type = 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -53,48 +93,48 @@
     </select>
     <select id="getByUserId" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id = #{userId}
-          <if test="adsourceType != null and adsourceType!=888">
-              and ad_source_type = #{adsourceType}
-          </if>
+        <if test="adsourceType != null and adsourceType!=888">
+            and ad_source_type = #{adsourceType}
+        </if>
         order by finish_time desc
     </select>
     <select id="getByUserIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id in
-              <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
-                  #{item}
-              </foreach>
+        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
+            #{item}
+        </foreach>
         order by finish_time
     </select>
     <select id="getHourRevenue" resultType="com.ytpm.middle.view.AppRevenueHourVO">
         SELECT
-            HOUR(finish_time) `hour`,
-            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
-            sum( revenue ) revenue
+        HOUR(finish_time) `hour`,
+        DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
+        sum( revenue ) revenue
         FROM
-            yt_dyz_ad_record
+        yt_dyz_ad_record
         WHERE
-            app_id = #{appId}
-            <if test="type != null and type ==1">
-                and DATE(finish_time) = DATE(now())
-            </if>
-            <if test="type != null and type ==2">
-                and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
-            </if>
-            <if test="type != null and type ==3">
-                and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
-            </if>
+        app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(finish_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
         GROUP BY
-            `hour`
+        `hour`
     </select>
     <select id="getRevenueByTime" resultType="java.math.BigDecimal">
         select
-            sum(ar.revenue)
+        sum(ar.revenue)
         from yt_dyz_ad_record ar
         join yt_dyz_user au on ar.user_id = au.user_id
         <where>
@@ -117,16 +157,16 @@
                 </foreach>
             </if>
             <if test="registryTimeBegin != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[>=]]> #{registryTimeBegin}
+                and au.registry_time <![CDATA[>=]]> #{registryTimeBegin}
             </if>
             <if test="registryTimeEnd != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[<=]]> #{registryTimeEnd}
+                and au.registry_time <![CDATA[<=]]> #{registryTimeEnd}
             </if>
         </where>
     </select>
     <select id="getTodayRecord" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
         from yt_dyz_ad_record
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -139,4 +179,16 @@
             and finish_time <![CDATA[<=]]> #{lastDay}
         </if>
     </select>
+    <select id="selectRecordByIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
+        select
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index,
+        revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        <if test="loginStatus != null and loginStatus == 1">
+            from yt_dyz_ad_record_visitor
+        </if>
+        <if test="loginStatus == null or loginStatus != 1">
+            from yt_dyz_ad_record
+        </if>
+        where record_id in <foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
+    </select>
 </mapper>

+ 174 - 135
yt-arena/arena-service/src/main/resources/mapper/AppUserMapper.xml

@@ -4,70 +4,70 @@
     <insert id="addOne" parameterType="com.ytpm.app.model.YtDyzUser">
         insert into yt_dyz_user
         (
-         user_id,
-         nick_name,
-         head_img,
-         registry_time,
-         last_login_time,
-         last_login_ip,
-         login_days,
-         total_video,
-         total_income,
-         red_packet_balance,
-         red_packet_amount,
-         points_balance,
-         points_total,
-         withdraw_total,
-         sign_days,
-         user_status,
-         risk_reason,
-         wx_open_id,
-         ditch_id,
-         platform_id,
-         app_id,
-         power,
-         phone,
-         phone_json,
-         device_id
+            user_id,
+            nick_name,
+            head_img,
+            registry_time,
+            last_login_time,
+            last_login_ip,
+            login_days,
+            total_video,
+            total_income,
+            red_packet_balance,
+            red_packet_amount,
+            points_balance,
+            points_total,
+            withdraw_total,
+            sign_days,
+            user_status,
+            risk_reason,
+            wx_open_id,
+            ditch_id,
+            platform_id,
+            app_id,
+            power,
+            phone,
+            phone_json,
+            device_id
         )
         values
-        (
-         #{userId},
-         #{nickName},
-         #{headImg},
-         #{registryTime},
-         #{lastLoginTime},
-         #{lastLoginIp},
-         #{loginDays},
-         #{totalVideo},
-         #{totalIncome},
-         #{redPacketBalance},
-         #{redPacketAmount},
-         #{pointsBalance},
-         #{pointsTotal},
-         #{withdrawTotal},
-         #{signDays},
-         #{userStatus},
-         #{riskReason},
-         #{wxOpenId},
-         #{ditchId},
-         #{platformId},
-         #{appId},
-         #{power},
-         #{phone},
-         #{phoneJson},
-         #{deviceId}
-        )
+            (
+                #{userId},
+                #{nickName},
+                #{headImg},
+                #{registryTime},
+                #{lastLoginTime},
+                #{lastLoginIp},
+                #{loginDays},
+                #{totalVideo},
+                #{totalIncome},
+                #{redPacketBalance},
+                #{redPacketAmount},
+                #{pointsBalance},
+                #{pointsTotal},
+                #{withdrawTotal},
+                #{signDays},
+                #{userStatus},
+                #{riskReason},
+                #{wxOpenId},
+                #{ditchId},
+                #{platformId},
+                #{appId},
+                #{power},
+                #{phone},
+                #{phoneJson},
+                #{deviceId}
+            )
     </insert>
     <insert id="addPowerRecord">
         insert into yt_dyz_power_record
         (
-         record_id, user_id, type, remark, add_time
+            record_id, user_id, type, remark, add_time
         )
         values
-        (
-         #{recordId},#{userId},#{type},#{remark},#{addTime}
-        )
+            (
+                #{recordId},#{userId},#{type},#{remark},#{addTime}
+            )
     </insert>
     <insert id="saveAppConfig">
         insert into yt_app_default_config
@@ -151,6 +151,24 @@
             <if test="interstitialIntervalTime != null">
                 interstitial_interval_time = #{interstitialIntervalTime}
             </if>
+            <if test="flowIntervalTime != null">
+                flow_interval_time = #{flowIntervalTime}
+            </if>
+            <if test="taskLimitTip != null">
+                task_limit_tip = #{taskLimitTip}
+            </if>
+            <if test="lowValueTip != null">
+                low_value_tip = #{lowValueTip}
+            </if>
+            <if test="brushTip != null">
+                brush_tip = #{brushTip}
+            </if>
+            <if test="startWaitTime != null">
+                start_wait_time = #{startWaitTime}
+            </if>
+            <if test="canCacheVideo != null">
+                can_cache_video = #{canCacheVideo}
+            </if>
         </set>
         where app_id = #{appId}
     </update>
@@ -234,14 +252,14 @@
     </delete>
     <select id="getYtAppUser" resultType="com.ytpm.app.model.YtDyzUser">
         select
-           user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+            user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where wx_open_id = #{openid}
-        and ditch_id = #{ditchId}
+          and ditch_id = #{ditchId}
     </select>
     <select id="queryAll" resultType="com.ytpm.app.view.YtAppUserListView">
         select
-            user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+        user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where 1 = 1
         <if test="userId != null and userId !=''">
@@ -270,9 +288,9 @@
         </if>
         <if test="appIds != null and appIds != ''">
             and app_id in
-                <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
-                    #{item}
-                </foreach>
+            <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
+                #{item}
+            </foreach>
         </if>
         order by user_id desc
     </select>
@@ -320,37 +338,37 @@
     </resultMap>
     <select id="getUserList" resultMap="UserMap">
         select
-            du.user_id,
-            du.head_img,
-            du.nick_name,
-            du.phone,
-            du.device_id,
-            du.registry_time,
-            du.last_login_time,
-            du.last_login_ip,
-            du.login_days,
-            du.total_video,
-            du.total_income,
-            du.red_packet_balance,
-            du.red_packet_amount,
-            du.points_balance,
-            du.points_total,
-            du.withdraw_total,
-            du.sign_days,
-            du.user_status,
-            du.risk_reason,
-            du.wx_open_id,
-            du.ditch_id,
-            du.app_id,
-            du.platform_id,
-            du.power,
-            lr.record_id,
-            lr.login_time,
-            lr.device_brand,
-            lr. device_model,
-            lr.login_ip,
-            lr.operator,
-            lr.ip_addr
+        du.user_id,
+        du.head_img,
+        du.nick_name,
+        du.phone,
+        du.device_id,
+        du.registry_time,
+        du.last_login_time,
+        du.last_login_ip,
+        du.login_days,
+        du.total_video,
+        du.total_income,
+        du.red_packet_balance,
+        du.red_packet_amount,
+        du.points_balance,
+        du.points_total,
+        du.withdraw_total,
+        du.sign_days,
+        du.user_status,
+        du.risk_reason,
+        du.wx_open_id,
+        du.ditch_id,
+        du.app_id,
+        du.platform_id,
+        du.power,
+        lr.record_id,
+        lr.login_time,
+        lr.device_brand,
+        lr. device_model,
+        lr.login_ip,
+        lr.operator,
+        lr.ip_addr
         from yt_dyz_user du
         left join yt_dyz_login_record lr on du.user_id = lr.user_id
         <where>
@@ -430,14 +448,32 @@
     </select>
     <select id="getDefaultConfig" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id appId, secret, app_id platformAppId, app_key platformAppSecret, app_type,user_path,login_path,ad_path,answer_path,power_path
-                     ,can_simulator,taku_app_id,taku_key,taku_banner_pid,taku_interstitial_pid,taku_reward_pid,taku_native_pid,can_use_adb,can_accumulation,can_use_float,can_use_root,ditch_id,power_wait_time,interstitial_interval_time
+            config_id, config_name, open_id as app_id, secret, app_id as platformAppId, app_key as platformAppSecret,
+            app_type,user_path, login_path,ad_path,answer_path,power_path,can_simulator,
+            taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid,
+            can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_type = #{appType}
     </select>
+    <select id="getDefaultConfigByAppId" resultType="com.ytpm.app.view.WxDefaultConfig">
+        select
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
+        from yt_app_default_config
+        where app_id = #{appId}
+    </select>
     <select id="getSecretByAppId" resultType="java.lang.String">
         select
-           secret
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id = #{appId}
     </select>
@@ -452,13 +488,16 @@
             platform_id
         from yt_dyz_user
         where device_id = #{deviceId}
-        and wx_open_id = #{openid}
+          and wx_open_id = #{openid}
         limit 1
     </select>
     <select id="getConfigByIds" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,answer_path,power_path
-        ,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation, ditch_id, power_wait_time, interstitial_interval_time
+        config_id, config_name, open_id, secret, app_id, app_key, app_type, user_path, login_path, ad_path,
+        answer_path, power_path,taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid,
+        taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,can_simulator,
+        ditch_id, power_wait_time, interstitial_interval_time,
+        low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id in
         <foreach collection="appIds.split(',')" item="item" separator="," open="(" close=")">
@@ -467,7 +506,7 @@
     </select>
     <select id="getAdCount" resultType="java.lang.Integer">
         select
-            sum(total_video)
+        sum(total_video)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -485,11 +524,11 @@
     </select>
     <select id="getAppRanking" resultType="com.ytpm.middle.view.AppRankingListVO">
         SELECT
-            u.app_id,
-            sum( ar.revenue ) totalRevenue
+        u.app_id,
+        sum( ar.revenue ) totalRevenue
         FROM
-            yt_dyz_ad_record ar
-            JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -506,21 +545,21 @@
             </if>
         </where>
         GROUP BY
-            u.app_id
+        u.app_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         LIMIT #{limit}
     </select>
     <select id="getUserRanking" resultType="com.ytpm.middle.view.UserRankingListVO">
         SELECT
-            u.user_id,
-            u.nick_name,
-            u.head_img,
-            u.total_video,
-            sum( ar.revenue ) totalIncome
+        u.user_id,
+        u.nick_name,
+        u.head_img,
+        u.total_video,
+        sum( ar.revenue ) totalIncome
         FROM
-            yt_dyz_ad_record ar
-                JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -538,12 +577,12 @@
         </where>
         GROUP BY ar.user_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         limit #{limit}
     </select>
     <select id="countUserByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -552,7 +591,7 @@
     </select>
     <select id="countRevenueByAppIds" resultType="java.math.BigDecimal">
         select
-            sum(total_income)
+        sum(total_income)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -561,7 +600,7 @@
     </select>
     <select id="countBannedByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where user_status > 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -600,8 +639,8 @@
     </select>
     <select id="countRegistryHour" resultType="com.ytpm.middle.view.AppUserHourVO">
         select
-            DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
-            count(user_id) `count`
+        DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
+        count(user_id) `count`
         from yt_dyz_user
         where app_id = #{appId}
         <if test="type != null and type ==1">
@@ -634,7 +673,7 @@
     </select>
     <select id="queryByUserIds" resultType="com.ytpm.app.model.YtDyzUser">
         select
-            user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
+        user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
         from yt_dyz_user
         where user_id in
         <foreach collection="userIds.split(',')" separator="," item="item"  open="(" close=")">
@@ -662,21 +701,21 @@
     </resultMap>
     <select id="queryTodayUserAd" resultMap="UserAdMap">
         select
-            u.user_id,
-            u.app_id,
-            u.nick_name,
-            ar.record_id,
-            ar.placement_id,
-            ar.ad_source_id,
-            ar.ad_source_type,
-            ar.ad_source_index,
-            ar.revenue,
-            ar.ecpm,
-            ar.network_form_id,
-            ar.network_name,
-            ar.network_placement_id,
-            ar.finish_time,
-            ar.begin_time
+        u.user_id,
+        u.app_id,
+        u.nick_name,
+        ar.record_id,
+        ar.placement_id,
+        ar.ad_source_id,
+        ar.ad_source_type,
+        ar.ad_source_index,
+        ar.revenue,
+        ar.ecpm,
+        ar.network_form_id,
+        ar.network_name,
+        ar.network_placement_id,
+        ar.finish_time,
+        ar.begin_time
         from yt_dyz_ad_record ar
         join yt_dyz_user u on ar.user_id = u.user_id
         where ar.ad_source_type = #{adSourceType} and ar.app_id = #{appId} and ar.user_id in

+ 22 - 20
yt-arena/arena-service/src/main/resources/mapper/LoginRecordMapper.xml

@@ -5,28 +5,30 @@
     <insert id="insertOne" parameterType="com.ytpm.app.model.YtDyzLoginRecord">
         insert into yt_dyz_login_record
         (
-         record_id,
-         user_id,
-         login_time,
-         device_brand,
-         device_model,
-         login_ip,
-         operator,
-         ip_addr,
-         phone_json
+            record_id,
+            user_id,
+            login_time,
+            device_brand,
+            device_model,
+            login_ip,
+            operator,
+            ip_addr,
+            phone_json,
+            login_type
         )
         values
-        (
-         #{recordId},
-         #{userId},
-         #{loginTime},
-         #{deviceBrand},
-         #{deviceModel},
-         #{loginIp},
-         #{operator},
-         #{ipAddr},
-         #{phoneJson}
-         );
+            (
+                #{recordId},
+                #{userId},
+                #{loginTime},
+                #{deviceBrand},
+                #{deviceModel},
+                #{loginIp},
+                #{operator},
+                #{ipAddr},
+                #{phoneJson},
+                #{loginType}
+            );
     </insert>
     <select id="getLoginRecords" resultType="com.ytpm.app.model.YtDyzLoginRecord">
         select

+ 2 - 1
yt-arithmetic/arithmetic-service/src/main/java/com/ytpm/arithmetic/controller/VisitorController.java

@@ -3,6 +3,7 @@ package com.ytpm.arithmetic.controller;
 
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.arithmetic.dao.AppUserMapper;
 import com.ytpm.general.Result;
@@ -35,7 +36,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 15 - 0
yt-arithmetic/arithmetic-service/src/main/java/com/ytpm/arithmetic/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 2 - 1
yt-calculator/calculator-service/src/main/java/com/ytpm/calculator/controller/VisitorController.java

@@ -3,6 +3,7 @@ package com.ytpm.calculator.controller;
 
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.calculator.dao.AppUserMapper;
 import com.ytpm.general.Result;
@@ -35,7 +36,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 15 - 0
yt-calculator/calculator-service/src/main/java/com/ytpm/calculator/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 1 - 0
yt-carp/carp-service/pom.xml

@@ -44,6 +44,7 @@
         <dependency>
             <groupId>com.zaxxer</groupId>
             <artifactId>HikariCP</artifactId>
+            <version>${hikar-icp.version}</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 3 - 1
yt-carp/carp-service/src/main/java/com/ytpm/carp/config/interceptor/HttpInterceptor.java

@@ -1,5 +1,6 @@
 package com.ytpm.carp.config.interceptor;
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.ModelAndView;
@@ -8,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
 
+@Slf4j
 @Component
 public class HttpInterceptor implements HandlerInterceptor {
 
@@ -16,7 +18,7 @@ public class HttpInterceptor implements HandlerInterceptor {
                              HttpServletResponse response, Object obj) throws Exception {
         // 获取客户端IP地址
         String clientIp = getClientIp(request);
-        System.out.println("小锦鲤日历接收客户端" + clientIp + "发起用户请求");
+        log.error("小锦鲤日历接收客户端" + clientIp + "发起用户请求");
         // 可以在这里添加更多的逻辑,比如记录日志等
         return true;
     }

+ 14 - 0
yt-carp/carp-service/src/main/java/com/ytpm/carp/controller/UserController.java

@@ -2,6 +2,7 @@ package com.ytpm.carp.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
 import com.github.pagehelper.PageInfo;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
@@ -23,9 +24,11 @@ import com.ytpm.carp.dao.AppUserMapper;
 import com.ytpm.carp.dao.LoginRecordMapper;
 import com.ytpm.carp.dao.QuestionMapper;
 import com.ytpm.carp.redis.RedisService;
+import com.ytpm.feign.RiskFeign;
 import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
+import com.ytpm.general.StatusCode;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import com.ytpm.risk.view.RiskConfigView;
 import com.ytpm.risk.view.RiskTemplateView;
@@ -66,6 +69,8 @@ public class UserController {
     @Autowired
     private RedisService redisService;
 
+    @Autowired
+    private RiskFeign riskFeign;
 
     /**
      * 根据应用ID查询当月注册用户
@@ -169,6 +174,15 @@ public class UserController {
         user.setTodayAnswerCount(questionMapper.getAnswerCount(userId,1));
         user.setHistoryAnswerCount(questionMapper.getAnswerCount(userId,2));
         user.setAnswerRecordList(questionMapper.getAnswerRecords(userId));
+        Result<?> result = riskFeign.checkAdRisk(user);
+        if (result != null) {
+            user.setIfPowerLimit(false);
+            if (result.getCode() != 200) {
+                if ("766".equals(result.getMessage()) || result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotEmpty(result.getMessage())) {
+                    user.setIfPowerLimit(true);
+                }
+            }
+        }
         return Result.resultObjOk(user);
     }
 

+ 2 - 1
yt-carp/carp-service/src/main/java/com/ytpm/carp/controller/VisitorController.java

@@ -3,6 +3,7 @@ package com.ytpm.carp.controller;
 
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.carp.dao.AppUserMapper;
 import com.ytpm.general.Result;
@@ -35,7 +36,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 2 - 0
yt-carp/carp-service/src/main/java/com/ytpm/carp/controller/WxController.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.ytpm.app.enums.AppTypeEnums;
+import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtAppDefaultConfig;
 import com.ytpm.app.model.YtDyzPowerRecord;
 import com.ytpm.app.model.YtDyzUser;
@@ -72,6 +73,7 @@ public class WxController {
         }
         param.setLoginIp(getClientIp(request));
         YtDyzUser old = appUserService.crudForNewTrans(param,wxUserInfo,loginResult);
+        old.setLoginType(LoginType.WX);
         //调用风控服务校验默认风控配置
         old.setRiskCode("313");
         Result<?> result = riskFeign.checkRisk(old);

+ 12 - 1
yt-carp/carp-service/src/main/java/com/ytpm/carp/dao/AdRecordMapper.java

@@ -15,10 +15,16 @@ public interface AdRecordMapper {
      * 新增广告记录
      */
     void addOne(YtDyzAdRecord adRecord);
+
+    /**
+     * 保存游客广告记录
+     */
+    void addOneVisitor(YtDyzAdRecord adRecord);
+
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
 
     /**
      * 查询激励视频记录
@@ -44,4 +50,9 @@ public interface AdRecordMapper {
      * 查询今日广告
      */
     List<YtDyzAdRecord> getTodayRecord(@Param("appIds")String appIds,@Param("firstDay")String firstDay,@Param("lastDay")String lastDay);
+
+    /**
+     * 查询指定广告记录
+     */
+    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
 }

+ 2 - 0
yt-carp/carp-service/src/main/java/com/ytpm/carp/dao/AppUserMapper.java

@@ -90,6 +90,8 @@ public interface AppUserMapper {
      */
     WxDefaultConfig getDefaultConfig(@Param("appType") int appType);
 
+    WxDefaultConfig getDefaultConfigByAppId(@Param("appId") String appId);
+
     /**
      * 根据微信openid查询用户
      */

+ 8 - 3
yt-carp/carp-service/src/main/java/com/ytpm/carp/monitor/RedisKeyExpirationListener.java

@@ -6,6 +6,7 @@ import com.ytpm.carp.dao.AppUserMapper;
 import com.ytpm.feign.RiskFeign;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.data.redis.connection.Message;
 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
@@ -28,7 +29,8 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
     private AppUserMapper appUserMapper;
     @Resource
     private RiskFeign riskFeign;
-
+    @Value("${spring.application.name:}")
+    private String applicationName;
     /**
      * Creates new {@link } for {@code __keyevent@*__:expired} messages.
      *
@@ -43,8 +45,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
      */
     @Override
     public void onMessage(Message message, byte[] pattern) {
-        String key = String.valueOf(message);
-        log.error("App-Service 发现预定风控用户:{}",key);
+       String key = String.valueOf(message);
+//        log.error("App-Service 发现预定风控用户:{}",key);
+        //        if (!key.endsWith(applicationName)) {
+//            return;
+//        }
         if(key.startsWith("lock_")){
             String[] arr = key.split("_");
             lockUser(arr[1], UserStatusEnum.RISK.getCode());

+ 6 - 0
yt-carp/carp-service/src/main/java/com/ytpm/carp/service/AdService.java

@@ -2,6 +2,8 @@ package com.ytpm.carp.service;
 
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
+import com.ytpm.app.model.YtDyzAdRecord;
+import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.general.Result;
 import com.ytpm.middle.view.DashboardRankingListVO;
@@ -46,4 +48,8 @@ public interface AdService {
      * 查询代理商首页广告数据统计
      */
     List<AgentAdGroupStaticsVO> getAgentProfit(String appIds);
+
+    String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user);
+
+    List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds);
 }

+ 36 - 7
yt-carp/carp-service/src/main/java/com/ytpm/carp/service/impl/AdServiceImpl.java

@@ -4,14 +4,17 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import com.ytpm.advertise.enums.AdPlatformTypeEnum;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
 import com.ytpm.app.model.YtDyzAdRecord;
 import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
+import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.carp.dao.AdRecordMapper;
 import com.ytpm.carp.dao.AppUserMapper;
 import com.ytpm.carp.service.AdService;
@@ -27,6 +30,7 @@ import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
 import com.ytpm.middle.view.DashboardRiskVO;
 import com.ytpm.middle.view.UserRankingListVO;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -49,6 +53,7 @@ import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Service
 @RefreshScope
 public class AdServiceImpl implements AdService {
@@ -70,6 +75,7 @@ public class AdServiceImpl implements AdService {
     @Transactional(rollbackFor = Exception.class)
     public Result<?> saveRecord(DyzAdRecordParam param) {
         YtDyzUser user = appUserMapper.selectPrimaryKey(param.getUserId());
+        log.error(StrUtil.format("[saveRecord]:{} ", param.getBeginTime()));
         if(Objects.isNull(user)){
             return Result.resultOk(RepMessage.SAVE_SUCCESS);
         }
@@ -79,9 +85,22 @@ public class AdServiceImpl implements AdService {
         saveRecordAndChangeUser(param, user);
         //调用风控广告校验
         if(AdSourceTypeEnum.rewarded_video.getAdSourceType() == param.getAdSourceType()){
+            WxDefaultConfig config = appUserMapper.getDefaultConfigByAppId(user.getAppId());
+            String format = StrUtil.emptyToDefault(config.getTaskLimitTip(), "当前设备完成任务次数过多,请{}后重试!");
+            user.setPowerLimitTip(format);
             Result<?> result = riskFeign.checkAdRisk(user);
-            if(result.getCode()!=200){
-                return new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+            if (result.getCode() != 200) {
+                Result<Object> resultObj = new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+                // 766处理
+                if("766".contains(result.getMessage())){
+                    resultObj.setData(result.getMessage());
+                }
+                else if (result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotBlank(result.getMessage())) {
+                    // 体力不再获取处理
+                    resultObj.setMessage(result.getMessage());
+                    resultObj.setData("767");
+                }
+                return resultObj;
             }
         }
         return Result.resultOk(RepMessage.SAVE_SUCCESS);
@@ -233,17 +252,15 @@ public class AdServiceImpl implements AdService {
         cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),actualMaximum,23,59,59);
         String lastDay = sdf.format(cal.getTime());
         List<YtDyzAdRecord> dyzMonthRecords = adRecordMapper.getTodayRecord(appIds,firstDay,lastDay);
-
         if(CollUtil.isNotEmpty(dyzMonthRecords)){monthRecords.addAll(dyzMonthRecords);}
         records = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),new Date())).collect(Collectors.toList());
 
-        cal = Calendar.getInstance();
+        cal = Calendar.getInstance(); // 获取当前日期时间
         cal.add(Calendar.DATE, -1); // 昨天的日期时间
         Date yest = cal.getTime();
         yestRecords = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),yest)).collect(Collectors.toList());
-
         //广告平台分组
         Map<String, List<YtDyzAdRecord>> networkMap = records.stream().collect(
                 Collectors.groupingBy(YtDyzAdRecord::getNetworkFormId));
@@ -288,7 +305,8 @@ public class AdServiceImpl implements AdService {
      *  始终创建新的事务以保障子方法的独立事务
      */
 //    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
-    public void saveRecordAndChangeUser(DyzAdRecordParam param,YtDyzUser user) {
+    @Override
+    public String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user) {
         //增加广告记录
         YtDyzAdRecord adRecord = new YtDyzAdRecord();
         if(Objects.isNull(param.getBeginTime())){
@@ -297,12 +315,23 @@ public class AdServiceImpl implements AdService {
         BeanUtils.copyProperties(param, adRecord);
         adRecord.setRecordId(IdUtil.fastSimpleUUID());
         adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
-        adRecordMapper.addOne(adRecord);
+        if (param.getLoginStatus() != null && AdRecordEnum.LOGIN_BEFORE.getCode().equals(param.getLoginStatus())) {
+            adRecordMapper.addOneVisitor(adRecord);
+        } else {
+            adRecordMapper.addOne(adRecord);
+        }
         //修改用户信息, 广告次数+1  总收益 + revenue
         YtDyzUser dyzUser = new YtDyzUser();
         dyzUser.setUserId(user.getUserId());
         dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo())?1:(user.getTotalVideo()+1));
         dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
         appUserMapper.updateUser(dyzUser);
+        return adRecord.getRecordId();
     }
+
+    @Override
+    public List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds) {
+        return adRecordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
+    }
+
 }

+ 15 - 0
yt-carp/carp-service/src/main/java/com/ytpm/carp/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 49 - 4
yt-carp/carp-service/src/main/java/com/ytpm/carp/service/impl/VisitorLoginServiceImpl.java

@@ -1,30 +1,38 @@
 package com.ytpm.carp.service.impl;
 
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzLoginRecord;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.app.param.LoginParam;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.carp.dao.AppUserMapper;
 import com.ytpm.carp.dao.LoginRecordMapper;
 import com.ytpm.carp.dao.QuestionMapper;
 import com.ytpm.carp.redis.RedisService;
+import com.ytpm.carp.service.AdService;
 import com.ytpm.constant.StrConstant;
 import com.ytpm.feign.RiskFeign;
+import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.handle.AbstractLoginService;
 import com.ytpm.handle.CommonException;
+import com.ytpm.handle.CustomerException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -48,6 +56,8 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
     private RiskFeign riskFeign;
     @Autowired
     private RedisService redisService;
+    @Autowired
+    private AdService adService;
 
     @Override
     protected WxDefaultConfig getLoginConfig(Integer appType) {
@@ -67,6 +77,20 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         return LoginType.VISITOR;
     }
 
+    @Override
+    protected void updateUserStatus(YtDyzUser ytDyzUser, UserStatusEnum statusEnum, String reason) {
+        if (ytDyzUser != null) {
+            YtDyzUser newUser = new YtDyzUser();
+            newUser.setUserId(ytDyzUser.getUserId());
+            newUser.setUserStatus(statusEnum.getCode());
+            newUser.setRiskReason(reason);
+            if(UserStatusEnum.NORMAL == statusEnum){
+                newUser.setRiskReason("");
+            }
+            appUserMapper.updateUser(newUser);
+        }
+    }
+
     @Override
     protected void validateParams(LoginParam loginParam, HttpServletRequest request) {
 
@@ -142,6 +166,7 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
      */
     @Override
     protected void setExtInfo(YtDyzUser old, Map<String, Object> paramMap) {
+        super.setExtInfo(old, paramMap);
         old.setLastQuestionId(questionMapper.getLastQuestionId(old.getUserId()));
         old.setTodayAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 1));
         old.setHistoryAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 2));
@@ -149,10 +174,30 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         old.setLoginRecordList(loginRecordMapper.getLoginRecords(old.getUserId()));
     }
 
-    @Override
-    protected void beforeDeadWithUserCrud(LoginParam loginParam, YtDyzUser ytDyzUser, Map<String, Object> paramMap) {
-        super.beforeDeadWithUserCrud(loginParam, ytDyzUser, paramMap);
-        // 新增风控 相关广告源记录 ecpm  和预估收益 小于 各自 阈值,登陆返回 301
 
+    // 仅保存登陆时的三条广告信息 并传入登陆实体用于后续 risk风控校验
+    protected void saveVisitorAdRecord(YtDyzUser ytDyzUser, LoginParam loginParam, WxDefaultConfig defaultConfig) {
+        super.saveVisitorAdRecord(ytDyzUser, loginParam, defaultConfig);
+        VisitorLoginParam visitorLoginParam = (VisitorLoginParam) loginParam;
+        List<DyzAdRecordParam> preAdList = visitorLoginParam.getPreAdList();
+        List<String> adRecordIds = new ArrayList<>();
+        if (CollUtil.isNotEmpty(preAdList)) {
+            for (DyzAdRecordParam adRecordParam : preAdList) {
+                if (adRecordParam == null) {
+                    continue;
+                }
+                adRecordParam.setUserId(ytDyzUser.getUserId());
+                adRecordParam.setNickName(ytDyzUser.getNickName());
+                adRecordParam.setAppId(ytDyzUser.getAppId());
+                adRecordParam.setLoginStatus(AdRecordEnum.LOGIN_BEFORE.getCode());
+                String recordId = adService.saveRecordAndChangeUser(adRecordParam, ytDyzUser);
+                adRecordIds.add(recordId);
+            }
+        }
+        if(CollUtil.isEmpty(adRecordIds)) {
+            throw new CustomerException(StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), RepMessage.RISK_VISITOR_LOWER_VALUE));
+        }
+        ytDyzUser.setPreAdRecordList(adService.queryRecordByIds(adRecordIds));
     }
+
 }

+ 112 - 60
yt-carp/carp-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -5,46 +5,86 @@
     <insert id="addOne">
         insert into yt_dyz_ad_record
         (
-         record_id,
-         user_id,
-         nick_name,
-         placement_id,
-         ad_source_id,
-         revenue,
-         network_form_id,
-         network_name,
-         network_placement_id,
-         begin_time,
-         finish_time,
-         result_json,
-         ad_source_index,
-         ad_source_type,
-         ecpm,
-         app_id
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
         values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
+    </insert>
+    <insert id="addOneVisitor">
+        insert into yt_dyz_ad_record_visitor
         (
-         #{recordId},
-         #{userId},
-         #{nickName},
-         #{placementId},
-         #{adSourceId},
-         #{revenue},
-         #{networkFormId},
-         #{networkName},
-         #{networkPlacementId},
-         ifnull(#{beginTime}, now()),
-         ifnull(#{finishTime}, now()),
-         #{resultJson},
-         #{adSourceIndex},
-         #{adSourceType},
-         #{ecpm},
-         #{appId}
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
+        values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
     </insert>
     <select id="countByAppIds" resultType="java.lang.Integer">
         select
-            count(record_id)
+        count(record_id)
         from yt_dyz_ad_record
         where ad_source_type = 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -53,48 +93,48 @@
     </select>
     <select id="getByUserId" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id = #{userId}
-          <if test="adsourceType != null and adsourceType!=888">
-              and ad_source_type = #{adsourceType}
-          </if>
+        <if test="adsourceType != null and adsourceType!=888">
+            and ad_source_type = #{adsourceType}
+        </if>
         order by finish_time desc
     </select>
     <select id="getByUserIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id in
-              <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
-                  #{item}
-              </foreach>
+        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
+            #{item}
+        </foreach>
         order by finish_time
     </select>
     <select id="getHourRevenue" resultType="com.ytpm.middle.view.AppRevenueHourVO">
         SELECT
-            HOUR(finish_time) `hour`,
-            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
-            sum( revenue ) revenue
+        HOUR(finish_time) `hour`,
+        DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
+        sum( revenue ) revenue
         FROM
-            yt_dyz_ad_record
+        yt_dyz_ad_record
         WHERE
-            app_id = #{appId}
-            <if test="type != null and type ==1">
-                and DATE(finish_time) = DATE(now())
-            </if>
-            <if test="type != null and type ==2">
-                and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
-            </if>
-            <if test="type != null and type ==3">
-                and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
-            </if>
+        app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(finish_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
         GROUP BY
-            `hour`
+        `hour`
     </select>
     <select id="getRevenueByTime" resultType="java.math.BigDecimal">
         select
-            sum(ar.revenue)
+        sum(ar.revenue)
         from yt_dyz_ad_record ar
         join yt_dyz_user au on ar.user_id = au.user_id
         <where>
@@ -117,16 +157,16 @@
                 </foreach>
             </if>
             <if test="registryTimeBegin != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[>=]]> #{registryTimeBegin}
+                and au.registry_time <![CDATA[>=]]> #{registryTimeBegin}
             </if>
             <if test="registryTimeEnd != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[<=]]> #{registryTimeEnd}
+                and au.registry_time <![CDATA[<=]]> #{registryTimeEnd}
             </if>
         </where>
     </select>
     <select id="getTodayRecord" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
         from yt_dyz_ad_record
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -139,4 +179,16 @@
             and finish_time <![CDATA[<=]]> #{lastDay}
         </if>
     </select>
+    <select id="selectRecordByIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
+        select
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index,
+        revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        <if test="loginStatus != null and loginStatus == 1">
+            from yt_dyz_ad_record_visitor
+        </if>
+        <if test="loginStatus == null or loginStatus != 1">
+            from yt_dyz_ad_record
+        </if>
+        where record_id in <foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
+    </select>
 </mapper>

+ 174 - 135
yt-carp/carp-service/src/main/resources/mapper/AppUserMapper.xml

@@ -4,70 +4,70 @@
     <insert id="addOne" parameterType="com.ytpm.app.model.YtDyzUser">
         insert into yt_dyz_user
         (
-         user_id,
-         nick_name,
-         head_img,
-         registry_time,
-         last_login_time,
-         last_login_ip,
-         login_days,
-         total_video,
-         total_income,
-         red_packet_balance,
-         red_packet_amount,
-         points_balance,
-         points_total,
-         withdraw_total,
-         sign_days,
-         user_status,
-         risk_reason,
-         wx_open_id,
-         ditch_id,
-         platform_id,
-         app_id,
-         power,
-         phone,
-         phone_json,
-         device_id
+            user_id,
+            nick_name,
+            head_img,
+            registry_time,
+            last_login_time,
+            last_login_ip,
+            login_days,
+            total_video,
+            total_income,
+            red_packet_balance,
+            red_packet_amount,
+            points_balance,
+            points_total,
+            withdraw_total,
+            sign_days,
+            user_status,
+            risk_reason,
+            wx_open_id,
+            ditch_id,
+            platform_id,
+            app_id,
+            power,
+            phone,
+            phone_json,
+            device_id
         )
         values
-        (
-         #{userId},
-         #{nickName},
-         #{headImg},
-         #{registryTime},
-         #{lastLoginTime},
-         #{lastLoginIp},
-         #{loginDays},
-         #{totalVideo},
-         #{totalIncome},
-         #{redPacketBalance},
-         #{redPacketAmount},
-         #{pointsBalance},
-         #{pointsTotal},
-         #{withdrawTotal},
-         #{signDays},
-         #{userStatus},
-         #{riskReason},
-         #{wxOpenId},
-         #{ditchId},
-         #{platformId},
-         #{appId},
-         #{power},
-         #{phone},
-         #{phoneJson},
-         #{deviceId}
-        )
+            (
+                #{userId},
+                #{nickName},
+                #{headImg},
+                #{registryTime},
+                #{lastLoginTime},
+                #{lastLoginIp},
+                #{loginDays},
+                #{totalVideo},
+                #{totalIncome},
+                #{redPacketBalance},
+                #{redPacketAmount},
+                #{pointsBalance},
+                #{pointsTotal},
+                #{withdrawTotal},
+                #{signDays},
+                #{userStatus},
+                #{riskReason},
+                #{wxOpenId},
+                #{ditchId},
+                #{platformId},
+                #{appId},
+                #{power},
+                #{phone},
+                #{phoneJson},
+                #{deviceId}
+            )
     </insert>
     <insert id="addPowerRecord">
         insert into yt_dyz_power_record
         (
-         record_id, user_id, type, remark, add_time
+            record_id, user_id, type, remark, add_time
         )
         values
-        (
-         #{recordId},#{userId},#{type},#{remark},#{addTime}
-        )
+            (
+                #{recordId},#{userId},#{type},#{remark},#{addTime}
+            )
     </insert>
     <insert id="saveAppConfig">
         insert into yt_app_default_config
@@ -151,6 +151,24 @@
             <if test="interstitialIntervalTime != null">
                 interstitial_interval_time = #{interstitialIntervalTime}
             </if>
+            <if test="flowIntervalTime != null">
+                flow_interval_time = #{flowIntervalTime}
+            </if>
+            <if test="taskLimitTip != null">
+                task_limit_tip = #{taskLimitTip}
+            </if>
+            <if test="lowValueTip != null">
+                low_value_tip = #{lowValueTip}
+            </if>
+            <if test="brushTip != null">
+                brush_tip = #{brushTip}
+            </if>
+            <if test="startWaitTime != null">
+                start_wait_time = #{startWaitTime}
+            </if>
+            <if test="canCacheVideo != null">
+                can_cache_video = #{canCacheVideo}
+            </if>
         </set>
         where app_id = #{appId}
     </update>
@@ -234,14 +252,14 @@
     </delete>
     <select id="getYtAppUser" resultType="com.ytpm.app.model.YtDyzUser">
         select
-           user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+            user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where wx_open_id = #{openid}
-        and ditch_id = #{ditchId}
+          and ditch_id = #{ditchId}
     </select>
     <select id="queryAll" resultType="com.ytpm.app.view.YtAppUserListView">
         select
-            user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+        user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where 1 = 1
         <if test="userId != null and userId !=''">
@@ -270,9 +288,9 @@
         </if>
         <if test="appIds != null and appIds != ''">
             and app_id in
-                <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
-                    #{item}
-                </foreach>
+            <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
+                #{item}
+            </foreach>
         </if>
         order by user_id desc
     </select>
@@ -320,37 +338,37 @@
     </resultMap>
     <select id="getUserList" resultMap="UserMap">
         select
-            du.user_id,
-            du.head_img,
-            du.nick_name,
-            du.phone,
-            du.device_id,
-            du.registry_time,
-            du.last_login_time,
-            du.last_login_ip,
-            du.login_days,
-            du.total_video,
-            du.total_income,
-            du.red_packet_balance,
-            du.red_packet_amount,
-            du.points_balance,
-            du.points_total,
-            du.withdraw_total,
-            du.sign_days,
-            du.user_status,
-            du.risk_reason,
-            du.wx_open_id,
-            du.ditch_id,
-            du.app_id,
-            du.platform_id,
-            du.power,
-            lr.record_id,
-            lr.login_time,
-            lr.device_brand,
-            lr. device_model,
-            lr.login_ip,
-            lr.operator,
-            lr.ip_addr
+        du.user_id,
+        du.head_img,
+        du.nick_name,
+        du.phone,
+        du.device_id,
+        du.registry_time,
+        du.last_login_time,
+        du.last_login_ip,
+        du.login_days,
+        du.total_video,
+        du.total_income,
+        du.red_packet_balance,
+        du.red_packet_amount,
+        du.points_balance,
+        du.points_total,
+        du.withdraw_total,
+        du.sign_days,
+        du.user_status,
+        du.risk_reason,
+        du.wx_open_id,
+        du.ditch_id,
+        du.app_id,
+        du.platform_id,
+        du.power,
+        lr.record_id,
+        lr.login_time,
+        lr.device_brand,
+        lr. device_model,
+        lr.login_ip,
+        lr.operator,
+        lr.ip_addr
         from yt_dyz_user du
         left join yt_dyz_login_record lr on du.user_id = lr.user_id
         <where>
@@ -430,14 +448,32 @@
     </select>
     <select id="getDefaultConfig" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id appId, secret, app_id platformAppId, app_key platformAppSecret, app_type,user_path,login_path,ad_path,answer_path,power_path
-                     ,can_simulator,taku_app_id,taku_key,taku_banner_pid,taku_interstitial_pid,taku_reward_pid,taku_native_pid,can_use_adb,can_accumulation,can_use_float,can_use_root,ditch_id,power_wait_time,interstitial_interval_time
+            config_id, config_name, open_id as app_id, secret, app_id as platformAppId, app_key as platformAppSecret,
+            app_type,user_path, login_path,ad_path,answer_path,power_path,can_simulator,
+            taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid,
+            can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_type = #{appType}
     </select>
+    <select id="getDefaultConfigByAppId" resultType="com.ytpm.app.view.WxDefaultConfig">
+        select
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
+        from yt_app_default_config
+        where app_id = #{appId}
+    </select>
     <select id="getSecretByAppId" resultType="java.lang.String">
         select
-           secret
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id = #{appId}
     </select>
@@ -452,13 +488,16 @@
             platform_id
         from yt_dyz_user
         where device_id = #{deviceId}
-        and wx_open_id = #{openid}
+          and wx_open_id = #{openid}
         limit 1
     </select>
     <select id="getConfigByIds" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,answer_path,power_path
-        ,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation, ditch_id, power_wait_time, interstitial_interval_time
+        config_id, config_name, open_id, secret, app_id, app_key, app_type, user_path, login_path, ad_path,
+        answer_path, power_path,taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid,
+        taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,can_simulator,
+        ditch_id, power_wait_time, interstitial_interval_time,
+        low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id in
         <foreach collection="appIds.split(',')" item="item" separator="," open="(" close=")">
@@ -467,7 +506,7 @@
     </select>
     <select id="getAdCount" resultType="java.lang.Integer">
         select
-            sum(total_video)
+        sum(total_video)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -485,11 +524,11 @@
     </select>
     <select id="getAppRanking" resultType="com.ytpm.middle.view.AppRankingListVO">
         SELECT
-            u.app_id,
-            sum( ar.revenue ) totalRevenue
+        u.app_id,
+        sum( ar.revenue ) totalRevenue
         FROM
-            yt_dyz_ad_record ar
-            JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -506,21 +545,21 @@
             </if>
         </where>
         GROUP BY
-            u.app_id
+        u.app_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         LIMIT #{limit}
     </select>
     <select id="getUserRanking" resultType="com.ytpm.middle.view.UserRankingListVO">
         SELECT
-            u.user_id,
-            u.nick_name,
-            u.head_img,
-            u.total_video,
-            sum( ar.revenue ) totalIncome
+        u.user_id,
+        u.nick_name,
+        u.head_img,
+        u.total_video,
+        sum( ar.revenue ) totalIncome
         FROM
-            yt_dyz_ad_record ar
-                JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -538,12 +577,12 @@
         </where>
         GROUP BY ar.user_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         limit #{limit}
     </select>
     <select id="countUserByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -552,7 +591,7 @@
     </select>
     <select id="countRevenueByAppIds" resultType="java.math.BigDecimal">
         select
-            sum(total_income)
+        sum(total_income)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -561,7 +600,7 @@
     </select>
     <select id="countBannedByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where user_status > 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -600,8 +639,8 @@
     </select>
     <select id="countRegistryHour" resultType="com.ytpm.middle.view.AppUserHourVO">
         select
-            DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
-            count(user_id) `count`
+        DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
+        count(user_id) `count`
         from yt_dyz_user
         where app_id = #{appId}
         <if test="type != null and type ==1">
@@ -634,7 +673,7 @@
     </select>
     <select id="queryByUserIds" resultType="com.ytpm.app.model.YtDyzUser">
         select
-            user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
+        user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
         from yt_dyz_user
         where user_id in
         <foreach collection="userIds.split(',')" separator="," item="item"  open="(" close=")">
@@ -662,21 +701,21 @@
     </resultMap>
     <select id="queryTodayUserAd" resultMap="UserAdMap">
         select
-            u.user_id,
-            u.app_id,
-            u.nick_name,
-            ar.record_id,
-            ar.placement_id,
-            ar.ad_source_id,
-            ar.ad_source_type,
-            ar.ad_source_index,
-            ar.revenue,
-            ar.ecpm,
-            ar.network_form_id,
-            ar.network_name,
-            ar.network_placement_id,
-            ar.finish_time,
-            ar.begin_time
+        u.user_id,
+        u.app_id,
+        u.nick_name,
+        ar.record_id,
+        ar.placement_id,
+        ar.ad_source_id,
+        ar.ad_source_type,
+        ar.ad_source_index,
+        ar.revenue,
+        ar.ecpm,
+        ar.network_form_id,
+        ar.network_name,
+        ar.network_placement_id,
+        ar.finish_time,
+        ar.begin_time
         from yt_dyz_ad_record ar
         join yt_dyz_user u on ar.user_id = u.user_id
         where ar.ad_source_type = #{adSourceType} and ar.app_id = #{appId} and ar.user_id in

+ 23 - 21
yt-carp/carp-service/src/main/resources/mapper/LoginRecordMapper.xml

@@ -5,28 +5,30 @@
     <insert id="insertOne" parameterType="com.ytpm.app.model.YtDyzLoginRecord">
         insert into yt_dyz_login_record
         (
-         record_id,
-         user_id,
-         login_time,
-         device_brand,
-         device_model,
-         login_ip,
-         operator,
-         ip_addr,
-         phone_json
+            record_id,
+            user_id,
+            login_time,
+            device_brand,
+            device_model,
+            login_ip,
+            operator,
+            ip_addr,
+            phone_json,
+            login_type
         )
         values
-        (
-         #{recordId},
-         #{userId},
-         #{loginTime},
-         #{deviceBrand},
-         #{deviceModel},
-         #{loginIp},
-         #{operator},
-         #{ipAddr},
-         #{phoneJson}
-         );
+            (
+                #{recordId},
+                #{userId},
+                #{loginTime},
+                #{deviceBrand},
+                #{deviceModel},
+                #{loginIp},
+                #{operator},
+                #{ipAddr},
+                #{phoneJson},
+                #{loginType}
+            );
     </insert>
     <select id="getLoginRecords" resultType="com.ytpm.app.model.YtDyzLoginRecord">
         select
@@ -63,7 +65,7 @@
     </select>
     <select id="getLoginRecordByIds" resultType="com.ytpm.app.model.YtDyzLoginRecord">
         select
-            record_id, user_id, login_time, device_brand, device_model, login_ip, operator, ip_addr
+        record_id, user_id, login_time, device_brand, device_model, login_ip, operator, ip_addr
         from yt_dyz_login_record
         where user_id in
         <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">

+ 3 - 1
yt-countstep/countstep-service/src/main/java/com/ytpm/countstep/controller/VisitorController.java

@@ -1,5 +1,6 @@
 package com.ytpm.countstep.controller;
 
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.countstep.dao.AppUserMapper;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
@@ -31,10 +32,11 @@ public class VisitorController {
     @Resource
     private LoginServiceFactory loginServiceFactory;
 
+
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 15 - 0
yt-countstep/countstep-service/src/main/java/com/ytpm/countstep/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 2 - 1
yt-diary/diary-service/src/main/java/com/ytpm/diary/controller/VisitorController.java

@@ -2,6 +2,7 @@ package com.ytpm.diary.controller;
 
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.diary.dao.AppUserMapper;
 import com.ytpm.general.Result;
@@ -34,7 +35,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 1 - 1
yt-diary/diary-service/src/main/java/com/ytpm/diary/dao/AdRecordMapper.java

@@ -24,7 +24,7 @@ public interface AdRecordMapper {
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
 
     /**
      * 查询激励视频记录

+ 1 - 0
yt-diary/diary-service/src/main/java/com/ytpm/diary/service/impl/AdServiceImpl.java

@@ -52,6 +52,7 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.stream.Collectors;
+
 @Slf4j
 @Service
 @RefreshScope

+ 15 - 0
yt-diary/diary-service/src/main/java/com/ytpm/diary/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 1 - 0
yt-diary/diary-service/src/main/java/com/ytpm/diary/service/impl/VisitorLoginServiceImpl.java

@@ -41,6 +41,7 @@ import java.util.Map;
  * @author lih
  * @date 2025/9/4
  */
+
 @Slf4j
 @Component
 public class VisitorLoginServiceImpl extends AbstractLoginService  {

+ 1 - 0
yt-dtw/dtw-service/pom.xml

@@ -38,6 +38,7 @@
         <dependency>
             <groupId>com.zaxxer</groupId>
             <artifactId>HikariCP</artifactId>
+            <version>${hikar-icp.version}</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 3 - 1
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/config/interceptor/HttpInterceptor.java

@@ -1,5 +1,6 @@
 package com.ytpm.dtw.config.interceptor;
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.ModelAndView;
@@ -8,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
 
+@Slf4j
 @Component
 public class HttpInterceptor implements HandlerInterceptor {
 
@@ -16,7 +18,7 @@ public class HttpInterceptor implements HandlerInterceptor {
                              HttpServletResponse response, Object obj) throws Exception {
         // 获取客户端IP地址
         String clientIp = getClientIp(request);
-        System.out.println("好运答题王接收客户端" + clientIp + "发起用户请求");
+        log.error("好运答题王接收客户端" + clientIp + "发起用户请求");
         // 可以在这里添加更多的逻辑,比如记录日志等
         return true;
     }

+ 15 - 0
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/controller/UserController.java

@@ -2,6 +2,7 @@ package com.ytpm.dtw.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
 import com.github.pagehelper.PageInfo;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
@@ -23,9 +24,11 @@ import com.ytpm.dtw.dao.AppUserMapper;
 import com.ytpm.dtw.dao.LoginRecordMapper;
 import com.ytpm.dtw.dao.QuestionMapper;
 import com.ytpm.dtw.redis.RedisService;
+import com.ytpm.feign.RiskFeign;
 import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
+import com.ytpm.general.StatusCode;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import com.ytpm.risk.view.RiskConfigView;
 import com.ytpm.risk.view.RiskTemplateView;
@@ -66,6 +69,9 @@ public class UserController {
     @Autowired
     private RedisService redisService;
 
+    @Autowired
+    private RiskFeign riskFeign;
+
     /**
      * 根据应用ID查询当月注册用户
      */
@@ -168,6 +174,15 @@ public class UserController {
         user.setTodayAnswerCount(questionMapper.getAnswerCount(userId,1));
         user.setHistoryAnswerCount(questionMapper.getAnswerCount(userId,2));
         user.setAnswerRecordList(questionMapper.getAnswerRecords(userId));
+        Result<?> result = riskFeign.checkAdRisk(user);
+        if (result != null) {
+            user.setIfPowerLimit(false);
+            if (result.getCode() != 200) {
+                if ("766".equals(result.getMessage()) || result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotEmpty(result.getMessage())) {
+                    user.setIfPowerLimit(true);
+                }
+            }
+        }
         return Result.resultObjOk(user);
     }
 

+ 2 - 1
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/controller/VisitorController.java

@@ -2,6 +2,7 @@ package com.ytpm.dtw.controller;
 
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.dtw.dao.AppUserMapper;
 import com.ytpm.general.Result;
@@ -34,7 +35,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 2 - 0
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/controller/WxController.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.ytpm.app.enums.AppTypeEnums;
+import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtAppDefaultConfig;
 import com.ytpm.app.model.YtDyzPowerRecord;
 import com.ytpm.app.model.YtDyzUser;
@@ -72,6 +73,7 @@ public class WxController {
         }
         param.setLoginIp(getClientIp(request));
         YtDyzUser old = appUserService.crudForNewTrans(param,wxUserInfo,loginResult);
+        old.setLoginType(LoginType.WX);
         //调用风控服务校验默认风控配置
         old.setRiskCode("313");
         Result<?> result = riskFeign.checkRisk(old);

+ 12 - 1
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/dao/AdRecordMapper.java

@@ -15,10 +15,16 @@ public interface AdRecordMapper {
      * 新增广告记录
      */
     void addOne(YtDyzAdRecord adRecord);
+
+    /**
+     * 保存游客广告记录
+     */
+    void addOneVisitor(YtDyzAdRecord adRecord);
+
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
 
     /**
      * 查询激励视频记录
@@ -44,4 +50,9 @@ public interface AdRecordMapper {
      * 查询今日广告
      */
     List<YtDyzAdRecord> getTodayRecord(@Param("appIds")String appIds,@Param("firstDay")String firstDay,@Param("lastDay")String lastDay);
+
+    /**
+     * 查询指定广告记录
+     */
+    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
 }

+ 2 - 0
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/dao/AppUserMapper.java

@@ -90,6 +90,8 @@ public interface AppUserMapper {
      */
     WxDefaultConfig getDefaultConfig(@Param("appType") int appType);
 
+    WxDefaultConfig getDefaultConfigByAppId(@Param("appId") String appId);
+
     /**
      * 根据微信openid查询用户
      */

+ 8 - 3
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/monitor/RedisKeyExpirationListener.java

@@ -6,6 +6,7 @@ import com.ytpm.dtw.dao.AppUserMapper;
 import com.ytpm.feign.RiskFeign;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.data.redis.connection.Message;
 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
@@ -28,7 +29,8 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
     private AppUserMapper appUserMapper;
     @Resource
     private RiskFeign riskFeign;
-
+    @Value("${spring.application.name:}")
+    private String applicationName;
     /**
      * Creates new {@link } for {@code __keyevent@*__:expired} messages.
      *
@@ -43,8 +45,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
      */
     @Override
     public void onMessage(Message message, byte[] pattern) {
-        String key = String.valueOf(message);
-        log.error("App-Service 发现预定风控用户:{}",key);
+       String key = String.valueOf(message);
+//        log.error("App-Service 发现预定风控用户:{}",key);
+        //        if (!key.endsWith(applicationName)) {
+//            return;
+//        }
         if(key.startsWith("lock_")){
             String[] arr = key.split("_");
             lockUser(arr[1], UserStatusEnum.RISK.getCode());

+ 6 - 0
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/service/AdService.java

@@ -2,6 +2,8 @@ package com.ytpm.dtw.service;
 
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
+import com.ytpm.app.model.YtDyzAdRecord;
+import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.general.Result;
 import com.ytpm.middle.view.DashboardRankingListVO;
@@ -46,4 +48,8 @@ public interface AdService {
      * 查询代理商首页广告数据统计
      */
     List<AgentAdGroupStaticsVO> getAgentProfit(String appIds);
+
+    String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user);
+
+    List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds);
 }

+ 36 - 7
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/service/impl/AdServiceImpl.java

@@ -4,14 +4,17 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import com.ytpm.advertise.enums.AdPlatformTypeEnum;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
 import com.ytpm.app.model.YtDyzAdRecord;
 import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
+import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.dtw.dao.AdRecordMapper;
 import com.ytpm.dtw.dao.AppUserMapper;
 import com.ytpm.dtw.service.AdService;
@@ -27,6 +30,7 @@ import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
 import com.ytpm.middle.view.DashboardRiskVO;
 import com.ytpm.middle.view.UserRankingListVO;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -49,6 +53,7 @@ import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Service
 @RefreshScope
 public class AdServiceImpl implements AdService {
@@ -70,6 +75,7 @@ public class AdServiceImpl implements AdService {
     @Transactional(rollbackFor = Exception.class)
     public Result<?> saveRecord(DyzAdRecordParam param) {
         YtDyzUser user = appUserMapper.selectPrimaryKey(param.getUserId());
+        log.error(StrUtil.format("[saveRecord]:{} ", param.getBeginTime()));
         if(Objects.isNull(user)){
             return Result.resultOk(RepMessage.SAVE_SUCCESS);
         }
@@ -79,9 +85,22 @@ public class AdServiceImpl implements AdService {
         saveRecordAndChangeUser(param, user);
         //调用风控广告校验
         if(AdSourceTypeEnum.rewarded_video.getAdSourceType() == param.getAdSourceType()){
+            WxDefaultConfig config = appUserMapper.getDefaultConfigByAppId(user.getAppId());
+            String format = StrUtil.emptyToDefault(config.getTaskLimitTip(), "当前设备完成任务次数过多,请{}后重试!");
+            user.setPowerLimitTip(format);
             Result<?> result = riskFeign.checkAdRisk(user);
-            if(result.getCode()!=200){
-                return new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+            if (result.getCode() != 200) {
+                Result<Object> resultObj = new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+                // 766处理
+                if("766".contains(result.getMessage())){
+                    resultObj.setData(result.getMessage());
+                }
+                else if (result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotBlank(result.getMessage())) {
+                    // 体力不再获取处理
+                    resultObj.setMessage(result.getMessage());
+                    resultObj.setData("767");
+                }
+                return resultObj;
             }
         }
         return Result.resultOk(RepMessage.SAVE_SUCCESS);
@@ -233,17 +252,15 @@ public class AdServiceImpl implements AdService {
         cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),actualMaximum,23,59,59);
         String lastDay = sdf.format(cal.getTime());
         List<YtDyzAdRecord> dyzMonthRecords = adRecordMapper.getTodayRecord(appIds,firstDay,lastDay);
-
         if(CollUtil.isNotEmpty(dyzMonthRecords)){monthRecords.addAll(dyzMonthRecords);}
         records = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),new Date())).collect(Collectors.toList());
 
-        cal = Calendar.getInstance();
+        cal = Calendar.getInstance(); // 获取当前日期时间
         cal.add(Calendar.DATE, -1); // 昨天的日期时间
         Date yest = cal.getTime();
         yestRecords = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),yest)).collect(Collectors.toList());
-
         //广告平台分组
         Map<String, List<YtDyzAdRecord>> networkMap = records.stream().collect(
                 Collectors.groupingBy(YtDyzAdRecord::getNetworkFormId));
@@ -288,7 +305,8 @@ public class AdServiceImpl implements AdService {
      *  始终创建新的事务以保障子方法的独立事务
      */
 //    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
-    public void saveRecordAndChangeUser(DyzAdRecordParam param,YtDyzUser user) {
+    @Override
+    public String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user) {
         //增加广告记录
         YtDyzAdRecord adRecord = new YtDyzAdRecord();
         if(Objects.isNull(param.getBeginTime())){
@@ -297,12 +315,23 @@ public class AdServiceImpl implements AdService {
         BeanUtils.copyProperties(param, adRecord);
         adRecord.setRecordId(IdUtil.fastSimpleUUID());
         adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
-        adRecordMapper.addOne(adRecord);
+        if (param.getLoginStatus() != null && AdRecordEnum.LOGIN_BEFORE.getCode().equals(param.getLoginStatus())) {
+            adRecordMapper.addOneVisitor(adRecord);
+        } else {
+            adRecordMapper.addOne(adRecord);
+        }
         //修改用户信息, 广告次数+1  总收益 + revenue
         YtDyzUser dyzUser = new YtDyzUser();
         dyzUser.setUserId(user.getUserId());
         dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo())?1:(user.getTotalVideo()+1));
         dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
         appUserMapper.updateUser(dyzUser);
+        return adRecord.getRecordId();
     }
+
+    @Override
+    public List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds) {
+        return adRecordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
+    }
+
 }

+ 15 - 0
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 50 - 5
yt-dtw/dtw-service/src/main/java/com/ytpm/dtw/service/impl/VisitorLoginServiceImpl.java

@@ -1,30 +1,38 @@
 package com.ytpm.dtw.service.impl;
 
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzLoginRecord;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.app.param.LoginParam;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.constant.StrConstant;
 import com.ytpm.dtw.dao.AppUserMapper;
 import com.ytpm.dtw.dao.LoginRecordMapper;
 import com.ytpm.dtw.dao.QuestionMapper;
 import com.ytpm.dtw.redis.RedisService;
+import com.ytpm.dtw.service.AdService;
 import com.ytpm.feign.RiskFeign;
+import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.handle.AbstractLoginService;
 import com.ytpm.handle.CommonException;
+import com.ytpm.handle.CustomerException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -48,6 +56,8 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
     private RiskFeign riskFeign;
     @Autowired
     private RedisService redisService;
+    @Autowired
+    private AdService adService;
 
     @Override
     protected WxDefaultConfig getLoginConfig(Integer appType) {
@@ -67,6 +77,20 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         return LoginType.VISITOR;
     }
 
+    @Override
+    protected void updateUserStatus(YtDyzUser ytDyzUser, UserStatusEnum statusEnum, String reason) {
+        if (ytDyzUser != null) {
+            YtDyzUser newUser = new YtDyzUser();
+            newUser.setUserId(ytDyzUser.getUserId());
+            newUser.setUserStatus(statusEnum.getCode());
+            newUser.setRiskReason(reason);
+            if(UserStatusEnum.NORMAL == statusEnum){
+                newUser.setRiskReason("");
+            }
+            appUserMapper.updateUser(newUser);
+        }
+    }
+
     @Override
     protected void validateParams(LoginParam loginParam, HttpServletRequest request) {
 
@@ -142,6 +166,7 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
      */
     @Override
     protected void setExtInfo(YtDyzUser old, Map<String, Object> paramMap) {
+        super.setExtInfo(old, paramMap);
         old.setLastQuestionId(questionMapper.getLastQuestionId(old.getUserId()));
         old.setTodayAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 1));
         old.setHistoryAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 2));
@@ -149,10 +174,30 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         old.setLoginRecordList(loginRecordMapper.getLoginRecords(old.getUserId()));
     }
 
-    @Override
-    protected void beforeDeadWithUserCrud(LoginParam loginParam, YtDyzUser ytDyzUser, Map<String, Object> paramMap) {
-        super.beforeDeadWithUserCrud(loginParam, ytDyzUser, paramMap);
-        // 新增风控 相关广告源记录 ecpm  和预估收益 小于 各自 阈值,登陆返回 301
 
+    // 仅保存登陆时的三条广告信息 并传入登陆实体用于后续 risk风控校验
+    protected void saveVisitorAdRecord(YtDyzUser ytDyzUser, LoginParam loginParam, WxDefaultConfig defaultConfig) {
+        super.saveVisitorAdRecord(ytDyzUser, loginParam, defaultConfig);
+        VisitorLoginParam visitorLoginParam = (VisitorLoginParam) loginParam;
+        List<DyzAdRecordParam> preAdList = visitorLoginParam.getPreAdList();
+        List<String> adRecordIds = new ArrayList<>();
+        if (CollUtil.isNotEmpty(preAdList)) {
+            for (DyzAdRecordParam adRecordParam : preAdList) {
+                if (adRecordParam == null) {
+                    continue;
+                }
+                adRecordParam.setUserId(ytDyzUser.getUserId());
+                adRecordParam.setNickName(ytDyzUser.getNickName());
+                adRecordParam.setAppId(ytDyzUser.getAppId());
+                adRecordParam.setLoginStatus(AdRecordEnum.LOGIN_BEFORE.getCode());
+                String recordId = adService.saveRecordAndChangeUser(adRecordParam, ytDyzUser);
+                adRecordIds.add(recordId);
+            }
+        }
+        if(CollUtil.isEmpty(adRecordIds)) {
+            throw new CustomerException(StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), RepMessage.RISK_VISITOR_LOWER_VALUE));
+        }
+        ytDyzUser.setPreAdRecordList(adService.queryRecordByIds(adRecordIds));
     }
-}
+
+}

+ 112 - 60
yt-dtw/dtw-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -5,46 +5,86 @@
     <insert id="addOne">
         insert into yt_dyz_ad_record
         (
-         record_id,
-         user_id,
-         nick_name,
-         placement_id,
-         ad_source_id,
-         revenue,
-         network_form_id,
-         network_name,
-         network_placement_id,
-         begin_time,
-         finish_time,
-         result_json,
-         ad_source_index,
-         ad_source_type,
-         ecpm,
-         app_id
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
         values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
+    </insert>
+    <insert id="addOneVisitor">
+        insert into yt_dyz_ad_record_visitor
         (
-         #{recordId},
-         #{userId},
-         #{nickName},
-         #{placementId},
-         #{adSourceId},
-         #{revenue},
-         #{networkFormId},
-         #{networkName},
-         #{networkPlacementId},
-         ifnull(#{beginTime}, now()),
-         ifnull(#{finishTime}, now()),
-         #{resultJson},
-         #{adSourceIndex},
-         #{adSourceType},
-         #{ecpm},
-         #{appId}
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
+        values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
     </insert>
     <select id="countByAppIds" resultType="java.lang.Integer">
         select
-            count(record_id)
+        count(record_id)
         from yt_dyz_ad_record
         where ad_source_type = 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -53,48 +93,48 @@
     </select>
     <select id="getByUserId" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id = #{userId}
-          <if test="adsourceType != null and adsourceType!=888">
-              and ad_source_type = #{adsourceType}
-          </if>
+        <if test="adsourceType != null and adsourceType!=888">
+            and ad_source_type = #{adsourceType}
+        </if>
         order by finish_time desc
     </select>
     <select id="getByUserIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id in
-              <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
-                  #{item}
-              </foreach>
+        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
+            #{item}
+        </foreach>
         order by finish_time
     </select>
     <select id="getHourRevenue" resultType="com.ytpm.middle.view.AppRevenueHourVO">
         SELECT
-            HOUR(finish_time) `hour`,
-            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
-            sum( revenue ) revenue
+        HOUR(finish_time) `hour`,
+        DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
+        sum( revenue ) revenue
         FROM
-            yt_dyz_ad_record
+        yt_dyz_ad_record
         WHERE
-            app_id = #{appId}
-            <if test="type != null and type ==1">
-                and DATE(finish_time) = DATE(now())
-            </if>
-            <if test="type != null and type ==2">
-                and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
-            </if>
-            <if test="type != null and type ==3">
-                and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
-            </if>
+        app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(finish_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
         GROUP BY
-            `hour`
+        `hour`
     </select>
     <select id="getRevenueByTime" resultType="java.math.BigDecimal">
         select
-            sum(ar.revenue)
+        sum(ar.revenue)
         from yt_dyz_ad_record ar
         join yt_dyz_user au on ar.user_id = au.user_id
         <where>
@@ -117,16 +157,16 @@
                 </foreach>
             </if>
             <if test="registryTimeBegin != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[>=]]> #{registryTimeBegin}
+                and au.registry_time <![CDATA[>=]]> #{registryTimeBegin}
             </if>
             <if test="registryTimeEnd != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[<=]]> #{registryTimeEnd}
+                and au.registry_time <![CDATA[<=]]> #{registryTimeEnd}
             </if>
         </where>
     </select>
     <select id="getTodayRecord" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
         from yt_dyz_ad_record
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -139,4 +179,16 @@
             and finish_time <![CDATA[<=]]> #{lastDay}
         </if>
     </select>
+    <select id="selectRecordByIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
+        select
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index,
+        revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        <if test="loginStatus != null and loginStatus == 1">
+            from yt_dyz_ad_record_visitor
+        </if>
+        <if test="loginStatus == null or loginStatus != 1">
+            from yt_dyz_ad_record
+        </if>
+        where record_id in <foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
+    </select>
 </mapper>

+ 177 - 135
yt-dtw/dtw-service/src/main/resources/mapper/AppUserMapper.xml

@@ -4,70 +4,70 @@
     <insert id="addOne" parameterType="com.ytpm.app.model.YtDyzUser">
         insert into yt_dyz_user
         (
-         user_id,
-         nick_name,
-         head_img,
-         registry_time,
-         last_login_time,
-         last_login_ip,
-         login_days,
-         total_video,
-         total_income,
-         red_packet_balance,
-         red_packet_amount,
-         points_balance,
-         points_total,
-         withdraw_total,
-         sign_days,
-         user_status,
-         risk_reason,
-         wx_open_id,
-         ditch_id,
-         platform_id,
-         app_id,
-         power,
-         phone,
-         phone_json,
-         device_id
+            user_id,
+            nick_name,
+            head_img,
+            registry_time,
+            last_login_time,
+            last_login_ip,
+            login_days,
+            total_video,
+            total_income,
+            red_packet_balance,
+            red_packet_amount,
+            points_balance,
+            points_total,
+            withdraw_total,
+            sign_days,
+            user_status,
+            risk_reason,
+            wx_open_id,
+            ditch_id,
+            platform_id,
+            app_id,
+            power,
+            phone,
+            phone_json,
+            device_id
         )
         values
-        (
-         #{userId},
-         #{nickName},
-         #{headImg},
-         #{registryTime},
-         #{lastLoginTime},
-         #{lastLoginIp},
-         #{loginDays},
-         #{totalVideo},
-         #{totalIncome},
-         #{redPacketBalance},
-         #{redPacketAmount},
-         #{pointsBalance},
-         #{pointsTotal},
-         #{withdrawTotal},
-         #{signDays},
-         #{userStatus},
-         #{riskReason},
-         #{wxOpenId},
-         #{ditchId},
-         #{platformId},
-         #{appId},
-         #{power},
-         #{phone},
-         #{phoneJson},
-         #{deviceId}
-        )
+            (
+                #{userId},
+                #{nickName},
+                #{headImg},
+                #{registryTime},
+                #{lastLoginTime},
+                #{lastLoginIp},
+                #{loginDays},
+                #{totalVideo},
+                #{totalIncome},
+                #{redPacketBalance},
+                #{redPacketAmount},
+                #{pointsBalance},
+                #{pointsTotal},
+                #{withdrawTotal},
+                #{signDays},
+                #{userStatus},
+                #{riskReason},
+                #{wxOpenId},
+                #{ditchId},
+                #{platformId},
+                #{appId},
+                #{power},
+                #{phone},
+                #{phoneJson},
+                #{deviceId}
+            )
     </insert>
     <insert id="addPowerRecord">
         insert into yt_dyz_power_record
         (
-         record_id, user_id, type, remark, add_time
+            record_id, user_id, type, remark, add_time
         )
         values
-        (
-         #{recordId},#{userId},#{type},#{remark},#{addTime}
-        )
+            (
+                #{recordId},#{userId},#{type},#{remark},#{addTime}
+            )
     </insert>
     <insert id="saveAppConfig">
         insert into yt_app_default_config
@@ -151,6 +151,24 @@
             <if test="interstitialIntervalTime != null">
                 interstitial_interval_time = #{interstitialIntervalTime}
             </if>
+            <if test="flowIntervalTime != null">
+                flow_interval_time = #{flowIntervalTime}
+            </if>
+            <if test="taskLimitTip != null">
+                task_limit_tip = #{taskLimitTip}
+            </if>
+            <if test="lowValueTip != null">
+                low_value_tip = #{lowValueTip}
+            </if>
+            <if test="brushTip != null">
+                brush_tip = #{brushTip}
+            </if>
+            <if test="startWaitTime != null">
+                start_wait_time = #{startWaitTime}
+            </if>
+            <if test="canCacheVideo != null">
+                can_cache_video = #{canCacheVideo}
+            </if>
         </set>
         where app_id = #{appId}
     </update>
@@ -220,6 +238,9 @@
             <if test="wxOpenId != null">
                 wx_open_id = #{wxOpenId},
             </if>
+            <if test="phoneJson != null">
+                phone_json = #{phoneJson},
+            </if>
             <if test="platformId != null">
                 platform_id = #{platformId}
             </if>
@@ -231,14 +252,14 @@
     </delete>
     <select id="getYtAppUser" resultType="com.ytpm.app.model.YtDyzUser">
         select
-           user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+            user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where wx_open_id = #{openid}
-        and ditch_id = #{ditchId}
+          and ditch_id = #{ditchId}
     </select>
     <select id="queryAll" resultType="com.ytpm.app.view.YtAppUserListView">
         select
-            user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+        user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where 1 = 1
         <if test="userId != null and userId !=''">
@@ -267,9 +288,9 @@
         </if>
         <if test="appIds != null and appIds != ''">
             and app_id in
-                <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
-                    #{item}
-                </foreach>
+            <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
+                #{item}
+            </foreach>
         </if>
         order by user_id desc
     </select>
@@ -317,37 +338,37 @@
     </resultMap>
     <select id="getUserList" resultMap="UserMap">
         select
-            du.user_id,
-            du.head_img,
-            du.nick_name,
-            du.phone,
-            du.device_id,
-            du.registry_time,
-            du.last_login_time,
-            du.last_login_ip,
-            du.login_days,
-            du.total_video,
-            du.total_income,
-            du.red_packet_balance,
-            du.red_packet_amount,
-            du.points_balance,
-            du.points_total,
-            du.withdraw_total,
-            du.sign_days,
-            du.user_status,
-            du.risk_reason,
-            du.wx_open_id,
-            du.ditch_id,
-            du.app_id,
-            du.platform_id,
-            du.power,
-            lr.record_id,
-            lr.login_time,
-            lr.device_brand,
-            lr. device_model,
-            lr.login_ip,
-            lr.operator,
-            lr.ip_addr
+        du.user_id,
+        du.head_img,
+        du.nick_name,
+        du.phone,
+        du.device_id,
+        du.registry_time,
+        du.last_login_time,
+        du.last_login_ip,
+        du.login_days,
+        du.total_video,
+        du.total_income,
+        du.red_packet_balance,
+        du.red_packet_amount,
+        du.points_balance,
+        du.points_total,
+        du.withdraw_total,
+        du.sign_days,
+        du.user_status,
+        du.risk_reason,
+        du.wx_open_id,
+        du.ditch_id,
+        du.app_id,
+        du.platform_id,
+        du.power,
+        lr.record_id,
+        lr.login_time,
+        lr.device_brand,
+        lr. device_model,
+        lr.login_ip,
+        lr.operator,
+        lr.ip_addr
         from yt_dyz_user du
         left join yt_dyz_login_record lr on du.user_id = lr.user_id
         <where>
@@ -427,14 +448,32 @@
     </select>
     <select id="getDefaultConfig" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id appId, secret, app_id platformAppId, app_key platformAppSecret, app_type,user_path,login_path,ad_path,answer_path,power_path
-                     ,can_simulator,taku_app_id,taku_key,taku_banner_pid,taku_interstitial_pid,taku_reward_pid,taku_native_pid,can_use_adb,can_accumulation,can_use_float,can_use_root,ditch_id,power_wait_time,interstitial_interval_time
+            config_id, config_name, open_id as app_id, secret, app_id as platformAppId, app_key as platformAppSecret,
+            app_type,user_path, login_path,ad_path,answer_path,power_path,can_simulator,
+            taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid,
+            can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_type = #{appType}
     </select>
+    <select id="getDefaultConfigByAppId" resultType="com.ytpm.app.view.WxDefaultConfig">
+        select
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
+        from yt_app_default_config
+        where app_id = #{appId}
+    </select>
     <select id="getSecretByAppId" resultType="java.lang.String">
         select
-           secret
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id = #{appId}
     </select>
@@ -449,13 +488,16 @@
             platform_id
         from yt_dyz_user
         where device_id = #{deviceId}
-        and wx_open_id = #{openid}
+          and wx_open_id = #{openid}
         limit 1
     </select>
     <select id="getConfigByIds" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,answer_path,power_path
-        ,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation, ditch_id, power_wait_time, interstitial_interval_time
+        config_id, config_name, open_id, secret, app_id, app_key, app_type, user_path, login_path, ad_path,
+        answer_path, power_path,taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid,
+        taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,can_simulator,
+        ditch_id, power_wait_time, interstitial_interval_time,
+        low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id in
         <foreach collection="appIds.split(',')" item="item" separator="," open="(" close=")">
@@ -464,7 +506,7 @@
     </select>
     <select id="getAdCount" resultType="java.lang.Integer">
         select
-            sum(total_video)
+        sum(total_video)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -482,11 +524,11 @@
     </select>
     <select id="getAppRanking" resultType="com.ytpm.middle.view.AppRankingListVO">
         SELECT
-            u.app_id,
-            sum( ar.revenue ) totalRevenue
+        u.app_id,
+        sum( ar.revenue ) totalRevenue
         FROM
-            yt_dyz_ad_record ar
-            JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -503,21 +545,21 @@
             </if>
         </where>
         GROUP BY
-            u.app_id
+        u.app_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         LIMIT #{limit}
     </select>
     <select id="getUserRanking" resultType="com.ytpm.middle.view.UserRankingListVO">
         SELECT
-            u.user_id,
-            u.nick_name,
-            u.head_img,
-            u.total_video,
-            sum( ar.revenue ) totalIncome
+        u.user_id,
+        u.nick_name,
+        u.head_img,
+        u.total_video,
+        sum( ar.revenue ) totalIncome
         FROM
-            yt_dyz_ad_record ar
-                JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -535,12 +577,12 @@
         </where>
         GROUP BY ar.user_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         limit #{limit}
     </select>
     <select id="countUserByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -549,7 +591,7 @@
     </select>
     <select id="countRevenueByAppIds" resultType="java.math.BigDecimal">
         select
-            sum(total_income)
+        sum(total_income)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -558,7 +600,7 @@
     </select>
     <select id="countBannedByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where user_status > 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -597,8 +639,8 @@
     </select>
     <select id="countRegistryHour" resultType="com.ytpm.middle.view.AppUserHourVO">
         select
-            DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
-            count(user_id) `count`
+        DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
+        count(user_id) `count`
         from yt_dyz_user
         where app_id = #{appId}
         <if test="type != null and type ==1">
@@ -631,7 +673,7 @@
     </select>
     <select id="queryByUserIds" resultType="com.ytpm.app.model.YtDyzUser">
         select
-            user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
+        user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
         from yt_dyz_user
         where user_id in
         <foreach collection="userIds.split(',')" separator="," item="item"  open="(" close=")">
@@ -659,21 +701,21 @@
     </resultMap>
     <select id="queryTodayUserAd" resultMap="UserAdMap">
         select
-            u.user_id,
-            u.app_id,
-            u.nick_name,
-            ar.record_id,
-            ar.placement_id,
-            ar.ad_source_id,
-            ar.ad_source_type,
-            ar.ad_source_index,
-            ar.revenue,
-            ar.ecpm,
-            ar.network_form_id,
-            ar.network_name,
-            ar.network_placement_id,
-            ar.finish_time,
-            ar.begin_time
+        u.user_id,
+        u.app_id,
+        u.nick_name,
+        ar.record_id,
+        ar.placement_id,
+        ar.ad_source_id,
+        ar.ad_source_type,
+        ar.ad_source_index,
+        ar.revenue,
+        ar.ecpm,
+        ar.network_form_id,
+        ar.network_name,
+        ar.network_placement_id,
+        ar.finish_time,
+        ar.begin_time
         from yt_dyz_ad_record ar
         join yt_dyz_user u on ar.user_id = u.user_id
         where ar.ad_source_type = #{adSourceType} and ar.app_id = #{appId} and ar.user_id in

+ 24 - 23
yt-dtw/dtw-service/src/main/resources/mapper/LoginRecordMapper.xml

@@ -5,28 +5,30 @@
     <insert id="insertOne" parameterType="com.ytpm.app.model.YtDyzLoginRecord">
         insert into yt_dyz_login_record
         (
-         record_id,
-         user_id,
-         login_time,
-         device_brand,
-         device_model,
-         login_ip,
-         operator,
-         ip_addr,
-         phone_json
+            record_id,
+            user_id,
+            login_time,
+            device_brand,
+            device_model,
+            login_ip,
+            operator,
+            ip_addr,
+            phone_json,
+            login_type
         )
         values
-        (
-         #{recordId},
-         #{userId},
-         #{loginTime},
-         #{deviceBrand},
-         #{deviceModel},
-         #{loginIp},
-         #{operator},
-         #{ipAddr},
-         #{phoneJson}
-         );
+            (
+                #{recordId},
+                #{userId},
+                #{loginTime},
+                #{deviceBrand},
+                #{deviceModel},
+                #{loginIp},
+                #{operator},
+                #{ipAddr},
+                #{phoneJson},
+                #{loginType}
+            );
     </insert>
     <select id="getLoginRecords" resultType="com.ytpm.app.model.YtDyzLoginRecord">
         select
@@ -63,19 +65,18 @@
     </select>
     <select id="getLoginRecordByIds" resultType="com.ytpm.app.model.YtDyzLoginRecord">
         select
-            record_id, user_id, login_time, device_brand, device_model, login_ip, operator, ip_addr
+        record_id, user_id, login_time, device_brand, device_model, login_ip, operator, ip_addr
         from yt_dyz_login_record
         where user_id in
         <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
             #{item}
         </foreach>
     </select>
+
     <select id="getTodayLoginCount" resultType="java.lang.Integer">
         select
             count(*)
         from yt_dyz_login_record
         where user_id = #{userId} and DATE(login_time) = current_date()
     </select>
-
-
 </mapper>

+ 2 - 1
yt-emoticons/emoticons-service/src/main/java/com/ytpm/emoticons/controller/VisitorController.java

@@ -2,6 +2,7 @@ package com.ytpm.emoticons.controller;
 
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.emoticons.dao.AppUserMapper;
 import com.ytpm.general.Result;
@@ -34,7 +35,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 15 - 0
yt-emoticons/emoticons-service/src/main/java/com/ytpm/emoticons/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 1 - 0
yt-funarith/funarith-service/pom.xml

@@ -44,6 +44,7 @@
         <dependency>
             <groupId>com.zaxxer</groupId>
             <artifactId>HikariCP</artifactId>
+            <version>${hikar-icp.version}</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 3 - 1
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/config/interceptor/HttpInterceptor.java

@@ -1,5 +1,6 @@
 package com.ytpm.funarith.config.interceptor;
 
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.HandlerInterceptor;
 import org.springframework.web.servlet.ModelAndView;
@@ -8,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
 
+@Slf4j
 @Component
 public class HttpInterceptor implements HandlerInterceptor {
 
@@ -16,7 +18,7 @@ public class HttpInterceptor implements HandlerInterceptor {
                              HttpServletResponse response, Object obj) throws Exception {
         // 获取客户端IP地址
         String clientIp = getClientIp(request);
-        System.out.println("天天趣算术接收客户端" + clientIp + "发起用户请求");
+        log.error("天天趣算术接收客户端" + clientIp + "发起用户请求");
         // 可以在这里添加更多的逻辑,比如记录日志等
         return true;
     }

+ 15 - 0
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/controller/UserController.java

@@ -2,6 +2,7 @@ package com.ytpm.funarith.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
 import com.github.pagehelper.PageInfo;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
@@ -18,6 +19,7 @@ import com.ytpm.app.param.AppUserTodayBannedParam;
 import com.ytpm.app.param.YtAppUserListParam;
 import com.ytpm.app.view.HourCountView;
 import com.ytpm.app.view.YtAppUserListView;
+import com.ytpm.feign.RiskFeign;
 import com.ytpm.funarith.dao.AdRecordMapper;
 import com.ytpm.funarith.dao.AppUserMapper;
 import com.ytpm.funarith.dao.LoginRecordMapper;
@@ -26,6 +28,7 @@ import com.ytpm.funarith.redis.RedisService;
 import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
+import com.ytpm.general.StatusCode;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import com.ytpm.risk.view.RiskConfigView;
 import com.ytpm.risk.view.RiskTemplateView;
@@ -66,6 +69,9 @@ public class UserController {
     @Autowired
     private RedisService redisService;
 
+    @Autowired
+    private RiskFeign riskFeign;
+
     /**
      * 根据应用ID查询当月注册用户
      */
@@ -167,6 +173,15 @@ public class UserController {
         user.setTodayAnswerCount(questionMapper.getAnswerCount(userId,1));
         user.setHistoryAnswerCount(questionMapper.getAnswerCount(userId,2));
         user.setAnswerRecordList(questionMapper.getAnswerRecords(userId));
+        Result<?> result = riskFeign.checkAdRisk(user);
+        if (result != null) {
+            user.setIfPowerLimit(false);
+            if (result.getCode() != 200) {
+                if ("766".equals(result.getMessage()) || result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotEmpty(result.getMessage())) {
+                    user.setIfPowerLimit(true);
+                }
+            }
+        }
         return Result.resultObjOk(user);
     }
 

+ 2 - 1
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/controller/VisitorController.java

@@ -2,6 +2,7 @@ package com.ytpm.funarith.controller;
 
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.param.WxLoginParam;
 import com.ytpm.funarith.dao.AppUserMapper;
 import com.ytpm.general.Result;
@@ -34,7 +35,7 @@ public class VisitorController {
     @PostMapping("/login")
     @ApiOperation("游客登录")
     @Transactional(rollbackFor = Exception.class)
-    public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
+    public Result<YtDyzUser> visitorLogin(@RequestBody VisitorLoginParam param, HttpServletRequest request) {
         return loginServiceFactory.login(LoginType.VISITOR, param, request);
     }
 

+ 2 - 0
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/controller/WxController.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.ytpm.app.enums.AppTypeEnums;
+import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtAppDefaultConfig;
 import com.ytpm.app.model.YtDyzPowerRecord;
 import com.ytpm.app.model.YtDyzUser;
@@ -72,6 +73,7 @@ public class WxController {
         }
         param.setLoginIp(getClientIp(request));
         YtDyzUser old = appUserService.crudForNewTrans(param,wxUserInfo,loginResult);
+        old.setLoginType(LoginType.WX);
         //调用风控服务校验默认风控配置
         old.setRiskCode("313");
         Result<?> result = riskFeign.checkRisk(old);

+ 13 - 1
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/dao/AdRecordMapper.java

@@ -15,10 +15,16 @@ public interface AdRecordMapper {
      * 新增广告记录
      */
     void addOne(YtDyzAdRecord adRecord);
+
+    /**
+     * 保存游客广告记录
+     */
+    void addOneVisitor(YtDyzAdRecord adRecord);
+
     /**
      * 查询用户的广告记录
      */
-    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId,@Param("adsourceType") Integer adsourceType);
+    List<YtDyzAdRecord> getByUserId(@Param("userId") String userId, @Param("adsourceType") Integer adsourceType);
 
     /**
      * 查询激励视频记录
@@ -44,4 +50,10 @@ public interface AdRecordMapper {
      * 查询今日广告
      */
     List<YtDyzAdRecord> getTodayRecord(@Param("appIds")String appIds,@Param("firstDay")String firstDay,@Param("lastDay")String lastDay);
+
+    /**
+     * 查询指定广告记录
+     */
+    List<YtDyzAdRecord> selectRecordByIds(@Param("loginStatus") Integer loginStatus, @Param("ids") List<String> adRecordIds);
 }
+

+ 2 - 0
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/dao/AppUserMapper.java

@@ -90,6 +90,8 @@ public interface AppUserMapper {
      */
     WxDefaultConfig getDefaultConfig(@Param("appType") int appType);
 
+    WxDefaultConfig getDefaultConfigByAppId(@Param("appId") String appId);
+
     /**
      * 根据微信openid查询用户
      */

+ 8 - 3
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/monitor/RedisKeyExpirationListener.java

@@ -6,6 +6,7 @@ import com.ytpm.feign.RiskFeign;
 import com.ytpm.funarith.dao.AppUserMapper;
 import com.ytpm.risk.enums.BannedTypeEnum;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.data.redis.connection.Message;
 import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
@@ -28,7 +29,8 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
     private AppUserMapper appUserMapper;
     @Resource
     private RiskFeign riskFeign;
-
+    @Value("${spring.application.name:}")
+    private String applicationName;
     /**
      * Creates new {@link } for {@code __keyevent@*__:expired} messages.
      *
@@ -43,8 +45,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
      */
     @Override
     public void onMessage(Message message, byte[] pattern) {
-        String key = String.valueOf(message);
-        log.error("App-Service 发现预定风控用户:{}",key);
+       String key = String.valueOf(message);
+//        log.error("App-Service 发现预定风控用户:{}",key);
+        //        if (!key.endsWith(applicationName)) {
+//            return;
+//        }
         if(key.startsWith("lock_")){
             String[] arr = key.split("_");
             lockUser(arr[1], UserStatusEnum.RISK.getCode());

+ 6 - 0
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/service/AdService.java

@@ -2,6 +2,8 @@ package com.ytpm.funarith.service;
 
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
+import com.ytpm.app.model.YtDyzAdRecord;
+import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.general.Result;
 import com.ytpm.middle.view.DashboardRankingListVO;
@@ -46,4 +48,8 @@ public interface AdService {
      * 查询代理商首页广告数据统计
      */
     List<AgentAdGroupStaticsVO> getAgentProfit(String appIds);
+
+    String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user);
+
+    List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds);
 }

+ 36 - 7
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/service/impl/AdServiceImpl.java

@@ -4,14 +4,17 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
+import cn.hutool.core.util.StrUtil;
 import com.ytpm.advertise.enums.AdPlatformTypeEnum;
 import com.ytpm.advertise.enums.AdSourceTypeEnum;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.agent.view.AgentAdGroupStaticsVO;
 import com.ytpm.agent.view.AgentTopCountView;
 import com.ytpm.app.model.YtDyzAdRecord;
 import com.ytpm.app.model.YtDyzUser;
 import com.ytpm.app.param.DyzAdRecordParam;
+import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.feign.RiskFeign;
 import com.ytpm.funarith.dao.AdRecordMapper;
 import com.ytpm.funarith.dao.AppUserMapper;
@@ -27,6 +30,7 @@ import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
 import com.ytpm.middle.view.DashboardRiskVO;
 import com.ytpm.middle.view.UserRankingListVO;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -49,6 +53,7 @@ import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.stream.Collectors;
 
+@Slf4j
 @Service
 @RefreshScope
 public class AdServiceImpl implements AdService {
@@ -70,6 +75,7 @@ public class AdServiceImpl implements AdService {
     @Transactional(rollbackFor = Exception.class)
     public Result<?> saveRecord(DyzAdRecordParam param) {
         YtDyzUser user = appUserMapper.selectPrimaryKey(param.getUserId());
+        log.error(StrUtil.format("[saveRecord]:{} ", param.getBeginTime()));
         if(Objects.isNull(user)){
             return Result.resultOk(RepMessage.SAVE_SUCCESS);
         }
@@ -79,9 +85,22 @@ public class AdServiceImpl implements AdService {
         saveRecordAndChangeUser(param, user);
         //调用风控广告校验
         if(AdSourceTypeEnum.rewarded_video.getAdSourceType() == param.getAdSourceType()){
+            WxDefaultConfig config = appUserMapper.getDefaultConfigByAppId(user.getAppId());
+            String format = StrUtil.emptyToDefault(config.getTaskLimitTip(), "当前设备完成任务次数过多,请{}后重试!");
+            user.setPowerLimitTip(format);
             Result<?> result = riskFeign.checkAdRisk(user);
-            if(result.getCode()!=200){
-                return new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+            if (result.getCode() != 200) {
+                Result<Object> resultObj = new Result<>(StatusCode.ACCESS_ERR, getTipsMsg());
+                // 766处理
+                if("766".contains(result.getMessage())){
+                    resultObj.setData(result.getMessage());
+                }
+                else if (result.getCode() == StatusCode.ACCESS_RISK_ERROR && StrUtil.isNotBlank(result.getMessage())) {
+                    // 体力不再获取处理
+                    resultObj.setMessage(result.getMessage());
+                    resultObj.setData("767");
+                }
+                return resultObj;
             }
         }
         return Result.resultOk(RepMessage.SAVE_SUCCESS);
@@ -233,17 +252,15 @@ public class AdServiceImpl implements AdService {
         cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),actualMaximum,23,59,59);
         String lastDay = sdf.format(cal.getTime());
         List<YtDyzAdRecord> dyzMonthRecords = adRecordMapper.getTodayRecord(appIds,firstDay,lastDay);
-
         if(CollUtil.isNotEmpty(dyzMonthRecords)){monthRecords.addAll(dyzMonthRecords);}
         records = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),new Date())).collect(Collectors.toList());
 
-        cal = Calendar.getInstance();
+        cal = Calendar.getInstance(); // 获取当前日期时间
         cal.add(Calendar.DATE, -1); // 昨天的日期时间
         Date yest = cal.getTime();
         yestRecords = monthRecords.stream().filter(
                 s->DateUtil.isSameDay(DateUtil.parse(s.getFinishTime()),yest)).collect(Collectors.toList());
-
         //广告平台分组
         Map<String, List<YtDyzAdRecord>> networkMap = records.stream().collect(
                 Collectors.groupingBy(YtDyzAdRecord::getNetworkFormId));
@@ -288,7 +305,8 @@ public class AdServiceImpl implements AdService {
      *  始终创建新的事务以保障子方法的独立事务
      */
 //    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
-    public void saveRecordAndChangeUser(DyzAdRecordParam param,YtDyzUser user) {
+    @Override
+    public String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user) {
         //增加广告记录
         YtDyzAdRecord adRecord = new YtDyzAdRecord();
         if(Objects.isNull(param.getBeginTime())){
@@ -297,12 +315,23 @@ public class AdServiceImpl implements AdService {
         BeanUtils.copyProperties(param, adRecord);
         adRecord.setRecordId(IdUtil.fastSimpleUUID());
         adRecord.setNetworkName(AdPlatformTypeEnum.getDesc(Integer.parseInt(param.getNetworkFormId())));
-        adRecordMapper.addOne(adRecord);
+        if (param.getLoginStatus() != null && AdRecordEnum.LOGIN_BEFORE.getCode().equals(param.getLoginStatus())) {
+            adRecordMapper.addOneVisitor(adRecord);
+        } else {
+            adRecordMapper.addOne(adRecord);
+        }
         //修改用户信息, 广告次数+1  总收益 + revenue
         YtDyzUser dyzUser = new YtDyzUser();
         dyzUser.setUserId(user.getUserId());
         dyzUser.setTotalVideo(Objects.isNull(user.getTotalVideo())?1:(user.getTotalVideo()+1));
         dyzUser.setTotalIncome(user.getTotalIncome().add(param.getRevenue()));
         appUserMapper.updateUser(dyzUser);
+        return adRecord.getRecordId();
     }
+
+    @Override
+    public List<YtDyzAdRecord> queryRecordByIds(List<String> adRecordIds) {
+        return adRecordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
+    }
+
 }

+ 15 - 0
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/service/impl/AppUserServiceImpl.java

@@ -55,6 +55,21 @@ public class AppUserServiceImpl implements AppUserService {
     public YtDyzUser crudForNewTrans(WxLoginParam param, WxUserInfo wxUserInfo, WxLoginResult loginResult) {
         //处理用户注册或登录更新信息
         YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
+        // 获取游客登陆信息
+        if (Objects.isNull(old)) {
+            old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
+            if (Objects.nonNull(old)) {
+                old.setWxOpenId(wxUserInfo.getOpenid());
+                old.setNickName(wxUserInfo.getNickname());
+                old.setHeadImg(wxUserInfo.getHeadimgurl());
+                YtDyzUser newUser = new YtDyzUser();
+                newUser.setUserId(old.getUserId());
+                newUser.setWxOpenId(wxUserInfo.getOpenid());
+                newUser.setNickName(wxUserInfo.getNickname());
+                newUser.setHeadImg(wxUserInfo.getHeadimgurl());
+                appUserMapper.updateUser(newUser);
+            }
+        }
         if(Objects.isNull(old)) {
             old = new YtDyzUser();
             registryUser(param,wxUserInfo,loginResult, old);

+ 50 - 5
yt-funarith/funarith-service/src/main/java/com/ytpm/funarith/service/impl/VisitorLoginServiceImpl.java

@@ -1,14 +1,18 @@
 package com.ytpm.funarith.service.impl;
 
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import com.ytpm.agent.enums.AdRecordEnum;
 import com.ytpm.agent.enums.UserStatusEnum;
 import com.ytpm.app.enums.LoginType;
 import com.ytpm.app.model.YtDyzLoginRecord;
 import com.ytpm.app.model.YtDyzUser;
+import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.app.param.LoginParam;
+import com.ytpm.app.param.VisitorLoginParam;
 import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.constant.StrConstant;
 import com.ytpm.funarith.dao.AppUserMapper;
@@ -16,15 +20,19 @@ import com.ytpm.funarith.dao.LoginRecordMapper;
 import com.ytpm.funarith.dao.QuestionMapper;
 import com.ytpm.funarith.redis.RedisService;
 import com.ytpm.feign.RiskFeign;
+import com.ytpm.funarith.service.AdService;
+import com.ytpm.general.RepMessage;
 import com.ytpm.general.Result;
 import com.ytpm.handle.AbstractLoginService;
 import com.ytpm.handle.CommonException;
+import com.ytpm.handle.CustomerException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -48,6 +56,8 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
     private RiskFeign riskFeign;
     @Autowired
     private RedisService redisService;
+    @Autowired
+    private AdService adService;
 
     @Override
     protected WxDefaultConfig getLoginConfig(Integer appType) {
@@ -67,6 +77,20 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         return LoginType.VISITOR;
     }
 
+    @Override
+    protected void updateUserStatus(YtDyzUser ytDyzUser, UserStatusEnum statusEnum, String reason) {
+        if (ytDyzUser != null) {
+            YtDyzUser newUser = new YtDyzUser();
+            newUser.setUserId(ytDyzUser.getUserId());
+            newUser.setUserStatus(statusEnum.getCode());
+            newUser.setRiskReason(reason);
+            if(UserStatusEnum.NORMAL == statusEnum){
+                newUser.setRiskReason("");
+            }
+            appUserMapper.updateUser(newUser);
+        }
+    }
+
     @Override
     protected void validateParams(LoginParam loginParam, HttpServletRequest request) {
 
@@ -142,6 +166,7 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
      */
     @Override
     protected void setExtInfo(YtDyzUser old, Map<String, Object> paramMap) {
+        super.setExtInfo(old, paramMap);
         old.setLastQuestionId(questionMapper.getLastQuestionId(old.getUserId()));
         old.setTodayAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 1));
         old.setHistoryAnswerCount(questionMapper.getAnswerCount(old.getUserId(), 2));
@@ -149,10 +174,30 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         old.setLoginRecordList(loginRecordMapper.getLoginRecords(old.getUserId()));
     }
 
-    @Override
-    protected void beforeDeadWithUserCrud(LoginParam loginParam, YtDyzUser ytDyzUser, Map<String, Object> paramMap) {
-        super.beforeDeadWithUserCrud(loginParam, ytDyzUser, paramMap);
-        // 新增风控 相关广告源记录 ecpm  和预估收益 小于 各自 阈值,登陆返回 301
 
+    // 仅保存登陆时的三条广告信息 并传入登陆实体用于后续 risk风控校验
+    protected void saveVisitorAdRecord(YtDyzUser ytDyzUser, LoginParam loginParam, WxDefaultConfig defaultConfig) {
+        super.saveVisitorAdRecord(ytDyzUser, loginParam, defaultConfig);
+        VisitorLoginParam visitorLoginParam = (VisitorLoginParam) loginParam;
+        List<DyzAdRecordParam> preAdList = visitorLoginParam.getPreAdList();
+        List<String> adRecordIds = new ArrayList<>();
+        if (CollUtil.isNotEmpty(preAdList)) {
+            for (DyzAdRecordParam adRecordParam : preAdList) {
+                if (adRecordParam == null) {
+                    continue;
+                }
+                adRecordParam.setUserId(ytDyzUser.getUserId());
+                adRecordParam.setNickName(ytDyzUser.getNickName());
+                adRecordParam.setAppId(ytDyzUser.getAppId());
+                adRecordParam.setLoginStatus(AdRecordEnum.LOGIN_BEFORE.getCode());
+                String recordId = adService.saveRecordAndChangeUser(adRecordParam, ytDyzUser);
+                adRecordIds.add(recordId);
+            }
+        }
+        if(CollUtil.isEmpty(adRecordIds)) {
+            throw new CustomerException(StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), RepMessage.RISK_VISITOR_LOWER_VALUE));
+        }
+        ytDyzUser.setPreAdRecordList(adService.queryRecordByIds(adRecordIds));
     }
-}
+
+}

+ 112 - 60
yt-funarith/funarith-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -5,46 +5,86 @@
     <insert id="addOne">
         insert into yt_dyz_ad_record
         (
-         record_id,
-         user_id,
-         nick_name,
-         placement_id,
-         ad_source_id,
-         revenue,
-         network_form_id,
-         network_name,
-         network_placement_id,
-         begin_time,
-         finish_time,
-         result_json,
-         ad_source_index,
-         ad_source_type,
-         ecpm,
-         app_id
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
         values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
+    </insert>
+    <insert id="addOneVisitor">
+        insert into yt_dyz_ad_record_visitor
         (
-         #{recordId},
-         #{userId},
-         #{nickName},
-         #{placementId},
-         #{adSourceId},
-         #{revenue},
-         #{networkFormId},
-         #{networkName},
-         #{networkPlacementId},
-         ifnull(#{beginTime}, now()),
-         ifnull(#{finishTime}, now()),
-         #{resultJson},
-         #{adSourceIndex},
-         #{adSourceType},
-         #{ecpm},
-         #{appId}
+            record_id,
+            user_id,
+            nick_name,
+            placement_id,
+            ad_source_id,
+            revenue,
+            network_form_id,
+            network_name,
+            network_placement_id,
+            begin_time,
+            finish_time,
+            result_json,
+            ad_source_index,
+            ad_source_type,
+            ecpm,
+            app_id
         )
+        values
+            (
+                #{recordId},
+                #{userId},
+                #{nickName},
+                #{placementId},
+                #{adSourceId},
+                #{revenue},
+                #{networkFormId},
+                #{networkName},
+                #{networkPlacementId},
+                ifnull(#{beginTime}, now()),
+                ifnull(#{finishTime}, now()),
+                #{resultJson},
+                #{adSourceIndex},
+                #{adSourceType},
+                #{ecpm},
+                #{appId}
+            )
     </insert>
     <select id="countByAppIds" resultType="java.lang.Integer">
         select
-            count(record_id)
+        count(record_id)
         from yt_dyz_ad_record
         where ad_source_type = 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -53,48 +93,48 @@
     </select>
     <select id="getByUserId" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id = #{userId}
-          <if test="adsourceType != null and adsourceType!=888">
-              and ad_source_type = #{adsourceType}
-          </if>
+        <if test="adsourceType != null and adsourceType!=888">
+            and ad_source_type = #{adsourceType}
+        </if>
         order by finish_time desc
     </select>
     <select id="getByUserIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
+        record_id, user_id,app_id, nick_name, placement_id, ad_source_id, revenue, network_form_id, network_name, network_placement_id, finish_time, begin_time,result_json,ad_source_type,ad_source_index,ecpm
         from yt_dyz_ad_record
         where user_id in
-              <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
-                  #{item}
-              </foreach>
+        <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
+            #{item}
+        </foreach>
         order by finish_time
     </select>
     <select id="getHourRevenue" resultType="com.ytpm.middle.view.AppRevenueHourVO">
         SELECT
-            HOUR(finish_time) `hour`,
-            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
-            sum( revenue ) revenue
+        HOUR(finish_time) `hour`,
+        DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
+        sum( revenue ) revenue
         FROM
-            yt_dyz_ad_record
+        yt_dyz_ad_record
         WHERE
-            app_id = #{appId}
-            <if test="type != null and type ==1">
-                and DATE(finish_time) = DATE(now())
-            </if>
-            <if test="type != null and type ==2">
-                and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
-            </if>
-            <if test="type != null and type ==3">
-                and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
-            </if>
+        app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(finish_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(finish_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(finish_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
         GROUP BY
-            `hour`
+        `hour`
     </select>
     <select id="getRevenueByTime" resultType="java.math.BigDecimal">
         select
-            sum(ar.revenue)
+        sum(ar.revenue)
         from yt_dyz_ad_record ar
         join yt_dyz_user au on ar.user_id = au.user_id
         <where>
@@ -117,16 +157,16 @@
                 </foreach>
             </if>
             <if test="registryTimeBegin != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[>=]]> #{registryTimeBegin}
+                and au.registry_time <![CDATA[>=]]> #{registryTimeBegin}
             </if>
             <if test="registryTimeEnd != null ">
-                and DATE_FORMAT(au.registry_time,'%Y-%m-%d') <![CDATA[<=]]> #{registryTimeEnd}
+                and au.registry_time <![CDATA[<=]]> #{registryTimeEnd}
             </if>
         </where>
     </select>
     <select id="getTodayRecord" resultType="com.ytpm.app.model.YtDyzAdRecord">
         select
-            record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index, revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
         from yt_dyz_ad_record
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -139,4 +179,16 @@
             and finish_time <![CDATA[<=]]> #{lastDay}
         </if>
     </select>
+    <select id="selectRecordByIds" resultType="com.ytpm.app.model.YtDyzAdRecord">
+        select
+        record_id, user_id, app_id, nick_name, placement_id, ad_source_id, ad_source_type, ad_source_index,
+        revenue, ecpm, network_form_id, network_name, network_placement_id, finish_time, begin_time, result_json
+        <if test="loginStatus != null and loginStatus == 1">
+            from yt_dyz_ad_record_visitor
+        </if>
+        <if test="loginStatus == null or loginStatus != 1">
+            from yt_dyz_ad_record
+        </if>
+        where record_id in <foreach collection="ids" item="id" open="(" close=")" separator=",">#{id}</foreach>
+    </select>
 </mapper>

+ 174 - 135
yt-funarith/funarith-service/src/main/resources/mapper/AppUserMapper.xml

@@ -4,70 +4,70 @@
     <insert id="addOne" parameterType="com.ytpm.app.model.YtDyzUser">
         insert into yt_dyz_user
         (
-         user_id,
-         nick_name,
-         head_img,
-         registry_time,
-         last_login_time,
-         last_login_ip,
-         login_days,
-         total_video,
-         total_income,
-         red_packet_balance,
-         red_packet_amount,
-         points_balance,
-         points_total,
-         withdraw_total,
-         sign_days,
-         user_status,
-         risk_reason,
-         wx_open_id,
-         ditch_id,
-         platform_id,
-         app_id,
-         power,
-         phone,
-         phone_json,
-         device_id
+            user_id,
+            nick_name,
+            head_img,
+            registry_time,
+            last_login_time,
+            last_login_ip,
+            login_days,
+            total_video,
+            total_income,
+            red_packet_balance,
+            red_packet_amount,
+            points_balance,
+            points_total,
+            withdraw_total,
+            sign_days,
+            user_status,
+            risk_reason,
+            wx_open_id,
+            ditch_id,
+            platform_id,
+            app_id,
+            power,
+            phone,
+            phone_json,
+            device_id
         )
         values
-        (
-         #{userId},
-         #{nickName},
-         #{headImg},
-         #{registryTime},
-         #{lastLoginTime},
-         #{lastLoginIp},
-         #{loginDays},
-         #{totalVideo},
-         #{totalIncome},
-         #{redPacketBalance},
-         #{redPacketAmount},
-         #{pointsBalance},
-         #{pointsTotal},
-         #{withdrawTotal},
-         #{signDays},
-         #{userStatus},
-         #{riskReason},
-         #{wxOpenId},
-         #{ditchId},
-         #{platformId},
-         #{appId},
-         #{power},
-         #{phone},
-         #{phoneJson},
-         #{deviceId}
-        )
+            (
+                #{userId},
+                #{nickName},
+                #{headImg},
+                #{registryTime},
+                #{lastLoginTime},
+                #{lastLoginIp},
+                #{loginDays},
+                #{totalVideo},
+                #{totalIncome},
+                #{redPacketBalance},
+                #{redPacketAmount},
+                #{pointsBalance},
+                #{pointsTotal},
+                #{withdrawTotal},
+                #{signDays},
+                #{userStatus},
+                #{riskReason},
+                #{wxOpenId},
+                #{ditchId},
+                #{platformId},
+                #{appId},
+                #{power},
+                #{phone},
+                #{phoneJson},
+                #{deviceId}
+            )
     </insert>
     <insert id="addPowerRecord">
         insert into yt_dyz_power_record
         (
-         record_id, user_id, type, remark, add_time
+            record_id, user_id, type, remark, add_time
         )
         values
-        (
-         #{recordId},#{userId},#{type},#{remark},#{addTime}
-        )
+            (
+                #{recordId},#{userId},#{type},#{remark},#{addTime}
+            )
     </insert>
     <insert id="saveAppConfig">
         insert into yt_app_default_config
@@ -151,6 +151,24 @@
             <if test="interstitialIntervalTime != null">
                 interstitial_interval_time = #{interstitialIntervalTime}
             </if>
+            <if test="flowIntervalTime != null">
+                flow_interval_time = #{flowIntervalTime}
+            </if>
+            <if test="taskLimitTip != null">
+                task_limit_tip = #{taskLimitTip}
+            </if>
+            <if test="lowValueTip != null">
+                low_value_tip = #{lowValueTip}
+            </if>
+            <if test="brushTip != null">
+                brush_tip = #{brushTip}
+            </if>
+            <if test="startWaitTime != null">
+                start_wait_time = #{startWaitTime}
+            </if>
+            <if test="canCacheVideo != null">
+                can_cache_video = #{canCacheVideo}
+            </if>
         </set>
         where app_id = #{appId}
     </update>
@@ -234,14 +252,14 @@
     </delete>
     <select id="getYtAppUser" resultType="com.ytpm.app.model.YtDyzUser">
         select
-           user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+            user_id, app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where wx_open_id = #{openid}
-        and ditch_id = #{ditchId}
+          and ditch_id = #{ditchId}
     </select>
     <select id="queryAll" resultType="com.ytpm.app.view.YtAppUserListView">
         select
-            user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
+        user_id,app_id,phone,device_id, ditch_id, nick_name,head_img, power, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, platform_id
         from yt_dyz_user
         where 1 = 1
         <if test="userId != null and userId !=''">
@@ -270,9 +288,9 @@
         </if>
         <if test="appIds != null and appIds != ''">
             and app_id in
-                <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
-                    #{item}
-                </foreach>
+            <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
+                #{item}
+            </foreach>
         </if>
         order by user_id desc
     </select>
@@ -320,37 +338,37 @@
     </resultMap>
     <select id="getUserList" resultMap="UserMap">
         select
-            du.user_id,
-            du.head_img,
-            du.nick_name,
-            du.phone,
-            du.device_id,
-            du.registry_time,
-            du.last_login_time,
-            du.last_login_ip,
-            du.login_days,
-            du.total_video,
-            du.total_income,
-            du.red_packet_balance,
-            du.red_packet_amount,
-            du.points_balance,
-            du.points_total,
-            du.withdraw_total,
-            du.sign_days,
-            du.user_status,
-            du.risk_reason,
-            du.wx_open_id,
-            du.ditch_id,
-            du.app_id,
-            du.platform_id,
-            du.power,
-            lr.record_id,
-            lr.login_time,
-            lr.device_brand,
-            lr. device_model,
-            lr.login_ip,
-            lr.operator,
-            lr.ip_addr
+        du.user_id,
+        du.head_img,
+        du.nick_name,
+        du.phone,
+        du.device_id,
+        du.registry_time,
+        du.last_login_time,
+        du.last_login_ip,
+        du.login_days,
+        du.total_video,
+        du.total_income,
+        du.red_packet_balance,
+        du.red_packet_amount,
+        du.points_balance,
+        du.points_total,
+        du.withdraw_total,
+        du.sign_days,
+        du.user_status,
+        du.risk_reason,
+        du.wx_open_id,
+        du.ditch_id,
+        du.app_id,
+        du.platform_id,
+        du.power,
+        lr.record_id,
+        lr.login_time,
+        lr.device_brand,
+        lr. device_model,
+        lr.login_ip,
+        lr.operator,
+        lr.ip_addr
         from yt_dyz_user du
         left join yt_dyz_login_record lr on du.user_id = lr.user_id
         <where>
@@ -430,14 +448,32 @@
     </select>
     <select id="getDefaultConfig" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id appId, secret, app_id platformAppId, app_key platformAppSecret, app_type,user_path,login_path,ad_path,answer_path,power_path
-                     ,can_simulator ,taku_app_id,taku_key,taku_banner_pid,taku_interstitial_pid,taku_reward_pid,taku_native_pid,can_use_adb,can_accumulation,can_use_float,can_use_root,ditch_id,power_wait_time,interstitial_interval_time
+            config_id, config_name, open_id as app_id, secret, app_id as platformAppId, app_key as platformAppSecret,
+            app_type,user_path, login_path,ad_path,answer_path,power_path,can_simulator,
+            taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid,
+            can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_type = #{appType}
     </select>
+    <select id="getDefaultConfigByAppId" resultType="com.ytpm.app.view.WxDefaultConfig">
+        select
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip,flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
+        from yt_app_default_config
+        where app_id = #{appId}
+    </select>
     <select id="getSecretByAppId" resultType="java.lang.String">
         select
-           secret
+            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,
+            answer_path,power_path,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid,
+            taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,
+            ditch_id, power_wait_time, interstitial_interval_time,
+            low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id = #{appId}
     </select>
@@ -452,13 +488,16 @@
             platform_id
         from yt_dyz_user
         where device_id = #{deviceId}
-        and wx_open_id = #{openid}
+          and wx_open_id = #{openid}
         limit 1
     </select>
     <select id="getConfigByIds" resultType="com.ytpm.app.view.WxDefaultConfig">
         select
-            config_id, config_name, open_id, secret, app_id, app_key, app_type,user_path,login_path,ad_path,answer_path,power_path
-        ,can_simulator, taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid, taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation, ditch_id, power_wait_time, interstitial_interval_time
+        config_id, config_name, open_id, secret, app_id, app_key, app_type, user_path, login_path, ad_path,
+        answer_path, power_path,taku_app_id, taku_key, taku_banner_pid, taku_native_pid, taku_reward_pid,
+        taku_interstitial_pid, can_use_root, can_use_adb, can_use_float, can_accumulation,can_simulator,
+        ditch_id, power_wait_time, interstitial_interval_time,
+        low_value_tip, brush_tip, flow_interval_time,task_limit_tip,start_wait_time,can_cache_video
         from yt_app_default_config
         where app_id in
         <foreach collection="appIds.split(',')" item="item" separator="," open="(" close=")">
@@ -467,7 +506,7 @@
     </select>
     <select id="getAdCount" resultType="java.lang.Integer">
         select
-            sum(total_video)
+        sum(total_video)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -485,11 +524,11 @@
     </select>
     <select id="getAppRanking" resultType="com.ytpm.middle.view.AppRankingListVO">
         SELECT
-            u.app_id,
-            sum( ar.revenue ) totalRevenue
+        u.app_id,
+        sum( ar.revenue ) totalRevenue
         FROM
-            yt_dyz_ad_record ar
-            JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -506,21 +545,21 @@
             </if>
         </where>
         GROUP BY
-            u.app_id
+        u.app_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         LIMIT #{limit}
     </select>
     <select id="getUserRanking" resultType="com.ytpm.middle.view.UserRankingListVO">
         SELECT
-            u.user_id,
-            u.nick_name,
-            u.head_img,
-            u.total_video,
-            sum( ar.revenue ) totalIncome
+        u.user_id,
+        u.nick_name,
+        u.head_img,
+        u.total_video,
+        sum( ar.revenue ) totalIncome
         FROM
-            yt_dyz_ad_record ar
-                JOIN yt_dyz_user u ON ar.user_id = u.user_id
+        yt_dyz_ad_record ar
+        JOIN yt_dyz_user u ON ar.user_id = u.user_id
         <where>
             <if test="sortBy != null">
                 <choose>
@@ -538,12 +577,12 @@
         </where>
         GROUP BY ar.user_id
         ORDER BY
-            sum( ar.revenue ) DESC
+        sum( ar.revenue ) DESC
         limit #{limit}
     </select>
     <select id="countUserByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -552,7 +591,7 @@
     </select>
     <select id="countRevenueByAppIds" resultType="java.math.BigDecimal">
         select
-            sum(total_income)
+        sum(total_income)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -561,7 +600,7 @@
     </select>
     <select id="countBannedByAppIds" resultType="java.lang.Integer">
         select
-            count(user_id)
+        count(user_id)
         from yt_dyz_user
         where user_status > 1 and app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -600,8 +639,8 @@
     </select>
     <select id="countRegistryHour" resultType="com.ytpm.middle.view.AppUserHourVO">
         select
-            DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
-            count(user_id) `count`
+        DATE_FORMAT(registry_time,'%Y-%m-%d %H:00:00') as `time`,
+        count(user_id) `count`
         from yt_dyz_user
         where app_id = #{appId}
         <if test="type != null and type ==1">
@@ -634,7 +673,7 @@
     </select>
     <select id="queryByUserIds" resultType="com.ytpm.app.model.YtDyzUser">
         select
-            user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
+        user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days, total_video, total_income, red_packet_balance, red_packet_amount, points_balance, points_total, withdraw_total, sign_days, user_status, risk_reason, wx_open_id, ditch_id, app_id, platform_id, power, phone, device_id
         from yt_dyz_user
         where user_id in
         <foreach collection="userIds.split(',')" separator="," item="item"  open="(" close=")">
@@ -662,21 +701,21 @@
     </resultMap>
     <select id="queryTodayUserAd" resultMap="UserAdMap">
         select
-            u.user_id,
-            u.app_id,
-            u.nick_name,
-            ar.record_id,
-            ar.placement_id,
-            ar.ad_source_id,
-            ar.ad_source_type,
-            ar.ad_source_index,
-            ar.revenue,
-            ar.ecpm,
-            ar.network_form_id,
-            ar.network_name,
-            ar.network_placement_id,
-            ar.finish_time,
-            ar.begin_time
+        u.user_id,
+        u.app_id,
+        u.nick_name,
+        ar.record_id,
+        ar.placement_id,
+        ar.ad_source_id,
+        ar.ad_source_type,
+        ar.ad_source_index,
+        ar.revenue,
+        ar.ecpm,
+        ar.network_form_id,
+        ar.network_name,
+        ar.network_placement_id,
+        ar.finish_time,
+        ar.begin_time
         from yt_dyz_ad_record ar
         join yt_dyz_user u on ar.user_id = u.user_id
         where ar.ad_source_type = #{adSourceType} and ar.app_id = #{appId} and ar.user_id in

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff