<?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.PileMemberRelationMapper">

    <resultMap type="com.jsowell.pile.domain.PileMemberRelation" id="PileMemberRelationResult">
        <result property="id"    column="id"    />
        <result property="pileSn"    column="pile_sn"    />
        <result property="memberId"    column="member_id"    />
        <result property="type"    column="type"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectPileMemberRelationVo">
        select id, pile_sn, member_id, type, create_time from pile_member_relation
    </sql>

    <sql id="Base_Column_List">
        id, pile_sn, member_id, type, create_time
    </sql>

    <select id="selectPileMemberRelationList" parameterType="com.jsowell.pile.domain.PileMemberRelation" resultMap="PileMemberRelationResult">
        <include refid="selectPileMemberRelationVo"/>
        <where>
            <if test="pileSn != null  and pileSn != ''"> and pile_sn = #{pileSn}</if>
            <if test="memberId != null  and memberId != ''"> and member_id = #{memberId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>

    <select id="selectPileMemberRelationById" parameterType="Integer" resultMap="PileMemberRelationResult">
        <include refid="selectPileMemberRelationVo"/>
        where id = #{id}
    </select>

    <insert id="insertPileMemberRelation" parameterType="com.jsowell.pile.domain.PileMemberRelation" useGeneratedKeys="true" keyProperty="id">
        insert into pile_member_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pileSn != null">pile_sn,</if>
            <if test="memberId != null">member_id,</if>
            <if test="type != null">type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pileSn != null">#{pileSn},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="type != null">#{type},</if>
        </trim>
    </insert>

    <update id="updatePileMemberRelation" parameterType="com.jsowell.pile.domain.PileMemberRelation">
        update pile_member_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="pileSn != null">pile_sn = #{pileSn},</if>
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePileMemberRelationById" parameterType="Integer">
        delete from pile_member_relation where id = #{id}
    </delete>

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

    <select id="selectPileMemberRelation" resultMap="PileMemberRelationResult">
        select
        <include refid="Base_Column_List"/>
        from pile_member_relation
        <where>
            <if test="pileSn != null and pileSn != ''">
                and pile_sn = #{pileSn,jdbcType=VARCHAR}
            </if>
            <if test="memberId != null and memberId != ''">
                and member_id = #{memberId,jdbcType=VARCHAR}
            </if>
            <if test="type != null and type != ''">
                and type = #{type,jdbcType=VARCHAR}
            </if>
        </where>
    </select>

    <delete id="deleteRelationByIds">
        delete from pile_member_relation where id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>