<?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.ygtx.worklog.mapper.ReportCommentMapper">

    <resultMap type="ReportComment" id="ReportCommentResult">
        <result property="id"    column="id"    />
        <result property="reportId"    column="report_id"    />
        <result property="reportType"    column="report_type"    />
        <result property="commentContent"    column="comment_content"    />
        <result property="commentBy"    column="comment_by"    />
        <result property="commentByName"    column="comment_by_name"    />
        <result property="commentTime"    column="comment_time"    />
        <result property="parentId"    column="parent_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectReportCommentVo">
        select id, report_id, report_type, comment_content, comment_by, comment_by_name,
               comment_time, parent_id, create_time
        from wl_report_comment
    </sql>

    <select id="selectReportCommentList" parameterType="ReportComment" resultMap="ReportCommentResult">
        <include refid="selectReportCommentVo"/>
        <where>
            <if test="reportId != null "> and report_id = #{reportId}</if>
            <if test="reportType != null  and reportType != ''"> and report_type = #{reportType}</if>
            <if test="commentBy != null "> and comment_by = #{commentBy}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
        </where>
        order by comment_time asc
    </select>

    <select id="selectReportCommentById" parameterType="Long" resultMap="ReportCommentResult">
        <include refid="selectReportCommentVo"/>
        where id = #{id}
    </select>

    <select id="selectCommentsByReport" resultMap="ReportCommentResult">
        <include refid="selectReportCommentVo"/>
        where report_id = #{reportId} and report_type = #{reportType}
        order by comment_time asc
    </select>

    <insert id="insertReportComment" parameterType="ReportComment" useGeneratedKeys="true" keyProperty="id">
        insert into wl_report_comment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="reportId != null">report_id,</if>
            <if test="reportType != null and reportType != ''">report_type,</if>
            <if test="commentContent != null">comment_content,</if>
            <if test="commentBy != null">comment_by,</if>
            <if test="commentByName != null and commentByName != ''">comment_by_name,</if>
            <if test="commentTime != null">comment_time,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="reportId != null">#{reportId},</if>
            <if test="reportType != null and reportType != ''">#{reportType},</if>
            <if test="commentContent != null">#{commentContent},</if>
            <if test="commentBy != null">#{commentBy},</if>
            <if test="commentByName != null and commentByName != ''">#{commentByName},</if>
            <if test="commentTime != null">#{commentTime},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateReportComment" parameterType="ReportComment">
        update wl_report_comment
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportId != null">report_id = #{reportId},</if>
            <if test="reportType != null and reportType != ''">report_type = #{reportType},</if>
            <if test="commentContent != null">comment_content = #{commentContent},</if>
            <if test="commentBy != null">comment_by = #{commentBy},</if>
            <if test="commentByName != null and commentByName != ''">comment_by_name = #{commentByName},</if>
            <if test="commentTime != null">comment_time = #{commentTime},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteReportCommentById" parameterType="Long">
        delete from wl_report_comment where id = #{id}
    </delete>

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