Browse Source

first commit at shelter inspection project

master
Dizho A 2 months ago
parent
commit
32d8dcb2b6
  1. 8
      .classpath
  2. 12
      src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java
  3. 33
      src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/MainController.java
  4. 207
      src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java
  5. 139
      src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/MasterShelterService.java
  6. 1783
      src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java
  7. 2817
      src/main/resources/templates/modules/shelterinspection/dashboard.html
  8. 433
      src/main/resources/templates/modules/shelterinspection/shelterlist.html
  9. 1673
      src/main/resources/templates/modules/shelterinspection/visitlist.html

8
.classpath

@ -9,6 +9,7 @@
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
@ -28,5 +29,12 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

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

@ -442,6 +442,18 @@ public class DataSourceConfig {
return dataSource;
}
/////////////// Shelter Inspection /////////////////////
@Bean(name = "mysqlShelterinspectionDataSource")
public DataSource mysqlShelterinspectionDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://" + host + "/gcc_night_shelter_inspection");
dataSource.setUsername("root");
dataSource.setPassword(dbpassword);
return dataSource;
}
////////////////////////////// (For GCC USER) ////////////////////////
@Bean(name = "mysqlGCCUserDataSource")
public DataSource mysqlGCCUserDataSource() {

33
src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/MainController.java

@ -0,0 +1,33 @@
package in.gov.chennaicorporation.gccoffice.shelterinspection.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller("ShelterInspectionController")
@RequestMapping("/gcc/shelterinspection")
public class MainController {
@GetMapping("/dashboard")
public String Dashboard() {
return "modules/shelterinspection/dashboard";
}
@GetMapping("/shelterlist")
public String ShelterList() {
return "modules/shelterinspection/shelterlist";
}
@GetMapping("/visitlist")
public String VisitList() {
return "modules/shelterinspection/visitlist";
}
@GetMapping("/complaintlist")
public String ComplaintList() {
return "modules/shelterinspection/complaintlist";
}
}

207
src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Controller/ShelterInspectionController.java

@ -0,0 +1,207 @@
package in.gov.chennaicorporation.gccoffice.shelterinspection.Controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import in.gov.chennaicorporation.gccoffice.shelterinspection.Service.MasterShelterService;
import in.gov.chennaicorporation.gccoffice.shelterinspection.Service.ShelterInspectionService;
@RestController
@RequestMapping("/gcc/api/shelterinspection")
public class ShelterInspectionController {
@Autowired
private ShelterInspectionService shelterApiService;
@Autowired
private MasterShelterService masterShelterService;
private final RestTemplate restTemplate = new RestTemplate();
@GetMapping("/Sheltercount")
public ResponseEntity<Map<String, Object>> getTotalCount() {
int count = shelterApiService.getTotalShelterCount();
Map<String, Object> response = new HashMap<>();
response.put("totalShelterCount", count);
return ResponseEntity.ok(response);
}
@GetMapping("/dashboard")
public Map<String,Object> dashboard(
@RequestParam String type,
@RequestParam String value){
return shelterApiService.getDashboardData(type,value);
}
@GetMapping("/top5Shelters")
public List<Map<String,Object>> top5Shelters(
@RequestParam String type,
@RequestParam String value){
return shelterApiService.getTop5Shelters(type,value);
}
@GetMapping("/regionSummary")
public List<Map<String,Object>> regionSummary(
@RequestParam String type,
@RequestParam String value){
return shelterApiService.getRegionSummary(type,value);
}
@GetMapping("/fundReceivedSummary")
public List<Map<String,Object>> fundSummary(
@RequestParam String type,
@RequestParam String value){
return shelterApiService.getFundReceivedSummary(type,value);
}
@GetMapping("/fundReceivedShelterDetails")
public List<Map<String, Object>> fundReceivedShelterDetails(
@RequestParam String type,
@RequestParam String value) {
return shelterApiService.getFundReceivedShelterDetails( type, value);
}
@GetMapping("/monthlyTrends")
public List<Map<String,Object>> monthlyTrends(
@RequestParam String type,
@RequestParam String value){
return shelterApiService.getMonthlyTrends(type,value);
}
@GetMapping("/weeklyVisits")
public List<Map<String,Object>> weeklyVisits(
@RequestParam String type,
@RequestParam String value){
List<Map<String,Object>> results = shelterApiService.getWeeklyVisits(type,value);
System.out.println("Weekly Visits Results:" +results);
return results;
}
@GetMapping("/latestVisitShelters")
public List<Map<String,Object>> latestVisitShelters(
@RequestParam String type,
@RequestParam String 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")
public List<Map<String,Object>> shelterList(
@RequestParam(required = false) String zone,
@RequestParam(required = false) String category) {
return shelterApiService.getShelterList(zone, category);
}
@GetMapping("/visitList")
public List<Map<String,Object>> visitList(
@RequestParam(required=false) String fromDate,
@RequestParam(required=false) String toDate,
@RequestParam(required=false) String zone,
@RequestParam(required=false) String cdo){
return shelterApiService.getVisitList( fromDate, toDate, zone, cdo);
}
@GetMapping("/visitDetails")
public Map<String,Object> visitDetails(
@RequestParam String surveyId){
return shelterApiService.getVisitDetails(surveyId);
}
@GetMapping("/questions")
public ResponseEntity<?> getQuestions() {
return restTemplate.getForEntity(
"https://gccservices.in/gccofficialapp/api/shelterinspection/questions?cid=1",
Object.class
);
}
// @GetMapping("/shelterList")
// public List<Map<String,Object>> shelterList(){
// return shelterApiService.getShelterList();
// }
@GetMapping("/categories")
public List<String> getCategories() {
return masterShelterService.getCategoryList();
}
@GetMapping("/zones")
public List<String> getZones() {
return masterShelterService.getZoneList();
}
@GetMapping("/cdos")
public List<Map<String, Object>> getCdos() {
return masterShelterService.getCdos();
}
@GetMapping("/years")
public List<Integer> getYears() {
return masterShelterService.getAvailableYears();
}
}

139
src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/MasterShelterService.java

@ -0,0 +1,139 @@
package in.gov.chennaicorporation.gccoffice.shelterinspection.Service;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.client.RestTemplate;
@Service
public class MasterShelterService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(@Qualifier("mysqlShelterinspectionDataSource") DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
private final RestTemplate restTemplate = new RestTemplate();
private static final String API_URL = "https://nightshelter.gccservices.in/api/shelters/";
// Category Dropdown
public List<String> getCategoryList() {
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();
}
return apiList.stream()
.map(x -> String.valueOf(x.get("category")))
.filter(Objects::nonNull)
.distinct()
.sorted()
.collect(Collectors.toList());
}
//Zone Dropdown
public List<String> getZoneList() {
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();
}
return apiList.stream()
.map(x -> String.valueOf(x.get("zone")))
.filter(Objects::nonNull)
.distinct()
.sorted(Comparator.comparingInt(z ->
Integer.parseInt(z.replaceAll("[^0-9]", ""))))
.collect(Collectors.toList());
}
//CDO Dropdown
public List<Map<String,Object>> getCdos(){
String sql="""
SELECT DISTINCT
uid,
user_name
FROM login_details
ORDER BY user_name
""";
return jdbcTemplate.queryForList(sql);
}
// Year Dropdown
public List<Integer> getAvailableYears() {
String sql = """
SELECT DISTINCT YEAR(cdate) AS year
FROM night_shelter_inspection_response
WHERE isactive = 1
AND isdelete = 0
ORDER BY YEAR(cdate) DESC
""";
return jdbcTemplate.queryForList(sql, Integer.class);
}
// SHelter List
}

