<?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.ruixuan.live.mapper.KuaishouLiveCustomerMapper">

    <resultMap type="com.ruixuan.live.entity.KuaishouLiveCustomer" id="KuaishouLiveCustomerResult">
        <result property="ksId" column="ks_id"/>
        <result property="customerName" column="customer_name"/>
        <result property="launchType" column="launch_type"/>
        <result property="saleLeaderId" column="sale_leader_id"/>
        <result property="saleLeader" column="sale_leader"/>
        <result property="phone" column="phone"/>
        <result property="businessName" column="business_name"/>
        <result property="licenseCode" column="license_code"/>
        <result property="asMainBody" column="as_main_body"/>
        <result property="ksUrl" column="ks_url"/>
        <result property="sponsoredContent" column="sponsored_content"/>
        <result property="registration" column="registration"/>
        <result property="businessLicenseValidity" column="business_license_validity"/>
        <result property="copyrightValidity" column="copyright_validity"/>
        <result property="commitmentValidity" column="commitment_validity"/>
        <result property="businessLicenseUrl" column="business_license_url"/>
        <result property="copyrightUrl" column="copyright_url"/>
        <result property="commitmentUrl" column="commitment_url"/>
        <result property="invoiceStatus" column="invoice_status"/>
        <result property="createrId" column="creater_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouLiveCustomerVo">
        select ks_id,
               customer_name,
               launch_type,
               sale_leader_id,
               sale_leader,
               phone,
               business_name,
               license_code,
               as_main_body,
               ks_url,
               sponsored_content,
               registration,
               business_license_validity,
               copyright_validity,
               commitment_validity,
               business_license_url,
               copyright_url,
               commitment_url,
               invoice_status
        from kuaishou_live_customer
    </sql>

    <select id="selectKuaishouLiveCustomerList" parameterType="com.ruixuan.live.entity.KuaishouLiveCustomer"
            resultMap="KuaishouLiveCustomerResult">
        <include refid="selectKuaishouLiveCustomerVo"/>
        <where>
            <if test="customerName != null  and customerName != ''">and customer_name like concat('%', #{customerName},
                '%')
            </if>
            <if test="launchType != null  and launchType != ''">and launch_type = #{launchType}</if>
            <if test="saleLeaderId != null  and saleLeaderId != ''">and sale_leader_id = #{saleLeaderId}</if>
            <if test="saleLeader != null  and saleLeader != ''">and sale_leader = #{saleLeader}</if>
            <if test="phone != null  and phone != ''">and phone = #{phone}</if>
            <if test="businessName != null  and businessName != ''">and business_name like concat('%', #{businessName},
                '%')
            </if>
            <if test="licenseCode != null  and licenseCode != ''">and license_code = #{licenseCode}</if>
            <if test="asMainBody != null ">and as_main_body = #{asMainBody}</if>
            <if test="ksUrl != null  and ksUrl != ''">and ks_url = #{ksUrl}</if>
            <if test="sponsoredContent != null  and sponsoredContent != ''">and sponsored_content =
                #{sponsoredContent}
            </if>
            <if test="registration != null  and registration != ''">and registration = #{registration}</if>
            <if test="businessLicenseValidity != null  and businessLicenseValidity != ''">and business_license_validity
                = #{businessLicenseValidity}
            </if>
            <if test="copyrightValidity != null  and copyrightValidity != ''">and copyright_validity =
                #{copyrightValidity}
            </if>
            <if test="commitmentValidity != null  and commitmentValidity != ''">and commitment_validity =
                #{commitmentValidity}
            </if>
            <if test="businessLicenseUrl != null  and businessLicenseUrl != ''">and business_license_url =
                #{businessLicenseUrl}
            </if>
            <if test="copyrightUrl != null  and copyrightUrl != ''">and copyright_url = #{copyrightUrl}</if>
            <if test="commitmentUrl != null  and commitmentUrl != ''">and commitment_url = #{commitmentUrl}</if>
            <if test="invoiceStatus != null ">and invoice_status = #{invoiceStatus}</if>
            <if test="createrId != null  and createrId != ''">and creater_id = #{createrId}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectKuaishouLiveCustomerByKsId" parameterType="Long" resultMap="KuaishouLiveCustomerResult">
        <include refid="selectKuaishouLiveCustomerVo"/>
        where ks_id = #{ksId}
    </select>

    <insert id="insertKuaishouLiveCustomer" parameterType="com.ruixuan.live.entity.KuaishouLiveCustomer">
        insert into kuaishou_live_customer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ksId != null">ks_id,</if>
            <if test="customerName != null">customer_name,</if>
            <if test="launchType != null">launch_type,</if>
            <if test="saleLeaderId != null">sale_leader_id,</if>
            <if test="saleLeader != null">sale_leader,</if>
            <if test="phone != null">phone,</if>
            <if test="businessName != null">business_name,</if>
            <if test="licenseCode != null">license_code,</if>
            <if test="asMainBody != null">as_main_body,</if>
            <if test="ksUrl != null">ks_url,</if>
            <if test="sponsoredContent != null">sponsored_content,</if>
            <if test="registration != null">registration,</if>
            <if test="businessLicenseValidity != null">business_license_validity,</if>
            <if test="copyrightValidity != null">copyright_validity,</if>
            <if test="commitmentValidity != null">commitment_validity,</if>
            <if test="businessLicenseUrl != null">business_license_url,</if>
            <if test="copyrightUrl != null">copyright_url,</if>
            <if test="commitmentUrl != null">commitment_url,</if>
            <if test="invoiceStatus != null">invoice_status,</if>
            <if test="createrId != null">creater_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ksId != null">#{ksId},</if>
            <if test="customerName != null">#{customerName},</if>
            <if test="launchType != null">#{launchType},</if>
            <if test="saleLeaderId != null">#{saleLeaderId},</if>
            <if test="saleLeader != null">#{saleLeader},</if>
            <if test="phone != null">#{phone},</if>
            <if test="businessName != null">#{businessName},</if>
            <if test="licenseCode != null">#{licenseCode},</if>
            <if test="asMainBody != null">#{asMainBody},</if>
            <if test="ksUrl != null">#{ksUrl},</if>
            <if test="sponsoredContent != null">#{sponsoredContent},</if>
            <if test="registration != null">#{registration},</if>
            <if test="businessLicenseValidity != null">#{businessLicenseValidity},</if>
            <if test="copyrightValidity != null">#{copyrightValidity},</if>
            <if test="commitmentValidity != null">#{commitmentValidity},</if>
            <if test="businessLicenseUrl != null">#{businessLicenseUrl},</if>
            <if test="copyrightUrl != null">#{copyrightUrl},</if>
            <if test="commitmentUrl != null">#{commitmentUrl},</if>
            <if test="invoiceStatus != null">#{invoiceStatus},</if>
            <if test="createrId != null">#{createrId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouLiveCustomer" parameterType="com.ruixuan.live.entity.KuaishouLiveCustomer">
        update kuaishou_live_customer
        <trim prefix="SET" suffixOverrides=",">
            <if test="customerName != null">customer_name = #{customerName},</if>
            <if test="launchType != null">launch_type = #{launchType},</if>
            <if test="saleLeaderId != null">sale_leader_id = #{saleLeaderId},</if>
            <if test="saleLeader != null">sale_leader = #{saleLeader},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="businessName != null">business_name = #{businessName},</if>
            <if test="licenseCode != null">license_code = #{licenseCode},</if>
            <if test="asMainBody != null">as_main_body = #{asMainBody},</if>
            <if test="ksUrl != null">ks_url = #{ksUrl},</if>
            <if test="sponsoredContent != null">sponsored_content = #{sponsoredContent},</if>
            <if test="registration != null">registration = #{registration},</if>
            <if test="businessLicenseValidity != null">business_license_validity = #{businessLicenseValidity},</if>
            <if test="copyrightValidity != null">copyright_validity = #{copyrightValidity},</if>
            <if test="commitmentValidity != null">commitment_validity = #{commitmentValidity},</if>
            <if test="businessLicenseUrl != null">business_license_url = #{businessLicenseUrl},</if>
            <if test="copyrightUrl != null">copyright_url = #{copyrightUrl},</if>
            <if test="commitmentUrl != null">commitment_url = #{commitmentUrl},</if>
            <if test="invoiceStatus != null">invoice_status = #{invoiceStatus},</if>
            <if test="createrId != null">creater_id = #{createrId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where ks_id = #{ksId}
    </update>

    <delete id="deleteKuaishouLiveCustomerByKsId" parameterType="Long">
        delete
        from kuaishou_live_customer
        where ks_id = #{ksId}
    </delete>

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