<?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.UserFeedbackMapper">
    
    <resultMap type="UserFeedback" id="UserFeedbackResult">
        <result property="id"    column="id"    />
        <result property="feedbackContent"    column="feedback_content"    />
        <result property="userName"    column="user_name"    />
        <result property="contactType"    column="contact_type"    />
        <result property="contactInfo"    column="contact_info"    />
        <result property="status"    column="status"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
        <result property="ipAddress"    column="ip_address"    />
        <result property="userAgent"    column="user_agent"    />
        <result property="attachmentPath"    column="attachment_path"    />
    </resultMap>

    <sql id="selectUserFeedbackVo">
        select id, feedback_content, user_name, contact_type, contact_info, status, created_at, updated_at, ip_address, user_agent, attachment_path from user_feedback
    </sql>

    <select id="selectUserFeedbackList" parameterType="UserFeedback" resultMap="UserFeedbackResult">
        <include refid="selectUserFeedbackVo"/>
        <where>  
            <if test="feedbackContent != null  and feedbackContent != ''"> and feedback_content = #{feedbackContent}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="contactType != null  and contactType != ''"> and contact_type = #{contactType}</if>
            <if test="contactInfo != null  and contactInfo != ''"> and contact_info = #{contactInfo}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
            <if test="ipAddress != null  and ipAddress != ''"> and ip_address = #{ipAddress}</if>
            <if test="userAgent != null  and userAgent != ''"> and user_agent = #{userAgent}</if>
            <if test="attachmentPath != null  and attachmentPath != ''"> and attachment_path = #{attachmentPath}</if>
        </where>
    </select>
    
    <select id="selectUserFeedbackById" parameterType="String" resultMap="UserFeedbackResult">
        <include refid="selectUserFeedbackVo"/>
        where id = #{id}
    </select>

    <insert id="insertUserFeedback" parameterType="UserFeedback" useGeneratedKeys="true" keyProperty="id">
        insert into user_feedback
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="feedbackContent != null and feedbackContent != ''">feedback_content,</if>
            <if test="userName != null">user_name,</if>
            <if test="contactType != null">contact_type,</if>
            <if test="contactInfo != null">contact_info,</if>
            <if test="status != null">status,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="ipAddress != null">ip_address,</if>
            <if test="userAgent != null">user_agent,</if>
            <if test="attachmentPath != null">attachment_path,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="feedbackContent != null and feedbackContent != ''">#{feedbackContent},</if>
            <if test="userName != null">#{userName},</if>
            <if test="contactType != null">#{contactType},</if>
            <if test="contactInfo != null">#{contactInfo},</if>
            <if test="status != null">#{status},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="ipAddress != null">#{ipAddress},</if>
            <if test="userAgent != null">#{userAgent},</if>
            <if test="attachmentPath != null">#{attachmentPath},</if>
         </trim>
    </insert>

    <update id="updateUserFeedback" parameterType="UserFeedback">
        update user_feedback
        <trim prefix="SET" suffixOverrides=",">
            <if test="feedbackContent != null and feedbackContent != ''">feedback_content = #{feedbackContent},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="contactType != null">contact_type = #{contactType},</if>
            <if test="contactInfo != null">contact_info = #{contactInfo},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="ipAddress != null">ip_address = #{ipAddress},</if>
            <if test="userAgent != null">user_agent = #{userAgent},</if>
            <if test="attachmentPath != null">attachment_path = #{attachmentPath},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserFeedbackById" parameterType="String">
        delete from user_feedback where id = #{id}
    </delete>

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