<iftest="query.belong != null"> and (`goods_sku`.`belong` = #{query.belong} or goods_sku.special_flag=1) </if>
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 1">
and `goods_sku`.`special_flag` = 1
and `goods_sku`.id = goods_spu.special_sku_id
</if>
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 0">
and `goods_sku`.`special_flag` = 0
</if>
<iftest="query.orderFlag != null"> and `goods_sku`.`order_flag` = #{query.orderFlag}</if>
<iftest="query.keyword != null and query.keyword != '' ">
and (
`goods_spu`.`name` like concat('%', #{query.keyword},'%') or
`goods_spu`.`spu_code` like concat('%', #{query.keyword},'%') or
`goods_sku`.`sku_code` like concat('%', #{query.keyword},'%') or
`goods_sku`.`sku_name` like concat('%', #{query.keyword},'%')
)
</if>
</sql>
<sqlid="spuWherePart">
and `goods_spu`.`del_flag` = 0
<iftest="query.id != null"> and `goods_spu`.`id` = #{query.id}</if>
<iftest="query.spuCode != null and query.spuCode != ''"> and `goods_spu`.`spu_code` like concat('%', #{query.spuCode},'%')</if>
<iftest="query.name != null and query.name != ''"> and `goods_spu`.`name` like concat('%', #{query.name},'%') </if>
<iftest="query.categoryFirst != null"> and `goods_spu`.`category_first` = #{query.categoryFirst}</if>
<iftest="query.categorySecond != null"> and `goods_spu`.`category_second` = #{query.categorySecond}</if>
<iftest="query.categoryThird != null"> and `goods_spu`.`category_third` = #{query.categoryThird}</if>
<iftest="query.cateFirstLabel != null and query.cateFirstLabel != ''"> and `cate1`.`name` like concat('%',#{query.cateFirstLabel},'%') </if>
<iftest="query.cateSecondLabel != null and query.cateSecondLabel != ''"> and `cate2`.`name` like concat('%',#{query.cateSecondLabel},'%') </if>
<iftest="query.cateThirdLabel != null and query.cateThirdLabel != ''"> and `cate3`.`name` like concat('%',#{query.cateThirdLabel},'%') </if>
<iftest="query.categoryLast != null"> and `goods_spu`.`category_last` = #{query.categoryLast}</if>
<iftest="query.shelf != null and query.shelf != ''"> and `goods_spu`.`shelf` = #{query.shelf}</if>
<iftest="query.sort != null"> and `goods_spu`.`sort` = #{query.sort}</if>
<iftest="query.saleNum != null"> and `goods_spu`.`sale_num` = #{query.saleNum}</if>
<iftest="query.tasteValue != null and query.tasteValue != ''"> and `goods_spu`.`taste_value` like concat('%',#{query.tasteValue},'%') </if>
<iftest="query.createTime != null"> and `goods_spu`.`create_time` = #{query.createTime}</if>
<iftest="query.updateTime != null"> and `goods_spu`.`update_time` = #{query.updateTime}</if>
<iftest="query.createBy != null and query.createBy != ''"> and `goods_spu`.`create_by` = #{query.createBy}</if>
<iftest="query.updateBy != null and query.updateBy != ''"> and `goods_spu`.`update_by` = #{query.updateBy}</if>
<iftest="query.tenantId != null and query.tenantId != ''"> and `goods_spu`.`tenant_id` = #{query.tenantId}</if>
<iftest="query.delFlag != null and query.delFlag != ''"> and `goods_spu`.`del_flag` = #{query.delFlag}</if>
<!--<if test="query.selectSpecialFlag != null and query.selectSpecialFlag == 1">
and `goods_spu`.`special_sku_id` is not null and `goods_spu`.`special_sku_id` != '0'
</if>
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 0">
and (`goods_spu`.`special_sku_id` is null or `goods_spu`.`special_sku_id` = '0')
</if>-->
<iftest="query.searchValue != null and query.searchValue != ''"> and (`goods_spu`.`name` like concat('%',#{query.searchValue},'%') or `goods_spu`.`goods_spu` like concat('%',#{query.searchValue},'%')) </if>
<iftest="query.selectIds!=null and query.selectIds.size > 0">
LEFT JOIN `goods_category` `cate2` ON `cate2`.`id` = `goods_spu`.`category_second`
LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third`
<where>
and `goods_spu`.`del_flag` = 0
<iftest="query.id != null"> and `goods_spu`.`id` = #{query.id}</if>
<iftest="query.spuCode != null and query.spuCode != ''"> and `goods_spu`.`spu_code` like concat('%', #{query.spuCode},'%')</if>
<iftest="query.name != null and query.name != ''"> and `goods_spu`.`name` like concat('%', #{query.name},'%') </if>
<iftest="query.categoryFirst != null"> and `goods_spu`.`category_first` = #{query.categoryFirst}</if>
<iftest="query.categorySecond != null"> and `goods_spu`.`category_second` = #{query.categorySecond}</if>
<iftest="query.categoryThird != null"> and `goods_spu`.`category_third` = #{query.categoryThird}</if>
<iftest="query.cateFirstLabel != null and query.cateFirstLabel != ''"> and `cate1`.`name` like concat('%',#{query.cateFirstLabel},'%') </if>
<iftest="query.cateSecondLabel != null and query.cateSecondLabel != ''"> and `cate2`.`name` like concat('%',#{query.cateSecondLabel},'%') </if>
<iftest="query.cateThirdLabel != null and query.cateThirdLabel != ''"> and `cate3`.`name` like concat('%',#{query.cateThirdLabel},'%') </if>
<iftest="query.categoryLast != null"> and `goods_spu`.`category_last` = #{query.categoryLast}</if>
<iftest="query.shelf != null and query.shelf != ''"> and `goods_spu`.`shelf` = #{query.shelf}</if>
<iftest="query.sort != null"> and `goods_spu`.`sort` = #{query.sort}</if>
<iftest="query.saleNum != null"> and `goods_spu`.`sale_num` = #{query.saleNum}</if>
<iftest="query.belong != null"> and `goods_spu`.`belong` = #{query.belong}</if>
<iftest="query.tasteValue != null and query.tasteValue != ''"> and `goods_spu`.`taste_value` like concat('%',#{query.tasteValue},'%') </if>
<iftest="query.createTime != null"> and `goods_spu`.`create_time` = #{query.createTime}</if>
<iftest="query.updateTime != null"> and `goods_spu`.`update_time` = #{query.updateTime}</if>
<iftest="query.createBy != null and query.createBy != ''"> and `goods_spu`.`create_by` = #{query.createBy}</if>
<iftest="query.updateBy != null and query.updateBy != ''"> and `goods_spu`.`update_by` = #{query.updateBy}</if>
<iftest="query.tenantId != null and query.tenantId != ''"> and `goods_spu`.`tenant_id` = #{query.tenantId}</if>
<iftest="query.delFlag != null and query.delFlag != ''"> and `goods_spu`.`del_flag` = #{query.delFlag}</if>
<iftest="query.orderFlag != null"> and `goods_spu`.`order_flag` = #{query.orderFlag}</if>
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 1">
and `goods_spu`.`special_sku_id` is not null and `goods_spu`.`special_sku_id` != '0'
</if>
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 0">
and (`goods_spu`.`special_sku_id` is null or `goods_spu`.`special_sku_id` = '0')
</if>
<iftest="query.searchValue != null and query.searchValue != ''"> and (`goods_spu`.`name` like concat('%',#{query.searchValue},'%') or `goods_spu`.`goods_spu` like concat('%',#{query.searchValue},'%')) </if>
<iftest="query.selectIds!=null and query.selectIds.size > 0">
(SELECT sku.*,ROW_NUMBER() OVER(PARTITION BY sku.spu_id ORDER BY sku.belong_sort) AS rn FROM goods_sku sku WHERE sku.order_flag = 1 AND sku.special_flag = 0)
UNION ALL
SELECT sku.*,1 as rn FROM goods_sku sku WHERE sku.order_flag = 1 AND sku.special_flag = 1
) AS goods_sku
left join goods_spu on goods_sku.spu_id = goods_spu.id
LEFT JOIN `goods_category` `cate1` ON `cate1`.`id` = `goods_spu`.`category_first`
LEFT JOIN `goods_category` `cate2` ON `cate2`.`id` = `goods_spu`.`category_second`
LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third`
(SELECT sku.*,ROW_NUMBER() OVER(PARTITION BY sku.spu_id ORDER BY sku.belong_sort) AS rn FROM goods_sku sku WHERE sku.order_flag = 1 AND sku.special_flag = 0)
UNION ALL
SELECT sku.*,1 as rn FROM goods_sku sku WHERE sku.order_flag = 1 AND sku.special_flag = 1
) AS goods_sku
left join goods_spu on goods_sku.spu_id = goods_spu.id