<?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="cn.ysk.cashier.mybatis.mapper.TbPadProductCategoryMapper">

    <select id="findList" resultType="cn.ysk.cashier.dto.product.PadProductCategoryDTO">
        SELECT
        t1.*,
        t3.name as productCategoryName,
        GROUP_CONCAT(t4.name) as productNames,
        t5.code as padLayoutCode,
        t5.name as padLayoutName
        FROM
        tb_pad_product_category t1
        LEFT JOIN tb_pad_product_category_detail t2 on t1.id = t2.pad_product_category_id
        LEFT JOIN tb_shop_category t3 on t1.product_category_id = t3.id
        LEFT JOIN tb_product t4 on t2.product_id = t4.id
        LEFT JOIN tb_pad_layout t5 on t1.pad_layout_id = t5.id
        <where>
            and t1.shop_id = #{shopId}
            <if test="id != null and id!=''">
                and t1.id = #{id}
            </if>
            <if test="customName != null and customName != ''">
                and t1.custom_name like concat(#{customName},'%')
            </if>
            <if test="productCategoryId != null and productCategoryId != ''">
                and t1.product_category_id = #{productCategoryId}
            </if>
            <if test="padLayoutId != null and padLayoutId != ''">
                and t1.pad_layout_id = #{padLayoutId}
            </if>
            <if test="padLayoutCode != null and padLayoutCode != ''">
                and t5.code = #{padLayoutCode}
            </if>
        </where>
        group by t1.id
        order by t1.id asc
    </select>
</mapper>