Browse Source

moditify the visit list at shelter inspection project

master
Dizho A 2 months ago
parent
commit
aa7be06fde
  1. 2
      src/main/java/in/gov/chennaicorporation/gccoffice/configuration/AppConfig.java
  2. 68
      src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java
  3. 684
      src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java
  4. 8
      src/main/resources/templates/modules/shelterinspection/dashboard.html
  5. 214
      src/main/resources/templates/modules/shelterinspection/shelterlist.html
  6. 146
      src/main/resources/templates/modules/shelterinspection/visitlist.html

2
src/main/java/in/gov/chennaicorporation/gccoffice/configuration/AppConfig.java

@ -25,6 +25,8 @@ public class AppConfig {
public String gccappsMysqlPassword = ""; public String gccappsMysqlPassword = "";
public String domesticurl="https://gccservices.in/gccofficialapp/api/domesticwaste"; 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 otpUrl = "https://tmegov.onex-aura.com/api/sms?";
public String getOtpUrl() { public String getOtpUrl() {

68
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.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; 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.MasterShelterService;
import in.gov.chennaicorporation.gccoffice.shelterinspection.Service.ShelterInspectionService; import in.gov.chennaicorporation.gccoffice.shelterinspection.Service.ShelterInspectionService;
@ -26,7 +27,16 @@ public class ShelterInspectionController {
@Autowired @Autowired
private MasterShelterService masterShelterService; 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") @GetMapping("/Sheltercount")
public ResponseEntity<Map<String, Object>> getTotalCount() { public ResponseEntity<Map<String, Object>> getTotalCount() {
@ -106,41 +116,6 @@ public class ShelterInspectionController {
return shelterApiService.getLatestVisitShelters(type,value); return shelterApiService.getLatestVisitShelters(type,value);
} }
// @GetMapping("/dashboard")
// public Map<String, Object> dashboard() {
// return shelterApiService.getDashboardData();
// }
// @GetMapping("/top5Shelters")
// public List<Map<String, Object>> getTop5Shelters() {
// return shelterApiService.getTop5Shelters();
// }
// @GetMapping("/regionSummary")
// public List<Map<String, Object>> regionWiseSummary() {
// return shelterApiService.getRegionSummary();
// }
// @GetMapping("/fundReceivedSummary")
// public List<Map<String, Object>> fundReceivedSummary() {
// return shelterApiService.getFundReceivedSummary();
// }
//
// @GetMapping("/monthlyTrends")
// public List<Map<String,Object>> monthlyTrends(){
// return shelterApiService.getMonthlyTrends();
// }
//
// @GetMapping("/weeklyVisits")
// public List<Map<String,Object>> weeklyVisits(){
// return shelterApiService.getWeeklyVisits();
// }
//
// @GetMapping("/latestVisitShelters")
// public List<Map<String,Object>> latestVisitShelters(){
// return shelterApiService.getLatestVisitShelters();
// }
@GetMapping("/shelterList") @GetMapping("/shelterList")
public List<Map<String,Object>> shelterList( public List<Map<String,Object>> shelterList(
@ -168,15 +143,24 @@ public class ShelterInspectionController {
} }
@GetMapping("/questions") @GetMapping("/questions")
public ResponseEntity<?> getQuestions() {
public ResponseEntity<?> getquestionsDetails(@RequestParam("cid") String cid){
String apiUrl = appConfig.shelterurl + "/questions?cid=" + cid;
return restTemplate.getForEntity(apiUrl, String.class);
return restTemplate.getForEntity(
"https://gccservices.in/gccofficialapp/api/shelterinspection/questions?cid=1",
Object.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") // @GetMapping("/shelterList")
// public List<Map<String,Object>> shelterList(){ // public List<Map<String,Object>> shelterList(){

684
src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java

@ -58,7 +58,7 @@ public class ShelterInspectionService {
} }
// Dashboard // Dashboard
// Dashboard
public Map<String, Object> getDashboardData(String type, String value) { public Map<String, Object> getDashboardData(String type, String value) {
Map<String, Object> response = new LinkedHashMap<>(); Map<String, Object> response = new LinkedHashMap<>();
@ -66,17 +66,11 @@ public class ShelterInspectionService {
String dateCondition = ""; String dateCondition = "";
if ("day".equalsIgnoreCase(type)) { if ("day".equalsIgnoreCase(type)) {
dateCondition = " AND DATE(cdate) = ? "; dateCondition = " AND DATE(cdate) = ? ";
} else if ("month".equalsIgnoreCase(type)) { } else if ("month".equalsIgnoreCase(type)) {
dateCondition = " AND DATE_FORMAT(cdate,'%Y-%m') = ? "; dateCondition = " AND DATE_FORMAT(cdate,'%Y-%m') = ? ";
} else if ("year".equalsIgnoreCase(type)) { } else if ("year".equalsIgnoreCase(type)) {
dateCondition = " AND YEAR(cdate) = ? "; dateCondition = " AND YEAR(cdate) = ? ";
} }
String dashboardSql = """ String dashboardSql = """
@ -114,40 +108,6 @@ public class ShelterInspectionService {
return response; return response;
} }
// public Map<String, Object> getDashboardData() {
//
// Map<String, Object> 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 // Top 5 Shelter List
@ -173,17 +133,11 @@ public class ShelterInspectionService {
StringBuilder dateCondition = new StringBuilder(); StringBuilder dateCondition = new StringBuilder();
if ("day".equalsIgnoreCase(type)) { if ("day".equalsIgnoreCase(type)) {
dateCondition.append(" AND DATE(r.cdate) = ? "); dateCondition.append(" AND DATE(r.cdate) = ? ");
} else if ("month".equalsIgnoreCase(type)) { } else if ("month".equalsIgnoreCase(type)) {
dateCondition.append(" AND DATE_FORMAT(r.cdate,'%Y-%m') = ? "); dateCondition.append(" AND DATE_FORMAT(r.cdate,'%Y-%m') = ? ");
} else if ("year".equalsIgnoreCase(type)) { } else if ("year".equalsIgnoreCase(type)) {
dateCondition.append(" AND YEAR(r.cdate) = ? "); dateCondition.append(" AND YEAR(r.cdate) = ? ");
} }
for (Map<String, Object> shelter : apiList) { for (Map<String, Object> shelter : apiList) {
@ -208,20 +162,16 @@ public class ShelterInspectionService {
Integer residents; Integer residents;
if (dateCondition.length() == 0) { if (dateCondition.length() == 0) {
residents = jdbcTemplate.queryForObject( residents = jdbcTemplate.queryForObject(
sql, sql,
Integer.class, Integer.class,
uqid); uqid);
} else { } else {
residents = jdbcTemplate.queryForObject( residents = jdbcTemplate.queryForObject(
sql, sql,
Integer.class, Integer.class,
uqid, uqid,
value); value);
} }
Map<String, Object> row = new LinkedHashMap<>(); Map<String, Object> row = new LinkedHashMap<>();
@ -245,155 +195,6 @@ public class ShelterInspectionService {
} }
// public List<Map<String, Object>> getTop5Shelters(String type, String value) {
//
// ResponseEntity<List<Map<String, Object>>> response =
// restTemplate.exchange(
// API_URL,
// HttpMethod.GET,
// null,
// new ParameterizedTypeReference<List<Map<String, Object>>>() {
// });
//
// List<Map<String, Object>> apiList = response.getBody();
//
// if (apiList == null) {
// return Collections.emptyList();
// }
//
// List<Map<String, Object>> 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<String, Object> 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<String, Object> 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<Map<String, Object>> getTop5Shelters() {
//
// ResponseEntity<List<Map<String, Object>>> response =
// restTemplate.exchange(
// API_URL,
// HttpMethod.GET,
// null,
// new ParameterizedTypeReference<List<Map<String, Object>>>() {
// });
//
// List<Map<String, Object>> apiList = response.getBody();
//
// if (apiList == null) {
// return Collections.emptyList();
// }
//
// List<Map<String, Object>> result = new ArrayList<>();
//
// for (Map<String, Object> 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<String, Object> 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 //Region Summary
public List<Map<String, Object>> getRegionSummary(String type, String value) { public List<Map<String, Object>> getRegionSummary(String type, String value) {
@ -544,100 +345,6 @@ public class ShelterInspectionService {
} }
// public List<Map<String, Object>> getRegionSummary() {
//
// ResponseEntity<List<Map<String, Object>>> response =
// restTemplate.exchange(
// API_URL,
// HttpMethod.GET,
// null,
// new ParameterizedTypeReference<List<Map<String, Object>>>() {
// });
//
// List<Map<String, Object>> 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<Map<String, Object>> dbData =
// jdbcTemplate.queryForList(sql);
//
// Map<String, Map<String, Object>> dbMap = new HashMap<>();
//
// for (Map<String, Object> row : dbData) {
// dbMap.put(
// String.valueOf(row.get("shelter_id")),
// row);
// }
//
// Map<String, Map<String, Object>> regionMap = new LinkedHashMap<>();
//
// for (Map<String, Object> api : apiData) {
//
// String uqid = String.valueOf(api.get("uqid"));
//
// String region = String.valueOf(api.get("region"));
//
// Map<String, Object> 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<String, Object> regionRow =
// regionMap.computeIfAbsent(region, k -> {
//
// Map<String, Object> 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 //Fund Received Summary
@ -647,17 +354,11 @@ public class ShelterInspectionService {
String dateCondition = ""; String dateCondition = "";
if ("day".equalsIgnoreCase(type)) { if ("day".equalsIgnoreCase(type)) {
dateCondition = " AND DATE(r.cdate)=? "; dateCondition = " AND DATE(r.cdate)=? ";
} else if ("month".equalsIgnoreCase(type)) { } else if ("month".equalsIgnoreCase(type)) {
dateCondition = " AND DATE_FORMAT(r.cdate,'%Y-%m')=? "; dateCondition = " AND DATE_FORMAT(r.cdate,'%Y-%m')=? ";
} else if ("year".equalsIgnoreCase(type)) { } else if ("year".equalsIgnoreCase(type)) {
dateCondition = " AND YEAR(r.cdate)=? "; dateCondition = " AND YEAR(r.cdate)=? ";
} }
String sql = """ String sql = """
@ -692,13 +393,9 @@ public class ShelterInspectionService {
"""; """;
if (dateCondition.isEmpty()) { if (dateCondition.isEmpty()) {
return jdbcTemplate.queryForList(sql); return jdbcTemplate.queryForList(sql);
} else { } else {
return jdbcTemplate.queryForList(sql, value); return jdbcTemplate.queryForList(sql, value);
} }
} }
@ -817,9 +514,8 @@ public class ShelterInspectionService {
String fundType = String.valueOf(row.get("fund_type")); String fundType = String.valueOf(row.get("fund_type"));
String shelterId = String.valueOf(row.get("shelter_id")); String shelterId = String.valueOf(row.get("shelter_id"));
/*
* Create fund group
*/
//Create fund group
Map<String, Object> fundRow =fundMap.computeIfAbsent( Map<String, Object> fundRow =fundMap.computeIfAbsent(
fundId, k -> { fundId, k -> {
@ -852,9 +548,8 @@ public class ShelterInspectionService {
fundRow.get("shelters"); fundRow.get("shelters");
/*
* Avoid duplicate shelter in same fund type
*/
// Avoid duplicate shelter in same fund type
boolean alreadyExists = boolean alreadyExists =
shelters.stream() shelters.stream()
.anyMatch( .anyMatch(
@ -889,9 +584,8 @@ public class ShelterInspectionService {
} }
/*
* Add DB details also
*/
// Add DB details also
shelter.put("qid", row.get("qid")); shelter.put("qid", row.get("qid"));
shelter.put("cby", row.get("cby")); shelter.put("cby", row.get("cby"));
shelter.put("survey_id", row.get("survey_id")); shelter.put("survey_id", row.get("survey_id"));
@ -909,28 +603,6 @@ public class ShelterInspectionService {
// public List<Map<String, Object>> 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 //Monthly Trends
public List<Map<String, Object>> getMonthlyTrends(String type, String value) { public List<Map<String, Object>> getMonthlyTrends(String type, String value) {
@ -1036,65 +708,6 @@ public class ShelterInspectionService {
} }
// public List<Map<String, Object>> 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<Map<String,Object>> list =
// jdbcTemplate.queryForList(sql);
//
// for(Map<String,Object> 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 //CDO Week Visit
@ -1167,25 +780,6 @@ public class ShelterInspectionService {
} }
// public List<Map<String, Object>> 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 // Latest Visit Shelter
@ -1224,9 +818,9 @@ public class ShelterInspectionService {
FROM night_shelter_inspection_response r FROM night_shelter_inspection_response r
INNER JOIN surveyor_location_details s 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 ON ld.uid = s.loginId
WHERE r.isactive = 1 WHERE r.isactive = 1
@ -1329,78 +923,6 @@ public class ShelterInspectionService {
} }
// public List<Map<String, Object>> getLatestVisitShelters() {
//
// ResponseEntity<List<Map<String, Object>>> response =
// restTemplate.exchange(
// API_URL,
// HttpMethod.GET,
// null,
// new ParameterizedTypeReference<List<Map<String, Object>>>() {});
//
// List<Map<String, Object>> apiList = response.getBody();
//
// if (apiList == null) {
// return Collections.emptyList();
// }
//
// List<Map<String, Object>> result = new ArrayList<>();
//
// for (Map<String, Object> 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<Map<String,Object>> list =
// jdbcTemplate.queryForList(sql, uqid);
//
// Map<String,Object> 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 // SHelter List
@ -1502,6 +1024,77 @@ public class ShelterInspectionService {
} }
} }
// 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<String, Object> 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<String, Object> row = new LinkedHashMap<>(); Map<String, Object> row = new LinkedHashMap<>();
row.put("uqid", uqid); row.put("uqid", uqid);
@ -1511,6 +1104,9 @@ public class ShelterInspectionService {
row.put("totalResidents", residents == null ? 0 : residents); row.put("totalResidents", residents == null ? 0 : residents);
row.put("latestVisit", latestVisit); row.put("latestVisit", latestVisit);
// NEW
row.put("maintenanceStatus", maintenanceStatus);
result.add(row); result.add(row);
} }
@ -1524,11 +1120,7 @@ public class ShelterInspectionService {
//Visit List //Visit List
public List<Map<String,Object>> getVisitList(
String fromDate,
String toDate,
String zone,
String cdo) {
public List<Map<String,Object>> getVisitList(String fromDate, String toDate, String zone, String cdo) {
ResponseEntity<List<Map<String, Object>>> response = ResponseEntity<List<Map<String, Object>>> response =
restTemplate.exchange( restTemplate.exchange(
@ -1570,14 +1162,55 @@ public class ShelterInspectionService {
END END
), ),
'/5' '/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 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 ON ld.uid = s.loginId
WHERE r.isactive = 1 WHERE r.isactive = 1
@ -1651,6 +1284,59 @@ public class ShelterInspectionService {
time = dt.format(DateTimeFormatter.ofPattern("hh:mm a")); 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<String,Object> row=new LinkedHashMap<>(); Map<String,Object> row=new LinkedHashMap<>();
row.put("surveyId", db.get("survey_id")); row.put("surveyId", db.get("survey_id"));
@ -1665,6 +1351,8 @@ public class ShelterInspectionService {
row.put("food",db.get("food")); row.put("food",db.get("food"));
row.put("staff",db.get("staff")); row.put("staff",db.get("staff"));
row.put("maintenanceStatus", maintenanceStatus);
result.add(row); result.add(row);
} }
@ -1704,7 +1392,7 @@ public class ShelterInspectionService {
INNER JOIN surveyor_location_details s INNER JOIN surveyor_location_details s
ON s.loginId = r.cby ON s.loginId = r.cby
INNER JOIN login_details ld
INNER JOIN gcc_children_survey.login_details ld
ON ld.uid = s.loginId ON ld.uid = s.loginId
WHERE r.survey_id = ? WHERE r.survey_id = ?
@ -1768,6 +1456,8 @@ public class ShelterInspectionService {
result.put("address",api.get("address")); result.put("address",api.get("address"));
result.put("image",api.get("image")); result.put("image",api.get("image"));
} }
result.put("answers",answers); result.put("answers",answers);

8
src/main/resources/templates/modules/shelterinspection/dashboard.html

@ -409,14 +409,6 @@
color: #ffffff; color: #ffffff;
} }
/* .btn-view-all{
background:#EAF5FB;
color:#1f6ea5;
border-radius:8px;
width:100%;
font-weight:600;
} */
/* Fund List */ /* Fund List */

214
src/main/resources/templates/modules/shelterinspection/shelterlist.html

@ -24,35 +24,31 @@
<div class="main-content"> <div class="main-content">
<div class="container-fluid"> <div class="container-fluid">
<div class="page-header">
<div class="row align-items-center">
<div class="page-header">
<div class="row align-items-end">
<div class="col-lg-6">
<div class="page-header-title">
<i class="far fa-list-alt bg-blue"></i>
<div class="d-inline">
<h5>Shelter List</h5>
<span>Shelter Inspection</span>
</div>
</div>
</div>
<div class="col-lg-6">
<nav class="breadcrumb-container" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="/index"><i class="ik ik-home"></i></a>
</li>
<li class="breadcrumb-item" aria-current="page">Shelter Inspection</li>
<li class="breadcrumb-item active" aria-current="page">Shelter List</li>
</ol>
</nav>
</div>
</div>
</div>
<!-- LEFT SIDE -->
<div class="col-lg-6">
<div class="page-header-title d-flex align-items-center">
<i class="ik ik-thumbs-up bg-blue me-2"></i>
<h5 class="mb-0">Shelters List</h5>
</div>
</div>
</div>
<!-- BREADCRUMB (SEPARATE ROW) -->
<div class="row mt-2">
<div class="col-lg-12">
<nav class="breadcrumb-container">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="/index"><i class="ik ik-home"></i></a>
</li>
<li class="breadcrumb-item active"> Shelters List</li>
</ol>
</nav>
</div>
</div>
</div>
<hr> <hr>
@ -70,14 +66,6 @@
<option value="">All Categories</option> <option value="">All Categories</option>
</select> </select>
</div> </div>
<!-- <div class="col-md-6">
<label class="form-label fw-semibold me-2">From Date:</label>
<input type="date" id="fromDate" class="form-control d-inline-block" style="width:150px;">
<label class="form-label fw-semibold me-2">To Date:</label>
<input type="date" id="toDate" class="form-control d-inline-block" style="width:150px;">
</div> -->
<div class="col-md-2"> <div class="col-md-2">
@ -95,13 +83,14 @@
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th>S.No</th>
<th>SHELTER</th>
<th>ZONE</th>
<th>CATEGORY</th>
<th>RESIDENTS</th>
<th>STATUS</th>
<th>Latest Visit</th>
<th class="text-center">S.No</th>
<th class="text-center">SHELTER</th>
<th class="text-center">ZONE</th>
<th class="text-center">CATEGORY</th>
<th class="text-center">RESIDENTS</th>
<th class="text-center">OCCUPANCY STATUS</th>
<th class="text-center">MAINTENACE STATUS</th>
<th class="text-center">Latest Visit</th>
</tr> </tr>
</thead> </thead>
@ -187,21 +176,13 @@
<tr> <tr>
<td>${i + 1}</td> <td>${i + 1}</td>
<td>
<strong>${item.shelterName || "-"}</strong>
</td>
<td>${item.zone || "-"}</td>
<td>${formatCategory(item.category)}</td>
<td class="text-center">
${item.totalResidents || 0}
</td>
<td>${getStatusBadge(item.totalResidents)}</td>
<td>${item.latestVisit || "-"}</td>
<td><strong>${item.shelterName || "-"}</strong></td>
<td class="text-center">${item.zone || "-"}</td>
<td class="text-center">${formatCategory(item.category)}</td>
<td class="text-center">${item.totalResidents || 0}</td>
<td class="text-center">${getStatusBadge(item.totalResidents)}</td>
<td class="text-center">${getMaintenanceBadge(item.maintenanceStatus)}</td>
<td class="text-center">${item.latestVisit || "-"}</td>
</tr> </tr>
`; `;
}); });
@ -244,7 +225,8 @@
Swal.fire({ Swal.fire({
icon: 'error', icon: 'error',
title: '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 += `
<tr>
<td>${i + 1}</td>
<td>
<strong>${item.shelterName || "-"}</strong>
</td>
<td>${item.zone || "-"}</td>
<td>${formatCategory(item.category)}</td>
<td class="text-center">
${item.totalResidents || 0}
</td>
<td>
${getStatusBadge(item.totalResidents)}
</td>
<td>${item.latestVisit || "-"}</td>
</tr>
`;
});
$("#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) { function formatCategory(category) {
@ -360,21 +253,34 @@
function getStatusBadge(residents){ function getStatusBadge(residents){
if(residents >= 100){ if(residents >= 100){
return '<span class="badge badge-success">Good</span>'; return '<span class="badge badge-success">Good</span>';
}else if(residents >= 25){ }else if(residents >= 25){
return '<span class="badge badge-warning">Average</span>'; return '<span class="badge badge-warning">Average</span>';
}else{ }else{
return '<span class="badge badge-danger">Poor</span>'; return '<span class="badge badge-danger">Poor</span>';
} }
} }
function getMaintenanceBadge(status) {
if (!status || status === "Not Available") {
return '<span class="badge badge-secondary">Not Available</span>';
}
if (status === "Well maintained") {
return '<span class="badge badge-success">Well maintained</span>';
}
if (status === "Averagely maintained") {
return '<span class="badge badge-warning">Averagely maintained</span>';
}
if (status === "Poorly maintained") {
return '<span class="badge badge-danger">Poorly maintained</span>';
}
if (status === "Extremely bad condition") {
return '<span class="badge badge-dark">Extremely bad condition</span>';
}
return '<span class="badge badge-secondary">Not Available</span>';
}

146
src/main/resources/templates/modules/shelterinspection/visitlist.html

@ -122,35 +122,31 @@
<div class="main-content"> <div class="main-content">
<div class="container-fluid"> <div class="container-fluid">
<div class="page-header">
<div class="row align-items-center">
<div class="page-header">
<div class="row align-items-end">
<div class="col-lg-6">
<div class="page-header-title">
<i class="far fa-list-alt bg-blue"></i>
<div class="d-inline">
<h5>Visit List</h5>
<span>Shelter Inspection</span>
</div>
</div>
</div>
<div class="col-lg-6">
<nav class="breadcrumb-container" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="/index"><i class="ik ik-home"></i></a>
</li>
<li class="breadcrumb-item" aria-current="page">Shelter Inspection</li>
<li class="breadcrumb-item active" aria-current="page">Visit List</li>
</ol>
</nav>
</div>
</div>
</div>
<!-- LEFT SIDE -->
<div class="col-lg-6">
<div class="page-header-title d-flex align-items-center">
<i class="ik ik-thumbs-up bg-blue me-2"></i>
<h5 class="mb-0">Visits List</h5>
</div>
</div>
</div>
<!-- BREADCRUMB (SEPARATE ROW) -->
<div class="row mt-2">
<div class="col-lg-12">
<nav class="breadcrumb-container">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="/index"><i class="ik ik-home"></i></a>
</li>
<li class="breadcrumb-item active"> Visits List</li>
</ol>
</nav>
</div>
</div>
</div>
<hr> <hr>
@ -192,15 +188,16 @@
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th>S.No</th>
<th>SHELTER</th>
<th>ZONE</th>
<th>CDO</th>
<th>DATE</th>
<th>TIME</th>
<th>FOOD</th>
<th>STAFF</th>
<th>ACTION</th>
<th class="text-center">S.No</th>
<th class="text-center">SHELTER</th>
<th class="text-center">ZONE</th>
<th class="text-center">CDO</th>
<th class="text-center">DATE</th>
<th class="text-center">TIME</th>
<th class="text-center">FOOD</th>
<th class="text-center">Maintenance Status</th>
<th class="text-center">STAFF</th>
<th class="text-center">ACTION</th>
</tr> </tr>
</thead> </thead>
@ -233,7 +230,6 @@
<div class="modal-header bg-dark text-white"> <div class="modal-header bg-dark text-white">
<div> <div>
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<h5 class="mb-0">CDO Daily Inspection</h5> <h5 class="mb-0">CDO Daily Inspection</h5>
<span class="mx-2">-</span> <span class="mx-2">-</span>
@ -890,12 +886,13 @@
<tr> <tr>
<td>${i + 1}</td> <td>${i + 1}</td>
<td><strong>${item.shelterName || "-"}</strong></td> <td><strong>${item.shelterName || "-"}</strong></td>
<td>${item.zone || "-"}</td>
<td>${item.userName || "-"}</td>
<td>${item.date || "-"}</td>
<td>${item.time || "-"}</td>
<td>${getFoodBadge(item.food)}</td>
<td>${getStaffBadge(item.staff)}</td>
<td class="text-center">${item.zone || "-"}</td>
<td class="text-center">${item.userName || "-"}</td>
<td class="text-center">${item.date || "-"}</td>
<td class="text-center">${item.time || "-"}</td>
<td class="text-center">${getFoodBadge(item.food)}</td>
<td class="text-center">${getMaintenanceBadge( item.maintenanceStatus)}</td>
<td class="text-center">${getStaffBadge(item.staff)}</td>
<td class="text-center"> <td class="text-center">
<button class="btn btn-sm btn-primary" <button class="btn btn-sm btn-primary"
@ -945,7 +942,8 @@
Swal.fire({ Swal.fire({
icon: 'error', icon: 'error',
title: 'Error', title: 'Error',
text: 'Unable to load Visit List.'
text: 'Unable to load Visit List.',
allowOutsideClick: false
}); });
} }
@ -978,6 +976,28 @@
} }
function getMaintenanceBadge(status) {
if (!status || status === "Not Available") {
return '<span class="badge badge-secondary">Not Available</span>';
}
if (status === "Well maintained") {
return '<span class="badge badge-success">Well maintained</span>';
}
if (status === "Averagely maintained") {
return '<span class="badge badge-warning">Averagely maintained</span>';
}
if (status === "Poorly maintained") {
return '<span class="badge badge-danger">Poorly maintained</span>';
}
if (status === "Extremely bad condition") {
return '<span class="badge badge-dark">Extremely bad condition</span>';
}
return '<span class="badge badge-secondary">Not Available</span>';
}
//dropdown //dropdown
function loadDropdowns() { function loadDropdowns() {
@ -1025,13 +1045,13 @@
//Visit tab //Visit tab
const tabs = [ const tabs = [
"#generalTab",
"#residentTab",
"#foodTab",
"#billTab",
"#documentTab",
"#maintenanceTab"
];
"#generalTab",
"#residentTab",
"#foodTab",
"#billTab",
"#documentTab",
"#maintenanceTab"
];
function activateTab(index){ function activateTab(index){
@ -1113,11 +1133,6 @@
} }
/* $("#gGPS").text(
res.latitude+
", "+
res.longitude
); */
if(res.image){ if(res.image){
@ -1241,7 +1256,7 @@
$.ajax({ $.ajax({
url:"/gcc/api/shelterinspection/questions", url:"/gcc/api/shelterinspection/questions",
type:"GET", type:"GET",
data:{ cid:1 },
data:{cid:1},
success:function(res){ success:function(res){
@ -1647,21 +1662,6 @@
} }
/* if(ans["47"]){
$("#maintPhoto")
.attr("href",ans["47"])
.show();
}else{
$("#maintPhoto")
.removeAttr("href")
.text("No Photo")
.addClass("disabled");
} */
} }

Loading…
Cancel
Save