<?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.ximai.mes.md.mapper.MdClientPaymentRelationMapper">

    <resultMap type="MdClientPaymentRelation" id="MdClientPaymentRelationResult">
        <result property="id" column="id"/>
        <result property="clientCode" column="client_code"/>
        <result property="relatedClientId" column="related_client_id"/>
        <result property="relatedName" column="related_name"/>
        <result property="relatedCode" column="related_code"/>
        <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="selectMdClientPaymentRelationVo">
        select t1.id, t1.client_code, t1.related_client_id, t2.client_code related_code, t2.client_name related_name,
               t1.create_by, t1.create_time, t1.update_by, t1.update_time
        from md_client_payment_relation t1
        left join md_client t2 on t1.related_client_id = t2.client_id
    </sql>

    <select id="selectMdClientPaymentRelationList" parameterType="MdClientPaymentRelation" resultMap="MdClientPaymentRelationResult">
        <include refid="selectMdClientPaymentRelationVo"/>
        <where>
            <if test="clientCode != null "> and t1.client_code = #{clientCode}</if>
            <if test="relatedClientId != null "> and t1.related_client_id = #{relatedClientId}</if>
        </where>
    </select>

    <select id="selectMdClientPaymentRelationById" parameterType="String" resultMap="MdClientPaymentRelationResult">
        <include refid="selectMdClientPaymentRelationVo"/>
        where t1.id = #{id}
    </select>

    <insert id="insertMdClientPaymentRelation" parameterType="MdClientPaymentRelation" useGeneratedKeys="true" keyProperty="id">
        insert into md_client_payment_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientCode != null">client_code,</if>
            <if test="relatedClientId != null">related_client_id,</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="clientCode != null">#{clientCode},</if>
            <if test="relatedClientId != null">#{relatedClientId},</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="updateMdClientPaymentRelation" parameterType="MdClientPaymentRelation">
        update md_client_payment_relation
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientCode != null">client_code = #{clientCode},</if>
            <if test="relatedClientId != null">related_client_id = #{relatedClientId},</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 id = #{id}
    </update>

    <delete id="deleteMdClientPaymentRelationById" parameterType="String">
        delete from md_client_payment_relation where id = #{id}
    </delete>

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