<?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.bonus.canteen.core.alloc.mapper.AllocCanteenSuggestionMapper">
    <resultMap type="com.bonus.canteen.core.alloc.domain.AllocCanteenSuggestion" id="AllocCanteenSuggestionResult">
        <result property="complaintId"    column="complaint_id"    />
        <result property="userId"    column="user_id"    />
        <result property="content"    column="content"    />
        <result property="canteenId"    column="canteen_id"    />
        <result property="canteenName"    column="canteen_name"    />
        <result property="complaintPicture"    column="complaint_picture"    />
        <result property="sourceType"    column="source_type"    />
        <result property="mobile"    column="mobile"    />
        <result property="replyContent"    column="reply_content"    />
        <result property="revision"    column="revision"    />
        <result property="replyState"    column="reply_state"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAllocCanteenSuggestionVo">
        select acs.complaint_id, acs.user_id, acs.content, acs.canteen_id, acs.complaint_picture, acs.source_type,
               acs.mobile, acs.reply_content, acs.revision, acs.reply_state, acs.create_by, acs.create_time,
               acs.update_by, acs.update_time, ac.canteen_name
        from alloc_canteen_suggestion acs
         left join alloc_canteen ac on acs.canteen_id = ac.canteen_id
    </sql>

    <select id="selectAllocCanteenSuggestionList" parameterType="com.bonus.canteen.core.alloc.domain.AllocCanteenSuggestion" resultMap="AllocCanteenSuggestionResult">
        <include refid="selectAllocCanteenSuggestionVo"/>
        <where>  
            <if test="complaintId != null "> and acs.complaint_id = #{complaintId}</if>
            <if test="userId != null "> and acs.user_id = #{userId}</if>
            <if test="content != null  and content != ''"> and acs.content = #{content}</if>
            <if test="canteenId != null "> and acs.canteen_id = #{canteenId}</if>
            <if test="complaintPicture != null  and complaintPicture != ''"> and acs.complaint_picture = #{complaintPicture}</if>
            <if test="sourceType != null "> and acs.source_type = #{sourceType}</if>
            <if test="mobile != null  and mobile != ''"> and acs.mobile = #{mobile}</if>
            <if test="replyContent != null  and replyContent != ''"> and acs.reply_content = #{replyContent}</if>
            <if test="revision != null "> and acs.revision = #{revision}</if>
            <if test="replyState != null "> and acs.reply_state = #{replyState}</if>
        </where>
    </select>
    
    <select id="selectAllocCanteenSuggestionById" parameterType="Long" resultMap="AllocCanteenSuggestionResult">
        <include refid="selectAllocCanteenSuggestionVo"/>
        where acs.complaint_id = #{complaintId}
    </select>
        
    <insert id="insertAllocCanteenSuggestion" parameterType="com.bonus.canteen.core.alloc.domain.AllocCanteenSuggestion" useGeneratedKeys="true" keyProperty="complaintId">
        insert into alloc_canteen_suggestion
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="canteenId != null">canteen_id,</if>
            <if test="complaintPicture != null and complaintPicture != ''">complaint_picture,</if>
            <if test="sourceType != null">source_type,</if>
            <if test="mobile != null">mobile,</if>
            <if test="replyContent != null">reply_content,</if>
            <if test="revision != null">revision,</if>
            <if test="replyState != null">reply_state,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="canteenId != null">#{canteenId},</if>
            <if test="complaintPicture != null and complaintPicture != ''">#{complaintPicture},</if>
            <if test="sourceType != null">#{sourceType},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="replyContent != null">#{replyContent},</if>
            <if test="revision != null">#{revision},</if>
            <if test="replyState != null">#{replyState},</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>
         </trim>
    </insert>

    <update id="updateAllocCanteenSuggestion" parameterType="com.bonus.canteen.core.alloc.domain.AllocCanteenSuggestion">
        update alloc_canteen_suggestion
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="canteenId != null">canteen_id = #{canteenId},</if>
            <if test="complaintPicture != null and complaintPicture != ''">complaint_picture = #{complaintPicture},</if>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="replyContent != null">reply_content = #{replyContent},</if>
            <if test="revision != null">revision = #{revision},</if>
            <if test="replyState != null">reply_state = #{replyState},</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>
        </trim>
        where complaint_id = #{complaintId}
    </update>

    <delete id="deleteAllocCanteenSuggestionById" parameterType="Long">
        delete from alloc_canteen_suggestion where complaint_id = #{complaintId}
    </delete>

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