15 Commits

Author SHA1 Message Date
bao
4a2aff888a 配置redis
(cherry picked from commit ae0cca5437)
2025-12-27 19:37:01 +08:00
bao
0b0959fa80 增加User项目结构
(cherry picked from commit c329eaef79)
2025-12-27 19:28:19 +08:00
KilLze
4401a8a44a 用户密码登录功能完成 2025-12-27 19:25:03 +08:00
KilLze
55c7c9a03a 增加User项目结构 2025-12-27 17:37:35 +08:00
KilLze
a6716e32b6 增加登录返回数据实体类 2025-12-27 16:58:34 +08:00
KilLze
8506fbb7e4 将评论表实体类放入规范位置(李海洋赶紧修你的实体类) 2025-12-27 16:45:48 +08:00
KilLze
64bfb08257 将评论表实体类放入规范位置(李海洋赶紧修你的实体类) 2025-12-26 16:23:58 +08:00
KilLze
71dbb6fc82 在实体类中添加Serializable接口(其实无所谓) 2025-12-26 16:22:53 +08:00
KilLze
b6ac177148 Merge remote-tracking branch 'upstream/master' 2025-12-25 18:38:57 +08:00
KilLze
df463f2a52 修bug(这git怎么这么难用啊😡😡😡) 2025-12-25 18:37:20 +08:00
KilLze
34663e8e84 整合 2025-12-25 18:23:04 +08:00
KilLze
176e133a57 将删除动态优化为批量删除动态 2025-12-25 18:00:56 +08:00
KilLze
fd3a38efb5 为上传的文件分配目录动态的图片
动态图片存放在post/下的/yyyy/MM目录中
2025-12-25 17:54:52 +08:00
KilLze
7d99b30d73 Merge remote-tracking branch 'upstream/master' 2025-12-25 17:28:21 +08:00
KilLze
370e81f3c6 修改遍历图片审查,实现图片全部审察 2025-12-19 02:08:48 +08:00
28 changed files with 246 additions and 47 deletions

View File

