<?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.boyue.hasfj.mapper.UserFeedbackMapper">
    
    <resultMap type="UserFeedback" id="UserFeedbackResult">
        <result property="id" column="id" />
        <result property="feedbackNo" column="feedback_no" />
        <result property="legalArticle" column="legal_article" />
        <result property="issueDescription" column="issue_description" />
        <result property="userName" column="user_name" />
        <result property="phoneNumber" column="phone_number" />
        <result property="idCardNumber" column="id_card_number" />
        <result property="contactInfoType" column="contact_info_type" />
        <result property="status" column="status" />
        <result property="createTime" column="create_time" />
        <result property="adminReplyContent" column="admin_reply_content" />
        <result property="adminReplyTime" column="admin_reply_time" />
        <result property="adminId" column="admin_id" />
    </resultMap>

    <sql id="selectUserFeedbackVo">
        select 
            uf.id,
            uf.feedback_no,
            uf.legal_article,
            uf.issue_description,
            uf.user_name,
            uf.phone_number,
            uf.id_card_number,
            uf.contact_info_type,
            uf.status,
            uf.create_time,
            uf.admin_reply_content,
            uf.admin_reply_time,
            uf.admin_id
        from user_feedback uf
    </sql>

    <select id="selectUserFeedbackList" parameterType="UserFeedback" resultMap="UserFeedbackResult">
        <include refid="selectUserFeedbackVo"/>
        <where>
            <if test="feedbackNo != null  and feedbackNo != ''">
                and uf.feedback_no = #{feedbackNo}
            </if>
            <if test="userName != null and userName != '' or idCardNumber != null and idCardNumber != '' or phoneNumber != null and phoneNumber != ''">
                AND (
                    <trim prefixOverrides="OR">
                        <if test="userName != null  and userName != ''">
                            OR uf.user_name like concat('%', #{userName}, '%')
                        </if>
                        <if test="idCardNumber != null  and idCardNumber != ''">
                            OR uf.id_card_number = #{idCardNumber}
                        </if>
                        <if test="phoneNumber != null  and phoneNumber != ''">
                            OR uf.phone_number = #{phoneNumber}
                        </if>
                    </trim>
                )
            </if>
            <if test="legalArticle != null  and legalArticle != ''"> and uf.legal_article like concat('%', #{legalArticle}, '%')</if>
            <if test="issueDescription != null  and issueDescription != ''"> and uf.issue_description like concat('%', #{issueDescription}, '%')</if>
            <if test="contactInfoType != null "> and uf.contact_info_type = #{contactInfoType}</if>
            <if test="status != null "> and uf.status = #{status}</if>
            <if test="adminReplyContent != null  and adminReplyContent != ''"> and uf.admin_reply_content = #{adminReplyContent}</if>
            <if test="adminReplyTime != null "> and uf.admin_reply_time = #{adminReplyTime}</if>
            <if test="adminId != null "> and uf.admin_id = #{adminId}</if>
        </where>
    </select>
    
    <select id="selectUserFeedbackById" parameterType="Long" resultMap="UserFeedbackResult">
        <include refid="selectUserFeedbackVo"/>
        where uf.id = #{id}
    </select>
        
    <insert id="insertUserFeedback" parameterType="UserFeedback" useGeneratedKeys="true" keyProperty="id">
        insert into user_feedback
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="feedbackNo != null and feedbackNo != ''">feedback_no,</if>
            <if test="legalArticle != null">legal_article,</if>
            <if test="issueDescription != null and issueDescription != ''">issue_description,</if>
            <if test="userName != null">user_name,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="idCardNumber != null">id_card_number,</if>
            <if test="contactInfoType != null">contact_info_type,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="adminReplyContent != null">admin_reply_content,</if>
            <if test="adminReplyTime != null">admin_reply_time,</if>
            <if test="adminId != null">admin_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="feedbackNo != null and feedbackNo != ''">#{feedbackNo},</if>
            <if test="legalArticle != null">#{legalArticle},</if>
            <if test="issueDescription != null and issueDescription != ''">#{issueDescription},</if>
            <if test="userName != null">#{userName},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="idCardNumber != null">#{idCardNumber},</if>
            <if test="contactInfoType != null">#{contactInfoType},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="adminReplyContent != null">#{adminReplyContent},</if>
            <if test="adminReplyTime != null">#{adminReplyTime},</if>
            <if test="adminId != null">#{adminId},</if>
         </trim>
    </insert>

    <update id="updateUserFeedback" parameterType="UserFeedback">
        update user_feedback
        <trim prefix="SET" suffixOverrides=",">
            <if test="feedbackNo != null and feedbackNo != ''">feedback_no = #{feedbackNo},</if>
            <if test="legalArticle != null">legal_article = #{legalArticle},</if>
            <if test="issueDescription != null and issueDescription != ''">issue_description = #{issueDescription},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="idCardNumber != null">id_card_number = #{idCardNumber},</if>
            <if test="contactInfoType != null">contact_info_type = #{contactInfoType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="adminReplyContent != null">admin_reply_content = #{adminReplyContent},</if>
            <if test="adminReplyTime != null">admin_reply_time = #{adminReplyTime},</if>
            <if test="adminId != null">admin_id = #{adminId},</if>
        </trim>
        where user_feedback.id = #{id}
    </update>

    <delete id="deleteUserFeedbackById" parameterType="Long">
        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>