<?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.project.system.mapper.SysUserNoticeMapper">
    
    <resultMap type="SysUserNotice" id="SysUserNoticeResult">
        <result property="userId"    column="user_id"    />
        <result property="noticeId"    column="notice_id"    />
        <result property="createtime"    column="createtime"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectSysUserNoticeVo">
        select d.user_id, d.notice_id, d.createtime ,s.dept_name from sys_user_notice d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectSysUserNoticeList" parameterType="SysUserNotice" resultMap="SysUserNoticeResult">
        <include refid="selectSysUserNoticeVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="noticeId != null "> and notice_id = #{noticeId}</if>
            <if test="createtime != null "> and createtime = #{createtime}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectSysUserNoticeById" parameterType="Long" resultMap="SysUserNoticeResult">
        <include refid="selectSysUserNoticeVo"/>
        where user_id = #{userId}
    </select>


    <insert id="insertSysUserNotice" parameterType="SysUserNotice">
        insert into sys_user_notice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="noticeId != null">notice_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="noticeId != null">#{noticeId},</if>
         </trim>
    </insert>


    
</mapper>