好友/用户搜索优化

master
pan 5 years ago
parent caed343fc4
commit ed8d5c0a4a
  1. 32
      src/main/java/com/share/help/controller/UserController.java
  2. 8
      src/main/java/com/share/help/dao/FriendMapper.java
  3. 10
      src/main/java/com/share/help/form/SearchFrom.java
  4. 4
      src/main/java/com/share/help/service/UserService.java
  5. 17
      src/main/resources/mapping/FriendMapper.xml
  6. 4
      src/test/java/com/share/help/HelpApplicationTests.java

@ -131,21 +131,6 @@ public class UserController {
/**
* 查询用户信息
* @param queryUserForm 搜索条件
* @return 返回查询结果
*/
@GetMapping(Constants.USER_INTERFACE_FIND_NAME)
public JSONResponse<DefaultRes, Page<List<UserWithName>>> queryUser(QueryUserForm queryUserForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(userId!=null){
queryUserForm.setUserId(userId);
return userService.queryUser(queryUserForm);
}else{
return new JSONResponse<>(DefaultRes.fail, Result.FAIL);
}
}
/**
* 留言列表
* @return 返回留言列表
@ -219,6 +204,23 @@ public class UserController {
}
}
/**
* 查询用户信息
* @param queryUserForm 搜索条件
* @return 返回查询结果
*/
@GetMapping(Constants.USER_INTERFACE_FIND_NAME)
public JSONResponse<DefaultRes, Page<List<UserWithName>>> queryUser(QueryUserForm queryUserForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(userId!=null){
queryUserForm.setUserId(userId);
return userService.queryUser(queryUserForm);
}else{
return new JSONResponse<>(DefaultRes.fail, Result.FAIL);
}
}
/**
* 刷新用户的聊天状态
* @param chatForm 刷新表单

@ -24,16 +24,16 @@ public interface FriendMapper {
/**
* 获取好友邀请
* @param userId 目标用户
* @param serviceAddress 服务地点
* @return 返回好友id
*/
List<Friend> getFriend(@Param("userId") String userId, @Param("name") String name, String serviceAddress, @Param("start") long start, @Param("count") long count);
List<Friend> getFriend(@Param("userId") String userId, @Param("name") String name,
@Param("targetUserId") String targetUserId, @Param("start") long start, @Param("count") long count);
/**
* 统计好友分页数
* @param userId 目标用户
* @param serviceAddress 服务地点
* @return 返回分页数
*/
Page<List<Friend>> count(@Param("userId") String userId, @Param("name") String name, String serviceAddress, @Param("pageSize") Integer pageSize);
Page<List<Friend>> count(@Param("userId") String userId, @Param("name") String name,
@Param("targetUserId") String targetUserId, @Param("pageSize") Integer pageSize);
}

@ -10,8 +10,6 @@ public class SearchFrom {
private String targetUserId;
//用户名
private String name;
//服务地点
private String serviceAddress;
//分页数
private Integer currentPage;
@ -46,12 +44,4 @@ public class SearchFrom {
public void setUserId(String userId) {
this.userId = userId;
}
public String getServiceAddress() {
return serviceAddress;
}
public void setServiceAddress(String serviceAddress) {
this.serviceAddress = serviceAddress;
}
}

@ -215,9 +215,9 @@ public class UserService{
* @return 返回好友列表
*/
public JSONResponse<DefaultRes, Page<List<Friend>>> searchFriend(SearchFrom searchFrom) {
Page<List<Friend>> page=friendMapper.count(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getServiceAddress(),friendSize);
Page<List<Friend>> page=friendMapper.count(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getTargetUserId(),friendSize);
page.setCurrentPage(searchFrom.getCurrentPage());
List<Friend> list=friendMapper.getFriend(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getServiceAddress(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize);
List<Friend> list=friendMapper.getFriend(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getTargetUserId(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize);
page.setBody(list);
return new JSONResponse<DefaultRes,Page<List<Friend>>>(DefaultRes.ok,Result.OK).setBody(page);
}

@ -13,12 +13,12 @@
union all
select target_user_id as userId from friend where target_user_id!=#{userId} and source_user_id=#{userId})
<if test="name!=null and name!=''">
and name like '%${name}%'
<if test="targetUserId!=null and targetUserId!=''">
and user_id like '%${targetUserId}%'
</if>
<if test="serviceAddress!=null and serviceAddress!=''">
and service_address like '%${serviceAddress}%'
<if test="name!=null and name!=''">
and name like '%${name}%'
</if>
</where>
limit #{start},#{count}
@ -39,12 +39,13 @@
where target_user_id != #{userId}
and source_user_id = #{userId}
)
<if test="name!=null and name!=''">
and name like '%${name}%'
<if test="targetUserId!=null and targetUserId!=''">
and user_id like '%${targetUserId}%'
</if>
<if test="serviceAddress!=null and serviceAddress!=''">
and service_address like '%${serviceAddress}%'
<if test="name!=null and name!=''">
and name like '%${name}%'
</if>
</where>
</select>

@ -232,9 +232,9 @@ class HelpApplicationTests {
*/
@Test
public void queryFriend(){
Page<List<Friend>> page=friendMapper.count("123","6", "", 3);
Page<List<Friend>> page=friendMapper.count("123","", "2", 3);
Assertions.assertEquals(1, (long) page.getCount());
List<Friend> user=friendMapper.getFriend("123","6", "上海", 0,3);
List<Friend> user=friendMapper.getFriend("123","", "2", 0,3);
Assertions.assertEquals(1,user.size());
user=friendMapper.getFriend("123","6", "广州", 0,3);
Assertions.assertTrue(user.isEmpty());

Loading…
Cancel
Save