5 changed files with 2013 additions and 0 deletions
-
11src/main/java/com/gcc/commissionerreview/configuration/DataSourceConfig.java
-
68src/main/java/com/gcc/commissionerreview/controller/BoatServiceReportController.java
-
5src/main/java/com/gcc/commissionerreview/controller/MainController.java
-
165src/main/java/com/gcc/commissionerreview/service/BoatServiceReportService.java
-
1764src/main/resources/templates/modules/boatreport.html
@ -0,0 +1,68 @@ |
|||||
|
package com.gcc.commissionerreview.controller; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.http.ResponseEntity; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
import com.gcc.commissionerreview.service.AttendanceService; |
||||
|
import com.gcc.commissionerreview.service.BoatServiceReportService; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/commissionerreview/api/boatController") |
||||
|
public class BoatServiceReportController { |
||||
|
@Autowired |
||||
|
private BoatServiceReportService boatServiceReportService; |
||||
|
|
||||
|
@GetMapping("/report") |
||||
|
public ResponseEntity<?> getBoatServiceReport( |
||||
|
@RequestParam String fromDate, |
||||
|
@RequestParam String toDate) { |
||||
|
|
||||
|
try { |
||||
|
|
||||
|
List<Map<String, Object>> report = boatServiceReportService |
||||
|
.getBoatServiceReport( |
||||
|
fromDate, |
||||
|
toDate); |
||||
|
|
||||
|
return ResponseEntity.ok(report); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
|
||||
|
e.printStackTrace(); |
||||
|
|
||||
|
return ResponseEntity |
||||
|
.internalServerError() |
||||
|
.body("Failed to load Boat Service Report"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@GetMapping("/summary") |
||||
|
public ResponseEntity<?> getBoatSummary() { |
||||
|
|
||||
|
try { |
||||
|
|
||||
|
Map<String, Object> summary = boatServiceReportService.getBoatSummary(); |
||||
|
|
||||
|
return ResponseEntity.ok(summary); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
|
||||
|
e.printStackTrace(); |
||||
|
|
||||
|
return ResponseEntity |
||||
|
.internalServerError() |
||||
|
.body("Unable to fetch boat summary"); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,165 @@ |
|||||
|
package com.gcc.commissionerreview.service; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
|
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.jdbc.core.JdbcTemplate; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.sql.Date; |
||||
|
import java.time.LocalDate; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.format.DateTimeFormatter; |
||||
|
import java.util.Collections; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Locale; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Service |
||||
|
public class BoatServiceReportService { |
||||
|
|
||||
|
@Autowired |
||||
|
private JdbcTemplate jdbcTemplate; |
||||
|
|
||||
|
@Autowired |
||||
|
public void setDataSource(@Qualifier("mysqlbootDataSource") DataSource dataSource) { |
||||
|
this.jdbcTemplate = new JdbcTemplate(dataSource); |
||||
|
} |
||||
|
|
||||
|
public List<Map<String, Object>> getBoatServiceReport( |
||||
|
String fromDate, |
||||
|
String toDate) { |
||||
|
|
||||
|
String sql = """ |
||||
|
|
||||
|
SELECT |
||||
|
|
||||
|
sl.zone AS zone, |
||||
|
|
||||
|
sl.name AS location, |
||||
|
|
||||
|
DATE(tkt.ticketdatetime) |
||||
|
AS report_date, |
||||
|
|
||||
|
tkt.boat_name |
||||
|
AS boat_name, |
||||
|
|
||||
|
COALESCE( |
||||
|
SUM(tkt.adult_count), |
||||
|
0 |
||||
|
) AS no_of_adults, |
||||
|
|
||||
|
COALESCE( |
||||
|
SUM(tkt.child_count), |
||||
|
0 |
||||
|
) AS no_of_kids, |
||||
|
|
||||
|
COUNT(tkt.ticketid) |
||||
|
AS total_bookings, |
||||
|
|
||||
|
COALESCE( |
||||
|
SUM(tkt.ticket_amount), |
||||
|
0 |
||||
|
) AS total_collection |
||||
|
|
||||
|
|
||||
|
FROM tickets tkt |
||||
|
|
||||
|
|
||||
|
LEFT JOIN |
||||
|
service_location sl |
||||
|
|
||||
|
ON tkt.lid = sl.lid |
||||
|
|
||||
|
|
||||
|
|
||||
|
WHERE tkt.status = 'Transaction success' |
||||
|
AND |
||||
|
|
||||
|
tkt.ticketdatetime >= ? |
||||
|
|
||||
|
AND |
||||
|
|
||||
|
tkt.ticketdatetime < ? |
||||
|
|
||||
|
|
||||
|
GROUP BY |
||||
|
|
||||
|
sl.zone, |
||||
|
|
||||
|
sl.name, |
||||
|
|
||||
|
DATE(tkt.ticketdatetime), |
||||
|
|
||||
|
tkt.boat_name |
||||
|
|
||||
|
|
||||
|
ORDER BY |
||||
|
|
||||
|
sl.zone, |
||||
|
|
||||
|
sl.name, |
||||
|
|
||||
|
DATE(tkt.ticketdatetime), |
||||
|
|
||||
|
tkt.boat_name |
||||
|
|
||||
|
"""; |
||||
|
|
||||
|
return jdbcTemplate.queryForList( |
||||
|
sql, |
||||
|
fromDate, |
||||
|
toDate); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public Map<String, Object> getBoatSummary() { |
||||
|
|
||||
|
Map<String, Object> response = new HashMap<>(); |
||||
|
|
||||
|
// ========================================== |
||||
|
// 1. Total Bookings & Total Revenue |
||||
|
// ========================================== |
||||
|
|
||||
|
String summarySql = "SELECT " + |
||||
|
"COUNT(ticketid) AS totalbooking, " + |
||||
|
"COALESCE(SUM(ticket_amount), 0) AS totalamount " + |
||||
|
"FROM tickets"; |
||||
|
|
||||
|
Map<String, Object> summary = jdbcTemplate.queryForMap(summarySql); |
||||
|
|
||||
|
// ========================================== |
||||
|
// 2. Boat Price |
||||
|
// ========================================== |
||||
|
|
||||
|
String priceSql = "SELECT " + |
||||
|
"bcid, " + |
||||
|
"name, " + |
||||
|
"adult_price, " + |
||||
|
"child_price " + |
||||
|
"FROM boat_config " + |
||||
|
"WHERE bcid IN (1, 3) " + |
||||
|
"ORDER BY bcid"; |
||||
|
|
||||
|
List<Map<String, Object>> boatPrices = jdbcTemplate.queryForList(priceSql); |
||||
|
|
||||
|
// ========================================== |
||||
|
// Add both responses |
||||
|
// ========================================== |
||||
|
|
||||
|
response.put("totalbooking", |
||||
|
summary.get("totalbooking")); |
||||
|
|
||||
|
response.put("totalamount", |
||||
|
summary.get("totalamount")); |
||||
|
|
||||
|
response.put("boatPrices", |
||||
|
boatPrices); |
||||
|
|
||||
|
return response; |
||||
|
} |
||||
|
} |
||||
1764
src/main/resources/templates/modules/boatreport.html
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue