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

    <resultMap type="com.jsowell.pile.domain.PileStationWhitelist" id="PileStationWhitelistResult">
        <result property="id"    column="id"    />
        <result property="stationId"    column="station_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="mobileNumber"    column="mobile_number"    />
        <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, station_id, member_id, mobile_number, create_time, create_by, update_time, update_by, del_flag
    </sql>
    
    <sql id="selectPileStationWhitelistVo">
        select
        <include refid="Base_Column_List"/>
        from pile_station_whitelist
    </sql>

    <select id="selectPileStationWhitelistList" parameterType="com.jsowell.pile.domain.PileStationWhitelist" resultMap="PileStationWhitelistResult">
        <include refid="selectPileStationWhitelistVo"/>
        <where>
            <if test="stationId != null  and stationId != ''"> and station_id = #{stationId}</if>
            <if test="memberId != null  and memberId != ''"> and member_id = #{memberId}</if>
            <if test="mobileNumber != null  and mobileNumber != ''"> and mobile_number = #{mobileNumber}</if>
        </where>
    </select>

    <select id="selectPileStationWhitelistById" parameterType="Long" resultMap="PileStationWhitelistResult">
        <include refid="selectPileStationWhitelistVo"/>
        where id = #{id}
    </select>

    <insert id="insertPileStationWhitelist" parameterType="com.jsowell.pile.domain.PileStationWhitelist">
        insert into pile_station_whitelist
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="stationId != null">station_id,</if>
            <if test="memberId != null">member_id,</if>
            <if test="mobileNumber != null">mobile_number,</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="id != null">#{id},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="mobileNumber != null">#{mobileNumber},</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="updatePileStationWhitelist" parameterType="com.jsowell.pile.domain.PileStationWhitelist">
        update pile_station_whitelist
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="mobileNumber != null">mobile_number = #{mobileNumber},</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>

    <delete id="deletePileStationWhitelistById" parameterType="Long">
        delete from pile_station_whitelist where id = #{id}
    </delete>

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

    <select id="queryWhitelistByMemberId" resultMap="PileStationWhitelistResult">
        select
            <include refid="Base_Column_List"/>
        from pile_station_whitelist
        where del_flag = '0'
        and member_id = #{memberId,jdbcType=VARCHAR}
        and station_id = #{stationId,jdbcType=VARCHAR}
    </select>
</mapper>