<?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.ruoyi.system.mapper.PosStoreNewebpayMapper">

    <!-- 门店蓝新支付开通管理列表：列名别名对齐 VO 属性，resultType 自动映射 -->
    <select id="selectNewebpayStoreList" parameterType="com.ruoyi.system.domain.vo.PosStoreNewebpayVo"
            resultType="com.ruoyi.system.domain.vo.PosStoreNewebpayVo">
        SELECT
            s.id              AS storeId,
            s.pos_name        AS posName,
            s.user_id         AS userId,
            u.user_name       AS userName,
            s.is_stall        AS isStall,
            s.is_night_market AS isNightMarket,
            s.night_market_id AS nightMarketId,
            IFNULL(n.newebpay_status, 0) AS newebpayStatus,
            IFNULL(n.is_enabled, 1)      AS isEnabled,
            CASE WHEN n.merchant_id IS NULL OR n.merchant_id = '' THEN 0 ELSE 1 END AS hasMerchantId,
            n.enabled_payments AS enabledPayments,
            n.apply_time       AS applyTime,
            n.approved_time    AS approvedTime,
            n.last_verify_result AS lastVerifyResult
        FROM pos_store s
        LEFT JOIN pos_store_newebpay n ON n.store_id = s.id
        LEFT JOIN info_user u ON u.user_id = s.user_id
        <where>
            s.del_flag = '0'
            <if test="isStall != null"> AND s.is_stall = #{isStall} </if>
            <if test="posName != null and posName != ''"> AND s.pos_name LIKE concat('%', #{posName}, '%') </if>
            <if test="newebpayStatus != null"> AND IFNULL(n.newebpay_status, 0) = #{newebpayStatus} </if>
            <if test="quickFilter != null and quickFilter == 'needApply'">
                AND IFNULL(n.newebpay_status, 0) = 0
            </if>
            <if test="quickFilter != null and quickFilter == 'notEnabled'">
                AND IFNULL(n.newebpay_status, 0) IN (0, 1)
            </if>
        </where>
        ORDER BY s.id DESC
    </select>

    <!-- 门店蓝新详情 -->
    <select id="selectNewebpayStoreDetail" parameterType="Long"
            resultType="com.ruoyi.system.domain.vo.PosStoreNewebpayVo">
        SELECT
            s.id              AS storeId,
            s.pos_name        AS posName,
            s.user_id         AS userId,
            u.user_name       AS userName,
            s.is_stall        AS isStall,
            s.is_night_market AS isNightMarket,
            s.night_market_id AS nightMarketId,
            IFNULL(n.newebpay_status, 0) AS newebpayStatus,
            IFNULL(n.is_enabled, 1)      AS isEnabled,
            CASE WHEN n.merchant_id IS NULL OR n.merchant_id = '' THEN 0 ELSE 1 END AS hasMerchantId,
            n.merchant_id      AS merchantId,
            n.hash_key         AS hashKey,
            n.hash_iv          AS hashIv,
            n.enabled_payments AS enabledPayments,
            n.apply_time       AS applyTime,
            n.approved_time    AS approvedTime,
            n.last_verify_result AS lastVerifyResult,
            n.remark           AS remark
        FROM pos_store s
        LEFT JOIN pos_store_newebpay n ON n.store_id = s.id
        LEFT JOIN info_user u ON u.user_id = s.user_id
        WHERE s.id = #{storeId}
    </select>

</mapper>
