<?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.diagbot.mapper.MedNewsNoticeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.MedNewsNotice">
        <id column="id" property="id" />
        <result column="hospital_id" property="hospitalId" />
        <result column="title" property="title" />
        <result column="type" property="type" />
        <result column="news" property="news" />
        <result column="status" property="status" />
        <result column="sender" property="sender" />
        <result column="receiver" property="receiver" />
        <result column="is_deleted" property="isDeleted" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="creator" property="creator" />
        <result column="modifier" property="modifier" />
    </resultMap>
    <select id="newsNoticePage" resultType="com.diagbot.dto.NewsNoticePageDTO">
        SELECT
            *
        FROM
        (SELECT
            n.id,
            n.title,
            n.type,
            n.news,
            n.`status`,
            n.sender,
            CASE WHEN n.sender = '0' THEN '系统'
            ELSE u.linkman END senderName,
            n.gmt_create gmtCreate
        FROM
            `med_news_notice` n
        LEFT JOIN sys_user u ON u.id = n.sender
        AND u.is_deleted = "N"
        WHERE
            n.is_deleted = "N"
        AND n.receiver = #{newsNoticePageVO.principle}
        <if test="newsNoticePageVO.type != null and newsNoticePageVO.type != ''">
            AND n.type = #{newsNoticePageVO.type}
        </if>
        <if test="newsNoticePageVO.status != null and newsNoticePageVO.status != ''">
            AND n.`status` = #{newsNoticePageVO.status}
        </if>
         )p
    </select>

</mapper>
