<?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.TbYsSxtMapper">
    <resultMap type="com.mosty.base.model.entity.yszx.TbYsSxt" id="tbYsSxt">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="sjlyid" column="sjlyid" jdbcType="VARCHAR"/>
        <result property="jkdbgbh" column="jkdbgbh" jdbcType="VARCHAR"/>
        <result property="sbbh" column="sbbh" jdbcType="VARCHAR"/>
        <result property="sbmc" column="sbmc" jdbcType="VARCHAR"/>
        <result property="csmc" column="csmc" jdbcType="VARCHAR"/>
        <result property="ipdz" column="ipdz" jdbcType="VARCHAR"/>
        <result property="ipv6dz" column="ipv6dz" jdbcType="VARCHAR"/>
        <result property="jd" column="jd" jdbcType="NUMERIC"/>
        <result property="wd" column="wd" jdbcType="NUMERIC"/>
        <result property="xzqhdm" column="xzqhdm" jdbcType="VARCHAR"/>
        <result property="dzmc" column="dzmc" jdbcType="VARCHAR"/>
        <result property="sblxdm" column="sblxdm" jdbcType="VARCHAR"/>
        <result property="sjlxdm" column="sjlxdm" jdbcType="VARCHAR"/>
        <result property="jsfxdm" column="jsfxdm" jdbcType="VARCHAR"/>
        <result property="jsqysm" column="jsqysm" jdbcType="VARCHAR"/>
        <result property="sxjwzlxdm" column="sxjwzlxdm" jdbcType="VARCHAR"/>
        <result property="sxjytdm" column="sxjytdm" jdbcType="VARCHAR"/>
        <result property="sbzt" column="sbzt" jdbcType="VARCHAR"/>
        <result property="sblx" column="sblx" 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="sssgajid" column="sssgajid" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="ssbmid" column="ssbmid" 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_cjbmmc" 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"/>
    </resultMap>

    <sql id="base_column_list">

                id
                ,sjlyid, jkdbgbh,sbbh,sbmc,csmc,ipdz,ipv6dz,jd,wd,xzqhdm,dzmc,sblxdm,sjlxdm,jsfxdm,jsqysm,sxjwzlxdm,sxjytdm,
                sbzt,sblx,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,ssbmid,ssxgajid,sssgajid

    </sql>


    <!--查询摄像头列表总数-->
    <select id="getCount" resultType="Integer" parameterType="Map">
        select count(1) from tb_ys_sxt where xt_sjzt = '1' and xt_scbz = '0'
        and jd is not null and wd is not null
        <if test="dto.sbbh != null and dto.sbbh != ''">
            and sbbh like concat('%',#{dto.sbbh},'%')
        </if>
        <if test="dto.sbmc != null and dto.sbmc != ''">
            and sbmc like concat('%',#{dto.sbmc},'%')
        </if>
        <if test="dto.sblxdm != null and dto.sblxdm != ''">
            and sblxdm = #{dto.sblxdm}
        </if>
        <if test="dto.sbzt != null and dto.sbzt != ''">
            and sbzt = #{dto.sbzt}
        </if>
        <if test="dto.sblx != null and dto.sblx != ''">
            and sblx = #{dto.sblx}
        </if>
        <if test="dto.jsnr != null and dto.jsnr != ''">
            and jsnr like concat('%', #{dto.jsnr},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat(#{dto.ssbmdm},'%')
        </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>
    </select>

    <!--查询分页-->
    <select id="getPageList" parameterType="Map" resultMap="tbYsSxt">
        select
        <include refid="base_column_list"/>
        <if test="dto.jd != null and dto.wd != null">
            ,st_distance_sphere(POINT(jd,wd),POINT(#{dto.jd},#{dto.wd})) as distance
        </if>
        from tb_ys_sxt where xt_sjzt = '1' and xt_scbz = '0'
        and jd is not null and wd is not null
        <if test="dto.sbbh != null and dto.sbbh != ''">
            and sbbh like concat('%',#{dto.sbbh},'%')
        </if>
        <if test="dto.sbmc != null and dto.sbmc != ''">
            and sbmc like concat('%',#{dto.sbmc},'%')
        </if>
        <if test="dto.sblxdm != null and dto.sblxdm != ''">
            and sblxdm = #{dto.sblxdm}
        </if>
        <if test="dto.sbzt != null and dto.sbzt != ''">
            and sbzt = #{dto.sbzt}
        </if>
        <if test="dto.sblx != null and dto.sblx != ''">
            and sblx = #{dto.sblx}
        </if>
        <if test="dto.jsnr != null and dto.jsnr != ''">
            and jsnr like concat('%', #{dto.jsnr},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat(#{dto.ssbmdm},'%')
        </if>

        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
        <if test="dto.jd != null and dto.wd != null ">
            order by distance asc
        </if>
        limit #{pageIndex},#{pageSize}
    </select>

    <!--查询不分页-->
    <select id="getList" parameterType="Map" resultMap="tbYsSxt">
        select
        <include refid="base_column_list"/>
        <if test="dto.jd != null and dto.wd != null">
            ,st_distance_sphere(POINT(jd,wd),POINT(#{dto.jd},#{dto.wd})) as distance
        </if>
        from tb_ys_sxt where xt_sjzt = '1' and xt_scbz = '0'
        and jd is not null and wd is not null
        <if test="dto.sbbh != null and dto.sbbh != ''">
            and sbbh like concat('%',#{dto.sbbh},'%')
        </if>
        <if test="dto.sbmc != null and dto.sbmc != ''">
            and sbmc like concat('%',#{dto.sbmc},'%')
        </if>
        <if test="dto.sblxdm != null and dto.sblxdm != ''">
            and sblxdm = #{dto.sblxdm}
        </if>
        <if test="dto.sbzt != null and dto.sbzt != ''">
            and sbzt = #{dto.sbzt}
        </if>
        <if test="dto.sblx != null and dto.sblx != ''">
            and sblx = #{dto.sblx}
        </if>
        <if test="dto.jsnr != null and dto.jsnr != ''">
            and jsnr like concat('%', #{dto.jsnr},'%')
        </if>

        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat(#{dto.ssbmdm},'%')
        </if>


        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
        <if test="dto.jd != null and dto.wd != null">
            order by distance asc
        </if>
    </select>

    <!--获取公安机关详情-->
    <select id="getInfoById" resultMap="tbYsSxt">
        select
        <include refid="base_column_list"/>
        from tb_ys_sxt where xt_sjzt = '1' and xt_scbz = '0'
        and id = #{id}
    </select>

    <select id="queryBySjlyid" resultMap="tbYsSxt">
        select
        <include refid="base_column_list"/>
        from tb_ys_sxt where xt_sjzt = '1' and xt_scbz = '0'
        and sjlyid = #{sjlyid} limit 0,1
    </select>

    <insert id="insertEntity" parameterType="com.mosty.base.model.entity.yszx.TbYsSxt">

                insert into tb_ys_sxt(id, sjlyid, jkdbgbh, sbbh, sbmc, csmc, ipdz, ipv6dz, jd, wd,
                                    xzqhdm, dzmc, sblxdm, sjlxdm, jsfxdm, jsqysm, sxjwzlxdm, sxjytdm, sbzt, sblx,
                                      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,ssbmid,ssxgajid,sssgajid)
                values (#{id}, #{sjlyid}, #{jkdbgbh}, #{sbbh}, #{sbmc}, #{csmc}, #{ipdz}, #{ipv6dz}, #{jd}, #{wd},
                        #{xzqhdm},
                        #{dzmc}, #{sblxdm}, #{sjlxdm}, #{jsfxdm}, #{jsqysm}, #{sxjwzlxdm}, #{sxjytdm}, #{sbzt}, #{sblx},
                        #{jsnr}, #{ssbm}, #{ssbmdm}, #{ssxgaj}, #{ssxgajdm}, #{sssgaj}, #{sssgajdm}, #{xtSjly}, #{xtSjzt},
                        #{xtScbz}, #{xtCjip}, #{xtCjsj}, #{xtCjrId}, #{xtCjr}, #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip},
                        #{xtZhgxsj},
                        #{xtZhgxrid}, #{xtZhgxr}, #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz},#{ssbmid},#{ssxgajid},#{sssgajid})

    </insert>

    <!--修改公安机关要素-->
    <update id="updateEntity" parameterType="com.mosty.base.model.entity.yszx.TbYsSxt">
        update tb_ys_sxt
        <set>
            <if test="sjlyid != null and sjlyid != ''">
                sjlyid = #{sjlyid},
            </if>
            <if test="jkdbgbh != null and jkdbgbh != ''">
                jkdbgbh = #{jkdbgbh},
            </if>
            <if test="sbbh != null and sbbh != ''">
                sbbh = #{sbbh},
            </if>
            <if test="sbmc != null and sbmc != ''">
                sbmc = #{sbmc},
            </if>
            <if test="csmc != null and csmc != ''">
                csmc = #{csmc},
            </if>
            <if test="ipdz != null and ipdz != ''">
                ipdz = #{ipdz},
            </if>
            <if test="ipv6dz != null and ipv6dz != ''">
                ipv6dz = #{ipv6dz},
            </if>
            <if test="jd != null">
                jd = #{jd},
            </if>
            <if test="wd != null">
                wd = #{wd},
            </if>
            <if test="xzqhdm != null and xzqhdm != ''">
                xzqhdm = #{xzqhdm},
            </if>
            <if test="dzmc != null and dzmc != ''">
                dzmc = #{dzmc},
            </if>
            <if test="sblxdm != null and sblxdm != ''">
                sblxdm = #{sblxdm},
            </if>
            <if test="sjlxdm != null and sjlxdm != ''">
                sjlxdm = #{sjlxdm},
            </if>
            <if test="jsfxdm != null and jsfxdm != ''">
                jsfxdm = #{jsfxdm},
            </if>
            <if test="jsqysm != null and jsqysm != ''">
                jsqysm = #{jsqysm},
            </if>
            <if test="sxjwzlxdm != null and sxjwzlxdm != ''">
                sxjwzlxdm = #{sxjwzlxdm},
            </if>
            <if test="sxjytdm != null and sxjytdm != ''">
                sxjytdm = #{sxjytdm},
            </if>
            <if test="sbzt != null and sbzt != ''">
                sbzt = #{sbzt},
            </if>
            <if test="sblx != null and sblx != ''">
                sblx = #{sblx},
            </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="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>
            <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>
        </set>
        where id = #{id}
    </update>

    <select id="getSjList" parameterType="Map" resultMap="tbYsSxt">
        select
        <include refid="base_column_list"/>
        <if test="jd != null and wd != null ">
            ,st_distance_sphere(POINT(jd,wd),POINT(#{jd},#{wd})) as distance
        </if>
        from tb_ys_sxt where xt_sjzt = '1' and xt_scbz = '0'
        order by distance asc
        limit 0,3
    </select>

    <delete id="deleteAll">
            delete from tb_ys_sxt
    </delete>
</mapper>


