<?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.fuint.repository.mapper.MtTableCategoryMapper">

    <select id="selectByStoreIdAndCategoryName" resultType="com.fuint.repository.bean.TableCategoryBean">
        SELECT
            c.id,
            c.category_name as categoryName,
            c.create_time as createTime,
            c.update_time as updateTime,
            c.description,
            s.name as storeName
        FROM mt_table_category c left join mt_store s on c.store_id = s.id
        <where> c.delete_flag = 0
            <if test="storeId!=null and storeId>0">
                AND c.store_id = #{storeId}
            </if>
        <if test="categoryName != null and categoryName != ''">
            AND c.category_name LIKE CONCAT(#{categoryName}, '%')
        </if>
        ORDER BY c.create_time DESC limit #{page},#{pageSize}
        </where>
    </select>
    <select id="selectByStoreIdAndCategoryCount" resultType="java.lang.Integer">
        SELECT
        count(*)
        FROM mt_table_category c inner join mt_store s on c.store_id = s.id
        <where> c.delete_flag = 0
            <if test="storeId!=null and storeId>0">
                AND c.store_id = #{storeId}
            </if>
            <if test="categoryName != null and categoryName != ''">
                AND c.category_name LIKE CONCAT(#{categoryName}, '%')
            </if>
        </where>
    </select>
</mapper>
