finance.sql.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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="financeSqlMapper">
  4. <sql id="base_column">
  5. id,
  6. account_id as accountId,
  7. act_time as actTime,
  8. num,
  9. t_advertiser.name as advertiserName,
  10. memo,
  11. agent_id as agentId,
  12. advertiser_id as advertiserId,
  13. charge,
  14. allocate,
  15. consume,
  16. balance
  17. </sql>
  18. <!-- 此时加入了帐号管理,只有该帐号下的广告主显示 -->
  19. <select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Finance">
  20. select a.id,b.name as advertiserName,(sum(a.allocate)-sum(a.consume)) as adBalance,sum(a.allocate) as sumAllocation,max(a.act_time) as upDated from t_adv_balance a,t_advertiser b
  21. where a.advertiser_id=b.id and a.agent_id=b.agent_id
  22. and a.agent_id=#{agentId}
  23. <!-- and a.account_id=#{accountId} -->
  24. <if test="advertiserId !=null ">
  25. and a.advertiser_id = #{advertiserId}
  26. </if>
  27. <if test="adverId !=null ">
  28. and a.advertiser_id = #{adverId}
  29. </if>
  30. <!-- <if test="advertiserName !=null ">
  31. and b.name = #{advertiserName}
  32. </if>
  33. -->
  34. group by a.advertiser_id
  35. order by b.name desc
  36. limit #{pager.offset}, #{pager.limit}
  37. </select>
  38. <select id="countByParams" parameterType="map" resultType="int">
  39. select count(1)
  40. from (( select distinct a.advertiser_id from t_adv_balance a,t_advertiser b
  41. where a.advertiser_id=b.id and a.agent_id=b.agent_id
  42. and a.agent_id=#{agentId}
  43. <!-- and a.account_id=#{accountId} -->
  44. <if test="advertiserId !=null ">
  45. and a.advertiser_id = #{advertiserId}
  46. </if>
  47. <if test="adverId !=null ">
  48. and a.advertiser_id = #{adverId}
  49. </if>
  50. group by a.advertiser_id ) c)
  51. </select>
  52. <!-- 最主要的是下面的balance,此时的balance对应为广告主的余额 -->
  53. <select id="findById" parameterType="long" resultType="com.cloudcross.ssp.advertiser.model.Finance">
  54. select
  55. id,
  56. account_id as accountId,
  57. act_time as actTime,
  58. num,
  59. memo,
  60. agent_id as agentId,
  61. advertiser_id as advertiserId,
  62. charge,
  63. allocate,
  64. consume,
  65. balance
  66. from t_adv_balance
  67. where id = #{id}
  68. </select>
  69. <insert id="editFinance" parameterType="com.cloudcross.ssp.advertiser.model.Finance">
  70. insert into t_adv_balance
  71. (account_id,agent_id,advertiser_id,charge,allocate,consume,memo,num,balance,act_time)
  72. values
  73. (#{accountId},#{agentId},#{advertiserId},0,#{allocate},0,#{memo},#{num},#{balance}+#{allocate},NOW())
  74. </insert>
  75. <insert id="addFinance" parameterType="com.cloudcross.ssp.advertiser.model.Finance">
  76. insert into t_adv_balance
  77. (account_id,agent_id,advertiser_id,allocate,balance,act_time)
  78. values
  79. (#{accountId},#{agentId},0,#{allocate},#{agentBalance}-#{allocate},NOW())
  80. </insert>
  81. <select id="findByBalance" parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Finance" >
  82. select a.balance as agentBalance from t_adv_balance a
  83. where a.agent_id = #{agentId} and a.advertiser_id = 0
  84. and a.account_id = #{accountId}
  85. order by a.act_time desc limit 1
  86. </select>
  87. </mapper>