diff --git a/src/main/java/in/gov/chennaicorporation/mobileservice/gccVolunteer/controller/VolunteerController.java b/src/main/java/in/gov/chennaicorporation/mobileservice/gccVolunteer/controller/VolunteerController.java index 3b7c67d8..c31b92be 100644 --- a/src/main/java/in/gov/chennaicorporation/mobileservice/gccVolunteer/controller/VolunteerController.java +++ b/src/main/java/in/gov/chennaicorporation/mobileservice/gccVolunteer/controller/VolunteerController.java @@ -52,9 +52,27 @@ public class VolunteerController { @RequestParam(value = "mid", required = false) String mid, @RequestParam(value = "latitude", required = false) String latitude, @RequestParam(value = "longitude", required = false) String longitude, - @RequestParam(value = "active_status", required = false) String activeStatus) { + @RequestParam(value = "zone", required = false) String zone, + @RequestParam(value = "ward", required = false) String ward, + @RequestParam(value = "address", required = false) String address) { - return volunteerService.saveVolunteerLocationHistory(volunteerId, mid, latitude, longitude, activeStatus); + return volunteerService.saveVolunteerLocationHistory(volunteerId, mid, latitude, longitude, zone, + ward, address); + } + + @PostMapping("/saveVolunteerActiveHistory") + public Map saveVolunteerActiveHistory( + @RequestParam(value = "volunteer_id", required = false) Integer volunteerId, + @RequestParam(value = "mid", required = false) String mid, + @RequestParam(value = "latitude", required = false) String latitude, + @RequestParam(value = "longitude", required = false) String longitude, + @RequestParam(value = "active_status", required = false) String activeStatus, + @RequestParam(value = "zone", required = false) String zone, + @RequestParam(value = "ward", required = false) String ward, + @RequestParam(value = "address", required = false) String address) { + + return volunteerService.saveVolunteerActiveHistory(volunteerId, mid, latitude, longitude, activeStatus, zone, + ward, address); } @GetMapping("/getComplaintList") @@ -65,13 +83,25 @@ public class VolunteerController { @PostMapping("/updateComplaintStatus") public Map updateComplaintStatus( - @RequestParam(value = "volunteer_id", required = false) Integer volunteerId, - @RequestParam(value = "complaint_id", required = false) Integer complaintId, + @RequestParam(value = "volunteer_id", required = false) String volunteerId, + @RequestParam(value = "complaint_id", required = false) String complaintId, @RequestParam(value = "status", required = false) String status, @RequestParam(value = "remarks", required = false) String remarks, - @RequestParam(value = "File", required = false) List file) { + @RequestParam(value = "file", required = false) List file, + @RequestParam(value = "latitude", required = false) String latitude, + @RequestParam(value = "longitude", required = false) String longitude, + @RequestParam(value = "zone", required = false) String zone, + @RequestParam(value = "ward", required = false) String ward, + @RequestParam(value = "address", required = false) String address) { + + // List uploadFiles = (file != null && !file.isEmpty()) ? file : + // fileCapital; - return volunteerService.updateComplaintStatus(volunteerId, complaintId, status, remarks, file); + Integer volunteerIdInt = Integer.parseInt(volunteerId); + Integer complaintIdInt = Integer.parseInt(complaintId); + + return volunteerService.updateComplaintStatus(volunteerIdInt, complaintIdInt, status, remarks, file, latitude, + longitude, zone, ward, address); } @GetMapping("/getVolunteerLastLocation") @@ -79,4 +109,9 @@ public class VolunteerController { return volunteerService.getVolunteerLastLocation(volunteerId); } + @GetMapping("/getVolunteerLastActiveStatus") + public Map getVolunteerLastActiveStatus(@RequestParam("volunteer_id") Integer volunteerId) { + return volunteerService.getVolunteerLastActiveStatus(volunteerId); + } + } diff --git a/src/main/java/in/gov/chennaicorporation/mobileservice/gccVolunteer/service/VolunteerService.java b/src/main/java/in/gov/chennaicorporation/mobileservice/gccVolunteer/service/VolunteerService.java index 8d0c1e77..5ee4104a 100644 --- a/src/main/java/in/gov/chennaicorporation/mobileservice/gccVolunteer/service/VolunteerService.java +++ b/src/main/java/in/gov/chennaicorporation/mobileservice/gccVolunteer/service/VolunteerService.java @@ -353,12 +353,9 @@ public class VolunteerService { } public Map saveVolunteerLocationHistory(Integer volunteerId, String mid, String latitude, - String longitude, String activeStatus) { + String longitude, String zone, String ward, String address) { Map 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> 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> activeLogins = jdbcTemplate.queryForList(checkLoginSql, volunteerId); if (activeLogins == null || activeLogins.isEmpty()) { @@ -461,7 +479,8 @@ public class VolunteerService { } public Map updateComplaintStatus(Integer volunteerId, Integer complaintId, String status, - String remarks, List file) { + String remarks, List file, String latitude, + String longitude, String zone, String ward, String address) { Map 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 getVolunteerLastLocation(Integer volunteerId) { Map 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 result = jdbcTemplate.queryForMap(sqlQuery, volunteerId); - if (result.isEmpty()) { - response.put("status", 404); - response.put("message", "No volunteer last location found."); + List> 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 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 saveVolunteerActiveHistory(Integer volunteerId, String mid, String latitude, + String longitude, String activeStatus, String zone, String ward, String address) { + Map 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 getVolunteerLastActiveStatus(Integer volunteerId) { + Map 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> 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 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; + } + }