<?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.mapper.GajgSearchMapper">

<!--    映射  property实体类 column数据库字段-->
    <resultMap type="com.mosty.base.model.entity.yszx.TbYsGajg" id="tbYsGajg">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="ysdl" column="ysdl" jdbcType="VARCHAR"/>
        <result property="yszl" column="yszl" jdbcType="VARCHAR"/>
        <result property="ysxl" column="ysxl" jdbcType="VARCHAR"/>
        <result property="gajgmc" column="gajgmc" jdbcType="VARCHAR"/>
        <result property="gajgjc" column="gajgjc" jdbcType="VARCHAR"/>
        <result property="wzXzqh" column="wz_xzqh" jdbcType="VARCHAR"/>
        <result property="wzXz" column="wz_xz" jdbcType="VARCHAR"/>
        <result property="wzBc" column="wz_bc" 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="dtm" column="dtm" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <result property="dtm1" column="dtm1" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <result property="dtm2" column="dtm2" typeHandler="com.mosty.base.feign.handle.PolygonTypeHandler"/>
        <result property="lybm" column="lybm" jdbcType="VARCHAR"/>
        <result property="lyid" column="lyid" jdbcType="VARCHAR"/>
        <result property="jsnr" column="jsnr" 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="sssgajid" column="sssgajid" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="ssbmid" column="ssbmid" jdbcType="VARCHAR"/>
    </resultMap>

<!--    公共sql 全部字段-->
    <sql id="base_column_list">
        id
        ,ysdl,yszl,ysxl,gajgmc,gajgjc,wz_xzqh,wz_xz,wz_bc,jd,wd,ssbmid,ssxgajid,sssgajid,
        zbhash,lybm,lyid,jsnr,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
    </sql>

<!--    公共sql 面 , 业务层转成了point点：jd、wd-->
    <sql id="zb_sql">
        ST_ASWKT
                (zb)
                as zb,
        ST_ASWKT(dtm) as dtm,
        ST_ASWKT(dtm1) as dtm1,
        ST_ASWKT(dtm2) as dtm2
    </sql>

    <!-- 从子表中关联查询到公安机关主键Id -->
    <select id="getGajgFromGlbl" resultType="String">
        select gajg_id from mosty_yszx.tb_ys_gajg_glbm where ssbmid = #{ssbmid} and
        xt_scbz = '0' and xt_sjzt = '1'
        limit 1
    </select>

<!--    引用映射 通过主表查询全部信息-->
    <select id="getGajg" resultMap="tbYsGajg">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from mosty_yszx.tb_ys_gajg where ssbmid = #{ssbmid}
        and (ysxl = '001001003' or ysxl = '001001004') and xt_scbz = '0' and xt_sjzt = '1'
        limit 1
    </select>

    <!--    引用映射 通过子表查询全部信息-->
    <select id="getGajgById" resultMap="tbYsGajg">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from mosty_yszx.tb_ys_gajg where xt_scbz = '0' and xt_sjzt = '1'
        and id = #{id}
    </select>
</mapper>


