@ -353,12 +353,9 @@ public class VolunteerService {
}
public Map < String , Object > saveVolunteerLocationHistory ( Integer volunteerId , String mid , String latitude ,
String longitude , String activeStatu s) {
String longitude , String zone , String ward , String addres s) {
Map < String , Object > response = new HashMap < > ( ) ;
activeStatus = activeStatus . equals ( "A" ) ? "1" : "0" ;
int aS = Integer . parseInt ( activeStatus ) ;
if ( volunteerId = = null | | volunteerId < = 0 ) {
response . put ( "status" , 400 ) ;
response . put ( "message" , "volunteer_id is required." ) ;
@ -371,6 +368,28 @@ public class VolunteerService {
return response ;
}
String sqlQuery = "select id, latitude, longitude, zone, ward, address, case when is_active = 1 then 'ACTIVE' else 'INACTIVE' END as active_status from volunteer_active_history where volunteer_id = ? order by id desc limit 1" ;
try {
List < Map < String , Object > > activeRecords = jdbcTemplate . queryForList ( sqlQuery , volunteerId ) ;
if ( activeRecords . isEmpty ( ) ) {
response . put ( "status" , 200 ) ;
response . put ( "message" , "No active record found." ) ;
return response ;
}
if ( activeRecords . get ( 0 ) . get ( "active_status" ) . equals ( "INACTIVE" ) ) {
response . put ( "status" , 200 ) ;
response . put ( "message" , "Active status is already INACTIVE. Kindly make the Active status as ACTIVE." ) ;
return response ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
response . put ( "status" , 500 ) ;
response . put ( "message" , "Failed to save volunteer location history: " + e . getMessage ( ) ) ;
return response ;
}
/ / String midVal = ( mid ! = null & & ! mid . trim ( ) . isEmpty ( ) ) ? mid . trim ( ) : null ;
try {
@ -380,14 +399,13 @@ public class VolunteerService {
jdbcTemplate . update ( disableSql , volunteerId ) ;
/ / Insert the new entry
String insertSql = "INSERT INTO volunteer_location_history (volunteer_id, mid, latitude, longitude, is_active, is_delete, cdate) VALUES (?, ?, ?, ?, ?, 0, NOW())" ;
jdbcTemplate . update ( insertSql , volunteerId , mid , latitude . trim ( ) , longitude . trim ( ) , aS ) ;
String insertSql = "INSERT INTO volunteer_location_history (volunteer_id, mid, latitude, longitude, cdate, zone, ward, address) VALUES (?, ?, ?, ?, NOW(), ?, ?, ?)" ;
jdbcTemplate . update ( insertSql , volunteerId , mid , latitude . trim ( ) , longitude . trim ( ) , zone , ward ,
address ) ;
activeStatus = activeStatus . equals ( "1" ) ? "Active" : "In-Active" ;
response . put ( "status" , 200 ) ;
response . put ( "message" , "Volunteer location history saved successfully." ) ;
response . put ( "volunteer_id" , volunteerId ) ;
response . put ( "active_status" , activeStatus ) ;
return response ;
} catch ( Exception e ) {
@ -408,7 +426,7 @@ public class VolunteerService {
}
/ / 1 . Check for active VolunteerLoginHistory
String checkLoginSql = "SELECT id FROM volunteer_login _history WHERE volunteer_id = ? AND is_active = 1 AND is_delete = 0 LIMIT 1" ;
String checkLoginSql = "SELECT id FROM volunteer_active _history WHERE volunteer_id = ? AND is_active = 1 AND is_delete = 0 LIMIT 1" ;
List < Map < String , Object > > activeLogins = jdbcTemplate . queryForList ( checkLoginSql , volunteerId ) ;
if ( activeLogins = = null | | activeLogins . isEmpty ( ) ) {
@ -461,7 +479,8 @@ public class VolunteerService {
}
public Map < String , Object > updateComplaintStatus ( Integer volunteerId , Integer complaintId , String status ,
String remarks , List < MultipartFile > file ) {
String remarks , List < MultipartFile > file , String latitude ,
String longitude , String zone , String ward , String address ) {
Map < String , Object > response = new HashMap < > ( ) ;
if ( volunteerId = = null | | complaintId = = null ) {
@ -490,8 +509,9 @@ public class VolunteerService {
if ( fileLocation ! = null & & ! fileLocation . isEmpty ( ) ) {
String insertFileSql = "INSERT INTO volunteer_complaint_files (volunteer_id, complaint_id, file_path) VALUES (?, ?, ?)" ;
jdbcTemplate . update ( insertFileSql , volunteerId , complaintId , fileLocation ) ;
String insertFileSql = "INSERT INTO volunteer_complaint_files (volunteer_id, complaint_id, file_path,latitude,longitude,zone,ward,address) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" ;
jdbcTemplate . update ( insertFileSql , volunteerId , complaintId , fileLocation , latitude , longitude ,
zone , ward , address ) ;
}
}
@ -521,14 +541,23 @@ public class VolunteerService {
public Map < String , Object > getVolunteerLastLocation ( Integer volunteerId ) {
Map < String , Object > response = new HashMap < > ( ) ;
if ( volunteerId = = null | | volunteerId < = 0 ) {
response . put ( "status" , 400 ) ;
response . put ( "message" , "volunteer_id is required." ) ;
return response ;
}
String sqlQuery = "Select id, latitude, longitude, case when is_active = 1 then 'ACTIVE' else 'INACTIVE' END as location_status from volunteer_location_history where volunteer_id = ? order by id desc limit 1" ;
try {
Map < String , Object > result = jdbcTemplate . queryForMap ( sqlQuery , volunteerId ) ;
if ( result . isEmpty ( ) ) {
response . put ( "status" , 404 ) ;
response . put ( "message" , "No volunteer last location found." ) ;
List < Map < String , Object > > resultList = jdbcTemplate . queryForList ( sqlQuery , volunteerId ) ;
if ( resultList = = null | | resultList . isEmpty ( ) ) {
response . put ( "status" , 200 ) ;
response . put ( "active_status" , "INACTIVE" ) ;
response . put ( "message" , "No data found" ) ;
return response ;
}
Map < String , Object > result = resultList . get ( 0 ) ;
response . put ( "status" , 200 ) ;
response . put ( "message" , "Volunteer last location found successfully." ) ;
response . put ( "volunteer_id" , volunteerId ) ;
@ -541,4 +570,82 @@ public class VolunteerService {
return response ;
}
public Map < String , Object > saveVolunteerActiveHistory ( Integer volunteerId , String mid , String latitude ,
String longitude , String activeStatus , String zone , String ward , String address ) {
Map < String , Object > response = new HashMap < > ( ) ;
activeStatus = activeStatus . equals ( "A" ) ? "1" : "0" ;
int aS = Integer . parseInt ( activeStatus ) ;
if ( volunteerId = = null | | volunteerId < = 0 ) {
response . put ( "status" , 400 ) ;
response . put ( "message" , "volunteer_id is required." ) ;
return response ;
}
if ( latitude = = null | | latitude . trim ( ) . isEmpty ( ) | | longitude = = null | | longitude . trim ( ) . isEmpty ( ) ) {
response . put ( "status" , 400 ) ;
response . put ( "message" , "latitude and longitude are required." ) ;
return response ;
}
/ / String midVal = ( mid ! = null & & ! mid . trim ( ) . isEmpty ( ) ) ? mid . trim ( ) : null ;
try {
/ / If one entry is already available for the volunteer_id , make the existing
/ / entry disabled ( is_active = 0 and is_delete = 1 )
String disableSql = "UPDATE volunteer_active_history SET is_active = 0, is_delete = 1 WHERE volunteer_id = ? AND is_active = 1 AND is_delete = 0" ;
jdbcTemplate . update ( disableSql , volunteerId ) ;
/ / Insert the new entry
String insertSql = "INSERT INTO volunteer_active_history (volunteer_id, mid, latitude, longitude, is_active, is_delete, cdate, zone, ward, address) VALUES (?, ?, ?, ?, ?, 0, NOW(), ?, ?, ?)" ;
jdbcTemplate . update ( insertSql , volunteerId , mid , latitude . trim ( ) , longitude . trim ( ) , aS , zone , ward ,
address ) ;
activeStatus = activeStatus . equals ( "1" ) ? "Active" : "In-Active" ;
response . put ( "status" , 200 ) ;
response . put ( "message" , "Volunteer active history saved successfully." ) ;
response . put ( "volunteer_id" , volunteerId ) ;
response . put ( "active_status" , activeStatus ) ;
return response ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
response . put ( "status" , 500 ) ;
response . put ( "message" , "Failed to save volunteer active history: " + e . getMessage ( ) ) ;
return response ;
}
}
public Map < String , Object > getVolunteerLastActiveStatus ( Integer volunteerId ) {
Map < String , Object > response = new HashMap < > ( ) ;
if ( volunteerId = = null | | volunteerId < = 0 ) {
response . put ( "status" , 400 ) ;
response . put ( "message" , "volunteer_id is required." ) ;
return response ;
}
String sqlQuery = "Select id, latitude, longitude, zone, ward, address, case when is_active = 1 then 'ACTIVE' else 'INACTIVE' END as active_status from volunteer_active_history where volunteer_id = ? order by id desc limit 1" ;
try {
List < Map < String , Object > > resultList = jdbcTemplate . queryForList ( sqlQuery , volunteerId ) ;
if ( resultList = = null | | resultList . isEmpty ( ) ) {
response . put ( "status" , 200 ) ;
response . put ( "active_status" , "INACTIVE" ) ;
response . put ( "message" , "No data found" ) ;
return response ;
}
Map < String , Object > result = resultList . get ( 0 ) ;
response . put ( "status" , 200 ) ;
response . put ( "message" , "Volunteer active status found successfully." ) ;
response . put ( "volunteer_id" , volunteerId ) ;
response . put ( "location" , result ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
response . put ( "status" , 500 ) ;
response . put ( "message" , "Failed to get volunteer active status: " + e . getMessage ( ) ) ;
}
return response ;
}
}