<?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.catenary.mapper.BusJcebXsjcjlMapper">

  <resultMap id="BaseResultMap" type="com.railway.business.catenary.domain.BusJcebXsjcjl">
    <result column="id" property="id"/>
    <result column="station_id" property="stationId"/>
    <result column="station_name" property="stationName"/>
    <result column="dept_station_id" property="deptStationId"/>
    <result column="operation_date" property="operationDate"/>
    <result column="xsjcfs" property="xsjcfs"/>
    <result column="qxdd" property="qxdd"/>
    <result column="qxnr" property="qxnr"/>
    <result column="qxdj" property="qxdj"/>
    <result column="yqwcsj" property="yqwcsj"/>
    <result column="operator" property="operator"/>
    <result column="clcs" property="clcs"/>
    <result column="cljg" property="cljg"/>
    <result column="clqxldr" property="clqxldr"/>
    <result column="clqxczz" property="clqxczz"/>
    <result column="clrq" property="clrq"/>
    <result column="remark" property="remark"/>
    <result column="submit_state" property="submitState"/>
    <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="user_id" property="userId"/>
    <result column="del_flag" property="delFlag"/>
  </resultMap>

  <sql id="Base_Column_List">
    t.id,
    v.station_name as station_name,
    v.station_id,
    t.dept_station_id,
    t.operation_date,
    t.xsjcfs,
    t.qxdd,
    t.qxnr,
    t.qxdj,
    t.yqwcsj,
    t.operator,
    t.clcs,
    t.cljg,
    t.clqxldr,
    t.clqxczz,
    t.clrq,
    t.remark,
    t.submit_state,
    t.create_by,
    t.create_time,
    t.update_by,
    t.update_time,
    t.user_id,
    t.del_flag
  </sql>

  <insert id="insert" parameterType="com.railway.business.catenary.domain.BusJcebXsjcjl">
    INSERT INTO bus_jceb_xsjcjl
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test='null != deptStationId'>
        dept_station_id,
      </if>
      <if test='null != operationDate'>
        operation_date,
      </if>
      <if test='null != xsjcfs'>
        xsjcfs,
      </if>
      <if test='null != qxdd'>
        qxdd,
      </if>
      <if test='null != qxnr'>
        qxnr,
      </if>
      <if test='null != qxdj'>
        qxdj,
      </if>
      <if test='null != yqwcsj'>
        yqwcsj,
      </if>
      <if test='null != operator'>
        operator,
      </if>
      <if test='null != clcs'>
        clcs,
      </if>
      <if test='null != cljg'>
        cljg,
      </if>
      <if test='null != clqxldr'>
        clqxldr,
      </if>
      <if test='null != clqxczz'>
        clqxczz,
      </if>
      <if test='null != clrq'>
        clrq,
      </if>
      <if test='null != remark'>
        remark,
      </if>
      <if test='null != submitState'>
        submit_state,
      </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 != userId'>
        user_id,
      </if>
      <if test='null != delFlag'>
        del_flag
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test='null != deptStationId'>
        #{deptStationId},
      </if>
      <if test='null != operationDate'>
        #{operationDate},
      </if>
      <if test='null != xsjcfs'>
        #{xsjcfs},
      </if>
      <if test='null != qxdd'>
        #{qxdd},
      </if>
      <if test='null != qxnr'>
        #{qxnr},
      </if>
      <if test='null != qxdj'>
        #{qxdj},
      </if>
      <if test='null != yqwcsj'>
        #{yqwcsj},
      </if>
      <if test='null != operator'>
        #{operator},
      </if>
      <if test='null != clcs'>
        #{clcs},
      </if>
      <if test='null != cljg'>
        #{cljg},
      </if>
      <if test='null != clqxldr'>
        #{clqxldr},
      </if>
      <if test='null != clqxczz'>
        #{clqxczz},
      </if>
      <if test='null != clrq'>
        #{clrq},
      </if>
      <if test='null != remark'>
        #{remark},
      </if>
      <if test='null != submitState'>
        #{submitState},
      </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 != userId'>
        #{userId},
      </if>
      <if test='null != delFlag'>
        #{delFlag}
      </if>
    </trim>
  </insert>

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

  <update id="update" parameterType="com.railway.business.catenary.domain.BusJcebXsjcjl">
    UPDATE bus_jceb_xsjcjl
    <set>
      <if test='null != deptStationId'>dept_station_id = #{deptStationId},</if>
      <if test='null != operationDate'>operation_date = #{operationDate},</if>
      <if test='null != xsjcfs'>xsjcfs = #{xsjcfs},</if>
      <if test='null != qxdd'>qxdd = #{qxdd},</if>
      <if test='null != qxnr'>qxnr = #{qxnr},</if>
      <if test='null != qxdj'>qxdj = #{qxdj},</if>
      <if test='null != yqwcsj'>yqwcsj = #{yqwcsj},</if>
      <if test='null != operator'>operator = #{operator},</if>
      <if test='null != clcs'>clcs = #{clcs},</if>
      <if test='null != cljg'>cljg = #{cljg},</if>
      <if test='null != clqxldr'>clqxldr = #{clqxldr},</if>
      <if test='null != clqxczz'>clqxczz = #{clqxczz},</if>
      <if test='null != clrq'>clrq = #{clrq},</if>
      <if test='null != remark'>remark = #{remark},</if>
      <if test='null != submitState'>submit_state = #{submitState},</if>
      <if test='null != updateBy'>update_by = #{updateBy},</if>
      <if test='null != updateTime'>update_time = #{updateTime},</if>
      <if test='null != userId'>user_id = #{userId},</if>
      <if test='null != delFlag'>del_flag = #{delFlag}</if>
    </set>
    WHERE id = #{id}
  </update>


  <select id="getInfo" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>
    FROM bus_jceb_xsjcjl t
    LEFT JOIN v_station v on t.dept_station_id = v.dept_station_id
    WHERE t.del_flag='0' and t.id = #{id}
  </select>

  <select id="getList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>
    FROM bus_jceb_xsjcjl t
    LEFT JOIN v_station v on t.dept_station_id = v.dept_station_id
    <where>
      t.del_flag='0'
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
      <if test="stationId!=null and stationId!=''">
        and v.station_id=#{stationId}
      </if>
      <if test="stationIds!=null and stationIds.length > 0">
        and v.station_id in
        <foreach collection="stationIds" item="stationId" index="i" open="(" separator="," close=")">
          #{stationId}
        </foreach>
      </if>
      <if test="operationDate!=null">
        and t.operation_date=#{operationDate}
      </if>
      <if test="xsjcfs!=null and xsjcfs!=''">
        and t.xsjcfs=#{xsjcfs}
      </if>
      <if test="qxdd!=null and qxdd!=''">
        and t.qxdd=#{qxdd}
      </if>
      <if test="qxnr!=null and qxnr!=''">
        and t.qxnr=#{qxnr}
      </if>
      <if test="qxdj!=null and qxdj!=''">
        and t.qxdj=#{qxdj}
      </if>
      <if test="yqwcsj!=null and yqwcsj!=''">
        and t.yqwcsj=#{yqwcsj}
      </if>
      <if test="operator!=null and operator!=''">
        and t.operator like concat('%', #{operator}, '%')
      </if>
      <if test="clcs!=null and clcs!=''">
        and t.clcs=#{clcs}
      </if>
      <if test="cljg!=null and cljg!=''">
        and t.cljg=#{cljg}
      </if>
      <if test="clqxldr!=null and clqxldr!=''">
        and t.clqxldr=#{clqxldr}
      </if>
      <if test="clqxczz!=null and clqxczz!=''">
        and t.clqxczz=#{clqxczz}
      </if>
      <if test="clrq!=null and clrq!=''">
        and t.clrq=#{clrq}
      </if>
      <if test="remark!=null and remark!=''">
        and t.remark=#{remark}
      </if>
      <if test="submitState!=null and submitState!=''">
        and t.submit_state <![CDATA[ >= ]]> #{submitState}
      </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="userId!=null and userId!=''">
        and t.user_id=#{userId}
      </if>
      <if test="delFlag!=null and delFlag!=''">
        and t.del_flag=#{delFlag}
      </if>
    </where>
    <if test="orderBy!=null and orderBy!=''">
      order by t.${orderBy}
    </if>
    <if test="isAsc!=null and isAsc!=''">
      <if test="isAsc == '1'.toString()">
        asc
      </if>
      <if test="isAsc == '0'.toString()">
        desc
      </if>
    </if>
  </select>

  <select id="getJcebList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>
    FROM bus_jceb_xsjcjl t
    LEFT JOIN v_station v on t.dept_station_id = v.dept_station_id
    <where>
      t.del_flag='0'
      <if test="submitState!=null and submitState!=''">
        and t.submit_state <![CDATA[ >= ]]> #{submitState}
      </if>
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
      <if test="stationId!=null and stationId!=''">
        and v.station_id=#{stationId}
      </if>
      <if test="stationIds!=null and stationIds.length > 0">
        and v.station_id in
        <foreach collection="stationIds" item="stationId" index="i" open="(" separator="," close=")">
          #{stationId}
        </foreach>
      </if>
      <if test="pillarCode!=null and pillarCode!=''">
        and t.pillar_start=#{pillarCode}
      </if>
      <if test="operator!=null and operator!=''">
        and t.operator like concat('%', #{operator}, '%')
      </if>
      <if test="createBy!=null and createBy!=''">
        and t.create_by=#{createBy}
      </if>
    </where>
  </select>

  <resultMap id="JcebResultMap" type="com.railway.business.catenary.domain.vo.JcebRecordVo">
    <result column="id" property="id"/>
    <result column="dept_name" property="deptName"/>
    <result column="station_name" property="stationName"/>
    <result column="operation_date" property="operationDate"/>
    <result column="operator" property="operator"/>
    <result column="jcebType" property="jcebType"/>
  </resultMap>

  <select id="getListByType" resultMap="JcebResultMap">
    SELECT t.id, v.dept_name, v.station_name, t.operation_date, t.operator, #{jcebType} as jcebType
    FROM bus_jceb_xsjcjl t
    LEFT JOIN v_station v on t.dept_station_id = v.dept_station_id
    <where>
      t.del_flag='0'
      <if test="submitState!=null and submitState!=''">
        and t.submit_state <![CDATA[ >= ]]> #{submitState}
      </if>
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
      <if test="stationId!=null and stationId!=''">
        and v.station_id=#{stationId}
      </if>
      <if test="stationIds!=null and stationIds.length > 0">
        and v.station_id in
        <foreach collection="stationIds" item="stationId" index="i" open="(" separator="," close=")">
          #{stationId}
        </foreach>
      </if>
      <if test="pillarCode!=null and pillarCode!=''">
        and t.pillar_start=#{pillarCode}
      </if>
      <if test="operator!=null and operator!=''">
        and t.operator like concat('%', #{operator}, '%')
      </if>
      <if test="createBy!=null and createBy!=''">
        and t.create_by=#{createBy}
      </if>
    </where>
  </select>

  <resultMap id="JcebCountResultMap" type="com.railway.business.catenary.domain.vo.JcebCountVo">
    <result column="c" property="count"/>
    <result column="operation_date" property="operationDate"/>
  </resultMap>

  <select id="getCountByType" resultMap="JcebCountResultMap">
    SELECT count(*) c, max(t.operation_date) as operation_date
    FROM bus_jceb_xsjcjl t
    LEFT JOIN v_station v on t.dept_station_id = v.dept_station_id
    <where>
      t.del_flag='0'
      <if test="submitState!=null and submitState!=''">
        and t.submit_state <![CDATA[ >= ]]> #{submitState}
      </if>
      <if test="deptId!=null and deptId!=''">
        and v.dept_id=#{deptId}
      </if>
      <if test="stationId!=null and stationId!=''">
        and v.station_id=#{stationId}
      </if>
      <if test="pillarCode!=null and pillarCode!=''">
        and t.pillar_start=#{pillarCode}
      </if>
      <if test="operator!=null and operator!=''">
        and t.operator like concat('%', #{operator}, '%')
      </if>
      <if test="createBy!=null and createBy!=''">
        and t.create_by=#{createBy}
      </if>
    </where>
  </select>

</mapper>