<?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.casic.missiles.mapper.system.SystemNoticeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.casic.missiles.model.system.SystemNotice">
        <id column="id" property="id" />
        <result column="notice_no" property="noticeNo" />
        <result column="notice_title" property="noticeTitle" />
        <result column="notice_publisher" property="noticePublisher" />
        <result column="notice_company" property="noticeCompany" />
        <result column="notice_time" property="noticeTime" />
        <result column="notice_sketch" property="noticeSketch" />
        <result column="notice_content" property="noticeContent" />
        <result column="minio_file_name" property="minioFileName" />
        <result column="is_del" property="isDel" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="already_read" property="read" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, notice_no, notice_title, notice_publisher, notice_company, notice_time, notice_sketch, notice_content, minio_file_name, is_del, create_time, update_time
    </sql>

    <select id="selectMaxNoticeNo" resultType="java.lang.Long">
        SELECT IFNULL(max(RIGHT(notice_no, 12)), 0) from system_notice
    </select>

    <select id="selectListPage" resultMap="BaseResultMap">
        SELECT sn.*, IF(snur.user_id IS NULL, 0, 1) already_read
        FROM system_notice sn
        LEFT JOIN system_notice_user_relation snur ON (sn.id = snur.notice_id AND snur.user_id = #{request.userId})
        WHERE sn.is_del = 0
        <if test="request.noticeNo != null and request.noticeNo !=''">
            AND sn.notice_no LIKE concat('%',#{request.noticeNo},'%')
        </if>
        <if test="request.noticeTitle != null and request.noticeTitle !=''">
            AND sn.notice_title LIKE concat('%',#{request.noticeTitle},'%')
        </if>
        <if test="request.noticePublisher != null and request.noticePublisher !=''">
            AND sn.notice_publisher LIKE concat('%',#{request.noticePublisher},'%')
        </if>
        <if test="request.noticeStartTime != null and request.noticeStartTime !=''">
            AND sn.notice_time &gt;= #{request.noticeStartTime}
        </if>
        <if test="request.noticeEndTime != null and request.noticeEndTime !=''">
            AND sn.notice_time &lt;= #{request.noticeEndTime}
        </if>
        ORDER BY sn.notice_time DESC
    </select>
</mapper>
