<?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.huijy.management.mapper.ShopMapper">

    <resultMap type="Shop" id="ShopResult">
        <result property="shopId"    column="shop_id"    />
        <result property="name"    column="name"    />
        <result property="addres"    column="addres"    />
        <result property="lat"    column="lat"    />
        <result property="lng"    column="lng"    />
        <result property="bossName"    column="boss_name"    />
        <result property="bossPhone"    column="boss_phone"    />
        <result property="showPictures"    column="show_pictures"    />
        <result property="labelText"    column="label_text"    />
        <result property="businessHours"    column="business_hours"    />
        <result property="briefContent"    column="brief_content"    />
        <result property="content"    column="content"    />
        <result property="enableFlag"    column="enable_flag"    />
        <result property="auditFlag"    column="audit_flag"    />
        <result property="auditAt"    column="audit_at"    />
        <result property="auditTime"    column="audit_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="memberId"    column="member_id"    />
        <result property="shopType"    column="shop_type"    />
    </resultMap>

    <sql id="selectShopVo">
        select shop_id, name, addres, lat, lng, boss_name, boss_phone, show_pictures, label_text, business_hours, brief_content, content, enable_flag, audit_flag, audit_at, audit_time, create_time,
        member_id,shop_type from t_shop
    </sql>

    <select id="selectShopList" parameterType="Shop" resultMap="ShopResult">
        <include refid="selectShopVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="bossName != null  and bossName != ''"> and boss_name like concat('%', #{bossName}, '%')</if>
            <if test="bossPhone != null  and bossPhone != ''"> and boss_phone = #{bossPhone}</if>
            <if test="enableFlag != null  and enableFlag != ''"> and enable_flag = #{enableFlag}</if>
            <if test="auditFlag != null  and auditFlag != ''"> and audit_flag = #{auditFlag}</if>
        </where>
    </select>

    <select id="selectShopByShopId" parameterType="Long" resultMap="ShopResult">
        <include refid="selectShopVo"/>
        where shop_id = #{shopId}
    </select>

    <insert id="insertShop" parameterType="Shop" useGeneratedKeys="true" keyProperty="shopId">
        insert into t_shop
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="addres != null">addres,</if>
            <if test="lat != null">lat,</if>
            <if test="lng != null">lng,</if>
            <if test="bossName != null">boss_name,</if>
            <if test="bossPhone != null">boss_phone,</if>
            <if test="showPictures != null">show_pictures,</if>
            <if test="labelText != null">label_text,</if>
            <if test="businessHours != null">business_hours,</if>
            <if test="briefContent != null">brief_content,</if>
            <if test="content != null">content,</if>
            <if test="enableFlag != null">enable_flag,</if>
            <if test="auditFlag != null">audit_flag,</if>
            <if test="auditAt != null">audit_at,</if>
            <if test="auditTime != null">audit_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="memberId != null">member_id,</if>
            <if test="shopType != null">shop_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="addres != null">#{addres},</if>
            <if test="lat != null">#{lat},</if>
            <if test="lng != null">#{lng},</if>
            <if test="bossName != null">#{bossName},</if>
            <if test="bossPhone != null">#{bossPhone},</if>
            <if test="showPictures != null">#{showPictures},</if>
            <if test="labelText != null">#{labelText},</if>
            <if test="businessHours != null">#{businessHours},</if>
            <if test="briefContent != null">#{briefContent},</if>
            <if test="content != null">#{content},</if>
            <if test="enableFlag != null">#{enableFlag},</if>
            <if test="auditFlag != null">#{auditFlag},</if>
            <if test="auditAt != null">#{auditAt},</if>
            <if test="auditTime != null">#{auditTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="shopType != null">#{shopType},</if>
         </trim>
    </insert>

    <update id="updateShop" parameterType="Shop">
        update t_shop
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="addres != null">addres = #{addres},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="bossName != null">boss_name = #{bossName},</if>
            <if test="bossPhone != null">boss_phone = #{bossPhone},</if>
            <if test="showPictures != null">show_pictures = #{showPictures},</if>
            <if test="labelText != null">label_text = #{labelText},</if>
            <if test="businessHours != null">business_hours = #{businessHours},</if>
            <if test="briefContent != null">brief_content = #{briefContent},</if>
            <if test="content != null">content = #{content},</if>
            <if test="enableFlag != null">enable_flag = #{enableFlag},</if>
            <if test="auditFlag != null">audit_flag = #{auditFlag},</if>
            <if test="auditAt != null">audit_at = #{auditAt},</if>
            <if test="auditTime != null">audit_time = #{auditTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="shopType != null">shop_type = #{shopType},</if>
        </trim>
        where shop_id = #{shopId}
    </update>

    <delete id="deleteShopByShopId" parameterType="Long">
        delete from t_shop where shop_id = #{shopId}
    </delete>

    <delete id="deleteShopByShopIds" parameterType="String">
        delete from t_shop where shop_id in
        <foreach item="shopId" collection="array" open="(" separator="," close=")">
            #{shopId}
        </foreach>
    </delete>

    <select id="selectListByMemberId" parameterType="Long" resultMap="ShopResult">
        <include refid="selectShopVo"/>
        where member_id = #{memberId}

    </select>
</mapper>
