Pārlūkot izejas kodu

ADS首页统计数据

marxjaw 3 mēneši atpakaļ
vecāks
revīzija
159345c647
20 mainītis faili ar 362 papildinājumiem un 16 dzēšanām
  1. 4 0
      yt-app/app-feign/src/main/java/com/ytpm/feign/AppFeign.java
  2. 7 0
      yt-app/app-service/src/main/java/com/ytpm/controller/dyz/AdController.java
  3. 2 1
      yt-app/app-service/src/main/java/com/ytpm/dao/dyz/AdRecordMapper.java
  4. 20 0
      yt-app/app-service/src/main/java/com/ytpm/dao/dyz/AppUserMapper.java
  5. 6 0
      yt-app/app-service/src/main/java/com/ytpm/service/dyz/AdService.java
  6. 56 8
      yt-app/app-service/src/main/java/com/ytpm/service/dyz/impl/AdServiceImpl.java
  7. 12 4
      yt-app/app-service/src/main/resources/mapper/dyz/AdRecordMapper.xml
  8. 64 0
      yt-app/app-service/src/main/resources/mapper/dyz/AppUserMapper.xml
  9. 2 0
      yt-common/src/main/java/com/ytpm/agent/param/AppListParam.java
  10. 25 0
      yt-common/src/main/java/com/ytpm/middle/view/AppRevenueHourVO.java
  11. 21 0
      yt-common/src/main/java/com/ytpm/middle/view/AppUserHourVO.java
  12. 4 2
      yt-common/src/main/java/com/ytpm/middle/view/DashboardAppRevenueVO.java
  13. 44 0
      yt-common/src/main/java/com/ytpm/middle/view/DashboardRiskVO.java
  14. 10 0
      yt-middle/middle-platform/src/main/java/com/ytpm/middle/controller/HomeController.java
  15. 13 0
      yt-middle/middle-platform/src/main/java/com/ytpm/middle/dao/RiskMapper.java
  16. 6 0
      yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/CountService.java
  17. 31 0
      yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/impl/CountServiceImpl.java
  18. 3 0
      yt-middle/middle-platform/src/main/resources/mapper/ApkMapper.xml
  19. 1 1
      yt-middle/middle-platform/src/main/resources/mapper/PermissionMapper.xml
  20. 31 0
      yt-middle/middle-platform/src/main/resources/mapper/RiskMapper.xml

+ 4 - 0
yt-app/app-feign/src/main/java/com/ytpm/feign/AppFeign.java

@@ -15,6 +15,7 @@ import com.ytpm.general.Result;
 import com.ytpm.general.ResultTable;
 import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
+import com.ytpm.middle.view.DashboardRiskVO;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -73,4 +74,7 @@ public interface AppFeign {
 
     @GetMapping("/ad/revenueStatics")
     DashboardRevenueVO revenueStatics(@RequestParam(name = "apkIds") String apkIds);
+
+    @GetMapping("/ad/userStatics")
+    DashboardRiskVO userStatics(@RequestParam(name = "appId") String appId);
 }

+ 7 - 0
yt-app/app-service/src/main/java/com/ytpm/controller/dyz/AdController.java

@@ -5,6 +5,7 @@ import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.general.Result;
 import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
+import com.ytpm.middle.view.DashboardRiskVO;
 import com.ytpm.service.dyz.AdService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -76,4 +77,10 @@ public class AdController {
     public AgentTopCountView getAppTopCount(@RequestParam(name = "appIds")String appIds){
         return adService.getAppTopCount(appIds);
     }
+
+    @ApiOperation("查询用户风控分时数据统计")
+    @GetMapping("/userStatics")
+    public DashboardRiskVO userStatics(@RequestParam(name = "appId")String appId){
+        return adService.userStatics(appId);
+    }
 }

+ 2 - 1
yt-app/app-service/src/main/java/com/ytpm/dao/dyz/AdRecordMapper.java

@@ -1,6 +1,7 @@
 package com.ytpm.dao.dyz;
 
 import com.ytpm.app.model.YtDyzAdRecord;
+import com.ytpm.middle.view.AppRevenueHourVO;
 import com.ytpm.middle.view.DashboardAppRevenueVO;
 import org.apache.ibatis.annotations.Param;
 import org.mapstruct.Mapper;
