From ee4653652dcd7805ffe116f99f4236846abd0147 Mon Sep 17 00:00:00 2001 From: AJITHKUMAR12 <48044092+AJITHKUMAR12@users.noreply.github.com> Date: Thu, 2 Apr 2026 17:43:59 +0530 Subject: [PATCH] added logic for monthly and fix error for half day and full day logic --- .../coworkspace/service/BookingService.java | 173 +++++++++++++++++- src/main/resources/application.properties | 7 +- .../templates/user/book-Conferance.html | 12 ++ .../templates/user/book-reading.html | 12 ++ .../templates/user/book-workdesk.html | 15 +- .../resources/templates/user/razor-pay.html | 20 +- 6 files changed, 233 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gcc/coworkspace/service/BookingService.java b/src/main/java/com/gcc/coworkspace/service/BookingService.java index 370c36f..505dcac 100644 --- a/src/main/java/com/gcc/coworkspace/service/BookingService.java +++ b/src/main/java/com/gcc/coworkspace/service/BookingService.java @@ -214,7 +214,8 @@ public class BookingService { System.out.println("noOfPerson: " + noOfPerson); System.out.println("slotId: " + slotId); - Map getcalendar = getCalendarBySlotId(bid, cid, Bdate, slotId); + Map getcalendar = getCalendarBySlotId(bid, cid, Bdate, slotId); + Map capacity = getCapacity(scid, cid); int capsint = Integer.parseInt(capacity.get("limits").toString()); @@ -288,6 +289,7 @@ public class BookingService { return availableSeats; } + public Map getCapacity(int sId, int catId) { System.out.println("sid" + sId); System.out.println("catId" + catId); @@ -303,8 +305,175 @@ public class BookingService { } } + public Map 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 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 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> 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 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 getCalendarBySlotId1(int bid, int cid, LocalDate Bdate, int slotId) { + System.out.println("Bdate: " + Bdate); String sql = ""; if (cid == 2 || cid == 6 || cid == 16) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d802b20..efd7ec3 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -8,4 +8,9 @@ google.api.key=AIzaSyCi7N6uW5MZaSkd50Kzw7ax2GkMN1vjE-E google.place.id=ChIJG8YjaABlUjoRAyFklVuYvk4 complaintfile_directory=complaintfile_uploads -caretakerfileuploads_directory=caretakercomplaintfile_uploads \ No newline at end of file +caretakerfileuploads_directory=caretakercomplaintfile_uploads + + +# \u2705 Allow long-running report requests (3 minutes) +spring.mvc.async.request-timeout=180000 +server.connection-timeout=180000 \ No newline at end of file diff --git a/src/main/resources/templates/user/book-Conferance.html b/src/main/resources/templates/user/book-Conferance.html index 5011bef..a52d90c 100644 --- a/src/main/resources/templates/user/book-Conferance.html +++ b/src/main/resources/templates/user/book-Conferance.html @@ -608,6 +608,16 @@ + @@ -987,6 +997,7 @@ if (msg.includes("Slot Full")) { $('.adultcount').text(noOfPeople); $('.slot').text(selectedSlot); $(".noOfPeoplecount").text(noOfPeople); + $('#pageLoader').show(); $.ajax({ url: '/muthalvarpadaippagam/book/api/saveInTemp', @@ -1004,6 +1015,7 @@ if (msg.includes("Slot Full")) { }, success: function (response) { if (response) { + $('#pageLoader').hide(); let tempId = response.tempBookId; $(".amount").text(response.amount); let finalAmount = response.amount; diff --git a/src/main/resources/templates/user/book-reading.html b/src/main/resources/templates/user/book-reading.html index f517829..76f4b8c 100644 --- a/src/main/resources/templates/user/book-reading.html +++ b/src/main/resources/templates/user/book-reading.html @@ -547,6 +547,16 @@ + @@ -912,6 +922,7 @@ if (msg.includes("Slot Full")) { $('.adultcount').text(noOfPeople); $('.slot').text(selectedSlot); $(".noOfPeoplecount").text(noOfPeople); + $('#pageLoader').show(); $.ajax({ @@ -931,6 +942,7 @@ if (msg.includes("Slot Full")) { success: function (response) { console.log(response); if (response) { + $('#pageLoader').hide(); let tempId = response.tempBookId; $(".amount").text(response.amount); let finalAmount = response.amount; diff --git a/src/main/resources/templates/user/book-workdesk.html b/src/main/resources/templates/user/book-workdesk.html index ffc828b..9fa2442 100644 --- a/src/main/resources/templates/user/book-workdesk.html +++ b/src/main/resources/templates/user/book-workdesk.html @@ -648,6 +648,16 @@ + @@ -833,7 +843,8 @@ function selectTimeSlot(element) { let slotId = element.value; let bid = $('#buildingId').val(); let cid = $('#categoryId').val(); - let scid = $('#subId').val(); + //let scid = $('#subId').val(); + let scid =document.querySelector('input[name="booking_type"]:checked').value; let bDate = $('#selectDate').val(); let noOfPerson = $('#numSeats').val(); @@ -1098,6 +1109,7 @@ if (msg.includes("Slot Full")) { $('.adultcount').text(noOfPeople); $('.slot').text(selectedSlot); $(".noOfPeoplecount").text(noOfPeople); + $('#pageLoader').show(); $.ajax({ @@ -1117,6 +1129,7 @@ if (msg.includes("Slot Full")) { success: function (response) { //console.log("Akg Response:"+response); if (response) { + $('#pageLoader').hide(); let tempId = response.tempBookId; $(".amount").text(response.amount); let finalAmount = response.amount; diff --git a/src/main/resources/templates/user/razor-pay.html b/src/main/resources/templates/user/razor-pay.html index e7c5568..7721060 100644 --- a/src/main/resources/templates/user/razor-pay.html +++ b/src/main/resources/templates/user/razor-pay.html @@ -1,5 +1,15 @@
+ @@ -7,6 +17,7 @@