<?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.mall.coupon.mapper.CouponSpuRelationMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.mall.coupon.domain.entity.CouponSpuRelation">
            <id column="id" property="id"/>
            <id column="coupon_id" property="couponId"/>
            <id column="spu_id" property="spuId"/>
            <id column="spu_name" property="spuName"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,coupon_id,spu_id,spu_name
    </sql>

    <!-- 分页查询优惠券与产品关联内容 -->
    <select id="selectListByPage" resultType="com.mall.coupon.domain.vo.CouponSpuRelationVo">
        select
        <include refid="Base_Column_List"/>
        from sms_coupon_spu_relation
        <where>
                <if test="dto.id != null and dto.id != ''">
                    and id like CONCAT('%',#{dto.id},'%')
                </if>
                <if test="dto.couponId != null and dto.couponId != ''">
                    and coupon_id like CONCAT('%',#{dto.couponId},'%')
                </if>
                <if test="dto.spuId != null and dto.spuId != ''">
                    and spu_id like CONCAT('%',#{dto.spuId},'%')
                </if>
                <if test="dto.spuName != null and dto.spuName != ''">
                    and spu_name like CONCAT('%',#{dto.spuName},'%')
                </if>
        </where>
    </select>

</mapper>
