Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”€ :: 이벀트 μ‹œκ°„ 뢈일치 문제 ν•΄κ²° #197

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.time.ZoneId;
import java.util.List;
import java.util.Objects;


@ServiceWithTransaction
@RequiredArgsConstructor
@Slf4j
public class ChangeEventStatusServiceImpl implements ChangeEventStatusService {

private final EventRepository eventRepository;
private final ZoneId zoneId = ZoneId.of("Asia/Seoul");

public void execute() {
log.info("===================이벀트 μŠ€μΌ€μ€„λŸ¬ μ‹œμž‘===================");
Expand All @@ -34,8 +32,10 @@ public void execute() {
}

private void saveChangePast(List<Event> nowEvents) {
for (Event event: nowEvents) {
if (Objects.equals(event.getStarted_at(), LocalDate.now())) {
LocalDate now = LocalDate.now(zoneId);

for (Event event : nowEvents) {
if (Objects.equals(event.getStarted_at(), now)) {
event.changeStatus(Status.PAST);
eventRepository.save(event);
log.info("EventId: {}, status: NOW -> PAST", event.getId());
Expand All @@ -45,21 +45,17 @@ private void saveChangePast(List<Event> nowEvents) {
}

private void saveChangeNow(List<Event> pendingEvents) {
try {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date now = formatter.parse(String.valueOf(LocalDate.now()));
LocalDate now = LocalDate.now(zoneId);

for (Event event: pendingEvents) {
Date endDate = formatter.parse(String.valueOf(event.getEnded_at()));
for (Event event : pendingEvents) {
LocalDate endDate = event.getEnded_at();

if (now.after(endDate)) {
event.changeStatus(Status.NOW);
eventRepository.save(event);
log.info("EventId: {}, status: PENDING -> NOW", event.getId());
}
if (now.isAfter(endDate)) {
event.changeStatus(Status.NOW);
eventRepository.save(event);
log.info("EventId: {}, status: PENDING -> NOW", event.getId());
}
log.info("===================EventPendingToNow End===================");
} catch (ParseException e) {}
}
log.info("===================EventPendingToNow End===================");
}
}
Loading