diff --git a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java index 401dd29..311a985 100644 --- a/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java +++ b/src/main/java/org/ntlab/citrusserver/repositories/ScheduleManager.java @@ -9,7 +9,9 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.time.temporal.ChronoUnit; import java.util.*; +import java.util.concurrent.ScheduledExecutorService; @Repository public class ScheduleManager implements IAccountListener, IBookListener{ @@ -157,6 +159,9 @@ Schedule lastCreatedSchedule = null; System.out.println(day); + int newScheduleId = nextScheduleId.computeIfAbsent(accountId, k -> 0); + int groupId = newScheduleId; + try { Date startDate = sdf.parse(startTime); Date endDate = sdf.parse(endTime); @@ -173,12 +178,10 @@ schedules.get(accountId).computeIfAbsent(currentYear, k -> new HashMap<>()).computeIfAbsent(currentMonth, k -> new HashMap<>()) .computeIfAbsent(currentDay, k -> new HashMap<>()); - String accountSchedule = accountId + currentYear + currentMonth + currentDay; - int newScheduleId = nextScheduleId.computeIfAbsent(accountSchedule, k -> 0); - Schedule newSchedule = new Schedule(title, startTime, endTime, bookId, newScheduleId); - schedules.get(accountId).get(currentYear).get(currentMonth).get(currentDay).put(newScheduleId, newSchedule); - nextScheduleId.put(accountSchedule, newScheduleId + 1); + Schedule newSchedule = new Schedule(title, startTime, endTime, bookId, groupId); + schedules.get(accountId).get(currentYear).get(currentMonth).get(currentDay).put(groupId, newSchedule); + nextScheduleId.put(accountId, newScheduleId); lastCreatedSchedule = newSchedule; // 次の日に進む @@ -188,7 +191,7 @@ e.printStackTrace(); // より具体的なエラーハンドリングを検討 return null; } - + nextScheduleId.put(accountId, newScheduleId + 1); return lastCreatedSchedule; } @@ -211,7 +214,25 @@ } public void deleteSchedule(String accountId, int year, int month, int day, int scheduleId) { - schedules.get(accountId).get(year).get(month).get(day).remove(scheduleId); + Schedule schedule = schedules.get(accountId).get(year).get(month).get(day).get(scheduleId); + String startDate = schedule.getStartTime(); + String endDate = schedule.getEndTime(); + String[] startDateTime = startDate.split(" "); + String[] endDateTime = endDate.split(" "); + String[] startYMD = startDateTime[0].split("/"); + String[] endYMD = endDateTime[0].split("/"); + LocalDate start = LocalDate.of(Integer.parseInt(startYMD[0]), Integer.parseInt(startYMD[1]), Integer.parseInt(startYMD[2])); + LocalDate end = LocalDate.of(Integer.parseInt(endYMD[0]), Integer.parseInt(endYMD[1]), Integer.parseInt(endYMD[2])); + long dist = ChronoUnit.DAYS.between(start, end); + LocalDate now = LocalDate.of(year, month, day); + long toStart = ChronoUnit.DAYS.between(now, start); + for(int i = 0; i < dist + 1; i++) { + int nowYear = start.getYear(); + int nowMonth = start.getMonthValue(); + int nowDay = start.getDayOfMonth(); + schedules.get(accountId).get(nowYear).get(nowMonth).get(nowDay).remove(schedule.getScheduleId()); + start = start.plusDays(1); + } } public void setScheduleStartTime(String accountId, int year, int month, int day, int scheduleId, String newTime) {