<?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.gxwebsoft.shop.mapper.GoodsMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,
        b.merchant_name,b.merchant_code,
        c.title as categoryName,c.parent_id,c.category_id
        FROM shop_goods a
        LEFT JOIN shop_merchant b ON a.merchant_code = b.merchant_code
        LEFT JOIN shop_category c ON a.category_id = c.category_id
        <where>
            <if test="param.goodsId != null">
                AND a.goods_id = #{param.goodsId}
            </if>
            <if test="param.goodsName != null">
                AND a.goods_name LIKE CONCAT('%', #{param.goodsName}, '%')
            </if>
            <if test="param.goodsCode != null">
                AND a.goods_code LIKE CONCAT('%', #{param.goodsCode}, '%')
            </if>
            <if test="param.goodsType != null">
                AND a.goods_type = #{param.goodsType}
            </if>
            <if test="param.categoryId != null">
                AND a.category_id = #{param.categoryId}
            </if>
            <if test="param.image != null">
                AND a.image LIKE CONCAT('%', #{param.image}, '%')
            </if>
            <if test="param.files != null">
                AND a.files LIKE CONCAT('%', #{param.files}, '%')
            </if>
            <if test="param.videoUrl != null">
                AND a.video_url LIKE CONCAT('%', #{param.videoUrl}, '%')
            </if>
            <if test="param.sellingPoint != null">
                AND a.selling_point LIKE CONCAT('%', #{param.sellingPoint}, '%')
            </if>
            <if test="param.specType != null">
                AND a.spec_type = #{param.specType}
            </if>
            <if test="param.goodsPriceMin != null">
                AND a.goods_price_min = #{param.goodsPriceMin}
            </if>
            <if test="param.goodsPriceMax != null">
                AND a.goods_price_max = #{param.goodsPriceMax}
            </if>
            <if test="param.linePriceMin != null">
                AND a.line_price_min = #{param.linePriceMin}
            </if>
            <if test="param.linePriceMax != null">
                AND a.line_price_max = #{param.linePriceMax}
            </if>
            <if test="param.stockTotal != null">
                AND a.stock_total = #{param.stockTotal}
            </if>
            <if test="param.deductStockType != null">
                AND a.deduct_stock_type = #{param.deductStockType}
            </if>
            <if test="param.content != null">
                AND a.content LIKE CONCAT('%', #{param.content}, '%')
            </if>
            <if test="param.salesInitial != null">
                AND a.sales_initial = #{param.salesInitial}
            </if>
            <if test="param.salesActual != null">
                AND a.sales_actual = #{param.salesActual}
            </if>
            <if test="param.deliveryId != null">
                AND a.delivery_id = #{param.deliveryId}
            </if>
            <if test="param.isPointsGift != null">
                AND a.is_points_gift = #{param.isPointsGift}
            </if>
            <if test="param.isPointsDiscount != null">
                AND a.is_points_discount = #{param.isPointsDiscount}
            </if>
            <if test="param.isAlonePointsDiscount != null">
                AND a.is_alone_points_discount = #{param.isAlonePointsDiscount}
            </if>
            <if test="param.pointsDiscountConfig != null">
                AND a.points_discount_config LIKE CONCAT('%', #{param.pointsDiscountConfig}, '%')
            </if>
            <if test="param.isEnableGrade != null">
                AND a.is_enable_grade = #{param.isEnableGrade}
            </if>
            <if test="param.isAloneGrade != null">
                AND a.is_alone_grade = #{param.isAloneGrade}
            </if>
            <if test="param.aloneGradeEquity != null">
                AND a.alone_grade_equity LIKE CONCAT('%', #{param.aloneGradeEquity}, '%')
            </if>
            <if test="param.isHot != null">
                AND a.is_hot = #{param.isHot}
            </if>
            <if test="param.unit != null">
                AND a.unit LIKE CONCAT('%', #{param.unit}, '%')
            </if>
            <if test="param.attribute != null">
                AND a.attribute = #{param.attribute}
            </if>
            <if test="param.isIndDealer != null">
                AND a.is_ind_dealer = #{param.isIndDealer}
            </if>
            <if test="param.dealerMoneyType != null">
                AND a.dealer_money_type = #{param.dealerMoneyType}
            </if>
            <if test="param.firstMoney != null">
                AND a.first_money = #{param.firstMoney}
            </if>
            <if test="param.secondMoney != null">
                AND a.second_money = #{param.secondMoney}
            </if>
            <if test="param.thirdMoney != null">
                AND a.third_money = #{param.thirdMoney}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.merchantCode != null">
              AND a.merchant_code = #{param.merchantCode}
            </if>
            <if test="param.merchantName != null">
              AND b.merchant_name = #{param.merchantName}
            </if>
            <if test="param.period != null">
              AND a.period = #{param.period}
            </if>
            <if test="param.gear != null">
              AND a.gear = #{param.gear}
            </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.shop.entity.Goods">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.shop.entity.Goods">
        <include refid="selectSql"></include>
    </select>

</mapper>
