DailyReportChannelMapper.xml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.juxiao.xchat.module.xbd.mapper.marketing.DailyReportChannelMapper">
  6. <resultMap id="BaseResultMap" type="com.juxiao.xchat.module.xbd.domain.marketing.DailyReportChannel" >
  7. <id column="report_id" property="reportId" jdbcType="INTEGER"/>
  8. <result column="reportDate" property="reportDate" jdbcType="TIMESTAMP"/>
  9. <result column="str1" property="str1" jdbcType="VARCHAR"/>
  10. <result column="str2" property="str2" jdbcType="VARCHAR"/>
  11. <result column="str3" property="str3" jdbcType="VARCHAR"/>
  12. <result column="str4" property="str4" jdbcType="VARCHAR"/>
  13. <result column="str5" property="str5" jdbcType="VARCHAR"/>
  14. <result column="str6" property="str6" jdbcType="VARCHAR"/>
  15. <result column="str7" property="str7" jdbcType="VARCHAR"/>
  16. <result column="str8" property="str8" jdbcType="VARCHAR"/>
  17. <result column="str9" property="str9" jdbcType="VARCHAR"/>
  18. <result column="str10" property="str10" jdbcType="VARCHAR"/>
  19. <result column="str11" property="str11" jdbcType="VARCHAR"/>
  20. <result column="str12" property="str12" jdbcType="VARCHAR"/>
  21. <result column="str13" property="str13" jdbcType="VARCHAR"/>
  22. <result column="str14" property="str14" jdbcType="VARCHAR"/>
  23. <result column="str15" property="str15" jdbcType="VARCHAR"/>
  24. <result column="str16" property="str16" jdbcType="VARCHAR"/>
  25. <result column="str17" property="str17" jdbcType="VARCHAR"/>
  26. <result column="str18" property="str18" jdbcType="VARCHAR"/>
  27. <result column="str19" property="str19" jdbcType="VARCHAR"/>
  28. <result column="str20" property="str20" jdbcType="VARCHAR"/>
  29. <result column="str21" property="str21" jdbcType="VARCHAR"/>
  30. <result column="str22" property="str22" jdbcType="VARCHAR"/>
  31. <result column="str23" property="str23" jdbcType="VARCHAR"/>
  32. <result column="str24" property="str24" jdbcType="VARCHAR"/>
  33. <result column="str25" property="str25" jdbcType="VARCHAR"/>
  34. <result column="str26" property="str26" jdbcType="VARCHAR"/>
  35. <result column="str27" property="str27" jdbcType="VARCHAR"/>
  36. <result column="str28" property="str28" jdbcType="VARCHAR"/>
  37. <result column="str29" property="str29" jdbcType="VARCHAR"/>
  38. <result column="str30" property="str30" jdbcType="VARCHAR"/>
  39. </resultMap>
  40. <select id="selectDailyReportChannelByList" resultMap="BaseResultMap">
  41. SELECT if(#{statistical} = 1, drc.report_date, null) as reportDate, if(#{statistical} = 2, drc.str1, ifnull(#{channel}, '全部')) as str1, sum(drc.str2) as str2, sum(drc.str3) as str3, sum(drc.str5) as str5, sum(drc.str6) as str6, sum(drc.str7) as str7, sum(drc.str8) as str8,
  42. 0 as str9, 0 as str10, 0 as str11, 0 as str12, 0 as str13, 0 as str14, 0 as str15, 0 as str16, 0 as str17, 0 as str18, 0 as str19, 0 as str20, 0 as str21,
  43. sum(drc.str5) - sum(drc.str3) as str22,
  44. CONCAT(if(sum(drc.str2) = 0, 0, ROUND(sum(drc.str3)*100/sum(drc.str2), 2)),'%') as str23,
  45. CONCAT(if(sum(drc.str3) = 0, 0, ROUND(sum(drc.str4)*100/sum(drc.str3), 2)),'%') as str24,
  46. CONCAT(if(sum(drc.str3) = 0, 0, ROUND(sum(drc.str6)*100/sum(drc.str3), 2)),'%') as str27,
  47. '0.00%' as str25, '0.00%' as str26, 0 as str28, 0 as str29, 0 as str30
  48. from daily_report_channel drc
  49. where 1=1
  50. <if test="channel != null and channel != ''">
  51. AND drc.str1 in (SELECT hc.channel from home_channel hc where hc.channel = #{channel} UNION ALL SELECT hc.channel from home_channel hc where hc.superior_channel = #{channel})
  52. </if>
  53. <if test="app != null and app != ''">
  54. AND drc.str9 = #{app}
  55. </if>
  56. <choose>
  57. <when test="statistical == 1">
  58. <if test="beginTime != null and beginTime != ''">
  59. AND drc.report_date &gt;= #{beginTime}
  60. </if>
  61. <if test="endTime != null and endTime != ''">
  62. AND drc.report_date &lt;= #{endTime}
  63. </if>
  64. GROUP BY drc.report_date
  65. ORDER BY drc.report_date desc, drc.str1
  66. </when>
  67. <when test="statistical==2">
  68. <if test="beginTime != null and beginTime != ''">
  69. AND drc.report_date = #{beginTime}
  70. </if>
  71. GROUP BY drc.str1
  72. ORDER BY drc.str1, drc.report_date desc
  73. </when>
  74. </choose>
  75. </select>
  76. <select id="selectDailyReportChannelRetain" resultMap="BaseResultMap">
  77. SELECT
  78. CONCAT(ROUND(sum(if(a.idiff = 1, 1, 0))*100/COUNT(DISTINCT a.deviceId), 2),'%') as str1,
  79. CONCAT(ROUND(sum(if(a.idiff = 7, 1, 0))*100/COUNT(DISTINCT a.deviceId), 2),'%') as str2,
  80. CONCAT(ROUND(sum(if(a.idiff = 30, 1, 0))*100/COUNT(DISTINCT a.deviceId), 2),'%') as str3,
  81. sum(if(a.idiff = 1, 1, 0)) as str4
  82. FROM
  83. (SELECT
  84. u.device_id as deviceId, DATEDIFF(alr.create_time, #{startDate}) as idiff
  85. from users u
  86. INNER JOIN home_channel hc on u.channel = hc.channel
  87. LEFT JOIN account_login_record alr on alr.uid = u.uid
  88. where
  89. u.def_user = 1 and u.create_time BETWEEN #{startDate} and #{endDate}
  90. and alr.create_time BETWEEN #{startDate} and date_add(#{endDate}, interval 30 day)
  91. <if test="channel != null and channel != ''">
  92. AND (hc.channel = #{channel} or hc.superior_channel = #{channel})
  93. </if>
  94. <if test="app != null and app != ''">
  95. <if test="app == 'tmxq_an'">
  96. AND ifnull(u.app, '') = 'tmxq_an'
  97. </if>
  98. <if test="app != 'tmxq_an'">
  99. AND ifnull(u.app, '') != 'tmxq_an'
  100. </if>
  101. </if>
  102. GROUP BY u.device_id, idiff
  103. ) a
  104. </select>
  105. <select id="selectDailyReportChannelCharge" resultMap="BaseResultMap">
  106. SELECT
  107. ROUND(sum(if(a.cdiff &lt; 8, a.amount/100, 0)), 0) as str1,
  108. ROUND(sum(if(a.cdiff &lt; 16, a.amount/100, 0)), 0) as str2,
  109. ROUND(sum(a.amount/100), 0) as str3
  110. FROM
  111. (SELECT
  112. DATEDIFF(cr.create_time, #{startDate}) as cdiff,
  113. cr.amount
  114. from users u
  115. INNER JOIN home_channel hc on u.channel = hc.channel
  116. LEFT JOIN charge_record cr on u.uid = cr.uid and cr.charge_status = 2 and cr.create_time BETWEEN #{startDate} and DATE_ADD(#{endDate}, INTERVAL 30 DAY)
  117. where
  118. u.def_user = 1 and u.create_time BETWEEN #{startDate} and #{endDate}
  119. <if test="channel != null and channel != ''">
  120. AND (hc.channel = #{channel} or hc.superior_channel = #{channel})
  121. </if>
  122. <if test="app != null and app != ''">
  123. <if test="app == 'tmxq_an'">
  124. AND ifnull(u.app, '') = 'tmxq_an'
  125. </if>
  126. <if test="app != 'tmxq_an'">
  127. AND ifnull(u.app, '') != 'tmxq_an'
  128. </if>
  129. </if>
  130. ) a
  131. </select>
  132. <resultMap id="BaseDailyReportChannelPutInResultMap" type="com.juxiao.xchat.module.xbd.domain.marketing.DailyReportChannelPutIn" >
  133. <id column="put_in_date" property="putInDate" jdbcType="TIMESTAMP" />
  134. <id column="channel" property="channel" jdbcType="VARCHAR" />
  135. <id column="app" property="app" jdbcType="VARCHAR" />
  136. <result column="amount_invested" property="amountInvested" jdbcType="INTEGER" />
  137. <result column="total_download" property="totalDownload" jdbcType="INTEGER" />
  138. <result column="purchase_download" property="purchaseDownload" jdbcType="INTEGER" />
  139. </resultMap>
  140. <select id="selectDailyReportChannelPutIn" resultMap="BaseDailyReportChannelPutInResultMap">
  141. SELECT
  142. SUM(drcpi.amount_invested) as amountInvested, SUM(drcpi.total_download) as totalDownload, SUM(drcpi.purchase_download) as purchaseDownload
  143. FROM
  144. daily_report_channel_put_in drcpi
  145. INNER JOIN home_channel hc on drcpi.channel = hc.channel
  146. WHERE
  147. 1 = 1
  148. <if test="putInDate != null">
  149. AND drcpi.put_in_date = #{putInDate}
  150. </if>
  151. <if test="channel != null and channel != ''">
  152. AND (hc.channel = #{channel} or hc.superior_channel = #{channel})
  153. </if>
  154. <if test="app != null and app != ''">
  155. and drcpi.app = #{app}
  156. </if>
  157. </select>
  158. </mapper>