<?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.gree.mall.miniapp.commonmapper.SecActivityStageMapper">
    <select id="queryStageCount" resultType="java.lang.Integer">
        SELECT count(*)
        FROM `sec_kill_stage` sks
        where sec_kill_id = #{secKillId}
          AND CASE
                  WHEN HOUR (
            now())>=10
          and HOUR (now())
         &lt; 20
            THEN sks.end_hour
            > HOUR (now())
          AND sks.start_hour &lt;= HOUR (now())
            ELSE sks.end_hour = 10
        END
    </select>

    <select id="queryStage" resultType="com.gree.mall.miniapp.plus.entity.SecKillStage">
        SELECT sks.*
        FROM `sec_kill_stage` sks
                 left join sec_kill_activity ska on ska.sec_kill_id = sks.sec_kill_id
        where sks.sec_kill_id = #{secKillId}
          and ska.status = 1
          and ska.del = 0
          and (now() between ska.start_time and ska.end_time)
          AND CASE
                  WHEN HOUR (
            now())>=10
          and HOUR (now())
         &lt;20
            THEN sks.end_hour
            > HOUR (now())
          AND sks.start_hour &lt;= HOUR (now())
            ELSE sks.end_hour = 10
        END
    </select>


    <select id="getSecKillSpecByGoodsSpecId" resultType="com.gree.mall.miniapp.plus.entity.SecKillActivitySpec">
        select b.*
        from sec_kill_activity a
                 join sec_kill_activity_spec b
                      on a.sec_kill_id = b.sec_kill_id
        where a.del = 0
          and now() BETWEEN a.start_time and a.end_time
          and b.goods_spec_id = #{goodsSpecId}
          and a.status = true
          and b.status = true
    </select>

    <select id="querySecGoods" resultType="com.gree.mall.miniapp.plus.entity.SecKillActivitySpec">
        select skas.*
        from sec_kill_activity_spec skas
                 LEFT JOIN
             goods_spec gsp on gsp.goods_spec_id = skas.goods_spec_id
                 LEFT JOIN
             goods gs on gsp.goods_id = skas.goods_id
        where skas.sec_kill_id = #{secKillId}
          and skas.status = 1
          and gs.del = 0
          and gs.status = 1
          and gsp.del = 0
        group by skas.goods_id
        ORDER BY skas.sort_num,skas.price
    </select>

    <select id="getSecKillActivitySpecByGoodId" resultType="com.gree.mall.miniapp.plus.entity.SecKillActivitySpec">
        SELECT skas.*
        from sec_kill_activity_spec skas
                 left JOIN sec_kill_activity ska on ska.sec_kill_id=skas.sec_kill_id
        WHERE
            skas.goods_id=#{goodId}
          and skas.status=TRUE
          and ska.company_wechat_id = #{companyWechatId}
          and ska.status=TRUE
          and ska.del=FALSE
          AND NOW() BETWEEN ska.start_time and ska.end_time
          Limit 1

    </select>


</mapper>