<?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.wansenai.mappers.shop.BasShopMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.wansenai.entities.shop.BasShop">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="name" property="name"/>
        <result column="channel" property="channel"/>
        <result column="type" property="type"/>
        <result column="address_id" property="addressId"/>
        <result column="price_type" property="priceType"/>
        <result column="field_1" property="field1"/>
        <result column="field_2" property="field2"/>
        <result column="field_3" property="field3"/>
        <result column="field_4" property="field4"/>
        <result column="field_5" property="field5"/>
        <result column="field_6" property="field6"/>
        <result column="field_7" property="field7"/>
        <result column="field_8" property="field8"/>
        <result column="field_9" property="field9"/>
        <result column="field_10" property="field10"/>
        <result column="create_time" property="createTime"/>
        <result column="create_by" property="createBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, code, name, channel, type, address_id, price_type,
        field_1, field_2, field_3, field_4, field_5, field_6, field_7, field_8, field_9, field_10,
        create_time, create_by, update_time, update_by, remark
    </sql>

    <!-- 根据店铺编码查询店铺信息 -->
    <select id="getShopByCode" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM bas_shop
        WHERE code = #{code}
    </select>

    <!-- 根据店铺名称模糊查询店铺列表 -->
    <select id="getShopListByName" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM bas_shop
        WHERE name LIKE CONCAT('%', #{name}, '%')
    </select>

    <!-- 根据渠道查询店铺列表 -->
    <select id="getShopListByChannel" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM bas_shop
        WHERE channel = #{channel}
    </select>

    <!-- 批量插入店铺信息 -->
    <insert id="batchInsert">
        INSERT INTO bas_shop (
            code, name, channel, type, address_id, price_type,
            field_1, field_2, field_3, field_4, field_5, 
            field_6, field_7, field_8, field_9, field_10,
            create_time, create_by, remark
        ) VALUES
        <foreach collection="shopList" item="shop" separator=",">
            (
                #{shop.code}, #{shop.name}, #{shop.channel}, #{shop.type},
                #{shop.addressId}, #{shop.priceType},
                #{shop.field1}, #{shop.field2}, #{shop.field3}, #{shop.field4}, #{shop.field5},
                #{shop.field6}, #{shop.field7}, #{shop.field8}, #{shop.field9}, #{shop.field10},
                #{shop.createTime}, #{shop.createBy}, #{shop.remark}
            )
        </foreach>
    </insert>

</mapper>
