<?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.cyl.manager.ums.mapper.MemberDoorLockMapper">
    
    <resultMap type="com.cyl.manager.ums.domain.MemberDoorLock" id="MemberDoorLockResult">
        <result property="id" column="id"/>
        <result property="memberId" column="member_id"/>
        <result property="openId" column="open_id"/>
        <result property="houseType" column="house_type"/>
        <result property="lockType" column="lock_type"/>
        <result property="keyHandover" column="key_handover"/>
        <result property="keyStorageLocation" column="key_storage_location"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMemberDoorLockVo">
        select id, member_id, open_id,house_type, lock_type, key_handover, key_storage_location, create_by, create_time, update_by, update_time  from ums_member_door_lock
    </sql>

    <select id="selectList" parameterType="com.cyl.manager.ums.domain.MemberDoorLock" resultMap="MemberDoorLockResult">
        <include refid="selectMemberDoorLockVo"/>
        <where>  
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="openId != null "> and open_id = #{openId}</if>
            <if test="houseType != null  and houseType != ''"> and house_type = #{houseType}</if>
            <if test="lockType != null  and lockType != ''"> and lock_type = #{lockType}</if>
            <if test="keyHandover != null  and keyHandover != ''"> and key_handover = #{keyHandover}</if>
            <if test="keyStorageLocation != null  and keyStorageLocation != ''"> and key_storage_location = #{keyStorageLocation}</if>
        </where>
    </select>
    
    <select id="selectById" parameterType="Long" resultMap="MemberDoorLockResult">
        <include refid="selectMemberDoorLockVo"/>
        where id = #{id}
    </select>
        
    <insert id="insert" parameterType="com.cyl.manager.ums.domain.MemberDoorLock">
        insert into ums_member_door_lock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="memberId != null">member_id,</if>
            <if test="openId != null">open_id,</if>
            <if test="houseType != null">house_type,</if>
            <if test="lockType != null">lock_type,</if>
            <if test="keyHandover != null">key_handover,</if>
            <if test="keyStorageLocation != null">key_storage_location,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>

         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="memberId != null">#{memberId},</if>
            <if test="openId != null">#{openId},</if>
            <if test="houseType != null">#{houseType},</if>
            <if test="lockType != null">#{lockType},</if>
            <if test="keyHandover != null">#{keyHandover},</if>
            <if test="keyStorageLocation != null">#{keyStorageLocation},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>

         </trim>
    </insert>

    <update id="update" parameterType="com.cyl.manager.ums.domain.MemberDoorLock">
        update ums_member_door_lock
        <trim prefix="SET" suffixOverrides=",">
            <if test="houseType != null">house_type = #{houseType},</if>
            <if test="lockType != null">lock_type = #{lockType},</if>
            <if test="keyHandover != null">key_handover = #{keyHandover},</if>
            <if test="keyStorageLocation != null">key_storage_location = #{keyStorageLocation},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where member_id = #{memberId}
    </update>

    <delete id="deleteById" parameterType="Long">
        delete from ums_member_door_lock where id = #{id}
    </delete>

    <delete id="deleteByIds" parameterType="String">
        delete from ums_member_door_lock where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="insertOrUpdate" parameterType="com.cyl.manager.ums.domain.MemberDoorLock" useGeneratedKeys="true" keyProperty="id">
        insert into ums_member_door_lock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
             member_id, open_id,house_type, lock_type, key_handover, key_storage_location, create_by, create_time, update_by, update_time
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="id != null">
            #{id, jdbcType=BIGINT},
        </if>
            #{memberId, jdbcType=BIGINT},#{openId, jdbcType=VARCHAR},#{houseType, jdbcType=VARCHAR},#{lockType, jdbcType=VARCHAR},#{keyHandover, jdbcType=VARCHAR},#{keyStorageLocation, jdbcType=VARCHAR},#{createBy, jdbcType=BIGINT},#{createTime, jdbcType=DATE},#{updateBy, jdbcType=BIGINT},#{updateTime, jdbcType=DATE}
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=BIGINT},
            </if>
            member_id = #{memberId, jdbcType=BIGINT},
            open_id = #{openId, jdbcType=VARCHAR},
            house_type = #{houseType, jdbcType=VARCHAR},
            lock_type = #{lockType, jdbcType=VARCHAR},
            key_handover = #{keyHandover, jdbcType=VARCHAR},
            key_storage_location = #{keyStorageLocation, jdbcType=VARCHAR},
            create_by = #{createBy, jdbcType=BIGINT},
            create_time = #{createTime, jdbcType=DATE},
            update_by = #{updateBy, jdbcType=BIGINT},
            update_time = #{updateTime, jdbcType=DATE}
        </trim>
    </insert>

    <select id="selectByMemberId" resultMap="MemberDoorLockResult">
        <include refid="selectMemberDoorLockVo"/>
        where member_id = #{memberId}
        limit 1
    </select>

    <delete id="deleteMemberDoorLockByMemberId" parameterType="Long">
        delete from ums_member_door_lock where  member_id = #{memberId}
    </delete>
</mapper>
