123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <?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="advBalanceSqlMapper">
-
- <sql id="base_column">
- t_adv_balance.id as id,
- account_id as accountId,
- agent_id as agentId,
- advertiser_id as advertiserId,
- act_time as actTime,
- num,
- <!-- type, -->
- charge,
- allocate,
- consume,
- t_advertiser.name as advertiserName,
- t_agent.name as agentName,
- balance,
- memo
- </sql>
- <sql id="base_column2">
- t_adv_balance.id as id,
- t_adv_balance.account_id as accountId,
- t_adv_balance.agent_id as agentId,
- t_adv_balance.advertiser_id as advertiserId,
- t_adv_balance.act_time as actTime,
- t_adv_balance.num as num,
- t_adv_balance.charge as charge,
- t_adv_balance.allocate as allocate,
- t_adv_balance.memo as memo,
- t_adv_balance.consume as consume,
- t_adv_balance.balance as balance,
- t_adv_balance.status as status
- </sql>
- <select id="findAdvBalance" parameterType="int" resultType="com.cloudcross.ssp.model.AdvBalance">
- select * from t_adv_balance where id=#{advBalanceId}
- </select>
-
- <select id="selectByParams" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
- select
- a.act_time as actTime,
- <if test="type != 'charge'">
- b.name as advertiserName,
- </if>
- <if test="type == 'charge'">
- d.name as agentName,
- </if>
- a.num,a.charge,a.allocate,a.consume,a.balance
- from t_adv_balance a,
- <if test="type != 'charge'">
- t_advertiser b
- </if>
- <if test="type == 'charge'">
- t_adv_agent d
- </if>
- where
- <!-- a.account_id=#{accountId} -->
- a.agent_id=#{agentId}
- <if test="adverId !=null ">
- and a.advertiser_id = #{adverId}
- </if>
- <if test="type == 'charge'">
- and a.agent_id=d.id
- </if>
- <if test="startDate!=null and endDate!=null">
- and a.act_time >= #{startDate} and #{endDate} >=a.act_time
- </if>
- <if test="advertiserId !=null ">
- and a.advertiser_id = #{advertiserId}
- </if>
- <if test="type != 'charge'">
- and b.id= a.advertiser_id
- </if>
- <if test="type!=null and type == 'charge'">
- and a.charge > 0
- and a.advertiser_id=0
- </if>
- <if test="type!=null and type == 'consume'">
- and a.consume > 0
- </if>
- <if test="type!=null and type == 'allocate'">
- and a.allocate > 0
- </if>
- order by a.act_time desc
- limit #{pager.offset}, #{pager.limit}
- </select>
-
- <select id="selectByParams2" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
- select
- a.act_time as actTime,b.name as advertiserName,num,charge,allocate,consume,a.balance,d.name as agentName
- from t_adv_balance a,t_advertiser b,t_account c,t_adv_agent d
- where b.id= a.advertiser_id
- and a.account_id=c.id
- and a.agent_id=b.agent_id=c.agent_id=d.id
- and a.allocate != 0
- <!-- a.account_id=#{accountId} -->
- and a.agent_id=#{agentId}
- <if test="adverId !=null ">
- and a.advertiser_id = #{adverId}
- </if>
- <if test="startDate!=null and endDate!=null">
- and a.act_time >= #{startDate} and #{endDate} >=a.act_time
- </if>
- <if test="advertiserId !=null ">
- and a.advertiser_id = #{advertiserId}
- </if>
- order by a.id desc
- limit #{pager.offset}, #{pager.limit}
- </select>
-
-
- <select id="countByParams" parameterType="map" resultType="int">
- select count(a.id)
- from t_adv_balance a,
- <if test="type != 'charge'">
- t_advertiser b
- </if>
- <if test="type == 'charge'">
- t_adv_agent d
- </if>
- where
- <!-- a.account_id=#{accountId} -->
- a.agent_id=#{agentId}
- <if test="adverId !=null ">
- and a.advertiser_id = #{adverId}
- </if>
- <if test="type == 'charge'">
- and a.agent_id=d.id
- </if>
- <if test="startDate!=null and endDate!=null">
- and a.act_time >= #{startDate} and #{endDate} >=a.act_time
- </if>
- <if test="advertiserId !=null ">
- and a.advertiser_id = #{advertiserId}
- </if>
- <if test="type != 'charge'">
- and b.id= a.advertiser_id
- </if>
- <if test="type!=null and type == 'charge'">
- and a.charge > 0
- and a.advertiser_id=0
- </if>
- <if test="type!=null and type == 'consume'">
- and a.consume > 0
- </if>
- <if test="type!=null and type == 'allocate'">
- and a.allocate > 0
- </if>
- </select>
-
- <select id="countByParams2" parameterType="map" resultType="int">
- select count(a.id)
- from t_adv_balance a,t_advertiser b,t_account c,t_adv_agent d
- where b.id= a.advertiser_id
- and a.account_id=c.id
- and a.agent_id=b.agent_id=c.agent_id=d.id
- and a.allocate != 0
- <!-- a.account_id=#{accountId} -->
- and a.agent_id=#{agentId}
- <if test="adverId !=null ">
- and a.advertiser_id = #{adverId}
- </if>
- <if test="startDate!=null and endDate!=null">
- and a.act_time >= #{startDate} and #{endDate} >=a.act_time
- </if>
-
- <!-- <if test="advertiserName!=null">
- and b.name = #{advertiserName}
- </if> -->
- <if test="advertiserId !=null ">
- and a.advertiser_id = #{advertiserId}
- </if>
- </select>
-
- <select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.AdvBalance">
- select
- <include refid="base_column2" />
- from t_adv_balance
- <where>
- id = #{id}
- </where>
- </select>
- <select id="countByParamsBack" parameterType="map" resultType="int">
- select count(id) from t_adv_balance
- <where>
- advertiser_id = 0 and agent_id != 0 and status != -1
- <if test="actTime != null">
- and act_time like #{actTime}
- </if>
- </where>
- </select>
-
- <select id="findByParamsBack" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
- select <include refid="base_column2"/>, name as agentName from t_adv_balance left join
- t_adv_agent on t_adv_balance.agent_id = t_adv_agent.id
- <where>
- t_adv_balance.advertiser_id = 0 and t_adv_balance.agent_id != 0 and t_adv_balance.status != -1
- <if test="actTime != null">
- and act_time like #{actTime}
- </if>
- </where>
- order by act_time desc
- limit #{pager.offset}, #{pager.limit}
- </select>
-
- <select id="findByParams1Back" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
- select <include refid="base_column2"/>, name as agentName from t_adv_balance left join
- t_adv_agent on t_adv_balance.agent_id = t_adv_agent.id
- <where>
- t_adv_balance.advertiser_id = 0 and t_adv_balance.agent_id != 0 and t_adv_balance.status != -1
- <if test="actTime != null">
- and act_time like #{actTime}
- </if>
- </where>
- order by act_time desc
- </select>
-
- <select id="findBalanceByAgentIdBack" parameterType="long" resultType="double">
- select balance from t_adv_balance where agent_id = #{agentId} and status != -1 order by id desc limit 1
- </select>
-
-
- <insert id="addBack" parameterType="com.cloudcross.ssp.model.AdvBalance">
- insert into t_adv_balance(account_id,agent_id,act_time,num,charge,balance)
- values(#{accountId},#{agentId},#{actTime},#{num},#{charge},#{balance})
- </insert>
-
- <select id="findByIdBack" parameterType="long" resultType="com.cloudcross.ssp.model.AdvBalance">
- select <include refid="base_column2"/> from t_adv_balance
- where id = #{id} and status != -1
- </select>
-
- <update id="updateBalanceByAgentIdBack" parameterType="map">
- update t_adv_balance set balance = #{balance}
- 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)
- </update>
-
- <delete id="deleteAdvBalanceByIdBack" parameterType="long">
- delete from t_adv_balance where id = #{id}
- </delete>
- </mapper>
|