Merge remote-tracking branch 'origin/master'
# Conflicts: # src/test/java/com/bao/dating/DatingApplicationTests.java
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
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.pojo.dto.PostRequestDTO;
|
||||
import com.bao.dating.pojo.entity.Post;
|
||||
@@ -14,6 +16,7 @@ import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -27,6 +30,12 @@ public class PostServiceImpl implements PostService {
|
||||
@Autowired
|
||||
private AliOssUtil ossUtil;
|
||||
|
||||
@Autowired
|
||||
private GreenTextScan greenTextScan;
|
||||
|
||||
@Autowired
|
||||
private GreenImageScan greenImageScan;
|
||||
|
||||
@Autowired
|
||||
private PostMapper postMapper;
|
||||
|
||||
@@ -73,6 +82,34 @@ public class PostServiceImpl implements PostService {
|
||||
*/
|
||||
@Override
|
||||
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.setUserId(Long.valueOf(postRequestDTO.getUserId()));
|
||||
post.setContent(postRequestDTO.getContent());
|
||||
@@ -84,7 +121,14 @@ public class PostServiceImpl implements PostService {
|
||||
post.setMediaOssKeys(postRequestDTO.getMediaUrls());
|
||||
}
|
||||
|
||||
post.setIsPublic(0);
|
||||
// 4. 根据审核结果设置状态
|
||||
if ("review".equals(textSuggestion)) {
|
||||
// 待审核,需人工审核
|
||||
post.setIsPublic(0);
|
||||
} else {
|
||||
// 审核通过
|
||||
post.setIsPublic(1);
|
||||
}
|
||||
post.setUpdatedAt(LocalDateTime.now());
|
||||
post.setCreatedAt(LocalDateTime.now());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user