@@ -29,7 +30,7 @@ public interface AdRecordMapper {
      * @param appId
      * @return
      */
-    DashboardAppRevenueVO getHourRevenue(@Param("appId") String appId);
+    List<AppRevenueHourVO> getHourRevenue(@Param("appId") String appId,@Param("type")int type);
 
     /**
      * 根据应用统计激励广告数

+ 20 - 0
yt-app/app-service/src/main/java/com/ytpm/dao/dyz/AppUserMapper.java

@@ -8,6 +8,7 @@ import com.ytpm.app.view.HourCountView;
 import com.ytpm.app.view.WxDefaultConfig;
 import com.ytpm.app.view.YtAppUserListView;
 import com.ytpm.middle.view.AppRankingListVO;
+import com.ytpm.middle.view.AppUserHourVO;
 import com.ytpm.middle.view.UserRankingListVO;
 import org.apache.ibatis.annotations.Param;
 import org.mapstruct.Mapper;
@@ -145,4 +146,23 @@ public interface AppUserMapper {
      * 根据应用查询风控用户数
      */
     int countBannedByAppIds(@Param("appIds")String appIds);
+
+    /**
+     * 统计注册用户数
+     */
+    int countRegistryUser(@Param("appId")String appId, @Param("type")int type);
+    /**
+     * 统计登录用户数
+     */
+    int countLoginUser(@Param("appId")String appId, @Param("type")int type);
+
+    /**
+     * 分时统计注册数
+     */
+    List<AppUserHourVO> countRegistryHour(@Param("appId")String appId, @Param("type")int type);
+
+    /**
+     * 分时统计登录
+     */
+    List<AppUserHourVO> countLoginHour(@Param("appId")String appId, @Param("type")int type);
 }

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

@@ -5,6 +5,7 @@ import com.ytpm.app.param.DyzAdRecordParam;
 import com.ytpm.general.Result;
 import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
+import com.ytpm.middle.view.DashboardRiskVO;
 
 import java.math.BigDecimal;
 import java.util.Map;
@@ -33,4 +34,9 @@ public interface AdService {
      * 查询代理商顶部数据统计
      */
     AgentTopCountView getAppTopCount(String appIds);
+
+    /**
+     * 查询用户风控分时数据统计
+     */
+    DashboardRiskVO userStatics(String appIds);
 }

+ 56 - 8
yt-app/app-service/src/main/java/com/ytpm/service/dyz/impl/AdServiceImpl.java

@@ -16,9 +16,12 @@ import com.ytpm.general.Result;
 import com.ytpm.general.StatusCode;
 import com.ytpm.handle.CustomerException;
 import com.ytpm.middle.view.AppRankingListVO;
+import com.ytpm.middle.view.AppRevenueHourVO;
+import com.ytpm.middle.view.AppUserHourVO;
 import com.ytpm.middle.view.DashboardAppRevenueVO;
 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 com.ytpm.service.dyz.AdService;
 import org.springframework.beans.BeanUtils;
