<?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.wechat.dao.MdeVideoUseHisMapper">
  <resultMap id="BaseResultMap" type="com.wechat.model.dbEntity.MdeVideoUseHis">
    <id column="USED_ID" jdbcType="BIGINT" property="usedId" />
    <result column="FILL_ID" jdbcType="VARCHAR" property="fillId" />
    <result column="ROOM_ID" jdbcType="VARCHAR" property="roomId" />
    <result column="HOTEL_CODE" jdbcType="VARCHAR" property="hotelCode" />
    <result column="PARTICIPANT" jdbcType="VARCHAR" property="participant" />
    <result column="TYPE" jdbcType="CHAR" property="type" />
    <result column="START_TIME" jdbcType="TIMESTAMP" property="startTime" />
    <result column="STOP_TIME" jdbcType="TIMESTAMP" property="stopTime" />
    <result column="USED_TIME" jdbcType="INTEGER" property="usedTime" />
    <result column="VERSION_NO" jdbcType="INTEGER" property="versionNo" />
    <result column="CREATE_BY" jdbcType="VARCHAR" property="createBy" />
    <result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate" />
    <result column="UPDATE_BY" jdbcType="VARCHAR" property="updateBy" />
    <result column="UPDATE_DATE" jdbcType="TIMESTAMP" property="updateDate" />
    <result column="REMARKS" jdbcType="VARCHAR" property="remarks" />
    <result column="DEL_FLAG" jdbcType="CHAR" property="delFlag" />
  </resultMap>
  <sql id="Base_Column_List">
    USED_ID, FILL_ID, ROOM_ID, HOTEL_CODE, PARTICIPANT, TYPE, START_TIME, STOP_TIME, 
    USED_TIME, VERSION_NO, CREATE_BY, CREATE_DATE, UPDATE_BY, UPDATE_DATE, REMARKS, DEL_FLAG
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from mde_video_use_his
    where USED_ID = #{usedId,jdbcType=BIGINT}
  </select>

  
  <insert id="insert" useGeneratedKeys="true" keyProperty="usedId" parameterType="com.wechat.model.dbEntity.MdeVideoUseHis">
    insert into mde_video_use_his (FILL_ID, ROOM_ID, 
      HOTEL_CODE, PARTICIPANT, TYPE, 
      START_TIME, STOP_TIME, USED_TIME, 
      CREATE_BY, CREATE_DATE, 
      UPDATE_BY, UPDATE_DATE)
    values ( #{fillId,jdbcType=VARCHAR}, #{roomId,jdbcType=VARCHAR}, 
      #{hotelCode,jdbcType=VARCHAR}, #{participant,jdbcType=VARCHAR}, #{type,jdbcType=CHAR}, 
      #{startTime,jdbcType=TIMESTAMP}, #{stopTime,jdbcType=TIMESTAMP}, #{usedTime,jdbcType=INTEGER}, 
      #{createBy,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, 
      #{updateBy,jdbcType=VARCHAR}, #{updateDate,jdbcType=TIMESTAMP})
  </insert>
  
  <update id="updateHisStoptime" parameterType="com.wechat.model.dbEntity.MdeVideoUseHis">
    update mde_video_use_his
    set 
      <if test="fillId != null">
        FILL_ID = #{fillId,jdbcType=VARCHAR},
      </if>
      STOP_TIME = #{stopTime,jdbcType=TIMESTAMP},
      USED_TIME = ceiling(TIMESTAMPDIFF(SECOND,START_TIME,#{stopTime})/60),
      UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
      version_no = version_no+1 
    where USED_ID = #{usedId}
      <if test="hotelCode != null and hotelCode !=''" >
        and HOTEL_CODE = #{hotelCode}
      </if>
      <if test="participant != null and participant !=''" >
        and PARTICIPANT = #{participant}
      </if>
      and ROOM_ID = #{roomId}
  </update>
  
  
  <update id="updateByPrimaryKeySelective" parameterType="com.wechat.model.dbEntity.MdeVideoUseHis">
    update mde_video_use_his
    <set>
      <if test="fillId != null">
        FILL_ID = #{fillId,jdbcType=VARCHAR},
      </if>
      <if test="roomId != null">
        ROOM_ID = #{roomId,jdbcType=VARCHAR},
      </if>
      <if test="hotelCode != null">
        HOTEL_CODE = #{hotelCode,jdbcType=VARCHAR},
      </if>
      <if test="participant != null">
        PARTICIPANT = #{participant,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        TYPE = #{type,jdbcType=CHAR},
      </if>
      <if test="startTime != null">
        START_TIME = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="stopTime != null">
        STOP_TIME = #{stopTime,jdbcType=TIMESTAMP},
      </if>
      <if test="usedTime != null">
        USED_TIME = #{usedTime,jdbcType=INTEGER},
      </if>
      <if test="versionNo != null">
        VERSION_NO = #{versionNo,jdbcType=INTEGER},
      </if>
      <if test="createBy != null">
        CREATE_BY = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null">
        CREATE_DATE = #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null">
        UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="remarks != null">
        REMARKS = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null">
        DEL_FLAG = #{delFlag,jdbcType=CHAR},
      </if>
    </set>
    where USED_ID = #{usedId,jdbcType=BIGINT}
  </update>

</mapper>