<?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.TComplainDealTransferMapper">
    
    <resultMap type="TComplainDealTransfer" id="TComplainDealTransferResult">
        <result property="complainDealTransferId"    column="complain_deal_transfer_id"    />
        <result property="complainDealId"    column="complain_deal_id"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="complainAssignManId"    column="complain_assign_man_id"    />
        <result property="complainAssignMan"    column="complain_assign_man"    />
        <result property="reasonConcent"    column="reason_concent"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTComplainDealTransferVo">
        select
            t.complain_deal_transfer_id,
            t.complain_deal_id,
            t.enterprise_id,
            i.enterprise_name,
            t.complain_assign_man_id,
            t.complain_assign_man,
            t.reason_concent,
            t.create_by,
            t.create_time from t_complain_deal_transfer t left join t_enterprise_info i on t.enterprise_id = i.enterprise_id
    </sql>

    <select id="selectTComplainDealTransferList" parameterType="TComplainDealTransfer" resultMap="TComplainDealTransferResult">
        <include refid="selectTComplainDealTransferVo"/>
        <where>  
            <if test="complainDealId != null "> and complain_deal_id = #{complainDealId}</if>
            <if test="enterpriseId != null  and enterpriseId != ''"> and enterprise_id = #{enterpriseId}</if>
            <if test="enterpriseName != null  and enterpriseName != ''"> and enterprise_name like concat('%', #{enterpriseName}, '%')</if>
            <if test="reasonConcent != null  and reasonConcent != ''"> and reason_concent = #{reasonConcent}</if>
        </where>
    </select>
    
    <select id="selectTComplainDealTransferById" parameterType="Long" resultMap="TComplainDealTransferResult">
        <include refid="selectTComplainDealTransferVo"/>
        where complain_deal_transfer_id = #{complainDealTransferId}
    </select>
    <select id="queryComplainDealTransferListByComplainDealId" resultMap="TComplainDealTransferResult">
        <include refid="selectTComplainDealTransferVo"/>
        where complain_deal_id = #{complainDealId}
    </select>
        
    <insert id="insertTComplainDealTransfer" parameterType="TComplainDealTransfer" useGeneratedKeys="true" keyProperty="complainDealTransferId">
        insert into t_complain_deal_transfer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="complainDealId != null">complain_deal_id,</if>
            <if test="enterpriseId != null and enterpriseId != ''">enterprise_id,</if>
            <if test="enterpriseName != null">enterprise_name,</if>
            <if test="reasonConcent != null">reason_concent,</if>
            <if test="complainAssignManId != null">complain_assign_man_id,</if>
            <if test="complainAssignMan != null">complain_assign_man,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="complainDealId != null">#{complainDealId},</if>
            <if test="enterpriseId != null and enterpriseId != ''">#{enterpriseId},</if>
            <if test="enterpriseName != null">#{enterpriseName},</if>
            <if test="reasonConcent != null">#{reasonConcent},</if>
            <if test="complainAssignManId != null">#{complainAssignManId},</if>
            <if test="complainAssignMan != null">#{complainAssignMan},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTComplainDealTransfer" parameterType="TComplainDealTransfer">
        update t_complain_deal_transfer
        <trim prefix="SET" suffixOverrides=",">
            <if test="complainDealId != null">complain_deal_id = #{complainDealId},</if>
            <if test="enterpriseId != null and enterpriseId != ''">enterprise_id = #{enterpriseId},</if>
            <if test="enterpriseName != null">enterprise_name = #{enterpriseName},</if>

            <if test="complainAssignManId != null">enterprise_id = #{complainAssignManId},</if>
            <if test="complainAssignMan != null">enterprise_name = #{complainAssignMan},</if>

            <if test="reasonConcent != null">reason_concent = #{reasonConcent},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where complain_deal_transfer_id = #{complainDealTransferId}
    </update>

    <delete id="deleteTComplainDealTransferById" parameterType="Long">
        delete from t_complain_deal_transfer where complain_deal_transfer_id = #{complainDealTransferId}
    </delete>

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