<?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="cn.iocoder.yudao.module.inspection.mapper.InspectionNewsCommentMapper">

    <resultMap type="cn.iocoder.yudao.module.inspection.entity.InspectionNewsComment" id="InspectionNewsCommentResult">
        <result property="id"    column="id"    />
        <result property="newsId"    column="news_id"    />
        <result property="context"    column="context"    />
        <result property="realName"    column="real_name"    />
        <result property="userAvatar"    column="user_avatar"    />
        <result property="createTime"    column="create_time"    />
        <result property="creator"    column="creator"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updater"    column="updater"    />
    </resultMap>

    <sql id="selectInspectionNewsCommentVo">
        select id, news_id, context, real_name, user_avatar, create_time, creator, update_time, updater from inspection_news_comment
    </sql>

    <select id="selectInspectionNewsCommentList" parameterType="cn.iocoder.yudao.module.inspection.entity.InspectionNewsComment" resultMap="InspectionNewsCommentResult">
        <include refid="selectInspectionNewsCommentVo"/>
        <where>
            <if test="vo.newsId != null "> and news_id = #{vo.newsId}</if>
            <if test="vo.context != null  and vo.context != ''"> and context = #{vo.context}</if>
            <if test="vo.realName != null  and vo.realName != ''"> and real_name like concat('%', #{vo.realName}, '%')</if>
            <if test="vo.userAvatar != null  and vo.userAvatar != ''"> and user_avatar = #{vo.userAvatar}</if>
        </where>
    </select>

    <select id="selectInspectionNewsCommentById" parameterType="Long" resultMap="InspectionNewsCommentResult">
        <include refid="selectInspectionNewsCommentVo"/>
        where id = #{id}
    </select>

    <insert id="insertInspectionNewsComment" parameterType="cn.iocoder.yudao.module.inspection.entity.InspectionNewsComment" useGeneratedKeys="true" keyProperty="id">
        insert into inspection_news_comment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="newsId != null">news_id,</if>
            <if test="context != null">context,</if>
            <if test="realName != null">real_name,</if>
            <if test="userAvatar != null">user_avatar,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creator != null">creator,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updater != null">updater,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="newsId != null">#{newsId},</if>
            <if test="context != null">#{context},</if>
            <if test="realName != null">#{realName},</if>
            <if test="userAvatar != null">#{userAvatar},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creator != null">#{creator},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updater != null">#{updater},</if>
         </trim>
    </insert>

    <update id="updateInspectionNewsComment" parameterType="cn.iocoder.yudao.module.inspection.entity.InspectionNewsComment">
        update inspection_news_comment
        <trim prefix="SET" suffixOverrides=",">
            <if test="newsId != null">news_id = #{newsId},</if>
            <if test="context != null">context = #{context},</if>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="userAvatar != null">user_avatar = #{userAvatar},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updater != null">updater = #{updater},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInspectionNewsCommentById" parameterType="Long">
        delete from inspection_news_comment where id = #{id}
    </delete>

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