u
This commit is contained in:
1 parent
6fd3bf5138
commit
28678fb4df
13 files changed
+358
-136
No files matched your search
@@ -19,5 +19,8 @@ public interface ImFriendMapper extends BaseMapper<ImFriend> {
|
||||
@Param("id") Long id
|
||||
);
|
||||
|
||||
Long selectFriendTotal(@Param("userId") Long userId);
|
||||
Long selectFriendTotal(
|
||||
@Param("userId") Long userId,
|
||||
@Param("name") String name
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,24 @@
|
||||
package cn.link56.im.mapper;
|
||||
|
||||
import cn.link56.im.model.po.ImGroup;
|
||||
import cn.link56.im.model.vo.QueryFriendVO;
|
||||
import cn.link56.im.model.vo.QueryGroupVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ImGroupMapper extends BaseMapper<ImGroup> {
|
||||
List<QueryGroupVO> selectGroup(
|
||||
@Param("offset") int offset,
|
||||
@Param("limit") int limit,
|
||||
@Param("userId") Long userId,
|
||||
@Param("name") String name,
|
||||
@Param("id") Long id
|
||||
);
|
||||
|
||||
Long selectGroupTotal(@Param("userId") Long userId,
|
||||
@Param("name") String name);
|
||||
}
|
||||
@@ -22,8 +22,8 @@ public class ImGroupUser {
|
||||
@TableField("b_join_time")
|
||||
private Date joinTime;
|
||||
|
||||
@TableField("b_last_active_time")
|
||||
private Date lastActiveTime;
|
||||
@TableField("b_last_message_id")
|
||||
private Integer lastMessageId;
|
||||
|
||||
@TableField("b_unread_count")
|
||||
private Integer unreadCount;
|
||||
|
||||
@@ -10,8 +10,6 @@ import java.util.Date;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryFriendVO {
|
||||
private Long id;
|
||||
|
||||
private Long friendId;
|
||||
private String friendName;
|
||||
private String friendAvatar;
|
||||
|
||||
@@ -8,9 +8,9 @@ import lombok.NoArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class QueryGroupVO {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String avatar;
|
||||
private Long groupId;
|
||||
private String groupName;
|
||||
private String groupAvatar;
|
||||
|
||||
private Integer unreadCount;
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ImFriendService extends ServiceImpl<ImFriendMapper, ImFriend> {
|
||||
item.setIsOnline(SessionManager.isOnline(friendId));
|
||||
});
|
||||
// 查询总数
|
||||
Long total = imFriendMapper.selectFriendTotal(userId);
|
||||
Long total = imFriendMapper.selectFriendTotal(userId,name);
|
||||
|
||||
BasePageVO<QueryFriendVO> basePageVO = new BasePageVO<>();
|
||||
basePageVO.setRecords(queryFriendVOS);
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package cn.link56.im.service;
|
||||
|
||||
import cn.link56.common.BasePageVO;
|
||||
import cn.link56.common.context.UserContext;
|
||||
import cn.link56.im.mapper.ImGroupMapper;
|
||||
import cn.link56.im.model.dto.QueryGroupDTO;
|
||||
import cn.link56.im.model.po.ImGroup;
|
||||
import cn.link56.im.model.vo.QueryFriendVO;
|
||||
import cn.link56.im.model.vo.QueryGroupVO;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ImGroupService extends ServiceImpl<ImGroupMapper, ImGroup>{
|
||||
@@ -16,13 +19,17 @@ public class ImGroupService extends ServiceImpl<ImGroupMapper, ImGroup>{
|
||||
private ImGroupMapper imGroupMapper;
|
||||
|
||||
public BasePageVO<QueryGroupVO> queryGroup(QueryGroupDTO dto) {
|
||||
Long userId = UserContext.getUserId();
|
||||
|
||||
String name = dto.getName();
|
||||
Long id = dto.getId();
|
||||
|
||||
int offset = (dto.getCurrentPage() - 1) * dto.getPageSize() + 1;
|
||||
int limit = dto.getCurrentPage() * dto.getPageSize();
|
||||
|
||||
List<QueryGroupVO> queryFriendVOS = imGroupMapper.selectGroup(offset, limit, userId, name, id);
|
||||
Long total = imGroupMapper.selectGroupTotal(userId, name);
|
||||
|
||||
return new BasePageVO<>();
|
||||
return new BasePageVO<>(total,queryFriendVOS);
|
||||
}
|
||||
}
|
||||
+24
-17
@@ -9,34 +9,41 @@
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
f.b_id AS id,
|
||||
f.b_friend_id AS friendId,
|
||||
u.b_name AS friendName,
|
||||
u.b_avatar AS friendAvatar,
|
||||
f.b_unread_count AS unreadCount,
|
||||
m.b_id AS lastMessageId,
|
||||
m.b_send_time AS lastMessageTime,
|
||||
m.b_type AS lastMessageType,
|
||||
m.b_content AS lastMessageContent,
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY
|
||||
<if test="id != null and id != 0">
|
||||
CASE WHEN f.b_id = #{id} THEN 0 ELSE 1 END,
|
||||
</if>
|
||||
m.b_send_time DESC
|
||||
) AS rn
|
||||
f.b_id AS id,
|
||||
f.b_friend_id AS friendId,
|
||||
u.b_name AS friendName,
|
||||
u.b_avatar AS friendAvatar,
|
||||
f.b_unread_count AS unreadCount,
|
||||
m.b_id AS lastMessageId,
|
||||
m.b_send_time AS lastMessageTime,
|
||||
m.b_type AS lastMessageType,
|
||||
m.b_content AS lastMessageContent,
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY
|
||||
<if test="id != null and id != 0">
|
||||
CASE WHEN f.b_id = #{id} THEN 0 ELSE 1 END,
|
||||
</if>
|
||||
m.b_send_time DESC
|
||||
) AS rn
|
||||
FROM b_im_friend f
|
||||
LEFT JOIN b_company_user u ON f.b_friend_id = u.b_id
|
||||
LEFT JOIN b_im_private_message m ON f.b_last_message_id = m.b_id
|
||||
WHERE f.b_user_id = #{userId}
|
||||
) AS t
|
||||
<if test="name != null and name != ''">
|
||||
AND u.b_name LIKE '%' + #{name} + '%'
|
||||
</if>
|
||||
) t
|
||||
WHERE t.rn BETWEEN #{offset} AND #{limit}
|
||||
</select>
|
||||
|
||||
<select id="selectFriendTotal" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM b_im_friend f
|
||||
LEFT JOIN b_company_user u ON f.b_friend_id = u.b_id
|
||||
WHERE f.b_user_id = #{userId}
|
||||
<if test="name != null and name != ''">
|
||||
AND u.b_name LIKE '%' + #{name} + '%'
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
+27
-14
@@ -9,35 +9,48 @@
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
g.b_id AS id,
|
||||
g.b_name AS name,
|
||||
g.b_avatar AS avatar,
|
||||
g.b_id AS groupId,
|
||||
g.b_name AS groupName,
|
||||
g.b_avatar AS groupAvatar,
|
||||
gu.b_unread_count AS unreadCount,
|
||||
|
||||
m.b_id AS lastMessageId,
|
||||
m.b_send_time AS lastMessageTime,
|
||||
m.b_type AS lastMessageType,
|
||||
m.b_content AS lastMessageContent,
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY
|
||||
|
||||
u.b_id AS lastMessageSenderId,
|
||||
u.b_name AS lastMessageSenderName,
|
||||
u.b_avatar AS lastMessageSenderAvatar,
|
||||
|
||||
ROW_NUMBER() OVER (
|
||||
ORDER BY
|
||||
<if test="id != null and id != 0">
|
||||
CASE WHEN g.b_id = #{id} THEN 0 ELSE 1 END,
|
||||
</if>
|
||||
m.b_send_time DESC
|
||||
) AS rn
|
||||
FROM b_im_group g
|
||||
INNER JOIN b_im_group_user gu ON g.b_id = gu.b_group_id
|
||||
LEFT JOIN b_im_group_message m ON gu.b_last_message_id = m.b_id
|
||||
WHERE gu.b_user_id = #{userId}
|
||||
) AS t
|
||||
m.b_send_time DESC
|
||||
) AS rn
|
||||
FROM b_im_group g
|
||||
INNER JOIN b_im_group_user gu ON g.b_id = gu.b_group_id
|
||||
LEFT JOIN b_im_group_message m ON gu.b_last_message_id = m.b_id
|
||||
LEFT JOIN b_company_user u ON m.b_sender_id = u.b_id
|
||||
WHERE gu.b_user_id = #{userId}
|
||||
<if test="name != null and name != ''">
|
||||
AND g.b_name LIKE '%' + #{name} + '%'
|
||||
</if>
|
||||
) t
|
||||
WHERE t.rn BETWEEN #{offset} AND #{limit}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectGroupTotal" resultType="java.lang.Long">
|
||||
SELECT COUNT(DISTINCT g.b_id)
|
||||
FROM b_im_group g
|
||||
INNER JOIN b_im_group_user gu ON g.b_id = gu.b_group_id
|
||||
INNER JOIN b_im_group_user gu ON g.b_id = gu.b_group_id
|
||||
WHERE gu.b_user_id = #{userId}
|
||||
<if test="name != null and name != ''">
|
||||
AND g.b_name LIKE '%' + #{name} + '%'
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user