|
@@ -56,7 +56,7 @@ public class StorePlatformDiscussionServiceImpl extends ServiceImpl<StorePlatfor
|
|
|
* 删除策略: 1-只删除当前讨论, 2-级联删除所有回复
|
|
* 删除策略: 1-只删除当前讨论, 2-级联删除所有回复
|
|
|
* 默认为 2 (级联删除)
|
|
* 默认为 2 (级联删除)
|
|
|
*/
|
|
*/
|
|
|
- private Integer defaultDeleteStrategy = 2;
|
|
|
|
|
|
|
+ private Integer defaultDeleteStrategy = STRATEGY_CASCADE;
|
|
|
|
|
|
|
|
public static final int STRATEGY_SINGLE = 1;
|
|
public static final int STRATEGY_SINGLE = 1;
|
|
|
public static final int STRATEGY_CASCADE = 2;
|
|
public static final int STRATEGY_CASCADE = 2;
|
|
@@ -187,6 +187,11 @@ public class StorePlatformDiscussionServiceImpl extends ServiceImpl<StorePlatfor
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean postTopic(StorePlatformDiscussion discussion) {
|
|
public boolean postTopic(StorePlatformDiscussion discussion) {
|
|
|
|
|
+ Integer currentUserId = LoginUserUtil.getCurrentUserId();
|
|
|
|
|
+ if (currentUserId == null) {
|
|
|
|
|
+ throw new RuntimeException("请先登录再发表讨论");
|
|
|
|
|
+ }
|
|
|
|
|
+ discussion.setUserId(currentUserId);
|
|
|
discussion.setParentId(0);
|
|
discussion.setParentId(0);
|
|
|
discussion.setRootId(0);
|
|
discussion.setRootId(0);
|
|
|
discussion.setLikeCount(0); // 初始化点赞数
|
|
discussion.setLikeCount(0); // 初始化点赞数
|
|
@@ -202,6 +207,12 @@ public class StorePlatformDiscussionServiceImpl extends ServiceImpl<StorePlatfor
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean postReply(StorePlatformDiscussion discussion) {
|
|
public boolean postReply(StorePlatformDiscussion discussion) {
|
|
|
|
|
+ Integer currentUserId = LoginUserUtil.getCurrentUserId();
|
|
|
|
|
+ if (currentUserId == null) {
|
|
|
|
|
+ throw new RuntimeException("请先登录再发表回复");
|
|
|
|
|
+ }
|
|
|
|
|
+ discussion.setUserId(currentUserId);
|
|
|
|
|
+
|
|
|
if (discussion.getParentId() == null || discussion.getParentId() == 0) {
|
|
if (discussion.getParentId() == null || discussion.getParentId() == 0) {
|
|
|
throw new RuntimeException("回复必须指定父级讨论 ID");
|
|
throw new RuntimeException("回复必须指定父级讨论 ID");
|
|
|
}
|
|
}
|
|
@@ -260,6 +271,12 @@ public class StorePlatformDiscussionServiceImpl extends ServiceImpl<StorePlatfor
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 权限校验:只能删除自己发表的讨论
|
|
|
|
|
+ Integer currentUserId = LoginUserUtil.getCurrentUserId();
|
|
|
|
|
+ if (currentUserId == null || !currentUserId.equals(discussion.getUserId())) {
|
|
|
|
|
+ throw new RuntimeException("无权删除他人发表的讨论");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 使用配置中的默认策略
|
|
// 使用配置中的默认策略
|
|
|
int finalStrategy = discussionConfig.getDefaultDeleteStrategy();
|
|
int finalStrategy = discussionConfig.getDefaultDeleteStrategy();
|
|
|
|
|
|