1783
src/main/java/in/gov/chennaicorporation/gccoffice/shelterinspection/Service/ShelterInspectionService.java
File diff suppressed because it is too large
View File

2817
src/main/resources/templates/modules/shelterinspection/dashboard.html
File diff suppressed because it is too large
View File

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

@ -0,0 +1,433 @@
<!DOCTYPE html>
<html lang="en" dir="">
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{fragments/modules/base/head :: head}"></head>
<!-- DataTables -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.8/css/dataTables.bootstrap5.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.bootstrap5.min.css">
<style>
.table-responsive {
width: 100%;
}
</style>
<body>
<div class="wrapper">
<header th:replace="~{fragments/modules/base/header :: header}"></header>
<div class="page-wrap">
<div th:replace="~{fragments/modules/base/menu :: menu}"></div>
<div class="main-content">
<div class="container-fluid">
<div class="page-header">
<div class="row align-items-center">
<!-- 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>
<!-- Filters Section -->
<div class="row mb-3">
<div class="col-md-2">
<select id="zone" class="form-control">
<option value="">All Zones</option>
</select>
</div>
<div class="col-md-2">
<select id="category" class="form-control">
<option value="">All Categories</option>
</select>
</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">
<button class="btn btn-primary w-100" onclick="loadShelterList()">Search</button>
</div>
<div class="col-md-2">
<button class="btn btn-secondary w-100" onclick="resetFilters()">Reset</button>
</div>
</div>
<div class="table-responsive">
<table id="shelterListTable" class="table table-bordered table-striped dt-responsive nowrap w-100">
<thead class="thead-dark">
<tr>
<th>S.No</th>
<th>SHELTER</th>
<th>ZONE</th>
<th>CATEGORY</th>
<th>RESIDENTS</th>
<th>STATUS</th>
<th>Latest Visit</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
</div>
</div>
<div th:replace="~{fragments/modules/base/script :: script}"></div>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.datatables.net/1.13.8/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.8/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/dataTables.responsive.min.js"></script>
<!-- DataTable Buttons -->
<script src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.bootstrap5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
<script th:inline="javascript">
$(document).ready(function () {
loadDropdowns();
loadShelterList();
});
function resetFilters() {
$("#zone").val("");
$("#category").val("");
loadShelterList();
}
function loadShelterList() {
if ($.fn.DataTable.isDataTable('#shelterListTable')) {
$('#shelterListTable').DataTable().destroy();
}
$("#shelterListTable tbody").empty();
$.ajax({
url: "/gcc/api/shelterinspection/shelterList",
type: "GET",
data: {
zone: $("#zone").val(),
category: $("#category").val()
},
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() {
Swal.fire({
icon: 'error',
title: 'Error',
text: 'Unable to load shelter list.'
});
}
});
}
/* 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) {
if (!category) return "-";
return category
.replace(/-/g, " ")
.replace(/\b\w/g, function(letter) {
return letter.toUpperCase();
});
}
function getStatusBadge(residents){
if(residents >= 100){
return '<span class="badge badge-success">Good</span>';
}else if(residents >= 25){
return '<span class="badge badge-warning">Average</span>';
}else{
return '<span class="badge badge-danger">Poor</span>';
}
}
function loadDropdowns() {
// Zone
$.ajax({
url: "/gcc/api/shelterinspection/zones",
type: "GET",
success: function(data) {
let options = '<option value="">All Zones</option>';
data.forEach(function(zone) {
options += `<option value="${zone}">${zone}</option>`;
});
$("#zone").html(options);
}
});
// Category
$.ajax({
url: "/gcc/api/shelterinspection/categories",
type: "GET",
success: function(data) {
let options = '<option value="">All Categories</option>';
data.forEach(function(category) {
let text = category
.replace(/-/g, " ")
.replace(/\b\w/g, function(c) {
return c.toUpperCase();
});
options += `<option value="${category}">${text}</option>`;
});
$("#category").html(options);
}
});
}
</script>
</body>
</html>

1673
src/main/resources/templates/modules/shelterinspection/visitlist.html
File diff suppressed because it is too large
View File

Loading…
Cancel
Save