@@ -36,6 +39,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
+import java.util.stream.Collectors;
 
 @Service
 public class AdServiceImpl implements AdService {
@@ -108,20 +112,40 @@ public class AdServiceImpl implements AdService {
         //查询出各应用的用户及收益数据
         List<String> appIdList = Arrays.asList(apkIds.split(","));
         int index = appIdList.size();
-        index--;
         // 由于子表数据庞大导致range查询低于const
         CountDownLatch countDownLatch = new CountDownLatch(index);
+        DashboardAppRevenueVO appRevenueVO;
+        String appId;
         do {
-            String appId = appIdList.get(index);
-            //根据应用ID查询收益数据及个小时数据
-            DashboardAppRevenueVO appRevenueVO =  adRecordMapper.getHourRevenue(appId);
+            --index;
+            appId = appIdList.get(index);
+            //根据应用ID查询收益数据及个小时数据  1-今日
+            List<AppRevenueHourVO> todayRevenues =  adRecordMapper.getHourRevenue(appId,1);
+            Map<String, BigDecimal> todayHourMap = todayRevenues.stream().collect(Collectors.toMap(AppRevenueHourVO::getHour, AppRevenueHourVO::getRevenue));
+            appRevenueVO = new DashboardAppRevenueVO();
+            appRevenueVO.setAppId(appId);
+            //统计今日数据
+            BigDecimal todayRevenue = todayHourMap.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+            appRevenueVO.setTodayHourRevenueMap(todayHourMap);
+            appRevenueVO.setTodayRevenue(todayRevenue);
+            //统计昨日数据
+            List<AppRevenueHourVO> yesterdayRevenues =  adRecordMapper.getHourRevenue(appId,2);
+            Map<String, BigDecimal> yesterdayHourMap = yesterdayRevenues.stream().collect(Collectors.toMap(AppRevenueHourVO::getHour, AppRevenueHourVO::getRevenue));
+            appRevenueVO.setYesterdayHourRevenueMap(yesterdayHourMap);
+            BigDecimal yesterdayRevenue = yesterdayHourMap.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+            appRevenueVO.setYesterdayRevenue(yesterdayRevenue);
+            //统计本月数据
+            List<AppRevenueHourVO> monthRevenues =  adRecordMapper.getHourRevenue(appId,3);
+            BigDecimal monthRevenue = monthRevenues.stream().map(AppRevenueHourVO::getRevenue).reduce(BigDecimal.ZERO, BigDecimal::add);
+            appRevenueVO.setMonthRevenue(monthRevenue);
             appRevenueList.add(appRevenueVO);
             countDownLatch.countDown();
-        }while (index<0);
+        }while (index>0);
         vo.setAppRevenueList(appRevenueList);
-        vo.setTodayTotalRevenue(adRecordMapper.getRevenueByType(apkIds,1));
-        vo.setYesterdayTotalRevenue(adRecordMapper.getRevenueByType(apkIds,2));
-        vo.setMonthTotalRevenue(adRecordMapper.getRevenueByType(apkIds,3));
+        //直接统计各应用的收益
+        vo.setTodayTotalRevenue(appRevenueList.stream().map(DashboardAppRevenueVO::getTodayRevenue).reduce(BigDecimal.ZERO, BigDecimal::add));
+        vo.setYesterdayTotalRevenue(appRevenueList.stream().map(DashboardAppRevenueVO::getYesterdayRevenue).reduce(BigDecimal.ZERO, BigDecimal::add));
+        vo.setMonthTotalRevenue(appRevenueList.stream().map(DashboardAppRevenueVO::getMonthRevenue).reduce(BigDecimal.ZERO, BigDecimal::add));
         return vo;
     }
 
@@ -138,6 +162,30 @@ public class AdServiceImpl implements AdService {
         return view;
     }
 