@@ -11,6 +11,8 @@ 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
@@ -30,7 +32,6 @@ public class AliOssUtil {
* @return 完整的文件访问URL
*/
public String upload(byte[] bytes, String objectName) {
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

View File

@@ -147,3 +147,5 @@ public class SmsUtil {
}
}

View File

@@ -1,6 +1,6 @@
package com.bao.dating.controller;
import com.bao.dating.common.Comments;
import com.bao.dating.pojo.entity.Comments;
import com.bao.dating.common.Result;
import com.bao.dating.common.ResultCode;
import com.bao.dating.service.CommentsService;

View File

@@ -45,15 +45,15 @@ public class PostController {
}
/**
* 删除动态
* 批量删除动态
*
* @param postId 动态ID
* @param postIds 动态ID
* @return 删除结果
*/
@DeleteMapping("/{postId}")
public Result<String> deleteById(@PathVariable Long postId){
postService.deletePostById(postId);
return Result.success(ResultCode.SUCCESS_DELETE, "动态删除成功", null);
@DeleteMapping
public Result<String> deleteById(@RequestParam List<Long> postIds){
int deletedCount = postService.deletePostById(postIds);
return Result.success(ResultCode.SUCCESS_DELETE, deletedCount > 0 ? "成功删除" : "删除失败,该动态不存在", null);
}
/**

View File

@@ -0,0 +1,27 @@
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);
}
}

View File

@@ -1,8 +1,7 @@
package com.bao.dating.mapper;
import com.bao.dating.common.Comments;
import com.bao.dating.common.Post;
import com.bao.dating.pojo.entity.Comments;
import org.apache.ibatis.annotations.*;
import java.util.List;

View File

@@ -4,6 +4,8 @@ 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 {
/**
@@ -16,9 +18,9 @@ public interface PostMapper {
/**
* 根据ID删除动态
*
* @param postId 动态ID
* @param postIds 动态ID
*/
void deletePostById(@Param("postId") Long postId);
int deletePostByIds(@Param("postIds") List<Long> postIds);
/**
* 根据ID查询动态

View File

@@ -0,0 +1,16 @@
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);
}

View File

@@ -2,13 +2,14 @@ package com.bao.dating.pojo.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 动态数据传输对象
*/
@Data
public class PostRequestDTO {
public class PostRequestDTO implements Serializable {
private String content;
private List<String> mediaOssKeys;
private List<String> tags;

View File

@@ -0,0 +1,14 @@
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;
}

View File

@@ -1,8 +1,9 @@
package com.bao.dating.common;
package com.bao.dating.pojo.entity;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@@ -10,7 +11,7 @@ import java.time.LocalDateTime;
* 评论表
*/
@Data
public class Comments {
public class Comments implements Serializable {
private Long comment_id; // 评论ID
private String content; // 评论内容
private Long user_id; // 评论人ID

View File

@@ -2,6 +2,7 @@ package com.bao.dating.pojo.entity;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
@@ -10,7 +11,7 @@ import java.util.List;
* @author KilLze
*/
@Data
public class Post {
public class Post implements Serializable {
private Long postId;

View File

@@ -2,6 +2,7 @@ package com.bao.dating.pojo.entity;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
@@ -9,7 +10,7 @@ import java.time.LocalDateTime;
* @author KilLze
*/
@Data
public class PostFavorite {
public class PostFavorite implements Serializable {
private Long favoriteId;

View File

@@ -2,6 +2,7 @@ package com.bao.dating.pojo.entity;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
@@ -9,7 +10,7 @@ import java.time.LocalDateTime;
* @author KilLze
*/
@Data
public class PostLike {
public class PostLike implements Serializable {
private Long likeId;
private Long userId;

View File

@@ -2,6 +2,7 @@ package com.bao.dating.pojo.entity;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -10,7 +11,7 @@ import java.time.LocalDateTime;
* @author KilLze
*/
@Data
public class User {
public class User implements Serializable {
private Long userId;
@@ -37,4 +38,8 @@ public class User {
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private String userEmail;
private String userPhone;
}

View File

@@ -2,6 +2,7 @@ package com.bao.dating.pojo.vo;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
@@ -9,7 +10,7 @@ import java.util.List;
* 修改内容查询返回数据
*/
@Data
public class PostEditVO {
public class PostEditVO implements Serializable {
private Long postId;
private String content;
private List<String> mediaOssKeys;

View File

@@ -0,0 +1,14 @@
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;
}

View File

@@ -1,7 +1,7 @@
package com.bao.dating.service;
import com.bao.dating.common.Comments;
import com.bao.dating.pojo.entity.Comments;
import java.util.List;

View File

@@ -24,13 +24,12 @@ public interface PostService {
Post createPost(Long userId, PostRequestDTO postRequestDTO);
/**
* 删除动态
* @param postId 动态ID
* 批量删除动态
* @param postIds 动态ID
* @return 删除的动态对象
*/
void deletePostById(Long postId);
int deletePostById(List<Long> postIds);
void deletePostById(Integer postId);
/**
* 查询动态详情(用于编辑)

View File

@@ -0,0 +1,13 @@
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);
}

View File

@@ -1,6 +1,6 @@
package com.bao.dating.service.impl;
import com.bao.dating.common.Comments;
import com.bao.dating.pojo.entity.Comments;
import com.bao.dating.mapper.CommentsMapper;

View File

@@ -12,10 +12,13 @@ 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;
@@ -55,8 +58,11 @@ public class PostServiceImpl implements PostService {
try {
// 根据文件扩展名判断文件类型
String fileType = FileUtil.getFileType(file.getOriginalFilename());
// 创建目录
String dir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM"));
// 生成唯一文件名
String fileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
String newFileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
String fileName = "post/" + dir + "/" + newFileName;
// 获取文件字节数据
byte[] fileBytes = file.getBytes();
// 根据文件类型处理
@@ -106,9 +112,6 @@ 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()) {
@@ -153,22 +156,25 @@ public class PostServiceImpl implements PostService {
return post;
}
@Override
public void deletePostById(Long postId) {
postMapper.deletePostById(postId);
}
/**
* 删除动态
* 批量删除动态
*
* @param postId 动态ID
* @param postIds 动态ID
* @return 删除的动态对象
*/
@Override
public void deletePostById(Integer postId) {
postMapper.deletePostById(Long.valueOf(postId));
@Transactional(rollbackFor = Exception.class)
public int deletePostById(List<Long> postIds) {
// 批量删除动态
return postMapper.deletePostByIds(postIds);
}
/**
* 查询动态详情(用于编辑)
*
* @param postId 动态ID
* @return
*/
@Override
public PostEditVO getPostForEdit(Long postId) {

View File

@@ -0,0 +1,52 @@
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.util.HashMap;
import java.util.Map;
@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;
}
}

View File

@@ -89,3 +89,5 @@ public class MD5Util {
}
}

View File

@@ -7,6 +7,19 @@ 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服务器地址
@@ -46,9 +59,9 @@ aliyun:
secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
scenes: antispam
# 阿里云短信服务配置
# sms:
# access-key-id: LTAI5t5vpcbCZwweNHEDDDaF
# access-key-secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
# region-id: cn-hangzhou
# sign-name:
# template-code: SMS_123456789
sms:
access-key-id: LTAI5t5vpcbCZwweNHEDDDaF
access-key-secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
region-id: cn-hangzhou
sign-name: 速通互联验证码
template-code: 100001

View File

@@ -29,8 +29,23 @@
</insert>
<!--动态删除-->
<delete id="deletePostById">
DELETE FROM post WHERE post_id = #{postId}
<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>
<!--动态查询-->

View File

@@ -0,0 +1,11 @@
<?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">
<select id="getByUsername" resultType="com.bao.dating.pojo.entity.User">
SELECT * FROM user WHERE user_name = #{userName}
</select>
</mapper>

View File

@@ -73,3 +73,5 @@ public class EmailAndSmsTest {
}