Compare commits
16 Commits
123321
...
0a17eb8deb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a17eb8deb | ||
|
|
448ce1d3d6 | ||
|
|
a4e66b39d1 | ||
|
|
0a1425c7ab | ||
|
|
21c0a94a5d | ||
|
|
b6953cb8d0 | ||
|
|
f6769c8c69 | ||
|
|
5e1f3b7e8a | ||
|
|
e30a0dba97 | ||
|
|
74d47d586f | ||
|
|
0bb69075f7 | ||
|
|
1d179da910 | ||
|
|
c0969406b3 | ||
|
|
2a9acb946e | ||
|
|
fb2b7823b8 | ||
|
|
951cd7249d |
6
pom.xml
6
pom.xml
@@ -171,6 +171,12 @@
|
|||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
|
<version>1.4.7</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ public class SmsUtil {
|
|||||||
.setTemplateCode(templateCode != null ? templateCode : this.templateCode)
|
.setTemplateCode(templateCode != null ? templateCode : this.templateCode)
|
||||||
.setTemplateParam(templateParam);
|
.setTemplateParam(templateParam);
|
||||||
|
|
||||||
log.error("TemplateParam 实际值 = {}", templateParam);
|
|
||||||
|
|
||||||
SendSmsResponse response = client.sendSms(sendSmsRequest);
|
SendSmsResponse response = client.sendSms(sendSmsRequest);
|
||||||
|
|
||||||
if ("OK".equals(response.getBody().getCode())) {
|
if ("OK".equals(response.getBody().getCode())) {
|
||||||
@@ -147,7 +145,6 @@ public class SmsUtil {
|
|||||||
jsonBuilder.append("}");
|
jsonBuilder.append("}");
|
||||||
return sendSms(phoneNumber, templateCode, jsonBuilder.toString());
|
return sendSms(phoneNumber, templateCode, jsonBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.bao.dating.common.result;
|
||||||
|
|
||||||
|
import com.bao.dating.pojo.vo.ChatRecordsVO;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天发送结果
|
||||||
|
* @author KilLze
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatSendResult {
|
||||||
|
private boolean success;
|
||||||
|
private String message;
|
||||||
|
private ChatRecordsVO record;
|
||||||
|
}
|
||||||
28
src/main/java/com/bao/dating/common/result/PageResult.java
Normal file
28
src/main/java/com/bao/dating/common/result/PageResult.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package com.bao.dating.common.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PageResult<T> {
|
||||||
|
/** 总记录数 */
|
||||||
|
private Long total;
|
||||||
|
/** 当前页码 */
|
||||||
|
private Integer page;
|
||||||
|
/** 每页大小 */
|
||||||
|
private Integer size;
|
||||||
|
/** 总页数 */
|
||||||
|
private Integer pages;
|
||||||
|
/** 当前页数据 */
|
||||||
|
private List<T> records;
|
||||||
|
|
||||||
|
public PageResult(Long total, Integer page, Integer size, List<T> records) {
|
||||||
|
this.total = total;
|
||||||
|
this.page = page;
|
||||||
|
this.size = size;
|
||||||
|
this.records = records;
|
||||||
|
// 计算总页数
|
||||||
|
this.pages = (int) Math.ceil((double) total / size);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.bao.dating.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "aliyun.oss")
|
|
||||||
public class AliyunOSSConfig {
|
|
||||||
private String endpoint;
|
|
||||||
private String accessKeyId;
|
|
||||||
private String accessKeySecret;
|
|
||||||
private String bucketName;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -14,9 +14,9 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class RedisConfig {
|
public class RedisConfig {
|
||||||
@Bean
|
@Bean
|
||||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||||
// 创建RedisTemplate对象
|
// 创建RedisTemplate对象
|
||||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
RedisTemplate redisTemplate = new RedisTemplate<>();
|
||||||
// 设置redis的连接工厂对象
|
// 设置redis的连接工厂对象
|
||||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
.addPathPatterns("/**")
|
.addPathPatterns("/**")
|
||||||
// 忽略的接口
|
// 忽略的接口
|
||||||
.excludePathPatterns(
|
.excludePathPatterns(
|
||||||
"/user/login",
|
"/user/login"
|
||||||
"/user/sendCode",
|
|
||||||
"/download/{postId}"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/main/java/com/bao/dating/config/WebSocketConfig.java
Normal file
35
src/main/java/com/bao/dating/config/WebSocketConfig.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package com.bao.dating.config;
|
||||||
|
|
||||||
|
|
||||||
|
import com.bao.dating.controller.websocket.ChatWebSocketHandler;
|
||||||
|
import com.bao.dating.interceptor.WsAuthInterceptor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||||
|
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||||
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket 配置类
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSocket
|
||||||
|
public class WebSocketConfig implements WebSocketConfigurer {
|
||||||
|
@Autowired
|
||||||
|
private ChatWebSocketHandler chatWebSocketHandler;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WsAuthInterceptor wsAuthInterceptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册 WebSocket 处理器
|
||||||
|
* @param registry
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||||
|
registry.addHandler(chatWebSocketHandler, "/ws/chat")
|
||||||
|
.addInterceptors(wsAuthInterceptor)
|
||||||
|
.setAllowedOrigins("*");
|
||||||
|
}
|
||||||
|
}
|
||||||
104
src/main/java/com/bao/dating/controller/ChatController.java
Normal file
104
src/main/java/com/bao/dating/controller/ChatController.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package com.bao.dating.controller;
|
||||||
|
|
||||||
|
import com.bao.dating.common.Result;
|
||||||
|
import com.bao.dating.common.ResultCode;
|
||||||
|
import com.bao.dating.common.result.PageResult;
|
||||||
|
import com.bao.dating.context.UserContext;
|
||||||
|
import com.bao.dating.pojo.dto.*;
|
||||||
|
import com.bao.dating.pojo.vo.ChatRecordsVO;
|
||||||
|
import com.bao.dating.pojo.vo.ChatSessionsVO;
|
||||||
|
import com.bao.dating.service.ChatService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天控制器
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/chat")
|
||||||
|
public class ChatController {
|
||||||
|
@Autowired
|
||||||
|
private ChatService chatService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
* @param file 文件
|
||||||
|
* @return 文件URL
|
||||||
|
*/
|
||||||
|
@PostMapping("/upload")
|
||||||
|
public Result<String> uploadVideo(@RequestParam MultipartFile file) {
|
||||||
|
String url = chatService.uploadChat(file);
|
||||||
|
return Result.success(ResultCode.SUCCESS, "文件上传成功", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取聊天记录
|
||||||
|
* @param targetUserId 目标用户ID
|
||||||
|
* @param pageDTO 分页参数
|
||||||
|
* @return 聊天记录列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/history/{targetUserId}")
|
||||||
|
public Result<List<ChatRecordsVO>> getChatHistory(
|
||||||
|
@PathVariable Long targetUserId,
|
||||||
|
ChatCursorPageDTO pageDTO){
|
||||||
|
Long currentUserId = UserContext.getUserId();
|
||||||
|
ChatHistoryQueryDTO queryDTO = new ChatHistoryQueryDTO();
|
||||||
|
queryDTO.setCurrentUserId(currentUserId);
|
||||||
|
queryDTO.setTargetUserId(targetUserId);
|
||||||
|
queryDTO.setCursor(pageDTO.getCursor());
|
||||||
|
queryDTO.setSize(pageDTO.getSize());
|
||||||
|
chatService.markChatMessagesAsRead(currentUserId, targetUserId);
|
||||||
|
List<ChatRecordsVO> history = chatService.getChatHistory(queryDTO);
|
||||||
|
return Result.success(ResultCode.SUCCESS, "获取聊天记录成功", history);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取会话列表
|
||||||
|
* @return 会话列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/sessions")
|
||||||
|
public Result<List<ChatSessionsVO>> getSessionList() {
|
||||||
|
Long currentUserId = UserContext.getUserId();
|
||||||
|
List<ChatSessionsVO> list = chatService.getSessionList(currentUserId);
|
||||||
|
return Result.success(ResultCode.SUCCESS, "获取会话列表成功", list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新会话状态
|
||||||
|
* @param dto 会话状态
|
||||||
|
* @return 无
|
||||||
|
*/
|
||||||
|
@PostMapping("/session/status")
|
||||||
|
public Result<Void> updateSessionStatus(@RequestBody ChatSessionStatusDTO dto) {
|
||||||
|
chatService.updateSessionStatus(UserContext.getUserId(), dto);
|
||||||
|
return Result.success(ResultCode.SUCCESS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 置顶会话
|
||||||
|
* @param dto 置顶状态
|
||||||
|
* @return 无
|
||||||
|
*/
|
||||||
|
@PostMapping("/session/top")
|
||||||
|
public Result<Void> updateTopStatus(@RequestBody ChatSessionTopDTO dto) {
|
||||||
|
chatService.updateTopStatus(UserContext.getUserId(), dto);
|
||||||
|
return Result.success(ResultCode.SUCCESS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静音会话
|
||||||
|
* @param dto 静音状态
|
||||||
|
* @return 无
|
||||||
|
*/
|
||||||
|
@PostMapping("/session/mute")
|
||||||
|
public Result<Void> updateMuteStatus(@RequestBody ChatSessionMuteDTO dto) {
|
||||||
|
chatService.updateMuteStatus(UserContext.getUserId(), dto);
|
||||||
|
return Result.success(ResultCode.SUCCESS, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,9 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +31,6 @@ public class PostController {
|
|||||||
* @param files 媒体文件数组
|
* @param files 媒体文件数组
|
||||||
* @return 上传后的文件URL列表
|
* @return 上传后的文件URL列表
|
||||||
*/
|
*/
|
||||||
@Log
|
|
||||||
@PostMapping(value = "/upload", consumes = "multipart/form-data")
|
@PostMapping(value = "/upload", consumes = "multipart/form-data")
|
||||||
public Result<List<String>> uploadMedia(@RequestParam("files") MultipartFile[] files) {
|
public Result<List<String>> uploadMedia(@RequestParam("files") MultipartFile[] files) {
|
||||||
List<String> fileUrls = postService.uploadMedia(files);
|
List<String> fileUrls = postService.uploadMedia(files);
|
||||||
@@ -46,7 +42,6 @@ public class PostController {
|
|||||||
* @param postDTO 动态信息
|
* @param postDTO 动态信息
|
||||||
* @return 发布的动态对象
|
* @return 发布的动态对象
|
||||||
*/
|
*/
|
||||||
@Log
|
|
||||||
@PostMapping( "/createPost")
|
@PostMapping( "/createPost")
|
||||||
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO) {
|
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO) {
|
||||||
// 调用 Service 层处理发布动态业务逻辑
|
// 调用 Service 层处理发布动态业务逻辑
|
||||||
@@ -60,7 +55,6 @@ public class PostController {
|
|||||||
* @param postIds 动态ID
|
* @param postIds 动态ID
|
||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
*/
|
*/
|
||||||
@Log
|
|
||||||
@PostMapping("/deletePost")
|
@PostMapping("/deletePost")
|
||||||
public Result<String> deleteById(@RequestBody List<Long> postIds){
|
public Result<String> deleteById(@RequestBody List<Long> postIds){
|
||||||
int deletedCount = postService.deletePostById(postIds);
|
int deletedCount = postService.deletePostById(postIds);
|
||||||
@@ -84,26 +78,9 @@ public class PostController {
|
|||||||
* @param postRequestDTO 动态信息
|
* @param postRequestDTO 动态信息
|
||||||
* @return 更新后的动态对象
|
* @return 更新后的动态对象
|
||||||
*/
|
*/
|
||||||
@Log
|
|
||||||
@PostMapping("/{postId}/updatePost")
|
@PostMapping("/{postId}/updatePost")
|
||||||
public Result<PostEditVO> updatePost(@PathVariable Long postId, @RequestBody PostRequestDTO postRequestDTO) {
|
public Result<PostEditVO> updatePost(@PathVariable Long postId, @RequestBody PostRequestDTO postRequestDTO) {
|
||||||
PostEditVO result = postService.updatePost(postId, postRequestDTO);
|
PostEditVO result = postService.updatePost(postId, postRequestDTO);
|
||||||
return Result.success(ResultCode.SUCCESS, "动态更新成功", result);
|
return Result.success(ResultCode.SUCCESS, "动态更新成功", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/download/{postId}")
|
|
||||||
public void downloadPostImage(@PathVariable Long postId, HttpServletResponse response) throws Exception {
|
|
||||||
try {
|
|
||||||
//Service 返回已经加好水印的图片
|
|
||||||
BufferedImage image = postService.downloadWithWatermark(postId);
|
|
||||||
//设置响应头,触发浏览器下载
|
|
||||||
response.setContentType("image/jpeg");
|
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=post_" + postId + ".jpg");
|
|
||||||
//输出到浏览器
|
|
||||||
ImageIO.write(image, "jpg", response.getOutputStream());
|
|
||||||
response.getOutputStream().flush();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,20 +4,16 @@ import com.bao.dating.anno.Log;
|
|||||||
import com.bao.dating.common.Result;
|
import com.bao.dating.common.Result;
|
||||||
import com.bao.dating.common.ResultCode;
|
import com.bao.dating.common.ResultCode;
|
||||||
import com.bao.dating.context.UserContext;
|
import com.bao.dating.context.UserContext;
|
||||||
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
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 com.bao.dating.service.UserService;
|
import com.bao.dating.service.UserService;
|
||||||
import io.jsonwebtoken.Jwt;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户接口
|
* 用户接口
|
||||||
@@ -91,77 +87,10 @@ public class UserController {
|
|||||||
* @return 更新后的用户信息
|
* @return 更新后的用户信息
|
||||||
*/
|
*/
|
||||||
@PostMapping("/info/update")
|
@PostMapping("/info/update")
|
||||||
public Result<UserInfoVO> userInfoUpdate(@RequestBody UserInfoUpdateDTO userInfoUpdateDTO) {
|
public Result<UserInfoVO> userInfoUpdate(@RequestBody UserInfoDTO userInfoUpdateDTO) {
|
||||||
Long userId = UserContext.getUserId();
|
Long userId = UserContext.getUserId();
|
||||||
userInfoUpdateDTO.setUserId(userId);
|
userInfoUpdateDTO.setUserId(userId);
|
||||||
UserInfoVO userInfoVO =userService.updateUserInfo(userInfoUpdateDTO);
|
UserInfoVO userInfoVO =userService.updateUserInfo(userInfoUpdateDTO);
|
||||||
return Result.success(ResultCode.SUCCESS, "用户信息更新成功", userInfoVO);
|
return Result.success(ResultCode.SUCCESS, "用户信息更新成功", userInfoVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/sendCode")
|
|
||||||
public Result sendCode(@RequestBody Map<String, String> body) {
|
|
||||||
String phone = body.get("phone");
|
|
||||||
userService.sendSmsCode(phone);
|
|
||||||
return Result.success(ResultCode.SUCCESS, "验证码发送成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/loginByCode")
|
|
||||||
public Result loginByCode(@RequestBody Map<String, String> body){
|
|
||||||
boolean ok = userService.verifyCode(body.get("phone"), body.get("code"));
|
|
||||||
return ok ? Result.success(ResultCode.SUCCESS, "登录成功") : Result.error(ResultCode.SYSTEM_ERROR, "登录失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录
|
|
||||||
* @param body 登录参数
|
|
||||||
*/
|
|
||||||
@PostMapping("/loginPhone")
|
|
||||||
public Result<?> loginPhone(@RequestBody Map<String, String> body) {
|
|
||||||
String phone = body.get("phone");
|
|
||||||
String code = body.get("code");
|
|
||||||
|
|
||||||
//校验验证码
|
|
||||||
boolean verify = userService.verifyCode(phone, code);
|
|
||||||
if (!verify){
|
|
||||||
return Result.error(ResultCode.SYSTEM_ERROR, "验证码错误或已过期");
|
|
||||||
}
|
|
||||||
//登录
|
|
||||||
UserLoginVO vo = userService.loginByPhone(phone);
|
|
||||||
return Result.success(ResultCode.SUCCESS, "登录成功", vo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/nearby")
|
|
||||||
public Result<List<UserInfoVO>> nearby(@RequestParam(defaultValue = "5") double distance){
|
|
||||||
// 获取当前线程的用户 ID
|
|
||||||
Long userId = UserContext.getUserId();
|
|
||||||
if (userId == null) {
|
|
||||||
return Result.error(ResultCode.SYSTEM_ERROR, "用户未登录");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 通过 UserID 获取当前用户的经纬度信息
|
|
||||||
UserInfoVO currentUser = userService.getUserInfo(userId);
|
|
||||||
if (currentUser == null) {
|
|
||||||
return Result.error(ResultCode.SYSTEM_ERROR, "用户信息获取失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取当前用户的经纬度
|
|
||||||
Double latitude = currentUser.getLatitude();
|
|
||||||
Double longitude = currentUser.getLongitude();
|
|
||||||
|
|
||||||
// 检查经纬度是否为空
|
|
||||||
if (latitude == null || longitude == null) {
|
|
||||||
return Result.error(ResultCode.SYSTEM_ERROR, "用户经纬度信息未完善");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 这里可以添加默认值,比如如果 latitude 或 longitude 为 null,则设置为某个默认值(例如 0)
|
|
||||||
latitude = (latitude != null) ? latitude : 0.0;
|
|
||||||
longitude = (longitude != null) ? longitude : 0.0;
|
|
||||||
|
|
||||||
// 查询附近用户
|
|
||||||
List<UserInfoVO> nearbyUsers = userService.findNearbyUsers(latitude, longitude, distance);
|
|
||||||
|
|
||||||
// 返回成功结果
|
|
||||||
return Result.success(ResultCode.SUCCESS, "查询成功", nearbyUsers);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package com.bao.dating.controller.websocket;
|
||||||
|
|
||||||
|
import com.bao.dating.message.WsMessage;
|
||||||
|
import com.bao.dating.pojo.dto.ChatRecordSendDTO;
|
||||||
|
import com.bao.dating.pojo.vo.ChatRecordsVO;
|
||||||
|
import com.bao.dating.service.ChatService;
|
||||||
|
import com.bao.dating.session.WsSessionManager;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.socket.CloseStatus;
|
||||||
|
import org.springframework.web.socket.TextMessage;
|
||||||
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket处理器类
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class ChatWebSocketHandler extends TextWebSocketHandler {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChatService chatService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WsSessionManager sessionManager;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户建立连接(上线)
|
||||||
|
* @param session WebSocketSession
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterConnectionEstablished(WebSocketSession session) {
|
||||||
|
Long userId = (Long) session.getAttributes().get("userId");
|
||||||
|
sessionManager.addSession(userId, session);
|
||||||
|
log.info("用户 " + userId + " 已上线");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收并处理消息
|
||||||
|
* @param session WebSocketSession
|
||||||
|
* @param message 消息
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception{
|
||||||
|
// 获取当前用户ID
|
||||||
|
Long senderUserId = (Long) session.getAttributes().get("userId");
|
||||||
|
if (senderUserId == null) {
|
||||||
|
log.error("WebSocket session 中未找到 userId");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 解析消息
|
||||||
|
WsMessage<ChatRecordSendDTO> wsMessage =
|
||||||
|
objectMapper.readValue(message.getPayload(),
|
||||||
|
new TypeReference<WsMessage<ChatRecordSendDTO>>(){});
|
||||||
|
|
||||||
|
// 处理私聊消息
|
||||||
|
if ("chat".equals(wsMessage.getType())) {
|
||||||
|
handlePrivateChat(session, senderUserId, wsMessage.getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私聊处理
|
||||||
|
*/
|
||||||
|
private void handlePrivateChat(WebSocketSession session, Long senderUserId, ChatRecordSendDTO dto) throws Exception {
|
||||||
|
|
||||||
|
// 1. 消息入库 + 会话更新
|
||||||
|
ChatRecordsVO chatRecordsVO = chatService.createSession(senderUserId, dto);
|
||||||
|
if (chatRecordsVO == null){
|
||||||
|
WsMessage<String> errorMsg = new WsMessage<>();
|
||||||
|
errorMsg.setType("error");
|
||||||
|
errorMsg.setData("会话已删除,无法发送消息");
|
||||||
|
session.sendMessage(new TextMessage(objectMapper.writeValueAsString(errorMsg)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2. 推送给接收方
|
||||||
|
WebSocketSession receiverSession =
|
||||||
|
sessionManager.getSession(dto.getReceiverUserId());
|
||||||
|
|
||||||
|
if (receiverSession != null && receiverSession.isOpen()) {
|
||||||
|
WsMessage<ChatRecordsVO> pushMsg = new WsMessage<>();
|
||||||
|
pushMsg.setType("chat");
|
||||||
|
pushMsg.setData(chatRecordsVO);
|
||||||
|
|
||||||
|
receiverSession.sendMessage(
|
||||||
|
new TextMessage(objectMapper.writeValueAsString(pushMsg))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户断开连接(下线)
|
||||||
|
* @param session WebSocketSession
|
||||||
|
* @param status 断开原因
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterConnectionClosed(WebSocketSession session, CloseStatus status){
|
||||||
|
// 下线处理
|
||||||
|
Long userId = (Long) session.getAttributes().get("userId");
|
||||||
|
sessionManager.removeSession(userId);
|
||||||
|
log.info("用户 " + userId + " 已下线");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
|||||||
public class TokenInterceptor implements HandlerInterceptor {
|
public class TokenInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在请求处理之前进行拦截
|
* 在请求处理之前进行拦截
|
||||||
@@ -68,7 +68,7 @@ public class TokenInterceptor implements HandlerInterceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 解析 token
|
// 解析 token
|
||||||
String userId = JwtUtil.getSubjectFromToken(token);
|
Long userId = Long.valueOf(JwtUtil.getSubjectFromToken(token));
|
||||||
|
|
||||||
// 从Redis获取存储的token进行比对
|
// 从Redis获取存储的token进行比对
|
||||||
Object redisTokenObj = redisTemplate.opsForValue().get("login:token:" + userId);
|
Object redisTokenObj = redisTemplate.opsForValue().get("login:token:" + userId);
|
||||||
@@ -85,7 +85,7 @@ public class TokenInterceptor implements HandlerInterceptor {
|
|||||||
|
|
||||||
log.info("用户: {}", userId);
|
log.info("用户: {}", userId);
|
||||||
// 保存 userId 到 ThreadLocal
|
// 保存 userId 到 ThreadLocal
|
||||||
UserContext.setUserId(Long.valueOf(userId));
|
UserContext.setUserId(userId);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Token 校验失败: {}", e.getMessage());
|
log.error("Token 校验失败: {}", e.getMessage());
|
||||||
|
|||||||
111
src/main/java/com/bao/dating/interceptor/WsAuthInterceptor.java
Normal file
111
src/main/java/com/bao/dating/interceptor/WsAuthInterceptor.java
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
package com.bao.dating.interceptor;
|
||||||
|
|
||||||
|
import com.bao.dating.util.JwtUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.http.server.ServerHttpRequest;
|
||||||
|
import org.springframework.http.server.ServerHttpResponse;
|
||||||
|
import org.springframework.http.server.ServletServerHttpRequest;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.socket.WebSocketHandler;
|
||||||
|
import org.springframework.web.socket.server.HandshakeInterceptor;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket 认证拦截器
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class WsAuthInterceptor implements HandshakeInterceptor {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
/**
|
||||||
|
* 拦截WebSocket连接请求
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
|
||||||
|
log.info("开始WebSocket握手认证");
|
||||||
|
|
||||||
|
// 获取请求参数
|
||||||
|
if (!(request instanceof ServletServerHttpRequest)) {
|
||||||
|
log.error("WebSocket握手失败:非HTTP请求");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取HttpServletRequest对象
|
||||||
|
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
|
||||||
|
|
||||||
|
// 从URL参数中获取token
|
||||||
|
String token = servletRequest.getParameter("token");
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(token)) {
|
||||||
|
log.error("WebSocket握手失败:令牌丢失");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 验证 token 是否有效(包括是否过期)
|
||||||
|
if (!JwtUtil.validateToken(token)) {
|
||||||
|
log.error("Token无效或已过期: {}", token);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查 token 是否在黑名单中
|
||||||
|
String blacklistKey = "jwt:blacklist:" + token;
|
||||||
|
Object blacklistToken = redisTemplate.opsForValue().get(blacklistKey);
|
||||||
|
if (blacklistToken != null) {
|
||||||
|
log.error("Token已在黑名单中: {}", token);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证token并获取用户ID
|
||||||
|
String userIdStr = JwtUtil.getSubjectFromToken(token);
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(userIdStr) || !userIdStr.matches("\\d+")) {
|
||||||
|
log.error("无效的用户ID格式: {}", userIdStr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Long userId = Long.valueOf(userIdStr);
|
||||||
|
|
||||||
|
// 从Redis获取存储的token进行比对
|
||||||
|
String redisTokenKey = "login:token:" + userId;
|
||||||
|
Object redisTokenObj = redisTemplate.opsForValue().get(redisTokenKey);
|
||||||
|
String redisToken = redisTokenObj != null ? redisTokenObj.toString() : null;
|
||||||
|
log.info("Redis中存储的token: {}", redisToken != null ? "存在" : "不存在");
|
||||||
|
|
||||||
|
// 验证Redis中的token是否存在且匹配
|
||||||
|
if (redisToken == null || !redisToken.equals(token)) {
|
||||||
|
log.error("登录已失效 - Redis中token不存在或不匹配");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("WebSocket认证成功,用户ID: {}", userId);
|
||||||
|
// 将用户ID保存到attributes中
|
||||||
|
attributes.put("userId", userId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
log.error("用户ID格式转换异常: {}", e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.error("WebSocket握手失败:{}", e.getMessage(), e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {
|
||||||
|
if (exception != null) {
|
||||||
|
log.error("WebSocket握手后出现异常:", exception);
|
||||||
|
} else {
|
||||||
|
log.info("WebSocket握手完成");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/main/java/com/bao/dating/mapper/ChatRecordsMapper.java
Normal file
35
src/main/java/com/bao/dating/mapper/ChatRecordsMapper.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package com.bao.dating.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.bao.dating.pojo.dto.ChatHistoryQueryDTO;
|
||||||
|
import com.bao.dating.pojo.dto.ChatMarkReadDTO;
|
||||||
|
import com.bao.dating.pojo.entity.ChatRecords;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ChatRecordsMapper {
|
||||||
|
/**
|
||||||
|
* 插入聊天记录
|
||||||
|
* @param chatRecords 聊天记录
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int insert(ChatRecords chatRecords);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据时间游标查询聊天记录
|
||||||
|
* @param queryDTO 查询参数
|
||||||
|
* @return 聊天记录列表
|
||||||
|
*/
|
||||||
|
List<ChatRecords> selectChatHistoryByCursor(ChatHistoryQueryDTO queryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记聊天记录为已读
|
||||||
|
* @param markReadDTO 标记参数
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int markMessagesAsRead(ChatMarkReadDTO markReadDTO);
|
||||||
|
}
|
||||||
88
src/main/java/com/bao/dating/mapper/ChatSessionsMapper.java
Normal file
88
src/main/java/com/bao/dating/mapper/ChatSessionsMapper.java
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package com.bao.dating.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.bao.dating.pojo.entity.ChatRecords;
|
||||||
|
import com.bao.dating.pojo.entity.ChatSessions;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface ChatSessionsMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果发送方存在会话则更新,不存在则创建
|
||||||
|
* @param chatSessions 会话
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int upsertSessionForSender(ChatSessions chatSessions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取会话
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param targetUserId 目标用户ID
|
||||||
|
* @return 会话
|
||||||
|
*/
|
||||||
|
@Select("SELECT * FROM chat_sessions WHERE user_id = #{userId} AND target_user_id = #{targetUserId} LIMIT 1")
|
||||||
|
ChatSessions getSession(@Param("userId") Long userId, @Param("targetUserId") Long targetUserId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果接收方存在会话则更新,不存在则创建
|
||||||
|
* @param chatSessions 会话
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int upsertSessionForReceiver(ChatSessions chatSessions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空会话的未读数
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param targetUserId 目标用户ID
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int clearUnreadCount(
|
||||||
|
@Param("userId") Long userId,
|
||||||
|
@Param("targetUserId") Long targetUserId
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当前用户的会话列表
|
||||||
|
* @param userId 当前用户ID
|
||||||
|
* @return 会话列表
|
||||||
|
*/
|
||||||
|
List<ChatSessions> selectSessionsByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新会话状态
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param targetUserId 目标用户ID
|
||||||
|
* @param sessionStatus 会话状态
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int updateSessionStatus(@Param("userId") Long userId,
|
||||||
|
@Param("targetUserId") Long targetUserId,
|
||||||
|
@Param("sessionStatus") Integer sessionStatus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新会话置顶状态
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param targetUserId 目标用户ID
|
||||||
|
* @param topStatus 置顶状态
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int updateTopStatus(@Param("userId") Long userId,
|
||||||
|
@Param("targetUserId") Long targetUserId,
|
||||||
|
@Param("topStatus") Integer topStatus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新会话免打扰状态
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param targetUserId 目标用户ID
|
||||||
|
* @param muteStatus 免打扰状态
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int updateMuteStatus(@Param("userId") Long userId,
|
||||||
|
@Param("targetUserId") Long targetUserId,
|
||||||
|
@Param("muteStatus") Integer muteStatus);
|
||||||
|
}
|
||||||
@@ -5,18 +5,18 @@ import com.bao.dating.pojo.entity.Comments;
|
|||||||
import org.apache.ibatis.annotations.*;
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@Mapper
|
|
||||||
public interface CommentsMapper {
|
public interface CommentsMapper {
|
||||||
// 添加评论
|
// 添加评论
|
||||||
@Insert("INSERT INTO dating.comments(content, user_id, post_id, created_at) VALUES(#{content}, #{user_id}, #{post_id}, #{created_at})")
|
@Insert("INSERT INTO comments(content, user_id, post_id, created_at) VALUES(#{content}, #{user_id}, #{post_id}, #{created_at})")
|
||||||
int addComment(Comments comments);
|
int addComment(Comments comments);
|
||||||
|
|
||||||
// 删除评论
|
// 删除评论
|
||||||
@Delete("DELETE FROM dating.comments WHERE user_id = #{user_id}")
|
@Delete("DELETE FROM comments WHERE user_id = #{user_id}")
|
||||||
int deleteComments(@Param("user_id") Long user_id);
|
int deleteComments(@Param("user_id") Long user_id);
|
||||||
|
|
||||||
// 根据动态ID查询评论列表
|
// 根据动态ID查询评论列表
|
||||||
@Select("SELECT * FROM dating.comments WHERE post_id = #{post_id} ORDER BY created_at DESC")
|
@Select("SELECT * FROM comments WHERE post_id = #{post_id} ORDER BY created_at DESC")
|
||||||
List<Comments> getCommentsByPostId(@Param("post_id") Long post_id);
|
List<Comments> getCommentsByPostId(@Param("post_id") Long post_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Param;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface PostFavoriteMapper {
|
public interface PostFavoriteMapper {
|
||||||
//查询当前已收藏所有用户
|
//查询当前已收藏所有用户
|
||||||
List<Long> selectUserIDByPostID(@Param("postId") Long postId);
|
List<Long> selectUserIDByPostID(@Param("postId") Long postId);
|
||||||
int addPostFavorite(PostFavorite postFavorite);
|
int addPostFavorite(PostFavorite postFavorite);
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动态Mapper
|
* 动态Mapper
|
||||||
@@ -96,12 +95,4 @@ public interface PostMapper {
|
|||||||
* @return 影响行数
|
* @return 影响行数
|
||||||
*/
|
*/
|
||||||
int decreaseFavoriteCount(Long postId);
|
int decreaseFavoriteCount(Long postId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据动态id查询用户名和媒体信息
|
|
||||||
*
|
|
||||||
* @param postId 动态id
|
|
||||||
* @return 用户名和媒体信息
|
|
||||||
*/
|
|
||||||
Map<String, Object> getUsernameByUserId(Long postId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package com.bao.dating.mapper;
|
package com.bao.dating.mapper;
|
||||||
|
|
||||||
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
import com.bao.dating.pojo.dto.UserInfoDTO;
|
||||||
import com.bao.dating.pojo.entity.User;
|
import com.bao.dating.pojo.entity.User;
|
||||||
import com.bao.dating.pojo.vo.UserInfoVO;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户Mapper
|
* 用户Mapper
|
||||||
@@ -35,17 +31,6 @@ public interface UserMapper {
|
|||||||
* 更新用户信息
|
* 更新用户信息
|
||||||
* @param userInfoUpdateDTO 用户信息更新参数
|
* @param userInfoUpdateDTO 用户信息更新参数
|
||||||
*/
|
*/
|
||||||
void updateUserInfoByUserId(UserInfoUpdateDTO userInfoUpdateDTO);
|
void updateUserInfoByUserId(UserInfoDTO userInfoUpdateDTO);
|
||||||
|
|
||||||
User selectByPhone(@Param("phone") String phone);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据经纬度范围查询用户
|
|
||||||
* @param minLat 最小纬度
|
|
||||||
* @param maxLat 最大纬度
|
|
||||||
* @param minLng 最小经度
|
|
||||||
* @param maxLng 最大经度
|
|
||||||
* @return 用户列表
|
|
||||||
*/
|
|
||||||
List<UserInfoVO> findByLatLngRange(@Param("minLat") double minLat, @Param("maxLat") double maxLat, @Param("minLng") double minLng, @Param("maxLng") double maxLng);
|
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/main/java/com/bao/dating/message/WsMessage.java
Normal file
17
src/main/java/com/bao/dating/message/WsMessage.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.bao.dating.message;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket 消息
|
||||||
|
* @author KilLze
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WsMessage<T> {
|
||||||
|
|
||||||
|
/** 消息类型:chat / read / system */
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/** 消息体 */
|
||||||
|
private T data;
|
||||||
|
}
|
||||||
25
src/main/java/com/bao/dating/pojo/dto/ChatCursorPageDTO.java
Normal file
25
src/main/java/com/bao/dating/pojo/dto/ChatCursorPageDTO.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package com.bao.dating.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录分页参数
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatCursorPageDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间游标:最后一条消息的发送时间
|
||||||
|
*/
|
||||||
|
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||||
|
private LocalDateTime cursor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉取条数
|
||||||
|
*/
|
||||||
|
private Integer size;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.bao.dating.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录查询参数
|
||||||
|
* @author KilLze
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatHistoryQueryDTO {
|
||||||
|
private Long currentUserId;
|
||||||
|
private Long targetUserId;
|
||||||
|
private LocalDateTime cursor;
|
||||||
|
private Integer size;
|
||||||
|
}
|
||||||
16
src/main/java/com/bao/dating/pojo/dto/ChatMarkReadDTO.java
Normal file
16
src/main/java/com/bao/dating/pojo/dto/ChatMarkReadDTO.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.bao.dating.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录已读参数
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatMarkReadDTO {
|
||||||
|
private Long senderUserId;
|
||||||
|
private Long receiverUserId;
|
||||||
|
private LocalDateTime readTime;
|
||||||
|
}
|
||||||
17
src/main/java/com/bao/dating/pojo/dto/ChatRecordSendDTO.java
Normal file
17
src/main/java/com/bao/dating/pojo/dto/ChatRecordSendDTO.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.bao.dating.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录发送数据传输对象
|
||||||
|
* @author KilLze
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatRecordSendDTO {
|
||||||
|
/** 接收者用户ID */
|
||||||
|
private Long receiverUserId;
|
||||||
|
/** 消息内容 */
|
||||||
|
private String messageContent;
|
||||||
|
/** 消息类型 (1-文本消息,2-文件消息) */
|
||||||
|
private Integer messageType;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bao.dating.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天会话静音参数
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatSessionMuteDTO {
|
||||||
|
private Long targetUserId;
|
||||||
|
private Integer muteStatus;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bao.dating.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话状态参数
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatSessionStatusDTO {
|
||||||
|
private Long targetUserId;
|
||||||
|
private Integer sessionStatus;
|
||||||
|
}
|
||||||
13
src/main/java/com/bao/dating/pojo/dto/ChatSessionTopDTO.java
Normal file
13
src/main/java/com/bao/dating/pojo/dto/ChatSessionTopDTO.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bao.dating.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话置顶参数
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatSessionTopDTO {
|
||||||
|
private Long targetUserId;
|
||||||
|
private Integer topStatus;
|
||||||
|
}
|
||||||
@@ -8,11 +8,11 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息更新数据传输对象
|
* 用户信息数据传输对象
|
||||||
* @author KilLze
|
* @author KilLze
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class UserInfoUpdateDTO implements Serializable {
|
public class UserInfoDTO implements Serializable {
|
||||||
private Long userId;
|
private Long userId;
|
||||||
private String userName;
|
private String userName;
|
||||||
private String nickname;
|
private String nickname;
|
||||||
35
src/main/java/com/bao/dating/pojo/entity/ChatRecords.java
Normal file
35
src/main/java/com/bao/dating/pojo/entity/ChatRecords.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package com.bao.dating.pojo.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录表
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatRecords {
|
||||||
|
/** 聊天记录ID */
|
||||||
|
private Long chatId;
|
||||||
|
/** 发送者用户ID */
|
||||||
|
private Long senderUserId;
|
||||||
|
/** 接收者用户ID */
|
||||||
|
private Long receiverUserId;
|
||||||
|
/** 消息内容 */
|
||||||
|
private String messageContent;
|
||||||
|
/** 消息类型 (1-文本消息,2-文件消息) */
|
||||||
|
private Integer messageType;
|
||||||
|
/** 阅读状态 (0-未读,1-已读) */
|
||||||
|
private Integer readStatus;
|
||||||
|
/** 阅读时间 */
|
||||||
|
private LocalDateTime readTime;
|
||||||
|
/** 发送时间 */
|
||||||
|
private LocalDateTime sendTime;
|
||||||
|
/** 消息状态 (1-正常,2-已撤回,3-已删除) */
|
||||||
|
private Integer messageStatus;
|
||||||
|
/** 创建时间 */
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
/** 更新时间 */
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
}
|
||||||
40
src/main/java/com/bao/dating/pojo/entity/ChatSessions.java
Normal file
40
src/main/java/com/bao/dating/pojo/entity/ChatSessions.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package com.bao.dating.pojo.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话表
|
||||||
|
* @author KilLze
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatSessions {
|
||||||
|
/** 会话ID */
|
||||||
|
private Long sessionId;
|
||||||
|
/** 所属用户ID */
|
||||||
|
private Long userId;
|
||||||
|
/** 目标用户ID */
|
||||||
|
private Long targetUserId;
|
||||||
|
/** 会话名称 */
|
||||||
|
private String sessionName;
|
||||||
|
/** 最后一条消息ID (关联chat_records.chat_id) */
|
||||||
|
private Long lastMessageId;
|
||||||
|
/** 最后一条消息内容 */
|
||||||
|
private String lastMessageContent;
|
||||||
|
/** 最后一条消息时间 */
|
||||||
|
private LocalDateTime lastMessageTime;
|
||||||
|
/** 未读消息数量 */
|
||||||
|
private Integer unreadCount;
|
||||||
|
/** 会话状态 (1-正常,2-已隐藏,3-已删除) */
|
||||||
|
private Integer sessionStatus;
|
||||||
|
/** 置顶状态 (0-未置顶,1-已置顶) */
|
||||||
|
private Integer topStatus;
|
||||||
|
/** 免打扰状态 (0-正常提醒,1-免打扰) */
|
||||||
|
private Integer muteStatus;
|
||||||
|
/** 创建时间 */
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
/** 更新时间 */
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -43,8 +43,4 @@ public class User implements Serializable {
|
|||||||
private String userEmail;
|
private String userEmail;
|
||||||
|
|
||||||
private String userPhone;
|
private String userPhone;
|
||||||
|
|
||||||
private Double latitude; // 纬度
|
|
||||||
|
|
||||||
private Double longitude; // 经度
|
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/main/java/com/bao/dating/pojo/vo/ChatRecordsVO.java
Normal file
29
src/main/java/com/bao/dating/pojo/vo/ChatRecordsVO.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package com.bao.dating.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天记录返回数据
|
||||||
|
* @author KilLze
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatRecordsVO {
|
||||||
|
/** 聊天记录ID */
|
||||||
|
private Long chatId;
|
||||||
|
/** 发送者用户ID */
|
||||||
|
private Long senderUserId;
|
||||||
|
/** 接收者用户ID */
|
||||||
|
private Long receiverUserId;
|
||||||
|
/** 消息内容 */
|
||||||
|
private String messageContent;
|
||||||
|
/** 消息类型 (1-文本消息,2-文件消息) */
|
||||||
|
private Integer messageType;
|
||||||
|
/** 阅读状态 (0-未读,1-已读) */
|
||||||
|
private Integer readStatus;
|
||||||
|
/** 发送时间 */
|
||||||
|
private LocalDateTime sendTime;
|
||||||
|
/** 消息状态 (1-正常,2-已撤回,3-已删除) */
|
||||||
|
private Integer messageStatus;
|
||||||
|
}
|
||||||
32
src/main/java/com/bao/dating/pojo/vo/ChatSessionsVO.java
Normal file
32
src/main/java/com/bao/dating/pojo/vo/ChatSessionsVO.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package com.bao.dating.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话信息
|
||||||
|
* @author KilLze
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChatSessionsVO {
|
||||||
|
|
||||||
|
/** 会话ID */
|
||||||
|
private Long sessionId;
|
||||||
|
/** 对方用户ID */
|
||||||
|
private Long targetUserId;
|
||||||
|
/** 会话名称 */
|
||||||
|
private String sessionName;
|
||||||
|
/** 对方用户头像 */
|
||||||
|
private String avatarUrl;
|
||||||
|
/** 最后一条消息内容 */
|
||||||
|
private String lastMessageContent;
|
||||||
|
/** 最后一条消息时间 */
|
||||||
|
private LocalDateTime lastMessageTime;
|
||||||
|
/** 未读消息数量 */
|
||||||
|
private Integer unreadCount;
|
||||||
|
/** 置顶状态 */
|
||||||
|
private Integer topStatus;
|
||||||
|
/** 免打扰状态 */
|
||||||
|
private Integer muteStatus;
|
||||||
|
}
|
||||||
@@ -24,6 +24,4 @@ public class UserInfoVO implements Serializable {
|
|||||||
private String signature;
|
private String signature;
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private Double latitude;
|
|
||||||
private Double longitude;
|
|
||||||
}
|
}
|
||||||
|
|||||||
74
src/main/java/com/bao/dating/service/ChatService.java
Normal file
74
src/main/java/com/bao/dating/service/ChatService.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package com.bao.dating.service;
|
||||||
|
|
||||||
|
import com.bao.dating.common.result.PageResult;
|
||||||
|
import com.bao.dating.pojo.dto.*;
|
||||||
|
import com.bao.dating.pojo.vo.ChatRecordsVO;
|
||||||
|
import com.bao.dating.pojo.vo.ChatSessionsVO;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天服务
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
public interface ChatService {
|
||||||
|
/**
|
||||||
|
* 消息入库,如果会话不存在则创建会话
|
||||||
|
* @param senderUserId 发送方用户ID
|
||||||
|
* @param dto 发送参数
|
||||||
|
* @return 聊天记录VO
|
||||||
|
*/
|
||||||
|
ChatRecordsVO createSession(Long senderUserId, ChatRecordSendDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传媒体文件
|
||||||
|
* @param file 文件
|
||||||
|
* @return 文件URL列表
|
||||||
|
*/
|
||||||
|
String uploadChat(MultipartFile file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取聊天记录
|
||||||
|
* @param dto 查询参数
|
||||||
|
* @return 聊天记录列表
|
||||||
|
*/
|
||||||
|
List<ChatRecordsVO> getChatHistory(ChatHistoryQueryDTO dto);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记聊天记录为已读
|
||||||
|
* @param currentUserId 当前用户ID
|
||||||
|
* @param targetUserId 目标用户ID
|
||||||
|
*/
|
||||||
|
void markChatMessagesAsRead(Long currentUserId, Long targetUserId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取会话列表
|
||||||
|
* @param currentUserId 当前用户ID
|
||||||
|
* @return 会话列表
|
||||||
|
*/
|
||||||
|
List<ChatSessionsVO> getSessionList(Long currentUserId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新会话状态
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param dto 更新参数
|
||||||
|
*/
|
||||||
|
void updateSessionStatus(Long userId, ChatSessionStatusDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 置顶会话
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param dto 置顶参数
|
||||||
|
*/
|
||||||
|
void updateTopStatus(Long userId, ChatSessionTopDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 免打扰会话
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param dto 免打扰参数
|
||||||
|
*/
|
||||||
|
void updateMuteStatus(Long userId, ChatSessionMuteDTO dto);
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import com.bao.dating.pojo.entity.Post;
|
|||||||
import com.bao.dating.pojo.vo.PostEditVO;
|
import com.bao.dating.pojo.vo.PostEditVO;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,11 +55,4 @@ public interface PostService {
|
|||||||
* @return 用户id
|
* @return 用户id
|
||||||
*/
|
*/
|
||||||
Long selectUserIdByPostId(Long postId);
|
Long selectUserIdByPostId(Long postId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载动态图片并添加水印
|
|
||||||
* @param postId 动态ID
|
|
||||||
* @return 带水印的图片
|
|
||||||
*/
|
|
||||||
BufferedImage downloadWithWatermark(Long postId) throws Exception;
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
package com.bao.dating.service;
|
package com.bao.dating.service;
|
||||||
|
|
||||||
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
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;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户服务接口
|
* 用户服务接口
|
||||||
* @author KilLze
|
* @author KilLze
|
||||||
@@ -54,20 +51,12 @@ public interface UserService {
|
|||||||
* @param userInfoUpdateDTO 用户信息
|
* @param userInfoUpdateDTO 用户信息
|
||||||
* @return 更新后的用户信息
|
* @return 更新后的用户信息
|
||||||
*/
|
*/
|
||||||
UserInfoVO updateUserInfo(UserInfoUpdateDTO userInfoUpdateDTO);
|
UserInfoVO updateUserInfo(UserInfoDTO userInfoUpdateDTO);
|
||||||
|
|
||||||
void sendSmsCode(String phone);
|
|
||||||
|
|
||||||
boolean verifyCode(String phone, String code);
|
|
||||||
|
|
||||||
UserLoginVO loginByPhone(String phone);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定经纬度范围内的用户
|
* 根据用户ID查询用户信息
|
||||||
* @param lat 用户纬度
|
* @param userId 用户ID
|
||||||
* @param lng 用户经度
|
* @return 用户
|
||||||
* @param radiusKm 半径 km
|
|
||||||
* @return 用户列表
|
|
||||||
*/
|
*/
|
||||||
List<UserInfoVO> findNearbyUsers(double lat,double lng,double radiusKm);
|
UserInfoDTO getUserInfoById(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
280
src/main/java/com/bao/dating/service/impl/ChatServiceImpl.java
Normal file
280
src/main/java/com/bao/dating/service/impl/ChatServiceImpl.java
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
package com.bao.dating.service.impl;
|
||||||
|
|
||||||
|
import com.bao.dating.common.aliyun.AliOssUtil;
|
||||||
|
import com.bao.dating.common.result.AliOssResult;
|
||||||
|
import com.bao.dating.context.UserContext;
|
||||||
|
import com.bao.dating.mapper.ChatRecordsMapper;
|
||||||
|
import com.bao.dating.mapper.ChatSessionsMapper;
|
||||||
|
import com.bao.dating.pojo.dto.*;
|
||||||
|
import com.bao.dating.pojo.entity.ChatRecords;
|
||||||
|
import com.bao.dating.pojo.entity.ChatSessions;
|
||||||
|
import com.bao.dating.pojo.vo.ChatRecordsVO;
|
||||||
|
import com.bao.dating.pojo.vo.ChatSessionsVO;
|
||||||
|
import com.bao.dating.service.ChatService;
|
||||||
|
import com.bao.dating.service.UserService;
|
||||||
|
import com.bao.dating.util.FileUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聊天服务实现类
|
||||||
|
* @author lenovo
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ChatServiceImpl implements ChatService {
|
||||||
|
@Autowired
|
||||||
|
private ChatRecordsMapper chatRecordsMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChatSessionsMapper chatSessionsMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AliOssUtil ossUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息入库,如果会话不存在则创建会话
|
||||||
|
* @param senderUserId 发送者用户ID
|
||||||
|
* @param dto 消息
|
||||||
|
* @return 聊天记录
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ChatRecordsVO createSession(Long senderUserId, ChatRecordSendDTO dto) {
|
||||||
|
|
||||||
|
ChatSessions session = chatSessionsMapper.getSession(senderUserId, dto.getReceiverUserId());
|
||||||
|
if (session != null && session.getSessionStatus() == 3) {
|
||||||
|
log.warn("会话已删除,无法发送消息");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatRecords record = new ChatRecords();
|
||||||
|
record.setSenderUserId(senderUserId);
|
||||||
|
record.setReceiverUserId(dto.getReceiverUserId());
|
||||||
|
record.setMessageContent(dto.getMessageContent());
|
||||||
|
record.setMessageType(dto.getMessageType());
|
||||||
|
record.setReadStatus(0);
|
||||||
|
record.setMessageStatus(1);
|
||||||
|
record.setSendTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
// 插入消息记录
|
||||||
|
chatRecordsMapper.insert(record);
|
||||||
|
|
||||||
|
// 创建发送方会话
|
||||||
|
ChatSessions sessions = new ChatSessions();
|
||||||
|
sessions.setUserId(senderUserId);
|
||||||
|
sessions.setTargetUserId(dto.getReceiverUserId());
|
||||||
|
// 获取接收方昵称作为发送方会话名称
|
||||||
|
try {
|
||||||
|
UserInfoDTO receiverNicknameInfo = userService.getUserInfoById(dto.getReceiverUserId());
|
||||||
|
if (receiverNicknameInfo != null && receiverNicknameInfo.getNickname() != null) {
|
||||||
|
sessions.setSessionName(receiverNicknameInfo.getNickname());
|
||||||
|
} else {
|
||||||
|
log.warn("接收用户ID获取用户信息时出现错误: {} , 使用默认id", dto.getReceiverUserId());
|
||||||
|
sessions.setSessionName("用户" + dto.getReceiverUserId());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("接收用户ID获取用户信息时出现错误: {} , 使用默认id", dto.getReceiverUserId(), e);
|
||||||
|
sessions.setSessionName("用户" + dto.getReceiverUserId());
|
||||||
|
}
|
||||||
|
sessions.setLastMessageId(record.getChatId());
|
||||||
|
sessions.setLastMessageContent(record.getMessageContent());
|
||||||
|
sessions.setLastMessageTime(record.getSendTime());
|
||||||
|
|
||||||
|
chatSessionsMapper.upsertSessionForSender(sessions);
|
||||||
|
|
||||||
|
// 创建接收方会话
|
||||||
|
sessions.setUserId(dto.getReceiverUserId());
|
||||||
|
sessions.setTargetUserId(senderUserId);
|
||||||
|
try {
|
||||||
|
UserInfoDTO senderNicknameInfo = userService.getUserInfoById(senderUserId);
|
||||||
|
if (senderNicknameInfo != null && senderNicknameInfo.getNickname() != null) {
|
||||||
|
sessions.setSessionName(senderNicknameInfo.getNickname());
|
||||||
|
} else {
|
||||||
|
log.warn("接收用户ID获取用户信息时出现错误: {} , 使用默认id", senderUserId);
|
||||||
|
sessions.setSessionName("用户" + senderUserId);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("接收用户ID获取用户信息时出现错误: {} , 使用默认id", senderUserId, e);
|
||||||
|
sessions.setSessionName("用户" + senderUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
chatSessionsMapper.upsertSessionForReceiver(sessions);
|
||||||
|
|
||||||
|
// 3. 返回 VO
|
||||||
|
ChatRecordsVO vo = new ChatRecordsVO();
|
||||||
|
BeanUtils.copyProperties(record, vo);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传媒体文件
|
||||||
|
* @return 上传后的文件URL
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String uploadChat(MultipartFile file) {
|
||||||
|
// 参数校验
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
throw new RuntimeException("文件不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
if (originalFilename == null) {
|
||||||
|
throw new RuntimeException("文件名非法");
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileType = FileUtil.getFileType(originalFilename);
|
||||||
|
// 仅支持图片和视频文件上传
|
||||||
|
if (!AliOssResult.IMAGE.equals(fileType) && !AliOssResult.VIDEO.equals(fileType)) {
|
||||||
|
throw new RuntimeException("仅支持图片和视频文件上传");
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成 OSS 路径
|
||||||
|
String extension = FileUtil.getFileExtension(originalFilename);
|
||||||
|
String fileName = UUID.randomUUID().toString().replace("-", "") + "." + extension;
|
||||||
|
Long userId = UserContext.getUserId();
|
||||||
|
String objectKey = "chat/" + userId + "/" + fileName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
byte[] fileBytes = file.getBytes();
|
||||||
|
String ossUrl = ossUtil.upload(fileBytes, objectKey);
|
||||||
|
|
||||||
|
if (ossUrl == null || ossUrl.isEmpty()) {
|
||||||
|
throw new RuntimeException("图片上传失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ossUrl;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("上传图片失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取聊天记录
|
||||||
|
* @return 聊天记录列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<ChatRecordsVO> getChatHistory(ChatHistoryQueryDTO dto) {
|
||||||
|
|
||||||
|
Integer size = dto.getSize();
|
||||||
|
if (size == null || size < 1 || size > 100) {
|
||||||
|
dto.setSize(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询聊天记录
|
||||||
|
List<ChatRecords> records = chatRecordsMapper.selectChatHistoryByCursor(dto);
|
||||||
|
|
||||||
|
// 倒序
|
||||||
|
Collections.reverse(records);
|
||||||
|
|
||||||
|
return records.stream().map(record -> {
|
||||||
|
ChatRecordsVO vo = new ChatRecordsVO();
|
||||||
|
BeanUtils.copyProperties(record, vo);
|
||||||
|
return vo;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void markChatMessagesAsRead(Long currentUserId, Long targetUserId) {
|
||||||
|
// 更新 chat_records:把对方发给我的未读消息设为已读
|
||||||
|
ChatMarkReadDTO markReadDTO = new ChatMarkReadDTO();
|
||||||
|
// 因为读的是对方发给我的消息所以要把填入的参数反过来
|
||||||
|
markReadDTO.setSenderUserId(targetUserId);
|
||||||
|
markReadDTO.setReceiverUserId(currentUserId);
|
||||||
|
markReadDTO.setReadTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
chatRecordsMapper.markMessagesAsRead(markReadDTO);
|
||||||
|
|
||||||
|
// 更新 chat_sessions:清空当前会话的未读数
|
||||||
|
chatSessionsMapper.clearUnreadCount(
|
||||||
|
currentUserId,
|
||||||
|
targetUserId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取会话列表
|
||||||
|
* @return 会话列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<ChatSessionsVO> getSessionList(Long currentUserId) {
|
||||||
|
List<ChatSessions> sessions = chatSessionsMapper.selectSessionsByUserId(currentUserId);
|
||||||
|
|
||||||
|
return sessions.stream().map(session -> {
|
||||||
|
ChatSessionsVO vo = new ChatSessionsVO();
|
||||||
|
BeanUtils.copyProperties(session, vo);
|
||||||
|
|
||||||
|
UserInfoDTO targetUser = userService.getUserInfoById(session.getTargetUserId());
|
||||||
|
if (targetUser != null){
|
||||||
|
vo.setSessionName(targetUser.getNickname());
|
||||||
|
vo.setAvatarUrl(targetUser.getAvatarUrl());
|
||||||
|
}else {
|
||||||
|
vo.setSessionName("用户" + session.getTargetUserId());
|
||||||
|
vo.setAvatarUrl(null);
|
||||||
|
}
|
||||||
|
return vo;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新会话状态
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param dto 会话状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateSessionStatus(Long userId, ChatSessionStatusDTO dto) {
|
||||||
|
chatSessionsMapper.updateSessionStatus(
|
||||||
|
userId,
|
||||||
|
dto.getTargetUserId(),
|
||||||
|
dto.getSessionStatus()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 置顶会话
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param dto 置顶状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateTopStatus(Long userId, ChatSessionTopDTO dto) {
|
||||||
|
chatSessionsMapper.updateTopStatus(
|
||||||
|
userId,
|
||||||
|
dto.getTargetUserId(),
|
||||||
|
dto.getTopStatus()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 免打扰会话
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param dto 免打扰状态
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateMuteStatus(Long userId, ChatSessionMuteDTO dto) {
|
||||||
|
chatSessionsMapper.updateMuteStatus(
|
||||||
|
userId,
|
||||||
|
dto.getTargetUserId(),
|
||||||
|
dto.getMuteStatus()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,13 +10,11 @@ import com.bao.dating.mapper.PostLikeMapper;
|
|||||||
import com.bao.dating.mapper.PostMapper;
|
import com.bao.dating.mapper.PostMapper;
|
||||||
import com.bao.dating.pojo.dto.PostRequestDTO;
|
import com.bao.dating.pojo.dto.PostRequestDTO;
|
||||||
import com.bao.dating.pojo.entity.Post;
|
import com.bao.dating.pojo.entity.Post;
|
||||||
import com.bao.dating.pojo.entity.User;
|
|
||||||
import com.bao.dating.pojo.vo.PostEditVO;
|
import com.bao.dating.pojo.vo.PostEditVO;
|
||||||
import com.bao.dating.service.PostService;
|
import com.bao.dating.service.PostService;
|
||||||
import com.bao.dating.common.aliyun.AliOssUtil;
|
import com.bao.dating.common.aliyun.AliOssUtil;
|
||||||
import com.bao.dating.service.UserService;
|
import com.bao.dating.service.UserService;
|
||||||
import com.bao.dating.util.FileUtil;
|
import com.bao.dating.util.FileUtil;
|
||||||
import com.bao.dating.util.WatermarkUtil;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -24,7 +22,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -60,9 +57,6 @@ public class PostServiceImpl implements PostService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CommentsMapper commentsMapper;
|
private CommentsMapper commentsMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WatermarkUtil watermarkUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传媒体文件
|
* 上传媒体文件
|
||||||
* @param files 媒体文件数组
|
* @param files 媒体文件数组
|
||||||
@@ -337,61 +331,4 @@ public class PostServiceImpl implements PostService {
|
|||||||
return postMapper.selectUserIdByPostId(postId);
|
return postMapper.selectUserIdByPostId(postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载动态图片并添加水印
|
|
||||||
*
|
|
||||||
* @param postId 动态ID
|
|
||||||
* @return 带水印的图片
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public BufferedImage downloadWithWatermark(Long postId) throws Exception {
|
|
||||||
// 一次性查出 动态图片 + 作者信息
|
|
||||||
Map<String, Object> map = postMapper.getUsernameByUserId(postId);
|
|
||||||
|
|
||||||
if (map == null || map.isEmpty()) {
|
|
||||||
Post post = postMapper.selectById(postId);
|
|
||||||
if (post == null) {
|
|
||||||
throw new RuntimeException("未找到指定postId的帖子: " + postId);
|
|
||||||
}
|
|
||||||
throw new RuntimeException("未找到与postId相关的用户和媒体信息: " + postId);
|
|
||||||
}
|
|
||||||
|
|
||||||
String mediaUrl = (String) map.get("media_oss_keys");
|
|
||||||
String username = (String) map.get("user_name");
|
|
||||||
Object userIdObj = map.get("user_id");
|
|
||||||
|
|
||||||
if (mediaUrl == null || username == null || userIdObj == null) {
|
|
||||||
throw new RuntimeException("用户或媒体信息不完整: " + map);
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaUrl = mediaUrl.trim();
|
|
||||||
if (mediaUrl.isEmpty()) {
|
|
||||||
throw new RuntimeException("媒体URL为空,postId: " + postId);
|
|
||||||
}
|
|
||||||
|
|
||||||
Long userId = userIdObj instanceof Number
|
|
||||||
? ((Number) userIdObj).longValue()
|
|
||||||
: Long.valueOf(userIdObj.toString());
|
|
||||||
|
|
||||||
// 解析 OSS ObjectKey(支持完整URL和直接存key两种)
|
|
||||||
String cleanUrl = mediaUrl.split("\\?")[0]; // 去掉 ? 后面的参数
|
|
||||||
String objectKey;
|
|
||||||
|
|
||||||
if (cleanUrl.startsWith("http")) {
|
|
||||||
// https://xxx.oss-cn-xxx.aliyuncs.com/post/xxx.jpg → post/xxx.jpg
|
|
||||||
objectKey = cleanUrl.substring(cleanUrl.indexOf(".com/") + 5);
|
|
||||||
} else {
|
|
||||||
objectKey = cleanUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (objectKey.trim().isEmpty()) {
|
|
||||||
throw new RuntimeException("解析后的ObjectKey为空,url: " + mediaUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 下载并动态加水印(只给下载的人看,OSS原图不改,数据库不动)
|
|
||||||
return watermarkUtil.downloadAndWatermark(objectKey, username, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,20 +3,16 @@ package com.bao.dating.service.impl;
|
|||||||
import com.bao.dating.common.aliyun.AliOssUtil;
|
import com.bao.dating.common.aliyun.AliOssUtil;
|
||||||
import com.bao.dating.common.aliyun.GreenImageScan;
|
import com.bao.dating.common.aliyun.GreenImageScan;
|
||||||
import com.bao.dating.common.aliyun.GreenTextScan;
|
import com.bao.dating.common.aliyun.GreenTextScan;
|
||||||
import com.bao.dating.common.aliyun.SmsUtil;
|
|
||||||
import com.bao.dating.common.result.AliOssResult;
|
import com.bao.dating.common.result.AliOssResult;
|
||||||
import com.bao.dating.common.result.GreenAuditResult;
|
import com.bao.dating.common.result.GreenAuditResult;
|
||||||
import com.bao.dating.config.RedisConfig;
|
|
||||||
import com.bao.dating.context.UserContext;
|
import com.bao.dating.context.UserContext;
|
||||||
import com.bao.dating.mapper.UserMapper;
|
import com.bao.dating.mapper.UserMapper;
|
||||||
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
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.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 com.bao.dating.service.UserService;
|
import com.bao.dating.service.UserService;
|
||||||
import com.bao.dating.util.*;
|
|
||||||
import com.bao.dating.util.CodeUtil;
|
|
||||||
import com.bao.dating.util.FileUtil;
|
import com.bao.dating.util.FileUtil;
|
||||||
import com.bao.dating.util.JwtUtil;
|
import com.bao.dating.util.JwtUtil;
|
||||||
import com.bao.dating.util.MD5Util;
|
import com.bao.dating.util.MD5Util;
|
||||||
@@ -24,7 +20,6 @@ import io.jsonwebtoken.Claims;
|
|||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -41,10 +36,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Service
|
@Service
|
||||||
public class UserServiceImpl implements UserService {
|
public class UserServiceImpl implements UserService {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SmsUtil smsUtil;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AliOssUtil ossUtil;
|
private AliOssUtil ossUtil;
|
||||||
|
|
||||||
@@ -60,9 +51,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录
|
* 用户登录
|
||||||
*
|
*
|
||||||
@@ -242,7 +230,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
* @param userInfoUpdateDTO 用户信息更新参数
|
* @param userInfoUpdateDTO 用户信息更新参数
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public UserInfoVO updateUserInfo(UserInfoUpdateDTO userInfoUpdateDTO) {
|
public UserInfoVO updateUserInfo(UserInfoDTO userInfoUpdateDTO) {
|
||||||
Long userId = userInfoUpdateDTO.getUserId();
|
Long userId = userInfoUpdateDTO.getUserId();
|
||||||
User user = userMapper.selectByUserId(userId);
|
User user = userMapper.selectByUserId(userId);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
@@ -323,84 +311,22 @@ public class UserServiceImpl implements UserService {
|
|||||||
return userInfoVO;
|
return userInfoVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送短信验证码
|
/**
|
||||||
|
* 根据用户ID获取用户昵称和头像
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 用户昵称
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendSmsCode(String phone) {
|
public UserInfoDTO getUserInfoById(Long userId) {
|
||||||
//防刷:60 秒内只能发一次
|
// 查询数据库获取昵称
|
||||||
String key = "sms:code:" + phone;
|
User user = userMapper.selectByUserId(userId);
|
||||||
Boolean exists = stringRedisTemplate.hasKey(key);
|
if (user == null) {
|
||||||
if (Boolean.TRUE.equals(exists)){
|
throw new RuntimeException("没有此用户");
|
||||||
throw new RuntimeException("请勿频繁发送验证码");
|
|
||||||
}
|
}
|
||||||
|
UserInfoDTO dto = new UserInfoDTO();
|
||||||
// 生成验证码
|
dto.setUserId(user.getUserId());
|
||||||
String code = CodeUtil.generateCode();
|
dto.setNickname(user.getNickname());
|
||||||
// 发送短信
|
return dto;
|
||||||
smsUtil.sendVerificationCode(phone, code);
|
|
||||||
//存 Redis(5分钟过期)
|
|
||||||
stringRedisTemplate.opsForValue()
|
|
||||||
.set(key,code, 5, TimeUnit.MINUTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 校验验证码
|
|
||||||
@Override
|
|
||||||
public boolean verifyCode(String phone, String code) {
|
|
||||||
|
|
||||||
String key = "sms:code:" + phone;
|
|
||||||
String realCode = stringRedisTemplate.opsForValue().get(key);
|
|
||||||
//过期,未发送
|
|
||||||
if (realCode ==null){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//不匹配
|
|
||||||
if (!realCode.equals(code)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 校验成功,删除验证码(一次性)
|
|
||||||
stringRedisTemplate.delete(key);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserLoginVO loginByPhone(String phone) {
|
|
||||||
//根据手机号查询用户
|
|
||||||
User user = userMapper.selectByPhone(phone);
|
|
||||||
//创建token
|
|
||||||
String token = JwtUtil.generateToken(user.getUserId().toString());
|
|
||||||
//封装返回结果
|
|
||||||
UserLoginVO VO = new UserLoginVO();
|
|
||||||
VO.setUserId(user.getUserId());
|
|
||||||
VO.setToken(token);
|
|
||||||
return VO;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<UserInfoVO> findNearbyUsers(double lat, double lng, double radiusKm) {
|
|
||||||
//先用经纬度范围筛选(矩形框,提高性能)
|
|
||||||
double delta = radiusKm / 111.0; // 1° ≈ 111km
|
|
||||||
double minLat = lat - delta;// 最小纬度
|
|
||||||
double maxLat = lat + delta;// 最大纬度
|
|
||||||
double minLng = lng - delta;// 最小经度
|
|
||||||
double maxLng = lng + delta;// 最大经度
|
|
||||||
|
|
||||||
// 打印经纬度范围
|
|
||||||
System.out.println("Min Latitude: " + minLat + ", Max Latitude: " + maxLat);
|
|
||||||
System.out.println("Min Longitude: " + minLng + ", Max Longitude: " + maxLng);
|
|
||||||
|
|
||||||
List<UserInfoVO> byLatLngRange = userMapper.findByLatLngRange(minLat, maxLat, minLng, maxLng);
|
|
||||||
|
|
||||||
//精确计算距离,筛选在半径内的用户
|
|
||||||
List<UserInfoVO> result = new ArrayList<>();
|
|
||||||
for (UserInfoVO u:byLatLngRange){
|
|
||||||
// 检查用户是否有经纬度信息
|
|
||||||
if (u.getLatitude() != null && u.getLongitude() != null) {
|
|
||||||
double distance = DistanceUtil.calculate(lat, lng, u.getLatitude(), u.getLongitude());
|
|
||||||
if (distance <= radiusKm){
|
|
||||||
result.add(u);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/main/java/com/bao/dating/session/WsSessionManager.java
Normal file
51
src/main/java/com/bao/dating/session/WsSessionManager.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package com.bao.dating.session;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.socket.WebSocketSession;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocketSession 管理类
|
||||||
|
* @author KilLze
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class WsSessionManager {
|
||||||
|
|
||||||
|
private final Map<Long, WebSocketSession> SESSION_MAP = new ConcurrentHashMap<>();
|
||||||
|
/**
|
||||||
|
* 添加 WebSocketSession
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param session WebSocketSession
|
||||||
|
*/
|
||||||
|
public void addSession(Long userId, WebSocketSession session) {
|
||||||
|
SESSION_MAP.put(userId, session);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除 WebSocketSession
|
||||||
|
* @param userId 用户ID
|
||||||
|
*/
|
||||||
|
public void removeSession(Long userId) {
|
||||||
|
SESSION_MAP.remove(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 WebSocketSession
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return WebSocketSession
|
||||||
|
*/
|
||||||
|
public WebSocketSession getSession(Long userId) {
|
||||||
|
return SESSION_MAP.get(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断用户是否在线
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return true-在线,false-离线
|
||||||
|
*/
|
||||||
|
public boolean isOnline(Long userId) {
|
||||||
|
return SESSION_MAP.containsKey(userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.bao.dating.util;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class CodeUtil {
|
|
||||||
// 生成6位数字验证码
|
|
||||||
public static String generateCode() {
|
|
||||||
Random random = new Random();
|
|
||||||
int code=100000+random.nextInt(900000);
|
|
||||||
return String.valueOf(code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.bao.dating.util;
|
|
||||||
|
|
||||||
//Haversine 公式(标准写法)
|
|
||||||
|
|
||||||
public class DistanceUtil {
|
|
||||||
private static final double EARTH_RADIUS = 6371.0; // 地球半径 km
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算两点之间距离(单位:km)
|
|
||||||
*/
|
|
||||||
public static double calculate(
|
|
||||||
double lat1, double lon1,
|
|
||||||
double lat2, double lon2) {
|
|
||||||
|
|
||||||
double dLat = Math.toRadians(lat2 - lat1);
|
|
||||||
double dLon = Math.toRadians(lon2 - lon1);
|
|
||||||
|
|
||||||
lat1 = Math.toRadians(lat1);
|
|
||||||
lat2 = Math.toRadians(lat2);
|
|
||||||
|
|
||||||
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
|
|
||||||
+ Math.cos(lat1) * Math.cos(lat2)
|
|
||||||
* Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
|
||||||
|
|
||||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
||||||
|
|
||||||
return EARTH_RADIUS * c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package com.bao.dating.util;
|
|
||||||
|
|
||||||
import com.aliyun.oss.OSS;
|
|
||||||
import com.aliyun.oss.OSSClientBuilder;
|
|
||||||
import com.bao.dating.config.AliyunOSSConfig;
|
|
||||||
import com.bao.dating.mapper.PostMapper;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class WatermarkUtil {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AliyunOSSConfig aliyunOSSConfig;
|
|
||||||
|
|
||||||
|
|
||||||
public BufferedImage downloadAndWatermark(String objectKey, String username, Long userId) throws Exception {
|
|
||||||
OSS ossClient = new OSSClientBuilder().build(
|
|
||||||
aliyunOSSConfig.getEndpoint(),
|
|
||||||
aliyunOSSConfig.getAccessKeyId(),
|
|
||||||
aliyunOSSConfig.getAccessKeySecret()
|
|
||||||
);
|
|
||||||
|
|
||||||
InputStream inputStream = ossClient.getObject(aliyunOSSConfig.getBucketName(), objectKey).getObjectContent();
|
|
||||||
BufferedImage image = ImageIO.read(inputStream);
|
|
||||||
Graphics2D g2d = image.createGraphics();
|
|
||||||
|
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
||||||
|
|
||||||
// 字体小一点
|
|
||||||
Font font = new Font("微软雅黑", Font.BOLD, 24);
|
|
||||||
g2d.setFont(font);
|
|
||||||
|
|
||||||
String text = "作者:" + username + " (ID:" + userId + ")";
|
|
||||||
|
|
||||||
FontMetrics fm = g2d.getFontMetrics();
|
|
||||||
int textWidth = fm.stringWidth(text);
|
|
||||||
int textHeight = fm.getHeight();
|
|
||||||
|
|
||||||
// 右下角留边距
|
|
||||||
int x = image.getWidth() - textWidth - 20;
|
|
||||||
int y = image.getHeight() - 20;
|
|
||||||
|
|
||||||
// 黑色描边
|
|
||||||
g2d.setColor(Color.BLACK);
|
|
||||||
g2d.drawString(text, x - 1, y - 1);
|
|
||||||
g2d.drawString(text, x + 1, y - 1);
|
|
||||||
g2d.drawString(text, x - 1, y + 1);
|
|
||||||
g2d.drawString(text, x + 1, y + 1);
|
|
||||||
|
|
||||||
// 白色正文
|
|
||||||
g2d.setColor(Color.WHITE);
|
|
||||||
g2d.drawString(text, x, y);
|
|
||||||
|
|
||||||
g2d.dispose();
|
|
||||||
ossClient.shutdown();
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?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.bao.dating.mapper.ChatRecordsMapper">
|
||||||
|
|
||||||
|
<!-- 插入聊天记录 -->
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="chatId">
|
||||||
|
INSERT INTO chat_records
|
||||||
|
(
|
||||||
|
sender_user_id,
|
||||||
|
receiver_user_id,
|
||||||
|
message_content,
|
||||||
|
message_type,
|
||||||
|
read_status,
|
||||||
|
send_time,
|
||||||
|
message_status,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
#{senderUserId},
|
||||||
|
#{receiverUserId},
|
||||||
|
#{messageContent},
|
||||||
|
#{messageType},
|
||||||
|
#{readStatus},
|
||||||
|
#{sendTime},
|
||||||
|
#{messageStatus},
|
||||||
|
NOW(),
|
||||||
|
NOW()
|
||||||
|
)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 根据两个用户ID查询聊天记录 (按发送时间倒序) - PageHelper 会自动处理分页 -->
|
||||||
|
<select id="selectChatHistoryByCursor" resultType="com.bao.dating.pojo.entity.ChatRecords">
|
||||||
|
SELECT
|
||||||
|
chat_id, sender_user_id, receiver_user_id, message_content, message_type,
|
||||||
|
read_status, read_time, send_time, message_status, created_at, updated_at
|
||||||
|
FROM chat_records
|
||||||
|
WHERE
|
||||||
|
message_status = 1
|
||||||
|
AND (
|
||||||
|
(sender_user_id = #{currentUserId} AND receiver_user_id = #{targetUserId})
|
||||||
|
OR
|
||||||
|
(sender_user_id = #{targetUserId} AND receiver_user_id = #{currentUserId})
|
||||||
|
)
|
||||||
|
<if test="cursor != null">
|
||||||
|
AND send_time < #{cursor}
|
||||||
|
</if>
|
||||||
|
ORDER BY send_time DESC
|
||||||
|
LIMIT #{size}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 标记消息为已读 -->
|
||||||
|
<update id="markMessagesAsRead">
|
||||||
|
UPDATE chat_records
|
||||||
|
SET
|
||||||
|
read_status = 1,
|
||||||
|
read_time = #{readTime},
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE
|
||||||
|
sender_user_id = #{senderUserId}
|
||||||
|
AND receiver_user_id = #{receiverUserId}
|
||||||
|
AND read_status = 0
|
||||||
|
AND message_status = 1
|
||||||
|
</update>
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?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.bao.dating.mapper.ChatSessionsMapper">
|
||||||
|
|
||||||
|
<!-- 插入或更新发送方会话 -->
|
||||||
|
<insert id="upsertSessionForSender" parameterType="com.bao.dating.pojo.entity.ChatSessions">
|
||||||
|
INSERT INTO chat_sessions
|
||||||
|
(user_id, target_user_id, session_name, last_message_id, last_message_content, last_message_time,
|
||||||
|
unread_count, session_status, top_status, mute_status, created_at, updated_at)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
#{userId}, #{targetUserId}, #{sessionName}, #{lastMessageId}, #{lastMessageContent}, #{lastMessageTime},
|
||||||
|
0, 1, 0, 0, NOW(), NOW()
|
||||||
|
)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
last_message_id = VALUES(last_message_id),
|
||||||
|
last_message_content = VALUES(last_message_content),
|
||||||
|
last_message_time = VALUES(last_message_time),
|
||||||
|
unread_count = 0,
|
||||||
|
updated_at = NOW();
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 插入或更新接收方会话 -->
|
||||||
|
<insert id="upsertSessionForReceiver" parameterType="com.bao.dating.pojo.entity.ChatSessions">
|
||||||
|
INSERT INTO chat_sessions
|
||||||
|
(user_id, target_user_id, session_name, last_message_id, last_message_content, last_message_time,
|
||||||
|
unread_count, session_status, top_status, mute_status, created_at, updated_at)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
#{userId}, #{targetUserId}, #{sessionName}, #{lastMessageId}, #{lastMessageContent}, #{lastMessageTime},
|
||||||
|
1, 1, 0, 0, NOW(), NOW()
|
||||||
|
)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
last_message_id = VALUES(last_message_id),
|
||||||
|
last_message_content = VALUES(last_message_content),
|
||||||
|
last_message_time = VALUES(last_message_time),
|
||||||
|
unread_count = unread_count + 1,
|
||||||
|
updated_at = NOW();
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 清空未读消息数 -->
|
||||||
|
<update id="clearUnreadCount">
|
||||||
|
UPDATE chat_sessions
|
||||||
|
SET
|
||||||
|
unread_count = 0,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE
|
||||||
|
user_id = #{userId}
|
||||||
|
AND target_user_id = #{targetUserId}
|
||||||
|
AND session_status = 1
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!-- 查询会话列表 -->
|
||||||
|
<select id="selectSessionsByUserId" resultType="com.bao.dating.pojo.entity.ChatSessions">
|
||||||
|
SELECT session_id, target_user_id, session_name, last_message_content,
|
||||||
|
last_message_time, unread_count, top_status, mute_status
|
||||||
|
FROM chat_sessions
|
||||||
|
WHERE user_id = #{userId}
|
||||||
|
AND session_status = 1
|
||||||
|
AND session_status in (1,2)
|
||||||
|
ORDER BY top_status DESC, last_message_time DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 更新会话状态 -->
|
||||||
|
<update id="updateSessionStatus">
|
||||||
|
UPDATE chat_sessions
|
||||||
|
SET session_status = #{sessionStatus},
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE user_id = #{userId}
|
||||||
|
AND target_user_id = #{targetUserId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!-- 置顶会话 -->
|
||||||
|
<update id="updateTopStatus">
|
||||||
|
UPDATE chat_sessions
|
||||||
|
SET top_status = #{topStatus},
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE user_id = #{userId}
|
||||||
|
AND target_user_id = #{targetUserId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!-- 静音会话 -->
|
||||||
|
<update id="updateMuteStatus">
|
||||||
|
UPDATE chat_sessions
|
||||||
|
SET mute_status = #{muteStatus},
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE user_id = #{userId}
|
||||||
|
AND target_user_id = #{targetUserId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -122,11 +122,5 @@
|
|||||||
<select id="selectFavoriteCount" resultType="java.lang.Integer">
|
<select id="selectFavoriteCount" resultType="java.lang.Integer">
|
||||||
select dating.post.favorite_count from dating.post where post.post_id = #{postId}
|
select dating.post.favorite_count from dating.post where post.post_id = #{postId}
|
||||||
</select>
|
</select>
|
||||||
<select id="getUsernameByUserId" resultType="map">
|
|
||||||
SELECT u.user_name, u.user_id, p.media_oss_keys
|
|
||||||
FROM post p
|
|
||||||
LEFT JOIN user u ON p.user_id = u.user_id
|
|
||||||
WHERE p.post_id = #{postId}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -28,8 +28,6 @@
|
|||||||
<result property="signature" column="signature"/>
|
<result property="signature" column="signature"/>
|
||||||
<result property="createdAt" column="created_at"/>
|
<result property="createdAt" column="created_at"/>
|
||||||
<result property="updatedAt" column="updated_at"/>
|
<result property="updatedAt" column="updated_at"/>
|
||||||
<result property="latitude" column="user_latitude"/>
|
|
||||||
<result property="longitude" column="user_longitude"/>
|
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<select id="selectByUserId" resultMap="UserResultMap">
|
<select id="selectByUserId" resultMap="UserResultMap">
|
||||||
SELECT
|
SELECT
|
||||||
@@ -43,10 +41,8 @@
|
|||||||
hobbies,
|
hobbies,
|
||||||
signature,
|
signature,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at,
|
updated_at
|
||||||
user_latitude,
|
FROM user WHERE user_id = #{userId}
|
||||||
user_longitude
|
|
||||||
FROM dating.user WHERE user_id = #{userId}
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!--根据ID更新动态-->
|
<!--根据ID更新动态-->
|
||||||
@@ -78,43 +74,4 @@
|
|||||||
</set>
|
</set>
|
||||||
WHERE user_id = #{userId}
|
WHERE user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<select id="selectByPhone" resultType="com.bao.dating.pojo.entity.User">
|
|
||||||
select * from dating.user where user_phone =#{phone}
|
|
||||||
</select>
|
|
||||||
<resultMap id="UserInfoVOResultMap" type="com.bao.dating.pojo.vo.UserInfoVO">
|
|
||||||
<id property="userId" column="user_id"/>
|
|
||||||
<result property="userName" column="user_name"/>
|
|
||||||
<result property="nickname" column="nickname"/>
|
|
||||||
<result property="avatarUrl" column="avatar_url"/>
|
|
||||||
<result property="backgroundUrl" column="background_url"/>
|
|
||||||
<result property="gender" column="gender"/>
|
|
||||||
<result property="birthday" column="birthday"/>
|
|
||||||
<result property="hobbies" column="hobbies" typeHandler="com.bao.dating.handler.ListToJsonTypeHandler"/>
|
|
||||||
<result property="signature" column="signature"/>
|
|
||||||
<result property="createdAt" column="created_at"/>
|
|
||||||
<result property="updatedAt" column="updated_at"/>
|
|
||||||
<result property="latitude" column="user_latitude"/>
|
|
||||||
<result property="longitude" column="user_longitude"/>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<select id="findByLatLngRange" resultMap="UserInfoVOResultMap">
|
|
||||||
SELECT
|
|
||||||
user_id,
|
|
||||||
user_name,
|
|
||||||
nickname,
|
|
||||||
avatar_url,
|
|
||||||
background_url,
|
|
||||||
gender,
|
|
||||||
birthday,
|
|
||||||
hobbies,
|
|
||||||
signature,
|
|
||||||
created_at,
|
|
||||||
updated_at,
|
|
||||||
user_latitude,
|
|
||||||
user_longitude
|
|
||||||
FROM user WHERE user_latitude BETWEEN #{minLat} AND #{maxLat} AND user_longitude BETWEEN #{minLng} AND #{maxLng}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user