20 Commits

Author SHA1 Message Date
lihaiyang
205f347d08 公告 2026-01-21 23:32:22 +08:00
bao
3485577874 合并分区 2025-12-23 00:36:34 +08:00
bao
dbf303c03d Merge remote-tracking branch 'refs/remotes/origin/feature-PostLike' into dev
# Conflicts:
#	src/main/java/com/bao/dating/mapper/PostMapper.java
#	src/main/java/com/bao/dating/service/PostService.java
#	src/main/java/com/bao/dating/service/impl/PostServiceImpl.java
2025-12-23 00:31:28 +08:00
KilLze
08018ede83 优化文件上传功能 2025-12-20 17:17:09 +08:00
KilLze
0149008eb0 优化文件上传功能 2025-12-20 17:13:59 +08:00
2c4504090c 完成收藏模块 2025-12-20 11:27:05 +08:00
ee708724ab 完成收藏模块 2025-12-20 11:19:56 +08:00
KilLze
0ce96c3104 优化审核,审核未通过依旧会加入数据库,并将动态状态改为2(未通过),若有嫌疑则改为1进行人工审核,通过则为0
新增动态修改功能,可以修改文本,图片,标签,修改内容若审核未通过则将状态改为2,若有嫌疑则改为1进行人工审核,通过则改为0
2025-12-19 20:21:47 +08:00
KilLze
756fbd1a31 修改遍历图片审查,实现图片全部审察 2025-12-19 02:20:02 +08:00
bao
17877753d5 Merge pull request 'feature-PostLike' (#3) from feature-PostLike into master
Reviewed-on: #3
2025-12-19 02:07:09 +08:00
bao
8d9f2285e4 测试 like123 2025-12-19 02:05:22 +08:00
bao
e5f411e342 测试 like 2025-12-19 01:58:09 +08:00
bao
80ede2ad2f Merge remote-tracking branch 'origin/feature-PostLike' into feature-PostLike
# Conflicts:
#	src/main/java/com/bao/dating/controller/PostController.java
2025-12-19 01:56:47 +08:00
bao
088e5612d3 测试 2025-12-19 01:56:15 +08:00
bao
2d3ac68886 测试 2025-12-19 01:55:23 +08:00
bao
bc3ffac3db 测试 2025-12-19 01:54:29 +08:00
KilLze
05e71576c6 添加注释 2025-12-19 01:42:40 +08:00
KilLze
c6f3cb72dd 添加注释 2025-12-19 01:41:04 +08:00
bao
0f3c9e78a6 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/test/java/com/bao/dating/DatingApplicationTests.java
2025-12-19 01:19:22 +08:00
bao
1051a7b84f 图片审核 文本审核测试类 2025-12-19 01:18:25 +08:00
29 changed files with 756 additions and 121 deletions

View File

@@ -1,4 +1,4 @@
package com.bao.dating.util; package com.bao.dating.common.aliyun;
import com.aliyun.oss.ClientException; import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS; import com.aliyun.oss.OSS;
@@ -7,12 +7,15 @@ import com.aliyun.oss.OSSException;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@Data @Data
@AllArgsConstructor
@Slf4j @Slf4j
@Component
@ConfigurationProperties(prefix = "aliyun.oss")
public class AliOssUtil { public class AliOssUtil {
private String endpoint; private String endpoint;

View File

@@ -25,7 +25,7 @@ public class GreenImageScan {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(accessKeyId) .setAccessKeyId(accessKeyId)
.setAccessKeySecret(secret); .setAccessKeySecret(secret);
// 访问的域名 // 访问的域名 - 修改为北京区域
config.endpoint = "imageaudit.cn-shanghai.aliyuncs.com"; config.endpoint = "imageaudit.cn-shanghai.aliyuncs.com";
com.aliyun.imageaudit20191230.Client client = new com.aliyun.imageaudit20191230.Client(config); com.aliyun.imageaudit20191230.Client client = new com.aliyun.imageaudit20191230.Client(config);
@@ -34,21 +34,21 @@ public class GreenImageScan {
for (String img: imageList) { for (String img: imageList) {
ScanImageRequest.ScanImageRequestTask task = new ScanImageRequest.ScanImageRequestTask(); ScanImageRequest.ScanImageRequestTask task = new ScanImageRequest.ScanImageRequestTask();
task.setImageURL(img); // 修复直接使用图片URL而不是转换为字符数组 task.setDataId(UUID.randomUUID().toString()); task.setImageURL(img);
task.setDataId(UUID.randomUUID().toString());
task.setImageTimeMillisecond(1L); task.setImageTimeMillisecond(1L);
task.setInterval(1); task.setInterval(1);
task.setMaxFrames(1); task.setMaxFrames(1);
taskList.add(task); taskList.add(task);
} }
//场景 //场景
List<String> sceneList = new ArrayList<>(); List<String> sceneList = new ArrayList<>();
// 移除了不支持的"antispam"场景,使用支持的场景 // 移除了不支持的"antispam"场景,使用支持的场景
sceneList.add("porn"); // 涉黄识别 sceneList.add("porn"); // 涉黄识别
sceneList.add("terrorism"); // 暴恐识别 sceneList.add("terrorism"); // 暴恐识别
sceneList.add("ad"); // 图片广告 sceneList.add("ad"); // 图片广告
sceneList.add("live"); // 不良场景 sceneList.add("live"); // 不良场景
sceneList.add("logo"); // logo识别 sceneList.add("logo"); // logo识别
com.aliyun.imageaudit20191230.models.ScanImageRequest scanImageRequest = new com.aliyun.imageaudit20191230.models.ScanImageRequest() com.aliyun.imageaudit20191230.models.ScanImageRequest scanImageRequest = new com.aliyun.imageaudit20191230.models.ScanImageRequest()
@@ -61,35 +61,33 @@ public class GreenImageScan {
if (scanImageResponse.getStatusCode() == 200) { if (scanImageResponse.getStatusCode() == 200) {
List<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> subResults = scanImageResponse.body.data.results.get(0).getSubResults(); List<ScanImageResponseBody.ScanImageResponseBodyDataResults> results = scanImageResponse.body.data.results;
ListIterator<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> listIterator = subResults.listIterator(); // 遍历每一张图片的审核结果
while (listIterator.hasNext()) { for (ScanImageResponseBody.ScanImageResponseBodyDataResults result : results) {
ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults item = listIterator.next(); List<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> subResults = result.getSubResults();
/* System.out.println("scene = [" + item.scene + "]");
System.out.println("suggestion = [" + item.suggestion + "]"); // 检查这张图片的所有子审核项
System.out.println("label = [" + item.label + "]");*/ for (ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults subResult : subResults) {
// 如果有任何一项未通过审核,则整个审核不通过
if (!item.suggestion.equals("pass")) { if (!subResult.suggestion.equals("pass")) {
resultMap.put("suggestion", item.suggestion); resultMap.put("suggestion", subResult.suggestion);
resultMap.put("label", item.label); resultMap.put("label", subResult.label);
return resultMap; return resultMap;
}
} }
} }
// 所有审核项都通过时返回pass结果
// 所有图片的所有审核项都通过时返回pass结果
resultMap.put("suggestion", "pass"); resultMap.put("suggestion", "pass");
resultMap.put("label", "normal"); resultMap.put("label", "normal");
return resultMap; return resultMap;
} else { } else {
/* *
* 表明请求整体处理失败,原因视具体的情况详细分析
*/
System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scanImageResponse)); System.out.println("the whole image scan request failed. response:" + JSON.toJSONString(scanImageResponse));
return null; return null;
} }
} catch (com.aliyun.tea.TeaException teaException) { } catch (com.aliyun.tea.TeaException teaException) {
// 获取整体报错信息 // 获取整体报错信息
System.out.println(com.aliyun.teautil.Common.toJSONString(teaException)); System.out.println(com.aliyun.teautil.Common.toJSONString(teaException));
@@ -100,9 +98,5 @@ public class GreenImageScan {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
/* Map<String, String> resultMap = new HashMap<>();
resultMap.put("suggestion", "pass");
return resultMap;*/
} }
} }

View File

@@ -1,26 +0,0 @@
package com.bao.dating.config;
import com.bao.dating.properties.AliOssProperties;
import com.bao.dating.util.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 配置类用于创建AliOssUtil对象
*/
@Configuration
@Slf4j
public class OssConfiguration {
@Bean
@ConditionalOnMissingBean
public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
log.info("开始创建阿里云文件上传工具类对象:{}",aliOssProperties);
return new AliOssUtil(aliOssProperties.getEndpoint(),
aliOssProperties.getAccessKeyId(),
aliOssProperties.getAccessKeySecret(),
aliOssProperties.getBucketName());
}
}

