<?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.ym.mec.biz.dal.dao.ImSendGroupMessageDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.ImSendGroupMessage" id="ImSendGroupMessage">
		<result column="id_" property="id" />
		<result column="message_content_" property="messageContent" />
		<result column="sender_id_" property="senderId" />
		<result column="extra" property="extra" />
		<result column="target_ids_" property="targetIds" />
		<result column="file_url_" property="fileUrl" />
		<result column="file_name_" property="fileName" />
		<result column="file_size_" property="fileSize" />
		<result column="message_type_" property="messageType" />
		<result column="send_type_" property="sendType" />
		<result column="send_flag_" property="sendFlag" />
		<result column="send_time_" property="sendTime" />
		<result column="operator_" property="operator" />
		<result column="is_include_sender_" property="isIncludeSender" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="ImSendGroupMessage" >
		SELECT * FROM im_send_group_message WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="ImSendGroupMessage">
		SELECT * FROM im_send_group_message ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ImSendGroupMessage" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO im_send_group_message (message_content_,sender_id_,extra,target_ids_,file_url_,file_name_,
		                                   file_size_,message_type_,send_flag_,send_time_,
		                                   create_time_,update_time_,operator_,send_type_,is_include_sender_)
		VALUES(#{messageContent},#{senderId},#{extra},#{targetIds},#{fileUrl},#{fileName},#{fileSize},
		       #{messageType},#{sendFlag},#{sendTime},NOW(),NOW(),#{operator},#{sendType},#{isIncludeSender})
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.ImSendGroupMessage">
		UPDATE im_send_group_message <set>
			<if test="isIncludeSender != null">
				is_include_sender_ = #{isIncludeSender},
			</if>
			<if test="sendType != null">
				send_type_ = #{sendType},
			</if>
			<if test="operator != null">
				operator_ = #{operator},
			</if>
			<if test="senderId != null">
			sender_id_ = #{senderId},
			</if>
			<if test="messageType != null">
			message_type_ = #{messageType},
			</if>
			<if test="sendTime != null">
			send_time_ = #{sendTime},
			</if>
			<if test="sendFlag != null">
			send_flag_ = #{sendFlag},
			</if>
			<if test="targetIds != null">
			target_ids_ = #{targetIds},
			</if>
			<if test="fileName != null">
			file_name_ = #{fileName},
			</if>
			<if test="fileSize != null">
			file_size_ = #{fileSize},
			</if>
			<if test="messageContent != null">
			message_content_ = #{messageContent},
			</if>
			<if test="extra != null">
			extra = #{extra},
			</if>
			<if test="fileUrl != null and fileUrl != ''">
				file_url_ = #{fileUrl},
			</if>
			update_time_ = NOW()
			</set> WHERE id_ = #{id}
	</update>
	<update id="batchUpdateSendFlag">
		<foreach collection="sendGroupMessages" item="item" separator=";">
			UPDATE im_send_group_message SET send_flag_ = #{item.sendFlag},update_time_ = NOW() WHERE id_ = #{item.id}
		</foreach>
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM im_send_group_message WHERE id_ = #{id} 
	</delete>

	<sql id="queryPageSql">
		<where>
			<if test="sendFlag != null">
				AND send_flag_ = #{sendFlag}
			</if>
			<if test="senderId != null">
				AND sender_id_ = #{senderId}
			</if>
			<if test="sendType != null">
				AND send_type_ = #{sendType}
			</if>
			<if test="isIncludeSender != null">
				AND is_include_sender_ = #{isIncludeSender}
			</if>
		</where>
	</sql>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="ImSendGroupMessage" parameterType="map">
		SELECT * FROM im_send_group_message
		<include refid="queryPageSql" />
		ORDER BY id_ DESC
		<include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM im_send_group_message
		<include refid="queryPageSql" />
	</select>
    <select id="findBySendFlag" resultMap="ImSendGroupMessage">
		SELECT * FROM im_send_group_message WHERE send_flag_ = #{sendFlag}
		<if test="sendTime != null">
		AND send_time_ &lt;= #{sendTime}
		</if>
	</select>
</mapper>
