|
|
|
@ -214,7 +214,8 @@ public class BookingService { |
|
|
|
System.out.println("noOfPerson: " + noOfPerson); |
|
|
|
System.out.println("slotId: " + slotId); |
|
|
|
|
|
|
|
Map<String, Object> getcalendar = getCalendarBySlotId(bid, cid, Bdate, slotId); |
|
|
|
Map<String, Object> getcalendar = getCalendarBySlotId(bid, cid, Bdate, slotId); |
|
|
|
|
|
|
|
Map<String, Object> capacity = getCapacity(scid, cid); |
|
|
|
|
|
|
|
int capsint = Integer.parseInt(capacity.get("limits").toString()); |
|
|
|
@ -288,6 +289,7 @@ public class BookingService { |
|
|
|
return availableSeats; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> getCapacity(int sId, int catId) { |
|
|
|
System.out.println("sid" + sId); |
|
|
|
System.out.println("catId" + catId); |
|
|
|
@ -303,8 +305,175 @@ public class BookingService { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
public Map<String, Object> getCalendarBySlotId(int bid, int cid, LocalDate Bdate, int slotId) { |
|
|
|
|
|
|
|
System.out.println("Bdate: " + Bdate); |
|
|
|
|
|
|
|
// ✅ Detect monthly slot |
|
|
|
boolean isMonthly = (cid == 2 && slotId == 9) || |
|
|
|
(cid == 6 && slotId == 62) || |
|
|
|
(cid == 16 && slotId == 111); |
|
|
|
|
|
|
|
// ================= DESKSPACE GROUP ================= |
|
|
|
if (cid == 2 || cid == 6 || cid == 16) { |
|
|
|
|
|
|
|
String slotCondition = ""; |
|
|
|
boolean hasDynamicSlot = true; |
|
|
|
|
|
|
|
/*if (cid == 2) { |
|
|
|
slotCondition = "slotId IN (?,8,9)"; |
|
|
|
} else if (cid == 6) { |
|
|
|
slotCondition = "slotId IN (?,61,62)"; |
|
|
|
} else if (cid == 16) { |
|
|
|
slotCondition = "slotId IN (?,110,111)"; |
|
|
|
}*/ |
|
|
|
if (cid == 2) { |
|
|
|
|
|
|
|
if (slotId == 8 || slotId == 9) { |
|
|
|
// ✅ FULL DAY → include ALL |
|
|
|
slotCondition = "slotId IN (6,7,8,9)"; |
|
|
|
hasDynamicSlot = false; |
|
|
|
} else { |
|
|
|
// ✅ NORMAL |
|
|
|
slotCondition = "slotId IN (?,8,9)"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (cid == 6) { |
|
|
|
|
|
|
|
if (slotId == 61 || slotId == 62) { |
|
|
|
slotCondition = "slotId IN (59,60,61,62)"; |
|
|
|
hasDynamicSlot = false; |
|
|
|
} else { |
|
|
|
slotCondition = "slotId IN (?,61,62)"; |
|
|
|
} |
|
|
|
|
|
|
|
} else if (cid == 16) { |
|
|
|
|
|
|
|
if (slotId == 110 || slotId == 111) { |
|
|
|
slotCondition = "slotId IN (108,109,110,111)"; |
|
|
|
hasDynamicSlot = false; |
|
|
|
} else { |
|
|
|
slotCondition = "slotId IN (?,110,111)"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ================= MONTHLY ================= |
|
|
|
/* if (isMonthly) { |
|
|
|
|
|
|
|
int maxBooked = 0; |
|
|
|
|
|
|
|
for (int i = 0; i < 30; i++) { |
|
|
|
|
|
|
|
LocalDate date = Bdate.plusDays(i); |
|
|
|
|
|
|
|
String sql = "SELECT COALESCE(SUM(bcount),0) AS filed " + |
|
|
|
"FROM calendar " + |
|
|
|
"WHERE bdate = ? AND cid = ? AND bid = ? " + |
|
|
|
"AND " + slotCondition; |
|
|
|
|
|
|
|
Map<String, Object> row; |
|
|
|
|
|
|
|
// ✅ FIX HERE |
|
|
|
if (hasDynamicSlot) { |
|
|
|
row = jdbcTemplate.queryForMap(sql, date, cid, bid, slotId); |
|
|
|
} else { |
|
|
|
row = jdbcTemplate.queryForMap(sql, date, cid, bid); |
|
|
|
} |
|
|
|
System.out.println("Slot condition: " + slotCondition); |
|
|
|
System.out.println("SQL: " + sql); |
|
|
|
System.out.println( |
|
|
|
"Params → date: " + date + ", cid: " + cid + ", bid: " + bid + ", slotId: " + slotId); |
|
|
|
|
|
|
|
int booked = Integer.parseInt(row.get("filed").toString()); |
|
|
|
|
|
|
|
public Map<String, Object> getCalendarBySlotId(int bid, int cid, LocalDate Bdate, int slotId) { |
|
|
|
System.out.println("Date: " + date + " → booked: " + booked); |
|
|
|
System.out.println("booked"+booked); |
|
|
|
|
|
|
|
if (booked > maxBooked) { |
|
|
|
maxBooked = booked; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return Collections.singletonMap("filed", maxBooked); |
|
|
|
}*/ |
|
|
|
if (isMonthly) { |
|
|
|
|
|
|
|
LocalDate endDate = Bdate.plusDays(29); // 30 days range |
|
|
|
|
|
|
|
String sql = "SELECT bdate, COALESCE(SUM(bcount), 0) AS filed " + |
|
|
|
"FROM calendar " + |
|
|
|
"WHERE bdate BETWEEN ? AND ? " + |
|
|
|
"AND cid = ? AND bid = ? " + |
|
|
|
"AND " + slotCondition + " " + |
|
|
|
"GROUP BY bdate ORDER BY bdate"; |
|
|
|
|
|
|
|
System.out.println("SQL: " + sql); |
|
|
|
System.out.println("Params → startDate: " + Bdate + |
|
|
|
", endDate: " + endDate + |
|
|
|
", cid: " + cid + |
|
|
|
", bid: " + bid + |
|
|
|
(hasDynamicSlot ? ", slotId: " + slotId : "")); |
|
|
|
|
|
|
|
List<Map<String, Object>> rows; |
|
|
|
|
|
|
|
// ✅ Handle dynamic slot |
|
|
|
if (hasDynamicSlot) { |
|
|
|
rows = jdbcTemplate.queryForList(sql, Bdate, endDate, cid, bid, slotId); |
|
|
|
} else { |
|
|
|
rows = jdbcTemplate.queryForList(sql, Bdate, endDate, cid, bid); |
|
|
|
} |
|
|
|
|
|
|
|
int maxBooked = 0; |
|
|
|
|
|
|
|
for (Map<String, Object> row : rows) { |
|
|
|
int booked = Integer.parseInt(row.get("filed").toString()); |
|
|
|
|
|
|
|
System.out.println("Date: " + row.get("bdate") + " → booked: " + booked); |
|
|
|
|
|
|
|
if (booked > maxBooked) { |
|
|
|
maxBooked = booked; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return Collections.singletonMap("filed", maxBooked); |
|
|
|
} |
|
|
|
|
|
|
|
// ================= NORMAL (DAILY) ================= |
|
|
|
|
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
String sql = "SELECT COALESCE(SUM(bcount),0) AS filed " + |
|
|
|
"FROM calendar " + |
|
|
|
"WHERE bdate = ? AND cid = ? AND bid = ? " + |
|
|
|
"AND " + slotCondition; |
|
|
|
System.out.println("slotCondition"+slotCondition); |
|
|
|
System.out.println("SQL: " + sql); |
|
|
|
System.out.println( |
|
|
|
"Params → Bdate: " + Bdate + ", cid: " + cid + ", bid: " + bid + ", slotId: " + slotId); |
|
|
|
|
|
|
|
if (hasDynamicSlot) { |
|
|
|
return jdbcTemplate.queryForMap(sql, Bdate, cid, bid, slotId); |
|
|
|
} else { |
|
|
|
return jdbcTemplate.queryForMap(sql, Bdate, cid, bid); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ================= DEFAULT ================= |
|
|
|
else { |
|
|
|
|
|
|
|
String sql = "SELECT COALESCE(SUM(bcount),0) AS filed " + |
|
|
|
"FROM calendar " + |
|
|
|
"WHERE bdate = ? AND cid = ? AND bid = ? AND slotId = ?"; |
|
|
|
|
|
|
|
return jdbcTemplate.queryForMap(sql, Bdate, cid, bid, slotId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Map<String, Object> getCalendarBySlotId1(int bid, int cid, LocalDate Bdate, int slotId) { |
|
|
|
System.out.println("Bdate: " + Bdate); |
|
|
|
String sql = ""; |
|
|
|
if (cid == 2 || cid == 6 || cid == 16) { |
|
|
|
|
|
|
|
|