From dbdf0e9bc48bb1ec2f4892a3057cb43aba2b6e76 Mon Sep 17 00:00:00 2001 From: harijana2494 Date: Thu, 17 Sep 2026 12:46:17 +0530 Subject: [PATCH] Volunteer Details added --- .../configuration/DataSourceConfig.java | 26 +- .../controller/VolunteerController.java | 114 + .../service/VolunteerService.java | 2037 +++++++++++++++++ 3 files changed, 2175 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/gcc/commissionerreview/controller/VolunteerController.java create mode 100644 src/main/java/com/gcc/commissionerreview/service/VolunteerService.java diff --git a/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java b/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java index e41a056..a8a2df0 100644 --- a/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java +++ b/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java @@ -17,8 +17,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableTransactionManagement public class DataSourceConfig { - //private static String host = "localhost:3306"; - //private static String dbpassword = "root"; +// private static String host = "localhost:3306"; +// private static String dbpassword = "root"; private static String host = "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; private static String dbpassword = "gcc-facial-password"; @@ -312,4 +312,26 @@ public class DataSourceConfig { return dataSource; } + /// //////////////////////// For Volunteer //////////////////////////// + @Bean(name = "mysqlVolunteerDataSource") + public DataSource mysqlVolunteerDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://" + host + "/volunteer"); + dataSource.setUsername("root"); + dataSource.setPassword(dbpassword); + return dataSource; + } + + /// //////////////////////// For gcc_sos //////////////////////////// + @Bean(name = "mysqlGccsosDataSource") + public DataSource mysqlGccsosDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://" + host + "/gcc_sos"); + dataSource.setUsername("root"); + dataSource.setPassword(dbpassword); + return dataSource; + } + } diff --git a/src/main/java/com/gcc/commissionerreview/controller/VolunteerController.java b/src/main/java/com/gcc/commissionerreview/controller/VolunteerController.java new file mode 100644 index 0000000..1c5668c --- /dev/null +++ b/src/main/java/com/gcc/commissionerreview/controller/VolunteerController.java @@ -0,0 +1,114 @@ +package com.gcc.commissionerreview.controller; + +import com.gcc.commissionerreview.service.VolunteerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/commissionerreview/api/volunteer") +public class VolunteerController { + + @Autowired + private VolunteerService volunteerService; + + @GetMapping("/overall-details") + public ResponseEntity> getOverallDetails() { + return volunteerService.getOverallDetails(); + } + + @GetMapping("/overall-totalvolunteers") + public ResponseEntity> getOverallTotalVolunteers() { + return volunteerService.getOverallTotalVolunteers(); + } + + @GetMapping("/overall-inactivevolunteers") + public ResponseEntity> getOverallInactiveVolunteers() { + return volunteerService.getOverallInactiveVolunteers(); + } + + @GetMapping("/overall-activevolunteers") + public ResponseEntity> getOverallActiveVolunteers() { + return volunteerService.getOverallActiveVolunteers(); + } + + @GetMapping("/overall-readytoworkvolunteers") + public ResponseEntity> getOverallReadyToWorkVolunteers() { + return volunteerService.getOverallReadyToWorkVolunteers(); + } + + @GetMapping("/overall-totalrequest") + public ResponseEntity> getOverallTotalRequest() { + return volunteerService.getOverallTotalRequest(); + } + + @GetMapping("/overall-completedrequest") + public ResponseEntity> getOverallCompletedRequest() { + return volunteerService.getOverallCompletedRequest(); + } + + @GetMapping("/overall-pendingrequest") + public ResponseEntity> getOverallPendingRequest() { + return volunteerService.getOverallPendingRequest(); + } +/// ////////////////////////////////////// + @GetMapping("/zonewise-details") + public ResponseEntity> getZonewiseDetails() { + return volunteerService.getZonewiseDetails(); + } + + @GetMapping("/zonewise-totalvolunteers") + public ResponseEntity> getZonewiseTotalVolunteers(@RequestParam String zone) { + return volunteerService.getZonewiseTotalVolunteers(zone); + } + + @GetMapping("/zonewise-distincttotalvolunteers") + public ResponseEntity> getZonewiseDistinctTotalVolunteers(@RequestParam String zone) { + return volunteerService.getZonewiseDistinctTotalVolunteers(zone); + } + + @GetMapping("/zonewise-activevolunteers") + public ResponseEntity> getZonewiseActiveVolunteers(@RequestParam String zone) { + return volunteerService.getZonewiseActiveVolunteers(zone); + } + + @GetMapping("/zonewise-inactivevolunteers") + public ResponseEntity> getZonewiseInActiveVolunteers(@RequestParam String zone) { + return volunteerService.getZonewiseInActiveVolunteers(zone); + } + + @GetMapping("/zonewise-readytoworkvolunteers") + public ResponseEntity> getZonewiseReadyToWorkVolunteers(@RequestParam String zone) { + return volunteerService.getZonewiseReadyToWorkVolunteers(zone); + } + + @GetMapping("/zonewise-totalrequest") + public ResponseEntity> getZonewiseTotalRequest(@RequestParam String zone) { + return volunteerService.getZonewiseTotalRequest(zone); + } + + @GetMapping("/zonewise-completedrequest") + public ResponseEntity> getZonewiseCompletedRequest(@RequestParam String zone) { + return volunteerService.getZonewiseCompletedRequest(zone); + } + + @GetMapping("/zonewise-pendingrequest") + public ResponseEntity> getZonewisePendingRequest(@RequestParam String zone) { + return volunteerService.getZonewisePendingRequest(zone); + } +/// //////////////////////////////////// + @GetMapping("/wardwise-details") + public ResponseEntity> getWardwiseDetails(@RequestParam String zone) { + return volunteerService.getWardwiseDetails(zone); + } +/// ///////////////////////////////////// + @GetMapping("/volunteer-details") + public ResponseEntity> getVolunteerDetails(@RequestParam String zone) { + return volunteerService.getVolunteerDetails(zone); + } +} diff --git a/src/main/java/com/gcc/commissionerreview/service/VolunteerService.java b/src/main/java/com/gcc/commissionerreview/service/VolunteerService.java new file mode 100644 index 0000000..620521c --- /dev/null +++ b/src/main/java/com/gcc/commissionerreview/service/VolunteerService.java @@ -0,0 +1,2037 @@ +package com.gcc.commissionerreview.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class VolunteerService { + + @Autowired + private JdbcTemplate jdbcVolunteerTemplate; + + @Autowired + public void setDatasource(@Qualifier("mysqlVolunteerDataSource") DataSource datasource) { + this.jdbcVolunteerTemplate = new JdbcTemplate(datasource); + } + +// Overall Details + public ResponseEntity> getOverallDetails() { + + Map response = new HashMap<>(); + + try { + + String sql = """ + WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate + ), + + rescue_counts AS ( + SELECT + COUNT(*) AS total_requests, + SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS completed_requests, + SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END) AS pending_requests + FROM gcc_sos.rescue + WHERE zone IS NOT NULL + ) + + SELECT + COUNT(DISTINCT vi.volunteer_id) AS total_volunteers, + + COUNT(DISTINCT CASE + WHEN ll.is_active = 1 + THEN vi.volunteer_id + END) AS active_volunteers, + + COUNT(DISTINCT CASE + WHEN ll.is_active = 0 + THEN vi.volunteer_id + END) AS inactive_volunteers, + + COUNT(DISTINCT CASE + WHEN ll.is_active = 1 + AND NOT EXISTS ( + SELECT 1 + FROM volunteer_complaintlist vc + WHERE vc.volunteer_id = vi.volunteer_id + AND vc.is_active = 1 + AND vc.is_delete = 0 + AND vc.complaint_status = 2 + ) + THEN vi.volunteer_id + END) AS ready_to_work, + + MAX(rc.total_requests) AS total_requests, + MAX(rc.completed_requests) AS completed_requests, + MAX(rc.pending_requests) AS pending_requests + + FROM volunteer_information vi + + LEFT JOIN latest_location ll + ON ll.volunteer_id = vi.volunteer_id + + CROSS JOIN rescue_counts rc + """; + + List> data = jdbcVolunteerTemplate.queryForList(sql); + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + // Overall Total Volunteers + public ResponseEntity> getOverallTotalVolunteers() { + + Map response = new HashMap<>(); + String baseurl = "https://gccservices.in/gccofficialapp/files"; + + try { + + String sql = """ +WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate +), + +complaint_counts AS ( + SELECT + volunteer_id, + + SUM( + CASE + WHEN complaint_status = 2 THEN 1 + ELSE 0 + END + ) AS pending_complaints, + + SUM( + CASE + WHEN complaint_status = 3 THEN 1 + ELSE 0 + END + ) AS completed_complaints + + FROM volunteer_complaintlist + + WHERE is_active = 1 + AND is_delete = 0 + + GROUP BY volunteer_id +) + +SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT( + ?, + vi.doc_url + ) AS doc_url, + + COALESCE(cc.pending_complaints, 0) AS pending_complaints, + + COALESCE(cc.completed_complaints, 0) AS completed_complaints, + + ll.zone AS current_zone, + ll.cdate AS location_cdate, + ll.is_active AS location_is_active + +FROM volunteer_information vi + +LEFT JOIN latest_location ll + ON ll.volunteer_id = vi.volunteer_id + +LEFT JOIN complaint_counts cc + ON cc.volunteer_id = vi.volunteer_id + +ORDER BY vi.volunteer_id +"""; + + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl); + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + // Overall Inactive Volunteers + public ResponseEntity> getOverallInactiveVolunteers() { + + Map response = new HashMap<>(); + String baseurl = "https://gccservices.in/gccofficialapp/files"; + + try { + + String sql = """ + WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate + ), + + complaint_counts AS ( + SELECT + volunteer_id, + + SUM( + CASE + WHEN complaint_status = 2 THEN 1 + ELSE 0 + END + ) AS pending_complaints, + + SUM( + CASE + WHEN complaint_status = 3 THEN 1 + ELSE 0 + END + ) AS completed_complaints + + FROM volunteer_complaintlist + + WHERE is_active = 1 + AND is_delete = 0 + + GROUP BY volunteer_id + ) + + SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT( + ?, + vi.doc_url + ) AS doc_url, + + COALESCE(cc.pending_complaints, 0) AS pending_complaints, + + COALESCE(cc.completed_complaints, 0) AS completed_complaints + + FROM latest_location ll + + INNER JOIN volunteer_information vi + ON vi.volunteer_id = ll.volunteer_id + + LEFT JOIN complaint_counts cc + ON cc.volunteer_id = vi.volunteer_id + + WHERE ll.is_active = 0 + + ORDER BY vi.volunteer_id + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl); + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + // Overall Active Volunteers + public ResponseEntity> getOverallActiveVolunteers() { + + Map response = new HashMap<>(); + String baseurl = "https://gccservices.in/gccofficialapp/files"; + + try { + + String sql = """ + WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate + ), + + complaint_counts AS ( + SELECT + volunteer_id, + + SUM( + CASE + WHEN complaint_status = 2 THEN 1 + ELSE 0 + END + ) AS pending_complaints, + + SUM( + CASE + WHEN complaint_status = 3 THEN 1 + ELSE 0 + END + ) AS completed_complaints + + FROM volunteer_complaintlist + + WHERE is_active = 1 + AND is_delete = 0 + + GROUP BY volunteer_id + ) + + SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT( + ?, + vi.doc_url + ) AS doc_url, + + COALESCE(cc.pending_complaints, 0) AS pending_complaints, + + COALESCE(cc.completed_complaints, 0) AS completed_complaints + + FROM latest_location ll + + INNER JOIN volunteer_information vi + ON vi.volunteer_id = ll.volunteer_id + + LEFT JOIN complaint_counts cc + ON cc.volunteer_id = vi.volunteer_id + + WHERE ll.is_active = 1 + + ORDER BY vi.volunteer_id + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl); + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + // Overall Ready To Work Volunteers + public ResponseEntity> getOverallReadyToWorkVolunteers() { + + Map response = new HashMap<>(); + String baseurl = "https://gccservices.in/gccofficialapp/files"; + + try { + + String sql = """ + WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate + ), + + complaint_counts AS ( + SELECT + volunteer_id, + + SUM( + CASE + WHEN complaint_status = 2 THEN 1 + ELSE 0 + END + ) AS pending_complaints, + + SUM( + CASE + WHEN complaint_status = 3 THEN 1 + ELSE 0 + END + ) AS completed_complaints + + FROM volunteer_complaintlist + + WHERE is_active = 1 + AND is_delete = 0 + + GROUP BY volunteer_id + ) + + SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT( + ?, + vi.doc_url + ) AS doc_url, + + COALESCE(cc.pending_complaints, 0) AS pending_complaints, + + COALESCE(cc.completed_complaints, 0) AS completed_complaints + + FROM latest_location ll + + INNER JOIN volunteer_information vi + ON vi.volunteer_id = ll.volunteer_id + + LEFT JOIN complaint_counts cc + ON cc.volunteer_id = vi.volunteer_id + + WHERE NOT EXISTS ( + SELECT 1 + FROM volunteer_complaintlist vc + WHERE vc.volunteer_id = ll.volunteer_id + AND vc.is_active = 1 + AND vc.is_delete = 0 + AND vc.complaint_status = 2 + ) + + ORDER BY vi.volunteer_id + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl); + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + // Overall Total Request + public ResponseEntity> getOverallTotalRequest() { + + Map response = new HashMap<>(); + + + try { + + String sql = """ + SELECT + contact_name, + contact_number, + zone, + ward, + streetname, + location_details, + request_type, + remarks, + cdate + FROM gcc_sos.rescue + WHERE zone IS NOT NULL + ORDER BY cdate DESC + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql); + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + // Overall Completed Request + public ResponseEntity> getOverallCompletedRequest() { + + Map response = new HashMap<>(); + + + try { + + String sql = """ + SELECT + contact_name, + contact_number, + zone, + ward, + streetname, + location_details, + request_type, + remarks, + cdate, + status + FROM gcc_sos.rescue + WHERE zone IS NOT NULL + AND status = 1 + ORDER BY cdate DESC + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql); + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + // Overall Pending Request + public ResponseEntity> getOverallPendingRequest() { + + Map response = new HashMap<>(); + + + try { + + String sql = """ + SELECT + contact_name, + contact_number, + zone, + ward, + streetname, + location_details, + request_type, + remarks, + cdate, + status + FROM gcc_sos.rescue + WHERE zone IS NOT NULL + AND status = 0 + ORDER BY cdate DESC + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql); + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } +// public ResponseEntity> getZonewiseDetails() { +// +// Map response = new HashMap<>(); +// +// try { +// +// String sql = "SELECT zone, " + +// "SUM(total_volunteers) AS Total_Volunteers, " + +// "SUM(active_volunteers) AS Active_Volunteers, " + +// "SUM(inactive_volunteers) AS Inactive_Volunteers, " + +// "SUM(total_request) AS Total_Request, " + +// "SUM(pending_request) AS Pending_Request, " + +// "SUM(completed_request) AS Completed_Request, " + +// "SUM(uphc_count) AS UPHC_Count " + +// "FROM zonewise_details " + +// "GROUP BY zone"; +// +// List> data = jdbcVolunteerTemplate.queryForList(sql); +// +// response.put("status", true); +// response.put("message", "Zone summary fetched successfully."); +// response.put("data", data); +// +// return ResponseEntity.ok(response); +// +// } catch (Exception e) { +// +// response.put("status", false); +// response.put("message", "Failed to fetch zone summary."); +// response.put("error", e.getMessage()); +// +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); +// } +// } +/// //////////////// Zonewise Details + public ResponseEntity> getZonewiseDetails() { + + Map response = new HashMap<>(); + + try { + +// String sql = "WITH RECURSIVE zones AS ( " + +// "SELECT 1 AS zone " + +// "UNION ALL " + +// "SELECT zone + 1 FROM zones WHERE zone < 15 " + +// ") " + +// "SELECT " + +// "LPAD(z.zone, 2, '0') AS zone, " + +// "COUNT(vi.volunteer_id) AS Total_Volunteers, " + +// "'-' AS Active_Volunteers, " + +// "'-' AS Inactive_Volunteers, " + +// "'-' AS Total_Request, " + +// "'-' AS Pending_Request, " + +// "'-' AS Completed_Request, " + +// "'-' AS UPHC_Count " + +// "FROM zones z " + +// "LEFT JOIN volunteer_information vi " + +// "ON vi.preferred_zones = '0' " + +// "OR FIND_IN_SET(z.zone, vi.preferred_zones) > 0 " + +// "GROUP BY z.zone " + +// "ORDER BY z.zone"; +// String sql = """ +// WITH zones AS ( +// SELECT '01' AS zone +// UNION ALL SELECT '02' +// UNION ALL SELECT '03' +// UNION ALL SELECT '04' +// UNION ALL SELECT '05' +// UNION ALL SELECT '06' +// UNION ALL SELECT '07' +// UNION ALL SELECT '08' +// UNION ALL SELECT '09' +// UNION ALL SELECT '10' +// UNION ALL SELECT '11' +// UNION ALL SELECT '12' +// UNION ALL SELECT '13' +// UNION ALL SELECT '14' +// UNION ALL SELECT '15' +// ), +// +// latest_location AS ( +// SELECT +// vlh.volunteer_id, +// vlh.zone, +// vlh.cdate +// FROM volunteer_location_history vlh +// INNER JOIN ( +// SELECT +// volunteer_id, +// MAX(cdate) AS latest_cdate +// FROM volunteer_location_history +// GROUP BY volunteer_id +// ) latest +// ON vlh.volunteer_id = latest.volunteer_id +// AND vlh.cdate = latest.latest_cdate +// ), +// +// rescue_counts AS ( +// SELECT +// zone, +// +// COUNT(*) AS total_requests, +// +// SUM( +// CASE +// WHEN status = 1 THEN 1 +// ELSE 0 +// END +// ) AS completed_requests, +// +// SUM( +// CASE +// WHEN status = 0 THEN 1 +// ELSE 0 +// END +// ) AS pending_requests +// +// FROM gcc_sos.rescue +// +// WHERE zone IS NOT NULL +// +// GROUP BY zone +// ) +// +// SELECT +// z.zone, +// +// COUNT(DISTINCT ll.volunteer_id) AS total_volunteers, +// +// COUNT(DISTINCT CASE +// WHEN DATE(ll.cdate) = CURDATE() +// THEN ll.volunteer_id +// END) AS active_volunteers, +// +// COUNT(DISTINCT CASE +// WHEN DATE(ll.cdate) < CURDATE() +// THEN ll.volunteer_id +// END) AS inactive_volunteers, +// +// COUNT(DISTINCT CASE +// WHEN NOT EXISTS ( +// SELECT 1 +// FROM volunteer_complaintlist vc +// WHERE vc.volunteer_id = ll.volunteer_id +// AND vc.is_active = 1 +// AND vc.is_delete = 0 +// AND vc.complaint_status = 2 +// ) +// THEN ll.volunteer_id +// END) AS ready_to_work, +// +// COALESCE(rc.total_requests, 0) AS total_requests, +// +// COALESCE(rc.completed_requests, 0) AS completed_requests, +// +// COALESCE(rc.pending_requests, 0) AS pending_requests +// +// FROM zones z +// +// LEFT JOIN latest_location ll +// ON ll.zone = z.zone +// +// LEFT JOIN volunteer_information vi +// ON vi.volunteer_id = ll.volunteer_id +// +// LEFT JOIN rescue_counts rc +// ON rc.zone = z.zone +// +// GROUP BY +// z.zone, +// rc.total_requests, +// rc.completed_requests, +// rc.pending_requests +// +// ORDER BY z.zone +// """; + String sql = """ +WITH zones AS ( + SELECT '01' AS zone + UNION ALL SELECT '02' + UNION ALL SELECT '03' + UNION ALL SELECT '04' + UNION ALL SELECT '05' + UNION ALL SELECT '06' + UNION ALL SELECT '07' + UNION ALL SELECT '08' + UNION ALL SELECT '09' + UNION ALL SELECT '10' + UNION ALL SELECT '11' + UNION ALL SELECT '12' + UNION ALL SELECT '13' + UNION ALL SELECT '14' + UNION ALL SELECT '15' +), + +latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate +), + +rescue_counts AS ( + SELECT + zone, + + COUNT(*) AS total_requests, + + SUM( + CASE + WHEN status = 1 THEN 1 + ELSE 0 + END + ) AS completed_requests, + + SUM( + CASE + WHEN status = 0 THEN 1 + ELSE 0 + END + ) AS pending_requests + + FROM gcc_sos.rescue + + WHERE zone IS NOT NULL + + GROUP BY zone +) + +SELECT + z.zone, + + /* OLD LOGIC: + Volunteer preferred zone */ + COUNT(DISTINCT vi.volunteer_id) AS total_volunteers, + + /* NEW DISTINCT LOGIC: + Volunteer latest location zone */ + COUNT(DISTINCT ll.volunteer_id) AS distinct_total_volunteers, + + /* Active based on latest location */ + COUNT(DISTINCT CASE + WHEN ll.is_active = 1 + THEN ll.volunteer_id + END) AS active_volunteers, + + /* Inactive based on latest location */ + COUNT(DISTINCT CASE + WHEN ll.is_active = 0 + THEN ll.volunteer_id + END) AS inactive_volunteers, + + /* Ready to work */ + COUNT(DISTINCT CASE + WHEN ll.is_active = 1 + AND NOT EXISTS ( + SELECT 1 + FROM volunteer_complaintlist vc + WHERE vc.volunteer_id = ll.volunteer_id + AND vc.is_active = 1 + AND vc.is_delete = 0 + AND vc.complaint_status = 2 + ) + THEN ll.volunteer_id + END) AS ready_to_work, + + COALESCE(rc.total_requests, 0) AS total_requests, + + COALESCE(rc.completed_requests, 0) AS completed_requests, + + COALESCE(rc.pending_requests, 0) AS pending_requests + +FROM zones z + +/* OLD TOTAL VOLUNTEER LOGIC */ +LEFT JOIN volunteer_information vi + ON vi.preferred_zones = '0' + OR FIND_IN_SET(z.zone, vi.preferred_zones) > 0 + +/* LATEST LOCATION LOGIC */ +LEFT JOIN latest_location ll + ON ll.zone = z.zone + +LEFT JOIN rescue_counts rc + ON rc.zone = z.zone + +GROUP BY + z.zone, + rc.total_requests, + rc.completed_requests, + rc.pending_requests + +ORDER BY z.zone +"""; + + List> data = jdbcVolunteerTemplate.queryForList(sql); + + response.put("status", true); + response.put("message", "Zone summary fetched successfully."); + response.put("data", data); + + return ResponseEntity.ok(response); + + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch zone summary."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + /// //////////////// Zonewise Total Volunteers + public ResponseEntity> getZonewiseTotalVolunteers(String zone) { + + Map response = new HashMap<>(); + + String baseurl = "https://gccservices.in/gccofficialapp/files"; + try { + + String sql = """ + SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT(?, vi.doc_url) AS doc_url + + FROM volunteer_information vi + + WHERE vi.preferred_zones = '0' + OR FIND_IN_SET( + CAST(? AS UNSIGNED), + vi.preferred_zones + ) > 0 + + ORDER BY vi.volunteer_id + """; + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + /// //////////////// Zonewise Distinct Total Volunteers + public ResponseEntity> getZonewiseDistinctTotalVolunteers(String zone) { + + Map response = new HashMap<>(); + + String baseurl = "https://gccservices.in/gccofficialapp/files"; + try { + + String sql = """ + WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate + ) + + SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT(?, vi.doc_url) AS doc_url + + FROM latest_location ll + + INNER JOIN volunteer_information vi + ON vi.volunteer_id = ll.volunteer_id + + WHERE ll.zone = ? + + ORDER BY vi.volunteer_id + """; + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + /// //////////////// Zonewise Active Volunteers + public ResponseEntity> getZonewiseActiveVolunteers(String zone) { + + Map response = new HashMap<>(); + + String baseurl = "https://gccservices.in/gccofficialapp/files"; + try { + + String sql = """ + WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate + ), + + complaint_counts AS ( + SELECT + volunteer_id, + + SUM( + CASE + WHEN complaint_status = 2 THEN 1 + ELSE 0 + END + ) AS pending_complaints, + + SUM( + CASE + WHEN complaint_status = 3 THEN 1 + ELSE 0 + END + ) AS completed_complaints + + FROM volunteer_complaintlist + + WHERE is_active = 1 + AND is_delete = 0 + + GROUP BY volunteer_id + ) + + SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT(?, vi.doc_url) AS doc_url, + + COALESCE(cc.pending_complaints, 0) AS pending_complaints, + + COALESCE(cc.completed_complaints, 0) AS completed_complaints + + FROM latest_location ll + + INNER JOIN volunteer_information vi + ON vi.volunteer_id = ll.volunteer_id + + LEFT JOIN complaint_counts cc + ON cc.volunteer_id = vi.volunteer_id + + WHERE ll.zone = ? + AND ll.is_active = 1 + + ORDER BY vi.volunteer_id + """; + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + /// //////////////// Zonewise InActive Volunteers + public ResponseEntity> getZonewiseInActiveVolunteers(String zone) { + + Map response = new HashMap<>(); + + String baseurl = "https://gccservices.in/gccofficialapp/files"; + try { + + String sql = """ + WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate + ), + + complaint_counts AS ( + SELECT + volunteer_id, + + SUM( + CASE + WHEN complaint_status = 2 THEN 1 + ELSE 0 + END + ) AS pending_complaints, + + SUM( + CASE + WHEN complaint_status = 3 THEN 1 + ELSE 0 + END + ) AS completed_complaints + + FROM volunteer_complaintlist + + WHERE is_active = 1 + AND is_delete = 0 + + GROUP BY volunteer_id + ) + + SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT(?, vi.doc_url) AS doc_url, + + COALESCE(cc.pending_complaints, 0) AS pending_complaints, + + COALESCE(cc.completed_complaints, 0) AS completed_complaints + + FROM latest_location ll + + INNER JOIN volunteer_information vi + ON vi.volunteer_id = ll.volunteer_id + + LEFT JOIN complaint_counts cc + ON cc.volunteer_id = vi.volunteer_id + + WHERE ll.zone = ? + AND ll.is_active = 0 + + ORDER BY vi.volunteer_id + """; + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + /// //////////////// Zonewise Ready To Work Volunteers + public ResponseEntity> getZonewiseReadyToWorkVolunteers(String zone) { + + Map response = new HashMap<>(); + + String baseurl = "https://gccservices.in/gccofficialapp/files"; + try { + + String sql = """ + WITH latest_location AS ( + SELECT + vlh.volunteer_id, + vlh.zone, + vlh.cdate, + vlh.is_active + FROM volunteer_location_history vlh + INNER JOIN ( + SELECT + volunteer_id, + MAX(cdate) AS latest_cdate + FROM volunteer_location_history + GROUP BY volunteer_id + ) latest + ON vlh.volunteer_id = latest.volunteer_id + AND vlh.cdate = latest.latest_cdate + ), + + complaint_counts AS ( + SELECT + volunteer_id, + + SUM( + CASE + WHEN complaint_status = 2 THEN 1 + ELSE 0 + END + ) AS pending_complaints, + + SUM( + CASE + WHEN complaint_status = 3 THEN 1 + ELSE 0 + END + ) AS completed_complaints + + FROM volunteer_complaintlist + + WHERE is_active = 1 + AND is_delete = 0 + + GROUP BY volunteer_id + ) + + SELECT + vi.volunteer_id, + vi.aadhar, + vi.address, + vi.bloodgroup, + vi.category, + vi.cdate, + vi.college_name, + vi.degree, + vi.designation, + vi.district, + vi.dob, + vi.email, + vi.gender, + vi.isactive, + vi.landline_no, + vi.mobile_no, + vi.name, + vi.ngo_associated, + vi.occupation, + vi.pin_code, + vi.preferred_area, + vi.preferred_zones, + vi.previous_volunteered, + vi.refer_by, + vi.sub_category, + vi.vol_ncc, + vi.vol_nss, + vi.doc_number, + vi.doc_type, + vi.ephno, + vi.expertise_area, + vi.other_expertise, + + CONCAT(?, vi.doc_url) AS doc_url, + + COALESCE(cc.pending_complaints, 0) AS pending_complaints, + + COALESCE(cc.completed_complaints, 0) AS completed_complaints + + FROM latest_location ll + + INNER JOIN volunteer_information vi + ON vi.volunteer_id = ll.volunteer_id + + LEFT JOIN complaint_counts cc + ON cc.volunteer_id = vi.volunteer_id + + WHERE ll.zone = ? + AND ll.is_active = 1 + + AND NOT EXISTS ( + SELECT 1 + FROM volunteer_complaintlist vc + WHERE vc.volunteer_id = ll.volunteer_id + AND vc.is_active = 1 + AND vc.is_delete = 0 + AND vc.complaint_status = 2 + ) + + ORDER BY vi.volunteer_id + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + /// //////////////// Zonewise Total Request + public ResponseEntity> getZonewiseTotalRequest(String zone) { + + Map response = new HashMap<>(); + + + try { + + String sql = """ + SELECT + contact_name, + contact_number, + zone, + ward, + streetname, + location_details, + request_type, + remarks, + cdate + FROM gcc_sos.rescue + WHERE zone = ? + ORDER BY cdate DESC + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + /// //////////////// Zonewise Completed Request + public ResponseEntity> getZonewisePendingRequest(String zone) { + + Map response = new HashMap<>(); + + + try { + + String sql = """ + SELECT + contact_name, + contact_number, + zone, + ward, + streetname, + location_details, + request_type, + remarks, + cdate + FROM gcc_sos.rescue + WHERE zone = ? + AND status = 0 + ORDER BY cdate DESC + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + /// //////////////// Zonewise Pending Request + public ResponseEntity> getZonewiseCompletedRequest(String zone) { + + Map response = new HashMap<>(); + + + try { + + String sql = """ + SELECT + contact_name, + contact_number, + zone, + ward, + streetname, + location_details, + request_type, + remarks, + cdate + FROM gcc_sos.rescue + WHERE zone = ? + AND status = 1 + ORDER BY cdate DESC + """; + + + List> data = jdbcVolunteerTemplate.queryForList(sql, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } +// public ResponseEntity> getWardwiseDetails(String zone) { +// +// Map response = new HashMap<>(); +// +// try { +// String sql = "SELECT * FROM zonewise_details WHERE zone = ?"; +// List> data = jdbcVolunteerTemplate.queryForList(sql, zone); +// +// if (data.isEmpty()) { +// response.put("status", false); +// response.put("message", "Data not found"); +// response.put("data", data); +// +// return ResponseEntity.ok(response); +// } +// response.put("status", true); +// response.put("message", "Data fetched successfully"); +// response.put("data", data); +// +// return ResponseEntity.ok(response); +// } catch (Exception e) { +// +// response.put("status", false); +// response.put("message", "Failed to fetch data."); +// response.put("error", e.getMessage()); +// +// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); +// } +// } + + public ResponseEntity> getWardwiseDetails(String zone) { + + Map response = new HashMap<>(); + + try { + +// String sql = "SELECT " + +// "LPAD(?, 2, '0') AS zone, " + +// "'-' AS division, " + +// "COUNT(volunteer_id) AS total_volunteers, " + +// "'-' AS active_volunteers, " + +// "'-' AS inactive_volunteers, " + +// "'-' AS total_request, " + +// "'-' AS pending_request, " + +// "'-' AS completed_request, " + +// "'-' AS uphc_count " + +// "FROM volunteer_information " + +// "WHERE preferred_zones = '0' " + +// "OR FIND_IN_SET(CAST(? AS UNSIGNED), preferred_zones) > 0"; + String sql = """ + SELECT + ward, + + COUNT(*) AS total_complaints, + + SUM( + CASE + WHEN status = 1 THEN 1 + ELSE 0 + END + ) AS completed_complaints, + + SUM( + CASE + WHEN status = 0 THEN 1 + ELSE 0 + END + ) AS pending_complaints + + FROM gcc_sos.rescue + + WHERE zone = ? + + GROUP BY ward + + ORDER BY ward + """; + List> data = jdbcVolunteerTemplate.queryForList(sql, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + public ResponseEntity> getVolunteerDetails(String zone) { + + Map response = new HashMap<>(); + + String baseurl = "https://gccservices.in/gccofficialapp/files"; + try { + + String sql = "SELECT " + + "vi.volunteer_id, " + + "vi.aadhar, " + + "vi.address, " + + "vi.bloodgroup, " + + "vi.category, " + + "vi.cdate, " + + "vi.college_name, " + + "vi.degree, " + + "vi.designation, " + + "vi.district, " + + "vi.dob, " + + "vi.email, " + + "vi.gender, " + + "vi.isactive, " + + "vi.landline_no, " + + "vi.mobile_no, " + + "vi.name, " + + "vi.ngo_associated, " + + "vi.occupation, " + + "vi.pin_code, " + + "vi.preferred_area, " + + "vi.preferred_zones, " + + "vi.previous_volunteered, " + + "vi.refer_by, " + + "vi.sub_category, " + + "vi.vol_ncc, " + + "vi.vol_nss, " + + "vi.doc_number, " + + "vi.doc_type, " + + "vi.ephno, " + + "vi.expertise_area, " + + "vi.other_expertise, " + + "CONCAT(?, vi.doc_url) AS doc_url " + + "FROM volunteer_information vi " + + "WHERE vi.preferred_zones = '0' " + + "OR FIND_IN_SET(CAST(? AS UNSIGNED), vi.preferred_zones) > 0"; + List> data = jdbcVolunteerTemplate.queryForList(sql, baseurl, zone); + + if (data.isEmpty()) { + response.put("status", false); + response.put("message", "Data not found"); + response.put("data", data); + + return ResponseEntity.ok(response); + } + response.put("status", true); + response.put("message", "Data fetched successfully"); + response.put("data", data); + + return ResponseEntity.ok(response); + } catch (Exception e) { + + response.put("status", false); + response.put("message", "Failed to fetch data."); + response.put("error", e.getMessage()); + + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } +}