diff --git a/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java b/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java index a8a2df0..db4f40e 100644 --- a/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java +++ b/src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java @@ -17,11 +17,12 @@ 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"; + // private static String host = + // "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; + // private static String dbpassword = "gcc-facial-password"; public static class MyDataSourceConfig { @Primary diff --git a/src/main/java/com/gcc/commissionerreview/controller/VolunteerController.java b/src/main/java/com/gcc/commissionerreview/controller/VolunteerController.java index 1c5668c..fca592c 100644 --- a/src/main/java/com/gcc/commissionerreview/controller/VolunteerController.java +++ b/src/main/java/com/gcc/commissionerreview/controller/VolunteerController.java @@ -7,6 +7,7 @@ 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 org.springframework.http.MediaType; import java.util.Map; @@ -17,7 +18,7 @@ public class VolunteerController { @Autowired private VolunteerService volunteerService; - @GetMapping("/overall-details") + @GetMapping(value = "/overall-details", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getOverallDetails() { return volunteerService.getOverallDetails(); } @@ -56,7 +57,8 @@ public class VolunteerController { public ResponseEntity> getOverallPendingRequest() { return volunteerService.getOverallPendingRequest(); } -/// ////////////////////////////////////// + + /// ////////////////////////////////////// @GetMapping("/zonewise-details") public ResponseEntity> getZonewiseDetails() { return volunteerService.getZonewiseDetails(); @@ -101,14 +103,23 @@ public class VolunteerController { 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); } + + /// ///////////////////////////////////// + @GetMapping(value = "/categorywise-details", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity> getCategorywiseDetails(@RequestParam String zone) { + return volunteerService.getCategorywiseDetails(zone); + } + } diff --git a/src/main/java/com/gcc/commissionerreview/service/VolunteerService.java b/src/main/java/com/gcc/commissionerreview/service/VolunteerService.java index 620521c..15f7749 100644 --- a/src/main/java/com/gcc/commissionerreview/service/VolunteerService.java +++ b/src/main/java/com/gcc/commissionerreview/service/VolunteerService.java @@ -23,7 +23,7 @@ public class VolunteerService { this.jdbcVolunteerTemplate = new JdbcTemplate(datasource); } -// Overall Details + // Overall Details public ResponseEntity> getOverallDetails() { Map response = new HashMap<>(); @@ -31,82 +31,168 @@ public class VolunteerService { 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 - """; + 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); - } + String sql1 = """ + WITH volunteer_zone AS ( + SELECT + volunteer_id, + sub_category, + CASE + WHEN TRIM(preferred_zones) = '0' THEN 0 + ELSE CAST( + SUBSTRING_INDEX( + REPLACE(TRIM(preferred_zones), ' ', ''), + ',', + 1 + ) AS UNSIGNED + ) + END AS zone + FROM volunteer_information + WHERE isactive = 1 + ) + SELECT + CASE + WHEN zone IS NULL THEN 'Grand Total' + WHEN zone = 0 THEN 'Any' + ELSE CAST(zone AS CHAR) + END AS `zone`, + + SUM( + CASE + WHEN sub_category = 'Call Centre Support' + THEN 1 ELSE 0 + END + ) AS `call_centre_support`, + + SUM( + CASE + WHEN sub_category = 'Centre Admin Support' + THEN 1 ELSE 0 + END + ) AS `centre_admin_support`, + + SUM( + CASE + WHEN sub_category = 'Cooks & Assistance' + THEN 1 ELSE 0 + END + ) AS `cooks_and_assistance`, + + SUM( + CASE + WHEN sub_category = 'Distribution/Delivery Support' + THEN 1 ELSE 0 + END + ) AS `distribution/delivery_support`, + + SUM( + CASE + WHEN sub_category = 'General Assistance' + THEN 1 ELSE 0 + END + ) AS `general_assistance`, + + SUM( + CASE + WHEN sub_category = 'Graphic Designers' + THEN 1 ELSE 0 + END + ) AS `graphic_designers`, + + SUM( + CASE + WHEN sub_category = 'Medical Assistance/Counselling Service' + THEN 1 ELSE 0 + END + ) AS `medical_assistance/counselling_service`, + + SUM( + CASE + WHEN sub_category = 'Survey' + THEN 1 ELSE 0 + END + ) AS `survey`, + + COUNT(*) AS `grand_total` + + FROM volunteer_zone + GROUP BY zone WITH ROLLUP + ORDER BY + CASE WHEN zone IS NULL THEN 1 ELSE 0 END, + CAST(zone AS UNSIGNED) + """; + List> data1 = jdbcVolunteerTemplate.queryForList(sql1); + response.put("status", true); response.put("message", "Data fetched successfully."); response.put("data", data); + response.put("categorywise_data", data1); return ResponseEntity.ok(response); @@ -129,108 +215,107 @@ public class VolunteerService { 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 -"""; - + 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()) { @@ -265,106 +350,105 @@ ORDER BY vi.volunteer_id 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 - """; - + 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()) { @@ -399,106 +483,105 @@ ORDER BY vi.volunteer_id 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 - """; - + 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()) { @@ -533,112 +616,111 @@ ORDER BY vi.volunteer_id 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 - """; - + 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()) { @@ -669,25 +751,23 @@ ORDER BY vi.volunteer_id 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 - """; - + 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()) { @@ -718,27 +798,25 @@ ORDER BY vi.volunteer_id 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 - """; - + 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()) { @@ -769,27 +847,25 @@ ORDER BY vi.volunteer_id 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 - """; - + 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()) { @@ -814,311 +890,416 @@ ORDER BY vi.volunteer_id 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 = "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 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 -"""; + WITH zones AS ( + + SELECT '0' AS zone + UNION ALL SELECT '01' + 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' + ), + + /* + * Get the latest location of each volunteer + */ + 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 request counts by zone + */ + 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 + ), + + /* + * Get ONLY the first preferred zone of each volunteer. + * + * Examples: + * + * 1 -> 1 + * 1,2,3 -> 1 + * 4,5,6 -> 4 + * 0 -> 0 + * 0,2,3 -> 0 + */ + preferred_zone AS ( + + SELECT + volunteer_id, + + CAST( + SUBSTRING_INDEX( + REPLACE(TRIM(preferred_zones), ' ', ''), + ',', + 1 + ) AS UNSIGNED + ) AS first_zone + + FROM volunteer_information + + WHERE isactive = 1 + AND preferred_zones IS NOT NULL + AND TRIM(preferred_zones) <> '' + ) + + SELECT + + z.zone, + + /* + * Total volunteers based on FIRST preferred zone only + */ + COUNT(DISTINCT pz.volunteer_id) AS total_volunteers, + + /* + * Volunteer latest location zone + */ + COUNT(DISTINCT ll.volunteer_id) AS distinct_total_volunteers, + + /* + * Active volunteers based on latest location + */ + COUNT( + DISTINCT CASE + WHEN ll.is_active = 1 + THEN ll.volunteer_id + END + ) AS active_volunteers, + + /* + * Inactive volunteers based on latest location + */ + COUNT( + DISTINCT CASE + WHEN ll.is_active = 0 + THEN ll.volunteer_id + END + ) AS inactive_volunteers, + + /* + * Ready to work + * + * Active volunteer + * AND + * No active complaint with complaint_status = 2 + */ + 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, + + /* + * Rescue request counts + */ + 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 + + /* + * NEW TOTAL VOLUNTEER LOGIC + * + * Only the FIRST preferred zone is considered. + * + * Example: + * + * preferred_zones = '1,2,3' + * + * SUBSTRING_INDEX(...) = '1' + * + * Therefore volunteer is counted only in Zone 1. + */ + LEFT JOIN preferred_zone pz + + ON CAST(z.zone AS UNSIGNED) = pz.first_zone + + /* + * Latest location logic + */ + LEFT JOIN latest_location ll + + ON ll.zone = z.zone + + /* + * Rescue counts + */ + 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 + + CAST(z.zone AS UNSIGNED) + """; List> data = jdbcVolunteerTemplate.queryForList(sql); @@ -1138,7 +1319,7 @@ ORDER BY z.zone } } - /// //////////////// Zonewise Total Volunteers + /// //////////////// Zonewise Total Volunteers public ResponseEntity> getZonewiseTotalVolunteers(String zone) { Map response = new HashMap<>(); @@ -1147,52 +1328,52 @@ ORDER BY z.zone 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 - """; + 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); @@ -1218,7 +1399,7 @@ ORDER BY z.zone } } - /// //////////////// Zonewise Distinct Total Volunteers + /// //////////////// Zonewise Distinct Total Volunteers public ResponseEntity> getZonewiseDistinctTotalVolunteers(String zone) { Map response = new HashMap<>(); @@ -1227,69 +1408,69 @@ ORDER BY z.zone 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 - """; + 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); @@ -1315,7 +1496,7 @@ ORDER BY z.zone } } - /// //////////////// Zonewise Active Volunteers + /// //////////////// Zonewise Active Volunteers public ResponseEntity> getZonewiseActiveVolunteers(String zone) { Map response = new HashMap<>(); @@ -1324,103 +1505,103 @@ ORDER BY z.zone 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 - """; + 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); @@ -1446,7 +1627,7 @@ ORDER BY z.zone } } - /// //////////////// Zonewise InActive Volunteers + /// //////////////// Zonewise InActive Volunteers public ResponseEntity> getZonewiseInActiveVolunteers(String zone) { Map response = new HashMap<>(); @@ -1455,103 +1636,103 @@ ORDER BY z.zone 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 - """; + 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); @@ -1577,7 +1758,7 @@ ORDER BY z.zone } } - /// //////////////// Zonewise Ready To Work Volunteers + /// //////////////// Zonewise Ready To Work Volunteers public ResponseEntity> getZonewiseReadyToWorkVolunteers(String zone) { Map response = new HashMap<>(); @@ -1586,113 +1767,112 @@ ORDER BY z.zone 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 - """; - + 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); @@ -1718,30 +1898,28 @@ ORDER BY z.zone } } - /// //////////////// Zonewise Total Request + /// //////////////// 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 - """; - + 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); @@ -1767,31 +1945,29 @@ ORDER BY z.zone } } - /// //////////////// Zonewise Completed Request + /// //////////////// 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 - """; - + 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); @@ -1817,31 +1993,29 @@ ORDER BY z.zone } } - /// //////////////// Zonewise Pending Request + /// //////////////// 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 - """; - + 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); @@ -1866,35 +2040,37 @@ ORDER BY z.zone 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 * 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) { @@ -1902,47 +2078,47 @@ ORDER BY z.zone 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 " + + // "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, + SELECT + ward, - COUNT(*) AS total_complaints, + COUNT(*) AS total_complaints, - SUM( - CASE - WHEN status = 1 THEN 1 - ELSE 0 - END - ) AS completed_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 + SUM( + CASE + WHEN status = 0 THEN 1 + ELSE 0 + END + ) AS pending_complaints - FROM gcc_sos.rescue + FROM gcc_sos.rescue - WHERE zone = ? + WHERE zone = ? - GROUP BY ward + GROUP BY ward - ORDER BY ward - """; + ORDER BY ward + """; List> data = jdbcVolunteerTemplate.queryForList(sql, zone); if (data.isEmpty()) { @@ -2034,4 +2210,86 @@ ORDER BY z.zone return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } } + + ////// categorywise-details + public ResponseEntity> getCategorywiseDetails(String zone) { + + Map response = new HashMap<>(); + + try { + + String sql = """ + WITH volunteer_zone AS ( + SELECT + volunteer_id, + sub_category, + CASE + WHEN TRIM(preferred_zones) = '0' THEN 0 + ELSE CAST( + SUBSTRING_INDEX( + REPLACE(TRIM(preferred_zones), ' ', ''), + ',', + 1 + ) AS UNSIGNED + ) + END AS zone + FROM volunteer_information + WHERE isactive = 1 + ) + SELECT + CAST(zone AS CHAR) AS `Zone`, + + SUM(CASE WHEN sub_category = 'Call Centre Support' + THEN 1 ELSE 0 END) AS `call_centre_support`, + + SUM(CASE WHEN sub_category = 'Centre Admin Support' + THEN 1 ELSE 0 END) AS `centre_admin_support`, + + SUM(CASE WHEN sub_category = 'Cooks & Assistance' + THEN 1 ELSE 0 END) AS `cooks_and_assistance`, + + SUM(CASE WHEN sub_category = 'Distribution/Delivery Support' + THEN 1 ELSE 0 END) AS `distribution/delivery_support`, + + SUM(CASE WHEN sub_category = 'General Assistance' + THEN 1 ELSE 0 END) AS `general_assistance`, + + SUM(CASE WHEN sub_category = 'Graphic Designers' + THEN 1 ELSE 0 END) AS `graphic_designers`, + + SUM(CASE WHEN sub_category = 'Medical Assistance/Counselling Service' + THEN 1 ELSE 0 END) AS `medical_assistance/counselling_service`, + + SUM(CASE WHEN sub_category = 'Survey' + THEN 1 ELSE 0 END) AS `survey`, + + COUNT(*) AS `grand_total` + + FROM volunteer_zone + WHERE zone = ? + GROUP BY 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); + } + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 196b48f..128dae4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ -spring.profiles.active=prod -#spring.profiles.active=dev \ No newline at end of file +#spring.profiles.active=prod +spring.profiles.active=dev