|
|
@@ -3,6 +3,7 @@ package space.anyi.client.controller;
|
|
|
import javafx.application.Platform;
|
|
|
import javafx.collections.FXCollections;
|
|
|
import javafx.fxml.FXML;
|
|
|
+import javafx.scene.chart.*;
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
import javafx.scene.Node;
|
|
|
import javafx.scene.control.*;
|
|
|
@@ -122,7 +123,9 @@ public class MainController {
|
|
|
@FXML private TableView<DeptDiscountDTO> discountTable;
|
|
|
@FXML private TableColumn<DeptDiscountDTO, String> discountDeptCol;
|
|
|
@FXML private TableColumn<DeptDiscountDTO, java.math.BigDecimal> discountRateCol;
|
|
|
- @FXML private TableColumn<DeptDiscountDTO, Void> discountBarCol;
|
|
|
+ @FXML private PieChart deptPieChart;
|
|
|
+ @FXML private BarChart<String, Number> hotBookChart;
|
|
|
+ @FXML private LineChart<String, Number> discountChart;
|
|
|
|
|
|
// Admin tab
|
|
|
@FXML private TableView<User> userTable;
|
|
|
@@ -506,7 +509,9 @@ public class MainController {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- transTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
|
|
+ deptTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
|
|
+ hotBookTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
|
|
+ discountTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
|
@@ -838,30 +843,6 @@ public class MainController {
|
|
|
|
|
|
discountDeptCol.setCellValueFactory(new PropertyValueFactory<>("dept"));
|
|
|
discountRateCol.setCellValueFactory(new PropertyValueFactory<>("avgDiscountRate"));
|
|
|
- discountBarCol.setCellFactory(col -> new TableCell<DeptDiscountDTO, Void>() {
|
|
|
- @Override
|
|
|
- protected void updateItem(Void item, boolean empty) {
|
|
|
- super.updateItem(item, empty);
|
|
|
- if (empty) {
|
|
|
- setGraphic(null);
|
|
|
- } else {
|
|
|
- DeptDiscountDTO d = getTableView().getItems().get(getIndex());
|
|
|
- if (d.getAvgDiscountRate() == null) {
|
|
|
- setGraphic(null);
|
|
|
- return;
|
|
|
- }
|
|
|
- double rate = d.getAvgDiscountRate().doubleValue();
|
|
|
- ProgressBar bar = new ProgressBar(rate / 100.0);
|
|
|
- bar.setPrefWidth(150);
|
|
|
- bar.setPrefHeight(8);
|
|
|
- Label pct = new Label(String.format("%.0f%%", rate));
|
|
|
- pct.setStyle("-fx-font-size: 12px; -fx-text-fill: -fx-text-secondary;");
|
|
|
- HBox hb = new HBox(8, bar, pct);
|
|
|
- hb.setAlignment(Pos.CENTER_LEFT);
|
|
|
- setGraphic(hb);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
|
@@ -875,16 +856,36 @@ public class MainController {
|
|
|
R<List<DeptSalesDTO>> deptResult = statisticsService.getTopDepartments();
|
|
|
if (deptResult.getCode() == 200 && deptResult.getData() != null) {
|
|
|
deptTable.setItems(FXCollections.observableArrayList(deptResult.getData()));
|
|
|
+ deptPieChart.getData().clear();
|
|
|
+ for (DeptSalesDTO d : deptResult.getData()) {
|
|
|
+ deptPieChart.getData().add(new PieChart.Data(d.getDept(), d.getSalesAmount().doubleValue()));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
R<List<HotBookDTO>> bookResult = statisticsService.getTopBooks();
|
|
|
if (bookResult.getCode() == 200 && bookResult.getData() != null) {
|
|
|
hotBookTable.setItems(FXCollections.observableArrayList(bookResult.getData()));
|
|
|
+ hotBookChart.getData().clear();
|
|
|
+ XYChart.Series<String, Number> series = new XYChart.Series<>();
|
|
|
+ series.setName("销量");
|
|
|
+ for (HotBookDTO b : bookResult.getData()) {
|
|
|
+ String label = b.getTitle();
|
|
|
+ if (label.length() > 8) label = label.substring(0, 8) + "…";
|
|
|
+ series.getData().add(new XYChart.Data<>(label, b.getTotalSold()));
|
|
|
+ }
|
|
|
+ hotBookChart.getData().add(series);
|
|
|
}
|
|
|
|
|
|
R<List<DeptDiscountDTO>> discountResult = statisticsService.getDiscountRates();
|
|
|
if (discountResult.getCode() == 200 && discountResult.getData() != null) {
|
|
|
discountTable.setItems(FXCollections.observableArrayList(discountResult.getData()));
|
|
|
+ discountChart.getData().clear();
|
|
|
+ XYChart.Series<String, Number> ds = new XYChart.Series<>();
|
|
|
+ ds.setName("折扣率");
|
|
|
+ for (DeptDiscountDTO d : discountResult.getData()) {
|
|
|
+ ds.getData().add(new XYChart.Data<>(d.getDept(), d.getAvgDiscountRate().doubleValue()));
|
|
|
+ }
|
|
|
+ discountChart.getData().add(ds);
|
|
|
}
|
|
|
}
|
|
|
|