<iftest="query.belong != null"> and (`goods_sku`.`belong` = #{query.belong} or goods_sku.special_flag=1) </if>
`cate1`.`name` AS `cate_first_label`,
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 1">
`cate2`.`name` AS `cate_second_label`,
and `goods_sku`.`special_flag` = 1
`cate3`.`name` AS `cate_third_label`,
and `goods_sku`.id = goods_spu.special_sku_id
<includerefid="goodsSpuSql"/>
</if>
FROM `goods_spu` `goods_spu`
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 0">
LEFT JOIN `goods_category` `cate1` ON `cate1`.`id` = `goods_spu`.`category_first`
and `goods_sku`.`special_flag` = 0
LEFT JOIN `goods_category` `cate2` ON `cate2`.`id` = `goods_spu`.`category_second`
</if>
LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third`
<iftest="query.orderFlag != null"> and `goods_sku`.`order_flag` = #{query.orderFlag}</if>
<where>
<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
and `goods_spu`.`del_flag` = 0
<iftest="query.id != null"> and `goods_spu`.`id` = #{query.id}</if>
<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.spuCode != null and query.spuCode != ''"> and `goods_spu`.`spu_code` like concat('%', #{query.spuCode},'%')</if>
@ -80,7 +100,6 @@
<iftest="query.shelf != null and query.shelf != ''"> and `goods_spu`.`shelf` = #{query.shelf}</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.sort != null"> and `goods_spu`.`sort` = #{query.sort}</if>
<iftest="query.saleNum != null"> and `goods_spu`.`sale_num` = #{query.saleNum}</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.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.createTime != null"> and `goods_spu`.`create_time` = #{query.createTime}</if>
<iftest="query.updateTime != null"> and `goods_spu`.`update_time` = #{query.updateTime}</if>
<iftest="query.updateTime != null"> and `goods_spu`.`update_time` = #{query.updateTime}</if>
@ -88,13 +107,13 @@
<iftest="query.updateBy != null and query.updateBy != ''"> and `goods_spu`.`update_by` = #{query.updateBy}</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.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.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">
<!--<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'
and `goods_spu`.`special_sku_id` is not null and `goods_spu`.`special_sku_id` != '0'
</if>
</if>
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 0">
<iftest="query.selectSpecialFlag != null and query.selectSpecialFlag == 0">
and (`goods_spu`.`special_sku_id` is null or `goods_spu`.`special_sku_id` = '0')
and (`goods_spu`.`special_sku_id` is null or `goods_spu`.`special_sku_id` = '0')
</if>
</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.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">
<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