<?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.lantone.security.mapper.NoticeUserMapper">

    <select id="listPage" resultType="com.lantone.security.dto.GetMyNoticeListDTO">
        SELECT
        n.id,
        u.user_id userId,
        n.title,
        n.type,
        (
        CASE
        WHEN n.type = 0 THEN
        "公告"
        WHEN n.type = 1 THEN
        "其他"
        ELSE
        "未知类型"
        END
        ) typeName,
        n.content,
        n.creatorName sender,
        n.gmt_create gmtCreate,
        u.`status`,
        (
        CASE
        WHEN u.`status` = 0 THEN
        "未读"
        WHEN u.`status` = 1 THEN
        "已读"
        ELSE
        "未知类型"
        END
        ) statusName
        FROM
        `sys_notice_user` u,
        sys_notice n
        WHERE
        u.is_deleted = 'N'
        AND n.is_deleted = 'N'
        AND u.notice_id = n.id
        <if test="getMyNoticeListVO.hospitalId != null">
            AND u.hospital_id = #{getMyNoticeListVO.hospitalId}
        </if>
        <if test="getMyNoticeListVO.id != null">
            AND u.user_id = #{getMyNoticeListVO.id}
        </if>
        <if test="getMyNoticeListVO.status != null and getMyNoticeListVO.status != ''">
            AND u.`status` = #{getMyNoticeListVO.status}
        </if>
        <if test="getMyNoticeListVO.type != null and getMyNoticeListVO.type != ''">
            AND n.type = #{getMyNoticeListVO.type}
        </if>
    </select>
</mapper>