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

    <resultMap type="PlayletPublicUser" id="PlayletPublicUserResult">
        <result property="id"    column="id"    />
        <result property="publicId"    column="public_id"    />
        <result property="name"    column="name"    />
        <result property="unionId"    column="union_id"    />
        <result property="imgUrl"    column="img_url"    />
        <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="selectPlayletPublicUserVo">
        select id, public_id, name, union_id, img_url, create_by, create_time, update_by, update_time, remark from playlet_public_user
    </sql>

    <select id="selectPlayletPublicUserList" parameterType="PlayletPublicUser" resultMap="PlayletPublicUserResult">
        <include refid="selectPlayletPublicUserVo"/>
        <where>
            <if test="publicId != null "> and public_id = #{publicId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="unionId != null  and unionId != ''"> and union_id = #{unionId}</if>
            <if test="imgUrl != null  and imgUrl != ''"> and img_url = #{imgUrl}</if>
        </where>
    </select>

    <select id="selectPlayletPublicUserById" parameterType="Long" resultMap="PlayletPublicUserResult">
        <include refid="selectPlayletPublicUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertPlayletPublicUser" parameterType="PlayletPublicUser" useGeneratedKeys="true" keyProperty="id">
        insert into playlet_public_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="publicId != null">public_id,</if>
            <if test="name != null">name,</if>
            <if test="unionId != null">union_id,</if>
            <if test="imgUrl != null">img_url,</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="publicId != null">#{publicId},</if>
            <if test="name != null">#{name},</if>
            <if test="unionId != null">#{unionId},</if>
            <if test="imgUrl != null">#{imgUrl},</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="updatePlayletPublicUser" parameterType="PlayletPublicUser">
        update playlet_public_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="publicId != null">public_id = #{publicId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="unionId != null">union_id = #{unionId},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</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="deletePlayletPublicUserById" parameterType="Long">
        delete from playlet_public_user where id = #{id}
    </delete>

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

</mapper>