@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestParam ;
import org.springframework.web.bind.annotation.ResponseBody ;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ;
import org.springframework.web.multipart.MultipartFile ;
@ -43,6 +44,8 @@ import com.gcc.communityHall.entity.HallDetails;
import com.gcc.communityHall.entity.Notification ;
import com.gcc.communityHall.entity.Settlement ;
import com.gcc.communityHall.entity.Users ;
import com.gcc.communityHall.entity.Login ;
import com.gcc.communityHall.entity.LoginHallId ;
import com.gcc.communityHall.others.UserSession ;
import com.gcc.communityHall.paymentService.entity.TransactionResponse ;
import com.gcc.communityHall.paymentService.repository.TransactionResponseRepository ;
@ -54,12 +57,15 @@ import com.gcc.communityHall.repository.HallDetailsRepository;
import com.gcc.communityHall.repository.NotificationRepository ;
import com.gcc.communityHall.repository.SettlementRepository ;
import com.gcc.communityHall.repository.UsersRepository ;
import com.gcc.communityHall.repository.LoginHallIdRepository ;
import com.gcc.communityHall.repository.LoginRepository ;
import com.gcc.communityHall.service.BookingService ;
import com.gcc.communityHall.service.HallDetailService ;
import com.gcc.communityHall.service.ReasonMasterService ;
import com.gcc.communityHall.service.UserService ;
import jakarta.servlet.http.HttpSession ;
import jakarta.transaction.Transactional ;
@Controller
@RequestMapping ( "/communityhall/admin" )
@ -110,6 +116,12 @@ public class Admincontroller {
@Autowired
private TransactionResponseRepository transactionResponseRepository ;
@Autowired
private LoginRepository loginRepository ;
@Autowired
private LoginHallIdRepository loginHallIdRepository ;
@GetMapping ( "/dashboard" )
public String viewDashboard (
@RequestParam ( required = false , defaultValue = "all zones" ) String zone ,
@ -147,7 +159,6 @@ public class Admincontroller {
}
}
@GetMapping ( "/Reports" )
public String viewReports ( Model model , HttpSession session ) {
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
@ -174,7 +185,6 @@ public class Admincontroller {
}
}
@GetMapping ( "/HallDetails" )
public String viewHallDetails ( Model model , HttpSession session ) {
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
@ -287,8 +297,10 @@ public class Admincontroller {
String zone = ( String ) session . getAttribute ( "zone" ) ;
model . addAttribute ( "zone" , zone ) ;
List < BookingDetails > settlementrefundfailed = bookingDetailsRepository . findAllSettlementRefundFailed ( ) ;
List < BookingDetails > refundfailedcancelledbookings = bookingDetailsRepository . findAllRefundFaileCancelledList ( ) ;
List < BookingDetails > refundfailedrejectedbookings = bookingDetailsRepository . findAllRefundFaileRejectedList ( ) ;
List < BookingDetails > refundfailedcancelledbookings = bookingDetailsRepository
. findAllRefundFaileCancelledList ( ) ;
List < BookingDetails > refundfailedrejectedbookings = bookingDetailsRepository
. findAllRefundFaileRejectedList ( ) ;
model . addAttribute ( "settlementrefundfailed" , settlementrefundfailed ) ;
model . addAttribute ( "refundfailedcancelledbookings" , refundfailedcancelledbookings ) ;
model . addAttribute ( "refundfailedrejectedbookings" , refundfailedrejectedbookings ) ;
@ -392,6 +404,20 @@ public class Admincontroller {
}
}
/ / ─ ─ New enhanced GCC Blocking page ( does NOT affect the existing page ) ─ ─
@GetMapping ( "/GccblockingNew" )
public String viewGccBlockingNew ( Model model , HttpSession session ) {
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
if ( adminname ! = null ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "adminname" , adminname ) ;
return "admin/gccblocking-new" ;
} else {
session . invalidate ( ) ;
return "redirect:/communityhall/login" ;
}
}
/ / Utility method to ensure distinct by a key
private static < T > Predicate < T > distinctByKey ( Function < ? super T , ? > keyExtractor ) {
@ -410,7 +436,7 @@ public class Admincontroller {
@RequestParam float hallArea ,
@RequestParam String ebNumber ,
@RequestParam float ebCostPerUnit ,
@RequestParam int parkingCapacity ,
@RequestParam String parkingCapacity ,
@RequestParam int seatingCapacity ,
@RequestParam String doorNo ,
@RequestParam String street ,
@ -426,8 +452,10 @@ public class Admincontroller {
@RequestParam long hallInchargeNo ,
@RequestParam ( "hallImages" ) MultipartFile [ ] hallImages , HttpSession session ) {
String updatedId = ( String ) session . getAttribute ( "employeeId" ) ;
hallDetailService . saveHall ( hallName , depositAmount , halfDayAmt , fullDayAmt , gst , hallArea , ebNumber , ebCostPerUnit , parkingCapacity , seatingCapacity , doorNo ,
street , area , zone , division , landMark , city , pinCode , latitude , longitude , hallInchargeName , hallInchargeNo , updatedId , hallImages , halfdepositAmt ) ;
hallDetailService . saveHallByAdmin ( hallName , depositAmount , halfDayAmt , fullDayAmt , gst , hallArea , ebNumber ,
ebCostPerUnit , parkingCapacity , seatingCapacity , doorNo ,
street , area , zone , division , landMark , city , pinCode , latitude , longitude , hallInchargeName ,
hallInchargeNo , updatedId , hallImages , halfdepositAmt ) ;
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
Integer loginid = ( Integer ) session . getAttribute ( "id" ) ;
ApplicationLogs logs = new ApplicationLogs ( ) ;
@ -444,7 +472,8 @@ public class Admincontroller {
e . printStackTrace ( ) ;
}
applicationLogsRepository . save ( logs ) ;
/ / Redirect to a success page or return a ModelAndView as per your application flow
/ / Redirect to a success page or return a ModelAndView as per your application
/ / flow
return "redirect:/communityhall/admin/halldetailslist" ;
}
@ -573,33 +602,45 @@ public class Admincontroller {
@RequestParam ( name = "basedon" , required = false ) String basedon ,
@RequestParam ( name = "bookingId" , required = false ) Long bookingId ,
@RequestParam ( name = "reporttype" , required = false ) String reporttype ,
@RequestParam ( name = "counterId" , required = false ) String counterId , HttpSession session ) throws JsonProcessingException {
@RequestParam ( name = "counterId" , required = false ) String counterId , HttpSession session )
throws JsonProcessingException {
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
if ( adminname ! = null ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
List < Users > userList = handleUserRequest ( request , fromDate , toDate , userstatus , usertype ) ;
List < Object [ ] > bookingList = handleBookingRequest ( request , fromDate , toDate , bookingStatus , filterby , bookingId , zone , division , hallid ) ;
List < BookingDetails > bookingSettlementList = handleBookingSettlementRequest ( request , fromDate , toDate , refundStatus , filterby ) ;
/ / List < Object [ ] > paymentList = request . equals ( "3" ) ? bookingService . getAllPaymentsDetails ( fromDate , toDate , zone , division , hallid ) : new ArrayList < > ( ) ;
List < Object [ ] > bookingList = handleBookingRequest ( request , fromDate , toDate , bookingStatus , filterby ,
bookingId , zone , division , hallid ) ;
List < BookingDetails > bookingSettlementList = handleBookingSettlementRequest ( request , fromDate , toDate ,
refundStatus , filterby ) ;
/ / List < Object [ ] > paymentList = request . equals ( "3" ) ?
/ / bookingService . getAllPaymentsDetails ( fromDate , toDate , zone , division , hallid ) :
/ / new ArrayList < > ( ) ;
List < Object [ ] > paymentList = new ArrayList < > ( ) ;
List < Object [ ] > extrapaymentList = new ArrayList < > ( ) ;
if ( request . equals ( "3" ) ) {
if ( paymentStatus = = null | | paymentStatus . isEmpty ( ) ) {
paymentList = bookingService . getAllPaymentsDetails ( fromDate , toDate , null , zone , division , hallid ) ;
} else {
paymentList = bookingService . getAllPaymentsDetails ( fromDate , toDate , paymentStatus , zone , division , hallid ) ;
paymentList = bookingService . getAllPaymentsDetails ( fromDate , toDate , paymentStatus , zone , division ,
hallid ) ;
}
}
if ( request . equals ( "8" ) ) {
if ( paymentStatus = = null | | paymentStatus . isEmpty ( ) ) {
extrapaymentList = bookingService . getAllExtraPaymentsDetails ( fromDate , toDate , null , zone , division , hallid ) ;
extrapaymentList = bookingService . getAllExtraPaymentsDetails ( fromDate , toDate , null , zone , division ,
hallid ) ;
} else {
extrapaymentList = bookingService . getAllExtraPaymentsDetails ( fromDate , toDate , paymentStatus , zone , division , hallid ) ;
extrapaymentList = bookingService . getAllExtraPaymentsDetails ( fromDate , toDate , paymentStatus , zone ,
division , hallid ) ;
}
}
List < Object [ ] > userbookingList = request . equals ( "4" ) ? bookingService . getBookingUserDetailsReport ( fromDate , toDate ) : new ArrayList < > ( ) ;
/ / List < Object [ ] > hallbookingList = request . equals ( "5" ) ? bookingService . getBookingHallDetailsReport ( fromDate , toDate ) : new ArrayList < > ( ) ;
List < Object [ ] > userbookingList = request . equals ( "4" )
? bookingService . getBookingUserDetailsReport ( fromDate , toDate )
: new ArrayList < > ( ) ;
/ / List < Object [ ] > hallbookingList = request . equals ( "5" ) ?
/ / bookingService . getBookingHallDetailsReport ( fromDate , toDate ) : new
/ / ArrayList < > ( ) ;
/ / In your controller method
/ / Fetch booking count by zone
List < Object [ ] > totalcount = new ArrayList < > ( ) ;
@ -626,7 +667,8 @@ public class Admincontroller {
model . addAttribute ( "basedon" , basedon ) ;
model . addAttribute ( "totalcount" , totalcount ) ;
model . addAttribute ( "totalBookings" , totalBookings ) ;
List < Object [ ] > hallbookingList = handleBookingHallDetailsReportRequest ( request , fromDate , toDate , filterby , zone , division , hallid ) ;
List < Object [ ] > hallbookingList = handleBookingHallDetailsReportRequest ( request , fromDate , toDate , filterby ,
zone , division , hallid ) ;
if ( "9" . equals ( request ) ) {
if ( "abstract" . equals ( reporttype ) ) {
@ -635,13 +677,14 @@ public class Admincontroller {
model . addAttribute ( "counterBookingList" , counterBookingList ) ;
System . out . println ( "counterBookingList.." + counterBookingList ) ;
List < Object [ ] > hallBookingByCounter = bookingService . getHallWiseBookingDetails ( fromDate , toDate , counterId ) ;
List < Object [ ] > hallBookingByCounter = bookingService . getHallWiseBookingDetails ( fromDate , toDate ,
counterId ) ;
/ / Convert to JSON for JS usage
String hallBookingJson = new ObjectMapper ( ) . writeValueAsString ( hallBookingByCounter ) ;
model . addAttribute ( "hallBookingJson" , hallBookingJson ) ;
List < Object [ ] > hallBookingDetails = bookingService . getBookingDetailsForAllHalls ( fromDate , toDate , counterId , hallid ) ;
List < Object [ ] > hallBookingDetails = bookingService . getBookingDetailsForAllHalls ( fromDate , toDate ,
counterId , hallid ) ;
String hallBookingDetailsJson = new ObjectMapper ( ) . writeValueAsString ( hallBookingDetails ) ;
model . addAttribute ( "hallBookingDetailsJson" , hallBookingDetailsJson ) ;
@ -702,7 +745,6 @@ public class Admincontroller {
model . addAttribute ( "adminname" , adminname ) ;
System . out . println ( "request" + request ) ;
return "admin/reports" ;
} else {
session . invalidate ( ) ; / / Invalidate the session to clear all session attributes
@ -710,7 +752,8 @@ public class Admincontroller {
}
}
private List < Object [ ] > handleBookingHallDetailsReportRequest ( String request , String fromDate , String toDate , String filterby , String zone , String division , Integer hallid ) {
private List < Object [ ] > handleBookingHallDetailsReportRequest ( String request , String fromDate , String toDate ,
String filterby , String zone , String division , Integer hallid ) {
if ( ! request . equals ( "5" ) ) {
return new ArrayList < > ( ) ;
}
@ -731,7 +774,8 @@ public class Admincontroller {
return new ArrayList < > ( ) ;
}
private List < Users > handleUserRequest ( String request , String fromDate , String toDate , String userstatus , String usertype ) {
private List < Users > handleUserRequest ( String request , String fromDate , String toDate , String userstatus ,
String usertype ) {
if ( ! request . equals ( "1" ) ) {
return new ArrayList < > ( ) ;
}
@ -747,8 +791,8 @@ public class Admincontroller {
return userService . getAllUsers ( fromDate , toDate ) ;
}
private List < Object [ ] > handleBookingRequest ( String request , String fromDate , String toDate , String bookingStatus , String filterby , Long bookingId , String zone , String division , Integer hallid ) {
private List < Object [ ] > handleBookingRequest ( String request , String fromDate , String toDate , String bookingStatus ,
String filterby , Long bookingId , String zone , String division , Integer hallid ) {
if ( ! request . equals ( "2" ) ) {
return new ArrayList < > ( ) ;
}
@ -759,10 +803,12 @@ public class Admincontroller {
return bookingDetailsRepo . getAllBookingDetailsWithBookingId ( fromDate , toDate , bookingId ) ;
}
if ( bookingId ! = null & & ! bookingStatus . isEmpty ( ) ) {
return bookingDetailsRepo . getAllBookingDetailsWithBookingIdwithbookingStatus ( fromDate , toDate , bookingId , bookingStatus ) ;
return bookingDetailsRepo . getAllBookingDetailsWithBookingIdwithbookingStatus ( fromDate , toDate , bookingId ,
bookingStatus ) ;
}
if ( bookingId = = null & & filterby . isEmpty ( ) & & ! bookingStatus . isEmpty ( ) ) {
return bookingService . getBookingDetailsByBookingDateWithStatus ( fromDate , toDate , bookingStatus , zone , division , hallid ) ;
return bookingService . getBookingDetailsByBookingDateWithStatus ( fromDate , toDate , bookingStatus , zone ,
division , hallid ) ;
}
if ( ! filterby . isEmpty ( ) ) {
@ -770,7 +816,8 @@ public class Admincontroller {
if ( bookingStatus . isEmpty ( ) ) {
return bookingService . getBookingDetailsByBookingDate ( fromDate , toDate , zone , division , hallid ) ;
} else {
return bookingService . getBookingDetailsByBookingDateWithStatus ( fromDate , toDate , bookingStatus , zone , division , hallid ) ;
return bookingService . getBookingDetailsByBookingDateWithStatus ( fromDate , toDate , bookingStatus ,
zone , division , hallid ) ;
}
}
@ -778,7 +825,8 @@ public class Admincontroller {
if ( bookingStatus . isEmpty ( ) ) {
return bookingService . getBookingDetailsByEventDate ( fromDate , toDate , zone , division , hallid ) ;
} else {
return bookingService . getBookingDetailsByEventDateWithStatus ( fromDate , toDate , bookingStatus , zone , division , hallid ) ;
return bookingService . getBookingDetailsByEventDateWithStatus ( fromDate , toDate , bookingStatus , zone ,
division , hallid ) ;
}
}
@ -787,8 +835,8 @@ public class Admincontroller {
return new ArrayList < > ( ) ;
}
private List < BookingDetails > handleBookingSettlementRequest ( String request , String fromDate , String toDate , String refundStatus , String filterby ) {
private List < BookingDetails > handleBookingSettlementRequest ( String request , String fromDate , String toDate ,
String refundStatus , String filterby ) {
if ( ! request . equals ( "6" ) ) {
return new ArrayList < > ( ) ;
}
@ -804,7 +852,8 @@ public class Admincontroller {
if ( refundStatus . isEmpty ( ) ) {
return bookingService . getAllBookingsettlementDetailsByBookingDate ( fromDate , toDate ) ;
} else {
return bookingService . getAllBookingsettlementDetailsByBookingDateWithStatus ( fromDate , toDate , refundStatus ) ;
return bookingService . getAllBookingsettlementDetailsByBookingDateWithStatus ( fromDate , toDate ,
refundStatus ) ;
}
}
@ -812,7 +861,8 @@ public class Admincontroller {
if ( refundStatus . isEmpty ( ) ) {
return bookingService . getAllBookingsettlementDetailsByEventDate ( fromDate , toDate ) ;
} else {
return bookingService . getAllBookingsettlementDetailsByEventDateWithStatus ( fromDate , toDate , refundStatus ) ;
return bookingService . getAllBookingsettlementDetailsByEventDateWithStatus ( fromDate , toDate ,
refundStatus ) ;
}
}
@ -897,7 +947,8 @@ public class Admincontroller {
/ / model . addAttribute ( "mobileno" , mobileno ) ;
/ / return "admin/developer" ;
/ / } else {
/ / session . invalidate ( ) ; / / Invalidate the session to clear all session attributes
/ / session . invalidate ( ) ; / / Invalidate the session to clear all session
/ / attributes
/ / return "redirect:/communityhall/login" ;
/ / }
/ / }
@ -910,7 +961,6 @@ public class Admincontroller {
@RequestParam ( name = "hallId" , required = false ) Long hallId ,
@RequestParam ( name = "hallName" , required = false ) String hallName , HttpSession session ) {
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
if ( adminname ! = null ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
@ -941,11 +991,13 @@ public class Admincontroller {
/ / if ( hallName . isEmpty ( ) ) {
/ / System . out . println ( "check1" ) ;
/ / / / Fetch all details for the given date range
/ / BookingCalendar = bookingService . getBookingCalendarDetails ( fromDate , toDate , hallName ) ;
/ / BookingCalendar = bookingService . getBookingCalendarDetails ( fromDate ,
/ / toDate , hallName ) ;
/ / } else {
/ / System . out . println ( "check2" ) ;
/ / / / Fetch filtered details based on hallName
/ / BookingCalendar = bookingService . getBookingCalendarDetails ( fromDate , toDate , hallName ) ;
/ / BookingCalendar = bookingService . getBookingCalendarDetails ( fromDate , toDate ,
/ / hallName ) ;
/ / }
BookingCalendar = bookingService . getBookingCalendarDetails ( fromDate , toDate , bookingId , hallName ) ;
}
@ -1045,7 +1097,6 @@ public class Admincontroller {
}
}
@GetMapping ( "/logout" )
public String viewLogout ( Model model , HttpSession session ) {
session . invalidate ( ) ;
@ -1072,5 +1123,255 @@ public class Admincontroller {
}
}
/ / care taker , counter and officer login creation added by kanimozhi 15062026
@GetMapping ( "/login-creation" )
public String viewLoginCreation ( Model model , HttpSession session ) {
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
if ( adminname ! = null & & "admin" . equals ( adminname ) ) {
long mobileno = ( long ) session . getAttribute ( "mobileno" ) ;
model . addAttribute ( "mobileno" , mobileno ) ;
model . addAttribute ( "adminname" , adminname ) ;
/ / Fetch existing active non - admin logins ( returns projection , not full entity )
List < Map < String , Object > > loginList = loginRepository . findActiveLogins ( ) ;
model . addAttribute ( "loginList" , loginList ) ;
/ / Fetch hall details for the modal dropdown
List < Map < String , Object > > hallList = hallDetailsRepo . getAllHalls ( ) ;
model . addAttribute ( "hallList" , hallList ) ;
return "admin/login-creation" ;
} else {
session . invalidate ( ) ;
return "redirect:/communityhall/login" ;
}
}
@PostMapping ( "/login-creation/save" )
@ResponseBody
@Transactional
public Map < String , Object > saveLoginCreation (
@RequestParam ( "mobileNumber" ) long mobileNumber ,
@RequestParam ( "name" ) String name ,
@RequestParam ( "password" ) String password ,
@RequestParam ( "userType" ) String userType ,
@RequestParam ( "zone" ) String zone ,
@RequestParam ( value = "hallIds" , required = false ) List < Integer > hallIds ,
HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
if ( adminname = = null & & "admin" . equals ( adminname ) ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Session expired. Please log in again." ) ;
return response ;
}
try {
/* -------- Duplicate hall check for counter / caretaker -------- */
boolean isSingleMode = "counter" . equals ( userType ) | | "caretaker" . equals ( userType ) ;
boolean isMulitpleMode = "officer" . equals ( userType ) ;
if ( isSingleMode & & hallIds ! = null & & ! hallIds . isEmpty ( ) ) {
int hallId = hallIds . get ( 0 ) ;
int existingCount = loginRepository . countActiveLoginsByHallId ( hallId , userType ) ;
if ( existingCount > 0 ) {
/ / Fetch hall name for a clear message
String hallName = hallId + "" ;
try {
String fetched = hallDetailsRepo . findHallNameById ( hallId ) ;
if ( fetched ! = null & & ! fetched . isBlank ( ) )
hallName = fetched ;
} catch ( Exception ignored ) {
}
response . put ( "status" , "error" ) ;
response . put ( "message" , "A login already exists for hall \"" + hallName
+ "\". Only one counter/caretaker login is allowed per hall." ) ;
return response ;
}
}
/* -------- Duplicate hall check for officer -------- */
if ( isMulitpleMode & & hallIds ! = null & & ! hallIds . isEmpty ( ) ) {
int existingCount = loginRepository . getActiveLoginsByHallIds ( hallIds , userType ) ;
if ( existingCount > 0 ) {
response . put ( "status" , "error" ) ;
response . put ( "message" ,
"A login already exists for the selected hall(s). Only one officer login is allowed per hall." ) ;
return response ;
}
}
Login login = new Login ( ) ;
login . setMobileNumber ( mobileNumber ) ;
login . setName ( name ) ;
login . setPassword ( password ) ;
login . setUserType ( userType ) ;
login . setZone ( zone ) ;
login . setActive ( true ) ;
login . setDelete ( false ) ;
if ( hallIds = = null | | hallIds . isEmpty ( ) ) {
/ / HQ may have no hall assigned
loginRepository . save ( login ) ;
} else if ( hallIds . size ( ) = = 1 ) {
/ / Single hall : store directly in login . hallId
login . setHallId ( hallIds . get ( 0 ) ) ;
loginRepository . save ( login ) ;
} else {
/ / Multiple halls : store first in hallId , rest in login_hall_ids
login . setHallId ( hallIds . get ( 0 ) ) ;
Login savedLogin = loginRepository . save ( login ) ;
for ( int hallId : hallIds ) {
LoginHallId loginHallId = new LoginHallId ( savedLogin , hallId ) ;
loginHallIdRepository . save ( loginHallId ) ;
}
}
response . put ( "status" , "success" ) ;
response . put ( "message" , "Login created successfully." ) ;
} catch ( Exception e ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Error creating login: " + e . getMessage ( ) ) ;
}
return response ;
}
@PostMapping ( "/login-creation/delete/{id}" )
@ResponseBody
@Transactional
public Map < String , Object > deleteLogin ( @PathVariable ( "id" ) int id , HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
String adminname = ( String ) session . getAttribute ( "usertype" ) ;
if ( adminname = = null & & "admin" . equals ( adminname ) ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Session expired. Please log in again." ) ;
return response ;
}
try {
Login login = loginRepository . findLoginById ( id ) ;
if ( login = = null ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Login not found." ) ;
return response ;
}
/ / Soft delete : set is_active = 0 , is_delete = 1
login . setActive ( false ) ;
login . setDelete ( true ) ;
loginRepository . save ( login ) ;
/ / Also soft - delete any related login_hall_ids
loginHallIdRepository . softDeleteByLoginId ( id ) ;
response . put ( "status" , "success" ) ;
response . put ( "message" , "Login deleted successfully." ) ;
} catch ( Exception e ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Error deleting login: " + e . getMessage ( ) ) ;
}
return response ;
}
@GetMapping ( "/login-creation/check-mobile" )
@ResponseBody
public Map < String , Object > checkMobileExists ( @RequestParam ( "mobileNumber" ) long mobileNumber , HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
try {
int count = loginRepository . countByMobileNumber ( mobileNumber ) ;
response . put ( "exists" , count > 0 ) ;
} catch ( Exception e ) {
response . put ( "exists" , false ) ;
response . put ( "error" , e . getMessage ( ) ) ;
}
return response ;
}
@GetMapping ( "/login-creation/halls-by-zone" )
@ResponseBody
public List < Map < String , Object > > getHallsByZone ( @RequestParam ( "zone" ) String zone , HttpSession session ) {
try {
return hallDetailsRepo . getHallsByZone ( zone ) ;
} catch ( Exception e ) {
return new java . util . ArrayList < > ( ) ;
}
}
@GetMapping ( "/login-creation/get-login-halls" )
@ResponseBody
public Map < String , Object > getLoginHalls ( @RequestParam ( "loginId" ) int loginId , HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
try {
Login login = loginRepository . findLoginById ( loginId ) ;
if ( login = = null ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Login not found." ) ;
return response ;
}
/ / Collect all assigned hall IDs
java . util . List < Integer > assignedHallIds = new java . util . ArrayList < > ( ) ;
if ( login . getHallId ( ) ! = 0 ) {
assignedHallIds . add ( login . getHallId ( ) ) ;
}
loginHallIdRepository . findActiveByLoginId ( loginId ) . forEach ( lh - > assignedHallIds . add ( lh . getHallId ( ) ) ) ;
response . put ( "status" , "success" ) ;
response . put ( "loginId" , loginId ) ;
response . put ( "name" , login . getName ( ) ) ;
response . put ( "zone" , login . getZone ( ) ) ;
response . put ( "userType" , login . getUserType ( ) ) ;
response . put ( "assignedHallIds" , assignedHallIds ) ;
/ / Also return all halls for the zone
response . put ( "hallsForZone" , hallDetailsRepo . getHallsByZone ( login . getZone ( ) ) ) ;
} catch ( Exception e ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Error fetching login halls: " + e . getMessage ( ) ) ;
}
return response ;
}
@PostMapping ( "/login-creation/update-halls" )
@ResponseBody
@Transactional
public Map < String , Object > updateLoginHalls (
@RequestParam ( "loginId" ) int loginId ,
@RequestParam ( "hallIds" ) java . util . List < Integer > hallIds ,
HttpSession session ) {
Map < String , Object > response = new HashMap < > ( ) ;
try {
Login login = loginRepository . findLoginById ( loginId ) ;
if ( login = = null ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Login not found." ) ;
return response ;
}
if ( hallIds = = null | | hallIds . isEmpty ( ) ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "At least one hall must be selected." ) ;
return response ;
}
/ / Clear all existing login_hall_ids rows for this login
loginHallIdRepository . softDeleteByLoginId ( loginId ) ;
if ( hallIds . size ( ) = = 1 ) {
/ / Single hall : store in login . hall_id only
login . setHallId ( hallIds . get ( 0 ) ) ;
loginRepository . save ( login ) ;
} else {
/ / Multiple halls : first goes to login . hall_id , rest to login_hall_ids
login . setHallId ( hallIds . get ( 0 ) ) ;
loginRepository . save ( login ) ;
for ( int i = 1 ; i < hallIds . size ( ) ; i + + ) {
LoginHallId lh = new LoginHallId ( login , hallIds . get ( i ) ) ;
loginHallIdRepository . save ( lh ) ;
}
}
response . put ( "status" , "success" ) ;
response . put ( "message" , "Hall assignment updated successfully." ) ;
} catch ( Exception e ) {
response . put ( "status" , "error" ) ;
response . put ( "message" , "Error updating halls: " + e . getMessage ( ) ) ;
}
return response ;
}
}