Browse Source

added gcc_mobile_menus schema

master
AJITHKUMAR12 2 months ago
parent
commit
d8f9b150c9
  1. 2
      src/main/java/in/gov/chennaicorporation/gccoffice/childrensurvey/Service/ChildrenSurveyService.java
  2. 10
      src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java
  3. 2
      src/main/java/in/gov/chennaicorporation/gccoffice/homelesssurvey/Service/HomelessSurveyService.java
  4. 154
      src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java
  5. 4
      src/main/resources/application.properties

2
src/main/java/in/gov/chennaicorporation/gccoffice/childrensurvey/Service/ChildrenSurveyService.java

@ -979,7 +979,7 @@ public class ChildrenSurveyService {
DATE(sr.cdate) AS survey_date DATE(sr.cdate) AS survey_date
FROM login_details d
FROM gcc_mobile_menus.login_details d
INNER JOIN surveyor_location_details ld INNER JOIN surveyor_location_details ld
ON d.uid = ld.loginId ON d.uid = ld.loginId

10
src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java

@ -24,14 +24,15 @@ import java.util.Properties;
@EnableTransactionManagement @EnableTransactionManagement
public class DataSourceConfig { public class DataSourceConfig {
// private static String host = "localhost:3306";
// private static String dbpassword = "root";
private static String host = "localhost:3306";
private static String dbpassword = "root";
// private static String dbpassword = "gccroot"; // private static String dbpassword = "gccroot";
// AWS // AWS
private static String host = "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306";
private static String dbpassword = "gcc-facial-password";
// private static String host =
// "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306";
// private static String dbpassword = "gcc-facial-password";
////////////////////////////// (For GCC APP) //////////////////////// ////////////////////////////// (For GCC APP) ////////////////////////
@Configuration @Configuration
@ -453,7 +454,6 @@ public class DataSourceConfig {
return dataSource; return dataSource;
} }
////////////////////////////// (For GCC USER) //////////////////////// ////////////////////////////// (For GCC USER) ////////////////////////
@Bean(name = "mysqlGCCUserDataSource") @Bean(name = "mysqlGCCUserDataSource")
public DataSource mysqlGCCUserDataSource() { public DataSource mysqlGCCUserDataSource() {

2
src/main/java/in/gov/chennaicorporation/gccoffice/homelesssurvey/Service/HomelessSurveyService.java

@ -549,7 +549,7 @@ public class HomelessSurveyService {
INNER JOIN surveyor_location_details sl INNER JOIN surveyor_location_details sl
ON sl.survey_id = hs.survey_id ON sl.survey_id = hs.survey_id
INNER JOIN login_details d
INNER JOIN gcc_mobile_menus.login_details d
ON d.uid = sl.loginId ON d.uid = sl.loginId
WHERE 1 = 1 WHERE 1 = 1

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

@ -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,
@ -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,8 +336,6 @@ 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,
@ -430,7 +417,6 @@ public class ShelterInspectionService {
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,11 +487,9 @@ 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"));
@ -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);
@ -583,7 +558,6 @@ public class ShelterInspectionService {
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,17 +566,13 @@ 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) {
@ -694,8 +664,7 @@ public class ShelterInspectionService {
for (Map<String, Object> row : list) { for (Map<String, Object> row : list) {
int totalCount =
((Number)row.get("residents")).intValue()
int totalCount = ((Number) row.get("residents")).intValue()
+ ((Number) row.get("rehabilitated")).intValue() + ((Number) row.get("rehabilitated")).intValue()
+ ((Number) row.get("reintegration")).intValue() + ((Number) row.get("reintegration")).intValue()
+ ((Number) row.get("death")).intValue(); + ((Number) row.get("death")).intValue();
@ -708,7 +677,6 @@ 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) {
@ -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,8 +824,7 @@ 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());
@ -870,8 +835,7 @@ public class ShelterInspectionService {
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"));
@ -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,13 +1073,10 @@ public class ShelterInspectionService {
return result; return result;
} }
// 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 =
restTemplate.exchange(
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange(
API_URL, API_URL,
HttpMethod.GET, HttpMethod.GET,
null, null,
@ -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,9 +1198,7 @@ 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<>();
@ -1266,7 +1217,6 @@ public class ShelterInspectionService {
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,7 +1274,6 @@ 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"));
@ -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,8 +1336,7 @@ 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();
@ -1422,8 +1357,7 @@ public class ShelterInspectionService {
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");
@ -1456,8 +1390,6 @@ 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);
@ -1466,8 +1398,4 @@ public class ShelterInspectionService {
} }
} }

4
src/main/resources/application.properties

@ -1,5 +1,5 @@
#spring.profiles.active=local
spring.profiles.active=production
spring.profiles.active=local
#spring.profiles.active=production
#For Server production #For Server production
#assets.base-url=/gcc/assets/ #assets.base-url=/gcc/assets/
#For local test #For local test

Loading…
Cancel
Save