Ver Fonte

lime修改同步nofeeds

hidewnd há 1 mês atrás
pai
commit
b85f5ac5ca

+ 3 - 0
yt-nofeeds/nofeeds-service/src/main/java/com/ytpm/nofeeds/dao/AppUserMapper.java

@@ -208,4 +208,7 @@ public interface AppUserMapper {
     YtDyzUser getByDeviceAndDitch(@Param("deviceId") String deviceId,@Param("ditchId")Long ditchId);
 
     String getPlatformByDeviceId(@Param("deviceId")String deviceId);
+
+    void updateTotal(@Param("userId") String userId, @Param("videoCount") int videoCount, @Param("revenue") BigDecimal revenue);
+
 }

+ 12 - 8
yt-nofeeds/nofeeds-service/src/main/java/com/ytpm/nofeeds/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);
@@ -328,11 +332,10 @@ public class AdServiceImpl implements AdService {
         }
         if (updateUserTotal) {
             //修改用户信息, 广告次数+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);
+            if (param.getRevenue() == null) {
+                param.setRevenue(BigDecimal.ZERO);
+            }
+            appUserMapper.updateTotal(user.getUserId(), 1, param.getRevenue());
         }
         return adRecord.getRecordId();
     }
@@ -343,3 +346,4 @@ public class AdServiceImpl implements AdService {
     }
 
 }
+

+ 11 - 3
yt-nofeeds/nofeeds-service/src/main/resources/mapper/AdRecordMapper.xml

@@ -106,9 +106,17 @@
             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>
+        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-nofeeds/nofeeds-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>