<?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.gic.haoban.manage.service.dao.mapper.chat.GroupChatOwnerHistoryMapper">
  <resultMap type="com.gic.haoban.manage.service.entity.chat.TabGroupChatOwnerHistory" id="result-map-tabHaobanGroupChatOwnerHistory">
      <result column="owner_history_id"  property="ownerHistoryId"/>
      <result column="wx_enterprise_id"  property="wxEnterpriseId"/>
      <result column="group_chat_id"  property="groupChatId"/>
      <result column="staff_id"  property="staffId"/>
      <result column="create_time"  property="createTime"/>
      <result column="end_time"  property="endTime"/>
  </resultMap>
  <sql id="Base_Column_List">
	  owner_history_id,
	  wx_enterprise_id,
	  group_chat_id,
	  staff_id,
	  create_time,
	  end_time
  </sql>
  <!-- ===================== 新增 ======================== -->
  <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.chat.TabGroupChatOwnerHistory">
  <![CDATA[
  INSERT INTO tab_haoban_group_chat_owner_history(
	  owner_history_id,
	  wx_enterprise_id,
	  group_chat_id,
	  staff_id,
	  create_time,
	  end_time
  )VALUES(
	  #{ownerHistoryId},
	  #{wxEnterpriseId},
	  #{groupChatId},
	  #{staffId},
	  #{createTime},
	  #{endTime}
  )
  ]]>
  </insert>
  
  <select id="getGroupChatNowStaff" resultMap="result-map-tabHaobanGroupChatOwnerHistory">
  	select <include refid="Base_Column_List" /> from tab_haoban_group_chat_owner_history
  	where group_chat_id=#{groupChatId} and staff_id=#{staffId} and end_time is null 
  </select>
  
   <!-- ==================更新 ========== -->
  <update id="updateOwnerEnd">
  <![CDATA[
  UPDATE tab_haoban_group_chat_owner_history SET
	  end_time= now() 
  where group_chat_id=#{groupChatId} and staff_id=#{staffId}
  ]]>
  </update>
  
  <select id="listAll" resultType="com.gic.haoban.manage.api.dto.chat.GroupChatOwnerHistoryDTO">
  	 select a.staff_id staffId , b.staff_name staffName , a.create_time createTime , a.end_time endTime  from tab_haoban_group_chat_owner_history  a LEFT JOIN tab_haoban_staff b on a.staff_id = b.staff_id
  	 where a.group_chat_id=#{groupChatId} and a.wx_enterprise_id=#{wxEnterpriseId} order by a.create_time desc
  </select>
</mapper> 