<?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.yonge.cooleshow.biz.dal.dao.ImGroupNoticeDao">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.ImGroupNotice">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="group_id_" jdbcType="VARCHAR" property="groupId"/>
        <result column="title_" jdbcType="VARCHAR" property="title"/>
        <result column="content_" jdbcType="VARCHAR" property="content"/>
        <result column="top_flag_" property="topFlag"/>
        <result column="sent_to_new_member_flag_" property="sentToNewMemberFlag"/>
        <result column="del_flag_" jdbcType="VARCHAR" property="delFlag"/>
        <result column="operator_id_" jdbcType="INTEGER" property="operatorId"/>
        <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>
    <resultMap id="ImGroupNoticeDto" type="com.yonge.cooleshow.biz.dal.dto.ImGroupNoticeDto" extends="BaseResultMap">
        <result property="avatar" column="avatar_"/>
        <result property="username" column="username_"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_, group_id_, title_, content_, top_flag_, sent_to_new_member_flag_, del_flag_, operator_id_, create_time_, update_time_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.yonge.cooleshow.biz.dal.entity.ImGroupNotice">
        insert into im_group_notice(group_id_, title_, content_, top_flag_, sent_to_new_member_flag_, del_flag_,
        operator_id_, create_time_, update_time_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.groupId}, #{entity.title}, #{entity.content}, #{entity.topFlag}, #{entity.sentToNewMemberFlag},
            #{entity.delFlag}, #{entity.operatorId}, #{entity.createTime}, #{entity.updateTime})
        </foreach>
    </insert>
    <select id="queryPage" resultMap="ImGroupNoticeDto">
        SELECT gn.*,su.avatar_,su.username_ FROM im_group_notice gn
        LEFT JOIN sys_user su ON su.id_ = gn.operator_id_
        WHERE gn.group_id_ = #{params.groupId}
    </select>

    <update id="updateTopFlag">
        update im_group_notice set top_flag_ = false where group_id_ = #{groupId}
    </update>
</mapper>
