<?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.ruoyi.ss.balancePeriod.mapper.SmBalancePeriodMapper">

    <resultMap type="SmBalancePeriod" id="SmBalancePeriodResult">
        <result property="id"    column="id"    />
        <result property="userBalance"    column="user_balance"    />
        <result property="platformBalance"    column="platform_balance"    />
        <result property="recharge"    column="recharge"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectSmBalancePeriodVo">
        select id, user_balance, platform_balance, recharge, create_time from sm_balance_period
    </sql>

    <select id="selectSmBalancePeriodList" parameterType="SmBalancePeriodQuery" resultMap="SmBalancePeriodResult">
        <include refid="selectSmBalancePeriodVo"/>
        <where>
            <if test="userBalance != null "> and user_balance = #{userBalance}</if>
            <if test="platformBalance != null "> and platform_balance = #{platformBalance}</if>
            <if test="recharge != null "> and recharge = #{recharge}</if>
            <if test="createDate != null "> and date(create_time) = #{createDate}</if>
            <if test="createHour != null "> and hour(create_time) = #{createHour}</if>
        </where>
    </select>

    <select id="selectSmBalancePeriodById" parameterType="Long" resultMap="SmBalancePeriodResult">
        <include refid="selectSmBalancePeriodVo"/>
        where id = #{id}
    </select>

    <insert id="insertSmBalancePeriod" parameterType="SmBalancePeriod" useGeneratedKeys="true" keyProperty="id">
        insert into sm_balance_period
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userBalance != null">user_balance,</if>
            <if test="platformBalance != null">platform_balance,</if>
            <if test="recharge != null">recharge,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userBalance != null">#{userBalance},</if>
            <if test="platformBalance != null">#{platformBalance},</if>
            <if test="recharge != null">#{recharge},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateSmBalancePeriod" parameterType="SmBalancePeriod">
        update sm_balance_period
        <trim prefix="SET" suffixOverrides=",">
            <if test="userBalance != null">user_balance = #{userBalance},</if>
            <if test="platformBalance != null">platform_balance = #{platformBalance},</if>
            <if test="recharge != null">recharge = #{recharge},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSmBalancePeriodById" parameterType="Long">
        delete from sm_balance_period where id = #{id}
    </delete>

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