Compare commits
15 Commits
3daecbdfc2
...
feature-us
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c4504090c | |||
| ee708724ab | |||
| 17877753d5 | |||
| 8d9f2285e4 | |||
| e5f411e342 | |||
| 80ede2ad2f | |||
| 088e5612d3 | |||
| 2d3ac68886 | |||
| bc3ffac3db | |||
|
|
05e71576c6 | ||
|
|
c6f3cb72dd | ||
| 0f3c9e78a6 | |||
| 1051a7b84f | |||
|
|
1d838ec57e | ||
|
|
8cb0830f8d |
14
pom.xml
14
pom.xml
@@ -50,6 +50,14 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JUnit Platform Launcher for resolving junit-platform-launcher:1.8.2 issue -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-launcher</artifactId>
|
||||||
|
<version>1.8.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
@@ -95,12 +103,6 @@
|
|||||||
<version>0.2.8</version>
|
<version>0.2.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.aliyun</groupId>
|
|
||||||
<artifactId>teautil</artifactId>
|
|
||||||
<version>0.2.16</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -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()
|
||||||
@@ -66,9 +66,6 @@ public class GreenImageScan {
|
|||||||
ListIterator<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> listIterator = subResults.listIterator();
|
ListIterator<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> listIterator = subResults.listIterator();
|
||||||
while (listIterator.hasNext()) {
|
while (listIterator.hasNext()) {
|
||||||
ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults item = listIterator.next();
|
ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults item = listIterator.next();
|
||||||
/* System.out.println("scene = [" + item.scene + "]");
|
|
||||||
System.out.println("suggestion = [" + item.suggestion + "]");
|
|
||||||
System.out.println("label = [" + item.label + "]");*/
|
|
||||||
|
|
||||||
if (!item.suggestion.equals("pass")) {
|
if (!item.suggestion.equals("pass")) {
|
||||||
resultMap.put("suggestion", item.suggestion);
|
resultMap.put("suggestion", item.suggestion);
|
||||||
@@ -82,14 +79,10 @@ public class GreenImageScan {
|
|||||||
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 +93,5 @@ public class GreenImageScan {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map<String, String> resultMap = new HashMap<>();
|
|
||||||
resultMap.put("suggestion", "pass");
|
|
||||||
return resultMap;*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class PostController {
|
|||||||
private PostService postService;
|
private PostService postService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传媒体文件接口
|
* 上传媒体文件接口 like
|
||||||
* @param files 媒体文件数组
|
* @param files 媒体文件数组
|
||||||
* @return 上传后的文件URL列表
|
* @return 上传后的文件URL列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/main/java/com/bao/dating/controller/text.java
Normal file
4
src/main/java/com/bao/dating/controller/text.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package com.bao.dating.controller;
|
||||||
|
|
||||||
|
public class text {
|
||||||
|
}
|
||||||
15
src/main/java/com/bao/dating/mapper/PostFavoriteMapper.java
Normal file
15
src/main/java/com/bao/dating/mapper/PostFavoriteMapper.java
Normal 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);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,77 @@ 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 {
|
||||||
|
/**
|
||||||
|
* 插入动态
|
||||||
|
*
|
||||||
|
* @param post 动态对象
|
||||||
|
* @return 插入的行数
|
||||||
|
*/
|
||||||
int insert(Post post);
|
int insert(Post post);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID删除动态
|
||||||
|
*
|
||||||
|
* @param postId 动态ID
|
||||||
|
* @return 删除的行数
|
||||||
|
*/
|
||||||
|
int deletePostById(Integer postId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询点赞数
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class PostRequestDTO {
|
public class PostRequestDTO {
|
||||||
private Integer userId;
|
private Long userId;
|
||||||
private String content;
|
private String content;
|
||||||
private List<String> tags;
|
private List<String> tags;
|
||||||
private List<String> mediaUrls;
|
private List<String> mediaUrls;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,11 @@ public interface PostService {
|
|||||||
* @return 删除的动态对象
|
* @return 删除的动态对象
|
||||||
*/
|
*/
|
||||||
void deletePostById(Integer postId);
|
void deletePostById(Integer postId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
* @param postId 动态id
|
||||||
|
* @return 用户id
|
||||||
|
*/
|
||||||
|
Long selectUserIdByPostId(Long postId);
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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) {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.bao.dating.service.impl;
|
package com.bao.dating.service.impl;
|
||||||
|
|
||||||
|
import com.bao.dating.common.aliyun.GreenImageScan;
|
||||||
|
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;
|
||||||
@@ -14,6 +16,7 @@ import java.io.IOException;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,6 +30,12 @@ public class PostServiceImpl implements PostService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AliOssUtil ossUtil;
|
private AliOssUtil ossUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GreenTextScan greenTextScan;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GreenImageScan greenImageScan;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PostMapper postMapper;
|
private PostMapper postMapper;
|
||||||
|
|
||||||
@@ -73,8 +82,36 @@ public class PostServiceImpl implements PostService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Post createPost(PostRequestDTO postRequestDTO) {
|
public Post createPost(PostRequestDTO postRequestDTO) {
|
||||||
|
|
||||||
|
// 1. 文本内容审核
|
||||||
|
Map textResult;
|
||||||
|
try {
|
||||||
|
textResult = greenTextScan.greeTextScan(postRequestDTO.getContent());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("文本审核失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
String textSuggestion = (String) textResult.get("suggestion");
|
||||||
|
if ("block".equals(textSuggestion)) {
|
||||||
|
throw new RuntimeException("动态内容违规,禁止发布");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 图片审核(如果有)
|
||||||
|
if (postRequestDTO.getMediaUrls() != null && !postRequestDTO.getMediaUrls().isEmpty()) {
|
||||||
|
Map imageResult;
|
||||||
|
try {
|
||||||
|
imageResult = greenImageScan.imageScan(postRequestDTO.getMediaUrls());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("block".equals(imageResult.get("suggestion"))) {
|
||||||
|
throw new RuntimeException("图片内容违规,禁止发布");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Post post = new Post();
|
Post post = new Post();
|
||||||
post.setUserId(postRequestDTO.getUserId());
|
post.setUserId(Long.valueOf(postRequestDTO.getUserId()));
|
||||||
post.setContent(postRequestDTO.getContent());
|
post.setContent(postRequestDTO.getContent());
|
||||||
post.setTags(postRequestDTO.getTags());
|
post.setTags(postRequestDTO.getTags());
|
||||||
post.setMediaOssKeys(new ArrayList<>());
|
post.setMediaOssKeys(new ArrayList<>());
|
||||||
@@ -84,7 +121,14 @@ public class PostServiceImpl implements PostService {
|
|||||||
post.setMediaOssKeys(postRequestDTO.getMediaUrls());
|
post.setMediaOssKeys(postRequestDTO.getMediaUrls());
|
||||||
}
|
}
|
||||||
|
|
||||||
post.setIsPublic(0);
|
// 4. 根据审核结果设置状态
|
||||||
|
if ("review".equals(textSuggestion)) {
|
||||||
|
// 待审核,需人工审核
|
||||||
|
post.setIsPublic(0);
|
||||||
|
} else {
|
||||||
|
// 审核通过
|
||||||
|
post.setIsPublic(1);
|
||||||
|
}
|
||||||
post.setUpdatedAt(LocalDateTime.now());
|
post.setUpdatedAt(LocalDateTime.now());
|
||||||
post.setCreatedAt(LocalDateTime.now());
|
post.setCreatedAt(LocalDateTime.now());
|
||||||
|
|
||||||
@@ -103,4 +147,15 @@ public class PostServiceImpl implements PostService {
|
|||||||
public void deletePostById(Integer postId) {
|
public void deletePostById(Integer postId) {
|
||||||
postMapper.deletePostById(postId);
|
postMapper.deletePostById(postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户id
|
||||||
|
* @param postId 动态id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long selectUserIdByPostId(Long postId) {
|
||||||
|
return postMapper.selectUserIdByPostId(postId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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>
|
||||||
@@ -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,41 @@
|
|||||||
</if>
|
</if>
|
||||||
#{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
|
#{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<!--动态删除-->
|
||||||
|
<delete id="deletePostById" parameterType="int">
|
||||||
|
DELETE FROM post WHERE post_id = #{postId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
<!--增加点赞数量-->
|
<!--增加点赞数量-->
|
||||||
<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>
|
||||||
@@ -31,7 +31,10 @@ public class DatingApplicationTests {
|
|||||||
public void testUploadAndScanImageFromUrl() {
|
public void testUploadAndScanImageFromUrl() {
|
||||||
try {
|
try {
|
||||||
// 阿里oss图片url
|
// 阿里oss图片url
|
||||||
String imageUrl = "https://heimato.oss-cn-beijing.aliyuncs.com/9d1325d1-6e5a-426c-8081-306e7d3f6386.jpg?x-oss-credential=LTAI5tKo9TpWH1aW6JxWm1Gp%2F20251218%2Fcn-beijing%2Foss%2Faliyun_v4_request&x-oss-date=20251218T132839Z&x-oss-expires=3600&x-oss-signature-version=OSS4-HMAC-SHA256&x-oss-signature=a1b6b5a8e8728012093e9c38c6fb6f4487e7adf983db63c412848d3dbb0697b8";
|
String imageUrl = "https://heimato.oss-cn-beijing.aliyuncs.com/75d067b3-8605-494a-a839-b0a9d32c993a.jpg" +
|
||||||
|
"?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);
|
||||||
|
|||||||
Reference in New Issue
Block a user