Jelajahi Sumber

feat: Agent用户管理用户列表增加一列 前三日总收益

hidewnd 1 bulan lalu
induk
melakukan
926c422195

+ 11 - 1
yt-agent/agent-service/src/main/java/com/ytpm/dao/AppMapper.java

@@ -20,7 +20,7 @@ public interface AppMapper {
      */
     YtApp selectPrimary(@Param("appId") String appId);
 
-    YtApp selectByDitchId(@Param("ditchId") Long ditchId);
+    List<YtApp> selectByDitchId(@Param("ditchId") Long ditchId);
 
     /**
      * 保存应用
@@ -47,4 +47,14 @@ public interface AppMapper {
     YtApp getByDitchIdAndSuperiorId(@Param("ditchId") Long ditchId, @Param("superiorId") String superiorId);
 
     List<YtApp> getBySuperiorId(@Param("superiorId") String superiorId);
+
+    /**
+     * 批量删除应用
+     */
+    void deleteAppIds(@Param("ids") List<String> ids);
+
+    /**
+     * 删除指定应用所有风控规则
+     */
+    void deleteRisks(@Param("ids") List<String> ids);
 }

+ 15 - 5
yt-agent/agent-service/src/main/java/com/ytpm/service/impl/AgentDitchServiceImpl.java

@@ -1,12 +1,12 @@
 package com.ytpm.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.ytpm.agent.model.YtApp;
 import com.ytpm.agent.model.YtDitch;
 import com.ytpm.agent.param.DitchListParam;
 import com.ytpm.agent.view.AgentDitchView;
-import com.ytpm.agent.view.AgentUserInfo;
 import com.ytpm.dao.AgentDitchMapper;
 import com.ytpm.dao.AppMapper;
 import com.ytpm.general.RepMessage;
