<?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.cyksj.mapper.GoodsDonSkuMapper">

    <select id="selectAIMonthSkuIds" resultType="java.lang.Long">
        select id from goods_don_sku where goods_id in
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and `months` = 1
    </select>

    <select id="getSpecificSkuIdsByGoodsIds" resultType="java.lang.Long">
        select id from goods_don_sku where goods_id in
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and `months` = #{months}
    </select>

    <select id="getSpecificSkuIdsByGoodsId" resultType="java.lang.Long">
        select id
        from goods_don_sku
        where goods_id = #{goodsId}
          and num = #{num}
          and `months` = #{months}
    </select>

    <select id="selectSkuShops" resultType="com.cyksj.model.entity.YhShopGoodsSku">
        select id as skuId,goods_id,price from goods_don_sku where goods_id in
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        and status = true
    </select>

    <select id="selectSingleSkuIdsByGoodsId" resultType="java.lang.Long">
        select id from goods_don_sku where goods_id = #{goodsId} and num = 1
    </select>

    <select id="checkAndReturnMinPriceUserOwnsSku" resultType="com.cyksj.model.entity.GoodsDonSku">
        select id,price,months,days
        from goods_don_sku
        where goods_id = #{goodsId}
        and status is true
        and (user_owns is null
        <if test="dsUserId != 0">
            or JSON_CONTAINS(user_owns, '${dsUserId}')
        </if>) order by price limit 1
    </select>

    <select id="selectRenewOriSku" resultType="com.cyksj.model.dto.OriSkuDto">
        select *
        from goods_don_sku
        where id = #{skuId}
        limit 1
    </select>

    <select id="selectExchangeTitle" resultType="java.lang.String">
        select GROUP_CONCAT(g.title, ifnull(sku.spec_val,''),cast(sku.price/100 as decimal(10,2))) from goods_don_sku sku inner join goods_don g on g.id = sku.goods_id
        where sku.id in
        <foreach collection="ids" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectGIdsBySkuIds" resultType="java.lang.Long">
        select distinct sku.goods_id from goods_don_sku sku
        where sku.id in
        <foreach collection="ids" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="selectExchangeTitleSkus" resultType="com.cyksj.model.views.GoodsDonSkuDetailView">
        select g.id as goods_id,g.title,sku.id as sku_id,sku.spec_val,g.logo from goods_don_sku sku inner join goods_don g on g.id = sku.goods_id
        where sku.id in
        <foreach collection="ids" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>