Bläddra i källkod

ADS 调用首页分时收益统计

marxjaw 3 månader sedan
förälder
incheckning
793c903e2a

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

@@ -5,6 +5,7 @@ import com.ytpm.middle.view.DashboardAppRevenueVO;
 import org.apache.ibatis.annotations.Param;
 import org.mapstruct.Mapper;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 @Mapper
@@ -34,4 +35,9 @@ public interface AdRecordMapper {
      * 根据应用统计激励广告数
      */
     int countByAppIds(@Param("appIds")String appIds);
+
+    /**
+     * 根据应用查询收益
+     */
+    BigDecimal getRevenueByType(@Param("appIds") String appIds,@Param("type") int type);
 }

+ 10 - 3
yt-app/app-service/src/main/java/com/ytpm/service/dyz/impl/AdServiceImpl.java

@@ -29,6 +29,7 @@ import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -98,11 +99,12 @@ public class AdServiceImpl implements AdService {
     }
 
     /**
-     *  TODO 查询各渠道应用收益分时统计
+     *  查询各渠道应用收益分时统计
      */
     @Override
     public DashboardRevenueVO revenueStatics(String apkIds) {
         DashboardRevenueVO vo = new DashboardRevenueVO();
+        List<DashboardAppRevenueVO> appRevenueList = new ArrayList<>();
         //查询出各应用的用户及收益数据
         List<String> appIdList = Arrays.asList(apkIds.split(","));
         int index = appIdList.size();
@@ -113,9 +115,14 @@ public class AdServiceImpl implements AdService {
             String appId = appIdList.get(index);
             //根据应用ID查询收益数据及个小时数据
             DashboardAppRevenueVO appRevenueVO =  adRecordMapper.getHourRevenue(appId);
-
+            appRevenueList.add(appRevenueVO);
+            countDownLatch.countDown();
         }while (index<0);
-        return null;
+        vo.setAppRevenueList(appRevenueList);
+        vo.setTodayTotalRevenue(adRecordMapper.getRevenueByType(apkIds,1));
+        vo.setYesterdayTotalRevenue(adRecordMapper.getRevenueByType(apkIds,2));
+        vo.setMonthTotalRevenue(adRecordMapper.getRevenueByType(apkIds,3));
+        return vo;
     }
 
     /**

+ 31 - 1
yt-app/app-service/src/main/resources/mapper/dyz/AdRecordMapper.xml

@@ -72,6 +72,36 @@
         order by finish_time
     </select>
     <select id="getHourRevenue" resultType="com.ytpm.middle.view.DashboardAppRevenueVO">
-
+        SELECT
+            HOUR(finish_time) number,
+            DATE_FORMAT(finish_time,'%Y-%m-%d %H:00:00') as `hour`,
+            sum( revenue ) revenue
+        FROM
+            yt_dyz_ad_record
+        WHERE
+            app_id = #{appId}
+          and DATE( finish_time ) = DATE(now())
+        GROUP BY
+            `hour`
+    </select>
+    <select id="getRevenueByType" resultType="java.math.BigDecimal">
+        SELECT
+            sum( revenue ) revenue
+        FROM
+            yt_dyz_ad_record
+        WHERE
+            app_id in
+            <foreach collection="appIds.split(',')" separator="," item="item" open="(" close=")">
+                #{item}
+            </foreach>
+            <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>
     </select>
 </mapper>