<?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.zehong.system.mapper.TWorkSupervisionFeedbackMapper">
    
    <resultMap type="TWorkSupervisionFeedback" id="TWorkSupervisionFeedbackResult">
        <result property="feedbackId"    column="feedback_id"    />
        <result property="supervisionId"    column="supervision_id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="person"    column="person"    />
        <result property="phone"    column="phone"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTWorkSupervisionFeedbackVo">
        select feedback_id, supervision_id, title, content, image_url, file_url, enterprise_id,
        (SELECT enterprise_name FROM t_enterprise_info e WHERE e.enterprise_id = f.enterprise_id) as enterpriseName,
        person, phone, create_time from t_work_supervision_feedback f
    </sql>

    <select id="selectTWorkSupervisionFeedbackList" parameterType="TWorkSupervisionFeedback" resultMap="TWorkSupervisionFeedbackResult">
        <include refid="selectTWorkSupervisionFeedbackVo"/>
        <where>  
            <if test="supervisionId != null "> and supervision_id = #{supervisionId}</if>
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="enterpriseId != null "> and enterprise_id = #{enterpriseId}</if>
        </where>
    </select>
    
    <select id="selectTWorkSupervisionFeedbackById" parameterType="Long" resultMap="TWorkSupervisionFeedbackResult">
        <include refid="selectTWorkSupervisionFeedbackVo"/>
        where feedback_id = #{feedbackId}
    </select>
        
    <insert id="insertTWorkSupervisionFeedback" parameterType="TWorkSupervisionFeedback" useGeneratedKeys="true" keyProperty="feedbackId">
        insert into t_work_supervision_feedback
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="supervisionId != null">supervision_id,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="enterpriseId != null">enterprise_id,</if>
            <if test="person != null">person,</if>
            <if test="phone != null">phone,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="supervisionId != null">#{supervisionId},</if>
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="enterpriseId != null">#{enterpriseId},</if>
            <if test="person != null">#{person},</if>
            <if test="phone != null">#{phone},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTWorkSupervisionFeedback" parameterType="TWorkSupervisionFeedback">
        update t_work_supervision_feedback
        <trim prefix="SET" suffixOverrides=",">
            <if test="supervisionId != null">supervision_id = #{supervisionId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
            <if test="person != null">person = #{person},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where feedback_id = #{feedbackId}
    </update>

    <delete id="deleteTWorkSupervisionFeedbackById" parameterType="Long">
        delete from t_work_supervision_feedback where feedback_id = #{feedbackId}
    </delete>

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