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

  <resultMap id="BaseResultMap" type="com.railway.business.baseinfo.domain.BasePreventForeign">
    <result column="id" property="id"/>
    <result column="piecewise" property="piecewise"/>
    <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="xingbie" property="xingbie"/>
    <result column="xingbie_text" property="xingbieText"/>
    <result column="station_id" property="stationId"/>
    <result column="station_name" property="stationName"/>
    <result column="dept_station_id" property="deptStationId"/>
    <result column="pillar_code" property="pillarCode"/>
    <result column="marker" property="marker"/>
    <result column="start_marker" property="startMarker"/>
    <result column="end_marker" property="endMarker"/>
    <result column="risk_source" property="riskSource"/>
    <result column="measures" property="measures"/>
    <result column="remark" property="remark"/>
    <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.piecewise,
    v.dept_id,
    v.dept_name,
    v.line_id,
    v.line_name,
    t.xingbie,
    v.station_id,
    v.station_name,
    t.dept_station_id,
    t.pillar_code,
    t.marker,
    t.start_marker,
    t.end_marker,
    t.risk_source,
    t.measures,
    t.remark,
    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.BasePreventForeign">
    <selectKey keyProperty="id" order="AFTER" resultType="Long">
      select @@IDENTITY as id
    </selectKey>
    INSERT INTO base_prevent_foreign
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test='null != piecewise'>
        piecewise,
      </if>
      <if test='null != deptId'>
        dept_id,
      </if>
      <if test='null != deptName'>
        dept_name,
      </if>
      <if test='null != lineId'>
        line_id,
      </if>
      <if test='null != lineName'>
        line_name,
      </if>
      <if test='null != xingbie'>
        xingbie,
      </if>
      <if test='null != deptStationId'>
        dept_station_id,
      </if>
      <if test='null != stationName'>
        station_name,
      </if>
      <if test='null != pillarCode'>
        pillar_code,
      </if>
      <if test='null != marker'>
        marker,
      </if>
      <if test='null != startMarker'>
        start_marker,
      </if>
      <if test='null != endMarker'>
        end_marker,
      </if>
      <if test='null != riskSource'>
        risk_source,
      </if>
      <if test='null != measures'>
        measures,
      </if>
      <if test='null != remark'>
        remark,
      </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 != piecewise'>
        #{piecewise},
      </if>
      <if test='null != deptId'>
        #{deptId},
      </if>
      <if test='null != deptName'>
        #{deptName},
      </if>
      <if test='null != lineId'>
        #{lineId},
      </if>
      <if test='null != lineName'>
        #{lineName},
      </if>
      <if test='null != xingbie'>
        #{xingbie},
      </if>
      <if test='null != deptStationId'>
        #{deptStationId},
      </if>
      <if test='null != stationName'>
        #{stationName},
      </if>
      <if test='null != pillarCode'>
        #{pillarCode},
      </if>
      <if test='null != marker'>
        #{marker},
      </if>
      <if test='null != startMarker'>
        #{startMarker},
      </if>
      <if test='null != endMarker'>
        #{endMarker},
      </if>
      <if test='null != riskSource'>
        #{riskSource},
      </if>
      <if test='null != measures'>
        #{measures},
      </if>
      <if test='null != remark'>
        #{remark},
      </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_prevent_foreign
    set del_flag='1'
    WHERE id = #{id}
  </delete>

  <update id="update" parameterType="com.railway.business.baseinfo.domain.BasePreventForeign">
    UPDATE base_prevent_foreign
    <set>
      <if test='null != piecewise'>piecewise = #{piecewise},</if>
      <if test='null != deptId'>dept_id = #{deptId},</if>
      <if test='null != deptName'>dept_name = #{deptName},</if>
      <if test='null != lineId'>line_id = #{lineId},</if>
      <if test='null != lineName'>line_name = #{lineName},</if>
      <if test='null != xingbie'>xingbie = #{xingbie},</if>
      <if test='null != deptStationId'>dept_station_id = #{deptStationId},</if>
      <if test='null != stationName'>station_name = #{stationName},</if>
      <if test='null != pillarCode'>pillar_code = #{pillarCode},</if>
      <if test='null != marker'>marker = #{marker},</if>
      <if test='null != startMarker'>start_marker = #{startMarker},</if>
      <if test='null != endMarker'>end_marker = #{endMarker},</if>
      <if test='null != riskSource'>risk_source = #{riskSource},</if>
      <if test='null != measures'>measures = #{measures},</if>
      <if test='null != remark'>remark = #{remark},</if>
      <if test='null != delFlag'>del_flag = #{delFlag},</if>
      <if test='null != createBy'>create_by = #{createBy},</if>
      <if test='null != createTime'>create_time = #{createTime},</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,dict1.dict_label as
    piecewiseText
    FROM base_prevent_foreign 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')
    LEFT JOIN sys_dict_data dict1 ON (t.piecewise = dict1.dict_value AND dict1.dict_type =
    'piecewise')
    WHERE t.del_flag='0' and id = #{id}

  </select>

  <select id="getList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, dict.dict_label as xingbie_text,dict1.dict_label as
    piecewiseText
    FROM base_prevent_foreign 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')
    LEFT JOIN sys_dict_data dict1 ON (t.piecewise = dict1.dict_value AND dict1.dict_type =
    'piecewise')
    <where>
      t.del_flag='0'
      <if test="piecewise!=null and piecewise!=''">
        and t.piecewise=#{piecewise}
      </if>
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
      <if test="lineId!=null and lineId!=''">
        and t.line_id=#{lineId}
      </if>
      <if test="xingbie!=null and xingbie!=''">
        and t.xingbie=#{xingbie}
      </if>
      <if test="stationId!=null and stationId!=''">
        and v.station_id=#{stationId}
      </if>
      <if test="pillarCode!=null and pillarCode!=''">
        and t.pillar_code=#{pillarCode}
      </if>
      <if test="marker!=null and marker!=''">
        and t.marker=#{marker}
      </if>
      <if test="riskSource!=null and riskSource!=''">
        and t.risk_source=#{riskSource}
      </if>
      <if test="measures!=null and measures!=''">
        and t.measures=#{measures}
      </if>
      <if test="remark!=null and remark!=''">
        and t.remark=#{remark}
      </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>

</mapper>