adv-balance.sql.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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="advBalanceSqlMapper">
  4. <sql id="base_column">
  5. t_adv_balance.id as id,
  6. account_id as accountId,
  7. agent_id as agentId,
  8. advertiser_id as advertiserId,
  9. act_time as actTime,
  10. num,
  11. <!-- type, -->
  12. charge,
  13. allocate,
  14. consume,
  15. t_advertiser.name as advertiserName,
  16. t_agent.name as agentName,
  17. balance,
  18. memo
  19. </sql>
  20. <sql id="base_column2">
  21. t_adv_balance.id as id,
  22. t_adv_balance.account_id as accountId,
  23. t_adv_balance.agent_id as agentId,
  24. t_adv_balance.advertiser_id as advertiserId,
  25. t_adv_balance.act_time as actTime,
  26. t_adv_balance.num as num,
  27. t_adv_balance.charge as charge,
  28. t_adv_balance.allocate as allocate,
  29. t_adv_balance.memo as memo,
  30. t_adv_balance.consume as consume,
  31. t_adv_balance.balance as balance,
  32. t_adv_balance.status as status
  33. </sql>
  34. <select id="findAdvBalance" parameterType="int" resultType="com.cloudcross.ssp.model.AdvBalance">
  35. select * from t_adv_balance where id=#{advBalanceId}
  36. </select>
  37. <select id="selectByParams" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
  38. select
  39. a.act_time as actTime,
  40. <if test="type != 'charge'">
  41. b.name as advertiserName,
  42. </if>
  43. <if test="type == 'charge'">
  44. d.name as agentName,
  45. </if>
  46. a.num,a.charge,a.allocate,a.consume,a.balance
  47. from t_adv_balance a,
  48. <if test="type != 'charge'">
  49. t_advertiser b
  50. </if>
  51. <if test="type == 'charge'">
  52. t_adv_agent d
  53. </if>
  54. where
  55. <!-- a.account_id=#{accountId} -->
  56. a.agent_id=#{agentId}
  57. <if test="adverId !=null ">
  58. and a.advertiser_id = #{adverId}
  59. </if>
  60. <if test="type == 'charge'">
  61. and a.agent_id=d.id
  62. </if>
  63. <if test="startDate!=null and endDate!=null">
  64. and a.act_time &gt;= #{startDate} and #{endDate} &gt;=a.act_time
  65. </if>
  66. <if test="advertiserId !=null ">
  67. and a.advertiser_id = #{advertiserId}
  68. </if>
  69. <if test="type != 'charge'">
  70. and b.id= a.advertiser_id
  71. </if>
  72. <if test="type!=null and type == 'charge'">
  73. and a.charge > 0
  74. and a.advertiser_id=0
  75. </if>
  76. <if test="type!=null and type == 'consume'">
  77. and a.consume > 0
  78. </if>
  79. <if test="type!=null and type == 'allocate'">
  80. and a.allocate > 0
  81. </if>
  82. order by a.act_time desc
  83. limit #{pager.offset}, #{pager.limit}
  84. </select>
  85. <select id="selectByParams2" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
  86. select
  87. a.act_time as actTime,b.name as advertiserName,num,charge,allocate,consume,a.balance,d.name as agentName
  88. from t_adv_balance a,t_advertiser b,t_account c,t_adv_agent d
  89. where b.id= a.advertiser_id
  90. and a.account_id=c.id
  91. and a.agent_id=b.agent_id=c.agent_id=d.id
  92. and a.allocate != 0
  93. <!-- a.account_id=#{accountId} -->
  94. and a.agent_id=#{agentId}
  95. <if test="adverId !=null ">
  96. and a.advertiser_id = #{adverId}
  97. </if>
  98. <if test="startDate!=null and endDate!=null">
  99. and a.act_time &gt;= #{startDate} and #{endDate} &gt;=a.act_time
  100. </if>
  101. <if test="advertiserId !=null ">
  102. and a.advertiser_id = #{advertiserId}
  103. </if>
  104. order by a.id desc
  105. limit #{pager.offset}, #{pager.limit}
  106. </select>
  107. <select id="countByParams" parameterType="map" resultType="int">
  108. select count(a.id)
  109. from t_adv_balance a,
  110. <if test="type != 'charge'">
  111. t_advertiser b
  112. </if>
  113. <if test="type == 'charge'">
  114. t_adv_agent d
  115. </if>
  116. where
  117. <!-- a.account_id=#{accountId} -->
  118. a.agent_id=#{agentId}
  119. <if test="adverId !=null ">
  120. and a.advertiser_id = #{adverId}
  121. </if>
  122. <if test="type == 'charge'">
  123. and a.agent_id=d.id
  124. </if>
  125. <if test="startDate!=null and endDate!=null">
  126. and a.act_time &gt;= #{startDate} and #{endDate} &gt;=a.act_time
  127. </if>
  128. <if test="advertiserId !=null ">
  129. and a.advertiser_id = #{advertiserId}
  130. </if>
  131. <if test="type != 'charge'">
  132. and b.id= a.advertiser_id
  133. </if>
  134. <if test="type!=null and type == 'charge'">
  135. and a.charge > 0
  136. and a.advertiser_id=0
  137. </if>
  138. <if test="type!=null and type == 'consume'">
  139. and a.consume > 0
  140. </if>
  141. <if test="type!=null and type == 'allocate'">
  142. and a.allocate > 0
  143. </if>
  144. </select>
  145. <select id="countByParams2" parameterType="map" resultType="int">
  146. select count(a.id)
  147. from t_adv_balance a,t_advertiser b,t_account c,t_adv_agent d
  148. where b.id= a.advertiser_id
  149. and a.account_id=c.id
  150. and a.agent_id=b.agent_id=c.agent_id=d.id
  151. and a.allocate != 0
  152. <!-- a.account_id=#{accountId} -->
  153. and a.agent_id=#{agentId}
  154. <if test="adverId !=null ">
  155. and a.advertiser_id = #{adverId}
  156. </if>
  157. <if test="startDate!=null and endDate!=null">
  158. and a.act_time &gt;= #{startDate} and #{endDate} &gt;=a.act_time
  159. </if>
  160. <!-- <if test="advertiserName!=null">
  161. and b.name = #{advertiserName}
  162. </if> -->
  163. <if test="advertiserId !=null ">
  164. and a.advertiser_id = #{advertiserId}
  165. </if>
  166. </select>
  167. <select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.AdvBalance">
  168. select
  169. <include refid="base_column2" />
  170. from t_adv_balance
  171. <where>
  172. id = #{id}
  173. </where>
  174. </select>
  175. <select id="countByParamsBack" parameterType="map" resultType="int">
  176. select count(id) from t_adv_balance
  177. <where>
  178. advertiser_id = 0 and agent_id != 0 and status != -1
  179. <if test="actTime != null">
  180. and act_time like #{actTime}
  181. </if>
  182. </where>
  183. </select>
  184. <select id="findByParamsBack" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
  185. select <include refid="base_column2"/>, name as agentName from t_adv_balance left join
  186. t_adv_agent on t_adv_balance.agent_id = t_adv_agent.id
  187. <where>
  188. t_adv_balance.advertiser_id = 0 and t_adv_balance.agent_id != 0 and t_adv_balance.status != -1
  189. <if test="actTime != null">
  190. and act_time like #{actTime}
  191. </if>
  192. </where>
  193. order by act_time desc
  194. limit #{pager.offset}, #{pager.limit}
  195. </select>
  196. <select id="findByParams1Back" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
  197. select <include refid="base_column2"/>, name as agentName from t_adv_balance left join
  198. t_adv_agent on t_adv_balance.agent_id = t_adv_agent.id
  199. <where>
  200. t_adv_balance.advertiser_id = 0 and t_adv_balance.agent_id != 0 and t_adv_balance.status != -1
  201. <if test="actTime != null">
  202. and act_time like #{actTime}
  203. </if>
  204. </where>
  205. order by act_time desc
  206. </select>
  207. <select id="findBalanceByAgentIdBack" parameterType="long" resultType="double">
  208. select balance from t_adv_balance where agent_id = #{agentId} and status != -1 order by id desc limit 1
  209. </select>
  210. <insert id="addBack" parameterType="com.cloudcross.ssp.model.AdvBalance">
  211. insert into t_adv_balance(account_id,agent_id,act_time,num,charge,balance)
  212. values(#{accountId},#{agentId},#{actTime},#{num},#{charge},#{balance})
  213. </insert>
  214. <select id="findByIdBack" parameterType="long" resultType="com.cloudcross.ssp.model.AdvBalance">
  215. select <include refid="base_column2"/> from t_adv_balance
  216. where id = #{id} and status != -1
  217. </select>
  218. <update id="updateBalanceByAgentIdBack" parameterType="map">
  219. update t_adv_balance set balance = #{balance}
  220. where id in (select * from (select id from t_adv_balance where agent_id = #{agentId} and status != -1 order by id desc limit 1) as a)
  221. </update>
  222. <delete id="deleteAdvBalanceByIdBack" parameterType="long">
  223. delete from t_adv_balance where id = #{id}
  224. </delete>
  225. </mapper>