Compare commits
3 Commits
ae0cca5437
...
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 java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@@ -11,7 +10,7 @@ import java.time.LocalDateTime;
|
||||
* 评论表
|
||||
*/
|
||||
@Data
|
||||
public class Comments implements Serializable {
|
||||
public class Comments {
|
||||
private Long comment_id; // 评论ID
|
||||
private String content; // 评论内容
|
||||
private Long user_id; // 评论人ID
|
||||
@@ -11,8 +11,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@@ -32,6 +30,7 @@ public class AliOssUtil {
|
||||
* @return 完整的文件访问URL
|
||||
*/
|
||||
public String upload(byte[] bytes, String objectName) {
|
||||
|
||||
// 创建OSSClient实例。
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
|
||||
@@ -147,5 +147,3 @@ public class SmsUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.ResultCode;
|
||||
import com.bao.dating.service.CommentsService;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PostController {
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 上传媒体文件接口 like
|
||||
* 上传媒体文件接口
|
||||
* @param files 媒体文件数组
|
||||
* @return 上传后的文件URL列表
|
||||
*/
|
||||
@@ -33,27 +33,26 @@ public class PostController {
|
||||
|
||||
/**
|
||||
* 发布动态接口 - JSON格式请求
|
||||
* @param postDTO 动态信息
|
||||
* @param userId 用户ID
|
||||
* @param postRequestDTO 动态信息
|
||||
* @return 发布的动态对象
|
||||
*/
|
||||
@PostMapping(consumes = "application/json")
|
||||
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO, @RequestParam Long userId) {
|
||||
public Result<Post> createPostJson(@RequestBody PostRequestDTO postRequestDTO) {
|
||||
// 调用 Service 层处理发布动态业务逻辑
|
||||
Post result = postService.createPost(userId, postDTO);
|
||||
Post result = postService.createPost(postRequestDTO);
|
||||
return Result.success(ResultCode.SUCCESS_REVIEW, "动态发布成功,等待审核。", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除动态
|
||||
* 删除动态
|
||||
*
|
||||
* @param postIds 动态ID
|
||||
* @param postId 动态ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping
|
||||
public Result<String> deleteById(@RequestParam List<Long> postIds){
|
||||
int deletedCount = postService.deletePostById(postIds);
|
||||
return Result.success(ResultCode.SUCCESS_DELETE, deletedCount > 0 ? "成功删除" : "删除失败,该动态不存在", null);
|
||||
@DeleteMapping("/{postId}")
|
||||
public Result<String> deleteById(@PathVariable Integer postId){
|
||||
postService.deletePostById(postId);
|
||||
return Result.success(ResultCode.SUCCESS_DELETE, "动态删除成功", null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.bao.dating.controller;
|
||||
|
||||
import com.bao.dating.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
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 java.util.List;
|
||||
|
||||
@@ -4,8 +4,6 @@ import com.bao.dating.pojo.entity.Post;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PostMapper {
|
||||
/**
|
||||
@@ -18,9 +16,9 @@ public interface PostMapper {
|
||||
/**
|
||||
* 根据ID删除动态
|
||||
*
|
||||
* @param postIds 动态ID
|
||||
* @param postId 动态ID
|
||||
*/
|
||||
int deletePostByIds(@Param("postIds") List<Long> postIds);
|
||||
void deletePostById(@Param("postId") Long postId);
|
||||
|
||||
/**
|
||||
* 根据ID查询动态
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.bao.dating.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
}
|
||||
@@ -2,14 +2,13 @@ package com.bao.dating.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 动态数据传输对象
|
||||
*/
|
||||
@Data
|
||||
public class PostRequestDTO implements Serializable {
|
||||
public class PostRequestDTO {
|
||||
private String content;
|
||||
private List<String> mediaOssKeys;
|
||||
private List<String> tags;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +10,7 @@ import java.util.List;
|
||||
* @author KilLze
|
||||
*/
|
||||
@Data
|
||||
public class Post implements Serializable {
|
||||
public class Post {
|
||||
|
||||
private Long postId;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -10,7 +9,7 @@ import java.time.LocalDateTime;
|
||||
* @author KilLze
|
||||
*/
|
||||
@Data
|
||||
public class PostFavorite implements Serializable {
|
||||
public class PostFavorite {
|
||||
|
||||
private Long favoriteId;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -10,7 +9,7 @@ import java.time.LocalDateTime;
|
||||
* @author KilLze
|
||||
*/
|
||||
@Data
|
||||
public class PostLike implements Serializable {
|
||||
public class PostLike {
|
||||
private Long likeId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -11,7 +10,7 @@ import java.time.LocalDateTime;
|
||||
* @author KilLze
|
||||
*/
|
||||
@Data
|
||||
public class User implements Serializable {
|
||||
public class User {
|
||||
|
||||
private Long userId;
|
||||
|
||||
@@ -38,8 +37,4 @@ public class User implements Serializable {
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
private String userEmail;
|
||||
|
||||
private String userPhone;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.bao.dating.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,7 +9,7 @@ import java.util.List;
|
||||
* 修改内容查询返回数据
|
||||
*/
|
||||
@Data
|
||||
public class PostEditVO implements Serializable {
|
||||
public class PostEditVO {
|
||||
private Long postId;
|
||||
private String content;
|
||||
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;
|
||||
|
||||
|
||||
import com.bao.dating.pojo.entity.Comments;
|
||||
import com.bao.dating.common.Comments;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -17,19 +17,20 @@ public interface PostService {
|
||||
|
||||
/**
|
||||
* 创建动态
|
||||
* @param userId 用户ID
|
||||
*
|
||||
* @param postRequestDTO 动态数据传输对象
|
||||
* @return 创建的动态对象
|
||||
*/
|
||||
Post createPost(Long userId, PostRequestDTO postRequestDTO);
|
||||
Post createPost(PostRequestDTO postRequestDTO);
|
||||
|
||||
/**
|
||||
* 批量删除动态
|
||||
* @param postIds 动态ID
|
||||
* 删除动态
|
||||
* @param postId 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
int deletePostById(List<Long> postIds);
|
||||
void deletePostById(Long postId);
|
||||
|
||||
void deletePostById(Integer postId);
|
||||
|
||||
/**
|
||||
* 查询动态详情(用于编辑)
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.bao.dating.service;
|
||||
|
||||
public interface UserService {
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
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;
|
||||
|
||||
|
||||
@@ -12,13 +12,10 @@ 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.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -58,11 +55,8 @@ public class PostServiceImpl implements PostService {
|
||||
try {
|
||||
// 根据文件扩展名判断文件类型
|
||||
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 = "post/" + dir + "/" + newFileName;
|
||||
String fileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
|
||||
// 获取文件字节数据
|
||||
byte[] fileBytes = file.getBytes();
|
||||
// 根据文件类型处理
|
||||
@@ -85,12 +79,11 @@ public class PostServiceImpl implements PostService {
|
||||
/**
|
||||
* 创建动态
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param postRequestDTO 动态数据传输对象
|
||||
* @return 创建的动态对象
|
||||
*/
|
||||
@Override
|
||||
public Post createPost(Long userId, PostRequestDTO postRequestDTO) {
|
||||
public Post createPost(PostRequestDTO postRequestDTO) {
|
||||
|
||||
// 创建动态对象
|
||||
Post post = new Post();
|
||||
@@ -112,6 +105,9 @@ public class PostServiceImpl implements PostService {
|
||||
}
|
||||
|
||||
String textSuggestion = (String) textResult.get("suggestion");
|
||||
if ("block".equals(textSuggestion)) {
|
||||
throw new RuntimeException("动态内容违规,禁止发布");
|
||||
}
|
||||
|
||||
// 2. 图片审核(如果有)
|
||||
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
||||
@@ -156,25 +152,22 @@ public class PostServiceImpl implements PostService {
|
||||
return post;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除动态
|
||||
*
|
||||
* @param postIds 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deletePostById(List<Long> postIds) {
|
||||
// 批量删除动态
|
||||
return postMapper.deletePostByIds(postIds);
|
||||
public void deletePostById(Long postId) {
|
||||
postMapper.deletePostById(postId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询动态详情(用于编辑)
|
||||
* 删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @return
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
@Override
|
||||
public void deletePostById(Integer postId) {
|
||||
postMapper.deletePostById(Long.valueOf(postId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PostEditVO getPostForEdit(Long postId) {
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.bao.dating.service.impl;
|
||||
|
||||
import com.bao.dating.mapper.UserMapper;
|
||||
import com.bao.dating.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
}
|
||||
@@ -89,5 +89,3 @@ public class MD5Util {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,19 +7,6 @@ spring:
|
||||
username: root
|
||||
password: JoyeeServe2025
|
||||
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配置
|
||||
mail:
|
||||
host: smtp.163.com # QQ邮箱SMTP服务器地址
|
||||
@@ -59,9 +46,9 @@ aliyun:
|
||||
secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
||||
scenes: antispam
|
||||
# 阿里云短信服务配置
|
||||
sms:
|
||||
access-key-id: LTAI5t5vpcbCZwweNHEDDDaF
|
||||
access-key-secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
||||
region-id: cn-hangzhou
|
||||
sign-name: 速通互联验证码
|
||||
template-code: 100001
|
||||
# sms:
|
||||
# access-key-id: LTAI5t5vpcbCZwweNHEDDDaF
|
||||
# access-key-secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
||||
# region-id: cn-hangzhou
|
||||
# sign-name:
|
||||
# template-code: SMS_123456789
|
||||
|
||||
@@ -29,23 +29,8 @@
|
||||
</insert>
|
||||
|
||||
<!--动态删除-->
|
||||
<delete id="deletePostByIds">
|
||||
DELETE FROM post WHERE post_id IN
|
||||
<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 id="deletePostById">
|
||||
DELETE FROM post WHERE post_id = #{postId}
|
||||
</delete>
|
||||
|
||||
<!--动态查询-->
|
||||
|
||||
@@ -1,8 +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">
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -73,5 +73,3 @@ public class EmailAndSmsTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user