<?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.liquidnet.service.goblin.mapper.GoblinSelfMarketingMapper">

    <resultMap id="goblinZhengzaiStoreListDtoResult" type="com.liquidnet.service.goblin.dto.GoblinZhengzaiStoreListDto">
        <result column="store_id" property="storeId"/>
        <result column="store_name" property="storeName"/>
        <result column="show_time" property="showTime"/>
        <result column="spu_count" property="spuCount"/>
        <result column="sku_count" property="skuCount"/>
    </resultMap>

    <resultMap id="goblinZhengzaiStoreDetailsDtoResult"
               type="com.liquidnet.service.goblin.dto.GoblinZhengzaiStoreDetailsDto">
        <result column="sku_id" property="skuId"/>
        <result column="spec_name" property="specName"/>
        <result column="spec_vname" property="specVname"/>
        <result column="price" property="price"/>
        <result column="stock" property="stock"/>
        <result column="sku_stock" property="skuStock"/>
        <result column="price_marketing" property="priceMarketing"/>
        <result column="stock_marketing" property="stockMarketing"/>
        <result column="buy_limit" property="buyLimit"/>
        <result column="buy_type" property="buyType"/>
    </resultMap>


    <select id="getZhengzaiStoreList" resultMap="goblinZhengzaiStoreListDtoResult">
select b.store_id,c.store_name,b.show_time,IFNull(count(d.spu_id),0) as 'spu_count',IFNull(count(d.sku_id),0) as 'sku_count' from goblin_self_marketing as a
inner join goblin_marketing_zhengzai_relation as b on a.self_market_id = b.self_market_id
inner join goblin_store_info as c on c.store_id= b.store_id
left join goblin_marketing_zhengzai as d on d.self_market_id = b.self_market_id
where a.self_market_id = #{marketId}
GROUP BY b.store_id
    </select>

    <select id="getZhengzaiStoreDetails" resultMap="goblinZhengzaiStoreDetailsDtoResult">
    select ggsku.sku_id,price,spec_name, spec_vname, ggsku.stock, ggsku.sku_stock from goblin_goods_sku ggsku
         inner join goblin_goods_sku_spec_value ggssv on ggsku.sku_id = ggssv.sku_id
         left join (select spec_name, spec_vname, ggs.spec_id
                     from goblin_goods_spec ggs
                              inner join goblin_goods_spec_value ggsv on ggsv.spec_id = ggs.spec_id) as a
                    on a.spec_id = ggssv.spec_id where ggsku.sku_id in (
                    select sku_id from goblin_marketing_zhengzai where self_market_id = #{marketId} and store_id = #{storeId}
                    )
     </select>
</mapper>
