Kaynağa Gözat

doc:前三日收益计算缺陷处理

hidewnd 1 ay önce
ebeveyn
işleme
acbf372e9c

+ 5 - 1
yt-question/yt-question-service/src/main/java/com/ytpm/question/controller/UserController.java

@@ -121,6 +121,10 @@ public class UserController {
                 user.setTodayVideo((int) collect.stream().filter(
                         s -> s.getAdSourceType() == AdSourceTypeEnum.rewarded_video.getAdSourceType()).count());
                 user.setTodayIncome(todayIncome);
+                // 统计4天-今日收益=前三日收益
+                if (user.getNearlyIncome() != null && user.getNearlyIncome().compareTo(todayIncome) >= 0) {
+                    user.setNearlyIncome(user.getNearlyIncome().subtract(todayIncome));
+                }
             } else {
                 user.setTodayIncome(BigDecimal.ZERO);
                 user.setTodayVideo(0);
@@ -198,7 +202,7 @@ public class UserController {
     @GetMapping("/adRecords")
     public ResultTable<YtDyzAdRecord> adRecords(@RequestParam(name = "userId", required = true) String userId,
                                                 @RequestParam(name = "adsourceType", required = false) Integer adsourceType) {
-        return ResultTable.resultTableOk(new PageInfo<YtDyzAdRecord>(adRecordMapper.getByUserId(userId, adsourceType)));
+        return ResultTable.resultTableOk(new PageInfo<>(adRecordMapper.getByUserId(userId, adsourceType)));
     }
 
     @PostMapping("/adRecords/page")

+ 21 - 9
yt-question/yt-question-service/src/main/resources/mapper/AppUserMapper.xml

@@ -805,15 +805,27 @@
     </update>
     <update id="updateTotal">
         UPDATE yt_dyz_user
-        SET nearly_income = 0, nearly_begin_time = NOW()
-        WHERE user_id = #{userId}
-          AND last_login_time <![CDATA[ < ]]>  DATE_SUB(NOW(), INTERVAL 3 DAY)
-          AND IFNULL(nearly_begin_time, NOW()) <![CDATA[ < ]]> DATE_SUB(NOW(), INTERVAL 3 DAY);
-        UPDATE yt_dyz_user SET nearly_begin_time = NOW() WHERE user_id = #{userId} AND nearly_begin_time IS NULL;
-        UPDATE yt_dyz_user
-        SET total_video = COALESCE(total_video, 0) + #{videoCount},
-            total_income = COALESCE(total_income, 0) + #{revenue},
-            nearly_income = COALESCE(nearly_income, 0) + #{revenue}
+        SET
+        -- 处理近4天未登录 或间隔时间超过4天
+        nearly_income = (CASE
+        WHEN last_login_time <![CDATA[ < ]]> DATE_SUB(DATE(NOW()), INTERVAL 4 DAY)
+            OR IFNULL(nearly_begin_time, NOW()) <![CDATA[ < ]]> DATE_SUB(DATE(NOW()), INTERVAL 4 DAY)
+        THEN #{revenue}
+        ELSE COALESCE(nearly_income, 0) + #{revenue}
+        END),
+        nearly_begin_time = CASE
+        -- 优先处理重置场景
+        WHEN last_login_time <![CDATA[ < ]]> DATE_SUB(DATE(NOW()), INTERVAL 4 DAY)
+            OR IFNULL(nearly_begin_time, NOW()) <![CDATA[ < ]]> DATE_SUB(DATE(NOW()), INTERVAL 4 DAY)
+        THEN NOW()
+        -- 处理初始值为NULL的情况
+        WHEN nearly_begin_time IS NULL THEN NOW()
+        -- 其他情况保持不变
+        ELSE nearly_begin_time
+        END,
+        -- 累加统计值
+        total_video = COALESCE(total_video, 0) + #{videoCount},
+        total_income = COALESCE(total_income, 0) + #{revenue}
         WHERE user_id = #{userId};
     </update>
 </mapper>