优化查询条件

This commit is contained in:
wangxulei 2024-12-31 16:40:36 +08:00
parent 13e75b5b5e
commit a116c6276c
6 changed files with 41 additions and 37 deletions

View File

@ -216,10 +216,8 @@ public class AuthApi {
@OperLog(operModule = "获取关注目标作者的所有粉丝",operType = OperType.QUERY,operDesc = "获取关注目标作者的所有粉丝") @OperLog(operModule = "获取关注目标作者的所有粉丝",operType = OperType.QUERY,operDesc = "获取关注目标作者的所有粉丝")
public ResultBean getFollowMes(String authorId) { public ResultBean getFollowMes(String authorId) {
String myId = String.valueOf(request.getAttribute("authorId")); String myId = String.valueOf(request.getAttribute("authorId"));
//关注我的列表 //关注我的列表
List<FollowVo> followMes = followService.selectFollowMeList(authorId,myId); List<FollowVo> followMes = followService.selectFollowMeList(authorId,myId);
return ResultBean.success(followMes); return ResultBean.success(followMes);
} }
@ -229,7 +227,6 @@ public class AuthApi {
@OperLog(operModule = "getMyFollows",operType = OperType.QUERY,operDesc = "获取关注目标作者的所有粉丝") @OperLog(operModule = "getMyFollows",operType = OperType.QUERY,operDesc = "获取关注目标作者的所有粉丝")
public ResultBean getMyFollows(String authorId) { public ResultBean getMyFollows(String authorId) {
String myId = String.valueOf(request.getAttribute("authorId")); String myId = String.valueOf(request.getAttribute("authorId"));
//关注我的列表 //关注我的列表
List<FollowVo> myFollows = followService.selectMyFollowList(authorId,myId); List<FollowVo> myFollows = followService.selectMyFollowList(authorId,myId);
return ResultBean.success(myFollows); return ResultBean.success(myFollows);

View File

@ -15,6 +15,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
/** /**
@ -73,4 +74,8 @@ public class ChatVo {
private String fromAvatar; private String fromAvatar;
private String toAvatar; private String toAvatar;
private String authorId;
private String authorName;
private String authorAvatar;
} }

View File

@ -25,5 +25,6 @@ public interface ChatMapper extends BaseMapper<Chat> {
IPage<ChatVo> selectChatPage(Page<ChatVo> page, @Param("chatDto") ChatDto chatDto); IPage<ChatVo> selectChatPage(Page<ChatVo> page, @Param("chatDto") ChatDto chatDto);
ChatVo selectChat(@Param("chatId") String chatId); ChatVo selectChat(@Param("chatId") String chatId);
List<ChatVo> selectChatDetail(@Param("chatDto") ChatDto chatDto); List<ChatVo> selectChatDetail(@Param("chatDto") ChatDto chatDto);
List<ChatVo> selectChatList(@Param("toId")String toId); //查询我的聊天记录列表 当我作为收发方都需要考虑
List<ChatVo> selectChatList(@Param("authorId")String authorId);
} }

View File

@ -60,35 +60,36 @@
</select> </select>
<select id="selectChatList" resultType="com.dd.admin.business.chat.domain.ChatVo" <select id="selectChatList" resultType="com.dd.admin.business.chat.domain.ChatVo"
parameterType="java.lang.String"> parameterType="java.lang.String">
SELECT select * from (
c.* SELECT
FROM a.FROM_ID AS authorId,
( a.FROM_NAME AS authorName,
SELECT b.AVATAR_URL AS authorAvatar,
DISTINCT a.FROM_ID, a.content,
a.CHAT_ID, a.create_time
a.FROM_NAME, FROM
a.TO_ID, business_chat a
a.TO_NAME, LEFT JOIN
a.MESSAGE_TYPE, business_author b ON a.FROM_ID = b.AUTHOR_ID
a.MESSAGE_STATUS, WHERE
a.CONTENT, a.TO_ID = #{authorId}
a.RESOURCE_URL, UNION ALL
a.DELETED, SELECT
a.CREATE_TIME, a.TO_ID AS authorId,
a.IP_ADDRESS, a.TO_NAME AS authorName,
a.IP_REAL_ADDRESS, b.AVATAR_URL AS authorAvatar,
b.AVATAR_URL a.content,
AS fromAvatar a.create_time
FROM FROM
business_chat a business_chat a
LEFT JOIN business_author b ON a.FROM_ID = b.AUTHOR_ID LEFT JOIN
WHERE business_author b ON a.TO_ID = b.AUTHOR_ID
a.TO_ID = #{toId} WHERE
ORDER BY a.FROM_ID = #{authorId}
a.create_time DESC ORDER BY
) c create_time DESC
GROUP BY ) a1
c.TO_ID = #{toId} GROUP BY a1.authorId
</select> </select>
</mapper> </mapper>

View File

@ -24,6 +24,6 @@ public interface ChatService extends IService<Chat> {
ChatVo selectChat(String chatId); ChatVo selectChat(String chatId);
//-列表 //-列表
List<ChatVo> selectChatDetail(ChatDto chatDto); List<ChatVo> selectChatDetail(ChatDto chatDto);
List<ChatVo> selectChatList(String toId); List<ChatVo> selectChatList(String authorId);
} }

View File

@ -40,7 +40,7 @@ public class ChatServiceImpl extends ServiceImpl<ChatMapper, Chat> implements Ch
} }
@Override @Override
public List<ChatVo> selectChatList(String toId) { public List<ChatVo> selectChatList(String authorId) {
return baseMapper.selectChatList(toId); return baseMapper.selectChatList(authorId);
} }
} }