View File

@@ -0,0 +1,39 @@
package com.bao.dating.controller;
import com.bao.dating.pojo.entity.Notice;
import com.bao.dating.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 公告控制器
*/
@RestController
@RequestMapping("/notice")
public class NoticeController {
@Autowired
private NoticeService noticeService;
/**
* 查询所有公告数据
* @return 公告列表
*/
@GetMapping("/list")
public List<Notice> getNoticeList() {
return noticeService.getNoticeList();
}
/**
* 判断是否有公告数据
* @return true=有数据 false=无数据
*/
@GetMapping("/hasData")
public boolean hasNoticeData() {
List<Notice> noticeList = noticeService.getNoticeList();
return !noticeList.isEmpty();
}
}

View File

@@ -5,6 +5,7 @@ import com.bao.dating.common.Result;
import com.bao.dating.common.ResultCode; import com.bao.dating.common.ResultCode;
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;
import com.bao.dating.pojo.vo.PostEditVO;
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.*;
@@ -20,7 +21,7 @@ public class PostController {
private PostService postService; private PostService postService;
/** /**
* 上传媒体文件接口 * 上传媒体文件接口 like
* @param files 媒体文件数组 * @param files 媒体文件数组
* @return 上传后的文件URL列表 * @return 上传后的文件URL列表
*/ */
@@ -32,13 +33,14 @@ public class PostController {
/** /**
* 发布动态接口 - JSON格式请求 * 发布动态接口 - JSON格式请求
* @param postRequestDTO 动态信息 * @param postDTO 动态信息
* @param userId 用户ID
* @return 发布的动态对象 * @return 发布的动态对象
*/ */
@PostMapping(consumes = "application/json") @PostMapping(consumes = "application/json")
public Result<Post> createPostJson(@RequestBody PostRequestDTO postRequestDTO) { public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO, @RequestParam Long userId) {
// 调用 Service 层处理发布动态业务逻辑 // 调用 Service 层处理发布动态业务逻辑
Post result = postService.createPost(postRequestDTO); Post result = postService.createPost(userId, postDTO);
return Result.success(ResultCode.SUCCESS_REVIEW, "动态发布成功,等待审核。", result); return Result.success(ResultCode.SUCCESS_REVIEW, "动态发布成功,等待审核。", result);
} }
@@ -49,8 +51,31 @@ public class PostController {
* @return 删除结果 * @return 删除结果
*/ */
@DeleteMapping("/{postId}") @DeleteMapping("/{postId}")
public Result<String> deleteById(@PathVariable Integer postId){ public Result<String> deleteById(@PathVariable Long postId){
postService.deletePostById(postId); postService.deletePostById(postId);
return Result.success(ResultCode.SUCCESS_DELETE, "动态删除成功", null); return Result.success(ResultCode.SUCCESS_DELETE, "动态删除成功", null);
} }
/**
* 根据ID查询动态接口
* @param postId 动态ID
* @return 动态对象
*/
@GetMapping("/{postId}")
public Result<PostEditVO> getPostById(@PathVariable Long postId) {
PostEditVO postEditVO = postService.getPostForEdit(postId);
return Result.success(ResultCode.SUCCESS,"查询成功", postEditVO);
}
/**
* 更新动态接口
* @param postId 动态ID
* @param postRequestDTO 动态信息
* @return 更新后的动态对象
*/
@PutMapping("/{postId}")
public Result<PostEditVO> updatePost(@PathVariable Long postId, @RequestBody PostRequestDTO postRequestDTO) {
PostEditVO result = postService.updatePost(postId, postRequestDTO);
return Result.success(ResultCode.SUCCESS_REVIEW, "动态更新成功", result);
}
} }

