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

    <resultMap type="ParkInspectTaskUsrTrail" id="ParkInspectTaskUsrTrailResult">
        <result property="id" column="id"/>
        <result property="taskUsrRelId" column="task_usr_rel_id"/>
        <result property="taskName" column="task_name"/>
        <result property="taskId" column="task_id"/>
        <result property="usrId" column="usr_id"/>
        <result property="trail" column="trail"/>
        <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="selectParkInspectTaskUsrTrailVo">
        select id,
               task_usr_rel_id,
               task_name,
               task_id,
               usr_id,
               ST_AsText(trail) trail,
               update_time,
               create_time,
               create_by,
               update_by,
               tenant_id
        from park_inspect_task_usr_trail
    </sql>

    <select id="selectParkInspectTaskUsrTrailList" parameterType="ParkInspectTaskUsrTrail"
            resultMap="ParkInspectTaskUsrTrailResult">
        <include refid="selectParkInspectTaskUsrTrailVo"/>
        <where>
            <if test="taskName != null  and taskName != ''">and task_name like concat('%', #{taskName}, '%')</if>
        </where>
    </select>

    <select id="selectParkInspectTaskUsrTrailById" parameterType="Long" resultMap="ParkInspectTaskUsrTrailResult">
        <include refid="selectParkInspectTaskUsrTrailVo"/>
        where id = #{id}
    </select>

    <insert id="insertParkInspectTaskUsrTrail" parameterType="ParkInspectTaskUsrTrail" useGeneratedKeys="true"
            keyProperty="id">
        insert into park_inspect_task_usr_trail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskUsrRelId != null">task_usr_rel_id,</if>
            <if test="taskName != null and taskName != ''">task_name,</if>
            <if test="taskId != null">task_id,</if>
            <if test="usrId != null">usr_id,</if>
            <if test="trail != null">trail,</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="taskUsrRelId != null">#{taskUsrRelId},</if>
            <if test="taskName != null and taskName != ''">#{taskName},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="usrId != null">#{usrId},</if>
            <if test="trail != null">ST_GeomFromText(#{trail}),</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="updateParkInspectTaskUsrTrail" parameterType="ParkInspectTaskUsrTrail">
        update park_inspect_task_usr_trail
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskUsrRelId != null">task_usr_rel_id = #{taskUsrRelId},</if>
            <if test="taskName != null and taskName != ''">task_name = #{taskName},</if>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="usrId != null">usr_id = #{usrId},</if>
            <if test="trail != null">trail = ST_GeomFromText(#{trail}),</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="deleteParkInspectTaskUsrTrailById" parameterType="Long">
        delete
        from park_inspect_task_usr_trail
        where id = #{id}
    </delete>

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