<?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.repair.mapper.RepairSystemMessagesMapper">
    <resultMap type="com.repair.model.vo.SystemMessagePageVo" id="systemMessagePageMap">
        <result property="id" column="id"/>
        <result property="recordId" column="record_id"/>
        <result property="recordNo" column="record_no"/>
        <result property="isRead" column="is_read"/>
        <result property="content" column="content"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="querySystemMessagePage" resultType="com.repair.model.vo.SystemMessagePageVo" resultMap="systemMessagePageMap">
        select rsm.id,rsm.record_id,rr.record_no,rsm.is_read,rsm.content,rsm.create_time as update_time from repair_system_messages rsm
        left join repair_record rr on rr.deleted = 0 and rr.id = rsm.record_id
        where rsm.deleted = 0 and rsm.recipient_id = #{userId}
        order by rsm.is_read asc,rsm.create_time desc
    </select>

    <select id="queryPCSystemMessagePage" resultType="com.repair.model.vo.SystemMessagePageVo" resultMap="systemMessagePageMap">
        select rsm.id,rsm.record_id,rr.record_no,rsm.is_read,rsm.content,rsm.create_time as update_time from repair_system_messages rsm
        left join repair_record rr on rr.deleted = 0 and rr.id = rsm.record_id
        where rsm.deleted = 0 and rsm.recipient_id = #{userId}
        <if test="statu != 2">
            and rsm.is_read = #{statu}
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            and rsm.create_time &gt;= #{startTime} and rsm.create_time &lt;= #{endTime}
        </if>
        order by rsm.is_read asc,rsm.create_time desc
    </select>

</mapper>
