<?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.cool.store.mapper.store.StoreTypeMapper">

    <resultMap id="BaseResultMap" type="com.cool.store.entity.store.StoreTypeDO">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="store_type_code" property="storeTypeCode" jdbcType="VARCHAR"/>
        <result column="store_type_name" property="storeTypeName" jdbcType="VARCHAR"/>
        <result column="brand" property="brand" jdbcType="VARCHAR"/>
        <result column="store_type" property="storeType" jdbcType="INTEGER"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="image_url" property="imageUrl" jdbcType="VARCHAR"/>
        <result column="video_url" property="videoUrl" jdbcType="VARCHAR"/>
        <result column="vr_video_url" property="vrVideoUrl" jdbcType="VARCHAR"/>
        <result column="franchise_fee" property="franchiseFee" jdbcType="DECIMAL"/>
        <result column="original_franchise_fee" property="originalFranchiseFee" jdbcType="DECIMAL"/>
        <result column="brand_usage_fee" property="brandUsageFee" jdbcType="DECIMAL"/>
        <result column="original_brand_usage_fee" property="originalBrandUsageFee" jdbcType="DECIMAL"/>
        <result column="management_fee" property="managementFee" jdbcType="DECIMAL"/>
        <result column="original_management_fee" property="originalManagementFee" jdbcType="DECIMAL"/>
        <result column="system_usage_fee" property="systemUsageFee" jdbcType="DECIMAL"/>
        <result column="original_system_usage_fee" property="originalSystemUsageFee" jdbcType="DECIMAL"/>
        <result column="contract_deposit" property="contractDeposit" jdbcType="DECIMAL"/>
        <result column="original_contract_deposit" property="originalContractDeposit" jdbcType="DECIMAL"/>
        <result column="device_deposit" property="deviceDeposit" jdbcType="DECIMAL"/>
        <result column="original_device_deposit" property="originalDeviceDeposit" jdbcType="DECIMAL"/>
        <result column="design_fee" property="designFee" jdbcType="DECIMAL"/>
        <result column="original_design_fee" property="originalDesignFee" jdbcType="DECIMAL"/>
        <result column="first_order_fee" property="firstOrderFee" jdbcType="DECIMAL"/>
        <result column="sort_order" property="sortOrder" jdbcType="INTEGER"/>
        <result column="is_active" property="active" jdbcType="BOOLEAN"/>
        <result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, store_type_code, store_type_name, brand, store_type, description,
        image_url, video_url, vr_video_url,
        franchise_fee, original_franchise_fee,
        brand_usage_fee, original_brand_usage_fee,
        management_fee, original_management_fee,
        system_usage_fee, original_system_usage_fee,
        contract_deposit, original_contract_deposit,
        device_deposit, original_device_deposit,
        design_fee, original_design_fee,
        first_order_fee, sort_order,
        is_active, deleted, create_time, update_time
    </sql>

    <select id="queryByCondition" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM zxjp_store_type
        WHERE deleted = 0
        <if test="active != null">
            AND is_active = #{active}
        </if>
        <if test="brand != null and brand != ''">
            AND brand = #{brand}
        </if>
        <if test="keyword != null and keyword != ''">
            AND (store_type_name LIKE CONCAT('%', #{keyword}, '%')
            OR store_type_code LIKE CONCAT('%', #{keyword}, '%'))
        </if>
        ORDER BY sort_order ASC, create_time DESC
    </select>

    <select id="listByStoreType" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM zxjp_store_type
        WHERE deleted = 0
        AND is_active = 1
        AND store_type = #{storeType}
        ORDER BY sort_order ASC, create_time DESC
    </select>

</mapper>