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

    <resultMap type="com.mosty.base.model.entity.yjzl.TbFzycXljl" id="TbWzXfwzMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="xlbbId" column="xlbb_id" jdbcType="VARCHAR"/>
        <result property="fzyjyczlId" column="fzyjyczl_id" jdbcType="VARCHAR"/>
        <result property="xlkssj" column="xlkssj" jdbcType="TIMESTAMP"/>
        <result property="xljssj" column="xljssj" jdbcType="TIMESTAMP"/>

         <result property="xfsc" column="xfsc" jdbcType="INTEGER"/>
        <result property="xflc" column="xflc" jdbcType="INTEGER"/>
        <result property="dqjd" column="dqjd" jdbcType="NUMERIC"/>
        <result property="dqwd" column="dqwd" jdbcType="NUMERIC"/>
        <result property="zxJl" column="zxJl" jdbcType="NUMERIC"/>

        <result property="zb" column="zb" typeHandler="com.mosty.base.feign.handle.LineStringTypeHandler"/>
        <result property="ssbm" column="ssbm" jdbcType="VARCHAR"/>
        <result property="ssbmid" column="ssbmid" jdbcType="VARCHAR"/>
        <result property="ssbmdm" column="ssbmdm" jdbcType="VARCHAR"/>
        <result property="ssxgaj" column="ssxgaj" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="ssxgajdm" column="ssxgajdm" jdbcType="VARCHAR"/>
        <result property="sssgaj" column="sssgaj" jdbcType="VARCHAR"/>
        <result property="sssgajid" column="sssgajid" 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="TIMESTAMP"/>
        <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="TIMESTAMP"/>
        <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="xzmc" column="xzmc" jdbcType="VARCHAR"/>
    </resultMap>


    <sql id="base_column_list">
       id, xlbb_id, fzyjyczl_id, xlkssj, xljssj,
         dqjd, dqwd, zx_jl, ssbm, ssbmdm, ssbmid, ssxgaj, ssxgajdm,
        ssxgajid, sssgaj, sssgajdm, sssgajid, 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, xfsc, xflc, xzmc
    </sql>

    <sql id="zb_sql">
        ST_ASWKT
        (zb) as zb
    </sql>

    <!--新增所有列-->
    <insert id="insertEntity" keyProperty="id" useGeneratedKeys="true">
        insert into tb_fzyc_xljl(id, xlbb_id, fzyjyczl_id, xlkssj, xljssj,
         dqjd, dqwd, zx_jl, ssbm, ssbmdm, ssbmid, ssxgaj, ssxgajdm,
        ssxgajid, sssgaj, sssgajdm, sssgajid, 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, xfsc, xflc, zb, xzmc)
        values (#{id}, #{xlbbId}, #{fzyjyczlId}, #{xlkssj}, #{xljssj},
         #{dqjd}, #{dqwd}, #{zxJl}, #{ssbm}, #{ssbmdm}, #{ssbmid}, #{ssxgaj}, #{ssxgajdm},
         #{ssxgajid}, #{sssgaj}, #{sssgajdm}, #{sssgajid}, #{xtSjly}, #{xtSjzt}, #{xtScbz}, #{xtCjip},
          #{xtCjsj}, #{xtCjrId}, #{xtCjr}, #{xtCjbmdm},
         #{xtCjbmmc}, #{xtZhgxip},#{xtZhgxsj}, #{xtZhgxrid}, #{xtZhgxr}, #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz}, #{xfsc}, #{xflc},
         ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.LineStringTypeHandler}), #{xzmc})
    </insert>


    <!--通过主键修改数据-->
    <update id="updateEntity">
        update tb_fzyc_xljl
        <set>
            <if test="xlbbId != null and xlbbId != ''">
                xlbb_id = #{xlbbId},
            </if>
            <if test="fzyjyczlId != null and fzyjyczlId != ''">
                fzyjyczl_id = #{fzyjyczlId},
            </if>
            <if test="xlkssj != null">
                xlkssj = #{xlkssj},
            </if>
            <if test="xljssj != null">
                xljssj = #{xljssj},
            </if>
            <if test="dqjd != null">
                dqjd = #{dqjd},
            </if>
            <if test="dqwd != null">
                dqwd = #{dqwd},
            </if>
            <if test="zb != null">
                zb = ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.LineStringTypeHandler}),
            </if>

            <if test="zxJl != null">
                zx_jl = #{zxJl},
            </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="xfsc != null">
                xfsc = #{xfsc},
            </if>
            <if test="xflc != null">
                xflc = #{xflc},
            </if>
            <if test="xzmc != null and xzmc != ''">
                xzmc = #{xzmc},
            </if>
            <if test="bz != null and bz != ''">
                bz = #{bz}
            </if>
        </set>
        where id = #{id}
    </update>

    <select id="selectByFzBb" resultMap="TbWzXfwzMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_fzyc_xljl
        where xt_scbz = '0'
        <if test="xlbbId != null and xlbbId != ''">
          and   xlbb_id = #{xlbbId}
        </if>
        <if test="fzyjyczlId != null and fzyjyczlId != ''">
          and   fzyjyczl_id = #{fzyjyczlId}
        </if>
        order by xt_cjsj desc
        limit 1
    </select>

    <select id="qfzxl" resultMap="TbWzXfwzMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_fzyc_xljl
        where xt_scbz = '0'
        <if test="fzyjyczlId != null and fzyjyczlId != ''">
            and   fzyjyczl_id = #{fzyjyczlId}
        </if>
        order by xljssj desc

    </select>

    <select id="pcrys" resultType="java.lang.Integer">
         SELECT COUNT(1) FROM mosty_hczx.tb_hc_bpcry where  xt_scbz = '0'
        <if test="bbid != null and bbid != ''">
            and   bbid = #{bbid}
        </if>
    </select>

    <select id="pccls" resultType="java.lang.Integer">
         SELECT COUNT(1) FROM mosty_hczx.tb_hc_bpccl where  xt_scbz = '0'
        <if test="bbid != null and bbid != ''">
            and   bbid = #{bbid}
        </if>
    </select>
</mapper>
