<?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.copy.trade.dao.MessageMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.copy.trade.entity.po.Message">
	    <result column="id" property="id" />
        <result column="customer_id" property="customerId" />
	    <result column="create_time" property="createTime" />
        <result column="is_read" property="isRead" />
    </resultMap>
    <resultMap id="messageMap" type="com.copy.trade.entity.vo.MessageVo">
	    <result column="id" property="id" />
        <result column="customer_id" property="customerId" />
        <result column="message_type" property="messageType" />
        <result column="trigger_price" property="triggerPrice" />
        <result column="deal_price" property="dealPrice" />
	    <result column="create_time" property="createTime" />
        <result column="is_read" property="isRead" />
        <result column="symbol" property="symbol" />
    </resultMap>

    <select id="listByCustomerId" resultMap="messageMap">
        SELECT * from message
        <where>
            customer_id = #{customerId}
            ORDER by create_time DESC
        </where>
    </select>
    <select id="listUnreadByCustomerId" resultMap="BaseResultMap">
        SELECT * from message
        <where>
            customer_id = #{customerId} and is_read=0
            ORDER by id DESC
        </where>
    </select>
    <update id="setRead">
        update message m set m.is_read=1 where m.customer_id = #{customerId} and m.is_read=0
    </update>
</mapper>
