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

    <resultMap type="com.mosty.base.model.entity.jcgl.TbJcglXfqy" id="resultMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="xfqLx" column="xfq_lx" jdbcType="VARCHAR"/>
        <result property="xfqDj" column="xfq_dj" jdbcType="VARCHAR"/>
        <result property="xfqSx" column="xfq_sx" jdbcType="VARCHAR"/>
        <result property="xfqMc" column="xfq_mc" jdbcType="VARCHAR"/>
        <result property="xfqMj" column="xfq_mj" jdbcType="INTEGER"/>
        <result property="xfqFzr" column="xfq_fzr" jdbcType="VARCHAR"/>
        <result property="xfqFzrId" column="xfq_fzr_id" jdbcType="VARCHAR"/>
        <result property="xfqFzrSfz" column="xfq_fzr_sfz" jdbcType="VARCHAR"/>
        <result property="jd" column="jd" jdbcType="NUMERIC"/>
        <result property="wd" column="wd" jdbcType="NUMERIC"/>
        <result property="zxd" column="zxd" typeHandler="com.mosty.base.feign.handle.PointTypeHandler"/>
        <result property="zbhash" column="zbhash" jdbcType="VARCHAR"/>
        <result property="pgis" column="pgis" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <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="sssgajid" column="sssgajid" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="ssbmid" column="ssbmid" jdbcType="VARCHAR"/>
        <result property="xfbmlx" column="xfbmlx" jdbcType="VARCHAR"/>
        <result property="color" column="color" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="base_column_list">
        id
        , xfq_lx, xfq_dj, xfq_sx, xfq_mc, xfq_mj, xfq_fzr, xfq_fzr_id, xfq_fzr_sfz, jd, wd,
     zbhash, ssbm, ssbmdm, ssxgaj, ssxgajdm, sssgaj, sssgajdm, xt_sjly,
     xt_sjzt,ssbmid,ssxgajid,sssgajid,
     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,xfbmlx,color
    </sql>

    <sql id="zb_sql">
        ST_ASWKT
        (zxd) as zxd,
        ST_ASWKT(pgis) as pgis
    </sql>

    <!--获取详情-->
    <select id="getById" resultMap="resultMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_jcgl_xfqy where xt_sjzt = '1' and xt_scbz = '0'
        and id = #{id}
    </select>


    <!--查询不分页-->
    <select id="getListAll" resultMap="resultMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_jcgl_xfqy where xt_sjzt = '1' and xt_scbz = '0'
    </select>



    <!--查询分页-->
    <select id="getPageList" parameterType="Map" resultMap="resultMap">
        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_jcgl_xfqy where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.xfqLx != null and dto.xfqLx != ''">
            and xfq_lx = #{dto.xfqLx}
        </if>
        <if test="dto.xfqDj != null and dto.xfqDj != ''">
            and xfq_dj = #{dto.xfqDj}
        </if>
        <if test="dto.xfqSx != null and dto.xfqSx != ''">
            and xfq_sx = #{dto.xfqSx}
        </if>
        <if test="dto.xfqMc != null and dto.xfqMc != ''">
            and xfq_mc like concat('%',#{dto.xfqMc},'%')
        </if>
        <if test="dto.xfqFzr != null and dto.xfqFzr != ''">
            and xfq_fzr like concat('%',#{dto.xfqFzr},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat(#{dto.ssbmdm},'%')
        </if>
<!--        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">-->
<!--            and ssbmdm = #{dto.ssbmdm}-->
<!--        </if>-->
<!--        <if test="dto.ssbmid != null and dto.ssbmid != ''">-->
<!--            and ssbmid = #{dto.ssbmid}-->
<!--        </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="getCount" parameterType="Map" resultType="Integer">
        select count(1) from tb_jcgl_xfqy where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.xfqLx != null and dto.xfqLx != ''">
            and xfq_lx = #{dto.xfqLx}
        </if>
        <if test="dto.xfqDj != null and dto.xfqDj != ''">
            and xfq_dj = #{dto.xfqDj}
        </if>
        <if test="dto.xfqSx != null and dto.xfqSx != ''">
            and xfq_sx = #{dto.xfqSx}
        </if>
        <if test="dto.xfqMc != null and dto.xfqMc != ''">
            and xfq_mc like concat('%',#{dto.xfqMc},'%')
        </if>
        <if test="dto.xfqFzr != null and dto.xfqFzr != ''">
            and xfq_fzr like concat('%',#{dto.xfqFzr},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat(#{dto.ssbmdm},'%')
        </if>
<!--        <if test="dto.ssbmid != null and dto.ssbmid != ''">-->
<!--            and ssbmid = #{dto.ssbmid}-->
<!--        </if>-->
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
<!--        ${useSql}-->
    </select>

    <insert id="insertEntity" parameterType="com.mosty.base.model.entity.jcgl.TbJcglXfqy">
        insert into tb_jcgl_xfqy(id, xfq_lx, xfq_dj, xfq_sx, xfq_mc, xfq_mj, xfq_fzr, xfq_fzr_id, xfq_fzr_sfz, jd, wd,
                                 zxd, pgis, zbhash, ssbmid,ssxgajid,sssgajid,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,xfbmlx,color)
        values (#{id}, #{xfqLx}, #{xfqDj}, #{xfqSx}, #{xfqMc}, #{xfqMj}, #{xfqFzr}, #{xfqFzrId}, #{xfqFzrSfz}, #{jd}, #{wd},
                ST_GEOMFROMTEXT(#{zxd, typeHandler = com.mosty.base.feign.handle.PointTypeHandler}),
                ST_GEOMFROMTEXT(#{pgis,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
                #{zbhash},#{ssbmid},#{ssxgajid},#{sssgajid},
                #{ssbm}, #{ssbmdm}, #{ssxgaj}, #{ssxgajdm}, #{sssgaj}, #{sssgajdm}, #{xtSjly}, #{xtSjzt},
                #{xtScbz}, #{xtCjip}, #{xtCjsj}, #{xtCjrId}, #{xtCjr}, #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip},
                #{xtZhgxsj},
                #{xtZhgxrid}, #{xtZhgxr}, #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz}, #{xfbmlx}, #{color})
    </insert>

    <!--修改-->
    <update id="updateEntity" parameterType="com.mosty.base.model.entity.jcgl.TbJcglXfqy">
        update tb_jcgl_xfqy
        <set>
            <if test="xfqLx != null and xfqLx != ''">
                xfq_lx = #{xfqLx},
            </if>
            <if test="xfqDj != null and xfqDj != ''">
                xfq_dj = #{xfqDj},
            </if>
            <if test="xfqSx != null and xfqSx != ''">
                xfq_sx = #{xfqSx},
            </if>
            <if test="xfqMc != null and xfqMc != ''">
                xfq_mc = #{xfqMc},
            </if>
            <if test="xfqMj != null and xfqMj != ''">
                xfq_mj = #{xfqMj},
            </if>
            <if test="xfqFzr != null and xfqFzr != ''">
                xfq_fzr = #{xfqFzr},
            </if>
            <if test="xfqFzrId != null and xfqFzrId != ''">
                xfq_fzr_id = #{xfqFzrId},
            </if>
            <if test="xfqFzrSfz != null and xfqFzrSfz != ''">
                xfq_fzr_sfz = #{xfqFzrSfz},
            </if>
            <if test="jd != null">
                jd = #{jd},
            </if>
            <if test="wd != null">
                wd = #{wd},
            </if>
            <if test="zxd != null">
                zxd = ST_GEOMFROMTEXT(#{zxd,typeHandler=com.mosty.base.feign.handle.PointTypeHandler}),
            </if>
            <if test="zbhash != null and zbhash != ''">
                zbhash = #{zbhash},
            </if>
            <if test="pgis != null">
                pgis = ST_GEOMFROMTEXT(#{pgis,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
            </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="xfbmlx != null and xfbmlx != ''">
                xfbmlx = #{xfbmlx},
            </if>
            <if test="color != null and color != ''">
                color = #{color},
            </if>
            <if test="bz != null and bz != ''">
                bz = #{bz}
            </if>
        </set>
        where id = #{id}
    </update>

    <!--批量删除-->
    <update id="deleteBatch">
        delete from tb_jcgl_xfqy where id in
        <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>

    <select id="getSfzs" resultType="java.util.Map">
        select count(1) count,ssxgaj, ssxgajid from tb_jcgl_xfqy where xt_sjzt = '1' and xt_scbz = '0'
        group by ssxgajid, ssxgaj
    </select>

    <select id="getSfzd" resultType="java.util.Map">
        select
        sum(CHAR_LENGTH(xffwid) - CHAR_LENGTH(REPLACE(xffwid,',','')) + 1) as count, date_format(xfrq,'%H') time
        from mosty_qwgl.tb_qw_xfbb where xfrq = #{kssj}
        and xt_sjzt = '1' and xt_scbz = '0'
        and xffwlx = '1'
        group by date_format(xfrq,'%H') order by date_format(xfrq,'%H')
    </select>

    <select id="getJqTj" resultType="java.util.Map">
        select count(1) count,jqfsksxs time from mosty_sjzx.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 mosty_sjzx.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>

<!--    xfrq -->
    <select id="getXfzdByTime" resultType="java.util.Map">
        select
        sum(CHAR_LENGTH(xffwid) - CHAR_LENGTH(REPLACE(xffwid,',','')) + 1) as count, xfrq time
        from mosty_qwgl.tb_qw_xfbb where date_format(xfrq,'%Y-%m-%d') >= #{kssj} and date_format(xfrq,'%Y-%m-%d') &lt;= #{jssj}
        and xt_sjzt = '1' and xt_scbz = '0'
        and xffwlx = '1'
        group by xfrq order by xfrq
    </select>

</mapper>
