<?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.playlet.system.mapper.PlayletUserMapper">

    <resultMap type="PlayletUser" id="PlayletUserResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="phone"    column="phone"    />
        <result property="nickName"    column="nick_name"    />
        <result property="password"    column="password"    />
        <result property="icon"    column="icon"    />
        <result property="agencyId"    column="agency_id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectPlayletUserVo">
        select id, code, phone, nick_name, password, icon, agency_id, parent_id, status, create_by, create_time, update_by, update_time, remark from playlet_user
    </sql>

    <select id="selectPlayletUserList" parameterType="PlayletUser" resultMap="PlayletUserResult">
        <include refid="selectPlayletUserVo"/>
        <where>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="icon != null  and icon != ''"> and icon = #{icon}</if>
            <if test="agencyId != null  and agencyId != ''"> and agency_id = #{agencyId}</if>
            <if test="parentId != null  and parentId != ''"> and parent_id = #{parentId}</if>
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
            <if test="updateBy != null  and updateBy != ''"> and update_by = #{updateBy}</if>
            <if test="remark != null  and remark != ''"> and remark = #{remark}</if>
        </where>
    </select>

    <select id="selectPlayletUserById" parameterType="Long" resultMap="PlayletUserResult">
        <include refid="selectPlayletUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertPlayletUser" parameterType="PlayletUser" useGeneratedKeys="true" keyProperty="ID">
        insert into playlet_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="phone != null">phone,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="password != null">password,</if>
            <if test="icon != null">icon,</if>
            <if test="agencyId != null">agency_id,</if>
            <if test="parentId != null">parent_id,</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>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="phone != null">#{phone},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="password != null">#{password},</if>
            <if test="icon != null">#{icon},</if>
            <if test="agencyId != null">#{agencyId},</if>
            <if test="parentId != null">#{parentId},</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>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updatePlayletUser" parameterType="PlayletUser">
        update playlet_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="phone != null">phone = #{phone},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="password != null">password = #{password},</if>
            <if test="icon != null">icon = #{icon},</if>
            <if test="agencyId != null">agency_id = #{agencyId},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="status != null">status = #{status},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePlayletUserById" parameterType="Long">
        delete from playlet_user where id = #{id}
    </delete>

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

</mapper>