<?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.siwei.spatial.mapper.file.TGeomDbMapper">
    
    <resultMap type="TGeomDb" id="TGeomDbResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="shppath"    column="shppath"    />
        <result property="filetype"    column="filetype"    />
        <result property="geom"    column="geom"    />
        <result property="geomNumber"    column="geom_number"    />
        <result property="geomArea"    column="geom_area"    />
        <result property="fromroute"    column="fromroute"    />
    </resultMap>

    <sql id="selectTGeomDbVo">
        select id, name, create_by, create_time, shppath, filetype, public.st_asewkt(geom) AS  geom, geom_number, geom_area, fromroute from t_geom_db
    </sql>

    <select id="selectTGeomDbList" parameterType="TGeomDb" resultMap="TGeomDbResult">
        <include refid="selectTGeomDbVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="shppath != null  and shppath != ''"> and shppath = #{shppath}</if>
            <if test="filetype != null  and filetype != ''"> and filetype = #{filetype}</if>
            <if test="geom != null  and geom != ''"> and geom = #{geom}</if>
            <if test="geomNumber != null  and geomNumber != ''"> and geom_number = #{geomNumber}</if>
            <if test="fromroute != null  and fromroute != ''"> and fromroute = #{fromroute}</if>
        </where>
    </select>
    
    <select id="selectTGeomDbById" parameterType="String" resultMap="TGeomDbResult">
        <include refid="selectTGeomDbVo"/>
        where id = #{id}
    </select>

    <insert id="insertTGeomDb" parameterType="TGeomDb">
        insert into t_geom_db
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">id,</if>
            <if test="name != null">name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="shppath != null">shppath,</if>
            <if test="filetype != null">filetype,</if>
            <if test="geom != null">geom,</if>
            <if test="geomNumber != null">geom_number,</if>
            <if test="geomArea != null">geom_area,</if>
            <if test="fromroute != null">fromroute,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">#{id},</if>
            <if test="name != null">#{name},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="shppath != null">#{shppath},</if>
            <if test="filetype != null">#{filetype},</if>
            <if test="geom != null">public.st_transform(public.st_geomfromewkt(#{geom}), #{shpDbSRID}),</if>
            <if test="geomNumber != null">#{geomNumber},</if>
            <if test="geomArea != null">#{geomArea},</if>
            <if test="fromroute != null">#{fromroute},</if>
         </trim>
    </insert>

    <update id="updateTGeomDb" parameterType="TGeomDb">
        update t_geom_db
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="shppath != null">shppath = #{shppath},</if>
            <if test="filetype != null">filetype = #{filetype},</if>
            <if test="geom != null">geom = #{geom},</if>
            <if test="geomNumber != null">geom_number = #{geomNumber},</if>
            <if test="geomArea != null">geom_area = #{geomArea},</if>
            <if test="fromroute != null">fromroute = #{fromroute},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTGeomDbById" parameterType="String">
        delete from t_geom_db where id = #{id}
    </delete>

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