<?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.railway.business.baseinfo.mapper.BusZzdzxxMapper">

  <resultMap id="BaseResultMap" type="com.railway.business.baseinfo.domain.BusZzdzxx">
    <result column="id" property="id"/>
    <result column="dept_id" property="deptId"/>
    <result column="dept_name" property="deptName"/>
    <result column="line_id" property="lineId"/>
    <result column="line_name" property="lineName"/>
    <result column="station_id" property="stationId"/>
    <result column="station_name" property="stationName"/>
    <result column="dept_station_id" property="deptStationId"/>
    <result column="xingbie" property="xingbie"/>
    <result column="xingbie_text" property="xingbieText"/>
    <result column="pillar_code" property="pillarCode"/>
    <result column="station_track" property="stationTrack"/>
    <result column="gxms" property="gxms"/>
    <result column="jbdydm" property="jbdydm"/>
    <result column="sd" property="sd"/>
    <result column="marker" property="marker"/>
    <result column="jcxgmdh" property="jcxgmdh"/>
    <result column="jcxgazth" property="jcxgazth"/>
    <result column="fjxgazth" property="fjxgazth"/>
    <result column="zzlx" property="zzlx"/>
    <result column="zzxh" property="zzxh"/>
    <result column="zzyt" property="zzyt"/>
    <result column="cz" property="cz"/>
    <result column="zxqwqn" property="zxqwqn"/>
    <result column="kj" property="kj"/>
    <result column="qxbj" property="qxbj"/>
    <result column="dg" property="dg"/>
    <result column="lcz" property="lcz"/>
    <result column="gmbg_scz" property="gmbgScz"/>
    <result column="gmbg_bzz" property="gmbgBzz"/>
    <result column="cmxj_scz" property="cmxjScz"/>
    <result column="cmxj_bzz" property="cmxjBzz"/>
    <result column="wgcg_scz" property="wgcgScz"/>
    <result column="wgcg_bzz" property="wgcgBzz"/>
    <result column="zzzt" property="zzzt"/>
    <result column="sccj" property="sccj"/>
    <result column="tyrq" property="tyrq"/>
    <result column="ccrq" property="ccrq"/>
    <result column="sjsm" property="sjsm"/>
    <result column="zzjczt" property="zzjczt"/>
    <result column="jclx" property="jclx"/>
    <result column="dxzt" property="dxzt"/>
    <result column="jxzq" property="jxzq"/>
    <result column="sf_sfpwjjdm" property="sfSfpwjjdm"/>
    <result column="sf_bczz" property="sfBczz"/>
    <result column="sf_fdjyq" property="sfFdjyq"/>
    <result column="sf_fxjyq" property="sfFxjyq"/>
    <result column="sf_jcxc" property="sfJcxc"/>
    <result column="sf_lxwjcxc" property="sfLxwjcxc"/>
    <result column="sf_sxwjcxc" property="sfSxwjcxc"/>
    <result column="sf_mdgjzfx" property="sfMdgjzfx"/>
    <result column="sf_hkd" property="sfHkd"/>
    <result column="sf_dlj" property="sfDlj"/>
    <result column="sf_glkg" property="sfGlkg"/>
    <result column="sf_blq" property="sfBlq"/>
    <result column="sf_dcgyzz" property="sfDcgyzz"/>
    <result column="sf_xcbzp" property="sfXcbzp"/>
    <result column="sf_jdzz" property="sfJdzz"/>
    <result column="sf_xsx" property="sfXsx"/>
    <result column="sf_hlx" property="sfHlx"/>
    <result column="sf_gwx" property="sfGwx"/>
    <result column="sf_gdx" property="sfGdx"/>
    <result column="sf_pwx" property="sfPwx"/>
    <result column="sf_sfx" property="sfSfx"/>
    <result column="sf_jqx" property="sfJqx"/>
    <result column="sf_blx" property="sfBlx"/>
    <result column="sf_lx" property="sfLx"/>
    <result column="sf_zm" property="sfZm"/>
    <result column="qt" property="qt"/>
    <result column="fj" property="fj"/>
    <result column="sl" property="sl"/>
    <result column="dw" property="dw"/>
    <result column="sjbh" property="sjbh"/>
    <result column="del_flag" property="delFlag"/>
    <result column="create_by" property="createBy"/>
    <result column="create_time" property="createTime"/>
    <result column="update_by" property="updateBy"/>
    <result column="update_time" property="updateTime"/>
  </resultMap>

  <sql id="Base_Column_List">
    t.id,
    v.dept_id,
    v.dept_name,
    v.line_id,
    v.line_name,
    v.station_name as station_name,
    v.station_id,
    t.dept_station_id,
    t.xingbie,
    t.pillar_code,
    t.station_track,
    t.sd,
    t.marker,
    t.jcxgmdh,
    t.zzlx,
    t.zzxh,
    t.zzyt,
    t.cz,
    t.zxqwqn,
    t.zzzt,
    t.tyrq,
    t.ccrq,
    t.jxzq,
    t.sjbh,
    t.del_flag,
    t.create_by,
    t.create_time,
    t.update_by,
    t.update_time
  </sql>

  <insert id="insert" parameterType="com.railway.business.baseinfo.domain.BusZzdzxx">
    INSERT INTO base_pillar
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test='null != deptStationId'>
        dept_station_id,
      </if>
      <if test='null != xingbie'>
        xingbie,
      </if>
      <if test='null != pillarCode'>
        pillar_code,
      </if>
      <if test='null != stationTrack'>
        station_track,
      </if>
      <if test='null != sd'>
        sd,
      </if>
      <if test='null != marker'>
        marker,
      </if>
      <if test='null != jcxgmdh'>
        jcxgmdh,
      </if>
      <if test='null != zzlx'>
        zzlx,
      </if>
      <if test='null != zzxh'>
        zzxh,
      </if>
      <if test='null != zzyt'>
        zzyt,
      </if>
      <if test='null != cz'>
        cz,
      </if>
      <if test='null != zxqwqn'>
        zxqwqn,
      </if>
      <if test='null != zzzt'>
        zzzt,
      </if>
      <if test='null != tyrq'>
        tyrq,
      </if>
      <if test='null != ccrq'>
        ccrq,
      </if>
      <if test='null != jxzq'>
        jxzq,
      </if>
      <if test='null != sjbh'>
        sjbh,
      </if>
      <if test='null != delFlag'>
        del_flag,
      </if>
      <if test='null != createBy'>
        create_by,
      </if>
      <if test='null != createTime'>
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test='null != deptStationId'>
        #{deptStationId},
      </if>
      <if test='null != xingbie'>
        #{xingbie},
      </if>
      <if test='null != pillarCode'>
        #{pillarCode},
      </if>
      <if test='null != stationTrack'>
        #{stationTrack},
      </if>
      <if test='null != sd'>
        #{sd},
      </if>
      <if test='null != marker'>
        #{marker},
      </if>
      <if test='null != jcxgmdh'>
        #{jcxgmdh},
      </if>
      <if test='null != zzlx'>
        #{zzlx},
      </if>
      <if test='null != zzxh'>
        #{zzxh},
      </if>
      <if test='null != zzyt'>
        #{zzyt},
      </if>
      <if test='null != cz'>
        #{cz},
      </if>
      <if test='null != zxqwqn'>
        #{zxqwqn},
      </if>
      <if test='null != zzzt'>
        #{zzzt},
      </if>
      <if test='null != tyrq'>
        #{tyrq},
      </if>
      <if test='null != ccrq'>
        #{ccrq},
      </if>
      <if test='null != jxzq'>
        #{jxzq},
      </if>
      <if test='null != sjbh'>
        #{sjbh},
      </if>
      <if test='null != delFlag'>
        #{delFlag},
      </if>
      <if test='null != createBy'>
        #{createBy},
      </if>
      <if test='null != createTime'>
        #{createTime},
      </if>
    </trim>
  </insert>

  <delete id="delete">
    UPDATE base_pillar
    set del_flag='1'
    WHERE id = #{id}
  </delete>

  <update id="update" parameterType="com.railway.business.baseinfo.domain.BusZzdzxx">
    UPDATE base_pillar
    <set>
      <if test='null != deptStationId'>dept_station_id = #{deptStationId},</if>
      <if test='null != xingbie'>xingbie = #{xingbie},</if>
      <if test='null != pillarCode'>pillar_code = #{pillarCode},</if>
      <if test='null != stationTrack'>station_track = #{stationTrack},</if>
      <if test='null != sd'>sd = #{sd},</if>
      <if test='null != marker'>marker = #{marker},</if>
      <if test='null != jcxgmdh'>jcxgmdh = #{jcxgmdh},</if>
      <if test='null != zzlx'>zzlx = #{zzlx},</if>
      <if test='null != zzxh'>zzxh = #{zzxh},</if>
      <if test='null != zzyt'>zzyt = #{zzyt},</if>
      <if test='null != cz'>cz = #{cz},</if>
      <if test='null != zxqwqn'>zxqwqn = #{zxqwqn},</if>
      <if test='null != zzzt'>zzzt = #{zzzt},</if>
      <if test='null != sccj'>sccj = #{sccj},</if>
      <if test='null != tyrq'>tyrq = #{tyrq},</if>
      <if test='null != ccrq'>ccrq = #{ccrq},</if>
      <if test='null != jxzq'>jxzq = #{jxzq},</if>
      <if test='null != sjbh'>sjbh = #{sjbh},</if>
      <if test='null != delFlag'>del_flag = #{delFlag},</if>
      <if test='null != updateBy'>update_by = #{updateBy},</if>
      <if test='null != updateTime'>update_time = #{updateTime}</if>
    </set>
    WHERE id = #{id}
  </update>


  <select id="getInfo" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, dict.dict_label as xingbie_text
    FROM base_pillar t
    LEFT JOIN v_station v on t.dept_station_id = v.dept_station_id
    LEFT JOIN sys_dict_data dict ON (t.xingbie = dict.dict_value AND dict.dict_type = 'xingbie')
    WHERE t.del_flag='0' and t.id = #{id}
    and t.marker between v.up_start_marker and v.up_end_marker
  </select>

  <select id="getList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, dict.dict_label as xingbie_text
    FROM base_pillar t
    LEFT JOIN v_station v on t.dept_station_id = v.dept_station_id
    LEFT JOIN sys_dict_data dict ON (t.xingbie = dict.dict_value AND dict.dict_type = 'xingbie')
    <where>
      t.del_flag='0'
      and t.marker between v.up_start_marker and v.up_end_marker
      <if test="stationId!=null and stationId!=''">
        and v.station_id=#{stationId}
      </if>
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
      <if test="lineId!=null and lineId!=''">
        and v.line_id=#{lineId}
      </if>
      <if test="xingbie!=null and xingbie!=''">
        and t.xingbie=#{xingbie}
      </if>
      <if test="pillarCode!=null and pillarCode!=''">
        and t.pillar_code=#{pillarCode}
      </if>
      <if test="stationTrack!=null and stationTrack!=''">
        and t.station_track=#{stationTrack}
      </if>
      <if test="sd!=null and sd!=''">
        and t.sd=#{sd}
      </if>
      <if test="marker!=null and marker!=''">
        and t.marker=#{marker}
      </if>
      <if test="jcxgmdh!=null and jcxgmdh!=''">
        and t.jcxgmdh=#{jcxgmdh}
      </if>
      <if test="zzlx!=null and zzlx!=''">
        and t.zzlx=#{zzlx}
      </if>
      <if test="zzxh!=null and zzxh!=''">
        and t.zzxh=#{zzxh}
      </if>
      <if test="zzyt!=null and zzyt!=''">
        and t.zzyt=#{zzyt}
      </if>
      <if test="cz!=null and cz!=''">
        and t.cz=#{cz}
      </if>
      <if test="zxqwqn!=null and zxqwqn!=''">
        and t.zxqwqn=#{zxqwqn}
      </if>
      <if test="zzzt!=null and zzzt!=''">
        and t.zzzt=#{zzzt}
      </if>
      <if test="tyrq!=null and tyrq!=''">
        and t.tyrq=#{tyrq}
      </if>
      <if test="ccrq!=null and ccrq!=''">
        and t.ccrq=#{ccrq}
      </if>
      <if test="jxzq!=null and jxzq!=''">
        and t.jxzq=#{jxzq}
      </if>
      <if test="sjbh!=null and sjbh!=''">
        and t.sjbh=#{sjbh}
      </if>
      <if test="delFlag!=null and delFlag!=''">
        and t.del_flag=#{delFlag}
      </if>
      <if test="createBy!=null and createBy!=''">
        and t.create_by=#{createBy}
      </if>
      <if test="createTime!=null">
        and DATE_FORMAT(t.create_time, '%Y-%m-%d') = #{createTime}
      </if>
      <if test="updateBy!=null and updateBy!=''">
        and t.update_by=#{updateBy}
      </if>
      <if test="updateTime!=null">
        and DATE_FORMAT(t.update_time, '%Y-%m-%d') = #{updateTime}
      </if>
    </where>
  </select>


  <select id="smartQuery" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, dict.dict_label as xingbie_text
    FROM base_pillar t
    left join v_station v on t.dept_station_id = v.dept_station_id
    LEFT JOIN sys_dict_data dict ON (t.xingbie = dict.dict_value AND dict.dict_type = 'xingbie')
    <where>
      t.del_flag='0'
      and t.marker between v.up_start_marker and v.up_end_marker
      <if test="stationId!=null and stationId!=''">
        and v.station_id=#{stationId}
      </if>
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
      <if test="lineId!=null and lineId!=''">
        and v.line_id=#{lineId}
      </if>
      <if test="xingbie!=null and xingbie!=''">
        and t.xingbie=#{xingbie}
      </if>
      <if test="pillarCode!=null and pillarCode!=''">
        and t.pillar_code=#{pillarCode}
      </if>
      <if test="marker!=null and marker!=''">
        and abs(t.marker - ${marker})= (
        select min(abs(t.marker - ${marker})) FROM base_pillar t
        left join v_station v on t.dept_station_id = v.dept_station_id
        where 1=1
        and t.marker between v.up_start_marker and v.up_end_marker
        <if test="stationId!=null and stationId!=''">
          and v.station_id=#{stationId}
        </if>
        <if test="deptId!=null and deptId!=''">
          and v.dept_id=#{deptId}
        </if>
        <if test="lineId!=null and lineId!=''">
          and v.line_id=#{lineId}
        </if>
        <if test="xingbie!=null and xingbie!=''">
          and t.xingbie=#{xingbie}
        </if>
        )
      </if>
    </where>
  </select>

</mapper>