<?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.mosty.yszx.mapper.TbYsDlMapper">
    <resultMap type="com.mosty.base.model.entity.yszx.TbYsDl" id="TbYsDlMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="ysdl" column="ysdl" jdbcType="VARCHAR"/>
        <result property="yszl" column="yszl" jdbcType="VARCHAR"/>
        <result property="ysxl" column="ysxl" jdbcType="VARCHAR"/>
        <result property="ysmc" column="ysmc" jdbcType="VARCHAR"/>
        <result property="ysjc" column="ysjc" jdbcType="VARCHAR"/>
        <result property="yswzXzqh" column="yswz_xzqh" jdbcType="VARCHAR"/>
        <result property="yswzXz" column="yswz_xz" jdbcType="VARCHAR"/>
        <result property="yswzBc" column="yswz_bc" jdbcType="VARCHAR"/>
        <result property="jd" column="jd" jdbcType="NUMERIC"/>
        <result property="wd" column="wd" jdbcType="NUMERIC"/>
        <result property="zb" column="zb" typeHandler="com.mosty.base.feign.handle.PointTypeHandler"/>
        <result property="zbhash" column="zbhash" jdbcType="VARCHAR"/>
        <result property="dtm" column="dtm" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <result property="znsbbs" column="znsbbs" jdbcType="VARCHAR"/>
        <result property="lybm" column="lybm" jdbcType="VARCHAR"/>
        <result property="lyid" column="lyid" jdbcType="VARCHAR"/>
        <result property="jsnr" column="jsnr" jdbcType="VARCHAR"/>
        <result property="ssbm" column="ssbm" jdbcType="VARCHAR"/>
        <result property="ssbmdm" column="ssbmdm" jdbcType="VARCHAR"/>
        <result property="ssxgaj" column="ssxgaj" jdbcType="VARCHAR"/>
        <result property="ssxgajdm" column="ssxgajdm" jdbcType="VARCHAR"/>
        <result property="sssgaj" column="sssgaj" jdbcType="VARCHAR"/>
        <result property="sssgajdm" column="sssgajdm" jdbcType="VARCHAR"/>
        <result property="xtSjly" column="xt_sjly" jdbcType="VARCHAR"/>
        <result property="xtSjzt" column="xt_sjzt" jdbcType="VARCHAR"/>
        <result property="xtScbz" column="xt_scbz" jdbcType="VARCHAR"/>
        <result property="xtCjip" column="xt_cjip" jdbcType="VARCHAR"/>
        <result property="xtCjsj" column="xt_cjsj" jdbcType="VARCHAR"/>
        <result property="xtCjrId" column="xt_cjr_id" jdbcType="VARCHAR"/>
        <result property="xtCjr" column="xt_cjr" jdbcType="VARCHAR"/>
        <result property="xtCjbmdm" column="xt_cjbmdm" jdbcType="VARCHAR"/>
        <result property="xtCjbmmc" column="xt_cjbm" jdbcType="VARCHAR"/>
        <result property="xtZhgxip" column="xt_zhgxip" jdbcType="VARCHAR"/>
        <result property="xtZhgxsj" column="xt_zhgxsj" jdbcType="VARCHAR"/>
        <result property="xtZhgxrid" column="xt_zhgxrid" jdbcType="VARCHAR"/>
        <result property="xtZhgxr" column="xt_zhgxr" jdbcType="VARCHAR"/>
        <result property="xtZhgxbmdm" column="xt_zhgxbmdm" jdbcType="VARCHAR"/>
        <result property="xtZhgxbm" column="xt_zhgxbm" jdbcType="VARCHAR"/>
        <result property="bz" column="bz" jdbcType="VARCHAR"/>
        <result property="distance" column="distance" jdbcType="NUMERIC"/>
        <result property="sssgajid" column="sssgajid" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="ssbmid" column="ssbmid" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="base_column_list">
        id
        ,ysdl,yszl,ysxl,ysmc,ysjc,yswz_xzqh,yswz_xz,yswz_bc,jd,wd,zbhash,znsbbs,ssbmid,ssxgajid,sssgajid,
        lybm,lyid,jsnr,ssbm, ssbmdm, ssxgaj, ssxgajdm, sssgaj, sssgajdm, xt_sjly, xt_sjzt, xt_scbz,
        xt_cjip, xt_cjsj, xt_cjr_id, xt_cjr, xt_cjbmdm, xt_cjbmmc, xt_zhgxip, xt_zhgxsj, xt_zhgxrid,
        xt_zhgxr, xt_zhgxbmdm, xt_zhgxbm, bz
    </sql>

    <sql id="zb_sql">
        ST_ASWKT
                (zb)
                as zb,ST_ASWKT(dtm) as dtm
    </sql>

    <!--修改公安机关要素-->
    <update id="updateEntity" parameterType="com.mosty.base.model.entity.yszx.TbYsDl">
        update tb_ys_dl
        <set>
            <if test="ysdl != null and ysdl != ''">
                ysdl = #{ysdl},
            </if>
            <if test="yszl != null and yszl != ''">
                yszl = #{yszl},
            </if>
            <if test="ysxl != null and ysxl != ''">
                ysxl = #{ysxl},
            </if>
            <if test="ysmc != null and ysmc != ''">
                ysmc = #{ysmc},
            </if>
            <if test="ysjc != null and ysjc != ''">
                ysjc = #{ysjc},
            </if>
            <if test="yswzXzqh != null and yswzXzqh != ''">
                yswz_xzqh = #{yswzXzqh},
            </if>
            <if test="yswzXz != null and yswzXz != ''">
                yswz_xz = #{yswzXz},
            </if>
            <if test="yswzBc != null and yswzBc != ''">
                yswz_bc = #{yswzBc},
            </if>
            <if test="jd != null">
                jd = #{jd},
            </if>
            <if test="wd != null">
                wd = #{wd},
            </if>
            <if test="zb != null">
                zb = ST_GEOMFROMTEXT(#{zb,typeHandler=com.mosty.base.feign.handle.PointTypeHandler}),
            </if>
            <if test="zbhash != null and zbhash != ''">
                zbhash = #{zbhash},
            </if>
            <if test="dtm != null">
                dtm = ST_GEOMFROMTEXT(#{dtm,typeHandler=com.mosty.base.feign.handle.PolygonTypeHandler}),
            </if>
            <if test="znsbbs != null and znsbbs != ''">
                znsbbs = #{znsbbs},
            </if>
            <if test="lybm != null and lybm != ''">
                lybm = #{lybm},
            </if>
            <if test="lyid != null and lyid != ''">
                lyid = #{lyid},
            </if>
            <if test="jsnr != null and jsnr != ''">
                jsnr = #{jsnr},
            </if>
            <if test="ssbm != null and ssbm != ''">
                ssbm = #{ssbm},
            </if>
            <if test="ssbmdm != null and ssbmdm != ''">
                ssbmdm = #{ssbmdm},
            </if>
            <if test="ssxgaj != null and ssxgaj != ''">
                ssxgaj = #{ssxgaj},
            </if>
            <if test="ssxgajdm != null and ssxgajdm != ''">
                ssxgajdm = #{ssxgajdm},
            </if>
            <if test="sssgaj != null and sssgaj != ''">
                sssgaj = #{sssgaj},
            </if>
            <if test="sssgajdm != null and sssgajdm != ''">
                sssgajdm = #{sssgajdm},
            </if>
            <if test="xtSjly != null and xtSjly != ''">
                xt_sjly = #{xtSjly},
            </if>
            <if test="xtSjzt != null and xtSjzt != ''">
                xt_sjzt = #{xtSjzt},
            </if>
            <if test="xtScbz != null and xtScbz != ''">
                xt_scbz = #{xtScbz},
            </if>
            <if test="xtCjip != null and xtCjip != ''">
                xt_cjip = #{xtCjip},
            </if>
            <if test="xtCjsj != null">
                xt_cjsj = #{xtCjsj},
            </if>
            <if test="xtCjrId != null and xtCjrId != ''">
                xt_cjr_id = #{xtCjrId},
            </if>
            <if test="xtCjr != null and xtCjr != ''">
                xt_cjr = #{xtCjr},
            </if>
            <if test="xtCjbmdm != null and xtCjbmdm != ''">
                xt_cjbmdm = #{xtCjbmdm},
            </if>
            <if test="xtCjbmmc != null and xtCjbmmc != ''">
                xt_cjbmmc = #{xtCjbmmc},
            </if>
            <if test="xtZhgxip != null and xtZhgxip != ''">
                xt_zhgxip = #{xtZhgxip},
            </if>
            <if test="xtZhgxsj != null">
                xt_zhgxsj = #{xtZhgxsj},
            </if>
            <if test="xtZhgxrid != null and xtZhgxrid != ''">
                xt_zhgxrid = #{xtZhgxrid},
            </if>
            <if test="xtZhgxr != null and xtZhgxr != ''">
                xt_zhgxr = #{xtZhgxr},
            </if>
            <if test="xtZhgxbmdm != null and xtZhgxbmdm != ''">
                xt_zhgxbmdm = #{xtZhgxbmdm},
            </if>
            <if test="xtZhgxbm != null and xtZhgxbm != ''">
                xt_zhgxbm = #{xtZhgxbm},
            </if>
            <if test="bz != null and bz != ''">
                bz = #{bz}
            </if>
            <if test="ssbmid != null and ssbmid != ''">
                ssbmid = #{ssbmid},
            </if>
            <if test="ssxgajid != null and ssxgajid != ''">
                ssxgajid = #{ssxgajid},
            </if>
            <if test="sssgajid != null and sssgajid != ''">
                sssgajid = #{sssgajid},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--新增地理要素-->
    <insert id="insertEntity" parameterType="com.mosty.base.model.entity.yszx.TbYsDl">
        insert into tb_ys_dl
                (id, ysdl, yszl, ysxl, ysmc, ysjc, yswz_xzqh, yswz_xz, yswz_bc, jd, wd, zb, ssbmid, ssxgajid, sssgajid,
                 zbhash, dtm, znsbbs, lybm, lyid, jsnr, ssbm, ssbmdm, ssxgaj, ssxgajdm, sssgaj, sssgajdm,
                 xt_sjly, xt_sjzt, xt_scbz, xt_cjip, xt_cjsj, xt_cjr_id,
                 xt_cjr, xt_cjbmdm, xt_cjbmmc, xt_zhgxip, xt_zhgxsj, xt_zhgxrid,
                 xt_zhgxr, xt_zhgxbmdm, xt_zhgxbm, bz)
        values (#{id}, #{ysdl}, #{yszl}, #{ysxl}, #{ysmc}, #{ysjc}, #{yswzXzqh}, #{yswzXz}, #{yswzBc}, #{jd}, #{wd},
                ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.PointTypeHandler}), #{ssbmid},
                #{ssxgajid}, #{sssgajid},
                #{zbhash},
                ST_GEOMFROMTEXT(#{dtm,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
                #{znsbbs}, #{lybm}, #{lyid}, #{jsnr}, #{ssbm}, #{ssbmdm}, #{ssxgaj}, #{ssxgajdm},
                #{sssgaj}, #{sssgajdm}, #{xtSjly}, #{xtSjzt}, #{xtScbz}, #{xtCjip}, #{xtCjsj}, #{xtCjrId},
                #{xtCjr}, #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip}, #{xtZhgxsj}, #{xtZhgxrid},
                #{xtZhgxr}, #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz})
    </insert>

    <!--获取地理要素详情-->
    <select id="getInfoById" resultMap="TbYsDlMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_ys_dl where xt_sjzt = '1' and xt_scbz = '0'
        and id = #{id}
    </select>

    <select id="getCount" resultType="Integer" parameterType="Map">
        select count(1) from tb_ys_dl where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.ysdl != null and dto.ysdl != ''">
            and ysdl = #{dto.ysdl}
        </if>
        <if test="dto.yszl != null and dto.yszl != ''">
            and yszl = #{dto.yszl}
        </if>
        <if test="dto.ysxl != null and dto.ysxl != ''">
            and ysxl = #{dto.ysxl}
        </if>
        <if test="dto.ysmc != null and dto.ysmc != ''">
            and ysmc like concat('%',#{dto.ysmc},'%')
        </if>
        <if test="dto.jsnr != null and dto.jsnr != ''">
            and jsnr like concat('%',#{dto.jsnr},'%')
        </if>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[and st_distance_sphere(POINT(jd,wd),POINT(#{dto.jd},#{dto.wd})) <= #{dto.radius}]]>
        </if>
        ${useSql}
    </select>

    <!--查询分页-->
    <select id="getPageList" parameterType="Map" resultMap="TbYsDlMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            ,st_distance_sphere(POINT(jd,wd),POINT(#{dto.jd},#{dto.wd})) as distance
        </if>
        from tb_ys_dl where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.ysdl != null and dto.ysdl != ''">
            and ysdl = #{dto.ysdl}
        </if>
        <if test="dto.yszl != null and dto.yszl != ''">
            and yszl = #{dto.yszl}
        </if>
        <if test="dto.ysxl != null and dto.ysxl != ''">
            and ysxl = #{dto.ysxl}
        </if>
        <if test="dto.ysmc != null and dto.ysmc != ''">
            and ysmc like concat('%',#{dto.ysmc},'%')
        </if>
        <if test="dto.jsnr != null and dto.jsnr != ''">
            and jsnr like concat('%',#{dto.jsnr},'%')
        </if>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
        ${useSql}
        order by xt_cjsj desc
        limit #{pageIndex},#{pageSize}
    </select>

    <!--查询不分页-->
    <select id="getList" parameterType="Map" resultMap="TbYsDlMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            ,st_distance_sphere(POINT(jd,wd),POINT(#{dto.jd},#{dto.wd})) as distance
        </if>
        from tb_ys_dl where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.ysdl != null and dto.ysdl != ''">
            and ysdl = #{dto.ysdl}
        </if>
        <if test="dto.yszl != null and dto.yszl != ''">
            and yszl = #{dto.yszl}
        </if>
        <if test="dto.ysxl != null and dto.ysxl != ''">
            and ysxl = #{dto.ysxl}
        </if>
        <if test="dto.ysmc != null and dto.ysmc != ''">
            and ysmc like concat('%',#{dto.ysmc},'%')
        </if>
        <if test="dto.jsnr != null and dto.jsnr != ''">
            and jsnr like concat('%',#{dto.jsnr},'%')
        </if>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
        ${useSql}
        order by xt_cjsj desc
    </select>
</mapper>


