<?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="org.springblade.bank.message.mapper.MessageMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="messageResultMap" type="org.springblade.bank.message.entity.Message">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="title" property="title"/>
        <result column="content" property="content"/>
        <result column="file" property="file"/>
        <result column="person_id" property="personId"/>
        <result column="person_name" property="personName"/>
        <result column="approve_time" property="approveTime"/>
        <result column="process" property="process"/>
        <result column="is_completed" property="isCompleted"/>
        <result column="dept_id" property="deptId"/>
        <result column="role_id" property="roleId"/>
        <result column="target_ids" property="targetIds"/>
        <result column="type" property="type"/>

        <result column="current_user_id" property="currentUserId"/>

        <result column="domain" property="domain"/>
        <result column="name" property="name"/>
        <result column="original_name" property="originalName"/>
        <result column="extension" property="extension"/>
        <result column="attach_size" property="attachSize"/>
    </resultMap>


    <select id="selectMessagePage" resultMap="messageResultMap">
        SELECT c.* FROM
        (select * from zh_message where is_deleted = 0 and create_user = #{message.currentUserId}

        UNION
        select * from zh_message where is_deleted = 0
        AND target_ids like '%${message.currentUserId}%'
        ) c
        where  1=1
        <if test="message!=null">
            <if test="message.createUser!=null">
                AND c.create_user like '${message.createUser}'
            </if>
            <if test="message.title!=null">
                AND c.title like '${message.title}'
            </if>
        </if>
        ORDER BY c.create_time DESC

    </select>

</mapper>
