DataMapper.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.fdkankan.manage.mapper.IDataMapper">
  4. <select id="userDataGroupBy" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
  5. SELECT DATE_FORMAT(create_time,#{dateFormat}) AS groupKey, count(id) AS count FROM ${tb} WHERE rec_status = 'A'
  6. and create_time between #{startTime} and #{endTime}
  7. <include refid="tbWhereSql"></include>
  8. GROUP BY groupKey
  9. </select>
  10. <select id="userDataSumGroupBy" resultType="com.fdkankan.manage.vo.response.DataGroupBySum">
  11. SELECT DATE_FORMAT(create_time,#{dateFormat}) AS groupKey,
  12. <if test="tb == 't_order'">
  13. sum(total_amount) AS count
  14. </if>
  15. <if test="tb != 't_order'">
  16. sum(amount) AS count
  17. </if>
  18. FROM ${tb} WHERE rec_status = 'A'
  19. and create_time between #{startTime} and #{endTime}
  20. <include refid="tbWhereSql"></include>
  21. GROUP BY groupKey
  22. </select>
  23. <select id="userDataGroupByWeek" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
  24. SELECT groupKey ,count(1) as count FROM (
  25. select date_format(date_add(create_time,interval-(weekday(create_time ))day),'%Y-%m-%d') as groupKey
  26. from ${tb}
  27. WHERE rec_status = 'A'
  28. and create_time between #{startTime} and #{endTime}
  29. <include refid="tbWhereSql"></include>
  30. ) as tb GROUP BY groupKey
  31. </select>
  32. <select id="userDataSumGroupByWeek" resultType="com.fdkankan.manage.vo.response.DataGroupBySum">
  33. SELECT groupKey ,sum(amount) as count FROM (
  34. select
  35. <if test="tb == 't_order'">
  36. total_amount as amount
  37. </if>
  38. <if test="tb != 't_order'">
  39. amount
  40. </if>
  41. ,date_format(date_add(create_time,interval-(weekday(create_time ))day),'%Y-%m-%d') as groupKey
  42. from ${tb}
  43. WHERE rec_status = 'A'
  44. and create_time between #{startTime} and #{endTime}
  45. <include refid="tbWhereSql"></include>
  46. ) as tb GROUP BY groupKey
  47. </select>
  48. <sql id="typeSQL">
  49. <if test="type == 1">
  50. and is_upgrade = 0
  51. </if>
  52. <if test="type == 2">
  53. and pay_status = 1
  54. </if>
  55. </sql>
  56. <sql id="tbWhereSql">
  57. <if test="tb == 't_increment_order' || tb == 't_download_order'">
  58. and pay_status = 1
  59. </if>
  60. </sql>
  61. <select id="totalUserCount" resultType="java.lang.Long">
  62. select count(id) from ${tb} where rec_status = 'A'
  63. <include refid="typeSQL"></include>
  64. </select>
  65. <select id="preMonthAddCount" resultType="java.lang.Long">
  66. SELECT count(id) FROM ${tb}
  67. WHERE rec_status = 'A' and date_format(create_time, '%Y %m') = date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y %m')
  68. <include refid="typeSQL"></include>
  69. </select>
  70. <select id="todayAddCount" resultType="java.lang.Long">
  71. SELECT count(id) FROM ${tb}
  72. WHERE rec_status = 'A' and DATEDIFF(create_time,NOW())=0
  73. <include refid="typeSQL"></include>
  74. </select>
  75. <select id="todayActiveCount" resultType="java.lang.Long">
  76. SELECT count(distinct user_name) FROM t_login_log
  77. WHERE rec_status = 'A' and DATEDIFF(create_time,NOW())=0
  78. </select>
  79. <select id="sceneGroupBy" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
  80. SELECT DATE_FORMAT(create_time,#{dateFormat}) AS groupKey, count(id) AS count ,
  81. <if test="tb == 't_scene_pro' or tb == 't_scene_plus' ">
  82. scene_source as groupKey2
  83. </if>
  84. <if test="tb == 't_camera_detail'">
  85. type as groupKey2
  86. </if>
  87. FROM ${tb}
  88. WHERE rec_status = 'A'
  89. <if test="tb == 't_scene_pro'">
  90. AND is_upgrade = 0
  91. </if>
  92. and create_time between #{startTime} and #{endTime}
  93. GROUP BY groupKey ,groupKey2
  94. </select>
  95. <select id="sceneGroupByWeek" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
  96. SELECT groupKey ,count(1) as count,
  97. <if test="tb == 't_scene_pro' or tb == 't_scene_plus' ">
  98. scene_source as groupKey2
  99. </if>
  100. <if test="tb == 't_camera_detail'">
  101. type as groupKey2
  102. </if>
  103. FROM (
  104. select date_format(date_add(create_time,interval-(weekday(create_time ))day),'%Y-%m-%d') as groupKey,
  105. <if test="tb == 't_scene_pro' or tb == 't_scene_plus' ">
  106. scene_source
  107. </if>
  108. <if test="tb == 't_camera_detail'">
  109. type
  110. </if>
  111. from ${tb}
  112. WHERE rec_status = 'A'
  113. <if test="tb == 't_scene_pro'">
  114. AND is_upgrade = 0
  115. </if>
  116. and create_time between #{startTime} and #{endTime}
  117. ) as tb GROUP BY groupKey,groupKey2
  118. </select>
  119. <select id="sceneObjGroupBy" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
  120. SELECT DATE_FORMAT( p.create_time,#{dateFormat}) AS groupKey, count(p.id) AS count , scene_source as groupKey2
  121. FROM ${tb} p
  122. <if test="tb == 't_scene_plus'">
  123. LEFT JOIN t_scene_plus_ext e on p.id = e.plus_id
  124. </if>
  125. WHERE p.rec_status = 'A' and is_obj = 1
  126. <if test="tb == 't_scene_pro'">
  127. AND is_upgrade = 0
  128. </if>
  129. and p.create_time between #{startTime} and #{endTime}
  130. GROUP BY groupKey ,groupKey2
  131. </select>
  132. <select id="sceneObjGroupByWeek" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
  133. SELECT groupKey ,count(1) as count, scene_source as groupKey2
  134. FROM (
  135. select date_format(date_add(p.create_time,interval-(weekday(p.create_time ))day),'%Y-%m-%d') as groupKey,scene_source
  136. from ${tb} p
  137. <if test="tb == 't_scene_plus'">
  138. LEFT JOIN t_scene_plus_ext e on p.id = e.plus_id
  139. </if>
  140. WHERE p.rec_status = 'A' and is_obj = 1
  141. <if test="tb == 't_scene_pro'">
  142. AND is_upgrade = 0
  143. </if>
  144. and p.create_time between #{startTime} and #{endTime}
  145. ) as tb GROUP BY groupKey,groupKey2
  146. </select>
  147. <select id="sceneOutTimeGroupBy" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
  148. SELECT DATE_FORMAT(out_time,#{dateFormat}) AS groupKey, count(id) AS count ,
  149. <if test="tb == 't_scene_pro' or tb == 't_scene_plus' ">
  150. scene_source as groupKey2
  151. </if>
  152. <if test="tb == 't_camera_detail'">
  153. type as groupKey2
  154. </if>
  155. FROM ${tb}
  156. WHERE rec_status = 'A'
  157. <if test="tb == 't_scene_pro'">
  158. AND is_upgrade = 0
  159. </if>
  160. and out_time between #{startTime} and #{endTime}
  161. GROUP BY groupKey ,groupKey2
  162. </select>
  163. <select id="sceneOutTimeGroupByWeek" resultType="com.fdkankan.manage.vo.response.DataGroupByCount">
  164. SELECT groupKey ,count(1) as count,
  165. <if test="tb == 't_scene_pro' or tb == 't_scene_plus' ">
  166. scene_source as groupKey2
  167. </if>
  168. <if test="tb == 't_camera_detail'">
  169. type as groupKey2
  170. </if>
  171. FROM (
  172. select date_format(date_add(out_time,interval-(weekday(out_time ))day),'%Y-%m-%d') as groupKey,
  173. <if test="tb == 't_scene_pro' or tb == 't_scene_plus' ">
  174. scene_source
  175. </if>
  176. <if test="tb == 't_camera_detail'">
  177. type
  178. </if>
  179. from ${tb}
  180. WHERE rec_status = 'A'
  181. <if test="tb == 't_scene_pro'">
  182. AND is_upgrade = 0
  183. </if>
  184. and out_time between #{startTime} and #{endTime}
  185. ) as tb GROUP BY groupKey,groupKey2
  186. </select>
  187. </mapper>