From aa7be06fde27f9f2ffb15e977eb672b9bffa9f29 Mon Sep 17 00:00:00 2001 From: Dizho A Date: Fri, 14 Aug 2026 15:04:06 +0530 Subject: [PATCH] moditify the visit list at shelter inspection project --- .../gccoffice/configuration/AppConfig.java | 2 + .../ShelterInspectionController.java | 72 +- .../Service/ShelterInspectionService.java | 688 +++++------------- .../modules/shelterinspection/dashboard.html | 8 - .../shelterinspection/shelterlist.html | 218 ++---- .../modules/shelterinspection/visitlist.html | 150 ++-- 6 files changed, 356 insertions(+), 782 deletions(-) diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/AppConfig.java b/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/AppConfig.java index 8693e49..ec4ba6c 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/AppConfig.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/AppConfig.java @@ -25,6 +25,8 @@ public class AppConfig { public String gccappsMysqlPassword = ""; public String domesticurl="https://gccservices.in/gccofficialapp/api/domesticwaste"; + public String shelterurl="https://gccservices.in/gccofficialapp/api/shelterinspection"; + public String otpUrl = "https://tmegov.onex-aura.com/api/sms?"; public String getOtpUrl() { diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java b/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java index ae90cfe..2101370 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; +import in.gov.chennaicorporation.gccoffice.configuration.AppConfig; import in.gov.chennaicorporation.gccoffice.shelterinspection.Service.MasterShelterService; import in.gov.chennaicorporation.gccoffice.shelterinspection.Service.ShelterInspectionService; @@ -26,7 +27,16 @@ public class ShelterInspectionController { @Autowired private MasterShelterService masterShelterService; - private final RestTemplate restTemplate = new RestTemplate(); + private final RestTemplate restTemplate; + private final AppConfig appConfig; + + @Autowired + public ShelterInspectionController(RestTemplate restTemplate, AppConfig appConfig) { + this.restTemplate = restTemplate; + this.appConfig = appConfig; + } + + //private final RestTemplate restTemplate = new RestTemplate(); @GetMapping("/Sheltercount") public ResponseEntity> getTotalCount() { @@ -105,42 +115,7 @@ public class ShelterInspectionController { return shelterApiService.getLatestVisitShelters(type,value); } - -// @GetMapping("/dashboard") -// public Map dashboard() { -// return shelterApiService.getDashboardData(); -// } - -// @GetMapping("/top5Shelters") -// public List> getTop5Shelters() { -// return shelterApiService.getTop5Shelters(); -// } - -// @GetMapping("/regionSummary") -// public List> regionWiseSummary() { -// return shelterApiService.getRegionSummary(); -// } - -// @GetMapping("/fundReceivedSummary") -// public List> fundReceivedSummary() { -// return shelterApiService.getFundReceivedSummary(); -// } -// -// @GetMapping("/monthlyTrends") -// public List> monthlyTrends(){ -// return shelterApiService.getMonthlyTrends(); -// } -// -// @GetMapping("/weeklyVisits") -// public List> weeklyVisits(){ -// return shelterApiService.getWeeklyVisits(); -// } -// -// @GetMapping("/latestVisitShelters") -// public List> latestVisitShelters(){ -// return shelterApiService.getLatestVisitShelters(); -// } @GetMapping("/shelterList") public List> shelterList( @@ -168,15 +143,24 @@ public class ShelterInspectionController { } + @GetMapping("/questions") - public ResponseEntity getQuestions() { - - return restTemplate.getForEntity( - "https://gccservices.in/gccofficialapp/api/shelterinspection/questions?cid=1", - Object.class - ); - - } + public ResponseEntity getquestionsDetails(@RequestParam("cid") String cid){ + String apiUrl = appConfig.shelterurl + "/questions?cid=" + cid; + return restTemplate.getForEntity(apiUrl, String.class); + + } + + +// @GetMapping("/questions") +// public ResponseEntity getQuestions(@RequestParam String cid) { +// +// return restTemplate.getForEntity( +// "https://gccservices.in/gccofficialapp/api/shelterinspection/questions?cid="+cid, +// Object.class +// ); +// +// } // @GetMapping("/shelterList") // public List> shelterList(){ diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java b/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java index dccc473..915f78d 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java @@ -58,7 +58,7 @@ public class ShelterInspectionService { } // Dashboard - // Dashboard + public Map getDashboardData(String type, String value) { Map response = new LinkedHashMap<>(); @@ -66,17 +66,11 @@ public class ShelterInspectionService { String dateCondition = ""; if ("day".equalsIgnoreCase(type)) { - dateCondition = " AND DATE(cdate) = ? "; - } else if ("month".equalsIgnoreCase(type)) { - dateCondition = " AND DATE_FORMAT(cdate,'%Y-%m') = ? "; - } else if ("year".equalsIgnoreCase(type)) { - dateCondition = " AND YEAR(cdate) = ? "; - } String dashboardSql = """ @@ -114,40 +108,6 @@ public class ShelterInspectionService { return response; } -// public Map getDashboardData() { -// -// Map response = new LinkedHashMap<>(); -// -// String dashboardSql = """ -// SELECT -// -// COALESCE(SUM(CASE WHEN qid = 4 THEN CAST(answer AS UNSIGNED) END), 0) AS totalResidents, -// -// COALESCE(SUM(CASE WHEN qid = 5 THEN CAST(answer AS UNSIGNED) END), 0) AS numberOfVisits, -// -// COALESCE(SUM(CASE WHEN qid = 16 THEN CAST(answer AS UNSIGNED) END), 0) AS rehabilitation, -// -// COALESCE(SUM(CASE WHEN qid = 17 THEN CAST(answer AS UNSIGNED) END), 0) AS reintegration, -// -// COALESCE(SUM(CASE WHEN qid = 48 THEN CAST(answer AS UNSIGNED) END), 0) AS entitlementAccess, -// -// COALESCE(SUM(CASE WHEN qid = 11 THEN CAST(answer AS UNSIGNED) END), 0) AS leftWithInfo, -// -// COALESCE(SUM(CASE WHEN qid = 13 THEN CAST(answer AS UNSIGNED) END), 0) AS leftWithoutInfo, -// -// COALESCE(SUM(CASE WHEN qid = 10 THEN CAST(answer AS UNSIGNED) END), 0) AS deathCount -// -// FROM night_shelter_inspection_response -// -// WHERE isactive = 1 -// AND isdelete = 0 -// AND qid IN (4,5,10,11,13,16,17,48) -// """; -// -// response.putAll(jdbcTemplate.queryForMap(dashboardSql)); -// -// return response; -// } // Top 5 Shelter List @@ -173,17 +133,11 @@ public class ShelterInspectionService { StringBuilder dateCondition = new StringBuilder(); if ("day".equalsIgnoreCase(type)) { - dateCondition.append(" AND DATE(r.cdate) = ? "); - } else if ("month".equalsIgnoreCase(type)) { - dateCondition.append(" AND DATE_FORMAT(r.cdate,'%Y-%m') = ? "); - } else if ("year".equalsIgnoreCase(type)) { - dateCondition.append(" AND YEAR(r.cdate) = ? "); - } for (Map shelter : apiList) { @@ -208,20 +162,16 @@ public class ShelterInspectionService { Integer residents; if (dateCondition.length() == 0) { - residents = jdbcTemplate.queryForObject( sql, Integer.class, uqid); - } else { - residents = jdbcTemplate.queryForObject( sql, Integer.class, uqid, value); - } Map row = new LinkedHashMap<>(); @@ -245,155 +195,6 @@ public class ShelterInspectionService { } - -// public List> getTop5Shelters(String type, String value) { -// -// ResponseEntity>> response = -// restTemplate.exchange( -// API_URL, -// HttpMethod.GET, -// null, -// new ParameterizedTypeReference>>() { -// }); -// -// List> apiList = response.getBody(); -// -// if (apiList == null) { -// return Collections.emptyList(); -// } -// -// List> result = new ArrayList<>(); -// -// // Build date condition -// String dateCondition = ""; -// -// if ("day".equalsIgnoreCase(type)) { -// -// dateCondition = " AND DATE(r.cdate) = ? "; -// -// } else if ("month".equalsIgnoreCase(type)) { -// -// dateCondition = " AND DATE_FORMAT(r.cdate,'%Y-%m') = ? "; -// -// } else if ("year".equalsIgnoreCase(type)) { -// -// dateCondition = " AND YEAR(r.cdate) = ? "; -// -// } -// -// for (Map shelter : apiList) { -// -// String uqid = String.valueOf(shelter.get("uqid")); -// -// String sql = """ -// SELECT -// COALESCE(SUM(CAST(r.answer AS UNSIGNED)),0) -// FROM night_shelter_inspection_response r -// LEFT JOIN surveyor_location_details s -// ON r.cby = s.loginId -// WHERE r.qid = 4 -// AND r.isactive = 1 -// AND r.isdelete = 0 -// AND s.shelter_id = ? -// """ + dateCondition; -// -// Integer residents; -// -// if (dateCondition.isEmpty()) { -// -// residents = jdbcTemplate.queryForObject( -// sql, -// Integer.class, -// uqid); -// -// } else { -// -// residents = jdbcTemplate.queryForObject( -// sql, -// Integer.class, -// uqid, -// value); -// } -// -// Map row = new LinkedHashMap<>(); -// -// row.put("uqid", uqid); -// row.put("shelterName", shelter.get("shelter_name")); -// row.put("zone", shelter.get("zone")); -// row.put("category", shelter.get("category")); -// row.put("totalResidents", residents == null ? 0 : residents); -// -// result.add(row); -// } -// -// result.sort((a, b) -> Integer.compare( -// ((Number) b.get("totalResidents")).intValue(), -// ((Number) a.get("totalResidents")).intValue())); -// -// return result.stream() -// .limit(5) -// .collect(Collectors.toList()); -// } - - - -// public List> getTop5Shelters() { -// -// ResponseEntity>> response = -// restTemplate.exchange( -// API_URL, -// HttpMethod.GET, -// null, -// new ParameterizedTypeReference>>() { -// }); -// -// List> apiList = response.getBody(); -// -// if (apiList == null) { -// return Collections.emptyList(); -// } -// -// List> result = new ArrayList<>(); -// -// for (Map shelter : apiList) { -// -// String uqid = String.valueOf(shelter.get("uqid")); -// -// String sql = """ -// SELECT -// COALESCE(SUM(CAST(r.answer AS UNSIGNED)),0) -// FROM night_shelter_inspection_response r -// INNER JOIN surveyor_location_details s -// ON r.cby = s.loginId -// WHERE r.qid = 4 -// AND r.isactive = 1 -// AND r.isdelete = 0 -// AND s.shelter_id = ? -// """; -// -// Integer residents = jdbcTemplate.queryForObject( -// sql, -// Integer.class, -// uqid); -// -// Map row = new LinkedHashMap<>(); -// -// row.put("uqid", uqid); -// row.put("shelterName", shelter.get("shelter_name")); -// row.put("zone", shelter.get("zone")); -// row.put("category", shelter.get("category")); -// row.put("totalResidents", residents == null ? 0 : residents); -// -// result.add(row); -// } -// -// result.sort((a, b) -> Integer.compare( -// ((Number) b.get("totalResidents")).intValue(), -// ((Number) a.get("totalResidents")).intValue())); -// -// return result.stream().limit(5).collect(Collectors.toList()); -// } - //Region Summary public List> getRegionSummary(String type, String value) { @@ -543,101 +344,7 @@ public class ShelterInspectionService { return new ArrayList<>(regionMap.values()); } - -// public List> getRegionSummary() { -// -// ResponseEntity>> response = -// restTemplate.exchange( -// API_URL, -// HttpMethod.GET, -// null, -// new ParameterizedTypeReference>>() { -// }); -// -// List> apiData = response.getBody(); -// -// String sql = """ -// SELECT -// s.shelter_id, -// -// COALESCE(SUM( -// CASE -// WHEN r.qid = 4 THEN CAST(r.answer AS UNSIGNED) -// ELSE 0 -// END -// ),0) AS totalResidents, -// -// COUNT(DISTINCT r.cby) AS totalVisits -// -// FROM surveyor_location_details s -// -// LEFT JOIN night_shelter_inspection_response r -// ON s.loginId = r.cby -// AND r.isactive = 1 -// AND r.isdelete = 0 -// -// GROUP BY s.shelter_id -// """; -// -// List> dbData = -// jdbcTemplate.queryForList(sql); -// -// Map> dbMap = new HashMap<>(); -// -// for (Map row : dbData) { -// dbMap.put( -// String.valueOf(row.get("shelter_id")), -// row); -// } -// -// Map> regionMap = new LinkedHashMap<>(); -// -// for (Map api : apiData) { -// -// String uqid = String.valueOf(api.get("uqid")); -// -// String region = String.valueOf(api.get("region")); -// -// Map db = dbMap.get(uqid); -// -// int residents = 0; -// int visits = 0; -// -// if (db != null) { -// residents = ((Number) db.get("totalResidents")).intValue(); -// visits = ((Number) db.get("totalVisits")).intValue(); -// } -// -// Map regionRow = -// regionMap.computeIfAbsent(region, k -> { -// -// Map m = new LinkedHashMap(); -// -// m.put("region", region); -// m.put("totalShelters", 0); -// m.put("totalResidents", 0); -// m.put("totalVisits", 0); -// -// return m; -// }); -// -// regionRow.put( -// "totalShelters", -// (Integer) regionRow.get("totalShelters") + 1); -// -// regionRow.put( -// "totalResidents", -// (Integer) regionRow.get("totalResidents") + residents); -// -// regionRow.put( -// "totalVisits", -// (Integer) regionRow.get("totalVisits") + visits); -// -// } -// -// return new ArrayList<>(regionMap.values()); -// -// } + //Fund Received Summary @@ -647,17 +354,11 @@ public class ShelterInspectionService { String dateCondition = ""; if ("day".equalsIgnoreCase(type)) { - dateCondition = " AND DATE(r.cdate)=? "; - } else if ("month".equalsIgnoreCase(type)) { - dateCondition = " AND DATE_FORMAT(r.cdate,'%Y-%m')=? "; - } else if ("year".equalsIgnoreCase(type)) { - dateCondition = " AND YEAR(r.cdate)=? "; - } String sql = """ @@ -692,13 +393,9 @@ public class ShelterInspectionService { """; if (dateCondition.isEmpty()) { - return jdbcTemplate.queryForList(sql); - } else { - return jdbcTemplate.queryForList(sql, value); - } } @@ -817,9 +514,8 @@ public class ShelterInspectionService { String fundType = String.valueOf(row.get("fund_type")); String shelterId = String.valueOf(row.get("shelter_id")); - /* - * Create fund group - */ + //Create fund group + Map fundRow =fundMap.computeIfAbsent( fundId, k -> { @@ -852,9 +548,8 @@ public class ShelterInspectionService { fundRow.get("shelters"); - /* - * Avoid duplicate shelter in same fund type - */ + // Avoid duplicate shelter in same fund type + boolean alreadyExists = shelters.stream() .anyMatch( @@ -889,9 +584,8 @@ public class ShelterInspectionService { } - /* - * Add DB details also - */ + // Add DB details also + shelter.put("qid", row.get("qid")); shelter.put("cby", row.get("cby")); shelter.put("survey_id", row.get("survey_id")); @@ -907,29 +601,7 @@ public class ShelterInspectionService { return new ArrayList<>(fundMap.values()); } - - -// public List> getFundReceivedSummary() { -// -// String sql = """ -// SELECT -// am.answer AS fund_type, -// COUNT(r.id) AS total -// FROM night_shelter_inspection_answer_master am -// LEFT JOIN night_shelter_inspection_response r -// ON CAST(r.answer AS UNSIGNED) = am.id -// AND r.qid = 51 -// AND r.isactive = 1 -// AND r.isdelete = 0 -// WHERE am.qid = 51 -// AND am.isactive = 1 -// AND am.isdelete = 0 -// GROUP BY am.id, am.answer -// ORDER BY am.orderby -// """; -// -// return jdbcTemplate.queryForList(sql); -// } + //Monthly Trends @@ -1036,65 +708,6 @@ public class ShelterInspectionService { } -// public List> getMonthlyTrends() { -// -// String sql = """ -// SELECT -// -// MONTH(cdate) AS month_no, -// -// DATE_FORMAT(cdate,'%b') AS month, -// -// COALESCE(SUM(CASE -// WHEN qid = 4 -// THEN CAST(answer AS UNSIGNED) -// END),0) AS residents, -// -// COALESCE(SUM(CASE -// WHEN qid = 16 -// THEN CAST(answer AS UNSIGNED) -// END),0) AS rehabilitated, -// -// COALESCE(SUM(CASE -// WHEN qid = 17 -// THEN CAST(answer AS UNSIGNED) -// END),0) AS reintegration, -// -// COALESCE(SUM(CASE -// WHEN qid = 10 -// THEN CAST(answer AS UNSIGNED) -// END),0) AS death -// -// FROM night_shelter_inspection_response -// -// WHERE isactive=1 -// AND isdelete=0 -// -// GROUP BY -// MONTH(cdate), -// DATE_FORMAT(cdate,'%b') -// -// ORDER BY -// MONTH(cdate) -// """; -// -// List> list = -// jdbcTemplate.queryForList(sql); -// -// for(Map row:list){ -// -// int total_count = -// ((Number)row.get("residents")).intValue() -// + ((Number)row.get("rehabilitated")).intValue() -// + ((Number)row.get("reintegration")).intValue() -// + ((Number)row.get("death")).intValue(); -// -// row.put("total_count",total_count); -// } -// -// return list; -// } - //CDO Week Visit @@ -1166,25 +779,6 @@ public class ShelterInspectionService { } - -// public List> getWeeklyVisits() { -// -// String sql = -// "SELECT " + -// "DAYOFWEEK(sld.cdate) AS day_no, " + -// "DATE_FORMAT(sld.cdate,'%a') AS day_name, " + -// "COUNT(DISTINCT sld.loginId) AS visits " + -// "FROM surveyor_location_details sld " + -// "INNER JOIN night_shelter_inspection_response nr " + -// "ON nr.cby = sld.loginId " + -// "WHERE YEARWEEK(sld.cdate,1)=YEARWEEK(CURDATE(),1) " + -// "AND sld.is_active=1 " + -// "AND sld.is_delete=0 " + -// "GROUP BY DAYOFWEEK(sld.cdate),DATE_FORMAT(sld.cdate,'%a') " + -// "ORDER BY day_no"; -// -// return jdbcTemplate.queryForList(sql); -// } // Latest Visit Shelter @@ -1224,9 +818,9 @@ public class ShelterInspectionService { FROM night_shelter_inspection_response r INNER JOIN surveyor_location_details s - ON r.cby = s.loginId + ON r.cby = s.loginId AND r.survey_id = s.survey_id - INNER JOIN login_details ld + INNER JOIN gcc_children_survey.login_details ld ON ld.uid = s.loginId WHERE r.isactive = 1 @@ -1329,78 +923,6 @@ public class ShelterInspectionService { } -// public List> getLatestVisitShelters() { -// -// ResponseEntity>> response = -// restTemplate.exchange( -// API_URL, -// HttpMethod.GET, -// null, -// new ParameterizedTypeReference>>() {}); -// -// List> apiList = response.getBody(); -// -// if (apiList == null) { -// return Collections.emptyList(); -// } -// -// List> result = new ArrayList<>(); -// -// for (Map shelter : apiList) { -// -// String uqid = String.valueOf(shelter.get("uqid")); -// -// String sql = """ -// SELECT -// ld.user_name, -// MAX(r.cdate) AS visit_date -// FROM night_shelter_inspection_response r -// INNER JOIN surveyor_location_details s -// ON r.cby = s.loginId -// INNER JOIN login_details ld -// ON ld.uid = s.loginId -// WHERE r.isactive = 1 -// AND r.isdelete = 0 -// AND s.shelter_id = ? -// GROUP BY ld.user_name -// ORDER BY visit_date DESC -// LIMIT 1 -// """; -// -// List> list = -// jdbcTemplate.queryForList(sql, uqid); -// -// Map row = new LinkedHashMap<>(); -// -// row.put("shelterName", shelter.get("shelter_name")); -// row.put("zone", shelter.get("zone")); -// -// if(!list.isEmpty()){ -// row.put("userName", list.get(0).get("user_name")); -// row.put("visitDate", list.get(0).get("visit_date")); -// }else{ -// row.put("userName", "-"); -// row.put("visitDate", null); -// } -// -// result.add(row); -// } -// -// result.sort((a,b)->{ -// -// LocalDateTime t1 = (LocalDateTime) a.get("visitDate"); -// LocalDateTime t2 = (LocalDateTime) b.get("visitDate"); -// -// if(t1==null && t2==null) return 0; -// if(t1==null) return 1; -// if(t2==null) return -1; -// -// return t2.compareTo(t1); -// }); -// -// return result.stream().limit(5).collect(Collectors.toList()); -// } - // SHelter List @@ -1501,6 +1023,77 @@ public class ShelterInspectionService { DateTimeFormatter.ofPattern("dd/MM/yyyy")); } } + + + // Maintenance Status + String maintenanceSql = """ + SELECT + SUM(CASE WHEN CAST(r.answer AS UNSIGNED) = 1 THEN 1 ELSE 0 END) AS answer1_count, + SUM(CASE WHEN CAST(r.answer AS UNSIGNED) = 2 THEN 1 ELSE 0 END) AS answer2_count, + SUM(CASE WHEN CAST(r.answer AS UNSIGNED) = 3 THEN 1 ELSE 0 END) AS answer3_count, + SUM(CASE WHEN CAST(r.answer AS UNSIGNED) = 4 THEN 1 ELSE 0 END) AS answer4_count, + + MAX(CASE WHEN m.id = 1 THEN m.english_name END) AS well_maintained, + MAX(CASE WHEN m.id = 2 THEN m.english_name END) AS averagely_maintained, + MAX(CASE WHEN m.id = 3 THEN m.english_name END) AS poorly_maintained, + MAX(CASE WHEN m.id = 4 THEN m.english_name END) AS extremely_bad + + FROM surveyor_location_details s + + LEFT JOIN night_shelter_inspection_response r + ON r.survey_id = s.survey_id + AND r.cby = s.loginId + AND r.isactive = 1 + AND r.isdelete = 0 + AND r.qid BETWEEN 53 AND 58 + + LEFT JOIN night_shelter_inspection_questions_master q + ON q.qid = r.qid + AND q.master_table_name = 'shelter_maintenance_master' + AND q.isactive = 1 + AND q.isdelete = 0 + + LEFT JOIN shelter_maintenance_master m + ON m.id = CAST(r.answer AS UNSIGNED) + AND m.isactive = 1 + AND m.isdelete = 0 + + WHERE s.shelter_id = ? + """; + + Map maintenanceData = jdbcTemplate.queryForMap(maintenanceSql, uqid); + + + int answer1Count = maintenanceData.get("answer1_count") == null + ? 0 + : ((Number) maintenanceData.get("answer1_count")).intValue(); + + int answer2Count = maintenanceData.get("answer2_count") == null + ? 0 + : ((Number) maintenanceData.get("answer2_count")).intValue(); + + int answer3Count = maintenanceData.get("answer3_count") == null + ? 0 + : ((Number) maintenanceData.get("answer3_count")).intValue(); + + int answer4Count = maintenanceData.get("answer4_count") == null + ? 0 + : ((Number) maintenanceData.get("answer4_count")).intValue(); + + String maintenanceStatus = "Not Available"; + + if (answer1Count >= 4) { + maintenanceStatus = "Well maintained"; + } + else if (answer2Count >= 3) { + maintenanceStatus = "Averagely maintained"; + } + else if (answer3Count >= 2) { + maintenanceStatus = "Poorly maintained"; + } + else if (answer4Count >= 2) { + maintenanceStatus = "Extremely bad condition"; + } Map row = new LinkedHashMap<>(); @@ -1510,6 +1103,9 @@ public class ShelterInspectionService { row.put("category", shelter.get("category")); row.put("totalResidents", residents == null ? 0 : residents); row.put("latestVisit", latestVisit); + + // NEW + row.put("maintenanceStatus", maintenanceStatus); result.add(row); } @@ -1524,11 +1120,7 @@ public class ShelterInspectionService { //Visit List - public List> getVisitList( - String fromDate, - String toDate, - String zone, - String cdo) { + public List> getVisitList(String fromDate, String toDate, String zone, String cdo) { ResponseEntity>> response = restTemplate.exchange( @@ -1570,14 +1162,55 @@ public class ShelterInspectionService { END ), '/5' - ) AS staff + ) AS staff, + + SUM( + CASE + WHEN r.qid BETWEEN 53 AND 58 + AND CAST(r.answer AS UNSIGNED) = 1 + THEN 1 + ELSE 0 + END + ) AS maintenance_1, + + + SUM( + CASE + WHEN r.qid BETWEEN 53 AND 58 + AND CAST(r.answer AS UNSIGNED) = 2 + THEN 1 + ELSE 0 + END + ) AS maintenance_2, + + + SUM( + CASE + WHEN r.qid BETWEEN 53 AND 58 + AND CAST(r.answer AS UNSIGNED) = 3 + THEN 1 + ELSE 0 + END + ) AS maintenance_3, + + + SUM( + CASE + WHEN r.qid BETWEEN 53 AND 58 + AND CAST(r.answer AS UNSIGNED) = 4 + THEN 1 + ELSE 0 + END + ) AS maintenance_4 + FROM night_shelter_inspection_response r - INNER JOIN surveyor_location_details s - ON r.cby = s.loginId + INNER JOIN surveyor_location_details s + ON r.cby = s.loginId + AND r.survey_id = s.survey_id - INNER JOIN login_details ld + INNER JOIN gcc_children_survey.login_details ld ON ld.uid = s.loginId WHERE r.isactive = 1 @@ -1650,6 +1283,59 @@ public class ShelterInspectionService { date = dt.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")); time = dt.format(DateTimeFormatter.ofPattern("hh:mm a")); } + + // ========================= + // MAINTENANCE COUNTS + // ========================= + + int maintenance1 = + db.get("maintenance_1") == null + ? 0 + : ((Number) + db.get("maintenance_1")) + .intValue(); + + + int maintenance2 = + db.get("maintenance_2") == null + ? 0 + : ((Number) + db.get("maintenance_2")) + .intValue(); + + + int maintenance3 = + db.get("maintenance_3") == null + ? 0 + : ((Number) + db.get("maintenance_3")) + .intValue(); + + + int maintenance4 = + db.get("maintenance_4") == null + ? 0 + : ((Number) + db.get("maintenance_4")) + .intValue(); + + + // ========================= + // MAINTENANCE STATUS + // ========================= + + String maintenanceStatus = "Not Available"; + + if (maintenance1 >= 4) { + maintenanceStatus = "Well maintained"; + } else if (maintenance2 >= 3) { + maintenanceStatus = "Averagely maintained"; + } else if (maintenance3 >= 2) { + maintenanceStatus = "Poorly maintained"; + } else if (maintenance4 >= 2) { + maintenanceStatus = "Extremely bad condition"; + } + Map row=new LinkedHashMap<>(); @@ -1664,6 +1350,8 @@ public class ShelterInspectionService { row.put("food",db.get("food")); row.put("staff",db.get("staff")); + + row.put("maintenanceStatus", maintenanceStatus); result.add(row); @@ -1704,7 +1392,7 @@ public class ShelterInspectionService { INNER JOIN surveyor_location_details s ON s.loginId = r.cby - INNER JOIN login_details ld + INNER JOIN gcc_children_survey.login_details ld ON ld.uid = s.loginId WHERE r.survey_id = ? @@ -1767,6 +1455,8 @@ public class ShelterInspectionService { result.put("longitude",api.get("longitude")); result.put("address",api.get("address")); result.put("image",api.get("image")); + + } diff --git a/src/main/resources/templates/modules/shelterinspection/dashboard.html b/src/main/resources/templates/modules/shelterinspection/dashboard.html index 310cd6b..319c38d 100644 --- a/src/main/resources/templates/modules/shelterinspection/dashboard.html +++ b/src/main/resources/templates/modules/shelterinspection/dashboard.html @@ -408,14 +408,6 @@ background: #1f6ea5; color: #ffffff; } - -/* .btn-view-all{ - background:#EAF5FB; - color:#1f6ea5; - border-radius:8px; - width:100%; - font-weight:600; - } */ /* Fund List */ diff --git a/src/main/resources/templates/modules/shelterinspection/shelterlist.html b/src/main/resources/templates/modules/shelterinspection/shelterlist.html index e39ce76..55a43f4 100644 --- a/src/main/resources/templates/modules/shelterinspection/shelterlist.html +++ b/src/main/resources/templates/modules/shelterinspection/shelterlist.html @@ -23,36 +23,32 @@
+ + -
@@ -70,14 +66,6 @@
- -
@@ -95,13 +83,14 @@ - S.No - SHELTER - ZONE - CATEGORY - RESIDENTS - STATUS - Latest Visit + S.No + SHELTER + ZONE + CATEGORY + RESIDENTS + OCCUPANCY STATUS + MAINTENACE STATUS + Latest Visit @@ -187,21 +176,13 @@ ${i + 1} - - ${item.shelterName || "-"} - - - ${item.zone || "-"} - - ${formatCategory(item.category)} - - - ${item.totalResidents || 0} - - - ${getStatusBadge(item.totalResidents)} - - ${item.latestVisit || "-"} + ${item.shelterName || "-"} + ${item.zone || "-"} + ${formatCategory(item.category)} + ${item.totalResidents || 0} + ${getStatusBadge(item.totalResidents)} + ${getMaintenanceBadge(item.maintenanceStatus)} + ${item.latestVisit || "-"} `; }); @@ -244,7 +225,8 @@ Swal.fire({ icon: 'error', title: 'Error', - text: 'Unable to load shelter list.' + text: 'Unable to load shelter list.', + allowOutsideClick: false }); } @@ -253,96 +235,7 @@ } - /* function loadShelterList() { - - if ($.fn.DataTable.isDataTable('#shelterListTable')) { - $('#shelterListTable').DataTable().destroy(); - } - - $("#shelterListTable tbody").empty(); - - $.ajax({ - - url: "/gcc/api/shelterinspection/shelterList", - type: "GET", - - success: function (response) { - - let rows = ""; - - $.each(response, function (i, item) { - - rows += ` - - - ${i + 1} - - - ${item.shelterName || "-"} - - - ${item.zone || "-"} - - ${formatCategory(item.category)} - - - ${item.totalResidents || 0} - - - - ${getStatusBadge(item.totalResidents)} - - - ${item.latestVisit || "-"} - - - `; - }); - - $("#shelterListTable tbody").html(rows); - - $('#shelterListTable').DataTable({ - - responsive: true, - - pageLength: 10, - - ordering: true, - - dom: 'Bfrtip', - - buttons: [ - { - extend: 'pageLength', - className: 'btn btn-warning' - }, - { - extend: 'excelHtml5', - text: 'Excel', - className: 'btn btn-success' - }, - { - extend: 'pdfHtml5', - text: 'PDF', - className: 'btn btn-secondary', - orientation: 'landscape', - pageSize: 'A4' - } - ] - - }); - - }, - - error: function () { - - alert("Unable to load Shelter List."); - - } - - }); - - } */ + function formatCategory(category) { @@ -360,21 +253,34 @@ function getStatusBadge(residents){ if(residents >= 100){ - return 'Good'; - }else if(residents >= 25){ - return 'Average'; - }else{ - return 'Poor'; - } } + function getMaintenanceBadge(status) { + if (!status || status === "Not Available") { + return 'Not Available'; + } + if (status === "Well maintained") { + return 'Well maintained'; + } + if (status === "Averagely maintained") { + return 'Averagely maintained'; + } + if (status === "Poorly maintained") { + return 'Poorly maintained'; + } + if (status === "Extremely bad condition") { + return 'Extremely bad condition'; + } + return 'Not Available'; + } + diff --git a/src/main/resources/templates/modules/shelterinspection/visitlist.html b/src/main/resources/templates/modules/shelterinspection/visitlist.html index a6d508e..84dfd5a 100644 --- a/src/main/resources/templates/modules/shelterinspection/visitlist.html +++ b/src/main/resources/templates/modules/shelterinspection/visitlist.html @@ -121,36 +121,32 @@
+ + -
@@ -192,15 +188,16 @@ - S.No - SHELTER - ZONE - CDO - DATE - TIME - FOOD - STAFF - ACTION + S.No + SHELTER + ZONE + CDO + DATE + TIME + FOOD + Maintenance Status + STAFF + ACTION @@ -233,7 +230,6 @@