|
|
@ -24,8 +24,6 @@ import org.springframework.jdbc.core.JdbcTemplate; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class ShelterInspectionService { |
|
|
public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
@ -37,20 +35,18 @@ public class ShelterInspectionService { |
|
|
this.jdbcTemplate = new JdbcTemplate(dataSource); |
|
|
this.jdbcTemplate = new JdbcTemplate(dataSource); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final RestTemplate restTemplate = new RestTemplate(); |
|
|
private final RestTemplate restTemplate = new RestTemplate(); |
|
|
|
|
|
|
|
|
private static final String API_URL = "https://nightshelter.gccservices.in/api/shelters/"; |
|
|
private static final String API_URL = "https://nightshelter.gccservices.in/api/shelters/"; |
|
|
|
|
|
|
|
|
public int getTotalShelterCount() { |
|
|
public int getTotalShelterCount() { |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = |
|
|
|
|
|
restTemplate.exchange( |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange( |
|
|
API_URL, |
|
|
API_URL, |
|
|
HttpMethod.GET, |
|
|
HttpMethod.GET, |
|
|
null, |
|
|
null, |
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() {} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() { |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
List<Map<String, Object>> shelters = response.getBody(); |
|
|
List<Map<String, Object>> shelters = response.getBody(); |
|
|
|
|
|
|
|
|
@ -78,7 +74,7 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
COALESCE(SUM(CASE WHEN qid = 4 THEN CAST(answer AS UNSIGNED) END),0) AS totalResidents, |
|
|
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, |
|
|
|
|
|
|
|
|
COUNT(DISTINCT survey_id) AS numberOfVisits, |
|
|
|
|
|
|
|
|
COALESCE(SUM(CASE WHEN qid = 16 THEN CAST(answer AS UNSIGNED) END),0) AS rehabilitation, |
|
|
COALESCE(SUM(CASE WHEN qid = 16 THEN CAST(answer AS UNSIGNED) END),0) AS rehabilitation, |
|
|
|
|
|
|
|
|
@ -96,7 +92,7 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
WHERE isactive = 1 |
|
|
WHERE isactive = 1 |
|
|
AND isdelete = 0 |
|
|
AND isdelete = 0 |
|
|
AND qid IN (4,5,10,11,13,16,17,48) |
|
|
|
|
|
|
|
|
|
|
|
""" + dateCondition; |
|
|
""" + dateCondition; |
|
|
|
|
|
|
|
|
if (dateCondition.isEmpty()) { |
|
|
if (dateCondition.isEmpty()) { |
|
|
@ -108,13 +104,11 @@ public class ShelterInspectionService { |
|
|
return response; |
|
|
return response; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Top 5 Shelter List |
|
|
// Top 5 Shelter List |
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getTop5Shelters(String type, String value) { |
|
|
public List<Map<String, Object>> getTop5Shelters(String type, String value) { |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = |
|
|
|
|
|
restTemplate.exchange( |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange( |
|
|
API_URL, |
|
|
API_URL, |
|
|
HttpMethod.GET, |
|
|
HttpMethod.GET, |
|
|
null, |
|
|
null, |
|
|
@ -194,13 +188,11 @@ public class ShelterInspectionService { |
|
|
.collect(Collectors.toList()); |
|
|
.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) { |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = |
|
|
|
|
|
restTemplate.exchange( |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange( |
|
|
API_URL, |
|
|
API_URL, |
|
|
HttpMethod.GET, |
|
|
HttpMethod.GET, |
|
|
null, |
|
|
null, |
|
|
@ -274,13 +266,13 @@ public class ShelterInspectionService { |
|
|
GROUP BY s.shelter_id |
|
|
GROUP BY s.shelter_id |
|
|
"""); |
|
|
"""); |
|
|
|
|
|
|
|
|
List<Map<String,Object>> dbData; |
|
|
|
|
|
|
|
|
List<Map<String, Object>> dbData; |
|
|
|
|
|
|
|
|
if(params.isEmpty()){ |
|
|
|
|
|
|
|
|
if (params.isEmpty()) { |
|
|
|
|
|
|
|
|
dbData = jdbcTemplate.queryForList(sql.toString()); |
|
|
dbData = jdbcTemplate.queryForList(sql.toString()); |
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
dbData = jdbcTemplate.queryForList( |
|
|
dbData = jdbcTemplate.queryForList( |
|
|
sql.toString(), |
|
|
sql.toString(), |
|
|
@ -313,8 +305,7 @@ public class ShelterInspectionService { |
|
|
visits = ((Number) db.get("totalVisits")).intValue(); |
|
|
visits = ((Number) db.get("totalVisits")).intValue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Map<String, Object> regionRow = |
|
|
|
|
|
regionMap.computeIfAbsent(region, k -> { |
|
|
|
|
|
|
|
|
Map<String, Object> regionRow = regionMap.computeIfAbsent(region, k -> { |
|
|
|
|
|
|
|
|
Map<String, Object> m = new LinkedHashMap<>(); |
|
|
Map<String, Object> m = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
@ -345,9 +336,7 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Fund Received Summary |
|
|
|
|
|
|
|
|
// Fund Received Summary |
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getFundReceivedSummary(String type, String value) { |
|
|
public List<Map<String, Object>> getFundReceivedSummary(String type, String value) { |
|
|
|
|
|
|
|
|
@ -400,7 +389,6 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fund Recieved Total Details |
|
|
// Fund Recieved Total Details |
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getFundReceivedShelterDetails( |
|
|
public List<Map<String, Object>> getFundReceivedShelterDetails( |
|
|
@ -408,8 +396,7 @@ public class ShelterInspectionService { |
|
|
String value) { |
|
|
String value) { |
|
|
|
|
|
|
|
|
/* Get shelter details from external API */ |
|
|
/* Get shelter details from external API */ |
|
|
ResponseEntity<List<Map<String, Object>>> response = |
|
|
|
|
|
restTemplate.exchange( |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange( |
|
|
API_URL, |
|
|
API_URL, |
|
|
HttpMethod.GET, |
|
|
HttpMethod.GET, |
|
|
null, |
|
|
null, |
|
|
@ -426,11 +413,10 @@ public class ShelterInspectionService { |
|
|
Map<String, Map<String, Object>> shelterApiMap = new HashMap<>(); |
|
|
Map<String, Map<String, Object>> shelterApiMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
for (Map<String, Object> shelter : apiList) { |
|
|
for (Map<String, Object> shelter : apiList) { |
|
|
String uqid = String.valueOf( shelter.get("uqid")); |
|
|
|
|
|
|
|
|
String uqid = String.valueOf(shelter.get("uqid")); |
|
|
shelterApiMap.put(uqid, shelter); |
|
|
shelterApiMap.put(uqid, shelter); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Date filter */ |
|
|
/* Date filter */ |
|
|
String dateCondition = ""; |
|
|
String dateCondition = ""; |
|
|
|
|
|
|
|
|
@ -442,7 +428,6 @@ public class ShelterInspectionService { |
|
|
dateCondition = " AND YEAR(r.cdate) = ? "; |
|
|
dateCondition = " AND YEAR(r.cdate) = ? "; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Get fund response + shelter mapping |
|
|
* Get fund response + shelter mapping |
|
|
* |
|
|
* |
|
|
@ -493,7 +478,6 @@ public class ShelterInspectionService { |
|
|
ORDER BY am.orderby |
|
|
ORDER BY am.orderby |
|
|
"""; |
|
|
"""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Execute query */ |
|
|
/* Execute query */ |
|
|
List<Map<String, Object>> dbList; |
|
|
List<Map<String, Object>> dbList; |
|
|
|
|
|
|
|
|
@ -503,20 +487,18 @@ public class ShelterInspectionService { |
|
|
dbList = jdbcTemplate.queryForList(sql, value); |
|
|
dbList = jdbcTemplate.queryForList(sql, value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Group by Fund Type */ |
|
|
/* Group by Fund Type */ |
|
|
Map<String, Map<String, Object>> fundMap = new LinkedHashMap<>(); |
|
|
Map<String, Map<String, Object>> fundMap = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Map<String, Object> row : dbList) { |
|
|
for (Map<String, Object> row : dbList) { |
|
|
|
|
|
|
|
|
String fundId = String.valueOf(row.get("fund_id")); |
|
|
String fundId = String.valueOf(row.get("fund_id")); |
|
|
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 -> { |
|
|
|
|
|
|
|
|
Map<String, Object> map = new LinkedHashMap<>(); |
|
|
Map<String, Object> map = new LinkedHashMap<>(); |
|
|
@ -530,7 +512,6 @@ public class ShelterInspectionService { |
|
|
return map; |
|
|
return map; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Existing total + 1 |
|
|
* Existing total + 1 |
|
|
* |
|
|
* |
|
|
@ -540,24 +521,18 @@ public class ShelterInspectionService { |
|
|
int total = ((Number) fundRow.get("total")).intValue(); |
|
|
int total = ((Number) fundRow.get("total")).intValue(); |
|
|
fundRow.put("total", total + 1); |
|
|
fundRow.put("total", total + 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*Shelter list*/ |
|
|
|
|
|
|
|
|
/* Shelter list */ |
|
|
@SuppressWarnings("unchecked") |
|
|
@SuppressWarnings("unchecked") |
|
|
List<Map<String, Object>> shelters = |
|
|
|
|
|
(List<Map<String, Object>>) |
|
|
|
|
|
fundRow.get("shelters"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> shelters = (List<Map<String, Object>>) fundRow.get("shelters"); |
|
|
|
|
|
|
|
|
// Avoid duplicate shelter in same fund type |
|
|
// Avoid duplicate shelter in same fund type |
|
|
|
|
|
|
|
|
boolean alreadyExists = |
|
|
|
|
|
shelters.stream() |
|
|
|
|
|
|
|
|
boolean alreadyExists = shelters.stream() |
|
|
.anyMatch( |
|
|
.anyMatch( |
|
|
x -> shelterId.equals( |
|
|
x -> shelterId.equals( |
|
|
String.valueOf( |
|
|
String.valueOf( |
|
|
x.get("shelter_id")))); |
|
|
x.get("shelter_id")))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!alreadyExists) { |
|
|
if (!alreadyExists) { |
|
|
|
|
|
|
|
|
Map<String, Object> apiShelter = shelterApiMap.get(shelterId); |
|
|
Map<String, Object> apiShelter = shelterApiMap.get(shelterId); |
|
|
@ -579,11 +554,10 @@ public class ShelterInspectionService { |
|
|
shelter.put("shelter_name", "-"); |
|
|
shelter.put("shelter_name", "-"); |
|
|
shelter.put("zone", "-"); |
|
|
shelter.put("zone", "-"); |
|
|
shelter.put("division", "-"); |
|
|
shelter.put("division", "-"); |
|
|
shelter.put( "shelter_type", "-"); |
|
|
|
|
|
|
|
|
shelter.put("shelter_type", "-"); |
|
|
shelter.put("category", "-"); |
|
|
shelter.put("category", "-"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add DB details also |
|
|
// Add DB details also |
|
|
|
|
|
|
|
|
shelter.put("qid", row.get("qid")); |
|
|
shelter.put("qid", row.get("qid")); |
|
|
@ -592,18 +566,14 @@ public class ShelterInspectionService { |
|
|
shelter.put("loginId", row.get("loginId")); |
|
|
shelter.put("loginId", row.get("loginId")); |
|
|
shelter.put("location_survey_id", row.get("location_survey_id")); |
|
|
shelter.put("location_survey_id", row.get("location_survey_id")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shelters.add(shelter); |
|
|
shelters.add(shelter); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ArrayList<>(fundMap.values()); |
|
|
return new ArrayList<>(fundMap.values()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Monthly Trends |
|
|
|
|
|
|
|
|
// Monthly Trends |
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getMonthlyTrends(String type, String value) { |
|
|
public List<Map<String, Object>> getMonthlyTrends(String type, String value) { |
|
|
|
|
|
|
|
|
@ -678,13 +648,13 @@ public class ShelterInspectionService { |
|
|
MONTH(cdate) |
|
|
MONTH(cdate) |
|
|
"""); |
|
|
"""); |
|
|
|
|
|
|
|
|
List<Map<String,Object>> list; |
|
|
|
|
|
|
|
|
List<Map<String, Object>> list; |
|
|
|
|
|
|
|
|
if(params.isEmpty()){ |
|
|
|
|
|
|
|
|
if (params.isEmpty()) { |
|
|
|
|
|
|
|
|
list = jdbcTemplate.queryForList(sql.toString()); |
|
|
list = jdbcTemplate.queryForList(sql.toString()); |
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
list = jdbcTemplate.queryForList( |
|
|
list = jdbcTemplate.queryForList( |
|
|
sql.toString(), |
|
|
sql.toString(), |
|
|
@ -692,13 +662,12 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for(Map<String,Object> row : list){ |
|
|
|
|
|
|
|
|
for (Map<String, Object> row : list) { |
|
|
|
|
|
|
|
|
int totalCount = |
|
|
|
|
|
((Number)row.get("residents")).intValue() |
|
|
|
|
|
+ ((Number)row.get("rehabilitated")).intValue() |
|
|
|
|
|
+ ((Number)row.get("reintegration")).intValue() |
|
|
|
|
|
+ ((Number)row.get("death")).intValue(); |
|
|
|
|
|
|
|
|
int totalCount = ((Number) row.get("residents")).intValue() |
|
|
|
|
|
+ ((Number) row.get("rehabilitated")).intValue() |
|
|
|
|
|
+ ((Number) row.get("reintegration")).intValue() |
|
|
|
|
|
+ ((Number) row.get("death")).intValue(); |
|
|
|
|
|
|
|
|
row.put("total_count", totalCount); |
|
|
row.put("total_count", totalCount); |
|
|
|
|
|
|
|
|
@ -708,8 +677,7 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//CDO Week Visit |
|
|
|
|
|
|
|
|
// CDO Week Visit |
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getWeeklyVisits(String type, String value) { |
|
|
public List<Map<String, Object>> getWeeklyVisits(String type, String value) { |
|
|
|
|
|
|
|
|
@ -767,7 +735,7 @@ public class ShelterInspectionService { |
|
|
DAYOFWEEK(sld.cdate) |
|
|
DAYOFWEEK(sld.cdate) |
|
|
"""); |
|
|
"""); |
|
|
|
|
|
|
|
|
if(params.isEmpty()){ |
|
|
|
|
|
|
|
|
if (params.isEmpty()) { |
|
|
|
|
|
|
|
|
return jdbcTemplate.queryForList(sql.toString()); |
|
|
return jdbcTemplate.queryForList(sql.toString()); |
|
|
|
|
|
|
|
|
@ -779,20 +747,18 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Latest Visit Shelter |
|
|
// Latest Visit Shelter |
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getLatestVisitShelters( |
|
|
public List<Map<String, Object>> getLatestVisitShelters( |
|
|
String type, |
|
|
String type, |
|
|
String value) { |
|
|
String value) { |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = |
|
|
|
|
|
restTemplate.exchange( |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange( |
|
|
API_URL, |
|
|
API_URL, |
|
|
HttpMethod.GET, |
|
|
HttpMethod.GET, |
|
|
null, |
|
|
null, |
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() {}); |
|
|
|
|
|
|
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() { |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
List<Map<String, Object>> apiList = response.getBody(); |
|
|
List<Map<String, Object>> apiList = response.getBody(); |
|
|
|
|
|
|
|
|
@ -820,7 +786,7 @@ public class ShelterInspectionService { |
|
|
INNER JOIN surveyor_location_details s |
|
|
INNER JOIN surveyor_location_details s |
|
|
ON r.cby = s.loginId AND r.survey_id = s.survey_id |
|
|
ON r.cby = s.loginId AND r.survey_id = s.survey_id |
|
|
|
|
|
|
|
|
INNER JOIN gcc_children_survey.login_details ld |
|
|
|
|
|
|
|
|
INNER JOIN gcc_mobile_menus.login_details ld |
|
|
ON ld.uid = s.loginId |
|
|
ON ld.uid = s.loginId |
|
|
|
|
|
|
|
|
WHERE r.isactive = 1 |
|
|
WHERE r.isactive = 1 |
|
|
@ -858,20 +824,18 @@ public class ShelterInspectionService { |
|
|
LIMIT 1 |
|
|
LIMIT 1 |
|
|
"""); |
|
|
"""); |
|
|
|
|
|
|
|
|
List<Map<String,Object>> list = |
|
|
|
|
|
jdbcTemplate.queryForList( |
|
|
|
|
|
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList( |
|
|
sql.toString(), |
|
|
sql.toString(), |
|
|
params.toArray()); |
|
|
params.toArray()); |
|
|
|
|
|
|
|
|
Map<String,Object> row = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
Map<String, Object> row = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
row.put("shelterName", shelter.get("shelter_name")); |
|
|
row.put("shelterName", shelter.get("shelter_name")); |
|
|
row.put("zone", shelter.get("zone")); |
|
|
row.put("zone", shelter.get("zone")); |
|
|
|
|
|
|
|
|
if(!list.isEmpty()){ |
|
|
|
|
|
|
|
|
if (!list.isEmpty()) { |
|
|
|
|
|
|
|
|
LocalDateTime visit = |
|
|
|
|
|
(LocalDateTime) list.get(0).get("visit_date"); |
|
|
|
|
|
|
|
|
LocalDateTime visit = (LocalDateTime) list.get(0).get("visit_date"); |
|
|
|
|
|
|
|
|
row.put("userName", |
|
|
row.put("userName", |
|
|
list.get(0).get("user_name")); |
|
|
list.get(0).get("user_name")); |
|
|
@ -886,12 +850,12 @@ public class ShelterInspectionService { |
|
|
visit.format( |
|
|
visit.format( |
|
|
DateTimeFormatter.ofPattern("hh:mm a"))); |
|
|
DateTimeFormatter.ofPattern("hh:mm a"))); |
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
row.put("userName","-"); |
|
|
|
|
|
row.put("visitDate",null); |
|
|
|
|
|
row.put("date","-"); |
|
|
|
|
|
row.put("time","-"); |
|
|
|
|
|
|
|
|
row.put("userName", "-"); |
|
|
|
|
|
row.put("visitDate", null); |
|
|
|
|
|
row.put("date", "-"); |
|
|
|
|
|
row.put("time", "-"); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -899,18 +863,18 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
result.sort((a,b)->{ |
|
|
|
|
|
|
|
|
result.sort((a, b) -> { |
|
|
|
|
|
|
|
|
LocalDateTime t1=(LocalDateTime)a.get("visitDate"); |
|
|
|
|
|
LocalDateTime t2=(LocalDateTime)b.get("visitDate"); |
|
|
|
|
|
|
|
|
LocalDateTime t1 = (LocalDateTime) a.get("visitDate"); |
|
|
|
|
|
LocalDateTime t2 = (LocalDateTime) b.get("visitDate"); |
|
|
|
|
|
|
|
|
if(t1==null && t2==null) |
|
|
|
|
|
|
|
|
if (t1 == null && t2 == null) |
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
|
if(t1==null) |
|
|
|
|
|
|
|
|
if (t1 == null) |
|
|
return 1; |
|
|
return 1; |
|
|
|
|
|
|
|
|
if(t2==null) |
|
|
|
|
|
|
|
|
if (t2 == null) |
|
|
return -1; |
|
|
return -1; |
|
|
|
|
|
|
|
|
return t2.compareTo(t1); |
|
|
return t2.compareTo(t1); |
|
|
@ -923,17 +887,16 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SHelter List |
|
|
// SHelter List |
|
|
|
|
|
|
|
|
public List<Map<String, Object>> getShelterList(String zone, String category) { |
|
|
public List<Map<String, Object>> getShelterList(String zone, String category) { |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = |
|
|
|
|
|
restTemplate.exchange( |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange( |
|
|
API_URL, |
|
|
API_URL, |
|
|
HttpMethod.GET, |
|
|
HttpMethod.GET, |
|
|
null, |
|
|
null, |
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() {}); |
|
|
|
|
|
|
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() { |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
List<Map<String, Object>> apiList = response.getBody(); |
|
|
List<Map<String, Object>> apiList = response.getBody(); |
|
|
|
|
|
|
|
|
@ -982,7 +945,6 @@ public class ShelterInspectionService { |
|
|
WHERE s.shelter_id = ? |
|
|
WHERE s.shelter_id = ? |
|
|
"""; |
|
|
"""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer residents = jdbcTemplate.queryForObject( |
|
|
Integer residents = jdbcTemplate.queryForObject( |
|
|
residentSql, |
|
|
residentSql, |
|
|
Integer.class, |
|
|
Integer.class, |
|
|
@ -1002,7 +964,6 @@ public class ShelterInspectionService { |
|
|
WHERE s.shelter_id = ? |
|
|
WHERE s.shelter_id = ? |
|
|
"""; |
|
|
"""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LocalDateTime visitDate = jdbcTemplate.queryForObject( |
|
|
LocalDateTime visitDate = jdbcTemplate.queryForObject( |
|
|
latestVisitSql, |
|
|
latestVisitSql, |
|
|
LocalDateTime.class, |
|
|
LocalDateTime.class, |
|
|
@ -1024,7 +985,6 @@ public class ShelterInspectionService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Maintenance Status |
|
|
// Maintenance Status |
|
|
String maintenanceSql = """ |
|
|
String maintenanceSql = """ |
|
|
SELECT |
|
|
SELECT |
|
|
@ -1063,7 +1023,6 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
Map<String, Object> maintenanceData = jdbcTemplate.queryForMap(maintenanceSql, uqid); |
|
|
Map<String, Object> maintenanceData = jdbcTemplate.queryForMap(maintenanceSql, uqid); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int answer1Count = maintenanceData.get("answer1_count") == null |
|
|
int answer1Count = maintenanceData.get("answer1_count") == null |
|
|
? 0 |
|
|
? 0 |
|
|
: ((Number) maintenanceData.get("answer1_count")).intValue(); |
|
|
: ((Number) maintenanceData.get("answer1_count")).intValue(); |
|
|
@ -1084,14 +1043,11 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
if (answer1Count >= 4) { |
|
|
if (answer1Count >= 4) { |
|
|
maintenanceStatus = "Well maintained"; |
|
|
maintenanceStatus = "Well maintained"; |
|
|
} |
|
|
|
|
|
else if (answer2Count >= 3) { |
|
|
|
|
|
|
|
|
} else if (answer2Count >= 3) { |
|
|
maintenanceStatus = "Averagely maintained"; |
|
|
maintenanceStatus = "Averagely maintained"; |
|
|
} |
|
|
|
|
|
else if (answer3Count >= 2) { |
|
|
|
|
|
|
|
|
} else if (answer3Count >= 2) { |
|
|
maintenanceStatus = "Poorly maintained"; |
|
|
maintenanceStatus = "Poorly maintained"; |
|
|
} |
|
|
|
|
|
else if (answer4Count >= 2) { |
|
|
|
|
|
|
|
|
} else if (answer4Count >= 2) { |
|
|
maintenanceStatus = "Extremely bad condition"; |
|
|
maintenanceStatus = "Extremely bad condition"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1117,22 +1073,19 @@ public class ShelterInspectionService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Visit List |
|
|
|
|
|
public List<Map<String, Object>> getVisitList(String fromDate, String toDate, String zone, String cdo) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Visit List |
|
|
|
|
|
public List<Map<String,Object>> getVisitList(String fromDate, String toDate, String zone, String cdo) { |
|
|
|
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = |
|
|
|
|
|
restTemplate.exchange( |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange( |
|
|
API_URL, |
|
|
API_URL, |
|
|
HttpMethod.GET, |
|
|
HttpMethod.GET, |
|
|
null, |
|
|
null, |
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() { |
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
List<Map<String,Object>> apiShelters = response.getBody(); |
|
|
|
|
|
|
|
|
List<Map<String, Object>> apiShelters = response.getBody(); |
|
|
|
|
|
|
|
|
if(apiShelters==null){ |
|
|
|
|
|
|
|
|
if (apiShelters == null) { |
|
|
return Collections.emptyList(); |
|
|
return Collections.emptyList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1210,7 +1163,7 @@ public class ShelterInspectionService { |
|
|
ON r.cby = s.loginId |
|
|
ON r.cby = s.loginId |
|
|
AND r.survey_id = s.survey_id |
|
|
AND r.survey_id = s.survey_id |
|
|
|
|
|
|
|
|
INNER JOIN gcc_children_survey.login_details ld |
|
|
|
|
|
|
|
|
INNER JOIN gcc_mobile_menus.login_details ld |
|
|
ON ld.uid = s.loginId |
|
|
ON ld.uid = s.loginId |
|
|
|
|
|
|
|
|
WHERE r.isactive = 1 |
|
|
WHERE r.isactive = 1 |
|
|
@ -1245,28 +1198,25 @@ public class ShelterInspectionService { |
|
|
visitDate DESC |
|
|
visitDate DESC |
|
|
"""); |
|
|
"""); |
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> dbList = jdbcTemplate.queryForList(sql.toString(), params.toArray()); |
|
|
|
|
|
|
|
|
List<Map<String,Object>> dbList= |
|
|
|
|
|
jdbcTemplate.queryForList(sql.toString(),params.toArray()); |
|
|
|
|
|
|
|
|
|
|
|
List<Map<String,Object>> result=new ArrayList<>(); |
|
|
|
|
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>(); |
|
|
|
|
|
|
|
|
for(Map<String,Object> db:dbList){ |
|
|
|
|
|
|
|
|
for (Map<String, Object> db : dbList) { |
|
|
|
|
|
|
|
|
String shelterId=String.valueOf(db.get("shelter_id")); |
|
|
|
|
|
|
|
|
String shelterId = String.valueOf(db.get("shelter_id")); |
|
|
|
|
|
|
|
|
Map<String,Object> api=apiShelters.stream() |
|
|
|
|
|
|
|
|
Map<String, Object> api = apiShelters.stream() |
|
|
|
|
|
|
|
|
.filter(x->shelterId.equals(String.valueOf(x.get("uqid")))) |
|
|
|
|
|
|
|
|
.filter(x -> shelterId.equals(String.valueOf(x.get("uqid")))) |
|
|
|
|
|
|
|
|
.findFirst() |
|
|
.findFirst() |
|
|
|
|
|
|
|
|
.orElse(null); |
|
|
.orElse(null); |
|
|
|
|
|
|
|
|
if(api==null) |
|
|
|
|
|
|
|
|
if (api == null) |
|
|
continue; |
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String apiZone = String.valueOf(api.get("zone")); |
|
|
String apiZone = String.valueOf(api.get("zone")); |
|
|
|
|
|
|
|
|
if (zone != null && !zone.isBlank() |
|
|
if (zone != null && !zone.isBlank() |
|
|
@ -1288,38 +1238,26 @@ public class ShelterInspectionService { |
|
|
// MAINTENANCE COUNTS |
|
|
// MAINTENANCE COUNTS |
|
|
// ========================= |
|
|
// ========================= |
|
|
|
|
|
|
|
|
int maintenance1 = |
|
|
|
|
|
db.get("maintenance_1") == null |
|
|
|
|
|
|
|
|
int maintenance1 = db.get("maintenance_1") == null |
|
|
? 0 |
|
|
? 0 |
|
|
: ((Number) |
|
|
|
|
|
db.get("maintenance_1")) |
|
|
|
|
|
|
|
|
: ((Number) db.get("maintenance_1")) |
|
|
.intValue(); |
|
|
.intValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int maintenance2 = |
|
|
|
|
|
db.get("maintenance_2") == null |
|
|
|
|
|
|
|
|
int maintenance2 = db.get("maintenance_2") == null |
|
|
? 0 |
|
|
? 0 |
|
|
: ((Number) |
|
|
|
|
|
db.get("maintenance_2")) |
|
|
|
|
|
|
|
|
: ((Number) db.get("maintenance_2")) |
|
|
.intValue(); |
|
|
.intValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int maintenance3 = |
|
|
|
|
|
db.get("maintenance_3") == null |
|
|
|
|
|
|
|
|
int maintenance3 = db.get("maintenance_3") == null |
|
|
? 0 |
|
|
? 0 |
|
|
: ((Number) |
|
|
|
|
|
db.get("maintenance_3")) |
|
|
|
|
|
|
|
|
: ((Number) db.get("maintenance_3")) |
|
|
.intValue(); |
|
|
.intValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int maintenance4 = |
|
|
|
|
|
db.get("maintenance_4") == null |
|
|
|
|
|
|
|
|
int maintenance4 = db.get("maintenance_4") == null |
|
|
? 0 |
|
|
? 0 |
|
|
: ((Number) |
|
|
|
|
|
db.get("maintenance_4")) |
|
|
|
|
|
|
|
|
: ((Number) db.get("maintenance_4")) |
|
|
.intValue(); |
|
|
.intValue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ========================= |
|
|
// ========================= |
|
|
// MAINTENANCE STATUS |
|
|
// MAINTENANCE STATUS |
|
|
// ========================= |
|
|
// ========================= |
|
|
@ -1336,20 +1274,19 @@ public class ShelterInspectionService { |
|
|
maintenanceStatus = "Extremely bad condition"; |
|
|
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")); |
|
|
|
|
|
|
|
|
row.put("shelterName",api.get("shelter_name")); |
|
|
|
|
|
row.put("zone",api.get("zone")); |
|
|
|
|
|
row.put("userName",db.get("user_name")); |
|
|
|
|
|
|
|
|
row.put("shelterName", api.get("shelter_name")); |
|
|
|
|
|
row.put("zone", api.get("zone")); |
|
|
|
|
|
row.put("userName", db.get("user_name")); |
|
|
|
|
|
|
|
|
row.put("date", date); |
|
|
row.put("date", date); |
|
|
row.put("time", time); |
|
|
row.put("time", time); |
|
|
|
|
|
|
|
|
row.put("food",db.get("food")); |
|
|
|
|
|
row.put("staff",db.get("staff")); |
|
|
|
|
|
|
|
|
row.put("food", db.get("food")); |
|
|
|
|
|
row.put("staff", db.get("staff")); |
|
|
|
|
|
|
|
|
row.put("maintenanceStatus", maintenanceStatus); |
|
|
row.put("maintenanceStatus", maintenanceStatus); |
|
|
|
|
|
|
|
|
@ -1361,17 +1298,16 @@ public class ShelterInspectionService { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Visit Details for modal box |
|
|
// Visit Details for modal box |
|
|
|
|
|
|
|
|
public Map<String, Object> getVisitDetails(String surveyId) { |
|
|
public Map<String, Object> getVisitDetails(String surveyId) { |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = |
|
|
|
|
|
restTemplate.exchange( |
|
|
|
|
|
|
|
|
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange( |
|
|
API_URL, |
|
|
API_URL, |
|
|
HttpMethod.GET, |
|
|
HttpMethod.GET, |
|
|
null, |
|
|
null, |
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() {}); |
|
|
|
|
|
|
|
|
new ParameterizedTypeReference<List<Map<String, Object>>>() { |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
List<Map<String, Object>> apiShelters = response.getBody(); |
|
|
List<Map<String, Object>> apiShelters = response.getBody(); |
|
|
|
|
|
|
|
|
@ -1392,7 +1328,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 gcc_children_survey.login_details ld |
|
|
|
|
|
|
|
|
INNER JOIN gcc_mobile_menus.login_details ld |
|
|
ON ld.uid = s.loginId |
|
|
ON ld.uid = s.loginId |
|
|
|
|
|
|
|
|
WHERE r.survey_id = ? |
|
|
WHERE r.survey_id = ? |
|
|
@ -1400,39 +1336,37 @@ public class ShelterInspectionService { |
|
|
ORDER BY r.qid |
|
|
ORDER BY r.qid |
|
|
"""; |
|
|
"""; |
|
|
|
|
|
|
|
|
List<Map<String,Object>> list = |
|
|
|
|
|
jdbcTemplate.queryForList(sql, surveyId); |
|
|
|
|
|
|
|
|
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, surveyId); |
|
|
|
|
|
|
|
|
if(list.isEmpty()){ |
|
|
|
|
|
|
|
|
if (list.isEmpty()) { |
|
|
return Collections.emptyMap(); |
|
|
return Collections.emptyMap(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Map<String,Object> first = list.get(0); |
|
|
|
|
|
|
|
|
Map<String, Object> first = list.get(0); |
|
|
|
|
|
|
|
|
String shelterId = String.valueOf(first.get("shelter_id")); |
|
|
String shelterId = String.valueOf(first.get("shelter_id")); |
|
|
|
|
|
|
|
|
Map<String,Object> api = apiShelters.stream() |
|
|
|
|
|
|
|
|
Map<String, Object> api = apiShelters.stream() |
|
|
.filter(x -> shelterId.equals(String.valueOf(x.get("uqid")))) |
|
|
.filter(x -> shelterId.equals(String.valueOf(x.get("uqid")))) |
|
|
.findFirst() |
|
|
.findFirst() |
|
|
.orElse(null); |
|
|
.orElse(null); |
|
|
|
|
|
|
|
|
Map<String,String> answers = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
Map<String, String> answers = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
for(Map<String,Object> row : list){ |
|
|
|
|
|
|
|
|
for (Map<String, Object> row : list) { |
|
|
|
|
|
|
|
|
answers.put( |
|
|
answers.put( |
|
|
String.valueOf(row.get("qid")), |
|
|
String.valueOf(row.get("qid")), |
|
|
String.valueOf(row.get("answer")) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
String.valueOf(row.get("answer"))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
LocalDateTime dateTime = (LocalDateTime) first.get("cdate"); |
|
|
LocalDateTime dateTime = (LocalDateTime) first.get("cdate"); |
|
|
|
|
|
|
|
|
Map<String,Object> result = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
Map<String, Object> result = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
result.put("surveyId",surveyId); |
|
|
|
|
|
|
|
|
result.put("surveyId", surveyId); |
|
|
|
|
|
|
|
|
result.put("userName",first.get("user_name")); |
|
|
|
|
|
|
|
|
result.put("userName", first.get("user_name")); |
|
|
|
|
|
|
|
|
result.put("date", |
|
|
result.put("date", |
|
|
dateTime.format( |
|
|
dateTime.format( |
|
|
@ -1442,32 +1376,26 @@ public class ShelterInspectionService { |
|
|
dateTime.format( |
|
|
dateTime.format( |
|
|
DateTimeFormatter.ofPattern("hh:mm a"))); |
|
|
DateTimeFormatter.ofPattern("hh:mm a"))); |
|
|
|
|
|
|
|
|
if(api!=null){ |
|
|
|
|
|
|
|
|
|
|
|
result.put("region",api.get("region")); |
|
|
|
|
|
result.put("zone",api.get("zone")); |
|
|
|
|
|
result.put("division",api.get("division")); |
|
|
|
|
|
result.put("uqid",api.get("uqid")); |
|
|
|
|
|
result.put("shelterName",api.get("shelter_name")); |
|
|
|
|
|
result.put("category",api.get("category")); |
|
|
|
|
|
result.put("shelterType",api.get("shelter_type")); |
|
|
|
|
|
result.put("latitude",api.get("latitude")); |
|
|
|
|
|
result.put("longitude",api.get("longitude")); |
|
|
|
|
|
result.put("address",api.get("address")); |
|
|
|
|
|
result.put("image",api.get("image")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (api != null) { |
|
|
|
|
|
|
|
|
|
|
|
result.put("region", api.get("region")); |
|
|
|
|
|
result.put("zone", api.get("zone")); |
|
|
|
|
|
result.put("division", api.get("division")); |
|
|
|
|
|
result.put("uqid", api.get("uqid")); |
|
|
|
|
|
result.put("shelterName", api.get("shelter_name")); |
|
|
|
|
|
result.put("category", api.get("category")); |
|
|
|
|
|
result.put("shelterType", api.get("shelter_type")); |
|
|
|
|
|
result.put("latitude", api.get("latitude")); |
|
|
|
|
|
result.put("longitude", api.get("longitude")); |
|
|
|
|
|
result.put("address", api.get("address")); |
|
|
|
|
|
result.put("image", api.get("image")); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
result.put("answers",answers); |
|
|
|
|
|
|
|
|
result.put("answers", answers); |
|
|
|
|
|
|
|
|
return result; |
|
|
return result; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |