<?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.mingxue.mapper.CustomerFavoritesMapper">
    
    <resultMap type="CustomerFavorites" id="CustomerFavoritesResult">
        <result property="id"    column="id"    />
        <result property="customercode"    column="customerCode"    />
        <result property="type"    column="type"    />
        <result property="course"    column="course"    />
        <result property="refid"    column="refId"    />
        <result property="reftype"    column="refType"    />
        <result property="time"    column="time"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectCustomerFavoritesVo">
        select id, customerCode, type, course, refId, refType, time, status from b_customer_favorites
    </sql>

    <select id="selectCustomerFavoritesList" parameterType="CustomerFavorites" resultMap="CustomerFavoritesResult">
        <include refid="selectCustomerFavoritesVo"/>
        <where>  
            <if test="customercode != null  and customercode != ''"> and customerCode = #{customercode}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="course != null  and course != ''"> and course = #{course}</if>
            <if test="refid != null  and refid != ''"> and refId = #{refid}</if>
            <if test="reftype != null  and reftype != ''"> and refType = #{reftype}</if>
            <if test="time != null "> and time = #{time}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectCustomerFavoritesById" parameterType="Long" resultMap="CustomerFavoritesResult">
        <include refid="selectCustomerFavoritesVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCustomerFavorites" parameterType="CustomerFavorites" useGeneratedKeys="true" keyProperty="id">
        insert into b_customer_favorites
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="customercode != null">customerCode,</if>
            <if test="type != null">type,</if>
            <if test="course != null">course,</if>
            <if test="refid != null">refId,</if>
            <if test="reftype != null">refType,</if>
            <if test="time != null">time,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="customercode != null">#{customercode},</if>
            <if test="type != null">#{type},</if>
            <if test="course != null">#{course},</if>
            <if test="refid != null">#{refid},</if>
            <if test="reftype != null">#{reftype},</if>
            <if test="time != null">#{time},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateCustomerFavorites" parameterType="CustomerFavorites">
        update b_customer_favorites
        <trim prefix="SET" suffixOverrides=",">
            <if test="customercode != null">customerCode = #{customercode},</if>
            <if test="type != null">type = #{type},</if>
            <if test="course != null">course = #{course},</if>
            <if test="refid != null">refId = #{refid},</if>
            <if test="reftype != null">refType = #{reftype},</if>
            <if test="time != null">time = #{time},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustomerFavoritesById" parameterType="Long">
        delete from b_customer_favorites where id = #{id}
    </delete>

    <delete id="deleteCustomerFavoritesByIds" parameterType="String">
        delete from b_customer_favorites where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
    <select id="selectSubjects" parameterType="CustomerFavorites" resultMap="CustomerFavoritesResult">
        select distinct course from b_customer_favorites 
        where course is not null and course != ''
            <if test="customercode != null  and customercode != ''"> and customerCode = #{customercode}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="course != null  and course != ''"> and course = #{course}</if>
            <if test="refid != null  and refid != ''"> and refId = #{refid}</if>
            <if test="reftype != null  and reftype != ''"> and refType = #{reftype}</if>
            <if test="time != null "> and time = #{time}</if>
            <if test="status != null "> and status = #{status}</if>
    </select>
    
</mapper>