Compare commits
3 Commits
feature-Po
...
feature-Po
| Author | SHA1 | Date | |
|---|---|---|---|
| d20ce917a2 | |||
| d8b16e0287 | |||
| b1ea85b5e4 |
@@ -1,9 +1,8 @@
|
|||||||
package com.bao.dating.pojo.entity;
|
package com.bao.dating.common;
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@ import java.time.LocalDateTime;
|
|||||||
* 评论表
|
* 评论表
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Comments implements Serializable {
|
public class Comments {
|
||||||
private Long comment_id; // 评论ID
|
private Long comment_id; // 评论ID
|
||||||
private String content; // 评论内容
|
private String content; // 评论内容
|
||||||
private Long user_id; // 评论人ID
|
private Long user_id; // 评论人ID
|
||||||
@@ -11,8 +11,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -32,6 +30,7 @@ public class AliOssUtil {
|
|||||||
* @return 完整的文件访问URL
|
* @return 完整的文件访问URL
|
||||||
*/
|
*/
|
||||||
public String upload(byte[] bytes, String objectName) {
|
public String upload(byte[] bytes, String objectName) {
|
||||||
|
|
||||||
// 创建OSSClient实例。
|
// 创建OSSClient实例。
|
||||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||||
|
|
||||||
|
|||||||
@@ -147,5 +147,3 @@ public class SmsUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.bao.dating.config;
|
|
||||||
|
|
||||||
|
|
||||||
import com.bao.dating.interceptor.TokenInterceptor;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class WebConfig implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TokenInterceptor tokenInterceptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加拦截器到Spring MVC配置中
|
|
||||||
* @param registry 拦截器注册中心
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
|
||||||
//注册自定义拦截器对象
|
|
||||||
registry.addInterceptor(tokenInterceptor)
|
|
||||||
// 拦截所有请求
|
|
||||||
.addPathPatterns("/**")
|
|
||||||
// 忽略的接口
|
|
||||||
.excludePathPatterns(
|
|
||||||
"/user/login",
|
|
||||||
"/user/userRegister"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.bao.dating.context;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户上下文类
|
|
||||||
* @author lenovo
|
|
||||||
*/
|
|
||||||
public class UserContext {
|
|
||||||
|
|
||||||
private static final ThreadLocal<Long> userHolder = new ThreadLocal<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置当前线程的用户ID
|
|
||||||
* @param userId 用户ID
|
|
||||||
*/
|
|
||||||
public static void setUserId(Long userId) {
|
|
||||||
userHolder.set(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前线程的用户ID
|
|
||||||
* @return 当前用户ID,如果未设置则返回null
|
|
||||||
*/
|
|
||||||
public static Long getUserId() {
|
|
||||||
return userHolder.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除当前线程的用户ID
|
|
||||||
*/
|
|
||||||
public static void clear() {
|
|
||||||
userHolder.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.bao.dating.controller;
|
package com.bao.dating.controller;
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.Comments;
|
import com.bao.dating.common.Comments;
|
||||||
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.service.CommentsService;
|
import com.bao.dating.service.CommentsService;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class PostController {
|
|||||||
private PostService postService;
|
private PostService postService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传媒体文件接口 like
|
* 上传媒体文件接口
|
||||||
* @param files 媒体文件数组
|
* @param files 媒体文件数组
|
||||||
* @return 上传后的文件URL列表
|
* @return 上传后的文件URL列表
|
||||||
*/
|
*/
|
||||||
@@ -33,26 +33,26 @@ public class PostController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 发布动态接口 - JSON格式请求
|
* 发布动态接口 - JSON格式请求
|
||||||
* @param postDTO 动态信息
|
* @param postRequestDTO 动态信息
|
||||||
* @return 发布的动态对象
|
* @return 发布的动态对象
|
||||||
*/
|
*/
|
||||||
@PostMapping(consumes = "application/json")
|
@PostMapping(consumes = "application/json")
|
||||||
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO) {
|
public Result<Post> createPostJson(@RequestBody PostRequestDTO postRequestDTO) {
|
||||||
// 调用 Service 层处理发布动态业务逻辑
|
// 调用 Service 层处理发布动态业务逻辑
|
||||||
Post result = postService.createPost(postDTO);
|
Post result = postService.createPost(postRequestDTO);
|
||||||
return Result.success(ResultCode.SUCCESS_REVIEW, "动态发布成功,等待审核。", result);
|
return Result.success(ResultCode.SUCCESS_REVIEW, "动态发布成功,等待审核。", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除动态
|
* 删除动态
|
||||||
*
|
*
|
||||||
* @param postIds 动态ID
|
* @param postId 动态ID
|
||||||
* @return 删除结果
|
* @return 删除结果
|
||||||
*/
|
*/
|
||||||
@DeleteMapping
|
@DeleteMapping("/{postId}")
|
||||||
public Result<String> deleteById(@RequestParam List<Long> postIds){
|
public Result<String> deleteById(@PathVariable Integer postId){
|
||||||
int deletedCount = postService.deletePostById(postIds);
|
postService.deletePostById(postId);
|
||||||
return Result.success(ResultCode.SUCCESS_DELETE, deletedCount > 0 ? "成功删除" : "删除失败,该动态不存在", null);
|
return Result.success(ResultCode.SUCCESS_DELETE, "动态删除成功", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +65,7 @@ public class PostController {
|
|||||||
PostEditVO postEditVO = postService.getPostForEdit(postId);
|
PostEditVO postEditVO = postService.getPostForEdit(postId);
|
||||||
return Result.success(ResultCode.SUCCESS,"查询成功", postEditVO);
|
return Result.success(ResultCode.SUCCESS,"查询成功", postEditVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新动态接口
|
* 更新动态接口
|
||||||
* @param postId 动态ID
|
* @param postId 动态ID
|
||||||
|
|||||||
@@ -2,15 +2,12 @@ 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.PostFavorite;
|
|
||||||
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 com.bao.dating.service.PostService;
|
import com.bao.dating.service.PostService;
|
||||||
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
|
||||||
@@ -34,11 +31,4 @@ public class PostFavoriteController {
|
|||||||
Long userId = user.getUserId();
|
Long userId = user.getUserId();
|
||||||
return postFavoriteService.deletePostFavorite(userId, postId);
|
return postFavoriteService.deletePostFavorite(userId, postId);
|
||||||
}
|
}
|
||||||
@GetMapping("/{user_id}/favorites")
|
|
||||||
public Result<List<Post>> getFavorites(@PathVariable("user_id")Long postId){
|
|
||||||
if (postId == null){
|
|
||||||
return Result.error(ResultCode.PARAM_ERROR);
|
|
||||||
}
|
|
||||||
return postFavoriteService.getAllFavoritePost(postId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
package com.bao.dating.controller;
|
|
||||||
|
|
||||||
import com.bao.dating.common.Result;
|
|
||||||
import com.bao.dating.common.ResultCode;
|
|
||||||
import com.bao.dating.pojo.dto.UserLoginDTO;
|
|
||||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
|
||||||
import com.bao.dating.service.UserService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/user")
|
|
||||||
public class UserController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserService userService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录
|
|
||||||
* @param userLoginDTO 登录参数
|
|
||||||
*/
|
|
||||||
@PostMapping("/login")
|
|
||||||
public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
|
|
||||||
UserLoginVO userloginVO = userService.userLogin(userLoginDTO);
|
|
||||||
return Result.success(ResultCode.SUCCESS, "登录成功", userloginVO);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户注册
|
|
||||||
* @param userAccount 用户名称
|
|
||||||
* @param userPassword 用户密码
|
|
||||||
* @return 用户id
|
|
||||||
*/
|
|
||||||
@PostMapping("/userRegister")
|
|
||||||
public Result userRegister(String userAccount, String userPassword){
|
|
||||||
long result = userService.userRegister(userAccount, userPassword);
|
|
||||||
if (result == -1){
|
|
||||||
return Result.error(ResultCode.SYSTEM_ERROR);
|
|
||||||
}
|
|
||||||
if (result==-2){
|
|
||||||
return Result.error(ResultCode.PARAM_ERROR);
|
|
||||||
}
|
|
||||||
if (result == -3){
|
|
||||||
return Result.error(ResultCode.FAIL,"用户名称相同");
|
|
||||||
}
|
|
||||||
return Result.success(ResultCode.SUCCESS,"注册成功",result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
package com.bao.dating.interceptor;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
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.stereotype.Component;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HttpToken拦截器类
|
|
||||||
* 用于拦截请求并验证JWT token的有效性,同时从token中解析用户信息
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class TokenInterceptor implements HandlerInterceptor {
|
|
||||||
/**
|
|
||||||
* 在请求处理之前进行拦截
|
|
||||||
* 从请求头或URL参数中获取token,验证其有效性,并将用户ID保存到ThreadLocal中
|
|
||||||
* @param request HTTP请求对象
|
|
||||||
* @param response HTTP响应对象
|
|
||||||
* @param handler 处理器
|
|
||||||
* @return 验证通过返回true,否则返回false
|
|
||||||
* @throws Exception 异常
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
||||||
|
|
||||||
//判断当前拦截到的是Controller的方法还是其他资源
|
|
||||||
if (!(handler instanceof HandlerMethod)) {
|
|
||||||
//当前拦截到的不是动态方法,直接放行
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// 从 header 获取 token
|
|
||||||
String token = request.getHeader("token");
|
|
||||||
|
|
||||||
try {
|
|
||||||
log.info("jwt校验: {}", token);
|
|
||||||
|
|
||||||
// 验证 token 是否有效(包括是否过期)
|
|
||||||
if (!JwtUtil.validateToken(token)) {
|
|
||||||
log.error("Token 无效或已过期");
|
|
||||||
response.setStatus(401);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析 token
|
|
||||||
String userId = JwtUtil.getSubjectFromToken(token);
|
|
||||||
log.info("用户: {}", userId);
|
|
||||||
|
|
||||||
// 保存 userId 到 ThreadLocal
|
|
||||||
UserContext.setUserId(Long.valueOf(userId));
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Token 校验失败: {}", e.getMessage());
|
|
||||||
response.setStatus(401);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在请求完成之后执行清理工作
|
|
||||||
* 清除保存在ThreadLocal中的用户ID,防止内存泄漏
|
|
||||||
* @param request HTTP请求对象
|
|
||||||
* @param response HTTP响应对象
|
|
||||||
* @param handler 处理器
|
|
||||||
* @param ex 异常对象
|
|
||||||
* @throws Exception 异常
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
|
||||||
UserContext.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.bao.dating.mapper;
|
package com.bao.dating.mapper;
|
||||||
|
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.Comments;
|
import com.bao.dating.common.Comments;
|
||||||
|
import com.bao.dating.common.Post;
|
||||||
import org.apache.ibatis.annotations.*;
|
import org.apache.ibatis.annotations.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -13,5 +12,4 @@ 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);
|
||||||
List<Post> getAllPost(@Param("userId") Long userId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import com.bao.dating.pojo.entity.Post;
|
|||||||
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
|
||||||
public interface PostMapper {
|
public interface PostMapper {
|
||||||
/**
|
/**
|
||||||
@@ -18,9 +16,9 @@ public interface PostMapper {
|
|||||||
/**
|
/**
|
||||||
* 根据ID删除动态
|
* 根据ID删除动态
|
||||||
*
|
*
|
||||||
* @param postIds 动态ID
|
* @param postId 动态ID
|
||||||
*/
|
*/
|
||||||
int deletePostByIds(@Param("postIds") List<Long> postIds);
|
void deletePostById(@Param("postId") Long postId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询动态
|
* 根据ID查询动态
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.bao.dating.mapper;
|
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.User;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface UserMapper {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据用户名查询用户
|
|
||||||
*
|
|
||||||
* @param username 用户名
|
|
||||||
* @return 用户
|
|
||||||
*/
|
|
||||||
User getByUsername(String username);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加用户
|
|
||||||
* @param user 用户对象
|
|
||||||
* @return 受影响行数
|
|
||||||
*/
|
|
||||||
Long insertUser(User user);
|
|
||||||
long getMaxUserId();
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,13 @@ package com.bao.dating.pojo.dto;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动态数据传输对象
|
* 动态数据传输对象
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PostRequestDTO implements Serializable {
|
public class PostRequestDTO {
|
||||||
private String content;
|
private String content;
|
||||||
private List<String> mediaOssKeys;
|
private List<String> mediaOssKeys;
|
||||||
private List<String> tags;
|
private List<String> tags;
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.bao.dating.pojo.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户登录数据传输对象
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class UserLoginDTO implements Serializable {
|
|
||||||
private String username;
|
|
||||||
private String password;
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.entity;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@ import java.util.List;
|
|||||||
* @author KilLze
|
* @author KilLze
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class Post implements Serializable {
|
public class Post {
|
||||||
|
|
||||||
private Long postId;
|
private Long postId;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.entity;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,7 +9,7 @@ import java.time.LocalDateTime;
|
|||||||
* @author KilLze
|
* @author KilLze
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PostFavorite implements Serializable {
|
public class PostFavorite {
|
||||||
|
|
||||||
private Long favoriteId;
|
private Long favoriteId;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.entity;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,7 +9,7 @@ import java.time.LocalDateTime;
|
|||||||
* @author KilLze
|
* @author KilLze
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PostLike implements Serializable {
|
public class PostLike {
|
||||||
private Long likeId;
|
private Long likeId;
|
||||||
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.entity;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@ import java.time.LocalDateTime;
|
|||||||
* @author KilLze
|
* @author KilLze
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class User implements Serializable {
|
public class User {
|
||||||
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
@@ -38,8 +37,4 @@ public class User implements Serializable {
|
|||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
private LocalDateTime updatedAt;
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
private String userEmail;
|
|
||||||
|
|
||||||
private String userPhone;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.vo;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,7 +9,7 @@ import java.util.List;
|
|||||||
* 修改内容查询返回数据
|
* 修改内容查询返回数据
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PostEditVO implements Serializable {
|
public class PostEditVO {
|
||||||
private Long postId;
|
private Long postId;
|
||||||
private String content;
|
private String content;
|
||||||
private List<String> mediaOssKeys;
|
private List<String> mediaOssKeys;
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.bao.dating.pojo.vo;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录返回数据
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class UserLoginVO implements Serializable {
|
|
||||||
private Long userId;
|
|
||||||
private String nickname;
|
|
||||||
private String token;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.bao.dating.service;
|
package com.bao.dating.service;
|
||||||
|
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.Comments;
|
import com.bao.dating.common.Comments;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
Result<List<Post>> getAllFavoritePost(Long userId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,18 +17,20 @@ public interface PostService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建动态
|
* 创建动态
|
||||||
|
*
|
||||||
* @param postRequestDTO 动态数据传输对象
|
* @param postRequestDTO 动态数据传输对象
|
||||||
* @return 创建的动态对象
|
* @return 创建的动态对象
|
||||||
*/
|
*/
|
||||||
Post createPost(PostRequestDTO postRequestDTO);
|
Post createPost(PostRequestDTO postRequestDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除动态
|
* 删除动态
|
||||||
* @param postIds 动态ID
|
* @param postId 动态ID
|
||||||
* @return 删除的动态对象
|
* @return 删除的动态对象
|
||||||
*/
|
*/
|
||||||
int deletePostById(List<Long> postIds);
|
void deletePostById(Long postId);
|
||||||
|
|
||||||
|
void deletePostById(Integer postId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询动态详情(用于编辑)
|
* 查询动态详情(用于编辑)
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.bao.dating.service;
|
|
||||||
|
|
||||||
import com.bao.dating.pojo.dto.UserLoginDTO;
|
|
||||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
|
||||||
|
|
||||||
public interface UserService {
|
|
||||||
/**
|
|
||||||
* 登录
|
|
||||||
* @param userLoginDTO 登录参数
|
|
||||||
* @return 登录结果
|
|
||||||
*/
|
|
||||||
UserLoginVO userLogin(UserLoginDTO userLoginDTO);
|
|
||||||
long userRegister(String userAccount, String userPassword);
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.bao.dating.service.impl;
|
package com.bao.dating.service.impl;
|
||||||
|
|
||||||
import com.bao.dating.pojo.entity.Comments;
|
import com.bao.dating.common.Comments;
|
||||||
|
|
||||||
import com.bao.dating.mapper.CommentsMapper;
|
import com.bao.dating.mapper.CommentsMapper;
|
||||||
|
|
||||||
|
|||||||
@@ -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,10 +58,4 @@ public class PostFavoriteServiceImpl implements PostFavoriteService {
|
|||||||
postMapper.decreaseFavoriteCount(postId);
|
postMapper.decreaseFavoriteCount(postId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<List<Post>> getAllFavoritePost(Long userId) {
|
|
||||||
List<Post> result = postFavoriteMapper.getAllPost(userId);
|
|
||||||
return Result.success(ResultCode.SUCCESS,"查询成功",result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.bao.dating.service.impl;
|
|||||||
|
|
||||||
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.context.UserContext;
|
|
||||||
import com.bao.dating.mapper.PostMapper;
|
import com.bao.dating.mapper.PostMapper;
|
||||||
import com.bao.dating.pojo.dto.PostRequestDTO;
|
import com.bao.dating.pojo.dto.PostRequestDTO;
|
||||||
import com.bao.dating.pojo.entity.Post;
|
import com.bao.dating.pojo.entity.Post;
|
||||||
@@ -13,13 +12,10 @@ import com.bao.dating.util.FileUtil;
|
|||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -59,11 +55,8 @@ public class PostServiceImpl implements PostService {
|
|||||||
try {
|
try {
|
||||||
// 根据文件扩展名判断文件类型
|
// 根据文件扩展名判断文件类型
|
||||||
String fileType = FileUtil.getFileType(file.getOriginalFilename());
|
String fileType = FileUtil.getFileType(file.getOriginalFilename());
|
||||||
// 创建目录
|
|
||||||
String dir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM"));
|
|
||||||
// 生成唯一文件名
|
// 生成唯一文件名
|
||||||
String newFileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
|
String fileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
|
||||||
String fileName = "post/" + dir + "/" + newFileName;
|
|
||||||
// 获取文件字节数据
|
// 获取文件字节数据
|
||||||
byte[] fileBytes = file.getBytes();
|
byte[] fileBytes = file.getBytes();
|
||||||
// 根据文件类型处理
|
// 根据文件类型处理
|
||||||
@@ -94,7 +87,6 @@ public class PostServiceImpl implements PostService {
|
|||||||
|
|
||||||
// 创建动态对象
|
// 创建动态对象
|
||||||
Post post = new Post();
|
Post post = new Post();
|
||||||
Long userId = UserContext.getUserId();
|
|
||||||
post.setUserId(userId);
|
post.setUserId(userId);
|
||||||
post.setContent(postRequestDTO.getContent());
|
post.setContent(postRequestDTO.getContent());
|
||||||
post.setTags(postRequestDTO.getTags());
|
post.setTags(postRequestDTO.getTags());
|
||||||
@@ -113,6 +105,9 @@ public class PostServiceImpl implements PostService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String textSuggestion = (String) textResult.get("suggestion");
|
String textSuggestion = (String) textResult.get("suggestion");
|
||||||
|
if ("block".equals(textSuggestion)) {
|
||||||
|
throw new RuntimeException("动态内容违规,禁止发布");
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 图片审核(如果有)
|
// 2. 图片审核(如果有)
|
||||||
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
||||||
@@ -157,50 +152,29 @@ public class PostServiceImpl implements PostService {
|
|||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除动态
|
|
||||||
*
|
|
||||||
* @param postIds 动态ID
|
|
||||||
* @return 删除的动态对象
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
public void deletePostById(Long postId) {
|
||||||
public int deletePostById(List<Long> postIds) {
|
postMapper.deletePostById(postId);
|
||||||
// 判断用户权限
|
|
||||||
Long userId = UserContext.getUserId();
|
|
||||||
|
|
||||||
// 遍历所有要删除的帖子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("无权限删除此动态");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 批量删除动态
|
|
||||||
return postMapper.deletePostByIds(postIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询动态详情(用于编辑)
|
* 删除动态
|
||||||
*
|
*
|
||||||
* @param postId 动态ID
|
* @param postId 动态ID
|
||||||
* @return
|
* @return 删除的动态对象
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
|
public void deletePostById(Integer postId) {
|
||||||
|
postMapper.deletePostById(Long.valueOf(postId));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PostEditVO getPostForEdit(Long postId) {
|
public PostEditVO getPostForEdit(Long postId) {
|
||||||
|
|
||||||
Post post = postMapper.selectById(postId);
|
Post post = postMapper.selectById(postId);
|
||||||
if (post == null) {
|
if (post == null) {
|
||||||
throw new RuntimeException("动态不存在");
|
throw new RuntimeException("动态不存在");
|
||||||
}
|
}
|
||||||
// 判断用户权限
|
|
||||||
Long userId = UserContext.getUserId();
|
|
||||||
if (post.getUserId() == null || !post.getUserId().equals(userId)){
|
|
||||||
throw new RuntimeException("无权限查看此动态");
|
|
||||||
}
|
|
||||||
PostEditVO postEditVO = new PostEditVO();
|
PostEditVO postEditVO = new PostEditVO();
|
||||||
BeanUtils.copyProperties(post, postEditVO);
|
BeanUtils.copyProperties(post, postEditVO);
|
||||||
return postEditVO;
|
return postEditVO;
|
||||||
@@ -219,11 +193,6 @@ public class PostServiceImpl implements PostService {
|
|||||||
if (post == null) {
|
if (post == null) {
|
||||||
throw new RuntimeException("动态不存在");
|
throw new RuntimeException("动态不存在");
|
||||||
}
|
}
|
||||||
// 判断用户权限
|
|
||||||
Long userId = UserContext.getUserId();
|
|
||||||
if (post.getUserId() == null || !post.getUserId().equals(userId)){
|
|
||||||
throw new RuntimeException("无权限修改此动态");
|
|
||||||
}
|
|
||||||
post.setContent(postRequestDTO.getContent());
|
post.setContent(postRequestDTO.getContent());
|
||||||
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
||||||
post.setMediaOssKeys(postRequestDTO.getMediaOssKeys());
|
post.setMediaOssKeys(postRequestDTO.getMediaOssKeys());
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
package com.bao.dating.service.impl;
|
|
||||||
|
|
||||||
import com.bao.dating.mapper.UserMapper;
|
|
||||||
import com.bao.dating.pojo.dto.UserLoginDTO;
|
|
||||||
import com.bao.dating.pojo.entity.User;
|
|
||||||
import com.bao.dating.pojo.vo.UserLoginVO;
|
|
||||||
import com.bao.dating.service.UserService;
|
|
||||||
import com.bao.dating.util.JwtUtil;
|
|
||||||
import com.bao.dating.util.MD5Util;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class UserServiceImpl implements UserService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserMapper userMapper;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserLoginVO userLogin(UserLoginDTO userLoginDTO) {
|
|
||||||
// 参数校验
|
|
||||||
if (userLoginDTO == null || userLoginDTO.getUsername() == null || userLoginDTO.getPassword() == null) {
|
|
||||||
throw new RuntimeException("用户名或密码不能为空");
|
|
||||||
}
|
|
||||||
// 查询用户
|
|
||||||
User user = userMapper.getByUsername(userLoginDTO.getUsername());
|
|
||||||
if (user == null){
|
|
||||||
throw new RuntimeException("用户不存在");
|
|
||||||
}
|
|
||||||
// 密码校验
|
|
||||||
boolean match = MD5Util.verifyWithSalt(
|
|
||||||
userLoginDTO.getPassword(),
|
|
||||||
user.getSalt(),
|
|
||||||
user.getPasswordHash()
|
|
||||||
);
|
|
||||||
if (!match){
|
|
||||||
throw new RuntimeException("密码错误");
|
|
||||||
}
|
|
||||||
// 生成token
|
|
||||||
String token = JwtUtil.generateToken(String.valueOf(user.getUserId()));
|
|
||||||
// 封装返回
|
|
||||||
UserLoginVO userLoginVO = new UserLoginVO();
|
|
||||||
userLoginVO.setUserId(user.getUserId());
|
|
||||||
userLoginVO.setNickname(user.getNickname());
|
|
||||||
userLoginVO.setToken(token);
|
|
||||||
return userLoginVO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户注册
|
|
||||||
* @param userAccount 账户名称
|
|
||||||
* @param userPassword 密码
|
|
||||||
* @return 用户id
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public long userRegister(String userAccount, String userPassword) {
|
|
||||||
//验证非空
|
|
||||||
if (userAccount.isEmpty() ||userPassword.isEmpty()){
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
//校验账户不能重复
|
|
||||||
User resultUser = userMapper.getByUsername(userAccount);
|
|
||||||
if (resultUser!=null){
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
//对密码进行加密
|
|
||||||
String encryptPassword = MD5Util.encryptWithSalt(userPassword, "yujian");
|
|
||||||
long maxUserId = userMapper.getMaxUserId();
|
|
||||||
User user = new User();
|
|
||||||
user.setUserId(maxUserId+1);
|
|
||||||
user.setUserName(userAccount);
|
|
||||||
user.setSalt("yujian");
|
|
||||||
user.setPasswordHash(encryptPassword);
|
|
||||||
user.setCreatedAt(LocalDateTime.now());
|
|
||||||
user.setUpdatedAt(LocalDateTime.now());
|
|
||||||
Long result = userMapper.insertUser(user);
|
|
||||||
if (result < 0){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return user.getUserId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -89,5 +89,3 @@ public class MD5Util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,19 +7,6 @@ spring:
|
|||||||
username: root
|
username: root
|
||||||
password: JoyeeServe2025
|
password: JoyeeServe2025
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
redis:
|
|
||||||
host: 127.0.0.1
|
|
||||||
port: 6379
|
|
||||||
password: ""
|
|
||||||
database: 0
|
|
||||||
timeout: 10000
|
|
||||||
# 连接池配置(lettuce是Spring Boot默认Redis客户端,性能更优)
|
|
||||||
lettuce:
|
|
||||||
pool:
|
|
||||||
max-active: 8 # 连接池最大连接数(默认8,可根据业务并发调整)
|
|
||||||
max-wait: -1 # 连接池最大阻塞等待时间(毫秒,-1表示无限制)
|
|
||||||
max-idle: 8 # 连接池最大空闲连接数(默认8)
|
|
||||||
min-idle: 1 # 连接池最小空闲连接数(默认0,建议设置1-4,提高连接复用率)
|
|
||||||
# 邮箱SMTP配置
|
# 邮箱SMTP配置
|
||||||
mail:
|
mail:
|
||||||
host: smtp.163.com # QQ邮箱SMTP服务器地址
|
host: smtp.163.com # QQ邮箱SMTP服务器地址
|
||||||
@@ -59,9 +46,9 @@ aliyun:
|
|||||||
secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
||||||
scenes: antispam
|
scenes: antispam
|
||||||
# 阿里云短信服务配置
|
# 阿里云短信服务配置
|
||||||
sms:
|
# sms:
|
||||||
access-key-id: LTAI5t5vpcbCZwweNHEDDDaF
|
# access-key-id: LTAI5t5vpcbCZwweNHEDDDaF
|
||||||
access-key-secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
# access-key-secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
||||||
region-id: cn-hangzhou
|
# region-id: cn-hangzhou
|
||||||
sign-name: 速通互联验证码
|
# sign-name:
|
||||||
template-code: 100001
|
# template-code: SMS_123456789
|
||||||
|
|||||||
@@ -14,8 +14,4 @@
|
|||||||
<select id="selectUserIDByPostID" resultType="java.lang.Long">
|
<select id="selectUserIDByPostID" resultType="java.lang.Long">
|
||||||
SELECT user_id FROM post_favorite WHERE post_id = #{postId}
|
SELECT user_id FROM post_favorite WHERE post_id = #{postId}
|
||||||
</select>
|
</select>
|
||||||
<!--查询用户收藏的所有动态-->
|
|
||||||
<select id="getAllPost" 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>
|
||||||
@@ -29,23 +29,8 @@
|
|||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<!--动态删除-->
|
<!--动态删除-->
|
||||||
<delete id="deletePostByIds">
|
<delete id="deletePostById">
|
||||||
DELETE FROM post WHERE post_id IN
|
DELETE FROM post WHERE post_id = #{postId}
|
||||||
<foreach item="postId" index="index" collection="postIds" separator="," open="(" close=")">
|
|
||||||
#{postId}
|
|
||||||
</foreach>
|
|
||||||
</delete>
|
|
||||||
<!--删除收藏记录-->
|
|
||||||
<delete id="1">
|
|
||||||
DELETE FROM post_favorite WHERE post_id = #{postId}
|
|
||||||
</delete>
|
|
||||||
<!--删除点赞记录-->
|
|
||||||
<delete id="2">
|
|
||||||
DELETE FROM post_like WHERE post_id = #{postId}
|
|
||||||
</delete>
|
|
||||||
<!--动态评论删除-->
|
|
||||||
<delete id="3">
|
|
||||||
DELETE FROM comments WHERE post_id = #{postId}
|
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<!--动态查询-->
|
<!--动态查询-->
|
||||||
|
|||||||
@@ -1,17 +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.UserMapper">
|
|
||||||
<insert id="insertUser" useGeneratedKeys="true" parameterType="com.bao.dating.pojo.entity.User">
|
|
||||||
insert into user(user_id,user_name,salt,password_hash,created_at,updated_at) values (#{userId},#{userName},#{salt},#{passwordHash},#{createdAt},#{updatedAt})
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<select id="getByUsername" resultType="com.bao.dating.pojo.entity.User">
|
|
||||||
SELECT * FROM user WHERE user_name = #{userName}
|
|
||||||
</select>
|
|
||||||
<select id="getMaxUserId" resultType="java.lang.Long">
|
|
||||||
SELECT IFNULL(MAX(user_id), 0) AS max_id FROM user;
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
|
||||||
@@ -73,5 +73,3 @@ public class EmailAndSmsTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user