<?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.ruoyi.manage.mapper.NoticeAttachmentMapper">
    <!--
      模块：通知-附件
      说明：
        - 附件与公告一对多；删除按 noticeId 批量；排序字段 sort 升序。
    -->

    <resultMap id="AttachmentResult" type="com.ruoyi.manage.domain.NoticeAttachment">
        <result property="id" column="id"/>
        <result property="noticeId" column="notice_id"/>
        <result property="fileName" column="file_name"/>
        <result property="fileUrl" column="file_url"/>
        <result property="fileType" column="file_type"/>
        <result property="fileSize" column="file_size"/>
        <result property="sort" column="sort"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <insert id="insert" parameterType="com.ruoyi.manage.domain.NoticeAttachment" useGeneratedKeys="true"
            keyProperty="id">
        insert into tb_notice_attachment(notice_id, file_name, file_url, file_type, file_size, sort,
                                         create_by, create_time, update_by, update_time, del_flag)
        values (#{noticeId}, #{fileName}, #{fileUrl}, #{fileType}, #{fileSize}, #{sort},
                #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, '0')
    </insert>

    <delete id="deleteByNoticeId" parameterType="long">
        delete
        from tb_notice_attachment
        where notice_id = #{noticeId}
    </delete>

    <select id="selectByNoticeId" parameterType="long" resultMap="AttachmentResult">
        select id,
               notice_id,
               file_name,
               file_url,
               file_type,
               file_size,
               sort,
               create_by,
               create_time,
               update_by,
               update_time,
               del_flag
        from tb_notice_attachment
        where notice_id = #{noticeId}
        order by sort asc, id asc
    </select>

</mapper>
