Compare commits
5 Commits
88579a382e
...
feature-in
| Author | SHA1 | Date | |
|---|---|---|---|
| a4faa11036 | |||
| 290db24bc4 | |||
| 31b0dffd68 | |||
| 31fd23afa8 | |||
| d8d46ab089 |
7
pom.xml
7
pom.xml
@@ -82,13 +82,6 @@
|
|||||||
<version>3.12.0</version>
|
<version>3.12.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- OkHttp(用于调用API) -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
|
||||||
<artifactId>okhttp</artifactId>
|
|
||||||
<version>4.12.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- AOP起步依赖 -->
|
<!-- AOP起步依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.bao.dating;
|
|||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -12,7 +11,6 @@ import java.io.InputStreamReader;
|
|||||||
|
|
||||||
@MapperScan("com.bao.dating.mapper")
|
@MapperScan("com.bao.dating.mapper")
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableScheduling
|
|
||||||
public class DatingApplication {
|
public class DatingApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(DatingApplication.class, args);
|
SpringApplication.run(DatingApplication.class, args);
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ 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())) {
|
||||||
@@ -145,6 +147,7 @@ public class SmsUtil {
|
|||||||
jsonBuilder.append("}");
|
jsonBuilder.append("}");
|
||||||
return sendSms(phoneNumber, templateCode, jsonBuilder.toString());
|
return sendSms(phoneNumber, templateCode, jsonBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.bao.dating.common.ip2location;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "ip2location.api")
|
|
||||||
public class Ip2LocationConfig {
|
|
||||||
private String key;
|
|
||||||
private String url;
|
|
||||||
private int timeout;
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,6 @@ public class RedisConfig {
|
|||||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||||
|
|
||||||
redisTemplate.afterPropertiesSet();
|
|
||||||
return redisTemplate;
|
return redisTemplate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ public class WebConfig implements WebMvcConfigurer {
|
|||||||
// 忽略的接口
|
// 忽略的接口
|
||||||
.excludePathPatterns(
|
.excludePathPatterns(
|
||||||
"/user/login",
|
"/user/login",
|
||||||
"/user/register",
|
"/user/sendCode"
|
||||||
"/user/emailLogin",
|
|
||||||
"/api/verification/send-email-code",
|
|
||||||
"/ip/location"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
package com.bao.dating.controller;
|
|
||||||
|
|
||||||
import com.bao.dating.context.UserContext;
|
|
||||||
import com.bao.dating.service.ContactsService;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class ContactsController {
|
|
||||||
@Resource
|
|
||||||
private ContactsService contactsService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询好友列表
|
|
||||||
* @return 响应结果
|
|
||||||
*/
|
|
||||||
@GetMapping("/friends")
|
|
||||||
public Map<String, Object> getFriends() {
|
|
||||||
|
|
||||||
// 从UserContext获取当前用户ID
|
|
||||||
Long userId = UserContext.getUserId();
|
|
||||||
if (userId == null) {
|
|
||||||
Map<String, Object> error = new HashMap<>();
|
|
||||||
error.put("code", 401);
|
|
||||||
error.put("msg", "用户未授权");
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询好友列表
|
|
||||||
List<Map<String, Object>> friends = contactsService.getFriendsByUserId(userId);
|
|
||||||
|
|
||||||
// 构造响应
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
result.put("code", 200);
|
|
||||||
result.put("msg", "查询成功");
|
|
||||||
result.put("data", friends);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
package com.bao.dating.controller;
|
|
||||||
|
|
||||||
import com.bao.dating.context.UserContext;
|
|
||||||
import com.bao.dating.service.FriendRelationService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/friend-relation")
|
|
||||||
public class FriendController {
|
|
||||||
@Autowired
|
|
||||||
private FriendRelationService friendRelationService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送添加好友申请(写入数据库申请表)
|
|
||||||
* @param targetUserId 被申请人ID
|
|
||||||
* @param greeting 打招呼内容
|
|
||||||
* @return 操作结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/apply")
|
|
||||||
public Map<String, Object> sendFriendApply(
|
|
||||||
@RequestParam("targetUserId") Long targetUserId,
|
|
||||||
@RequestParam(value = "greeting", defaultValue = "你好,加个好友吧") String greeting) {
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
try {
|
|
||||||
Long applyUserId = UserContext.getUserId();
|
|
||||||
if (applyUserId == null) {
|
|
||||||
result.put("code", 401);
|
|
||||||
result.put("msg", "用户未登录");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
friendRelationService.addFriendApply(applyUserId, targetUserId, greeting);
|
|
||||||
result.put("code", 200);
|
|
||||||
result.put("msg", "好友申请发送成功");
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.put("code", 500);
|
|
||||||
result.put("msg", "发送失败:" + e.getMessage());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同意好友申请
|
|
||||||
* @param applyUserId 申请人ID
|
|
||||||
* @param targetUserId 被申请人ID(当前登录用户)
|
|
||||||
* @param contactNickname 给申请人的备注名
|
|
||||||
* @return 操作结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/agree")
|
|
||||||
public Map<String, Object> agreeFriendApply(
|
|
||||||
@RequestParam("applyUserId") Long applyUserId,
|
|
||||||
@RequestParam("targetUserId") Long targetUserId,
|
|
||||||
@RequestParam(value = "contactNickname", required = false) String contactNickname) {
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
try {
|
|
||||||
// 1. 同意申请(更新申请状态+删除/标记)
|
|
||||||
friendRelationService.agreeFriendApply(applyUserId, targetUserId);
|
|
||||||
// 2. 保存好友关系到通讯录表
|
|
||||||
friendRelationService.addFriendRelation(targetUserId, applyUserId, contactNickname);
|
|
||||||
friendRelationService.addFriendRelation(applyUserId, targetUserId, null);
|
|
||||||
result.put("code", 200);
|
|
||||||
result.put("msg", "同意好友申请成功");
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.put("code", 500);
|
|
||||||
result.put("msg", "同意失败:" + e.getMessage());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询待处理的好友申请
|
|
||||||
* @return 申请列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/apply/list")
|
|
||||||
public Map<String, Object> getApplyList() {
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
try {
|
|
||||||
Long targetUserId = UserContext.getUserId();
|
|
||||||
if (targetUserId == null) {
|
|
||||||
result.put("code", 401);
|
|
||||||
result.put("msg", "用户未登录");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
List<Map<String, Object>> applyList = friendRelationService.getFriendApplyList(targetUserId);
|
|
||||||
result.put("code", 200);
|
|
||||||
result.put("msg", "查询成功");
|
|
||||||
result.put("data", applyList);
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.put("code", 500);
|
|
||||||
result.put("msg", "查询失败:" + e.getMessage());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测试查询联系人
|
|
||||||
* @return 联系人列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/list")
|
|
||||||
public Map<String, Object> getFriendRelationList() {
|
|
||||||
Map<String, Object> result = new HashMap<>();
|
|
||||||
try {
|
|
||||||
Long userId = UserContext.getUserId();
|
|
||||||
if (userId == null) {
|
|
||||||
result.put("code", 401);
|
|
||||||
result.put("msg", "用户未登录");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
result.put("code", 200);
|
|
||||||
result.put("msg", "查询成功");
|
|
||||||
result.put("data", friendRelationService.getFriendRelationList(userId));
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.put("code", 500);
|
|
||||||
result.put("msg", "查询失败:" + e.getMessage());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package com.bao.dating.controller;
|
|
||||||
|
|
||||||
import com.bao.dating.common.Result;
|
|
||||||
import com.bao.dating.common.ResultCode;
|
|
||||||
import com.bao.dating.pojo.vo.IpLocationVO;
|
|
||||||
import com.bao.dating.service.Ip2LocationClientService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/ip")
|
|
||||||
public class IpLocationController {
|
|
||||||
@Autowired
|
|
||||||
private Ip2LocationClientService ip2LocationClientService;
|
|
||||||
/**
|
|
||||||
* 前端访问接口,获取IP地址位置信息
|
|
||||||
* @param ip 可选参数,要查询的IP地址
|
|
||||||
* @return IP位置信息(JSON格式)
|
|
||||||
*/
|
|
||||||
@GetMapping("/location")
|
|
||||||
public Result<?> getIpLocation(@RequestParam(required = false) String ip) {
|
|
||||||
if (ip.isEmpty()){
|
|
||||||
return Result.error(ResultCode.PARAM_ERROR);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// 调用工具类获取API响应
|
|
||||||
IpLocationVO ipLocationVo = ip2LocationClientService.getIpLocation(ip);
|
|
||||||
return Result.success(ResultCode.SUCCESS,ipLocationVo);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 异常处理:返回错误信息(实际项目建议封装统一响应格式)
|
|
||||||
return Result.error(ResultCode.SYSTEM_ERROR,e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,13 +2,11 @@ package com.bao.dating.controller;
|
|||||||
|
|
||||||
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.pojo.entity.Post;
|
|
||||||
import com.bao.dating.pojo.entity.User;
|
import com.bao.dating.pojo.entity.User;
|
||||||
import com.bao.dating.service.PostFavoriteService;
|
import com.bao.dating.service.PostFavoriteService;
|
||||||
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 java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -16,13 +14,6 @@ import java.util.Map;
|
|||||||
public class PostFavoriteController {
|
public class PostFavoriteController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PostFavoriteService postFavoriteService;
|
private PostFavoriteService postFavoriteService;
|
||||||
|
|
||||||
/**
|
|
||||||
* 收藏
|
|
||||||
* @param postId 动态ID
|
|
||||||
* @param user 当前登录用户对象
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@PostMapping("/{post_id}/favorites")
|
@PostMapping("/{post_id}/favorites")
|
||||||
public Result<Map<String,Long>> addPostFavorite(@PathVariable("post_id")Long postId, User user){
|
public Result<Map<String,Long>> addPostFavorite(@PathVariable("post_id")Long postId, User user){
|
||||||
if (user == null){
|
if (user == null){
|
||||||
@@ -31,13 +22,6 @@ public class PostFavoriteController {
|
|||||||
Long userId = user.getUserId();
|
Long userId = user.getUserId();
|
||||||
return postFavoriteService.postFavorite(userId,postId);
|
return postFavoriteService.postFavorite(userId,postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消收藏
|
|
||||||
* @param postId 动态id
|
|
||||||
* @param user 登录用户
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/{post_id}/favorites")
|
@DeleteMapping("/{post_id}/favorites")
|
||||||
public Result<?> deletePostFavorite(@PathVariable("post_id")Long postId, User user){
|
public Result<?> deletePostFavorite(@PathVariable("post_id")Long postId, User user){
|
||||||
if (user == null){
|
if (user == null){
|
||||||
@@ -46,21 +30,4 @@ public class PostFavoriteController {
|
|||||||
Long userId = user.getUserId();
|
Long userId = user.getUserId();
|
||||||
return postFavoriteService.deletePostFavorite(userId, postId);
|
return postFavoriteService.deletePostFavorite(userId, postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 展示所有收藏
|
|
||||||
* @param user 当前登录用户
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@GetMapping("/showFavorites")
|
|
||||||
public Result<List<Post>> showPostFavorites(@RequestBody User user){
|
|
||||||
//校验参数
|
|
||||||
if (user == null){
|
|
||||||
return Result.error(ResultCode.PARAM_ERROR);
|
|
||||||
}
|
|
||||||
Long userId = user.getUserId();
|
|
||||||
List<Post> posts = postFavoriteService.selectAllFavorites(userId);
|
|
||||||
return Result.success(ResultCode.SUCCESS,posts);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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.UserInfoUpdateDTO;
|
||||||
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;
|
||||||
@@ -14,7 +15,9 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户接口
|
* 用户接口
|
||||||
@@ -65,7 +68,6 @@ public class UserController {
|
|||||||
* @param file 头像文件
|
* @param file 头像文件
|
||||||
* @return 上传后的文件URL列表
|
* @return 上传后的文件URL列表
|
||||||
*/
|
*/
|
||||||
@Log
|
|
||||||
@PostMapping(value = "/info/uploadAvatar", consumes = "multipart/form-data")
|
@PostMapping(value = "/info/uploadAvatar", consumes = "multipart/form-data")
|
||||||
public Result<String> uploadAvatar(@RequestParam("file") MultipartFile file) {
|
public Result<String> uploadAvatar(@RequestParam("file") MultipartFile file) {
|
||||||
String fileUrl = userService.uploadAvatar(file);
|
String fileUrl = userService.uploadAvatar(file);
|
||||||
@@ -77,7 +79,6 @@ public class UserController {
|
|||||||
* @param file 背景文件
|
* @param file 背景文件
|
||||||
* @return 上传后的文件URL列表
|
* @return 上传后的文件URL列表
|
||||||
*/
|
*/
|
||||||
@Log
|
|
||||||
@PostMapping(value = "/info/uploadBackground", consumes = "multipart/form-data")
|
@PostMapping(value = "/info/uploadBackground", consumes = "multipart/form-data")
|
||||||
public Result<String> uploadBackground(@RequestParam("file") MultipartFile file) {
|
public Result<String> uploadBackground(@RequestParam("file") MultipartFile file) {
|
||||||
String fileUrl = userService.uploadBackground(file);
|
String fileUrl = userService.uploadBackground(file);
|
||||||
@@ -89,7 +90,6 @@ public class UserController {
|
|||||||
* @param userInfoUpdateDTO 用户信息更新参数
|
* @param userInfoUpdateDTO 用户信息更新参数
|
||||||
* @return 更新后的用户信息
|
* @return 更新后的用户信息
|
||||||
*/
|
*/
|
||||||
@Log
|
|
||||||
@PostMapping("/info/update")
|
@PostMapping("/info/update")
|
||||||
public Result<UserInfoVO> userInfoUpdate(@RequestBody UserInfoUpdateDTO userInfoUpdateDTO) {
|
public Result<UserInfoVO> userInfoUpdate(@RequestBody UserInfoUpdateDTO userInfoUpdateDTO) {
|
||||||
Long userId = UserContext.getUserId();
|
Long userId = UserContext.getUserId();
|
||||||
@@ -98,41 +98,70 @@ public class UserController {
|
|||||||
return Result.success(ResultCode.SUCCESS, "用户信息更新成功", userInfoVO);
|
return Result.success(ResultCode.SUCCESS, "用户信息更新成功", userInfoVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@PostMapping("/sendCode")
|
||||||
* 用户注册
|
public Result sendCode(@RequestBody Map<String, String> body) {
|
||||||
* @param userName 用户名称
|
String phone = body.get("phone");
|
||||||
* @param userPassword 用户密码
|
userService.sendSmsCode(phone);
|
||||||
* @return 返回
|
return Result.success(ResultCode.SUCCESS, "验证码发送成功");
|
||||||
*/
|
|
||||||
@PostMapping("/register")
|
|
||||||
public Result<?> userRegister(@RequestParam String userName , @RequestParam String userPassword){
|
|
||||||
//校验参数是否为空
|
|
||||||
if (userName.isEmpty() || userPassword.isEmpty()){
|
|
||||||
return Result.error(ResultCode.PARAM_ERROR);
|
|
||||||
}
|
}
|
||||||
if (!userService.registerUser(userName,userPassword)){
|
|
||||||
return Result.error(ResultCode.FAIL);
|
@PostMapping("/loginByCode")
|
||||||
}
|
public Result loginByCode(@RequestBody Map<String, String> body){
|
||||||
return Result.success(ResultCode.SUCCESS,"用户注册成功",null);
|
boolean ok = userService.verifyCode(body.get("phone"), body.get("code"));
|
||||||
|
return ok ? Result.success(ResultCode.SUCCESS, "登录成功") : Result.error(ResultCode.SYSTEM_ERROR, "登录失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过邮箱登录
|
* 登录
|
||||||
* @param email 邮箱
|
* @param body 登录参数
|
||||||
* @param code 验证码
|
|
||||||
* @return 用户信息
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/emailLogin")
|
@PostMapping("/loginPhone")
|
||||||
public Result<UserLoginVO> emailLogin(@RequestParam String email , @RequestParam String code){
|
public Result<?> loginPhone(@RequestBody Map<String, String> body) {
|
||||||
//校验参数是否为空
|
String phone = body.get("phone");
|
||||||
if (email.isEmpty() || code.isEmpty()){
|
String code = body.get("code");
|
||||||
return Result.error(ResultCode.PARAM_ERROR);
|
|
||||||
|
//校验验证码
|
||||||
|
boolean verify = userService.verifyCode(phone, code);
|
||||||
|
if (!verify){
|
||||||
|
return Result.error(ResultCode.SYSTEM_ERROR, "验证码错误或已过期");
|
||||||
}
|
}
|
||||||
UserLoginVO userLoginVO = userService.emailLogin(email, code);
|
//登录
|
||||||
if (userLoginVO == null){
|
UserLoginVO vo = userService.loginByPhone(phone);
|
||||||
return Result.error(ResultCode.FAIL,"请先注册用户或添加邮箱");
|
return Result.success(ResultCode.SUCCESS, "登录成功", vo);
|
||||||
}
|
}
|
||||||
return Result.success(ResultCode.SUCCESS,"用户登录成功",userLoginVO);
|
|
||||||
|
@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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
package com.bao.dating.controller;
|
|
||||||
|
|
||||||
public class text {
|
|
||||||
}
|
|
||||||
@@ -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 comments(content, user_id, post_id, created_at) VALUES(#{content}, #{user_id}, #{post_id}, #{created_at})")
|
@Insert("INSERT INTO dating.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 comments WHERE user_id = #{user_id}")
|
@Delete("DELETE FROM dating.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 comments WHERE post_id = #{post_id} ORDER BY created_at DESC")
|
@Select("SELECT * FROM dating.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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.bao.dating.mapper;
|
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.Contacts;
|
|
||||||
import com.bao.dating.pojo.entity.User;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface ContactMapper {
|
|
||||||
/**
|
|
||||||
* 根据用户ID查询好友列表(仅正常状态、非黑名单的好友)
|
|
||||||
* @param userId 当前用户ID
|
|
||||||
* @return 好友列表(包含联系人+用户基础信息)
|
|
||||||
*/
|
|
||||||
List<Map<String, Object>> selectFriendsByUserId(@Param("userId") Long userId);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package com.bao.dating.mapper;
|
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface FriendRelationMapper {
|
|
||||||
/**
|
|
||||||
* 插入好友申请
|
|
||||||
* @param params 申请参数(匹配friend_apply表字段)
|
|
||||||
*/
|
|
||||||
void insertFriendApply(Map<String, Object> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据申请人ID和被申请人ID查询好友申请
|
|
||||||
* @param applyUserId 申请人ID
|
|
||||||
* @param targetUserId 被申请人ID
|
|
||||||
* @return 好友申请记录
|
|
||||||
*/
|
|
||||||
Map<String, Object> selectFriendApplyByUsers(@Param("applyUserId") Long applyUserId, @Param("targetUserId") Long targetUserId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新好友申请状态
|
|
||||||
* @param params 更新参数
|
|
||||||
*/
|
|
||||||
void updateFriendApplyStatus(Map<String, Object> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除好友申请(可选)
|
|
||||||
* @param params 删除条件
|
|
||||||
*/
|
|
||||||
void deleteFriendApply(Map<String, Object> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询待处理的好友申请
|
|
||||||
* @param targetUserId 被申请人ID
|
|
||||||
* @return 申请列表
|
|
||||||
*/
|
|
||||||
List<Map<String, Object>> selectFriendApplyList(@Param("targetUserId") Long targetUserId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 插入联系人记录
|
|
||||||
* @param params 插入参数(匹配contacts表字段)
|
|
||||||
*/
|
|
||||||
void insertFriendRelation(Map<String, Object> params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据用户ID查询联系人列表
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @return 联系人列表
|
|
||||||
*/
|
|
||||||
List<Map<String, Object>> selectFriendRelationListByUserId(@Param("userId") Long userId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除过期的好友申请
|
|
||||||
* @param days 过期天数
|
|
||||||
* @return 删除的记录数
|
|
||||||
*/
|
|
||||||
int deleteExpiredFriendApply(@Param("days") Integer days);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.bao.dating.mapper;
|
package com.bao.dating.mapper;
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.Post;
|
|
||||||
import com.bao.dating.pojo.entity.PostFavorite;
|
import com.bao.dating.pojo.entity.PostFavorite;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
@@ -11,9 +10,7 @@ import java.util.List;
|
|||||||
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);
|
||||||
//删除收藏
|
|
||||||
int deletePostFavorite(@Param("postId") Long postId);
|
int deletePostFavorite(@Param("postId") Long postId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +20,4 @@ public interface PostFavoriteMapper {
|
|||||||
*/
|
*/
|
||||||
int deleteFavoritesByPostIds(@Param("postIds") List<Long> postIds);
|
int deleteFavoritesByPostIds(@Param("postIds") List<Long> postIds);
|
||||||
|
|
||||||
//查询用户所有收藏
|
|
||||||
List<Post> showAllFavorites(@Param("userid")Long userid);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,31 +24,9 @@ public interface PostMapper {
|
|||||||
* 根据ID修改动态状态
|
* 根据ID修改动态状态
|
||||||
*
|
*
|
||||||
* @param postIds 动态ID
|
* @param postIds 动态ID
|
||||||
* @param userId 用户ID
|
|
||||||
*/
|
*/
|
||||||
int updatePublicById(@Param("postIds") List<Long> postIds, @Param("userId") Long userId);
|
int updatePublicById(@Param("postIds") List<Long> postIds, @Param("userId") Long userId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据动态ID删除收藏记录
|
|
||||||
*
|
|
||||||
* @param postId 动态ID
|
|
||||||
*/
|
|
||||||
int deletePostFavoriteByPostId(Long postId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据动态ID删除点赞记录
|
|
||||||
*
|
|
||||||
* @param postId 动态ID
|
|
||||||
*/
|
|
||||||
int deletePostLikeByPostId(Long postId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据动态ID删除评论记录
|
|
||||||
*
|
|
||||||
* @param postId 动态ID
|
|
||||||
*/
|
|
||||||
int deleteCommentsByPostId(Long postId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询动态
|
* 根据ID查询动态
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package com.bao.dating.mapper;
|
|||||||
|
|
||||||
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
||||||
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 org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户Mapper
|
* 用户Mapper
|
||||||
* @author KilLze
|
* @author KilLze
|
||||||
@@ -34,24 +37,15 @@ public interface UserMapper {
|
|||||||
*/
|
*/
|
||||||
void updateUserInfoByUserId(UserInfoUpdateDTO userInfoUpdateDTO);
|
void updateUserInfoByUserId(UserInfoUpdateDTO userInfoUpdateDTO);
|
||||||
|
|
||||||
/**
|
User selectByPhone(@Param("phone") String phone);
|
||||||
* 添加用户
|
|
||||||
* @param user 用户对象
|
|
||||||
* @return 受影响行数
|
|
||||||
*/
|
|
||||||
int saveUser(User user);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询最大用户id
|
* 根据经纬度范围查询用户
|
||||||
* @return 用户id
|
* @param minLat 最小纬度
|
||||||
|
* @param maxLat 最大纬度
|
||||||
|
* @param minLng 最小经度
|
||||||
|
* @param maxLng 最大经度
|
||||||
|
* @return 用户列表
|
||||||
*/
|
*/
|
||||||
Long selectMaxId();
|
List<UserInfoVO> findByLatLngRange(@Param("minLat") double minLat, @Param("maxLat") double maxLat, @Param("minLng") double minLng, @Param("maxLng") double maxLng);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据邮箱查询用户
|
|
||||||
* @param email 用户邮箱
|
|
||||||
* @return 用户信息
|
|
||||||
*/
|
|
||||||
User selectByUserEmailUser(@Param("userEmail") String email);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.bao.dating.pojo.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class Contacts {
|
|
||||||
private Long contactId; // 通讯录记录ID
|
|
||||||
private Long userId; // 当前用户ID
|
|
||||||
private Long contactUserId; // 联系人用户ID
|
|
||||||
private String contactNickname; // 联系人备注名
|
|
||||||
private String contactAvatar; // 联系人头像缓存
|
|
||||||
private Integer relationType; // 关系类型(1普通好友/2特别关注/3黑名单/4陌生人)
|
|
||||||
private Date addTime; // 添加时间
|
|
||||||
private Date lastChatTime; // 最后聊天时间
|
|
||||||
private Integer contactStatus; // 联系人状态(1正常/2已删除/3已拉黑)
|
|
||||||
private String contactRemark; // 备注信息
|
|
||||||
private List<String> tags; // 标签(JSON数组)
|
|
||||||
private Date createdAt; // 创建时间
|
|
||||||
private Date updatedAt; // 更新时间
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package com.bao.dating.pojo.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 好友申请实体类
|
|
||||||
* @author KilLze
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class FriendApply {
|
|
||||||
/**
|
|
||||||
* 申请ID,主键
|
|
||||||
* 对应字段:apply_id
|
|
||||||
*/
|
|
||||||
private Long applyId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 申请人ID(对应user表user_id)
|
|
||||||
* 对应字段:apply_user_id
|
|
||||||
*/
|
|
||||||
private Long applyUserId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 被申请人ID(对应user表user_id)
|
|
||||||
* 对应字段:target_user_id
|
|
||||||
*/
|
|
||||||
private Long targetUserId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打招呼内容
|
|
||||||
* 对应字段:greeting
|
|
||||||
*/
|
|
||||||
private String greeting;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 申请时间
|
|
||||||
* 对应字段:apply_time
|
|
||||||
*/
|
|
||||||
private Date applyTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 申请状态:0-待处理,1-已同意,2-已拒绝
|
|
||||||
* 对应字段:apply_status
|
|
||||||
*/
|
|
||||||
private Byte applyStatus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
* 对应字段:created_at
|
|
||||||
*/
|
|
||||||
private Date createdAt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新时间
|
|
||||||
* 对应字段:updated_at
|
|
||||||
*/
|
|
||||||
private Date updatedAt;
|
|
||||||
}
|
|
||||||
@@ -43,4 +43,8 @@ public class User implements Serializable {
|
|||||||
private String userEmail;
|
private String userEmail;
|
||||||
|
|
||||||
private String userPhone;
|
private String userPhone;
|
||||||
|
|
||||||
|
private Double latitude; // 纬度
|
||||||
|
|
||||||
|
private Double longitude; // 经度
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.bao.dating.pojo.vo;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class IpLocationVO {
|
|
||||||
// 国家
|
|
||||||
@JsonProperty("country_name")
|
|
||||||
private String countryName;
|
|
||||||
// 省份/地区
|
|
||||||
@JsonProperty("region_name")
|
|
||||||
private String regionName;
|
|
||||||
// 城市
|
|
||||||
@JsonProperty("city_name")
|
|
||||||
private String cityName;
|
|
||||||
// 纬度
|
|
||||||
private String latitude;
|
|
||||||
// 经度
|
|
||||||
private String longitude;
|
|
||||||
// ISP运营商
|
|
||||||
@JsonProperty("isp")
|
|
||||||
private String isp;
|
|
||||||
}
|
|
||||||
@@ -24,4 +24,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.bao.dating.service;
|
|
||||||
|
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.User;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface ContactsService {
|
|
||||||
/**
|
|
||||||
* 根据用户ID查询好友列表
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @return 好友列表
|
|
||||||
*/
|
|
||||||
List<Map<String, Object>> getFriendsByUserId(Long userId);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.bao.dating.service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface FriendRelationService {
|
|
||||||
/**
|
|
||||||
* 新增好友申请
|
|
||||||
* @param applyUserId 申请人ID
|
|
||||||
* @param targetUserId 被申请人ID
|
|
||||||
* @param greeting 打招呼内容
|
|
||||||
*/
|
|
||||||
void addFriendApply(Long applyUserId, Long targetUserId, String greeting);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同意好友申请(更新状态/删除记录)
|
|
||||||
* @param applyUserId 申请人ID
|
|
||||||
* @param targetUserId 被申请人ID
|
|
||||||
*/
|
|
||||||
void agreeFriendApply(Long applyUserId, Long targetUserId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询待处理的好友申请
|
|
||||||
* @param targetUserId 被申请人ID
|
|
||||||
* @return 申请列表
|
|
||||||
*/
|
|
||||||
List<Map<String, Object>> getFriendApplyList(Long targetUserId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加好友到通讯录表
|
|
||||||
* @param userId 当前用户ID
|
|
||||||
* @param contactUserId 联系人ID
|
|
||||||
* @param contactNickname 备注名
|
|
||||||
*/
|
|
||||||
void addFriendRelation(Long userId, Long contactUserId, String contactNickname);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询用户的联系人列表
|
|
||||||
* @param userId 当前用户ID
|
|
||||||
* @return 联系人列表
|
|
||||||
*/
|
|
||||||
List<Map<String, Object>> getFriendRelationList(Long userId);
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.bao.dating.service;
|
|
||||||
|
|
||||||
import com.bao.dating.pojo.vo.IpLocationVO;
|
|
||||||
|
|
||||||
public interface Ip2LocationClientService {
|
|
||||||
IpLocationVO getIpLocation(String ip)throws Exception;
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
package com.bao.dating.service;
|
package com.bao.dating.service;
|
||||||
|
|
||||||
import com.bao.dating.common.Result;
|
import com.bao.dating.common.Result;
|
||||||
import com.bao.dating.pojo.entity.Post;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface PostFavoriteService {
|
public interface PostFavoriteService {
|
||||||
Result<Map<String,Long>> postFavorite(Long userid,Long postId);
|
Result<Map<String,Long>> postFavorite(Long userid,Long postId);
|
||||||
Result<?> deletePostFavorite(Long userid,Long postId);
|
Result<?> deletePostFavorite(Long userid,Long postId);
|
||||||
List<Post> selectAllFavorites(Long userid);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ 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,18 +56,18 @@ public interface UserService {
|
|||||||
*/
|
*/
|
||||||
UserInfoVO updateUserInfo(UserInfoUpdateDTO userInfoUpdateDTO);
|
UserInfoVO updateUserInfo(UserInfoUpdateDTO userInfoUpdateDTO);
|
||||||
|
|
||||||
/**
|
void sendSmsCode(String phone);
|
||||||
* 用户注册
|
|
||||||
* @param userName 用户民称
|
boolean verifyCode(String phone, String code);
|
||||||
* @return 用户信息
|
|
||||||
*/
|
UserLoginVO loginByPhone(String phone);
|
||||||
Boolean registerUser(String userName,String userPassword);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮箱登录
|
* 获取指定经纬度范围内的用户
|
||||||
* @param email 邮箱
|
* @param lat 用户纬度
|
||||||
* @param code 验证码
|
* @param lng 用户经度
|
||||||
* @return
|
* @param radiusKm 半径 km
|
||||||
|
* @return 用户列表
|
||||||
*/
|
*/
|
||||||
UserLoginVO emailLogin(String email , String code);
|
List<UserInfoVO> findNearbyUsers(double lat,double lng,double radiusKm);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
package com.bao.dating.service.impl;
|
|
||||||
|
|
||||||
import com.bao.dating.mapper.ContactMapper;
|
|
||||||
import com.bao.dating.service.ContactsService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ContactServiceImpl implements ContactsService {
|
|
||||||
@Autowired
|
|
||||||
private ContactMapper contactMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Map<String, Object>> getFriendsByUserId(Long userId) {
|
|
||||||
// 直接调用Mapper查询,无额外封装
|
|
||||||
return contactMapper.selectFriendsByUserId(userId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
package com.bao.dating.service.impl;
|
|
||||||
|
|
||||||
import com.bao.dating.mapper.FriendRelationMapper;
|
|
||||||
import com.bao.dating.service.FriendRelationService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class FriendRelationServiceImpl implements FriendRelationService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FriendRelationMapper friendRelationMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增好友申请(写入数据库)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void addFriendApply(Long applyUserId, Long targetUserId, String greeting) {
|
|
||||||
// 检查是否已存在待处理的申请
|
|
||||||
Map<String, Object> existingApply = friendRelationMapper.selectFriendApplyByUsers(applyUserId, targetUserId);
|
|
||||||
if (existingApply != null) {
|
|
||||||
throw new RuntimeException("好友申请已存在,请勿重复发送");
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
|
||||||
params.put("apply_user_id", applyUserId);
|
|
||||||
params.put("target_user_id", targetUserId);
|
|
||||||
params.put("greeting", greeting);
|
|
||||||
friendRelationMapper.insertFriendApply(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 同意好友申请(更新状态为已同意,也可直接删除)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void agreeFriendApply(Long applyUserId, Long targetUserId) {
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
|
||||||
params.put("apply_user_id", applyUserId);
|
|
||||||
params.put("target_user_id", targetUserId);
|
|
||||||
params.put("apply_status", 1); // 1-已同意
|
|
||||||
friendRelationMapper.updateFriendApplyStatus(params);
|
|
||||||
// 也可选择直接删除申请记录:friendRelationMapper.deleteFriendApply(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询待处理的好友申请
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<Map<String, Object>> getFriendApplyList(Long targetUserId) {
|
|
||||||
return friendRelationMapper.selectFriendApplyList(targetUserId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加好友到通讯录表(严格匹配contacts表字段)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void addFriendRelation(Long userId, Long contactUserId, String contactNickname) {
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
|
||||||
params.put("user_id", userId);
|
|
||||||
params.put("contact_user_id", contactUserId);
|
|
||||||
params.put("contact_nickname", contactNickname);
|
|
||||||
params.put("relation_type", 1); // 1-普通好友
|
|
||||||
params.put("contact_status", 1); // 1-正常
|
|
||||||
friendRelationMapper.insertFriendRelation(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询用户的联系人列表
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<Map<String, Object>> getFriendRelationList(Long userId) {
|
|
||||||
return friendRelationMapper.selectFriendRelationListByUserId(userId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
package com.bao.dating.service.impl;
|
|
||||||
|
|
||||||
import com.bao.dating.common.ip2location.Ip2LocationConfig;
|
|
||||||
import com.bao.dating.pojo.vo.IpLocationVO;
|
|
||||||
import com.bao.dating.service.Ip2LocationClientService;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.apache.http.client.config.RequestConfig;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClients;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class Ip2LocationClientServiceImpl implements Ip2LocationClientService {
|
|
||||||
@Autowired
|
|
||||||
private Ip2LocationConfig ip2LocationConfig;
|
|
||||||
|
|
||||||
// Jackson的ObjectMapper,用于JSON解析
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用API并只返回核心位置信息
|
|
||||||
* @param ip 要查询的IP地址
|
|
||||||
* @return 精简的位置信息实体类
|
|
||||||
* @throws Exception 异常
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public IpLocationVO getIpLocation(String ip) throws Exception {
|
|
||||||
// 1. 构建请求URL
|
|
||||||
URIBuilder uriBuilder = new URIBuilder(ip2LocationConfig.getUrl());
|
|
||||||
uriBuilder.addParameter("key", ip2LocationConfig.getKey());
|
|
||||||
if (ip != null && !ip.trim().isEmpty()) {
|
|
||||||
uriBuilder.addParameter("ip", ip);
|
|
||||||
}
|
|
||||||
URI uri = uriBuilder.build();
|
|
||||||
|
|
||||||
// 2. 配置超时时间(逻辑和之前一致)
|
|
||||||
RequestConfig requestConfig = RequestConfig.custom()
|
|
||||||
.setConnectTimeout(ip2LocationConfig.getTimeout())
|
|
||||||
.setSocketTimeout(ip2LocationConfig.getTimeout())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// 3. 发送请求并解析响应
|
|
||||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
||||||
HttpGet httpGet = new HttpGet(uri);
|
|
||||||
httpGet.setConfig(requestConfig);
|
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
|
||||||
String jsonStr = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
||||||
// 核心:将完整JSON解析为只包含位置信息的VO类
|
|
||||||
return objectMapper.readValue(jsonStr, IpLocationVO.class);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("调用API失败,状态码:" + response.getStatusLine().getStatusCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ import com.bao.dating.common.Result;
|
|||||||
import com.bao.dating.common.ResultCode;
|
import com.bao.dating.common.ResultCode;
|
||||||
import com.bao.dating.mapper.PostFavoriteMapper;
|
import com.bao.dating.mapper.PostFavoriteMapper;
|
||||||
import com.bao.dating.mapper.PostMapper;
|
import com.bao.dating.mapper.PostMapper;
|
||||||
import com.bao.dating.pojo.entity.Post;
|
|
||||||
import com.bao.dating.pojo.entity.PostFavorite;
|
import com.bao.dating.pojo.entity.PostFavorite;
|
||||||
import com.bao.dating.service.PostFavoriteService;
|
import com.bao.dating.service.PostFavoriteService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -59,18 +58,4 @@ public class PostFavoriteServiceImpl implements PostFavoriteService {
|
|||||||
postMapper.decreaseFavoriteCount(postId);
|
postMapper.decreaseFavoriteCount(postId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 展示所有收藏
|
|
||||||
* @param userid 用户id
|
|
||||||
* @return 查询到的结果
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Post> selectAllFavorites(Long userid) {
|
|
||||||
if (userid == null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return postFavoriteMapper.showAllFavorites(userid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,19 +205,6 @@ public class PostServiceImpl implements PostService {
|
|||||||
if (CollectionUtils.isEmpty(postIds)) {
|
if (CollectionUtils.isEmpty(postIds)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 遍历所有要删除的帖子ID,验证权限
|
|
||||||
for (Long postId : postIds) {
|
|
||||||
Post post = postMapper.selectById(postId);
|
|
||||||
if (post == null) {
|
|
||||||
throw new RuntimeException("动态不存在");
|
|
||||||
}
|
|
||||||
// 验证用户权限
|
|
||||||
if (post.getUserId() == null || !post.getUserId().equals(userId)) {
|
|
||||||
throw new RuntimeException("无权限删除此动态");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int affected = postMapper.updatePublicById(postIds, userId);
|
int affected = postMapper.updatePublicById(postIds, userId);
|
||||||
|
|
||||||
if (affected == 0) {
|
if (affected == 0) {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package com.bao.dating.service.impl;
|
package com.bao.dating.service.impl;
|
||||||
|
|
||||||
import com.bao.dating.common.Result;
|
|
||||||
import com.bao.dating.common.ResultCode;
|
|
||||||
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.config.RedisConfig;
|
||||||
@@ -16,7 +15,8 @@ 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.service.VerificationCodeService;
|
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,6 +24,7 @@ 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;
|
||||||
|
|
||||||
@@ -40,6 +41,10 @@ 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;
|
||||||
|
|
||||||
@@ -56,7 +61,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private VerificationCodeService verificationCodeService;
|
private StringRedisTemplate stringRedisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录
|
* 用户登录
|
||||||
@@ -318,58 +323,84 @@ public class UserServiceImpl implements UserService {
|
|||||||
return userInfoVO;
|
return userInfoVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 发送短信验证码
|
||||||
* 查询用户
|
|
||||||
* @param userName 用户民称
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean registerUser(String userName,String userPassword) {
|
public void sendSmsCode(String phone) {
|
||||||
//校验参数是否为空
|
//防刷:60 秒内只能发一次
|
||||||
if (userName.isEmpty() || userPassword.isEmpty()){
|
String key = "sms:code:" + phone;
|
||||||
return false;
|
Boolean exists = stringRedisTemplate.hasKey(key);
|
||||||
}
|
if (Boolean.TRUE.equals(exists)){
|
||||||
//产看数据库是否存在已注册用户
|
throw new RuntimeException("请勿频繁发送验证码");
|
||||||
User user = userMapper.getByUsername(userName);
|
|
||||||
if (user != null){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//将用户数据存入苏数据库
|
|
||||||
String salt = "lyy123";
|
|
||||||
String passwordHash = MD5Util.encryptWithSalt(userPassword, salt);
|
|
||||||
//查询最大用户id
|
|
||||||
Long maxId = userMapper.selectMaxId();
|
|
||||||
User saveUser = new User();
|
|
||||||
saveUser.setUserId(maxId+1);
|
|
||||||
saveUser.setUserName(userName);
|
|
||||||
saveUser.setPasswordHash(passwordHash);
|
|
||||||
saveUser.setSalt(salt);
|
|
||||||
saveUser.setUpdatedAt(LocalDateTime.now());
|
|
||||||
saveUser.setCreatedAt(LocalDateTime.now());
|
|
||||||
int count = userMapper.saveUser(saveUser);
|
|
||||||
return count > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// 生成验证码
|
||||||
* 邮箱登录
|
String code = CodeUtil.generateCode();
|
||||||
* @param email 邮箱
|
// 发送短信
|
||||||
* @param code 验证码
|
smsUtil.sendVerificationCode(phone, code);
|
||||||
* @return 脱敏用户信息
|
//存 Redis(5分钟过期)
|
||||||
*/
|
stringRedisTemplate.opsForValue()
|
||||||
|
.set(key,code, 5, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验验证码
|
||||||
@Override
|
@Override
|
||||||
public UserLoginVO emailLogin(String email, String code) {
|
public boolean verifyCode(String phone, String code) {
|
||||||
User user = userMapper.selectByUserEmailUser(email);
|
|
||||||
if (user == null)
|
String key = "sms:code:" + phone;
|
||||||
return null;
|
String realCode = stringRedisTemplate.opsForValue().get(key);
|
||||||
boolean flag = verificationCodeService.verifyEmailCode(email, code);
|
//过期,未发送
|
||||||
if (!flag)
|
if (realCode ==null){
|
||||||
return null;
|
return false;
|
||||||
// 生成token
|
}
|
||||||
String token = JwtUtil.generateToken(String.valueOf(user.getUserId()));
|
//不匹配
|
||||||
UserLoginVO userLoginVO = new UserLoginVO();
|
if (!realCode.equals(code)){
|
||||||
userLoginVO.setUserId(user.getUserId());
|
return false;
|
||||||
userLoginVO.setNickname(user.getNickname());
|
}
|
||||||
userLoginVO.setToken(token);
|
// 校验成功,删除验证码(一次性)
|
||||||
return userLoginVO;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package com.bao.dating.task;
|
|
||||||
|
|
||||||
import com.bao.dating.mapper.FriendRelationMapper;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 好友申请清理定时任务
|
|
||||||
* 定时清理数据库中超过7天未处理的好友申请
|
|
||||||
* @author KilLze
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class FriendApplyCleanupTask {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private FriendRelationMapper friendRelationMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定时清理过期的好友申请
|
|
||||||
* 每1分钟执行一次,清理创建时间超过7天的未处理申请
|
|
||||||
*/
|
|
||||||
@Scheduled(fixedRate = 60000) // 每1分钟执行一次
|
|
||||||
public void cleanupExpiredFriendApply() {
|
|
||||||
log.info("开始执行好友申请清理任务");
|
|
||||||
try {
|
|
||||||
// 删除创建时间超过7天的未处理申请(apply_status = 0)
|
|
||||||
int deletedCount = friendRelationMapper.deleteExpiredFriendApply(7);
|
|
||||||
log.info("好友申请清理任务执行完成,删除了 {} 条过期记录", deletedCount);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("好友申请清理任务执行失败", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
12
src/main/java/com/bao/dating/util/CodeUtil.java
Normal file
12
src/main/java/com/bao/dating/util/CodeUtil.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/java/com/bao/dating/util/DistanceUtil.java
Normal file
29
src/main/java/com/bao/dating/util/DistanceUtil.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,7 +84,6 @@ public class EmailUtil {
|
|||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
log.error("HTML邮件发送失败,收件人:{},异常信息:{}", to, e.getMessage(), e);
|
log.error("HTML邮件发送失败,收件人:{},异常信息:{}", to, e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +173,6 @@ public class EmailUtil {
|
|||||||
}
|
}
|
||||||
log.info("批量邮件发送完成,总数:{},成功:{}", toList.length, successCount);
|
log.info("批量邮件发送完成,总数:{},成功:{}", toList.length, successCount);
|
||||||
return successCount;
|
return successCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
* @author KilLze
|
* @author KilLze
|
||||||
*/
|
*/
|
||||||
public class MD5Util {
|
public class MD5Util {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对字符串进行MD5加密
|
* 对字符串进行MD5加密
|
||||||
* @param input 待加密的字符串
|
* @param input 待加密的字符串
|
||||||
@@ -18,6 +19,7 @@ public class MD5Util {
|
|||||||
if (input == null || input.isEmpty()) {
|
if (input == null || input.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
byte[] digest = md.digest(input.getBytes());
|
byte[] digest = md.digest(input.getBytes());
|
||||||
@@ -26,6 +28,7 @@ public class MD5Util {
|
|||||||
throw new RuntimeException("MD5算法不可用", e);
|
throw new RuntimeException("MD5算法不可用", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对字符串进行MD5加密(带盐值)
|
* 对字符串进行MD5加密(带盐值)
|
||||||
* @param input 待加密的字符串
|
* @param input 待加密的字符串
|
||||||
@@ -41,6 +44,7 @@ public class MD5Util {
|
|||||||
}
|
}
|
||||||
return encrypt(input + salt);
|
return encrypt(input + salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证字符串与MD5值是否匹配
|
* 验证字符串与MD5值是否匹配
|
||||||
* @param input 原始字符串
|
* @param input 原始字符串
|
||||||
@@ -53,6 +57,7 @@ public class MD5Util {
|
|||||||
}
|
}
|
||||||
return encrypt(input).equalsIgnoreCase(md5Hash);
|
return encrypt(input).equalsIgnoreCase(md5Hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证字符串与MD5值是否匹配(带盐值)
|
* 验证字符串与MD5值是否匹配(带盐值)
|
||||||
* @param input 原始字符串
|
* @param input 原始字符串
|
||||||
@@ -69,6 +74,7 @@ public class MD5Util {
|
|||||||
}
|
}
|
||||||
return encryptWithSalt(input, salt).equalsIgnoreCase(md5Hash);
|
return encryptWithSalt(input, salt).equalsIgnoreCase(md5Hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将字节数组转换为十六进制字符串
|
* 将字节数组转换为十六进制字符串
|
||||||
* @param bytes 字节数组
|
* @param bytes 字节数组
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ spring:
|
|||||||
connectiontimeout: 10000 # 连接超时时间(毫秒)
|
connectiontimeout: 10000 # 连接超时时间(毫秒)
|
||||||
timeout: 10000 # 读取超时时间(毫秒)
|
timeout: 10000 # 读取超时时间(毫秒)
|
||||||
writetimeout: 10000 # 写入超时时间(毫秒)
|
writetimeout: 10000 # 写入超时时间(毫秒)
|
||||||
|
|
||||||
# MyBatis 配置
|
# MyBatis 配置
|
||||||
mybatis:
|
mybatis:
|
||||||
mapper-locations: classpath:mapper/*.xml
|
mapper-locations: classpath:mapper/*.xml
|
||||||
@@ -69,11 +70,3 @@ aliyun:
|
|||||||
region-id: cn-hangzhou
|
region-id: cn-hangzhou
|
||||||
sign-name: 速通互联验证码
|
sign-name: 速通互联验证码
|
||||||
template-code: 100001
|
template-code: 100001
|
||||||
|
|
||||||
# ip2location.io 相关配置
|
|
||||||
ip2location:
|
|
||||||
api:
|
|
||||||
key: 95F4AB991174E296AFD5AD0EF927B2ED # ip2location.io API密钥
|
|
||||||
url: https://api.ip2location.io/
|
|
||||||
timeout: 5000 # 请求超时时间(毫秒)
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
<?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.ContactMapper">
|
|
||||||
<select id="selectFriendsByUserId" resultType="java.util.Map">
|
|
||||||
SELECT c.contact_id,
|
|
||||||
c.user_id,
|
|
||||||
c.contact_user_id,
|
|
||||||
c.contact_nickname,
|
|
||||||
c.relation_type,
|
|
||||||
c.add_time,
|
|
||||||
u.user_name,
|
|
||||||
u.nickname,
|
|
||||||
u.avatar_url,
|
|
||||||
u.signature
|
|
||||||
FROM contacts c
|
|
||||||
LEFT JOIN user u ON c.contact_user_id = u.user_id
|
|
||||||
WHERE c.user_id = #{userId}
|
|
||||||
AND c.contact_status = 1 -- 正常状态
|
|
||||||
AND c.relation_type != 3 -- 排除黑名单
|
|
||||||
AND c.user_id != c.contact_user_id -- 排除自己
|
|
||||||
</select>
|
|
||||||
</mapper>
|
|
||||||
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
<?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.FriendRelationMapper">
|
|
||||||
<!-- 插入好友申请 -->
|
|
||||||
<insert id="insertFriendApply" parameterType="java.util.Map">
|
|
||||||
INSERT INTO friend_apply (
|
|
||||||
apply_user_id,
|
|
||||||
target_user_id,
|
|
||||||
greeting,
|
|
||||||
apply_time,
|
|
||||||
apply_status,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
) VALUES (
|
|
||||||
#{apply_user_id},
|
|
||||||
#{target_user_id},
|
|
||||||
#{greeting},
|
|
||||||
NOW(),
|
|
||||||
0,
|
|
||||||
NOW(),
|
|
||||||
NOW()
|
|
||||||
)
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<!-- 更新好友申请状态 -->
|
|
||||||
<update id="updateFriendApplyStatus" parameterType="java.util.Map">
|
|
||||||
UPDATE friend_apply
|
|
||||||
SET apply_status = #{apply_status},
|
|
||||||
updated_at = NOW()
|
|
||||||
WHERE apply_user_id = #{apply_user_id}
|
|
||||||
AND target_user_id = #{target_user_id}
|
|
||||||
AND apply_status = 0
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<!-- 删除好友申请(可选) -->
|
|
||||||
<delete id="deleteFriendApply" parameterType="java.util.Map">
|
|
||||||
DELETE FROM friend_apply
|
|
||||||
WHERE apply_user_id = #{apply_user_id}
|
|
||||||
AND target_user_id = #{target_user_id}
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<!-- 根据申请人ID和被申请人ID查询好友申请 -->
|
|
||||||
<select id="selectFriendApplyByUsers" parameterType="java.util.Map" resultType="java.util.Map">
|
|
||||||
SELECT
|
|
||||||
apply_id,
|
|
||||||
apply_user_id,
|
|
||||||
target_user_id,
|
|
||||||
greeting,
|
|
||||||
apply_time,
|
|
||||||
apply_status,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
FROM friend_apply
|
|
||||||
WHERE apply_user_id = #{applyUserId}
|
|
||||||
AND target_user_id = #{targetUserId}
|
|
||||||
AND apply_status = 0
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!-- 查询待处理的好友申请 -->
|
|
||||||
<select id="selectFriendApplyList" parameterType="java.lang.Long" resultType="java.util.Map">
|
|
||||||
SELECT
|
|
||||||
apply_id,
|
|
||||||
apply_user_id,
|
|
||||||
target_user_id,
|
|
||||||
greeting,
|
|
||||||
apply_time,
|
|
||||||
apply_status,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
FROM friend_apply
|
|
||||||
WHERE target_user_id = #{targetUserId}
|
|
||||||
AND apply_status = 0
|
|
||||||
ORDER BY apply_time DESC
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!-- 插入联系人记录(方法名同步修改,字段名不变) -->
|
|
||||||
<insert id="insertFriendRelation" parameterType="java.util.Map">
|
|
||||||
INSERT INTO contacts (
|
|
||||||
user_id,
|
|
||||||
contact_user_id,
|
|
||||||
contact_nickname,
|
|
||||||
relation_type,
|
|
||||||
contact_status,
|
|
||||||
add_time,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
) VALUES (
|
|
||||||
#{user_id},
|
|
||||||
#{contact_user_id},
|
|
||||||
#{contact_nickname},
|
|
||||||
#{relation_type},
|
|
||||||
#{contact_status},
|
|
||||||
NOW(),
|
|
||||||
NOW(),
|
|
||||||
NOW()
|
|
||||||
)
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<!-- 查询联系人列表(方法名同步修改,字段名不变) -->
|
|
||||||
<select id="selectFriendRelationListByUserId" parameterType="java.lang.Long" resultType="java.util.Map">
|
|
||||||
SELECT
|
|
||||||
contact_id,
|
|
||||||
user_id,
|
|
||||||
contact_user_id,
|
|
||||||
contact_nickname,
|
|
||||||
contact_avatar,
|
|
||||||
relation_type,
|
|
||||||
add_time,
|
|
||||||
last_chat_time,
|
|
||||||
contact_status,
|
|
||||||
contact_remark,
|
|
||||||
tags,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
FROM contacts
|
|
||||||
WHERE user_id = #{userId}
|
|
||||||
AND contact_status = 1
|
|
||||||
ORDER BY add_time DESC
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!-- 删除过期的好友申请 -->
|
|
||||||
<delete id="deleteExpiredFriendApply" parameterType="java.lang.Integer">
|
|
||||||
DELETE FROM friend_apply
|
|
||||||
WHERE apply_status = 0
|
|
||||||
AND created_at < DATE_SUB(NOW(), INTERVAL #{days} DAY)
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
@@ -24,8 +24,4 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<!-- 查询所有收藏动态 -->
|
|
||||||
<select id="showAllFavorites" resultType="com.bao.dating.pojo.entity.Post">
|
|
||||||
SELECT * FROM post WHERE post_id IN (SELECT post_id FROM post_favorite WHERE user_id = #{userid})
|
|
||||||
</select>
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -42,19 +42,6 @@
|
|||||||
AND user_id = #{userId}
|
AND user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<!--删除收藏记录-->
|
|
||||||
<delete id="deletePostFavoriteByPostId">
|
|
||||||
DELETE FROM post_favorite WHERE post_id = #{postId}
|
|
||||||
</delete>
|
|
||||||
<!--删除点赞记录-->
|
|
||||||
<delete id="deletePostLikeByPostId">
|
|
||||||
DELETE FROM post_like WHERE post_id = #{postId}
|
|
||||||
</delete>
|
|
||||||
<!--动态评论删除-->
|
|
||||||
<delete id="deleteCommentsByPostId">
|
|
||||||
DELETE FROM comments WHERE post_id = #{postId}
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
<!--动态查询-->
|
<!--动态查询-->
|
||||||
<resultMap id="PostResultMap" type="com.bao.dating.pojo.entity.Post">
|
<resultMap id="PostResultMap" type="com.bao.dating.pojo.entity.Post">
|
||||||
<id property="postId" column="post_id"/>
|
<id property="postId" column="post_id"/>
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
<mapper namespace="com.bao.dating.mapper.UserMapper">
|
<mapper namespace="com.bao.dating.mapper.UserMapper">
|
||||||
<!-- 向数据库中添加用户 -->
|
|
||||||
<insert id="saveUser">
|
|
||||||
insert into user(user_id,user_name,password_hash,salt,created_at,updated_at) values (#{userId},#{userName},#{passwordHash},#{salt},#{createdAt},#{updatedAt})
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<!--根据用户名查询用户-->
|
<!--根据用户名查询用户-->
|
||||||
<select id="getByUsername" resultType="com.bao.dating.pojo.entity.User">
|
<select id="getByUsername" resultType="com.bao.dating.pojo.entity.User">
|
||||||
@@ -32,6 +28,8 @@
|
|||||||
<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
|
||||||
@@ -45,18 +43,10 @@
|
|||||||
hobbies,
|
hobbies,
|
||||||
signature,
|
signature,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at,
|
||||||
FROM user WHERE user_id = #{userId}
|
user_latitude,
|
||||||
</select>
|
user_longitude
|
||||||
|
FROM dating.user WHERE user_id = #{userId}
|
||||||
<!-- 查询最大用户id -->
|
|
||||||
<select id="selectMaxId" resultType="java.lang.Long">
|
|
||||||
SELECT MAX(user_id) FROM user
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!-- 根据邮箱查询用户信息 -->
|
|
||||||
<select id="selectByUserEmailUser" resultType="com.bao.dating.pojo.entity.User">
|
|
||||||
select * from user where user_email = #{userEmail}
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!--根据ID更新动态-->
|
<!--根据ID更新动态-->
|
||||||
@@ -89,5 +79,40 @@
|
|||||||
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