Browse Source

changes added flagpole service,controller and page

master
yoganandhan 8 months ago
parent
commit
bde68a021c
  1. 11
      src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java
  2. 6
      src/main/java/com/gcc/commissionerreview/controller/FlagpolesApiController.java
  3. 14
      src/main/java/com/gcc/commissionerreview/service/FlagpolesService.java
  4. 93
      src/main/resources/templates/modules/flagpoles/abstractreport.html

11
src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java

@ -17,11 +17,12 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@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 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";
public static class MyDataSourceConfig { public static class MyDataSourceConfig {
@Primary @Primary
@ -123,7 +124,7 @@ public class DataSourceConfig {
public DataSource mysqlFlagPoleManagerSystemDataSource() { public DataSource mysqlFlagPoleManagerSystemDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://" + host + "/gcc_flag_pole");
dataSource.setUrl("jdbc:mysql://" + host + "/gcc_flag_pole07022026");
dataSource.setUsername("root"); dataSource.setUsername("root");
dataSource.setPassword(dbpassword); dataSource.setPassword(dbpassword);
return dataSource; return dataSource;

6
src/main/java/com/gcc/commissionerreview/controller/FlagpolesApiController.java

@ -48,9 +48,11 @@ public class FlagpolesApiController {
@RequestParam String zone, @RequestParam String zone,
@RequestParam(required = false) String status, @RequestParam(required = false) String status,
@RequestParam(required = false) String fromDate, @RequestParam(required = false) String fromDate,
@RequestParam(required = false) String toDate) {
@RequestParam(required = false) String toDate,
@RequestParam(required = false) String applicationType) {
try { try {
List<Map<String, Object>> data = flagpolesService.getRequestDetails(zone, status, fromDate, toDate);
List<Map<String, Object>> data = flagpolesService.getRequestDetails(zone, status, fromDate, toDate,
applicationType);
return Map.of("status", "success", "data", data); return Map.of("status", "success", "data", data);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

14
src/main/java/com/gcc/commissionerreview/service/FlagpolesService.java

@ -23,9 +23,9 @@ public class FlagpolesService {
public List<Map<String, Object>> getZoneWiseRequestCounts(String fromDate, String toDate, String applicationType) { public List<Map<String, Object>> getZoneWiseRequestCounts(String fromDate, String toDate, String applicationType) {
StringBuilder sql = new StringBuilder("SELECT " + StringBuilder sql = new StringBuilder("SELECT " +
" s.zone, " + " s.zone, " +
" COUNT(u.id) as total_requests, " +
" SUM(CASE WHEN u.final_status = 'Approved' THEN 1 ELSE 0 END) as approved_count, " +
" SUM(CASE WHEN u.final_status = 'Rejected' THEN 1 ELSE 0 END) as rejected_count " +
" COUNT(DISTINCT u.id) as total_requests, " +
" COUNT(DISTINCT CASE WHEN u.final_status = 'Approved' THEN u.id END) as approved_count, " +
" COUNT(DISTINCT CASE WHEN u.final_status = 'Rejected' THEN u.id END) as rejected_count " +
"FROM user_request_details u " + "FROM user_request_details u " +
"JOIN street_details s ON u.id = s.user_req_id " + "JOIN street_details s ON u.id = s.user_req_id " +
"LEFT JOIN application_type at ON u.application_type = at.id "); "LEFT JOIN application_type at ON u.application_type = at.id ");
@ -94,7 +94,8 @@ public class FlagpolesService {
return finalResults; return finalResults;
} }
public List<Map<String, Object>> getRequestDetails(String zone, String status, String fromDate, String toDate) {
public List<Map<String, Object>> getRequestDetails(String zone, String status, String fromDate, String toDate,
String applicationType) {
StringBuilder sql = new StringBuilder("SELECT " + StringBuilder sql = new StringBuilder("SELECT " +
" u.id, " + " u.id, " +
" u.refid, " + " u.refid, " +
@ -147,6 +148,11 @@ public class FlagpolesService {
params.add(toDate); params.add(toDate);
} }
if (applicationType != null && !applicationType.isEmpty() && !applicationType.equalsIgnoreCase("OVERALL")) {
sql.append("AND at.type = ? ");
params.add(applicationType);
}
sql.append("GROUP BY u.id ORDER BY u.cdate DESC"); sql.append("GROUP BY u.id ORDER BY u.cdate DESC");
return jdbcTemplate.queryForList(sql.toString(), params.toArray()); return jdbcTemplate.queryForList(sql.toString(), params.toArray());

93
src/main/resources/templates/modules/flagpoles/abstractreport.html

@ -20,7 +20,8 @@
border: 1px solid #000; border: 1px solid #000;
} }
table.dataTable th {
table.dataTable th,
.table-dark th {
background-color: #003366 !important; background-color: #003366 !important;
color: white; color: white;
text-align: center !important; text-align: center !important;
@ -53,7 +54,7 @@
<input type="date" id="toDate" class="form-control"> <input type="date" id="toDate" class="form-control">
</div> </div>
<div class="col-auto"> <div class="col-auto">
<button class="btn btn-primary" id="searchBtn">Search</button>
<button type="button" class="btn btn-primary" id="searchBtn">Search</button>
</div> </div>
</div> </div>
@ -120,6 +121,7 @@
</div> </div>
<p>Loading details...</p> <p>Loading details...</p>
</div> </div>
<div class="table-responsive">
<table id="detailsTable" class="table table-bordered table-striped" style="width:100%"> <table id="detailsTable" class="table table-bordered table-striped" style="width:100%">
<thead class="table-dark"> <thead class="table-dark">
<tr> <tr>
@ -127,9 +129,9 @@
<th>Ref ID</th> <th>Ref ID</th>
<th>Applicant Name</th> <th>Applicant Name</th>
<th>Mobile</th> <th>Mobile</th>
<th>App Type</th>
<th>App Option</th>
<th>Install Type</th>
<th>Application Type</th>
<!-- <th>Application Option</th>
<th>Installation Type</th> -->
<th>Event Desc</th> <th>Event Desc</th>
<th>Event Date</th> <th>Event Date</th>
<th>Status</th> <th>Status</th>
@ -141,6 +143,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div> </div>
@ -265,7 +268,7 @@
const fromDate = document.getElementById("fromDate").value; const fromDate = document.getElementById("fromDate").value;
const toDate = document.getElementById("toDate").value; const toDate = document.getElementById("toDate").value;
$('#detailsModalLabel').text(`${status} Requests for ${zone}`);
$('#detailsModalLabel').text(`${status} Requests for zone: ${zone}`);
$('#detailsPageLoader').show(); $('#detailsPageLoader').show();
// Clear previous table data // Clear previous table data
if ($.fn.DataTable.isDataTable('#detailsTable')) { if ($.fn.DataTable.isDataTable('#detailsTable')) {
@ -275,7 +278,12 @@
new bootstrap.Modal(document.getElementById('detailsModal')).show(); new bootstrap.Modal(document.getElementById('detailsModal')).show();
fetch(`/commissionerreview/api/flagpoles/details?zone=${zone}&status=${status}&fromDate=${fromDate}&toDate=${toDate}`)
let url = `/commissionerreview/api/flagpoles/details?zone=${zone}&status=${status}&fromDate=${fromDate}&toDate=${toDate}`;
if (currentType && currentType !== 'OVERALL') {
url += `&applicationType=${currentType}`;
}
fetch(url)
.then(res => res.json()) .then(res => res.json())
.then(json => { .then(json => {
$('#detailsPageLoader').hide(); $('#detailsPageLoader').hide();
@ -302,7 +310,8 @@
function populateDetailsTable(data) { function populateDetailsTable(data) {
const tbody = $('#detailsTableBody'); const tbody = $('#detailsTableBody');
tbody.empty(); tbody.empty();
// <td>${formatValue(row.application_option)}</td>
// <td>${formatValue(row.installation_type)}</td>
data.forEach((row, index) => { data.forEach((row, index) => {
tbody.append(` tbody.append(`
<tr> <tr>
@ -311,13 +320,12 @@
<td>${formatValue(row.applicant_name)}</td> <td>${formatValue(row.applicant_name)}</td>
<td>${formatValue(row.mobile_number)}</td> <td>${formatValue(row.mobile_number)}</td>
<td>${formatValue(row.application_type)}</td> <td>${formatValue(row.application_type)}</td>
<td>${formatValue(row.application_option)}</td>
<td>${formatValue(row.installation_type)}</td>
<td>${formatValue(row.event_desc)}</td> <td>${formatValue(row.event_desc)}</td>
<td>${formatValue(row.event_date)}</td> <td>${formatValue(row.event_date)}</td>
<td>${formatValue(row.final_status)}</td> <td>${formatValue(row.final_status)}</td>
<td> <td>
<button class="btn btn-info btn-sm" onclick="viewStreetDetails(${row.id})">
<button class="btn btn-info btn-sm" onclick="viewStreetDetails(${row.id}, '${row.refid}')">
View Streets View Streets
</button> </button>
</td> </td>
@ -325,29 +333,46 @@
`); `);
}); });
$('#detailsTable').DataTable({
var table = $('#detailsTable').DataTable({
dom: 'Bfrtip', dom: 'Bfrtip',
scrollX: true,
buttons: [ buttons: [
'excelHtml5', 'excelHtml5',
'pdfHtml5' 'pdfHtml5'
] ]
}); });
// Adjust columns after small delay to ensure modal transition ends
setTimeout(function () {
table.columns.adjust().draw();
}, 200);
} }
function viewStreetDetails(requestId) {
$('#streetModalLabel').text(`Street Details for Request ID`);
$('#streetTableBody').html('<tr><td colspan="5" class="text-center">Loading...</td></tr>');
new bootstrap.Modal(document.getElementById('streetModal')).show();
function viewStreetDetails(requestId, refId) {
$('#streetModalLabel').text(`Street Details for Request: ${refId}`);
// Show modal
const modal = new bootstrap.Modal(document.getElementById('streetModal'));
modal.show();
// Destroy existing DataTable if it exists
if ($.fn.DataTable.isDataTable('#streetTable')) {
$('#streetTable').DataTable().destroy();
}
const tbody = $('#streetTableBody');
tbody.empty();
tbody.html('<tr><td colspan="6" class="text-center">Loading...</td></tr>');
fetch(`/commissionerreview/api/flagpoles/street-details?requestId=${requestId}`) fetch(`/commissionerreview/api/flagpoles/street-details?requestId=${requestId}`)
.then(res => res.json()) .then(res => res.json())
.then(json => { .then(json => {
const tbody = $('#streetTableBody');
tbody.empty(); tbody.empty();
if (json.status === "success" && json.data.length > 0) { if (json.status === "success" && json.data.length > 0) {
json.data.forEach(row => {
json.data.forEach((row, index) => {
tbody.append(` tbody.append(`
<tr> <tr>
<td>${index + 1}</td>
<td>${formatValue(row.zone)}</td> <td>${formatValue(row.zone)}</td>
<td>${formatValue(row.ward)}</td> <td>${formatValue(row.ward)}</td>
<td>${formatValue(row.street_name)}</td> <td>${formatValue(row.street_name)}</td>
@ -356,13 +381,28 @@
</tr> </tr>
`); `);
}); });
// Initialize DataTable
var table = $('#streetTable').DataTable({
dom: 'Bfrtip',
scrollX: true,
buttons: [
'excelHtml5',
'pdfHtml5'
]
});
// Adjust columns
setTimeout(function () {
table.columns.adjust().draw();
}, 200);
} else { } else {
tbody.html('<tr><td colspan="5" class="text-center">No street details found</td></tr>');
tbody.html('<tr><td colspan="6" class="text-center">No street details found</td></tr>');
} }
}) })
.catch(err => { .catch(err => {
console.error("Fetch Error:", err); console.error("Fetch Error:", err);
$('#streetTableBody').html('<tr><td colspan="5" class="text-center text-danger">Failed to load data</td></tr>');
tbody.html('<tr><td colspan="6" class="text-center text-danger">Failed to load data</td></tr>');
}); });
} }
@ -371,12 +411,18 @@
initDataTable(); initDataTable();
// Bind search button click // Bind search button click
$('#searchBtn').click(function () {
$('#searchBtn').click(function (e) {
e.preventDefault();
loadReport(); loadReport();
}); });
// Initial load // Initial load
loadReport(); loadReport();
// Fix DataTable alignment in modals
$('#detailsModal, #streetModal').on('shown.bs.modal', function () {
$.fn.dataTable.tables({ visible: true, api: true }).columns.adjust();
});
}); });
</script> </script>
@ -389,9 +435,11 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<table class="table table-bordered table-striped" width="100%">
<div class="table-responsive">
<table id="streetTable" class="table table-bordered table-striped" width="100%">
<thead class="table-dark"> <thead class="table-dark">
<tr> <tr>
<th>S.No</th>
<th>Zone</th> <th>Zone</th>
<th>Ward</th> <th>Ward</th>
<th>Street Name</th> <th>Street Name</th>
@ -404,6 +452,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div> </div>

Loading…
Cancel
Save