<?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.srs.comprehensive.mapper.SrsComplaintMapper">
    
    <resultMap type="SrsComplaint" id="SrsComplaintResult">
        <result property="id"    column="id"    />
        <result property="desc"    column="desc"    />
        <result property="keyWords"    column="key_words"    />
        <result property="photos"    column="photos"    />
        <result property="contact"    column="contact"    />
        <result property="contactNumber"    column="contact_number"    />
        <result property="status"    column="status"    />
        <result property="feedback"    column="feedback"    />
        <result property="createId"    column="create_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateId"    column="update_id"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectSrsComplaintVo">
        select id, `desc`, key_words, photos, contact, contact_number, status, feedback, create_id, create_time, update_id, update_time from srs_complaint
    </sql>

    <select id="selectSrsComplaintList" parameterType="SrsComplaint" resultMap="SrsComplaintResult">
        <include refid="selectSrsComplaintVo"/>
        <where>  
            <if test="desc != null  and desc != ''"> and `desc` = #{desc}</if>
            <if test="keyWords != null  and keyWords != ''"> and key_words like concat('%', #{keyWords}, '%')  </if>
            <if test="photos != null  and photos != ''"> and photos = #{photos}</if>
            <if test="contact != null  and contact != ''"> and contact = #{contact}</if>
            <if test="contactNumber != null  and contactNumber != ''"> and contact_number = #{contactNumber}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="feedback != null  and feedback != ''"> and feedback = #{feedback}</if>
            <if test="createId != null "> and create_id = #{createId}</if>
            <if test="updateId != null "> and update_id = #{updateId}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectSrsComplaintById" parameterType="Long" resultMap="SrsComplaintResult">
        <include refid="selectSrsComplaintVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSrsComplaint" parameterType="SrsComplaint">
        insert into srs_complaint
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="desc != null">`desc`,</if>
            <if test="keyWords != null">key_words,</if>
            <if test="photos != null">photos,</if>
            <if test="contact != null">contact,</if>
            <if test="contactNumber != null">contact_number,</if>
            <if test="status != null">status,</if>
            <if test="feedback != null">feedback,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="desc != null">#{desc},</if>
            <if test="keyWords != null">#{keyWords},</if>
            <if test="photos != null">#{photos},</if>
            <if test="contact != null">#{contact},</if>
            <if test="contactNumber != null">#{contactNumber},</if>
            <if test="status != null">#{status},</if>
            <if test="feedback != null">#{feedback},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateSrsComplaint" parameterType="SrsComplaint">
        update srs_complaint
        <trim prefix="SET" suffixOverrides=",">
            <if test="desc != null">`desc` = #{desc},</if>
            <if test="keyWords != null">key_words = #{keyWords},</if>
            <if test="photos != null">photos = #{photos},</if>
            <if test="contact != null">contact = #{contact},</if>
            <if test="contactNumber != null">contact_number = #{contactNumber},</if>
            <if test="status != null">status = #{status},</if>
            <if test="feedback != null">feedback = #{feedback},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateId != null">update_id = #{updateId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSrsComplaintById" parameterType="Long">
        delete from srs_complaint where id = #{id}
    </delete>

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