Compare commits
9 Commits
feature-Po
...
feature-us
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c4504090c | |||
| ee708724ab | |||
| 17877753d5 | |||
| 8d9f2285e4 | |||
| e5f411e342 | |||
| 80ede2ad2f | |||
| 088e5612d3 | |||
| 2d3ac68886 | |||
| bc3ffac3db |
@@ -61,24 +61,19 @@ public class GreenImageScan {
|
||||
|
||||
if (scanImageResponse.getStatusCode() == 200) {
|
||||
|
||||
List<ScanImageResponseBody.ScanImageResponseBodyDataResults> results = scanImageResponse.body.data.results;
|
||||
List<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> subResults = scanImageResponse.body.data.results.get(0).getSubResults();
|
||||
|
||||
// 遍历每一张图片的审核结果
|
||||
for (ScanImageResponseBody.ScanImageResponseBodyDataResults result : results) {
|
||||
List<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> subResults = result.getSubResults();
|
||||
|
||||
// 检查这张图片的所有子审核项
|
||||
for (ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults subResult : subResults) {
|
||||
// 如果有任何一项未通过审核,则整个审核不通过
|
||||
if (!subResult.suggestion.equals("pass")) {
|
||||
resultMap.put("suggestion", subResult.suggestion);
|
||||
resultMap.put("label", subResult.label);
|
||||
return resultMap;
|
||||
}
|
||||
ListIterator<ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults> listIterator = subResults.listIterator();
|
||||
while (listIterator.hasNext()) {
|
||||
ScanImageResponseBody.ScanImageResponseBodyDataResultsSubResults item = listIterator.next();
|
||||
|
||||
if (!item.suggestion.equals("pass")) {
|
||||
resultMap.put("suggestion", item.suggestion);
|
||||
resultMap.put("label", item.label);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
// 所有图片的所有审核项都通过时,返回pass结果
|
||||
// 所有审核项都通过时,返回pass结果
|
||||
resultMap.put("suggestion", "pass");
|
||||
resultMap.put("label", "normal");
|
||||
return resultMap;
|
||||
@@ -99,4 +94,4 @@ public class GreenImageScan {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
src/main/java/com/bao/dating/config/OssConfiguration.java
Normal file
26
src/main/java/com/bao/dating/config/OssConfiguration.java
Normal file
@@ -0,0 +1,26 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import com.bao.dating.common.Result;
|
||||
import com.bao.dating.common.ResultCode;
|
||||
import com.bao.dating.pojo.dto.PostRequestDTO;
|
||||
import com.bao.dating.pojo.entity.Post;
|
||||
import com.bao.dating.pojo.vo.PostEditVO;
|
||||
import com.bao.dating.service.PostService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -21,7 +20,7 @@ public class PostController {
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 上传媒体文件接口
|
||||
* 上传媒体文件接口 like
|
||||
* @param files 媒体文件数组
|
||||
* @return 上传后的文件URL列表
|
||||
*/
|
||||
@@ -33,49 +32,25 @@ public class PostController {
|
||||
|
||||
/**
|
||||
* 发布动态接口 - JSON格式请求
|
||||
* @param postDTO 动态信息
|
||||
* @param userId 用户ID
|
||||
* @param postRequestDTO 动态信息
|
||||
* @return 发布的动态对象
|
||||
*/
|
||||
@PostMapping(consumes = "application/json")
|
||||
public Result<Post> createPostJson(@RequestBody PostRequestDTO postDTO, @RequestParam Long userId) {
|
||||
public Result<Post> createPostJson(@RequestBody PostRequestDTO postRequestDTO) {
|
||||
// 调用 Service 层处理发布动态业务逻辑
|
||||
Post result = postService.createPost(userId, postDTO);
|
||||
Post result = postService.createPost(postRequestDTO);
|
||||
return Result.success(ResultCode.SUCCESS_REVIEW, "动态发布成功,等待审核。", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除动态
|
||||
* 删除动态
|
||||
*
|
||||
* @param postIds 动态ID
|
||||
* @param postId 动态ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping
|
||||
public Result<String> deleteById(@RequestParam List<Long> postIds){
|
||||
postService.deletePostById(postIds);
|
||||
@DeleteMapping("/{postId}")
|
||||
public Result<String> deleteById(@PathVariable Integer postId){
|
||||
postService.deletePostById(postId);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -4,39 +4,23 @@ 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 {
|
||||
/**
|
||||
* 插入动态
|
||||
*
|
||||
* @param post
|
||||
* @param post 动态对象
|
||||
* @return 插入的行数
|
||||
*/
|
||||
void insert(Post post);
|
||||
int insert(Post post);
|
||||
|
||||
/**
|
||||
* 根据ID删除动态
|
||||
*
|
||||
* @param postIds 动态ID
|
||||
* @param postId 动态ID
|
||||
* @return 删除的行数
|
||||
*/
|
||||
void deletePostByIds(@Param("postIds") List<Long> postIds);
|
||||
|
||||
/**
|
||||
* 根据ID查询动态
|
||||
*
|
||||
* @param postId
|
||||
* @return
|
||||
*/
|
||||
Post selectById(@Param("postId") Long postId);
|
||||
|
||||
/**
|
||||
* 根据ID更新动态
|
||||
*
|
||||
* @param post
|
||||
* @return
|
||||
*/
|
||||
void updateById(Post post);
|
||||
int deletePostById(Integer postId);
|
||||
|
||||
/**
|
||||
* 查询点赞数
|
||||
@@ -61,4 +45,34 @@ public interface PostMapper {
|
||||
* @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);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.bao.dating.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 动态数据传输对象
|
||||
*/
|
||||
@Data
|
||||
public class PostRequestDTO {
|
||||
private Long userId;
|
||||
private String content;
|
||||
private List<String> mediaOssKeys;
|
||||
private List<String> tags;
|
||||
private List<String> mediaUrls;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.bao.dating.service;
|
||||
|
||||
import com.bao.dating.pojo.dto.PostRequestDTO;
|
||||
import com.bao.dating.pojo.entity.Post;
|
||||
import com.bao.dating.pojo.vo.PostEditVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,30 +16,22 @@ public interface PostService {
|
||||
|
||||
/**
|
||||
* 创建动态
|
||||
* @param userId 用户ID
|
||||
* @param postRequestDTO 动态数据传输对象
|
||||
* @param postRequestDTO 动态请求数据传输对象
|
||||
* @return 创建的动态对象
|
||||
*/
|
||||
Post createPost(Long userId, PostRequestDTO postRequestDTO);
|
||||
Post createPost(PostRequestDTO postRequestDTO);
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
* @param postIds 动态ID
|
||||
* @param postId 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
void deletePostById(List<Long> postIds);
|
||||
void deletePostById(Integer postId);
|
||||
|
||||
/**
|
||||
* 查询动态详情(用于编辑)
|
||||
* @param postId 动态ID
|
||||
* 查询
|
||||
* @param postId 动态id
|
||||
* @return 用户id
|
||||
*/
|
||||
PostEditVO getPostForEdit(Long postId);
|
||||
|
||||
/**
|
||||
* 修改动态
|
||||
* @param postId 动态ID
|
||||
* @param postRequestDTO 修改的动态数据传输对象
|
||||
* @return 修改后的动态对象
|
||||
*/
|
||||
PostEditVO updatePost(Long postId, PostRequestDTO postRequestDTO);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -5,20 +5,15 @@ 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;
|
||||
import com.bao.dating.pojo.vo.PostEditVO;
|
||||
import com.bao.dating.service.PostService;
|
||||
import com.bao.dating.common.aliyun.AliOssUtil;
|
||||
import com.bao.dating.util.AliOssUtil;
|
||||
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;
|
||||
@@ -58,11 +53,8 @@ public class PostServiceImpl implements PostService {
|
||||
try {
|
||||
// 根据文件扩展名判断文件类型
|
||||
String fileType = FileUtil.getFileType(file.getOriginalFilename());
|
||||
// 创建目录
|
||||
String dir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM"));
|
||||
// 生成唯一文件名
|
||||
String newFileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
|
||||
String fileName = "post/" + dir + "/" + newFileName;
|
||||
String fileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
|
||||
// 获取文件字节数据
|
||||
byte[] fileBytes = file.getBytes();
|
||||
// 根据文件类型处理
|
||||
@@ -85,23 +77,11 @@ public class PostServiceImpl implements PostService {
|
||||
/**
|
||||
* 创建动态
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param postRequestDTO 动态数据传输对象
|
||||
* @param postRequestDTO 动态请求数据传输对象
|
||||
* @return 创建的动态对象
|
||||
*/
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
public Post createPost(PostRequestDTO postRequestDTO) {
|
||||
|
||||
// 1. 文本内容审核
|
||||
Map textResult;
|
||||
@@ -110,45 +90,45 @@ public class PostServiceImpl implements PostService {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("文本审核失败");
|
||||
}
|
||||
// 文本审核结果
|
||||
|
||||
String textSuggestion = (String) textResult.get("suggestion");
|
||||
if ("block".equals(textSuggestion)) {
|
||||
throw new RuntimeException("动态内容违规,禁止发布");
|
||||
}
|
||||
|
||||
// 2. 图片审核(如果有)
|
||||
if (postRequestDTO.getMediaOssKeys() != null && !postRequestDTO.getMediaOssKeys().isEmpty()) {
|
||||
if (postRequestDTO.getMediaUrls() != null && !postRequestDTO.getMediaUrls().isEmpty()) {
|
||||
Map imageResult;
|
||||
try {
|
||||
imageResult = greenImageScan.imageScan(postRequestDTO.getMediaOssKeys());
|
||||
imageResult = greenImageScan.imageScan(postRequestDTO.getMediaUrls());
|
||||
} 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);
|
||||
|
||||
if ("block".equals(imageResult.get("suggestion"))) {
|
||||
throw new RuntimeException("图片内容违规,禁止发布");
|
||||
}
|
||||
}
|
||||
|
||||
Post post = new Post();
|
||||
post.setUserId(Long.valueOf(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 {
|
||||
// 审核通过
|
||||
post.setIsPublic(1);
|
||||
}
|
||||
post.setUpdatedAt(LocalDateTime.now());
|
||||
post.setCreatedAt(LocalDateTime.now());
|
||||
|
||||
@@ -160,101 +140,22 @@ public class PostServiceImpl implements PostService {
|
||||
/**
|
||||
* 删除动态
|
||||
*
|
||||
* @param postIds 动态ID
|
||||
* @param postId 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deletePostById(List<Long> postIds) {
|
||||
// 批量删除动态
|
||||
postMapper.deletePostByIds(postIds);
|
||||
}
|
||||
|
||||
@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;
|
||||
public void deletePostById(Integer postId) {
|
||||
postMapper.deletePostById(postId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改动态
|
||||
* @param postId 动态ID
|
||||
* @param postRequestDTO 修改的动态数据传输对象
|
||||
* 查询用户id
|
||||
* @param postId 动态id
|
||||
* @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;
|
||||
public Long selectUserIdByPostId(Long postId) {
|
||||
return postMapper.selectUserIdByPostId(postId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bao.dating.common.aliyun;
|
||||
package com.bao.dating.util;
|
||||
|
||||
import com.aliyun.oss.ClientException;
|
||||
import com.aliyun.oss.OSS;
|
||||
@@ -7,17 +7,12 @@ import com.aliyun.oss.OSSException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "aliyun.oss")
|
||||
public class AliOssUtil {
|
||||
|
||||
private String endpoint;
|
||||
@@ -32,6 +27,7 @@ public class AliOssUtil {
|
||||
* @return 完整的文件访问URL
|
||||
*/
|
||||
public String upload(byte[] bytes, String objectName) {
|
||||
|
||||
// 创建OSSClient实例。
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
28
src/main/resources/application.yml
Normal file
28
src/main/resources/application.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://110.42.41.177:3306/dating?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: JoyeeServe2025
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
# MyBatis 配置
|
||||
mybatis:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
type-aliases-package: com.bao.dating.pojo
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
# 阿里云 OSS 配置
|
||||
aliyun:
|
||||
oss:
|
||||
endpoint: oss-cn-beijing.aliyuncs.com
|
||||
access-key-id: LTAI5tKo9TpWH1aW6JxWm1Gp
|
||||
access-key-secret: LHk9DdHECKCwIdaIM9fkGgEuowt18W
|
||||
bucket-name: heimato
|
||||
accessKeyId: LTAI5t5vpcbCZwweNHEDDDaF
|
||||
secret: bBHBAPiCqGyVBHUv07348wsHXkKqrk
|
||||
scenes: antispam
|
||||
@@ -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>
|
||||
@@ -29,74 +29,9 @@
|
||||
</insert>
|
||||
|
||||
<!--动态删除-->
|
||||
<delete id="deletePostByIds">
|
||||
DELETE FROM post WHERE post_id IN
|
||||
<foreach item="postId" index="index" collection="postIds" separator="," open="(" close=")">
|
||||
#{postId}
|
||||
</foreach>
|
||||
<delete id="deletePostById" parameterType="int">
|
||||
DELETE FROM post WHERE post_id = #{postId}
|
||||
</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>
|
||||
|
||||
<!--动态查询-->
|
||||
<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">
|
||||
@@ -107,10 +42,26 @@
|
||||
<update id="decreaseLikeCount">
|
||||
update dating.post set like_count= like_count - 1 where post.post_id = #{postId}
|
||||
</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 dating.post.like_count from dating.post where post.post_id = #{postId}
|
||||
</select>
|
||||
<!--查询当前动态的用户id-->
|
||||
<select id="selectUserIdByPostId" resultType="java.lang.Long">
|
||||
SELECT user_id FROM post WHERE post_id = #{post_id}
|
||||
</select>
|
||||
<!--查询当前收藏数量-->
|
||||
<select id="selectFavoriteCount" resultType="java.lang.Integer">
|
||||
select dating.post.favorite_count from dating.post where post.post_id = #{postId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user