<?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.ruoyi.ibs.list.mapper.RecordRelateMapper">
    
    <resultMap type="RecordRelate" id="RecordRelateResult">
        <result property="id"    column="id"    />
        <result property="socialCreditCode"    column="social_credit_code"    />
        <result property="relateCustIdc"    column="relate_cust_idc"    />
        <result property="relatePerson"    column="relate_person"    />
        <result property="relateMerchant"    column="relate_merchant"    />
        <result property="relateBusiness"    column="relate_business"    />
        <result property="custIdc"    column="cust_idc"    />
        <result property="custType"    column="cust_type"    />
        <result property="relateMerchantCode"    column="relate_merchant_code"    />
        <result property="relateBusinessCode"    column="relate_business_code"    />
        <result property="recordId"    column="record_id"    />
    </resultMap>

    <sql id="selectRecordRelateVo">
        select id, social_credit_code, relate_cust_idc, relate_person, relate_merchant, relate_business, cust_idc, cust_type, relate_merchant_code, relate_business_code,record_id from record_relate
    </sql>

    <select id="selectRecordRelateList" parameterType="RecordRelate" resultMap="RecordRelateResult">
        <include refid="selectRecordRelateVo"/>
        <where>  
            <if test="socialCreditCode != null  and socialCreditCode != ''"> and social_credit_code = #{socialCreditCode}</if>
            <if test="relateCustIdc != null  and relateCustIdc != ''"> and relate_cust_idc = #{relateCustIdc}</if>
            <if test="relatePerson != null  and relatePerson != ''"> and relate_person = #{relatePerson}</if>
            <if test="relateMerchant != null  and relateMerchant != ''"> and relate_merchant = #{relateMerchant}</if>
            <if test="relateBusiness != null  and relateBusiness != ''"> and relate_business = #{relateBusiness}</if>
            <if test="custIdc != null  and custIdc != ''"> and cust_idc = #{custIdc}</if>
            <if test="custType != null  and custType != ''"> and cust_type = #{custType}</if>
            <if test="relateMerchantCode != null  and relateMerchantCode != ''"> and relate_merchant_code = #{relateMerchantCode}</if>
            <if test="relateBusinessCode != null  and relateBusinessCode != ''"> and relate_business_code = #{relateBusinessCode}</if>
            <if test="recordId != null "> and record_id = #{recordId}</if>
        </where>
    </select>
    
    <select id="selectRecordRelateById" parameterType="Long" resultMap="RecordRelateResult">
        <include refid="selectRecordRelateVo"/>
        where id = #{id}
    </select>

    <insert id="insertRecordRelate" parameterType="RecordRelate" useGeneratedKeys="true" keyProperty="id">
        insert into record_relate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="socialCreditCode != null">social_credit_code,</if>
            <if test="relateCustIdc != null">relate_cust_idc,</if>
            <if test="relatePerson != null">relate_person,</if>
            <if test="relateMerchant != null">relate_merchant,</if>
            <if test="relateBusiness != null">relate_business,</if>
            <if test="custIdc != null">cust_idc,</if>
            <if test="custType != null">cust_type,</if>
            <if test="relateMerchantCode != null">relate_merchant_code,</if>
            <if test="relateBusinessCode != null">relate_business_code,</if>
            <if test="recordId != null">record_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="socialCreditCode != null">#{socialCreditCode},</if>
            <if test="relateCustIdc != null">#{relateCustIdc},</if>
            <if test="relatePerson != null">#{relatePerson},</if>
            <if test="relateMerchant != null">#{relateMerchant},</if>
            <if test="relateBusiness != null">#{relateBusiness},</if>
            <if test="custIdc != null">#{custIdc},</if>
            <if test="custType != null">#{custType},</if>
            <if test="relateMerchantCode != null">#{relateMerchantCode},</if>
            <if test="relateBusinessCode != null">#{relateBusinessCode},</if>
            <if test="recordId != null">#{recordId},</if>
         </trim>
    </insert>

    <update id="updateRecordRelate" parameterType="RecordRelate">
        update record_relate
        <trim prefix="SET" suffixOverrides=",">
            <if test="socialCreditCode != null">social_credit_code = #{socialCreditCode},</if>
            <if test="relateCustIdc != null">relate_cust_idc = #{relateCustIdc},</if>
            <if test="relatePerson != null">relate_person = #{relatePerson},</if>
            <if test="relateMerchant != null">relate_merchant = #{relateMerchant},</if>
            <if test="relateBusiness != null">relate_business = #{relateBusiness},</if>
            <if test="custIdc != null">cust_idc = #{custIdc},</if>
            <if test="custType != null">cust_type = #{custType},</if>
            <if test="relateMerchantCode != null">relate_merchant_code = #{relateMerchantCode},</if>
            <if test="relateBusinessCode != null">relate_business_code = #{relateBusinessCode},</if>
            <if test="recordId != null">record_id = #{recordId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRecordRelateById" parameterType="Long">
        delete from record_relate where id = #{id}
    </delete>

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