<?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="com.game.business.mapper.AppUserCountDividendMapper">
    
    <resultMap type="com.game.business.domain.AppUserCountDividend" id="AppUserCountDividendResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="dateNo"    column="date_no"    />
        <result property="beginTime"    column="beginTime"    />
        <result property="endTime"    column="endTime"    />
        <result property="profitLoss"    column="profit_loss"    />
        <result property="rate"    column="rate"    />
        <result property="coin"    column="coin"    />
        <result property="diamondCoin"    column="diamond_coin"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAppUserCountDividendVo">
        select id, user_id, beginTime, endTime, profit_loss, rate, coin, diamond_coin, status, create_time, update_time from app_user_count_dividend
    </sql>

    <select id="selectAppUserCountDividendList" parameterType="com.game.business.domain.AppUserCountDividend" resultMap="AppUserCountDividendResult">
        <include refid="selectAppUserCountDividendVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="beginTime != null "> and beginTime = #{beginTime}</if>
            <if test="endTime != null "> and endTime = #{endTime}</if>
            <if test="profitLoss != null "> and profit_loss = #{profitLoss}</if>
            <if test="rate != null "> and rate = #{rate}</if>
            <if test="coin != null "> and coin = #{coin}</if>
            <if test="diamondCoin != null "> and diamond_coin = #{diamondCoin}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectAppUserCountDividendById" parameterType="Long" resultMap="AppUserCountDividendResult">
        <include refid="selectAppUserCountDividendVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAppUserCountDividend" parameterType="com.game.business.domain.AppUserCountDividend" useGeneratedKeys="true" keyProperty="id">
        insert into app_user_count_dividend
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="beginTime != null">beginTime,</if>
            <if test="endTime != null">endTime,</if>
            <if test="profitLoss != null">profit_loss,</if>
            <if test="rate != null">rate,</if>
            <if test="coin != null">coin,</if>
            <if test="diamondCoin != null">diamond_coin,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="beginTime != null">#{beginTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="profitLoss != null">#{profitLoss},</if>
            <if test="rate != null">#{rate},</if>
            <if test="coin != null">#{coin},</if>
            <if test="diamondCoin != null">#{diamondCoin},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAppUserCountDividend" parameterType="com.game.business.domain.AppUserCountDividend">
        update app_user_count_dividend
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="beginTime != null">beginTime = #{beginTime},</if>
            <if test="endTime != null">endTime = #{endTime},</if>
            <if test="profitLoss != null">profit_loss = #{profitLoss},</if>
            <if test="rate != null">rate = #{rate},</if>
            <if test="coin != null">coin = #{coin},</if>
            <if test="diamondCoin != null">diamond_coin = #{diamondCoin},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppUserCountDividendById" parameterType="Long">
        delete from app_user_count_dividend where id = #{id}
    </delete>

    <delete id="deleteAppUserCountDividendByIds" parameterType="String">
        delete from app_user_count_dividend where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectUserDividendList" resultMap="AppUserCountDividendResult">
        select a.* from app_user_count_dividend as a inner join app_user_agent as b on a.user_id = b.user_id
        where b.pid = #{pid}
        <if test="userId != null">
            and a.user_id = #{userId}
        </if>
        <if test="dateNum != null and dateNum != ''">
            and a.date_no = #{dateNum}
        </if>
    </select>
</mapper>