<?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.corewing.app.mapper.BizProductMapper">


    <!-- 基础查询SQL片段 -->
    <sql id="selectVOSql">
        SELECT p.*
        FROM biz_product p
                 LEFT JOIN biz_product_category_relation pcr on p.id = pcr.product_id
    </sql>

    <!-- 分页查询 -->
    <select id="page" resultType="com.corewing.app.entity.BizProduct">
        <include refid="selectVOSql"/>
        <where>
            <if test="productPageRequest.categoryId != null and productPageRequest.categoryId != ''">
                and pcr.category_id = #{productPageRequest.categoryId}
            </if>

            <if test="productPageRequest.searchKey != null and productPageRequest.searchKey != ''">
               and p.title like CONCAT('%', #{productPageRequest.searchKey}, '%')
            </if>
            and delete_flag = 'NOT_DELETE'
        </where>
    </select>


</mapper>
