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
FROM login_details d
FROM gcc_mobile_menus.login_details d
INNER JOIN surveyor_location_details ld
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
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";
// 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) ////////////////////////
@Configuration
@ -453,7 +454,6 @@ public class DataSourceConfig {
return dataSource;
}
////////////////////////////// (For GCC USER) ////////////////////////
@Bean(name = "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
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
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.web.client.RestTemplate;
@Service
public class ShelterInspectionService {
@ -37,20 +35,18 @@ public class ShelterInspectionService {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
private final RestTemplate restTemplate = new RestTemplate();
private static final String API_URL = "https://nightshelter.gccservices.in/api/shelters/";
public int getTotalShelterCount() {
ResponseEntity<List<Map<String, Object>>> response =
restTemplate.exchange(
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange(
API_URL,
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Map<String, Object>>>() {}
);
new ParameterizedTypeReference<List<Map<String, Object>>>() {
});
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 = 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,
@ -96,7 +92,7 @@ public class ShelterInspectionService {
WHERE isactive = 1
AND isdelete = 0
AND qid IN (4,5,10,11,13,16,17,48)
""" + dateCondition;
if (dateCondition.isEmpty()) {
@ -108,13 +104,11 @@ public class ShelterInspectionService {
return response;
}
// Top 5 Shelter List
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,
HttpMethod.GET,
null,
@ -194,13 +188,11 @@ public class ShelterInspectionService {
.collect(Collectors.toList());
}
// Region Summary
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,
HttpMethod.GET,
null,
@ -313,8 +305,7 @@ public class ShelterInspectionService {
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<>();
@ -345,8 +336,6 @@ public class ShelterInspectionService {
}
// Fund Received Summary
public List<Map<String, Object>> getFundReceivedSummary(String type, String value) {
@ -400,7 +389,6 @@ public class ShelterInspectionService {
}
// Fund Recieved Total Details
public List<Map<String, Object>> getFundReceivedShelterDetails(
@ -408,8 +396,7 @@ public class ShelterInspectionService {
String value) {
/* Get shelter details from external API */
ResponseEntity<List<Map<String, Object>>> response =
restTemplate.exchange(
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange(
API_URL,
HttpMethod.GET,
null,
@ -430,7 +417,6 @@ public class ShelterInspectionService {
shelterApiMap.put(uqid, shelter);
}
/* Date filter */
String dateCondition = "";
@ -442,7 +428,6 @@ public class ShelterInspectionService {
dateCondition = " AND YEAR(r.cdate) = ? ";
}
/*
* Get fund response + shelter mapping
*
@ -493,7 +478,6 @@ public class ShelterInspectionService {
ORDER BY am.orderby
""";
/* Execute query */
List<Map<String, Object>> dbList;
@ -503,11 +487,9 @@ public class ShelterInspectionService {
dbList = jdbcTemplate.queryForList(sql, value);
}
/* Group by Fund Type */
Map<String, Map<String, Object>> fundMap = new LinkedHashMap<>();
for (Map<String, Object> row : dbList) {
String fundId = String.valueOf(row.get("fund_id"));
@ -530,7 +512,6 @@ public class ShelterInspectionService {
return map;
});
/*
* Existing total + 1
*
@ -540,24 +521,18 @@ public class ShelterInspectionService {
int total = ((Number) fundRow.get("total")).intValue();
fundRow.put("total", total + 1);
/* Shelter list */
@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
boolean alreadyExists =
shelters.stream()
boolean alreadyExists = shelters.stream()
.anyMatch(
x -> shelterId.equals(
String.valueOf(
x.get("shelter_id"))));
if (!alreadyExists) {
Map<String, Object> apiShelter = shelterApiMap.get(shelterId);
@ -583,7 +558,6 @@ public class ShelterInspectionService {
shelter.put("category", "-");
}
// Add DB details also
shelter.put("qid", row.get("qid"));
@ -592,17 +566,13 @@ public class ShelterInspectionService {
shelter.put("loginId", row.get("loginId"));
shelter.put("location_survey_id", row.get("location_survey_id"));
shelters.add(shelter);
}
}
return new ArrayList<>(fundMap.values());
}
// Monthly Trends
public List<Map<String, Object>> getMonthlyTrends(String type, String value) {
@ -694,8 +664,7 @@ public class ShelterInspectionService {
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("reintegration")).intValue()
+ ((Number) row.get("death")).intValue();
@ -708,7 +677,6 @@ public class ShelterInspectionService {
}
// CDO Week Visit
public List<Map<String, Object>> getWeeklyVisits(String type, String value) {
@ -779,20 +747,18 @@ public class ShelterInspectionService {
}
// Latest Visit Shelter
public List<Map<String, Object>> getLatestVisitShelters(
String type,
String value) {
ResponseEntity<List<Map<String, Object>>> response =
restTemplate.exchange(
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange(
API_URL,
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Map<String, Object>>>() {});
new ParameterizedTypeReference<List<Map<String, Object>>>() {
});
List<Map<String, Object>> apiList = response.getBody();
@ -820,7 +786,7 @@ public class ShelterInspectionService {
INNER JOIN surveyor_location_details s
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
WHERE r.isactive = 1
@ -858,8 +824,7 @@ public class ShelterInspectionService {
LIMIT 1
""");
List<Map<String,Object>> list =
jdbcTemplate.queryForList(
List<Map<String, Object>> list = jdbcTemplate.queryForList(
sql.toString(),
params.toArray());
@ -870,8 +835,7 @@ public class ShelterInspectionService {
if (!list.isEmpty()) {
LocalDateTime visit =
(LocalDateTime) list.get(0).get("visit_date");
LocalDateTime visit = (LocalDateTime) list.get(0).get("visit_date");
row.put("userName",
list.get(0).get("user_name"));
@ -923,17 +887,16 @@ public class ShelterInspectionService {
}
// SHelter List
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,
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Map<String, Object>>>() {});
new ParameterizedTypeReference<List<Map<String, Object>>>() {
});
List<Map<String, Object>> apiList = response.getBody();
@ -982,7 +945,6 @@ public class ShelterInspectionService {
WHERE s.shelter_id = ?
""";
Integer residents = jdbcTemplate.queryForObject(
residentSql,
Integer.class,
@ -1002,7 +964,6 @@ public class ShelterInspectionService {
WHERE s.shelter_id = ?
""";
LocalDateTime visitDate = jdbcTemplate.queryForObject(
latestVisitSql,
LocalDateTime.class,
@ -1024,7 +985,6 @@ public class ShelterInspectionService {
}
}
// Maintenance Status
String maintenanceSql = """
SELECT
@ -1063,7 +1023,6 @@ public class ShelterInspectionService {
Map<String, Object> maintenanceData = jdbcTemplate.queryForMap(maintenanceSql, uqid);
int answer1Count = maintenanceData.get("answer1_count") == null
? 0
: ((Number) maintenanceData.get("answer1_count")).intValue();
@ -1084,14 +1043,11 @@ public class ShelterInspectionService {
if (answer1Count >= 4) {
maintenanceStatus = "Well maintained";
}
else if (answer2Count >= 3) {
} else if (answer2Count >= 3) {
maintenanceStatus = "Averagely maintained";
}
else if (answer3Count >= 2) {
} else if (answer3Count >= 2) {
maintenanceStatus = "Poorly maintained";
}
else if (answer4Count >= 2) {
} else if (answer4Count >= 2) {
maintenanceStatus = "Extremely bad condition";
}
@ -1117,13 +1073,10 @@ public class ShelterInspectionService {
return result;
}
// 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,
HttpMethod.GET,
null,
@ -1210,7 +1163,7 @@ public class ShelterInspectionService {
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
WHERE r.isactive = 1
@ -1245,9 +1198,7 @@ public class ShelterInspectionService {
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<>();
@ -1266,7 +1217,6 @@ public class ShelterInspectionService {
if (api == null)
continue;
String apiZone = String.valueOf(api.get("zone"));
if (zone != null && !zone.isBlank()
@ -1288,38 +1238,26 @@ public class ShelterInspectionService {
// MAINTENANCE COUNTS
// =========================
int maintenance1 =
db.get("maintenance_1") == null
int maintenance1 = db.get("maintenance_1") == null
? 0
: ((Number)
db.get("maintenance_1"))
: ((Number) db.get("maintenance_1"))
.intValue();
int maintenance2 =
db.get("maintenance_2") == null
int maintenance2 = db.get("maintenance_2") == null
? 0
: ((Number)
db.get("maintenance_2"))
: ((Number) db.get("maintenance_2"))
.intValue();
int maintenance3 =
db.get("maintenance_3") == null
int maintenance3 = db.get("maintenance_3") == null
? 0
: ((Number)
db.get("maintenance_3"))
: ((Number) db.get("maintenance_3"))
.intValue();
int maintenance4 =
db.get("maintenance_4") == null
int maintenance4 = db.get("maintenance_4") == null
? 0
: ((Number)
db.get("maintenance_4"))
: ((Number) db.get("maintenance_4"))
.intValue();
// =========================
// MAINTENANCE STATUS
// =========================
@ -1336,7 +1274,6 @@ public class ShelterInspectionService {
maintenanceStatus = "Extremely bad condition";
}
Map<String, Object> row = new LinkedHashMap<>();
row.put("surveyId", db.get("survey_id"));
@ -1361,17 +1298,16 @@ public class ShelterInspectionService {
}
// Visit Details for modal box
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,
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Map<String, Object>>>() {});
new ParameterizedTypeReference<List<Map<String, Object>>>() {
});
List<Map<String, Object>> apiShelters = response.getBody();
@ -1392,7 +1328,7 @@ public class ShelterInspectionService {
INNER JOIN surveyor_location_details s
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
WHERE r.survey_id = ?
@ -1400,8 +1336,7 @@ public class ShelterInspectionService {
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()) {
return Collections.emptyMap();
@ -1422,8 +1357,7 @@ public class ShelterInspectionService {
answers.put(
String.valueOf(row.get("qid")),
String.valueOf(row.get("answer"))
);
String.valueOf(row.get("answer")));
}
LocalDateTime dateTime = (LocalDateTime) first.get("cdate");
@ -1456,8 +1390,6 @@ public class ShelterInspectionService {
result.put("address", api.get("address"));
result.put("image", api.get("image"));
}
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
#assets.base-url=/gcc/assets/
#For local test

Loading…
Cancel
Save