<?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.api.manage.dao.message.ManageSysMessageDao">

    <select id="list" parameterType="com.api.model.message.SearchManageSysMessage" resultType="com.api.model.message.ManageSysMessage">
        select * from manage_sys_message
        <where>
            receiver_account_id = #{receiverAccountId}
            <if test="senderType != null">
                and sender_type = #{senderType}
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
            <if test="content != null and content != ''">
                and content like concat('%',#{content},'%')
            </if>
        </where>
        order by send_date desc
    </select>

    <insert id="insert" parameterType="com.api.model.message.ManageSysMessage">
        insert into manage_sys_message(
            content,
            type,
            relation_id,
            receiver_account_id,
            sender_id,
            sender_type,
            send_status,
            send_date
        )values (
            #{content},
            #{type},
            #{relationId},
            #{receiverAccountId},
            #{senderId},
            #{senderType},
            #{sendStatus},
            #{sendDate}
        )
    </insert>

    <select id="findOrganizationByOrganizationId" parameterType="java.lang.Integer"
            resultType="com.api.model.businessManagement.SysOrganization">
        select * from sys_organization where id = #{organizationId}
    </select>

    <update id="read" parameterType="com.api.model.message.ManageSysMessage">
        update manage_sys_message
        set send_status = #{sendStatus}
        where id = #{id} and receiver_account_id = #{receiverAccountId}
    </update>
    <update id="allRead" parameterType="com.api.model.message.ManageSysMessage">
        update manage_sys_message
        set send_status = #{sendStatus}
        where receiver_account_id = #{receiverAccountId}
    </update>


</mapper>