<?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.MarkerMapper">

    <resultMap type="Marker" id="MarkerResult">
        <result property="markerId"    column="marker_id"    />
        <result property="markerName"    column="marker_name"    />
        <result property="markerType"    column="marker_type"    />
        <result property="address"    column="address"    />
        <result property="showPictures"    column="show_pictures"    />
        <result property="iconPictures"    column="icon_pictures"    />
        <result property="lat"    column="lat"    />
        <result property="lng"    column="lng"    />
        <result property="labelText"    column="label_text"    />
        <result property="businessHours"    column="business_hours"    />
        <result property="shapeType"    column="shape_type"    />
        <result property="locationSet"    column="location_set"    />
        <result property="radius"    column="radius"    />
        <result property="briefContent"    column="brief_content"    />
        <result property="content"    column="content"    />
    </resultMap>

    <sql id="selectMarkerVo">
        select marker_id, marker_name, marker_type, address, show_pictures, icon_pictures, lat, lng, label_text, business_hours, shape_type, location_set, radius, brief_content, content from t_marker
    </sql>

    <select id="selectMarkerList" parameterType="Marker" resultMap="MarkerResult">
        <include refid="selectMarkerVo"/>
        <where>
            <if test="markerName != null  and markerName != ''"> and marker_name like concat('%', #{markerName}, '%')</if>
            <if test="markerType != null  and markerType != ''"> and marker_type = #{markerType}</if>
        </where>
    </select>

    <select id="selectMarkerListByContentId" parameterType="Long" resultMap="MarkerResult">
        <include refid="selectMarkerVo"/>
        where marker_id in(select marker_id from t_marker_content where t_marker_content.content_id = #{contentId})
    </select>



    <select id="selectMarkerByMarkerId" parameterType="Long" resultMap="MarkerResult">
        <include refid="selectMarkerVo"/>
        where marker_id = #{markerId}
    </select>

    <insert id="insertMarker" parameterType="Marker" useGeneratedKeys="true" keyProperty="markerId">
        insert into t_marker
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="markerName != null">marker_name,</if>
            <if test="markerType != null">marker_type,</if>
            <if test="address != null">address,</if>
            <if test="showPictures != null">show_pictures,</if>
            <if test="iconPictures != null">icon_pictures,</if>
            <if test="lat != null">lat,</if>
            <if test="lng != null">lng,</if>
            <if test="labelText != null">label_text,</if>
            <if test="businessHours != null">business_hours,</if>
            <if test="shapeType != null">shape_type,</if>
            <if test="locationSet != null">location_set,</if>
            <if test="radius != null">radius,</if>
            <if test="briefContent != null">brief_content,</if>
            <if test="content != null">content,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="markerName != null">#{markerName},</if>
            <if test="markerType != null">#{markerType},</if>
            <if test="address != null">#{address},</if>
            <if test="showPictures != null">#{showPictures},</if>
            <if test="iconPictures != null">#{iconPictures},</if>
            <if test="lat != null">#{lat},</if>
            <if test="lng != null">#{lng},</if>
            <if test="labelText != null">#{labelText},</if>
            <if test="businessHours != null">#{businessHours},</if>
            <if test="shapeType != null">#{shapeType},</if>
            <if test="locationSet != null">#{locationSet},</if>
            <if test="radius != null">#{radius},</if>
            <if test="briefContent != null">#{briefContent},</if>
            <if test="content != null">#{content},</if>
         </trim>
    </insert>

    <update id="updateMarker" parameterType="Marker">
        update t_marker
        <trim prefix="SET" suffixOverrides=",">
            <if test="markerName != null">marker_name = #{markerName},</if>
            <if test="markerType != null">marker_type = #{markerType},</if>
            <if test="address != null">address = #{address},</if>
            <if test="showPictures != null">show_pictures = #{showPictures},</if>
            <if test="iconPictures != null">icon_pictures = #{iconPictures},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="labelText != null">label_text = #{labelText},</if>
            <if test="businessHours != null">business_hours = #{businessHours},</if>
            <if test="shapeType != null">shape_type = #{shapeType},</if>
            <if test="locationSet != null">location_set = #{locationSet},</if>
            <if test="radius != null">radius = #{radius},</if>
            <if test="briefContent != null">brief_content = #{briefContent},</if>
            <if test="content != null">content = #{content},</if>
        </trim>
        where marker_id = #{markerId}
    </update>

    <delete id="deleteMarkerByMarkerId" parameterType="Long">
        delete from t_marker where marker_id = #{markerId}
    </delete>

    <delete id="deleteMarkerByMarkerIds" parameterType="String">
        delete from t_marker where marker_id in
        <foreach item="markerId" collection="array" open="(" separator="," close=")">
            #{markerId}
        </foreach>
    </delete>
</mapper>
