Compare commits
47 Commits
feature-ip
...
88579a382e
| Author | SHA1 | Date | |
|---|---|---|---|
| 88579a382e | |||
| 4f36dd9aeb | |||
| 7c0bfbc1de | |||
|
|
c83d86ad1a | ||
|
|
b12128fad6 | ||
|
|
212668ae1c | ||
|
|
a648ecad2a | ||
|
|
b8ec4a434d | ||
|
|
3bc00334ea | ||
|
|
a6259875f2 | ||
| 34cad7457b | |||
| 61c4c9d442 | |||
|
|
717c0a0507 | ||
|
|
413bafa275 | ||
|
|
2ce8116126 | ||
|
|
60df001385 | ||
|
|
27c64b1106 | ||
|
|
0762b84c36 | ||
|
|
61d100fac0 | ||
|
|
8a6e44e1cb | ||
|
|
a004982355 | ||
|
|
3d8a32cbf7 | ||
|
|
34f41d61e2 | ||
|
|
0d166aa400 | ||
|
|
44c0b3611d | ||
|
|
f98b0e26f2 | ||
|
|
79345eb93e | ||
|
|
bfd6674dd9 | ||
|
|
70a1d0012e | ||
|
|
cc88ec820c | ||
|
|
0c4ddc2803 | ||
|
|
f31b42a038 | ||
|
|
9cf50ce7df | ||
|
|
401c2fa8bf | ||
|
|
fec7bb04b9 | ||
|
|
cd0abad225 | ||
|
|
96b256d46e | ||
|
|
fca54a6f97 | ||
|
|
0f8f47de8e | ||
|
|
2cb8ae5c3c | ||
|
|
7abd6fe27d | ||
|
|
dfc9508827 | ||
|
|
4c70bd3c6f | ||
|
|
d3c069967e | ||
| 4a2aff888a | |||
| 0b0959fa80 | |||
|
|
4401a8a44a |
17
pom.xml
17
pom.xml
@@ -26,6 +26,11 @@
|
||||
<version>3.5.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
@@ -56,6 +61,12 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- JUnit Platform Launcher for resolving junit-platform-launcher:1.8.2 issue -->
|
||||
<dependency>
|
||||
@@ -84,6 +95,12 @@
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- WebSocket 起步依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 阿里云相关依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
|
||||
@@ -3,12 +3,35 @@ package com.bao.dating;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
@MapperScan("com.bao.dating.mapper")
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class DatingApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DatingApplication.class, args);
|
||||
// 读取并打印 ciallo.txt 文件内容
|
||||
printCialloFile();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 读取并打印 ciallo.txt 文件内容
|
||||
*/
|
||||
private static void printCialloFile() {
|
||||
try (InputStream inputStream = DatingApplication.class.getClassLoader().getResourceAsStream("ciallo.txt");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("读取 ciallo.txt 文件时发生错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/main/java/com/bao/dating/anno/Log.java
Normal file
11
src/main/java/com/bao/dating/anno/Log.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.bao.dating.anno;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log {
|
||||
}
|
||||
48
src/main/java/com/bao/dating/aspect/LoggingAspect.java
Normal file
48
src/main/java/com/bao/dating/aspect/LoggingAspect.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.bao.dating.aspect;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 日志切面
|
||||
* @author KilLze
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LoggingAspect {
|
||||
@Pointcut("execution(* com.bao.dating.service.impl.*.*(..))")
|
||||
private void pt(){}
|
||||
|
||||
/**
|
||||
* 方法执行前执行
|
||||
* @param joinPoint 方法参数
|
||||
*/
|
||||
@Before("pt()")
|
||||
public void logBeforeMethod(JoinPoint joinPoint){
|
||||
// 获取方法名
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
// 获取参数
|
||||
Object[] args = joinPoint.getArgs();
|
||||
log.info("方法 {} 开始执行,参数: {}", methodName, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法执行成功后执行
|
||||
* @param joinPoint 方法参数
|
||||
*/
|
||||
@AfterReturning(pointcut = "pt()", returning = "result")
|
||||
public void logAfterMethod(JoinPoint joinPoint, Object result){
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
log.info("方法 {} 执行成功,返回值: {}", methodName, result);
|
||||
}
|
||||
|
||||
@AfterThrowing(pointcut = "pt()", throwing = "exception")
|
||||
public void logAfterThrowing(JoinPoint joinPoint, Exception exception){
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
log.error("方法 {} 执行异常", methodName, exception);
|
||||
}
|
||||
}
|
||||
64
src/main/java/com/bao/dating/aspect/OperateLogAspect.java
Normal file
64
src/main/java/com/bao/dating/aspect/OperateLogAspect.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package com.bao.dating.aspect;
|
||||
|
||||
|
||||
import com.bao.dating.context.UserContext;
|
||||
import com.bao.dating.mapper.OperateLogMapper;
|
||||
import com.bao.dating.pojo.entity.OperateLog;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 记录操作日志
|
||||
* @author KilLze
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class OperateLogAspect {
|
||||
|
||||
@Autowired
|
||||
private OperateLogMapper operateLogMapper;
|
||||
|
||||
@Around("@annotation(com.bao.dating.anno.Log)")
|
||||
public Object logOperate(ProceedingJoinPoint pjp) throws Throwable{
|
||||
|
||||
// 记录方法开始的时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// 执行目标方法
|
||||
Object result = pjp.proceed();
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
long costTime = endTime - startTime;
|
||||
|
||||
|
||||
// 构建日志对象
|
||||
OperateLog operatelog = new OperateLog();
|
||||
operatelog.setOperateUserId(getUserId());
|
||||
operatelog.setOperateTime(LocalDateTime.now());
|
||||
operatelog.setClassName(pjp.getTarget().getClass().getName());
|
||||
operatelog.setMethodName(pjp.getSignature().getName());
|
||||
operatelog.setMethodParams(Arrays.toString(pjp.getArgs()));
|
||||
operatelog.setReturnValue(result != null ? result.toString() : "void");
|
||||
operatelog.setCostTime(costTime);
|
||||
|
||||
log.info("记录操作日志: {}", operatelog);
|
||||
|
||||
operateLogMapper.insert(operatelog);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Long getUserId() {
|
||||
return UserContext.getUserId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.bao.dating.aspect;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 记录方法运行耗时
|
||||
* @author KilLze
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class RecordTimeAspect {
|
||||
@Around("execution(* com.bao.dating.service.impl.*.*(..))")
|
||||
public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {
|
||||
//1. 记录方法运行的开始时间
|
||||
long begin = System.currentTimeMillis();
|
||||
|
||||
//2. 执行原始的方法
|
||||
Object result = pjp.proceed();
|
||||
|
||||
//3. 记录方法运行的结束时间, 记录耗时
|
||||
long end = System.currentTimeMillis();
|
||||
log.info("方法 {} 执行耗时: {}ms", pjp.getSignature() ,end-begin);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.bao.dating.common;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
/**
|
||||
* 动态表
|
||||
*/
|
||||
@Data
|
||||
public class Post {
|
||||
private Long post_id; // 动态ID
|
||||
private String content; // 动态内容
|
||||
private Long user_id; // 发布人ID
|
||||
private LocalDateTime created_at; // 创建时间
|
||||
}
|
||||
34
src/main/java/com/bao/dating/config/RedisConfig.java
Normal file
34
src/main/java/com/bao/dating/config/RedisConfig.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.bao.dating.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Redis 配置类
|
||||
* @author KilLze
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
// 创建RedisTemplate对象
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
// 设置redis的连接工厂对象
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
|
||||
// 设置redis key的序列化器
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
// 设置value的序列化器
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
// 设置hash类型的key和value的序列化器
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,11 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
.addPathPatterns("/**")
|
||||
// 忽略的接口
|
||||
.excludePathPatterns(
|
||||
"/user/login","/user/register","/user/emailLogin","/ip/location"
|
||||
"/user/login",
|
||||
"/user/register",
|
||||
"/user/emailLogin",
|
||||
"/api/verification/send-email-code",
|
||||
"/ip/location"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
122
src/main/java/com/bao/dating/controller/FriendController.java
Normal file
122
src/main/java/com/bao/dating/controller/FriendController.java
Normal file
@@ -0,0 +1,122 @@
|
||||
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,6 +1,7 @@
|
||||
package com.bao.dating.controller;
|
||||
|
||||
|
||||
import com.bao.dating.anno.Log;
|
||||
import com.bao.dating.common.Result;
|
||||
import com.bao.dating.common.ResultCode;
|
||||
import com.bao.dating.pojo.dto.PostRequestDTO;
|
||||
@@ -30,6 +31,7 @@ public class PostController {
|
||||
* @param files 媒体文件数组
|
||||
* @return 上传后的文件URL列表
|
||||
*/
|
||||
@Log
|
||||
@PostMapping(value = "/upload", consumes = "multipart/form-data")
|
||||
public Result<List<String>> uploadMedia(@RequestParam("files") MultipartFile[] files) {
|
||||
List<String> fileUrls = postService.uploadMedia(files);
|
||||
@@ -41,6 +43,7 @@ public class PostController {
|
||||
* @param postDTO 动态信息
|
||||
* @return 发布的动态对象
|
||||
*/
|
||||
@Log
|
||||
@PostMapping( "/createPost")
|
||||
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO) {
|
||||
// 调用 Service 层处理发布动态业务逻辑
|
||||
@@ -54,10 +57,11 @@ public class PostController {
|
||||
* @param postIds 动态ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@Log
|
||||
@PostMapping("/deletePost")
|
||||
public Result<String> deleteById(@RequestBody List<Long> postIds){
|
||||
int deletedCount = postService.deletePostById(postIds);
|
||||
return Result.success(ResultCode.SUCCESS_DELETE, deletedCount > 0 ? "成功删除" : "删除失败,该动态不存在", null);
|
||||
return Result.success(ResultCode.SUCCESS_DELETE, "成功删除" + deletedCount + "条动态", null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +69,7 @@ public class PostController {
|
||||
* @param postId 动态ID
|
||||
* @return 动态对象
|
||||
*/
|
||||
@PostMapping("/{postId}")
|
||||
@GetMapping("/{postId}")
|
||||
public Result<PostEditVO> getPostById(@PathVariable Long postId) {
|
||||
PostEditVO postEditVO = postService.getPostForEdit(postId);
|
||||
return Result.success(ResultCode.SUCCESS,"查询成功", postEditVO);
|
||||
@@ -77,6 +81,7 @@ public class PostController {
|
||||
* @param postRequestDTO 动态信息
|
||||
* @return 更新后的动态对象
|
||||
*/
|
||||
@Log
|
||||
@PostMapping("/{postId}/updatePost")
|
||||
public Result<PostEditVO> updatePost(@PathVariable Long postId, @RequestBody PostRequestDTO postRequestDTO) {
|
||||
PostEditVO result = postService.updatePost(postId, postRequestDTO);
|
||||
|
||||
@@ -2,13 +2,11 @@ package com.bao.dating.controller;
|
||||
|
||||
import com.bao.dating.common.Result;
|
||||
import com.bao.dating.common.ResultCode;
|
||||
import com.bao.dating.mapper.PostLikeMapper;
|
||||
import com.bao.dating.service.PostLikeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/posts")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.bao.dating.controller;
|
||||
|
||||
import com.bao.dating.anno.Log;
|
||||
import com.bao.dating.common.Result;
|
||||
import com.bao.dating.common.ResultCode;
|
||||
import com.bao.dating.context.UserContext;
|
||||
@@ -8,10 +9,12 @@ import com.bao.dating.pojo.dto.UserLoginDTO;
|
||||
import com.bao.dating.pojo.vo.UserInfoVO;
|
||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
||||
import com.bao.dating.service.UserService;
|
||||
import io.jsonwebtoken.Jwt;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 用户接口
|
||||
@@ -35,6 +38,17 @@ public class UserController {
|
||||
return Result.success(ResultCode.SUCCESS, "登录成功", userloginVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* 从请求头中获取token并将其加入黑名单
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
public Result<Void> logout(HttpServletRequest request) {
|
||||
String token = request.getHeader("token");
|
||||
userService.logout(token);
|
||||
return Result.success(ResultCode.SUCCESS,"退出登录成功",null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @return 用户信息
|
||||
@@ -51,6 +65,7 @@ public class UserController {
|
||||
* @param file 头像文件
|
||||
* @return 上传后的文件URL列表
|
||||
*/
|
||||
@Log
|
||||
@PostMapping(value = "/info/uploadAvatar", consumes = "multipart/form-data")
|
||||
public Result<String> uploadAvatar(@RequestParam("file") MultipartFile file) {
|
||||
String fileUrl = userService.uploadAvatar(file);
|
||||
@@ -62,6 +77,7 @@ public class UserController {
|
||||
* @param file 背景文件
|
||||
* @return 上传后的文件URL列表
|
||||
*/
|
||||
@Log
|
||||
@PostMapping(value = "/info/uploadBackground", consumes = "multipart/form-data")
|
||||
public Result<String> uploadBackground(@RequestParam("file") MultipartFile file) {
|
||||
String fileUrl = userService.uploadBackground(file);
|
||||
@@ -73,6 +89,7 @@ public class UserController {
|
||||
* @param userInfoUpdateDTO 用户信息更新参数
|
||||
* @return 更新后的用户信息
|
||||
*/
|
||||
@Log
|
||||
@PostMapping("/info/update")
|
||||
public Result<UserInfoVO> userInfoUpdate(@RequestBody UserInfoUpdateDTO userInfoUpdateDTO) {
|
||||
Long userId = UserContext.getUserId();
|
||||
|
||||
4
src/main/java/com/bao/dating/controller/text.java
Normal file
4
src/main/java/com/bao/dating/controller/text.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.bao.dating.controller;
|
||||
|
||||
public class text {
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.bao.dating.common.Result;
|
||||
import com.bao.dating.common.ResultCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
@@ -15,7 +14,7 @@ import org.springframework.web.method.annotation.MethodArgumentTypeMismatchExcep
|
||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 全局异常处理器
|
||||
@@ -32,7 +31,12 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public Result<String> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
||||
log.error("参数验证失败: {}", e.getMessage());
|
||||
return Result.error(ResultCode.PARAM_ERROR, e.getBindingResult().getFieldError().getDefaultMessage());
|
||||
String msg = e.getBindingResult()
|
||||
.getFieldErrors()
|
||||
.stream()
|
||||
.map(error -> error.getField() + ":" + error.getDefaultMessage())
|
||||
.collect(Collectors.joining("; "));
|
||||
return Result.error(ResultCode.PARAM_ERROR, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,10 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.bao.dating.context.UserContext;
|
||||
import com.bao.dating.util.JwtUtil;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@@ -18,6 +21,10 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@Slf4j
|
||||
@Component
|
||||
public class TokenInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
/**
|
||||
* 在请求处理之前进行拦截
|
||||
* 从请求头或URL参数中获取token,验证其有效性,并将用户ID保存到ThreadLocal中
|
||||
@@ -45,13 +52,38 @@ public class TokenInterceptor implements HandlerInterceptor {
|
||||
if (!JwtUtil.validateToken(token)) {
|
||||
log.error("Token无效或已过期");
|
||||
response.setStatus(401);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("Token无效或已过期");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查 token 是否在黑名单中
|
||||
Object blacklistToken = redisTemplate.opsForValue().get("jwt:blacklist:" + token);
|
||||
if (blacklistToken != null) {
|
||||
log.error("Token已在黑名单中");
|
||||
response.setStatus(401);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("登录已失效, 请重新登录");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 解析 token
|
||||
String userId = JwtUtil.getSubjectFromToken(token);
|
||||
|
||||
// 从Redis获取存储的token进行比对
|
||||
Object redisTokenObj = redisTemplate.opsForValue().get("login:token:" + userId);
|
||||
String redisToken = redisTokenObj != null ? redisTokenObj.toString() : null;
|
||||
|
||||
// 验证Redis中的token是否存在且匹配
|
||||
if (redisToken == null || !redisToken.equals(token)) {
|
||||
log.error("登录已失效");
|
||||
response.setStatus(401);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("登录已失效");
|
||||
return false;
|
||||
}
|
||||
|
||||
log.info("用户: {}", userId);
|
||||
|
||||
// 保存 userId 到 ThreadLocal
|
||||
UserContext.setUserId(Long.valueOf(userId));
|
||||
return true;
|
||||
|
||||
@@ -18,4 +18,11 @@ public interface CommentsMapper {
|
||||
// 根据动态ID查询评论列表
|
||||
@Select("SELECT * FROM comments WHERE post_id = #{post_id} ORDER BY created_at DESC")
|
||||
List<Comments> getCommentsByPostId(@Param("post_id") Long post_id);
|
||||
|
||||
/**
|
||||
* 根据动态ID批量删除评论
|
||||
* @param postIds
|
||||
* @return
|
||||
*/
|
||||
int deleteCommentsByPostIds(@Param("postIds") List<Long> postIds);
|
||||
}
|
||||
|
||||
20
src/main/java/com/bao/dating/mapper/ContactMapper.java
Normal file
20
src/main/java/com/bao/dating/mapper/ContactMapper.java
Normal file
@@ -0,0 +1,20 @@
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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);
|
||||
}
|
||||
19
src/main/java/com/bao/dating/mapper/OperateLogMapper.java
Normal file
19
src/main/java/com/bao/dating/mapper/OperateLogMapper.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.bao.dating.mapper;
|
||||
|
||||
|
||||
import com.bao.dating.pojo.entity.OperateLog;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 操作日志Mapper
|
||||
* @author KilLze
|
||||
*/
|
||||
@Mapper
|
||||
public interface OperateLogMapper {
|
||||
|
||||
@Insert("insert into operate_log (operate_user_id, operate_time, class_name, method_name, method_params, return_value, cost_time) " +
|
||||
"values (#{operateUserId}, #{operateTime}, #{className}, #{methodName}, #{methodParams}, #{returnValue}, #{costTime});")
|
||||
public void insert(OperateLog log);
|
||||
|
||||
}
|
||||
@@ -15,6 +15,14 @@ public interface PostFavoriteMapper {
|
||||
int addPostFavorite(PostFavorite postFavorite);
|
||||
//删除收藏
|
||||
int deletePostFavorite(@Param("postId") Long postId);
|
||||
|
||||
/**
|
||||
* 批量删除收藏
|
||||
* @param postIds
|
||||
* @return
|
||||
*/
|
||||
int deleteFavoritesByPostIds(@Param("postIds") List<Long> postIds);
|
||||
|
||||
//查询用户所有收藏
|
||||
List<Post> showAllFavorites(@Param("userid")Long userid);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.bao.dating.pojo.entity.PostLike;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PostLikeMapper {
|
||||
/**
|
||||
@@ -31,4 +33,12 @@ public interface PostLikeMapper {
|
||||
* @return
|
||||
*/
|
||||
int deleteByPostIdAndUserId(@Param("postId") Long postId, @Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 批量删除点赞记录
|
||||
*
|
||||
* @param postIds
|
||||
* @return
|
||||
*/
|
||||
int deleteLikesByPostIds(@Param("postIds") List<Long> postIds);
|
||||
}
|
||||
|
||||
@@ -21,11 +21,33 @@ public interface PostMapper {
|
||||
void insert(Post post);
|
||||
|
||||
/**
|
||||
* 根据ID删除动态
|
||||
* 根据ID修改动态状态
|
||||
*
|
||||
* @param postIds 动态ID
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
int deletePostByIds(List<Long> postIds);
|
||||
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查询动态
|
||||
|
||||
@@ -54,5 +54,4 @@ public interface UserMapper {
|
||||
*/
|
||||
User selectByUserEmailUser(@Param("userEmail") String email);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.bao.dating.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@@ -11,7 +12,7 @@ import java.util.List;
|
||||
* @author KilLze
|
||||
*/
|
||||
@Data
|
||||
public class UserInfoUpdateDTO {
|
||||
public class UserInfoUpdateDTO implements Serializable {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String nickname;
|
||||
|
||||
24
src/main/java/com/bao/dating/pojo/entity/Contacts.java
Normal file
24
src/main/java/com/bao/dating/pojo/entity/Contacts.java
Normal file
@@ -0,0 +1,24 @@
|
||||
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; // 更新时间
|
||||
}
|
||||
60
src/main/java/com/bao/dating/pojo/entity/FriendApply.java
Normal file
60
src/main/java/com/bao/dating/pojo/entity/FriendApply.java
Normal file
@@ -0,0 +1,60 @@
|
||||
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;
|
||||
}
|
||||
30
src/main/java/com/bao/dating/pojo/entity/OperateLog.java
Normal file
30
src/main/java/com/bao/dating/pojo/entity/OperateLog.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.bao.dating.pojo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 操作日志
|
||||
* @author KilLze
|
||||
*/
|
||||
@Data
|
||||
public class OperateLog implements Serializable {
|
||||
/** ID */
|
||||
private Long id;
|
||||
/** 操作人ID */
|
||||
private Long operateUserId;
|
||||
/** 操作时间 */
|
||||
private LocalDateTime operateTime;
|
||||
/** 操作类名 */
|
||||
private String className;
|
||||
/** 操作方法名 */
|
||||
private String methodName;
|
||||
/** 操作方法参数 */
|
||||
private String methodParams;
|
||||
/** 操作方法返回值 */
|
||||
private String returnValue;
|
||||
/** 操作耗时 */
|
||||
private Long costTime;
|
||||
}
|
||||
20
src/main/java/com/bao/dating/service/ContactsService.java
Normal file
20
src/main/java/com/bao/dating/service/ContactsService.java
Normal file
@@ -0,0 +1,20 @@
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public interface PostService {
|
||||
Post createPost(PostRequestDTO postRequestDTO);
|
||||
|
||||
/**
|
||||
* 批量删除动态
|
||||
* 批量删除动态(将动态状态改为已删除)
|
||||
* @param postIds 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,13 @@ public interface UserService {
|
||||
*/
|
||||
UserLoginVO userLogin(UserLoginDTO userLoginDTO);
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @param token 登录凭证
|
||||
* @return 注册结果
|
||||
*/
|
||||
void logout(String token);
|
||||
|
||||
/**
|
||||
* 查询个人信息
|
||||
* @param userId 动态ID
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,22 @@ import com.bao.dating.common.aliyun.GreenImageScan;
|
||||
import com.bao.dating.common.aliyun.GreenTextScan;
|
||||
import com.bao.dating.common.result.GreenAuditResult;
|
||||
import com.bao.dating.context.UserContext;
|
||||
import com.bao.dating.mapper.CommentsMapper;
|
||||
import com.bao.dating.mapper.PostFavoriteMapper;
|
||||
import com.bao.dating.mapper.PostLikeMapper;
|
||||
import com.bao.dating.mapper.PostMapper;
|
||||
import com.bao.dating.pojo.dto.PostRequestDTO;
|
||||
import com.bao.dating.pojo.entity.Post;
|
||||
import com.bao.dating.pojo.vo.PostEditVO;
|
||||
import com.bao.dating.service.PostService;
|
||||
import com.bao.dating.common.aliyun.AliOssUtil;
|
||||
import com.bao.dating.service.UserService;
|
||||
import com.bao.dating.util.FileUtil;
|
||||
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.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -43,6 +48,15 @@ public class PostServiceImpl implements PostService {
|
||||
@Autowired
|
||||
private PostMapper postMapper;
|
||||
|
||||
@Autowired
|
||||
private PostLikeMapper postLikeMapper;
|
||||
|
||||
@Autowired
|
||||
private PostFavoriteMapper postFavoriteMapper;
|
||||
|
||||
@Autowired
|
||||
private CommentsMapper commentsMapper;
|
||||
|
||||
/**
|
||||
* 上传媒体文件
|
||||
* @param files 媒体文件数组
|
||||
@@ -177,7 +191,7 @@ public class PostServiceImpl implements PostService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除动态
|
||||
* 批量删除动态(将动态状态改为已删除)
|
||||
*
|
||||
* @param postIds 动态ID
|
||||
* @return 删除的动态对象
|
||||
@@ -188,6 +202,10 @@ public class PostServiceImpl implements PostService {
|
||||
// 判断用户权限
|
||||
Long userId = UserContext.getUserId();
|
||||
|
||||
if (CollectionUtils.isEmpty(postIds)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 遍历所有要删除的帖子ID,验证权限
|
||||
for (Long postId : postIds) {
|
||||
Post post = postMapper.selectById(postId);
|
||||
@@ -199,8 +217,19 @@ public class PostServiceImpl implements PostService {
|
||||
throw new RuntimeException("无权限删除此动态");
|
||||
}
|
||||
}
|
||||
// 批量删除动态
|
||||
return postMapper.deletePostByIds(postIds);
|
||||
|
||||
int affected = postMapper.updatePublicById(postIds, userId);
|
||||
|
||||
if (affected == 0) {
|
||||
throw new RuntimeException("未删除任何动态,可能无权限或动态不存在");
|
||||
}
|
||||
|
||||
// 删除动态下的评论、点赞、收藏
|
||||
commentsMapper.deleteCommentsByPostIds(postIds);
|
||||
postLikeMapper.deleteLikesByPostIds(postIds);
|
||||
postFavoriteMapper.deleteFavoritesByPostIds(postIds);
|
||||
|
||||
return affected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.bao.dating.common.aliyun.GreenImageScan;
|
||||
import com.bao.dating.common.aliyun.GreenTextScan;
|
||||
import com.bao.dating.common.result.AliOssResult;
|
||||
import com.bao.dating.common.result.GreenAuditResult;
|
||||
import com.bao.dating.config.RedisConfig;
|
||||
import com.bao.dating.context.UserContext;
|
||||
import com.bao.dating.mapper.UserMapper;
|
||||
import com.bao.dating.pojo.dto.UserInfoUpdateDTO;
|
||||
@@ -19,17 +20,17 @@ import com.bao.dating.service.VerificationCodeService;
|
||||
import com.bao.dating.util.FileUtil;
|
||||
import com.bao.dating.util.JwtUtil;
|
||||
import com.bao.dating.util.MD5Util;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 用户服务实现类
|
||||
@@ -48,6 +49,9 @@ public class UserServiceImpl implements UserService {
|
||||
@Autowired
|
||||
private GreenImageScan greenImageScan;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@@ -82,6 +86,15 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
// 生成token
|
||||
String token = JwtUtil.generateToken(String.valueOf(user.getUserId()));
|
||||
|
||||
String redisKey = "login:token:" + user.getUserId();
|
||||
redisTemplate.opsForValue().set(
|
||||
redisKey,
|
||||
token,
|
||||
7,
|
||||
TimeUnit.DAYS
|
||||
);
|
||||
|
||||
// 封装返回
|
||||
UserLoginVO userLoginVO = new UserLoginVO();
|
||||
userLoginVO.setUserId(user.getUserId());
|
||||
@@ -90,6 +103,29 @@ public class UserServiceImpl implements UserService {
|
||||
return userLoginVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @param token 登录凭证
|
||||
*/
|
||||
@Override
|
||||
public void logout(String token) {
|
||||
Claims claims = JwtUtil.getClaimsFromToken(token);
|
||||
Date expiration = claims.getExpiration();
|
||||
// 判断 token 是否已过期
|
||||
long ttl = expiration.getTime() - System.currentTimeMillis();
|
||||
// 如果 token 已过期,则不用处理
|
||||
if (ttl <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
String logoutKey = "jwt:blacklist:" + token;
|
||||
redisTemplate.opsForValue().set(
|
||||
logoutKey,
|
||||
"logout",
|
||||
ttl,
|
||||
TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,7 @@ public class EmailUtil {
|
||||
} catch (MessagingException e) {
|
||||
log.error("HTML邮件发送失败,收件人:{},异常信息:{}", to, e.getMessage(), e);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +174,7 @@ public class EmailUtil {
|
||||
}
|
||||
log.info("批量邮件发送完成,总数:{},成功:{}", toList.length, successCount);
|
||||
return successCount;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.security.NoSuchAlgorithmException;
|
||||
* @author KilLze
|
||||
*/
|
||||
public class MD5Util {
|
||||
|
||||
/**
|
||||
* 对字符串进行MD5加密
|
||||
* @param input 待加密的字符串
|
||||
@@ -19,7 +18,6 @@ public class MD5Util {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] digest = md.digest(input.getBytes());
|
||||
@@ -28,7 +26,6 @@ public class MD5Util {
|
||||
throw new RuntimeException("MD5算法不可用", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字符串进行MD5加密(带盐值)
|
||||
* @param input 待加密的字符串
|
||||
@@ -44,7 +41,6 @@ public class MD5Util {
|
||||
}
|
||||
return encrypt(input + salt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字符串与MD5值是否匹配
|
||||
* @param input 原始字符串
|
||||
@@ -57,7 +53,6 @@ public class MD5Util {
|
||||
}
|
||||
return encrypt(input).equalsIgnoreCase(md5Hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证字符串与MD5值是否匹配(带盐值)
|
||||
* @param input 原始字符串
|
||||
@@ -74,7 +69,6 @@ public class MD5Util {
|
||||
}
|
||||
return encryptWithSalt(input, salt).equalsIgnoreCase(md5Hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符串
|
||||
* @param bytes 字节数组
|
||||
@@ -88,6 +82,3 @@ public class MD5Util {
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,11 @@ server:
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
mvc:
|
||||
throw-exception-if-no-handler-found: true
|
||||
web:
|
||||
resources:
|
||||
add-mappings: false
|
||||
datasource:
|
||||
url: jdbc:mysql://110.42.41.177:3306/dating?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
@@ -39,7 +44,6 @@ spring:
|
||||
connectiontimeout: 10000 # 连接超时时间(毫秒)
|
||||
timeout: 10000 # 读取超时时间(毫秒)
|
||||
writetimeout: 10000 # 写入超时时间(毫秒)
|
||||
|
||||
# MyBatis 配置
|
||||
mybatis:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
|
||||
9
src/main/resources/ciallo.txt
Normal file
9
src/main/resources/ciallo.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
▄▄▄▄ ██ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄
|
||||
██▀▀▀▀█ ▀▀ ▀▀██ ▀▀██ ██ ▄▄ ██
|
||||
██▀ ████ ▄█████▄ ██ ██ ▄████▄ ▄▄▄ ▄█▀ ▄█▀ ██ █▄ ▄▄▄█ ▀█▄ ▄▄▄▄
|
||||
██ ██ ▀ ▄▄▄██ ██ ██ ██▀ ▀██ ▀ ▀▀▄▄ ▄ ██ ▄█▀ ██ ██ ██ ▄▄█▀▀▀ ██ █▀▀ ▀█▄ █▄
|
||||
██▄ ██ ▄██▀▀▀██ ██ ██ ██ ██ ▀▀▀ ██ ▄█▄▄▄▄▄ ▀▀ ██ ██ ██ ▀▀█▄▄▄ ██ █▀ █ ▀▀████▀
|
||||
██▄▄▄▄█ ▄▄▄██▄▄▄ ██▄▄▄███ ██▄▄▄ ██▄▄▄ ▀██▄▄██▀ ▀█▄ ▀▀▀▀▀▀▀▀ ██▄██▄██ ▀▀▀█ ▄█▀ █▀▀█
|
||||
▀▀▀▀ ▀▀▀▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ██ ▀▀▀ ▀▀▀ ██
|
||||
▀▀ ▀▀
|
||||
15
src/main/resources/com/bao/dating/mapper/CommentsMapper.xml
Normal file
15
src/main/resources/com/bao/dating/mapper/CommentsMapper.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?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.CommentsMapper">
|
||||
|
||||
<!-- 批量删除动态下的所有评论 -->
|
||||
<delete id="deleteCommentsByPostIds">
|
||||
DELETE FROM comments
|
||||
WHERE post_id IN
|
||||
<foreach collection="postIds" item="postId" open="(" close=")" separator=",">
|
||||
#{postId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
25
src/main/resources/com/bao/dating/mapper/ContactMapper.xml
Normal file
25
src/main/resources/com/bao/dating/mapper/ContactMapper.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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>
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
<?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>
|
||||
@@ -14,6 +14,16 @@
|
||||
<select id="selectUserIDByPostID" resultType="java.lang.Long">
|
||||
SELECT user_id FROM post_favorite WHERE post_id = #{postId}
|
||||
</select>
|
||||
|
||||
<!--批量删除动态收藏-->
|
||||
<delete id="deleteFavoritesByPostIds">
|
||||
DELETE FROM post_favorite
|
||||
WHERE post_id IN
|
||||
<foreach collection="postIds" item="postId" open="(" close=")" separator=",">
|
||||
#{postId}
|
||||
</foreach>
|
||||
</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})
|
||||
|
||||
@@ -14,4 +14,14 @@
|
||||
<delete id="deleteByPostIdAndUserId">
|
||||
delete from dating.post_like where post_id = #{postId} and user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
<!--批量删除点赞记录-->
|
||||
<delete id="deleteLikesByPostIds">
|
||||
DELETE FROM post_like
|
||||
WHERE post_id IN
|
||||
<foreach collection="postIds" item="postId" open="(" close=")" separator=",">
|
||||
#{postId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -28,23 +28,30 @@
|
||||
#{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
|
||||
</insert>
|
||||
|
||||
<!--动态删除-->
|
||||
<delete id="deletePostByIds">
|
||||
DELETE FROM post WHERE post_id IN
|
||||
<!--修改动态状态-->
|
||||
<update id="updatePublicById">
|
||||
UPDATE post
|
||||
<set>
|
||||
is_public = 3,
|
||||
updated_at = NOW()
|
||||
</set>
|
||||
WHERE post_id IN
|
||||
<foreach item="postId" index="index" collection="postIds" separator="," open="(" close=")">
|
||||
#{postId}
|
||||
</foreach>
|
||||
</delete>
|
||||
AND user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<!--删除收藏记录-->
|
||||
<delete id="1">
|
||||
<delete id="deletePostFavoriteByPostId">
|
||||
DELETE FROM post_favorite WHERE post_id = #{postId}
|
||||
</delete>
|
||||
<!--删除点赞记录-->
|
||||
<delete id="2">
|
||||
<delete id="deletePostLikeByPostId">
|
||||
DELETE FROM post_like WHERE post_id = #{postId}
|
||||
</delete>
|
||||
<!--动态评论删除-->
|
||||
<delete id="3">
|
||||
<delete id="deleteCommentsByPostId">
|
||||
DELETE FROM comments WHERE post_id = #{postId}
|
||||
</delete>
|
||||
|
||||
|
||||
@@ -88,4 +88,6 @@
|
||||
</set>
|
||||
WHERE user_id = #{userId}
|
||||
</update>
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user