<?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="cn.com.xingxi.store.data.mapper.WxaStoreMerchantMapper">

    <select id="selectMercByMercId" parameterType="Long" resultType="MercDTO">
        SELECT m_merchant.*,m_merc_wxapp.*  FROM m_merchant
        INNER JOIN m_merc_wxapp ON m_merchant.mercId = m_merc_wxapp.mercId
        WHERE m_merchant.delFlag = '0'
          AND m_merchant.status = 'IN_COOPERATION'
          AND m_merc_wxapp.curFlag = '1'
          AND m_merc_wxapp.applymentState = 'FINISH'
          AND m_merchant.mercId = #{mercId}
    </select>


    <select id="selectMinMercId" resultType="Long">
        <![CDATA[
        SELECT MIN(m_merchant.mercId)
        FROM m_merchant
        INNER JOIN m_merc_wxapp ON m_merchant.mercId = m_merc_wxapp.mercId
        WHERE m_merchant.delFlag = '0'
          AND m_merchant.status = 'IN_COOPERATION'
          AND m_merc_wxapp.curFlag = '1'
          AND m_merc_wxapp.applymentState = 'FINISH'
          AND m_merchant.mercId <> 100
        ]]>
    </select>

    <select id="selectMercWxappByMercId" parameterType="Long" resultType="MercWxapp">
        SELECT m_merc_wxapp.*
        FROM m_merc_wxapp
        WHERE m_merc_wxapp.delFlag = '0'
          AND m_merc_wxapp.curFlag = '1'
          AND m_merc_wxapp.mercId = #{mercId}
        LIMIT 1
    </select>

    <select id="selectMercIdList" resultType="Long">
        <![CDATA[
        SELECT MIN(m_merchant.mercId)
        FROM m_merchant
        INNER JOIN m_merc_wxapp ON m_merchant.mercId = m_merc_wxapp.mercId
        WHERE m_merchant.delFlag = '0'
          AND m_merchant.status = 'IN_COOPERATION'
          AND m_merc_wxapp.curFlag = '1'
          AND m_merchant.mercId <> 100
        ]]>
    </select>

    <select id="selectRandOneMerc" resultType="MercDTO">
        SELECT m_merchant.mercId
        FROM m_merchant
        WHERE m_merchant.delFlag = '0'
          AND m_merchant.`status` = 'IN_COOPERATION'
        ORDER BY RAND()
        LIMIT 1
    </select>

</mapper>