+    /**
+     * 查询用户风控分时数据统计
+     */
+    @Override
+    public DashboardRiskVO userStatics(String appId) {
+        DashboardRiskVO vo = new DashboardRiskVO();
+        vo.setTodayRegistryCount(appUserMapper.countRegistryUser(appId,1));
+        vo.setYesterdayRegistryCount(appUserMapper.countRegistryUser(appId,2));
+        vo.setMonthRegistryCount(appUserMapper.countRegistryUser(appId,3));
+
+        vo.setTodayLoginCount(appUserMapper.countLoginUser(appId,1));
+        vo.setYesterdayLoginCount(appUserMapper.countLoginUser(appId,2));
+        vo.setMonthLoginCount(appUserMapper.countLoginUser(appId,3));
+
+        List<AppUserHourVO> registryHour = appUserMapper.countRegistryHour(appId,1);
+        Map<String, Integer> registryMap = registryHour.stream().collect(Collectors.toMap(AppUserHourVO::getTime, AppUserHourVO::getCount));
+        vo.setTodayRegistryHourMap(registryMap);
+
+        List<AppUserHourVO> loginHour = appUserMapper.countLoginHour(appId,1);
+        Map<String, Integer> loginMap = loginHour.stream().collect(Collectors.toMap(AppUserHourVO::getTime, AppUserHourVO::getCount));
+        vo.setTodayLoginHourMap(loginMap);
+        return vo;
+    }
+
     /**
      * 保存记录
      *  始终创建新的事务以保障子方法的独立事务

+ 12 - 4
yt-app/app-service/src/main/resources/mapper/dyz/AdRecordMapper.xml

@@ -71,16 +71,24 @@
               </foreach>
         order by finish_time
     </select>
-    <select id="getHourRevenue" resultType="com.ytpm.middle.view.DashboardAppRevenueVO">
+    <select id="getHourRevenue" resultType="com.ytpm.middle.view.AppRevenueHourVO">
         SELECT
-            HOUR(finish_time) number,
-            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `hour`,
+            HOUR(finish_time) `hour`,
+            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `time`,
             sum( revenue ) revenue
         FROM
             yt_dyz_ad_record
         WHERE
             app_id = #{appId}
-          and DATE( finish_time ) = DATE(now())
+            <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`
     </select>

+ 64 - 0
yt-app/app-service/src/main/resources/mapper/dyz/AppUserMapper.xml

@@ -440,4 +440,68 @@
             #{item}
         </foreach>
     </select>
+    <select id="countRegistryUser" resultType="java.lang.Integer">
+        select
+        count(user_id)
+        from yt_dyz_user
+        where app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(registry_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(registry_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(registry_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
+    </select>
+    <select id="countLoginUser" resultType="java.lang.Integer">
+        select
+        count(user_id)
+        from yt_dyz_user
+        where app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(last_login_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(last_login_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
+    </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`
+        from yt_dyz_user
+        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>
+        group by `time`
+    </select>
+    <select id="countLoginHour" resultType="com.ytpm.middle.view.AppUserHourVO">
+        select
+        DATE_FORMAT(last_login_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">
+            and DATE(last_login_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(last_login_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(last_login_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
+        group by `time`
+    </select>
 </mapper>

+ 2 - 0
yt-common/src/main/java/com/ytpm/agent/param/AppListParam.java

@@ -22,4 +22,6 @@ public class AppListParam extends PageMeta {
     private Integer appType;
     @ApiModelProperty("渠道名称")
     private String channelName;
+    @ApiModelProperty("上级应用ID")
+    private String superiorId;
 }

+ 25 - 0
yt-common/src/main/java/com/ytpm/middle/view/AppRevenueHourVO.java

@@ -0,0 +1,25 @@
+package com.ytpm.middle.view;
+
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+
+/**
+ * @author Marx
+ * @date 2025/7/30 11:19
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ApiModel("收益分时统计数据")
+public class AppRevenueHourVO {
+    /** 小时 */
+    private String hour;
+    /** 时间 */
+    private String time;
+    /** 收益 */
+    private BigDecimal revenue;
+}

+ 21 - 0
yt-common/src/main/java/com/ytpm/middle/view/AppUserHourVO.java

@@ -0,0 +1,21 @@
+package com.ytpm.middle.view;
+
+import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author marx
+ * @date 2025/7/30 15:11
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ApiModel("收益分时统计数据")
+public class AppUserHourVO {
+    /** 分时 */
+    private String time;
+    /** 数量 */
+    private int count;
+}

+ 4 - 2
yt-common/src/main/java/com/ytpm/middle/view/DashboardAppRevenueVO.java

@@ -28,6 +28,8 @@ public class DashboardAppRevenueVO {
     private BigDecimal yesterdayRevenue;
     @ApiModelProperty("当月收益")
     private BigDecimal monthRevenue;
-    @ApiModelProperty("分小时收益集合")
-    private Map<String,Integer> hourRevenueMap;
+    @ApiModelProperty("今日分小时收益集合")
+    private Map<String,BigDecimal> todayHourRevenueMap;
+    @ApiModelProperty("昨日")
+    private Map<String,BigDecimal> yesterdayHourRevenueMap;
 }

+ 44 - 0
yt-common/src/main/java/com/ytpm/middle/view/DashboardRiskVO.java

