<?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.BaseDeptStationMapper">

  <resultMap id="BaseResultMap" type="com.railway.business.baseinfo.domain.BaseDeptStation">
    <result column="id" property="id"/>
    <result column="station_id" property="stationId"/>
    <result column="dept_id" property="deptId"/>
    <result column="dept_name" property="deptName"/>
    <result column="qjlc" property="qjlc"/>
    <result column="up_start_marker" property="upStartMarker"/>
    <result column="up_end_marker" property="upEndMarker"/>
    <result column="down_start_marker" property="downStartMarker"/>
    <result column="down_end_marker" property="downEndMarker"/>
    <result column="dhgds" property="dhgds"/>
    <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,
    t.station_id,
    t.dept_id,
    t.qjlc,
    t.up_start_marker,
    t.up_end_marker,
    t.down_start_marker,
    t.down_end_marker,
    t.dhgds,
    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.BaseDeptStation">
    INSERT INTO base_dept_station
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test='null != deptId'>
        dept_id,
      </if>
      <if test='null != stationId'>
        station_id,
      </if>
      <if test='null != qjlc'>
        qjlc,
      </if>
      <if test='null != upStartMarker'>
        up_start_marker,
      </if>
      <if test='null != upEndMarker'>
        up_end_marker,
      </if>
      <if test='null != downStartMarker'>
        down_start_marker,
      </if>
      <if test='null != downEndMarker'>
        down_end_marker,
      </if>
      <if test='null != dhgds'>
        dhgds,
      </if>
      <if test='null != delFlag'>
        del_flag,
      </if>
      <if test='null != createBy'>
        create_by,
      </if>
      <if test='null != createTime'>
        create_time,
      </if>
      <if test='null != updateBy'>
        update_by,
      </if>
      <if test='null != updateTime'>
        update_time
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test='null != deptId'>
        #{deptId},
      </if>
      <if test='null != stationId'>
        #{stationId},
      </if>
      <if test='null != qjlc'>
        #{qjlc},
      </if>
      <if test='null != upStartMarker'>
        #{upStartMarker},
      </if>
      <if test='null != upEndMarker'>
        #{upEndMarker},
      </if>
      <if test='null != downStartMarker'>
        #{downStartMarker},
      </if>
      <if test='null != downEndMarker'>
        #{downEndMarker},
      </if>
      <if test='null != dhgds'>
        #{dhgds},
      </if>
      <if test='null != delFlag'>
        #{delFlag},
      </if>
      <if test='null != createBy'>
        #{createBy},
      </if>
      <if test='null != createTime'>
        #{createTime},
      </if>
      <if test='null != updateBy'>
        #{updateBy},
      </if>
      <if test='null != updateTime'>
        #{updateTime}
      </if>
    </trim>
  </insert>

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

  <select id="getInfo" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, d.dept_name
    FROM base_dept_station t
    LEFT JOIN sys_dept d on t.dept_id = d.dept_id
    <where>
      t.del_flag='0'
      <if test="deptId!=null and deptId!=''">
        and t.dept_id=#{deptId}
      </if>
      <if test="stationId!=null and stationId!=''">
        and t.station_id = #{stationId}
      </if>
    </where>
  </select>

  <select id="getList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, d.dept_name
    FROM base_dept_station t
    LEFT JOIN sys_dept d on t.dept_id = d.dept_id
    <where>
      t.del_flag='0'
      <if test="stationId!=null and stationId!=''">
        and t.station_id = #{stationId}
      </if>
    </where>
  </select>

</mapper>