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

  <resultMap id="BaseResultMap" type="com.railway.business.catenary.domain.BusJcbDmcgyq">
    <result column="id" property="id"/>
    <result column="gyq_id" property="gyqId"/>
    <result column="dept_id" property="deptId"/>
    <result column="dept_name" property="deptName"/>
    <result column="station_id" property="stationId"/>
    <result column="station_name" property="stationName"/>
    <result column="dept_station_id" property="deptStationId"/>
    <result column="fenxiang" property="fenxiang"/>
    <result column="xingbie" property="xingbie"/>
    <result column="xingbie_text" property="xingbieText"/>
    <result column="pillar_area" property="pillarArea"/>
    <result column="tianqi" property="tianqi"/>
    <result column="temperature" property="temperature"/>
    <result column="check_date" property="checkDate"/>
    <result column="dgqwg_azlg" property="dgqwgAzlg"/>
    <result column="dgqwg_wzws" property="dgqwgWzws"/>
    <result column="dgqwg_bmqj" property="dgqwgBmqj"/>
    <result column="dgqwg_azlg_gzms" property="dgqwgAzlgGzms"/>
    <result column="dgqwg_wzws_gzms" property="dgqwgWzwsGzms"/>
    <result column="dgqwg_bmqj_gzms" property="dgqwgBmqjGzms"/>
    <result column="bspwg_bsqx" property="bspwgBsqx"/>
    <result column="bspwg_bsqx_gzms" property="bspwgBsqxGzms"/>
    <result column="bspwg_azlg" property="bspwgAzlg"/>
    <result column="bspwg_azlg_gzms" property="bspwgAzlgGzms"/>
    <result column="dgqcl_g1" property="dgqclG1"/>
    <result column="dgqcl_g2" property="dgqclG2"/>
    <result column="dgqcl_g3" property="dgqclG3"/>
    <result column="dgqcl_g4" property="dgqclG4"/>
    <result column="sbzt" property="sbzt"/>
    <result column="check_user" property="checkUser"/>
    <result column="confirm_user" property="confirmUser"/>
    <result column="czwt" property="czwt"/>
    <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"/>
  </resultMap>

  <sql id="Base_Column_List">
    t.id,
    t.gyq_id,
    v.dept_id,
    v.dept_name,
    v.station_name as station_name,
    v.station_id,
    t.dept_station_id,
    t.fenxiang,
    t.xingbie,
    t.pillar_area,
    t.tianqi,
    t.temperature,
    t.check_date,
    t.dgqwg_azlg,
    t.dgqwg_wzws,
    t.dgqwg_bmqj,
    t.dgqwg_azlg_gzms,
    t.dgqwg_wzws_gzms,
    t.dgqwg_bmqj_gzms,
    t.bspwg_bsqx,
    t.bspwg_bsqx_gzms,
    t.bspwg_azlg,
    t.bspwg_azlg_gzms,
    t.dgqcl_g1,
    t.dgqcl_g2,
    t.dgqcl_g3,
    t.dgqcl_g4,
    t.sbzt,
    t.check_user,
    t.confirm_user,
    t.czwt,
    t.submit_state,
    t.create_by,
    t.create_time,
    t.update_by,
    t.update_time,
    t.user_id
  </sql>

  <insert id="insert" parameterType="com.railway.business.catenary.domain.BusJcbDmcgyq">
    INSERT INTO bus_jcb_dmcgyq
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test='null != gyqId'>
        gyq_id,
      </if>
      <if test='null != deptStationId'>
        dept_station_id,
      </if>
      <if test='null != fenxiang'>
        fenxiang,
      </if>
      <if test='null != xingbie'>
        xingbie,
      </if>
      <if test='null != pillarArea'>
        pillar_area,
      </if>
      <if test='null != tianqi'>
        tianqi,
      </if>
      <if test='null != temperature'>
        temperature,
      </if>
      <if test='null != checkDate'>
        check_date,
      </if>
      <if test='null != dgqwgAzlg'>
        dgqwg_azlg,
      </if>
      <if test='null != dgqwgWzws'>
        dgqwg_wzws,
      </if>
      <if test='null != dgqwgBmqj'>
        dgqwg_bmqj,
      </if>
      <if test='null != dgqwgAzlgGzms'>
        dgqwg_azlg_gzms,
      </if>
      <if test='null != dgqwgWzwsGzms'>
        dgqwg_wzws_gzms,
      </if>
      <if test='null != dgqwgBmqjGzms'>
        dgqwg_bmqj_gzms,
      </if>
      <if test='null != bspwgBsqx'>
        bspwg_bsqx,
      </if>
      <if test='null != bspwgBsqxGzms'>
        bspwg_bsqx_gzms,
      </if>
      <if test='null != bspwgAzlg'>
        bspwg_azlg,
      </if>
      <if test='null != bspwgAzlgGzms'>
        bspwg_azlg_gzms,
      </if>
      <if test='null != dgqclG1'>
        dgqcl_g1,
      </if>
      <if test='null != dgqclG2'>
        dgqcl_g2,
      </if>
      <if test='null != dgqclG3'>
        dgqcl_g3,
      </if>
      <if test='null != dgqclG4'>
        dgqcl_g4,
      </if>
      <if test='null != sbzt'>
        sbzt,
      </if>
      <if test='null != checkUser'>
        check_user,
      </if>
      <if test='null != czwt'>
        czwt,
      </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>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test='null != gyqId'>
        #{gyqId},
      </if>
      <if test='null != deptStationId'>
        #{deptStationId},
      </if>
      <if test='null != fenxiang'>
        #{fenxiang},
      </if>
      <if test='null != xingbie'>
        #{xingbie},
      </if>
      <if test='null != pillarArea'>
        #{pillarArea},
      </if>
      <if test='null != tianqi'>
        #{tianqi},
      </if>
      <if test='null != temperature'>
        #{temperature},
      </if>
      <if test='null != checkDate'>
        #{checkDate},
      </if>
      <if test='null != dgqwgAzlg'>
        #{dgqwgAzlg},
      </if>
      <if test='null != dgqwgWzws'>
        #{dgqwgWzws},
      </if>
      <if test='null != dgqwgBmqj'>
        #{dgqwgBmqj},
      </if>
      <if test='null != dgqwgAzlgGzms'>
        #{dgqwgAzlgGzms},
      </if>
      <if test='null != dgqwgWzwsGzms'>
        #{dgqwgWzwsGzms},
      </if>
      <if test='null != dgqwgBmqjGzms'>
        #{dgqwgBmqjGzms},
      </if>
      <if test='null != bspwgBsqx'>
        #{bspwgBsqx},
      </if>
      <if test='null != bspwgBsqxGzms'>
        #{bspwgBsqxGzms},
      </if>
      <if test='null != bspwgAzlg'>
        #{bspwgAzlg},
      </if>
      <if test='null != bspwgAzlgGzms'>
        #{bspwgAzlgGzms},
      </if>
      <if test='null != dgqclG1'>
        #{dgqclG1},
      </if>
      <if test='null != dgqclG2'>
        #{dgqclG2},
      </if>
      <if test='null != dgqclG3'>
        #{dgqclG3},
      </if>
      <if test='null != dgqclG4'>
        #{dgqclG4},
      </if>
      <if test='null != sbzt'>
        #{sbzt},
      </if>
      <if test='null != checkUser'>
        #{checkUser},
      </if>
      <if test='null != czwt'>
        #{czwt},
      </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>
    </trim>
  </insert>

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

  <update id="update" parameterType="com.railway.business.catenary.domain.BusJcbDmcgyq">
    UPDATE bus_jcb_dmcgyq
    <set>
      <if test='null != gyqId'>dept_station_id = #{gyqId},</if>
      <if test='null != deptStationId'>dept_station_id = #{deptStationId},</if>
      <if test='null != fenxiang'>fenxiang = #{fenxiang},</if>
      <if test='null != xingbie'>xingbie = #{xingbie},</if>
      <if test='null != pillarArea'>pillar_area = #{pillarArea},</if>
      <if test='null != tianqi'>tianqi = #{tianqi},</if>
      <if test='null != temperature'>temperature = #{temperature},</if>
      <if test='null != checkDate'>check_date = #{checkDate},</if>
      <if test='null != dgqwgAzlg'>dgqwg_azlg = #{dgqwgAzlg},</if>
      <if test='null != dgqwgWzws'>dgqwg_wzws = #{dgqwgWzws},</if>
      <if test='null != dgqwgBmqj'>dgqwg_bmqj = #{dgqwgBmqj},</if>
      <if test='null != dgqwgAzlgGzms'>dgqwg_azlg_gzms = #{dgqwgAzlgGzms},</if>
      <if test='null != dgqwgWzwsGzms'>dgqwg_wzws_gzms = #{dgqwgWzwsGzms},</if>
      <if test='null != dgqwgBmqjGzms'>dgqwg_bmqj_gzms = #{dgqwgBmqjGzms},</if>
      <if test='null != bspwgBsqx'>bspwg_bsqx = #{bspwgBsqx},</if>
      <if test='null != bspwgBsqxGzms'>bspwg_bsqx_gzms = #{bspwgBsqxGzms},</if>
      <if test='null != bspwgAzlg'>bspwg_azlg = #{bspwgAzlg},</if>
      <if test='null != bspwgAzlgGzms'>bspwg_azlg_gzms = #{bspwgAzlgGzms},</if>
      <if test='null != dgqclG1'>dgqcl_g1 = #{dgqclG1},</if>
      <if test='null != dgqclG2'>dgqcl_g2 = #{dgqclG2},</if>
      <if test='null != dgqclG3'>dgqcl_g3 = #{dgqclG3},</if>
      <if test='null != dgqclG4'>dgqcl_g4 = #{dgqclG4},</if>
      <if test='null != sbzt'>sbzt = #{sbzt},</if>
      <if test='null != checkUser'>check_user = #{checkUser},</if>
      <if test='null != czwt'>czwt = #{czwt},</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>
    </set>
    WHERE id = #{id}
  </update>


  <select id="getInfo" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, dict.dict_label as xingbie_text
    FROM bus_jcb_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="getLastRecord" resultMap="BaseResultMap">
    SELECT
    a.DGQCL_G1, a.DGQCL_G2, a.DGQCL_G3, a.DGQCL_G4
    FROM bus_jcb_dmcgyq a,
    (
    select max(update_time) as lastTime
    from bus_jcb_dmcgyq
    WHERE user_id = #{user_id}
    and submit_state != '0'
    ) b
    WHERE a.update_time = b.lastTime

  </select>

  <select id="getList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>, dict.dict_label as xingbie_text
    FROM bus_jcb_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="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="fenxiang!=null and fenxiang!=''">
        and t.fenxiang=#{fenxiang}
      </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="tianqi!=null and tianqi!=''">
        and t.tianqi=#{tianqi}
      </if>
      <if test="temperature!=null and temperature!=''">
        and t.temperature=#{temperature}
      </if>
      <if test="checkDate!=null">
        and t.check_date=#{checkDate}
      </if>
      <if test="dgqwgAzlg!=null and dgqwgAzlg!=''">
        and t.dgqwg_azlg=#{dgqwgAzlg}
      </if>
      <if test="dgqwgWzws!=null and dgqwgWzws!=''">
        and t.dgqwg_wzws=#{dgqwgWzws}
      </if>
      <if test="dgqwgBmqj!=null and dgqwgBmqj!=''">
        and t.dgqwg_bmqj=#{dgqwgBmqj}
      </if>
      <if test="dgqwgAzlgGzms!=null and dgqwgAzlgGzms!=''">
        and t.dgqwg_azlg_gzms=#{dgqwgAzlgGzms}
      </if>
      <if test="dgqwgWzwsGzms!=null and dgqwgWzwsGzms!=''">
        and t.dgqwg_wzws_gzms=#{dgqwgWzwsGzms}
      </if>
      <if test="dgqwgBmqjGzms!=null and dgqwgBmqjGzms!=''">
        and t.dgqwg_bmqj_gzms=#{dgqwgBmqjGzms}
      </if>
      <if test="bspwgBsqx!=null and bspwgBsqx!=''">
        and t.bspwg_bsqx=#{bspwgBsqx}
      </if>
      <if test="bspwgBsqxGzms!=null and bspwgBsqxGzms!=''">
        and t.bspwg_bsqx_gzms=#{bspwgBsqxGzms}
      </if>
      <if test="bspwgAzlg!=null and bspwgAzlg!=''">
        and t.bspwg_azlg=#{bspwgAzlg}
      </if>
      <if test="bspwgAzlgGzms!=null and bspwgAzlgGzms!=''">
        and t.bspwg_azlg_gzms=#{bspwgAzlgGzms}
      </if>
      <if test="dgqclG1!=null and dgqclG1!=''">
        and t.dgqcl_g1=#{dgqclG1}
      </if>
      <if test="dgqclG2!=null and dgqclG2!=''">
        and t.dgqcl_g2=#{dgqclG2}
      </if>
      <if test="dgqclG3!=null and dgqclG3!=''">
        and t.dgqcl_g3=#{dgqclG3}
      </if>
      <if test="dgqclG4!=null and dgqclG4!=''">
        and t.dgqcl_g4=#{dgqclG4}
      </if>
      <if test="sbzt!=null and sbzt!=''">
        and t.sbzt=#{sbzt}
      </if>
      <if test="checkUser!=null and checkUser!=''">
        and t.check_user=#{checkUser}
      </if>
      <if test="czwt!=null and czwt!=''">
        and t.czwt=#{czwt}
      </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>
    </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"/>, dict.dict_label as xingbie_text
    FROM bus_jcb_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="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_area=#{pillarCode}
      </if>
      <if test="operator!=null and operator!=''">
        and t.check_user like concat('%', #{operator}, '%')
      </if>
      <if test="createBy!=null and createBy!=''">
        and t.create_by=#{createBy}
      </if>
      <if test="operationDate!=null">
        and t.check_date=#{operationDate}
      </if>
    </where>
  </select>

  <resultMap id="JcabResultMap" 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="check_date" property="operationDate"/>
    <result column="check_user" property="operator"/>
    <result column="jcebType" property="jcebType"/>
  </resultMap>

  <select id="getListByType" resultMap="JcabResultMap">
    SELECT t.id, v.dept_name, v.station_name, t.check_date, t.check_user, #{jcebType} as jcebType
    FROM bus_jcb_dmcgyq 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_code=#{pillarCode}
      </if>
      <if test="operator!=null and operator!=''">
        and t.check_user like concat('%', #{operator}, '%')
      </if>
      <if test="createBy!=null and createBy!=''">
        and t.create_by=#{createBy}
      </if>
      <if test="operationDate!=null">
        and t.check_date=#{operationDate}
      </if>
    </where>
  </select>

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

  <select id="getCountByType" resultMap="JcabCountResultMap">
    SELECT count(*) c, max(t.check_date) as check_date
    FROM bus_jcb_dmcgyq 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_code=#{pillarCode}
      </if>
      <if test="operator!=null and operator!=''">
        and t.check_user like concat('%', #{operator}, '%')
      </if>
      <if test="createBy!=null and createBy!=''">
        and t.create_by=#{createBy}
      </if>
      <if test="operationDate!=null">
        and t.check_date=#{operationDate}
      </if>
    </where>
  </select>

</mapper>