<?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.ChatNoticeMapper">
	<resultMap type="com.gic.haoban.manage.service.entity.chat.TabChatNotice" id="result-map-tabHaobanChatNotice">
		<result column="id" property="id" />
		<result column="wx_enterprise_id" property="wxEnterpriseId" />
		<result column="chat_id" property="chatId" />
		<result column="msg" property="msg" />
		<result column="type" property="type" />
		<result column="status_flag" property="statusFlag" />
		<result column="create_time" property="createTime" />
		<result column="update_time" property="updateTime" />
	</resultMap>
	<sql id="Base_Column_List">
		id ,
		wx_enterprise_id,
		chat_id,
		msg,
		type,
		status_flag,
		create_time,
		update_time
	</sql>
	<!-- ===================== 新增 ======================== -->
	<insert id="insert" parameterType="com.gic.haoban.manage.service.entity.chat.TabChatNotice">
	  <![CDATA[
	  INSERT INTO tab_haoban_chat_notice(
	  	  id ,
		  wx_enterprise_id,
		  chat_id,
		  msg,
		  type,
		  status_flag,
		  create_time,
		  update_time
	  )VALUES(
	      #{id},
		  #{wxEnterpriseId},
		  #{chatId},
		  #{msg},
		  #{type},
		  0,
		  now(),
		  now()
	  )
	  ]]>
	</insert>

	<update id="closeAll">
		 UPDATE tab_haoban_chat_notice SET
		  status_flag=1,
		  update_time=now()
	  where create_time > #{startTime} and create_time <![CDATA[<=]]> #{endTime}
	  and type in 
	  <foreach collection="list" close=")" index="index" item="type" open="(" separator=",">
	  	 #{type}
	  </foreach> 
	  and status_flag = 0
	</update>

	<select id="listAll" resultMap="result-map-tabHaobanChatNotice">
		select wx_enterprise_id wxEnterpriseId , chat_id chatId , type  from tab_haoban_chat_notice where create_time > #{startTime} and create_time <![CDATA[<=]]> #{endTime} and status_flag = 0
		 and type in 
		  <foreach collection="list" close=")" index="index" item="type" open="(" separator=",">
		  	 #{type}
		  </foreach>
		group by wx_enterprise_id , chat_id , type
	</select>
	
</mapper> 