Browse Source

lime修改同步allusion

hidewnd 1 tháng trước cách đây
mục cha
commit
fbdb5e919f

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

@@ -209,4 +209,6 @@ public interface AppUserMapper {
 
     String getPlatformByDeviceId(@Param("deviceId")String deviceId);
 
+    void updateTotal(@Param("userId") String userId, @Param("videoCount") int videoCount, @Param("revenue") BigDecimal revenue);
+
 }

+ 17 - 11
yt-allusion/allusion-service/src/main/java/com/ytpm/allusion/service/impl/AdServiceImpl.java

@@ -252,11 +252,12 @@ 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(
@@ -304,12 +305,15 @@ public class AdServiceImpl implements AdService {
      * 保存记录
      *  始终创建新的事务以保障子方法的独立事务
      */
-//    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
     @Override
+//    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
     public String saveRecordAndChangeUser(DyzAdRecordParam param, YtDyzUser user) {
         //增加广告记录
         YtDyzAdRecord adRecord = new YtDyzAdRecord();
-        if(Objects.isNull(param.getBeginTime())){
+        if(Objects.isNull(param.getBeginTime()) || "null".equals(param.getBeginTime())){
+            if ("null".equals(param.getBeginTime())) {
+                log.warn("param beginTime is null !");
+            }
             param.setBeginTime(param.getFinishTime());
         }
         BeanUtils.copyProperties(param, adRecord);
@@ -320,17 +324,19 @@ public class AdServiceImpl implements AdService {
         } else {
             adRecordMapper.addOne(adRecord);
         }
+        boolean updateUserTotal = true;
         // 游客登陆下 激励视频广告记录不算入用户统计
         if (AdRecordEnum.LOGIN_BEFORE.getCode().equals(param.getLoginStatus())
                 && AdSourceTypeEnum.rewarded_video.getAdSourceType() == param.getAdSourceType()) {
-            return adRecord.getRecordId();
+            updateUserTotal = false;
+        }
+        if (updateUserTotal) {
+            //修改用户信息, 广告次数+1  总收益 + revenue
+            if (param.getRevenue() == null) {
+                param.setRevenue(BigDecimal.ZERO);
+            }
+            appUserMapper.updateTotal(user.getUserId(), 1, param.getRevenue());
         }
-        //修改用户信息, 广告次数+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();
     }
 
@@ -339,4 +345,4 @@ public class AdServiceImpl implements AdService {
         return adRecordMapper.selectRecordByIds(AdRecordEnum.LOGIN_BEFORE.getCode(), adRecordIds);
     }
 
-}
+}

+ 8 - 0
yt-allusion/allusion-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -109,6 +109,14 @@
         <foreach collection="userIds.split(',')" open="(" close=")" separator="," item="item">
             #{item}
         </foreach>
+        union
+        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
+        from yt_dyz_ad_record_visitor
+        where ad_source_type != 1 and user_id in
+        <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">

+ 6 - 0
yt-allusion/allusion-service/src/main/resources/mapper/AppUserMapper.xml

@@ -782,4 +782,10 @@
             #{item}
         </foreach>
     </update>
+    <update id="updateTotal">
+        UPDATE yt_dyz_user
+        SET total_video = COALESCE(total_video, 0) + #{videoCount},
+            total_income = COALESCE(total_income, 0) + #{revenue}
+        WHERE user_id = #{userId}
+    </update>
 </mapper>