<?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="cn.reghao.tnb.content.app.chat.db.mapper.GroupNoticeMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into chat_group_notice
        (`id`,`deleted`,`create_time`,`update_time`,`notice_id`,`group_id`,`title`,`content`,`top`,`confirmed`,`create_by`)
        values 
        (#{id},#{deleted},#{createTime},#{updateTime},#{noticeId},#{groupId},#{title},#{content},#{top},#{confirmed},#{createBy})
    </insert>

    <update id="updateSetNotice">
        update chat_group_notice set update_time=now(),title=#{title},content=#{content}
        where id=#{noticeId}
    </update>

    <select id="findByNoticeId" resultType="cn.reghao.tnb.content.app.chat.model.po.GroupNotice">
        select * from chat_group_notice where id=#{noticeId}
    </select>
    <select id="findByGroupId" resultType="cn.reghao.tnb.content.app.chat.model.dto.group.NoticeRet">
        select groupNotice.id,groupNotice.title,groupNotice.content,groupNotice.confirmed as isConfirm,groupNotice.top as isTop,
        date_format(groupNotice.create_time,'%Y-%m-%d %H:%i:%s') as createdAt,
        date_format(groupNotice.update_time,'%Y-%m-%d %H:%i:%s') as updatedAt
        from chat_group_notice groupNotice
        where groupNotice.group_id=#{groupId}
    </select>
    <select id="findByLatest" resultType="cn.reghao.tnb.content.app.chat.model.dto.group.NoticeRet">
        select groupNotice.id,groupNotice.title,groupNotice.content,groupNotice.confirmed as isConfirm,groupNotice.top as isTop,
        date_format(groupNotice.create_time,'%Y-%m-%d %H:%i:%s') as createdAt,
        date_format(groupNotice.update_time,'%Y-%m-%d %H:%i:%s') as updatedAt
        from chat_group_notice groupNotice
        where groupNotice.group_id=#{groupId}
        order by groupNotice.create_time desc
        limit 1
    </select>
</mapper>
