<?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.PromotionCouponRuleMapper">

    <resultMap type="PromotionCouponRule" id="PromotionCouponRuleResult">
        <result property="id"    column="id"    />
        <result property="batchId"    column="batch_id"    />
        <result property="productId"    column="product_id"    />
        <result property="isMutex"    column="is_mutex"    />
        <result property="threshold"    column="threshold"    />
        <result property="amount"    column="amount"    />
        <result property="discountRate"    column="discount_rate"    />
        <result property="productName"    column="product_name"    />
        <result property="productImage"    column="product_image"    />
        <result property="productPrice"    column="product_price"    />
    </resultMap>

    <select id="selectRuleByBatchId" parameterType="Long" resultMap="PromotionCouponRuleResult">
        SELECT
            r.*,
            f.name AS product_name,
            f.image AS product_image,
            f.price AS product_price
        FROM promotion_coupon_rule r
        LEFT JOIN pos_food f ON r.product_id = f.id
        WHERE r.batch_id = #{batchId}
        LIMIT 1
    </select>

    <select id="selectRulesByBatchId" parameterType="Long" resultMap="PromotionCouponRuleResult">
        SELECT
            r.*,
            f.name AS product_name,
            f.image AS product_image,
            f.price AS product_price
        FROM promotion_coupon_rule r
        LEFT JOIN pos_food f ON r.product_id = f.id
        WHERE r.batch_id = #{batchId}
    </select>

</mapper>
