mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-08 13:00:45 +08:00
Merge branch 'pr-971' of github.com:nagisa77/OpenIsle into pr-971
This commit is contained in:
@@ -3,6 +3,7 @@ package com.openisle.repository;
|
|||||||
import com.openisle.model.PointHistory;
|
import com.openisle.model.PointHistory;
|
||||||
import com.openisle.model.User;
|
import com.openisle.model.User;
|
||||||
import com.openisle.model.Comment;
|
import com.openisle.model.Comment;
|
||||||
|
import com.openisle.model.Post;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -14,6 +15,8 @@ public interface PointHistoryRepository extends JpaRepository<PointHistory, Long
|
|||||||
long countByUser(User user);
|
long countByUser(User user);
|
||||||
|
|
||||||
List<PointHistory> findByUserAndCreatedAtAfterOrderByCreatedAtDesc(User user, LocalDateTime createdAt);
|
List<PointHistory> findByUserAndCreatedAtAfterOrderByCreatedAtDesc(User user, LocalDateTime createdAt);
|
||||||
|
|
||||||
List<PointHistory> findByComment(Comment comment);
|
List<PointHistory> findByComment(Comment comment);
|
||||||
|
|
||||||
|
List<PointHistory> findByPost(Post post);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import com.openisle.repository.CommentRepository;
|
|||||||
import com.openisle.repository.ReactionRepository;
|
import com.openisle.repository.ReactionRepository;
|
||||||
import com.openisle.repository.PostSubscriptionRepository;
|
import com.openisle.repository.PostSubscriptionRepository;
|
||||||
import com.openisle.repository.NotificationRepository;
|
import com.openisle.repository.NotificationRepository;
|
||||||
|
import com.openisle.repository.PointHistoryRepository;
|
||||||
import com.openisle.repository.PollVoteRepository;
|
import com.openisle.repository.PollVoteRepository;
|
||||||
import com.openisle.exception.RateLimitException;
|
import com.openisle.exception.RateLimitException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -67,6 +68,7 @@ public class PostService {
|
|||||||
private final ReactionRepository reactionRepository;
|
private final ReactionRepository reactionRepository;
|
||||||
private final PostSubscriptionRepository postSubscriptionRepository;
|
private final PostSubscriptionRepository postSubscriptionRepository;
|
||||||
private final NotificationRepository notificationRepository;
|
private final NotificationRepository notificationRepository;
|
||||||
|
private final PointHistoryRepository pointHistoryRepository;
|
||||||
private final PostReadService postReadService;
|
private final PostReadService postReadService;
|
||||||
private final ImageUploader imageUploader;
|
private final ImageUploader imageUploader;
|
||||||
private final TaskScheduler taskScheduler;
|
private final TaskScheduler taskScheduler;
|
||||||
@@ -95,6 +97,7 @@ public class PostService {
|
|||||||
ReactionRepository reactionRepository,
|
ReactionRepository reactionRepository,
|
||||||
PostSubscriptionRepository postSubscriptionRepository,
|
PostSubscriptionRepository postSubscriptionRepository,
|
||||||
NotificationRepository notificationRepository,
|
NotificationRepository notificationRepository,
|
||||||
|
PointHistoryRepository pointHistoryRepository,
|
||||||
PostReadService postReadService,
|
PostReadService postReadService,
|
||||||
ImageUploader imageUploader,
|
ImageUploader imageUploader,
|
||||||
TaskScheduler taskScheduler,
|
TaskScheduler taskScheduler,
|
||||||
@@ -118,6 +121,7 @@ public class PostService {
|
|||||||
this.reactionRepository = reactionRepository;
|
this.reactionRepository = reactionRepository;
|
||||||
this.postSubscriptionRepository = postSubscriptionRepository;
|
this.postSubscriptionRepository = postSubscriptionRepository;
|
||||||
this.notificationRepository = notificationRepository;
|
this.notificationRepository = notificationRepository;
|
||||||
|
this.pointHistoryRepository = pointHistoryRepository;
|
||||||
this.postReadService = postReadService;
|
this.postReadService = postReadService;
|
||||||
this.imageUploader = imageUploader;
|
this.imageUploader = imageUploader;
|
||||||
this.taskScheduler = taskScheduler;
|
this.taskScheduler = taskScheduler;
|
||||||
@@ -860,6 +864,18 @@ public class PostService {
|
|||||||
postSubscriptionRepository.findByPost(post).forEach(postSubscriptionRepository::delete);
|
postSubscriptionRepository.findByPost(post).forEach(postSubscriptionRepository::delete);
|
||||||
notificationRepository.deleteAll(notificationRepository.findByPost(post));
|
notificationRepository.deleteAll(notificationRepository.findByPost(post));
|
||||||
postReadService.deleteByPost(post);
|
postReadService.deleteByPost(post);
|
||||||
|
List<PointHistory> pointHistories = pointHistoryRepository.findByPost(post);
|
||||||
|
Set<User> usersToRecalculate = pointHistories.stream()
|
||||||
|
.map(PointHistory::getUser)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
pointHistoryRepository.deleteAll(pointHistories);
|
||||||
|
if (!usersToRecalculate.isEmpty()) {
|
||||||
|
for (User affectedUser : usersToRecalculate) {
|
||||||
|
int newPoints = pointService.recalculateUserPoints(affectedUser);
|
||||||
|
affectedUser.setPoint(newPoints);
|
||||||
|
}
|
||||||
|
userRepository.saveAll(usersToRecalculate);
|
||||||
|
}
|
||||||
imageUploader.removeReferences(imageUploader.extractUrls(post.getContent()));
|
imageUploader.removeReferences(imageUploader.extractUrls(post.getContent()));
|
||||||
if (post instanceof LotteryPost lp) {
|
if (post instanceof LotteryPost lp) {
|
||||||
ScheduledFuture<?> future = scheduledFinalizations.remove(lp.getId());
|
ScheduledFuture<?> future = scheduledFinalizations.remove(lp.getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user