<?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.spring.mapper.MessageMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.spring.domain.entity.MessageEntity">
            <id column="id" property="id"/>
            <id column="title" property="title"/>
            <id column="send_user_id" property="sendUserId"/>
            <id column="message_type" property="messageType"/>
            <id column="cover" property="cover"/>
            <id column="summary" property="summary"/>
            <id column="content" property="content"/>
            <id column="editor_type" property="editorType"/>
            <id column="level" property="level"/>
            <id column="extra" property="extra"/>
            <id column="create_time" property="createTime"/>
            <id column="update_time" property="updateTime"/>
            <id column="update_user" property="updateUser"/>
            <id column="create_user" property="createUser"/>
            <id column="is_deleted" property="isDeleted"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,title,send_user_id,message_type,cover,summary,content,editor_type,level,extra,create_time,update_time,update_user,create_user,is_deleted
    </sql>

    <!-- 分页查询系统消息内容 -->
    <select id="selectListByPage" resultType="com.spring.domain.vo.MessageVo">
        select
        base.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_message base
        left join sys_user create_user on create_user.id = base.create_user
        left join sys_user update_user on update_user.id = base.update_user
        <where>
            base.is_deleted = 0
                <if test="dto.id != null and dto.id != ''">
                    and base.id like CONCAT('%',#{dto.id},'%')
                </if>
                <if test="dto.title != null and dto.title != ''">
                    and base.title like CONCAT('%',#{dto.title},'%')
                </if>
                <if test="dto.sendUserId != null and dto.sendUserId != ''">
                    and base.send_user_id like CONCAT('%',#{dto.sendUserId},'%')
                </if>
                <if test="dto.messageType != null and dto.messageType != ''">
                    and base.message_type like CONCAT('%',#{dto.messageType},'%')
                </if>
                <if test="dto.cover != null and dto.cover != ''">
                    and base.cover like CONCAT('%',#{dto.cover},'%')
                </if>
                <if test="dto.summary != null and dto.summary != ''">
                    and base.summary like CONCAT('%',#{dto.summary},'%')
                </if>
                <if test="dto.content != null and dto.content != ''">
                    and base.content like CONCAT('%',#{dto.content},'%')
                </if>
                <if test="dto.editorType != null and dto.editorType != ''">
                    and base.editor_type like CONCAT('%',#{dto.editorType},'%')
                </if>
                <if test="dto.level != null and dto.level != ''">
                    and base.level like CONCAT('%',#{dto.level},'%')
                </if>
                <if test="dto.extra != null and dto.extra != ''">
                    and base.extra like CONCAT('%',#{dto.extra},'%')
                </if>
                <if test="dto.createTime != null and dto.createTime != ''">
                    and base.create_time like CONCAT('%',#{dto.createTime},'%')
                </if>
                <if test="dto.updateTime != null and dto.updateTime != ''">
                    and base.update_time like CONCAT('%',#{dto.updateTime},'%')
                </if>
                <if test="dto.updateUser != null and dto.updateUser != ''">
                    and base.update_user like CONCAT('%',#{dto.updateUser},'%')
                </if>
                <if test="dto.createUser != null and dto.createUser != ''">
                    and base.create_user like CONCAT('%',#{dto.createUser},'%')
                </if>
                <if test="dto.isDeleted != null and dto.isDeleted != ''">
                    and base.is_deleted like CONCAT('%',#{dto.isDeleted},'%')
                </if>
        </where>
    </select>

</mapper>