@@ -0,0 +1,44 @@
+package com.ytpm.middle.view;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Map;
+
+/**
+ * @author marx
+ * @date 2025/7/30 10:57
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ApiModel("用户统计返回数据")
+public class DashboardRiskVO {
+    @ApiModelProperty("今日注册数")
+    private int todayRegistryCount;
+    @ApiModelProperty("今日登录数")
+    private int todayLoginCount;
+    @ApiModelProperty("今日新增封禁")
+    private int todayBannedCount;
+    @ApiModelProperty("今日分时注册统计")
+    private Map<String,Integer> todayRegistryHourMap;
+    @ApiModelProperty("今日分时登录统计")
+    private Map<String,Integer> todayLoginHourMap;
+    @ApiModelProperty("今日分时风控统计")
+    private Map<String,Integer> todayBannedHourMap;
+    @ApiModelProperty("昨日注册数")
+    private int yesterdayRegistryCount;
+    @ApiModelProperty("昨日登录数")
+    private int yesterdayLoginCount;
+    @ApiModelProperty("昨日新增封禁")
+    private int yesterdayBannedCount;
+    @ApiModelProperty("本月注册数")
+    private int monthRegistryCount;
+    @ApiModelProperty("本月登录数")
+    private int monthLoginCount;
+    @ApiModelProperty("本月新增封禁")
+    private int monthBannedCount;
+}

+ 10 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/controller/HomeController.java

@@ -4,6 +4,7 @@ import com.ytpm.general.Result;
 import com.ytpm.middle.service.CountService;
 import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
+import com.ytpm.middle.view.DashboardRiskVO;
 import com.ytpm.middle.view.DashboardTopCountVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -42,4 +43,13 @@ public class HomeController {
     public Result<DashboardRevenueVO> getRevenueStatics(@RequestParam(name = "appId")String appId) {
         return countService.getRevenueStatics(appId);
     }
+
+    @ApiImplicitParam(name="appId", value = "所属应用ID")
+    @ApiOperation(value = "根据应用ID获取用户风控数据")
+    @GetMapping("/userStatics")
+    public Result<DashboardRiskVO> getUserStatics(@RequestParam(name = "appId")String appId) {
+        return countService.getUserStatics(appId);
+    }
+
+
 }

+ 13 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/dao/RiskMapper.java

@@ -1,11 +1,14 @@
 package com.ytpm.middle.dao;
 
+import com.ytpm.middle.view.AppUserHourVO;
 import com.ytpm.risk.model.YtRiskConfig;
 import com.ytpm.risk.model.YtRiskTemplate;
 import com.ytpm.risk.model.YtRiskTemplateConfig;
 import org.apache.ibatis.annotations.Param;
 import org.mapstruct.Mapper;
 
+import java.util.List;
+
 @Mapper
 public interface RiskMapper {
     /**
@@ -27,4 +30,14 @@ public interface RiskMapper {
      * 根据应用查询风控配置
      */
     YtRiskTemplate getTemplateByAppId(@Param("appId") String appId);
+
+    /**
+     * 查询风控数
+     */
+    int countBanned(@Param("appId")String appId, @Param("type")int type);
+
+    /**
+     * 分时统计风控数
+     */
+    List<AppUserHourVO> countBannedHour(@Param("appId")String appId, @Param("type")int type);
 }

+ 6 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/CountService.java

@@ -3,6 +3,7 @@ package com.ytpm.middle.service;
 import com.ytpm.general.Result;
 import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
