<?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.system.mapper.MarketStockMapper">
    
    <resultMap type="MarketStock" id="MarketStockResult">
        <result property="channel"    column="channel"    />
        <result property="parentCategory"    column="parent_category"    />
        <result property="sonCategory"    column="son_category"    />
        <result property="time"    column="time"    />
        <result property="amount"    column="amount"    />
        <result property="searchHeat"    column="search_heat"    />
        <result property="searchPopularity"    column="search_popularity"    />
        <result property="purchasePopularity"    column="purchase_popularity"    />
        <result property="purchaseHeat"    column="purchase_heat"    />
        <result property="collectionHeat"    column="collection_heat"    />
        <result property="browsingHeat"    column="browsing_heat"    />
        <result property="visitorPopularity"    column="visitor_popularity"    />
        <result property="collectionPopularity"    column="collection_popularity"    />
        <result property="customerBaseIndex"    column="customer_base_index"    />
        <result property="id"    column="ID"    />
    </resultMap>

    <sql id="selectMarketStockVo">
        select channel, parent_category, son_category, time, amount, search_heat, search_popularity, purchase_popularity, purchase_heat, collection_heat, browsing_heat, visitor_popularity, collection_popularity, customer_base_index, ID from market_stock
    </sql>

    <select id="selectMarketStockList" parameterType="MarketStock" resultMap="MarketStockResult">
        <include refid="selectMarketStockVo"/>
        <where>  
            <if test="channel != null  and channel != ''"> and channel = #{channel}</if>
            <if test="parentCategory != null  and parentCategory != ''"> and parent_category = #{parentCategory}</if>
            <if test="sonCategory != null  and sonCategory != ''"> and son_category = #{sonCategory}</if>
            <if test="time != null  and time != ''"> and time = #{time}</if>
        </where>
    </select>
    
    <select id="selectMarketStockById" parameterType="Integer" resultMap="MarketStockResult">
        <include refid="selectMarketStockVo"/>
        where ID = #{id}
    </select>
        
    <insert id="insertMarketStock" parameterType="MarketStock" useGeneratedKeys="true" keyProperty="id">
        insert into market_stock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="channel != null">channel,</if>
            <if test="parentCategory != null">parent_category,</if>
            <if test="sonCategory != null">son_category,</if>
            <if test="time != null">time,</if>
            <if test="amount != null">amount,</if>
            <if test="searchHeat != null">search_heat,</if>
            <if test="searchPopularity != null">search_popularity,</if>
            <if test="purchasePopularity != null">purchase_popularity,</if>
            <if test="purchaseHeat != null">purchase_heat,</if>
            <if test="collectionHeat != null">collection_heat,</if>
            <if test="browsingHeat != null">browsing_heat,</if>
            <if test="visitorPopularity != null">visitor_popularity,</if>
            <if test="collectionPopularity != null">collection_popularity,</if>
            <if test="customerBaseIndex != null">customer_base_index,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="channel != null">#{channel},</if>
            <if test="parentCategory != null">#{parentCategory},</if>
            <if test="sonCategory != null">#{sonCategory},</if>
            <if test="time != null">#{time},</if>
            <if test="amount != null">#{amount},</if>
            <if test="searchHeat != null">#{searchHeat},</if>
            <if test="searchPopularity != null">#{searchPopularity},</if>
            <if test="purchasePopularity != null">#{purchasePopularity},</if>
            <if test="purchaseHeat != null">#{purchaseHeat},</if>
            <if test="collectionHeat != null">#{collectionHeat},</if>
            <if test="browsingHeat != null">#{browsingHeat},</if>
            <if test="visitorPopularity != null">#{visitorPopularity},</if>
            <if test="collectionPopularity != null">#{collectionPopularity},</if>
            <if test="customerBaseIndex != null">#{customerBaseIndex},</if>
         </trim>
    </insert>

    <update id="updateMarketStock" parameterType="MarketStock">
        update market_stock
        <trim prefix="SET" suffixOverrides=",">
            <if test="channel != null">channel = #{channel},</if>
            <if test="parentCategory != null">parent_category = #{parentCategory},</if>
            <if test="sonCategory != null">son_category = #{sonCategory},</if>
            <if test="time != null">time = #{time},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="searchHeat != null">search_heat = #{searchHeat},</if>
            <if test="searchPopularity != null">search_popularity = #{searchPopularity},</if>
            <if test="purchasePopularity != null">purchase_popularity = #{purchasePopularity},</if>
            <if test="purchaseHeat != null">purchase_heat = #{purchaseHeat},</if>
            <if test="collectionHeat != null">collection_heat = #{collectionHeat},</if>
            <if test="browsingHeat != null">browsing_heat = #{browsingHeat},</if>
            <if test="visitorPopularity != null">visitor_popularity = #{visitorPopularity},</if>
            <if test="collectionPopularity != null">collection_popularity = #{collectionPopularity},</if>
            <if test="customerBaseIndex != null">customer_base_index = #{customerBaseIndex},</if>
        </trim>
        where ID = #{id}
    </update>

    <delete id="deleteMarketStockById" parameterType="Integer">
        delete from market_stock where ID = #{id}
    </delete>

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