<?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.ai.mapper.AiCustomerMapper">
    
    <resultMap type="AiCustomer" id="AiCustomerResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="userName"    column="user_name"    />
        <result property="userCode"    column="user_code"    />
        <result property="userEmail"    column="user_email"    />
        <result property="rebateAmount"    column="rebate_amount"    />
        <result property="serviceUrl"    column="service_url"    />
        <result property="logoUrl"    column="logo_url"    />
        <result property="bannerUrl"    column="banner_url"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectAiCustomerVo">
        select id, del_flag, create_by, create_time, update_by, update_time, remark, user_name, user_code, user_email, rebate_amount, service_url, logo_url, banner_url, status from ai_customer
    </sql>

    <select id="selectAiCustomerList" parameterType="AiCustomer" resultMap="AiCustomerResult">
        <include refid="selectAiCustomerVo"/>
        <where>  
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userCode != null  and userCode != ''"> and user_code = #{userCode}</if>
            <if test="userEmail != null  and userEmail != ''"> and user_email = #{userEmail}</if>
            <if test="rebateAmount != null  and rebateAmount != ''"> and rebate_amount = #{rebateAmount}</if>
            <if test="serviceUrl != null  and serviceUrl != ''"> and service_url = #{serviceUrl}</if>
            <if test="logoUrl != null  and logoUrl != ''"> and logo_url = #{logoUrl}</if>
            <if test="bannerUrl != null  and bannerUrl != ''"> and banner_url = #{bannerUrl}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectAiCustomerById" parameterType="Long" resultMap="AiCustomerResult">
        <include refid="selectAiCustomerVo"/>
        where id = #{id}
    </select>

    <insert id="insertAiCustomer" parameterType="AiCustomer" useGeneratedKeys="true" keyProperty="id">
        insert into ai_customer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">del_flag,</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>
            <if test="remark != null">remark,</if>
            <if test="userName != null">user_name,</if>
            <if test="userCode != null">user_code,</if>
            <if test="userEmail != null">user_email,</if>
            <if test="rebateAmount != null">rebate_amount,</if>
            <if test="serviceUrl != null">service_url,</if>
            <if test="logoUrl != null">logo_url,</if>
            <if test="bannerUrl != null">banner_url,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">#{delFlag},</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>
            <if test="remark != null">#{remark},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userCode != null">#{userCode},</if>
            <if test="userEmail != null">#{userEmail},</if>
            <if test="rebateAmount != null">#{rebateAmount},</if>
            <if test="serviceUrl != null">#{serviceUrl},</if>
            <if test="logoUrl != null">#{logoUrl},</if>
            <if test="bannerUrl != null">#{bannerUrl},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateAiCustomer" parameterType="AiCustomer">
        update ai_customer
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</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>
            <if test="remark != null">remark = #{remark},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userCode != null">user_code = #{userCode},</if>
            <if test="userEmail != null">user_email = #{userEmail},</if>
            <if test="rebateAmount != null">rebate_amount = #{rebateAmount},</if>
            <if test="serviceUrl != null">service_url = #{serviceUrl},</if>
            <if test="logoUrl != null">logo_url = #{logoUrl},</if>
            <if test="bannerUrl != null">banner_url = #{bannerUrl},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAiCustomerById" parameterType="Long">
        delete from ai_customer where id = #{id}
    </delete>

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