AppUserAgentMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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.game.business.mapper.AppUserAgentMapper">
  6. <resultMap type="com.game.business.domain.AppUserAgent" id="AppUserAgentResult">
  7. <result property="id" column="id" />
  8. <result property="userId" column="user_id" />
  9. <result property="pid" column="pid" />
  10. <result property="topId" column="top_id" />
  11. <result property="liveRate" column="live_rate" />
  12. <result property="dividendGuaranteeRate" column="dividend_guarantee_rate" />
  13. <result property="auditStatus" column="audit_status" />
  14. <result property="createTime" column="create_time" />
  15. <result property="updateTime" column="update_time" />
  16. </resultMap>
  17. <sql id="selectAppUserAgentVo">
  18. select id, user_id, pid, top_id, live_rate, dividend_guarantee_rate, audit_status, create_time, update_time from app_user_agent
  19. </sql>
  20. <select id="selectAppUserAgentList" parameterType="com.game.business.domain.AppUserAgent" resultMap="AppUserAgentResult">
  21. <include refid="selectAppUserAgentVo"/>
  22. <where>
  23. <if test="userId != null "> and user_id = #{userId}</if>
  24. <if test="pid != null "> and pid = #{pid}</if>
  25. <if test="topId != null "> and top_id = #{topId}</if>
  26. <if test="liveRate != null "> and live_rate = #{liveRate}</if>
  27. <if test="dividendGuaranteeRate != null "> and dividend_guarantee_rate = #{dividendGuaranteeRate}</if>
  28. <if test="auditStatus != null and auditStatus != ''"> and audit_status = #{auditStatus}</if>
  29. </where>
  30. </select>
  31. <select id="selectAppUserAgentById" parameterType="Long" resultMap="AppUserAgentResult">
  32. <include refid="selectAppUserAgentVo"/>
  33. where id = #{id}
  34. </select>
  35. <insert id="insertAppUserAgent" parameterType="com.game.business.domain.AppUserAgent" useGeneratedKeys="true" keyProperty="id">
  36. insert into app_user_agent
  37. <trim prefix="(" suffix=")" suffixOverrides=",">
  38. <if test="id != null">id,</if>
  39. <if test="userId != null">user_id,</if>
  40. <if test="pid != null">pid,</if>
  41. <if test="topId != null">top_id,</if>
  42. <if test="liveRate != null">live_rate,</if>
  43. <if test="dividendGuaranteeRate != null">dividend_guarantee_rate,</if>
  44. <if test="auditStatus != null">audit_status,</if>
  45. <if test="createTime != null">create_time,</if>
  46. <if test="updateTime != null">update_time,</if>
  47. </trim>
  48. <trim prefix="values (" suffix=")" suffixOverrides=",">
  49. <if test="id != null">#{id},</if>
  50. <if test="userId != null">#{userId},</if>
  51. <if test="pid != null">#{pid},</if>
  52. <if test="topId != null">#{topId},</if>
  53. <if test="liveRate != null">#{liveRate},</if>
  54. <if test="dividendGuaranteeRate != null">#{dividendGuaranteeRate},</if>
  55. <if test="auditStatus != null">#{auditStatus},</if>
  56. <if test="createTime != null">#{createTime},</if>
  57. <if test="updateTime != null">#{updateTime},</if>
  58. </trim>
  59. </insert>
  60. <update id="updateAppUserAgent" parameterType="com.game.business.domain.AppUserAgent">
  61. update app_user_agent
  62. <trim prefix="SET" suffixOverrides=",">
  63. <if test="userId != null">user_id = #{userId},</if>
  64. <if test="pid != null">pid = #{pid},</if>
  65. <if test="topId != null">top_id = #{topId},</if>
  66. <if test="liveRate != null">live_rate = #{liveRate},</if>
  67. <if test="dividendGuaranteeRate != null">dividend_guarantee_rate = #{dividendGuaranteeRate},</if>
  68. <if test="auditStatus != null">audit_status = #{auditStatus},</if>
  69. <if test="createTime != null">create_time = #{createTime},</if>
  70. <if test="updateTime != null">update_time = #{updateTime},</if>
  71. </trim>
  72. where id = #{id}
  73. </update>
  74. <delete id="deleteAppUserAgentById" parameterType="Long">
  75. delete from app_user_agent where id = #{id}
  76. </delete>
  77. <delete id="deleteAppUserAgentByIds" parameterType="String">
  78. delete from app_user_agent where id in
  79. <foreach item="id" collection="array" open="(" separator="," close=")">
  80. #{id}
  81. </foreach>
  82. </delete>
  83. <select id="sumBetting" resultType="java.lang.Double">
  84. select IFNULL(sum(betting_amount),0) as amount
  85. from app_user_agent as a left join app_game_betting as b on a.user_id = b.user_id
  86. where b.create_time between #{beginTime} and #{endTime}
  87. and a.pid = #{pid}
  88. </select>
  89. <select id="teamList" resultType="com.game.business.vo.AppAgentTeamVo">
  90. select
  91. a.user_id as userId,
  92. c.username as nickName,
  93. c.coin as coin,
  94. c.diamond_coin as diamondCoin,
  95. a.pid as pid,
  96. (
  97. select IFNULL(sum(betting_amount),0) from app_game_betting as b where b.user_id = a.user_id
  98. <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
  99. and <![CDATA[ b.create_time >= concat(#{teamDto.beginTime},' 00:00:00') ]]>
  100. </if>
  101. <if test="teamDto.endTime != null and teamDto.endTime != ''">
  102. and <![CDATA[ b.create_time <= concat(#{teamDto.endTime},' 23:59:59') ]]>
  103. </if>
  104. ) as bettingAmount,
  105. (
  106. select IFNULL(sum(d.game_commission),0) from app_user_count as d where d.user_id = a.user_id
  107. <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
  108. and <![CDATA[ d.str_date >= #{teamDto.beginTime} ]]>
  109. </if>
  110. <if test="teamDto.endTime != null and teamDto.endTime != ''">
  111. and <![CDATA[ d.str_date <= #{teamDto.endTime} ]]>
  112. </if>
  113. ) as gameCommission,
  114. (
  115. select IFNULL(sum(f.live_commission),0) from app_user_count as f where f.user_id = a.user_id
  116. <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
  117. and <![CDATA[ f.str_date >= #{teamDto.beginTime} ]]>
  118. </if>
  119. <if test="teamDto.endTime != null and teamDto.endTime != ''">
  120. and <![CDATA[ f.str_date <= #{teamDto.endTime} ]]>
  121. </if>
  122. ) as liveCommission,
  123. (
  124. select IFNULL(sum(e.game_win_amount - e.game_lose_amount),0) from app_user_count as e where e.user_id = a.user_id
  125. <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
  126. and <![CDATA[ e.str_date >= #{teamDto.beginTime} ]]>
  127. </if>
  128. <if test="teamDto.endTime != null and teamDto.endTime != ''">
  129. and <![CDATA[ e.str_date <= #{teamDto.endTime} ]]>
  130. </if>
  131. ) as gameAmount,
  132. (
  133. select IFNULL(sum(g.recharge_amount),0) from app_user_count as g where g.user_id = a.user_id
  134. <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
  135. and <![CDATA[ g.str_date >= #{teamDto.beginTime} ]]>
  136. </if>
  137. <if test="teamDto.endTime != null and teamDto.endTime != ''">
  138. and <![CDATA[ g.str_date <= #{teamDto.endTime} ]]>
  139. </if>
  140. ) as rechargeAmount,
  141. (
  142. select IFNULL(sum(g.recharge_commission),0) from app_user_count as h where h.user_id = a.user_id
  143. <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
  144. and <![CDATA[ h.str_date >= #{teamDto.beginTime} ]]>
  145. </if>
  146. <if test="teamDto.endTime != null and teamDto.endTime != ''">
  147. and <![CDATA[ h.str_date <= #{teamDto.endTime} ]]>
  148. </if>
  149. ) as rechargeCommission,
  150. (
  151. select IFNULL(sum(g.recharge_give),0) from app_user_count as i where i.user_id = a.user_id
  152. <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
  153. and <![CDATA[ i.str_date >= #{teamDto.beginTime} ]]>
  154. </if>
  155. <if test="teamDto.endTime != null and teamDto.endTime != ''">
  156. and <![CDATA[ i.str_date <= #{teamDto.endTime} ]]>
  157. </if>
  158. ) as rechargeGive,
  159. a.live_rate as liveRate,
  160. a.dividend_guarantee_rate as dividendGuaranteeRate
  161. from app_user_agent as a left join mugozbg_live.app_user as c on a.user_id = c.userid where (a.pid = #{teamDto.pid} or a.user_id = #{teamDto.pid})
  162. <if test="teamDto.userId != null ">
  163. and a.user_id = #{teamDto.userId}
  164. </if>
  165. <if test="teamDto.nickName != null and teamDto.nickName != ''">
  166. and c.username = #{teamDto.nickName}
  167. </if>
  168. </select>
  169. <select id="teamListNew" resultType="com.game.business.vo.AppAgentTeamVo">
  170. select
  171. a.user_id as userId,
  172. c.username as nickName,
  173. c.coin as coin,
  174. c.diamond_coin as diamondCoin,
  175. a.pid as pid,
  176. IFNULL(sum(b.game_betting),0) as bettingAmount,
  177. IFNULL(sum(b.game_commission),0) as gameCommission,
  178. IFNULL(sum(b.live_commission),0) as liveCommission,
  179. IFNULL(sum(b.game_win_amount - b.game_lose_amount),0) as gameAmount,
  180. IFNULL(sum(b.recharge_amount),0) as rechargeAmount,
  181. IFNULL(sum(b.recharge_commission),0) as rechargeCommission,
  182. IFNULL(sum(b.recharge_give),0) as rechargeGive,
  183. a.live_rate as liveRate,
  184. a.dividend_guarantee_rate as dividendGuaranteeRate
  185. from app_user_agent as a inner join app_user_count as b on a.user_id = b.user_id left join mugozbg_live.app_user as c on a.user_id = c.userid where (a.pid = #{teamDto.pid} or a.user_id = #{teamDto.pid})
  186. <if test="teamDto.userId != null ">
  187. and a.user_id = #{teamDto.userId}
  188. </if>
  189. <if test="teamDto.nickName != null and teamDto.nickName != ''">
  190. and c.username = #{teamDto.nickName}
  191. </if>
  192. <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
  193. and <![CDATA[ b.str_date >= #{teamDto.beginTime} ]]>
  194. </if>
  195. <if test="teamDto.endTime != null and teamDto.endTime != ''">
  196. and <![CDATA[ b.str_date <= #{teamDto.endTime} ]]>
  197. </if>
  198. group by a.user_id order by a.user_id
  199. </select>
  200. <select id="selectAllAgentList" resultMap="AppUserAgentResult">
  201. WITH RECURSIVE useragent AS
  202. (
  203. SELECT *
  204. FROM app_user_agent
  205. WHERE pid = #{pid}
  206. UNION ALL
  207. SELECT o.*
  208. FROM app_user_agent o
  209. JOIN useragent s ON o.pid = s.user_id
  210. )
  211. SELECT * FROM useragent where 1=1
  212. <if test="userId != null">
  213. and user_id = #{userId}
  214. </if>
  215. </select>
  216. </mapper>