55 lines
2.2 KiB
XML
55 lines
2.2 KiB
XML
<?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.datang.pet.mapperExtend.ChatMapperExtend">
|
|
|
|
<resultMap id="getUserChatListResultMap" type="com.datang.pet.vo.GetUserChatListResponse">
|
|
<id column="id" jdbcType="VARCHAR" property="id"/>
|
|
<result column="message_date" jdbcType="TIMESTAMP" property="messageDate"/>
|
|
<result column="head_portrait" jdbcType="VARCHAR" property="headPortrait"/>
|
|
<result column="nike_name" jdbcType="VARCHAR" property="nikeName"/>
|
|
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
|
|
<result column="is_read" jdbcType="CHAR" property="isRead" />
|
|
</resultMap>
|
|
<resultMap id="getChatListResultMap" type="com.datang.pet.pojo.Chat">
|
|
<result column="id" jdbcType="VARCHAR" property="id" />
|
|
<result column="sender_id" jdbcType="VARCHAR" property="senderId" />
|
|
<result column="consignee_id" jdbcType="VARCHAR" property="consigneeId" />
|
|
<result column="message" jdbcType="VARCHAR" property="message" />
|
|
<result column="message_date" jdbcType="TIMESTAMP" property="messageDate" />
|
|
<result column="is_read" jdbcType="CHAR" property="isRead" />
|
|
</resultMap>
|
|
|
|
<select id="getUserChatList" resultMap="getUserChatListResultMap">
|
|
SELECT c.id,c.message_date,c.is_read,u.nike_name,u.head_portrait, u.id AS user_id FROM
|
|
(
|
|
SELECT * FROM chat
|
|
<where>
|
|
LOCATE (#{userId},id)
|
|
<if test="time != null">
|
|
AND message_date < #{time}
|
|
</if>
|
|
|
|
</where>
|
|
)AS c
|
|
LEFT JOIN user_info AS u ON
|
|
(
|
|
CASE
|
|
WHEN c.sender_id!=#{userId} THEN c.sender_id=u.id
|
|
WHEN c.consignee_id!=#{userId} THEN c.consignee_id=u.id
|
|
END
|
|
)
|
|
GROUP BY id ORDER BY message_date DESC LIMIT 0,1
|
|
</select>
|
|
|
|
<select id="getChatList" resultMap="getChatListResultMap">
|
|
SELECT * FROM chat
|
|
<where>
|
|
id =#{id}
|
|
<if test="messageDate!=null">
|
|
AND message_date < #{messageDate}
|
|
</if>
|
|
</where>
|
|
ORDER BY message_date DESC LIMIT 0,20
|
|
</select>
|
|
|
|
</mapper> |