<?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.iotechn.unimall.data.mapper.CollectMapper">


    <select id="getCollectAll" resultType="com.iotechn.unimall.data.dto.CollectDTO">
     SELECT
            c.id as id,
            c.user_id as userId,
            c.gmt_create as gmtUpdate,
            c.gmt_update as gmtCreate,
            c.spu_id as spuId,
            s.original_price as originalPrice,
            s.price as price,
            s.vip_price as vipPrice,
            s.title as title,
            s.sales as sales,
            s.img as img,
            s.description as description,
            s.unit as unit,
            s.status as status
    from
            unimall_collect as c,
            unimall_spu as s
    where
            c.user_id = #{userId}
            and c.spu_id = s.id
    limit
            #{offset},#{size}
    </select>

    <select id="getCollectById" resultType="com.iotechn.unimall.data.dto.CollectDTO">
     SELECT
            c.id as id,
            c.user_id as userId,
            c.gmt_create as gmtCreate,
            c.gmt_update as gmtUpdate,
            c.spu_id as spuId,
            s.original_price as originalPrice,
            s.price as price,
            s.vip_price as vipPrice,
            s.title as title,
            s.sales as sales,
            s.img as img,
            s.description as description,
            s.unit as unit,
            s.status as status
    from
            unimall_collect as c,
            unimall_spu as s
    where
            c.user_id = #{userId}
            and c.spu_id = s.id
            and c.id = #{collectId}
            <if test="spuId != null">
                and c.spu_id = #{spuId}
            </if>
    </select>

    <select id="getUserCollectSpuIds" resultType="java.lang.String">
      SELECT spu_id FROM  unimall_collect WHERE user_id = #{userId}
    </select>

</mapper>