View File

@@ -0,0 +1,34 @@
package com.bao.dating.controller;
import com.bao.dating.common.Result;
import com.bao.dating.common.ResultCode;
import com.bao.dating.pojo.entity.User;
import com.bao.dating.service.PostFavoriteService;
import com.bao.dating.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/posts")
public class PostFavoriteController {
@Autowired
private PostFavoriteService postFavoriteService;
@PostMapping("/{post_id}/favorites")
public Result<Map<String,Long>> addPostFavorite(@PathVariable("post_id")Long postId, User user){
if (user == null){
return Result.error(ResultCode.PARAM_ERROR);
}
Long userId = user.getUserId();
return postFavoriteService.postFavorite(userId,postId);
}
@DeleteMapping("/{post_id}/favorites")
public Result<?> deletePostFavorite(@PathVariable("post_id")Long postId, User user){
if (user == null){
return Result.error(ResultCode.PARAM_ERROR);
}
Long userId = user.getUserId();
return postFavoriteService.deletePostFavorite(userId, postId);
}
}

View File

@@ -17,6 +17,12 @@ public class PostLikeController {
@Autowired @Autowired
private PostLikeService postLikeService; private PostLikeService postLikeService;
/**
* 点赞接口
* @param postId
* @param body
* @return
*/
@PostMapping("/{postId}/likes") @PostMapping("/{postId}/likes")
public Result<?> likePost(@PathVariable Long postId, @RequestBody Map<String, Long> body){ public Result<?> likePost(@PathVariable Long postId, @RequestBody Map<String, Long> body){
// 从请求体中取出 user_id // 从请求体中取出 user_id
@@ -27,6 +33,11 @@ public class PostLikeController {
return postLikeService.likePost(postId,userId); return postLikeService.likePost(postId,userId);
} }
/**
* 取消点赞接口
* @param postId
* @param body
*/
@DeleteMapping("/{postId}/likes") @DeleteMapping("/{postId}/likes")
public void unlike(@PathVariable Long postId, @RequestBody Map<String, Long> body){ public void unlike(@PathVariable Long postId, @RequestBody Map<String, Long> body){
// 从请求体中获取 user_id // 从请求体中获取 user_id

View File

@@ -0,0 +1,4 @@
package com.bao.dating.controller;
public class text {
}

View File

@@ -0,0 +1,16 @@
package com.bao.dating.mapper;
import com.bao.dating.pojo.entity.Notice;
import java.util.List;
/**
* 公告Mapper接口
*/
public interface NoticeMapper {
/**
* 查询所有公告
* @return 公告列表
*/
List<Notice> selectNoticeList();
}

View File

@@ -0,0 +1,15 @@
package com.bao.dating.mapper;
import com.bao.dating.pojo.entity.PostFavorite;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface PostFavoriteMapper {
//查询当前已收藏所有用户
List<Long> selectUserIDByPostID(@Param("postId") Long postId);
int addPostFavorite(PostFavorite postFavorite);
int deletePostFavorite(@Param("postId") Long postId);
}

View File

@@ -6,11 +6,29 @@ import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface PostLikeMapper { public interface PostLikeMapper {
//根据 postId 和 userId 查询点赞记录 用于判断是否已经点赞 /**
* 根据 postId 和 userId 查询点赞记录 用于判断是否已经点赞
* @param postId
* @param userId
* @return
*/
PostLike findByPostAndUser(@Param("postId") Long postId, @Param("userId") Long userId); PostLike findByPostAndUser(@Param("postId") Long postId, @Param("userId") Long userId);
/**
* 插入点赞记录
*
* @param postLike
* @return
*/
int insert(PostLike postLike); int insert(PostLike postLike);
// 根据 postId + userId 删除点赞 /**
* 删除点赞记录
* 根据 postId + userId 删除点赞
*
* @param postId
* @param userId
* @return
*/
int deleteByPostIdAndUserId(@Param("postId") Long postId, @Param("userId") Long userId); int deleteByPostIdAndUserId(@Param("postId") Long postId, @Param("userId") Long userId);
} }

View File

@@ -2,8 +2,91 @@ package com.bao.dating.mapper;
import com.bao.dating.pojo.entity.Post; 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;
@Mapper @Mapper
public interface PostMapper { public interface PostMapper {
int insert(Post post); /**
* 插入动态
*
* @param post
*/
void insert(Post post);
/**
* 根据ID删除动态
*
* @param postId 动态ID
*/
void deletePostById(@Param("postId") Long postId);
/**
* 根据ID查询动态
*
* @param postId
* @return
*/
Post selectById(@Param("postId") Long postId);
/**
* 根据ID更新动态
*
* @param post
* @return
*/
void updateById(Post post);
/**
* 查询点赞数
*
* @param postId
* @return
*/
int selectLikeCount(Long postId);
/**
* 点赞数+1
*
* @param postId 动态ID
* @return 影响行数
*/
int increaseLikeCount(Long postId);
/**
* 点赞数-1
*
* @param postId 动态ID
* @return 影响行数
*/
int decreaseLikeCount(Long postId);
/**
* 查询当前动态属于哪个用户id
* @param postId 动态id
* @return 用户id
*/
Long selectUserIdByPostId(@Param("post_id") Long postId);
/**
* 查询点赞数
*
* @param postId
* @return
*/
int selectFavoriteCount(Long postId);
/**
* 收藏数+1
*
* @param postId 动态ID
* @return 影响行数
*/
int increaseFavoriteCount(Long postId);
/**
* 收藏数-1
*
* @param postId 动态ID
* @return 影响行数
*/
int decreaseFavoriteCount(Long postId);
} }

View File

@@ -1,14 +1,15 @@
package com.bao.dating.pojo.dto; package com.bao.dating.pojo.dto;
import lombok.Data; import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
/**
* 动态数据传输对象
*/
@Data @Data
public class PostRequestDTO { public class PostRequestDTO {
private Integer userId;
private String content; private String content;
private List<String> mediaOssKeys;
private List<String> tags; private List<String> tags;
private List<String> mediaUrls;
} }

View File

@@ -0,0 +1,40 @@
package com.bao.dating.pojo.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
/**
* 公告实体类
*/
@Data
public class Notice {
/**
* 公告ID
*/
private Long noticeId;
/**
* 公告标题
*/
private String noticeTitle;
/**
* 公告内容
*/
private String noticeContent;
/**
* 状态0正常 1关闭
*/
private String noticeStatus;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@@ -0,0 +1,19 @@
package com.bao.dating.pojo.vo;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
/**
* 修改内容查询返回数据
*/
@Data
public class PostEditVO {
private Long postId;
private String content;
private List<String> mediaOssKeys;
private List<String> tags;
private Integer isPublic;
private LocalDateTime updatedAt;
}

View File

@@ -1,15 +0,0 @@
package com.bao.dating.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "aliyun.oss")
@Data
public class AliOssProperties {
private String endpoint;
private String accessKeyId;
private String accessKeySecret;
private String bucketName;
}

View File

@@ -0,0 +1,16 @@
package com.bao.dating.service;
import com.bao.dating.pojo.entity.Notice;
import java.util.List;
/**
* 公告服务接口
*/
public interface NoticeService {
/**
* 查询所有公告
* @return 公告列表
*/
List<Notice> getNoticeList();
}

View File

@@ -0,0 +1,10 @@
package com.bao.dating.service;
import com.bao.dating.common.Result;
import java.util.Map;
public interface PostFavoriteService {
Result<Map<String,Long>> postFavorite(Long userid,Long postId);
Result<?> deletePostFavorite(Long userid,Long postId);
}

View File

@@ -11,6 +11,12 @@ public interface PostLikeService {
* @return 统一返回结果 * @return 统一返回结果
*/ */
Result<?> likePost(Long postId, Long userId); Result<?> likePost(Long postId, Long userId);
//取消点赞
/**
* 取消点赞指定的 post
*
* @param postId 帖子ID
* @param userId 用户ID
*/
void unlike(Long postId, Long userId); void unlike(Long postId, Long userId);
} }

View File

@@ -2,6 +2,7 @@ package com.bao.dating.service;
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;
import com.bao.dating.pojo.vo.PostEditVO;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
@@ -16,15 +17,39 @@ public interface PostService {
/** /**
* 创建动态 * 创建动态
* @param postRequestDTO 动态请求数据传输对象 * @param userId 用户ID
* @param postRequestDTO 动态数据传输对象
* @return 创建的动态对象 * @return 创建的动态对象
*/ */
Post createPost(PostRequestDTO postRequestDTO); Post createPost(Long userId, PostRequestDTO postRequestDTO);
/** /**
* 删除动态 * 删除动态
* @param postId 动态ID * @param postId 动态ID
* @return 删除的动态对象 * @return 删除的动态对象
*/ */
void deletePostById(Long postId);
void deletePostById(Integer postId); void deletePostById(Integer postId);
/**
* 查询动态详情(用于编辑)
* @param postId 动态ID
*/
PostEditVO getPostForEdit(Long postId);
/**
* 修改动态
* @param postId 动态ID
* @param postRequestDTO 修改的动态数据传输对象
* @return 修改后的动态对象
*/
PostEditVO updatePost(Long postId, PostRequestDTO postRequestDTO);
/**
* 查询
* @param postId 动态id
* @return 用户id
*/
Long selectUserIdByPostId(Long postId);
} }

View File

@@ -0,0 +1,18 @@
package com.bao.dating.service.impl;
import com.bao.dating.mapper.NoticeMapper;
import com.bao.dating.pojo.entity.Notice;
import com.bao.dating.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class NoticeServiceImpl implements NoticeService {
@Autowired
private NoticeMapper noticeMapper;
@Override
public List<Notice> getNoticeList() {
return noticeMapper.selectNoticeList();
}
}

View File

@@ -0,0 +1,61 @@
package com.bao.dating.service.impl;
import com.bao.dating.common.Result;
import com.bao.dating.common.ResultCode;
import com.bao.dating.mapper.PostFavoriteMapper;
import com.bao.dating.mapper.PostMapper;
import com.bao.dating.pojo.entity.PostFavorite;
import com.bao.dating.service.PostFavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class PostFavoriteServiceImpl implements PostFavoriteService {
@Autowired
private PostFavoriteMapper postFavoriteMapper;
@Autowired
private PostMapper postMapper;
@Override
@Transactional
public Result<Map<String, Long>> postFavorite(Long userid, Long postId) {
Long userId = postMapper.selectUserIdByPostId(postId);
if (userid.equals(userId)){
return Result.error(ResultCode.FORBIDDEN,"无法收藏自己发布动态");
}
List<Long> allUserId = postFavoriteMapper.selectUserIDByPostID(postId);
if (allUserId.contains(userid)){
return Result.error(ResultCode.FORBIDDEN,"已收藏");
}
PostFavorite postFavorite = new PostFavorite();
postFavorite.setPostId(postId);
postFavorite.setUserId(userid);
postFavorite.setCreatedAt(LocalDateTime.now());
postFavoriteMapper.addPostFavorite(postFavorite);
postMapper.increaseFavoriteCount(postId);
Long count = (long) postMapper.selectFavoriteCount(postId);
Map<String, Long> data = new HashMap<>();
data.put("favorite_id",postFavorite.getFavoriteId());
data.put("post_id",postId);
data.put("user_id",userid);
data.put("current_favorites_count",count);
return Result.success(ResultCode.SUCCESS_REVIEW,"收藏成功",data);
}
@Override
@Transactional
public Result<?> deletePostFavorite(Long userid, Long postId) {
List<Long> allUserId = postFavoriteMapper.selectUserIDByPostID(postId);
if (! allUserId.contains(userid)){
return Result.error(ResultCode.FORBIDDEN,"请先收藏");
}
postFavoriteMapper.deletePostFavorite(postId);
postMapper.decreaseFavoriteCount(postId);
return null;
}
}

View File

@@ -24,6 +24,13 @@ public class PostLikeServiceImpl implements PostLikeService {
/**
* 点赞指定的 post
*
* @param postId 帖子ID
* @param userId 用户ID
* @return 统一返回结果
*/
@Override @Override
@Transactional // 保证点赞 + 点赞数更新是一个事务 @Transactional // 保证点赞 + 点赞数更新是一个事务
public Result<?> likePost(Long postId, Long userId) { public Result<?> likePost(Long postId, Long userId) {
@@ -51,6 +58,12 @@ public class PostLikeServiceImpl implements PostLikeService {
return Result.success(ResultCode.SUCCESS_REVIEW,"点赞成功",data); return Result.success(ResultCode.SUCCESS_REVIEW,"点赞成功",data);
} }
/**
* 取消点赞指定的 post
*
* @param postId 帖子ID
* @param userId 用户ID
*/
@Override @Override
@Transactional @Transactional
public void unlike(Long postId, Long userId) { public void unlike(Long postId, Long userId) {

View File

@@ -5,9 +5,11 @@ import com.bao.dating.common.aliyun.GreenTextScan;
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;
import com.bao.dating.pojo.vo.PostEditVO;
import com.bao.dating.service.PostService; import com.bao.dating.service.PostService;
import com.bao.dating.util.AliOssUtil; import com.bao.dating.common.aliyun.AliOssUtil;
import com.bao.dating.util.FileUtil; import com.bao.dating.util.FileUtil;
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.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@@ -77,11 +79,23 @@ public class PostServiceImpl implements PostService {
/** /**
* 创建动态 * 创建动态
* *
* @param postRequestDTO 动态请求数据传输对象 * @param userId 用户ID
* @param postRequestDTO 动态数据传输对象
* @return 创建的动态对象 * @return 创建的动态对象
*/ */
@Override @Override
public Post createPost(PostRequestDTO postRequestDTO) { public Post createPost(Long userId, PostRequestDTO postRequestDTO) {
// 创建动态对象
Post post = new Post();
post.setUserId(userId);
post.setContent(postRequestDTO.getContent());
post.setTags(postRequestDTO.getTags());
post.setMediaOssKeys(new ArrayList<>());
// 如果有传入的媒体链接,则使用它们
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
post.setMediaOssKeys(postRequestDTO.getMediaOssKeys());
}
// 1. 文本内容审核 // 1. 文本内容审核
Map textResult; Map textResult;
@@ -97,37 +111,39 @@ public class PostServiceImpl implements PostService {
} }
// 2. 图片审核(如果有) // 2. 图片审核(如果有)
if (postRequestDTO.getMediaUrls() != null && !postRequestDTO.getMediaUrls().isEmpty()) { if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
Map imageResult; Map imageResult;
try { try {
imageResult = greenImageScan.imageScan(postRequestDTO.getMediaUrls()); imageResult = greenImageScan.imageScan(postRequestDTO.getMediaOssKeys());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
// 图片审核结果
String imageSuggestion = (String) imageResult.get("suggestion");
if ("block".equals(imageResult.get("suggestion"))) { // 根据审核结果设置状态
throw new RuntimeException("图片内容违规,禁止发布"); if ("block".equals(textSuggestion) || "block".equals(imageSuggestion)) {
// 审核未通过,允许用户修改
post.setIsPublic(2);
} else if ("review".equals(textSuggestion) || "review".equals(imageSuggestion)) {
// 待审核,需人工审核
post.setIsPublic(1);
} else {
// 审核通过
post.setIsPublic(0);
} }
}
Post post = new Post();
post.setUserId(postRequestDTO.getUserId());
post.setContent(postRequestDTO.getContent());
post.setTags(postRequestDTO.getTags());
post.setMediaOssKeys(new ArrayList<>());
// 如果有传入的媒体链接,则使用它们
if (postRequestDTO.getMediaUrls() != null && !postRequestDTO.getMediaUrls().isEmpty()) {
post.setMediaOssKeys(postRequestDTO.getMediaUrls());
}
// 4. 根据审核结果设置状态
if ("review".equals(textSuggestion)) {
// 待审核,需人工审核
post.setIsPublic(0);
} else { } else {
// 审核通过 // 只有文本内容的情况
post.setIsPublic(1); if ("block".equals(textSuggestion)) {
// 审核未通过,允许用户修改
post.setIsPublic(2);
} else if ("review".equals(textSuggestion)) {
// 待审核,需人工审核
post.setIsPublic(1);
} else {
// 审核通过
post.setIsPublic(0);
}
} }
post.setUpdatedAt(LocalDateTime.now()); post.setUpdatedAt(LocalDateTime.now());
post.setCreatedAt(LocalDateTime.now()); post.setCreatedAt(LocalDateTime.now());
@@ -137,6 +153,11 @@ public class PostServiceImpl implements PostService {
return post; return post;
} }
@Override
public void deletePostById(Long postId) {
postMapper.deletePostById(postId);
}
/** /**
* 删除动态 * 删除动态
* *
@@ -147,4 +168,103 @@ public class PostServiceImpl implements PostService {
public void deletePostById(Integer postId) { public void deletePostById(Integer postId) {
postMapper.deletePostById(postId); postMapper.deletePostById(postId);
} }
@Override
public PostEditVO getPostForEdit(Long postId) {
Post post = postMapper.selectById(postId);
if (post == null) {
throw new RuntimeException("动态不存在");
}
PostEditVO postEditVO = new PostEditVO();
BeanUtils.copyProperties(post, postEditVO);
return postEditVO;
}
/**
* 修改动态
* @param postId 动态ID
* @param postRequestDTO 修改的动态数据传输对象
* @return
*/
@Override
public PostEditVO updatePost(Long postId, PostRequestDTO postRequestDTO) {
// 查询动态
Post post = postMapper.selectById(postId);
if (post == null) {
throw new RuntimeException("动态不存在");
}
post.setContent(postRequestDTO.getContent());
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
post.setMediaOssKeys(postRequestDTO.getMediaOssKeys());
}
// 1. 文本内容审核
Map textResult;
try {
textResult = greenTextScan.greeTextScan(postRequestDTO.getContent());
} catch (Exception e) {
throw new RuntimeException("文本审核失败");
}
// 文本审核结果
String textSuggestion = (String) textResult.get("suggestion");
// 2. 图片审核(如果有)
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
Map imageResult;
try {
imageResult = greenImageScan.imageScan(postRequestDTO.getMediaOssKeys());
} catch (Exception e) {
throw new RuntimeException(e);
}
// 图片审核结果
String imageSuggestion = (String) imageResult.get("suggestion");
// 根据审核结果设置状态
if ("block".equals(textSuggestion) || "block".equals(imageSuggestion)) {
// 审核未通过,允许用户修改
post.setIsPublic(2);
} else if ("review".equals(textSuggestion) || "review".equals(imageSuggestion)) {
// 待审核,需人工审核
post.setIsPublic(1);
} else {
// 审核通过
post.setIsPublic(0);
}
} else {
// 只有文本内容的情况
if ("block".equals(textSuggestion)) {
// 审核未通过,允许用户修改
post.setIsPublic(2);
} else if ("review".equals(textSuggestion)) {
// 待审核,需人工审核
post.setIsPublic(1);
} else {
// 审核通过
post.setIsPublic(0);
}
}
post.setTags(postRequestDTO.getTags());
post.setUpdatedAt(LocalDateTime.now());
// 更新动态
postMapper.updateById(post);
// 返回动态详情
PostEditVO postEditVO = new PostEditVO();
BeanUtils.copyProperties(post, postEditVO);
return postEditVO;
}
/**
* 根据动态ID查询用户ID
*
* @param postId 动态ID
* @return 用户ID
*/
@Override
public Long selectUserIdByPostId(Long postId) {
return postMapper.selectUserIdByPostId(postId);
}
} }

View File

@@ -20,9 +20,9 @@ mybatis:
aliyun: aliyun:
oss: oss:
endpoint: oss-cn-beijing.aliyuncs.com endpoint: oss-cn-beijing.aliyuncs.com
access-key-id: LTAI5tKo9TpWH1aW6JxWm1Gp access-key-id: LTAI5t5vpcbCZwweNHEDDDaF
access-key-secret: LHk9DdHECKCwIdaIM9fkGgEuowt18W access-key-secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
bucket-name: heimato bucket-name: heimatoo
accessKeyId: LTAI5t5vpcbCZwweNHEDDDaF accessKeyId: LTAI5t5vpcbCZwweNHEDDDaF
secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
scenes: antispam scenes: antispam

View File

@@ -0,0 +1,20 @@
<?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.NoticeMapper">
<!-- 通用查询结果列 -->
<sql id="Notice_Column_List">
notice_id, notice_title, notice_content, notice_status, create_time, update_time
</sql>
<!-- 查询所有公告 -->
<select id="selectNoticeList" resultType="com.bao.dating.pojo.entity.Notice">
select
<include refid="Notice_Column_List"/>
from sys_notice
where notice_status = '0'
order by create_time desc
</select>
</mapper>

View File

@@ -0,0 +1,17 @@
<?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.PostFavoriteMapper">
<!--添加动态收藏-->
<insert id="addPostFavorite">
insert into post_favorite values (null,#{userId},#{postId},#{createdAt})
</insert>
<!--删除动态收藏-->
<delete id="deletePostFavorite">
delete from post_favorite where post_id = #{postId}
</delete>
<!--查询当前已收藏所有用户-->
<select id="selectUserIDByPostID" resultType="java.lang.Long">
SELECT user_id FROM post_favorite WHERE post_id = #{postId}
</select>
</mapper>

View File

@@ -3,7 +3,8 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bao.dating.mapper.PostMapper"> <mapper namespace="com.bao.dating.mapper.PostMapper">
<!-- 动态添加 -->
<!--动态添加-->
<insert id="insert" useGeneratedKeys="true" keyProperty="postId"> <insert id="insert" useGeneratedKeys="true" keyProperty="postId">
INSERT INTO post INSERT INTO post
(user_id, content, (user_id, content,
@@ -26,21 +27,91 @@
</if> </if>
#{isPublic}, 0, 0, #{createdAt}, #{updatedAt}) #{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
</insert> </insert>
<!--动态删除-->
<delete id="deletePostById">
DELETE FROM post WHERE post_id = #{postId}
</delete>
<!--动态查询-->
<resultMap id="PostResultMap" type="com.bao.dating.pojo.entity.Post">
<id property="postId" column="post_id"/>
<result property="userId" column="user_id"/>
<result property="content" column="content"/>
<result property="mediaOssKeys" column="media_oss_keys" typeHandler="com.bao.dating.handler.ListToVarcharTypeHandler"/>
<result property="tags" column="tags" typeHandler="com.bao.dating.handler.ListToVarcharTypeHandler"/>
<result property="location" column="location"/>
<result property="isPublic" column="is_public"/>
<result property="likeCount" column="like_count"/>
<result property="favoriteCount" column="favorite_count"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
</resultMap>
<select id="selectById" resultMap="PostResultMap">
SELECT
post_id,
user_id,
content,
media_oss_keys,
tags,
location,
is_public,
like_count,
favorite_count,
created_at,
updated_at
FROM post WHERE post_id = #{postId}
</select>
<!--动态更新-->
<update id="updateById">
UPDATE post
<set>
<if test="content != null">
content = #{content},
</if>
<if test="tags != null">
tags = #{tags, typeHandler=com.bao.dating.handler.ListToVarcharTypeHandler},
</if>
<if test="mediaOssKeys != null">
media_oss_keys =
#{mediaOssKeys, typeHandler=com.bao.dating.handler.ListToVarcharTypeHandler},
</if>
is_public = #{isPublic},
updated_at = #{updatedAt}
</set>
WHERE post_id = #{postId}
</update>
<!--增加点赞数量--> <!--增加点赞数量-->
<update id="increaseLikeCount"> <update id="increaseLikeCount">
update dating.post set like_count = like_count + 1 where post.post_id = #{postId} update dating.post set like_count = like_count + 1 where post.post_id = #{postId}
</update> </update>
<!--减少点赞数量-->
<update id="decreaseLikeCount"> <update id="decreaseLikeCount">
update dating.post set like_count= like_count - 1 where post.post_id = #{postId} update dating.post set like_count= like_count - 1 where post.post_id = #{postId}
</update> </update>
<!--增加收藏数量-->
<update id="increaseFavoriteCount">
update post set favorite_count = favorite_count + 1 where post_id = #{post_id}
</update>
<!--减少收藏数量-->
<update id="decreaseFavoriteCount">
update post set favorite_count = favorite_count - 1 where post_id = #{post_id}
</update>
<!--查询点赞当前数量--> <!--查询点赞当前数量-->
<select id="selectLikeCount" resultType="java.lang.Integer"> <select id="selectLikeCount" resultType="java.lang.Integer">
select dating.post.like_count from dating.post where post.post_id = #{postId} select dating.post.like_count from dating.post where post.post_id = #{postId}
</select> </select>
<!--查询当前动态的用户id-->
<delete id="deletePostById" parameterType="int"> <select id="selectUserIdByPostId" resultType="java.lang.Long">
DELETE FROM post WHERE post_id = #{postId} SELECT user_id FROM post WHERE post_id = #{post_id}
</delete> </select>
<!--查询当前收藏数量-->
<select id="selectFavoriteCount" resultType="java.lang.Integer">
select dating.post.favorite_count from dating.post where post.post_id = #{postId}
</select>
</mapper> </mapper>

View File

@@ -31,10 +31,7 @@ public class DatingApplicationTests {
public void testUploadAndScanImageFromUrl() { public void testUploadAndScanImageFromUrl() {
try { try {
// 阿里oss图片url // 阿里oss图片url
String imageUrl = "https://heimato.oss-cn-beijing.aliyuncs.com/75d067b3-8605-494a-a839-b0a9d32c993a.jpg" + String imageUrl = "https://heimatoo.oss-cn-beijing.aliyuncs.com/ScreenShot_2025-12-01_135624_491.png?x-oss-credential=LTAI5t5vpcbCZwweNHEDDDaF%2F20251222%2Fcn-beijing%2Foss%2Faliyun_v4_request&x-oss-date=20251222T092951Z&x-oss-expires=32400&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-signature=c06742a4e530c7a095aa4c376c3c88e605dddcd232d0ee07da76988e5ccb7727";
"?x-oss-credential=LTAI5tKo9TpWH1aW6JxWm1Gp%2F20251218%2Fcn-beijing%2Foss%2Faliyun_v4_request" +
"&x-oss-date=20251218T164128Z&x-oss-expires=32400&x-oss-signature-version=OSS4-HMAC-SHA256" +
"&x-oss-signature=e9c46381a5d33e5c541fe2e838ff3ebeeb5dbc51f792ed31ae992aa0a4109d8a";
// 将图片URL添加到列表中进行检测 // 将图片URL添加到列表中进行检测
List<String> imageUrls = Arrays.asList(imageUrl); List<String> imageUrls = Arrays.asList(imageUrl);