<?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="org.springblade.modules.mall.mapper.GoodsInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="goodsInfoResultMap" type="org.springblade.modules.mall.entity.GoodsInfo">
        <id column="id" property="id"/>
        <result column="goods_no" property="goodsNo"/>
        <result column="goods_name" property="goodsName"/>
        <result column="goods_cover" property="goodsCover"/>
        <result column="goods_lable" property="goodsLable"/>
        <result column="origin" property="origin"/>
        <result column="goods_category_id" property="goodsCategoryId"/>
        <result column="brand_id" property="brandId"/>
        <result column="is_sale" property="isSale"/>
        <result column="sale_time" property="saleTime"/>
        <result column="is_recom" property="isRecom"/>
        <result column="is_hot" property="isHot"/>
        <result column="is_new" property="isNew"/>
        <result column="is_free_shipping" property="isFreeShipping"/>
        <result column="free_price" property="freePrice"/>
        <result column="total_stock" property="totalStock"/>
        <result column="total_sales" property="totalSales"/>
        <result column="total_views" property="totalViews"/>
        <result column="unit" property="unit"/>
        <result column="business_type" property="businessType"/>
        <result column="third_id" property="thirdId"/>
        <result column="source" property="source"/>
        <result column="is_delete" property="isDelete"/>
        <result column="create_user_id" property="createUserId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user_id" property="updateUserId"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>


    <select id="selectGoodsInfoPage" resultType="org.springblade.modules.mall.vo.GoodsInfoVO">
        select g.*,v.name supplierName from t_goods_info g LEFT JOIN t_store v on g.supplier_id = v.id
        WHERE g.is_delete = 0
        <if test="@cn.hutool.core.util.StrUtil@isNotBlank(goodsInfo.goodsName)">
            and instr(g.goods_name, #{goodsInfo.goodsName}) > 0
        </if>
        <if test="goodsInfo.isSale != null">
            and g.is_sale = #{goodsInfo.isSale}
        </if>
        <if test="goodsInfo.auditStatus != null">
            and g.audit_status = #{goodsInfo.auditStatus}
        </if>
        <if test="goodsInfo.id != null">
            and g.id = #{goodsInfo.id}
        </if>
        <if test="goodsInfo.brandId != null">
            and g.brand_id = #{goodsInfo.brandId}
        </if>
        <if test="@cn.hutool.core.util.StrUtil@isNotBlank(goodsInfo.goodsCategoryId)">
            and instr(g.goods_category_id, #{goodsInfo.goodsCategoryId}) > 0
        </if>
        <if test="@cn.hutool.core.util.StrUtil@isNotBlank(goodsInfo.supplierName)">
            and instr(v.name, #{goodsInfo.supplierName}) > 0
        </if>
        <if test="@cn.hutool.core.util.ObjectUtil@isNotEmpty(goodsInfo.supplierId)">
            and g.supplier_id = #{goodsInfo.supplierId}
        </if>
    </select>

    <select id="activityGoods" resultType="org.springblade.modules.mall.entity.GoodsInfo">
        SELECT gi.* FROM biz_activities_goods ag JOIN biz_goods_info gi on ag.goods_info_id = gi.id
        WHERE gi.is_delete = 0 and gi.is_activity = 1 and gi.is_sale = 1 and ag.is_delete = 0
        <if test="@cn.hutool.core.util.StrUtil@isNotBlank(activityDate)">
            and ag.activity_date = #{activityDate}
        </if>
        ORDER BY gi.sort
    </select>

</mapper>