+import com.ytpm.middle.view.DashboardRiskVO;
 import com.ytpm.middle.view.DashboardTopCountVo;
 
 public interface CountService {
@@ -20,4 +21,9 @@ public interface CountService {
      * 根据应用查询各渠道包分时收益
      */
     Result<DashboardRevenueVO> getRevenueStatics(String appId);
+
+    /**
+     * 根据应用获取用户风控数据
+     */
+    Result<DashboardRiskVO> getUserStatics(String appId);
 }

+ 31 - 0
yt-middle/middle-platform/src/main/java/com/ytpm/middle/service/impl/CountServiceImpl.java

@@ -1,16 +1,21 @@
 package com.ytpm.middle.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import com.alibaba.fastjson.JSON;
 import com.ytpm.agent.view.AgentAppView;
 import com.ytpm.feign.AppFeign;
 import com.ytpm.general.Result;
 import com.ytpm.middle.dao.ApkMapper;
 import com.ytpm.middle.dao.EnterpriseMapper;
+import com.ytpm.middle.dao.RiskMapper;
 import com.ytpm.middle.service.CountService;
 import com.ytpm.middle.util.RedisUtil;
 import com.ytpm.middle.view.AppRankingListVO;
+import com.ytpm.middle.view.AppUserHourVO;
+import com.ytpm.middle.view.DashboardAppRevenueVO;
 import com.ytpm.middle.view.DashboardRankingListVO;
 import com.ytpm.middle.view.DashboardRevenueVO;
+import com.ytpm.middle.view.DashboardRiskVO;
 import com.ytpm.middle.view.DashboardTopCountVo;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -32,6 +37,8 @@ public class CountServiceImpl implements CountService {
     @Resource
     private AppFeign appFeign;
     @Resource
+    private RiskMapper riskMapper;
+    @Resource
     private RedisUtil redisUtil;
     @Value("${ranking.expire}")
     private long rankingExpire;
@@ -97,6 +104,30 @@ public class CountServiceImpl implements CountService {
         List<AgentAppView> apkList =  apkMapper.queryBySuperiorId(appId);
         String apkIds = apkList.stream().map(AgentAppView::getAppId).collect(Collectors.joining(","));
         DashboardRevenueVO vo =  appFeign.revenueStatics(apkIds);
+        Map<String, String> appNameMap = apkList.stream().collect(Collectors.toMap(AgentAppView::getAppId, AgentAppView::getAppName));
+        List<DashboardAppRevenueVO> appRevenueList = vo.getAppRevenueList();
+        for (DashboardAppRevenueVO revenueVO : appRevenueList) {
+            revenueVO.setAppName(appNameMap.get(revenueVO.getAppId()));
+        }
+        vo.setAppRevenueList(appRevenueList);
+        return Result.resultObjOk(vo);
+    }
+
+    /**
+     * 根据应用查询风控用户数据
+     */
+    @Override
+    public Result<DashboardRiskVO> getUserStatics(String appId) {
+        DashboardRiskVO vo = appFeign.userStatics(appId);
+        vo.setTodayBannedCount(riskMapper.countBanned(appId,1));
+        vo.setYesterdayBannedCount(riskMapper.countBanned(appId,2));
+        vo.setMonthBannedCount(riskMapper.countBanned(appId,3));
+        List<AppUserHourVO> bannedHour = riskMapper.countBannedHour(appId,1);
+        if(CollUtil.isNotEmpty(bannedHour)){
+            Map<String, Integer> collect = bannedHour.stream().collect(
+                    Collectors.toMap(AppUserHourVO::getTime, AppUserHourVO::getCount));
+            vo.setTodayBannedHourMap(collect);
+        }
         return Result.resultObjOk(vo);
     }
 }

+ 3 - 0
yt-middle/middle-platform/src/main/resources/mapper/ApkMapper.xml

@@ -40,6 +40,9 @@
             <if test="appType !=null">
                 and ya.app_type = #{appType}
             </if>
+            <if test="superiorId !=null and superiorId != ''">
+                and ya.superior_id = #{superiorId}
+            </if>
         </where>
         GROUP BY
         ya.app_id

+ 1 - 1
yt-middle/middle-platform/src/main/resources/mapper/PermissionMapper.xml

@@ -166,7 +166,7 @@
         select
             permission_id, permission_name, permission_code, type, parent_id, target, icon, href, route, sort, create_time, create_user_id, update_time, update_user_id, available
         from yt_middle_permission
-        where type = #{type}
+        where available = 1 and type = #{type}
     </select>
     <select id="getFirstMenuByRoleIds" resultType="com.ytpm.middle.view.MiddlePermissionVO">
         select DISTINCT

+ 31 - 0
yt-middle/middle-platform/src/main/resources/mapper/RiskMapper.xml

@@ -80,4 +80,35 @@
         from yt_risk_template
         where app_id = #{appId}
     </select>
+    <select id="countBanned" resultType="java.lang.Integer">
+        select
+            count(distinct user_id)
+        from yt_platform_banned
+        where app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(banned_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(banned_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(banned_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
+    </select>
+    <select id="countBannedHour" resultType="com.ytpm.middle.view.AppUserHourVO">
+        select
+        DATE_FORMAT(banned_time,'%Y-%m-%d %H:00:00') as `time`,
+        count(distinct user_id)`count`
+        from yt_platform_banned
+        where app_id = #{appId}
+        <if test="type != null and type ==1">
+            and DATE(banned_time) = DATE(now())
+        </if>
+        <if test="type != null and type ==2">
+            and DATE(banned_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
+        </if>
+        <if test="type != null and type ==3">
+            and DATE_FORMAT(banned_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
+        </if>
+    </select>
 </mapper>