6 Commits

Author SHA1 Message Date
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
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
6 changed files with 51 additions and 28 deletions

View File

@@ -11,6 +11,8 @@ 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
@@ -30,7 +32,6 @@ 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);

View File

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

View File

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

View File

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

View File

@@ -12,10 +12,13 @@ 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;
@@ -55,8 +58,11 @@ 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 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(); byte[] fileBytes = file.getBytes();
// 根据文件类型处理 // 根据文件类型处理
@@ -106,9 +112,6 @@ 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()) {
@@ -153,22 +156,25 @@ public class PostServiceImpl implements PostService {
return post; return post;
} }
@Override
public void deletePostById(Long postId) {
postMapper.deletePostById(postId);
}
/** /**
* 删除动态 * 批量删除动态
* *
* @param postId 动态ID * @param postIds 动态ID
* @return 删除的动态对象 * @return 删除的动态对象
*/ */
@Override @Override
public void deletePostById(Integer postId) { @Transactional(rollbackFor = Exception.class)
postMapper.deletePostById(Long.valueOf(postId)); public int deletePostById(List<Long> postIds) {
// 批量删除动态
return postMapper.deletePostByIds(postIds);
} }
/**
* 查询动态详情(用于编辑)
*
* @param postId 动态ID
* @return
*/
@Override @Override
public PostEditVO getPostForEdit(Long postId) { public PostEditVO getPostForEdit(Long postId) {

View File

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