<?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.ruoyi.system.mapper.ComplaintSuggestionMapper">
    
    <resultMap type="ComplaintSuggestion" id="ComplaintSuggestionResult">
        <result property="suggestionId"    column="suggestion_id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="images"    column="images"    />
        <result property="createdTime"    column="created_time"    />
        <result property="status"    column="status"    />
        <result property="replyContent"    column="reply_content"    />
        <result property="type"    column="type"    />
        <result property="isPublic"    column="is_public"    />
        <result property="userId"    column="user_id"    />
        <result property="isDel"    column="is_del"    />
        <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="selectComplaintSuggestionVo">
        select suggestion_id, title, content, images, created_time, status, reply_content, type, is_public, user_id, is_del, create_by, create_time, update_by, update_time, remark from complaint_suggestion
    </sql>

    <select id="selectComplaintSuggestionList" parameterType="ComplaintSuggestion" resultMap="ComplaintSuggestionResult">
        <include refid="selectComplaintSuggestionVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="images != null  and images != ''"> and images = #{images}</if>
            <if test="createdTime != null "> and created_time = #{createdTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="replyContent != null  and replyContent != ''"> and reply_content = #{replyContent}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="isPublic != null  and isPublic != ''"> and is_public = #{isPublic}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectComplaintSuggestionBySuggestionId" parameterType="Long" resultMap="ComplaintSuggestionResult">
        <include refid="selectComplaintSuggestionVo"/>
        where suggestion_id = #{suggestionId}
    </select>

    <insert id="insertComplaintSuggestion" parameterType="ComplaintSuggestion" useGeneratedKeys="true" keyProperty="suggestionId">
        insert into complaint_suggestion
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="images != null">images,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="status != null">status,</if>
            <if test="replyContent != null">reply_content,</if>
            <if test="type != null">type,</if>
            <if test="isPublic != null">is_public,</if>
            <if test="userId != null">user_id,</if>
            <if test="isDel != null">is_del,</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="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="images != null">#{images},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="status != null">#{status},</if>
            <if test="replyContent != null">#{replyContent},</if>
            <if test="type != null">#{type},</if>
            <if test="isPublic != null">#{isPublic},</if>
            <if test="userId != null">#{userId},</if>
            <if test="isDel != null">#{isDel},</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="updateComplaintSuggestion" parameterType="ComplaintSuggestion">
        update complaint_suggestion
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="images != null">images = #{images},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="replyContent != null">reply_content = #{replyContent},</if>
            <if test="type != null">type = #{type},</if>
            <if test="isPublic != null">is_public = #{isPublic},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="isDel != null">is_del = #{isDel},</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 suggestion_id = #{suggestionId}
    </update>

    <delete id="deleteComplaintSuggestionBySuggestionId" parameterType="Long">
        delete from complaint_suggestion where suggestion_id = #{suggestionId}
    </delete>

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