<?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.rsmonitoring.mapper.TDkGeomDbDetailsMapper">
    
    <resultMap type="TDkGeomDbDetails" id="TDkGeomDbDetailsResult">
        <result property="id"    column="id"    />
        <result property="geom"    column="geom"    />
        <result property="uploadId"    column="upload_id"    />
        <result property="geomJson"    column="geom_json"    />
        <result property="sort"    column="sort"    />
        <result property="geomArea"    column="geom_area"    />
    </resultMap>

    <sql id="selectTDkGeomDbDetailsVo">
        select id, public.st_asewkt(geom) AS  geom, upload_id, geom_json, sort, geom_area from t_geom_db_details
    </sql>

    <select id="selectTDkGeomDbDetailsList" parameterType="TDkGeomDbDetails" resultMap="TDkGeomDbDetailsResult">
        <include refid="selectTDkGeomDbDetailsVo"/>
        <where>  
            <if test="geom != null  and geom != ''"> and geom = #{geom}</if>
            <if test="uploadId != null  and uploadId != ''"> and upload_id = #{uploadId}</if>
            <if test="geomJson != null  and geomJson != ''"> and geom_json = #{geomJson}</if>
            <if test="sort != null  and sort != ''"> and sort = #{sort}</if>
            <if test="geomArea != null  and geomArea != ''"> and geom_area = #{geomArea}</if>
        </where>
    </select>
    
    <select id="selectTDkGeomDbDetailsById" parameterType="String" resultMap="TDkGeomDbDetailsResult">
        <include refid="selectTDkGeomDbDetailsVo"/>
        where id = #{id}
    </select>

    <insert id="insertTDkGeomDbDetails" parameterType="TDkGeomDbDetails">
        insert into t_geom_db_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">id,</if>
            <if test="geom != null">geom,</if>
            <if test="uploadId != null and uploadId != ''">upload_id,</if>
            <if test="geomJson != null">geom_json,</if>
            <if test="sort != null">sort,</if>
            <if test="geom != null">geom_area,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">#{id},</if>
            <if test="geom != null">public.st_transform(public.st_geomfromewkt(#{geom}), #{shpDbSRID}),</if>
            <if test="uploadId != null and uploadId != ''">#{uploadId},</if>
            <if test="geomJson != null">#{geomJson},</if>
            <if test="sort != null">#{sort},</if>
            <if test="geom != null">
            public.st_area(public.st_transform(public.st_geomfromewkt(#{geom}), #{shpAreaSRID})
             <if test="shpAreaGeography != null and shpAreaGeography==true ">::PUBLIC.geography</if>
            ),
            </if>
         </trim>
    </insert>

    <update id="updateTDkGeomDbDetails" parameterType="TDkGeomDbDetails">
        update t_geom_db_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="geom != null">geom = #{geom},</if>
            <if test="uploadId != null and uploadId != ''">upload_id = #{uploadId},</if>
            <if test="geomJson != null">geom_json = #{geomJson},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="geomArea != null">geom_area = #{geomArea},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTDkGeomDbDetailsById" parameterType="String">
        delete from t_geom_db_details where id = #{id}
    </delete>

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


</mapper>