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

  <resultMap id="BaseResultMap" type="com.railway.business.baseinfo.domain.vo.BaseLineVo">
    <result column="line_id" property="lineId"/>
    <result column="line_name" property="lineName"/>
    <result column="line_sddj" property="lineSddj"/>
    <result column="line_type" property="lineType"/>
    <result column="line_dj" property="lineDj"/>
    <result column="line_yylc" property="lineYylc"/>
    <result column="start_marker" property="startMarker"/>
    <result column="end_marker" property="endMarker"/>
    <result column="order_num" property="orderNum"/>
    <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.line_id,
    t.line_name,
    t.line_sddj,
    t.line_type,
    t.line_dj,
    t.line_yylc,
    t.start_marker,
    t.end_marker,
    t.order_num,
    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.BaseLine">
    <selectKey keyProperty="lineId" order="AFTER" resultType="Long">
      select @@IDENTITY as line_id
    </selectKey>
    INSERT INTO base_line
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test='null != lineName'>
        line_name,
      </if>
      <if test='null != lineSddj'>
        line_sddj,
      </if>
      <if test='null != lineType'>
        line_type,
      </if>
      <if test='null != lineDj'>
        line_dj,
      </if>
      <if test='null != lineYylc'>
        line_yylc,
      </if>
      <if test='null != startMarker'>
        start_marker,
      </if>
      <if test='null != endMarker'>
        end_marker,
      </if>
      <if test='null != orderNum'>
        order_num,
      </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 != lineName'>
        #{lineName},
      </if>
      <if test='null != lineSddj'>
        #{lineSddj},
      </if>
      <if test='null != lineType'>
        #{lineType},
      </if>
      <if test='null != lineDj'>
        #{lineDj},
      </if>
      <if test='null != lineYylc'>
        #{lineYylc},
      </if>
      <if test='null != startMarker'>
        #{startMarker},
      </if>
      <if test='null != endMarker'>
        #{endMarker},
      </if>
      <if test='null != orderNum'>
        #{orderNum},
      </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_line
    set del_flag='1'
    WHERE line_id = #{lineId}
  </delete>

  <update id="update" parameterType="com.railway.business.baseinfo.domain.BaseLine">
    UPDATE base_line
    <set>
      <if test='null != lineName'>line_name = #{lineName},</if>
      <if test='null != lineSddj'>line_sddj = #{lineSddj},</if>
      <if test='null != lineType'>line_type = #{lineType},</if>
      <if test='null != lineDj'>line_dj = #{lineDj},</if>
      <if test='null != lineYylc'>line_yylc = #{lineYylc},</if>
      <if test='null != startMarker'>start_marker = #{startMarker},</if>
      <if test='null != endMarker'>end_marker = #{endMarker},</if>
      <if test='null != orderNum'>order_num = #{orderNum},</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 line_id = #{lineId}
  </update>


  <select id="getInfo" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>
    FROM base_line t
    left join v_line v on t.line_id = v.line_id
    WHERE t.del_flag='0' and t.line_id = #{lineId}

  </select>

  <select id="getList" resultMap="BaseResultMap">
    SELECT DISTINCT
    <include refid="Base_Column_List"/>
    FROM base_line t
    left join v_line v on t.line_id = v.line_id
    <where>
      t.del_flag='0'
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
      <if test="lineName!=null and lineName!=''">
        and t.line_name like concat('%', #{lineName}, '%')
      </if>
    </where>
  </select>

  <select id="getListByDeptId" resultMap="BaseResultMap">
    SELECT DISTINCT
    <include refid="Base_Column_List"/>
    FROM base_line t
    left join v_line v on t.line_id = v.line_id
    <where>
      t.del_flag='0'
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
    </where>
  </select>

</mapper>