修复token
This commit is contained in:
@@ -8,6 +8,8 @@ public class UserContext {
|
|||||||
|
|
||||||
private static final ThreadLocal<Long> USER_HOLDER = new ThreadLocal<>();
|
private static final ThreadLocal<Long> USER_HOLDER = new ThreadLocal<>();
|
||||||
|
|
||||||
|
private static final ThreadLocal<String> TOKEN_HOLDER = new ThreadLocal<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置当前线程的用户ID
|
* 设置当前线程的用户ID
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
@@ -24,12 +26,27 @@ public class UserContext {
|
|||||||
return USER_HOLDER.get();
|
return USER_HOLDER.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前线程的token
|
||||||
|
* @param token 要设置的token字符串
|
||||||
|
*/
|
||||||
|
public static void setToken(String token) {
|
||||||
|
TOKEN_HOLDER.set(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前线程的token
|
||||||
|
* @return 当前token,如果未设置则返回null
|
||||||
|
*/
|
||||||
|
public static String getToken() {
|
||||||
|
return TOKEN_HOLDER.get();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除当前线程的用户ID和token
|
* 清除当前线程的用户ID和token
|
||||||
*/
|
*/
|
||||||
public static void clear() {
|
public static void clear() {
|
||||||
USER_HOLDER.remove();
|
USER_HOLDER.remove();
|
||||||
|
TOKEN_HOLDER.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.bao.dating.pojo.dto.UserDeviceDTO;
|
|||||||
import com.bao.dating.pojo.dto.UserInfoDTO;
|
import com.bao.dating.pojo.dto.UserInfoDTO;
|
||||||
import com.bao.dating.pojo.dto.UserLoginDTO;
|
import com.bao.dating.pojo.dto.UserLoginDTO;
|
||||||
import com.bao.dating.pojo.dto.UserLoginWithDeviceDTO;
|
import com.bao.dating.pojo.dto.UserLoginWithDeviceDTO;
|
||||||
|
import com.bao.dating.pojo.entity.User;
|
||||||
import com.bao.dating.pojo.vo.UserDeviceVO;
|
import com.bao.dating.pojo.vo.UserDeviceVO;
|
||||||
import com.bao.dating.pojo.vo.UserInfoVO;
|
import com.bao.dating.pojo.vo.UserInfoVO;
|
||||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
import com.bao.dating.pojo.vo.UserLoginVO;
|
||||||
@@ -242,4 +243,19 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户名/爱好标签搜索用户
|
||||||
|
*
|
||||||
|
* @param userName 用户名(模糊匹配)
|
||||||
|
* @param hobbies 爱好标签(精确匹配单个标签)
|
||||||
|
* @return 符合条件的用户列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/api/users/search")
|
||||||
|
public List<User> searchUsers(
|
||||||
|
@RequestParam(required = false) String userName,
|
||||||
|
@RequestParam(required = false) String hobbies) {
|
||||||
|
// 调用Service层的搜索方法
|
||||||
|
return userService.searchUsers(userName, hobbies);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,4 +68,13 @@ public interface UserMapper {
|
|||||||
* @return 用户列表
|
* @return 用户列表
|
||||||
*/
|
*/
|
||||||
List<UserInfoVO> findByLatLngRange(@Param("minLat") double minLat, @Param("maxLat") double maxLat, @Param("minLng") double minLng, @Param("maxLng") double maxLng);
|
List<UserInfoVO> findByLatLngRange(@Param("minLat") double minLat, @Param("maxLat") double maxLat, @Param("minLng") double minLng, @Param("maxLng") double maxLng);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索用户
|
||||||
|
* @param userName 用户名
|
||||||
|
* @param hobbyTag 爱好标签
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
List<User> searchUsers(@Param("userName") String userName, @Param("hobbies") String hobbyTag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.bao.dating.service;
|
|||||||
|
|
||||||
import com.bao.dating.pojo.dto.UserInfoDTO;
|
import com.bao.dating.pojo.dto.UserInfoDTO;
|
||||||
import com.bao.dating.pojo.dto.UserLoginDTO;
|
import com.bao.dating.pojo.dto.UserLoginDTO;
|
||||||
|
import com.bao.dating.pojo.entity.User;
|
||||||
import com.bao.dating.pojo.vo.UserInfoVO;
|
import com.bao.dating.pojo.vo.UserInfoVO;
|
||||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
import com.bao.dating.pojo.vo.UserLoginVO;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -99,4 +100,12 @@ public interface UserService {
|
|||||||
* @return 是否在线
|
* @return 是否在线
|
||||||
*/
|
*/
|
||||||
boolean isUserOnline(Long userId);
|
boolean isUserOnline(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索用户
|
||||||
|
* @param userName 用户名(模糊)
|
||||||
|
* @param hobbies 爱好标签(精确)
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
List<User> searchUsers(String userName, String hobbies);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class UserServiceImpl implements UserService {
|
public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SmsUtil smsUtil;
|
private SmsUtil smsUtil;
|
||||||
|
|
||||||
@@ -517,4 +518,11 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
return Boolean.TRUE.equals(online);
|
return Boolean.TRUE.equals(online);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> searchUsers(String userName, String hobbies) {
|
||||||
|
// 调用Mapper层的查询方法
|
||||||
|
return userMapper.searchUsers(userName, hobbies);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -130,5 +130,17 @@
|
|||||||
FROM user WHERE user_latitude BETWEEN #{minLat} AND #{maxLat} AND user_longitude BETWEEN #{minLng} AND #{maxLng}
|
FROM user WHERE user_latitude BETWEEN #{minLat} AND #{maxLat} AND user_longitude BETWEEN #{minLng} AND #{maxLng}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 搜索用户:支持用户名模糊匹配、爱好标签精确匹配 -->
|
||||||
|
<select id="searchUsers" resultMap="UserResultMap">
|
||||||
|
SELECT * FROM user
|
||||||
|
WHERE 1=1
|
||||||
|
<!-- 用户名模糊搜索 -->
|
||||||
|
<if test="userName != null and userName != ''">
|
||||||
|
AND user_name LIKE CONCAT('%', #{userName}, '%')
|
||||||
|
</if>
|
||||||
|
<!-- 爱好标签搜索:MySQL 8.0+ 支持JSON_CONTAINS -->
|
||||||
|
<if test="hobbies != null and hobbies != ''">
|
||||||
|
AND JSON_CONTAINS(hobbies, CONCAT('"', #{hobbies}, '"'))
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user