<?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.IntegralProductMapper">
    
    <resultMap type="IntegralProduct" id="IntegralProductResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="image"    column="image"    />
        <result property="images"    column="images"    />
        <result property="price"    column="price"    />
        <result property="num"    column="num"    />
        <result property="sort"    column="sort"    />
        <result property="sales"    column="sales"    />
        <result property="stock"    column="stock"    />
        <result property="status"    column="status"    />
        <result property="tags"    column="tags"    />
        <result property="cateId"    column="cate_id"    />
        <result property="skuType"    column="sku_type"    />
        <result property="sku"    column="sku"    />
        <result property="contetnt"    column="contetnt"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectIntegralProductVo">
        select id, title, image, images, price, num, sort, sales, stock, status, tags, cate_id, sku_type, sku, contetnt, created_at, updated_at from integral_product
    </sql>

    <select id="selectIntegralProductList" parameterType="IntegralProduct" resultMap="IntegralProductResult">
        <include refid="selectIntegralProductVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="images != null  and images != ''"> and images = #{images}</if>
            <!-- 市场价范围 -->
            <if test="minPrice != null and maxPrice == null">
                AND price >= #{minPrice}
            </if>


            <!-- 积分范围 -->
            <if test="minNum != null and maxNum != null">
                AND num BETWEEN #{minNum} AND #{maxNum}
            </if>

            <!-- 积分范围 -->
            <if test="beginTime != null and endTime != null">
                AND created_at BETWEEN #{beginTime} AND #{endTime}
            </if>

            <if test="sort != null "> and sort = #{sort}</if>
            <if test="sales != null "> and sales = #{sales}</if>
            <if test="stock != null "> and stock = #{stock}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="tags != null  and tags != ''"> and tags = #{tags}</if>
            <if test="cateId != null "> and cate_id = #{cateId}</if>
            <if test="skuType != null "> and sku_type = #{skuType}</if>
            <if test="sku != null  and sku != ''"> and sku = #{sku}</if>
            <if test="contetnt != null  and contetnt != ''"> and contetnt = #{contetnt}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectIntegralProductById" parameterType="Long" resultMap="IntegralProductResult">
        <include refid="selectIntegralProductVo"/>
        where id = #{id}
    </select>

    <insert id="insertIntegralProduct" parameterType="IntegralProduct" useGeneratedKeys="true" keyProperty="id">
        insert into integral_product
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="image != null">image,</if>
            <if test="images != null">images,</if>
            <if test="price != null">price,</if>
            <if test="num != null">num,</if>
            <if test="sort != null">sort,</if>
            <if test="sales != null">sales,</if>
            <if test="stock != null">stock,</if>
            <if test="status != null">status,</if>
            <if test="tags != null and tags != ''">tags,</if>
            <if test="cateId != null">cate_id,</if>
            <if test="skuType != null">sku_type,</if>
            <if test="sku != null and sku != ''">sku,</if>
            <if test="contetnt != null">contetnt,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="image != null">#{image},</if>
            <if test="images != null">#{images},</if>
            <if test="price != null">#{price},</if>
            <if test="num != null">#{num},</if>
            <if test="sort != null">#{sort},</if>
            <if test="sales != null">#{sales},</if>
            <if test="stock != null">#{stock},</if>
            <if test="status != null">#{status},</if>
            <if test="tags != null and tags != ''">#{tags},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="skuType != null">#{skuType},</if>
            <if test="sku != null and sku != ''">#{sku},</if>
            <if test="contetnt != null">#{contetnt},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateIntegralProduct" parameterType="IntegralProduct">
        update integral_product
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="image != null">image = #{image},</if>
            <if test="images != null">images = #{images},</if>
            <if test="price != null">price = #{price},</if>
            <if test="num != null">num = #{num},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="sales != null">sales = #{sales},</if>
            <if test="stock != null">stock = #{stock},</if>
            <if test="status != null">status = #{status},</if>
            <if test="tags != null and tags != ''">tags = #{tags},</if>
            <if test="cateId != null">cate_id = #{cateId},</if>
            <if test="skuType != null">sku_type = #{skuType},</if>
            <if test="sku != null and sku != ''">sku = #{sku},</if>
            <if test="contetnt != null">contetnt = #{contetnt},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIntegralProductById" parameterType="Long">
        delete from integral_product where id = #{id}
    </delete>

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