<?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.elephant.framework.galaxy.aroad.module.szgl.mapper.SzglGsdGczMapper">

    <resultMap id="szglGsdGczMap" type="com.elephant.framework.galaxy.aroad.module.szgl.entity.SzglGsdGcz">
        <id property="id" column="id"/>
        <result property="gczbh" column="gczbh"/>
        <result property="gczmc" column="gczmc"/>
        <result property="lxbh" column="lxbh"/>
        <result property="lxmc" column="lxmc"/>
        <result property="xzqh" column="xzqh"/>
        <result property="gczlx" column="gczlx"/>
        <result property="gczzh" column="gczzh"/>
        <result property="qdzh" column="qdzh"/>
        <result property="zdzh" column="zdzh"/>
        <result property="gclc" column="gclc"/>
        <result property="qdmc" column="qdmc"/>
        <result property="zdmc" column="zdmc"/>
        <result property="jsdj" column="jsdj"/>
        <result property="xcds" column="xcds"/>
        <result property="mclx" column="mclx"/>
        <result property="lmkd" column="lmkd"/>
        <result property="sjss" column="sjss"/>
        <result property="dx" column="dx"/>
        <result property="tcyf" column="tcyf"/>
        <result property="lxbm" column="lxbm"/>
        <result property="zh" column="zh"/>
        <result property="jd" column="jd"/>
        <result property="wd" column="wd"/>
        <result property="gs" column="gs"/>
        <result property="nian" column="nian"/>
        <collection property="trfList"
                    ofType="com.elephant.framework.galaxy.aroad.module.traffic.entity.TrafficRoadsection">
            <result property="spotName" column="spotName"/>
            <result property="jdcCurrentAmount" column="jdcCurrentAmount"/>
            <result property="jdcNaturalAmount" column="jdcNaturalAmount"/>
            <result property="year" column="year"/>
        </collection>
    </resultMap>
    <select id="getGczJtl" resultMap="szglGsdGczMap">
        select gcz.*,
        jtl.spot_name as spotName,
        jtl.JDC_current_amount as jdcCurrentAmount,
        jtl.JDC_natural_amount as jdcNaturalAmount,
        jtl.year
        from t_szgl_gsd_gcz gcz
        left join v_traffic_roadsection jtl
        on
        gcz.gczmc =jtl.spot_name
        and
        left(gcz.gczbh,1)  = left(jtl.spot_code,1)
        and
        right(gcz.gczbh,6) = right(jtl.spot_code,6)
        where gcz.jsdj !='高速公路'
            <if test="lxbh !=null and lxbh !=''">
              and  gcz.lxbh =#{lxbh}
            </if>
            <if test="zxzh !=null">
                and gcz.qdzh <![CDATA[ <= ]]>#{zxzh} and gcz.zdzh <![CDATA[ >= ]]>#{zxzh}
            </if>

    </select>
    <select id="getAllGcz" resultMap="szglGsdGczMap">
        select gcz.*,
        jtl.spot_name as spotName,
        jtl.JDC_current_amount as jdcCurrentAmount,
        jtl.JDC_natural_amount as jdcNaturalAmount,
        jtl.year
        from t_szgl_gsd_gcz gcz
        left join v_traffic_roadsection jtl
        on
          gcz.gczmc =jtl.spot_name
        and
          left(gcz.gczbh,1)  = left(jtl.spot_code,1)
        and
          right(gcz.gczbh,6) = right(jtl.spot_code,6)
	    WHERE
	      gcz.jsdj !='高速公路'

    </select>
    <select id="querySpotCode" resultMap="szglGsdGczMap">
		SELECT tsgg.*,
		vtr.spot_name as spotName,
        vtr.JDC_current_amount as jdcCurrentAmount,
        vtr.JDC_natural_amount as jdcNaturalAmount,
        vtr.year FROM (SELECT tsgg.* FROM `t_szgl_gsd_gcz` as tsgg where lxbh = #{lxbh} and ((qdzh between #{qdzh} and #{zdzh}) or (zdzh between #{qdzh} and #{zdzh})) ) tsgg left join v_traffic_roadsection as vtr on tsgg.gczbh = vtr.spot_code
	</select>

</mapper>
