<?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.huashe.park.core.mapper.ParkAttendGroupMapper">

    <resultMap type="ParkAttendGroup" id="ParkAttendGroupResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="remark" column="remark"/>
        <result property="poly" column="poly"/>
        <result property="timeRange" column="time_range"/>
        <result property="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="tenantId" column="tenant_id"/>
    </resultMap>

    <sql id="selectParkAttendGroupVo">
        select id,
               name,
               remark,
               ST_AsText(poly) poly,
               time_range,
               update_time,
               create_time,
               create_by,
               update_by,
               tenant_id
        from park_attend_group
    </sql>

    <select id="selectParkAttendGroupList" parameterType="ParkAttendGroup" resultMap="ParkAttendGroupResult">
        <include refid="selectParkAttendGroupVo"/>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
        </where>
    </select>

    <select id="selectParkAttendGroupById" parameterType="Long" resultMap="ParkAttendGroupResult">
        <include refid="selectParkAttendGroupVo"/>
        where id = #{id}
    </select>

    <insert id="insertParkAttendGroup" parameterType="ParkAttendGroup" useGeneratedKeys="true" keyProperty="id">
        insert into park_attend_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="remark != null">remark,</if>
            <if test="poly != null">poly,</if>
            <if test="timeRange != null">time_range,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="tenantId != null">tenant_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="remark != null">#{remark},</if>
            <if test="poly != null">ST_GeomFromText(#{poly}),</if>
            <if test="timeRange != null">#{timeRange},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="tenantId != null">#{tenantId},</if>
        </trim>
    </insert>

    <update id="updateParkAttendGroup" parameterType="ParkAttendGroup">
        update park_attend_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="poly != null">poly = ST_GeomFromText(#{poly}),</if>
            <if test="timeRange != null">time_range = #{timeRange},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteParkAttendGroupById" parameterType="Long">
        delete
        from park_attend_group
        where id = #{id}
    </delete>

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