<?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="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 gsz.store_id, a.store_name, sum(gsz.spu_id), sum(sku_id)
from goblin_marketing_zhengzai as gsz
         inner join (select gsi.store_name, gsi.store_id
                     from goblin_marketing_zhengzai_relation as gmzr
                              left join goblin_store_info as gsi on gmzr.store_id = gsi.store_id
                     where del_tag = 0) as a on gsz.store_id = a.store_id
where gsz.self_market_id = #{marketId}
group by gsz.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>
