QR Added to the orders screens.
This commit is contained in:
@@ -7,15 +7,17 @@ public class GeneralDashboardData {
|
||||
private DashboardStats stats;
|
||||
private List<Map<String, Object>> storeOverview;
|
||||
private List<Map<String, Object>> hourlySales;
|
||||
private List<String> insights;
|
||||
private List<Map<String, String>> insights;
|
||||
private List<TrendingItem> trendingItems;
|
||||
|
||||
public GeneralDashboardData() {}
|
||||
|
||||
public GeneralDashboardData(DashboardStats stats, List<Map<String, Object>> storeOverview, List<Map<String, Object>> hourlySales, List<String> insights) {
|
||||
public GeneralDashboardData(DashboardStats stats, List<Map<String, Object>> storeOverview, List<Map<String, Object>> hourlySales, List<Map<String, String>> insights, List<TrendingItem> trendingItems) {
|
||||
this.stats = stats;
|
||||
this.storeOverview = storeOverview;
|
||||
this.hourlySales = hourlySales;
|
||||
this.insights = insights;
|
||||
this.trendingItems = trendingItems;
|
||||
}
|
||||
|
||||
public DashboardStats getStats() { return stats; }
|
||||
@@ -27,6 +29,9 @@ public class GeneralDashboardData {
|
||||
public List<Map<String, Object>> getHourlySales() { return hourlySales; }
|
||||
public void setHourlySales(List<Map<String, Object>> hourlySales) { this.hourlySales = hourlySales; }
|
||||
|
||||
public List<String> getInsights() { return insights; }
|
||||
public void setInsights(List<String> insights) { this.insights = insights; }
|
||||
public List<Map<String, String>> getInsights() { return insights; }
|
||||
public void setInsights(List<Map<String, String>> insights) { this.insights = insights; }
|
||||
|
||||
public List<TrendingItem> getTrendingItems() { return trendingItems; }
|
||||
public void setTrendingItems(List<TrendingItem> trendingItems) { this.trendingItems = trendingItems; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.rit.canteen.sales.model;
|
||||
|
||||
public class TrendingItem {
|
||||
private String name;
|
||||
private String category;
|
||||
private long qty;
|
||||
private String image;
|
||||
|
||||
public TrendingItem() {}
|
||||
|
||||
public TrendingItem(String name, String category, long qty, String image) {
|
||||
this.name = name;
|
||||
this.category = category;
|
||||
this.qty = qty;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getCategory() { return category; }
|
||||
public void setCategory(String category) { this.category = category; }
|
||||
|
||||
public long getQty() { return qty; }
|
||||
public void setQty(long qty) { this.qty = qty; }
|
||||
|
||||
public String getImage() { return image; }
|
||||
public void setImage(String image) { this.image = image; }
|
||||
}
|
||||
@@ -48,10 +48,10 @@ public interface OrderRepository extends JpaRepository<Order, Long>, JpaSpecific
|
||||
"ORDER BY HOUR(o.createdAt)")
|
||||
List<Object[]> getHourlySales(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
|
||||
|
||||
@Query("SELECT i.productName, SUM(i.quantity), SUM(i.price * i.quantity) " +
|
||||
"FROM Order o JOIN o.items i " +
|
||||
@Query("SELECT p.name, p.category, SUM(i.quantity), p.imageData " +
|
||||
"FROM Order o JOIN o.items i JOIN Product p ON i.productId = p.id " +
|
||||
"WHERE o.createdAt >= :start AND o.createdAt <= :end " +
|
||||
"GROUP BY i.productName " +
|
||||
"GROUP BY p.name, p.category, p.imageData " +
|
||||
"ORDER BY SUM(i.quantity) DESC")
|
||||
List<Object[]> getTopSellingItems(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.rit.canteen.sales.service;
|
||||
import com.rit.canteen.sales.model.DashboardStats;
|
||||
import com.rit.canteen.sales.model.GeneralDashboardData;
|
||||
import com.rit.canteen.sales.model.Order;
|
||||
import com.rit.canteen.sales.model.TrendingItem;
|
||||
import com.rit.canteen.sales.repository.OrderRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -26,6 +27,7 @@ public class DashboardService {
|
||||
|
||||
DashboardStats stats = getDashboardStats(from, to);
|
||||
|
||||
System.out.println("Fetching dashboard data for range: " + from + " to " + to);
|
||||
// 1. Store Overview
|
||||
List<Object[]> storeData = orderRepository.getStoreOverview(from, to);
|
||||
List<Map<String, Object>> storeOverview = new ArrayList<>();
|
||||
@@ -59,17 +61,54 @@ public class DashboardService {
|
||||
hourlySales.add(hourMap);
|
||||
}
|
||||
|
||||
// 3. Dynamic Insights
|
||||
List<String> insights = new ArrayList<>();
|
||||
if (stats.getActiveOrders() > 0) {
|
||||
insights.add(stats.getActiveOrders() + " orders today! Clearly the crowd's found their happy place 💃🕺");
|
||||
BigDecimal avg = stats.getTotalSales() > 0 ? BigDecimal.valueOf(stats.getTotalSales()).divide(BigDecimal.valueOf(stats.getActiveOrders()), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
insights.add("₹" + avg + " average order value! Proof that happy bellies don't need heavy bills 🤤🔥");
|
||||
} else {
|
||||
insights.add("Waiting for the first orders of the day to roll in... ☕");
|
||||
// 3. Trending Items
|
||||
List<Object[]> trendingData = orderRepository.getTopSellingItems(from, to);
|
||||
List<TrendingItem> trendingItems = new ArrayList<>();
|
||||
for (int i = 0; i < Math.min(trendingData.size(), 4); i++) {
|
||||
Object[] row = trendingData.get(i);
|
||||
String name = (String) row[0];
|
||||
String category = (String) row[1];
|
||||
long qty = ((Number) row[2]).longValue();
|
||||
String imageData = (String) row[3];
|
||||
|
||||
// Format image data for frontend
|
||||
String imageUrl = imageData != null ? (imageData.startsWith("http") ? imageData : (imageData.startsWith("data:") ? imageData : "data:image/png;base64," + imageData)) : "https://images.unsplash.com/photo-1546069901-ba9599a7e63c?w=200&q=80";
|
||||
|
||||
trendingItems.add(new TrendingItem(name, category, qty, imageUrl));
|
||||
}
|
||||
|
||||
return new GeneralDashboardData(stats, storeOverview, hourlySales, insights);
|
||||
// 4. Dynamic Insights
|
||||
List<Map<String, String>> insights = new ArrayList<>();
|
||||
if (stats.getActiveOrders() > 0) {
|
||||
Map<String, String> orderInsight = new HashMap<>();
|
||||
orderInsight.put("text", stats.getActiveOrders() + " orders at RIT Canteen! Clearly the crowd's found their happy place 💃🕺");
|
||||
orderInsight.put("color", "bg-rose-50 text-rose-600 border-rose-100");
|
||||
insights.add(orderInsight);
|
||||
|
||||
BigDecimal avg = stats.getTotalSales() > 0 ? BigDecimal.valueOf(stats.getTotalSales()).divide(BigDecimal.valueOf(stats.getActiveOrders()), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
|
||||
Map<String, String> avgInsight = new HashMap<>();
|
||||
avgInsight.put("text", "₹" + avg + " average order value! Either everyone's hungry or just living large 🔥😋");
|
||||
avgInsight.put("color", "bg-emerald-50 text-emerald-600 border-emerald-100");
|
||||
insights.add(avgInsight);
|
||||
|
||||
Map<String, String> customerInsight = new HashMap<>();
|
||||
customerInsight.put("text", "RIT Canteen had " + stats.getActiveOrders() + " orders but only " + stats.getDailyCustomers() + " customers — Maybe customers are shy! 🥰");
|
||||
customerInsight.put("color", "bg-orange-50 text-orange-600 border-orange-100");
|
||||
insights.add(customerInsight);
|
||||
|
||||
Map<String, String> revenueInsight = new HashMap<>();
|
||||
revenueInsight.put("text", "RIT Canteen clocked ₹" + String.format("%,d", stats.getTotalSales()) + " — ka-ching! That's called business booming 💸📈");
|
||||
revenueInsight.put("color", "bg-blue-50 text-blue-600 border-blue-100");
|
||||
insights.add(revenueInsight);
|
||||
} else {
|
||||
Map<String, String> emptyInsight = new HashMap<>();
|
||||
emptyInsight.put("text", "Waiting for the first orders of the day to roll in... ☕");
|
||||
emptyInsight.put("color", "bg-indigo-50 text-indigo-600 border-indigo-100");
|
||||
insights.add(emptyInsight);
|
||||
}
|
||||
|
||||
System.out.println("Dashboard data generated successfully with " + trendingItems.size() + " trending items.");
|
||||
return new GeneralDashboardData(stats, storeOverview, hourlySales, insights, trendingItems);
|
||||
}
|
||||
|
||||
public DashboardStats getDashboardStats(LocalDateTime from, LocalDateTime to) {
|
||||
|
||||
0
backend/src/main/resources/canteen.db
Normal file
0
backend/src/main/resources/canteen.db
Normal file
Reference in New Issue
Block a user