123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
- <mapper namespace="financeSqlMapper">
-
- <sql id="base_column">
- id,
- account_id as accountId,
- act_time as actTime,
- num,
- t_advertiser.name as advertiserName,
- memo,
- agent_id as agentId,
- advertiser_id as advertiserId,
- charge,
- allocate,
- consume,
- balance
- </sql>
-
- <!-- 此时加入了帐号管理,只有该帐号下的广告主显示 -->
- <select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Finance">
- 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
- where a.advertiser_id=b.id and a.agent_id=b.agent_id
- and a.agent_id=#{agentId}
- <!-- and a.account_id=#{accountId} -->
- <if test="advertiserId !=null ">
- and a.advertiser_id = #{advertiserId}
- </if>
- <if test="adverId !=null ">
- and a.advertiser_id = #{adverId}
- </if>
- <!-- <if test="advertiserName !=null ">
- and b.name = #{advertiserName}
- </if>
- -->
- group by a.advertiser_id
- order by b.name desc
- limit #{pager.offset}, #{pager.limit}
- </select>
-
- <select id="countByParams" parameterType="map" resultType="int">
- select count(1)
- from (( select distinct a.advertiser_id from t_adv_balance a,t_advertiser b
- where a.advertiser_id=b.id and a.agent_id=b.agent_id
- and a.agent_id=#{agentId}
- <!-- and a.account_id=#{accountId} -->
- <if test="advertiserId !=null ">
- and a.advertiser_id = #{advertiserId}
- </if>
- <if test="adverId !=null ">
- and a.advertiser_id = #{adverId}
- </if>
- group by a.advertiser_id ) c)
-
- </select>
-
- <!-- 最主要的是下面的balance,此时的balance对应为广告主的余额 -->
- <select id="findById" parameterType="long" resultType="com.cloudcross.ssp.advertiser.model.Finance">
- select
- id,
- account_id as accountId,
- act_time as actTime,
- num,
- memo,
- agent_id as agentId,
- advertiser_id as advertiserId,
- charge,
- allocate,
- consume,
- balance
- from t_adv_balance
- where id = #{id}
- </select>
-
- <insert id="editFinance" parameterType="com.cloudcross.ssp.advertiser.model.Finance">
- insert into t_adv_balance
- (account_id,agent_id,advertiser_id,charge,allocate,consume,memo,num,balance,act_time)
- values
- (#{accountId},#{agentId},#{advertiserId},0,#{allocate},0,#{memo},#{num},#{balance}+#{allocate},NOW())
- </insert>
-
- <insert id="addFinance" parameterType="com.cloudcross.ssp.advertiser.model.Finance">
- insert into t_adv_balance
- (account_id,agent_id,advertiser_id,allocate,balance,act_time)
- values
- (#{accountId},#{agentId},0,#{allocate},#{agentBalance}-#{allocate},NOW())
- </insert>
-
- <select id="findByBalance" parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Finance" >
- select a.balance as agentBalance from t_adv_balance a
- where a.agent_id = #{agentId} and a.advertiser_id = 0
- and a.account_id = #{accountId}
- order by a.act_time desc limit 1
- </select>
- </mapper>
|