<?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.base.manager.mapper.TbJcglBxdMapper">
    <!--批量删除-->
    <update id="deleteBatch">
        delete from tb_jcgl_bxd where id in
        <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <insert id="insertExtity">
        insert into tb_jcgl_bxd (id, ss_xfqy_id, bxd_mc, bxd_lx, yxq, jd, wd, zb, zbhash,
                                 xxdz, bxd_tp, xzqhdm, bxdlydm, ssbmid, ssbm, ssbmdm, ssxgajid, ssxgaj,
                                 ssxgajdm, sssgajid, 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}, #{ssXfqyId}, #{bxdMc}, #{bxdLx}, #{yxq}, #{jd}, #{wd},
                ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.PointTypeHandler}), #{zbhash},
                #{xxdz}, #{bxdTp}, #{xzqhdm}, #{bxdlydm}, #{ssbmid}, #{ssbm}, #{ssbmdm}, #{ssxgajid}, #{ssxgaj},
                #{ssxgajdm}, #{sssgajid}, #{sssgaj}, #{sssgajdm}, #{xtSjly}, #{xtSjzt}, #{xtScbz}, #{xtCjip}, #{xtCjsj},
                #{xtCjrId}, #{xtCjr}, #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip}, #{xtZhgxsj}, #{xtZhgxrid}, #{xtZhgxr},
                #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz})
    </insert>

    <update id="updateEntity">
        update tb_jcgl_bxd
        <set>
            <if test="ssXfqyId != null and ssXfqyId != ''">
                ss_xfqy_id = #{ssXfqyId},
            </if>
            <if test="bxdMc != null and bxdMc    != ''">
                bxd_mc = #{bxdMc},
            </if>
            <if test="bxdLx != null and bxdLx != ''">
                bxd_lx = #{bxdLx},
            </if>
            <if test="yxq != null">
                yxq = #{yxq},
            </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="xxdz != null and xxdz != ''">
                xxdz = #{xxdz},
            </if>
            <if test="bxdTp != null and bxdTp != ''">
                bxd_tp = #{bxdTp},
            </if>
            <if test="xzqhdm != null and xzqhdm != ''">
                xzqhdm = #{xzqhdm},
            </if>
            <if test="bxdlydm != null and bxdlydm != ''">
                bxdlydm = #{bxdlydm},
            </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>

    <update id="updateYesterdayBxd">
        update tb_jcgl_bxd
        set xt_sjzt = '0'
        where bxdlydm = '03'
    </update>

    <!--查询周边巡组或街面巡组数量-->
    <select id="selectNearbyList" resultType="com.mosty.base.model.entity.jcgl.TbJcglBxd" parameterType="com.mosty.base.model.query.jcgl.TbJcglBxdNearByQuery">
        select * from tb_jcgl_bxd
        where xt_scbz = '0'
          and xt_sjzt = '1'
          and <![CDATA[ st_distance_sphere(POINT(jd,wd),POINT(#{jd},#{wd})) <= #{radius}]]>
        <if test="bxdMc != null and bxdMc != ''">
        and bxd_mc like concat('%',#{bxdMc},'%')
    </if>
        <if test="bxdLxList != null and bxdLxList.length > 0">
            and bxd_lx in
            <foreach collection="bxdLxList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="ssbmdm != null and ssbmdm != ''">
            and ssbmdm like concat(#{ssbmdm},'%')
        </if>
    </select>

</mapper>