@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 @Service
 public class AgentDitchServiceImpl implements AgentDitchService {
@@ -58,10 +59,12 @@ public class AgentDitchServiceImpl implements AgentDitchService {
         agentDitchMapper.update(param);
         //同时修改app中的渠道类型名称
         Long ditchId = param.getDitchId();
-        YtApp ytApp = appMapper.selectByDitchId(ditchId);
-        if(Objects.nonNull(ytApp)){
-            ytApp.setDitchName(param.getDitchName());
-            appMapper.updateOne(ytApp);
+        List<YtApp> ytApps = appMapper.selectByDitchId(ditchId);
+        if(CollUtil.isNotEmpty(ytApps)){
+            for (YtApp ytApp : ytApps) {
+                ytApp.setDitchName(param.getDitchName());
+                appMapper.updateOne(ytApp);
+            }
         }
         return Result.resultOk(RepMessage.MODIFY_SUCCESS);
     }
@@ -72,6 +75,13 @@ public class AgentDitchServiceImpl implements AgentDitchService {
         ytDitch.setIsDelete(1);
         ytDitch.setDitchId(ditchId);
         agentDitchMapper.update(ytDitch);
+        // 20250917 删除渠道后 同步删除渠道下应用(假删除)及应用风控配置(真删除)
+        List<YtApp> ytApps = appMapper.selectByDitchId(ditchId);
+        if(CollUtil.isNotEmpty(ytApps)){
+            List<String> ids = ytApps.stream().map(YtApp::getAppId).collect(Collectors.toList());
+            appMapper.deleteAppIds(ids);
+            appMapper.deleteRisks(ids);
+        }
         return Result.resultOk(RepMessage.DELETE_SUCCESS);
     }
 }

+ 4 - 0
yt-common/src/main/java/com/ytpm/app/model/YtDyzUser.java

@@ -62,6 +62,10 @@ public class YtDyzUser extends PageMeta {
     /** 总收益 */
     @ApiModelProperty("总收益")
     private BigDecimal totalIncome;
+
+    @ApiModelProperty("前三日总收益")
+    private BigDecimal nearlyIncome;
+
     /** 红包余额 */
     @CustomField(node = 1)
     @ApiModelProperty("红包余额")

+ 3 - 0
yt-common/src/main/java/com/ytpm/app/view/YtAppUserListView.java

@@ -89,6 +89,9 @@ public class YtAppUserListView extends PageMeta {
     private String communicationOperator;
     @ApiModelProperty("今日收益")
     private BigDecimal todayIncome;
+
+    @ApiModelProperty("前三日总收益")
+    private BigDecimal nearlyIncome;
     /** 登录历史记录 */
     @ApiModelProperty("登录历史记录")
     private List<YtDyzLoginRecord> loginRecordList;

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

@@ -75,7 +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()));
+        log.warn(StrUtil.format("[saveRecord] userId:{} revenue:{} ", param.getUserId(), param.getRevenue()));
         if(Objects.isNull(user)){
             return Result.resultOk(RepMessage.SAVE_SUCCESS);
         }

+ 4 - 0
yt-lime/lime-service/src/main/java/com/ytpm/lime/service/impl/VisitorLoginServiceImpl.java

@@ -182,6 +182,7 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
         List<DyzAdRecordParam> preAdList = visitorLoginParam.getPreAdList();
         List<String> adRecordIds = new ArrayList<>();
         if (CollUtil.isNotEmpty(preAdList)) {
+            BigDecimal totalRevenue = BigDecimal.ZERO;
             for (DyzAdRecordParam adRecordParam : preAdList) {
                 if (adRecordParam == null) {
                     continue;
@@ -192,7 +193,10 @@ public class VisitorLoginServiceImpl extends AbstractLoginService  {
                 adRecordParam.setLoginStatus(AdRecordEnum.LOGIN_BEFORE.getCode());
                 String recordId = adService.saveRecordAndChangeUser(adRecordParam, ytDyzUser);
                 adRecordIds.add(recordId);
+                totalRevenue = adRecordParam.getRevenue() == null ? totalRevenue : totalRevenue.add(adRecordParam.getRevenue());
             }
+            log.info(StrUtil.format("[visitor adRecords] userId:{} recordCount:{} revenue:{} ",
+                    ytDyzUser.getUserId(), adRecordIds.size(), totalRevenue));
         }
         if(CollUtil.isEmpty(adRecordIds)) {
             throw new CustomerException(StrUtil.emptyToDefault(defaultConfig.getLowValueTip(), RepMessage.RISK_VISITOR_LOWER_VALUE));

+ 51 - 24
yt-lime/lime-service/src/main/resources/mapper/AppUserMapper.xml

@@ -13,6 +13,7 @@
             login_days,
             total_video,
             total_income,
+            nearly_income,
             red_packet_balance,
             red_packet_amount,
             points_balance,
@@ -41,6 +42,7 @@
                 #{loginDays},
                 #{totalVideo},
                 #{totalIncome},
+                #{nearlyIncome},
                 #{redPacketBalance},
                 #{redPacketAmount},
                 #{pointsBalance},
@@ -211,6 +213,9 @@
             <if test="totalIncome != null">
                 total_income = #{totalIncome},
             </if>
+            <if test="nearlyIncome != null">
+                nearly_income = #{nearlyIncome},
+            </if>
             <if test="redPacketBalance != null">
                 red_packet_balance = #{redPacketBalance},
             </if>
@@ -252,14 +257,20 @@
     </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, nearly_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}
     </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, nearly_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 !=''">
@@ -296,7 +307,9 @@
     </select>
     <select id="selectPrimaryKey" resultType="com.ytpm.app.model.YtDyzUser">
         select
-            user_id,app_id,phone,device_id, ditch_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, platform_id, power
+            user_id,app_id,phone,device_id, ditch_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, platform_id, power, nearly_income
         from yt_dyz_user
         where user_id = #{userId}
     </select>
@@ -312,6 +325,7 @@
         <result column="login_days" property="loginDays" />
         <result column="total_video" property="totalVideo" />
         <result column="total_income" property="totalIncome" />
+        <result column="nearly_income" property="nearlyIncome" />
         <result column="red_packet_balance" property="redPacketBalance" />
         <result column="red_packet_amount" property="redPacketAmount" />
         <result column="points_balance" property="pointsBalance" />
@@ -349,6 +363,7 @@
         du.login_days,
         du.total_video,
         du.total_income,
+        du.nearly_income,
         du.red_packet_balance,
         du.red_packet_amount,
         du.points_balance,
@@ -390,11 +405,10 @@
 
     <select id="queryAllByTime" resultType="com.ytpm.app.model.YtDyzUser">
         SELECT
-        user_id,app_id,phone,device_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, nick_name, head_img, power,
+        registry_time,last_login_time, last_login_ip, login_days, total_video, total_income, nearly_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>
             <if test="startTime != null">
@@ -479,16 +493,16 @@
     </select>
     <select id="queryByOpenid" resultType="com.ytpm.app.model.YtDyzUser">
         select
-            user_id,phone,device_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
+            user_id,phone,device_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
+            total_video, total_income, nearly_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
         from yt_dyz_user
         where wx_open_id = #{openid}
     </select>
     <select id="getByDeviceId" resultType="java.lang.String">
-        select
-            platform_id
+        select platform_id
         from yt_dyz_user
-        where device_id = #{deviceId}
-          and wx_open_id = #{openid}
+        where device_id = #{deviceId} and wx_open_id = #{openid}
         limit 1
     </select>
     <select id="getConfigByIds" resultType="com.ytpm.app.view.WxDefaultConfig">
@@ -505,8 +519,7 @@
         </foreach>
     </select>
     <select id="getAdCount" resultType="java.lang.Integer">
-        select
-        sum(total_video)
+        select sum(total_video)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -514,8 +527,7 @@
         </foreach>
     </select>
     <select id="getRevenueCount" resultType="java.math.BigDecimal">
-        select
-        sum(total_income)
+        select sum(total_income)
         from yt_dyz_user
         where app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -726,7 +738,10 @@
     </select>
     <select id="getMonthRegistryUser" 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, nearly_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 app_id in
         <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
@@ -755,20 +770,25 @@
     </select>
     <select id="getLastRegistryUser" 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, phone_json
+            user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
+            total_video, total_income, nearly_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, phone_json
         from yt_dyz_user
         where device_id = #{deviceId}
     </select>
 
     <select id="getByDeviceAndDitch" 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, phone_json
+            user_id, head_img, nick_name, registry_time, last_login_time, last_login_ip, login_days,
+            total_video, total_income, nearly_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, phone_json
         from yt_dyz_user
         where device_id = #{deviceId} and ditch_id = #{ditchId} limit 1
     </select>
     <select id="getPlatformByDeviceId" resultType="java.lang.String">
-        select
-            platform_id
+        select platform_id
         from yt_dyz_user
         where device_id = #{deviceId}
         limit 1
@@ -784,8 +804,15 @@
     </update>
     <update id="updateTotal">
         UPDATE yt_dyz_user
-        SET total_video = COALESCE(total_video, 0) + #{videoCount},
-        total_income = COALESCE(total_income, 0) + #{revenue}
+        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}
+        WHERE user_id = #{userId};
     </update>
 </mapper>

+ 4 - 4
yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/impl/ApkServiceImpl.java

@@ -60,10 +60,10 @@ public class ApkServiceImpl implements ApkService {
     @Value("${risk.config.initAdCompletedCount:10}")
     private String initAdCompletedCount;
 
-    @Value("${risk.config.initFirstCount:3}")
+    @Value("${risk.config.initFirstCount:4}")
     private String initFirstCount;
 
-    @Value("${risk.config.initAverageRevenue:0.05}")
+    @Value("${risk.config.initAverageRevenue:0.12}")
     private String initAverageRevenue;
 
     @Value("${risk.config.initMonthCount:1}")
@@ -72,10 +72,10 @@ public class ApkServiceImpl implements ApkService {
     @Value("${risk.config.initMonthTaskLimit:80}")
     private String initMonthTaskLimit;
 
-    @Value("${risk.config.initHourCount:24}")
+    @Value("${risk.config.initHourCount:3}")
     private String initHourCount;
 
-    @Value("${risk.config.initHourTaskLimit:5}")
+    @Value("${risk.config.initHourTaskLimit:10}")
     private String initHourTaskLimit;
 
     @Value("${risk.config.visitor.initEcpmLimit:20}")