@ -3,49 +3,70 @@ package com.gcc.communityHall.service.Impl;
import java.io.File ;
import java.io.FileOutputStream ;
import java.io.IOException ;
import java.math.BigDecimal ;
import java.net.InetAddress ;
import java.net.UnknownHostException ;
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.ZoneId ;
import java.time.format.DateTimeFormatter ;
import java.util.* ;
import java.util.concurrent.BlockingQueue ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.LinkedBlockingQueue ;
import java.util.concurrent.atomic.AtomicInteger ;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.Optional ;
import java.util.stream.Collectors ;
import ch.qos.logback.core.net.SyslogOutputStream ;
import com.gcc.communityHall.entity.* ;
import com.gcc.communityHall.repository.* ;
import jakarta.servlet.http.HttpSession ;
import lombok.Synchronized ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.http.ResponseEntity ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.PlatformTransactionManager ;
import org.springframework.transaction.TransactionStatus ;
import org.springframework.transaction.annotation.Propagation ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.support.DefaultTransactionDefinition ;
import org.springframework.web.client.RestTemplate ;
import org.springframework.web.multipart.MultipartFile ;
import com.gcc.communityHall.entity.ApplicationLogs ;
import com.gcc.communityHall.entity.BookingCalendar ;
import com.gcc.communityHall.entity.BookingDetails ;
import com.gcc.communityHall.entity.BookingDetails.BookingStatus ;
import com.gcc.communityHall.entity.BookingDetails.RefundStatus ;
import com.gcc.communityHall.entity.Users.userType ;
import com.gcc.communityHall.exception.PaymentRefundSlotOccupiedException ;
import com.gcc.communityHall.entity.BookingDocuments ;
import com.gcc.communityHall.entity.BookingHistory ;
import com.gcc.communityHall.entity.Damage ;
import com.gcc.communityHall.entity.DiscountRange ;
import com.gcc.communityHall.entity.EbDetails ;
import com.gcc.communityHall.entity.GccBlockingDate ;
import com.gcc.communityHall.entity.GccBlockingHistory ;
import com.gcc.communityHall.entity.GccblockingDocuments ;
import com.gcc.communityHall.entity.HallDetails ;
import com.gcc.communityHall.entity.HallDetailsConcession ;
import com.gcc.communityHall.entity.ReasonDocumentMaster ;
import com.gcc.communityHall.entity.ReasonMaster ;
import com.gcc.communityHall.entity.Settlement ;
import com.gcc.communityHall.entity.Users ;
import com.gcc.communityHall.exception.SlotOccupiedException ;
import com.gcc.communityHall.others.UserSession ;
import com.gcc.communityHall.paymentService.repository.TransRefundResRepository ;
import com.gcc.communityHall.paymentService.repository.TransactionResponseRepository ;
import com.gcc.communityHall.paymentService.service.PaymentGatewayService ;
import com.gcc.communityHall.repository.ApplicationLogsRepository ;
import com.gcc.communityHall.repository.BookingCalendarRepository ;
import com.gcc.communityHall.repository.BookingDetailsRepository ;
import com.gcc.communityHall.repository.BookingDocumentsRepository ;
import com.gcc.communityHall.repository.BookingHistoryRepository ;
import com.gcc.communityHall.repository.DamageRepository ;
import com.gcc.communityHall.repository.EbDetailsRepository ;
import com.gcc.communityHall.repository.GccBlockingDateRepository ;
import com.gcc.communityHall.repository.GccBlockingHistoryRepository ;
import com.gcc.communityHall.repository.GccblockingDocumentsRepo ;
import com.gcc.communityHall.repository.HallDetailsConcessionRepo ;
import com.gcc.communityHall.repository.HallDetailsRepository ;
import com.gcc.communityHall.repository.ReasonMasterRepository ;
import com.gcc.communityHall.repository.SettlementRepository ;
import com.gcc.communityHall.repository.UsersRepository ;
import com.gcc.communityHall.service.ApplicationLogService ;
import com.gcc.communityHall.service.BookingService ;
import com.gcc.communityHall.service.DiscountRangeService ;
@ -135,14 +156,6 @@ public class BookingServiceImpl implements BookingService {
@Autowired
private TransRefundResRepository transRefundResRepository ;
@Autowired
private QueueLogRepository queueLogRepository ;
private static final Map < String , BlockingQueue < Integer > > bookingQueueMap = new ConcurrentHashMap < > ( ) ;
private static final Map < String , Long > lockedSlots = new ConcurrentHashMap < > ( ) ;
private static final Map < String , Timer > slotTimers = new ConcurrentHashMap < > ( ) ;
@Value ( "${file.upload.directory}" )
private String uploadDirectory ;
@ -169,7 +182,7 @@ public class BookingServiceImpl implements BookingService {
}
@Override
public BookingDetails updateBookingStatus ( int bookingId , BookingStatus status , String comments ) {
public BookingDetails updateBookingStatus ( int bookingId , BookingDetails . BookingStatus status , String comments ) {
Optional < BookingDetails > booking = bookingDetailsRepository . findById ( bookingId ) ;
if ( booking . isPresent ( ) ) {
BookingDetails book = booking . get ( ) ;
@ -190,10 +203,12 @@ public class BookingServiceImpl implements BookingService {
}
return null ;
}
@Override
public String confirmTheDateAndSlot ( String fromDate , String toDate , int days , int fromStartingSlot , int fromEndingSlot , int toStartingSlot , int toEndingSlot , int bookingId , int userId ) {
return null ;
}
@Override
@Transactional
public String confirmBooking ( int bookingId ) {
@ -218,10 +233,6 @@ public class BookingServiceImpl implements BookingService {
BookingCalendar bookingCalendar = bookingCalendarRepository . findByBdateAndHallId ( date , hallId ) ;
if ( bookingCalendar ! = null ) {
if ( bookingCalendar . getIs_blocked ( ) ) {
throw new RuntimeException ( "GCC Blocked Date" ) ;
}
/ / System . out . println ( bookingCalendar . toString ( ) ) ;
/ / System . out . println ( "date:-" + date ) ;
/ / System . out . println ( "bookingDetails.getEndingSlot() :- " + bookingDetails . getEndingSlot ( ) ) ;
@ -229,10 +240,13 @@ public class BookingServiceImpl implements BookingService {
/ / System . out . println ( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 1 & & bookingCalendar . isMorningSlot ( ) ) ;
/ / System . out . println ( ) ;
/ / Check if the slot is already occupied
else if ( ( date . equals ( startDate ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingCalendar . isMorningSlot ( ) ) | |
if ( bookingCalendar . getIs_blocked ( ) ) {
throw new RuntimeException ( "GCC Blocked Date" ) ;
} else if ( ( date . equals ( startDate ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingCalendar . isMorningSlot ( ) ) | |
( date . equals ( startDate ) & & bookingDetails . getStartingSlot ( ) = = 2 & & bookingCalendar . isEveningSlot ( ) ) | |
( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 1 & & bookingCalendar . isMorningSlot ( ) ) | |
( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isEveningSlot ( ) ) ) {
/ / System . out . println ( "booking slot occupied:- 218" ) ;
throw new RuntimeException ( exMsg ) ;
} else if ( bookingCalendar . isMorningSlot ( ) & & bookingCalendar . isEveningSlot ( ) ) {
@ -242,8 +256,8 @@ public class BookingServiceImpl implements BookingService {
} else if ( ! date . equals ( endDate ) & & i ! = 0 & & i ! = Math . round ( bookingDetails . getNoOfDays ( ) - 1 )
& & ( bookingCalendar . isMorningSlot ( ) | | bookingCalendar . isEveningSlot ( ) ) ) {
/ / System . out . println ( "booking slot occupied:- 227 :-" + Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) ;
throw new RuntimeException ( exMsg ) ; }
else if ( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isMorningSlot ( )
throw new RuntimeException ( exMsg ) ;
} else if ( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isMorningSlot ( )
& & i ! = 0 & & i = = Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) {
/ / System . out . println ( "booking slot occupied:- 240 :-" + Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) ;
throw new RuntimeException ( exMsg ) ;
@ -269,19 +283,16 @@ public class BookingServiceImpl implements BookingService {
bookingCalendar . setEveningSlot ( true ) ;
bookingCalendar . setBookingId_2 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 1 ) ;
}
else if ( startDate . equals ( endDate ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingDetails . getEndingSlot ( ) = = 2 ) {
} else if ( startDate . equals ( endDate ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingDetails . getEndingSlot ( ) = = 2 ) {
bookingCalendar . setEveningSlot ( true ) ;
bookingCalendar . setBookingId_2 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 1 ) ;
}
bookingCalendar . setTemp_blocked ( false ) ;
} else {
bookingCalendar . setEveningSlot ( true ) ;
bookingCalendar . setBookingId_2 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 1 ) ;
bookingCalendar . setTemp_blocked ( false ) ;
}
} else if ( date . equals ( endDate ) ) {
if ( bookingDetails . getEndingSlot ( ) = = 1 ) {
@ -298,7 +309,6 @@ public class BookingServiceImpl implements BookingService {
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 1 ) ;
}
}
bookingCalendar . setTemp_blocked ( false ) ;
} else {
/ / For dates between start and end date , mark both slots as booked
bookingCalendar . setMorningSlot ( true ) ;
@ -306,9 +316,9 @@ public class BookingServiceImpl implements BookingService {
bookingCalendar . setBookingId_1 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setBookingId_2 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 2 ) ;
bookingCalendar . setTemp_blocked ( false ) ;
}
/ / System . out . println ( i + "end:-" + bookingCalendar . toString ( ) ) ;
bookingCalendarRepository . save ( bookingCalendar ) ;
i + + ;
@ -320,7 +330,7 @@ public class BookingServiceImpl implements BookingService {
reasoncode = "" ; / / or any default value
}
if ( reasoncode . equals ( "CGE" ) | | reasoncode . equals ( "CAO" ) | | reasoncode . equals ( "SGE" ) ) {
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingStatus . WAITING_FOR_NOC , "Waiting For NOC Documents" ) ;
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingDetails . Booking Status . WAITING_FOR_NOC , "Waiting For NOC Documents" ) ;
String bookingconfirmationmsg = "Your booking ID " + bookingDetails . getBookingId ( ) + " on " + bookingDetails . getBookingDate ( ) + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System." ;
String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails . getUsers ( ) . getMobileNo ( ) + "&from=GCCCRP&body=" + bookingconfirmationmsg + "&entityid=1401572690000011081&templateid=1407172346459428987" ;
String whatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + bookingDetails . getUsers ( ) . getMobileNo ( ) + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" + bookingDetails . getBookingId ( ) + "+on+" + bookingDetails . getBookingDate ( ) + "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System." ;
@ -328,10 +338,10 @@ public class BookingServiceImpl implements BookingService {
whatsappMsgServiceImpl . sendSMS ( urlString ) ;
return "Waiting For NOC Documents" ;
} else {
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingStatus . APPROVED , "Booking Confirmed Successfully" ) ;
String bookingconfirmationmsg = "Your booking ID " + bookingDetails . getBookingId ( ) + " on " + bookingDetails . getBooking Date ( ) + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System." ;
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingDetails . BookingStatus . APPROVED , "Booking Confirmed Successfully" ) ;
String bookingconfirmationmsg = "Your booking ID " + bookingDetails . getBookingId ( ) + " on " + bookingDetails . getStart Date ( ) + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System." ;
String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails . getUsers ( ) . getMobileNo ( ) + "&from=GCCCRP&body=" + bookingconfirmationmsg + "&entityid=1401572690000011081&templateid=1407172346459428987" ;
String whatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + bookingDetails . getUsers ( ) . getMobileNo ( ) + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" + bookingDetails . getBookingId ( ) + "+on+" + bookingDetails . getBooking Date ( ) + "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System." ;
String whatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + bookingDetails . getUsers ( ) . getMobileNo ( ) + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" + bookingDetails . getBookingId ( ) + "+on+" + bookingDetails . getStart Date ( ) + "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System." ;
whatsappMsgServiceImpl . sendMsg ( whatsupmsg ) ;
whatsappMsgServiceImpl . sendSMS ( urlString ) ;
return "Booking confirmed successfully" ;
@ -388,8 +398,8 @@ public class BookingServiceImpl implements BookingService {
} else if ( ! date . equals ( endDate ) & & i ! = 0 & & i ! = Math . round ( bookingDetails . getNoOfDays ( ) - 1 )
& & ( bookingCalendar . isMorningSlot ( ) | | bookingCalendar . isEveningSlot ( ) ) ) {
/ / System . out . println ( "booking slot occupied:- 227 :-" + Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) ;
throw new RuntimeException ( exMsg ) ; }
else if ( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isMorningSlot ( )
throw new RuntimeException ( exMsg ) ;
} else if ( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isMorningSlot ( )
& & i ! = 0 & & i = = Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) {
/ / System . out . println ( "booking slot occupied:- 240 :-" + Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) ;
throw new RuntimeException ( exMsg ) ;
@ -415,8 +425,7 @@ public class BookingServiceImpl implements BookingService {
bookingCalendar . setEveningSlot ( true ) ;
bookingCalendar . setBookingId_2 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 1 ) ;
}
else if ( startDate . equals ( endDate ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingDetails . getEndingSlot ( ) = = 2 ) {
} else if ( startDate . equals ( endDate ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingDetails . getEndingSlot ( ) = = 2 ) {
bookingCalendar . setEveningSlot ( true ) ;
bookingCalendar . setBookingId_2 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 1 ) ;
@ -455,7 +464,7 @@ public class BookingServiceImpl implements BookingService {
bookingCalendarRepository . save ( bookingCalendar ) ;
i + + ;
}
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingStatus . WAITING_FOR_NOC , "Waiting for NOC Documents" ) ;
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingDetails . BookingStatus . WAITING_FOR_NOC , "Waiting for NOC Documents" ) ;
String bookingconfirmationmsg = "Your booking ID " + bookingDetails . getBookingId ( ) + " on " + bookingDetails . getBookingDate ( ) + " has been confirmed successfully. Thanks for using GCC Community Hall Booking System." ;
String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails . getUsers ( ) . getMobileNo ( ) + "&from=GCCCRP&body=" + bookingconfirmationmsg + "&entityid=1401572690000011081&templateid=1407172346459428987" ;
String whatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + bookingDetails . getUsers ( ) . getMobileNo ( ) + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" + bookingDetails . getBookingId ( ) + "+on+" + bookingDetails . getBookingDate ( ) + "+has+been+successfully+confirmed.+%0AThanks+for+using+GCC+Community+Hall+Booking+System." ;
@ -485,7 +494,7 @@ public class BookingServiceImpl implements BookingService {
/ / System . out . println ( "refundedMsg==" + refundedMsg ) ;
if ( refundedMsg . equals ( "Refunded" ) ) {
/ / System . out . println ( "Refund completed........" ) ;
bookingDetails . setRefundStatus ( RefundStatus . COMPLETED ) ;
bookingDetails . setRefundStatus ( BookingDetails . RefundStatus . COMPLETED ) ;
bookingDetailsRepository . save ( bookingDetails ) ;
/ / System . out . println ( "refundStatus====" + bookingDetails . getRefundStatus ( ) ) ;
long mobile = bookingDetails . getUsers ( ) . getMobileNo ( ) ;
@ -501,28 +510,18 @@ public class BookingServiceImpl implements BookingService {
/ / thread . start ( ) ;
return "Success" ;
}
}
catch ( Exception e ) {
} catch ( Exception e ) {
applicationLogService . saveLog ( bookingDetails . getBookingId ( ) , ApplicationLogs . logsOfMsg . ERROR . toString ( ) , "Refund Error" ) ;
return "error" ;
} }
}
}
return "error" ;
}
@Override
public Map < String , Object > saveBookingDetails ( Map < String , Object > formData ) {
Map < String , Object > hs = new HashMap < > ( ) ;
BookingDetails bookingDetails = null ;
BookingCalendar bookingCal = new BookingCalendar ( ) ;
QueueLog queueLog = new QueueLog ( ) ;
Optional < BookingCalendar > existingBooking = Optional . empty ( ) ;
int bcid ;
/ / System . out . println ( "bc Id 2........" + formData . get ( "bcId" ) ) ;
AtomicInteger finalBcId = new AtomicInteger ( ) ;
Integer userId = userSession . getUserId ( ) ;
@ -565,134 +564,9 @@ public class BookingServiceImpl implements BookingService {
String usertype = user . getUsertype ( ) . toString ( ) ;
String reason = reasonMaster . getReason ( ) ;
/ / double depositeamount = hallDetails . getDepositAmount ( ) * daysrange ;
double depositeamount = hallDetails . getDepositAmount ( ) * Math . ceil ( days ) ;
/ / Adjust slotKey to consider multiple dates
/ / String slotKey = hallDetails . getHallId ( ) + "|" + startDate + "|" + endDate + "|" + startingSlot + "|" + endingSlot ;
String slotKey = hallDetails . getHallId ( ) + "|" + startDate + "|" + endDate ; / / 21212202413122024
System . out . println ( "slotKey: " + slotKey ) ;
/ / Generate individual keys for each day within the range
List < String > slotKeysForDates = new ArrayList < > ( ) ;
DateTimeFormatter dFormatter = DateTimeFormatter . ofPattern ( "yyyy-MM-dd" ) ;
LocalDate formattedStartDate = LocalDate . parse ( startDate , dFormatter ) ;
LocalDate formattedEndDate = LocalDate . parse ( endDate , dFormatter ) ;
int hallId1 = bookingDetails . getHallDetails ( ) . getHallId ( ) ;
for ( LocalDate date = formattedStartDate ; ! date . isAfter ( formattedEndDate ) ; date = date . plusDays ( 1 ) ) {
slotKeysForDates . add ( hallDetails . getHallId ( ) + "|" + date . toString ( ) ) ;
}
/ / Check each slot key for locks and manage queues
for ( String key : slotKeysForDates ) {
System . out . println ( "Key:" + key ) ;
bookingQueueMap . putIfAbsent ( key , new LinkedBlockingQueue < > ( ) ) ;
System . out . println ( "bookingQueueMap: " + bookingQueueMap . size ( ) ) ;
BlockingQueue < Integer > queue = bookingQueueMap . get ( key ) ;
System . out . println ( "queue: " + queue . size ( ) ) ;
existingBooking = Optional . ofNullable ( bookingCalendarRepository . findByBdateAndHallId ( formattedStartDate , hallId1 ) ) ;
if ( existingBooking . isPresent ( ) ) {
System . out . println ( "Record already exists for the given date and hall. Skipping save." ) ;
bcid = existingBooking . get ( ) . getId ( ) ; / / Use existing record ID
bookingCalendarRepository . updateTempBlocked ( bcid , true ) ;
System . out . println ( "bcid111: " + bcid ) ;
hs . put ( "bcId" , bcid ) ;
} else {
bookingCal . setBdate ( formattedStartDate ) ;
bookingCal . setEveningSlot ( false ) ;
bookingCal . setHallId ( hallId1 ) ;
bookingCal . setIs_active ( true ) ;
bookingCal . setIs_booked ( 0 ) ;
bookingCal . setIs_delete ( false ) ;
bookingCal . setMorningSlot ( false ) ;
bookingCal . setIs_blocked ( false ) ;
bookingCal . setTemp_blocked ( true ) ;
BookingCalendar bc = bookingCalendarRepository . save ( bookingCal ) ;
bcid = bc . getId ( ) ;
hs . put ( "bcId" , bcid ) ;
}
System . out . println ( "lockedSlots: " + lockedSlots . size ( ) ) ;
/ / Check if slot is locked
if ( lockedSlots . containsKey ( key ) ) {
/ / To allow first user in the queue to navigate between the steps
if ( ! queue . isEmpty ( ) & & queue . peek ( ) ! = userId ) {
queueLog . setStartDate ( formattedStartDate ) ;
queueLog . setStarting_slot ( startingSlot ) ;
queueLog . setEndDate ( formattedEndDate ) ;
queueLog . setEnding_slot ( endingSlot ) ;
queueLog . setUser_id ( userId ) ;
queueLog . setHall_id ( hallId1 ) ;
queueLog . setSlotKey ( key ) ;
QueueLog ql = queueLogRepository . save ( queueLog ) ;
System . out . println ( "Queue Id: " + ql . getQueue_id ( ) ) ;
hs . put ( "status" , "slotLocked" ) ;
hs . put ( "message" , "Hall slot is locked by another user. Please wait." ) ;
return hs ;
}
}
System . out . println ( "userId: " + userId ) ;
queue . add ( userId ) ;
int position = new ArrayList < > ( queue ) . indexOf ( userId ) + 1 ;
if ( position > 1 ) {
hs . put ( "status" , "inQueue" ) ;
hs . put ( "message" , "You are " + position + " in the queue for slot " + key + ". Please wait for your turn." ) ;
return hs ;
}
/ / lockedSlots . put ( slotKey , System . currentTimeMillis ( ) + 10 * 60 * 1000 ) ; / / 10 minutes lock
lockedSlots . put ( key , System . currentTimeMillis ( ) + 3 * 60 * 1000 ) ; / / 3 minute lock
if ( formData . containsKey ( "bcId" ) & & formData . get ( "bcId" ) ! = null & & ! formData . get ( "bcId" ) . toString ( ) . trim ( ) . isEmpty ( ) ) {
finalBcId . set ( Integer . parseInt ( formData . get ( "bcId" ) . toString ( ) ) ) ;
}
if ( ! slotTimers . containsKey ( key ) ) {
Timer timer = new Timer ( ) ;
slotTimers . put ( key , timer ) ;
timer . schedule ( new TimerTask ( ) {
@Override
public void run ( ) {
/ / Check if lock expired
if ( System . currentTimeMillis ( ) > lockedSlots . getOrDefault ( key , 0L ) ) {
lockedSlots . remove ( key ) ;
System . out . println ( "finalBcId: " + finalBcId ) ;
if ( finalBcId . get ( ) ! = 0 )
{
bookingCalendarRepository . updateTempBlocked ( finalBcId . get ( ) , false ) ;
}
/ / Clear the queue without processing further
if ( ! queue . isEmpty ( ) ) {
System . out . println ( "Clearing the queue for key: " + key ) ;
queue . clear ( ) ;
}
/ / Stop the timer if the queue is empty
if ( queue . isEmpty ( ) ) {
slotTimers . remove ( key ) ;
timer . cancel ( ) ;
}
}
}
} , 0 , 1000 * 60 ) ; / / Run every 1 minute
}
}
/ / Calculate discount based on user type
if ( usertype . equals ( "COUNCILLOR" ) | | usertype . equals ( "PENSIONER" ) | | usertype . equals ( "GCC_EMPLOYEE" ) | | usertype . equals ( "PUBLIC" ) ) {
discountAmount = ( hallAmount * discount ) / 100 ;
@ -763,8 +637,8 @@ public class BookingServiceImpl implements BookingService {
hs . put ( "additionalcharges" , additionalcharges ) ;
hs . put ( "totalAmount" , truncatedTotalAmount ) ;
}
} else if ( reasoncode . equals ( "CGE" ) ) {
/ * double hallAmountforcentral = calcHallAmount ( hallDetails , daysrange , startingSlot , endingSlot ) ;
} / * else if ( reasoncode . equals ( "CGE" ) ) {
double hallAmountforcentral = calcHallAmount ( hallDetails , daysrange , startingSlot , endingSlot ) ;
double discountAmounts = ( hallAmountforcentral * hallDetails . getCGEdiscount ( ) ) / 100 ;
hs . put ( "discount" , hallDetails . getCGEdiscount ( ) ) ; / / 50 % discount for Central Govt Event
hallAmountforcentral = hallAmountforcentral - discountAmounts ;
@ -782,8 +656,8 @@ public class BookingServiceImpl implements BookingService {
bookingDetails . setHallAmount ( hallAmountforcentral ) ;
bookingDetails . setGst ( gstAmount ) ;
bookingDetails . setAmountReceived ( truncatedTotalAmount ) ;
hs . put ( "totalAmount" , truncatedTotalAmount ) ; * /
hs . put ( "totalAmount" , truncatedTotalAmount ) ;
} * / else if ( reasoncode . equals ( "CGE" ) ) {
if ( startingSlot = = 1 & & endingSlot = = 2 ) {
discountAmount = ( hallDetails . getFullDayRent ( ) * hallDetails . getCGEdiscount ( ) ) / 100 ;
hallAmount = hallDetails . getFullDayRent ( ) ;
@ -800,7 +674,8 @@ public class BookingServiceImpl implements BookingService {
double truncatedTotalAmount = Math . round ( totalAmount * 100 . 0 ) / 100 . 0 ;
hs . put ( "actualhallamount" , hallAmount ) ;
bookingDetails . setDepositAmount ( depositeamount ) ;
bookingDetails . setHallAmount ( additionalcharges ) ;
/ / bookingDetails . setHallAmount ( additionalcharges ) ;
bookingDetails . setHallAmount ( netAmount ) ;
bookingDetails . setGst ( gstAmount ) ;
bookingDetails . setAmountReceived ( truncatedTotalAmount ) ;
@ -826,7 +701,8 @@ public class BookingServiceImpl implements BookingService {
double truncatedTotalAmount = Math . round ( totalAmount * 100 . 0 ) / 100 . 0 ;
hs . put ( "actualhallamount" , hallAmount ) ;
bookingDetails . setDepositAmount ( depositeamount ) ;
bookingDetails . setHallAmount ( additionalcharges ) ;
/ / bookingDetails . setHallAmount ( additionalcharges ) ;
bookingDetails . setHallAmount ( netAmount ) ;
bookingDetails . setGst ( gstAmount ) ;
bookingDetails . setAmountReceived ( truncatedTotalAmount ) ;
@ -839,6 +715,7 @@ public class BookingServiceImpl implements BookingService {
}
}
bookingDetails . setNoOfDays ( days ) ;
bookingDetails . setStartingSlot ( startingSlot ) ;
bookingDetails . setEndingSlot ( endingSlot ) ;
@ -846,25 +723,43 @@ public class BookingServiceImpl implements BookingService {
bookingDetails . setEndDate ( endDate ) ;
bookingDetails . setBookingDate ( LocalDate . now ( ) ) ;
bookingDetails . setReason ( reasonMaster . getReason ( ) ) ;
bookingDetails . setRefundStatus ( RefundStatus . WAITING ) ;
bookingDetails . setRefundStatus ( BookingDetails . RefundStatus . WAITING ) ;
bookingDetails . setComments ( "Booking Slot not Confirmed." ) ;
bookingDetails . setBookingtype ( BookingDetails . BookingType . ONLINE ) ;
bookingDetails . setRelationship ( relation ) ;
boolean slotStatus = isSlotOccupied ( bookingDetails ) ;
System . out . println ( "slotStatus: " + slotStatus ) ;
if ( slotStatus ) {
int i = 0 ;
String startDateStr = bookingDetails . getStartDate ( ) ;
String endDateStr = bookingDetails . getEndDate ( ) ;
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( "yyyy-MM-dd" ) ;
LocalDate start = LocalDate . parse ( startDateStr , formatter ) ;
LocalDate end = LocalDate . parse ( endDateStr , formatter ) ;
int hallId = bookingDetails . getHallDetails ( ) . getHallId ( ) ;
for ( LocalDate date = start ; ! date . isAfter ( end ) ; date = date . plusDays ( 1 ) ) {
BookingCalendar bookingCalendar = bookingCalendarRepository . findByBdateAndHallId ( date , hallId ) ;
if ( bookingCalendar ! = null ) {
if ( ( date . equals ( start ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingCalendar . isMorningSlot ( ) ) | |
( date . equals ( start ) & & bookingDetails . getStartingSlot ( ) = = 2 & & bookingCalendar . isEveningSlot ( ) ) | |
( date . equals ( end ) & & bookingDetails . getEndingSlot ( ) = = 1 & & bookingCalendar . isMorningSlot ( ) ) | |
( date . equals ( end ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isEveningSlot ( ) ) ) {
return Collections . singletonMap ( "status" , "slotOccupied" ) ;
} else if ( bookingCalendar . isMorningSlot ( ) & & bookingCalendar . isEveningSlot ( ) ) {
return Collections . singletonMap ( "status" , "slotOccupied" ) ;
} else if ( ! date . equals ( end ) & & i ! = 0 & & i ! = Math . round ( bookingDetails . getNoOfDays ( ) - 1 )
& & ( bookingCalendar . isMorningSlot ( ) | | bookingCalendar . isEveningSlot ( ) ) ) {
return Collections . singletonMap ( "status" , "slotOccupied" ) ;
} else if ( date . equals ( end ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isMorningSlot ( )
& & i ! = 0 & & i = = Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) {
return Collections . singletonMap ( "status" , "slotOccupied" ) ;
}
}
i + + ;
}
/ / Save the booking details after the loop
try {
bookingDetails = bookingDetailsRepository . save ( bookingDetails ) ;
} catch ( Exception e )
{
System . out . println ( "Exception:" + e . getMessage ( ) ) ;
return Collections . singletonMap ( "status" , "slotOccupiedbyAnotherUser" ) ;
}
/ / confirmation of amount
hs . put ( "bookingId" , bookingDetails . getBookingId ( ) ) ;
@ -919,43 +814,6 @@ public class BookingServiceImpl implements BookingService {
return hs ;
}
public boolean isSlotOccupied ( BookingDetails bookingDetails ) {
/ / Slot occupied logic
int i = 0 ;
String startDateStr = bookingDetails . getStartDate ( ) ;
String endDateStr = bookingDetails . getEndDate ( ) ;
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( "yyyy-MM-dd" ) ;
LocalDate start = LocalDate . parse ( startDateStr , formatter ) ;
LocalDate end = LocalDate . parse ( endDateStr , formatter ) ;
int hallId = bookingDetails . getHallDetails ( ) . getHallId ( ) ;
for ( LocalDate date = start ; ! date . isAfter ( end ) ; date = date . plusDays ( 1 ) ) {
BookingCalendar bookingCalendar = bookingCalendarRepository . findByBdateAndHallId ( date , hallId ) ;
if ( bookingCalendar ! = null ) {
if ( ( date . equals ( start ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingCalendar . isMorningSlot ( ) ) | |
( date . equals ( start ) & & bookingDetails . getStartingSlot ( ) = = 2 & & bookingCalendar . isEveningSlot ( ) ) | |
( date . equals ( end ) & & bookingDetails . getEndingSlot ( ) = = 1 & & bookingCalendar . isMorningSlot ( ) ) | |
( date . equals ( end ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isEveningSlot ( ) ) ) {
return true ;
} else if ( bookingCalendar . isMorningSlot ( ) & & bookingCalendar . isEveningSlot ( ) ) {
return true ;
} else if ( ! date . equals ( end ) & & i ! = 0 & & i ! = Math . round ( bookingDetails . getNoOfDays ( ) - 1 )
& & ( bookingCalendar . isMorningSlot ( ) | | bookingCalendar . isEveningSlot ( ) ) ) {
return true ;
} else if ( date . equals ( end ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isMorningSlot ( )
& & i ! = 0 & & i = = Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) {
return true ;
}
}
i + + ;
}
return false ;
}
private double calcHallAmount ( HallDetails hallDetails , int daysrange , int startPeriod , int endPeriod ) {
double hallAmount = 0 ;
if ( daysrange = = 1 ) {
@ -1053,12 +911,12 @@ public class BookingServiceImpl implements BookingService {
/ / Create and save BookingDetails
BookingDetails bookingDetails = new BookingDetails ( ) ;
bookingDetails . setBookingStatus ( BookingStatus . GCC_BLOCKED ) ;
bookingDetails . setBookingStatus ( BookingDetails . Booking Status . GCC_BLOCKED ) ;
bookingDetails . setReason ( gcc . getBlockingReason ( ) ) ;
bookingDetails . setNoOfDays ( 0 ) ;
bookingDetails . setAmountReceived ( 0 ) ;
bookingDetails . setDepositAmount ( 0 ) ;
bookingDetails . setRefundStatus ( RefundStatus . NA ) ;
bookingDetails . setRefundStatus ( BookingDetails . RefundStatus . NA ) ;
bookingDetails . setBookingDate ( LocalDate . now ( ) ) ;
bookingDetails . setStartDate ( LocalDate . ofInstant ( savedGcc . getStartDate ( ) . toInstant ( ) , ZoneId . systemDefault ( ) ) . format ( formatter ) ) ;
bookingDetails . setEndDate ( LocalDate . ofInstant ( savedGcc . getEndDate ( ) . toInstant ( ) , ZoneId . systemDefault ( ) ) . format ( formatter ) ) ;
@ -1069,7 +927,7 @@ public class BookingServiceImpl implements BookingService {
bookingDetails = bookingDetailsRepository . save ( bookingDetails ) ;
bookingIds . add ( bookingDetails . getBookingId ( ) ) ;
/ / System . out . println ( "BookingDetails saved with ID: " + bookingDetails . getBookingId ( ) ) ;
System . out . println ( "BookingDetails saved with ID: " + bookingDetails . getBookingId ( ) ) ;
}
/ / Save the list of booking IDs in the GccBlockingDate entity
@ -1095,6 +953,7 @@ public class BookingServiceImpl implements BookingService {
public void updateBookingStatus ( BookingCalendar book ) {
bookingCalendarRepository . save ( book ) ;
}
public List < BookingCalendar > getCancellingdata1 ( String bookID ) {
@ -1109,6 +968,7 @@ public class BookingServiceImpl implements BookingService {
/ / TODO Auto - generated method stub
return bookingDetailsRepository . findPresentsEventsByUserId ( hallId ) ;
}
public List < BookingDetails > getSettlementList ( Integer hallId ) {
/ / TODO Auto - generated method stub
return bookingDetailsRepository . getSettlementList ( hallId ) ;
@ -1125,6 +985,7 @@ public class BookingServiceImpl implements BookingService {
/ / TODO Auto - generated method stub
return bookingDetailsRepository . findFutureEventsByHallId ( hallId ) ;
}
@Override
public List < BookingDetails > getFilteredBookings ( LocalDate fromDate , LocalDate toDate , List < Long > hallIds ) {
return bookingDetailsRepository . findByFromDateBetweenAndToDateBetweenAndHallIdIn ( fromDate , toDate , hallIds ) ;
@ -1144,7 +1005,7 @@ public class BookingServiceImpl implements BookingService {
@Override
public BookingDetails updateBookingStatusById ( int bookingId , BookingStatus status , String comments ) {
public BookingDetails updateBookingStatusById ( int bookingId , BookingDetails . BookingStatus status , String comments ) {
Optional < BookingDetails > bookingDetails = bookingDetailsRepository . findById ( bookingId ) ;
if ( bookingDetails . isPresent ( ) ) {
BookingDetails bookDet = bookingDetails . get ( ) ;
@ -1158,7 +1019,7 @@ public class BookingServiceImpl implements BookingService {
}
@Override
public BookingDetails updateCancelledBookingStatus ( int bookingId , BookingStatus status , String comments ) {
public BookingDetails updateCancelledBookingStatus ( int bookingId , BookingDetails . BookingStatus status , String comments ) {
Optional < BookingDetails > bookingDetails = bookingDetailsRepository . findById ( bookingId ) ;
if ( bookingDetails . isPresent ( ) ) {
BookingDetails bookDet = bookingDetails . get ( ) ;
@ -1220,10 +1081,11 @@ public class BookingServiceImpl implements BookingService {
double startReading = ed . getStartingReading ( ) ;
if ( endUnit ! = 0 ) {
ed . setEndingReading ( endUnit ) ;
double usedUnit = endUnit - startReading ;
double usedUnit = Math . floor ( ( endUnit - startReading ) * 100 ) / 100 . 0 ;
ed . setUsedUnit ( Float . parseFloat ( usedUnit + "" ) ) ;
float costPerUnit = bd . getHallDetails ( ) . getEbCostPerUnit ( ) ;
ed . setEbAmount ( usedUnit * costPerUnit ) ;
double ebAmount = Math . floor ( ( usedUnit * costPerUnit ) * 100 ) / 100 . 0 ;
ed . setEbAmount ( ebAmount ) ;
ed . setUpdatedDate ( new Date ( ) ) ;
return ebDetailsRepository . save ( ed ) ;
}
@ -1233,14 +1095,14 @@ public class BookingServiceImpl implements BookingService {
}
@Override
public String cancelBooking ( int bookingId , BookingStatus currentStatus , String comments ) {
public String cancelBooking ( int bookingId , BookingDetails . Booking Status currentStatus , String comments ) {
Optional < BookingDetails > bd = bookingDetailsRepository . findById ( bookingId ) ;
if ( bd . isPresent ( ) ) {
BookingDetails bookingDetails = bd . get ( ) ;
/ / System . out . println ( "currentStatus:-" + currentStatus ) ;
if ( bookingDetails . getBookingStatus ( ) . equals ( BookingStatus . APPROVED ) ) {
if ( bookingDetails . getBookingStatus ( ) . equals ( BookingDetails . Booking Status . APPROVED ) ) {
/ / System . err . println ( "test" + currentStatus ) ;
if ( currentStatus . equals ( BookingStatus . CANCELED ) ) {
if ( currentStatus . equals ( BookingDetails . Booking Status . CANCELED ) ) {
/ / System . err . println ( "test11" + currentStatus ) ;
try {
/ / System . err . println ( "test13331===" + currentStatus ) ;
@ -1248,7 +1110,7 @@ public class BookingServiceImpl implements BookingService {
String refundTheDepositAmount = paymentGatewayService . refundTheDepositAmount ( bookingDetails . getBookingId ( ) , bookingDetails . getUsers ( ) . getUserId ( ) , bookingDetails . getDepositAmount ( ) ) ;
/ / System . out . println ( "refundTheDepositAmount===" + refundTheDepositAmount ) ;
if ( refundTheDepositAmount . equals ( "Refunded" ) ) {
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingStatus . CANCELED , "user cancelled Date:-" + new Date ( ) ) ;
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingDetails . Booking Status . CANCELED , "user cancelled Date:-" + new Date ( ) ) ;
List < BookingCalendar > bookingCalendarList = bookingCalendarRepository . getCancellingdata1 ( String . valueOf ( bookingDetails . getBookingId ( ) ) ) ;
@ -1283,13 +1145,13 @@ public class BookingServiceImpl implements BookingService {
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
} else if ( currentStatus . equals ( BookingStatus . REJECTED ) ) {
} else if ( currentStatus . equals ( BookingDetails . Booking Status . REJECTED ) ) {
try {
applicationLogService . saveLog ( bookingDetails . getBookingId ( ) , ApplicationLogs . logsOfMsg . GCC_REJECTED . toString ( ) , comments ) ;
String refundtheAmount = paymentGatewayService . refundTheAmount ( bookingDetails . getBookingId ( ) , bookingDetails . getUsers ( ) . getUserId ( ) ) ;
/ / System . out . println ( "refundtheAmount===" + refundtheAmount ) ;
if ( refundtheAmount . equals ( "Refunded" ) ) {
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingStatus . REJECTED , comments ) ;
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingDetails . Booking Status . REJECTED , comments ) ;
List < BookingCalendar > bookingCalendarList = bookingCalendarRepository . getCancellingdata1 ( String . valueOf ( bookingDetails . getBookingId ( ) ) ) ;
@ -1324,11 +1186,11 @@ public class BookingServiceImpl implements BookingService {
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
} else if ( currentStatus . equals ( BookingStatus . GCC_BLOCKED ) ) {
} else if ( currentStatus . equals ( BookingDetails . Booking Status . GCC_BLOCKED ) ) {
try {
applicationLogService . saveLog ( bookingDetails . getBookingId ( ) , ApplicationLogs . logsOfMsg . GCC_BLOCKED_DATE . toString ( ) , comments ) ;
paymentGatewayService . refundTheAmount ( bookingDetails . getBookingId ( ) , bookingDetails . getUsers ( ) . getUserId ( ) ) ;
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingStatus . GCC_BLOCKED , "total amount will refund shortly" ) ;
updateBookingStatusById ( bookingDetails . getBookingId ( ) , BookingDetails . Booking Status . GCC_BLOCKED , "total amount will refund shortly" ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
@ -1349,6 +1211,7 @@ public class BookingServiceImpl implements BookingService {
}
return null ;
}
@Override
public BookingDetails saveebdetails ( int bookingId , double startingReading ,
MultipartFile startingReadingimage ) {
@ -1375,6 +1238,7 @@ public class BookingServiceImpl implements BookingService {
}
return null ;
}
@Override
public String processEbDetailsAndDamage ( int bookingId , int ebId , double startingReading , double endingReading ,
float usedUnit , double ebAmount , String [ ] assetNames , String [ ] comments , int [ ] quantities ,
@ -1452,6 +1316,7 @@ public class BookingServiceImpl implements BookingService {
/ / TODO Auto - generated method stub
return bookingDetailsRepository . checkUserBookinglimitation ( userId ) ;
}
@Override
public List < BookingDetails > getAllBookingsByUserId ( Integer userId ) {
/ / TODO Auto - generated method stub
@ -1493,6 +1358,7 @@ public class BookingServiceImpl implements BookingService {
public List < BookingCalendar > getBookedslots ( LocalDate fromDate , LocalDate endDate , List < Long > hallIdList ) {
return bookingCalendarRepository . findByHallIdAndDateRange ( fromDate , endDate , hallIdList ) ;
}
/ / public List < String > processRefundRequests ( List < String > bookingIds ) {
/ / List < String > bookIds = new ArrayList < > ( ) ;
/ /
@ -1664,10 +1530,12 @@ public class BookingServiceImpl implements BookingService {
public List < Object [ ] > getAllPaymentsDetailsByZone ( String fromDate , String toDate , String zone ) {
return bookingDetailsRepository . getAllPaymentsDetailsByZone ( fromDate , toDate , zone ) ;
}
@Override
public List < Object [ ] > getBookingHallDetailsReportByZone ( String fromDate , String toDate , String zone ) {
return bookingDetailsRepository . getBookingHallDetailsReportByZone ( fromDate , toDate , zone ) ;
}
/ / R
@Transactional
public Optional < String > updateBookingDatesAndCalendar ( int bookingId , String startDat , String endDat ) {
@ -1685,6 +1553,20 @@ public class BookingServiceImpl implements BookingService {
List < BookingCalendar > existingCalendars = bookingCalendarRepository . getCancellingdata1 ( String . valueOf ( bookingId ) ) ;
/ / Empty the existing date in calendar
for ( BookingCalendar calendar : existingCalendars ) {
if ( calendar . getBookingId_1 ( ) ! = null & & calendar . getBookingId_1 ( ) . equals ( String . valueOf ( bookingId ) ) ) {
calendar . setMorningSlot ( false ) ;
calendar . setBookingId_1 ( null ) ;
}
if ( calendar . getBookingId_2 ( ) ! = null & & calendar . getBookingId_2 ( ) . equals ( String . valueOf ( bookingId ) ) ) {
calendar . setEveningSlot ( false ) ;
calendar . setBookingId_2 ( null ) ;
}
bookingCalendarRepository . save ( calendar ) ;
}
/ / Check if the dates exist and update or create new entries accordingly
String slotOccExpMsg = "Dates are already occupied. Please select another date." ;
int i = 0 ;
@ -1707,8 +1589,8 @@ public class BookingServiceImpl implements BookingService {
} else if ( ! date . equals ( endDate ) & & i ! = 0 & & i ! = Math . round ( bookingDetails . getNoOfDays ( ) - 1 )
& & ( bookingCalendar . isMorningSlot ( ) | | bookingCalendar . isEveningSlot ( ) ) ) {
/ / System . out . println ( "booking slot occupied:- 227 :-" + Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) ;
throw new SlotOccupiedException ( slotOccExpMsg ) ; }
else if ( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isMorningSlot ( )
throw new SlotOccupiedException ( slotOccExpMsg ) ;
} else if ( date . equals ( endDate ) & & bookingDetails . getEndingSlot ( ) = = 2 & & bookingCalendar . isMorningSlot ( )
& & i ! = 0 & & i = = Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) {
/ / System . out . println ( "booking slot occupied:- 240 :-" + Math . round ( bookingDetails . getNoOfDays ( ) - 1 ) ) ;
throw new SlotOccupiedException ( slotOccExpMsg ) ;
@ -1733,8 +1615,7 @@ public class BookingServiceImpl implements BookingService {
bookingCalendar . setEveningSlot ( true ) ;
bookingCalendar . setBookingId_2 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 1 ) ;
}
else if ( startDate . equals ( endDate ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingDetails . getEndingSlot ( ) = = 2 ) {
} else if ( startDate . equals ( endDate ) & & bookingDetails . getStartingSlot ( ) = = 1 & & bookingDetails . getEndingSlot ( ) = = 2 ) {
bookingCalendar . setEveningSlot ( true ) ;
bookingCalendar . setBookingId_2 ( String . valueOf ( bookingId ) ) ;
bookingCalendar . setIs_booked ( bookingCalendar . getIs_booked ( ) + 1 ) ;
@ -1774,18 +1655,6 @@ public class BookingServiceImpl implements BookingService {
}
/ / transactionManager . rollback ( status ) ;
updateResheduledBookingDetails ( bookingId , startDat , endDat ) ;
/ / Empty the existing date in calendar
for ( BookingCalendar calendar : existingCalendars ) {
if ( calendar . getBookingId_1 ( ) ! = null & & calendar . getBookingId_1 ( ) . equals ( String . valueOf ( bookingId ) ) ) {
calendar . setMorningSlot ( false ) ;
calendar . setBookingId_1 ( null ) ;
}
if ( calendar . getBookingId_2 ( ) ! = null & & calendar . getBookingId_2 ( ) . equals ( String . valueOf ( bookingId ) ) ) {
calendar . setEveningSlot ( false ) ;
calendar . setBookingId_2 ( null ) ;
}
bookingCalendarRepository . save ( calendar ) ;
}
String rescheduledmsg = "Your booking ID " + bookingId + " on " + starting + " has been successfully rescheduled to " + startDate + ". Thanks for using the GCC Community Hall Booking System." ;
String urlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + bookingDetails . getUsers ( ) . getMobileNo ( ) + "&from=GCCCRP&body=" + rescheduledmsg + "&entityid=1401572690000011081&templateid=1407172346565044999" ;
@ -1829,7 +1698,7 @@ public class BookingServiceImpl implements BookingService {
. orElseThrow ( ( ) - > new RuntimeException ( "Hall not found" ) ) ;
/ / Fetch BookingDetails with GCC_BLOCKED status
List < BookingDetails > bookingDetails = bookingDetailsRepository . findByHallDetailsAndBookingStatus ( hallDetails , BookingStatus . GCC_BLOCKED ) ;
List < BookingDetails > bookingDetails = bookingDetailsRepository . findByHallDetailsAndBookingStatus ( hallDetails , BookingDetails . BookingStatus . GCC_BLOCKED ) ;
/ / Fetch GccBlockingDate with BLOCKED status
List < GccBlockingDate > gccBlockingDates = gccBlockingDateRepository . findAllByHallIdAndBlockedStatus ( hallId , GccBlockingDate . BlockedStatus . BLOCKED ) ;
@ -1846,6 +1715,7 @@ public class BookingServiceImpl implements BookingService {
public int getBlockedHallCount ( String blockingReason , Date startDate , Date endDate ) {
return gccBlockingDateRepository . countBlockedHallsInDateRange ( blockingReason , startDate , endDate ) ;
}
public boolean isBlockingRecordExists ( String fromDate , String toDate , List < Long > hallIdsList ) {
LocalDate fromdate = LocalDate . parse ( fromDate ) ;
LocalDate todate = LocalDate . parse ( toDate ) ;
@ -1865,15 +1735,24 @@ public class BookingServiceImpl implements BookingService {
BookingDetails booking = optionalBooking . get ( ) ;
BookingStatus currentStatus = booking . getBookingStatus ( ) ;
if ( currentStatus = = BookingStatus . APPROVED ) {
if ( currentStatus = = BookingStatus . APPROVED | | currentStatus = = BookingStatus . WAITING_FOR_NOC | |
currentStatus = = BookingStatus . WAITING_FOR_NOC_APPROVAL ) {
booking . setBookingStatus ( BookingStatus . GCC_BLOCKED ) ;
List < BookingCalendar > calendardata = getCancellingdata1 ( bookingId . toString ( ) ) ;
for ( BookingCalendar bb : calendardata ) {
if ( bookingId ! = 0 & & bb . getBookingId_1 ( ) ! = null & &
bookingId . equals ( Integer . valueOf ( bb . getBookingId_1 ( ) ) ) ) {
bb . setBookingId_1 ( null ) ;
bb . setBookingId_2 ( null ) ;
bb . setMorningSlot ( false ) ;
}
if ( bookingId ! = 0 & & bb . getBookingId_2 ( ) ! = null & &
bookingId . equals ( Integer . valueOf ( bb . getBookingId_2 ( ) ) ) ) {
bb . setBookingId_2 ( null ) ;
bb . setEveningSlot ( false ) ;
}
/ / bb . setIs_blocked ( true ) ;
updateBookingStatus ( bb ) ;
}
/ / GCC blocking entry
GccBlockingDate gcc = new GccBlockingDate ( ) ;
@ -1945,19 +1824,19 @@ public class BookingServiceImpl implements BookingService {
book . setHallId ( hallId . intValue ( ) ) ;
book . setIs_active ( true ) ;
book . setIs_booked ( 2 ) ;
book . setIs_blocked ( true ) ;
book . setIs_delete ( false ) ;
book . setIs_blocked ( true ) ;
updateBookingStatus ( book ) ;
}
}
}
}
updateBookingStatusById ( booking . getBookingId ( ) , booking . getBookingStatus ( ) . GCC_BLOCKED , reasonforblocking ) ;
/ / whatsup msg and SMS
String gccblockedsms = "Your booking ID " + bookingId + " on " + booking . getStartDate ( ) + " has been blocked by GCC due to " + reasonforblocking + ". The entire amount paid will be refunded to your account with in 3 to 15 days." ;
String gccblockedurlString = "https://tmegov.onex-aura.com/api/sms?key=pfTEYN6H&to=" + booking . getUsers ( ) . getMobileNo ( ) + "&from=GCCCRP&body=" + gccblockedsms + "&entityid=1401572690000011081&templateid=1407172346521513227" ;
/ / String gccblockedwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + booking . getUsers ( ) . getMobileNo ( ) + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" + booking . getBookingId ( ) + "+on+" + booking . getBookingDate ( ) + "+has+been+blocked+by+GCC+due+to+" + reasonforblocking + ".+%0AThanks+for+using+GCC+Community+Hall+Booking+System." ;
String gccblockedwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + booking . getUsers ( ) . getMobileNo ( ) + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" + booking . getBookingId ( ) + "+on+" + booking . getBooking Date ( ) + "+has+been+blocked+by+the+GCC+due+to+Goverment+event++.+%0AThe+entire+amount+paid+will+be+refunded+to+your+account+within+3+to+15+days." ;
String gccblockedwhatsupmsg = "https://media.smsgupshup.com/GatewayAPI/rest?userid=2000233507&password=h2YjFNcJ&send_to=" + booking . getUsers ( ) . getMobileNo ( ) + "&v=1.1&format=json&msg_type=TEXT&method=SENDMESSAGE&msg=Your+booking+with+ID+" + booking . getBookingId ( ) + "+on+" + booking . getStart Date ( ) + "+has+been+blocked+by+the+GCC+due+to+Goverment+event++.+%0AThe+entire+amount+paid+will+be+refunded+to+your+account+within+3+to+15+days." ;
whatsappMsgServiceImpl . sendMsg ( gccblockedwhatsupmsg ) ;
whatsappMsgServiceImpl . sendSMS ( gccblockedurlString ) ;
bookingDetailsRepository . save ( booking ) ;
@ -2037,8 +1916,8 @@ public class BookingServiceImpl implements BookingService {
book . setHallId ( hallId . intValue ( ) ) ;
book . setIs_active ( true ) ;
book . setIs_booked ( 2 ) ;
book . setIs_blocked ( true ) ;
book . setIs_delete ( false ) ;
book . setIs_blocked ( true ) ;
updateBookingStatus ( book ) ;
}
}
@ -2195,6 +2074,7 @@ public class BookingServiceImpl implements BookingService {
/ / TODO Auto - generated method stub
return bookingDetailsRepository . getBookingDetailsByEventDateWithStatus ( fromDate , toDate , bookingStatus , zone , division , hallid ) ;
}
@Override
public List < Object [ ] > getAllPaymentsDetails ( String fromDate , String toDate , String paymentStatus , String zone , String division , Integer hallid ) {
/ / TODO Auto - generated method stub
@ -2333,17 +2213,17 @@ public class BookingServiceImpl implements BookingService {
/ / gccapps
@Override
public List < BookingDetails > getApprovedBookingDetails ( ) {
return bookingDetailsRepository . findByBookingStatus ( BookingStatus . APPROVED ) ;
return bookingDetailsRepository . findByBookingStatus ( BookingDetails . BookingStatus . APPROVED ) ;
}
@Override
public List < BookingDetails > getRejectedBookingDetails ( ) {
return bookingDetailsRepository . findByBookingStatus ( BookingStatus . REJECTED ) ;
return bookingDetailsRepository . findByBookingStatus ( BookingDetails . BookingStatus . REJECTED ) ;
}
@Override
public List < BookingDetails > getWaitingforNOCapproval ( ) {
return bookingDetailsRepository . findByBookingStatus ( BookingStatus . WAITING_FOR_NOC_APPROVAL ) ;
return bookingDetailsRepository . findByBookingStatus ( BookingDetails . BookingStatus . WAITING_FOR_NOC_APPROVAL ) ;
}
@Override
@ -2391,14 +2271,22 @@ public class BookingServiceImpl implements BookingService {
public List < Object [ ] > getTransactionresponse ( String fromDate , String toDate , Long bookingId , Long hallId ) {
return transactionResponseRepository . getTransactionResponseByBookingId ( fromDate , toDate , bookingId , hallId ) ;
}
@Override
public List < Object [ ] > getRefundResponse ( String fromDate , String toDate , Long bookingId ) {
return transRefundResRepository . getRefundResponseByBookingId ( fromDate , toDate , bookingId ) ;
}
@Override
public List < Object [ ] > getBookingCalendarDetails ( String fromDate , String toDate , Long bookingId , String hallName ) {
return bookingCalendarRepository . findBookingCalendarDetails ( fromDate , toDate , bookingId , hallName ) ;
}
@Override
public List < BookingDetails > getBookingsByDateAndHall ( String bookingDate , Long hallId ) {
LocalDate date = LocalDate . parse ( bookingDate ) ; / / Ensure format matches yyyy - MM - dd
return bookingDetailsRepository . findByBookingDateAndHallId ( date , hallId ) ;
}
}