<?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.modules.platform.mapper.UserMessageMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="userMessageResultMap" type="org.springblade.modules.platform.entity.UserMessage">
        <result column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="create_user_id" property="createUserId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user_id" property="updateUserId"/>
        <result column="update_time" property="updateTime"/>
        <result column="title" property="title"/>
        <result column="type" property="type"/>
        <result column="order_id" property="orderId"/>
        <result column="user_id" property="userId"/>
        <result column="is_read" property="isRead"/>
    </resultMap>


    <select id="selectUserMessagePage" resultMap="userMessageResultMap">
        select * from biz_user_message where is_delete = 0
    </select>
    <select id="selectUserNoticeList" resultType="org.springblade.modules.platform.vo.UserMessageVO">
        SELECT
            um.id,
            um.title,
            um.is_read,
            o.image,
            o.order_no,
            o.order_type,
            og.goods_name,
            um.create_time
        FROM
            biz_user_message um
            JOIN biz_order o ON um.order_id = o.id
            LEFT JOIN biz_order_goods og ON og.out_trade_no = o.order_no
        WHERE
            um.user_id = #{userId} and um.type = #{type}
        ORDER BY um.create_time desc
    </select>

</mapper>
