Compare commits
2 Commits
7c0bfbc1de
...
feature-Po
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03bd1474b5 | ||
|
|
5d3d85a325 |
@@ -11,6 +11,8 @@ 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
|
||||
@Slf4j
|
||||
@@ -30,7 +32,6 @@ public class AliOssUtil {
|
||||
* @return 完整的文件访问URL
|
||||
*/
|
||||
public String upload(byte[] bytes, String objectName) {
|
||||
|
||||
// 创建OSSClient实例。
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
|
||||
@@ -45,14 +45,14 @@ public class PostController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
* 批量删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @param postIds 动态ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/{postId}")
|
||||
public Result<String> deleteById(@PathVariable Long postId){
|
||||
postService.deletePostById(postId);
|
||||
@DeleteMapping
|
||||
public Result<String> deleteById(@RequestParam List<Long> postIds){
|
||||
postService.deletePostById(postIds);
|
||||
return Result.success(ResultCode.SUCCESS_DELETE, "动态删除成功", null);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ 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 {
|
||||
/**
|
||||
@@ -16,9 +18,9 @@ public interface PostMapper {
|
||||
/**
|
||||
* 根据ID删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @param postIds 动态ID
|
||||
*/
|
||||
void deletePostById(@Param("postId") Long postId);
|
||||
void deletePostByIds(@Param("postIds") List<Long> postIds);
|
||||
|
||||
/**
|
||||
* 根据ID查询动态
|
||||
|
||||
@@ -25,10 +25,10 @@ public interface PostService {
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
* @param postId 动态ID
|
||||
* @param postIds 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
void deletePostById(Long postId);
|
||||
void deletePostById(List<Long> postIds);
|
||||
|
||||
/**
|
||||
* 查询动态详情(用于编辑)
|
||||
|
||||
@@ -12,10 +12,13 @@ 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;
|
||||
@@ -55,8 +58,11 @@ public class PostServiceImpl implements PostService {
|
||||
try {
|
||||
// 根据文件扩展名判断文件类型
|
||||
String fileType = FileUtil.getFileType(file.getOriginalFilename());
|
||||
// 创建目录
|
||||
String dir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM"));
|
||||
// 生成唯一文件名
|
||||
String fileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
|
||||
String newFileName = UUID.randomUUID().toString() + "." + FileUtil.getFileExtension(file.getOriginalFilename());
|
||||
String fileName = "post/" + dir + "/" + newFileName;
|
||||
// 获取文件字节数据
|
||||
byte[] fileBytes = file.getBytes();
|
||||
// 根据文件类型处理
|
||||
@@ -154,12 +160,14 @@ public class PostServiceImpl implements PostService {
|
||||
/**
|
||||
* 删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @param postIds 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
@Override
|
||||
public void deletePostById(Long postId) {
|
||||
postMapper.deletePostById(postId);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deletePostById(List<Long> postIds) {
|
||||
// 批量删除动态
|
||||
postMapper.deletePostByIds(postIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
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
|
||||
@@ -29,8 +29,23 @@
|
||||
</insert>
|
||||
|
||||
<!--动态删除-->
|
||||
<delete id="deletePostById">
|
||||
DELETE FROM post WHERE post_id = #{postId}
|
||||
<delete id="deletePostByIds">
|
||||
DELETE FROM post WHERE post_id IN
|
||||
<foreach item="postId" index="index" collection="postIds" separator="," open="(" close=")">
|
||||
#{postId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<!--删除收藏记录-->
|
||||
<delete id="1">
|
||||
DELETE FROM post_favorite WHERE post_id = #{postId}
|
||||
</delete>
|
||||
<!--删除点赞记录-->
|
||||
<delete id="2">
|
||||
DELETE FROM post_like WHERE post_id = #{postId}
|
||||
</delete>
|
||||
<!--动态评论删除-->
|
||||
<delete id="3">
|
||||
DELETE FROM comments WHERE post_id = #{postId}
|
||||
</delete>
|
||||
|
||||
<!--动态查询-->
|
||||
|
||||
Reference in New Issue
Block a user