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

  <resultMap id="BaseResultMap" type="com.railway.business.baseinfo.domain.BusDmcgyq">
    <result column="id" property="id"/>
    <result column="dept_id" property="deptId"/>
    <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_area" property="pillarArea"/>
    <result column="station_track" property="stationTrack"/>
    <result column="gxms" property="gxms"/>
    <result column="fxcs" property="fxcs"/>
    <result column="fxmc" property="fxmc"/>
    <result column="mdh" property="mdh"/>
    <result column="sbbh" property="sbbh"/>
    <result column="gzlx" property="gzlx"/>
    <result column="czlc" property="czlc"/>
    <result column="fxzxlc" property="fxzxlc"/>
    <result column="sccj" property="sccj"/>
    <result column="xh" property="xh"/>
    <result column="line_id" property="lineId"/>
    <result column="station_id" property="stationId"/>
    <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"/>
    <result column="sjbh" property="sjbh"/>
  </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_area,
    t.station_track,
    t.gxms,
    t.fxcs,
    t.fxmc,
    t.mdh,
    t.sbbh,
    t.gzlx,
    t.czlc,
    t.fxzxlc,
    t.sccj,
    t.xh,
    t.del_flag,
    t.create_by,
    t.create_time,
    t.update_by,
    t.update_time,
    t.sjbh
  </sql>

  <insert id="insert" parameterType="com.railway.business.baseinfo.domain.BusDmcgyq">
    <selectKey keyProperty="id" order="AFTER" resultType="Long">
      select @@IDENTITY as id
    </selectKey>
    INSERT INTO base_dmcgyq
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test='null != deptStationId'>
        dept_station_id,
      </if>
      <if test='null != xingbie'>
        xingbie,
      </if>
      <if test='null != pillarArea'>
        pillar_area,
      </if>
      <if test='null != stationTrack'>
        station_track,
      </if>
      <if test='null != gxms'>
        gxms,
      </if>
      <if test='null != fxcs'>
        fxcs,
      </if>
      <if test='null != fxmc'>
        fxmc,
      </if>
      <if test='null != mdh'>
        mdh,
      </if>
      <if test='null != sbbh'>
        sbbh,
      </if>
      <if test='null != gzlx'>
        gzlx,
      </if>
      <if test='null != czlc'>
        czlc,
      </if>
      <if test='null != fxzxlc'>
        fxzxlc,
      </if>
      <if test='null != sccj'>
        sccj,
      </if>
      <if test='null != xh'>
        xh,
      </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>
      <if test='null != sjbh'>
        sjbh
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test='null != stationId'>
        #{station_id},
      </if>
      <if test='null != xingbie'>
        #{xingbie},
      </if>
      <if test='null != pillarArea'>
        #{pillarArea},
      </if>
      <if test='null != stationTrack'>
        #{stationTrack},
      </if>
      <if test='null != gxms'>
        #{gxms},
      </if>
      <if test='null != fxcs'>
        #{fxcs},
      </if>
      <if test='null != fxmc'>
        #{fxmc},
      </if>
      <if test='null != mdh'>
        #{mdh},
      </if>
      <if test='null != sbbh'>
        #{sbbh},
      </if>
      <if test='null != gzlx'>
        #{gzlx},
      </if>
      <if test='null != czlc'>
        #{czlc},
      </if>
      <if test='null != fxzxlc'>
        #{fxzxlc},
      </if>
      <if test='null != sccj'>
        #{sccj},
      </if>
      <if test='null != xh'>
        #{xh},
      </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>
      <if test='null != sjbh'>
        #{sjbh}
      </if>
    </trim>
  </insert>

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

  <update id="update" parameterType="com.railway.business.baseinfo.domain.BusDmcgyq">
    UPDATE base_dmcgyq
    <set>
      <if test='null != deptStationId'>dept_station_id = #{deptStationId},</if>
      <if test='null != xingbie'>xingbie = #{xingbie},</if>
      <if test='null != pillarArea'>pillar_area = #{pillarArea},</if>
      <if test='null != stationTrack'>station_track = #{stationTrack},</if>
      <if test='null != gxms'>gxms = #{gxms},</if>
      <if test='null != fxcs'>fxcs = #{fxcs},</if>
      <if test='null != fxmc'>fxmc = #{fxmc},</if>
      <if test='null != mdh'>mdh = #{mdh},</if>
      <if test='null != sbbh'>sbbh = #{sbbh},</if>
      <if test='null != gzlx'>gzlx = #{gzlx},</if>
      <if test='null != czlc'>czlc = #{czlc},</if>
      <if test='null != fxzxlc'>fxzxlc = #{fxzxlc},</if>
      <if test='null != sccj'>sccj = #{sccj},</if>
      <if test='null != xh'>xh = #{xh},</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>
      <if test='null != sjbh'>sjbh = #{sjbh}</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_dmcgyq 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}

  </select>

  <select id="getList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, dict.dict_label as xingbie_text
    FROM base_dmcgyq 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'
      <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="stationId!=null and stationId!=''">
        and v.station_id=#{stationId}
      </if>
      <if test="xingbie!=null and xingbie!=''">
        and t.xingbie=#{xingbie}
      </if>
      <if test="pillarArea!=null and pillarArea!=''">
        and t.pillar_area=#{pillarArea}
      </if>
      <if test="stationTrack!=null and stationTrack!=''">
        and t.station_track=#{stationTrack}
      </if>
      <if test="gxms!=null and gxms!=''">
        and t.gxms=#{gxms}
      </if>
      <if test="fxcs!=null and fxcs!=''">
        and t.fxcs=#{fxcs}
      </if>
      <if test="fxmc!=null and fxmc!=''">
        and t.fxmc=#{fxmc}
      </if>
      <if test="mdh!=null and mdh!=''">
        and t.mdh=#{mdh}
      </if>
      <if test="sbbh!=null and sbbh!=''">
        and t.sbbh=#{sbbh}
      </if>
      <if test="gzlx!=null and gzlx!=''">
        and t.gzlx=#{gzlx}
      </if>
      <if test="czlc!=null and czlc!=''">
        and t.czlc=#{czlc}
      </if>
      <if test="fxzxlc!=null and fxzxlc!=''">
        and t.fxzxlc=#{fxzxlc}
      </if>
      <if test="sccj!=null and sccj!=''">
        and t.sccj=#{sccj}
      </if>
      <if test="xh!=null and xh!=''">
        and t.xh=#{xh}
      </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>
      <if test="sjbh!=null and sjbh!=''">
        and t.sjbh=#{sjbh}
      </if>
    </where>
  </select>

</mapper>