<?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.czg.service.account.mapper.PadProductCategoryDetailMapper">

    <select id="selectPageByKeyAndShopId" resultType="com.czg.account.dto.pad.PadProductCategoryDTO">
        SELECT tb_pad_product_category.id,
        tb_shop_prod_category.id AS productCategoryId,
        tb_shop_prod_category.`name` AS productCategoryName,
        tb_pad_layout.code AS padLayoutCode,
        tb_pad_layout.NAME AS padLayoutName
        FROM tb_pad_product_category
        LEFT JOIN tb_shop_prod_category ON tb_pad_product_category.product_category_id = tb_shop_prod_category.id and tb_shop_prod_category.shop_id=#{shopId}

        LEFT JOIN tb_pad_layout ON tb_pad_product_category.pad_layout_id = tb_pad_layout.id
        where tb_pad_product_category.shop_id=#{shopId}
        <if test="categoryId != null">
            and tb_pad_product_category.product_category_id=#{categoryId}
        </if>
        group by tb_pad_product_category.id,tb_pad_product_category.sort
        order by tb_pad_product_category.sort desc
    </select>

    <select id="selectPageByKeyAndShopId1" resultType="com.czg.account.dto.pad.PadProductCategoryDTO">
        SELECT tb_pad_product_category.id,
        tb_shop_prod_category.id AS productCategoryId,
        tb_shop_prod_category.`name` AS productCategoryName,
        #         GROUP_CONCAT(tb_product.NAME) AS productNames,
        tb_pad_layout.code AS padLayoutCode,
        tb_pad_layout.NAME AS padLayoutName
        FROM tb_pad_product_category
        #         LEFT JOIN tb_pad_product_category_detail ON tb_pad_product_category.id = tb_pad_product_category_detail.pad_product_category_id
        LEFT JOIN tb_shop_prod_category ON tb_pad_product_category.product_category_id = tb_shop_prod_category.id and tb_shop_prod_category.shop_id=#{shopId}
        #         LEFT JOIN tb_product ON tb_pad_product_category_detail.product_id = tb_product.id
        LEFT JOIN tb_pad_layout ON tb_pad_product_category.pad_layout_id = tb_pad_layout.id
        where tb_pad_product_category.shop_id=#{shopId}
        <if test="categoryId != null">
            and tb_pad_product_category.product_category_id=#{categoryId}
        </if>
        group by tb_pad_product_category.id,tb_pad_product_category.sort
        order by tb_pad_product_category.sort desc
    </select>

</mapper>
