<?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.elephant.framework.galaxy.aroad.module.emergencyevent.mapper.EmergencyEventMapper">

  <resultMap id="emergencyEventMap" type="com.elephant.framework.galaxy.aroad.module.emergencyevent.entity.EmergencyEvent">
        <id property="eventId" column="event_id"/>
        <result property="eventName" column="event_name"/>
        <result property="eventType" column="event_type"/>
        <result property="eventDetail" column="event_detail"/>
        <result property="influence" column="influence"/>
        <result property="road" column="road"/>
        <result property="stationNumber" column="station_number"/>
        <result property="reportingDept" column="reporting_dept"/>
        <result property="reportingDeptId" column="reporting_dept_id"/>
        <result property="reporterId" column="reporter_id"/>
        <result property="reportingTime" column="reporting_time"/>
        <result property="status" column="status"/>
        <result property="fileName" column="file_name"/>
        <result property="fileUrl" column="file_url"/>
        <result property="isFile" column="is_file"/>
  </resultMap>

  <insert id="saveEvent" useGeneratedKeys="true" keyProperty="eventId">
    insert into
      emergency_event(event_name, event_type,event_detail,influence,road,station_number,
      reporting_dept,reporting_dept_id,reporter_id,reporting_time,status)
    values
      (#{eventName}, #{eventType},#{eventDetail},#{influence},#{road},#{stationNumber},
      #{reportingDept},#{reportingDeptId},#{reporterId},#{reportingTime},#{status})
  </insert>

  <update id="updateStatus">
     update emergency_event set status=#{newStatus}
     where event_id=#{eventId} and status = #{oldStatus}
  </update>

  <update id="updateStatusById">
     update emergency_event set status=#{newStatus}
     where event_id=#{eventId}
  </update>

  <select id="getEventPage" resultMap="emergencyEventMap">
    select * from emergency_event
    where 1=1
    <if test="reportingDept != null">
        and reporting_dept = #{reportingDept}
    </if>
    <if test="status != null">
        and status = #{status}
    </if>
    order by reporting_time desc
  </select>

  <update id="updateFile">
     update emergency_event set file_name=#{fileName},file_url=#{fileUrl},status=#{status}
     where event_id=#{eventId}
  </update>

  <update id="updateIsFile">
     update emergency_event set is_file= 1
     where event_id=#{eventId}
  </update>
</mapper>
