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

    <resultMap type="PublicDetailShare" id="PublicDetailShareResult">
        <result property="id"    column="id"    />
        <result property="detailId"    column="detail_id"    />
        <result property="authorId"    column="author_id"    />
        <result property="authorName"    column="author_name"    />
        <result property="readerOneId"    column="reader_one_id"    />
        <result property="readerOneName"    column="reader_one_name"    />
        <result property="readerTwoId"    column="reader_two_id"    />
        <result property="readerTwoName"    column="reader_two_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectPublicDetailShareVo">
        select id, detail_id, author_id, author_name, reader_one_id, reader_one_name, reader_two_id, reader_two_name, create_time, create_by, update_by, update_time, remark from public_detail_share
    </sql>

    <select id="selectPublicDetailShareList" parameterType="PublicDetailShare" resultMap="PublicDetailShareResult">
        <include refid="selectPublicDetailShareVo"/>
        <where>
            <if test="detailId != null "> and detail_id = #{detailId}</if>
            <if test="authorId != null "> and author_id = #{authorId}</if>
            <if test="authorName != null  and authorName != ''"> and author_name like concat('%', #{authorName}, '%')</if>
            <if test="readerOneId != null "> and reader_one_id = #{readerOneId}</if>
            <if test="readerOneName != null  and readerOneName != ''"> and reader_one_name like concat('%', #{readerOneName}, '%')</if>
            <if test="readerTwoId != null "> and reader_two_id = #{readerTwoId}</if>
            <if test="readerTwoName != null  and readerTwoName != ''"> and reader_two_name like concat('%', #{readerTwoName}, '%')</if>
        </where>
    </select>

    <select id="selectPublicDetailShareById" parameterType="Long" resultMap="PublicDetailShareResult">
        <include refid="selectPublicDetailShareVo"/>
        where id = #{id}
    </select>

    <insert id="insertPublicDetailShare" parameterType="PublicDetailShare" useGeneratedKeys="true" keyProperty="id">
        insert into public_detail_share
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="detailId != null">detail_id,</if>
            <if test="authorId != null">author_id,</if>
            <if test="authorName != null">author_name,</if>
            <if test="readerOneId != null">reader_one_id,</if>
            <if test="readerOneName != null">reader_one_name,</if>
            <if test="readerTwoId != null">reader_two_id,</if>
            <if test="readerTwoName != null">reader_two_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</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="detailId != null">#{detailId},</if>
            <if test="authorId != null">#{authorId},</if>
            <if test="authorName != null">#{authorName},</if>
            <if test="readerOneId != null">#{readerOneId},</if>
            <if test="readerOneName != null">#{readerOneName},</if>
            <if test="readerTwoId != null">#{readerTwoId},</if>
            <if test="readerTwoName != null">#{readerTwoName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updatePublicDetailShare" parameterType="PublicDetailShare">
        update public_detail_share
        <trim prefix="SET" suffixOverrides=",">
            <if test="detailId != null">detail_id = #{detailId},</if>
            <if test="authorId != null">author_id = #{authorId},</if>
            <if test="authorName != null">author_name = #{authorName},</if>
            <if test="readerOneId != null">reader_one_id = #{readerOneId},</if>
            <if test="readerOneName != null">reader_one_name = #{readerOneName},</if>
            <if test="readerTwoId != null">reader_two_id = #{readerTwoId},</if>
            <if test="readerTwoName != null">reader_two_name = #{readerTwoName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</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="deletePublicDetailShareById" parameterType="Long">
        delete from public_detail_share where id = #{id}
    </delete>

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

</mapper>