<?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.TpjcglZnzbMapper">

    <resultMap type="com.mosty.base.model.vo.jcgl.TbJcglZnzbVo" id="resultMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="sbImei" column="sb_imei" jdbcType="VARCHAR"/>
        <result property="sbbh" column="sbbh" jdbcType="VARCHAR"/>
        <result property="sbmc" column="sbmc" jdbcType="VARCHAR"/>
        <result property="scode" column="scode" jdbcType="VARCHAR"/>
        <result property="sname" column="sname" jdbcType="VARCHAR"/>
        <result property="sbIpv4" column="sb_ipv4" jdbcType="VARCHAR"/>
        <result property="sbIpv6" column="sb_ipv6" jdbcType="VARCHAR"/>
        <result property="sbMac" column="sb_mac" jdbcType="VARCHAR"/>
        <result property="sccs" column="sccs" jdbcType="VARCHAR"/>
        <result property="cgrq" column="cgrq" jdbcType="TIMESTAMP"/>
        <result property="dqsj" column="dqsj" jdbcType="TIMESTAMP"/>
        <result property="zbTp" column="zb_tp" jdbcType="VARCHAR"/>
        <result property="zbzt" column="zbzt" jdbcType="VARCHAR"/>
        <result property="sftx" column="sftx" 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="bz" column="bz" jdbcType="VARCHAR"/>
        <result property="distance" column="distance" jdbcType="NUMERIC"/>
        <result property="jd" column="jd" jdbcType="NUMERIC"/>
        <result property="wd" column="wd" jdbcType="NUMERIC"/>
        <result property="sssgajid" column="sssgajid" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="ssbmid" column="ssbmid" jdbcType="VARCHAR"/>
    </resultMap>


    <update id="deleteZb">
        update tb_jcgl_znzb set xt_scbz = '1' where id in
        <foreach collection="id" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <!--条件查询智能装备列表-->
    <select id="getFjzbCount" parameterType="Map" resultType="Integer">
        select count(1)
        from mosty_jcgl.tb_jcgl_znzb a,
        (
        select d.ssbmdm, c.jd, c.wd
        from mosty_yszx.tb_ys_gajg c,
        mosty_yszx.tb_ys_gajg_glbm d
        where c.ysdl = '001'
        and c.yszl = '001001'
        and c.ysxl in ('001001002', '001001003', '001001004')
        and d.xt_scbz = '0'
        and d.xt_sjzt = '1'
        and c.id = d.gajg_id
        and c.xt_scbz = '0'
        and c.xt_sjzt = '1'
        <if test="dto.radius != null">
            <![CDATA[and st_distance_sphere(POINT(c.jd,c.wd),POINT(#{dto.jd},#{dto.wd})) <= #{dto.radius}]]>
        </if>
        ) f
        where a.ssbmdm = f.ssbmdm
        and a.xt_scbz = '0'
        and a.xt_sjzt = '1'
        <if test="ssbmdm != null and ssbmdm != ''">
            and a.ssbmdm = #{dto.ssbmdm}
        </if>
    </select>

    <!--条件查询智能装备列表-->
    <select id="getFjzbList" parameterType="Map" resultMap="resultMap">
        select a.*, f.jd, f.wd
        <if test="dto.jd != null and dto.wd != null">
            ,st_distance_sphere(POINT(f.jd,f.wd),POINT(#{dto.jd},#{dto.wd})) as distance
        </if>
        from mosty_jcgl.tb_jcgl_znzb a,
        (
        select d.ssbmdm, c.jd, c.wd
        from mosty_yszx.tb_ys_gajg c,
        mosty_yszx.tb_ys_gajg_glbm d
        where c.ysdl = '001'
        and c.yszl = '001001'
        and c.ysxl in ('001001002', '001001003', '001001004')
        and d.xt_scbz = '0'
        and d.xt_sjzt = '1'
        and c.id = d.gajg_id
        and c.xt_scbz = '0'
        and c.xt_sjzt = '1'
        <if test="dto.radius != null">
            <![CDATA[and st_distance_sphere(POINT(c.jd,c.wd),POINT(#{dto.jd},#{dto.wd})) <= #{dto.radius}]]>
        </if>
        ) f
        where a.ssbmdm = f.ssbmdm
        and a.xt_scbz = '0'
        and a.xt_sjzt = '1'
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and a.ssbmdm = #{dto.ssbmdm}
        </if>
        <if test="dto.ssbmid != null and dto.ssbmid != ''">
            and a.ssbmid = #{dto.ssbmid}
        </if>
        <if test="dto.sfzy != null and dto.sfzy != ''">
            and a.sfzy = #{dto.sfzy}
        </if>
        <if test="dto.sfrh != null and dto.sfrh != ''">
            and a.sfrh = #{dto.sfrh}
        </if>
        <if test="dto.jd != null and dto.wd != null">
            order by distance
        </if>
        limit #{pageIndex},#{pageSize}
    </select>

    <select id="sblxTj" resultType="java.util.Map">
        SELECT scode,IFNULL(SUM(sl),0)  sl,IFNULL(SUM(xfs),0) xfs,IFNULL(SUM(bss),0) bss
        FROM `tb_jcgl_jyqx`
        WHERE xfid is NULL  and xt_scbz = '0'
        <if test="ssbmdm != null and ssbmdm != null">
            AND ssbmdm like concat(#{ssbmdm},'%')
        </if>
        GROUP BY scode
    </select>

    <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="znlxTj" resultType="java.util.Map">
        SELECT COUNT(1) sl,scode
        FROM `tb_jcgl_znzb`
        WHERE xfid is NULL   and xt_scbz = '0' and sfbs is null
        <if test="ssbmdm != null and ssbmdm != null">
            AND ssbmdm like concat(#{ssbmdm},'%')
        </if>
        <if test="scode != null and scode != null">
            AND scode like concat(#{scode},'%')
        </if>
        GROUP BY scode
    </select>

</mapper>
