<?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.jsowell.pile.mapper.AdapayMemberAccountMapper">

    <resultMap type="com.jsowell.pile.domain.AdapayMemberAccount" id="AdapayMemberAccountResult">
        <result property="id"    column="id"    />
        <result property="status"    column="status"    />
        <result property="merchantId"    column="merchant_id"    />
        <result property="adapayMemberId"    column="adapay_member_id"    />
        <result property="settleAccountId"    column="settle_account_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="Base_Column_List">
        id, status, merchant_id, adapay_member_id, settle_account_id, create_time, create_by, update_time, update_by, del_flag
    </sql>

    <sql id="selectAdapayMemberAccountVo">
        select
            <include refid="Base_Column_List"/>
        from adapay_member_account
    </sql>

    <select id="selectAdapayMemberAccountList" parameterType="com.jsowell.pile.domain.AdapayMemberAccount" resultMap="AdapayMemberAccountResult">
        <include refid="selectAdapayMemberAccountVo"/>
        <where>
            <if test="merchantId != null  and merchantId != ''"> and merchant_id = #{merchantId}</if>
            <if test="adapayMemberId != null  and adapayMemberId != ''"> and adapay_member_id = #{adapayMemberId}</if>
            <if test="settleAccountId != null  and settleAccountId != ''"> and settle_account_id = #{settleAccountId}</if>
        </where>
    </select>

    <select id="selectAdapayMemberAccountById" parameterType="Long" resultMap="AdapayMemberAccountResult">
        <include refid="selectAdapayMemberAccountVo"/>
        where id = #{id}
    </select>

    <insert id="insertAdapayMemberAccount" parameterType="com.jsowell.pile.domain.AdapayMemberAccount" useGeneratedKeys="true" keyProperty="id">
        insert into adapay_member_account
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="status != null">status,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="adapayMemberId != null">adapay_member_id,</if>
            <if test="settleAccountId != null">settle_account_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="status != null">#{status},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="adapayMemberId != null">#{adapayMemberId},</if>
            <if test="settleAccountId != null">#{settleAccountId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateAdapayMemberAccount" parameterType="com.jsowell.pile.domain.AdapayMemberAccount">
        update adapay_member_account
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null">status = #{status},</if>
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="adapayMemberId != null">adapay_member_id = #{adapayMemberId},</if>
            <if test="settleAccountId != null">settle_account_id = #{settleAccountId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateAdapayMemberAccountByMemberId" parameterType="com.jsowell.pile.domain.AdapayMemberAccount">
        update adapay_member_account
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null">status = #{status},</if>
            <if test="merchantId != null">merchant_id = #{merchantId},</if>
            <if test="adapayMemberId != null">adapay_member_id = #{adapayMemberId},</if>
            <if test="settleAccountId != null">settle_account_id = #{settleAccountId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where adapay_member_id = #{adapayMemberId,jdbcType=VARCHAR}
    </update>

    <delete id="deleteAdapayMemberAccountById" parameterType="Long">
        delete from adapay_member_account where id = #{id}
    </delete>

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

    <update id="deleteAdapayMemberAccountByIds" parameterType="com.jsowell.pile.domain.AdapayMemberAccount">
        update adapay_member_account
        set del_flag = '1'
        where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="selectByMerchantId" resultMap="AdapayMemberAccountResult">
        select
        <include refid="Base_Column_List"/>
        from adapay_member_account
        where del_flag = '0'
        and merchant_id = #{merchantId,jdbcType=VARCHAR}
    </select>

    <delete id="deleteByMemberId">
        delete from adapay_member_account where adapay_member_id = #{memberId,jdbcType=VARCHAR}
    </delete>

    <select id="selectByMemberId" resultMap="AdapayMemberAccountResult">
        select
        <include refid="Base_Column_List"/>
        from adapay_member_account
        where del_flag = '0'
        and adapay_member_id = #{memberId,jdbcType=VARCHAR}
    </select>
</mapper>