<?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.sjzx.mapper.TbJqMapper">
    <resultMap type="com.mosty.base.model.entity.sjzx.TbJq" id="TbJqMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="jq110Id" column="jq110_id" jdbcType="VARCHAR"/>
        <result property="jjdbh" column="jjdbh" jdbcType="VARCHAR"/>
        <result property="jjdwbh" column="jjdwbh" jdbcType="VARCHAR"/>
        <result property="jjdwmc" column="jjdwmc" jdbcType="VARCHAR"/>
        <result property="gljjdbh" column="gljjdbh" jdbcType="VARCHAR"/>
        <result property="jjybh" column="jjybh" jdbcType="VARCHAR"/>
        <result property="jjyxm" column="jjyxm" jdbcType="VARCHAR"/>
        <result property="jjtbh" column="jjtbh" jdbcType="VARCHAR"/>
        <result property="jjtip" column="jjtip" jdbcType="VARCHAR"/>
        <result property="hrsj" column="hrsj" jdbcType="TIMESTAMP"/>
        <result property="lhlxbh" column="lhlxbh" jdbcType="VARCHAR"/>
        <result property="bjfsbh" column="bjfsbh" jdbcType="VARCHAR"/>
        <result property="bjrq" column="bjrq" jdbcType="TIMESTAMP"/>
        <result property="bjsj" column="bjsj" jdbcType="TIMESTAMP"/>
        <result property="jjsj" column="jjsj" jdbcType="TIMESTAMP"/>
        <result property="jqfsksnf" column="jqfsksnf" jdbcType="INTEGER"/>
        <result property="jqfsksyf" column="jqfsksyf" jdbcType="INTEGER"/>
        <result property="jqfsksny" column="jqfsksny" jdbcType="INTEGER"/>
        <result property="jqfskszs" column="jqfskszs" jdbcType="INTEGER"/>
        <result property="jqfsksrq" column="jqfsksrq" jdbcType="TIMESTAMP"/>
        <result property="jqfskssj" column="jqfskssj" jdbcType="TIMESTAMP"/>
        <result property="jqfsksxs" column="jqfsksxs" jdbcType="INTEGER"/>
        <result property="jqfsjssj" column="jqfsjssj" jdbcType="TIMESTAMP"/>
        <result property="hrsc" column="hrsc" jdbcType="INTEGER"/>
        <result property="jjsc" column="jjsc" jdbcType="INTEGER"/>
        <result property="jjlyh" column="jjlyh" jdbcType="VARCHAR"/>
        <result property="bjdh" column="bjdh" jdbcType="VARCHAR"/>
        <result property="bjdhYhxm" column="bjdh_yhxm" jdbcType="VARCHAR"/>
        <result property="bjdhYhdz" column="bjdh_yhdz" jdbcType="VARCHAR"/>
        <result property="bjrSfzh" column="bjr_sfzh" jdbcType="VARCHAR"/>
        <result property="bjrXm" column="bjr_xm" jdbcType="VARCHAR"/>
        <result property="bjrXb" column="bjr_xb" jdbcType="VARCHAR"/>
        <result property="bjrLxdh" column="bjr_lxdh" jdbcType="VARCHAR"/>
        <result property="bjrZzdw" column="bjr_zzdw" jdbcType="VARCHAR"/>
        <result property="sfdzxzqh" column="sfdzxzqh" jdbcType="VARCHAR"/>
        <result property="sfdz" column="sfdz" jdbcType="VARCHAR"/>
        <result property="ldgbh" column="ldgbh" jdbcType="VARCHAR"/>
        <result property="bjnr" column="bjnr" jdbcType="VARCHAR"/>
        <result property="jqjb" column="jqjb" jdbcType="VARCHAR"/>
        <result property="bjlb" column="bjlb" jdbcType="VARCHAR"/>
        <result property="bjlx" column="bjlx" jdbcType="VARCHAR"/>
        <result property="bjxl" column="bjxl" jdbcType="VARCHAR"/>
        <result property="bjxlmc" column="bjxlmc" jdbcType="VARCHAR"/>
        <result property="bjlxmc" column="bjlxmc" jdbcType="VARCHAR"/>
        <result property="bjlbmc" column="bjlbmc" jdbcType="VARCHAR"/>
        <result property="bkrs" column="bkrs" jdbcType="INTEGER"/>
        <result property="ssrs" column="ssrs" jdbcType="INTEGER"/>
        <result property="swrs" column="swrs" jdbcType="INTEGER"/>
        <result property="ywwxwz" column="ywwxwz" jdbcType="VARCHAR"/>
        <result property="ywbzxl" column="ywbzxl" jdbcType="VARCHAR"/>
        <result property="ywbkry" column="ywbkry" jdbcType="VARCHAR"/>
        <result property="sfsw" column="sfsw" jdbcType="VARCHAR"/>
        <result property="sfswybj" column="sfswybj" jdbcType="VARCHAR"/>
        <result property="sfzdjq" column="sfzdjq" jdbcType="VARCHAR"/>
        <result property="jd" column="jd" jdbcType="NUMERIC"/>
        <result property="wd" column="wd" jdbcType="NUMERIC"/>
        <result property="czzt" column="czzt" jdbcType="VARCHAR"/>
        <result property="zdjqtjlx" column="zdjqtjlx" jdbcType="VARCHAR"/>
        <result property="sfjmjq" column="sfjmjq" 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_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="color" column="color" jdbcType="VARCHAR"/>
        <result property="distance" column="distance" jdbcType="NUMERIC"/>
        <result property="zb" column="zb" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <result property="zbhash" column="zbhash" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        , jq110_id, jjdbh, jjdwbh, jjdwmc, gljjdbh, jjybh, jjyxm, jjtbh, jjtip,hrsj, lhlxbh, bjfsbh, bjrq,
        bjsj, jjsj, jqfsksnf,jqfsksyf,jqfsksny,jqfskszs,jqfsksrq,jqfskssj,jqfsksxs,jqfsjssj,hrsc, jjsc, jjlyh,
        bjdh, bjdh_yhxm, bjdh_yhdz,bjr_sfzh, bjr_xm, bjr_xb, bjr_lxdh, bjr_zzdw, sfdzxzqh, sfdz, bjnr, jqjb,
        bjlb, bjlx,bjxl, bjxlmc,bjlxmc,bjlbmc,ldgbh,bkrs, ssrs, swrs, ywwxwz, ywbzxl, ywbkry, sfsw, sfswybj,sfzdjq,
        jd, wd, czzt,zdjqtjlx,sfjmjq, 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, color
    </sql>

    <select id="getZfgkCount" resultType="Integer" parameterType="Map">
        select count(1) from tb_jq where xt_sjzt = '1' and xt_scbz = '0'
        and (bjxlmc like '%赌%' or bjlbmc like '%赌%' or bjlxmc like '%赌%')
        <if test="dto.bjnr != null and dto.bjnr != ''">
            and bjnr like concat ('%',#{dto.bjnr},'%')
        </if>
        <if test="dto.jqjb != null and dto.jqjb != ''">
            and jqjb = #{dto.jqjb}
        </if>
        <if test="dto.bjlb != null and dto.bjlb != ''">
            and bjlb = #{dto.bjlb}
        </if>
        <if test="dto.bjlx != null and dto.bjlx != ''">
            and bjlx = #{dto.bjlx}
        </if>
        <if test="dto.bjxl != null and dto.bjxl != ''">
            and bjxl = #{dto.bjxl}
        </if>
        <if test="dto.czzt != null and dto.czzt != ''">
            and czzt = #{dto.czzt}
        </if>
        <if test="dto.zdjqtjlx != null and dto.zdjqtjlx != ''">
            and zdjqtjlx = #{dto.zdjqtjlx}
        </if>
        <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''">
            and bjsj between #{dto.startTime} and #{dto.endTime}
        </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="getCount" resultType="Integer" parameterType="Map">
        select count(1) from tb_jq where  xt_scbz = '0'
        <if test="dto.bjnr != null and dto.bjnr != ''">
            and bjnr like concat ('%',#{dto.bjnr},'%')
        </if>
        <if test="dto.bjrXm != null and dto.bjrXm != ''">
            and bjr_xm like concat ('%',#{dto.bjrXm},'%')
        </if>

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


        <if test="dto.keyword != null and dto.keyword != ''">
            and (
             bjnr  like concat ('%',#{dto.keyword},'%')
             or bjr_lxdh  like concat ('%',#{dto.keyword},'%')
             or ssbm  like concat ('%',#{dto.keyword},'%')
            )
        </if>

        <if test="dto.type != null and dto.type != ''">
            <if test="dto.type == '01' ">
                and ssbm like concat ('%交%')
            </if>
            <if test="dto.type == '03' ">
                and ssbm  not like concat ('%交%') and ssbmdm not like concat (#{dto.ssbmdm},'%')
            </if>
        </if>

        <!--<if test="dto.jqjb != null and dto.jqjb != ''">
            and jqjb = #{dto.jqjb}
        </if>-->

        <if test="dto.bjlb != null and dto.bjlb != ''">
            <if test='dto.bjlb == "1"'>
                and bjlb = '01000000'
            </if>
            <if test='dto.bjlb == "2"'>
                and bjlb = '02000000'
            </if>
            <if test='dto.bjlb == "3"'>
                and bjlb = '03000000'
            </if>
            <if test='dto.bjlb == "4"'>
                and bjlb not in ('01000000','02000000','03000000')
            </if>
        </if>

        <if test="list != null and list.size() != 0">
            and jqjb in
            <foreach collection="list" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.bjlx != null and dto.bjlx != ''">
            and bjlx = #{dto.bjlx}
        </if>
        <if test="dto.bjxl != null and dto.bjxl != ''">
            and bjxl = #{dto.bjxl}
        </if>
        <if test="dto.sfzdjq != null and dto.sfzdjq != ''">
            and sfzdjq = #{dto.sfzdjq}
        </if>

        <if test="dto.sfjmjq != null and dto.sfjmjq != ''">
            and sfjmjq = #{dto.sfjmjq}
        </if>

        <if test="dto.color != null and dto.color != ''">
            and color = #{dto.color}
        </if>

        <if test="czztList != null and czztList.size() != 0">
            and czzt in
            <foreach collection="czztList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>

        <if test="bjlbList != null and bjlbList.size() != 0">
            and bjlb in
            <foreach collection="bjlbList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>

        <if test="dto.zdjqtjlx != null and dto.zdjqtjlx != ''">
            and zdjqtjlx = #{dto.zdjqtjlx}
        </if>
        <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''">
            and bjsj between #{dto.startTime} and #{dto.endTime}
        </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="getZfgkList" parameterType="Map" resultMap="TbJqMap">
        select
        <include refid="Base_Column_List"/>
        <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_jq where xt_sjzt = '1' and xt_scbz = '0'
        and (bjxlmc like '%赌%' or bjlbmc like '%赌%' or bjlxmc like '%赌%')
        <if test="dto.bjnr != null and dto.bjnr != ''">
            and bjnr like concat ('%',#{dto.bjnr},'%')
        </if>
        <if test="list != null and list.size() != 0">
            and jqjb in
            <foreach collection="list" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.bjlb != null and dto.bjlb != ''">
            <if test='dto.bjlb == "1"'>
                and bjlb = '01000000'
            </if>
            <if test='dto.bjlb == "2"'>
                and bjlb = '02000000'
            </if>
            <if test='dto.bjlb == "3"'>
                and bjlb = '03000000'
            </if>
            <if test='dto.bjlb == "4"'>
                and bjlb not in ('01000000','02000000','03000000')
            </if>
        </if>
        <if test="dto.bjlx != null and dto.bjlx != ''">
            and bjlx = #{dto.bjlx}
        </if>
        <if test="dto.bjxl != null and dto.bjxl != ''">
            and bjxl = #{dto.bjxl}
        </if>
        <if test="dto.czzt != null and dto.czzt != ''">
            and czzt = #{dto.czzt}
        </if>
        <if test="dto.zdjqtjlx != null and dto.zdjqtjlx != ''">
            and zdjqtjlx = #{dto.zdjqtjlx}
        </if>
        <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''">
            and bjsj between #{dto.startTime} and #{dto.endTime}
        </if>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
        ${useSql}
        order by bjsj desc
        limit #{pageIndex},#{pageSize}
    </select>

    <!--查询分页-->
    <select id="getListByPage" parameterType="Map" resultMap="TbJqMap">
        select
        <include refid="Base_Column_List"/>
        <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_jq where   xt_scbz = '0'
        <if test="dto.bjnr != null and dto.bjnr != ''">
            and bjnr like concat ('%',#{dto.bjnr},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != '' and dto.type != '03' ">
            and ssbmdm like concat (#{dto.ssbmdm},'%')
        </if>

        <if test="dto.keyword != null and dto.keyword != ''">
            and (
            bjnr  like concat ('%',#{dto.keyword},'%')
            or bjr_lxdh  like concat ('%',#{dto.keyword},'%')
            or ssbm  like concat ('%',#{dto.keyword},'%')
            )
        </if>

        <if test="dto.type != null and dto.type != ''">
            <if test="dto.type == '01' ">
                and ssbm like concat ('%交%')
            </if>
            <if test="dto.type == '03' ">
                and ssbm not like concat ('%交%') and ssbmdm not like concat (#{dto.ssbmdm},'%')
            </if>
        </if>

        <if test="dto.bjrXm != null and dto.bjrXm != ''">
            and bjr_xm like concat ('%',#{dto.bjrXm},'%')
        </if>
        <if test="dto.bjlb != null and dto.bjlb != ''">
            <if test='dto.bjlb == "1"'>
                and bjlb = '01000000'
            </if>
            <if test='dto.bjlb == "2"'>
                and bjlb = '02000000'
            </if>
            <if test='dto.bjlb == "3"'>
                and bjlb = '03000000'
            </if>
            <if test='dto.bjlb == "4"'>
                and bjlb not in ('01000000','02000000','03000000')
            </if>
        </if>
        <if test="dto.bjlx != null and dto.bjlx != ''">
            and bjlx = #{dto.bjlx}
        </if>
        <if test="dto.bjxl != null and dto.bjxl != ''">
            and bjxl = #{dto.bjxl}
        </if>

        <if test="dto.sfzdjq != null and dto.sfzdjq != ''   ">
            and sfzdjq = #{dto.sfzdjq}
        </if>
        <if test="dto.sfjmjq != null and dto.sfjmjq != ''">
            and sfjmjq = #{dto.sfjmjq}
        </if>
        <if test="dto.color != null and dto.color != ''">
            and color = #{dto.color}
        </if>
        <if test="czztList != null and czztList.size() != 0">
            and czzt in
            <foreach collection="czztList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.zdjqtjlx != null and dto.zdjqtjlx != ''">
            and zdjqtjlx = #{dto.zdjqtjlx}
        </if>
        <if test="list != null and list.size() != 0">
            and jqjb in
            <foreach collection="list" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>


        <if test="bjlbList != null and bjlbList.size() != 0">
            and bjlb in
            <foreach collection="bjlbList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>

        <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''">
            and bjsj between #{dto.startTime} and #{dto.endTime}
        </if>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
<!--        ${useSql}-->
        order by bjsj desc
        limit #{pageIndex},#{pageSize}
    </select>


    <select id="getList" parameterType="Map" resultMap="TbJqMap">
        select
        <include refid="Base_Column_List"/>
        <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_jq where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.bjnr != null and dto.bjnr != ''">
            and bjnr like concat ('%',#{dto.bjnr},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat (#{dto.ssbmdm},'%')
        </if>
        <if test="dto.jqjb != null and dto.jqjb != ''">
            and jqjb = #{dto.jqjb}
        </if>
        <if test="dto.bjlb != null and dto.bjlb != ''">
            and bjlb = #{dto.bjlb}
        </if>
        <if test="dto.bjlx != null and dto.bjlx != ''">
            and bjlx = #{dto.bjlx}
        </if>
        <if test="dto.bjxl != null and dto.bjxl != ''">
            and bjxl = #{dto.bjxl}
        </if>
        <if test="dto.czzt != null and dto.czzt != ''">
            and czzt = #{dto.czzt}
        </if>
        <if test="dto.zdjqtjlx != null and dto.zdjqtjlx != ''">
            and zdjqtjlx = #{dto.zdjqtjlx}
        </if>
        <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''">
            and bjsj between #{dto.startTime} and #{dto.endTime}
        </if>

        <choose>
            <when test=" bjlbList != null and bjlbList.size() != 0">
                and ( bjlb in
                <foreach collection="bjlbList" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>

                <if test="mylbList != null and  mylbList.size() != 0">
                    <foreach collection="mylbList" item="item" separator=" ">
                        or bjnr like concat ('%',#{item},'%')
                    </foreach>
                </if>
                    )
            </when>
            <otherwise>
                <if test="mylbList != null and  mylbList.size() != 0">
                    and (
                    <foreach collection="mylbList" item="item" separator=" or ">
                          bjnr like concat ('%',#{item},'%')
                    </foreach>
                    )
                </if>
            </otherwise>
        </choose>





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


    <select id="getJqHotMap" parameterType="Map" resultType="java.util.Map">
        select jd as lng,wd as lat,count(1) as count
        from tb_jq where xt_sjzt = '1' and xt_scbz = '0' and LENGTH(jd) and LENGTH(wd) >0
        <if test="dto.bjnr != null and dto.bjnr != ''">
            and bjnr like concat ('%',#{dto.bjnr},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat (#{dto.ssbmdm},'%')
        </if>
        <if test="dto.jqjb != null and dto.jqjb != ''">
            and jqjb = #{dto.jqjb}
        </if>
        <if test="dto.bjlb != null and dto.bjlb != ''">
            and bjlb = #{dto.bjlb}
        </if>
        <if test="dto.bjlx != null and dto.bjlx != ''">
            and bjlx = #{dto.bjlx}
        </if>
        <if test="dto.bjxl != null and dto.bjxl != ''">
            and bjxl = #{dto.bjxl}
        </if>
        <if test="dto.czzt != null and dto.czzt != ''">
            and czzt = #{dto.czzt}
        </if>
        <if test="dto.zdjqtjlx != null and dto.zdjqtjlx != ''">
            and zdjqtjlx = #{dto.zdjqtjlx}
        </if>
        <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''">
            and bjsj between #{dto.startTime} and #{dto.endTime}
        </if>
        <if test="bjlbList != null and bjlbList.size() != 0">
            and bjlb in
            <foreach collection="bjlbList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
        GROUP BY jd,wd
    </select>



    <update id="updateEntity" parameterType="com.mosty.base.model.entity.sjzx.TbJq">
        update tb_jq
        <set>
            <if test="jq110Id != null and jq110Id != ''">
                jq110_id = #{jq110Id},
            </if>
            <if test="jjdbh != null and jjdbh != ''">
                jjdbh = #{jjdbh},
            </if>
            <if test="jjdwbh != null and jjdwbh != ''">
                jjdwbh = #{jjdwbh},
            </if>
            <if test="jjdwmc != null and jjdwmc != ''">
                jjdwmc = #{jjdwmc},
            </if>
            <if test="gljjdbh != null and gljjdbh != ''">
                gljjdbh = #{gljjdbh},
            </if>
            <if test="jjybh != null and jjybh != ''">
                jjybh = #{jjybh},
            </if>
            <if test="jjyxm != null and jjyxm != ''">
                jjyxm = #{jjyxm},
            </if>
            <if test="jjtbh != null and jjtbh != ''">
                jjtbh = #{jjtbh},
            </if>
            <if test="jjtip != null and jjtip != ''">
                jjtip = #{jjtip},
            </if>
            <if test="hrsj != null">
                hrsj = #{hrsj},
            </if>
            <if test="lhlxbh != null and lhlxbh != ''">
                lhlxbh = #{lhlxbh},
            </if>
            <if test="bjfsbh != null and bjfsbh != ''">
                bjfsbh = #{bjfsbh},
            </if>
            <if test="bjrq != null">
                bjrq = #{bjrq},
            </if>
            <if test="bjsj != null">
                bjsj = #{bjsj},
            </if>
            <if test="jjsj != null">
                jjsj = #{jjsj},
            </if>
            <if test="jqfsksnf != null">
                jqfsksnf = #{jqfsksnf},
            </if>
            <if test="jqfsksyf != null">
                jqfsksyf = #{jqfsksyf},
            </if>
            <if test="jqfsksny != null">
                jqfsksny = #{jqfsksny},
            </if>
            <if test="jqfskszs != null">
                jqfskszs = #{jqfskszs},
            </if>
            <if test="jqfsksrq != null">
                jqfsksrq = #{jqfsksrq},
            </if>
            <if test="jqfskssj != null">
                jqfskssj = #{jqfskssj},
            </if>
            <if test="jqfsksxs != null">
                jqfsksxs = #{jqfsksxs},
            </if>
            <if test="jqfsjssj != null">
                jqfsjssj = #{jqfsjssj},
            </if>
            <if test="hrsc != null">
                hrsc = #{hrsc},
            </if>
            <if test="jjsc != null">
                jjsc = #{jjsc},
            </if>
            <if test="jjlyh != null and jjlyh != ''">
                jjlyh = #{jjlyh},
            </if>
            <if test="bjdh != null and bjdh != ''">
                bjdh = #{bjdh},
            </if>
            <if test="bjdhYhxm != null and bjdhYhxm != ''">
                bjdh_yhxm = #{bjdhYhxm},
            </if>
            <if test="bjdhYhdz != null and bjdhYhdz != ''">
                bjdh_yhdz = #{bjdhYhdz},
            </if>
            <if test="bjrSfzh != null and bjrSfzh != ''">
                bjr_sfzh = #{bjrSfzh},
            </if>
            <if test="bjrXm != null and bjrXm != ''">
                bjr_xm = #{bjrXm},
            </if>
            <if test="bjrXb != null and bjrXb != ''">
                bjr_xb = #{bjrXb},
            </if>
            <if test="bjrLxdh != null and bjrLxdh != ''">
                bjr_lxdh = #{bjrLxdh},
            </if>
            <if test="bjrZzdw != null and bjrZzdw != ''">
                bjr_zzdw = #{bjrZzdw},
            </if>
            <if test="sfdzxzqh != null and sfdzxzqh != ''">
                sfdzxzqh = #{sfdzxzqh},
            </if>
            <if test="sfdz != null and sfdz != ''">
                sfdz = #{sfdz},
            </if>
            <if test="bjnr != null and bjnr != ''">
                bjnr = #{bjnr},
            </if>
            <if test="jqjb != null and jqjb != ''">
                jqjb = #{jqjb},
            </if>
            <if test="bjlb != null and bjlb != ''">
                bjlb = #{bjlb},
            </if>
            <if test="bjlx != null and bjlx != ''">
                bjlx = #{bjlx},
            </if>
            <if test="bjxl != null and bjxl != ''">
                bjxl = #{bjxl},
            </if>
            <if test="bjxlmc != null and bjxlmc != ''">
                bjxlmc = #{bjxlmc},
            </if>
            <if test="bjlxmc != null and bjlxmc != ''">
                bjlxmc = #{bjlxmc},
            </if>
            <if test="bjlbmc != null and bjlbmc != ''">
                bjlbmc = #{bjlbmc},
            </if>
            <if test="ldgbh != null and ldgbh != ''">
                ldgbh = #{ldgbh},
            </if>
            <if test="bkrs != null">
                bkrs = #{bkrs},
            </if>
            <if test="ssrs != null">
                ssrs = #{ssrs},
            </if>
            <if test="swrs != null">
                swrs = #{swrs},
            </if>
            <if test="ywwxwz != null">
                ywwxwz = #{ywwxwz},
            </if>
            <if test="ywbzxl != null">
                ywbzxl = #{ywbzxl},
            </if>
            <if test="ywbkry != null">
                ywbkry = #{ywbkry},
            </if>
            <if test="sfsw != null">
                sfsw = #{sfsw},
            </if>
            <if test="sfswybj != null">
                sfswybj = #{sfswybj},
            </if>
            <if test="sfzdjq != null and sfzdjq != ''">
                sfzdjq = #{sfzdjq},
            </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.PolygonTypeHandler}),
            </if>
            <if test="zbhash != null and zbhash != ''">
                zbhash = #{zbhash},
            </if>
            <if test="czzt != null and czzt != ''">
                czzt = #{czzt},
            </if>
            <if test="zdjqtjlx != null and zdjqtjlx != ''">
                zdjqtjlx = #{zdjqtjlx},
            </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="color != null and color != ''">
                color = #{color},
            </if>
            <if test="bz != null and bz != ''">
                bz = #{bz}
            </if>
        </set>
        where id = #{id}
    </update>

    <!--查询单个-->
    <select id="queryById" resultMap="TbJqMap">
        select
        <include refid="Base_Column_List"/>
        from tb_jq
        where id = #{id}
    </select>

    <insert id="insertEntity" parameterType="com.mosty.base.model.entity.sjzx.TbJq">
        insert into tb_jq(id, jq110_id, jjdbh, jjdwbh, jjdwmc, gljjdbh, jjybh, jjyxm, jjtbh, jjtip, hrsj, lhlxbh,
                          bjfsbh, bjrq, bjsj, jjsj, jqfsksnf, jqfsksyf, jqfsksny, jqfskszs, jqfsksrq, jqfskssj,
                          jqfsksxs, jqfsjssj, hrsc, jjsc, jjlyh, bjdh, bjdh_yhxm, bjdh_yhdz, bjr_sfzh, bjr_xm, bjr_xb,
                          bjr_lxdh, bjr_zzdw, sfdzxzqh, sfdz, bjnr, jqjb, bjlb, bjlx, bjxl, ldgbh, bjxlmc, bjlxmc,
                          bjlbmc, bkrs, ssrs, swrs, ywwxwz, ywbzxl, ywbkry, sfsw, sfswybj, sfzdjq, jd, wd,
                          czzt, zdjqtjlx, ssbm, ssbmdm, ssxgaj, sfjmjq,
                          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, color,
                          zb, zbhash)
        values (#{id}, #{jq110Id}, #{jjdbh}, #{jjdwbh}, #{jjdwmc}, #{gljjdbh}, #{jjybh}, #{jjyxm}, #{jjtbh}, #{jjtip},
                #{hrsj}, #{lhlxbh}, #{bjfsbh}, #{bjrq}, #{bjsj}, #{jjsj}, #{jqfsksnf}, #{jqfsksyf}, #{jqfsksny},
                #{jqfskszs}, #{jqfsksrq}, #{jqfskssj}, #{jqfsksxs}, #{jqfsjssj}, #{hrsc}, #{jjsc}, #{jjlyh},
                #{bjdh}, #{bjdhYhxm}, #{bjdhYhdz}, #{bjrSfzh}, #{bjrXm}, #{bjrXb}, #{bjrLxdh}, #{bjrZzdw},
                #{sfdzxzqh}, #{sfdz}, #{bjnr}, #{jqjb}, #{bjlb}, #{bjlx}, #{bjxl}, #{ldgbh}, #{bjxlmc}, #{bjlxmc},
                #{bjlbmc}, #{bkrs}, #{ssrs}, #{swrs},
                #{ywwxwz}, #{ywbzxl}, #{ywbkry}, #{sfsw}, #{sfswybj}, #{sfzdjq}, #{jd}, #{wd},
                #{czzt}, #{zdjqtjlx}, #{ssbm}, #{ssbmdm}, #{ssxgaj}, #{sfjmjq},
                #{ssxgajdm}, #{sssgaj}, #{sssgajdm}, #{xtSjly}, #{xtSjzt}, #{xtScbz}, #{xtCjip}, #{xtCjsj}, #{xtCjrId},
                #{xtCjr}, #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip}, #{xtZhgxsj}, #{xtZhgxrid}, #{xtZhgxr}, #{xtZhgxbmdm},
                #{xtZhgxbm}, #{bz}, #{color},
                ST_GEOMFROMTEXT(#{zb,typeHandler=com.mosty.base.feign.handle.PolygonTypeHandler}),
                #{zbhash} )
    </insert>

    <!--通过主键删除-->
    <delete id="deleteById">
        update tb_jq
        set xt_scbz = '1'
        where id = #{id}
    </delete>

    <select id="getStatistics" resultType="java.util.Map">
        select bjlb, count(bjlb) count
        from tb_jq
        where xt_scbz = '0'
        and xt_sjzt = '1'
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            and bjrq &gt;= #{startTime}
            and bjrq &lt;= #{endTime}
        </if>
        <if test="bjnr != null and bjnr != ''">
            <!--and match(bjnr) against (#{bjnr})-->
            and bjnr like concat ('%',#{bjnr},'%')
        </if>
        group by bjlb
    </select>

    <select id="getYjxx30Day" resultType="java.util.Map">
        select yj_lx,jd,wd,yjbqmc,ssbmdm from mosty_yjzl.tb_yjxx a where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and jd is not null and wd is not null and yjbqmc is not null and yj_lx is not null
        <if test="kssj != null and kssj != ''">
            and a.yj_fsrq >= #{kssj}
        </if>
        <if test="jssj != null and jssj != ''">
            and a.yj_fsrq &lt;= #{jssj}
        </if>
    </select>

    <select id="getPcryList" resultType="java.util.Map">
        select jd,wd,ssbmdm from mosty_hczx.tb_hc_bpcry a where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and jd is not null and wd is not null and bqxxsj is not null
        <if test="kssj != null and kssj != ''">
            and a.pcrq >= #{kssj}
        </if>
        <if test="jssj != null and jssj != ''">
            and a.pcrq &lt;= #{jssj}
        </if>
    </select>

    <select id="getPcclList" resultType="java.util.Map">
        select jd,wd,ssbmdm from mosty_hczx.tb_hc_bpccl a where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and jd is not null and wd is not null and bqxxsj is not null
        <if test="kssj != null and kssj != ''">
            and a.pcrq >= #{kssj}
        </if>
        <if test="jssj != null and jssj != ''">
            and a.pcrq &lt;= #{jssj}
        </if>
    </select>

    <select id="getJqTj" resultType="java.util.Map">
        select count(1) count,jqfsksxs time from tb_jq where xt_sjzt = '1' and xt_scbz = '0'
        and bjxl in ("01110200", "01110300", "01120300", "01120400", "01120700", "01120800", "01121000","01130100",
                     "01140100", "01149900", "02030200", "02030300", "02030400", "02030500", "02040100", "02050100",
                     "02050400","02121700", "02130000")
        and date_format(bjrq,'%Y-%m-%d') = #{kssj}
        group by jqfsksxs order by jqfsksxs
    </select>

    <select id="getJqTjByTime" resultType="java.util.Map">
        select count(1) count,bjrq time from tb_jq  where xt_sjzt = '1' and xt_scbz = '0'
        and bjxl in ("01110200", "01110300", "01120300", "01120400", "01120700", "01120800", "01121000","01130100",
                     "01140100", "01149900", "02030200", "02030300", "02030400", "02030500", "02040100", "02050100",
                     "02050400","02121700", "02130000")
        and date_format(bjrq,'%Y-%m-%d') >= #{kssj} and date_format(bjrq,'%Y-%m-%d') &lt;= #{jssj}
        group by bjrq order by bjrq
    </select>

    <select id="getWzList" resultType="java.util.Map">
        select sum(xfsc) xfsc,sum(xflc) xflc,date_format(dwsj,'%H') time from mosty_wzzx.tb_wz_sswz a
        where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and a.dwrq = #{kssj} and ywid is not null group by date_format(dwsj,'%H')
        order by time
    </select>

    <select id="getBbList" resultType="java.util.Map">
        select sum(xfsc) xfsc,sum(xflc) xflc,date_format(xfrq,'%Y-%m-%d') time from mosty_qwgl.tb_qw_xfbb a
        where a.xt_scbz = '0' and a.xt_sjzt = '1' and a.xfrq >= #{kssj} and a.xfrq &lt;= #{jssj}
        group by xfrq
    </select>

    <select id="getPcryTj" resultType="java.util.Map">
        select count(1) count,date_format(pcsj,'%H') time from mosty_hczx.tb_hc_bpcry a
        where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and a.pcrq = #{kssj}
        group by date_format(pcsj,'%H') order by date_format(pcsj,'%H')
    </select>

    <select id="getPcclTj" resultType="java.util.Map">
        select count(1) count,date_format(pcsj,'%H') time from mosty_hczx.tb_hc_bpccl a
        where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and a.pcrq = #{kssj}
        group by date_format(pcsj,'%H') order by date_format(pcsj,'%H')
    </select>

    <select id="getPcZdryTj" resultType="java.util.Map">
        select count(1) count,date_format(pcsj,'%H') time from mosty_hczx.tb_hc_bpcry a
        where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and a.pcrq = #{kssj} and bqmc is not null
        group by date_format(pcsj,'%H') order by date_format(pcsj,'%H')
    </select>

    <select id="getPcryByTime" resultType="java.util.Map">
        select count(1) count,pcrq time from mosty_hczx.tb_hc_bpcry a
        where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and a.pcrq >= #{kssj} and a.pcrq &lt;=#{jssj}
        group by pcrq order by pcrq
    </select>

    <select id="getPcclByTime" resultType="java.util.Map">
        select count(1) count,pcrq time from mosty_hczx.tb_hc_bpccl a
        where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and a.pcrq >= #{kssj} and a.pcrq &lt;=#{jssj}
        group by pcrq order by pcrq
    </select>

    <select id="getZdryByTime" resultType="java.util.Map">
        select count(1) count,pcrq time from mosty_hczx.tb_hc_bpcry a
        where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and a.pcrq >= #{kssj} and a.pcrq &lt;=#{jssj}
        and bqmc is not null
        group by pcrq order by pcrq
    </select>

    <update id="updateJqCzzt">
        update tb_jq set czzt = #{czzt} where id = #{id}
    </update>


    <select id="selectDict" resultType="com.mosty.common.config.entity.SysDictItem">
        select *
        from mosty_base.sys_dict_item
        where zdbh = #{dictName}  and dm = #{dm}
          and xt_zxbz = '0'
    </select>

    <select id="selectJjdbh" resultType="java.lang.String">
        SELECT DISTINCT jjdbh FROM  tb_jq  WHERE xt_scbz = '0'
        <if test="jwd != null and jwd != ''">
            AND jd is null AND wd is null
        </if>
       AND DATEDIFF(bjrq, NOW()) = 0
    </select>

    <update id="updateJqJwd" parameterType="com.mosty.base.model.entity.sjzx.TbJq">
        update tb_jq
        <set>
            <if test="fxdwjd != null">
                jd = #{jd},
            </if>
            <if test="fxdwwd != null">
                wd = #{wd}
            </if>
            <if test="zb != null">
                zb = ST_GEOMFROMTEXT(#{zb,typeHandler=com.mosty.base.feign.handle.PolygonTypeHandler}),
            </if>
            <if test="zbhash != null and zbhash != ''">
                zbhash = #{zbhash},
            </if>
        </set>
        where jjdbh = #{jjdbh}
    </update>


</mapper>

