<?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.system.mapper.WechatTransferMapper">
    
    <resultMap type="WechatTransfer" id="WechatTransferResult">
        <result property="id"    column="id"    />
        <result property="uid"    column="uid"    />
        <result property="batchId"    column="batch_id"    />
        <result property="money"    column="money"    />
        <result property="status"    column="status"    />
        <result property="orderId"    column="order_id"    />
        <result property="openid"    column="openid"    />
        <result property="paid"    column="paid"    />
        <result property="payTime"    column="pay_time"    />
        <result property="time"    column="time"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectWechatTransferVo">
        select id, uid, batch_id, money, status, order_id, openid, paid, pay_time, time, created_at, updated_at from wechat_transfer
    </sql>

    <select id="selectWechatTransferList" parameterType="WechatTransfer" resultMap="WechatTransferResult">
        <include refid="selectWechatTransferVo"/>
        <where>  
            <if test="uid != null "> and uid like concat('%', #{uid}, '%')</if>
            <if test="batchId != null  and batchId != ''"> and batch_id like concat('%', #{batchId}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="priceMin != null and priceMax != null">
                and money BETWEEN #{priceMin} AND #{priceMax}
            </if>
            <if test="params.beginPayTime != null and params.beginPayTime != '' and params.endPayTime != null and params.endPayTime != ''"> and pay_time between #{params.beginPayTime} and #{params.endPayTime}</if>
            <if test="params.beginTime != null and params.beginTime != '' and params.endTime != null and params.endTime != ''"> and time between #{params.beginTime} and #{params.endTime}</if>
        </where>
    </select>
    
    <select id="selectWechatTransferById" parameterType="Long" resultMap="WechatTransferResult">
        <include refid="selectWechatTransferVo"/>
        where id = #{id}
    </select>

    <insert id="insertWechatTransfer" parameterType="WechatTransfer" useGeneratedKeys="true" keyProperty="id">
        insert into wechat_transfer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">uid,</if>
            <if test="batchId != null">batch_id,</if>
            <if test="money != null">money,</if>
            <if test="status != null">status,</if>
            <if test="orderId != null and orderId != ''">order_id,</if>
            <if test="openid != null and openid != ''">openid,</if>
            <if test="paid != null">paid,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="time != null">time,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid},</if>
            <if test="batchId != null">#{batchId},</if>
            <if test="money != null">#{money},</if>
            <if test="status != null">#{status},</if>
            <if test="orderId != null and orderId != ''">#{orderId},</if>
            <if test="openid != null and openid != ''">#{openid},</if>
            <if test="paid != null">#{paid},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="time != null">#{time},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateWechatTransfer" parameterType="WechatTransfer">
        update wechat_transfer
        <trim prefix="SET" suffixOverrides=",">
            <if test="uid != null">uid = #{uid},</if>
            <if test="batchId != null">batch_id = #{batchId},</if>
            <if test="money != null">money = #{money},</if>
            <if test="status != null">status = #{status},</if>
            <if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
            <if test="openid != null and openid != ''">openid = #{openid},</if>
            <if test="paid != null">paid = #{paid},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="time != null">time = #{time},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWechatTransferById" parameterType="Long">
        delete from wechat_transfer where id = #{id}
    </delete>

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