<?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.TbJcglKfdMapper">
    <resultMap type="com.mosty.base.model.entity.jcgl.TbJcglKfd" id="resultMap">
        <result property="kfdId" column="kfd_id" jdbcType="VARCHAR"/>
        <result property="dwlx" column="dwlx" jdbcType="VARCHAR"/>
        <result property="kfdMc" column="kfd_mc" jdbcType="VARCHAR"/>
        <result property="xzqhdm" column="xzqhdm" jdbcType="VARCHAR"/>
        <result property="kfdDz" column="kfd_dz" jdbcType="VARCHAR"/>
        <result property="jd" column="jd" jdbcType="NUMERIC"/>
        <result property="wd" column="wd" jdbcType="NUMERIC"/>
        <result property="zb" column="zb" typeHandler="com.mosty.base.feign.handle.PointTypeHandler"/>
        <result property="zbhash" column="zbhash" jdbcType="VARCHAR"/>
        <result property="yfzfw" column="yfzfw" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <result property="sfzfw" column="sfzfw" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <result property="wfzfw" column="wfzfw" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <result property="kfdTp" column="znsbbs" 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="distance" column="distance" jdbcType="NUMERIC"/>
        <result property="sssgajid" column="sssgajid" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="fzrSfzh" column="fzr_sfzh" jdbcType="VARCHAR"/>
        <result property="fzrXm" column="fzr_xm" jdbcType="VARCHAR"/>
        <result property="cjsj" column="cjsj" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="base_column_list">
        kfd_id,dwlx,kfd_mc,xzqhdm,kfd_dz,jd,wd,zbhash,kfd_tp,ssbm,ssbmdm,ssxgaj,ssxgajdm,ssbmid,ssxgajid,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,fzr_sfzh,fzr_xm,cjsj
    </sql>

    <sql id="zb_sql">
        ST_ASWKT
                (zb)
                as zb,
        ST_ASWKT(yfzfw) as yfzfw,
        ST_ASWKT(sfzfw) as sfzfw,
        ST_ASWKT(wfzfw) as wfzfw
    </sql>

    <!--保存快反点信息-->
    <insert id="insertEntity" parameterType="com.mosty.base.model.entity.jcgl.TbJcglKfd">
        insert into tb_jcgl_kfd (kfd_id, dwlx, kfd_mc, xzqhdm, kfd_dz, jd, wd, zb, zbhash, yfzfw, sfzfw, wfzfw, kfd_tp,
                                 ssbm,
                                 ssbmdm, ssxgaj, ssxgajdm, ssbmid, ssxgajid, 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, fzr_sfzh, fzr_xm, cjsj)
        values (#{kfdId}, #{dwlx}, #{kfdMc}, #{xzqhdm}, #{kfdDz}, #{jd}, #{wd},
                ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.PointTypeHandler}), #{zbhash},
                ST_GEOMFROMTEXT(#{yfzfw,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
                ST_GEOMFROMTEXT(#{sfzfw,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
                ST_GEOMFROMTEXT(#{wfzfw,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
                #{kfdTp}, #{ssbm}, #{ssbmdm}, #{ssxgaj}, #{ssxgajdm}, #{ssbmid}, #{ssxgajid}, #{sssgajid},
                #{sssgaj}, #{sssgajdm}, #{xtSjly}, #{xtSjzt}, #{xtScbz}, #{xtCjip}, #{xtCjsj}, #{xtCjrId}, #{xtCjr},
                #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip},
                #{xtZhgxsj}, #{xtZhgxrid}, #{xtZhgxr}, #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz}, #{fzrSfzh}, #{fzrXm}, #{cjsj})
    </insert>

    <!--修改-->
    <update id="updateEntity" parameterType="com.mosty.base.model.entity.jcgl.TbJcglKfd">
        update tb_jcgl_kfd
        <set>
            <if test="dwlx != null and dwlx != ''">
                dwlx = #{dwlx},
            </if>
            <if test="kfdMc != null and kfdMc != ''">
                kfd_mc = #{kfdMc},
            </if>
            <if test="xzqhdm != null and xzqhdm != ''">
                xzqhdm = #{xzqhdm},
            </if>
            <if test="kfdDz != null and kfdDz != ''">
                kfd_dz = #{kfdDz},
            </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="yfzfw != null">
                yfzfw = ST_GEOMFROMTEXT(#{yfzfw,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
            </if>
            <if test="sfzfw != null">
                sfzfw = ST_GEOMFROMTEXT(#{sfzfw,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
            </if>
            <if test="wfzfw != null">
                wfzfw = ST_GEOMFROMTEXT(#{wfzfw,typeHandler = com.mosty.base.feign.handle.PolygonTypeHandler}),
            </if>
            <if test="kfdTp != null and kfdTp != ''">
                kfd_tp = #{kfdTp},
            </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="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="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="fzrSfzh != null and fzrSfzh != ''">
                fzr_sfzh = #{fzrSfzh},
            </if>

            <if test="fzrXm != null and fzrXm != ''">
                fzr_xm = #{fzrXm},
            </if>

            <if test="cjsj != null and cjsj != ''">
                cjsj = #{cjsj},
            </if>



            <if test="bz != null and bz != ''">
                bz = #{bz}
            </if>
        </set>
        where kfd_id = #{kfdId}
    </update>


    <!--查询不分页-->
    <select id="getListAll" resultMap="resultMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_jcgl_kfd 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_kfd where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.kfdMc != null and dto.kfdMc != ''">
            and kfd_mc like concat('%',#{dto.kfdMc},'%')
        </if>
        <if test="dto.kfdDz != null and dto.kfdDz != ''">
            and kfd_dz like concat('%',#{dto.kfdDz},'%')
        </if>
        <if test="dwlxList != null and dwlxList.size() > 0">
            and dwlx in
            <foreach collection="dwlxList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </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 like concat('%',#{dto.ssbmdm},'%')-->
<!--        </if>-->
<!--        <if test="dto.ssbmid != null and dto.ssbmid != ''">-->
<!--            and ssbmid like concat('%',#{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_kfd where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.kfdMc != null and dto.kfdMc != ''">
            and kfd_mc like concat('%',#{dto.kfdMc},'%')
        </if>
        <if test="dto.kfdDz != null and dto.kfdDz != ''">
            and kfd_dz like concat('%',#{dto.kfdDz},'%')
        </if>
        <if test="dwlxList != null and dwlxList.size() > 0">
            and dwlx in
            <foreach collection="dwlxList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </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 like concat('%',#{dto.ssbmdm},'%')-->
<!--        </if>-->
<!--        <if test="dto.ssbmid != null and dto.ssbmid != ''">-->
<!--            and ssbmid like concat('%',#{dto.ssbmid},'%')-->
<!--        </if>-->
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
<!--        ${useSql}-->
    </select>

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

    <!--删除快反点-->
    <update id="deleteKfd">
        delete from tb_jcgl_kfd where kfd_id in
        <foreach collection="id" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </update>
</mapper>
