|
@@ -0,0 +1,462 @@
|
|
|
|
|
+package space.anyi.client.controller;
|
|
|
|
|
+
|
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
+import javafx.collections.FXCollections;
|
|
|
|
|
+import javafx.fxml.FXML;
|
|
|
|
|
+import javafx.scene.control.*;
|
|
|
|
|
+import javafx.scene.control.cell.PropertyValueFactory;
|
|
|
|
|
+import javafx.scene.control.TextArea;
|
|
|
|
|
+import space.anyi.client.App;
|
|
|
|
|
+import space.anyi.client.service.BookService;
|
|
|
|
|
+import space.anyi.client.service.StatisticsService;
|
|
|
|
|
+import space.anyi.client.service.TransactionService;
|
|
|
|
|
+import space.anyi.client.service.UserService;
|
|
|
|
|
+import space.anyi.client.util.HttpClientUtil;
|
|
|
|
|
+import space.anyi.client.util.LoginUserHolder;
|
|
|
|
|
+import space.anyi.common.dto.PageResult;
|
|
|
|
|
+import space.anyi.common.dto.R;
|
|
|
|
|
+import space.anyi.common.entity.Book;
|
|
|
|
|
+import space.anyi.common.entity.TransactionRecord;
|
|
|
|
|
+import space.anyi.common.entity.User;
|
|
|
|
|
+import space.anyi.common.dto.DeptSalesDTO;
|
|
|
|
|
+import space.anyi.common.dto.HotBookDTO;
|
|
|
|
|
+import space.anyi.common.dto.DeptDiscountDTO;
|
|
|
|
|
+import space.anyi.common.dto.StatisticsSummary;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+public class MainController {
|
|
|
|
|
+
|
|
|
|
|
+ @FXML private Label welcomeLabel;
|
|
|
|
|
+
|
|
|
|
|
+ // Browse tab
|
|
|
|
|
+ @FXML private TextField searchField;
|
|
|
|
|
+ @FXML private ComboBox<String> categoryCombo;
|
|
|
|
|
+ @FXML private TableView<Book> bookTable;
|
|
|
|
|
+ @FXML private TableColumn<Book, Integer> bookIdCol;
|
|
|
|
|
+ @FXML private TableColumn<Book, String> titleCol;
|
|
|
|
|
+ @FXML private TableColumn<Book, String> authorCol;
|
|
|
|
|
+ @FXML private TableColumn<Book, String> categoryCol;
|
|
|
|
|
+ @FXML private TableColumn<Book, java.math.BigDecimal> priceCol;
|
|
|
|
|
+ @FXML private TableColumn<Book, Integer> stockCol;
|
|
|
|
|
+ @FXML private Label detailTitle;
|
|
|
|
|
+ @FXML private Label detailAuthor;
|
|
|
|
|
+ @FXML private Label detailCategory;
|
|
|
|
|
+ @FXML private Label detailPrice;
|
|
|
|
|
+ @FXML private Label detailStock;
|
|
|
|
|
+ @FXML private TextField quantityField;
|
|
|
|
|
+
|
|
|
|
|
+ // My transactions tab
|
|
|
|
|
+ @FXML private TableView<TransactionRecord> transTable;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, Integer> transIdCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, Integer> transBookIdCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, Integer> transNumCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, java.math.BigDecimal> transPriceCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, String> transTimeCol;
|
|
|
|
|
+
|
|
|
|
|
+ // Profile tab
|
|
|
|
|
+ @FXML private TextField profileUsername;
|
|
|
|
|
+ @FXML private TextField profileNickname;
|
|
|
|
|
+ @FXML private TextField profileEmail;
|
|
|
|
|
+ @FXML private TextField profilePhone;
|
|
|
|
|
+ @FXML private TextField profileDept;
|
|
|
|
|
+ @FXML private Label profileCredit;
|
|
|
|
|
+
|
|
|
|
|
+ // Seller tab
|
|
|
|
|
+ @FXML private Tab sellerTab;
|
|
|
|
|
+ @FXML private TableView<Book> myBookTable;
|
|
|
|
|
+ @FXML private TableColumn<Book, Integer> myBookIdCol;
|
|
|
|
|
+ @FXML private TableColumn<Book, String> myBookTitleCol;
|
|
|
|
|
+ @FXML private TableColumn<Book, java.math.BigDecimal> myBookPriceCol;
|
|
|
|
|
+ @FXML private TableColumn<Book, Integer> myBookStockCol;
|
|
|
|
|
+ @FXML private TextField newTitle;
|
|
|
|
|
+ @FXML private TextField newAuthor;
|
|
|
|
|
+ @FXML private TextField newCategory;
|
|
|
|
|
+ @FXML private TextField newOriginalPrice;
|
|
|
|
|
+ @FXML private TextField newSellingPrice;
|
|
|
|
|
+ @FXML private TextField newStock;
|
|
|
|
|
+
|
|
|
|
|
+ // Statistics tab
|
|
|
|
|
+ @FXML private Label statTotalAmount;
|
|
|
|
|
+ @FXML private Label statTotalCount;
|
|
|
|
|
+ @FXML private TableView<DeptSalesDTO> deptTable;
|
|
|
|
|
+ @FXML private TableColumn<DeptSalesDTO, String> deptNameCol;
|
|
|
|
|
+ @FXML private TableColumn<DeptSalesDTO, java.math.BigDecimal> deptSalesCol;
|
|
|
|
|
+ @FXML private TableView<HotBookDTO> hotBookTable;
|
|
|
|
|
+ @FXML private TableColumn<HotBookDTO, Integer> hotBookIdCol;
|
|
|
|
|
+ @FXML private TableColumn<HotBookDTO, String> hotBookTitleCol;
|
|
|
|
|
+ @FXML private TableColumn<HotBookDTO, String> hotBookAuthorCol;
|
|
|
|
|
+ @FXML private TableColumn<HotBookDTO, Integer> hotBookSoldCol;
|
|
|
|
|
+ @FXML private TableView<DeptDiscountDTO> discountTable;
|
|
|
|
|
+ @FXML private TableColumn<DeptDiscountDTO, String> discountDeptCol;
|
|
|
|
|
+ @FXML private TableColumn<DeptDiscountDTO, java.math.BigDecimal> discountRateCol;
|
|
|
|
|
+
|
|
|
|
|
+ // Admin tab
|
|
|
|
|
+ @FXML private Tab adminTab;
|
|
|
|
|
+ @FXML private TableView<User> userTable;
|
|
|
|
|
+ @FXML private TableColumn<User, Integer> userIdCol;
|
|
|
|
|
+ @FXML private TableColumn<User, String> userNameCol;
|
|
|
|
|
+ @FXML private TableColumn<User, String> userNicknameCol;
|
|
|
|
|
+ @FXML private TableColumn<User, String> userDeptCol;
|
|
|
|
|
+ @FXML private TableColumn<User, Integer> userCreditCol;
|
|
|
|
|
+ @FXML private TableColumn<User, Integer> userRoleCol;
|
|
|
|
|
+ @FXML private TableColumn<User, Integer> userSellerCol;
|
|
|
|
|
+ @FXML private TableView<TransactionRecord> allTransTable;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, Integer> allTransIdCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, Integer> allTransBookIdCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, Integer> allTransBuyerIdCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, Integer> allTransNumCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, java.math.BigDecimal> allTransPriceCol;
|
|
|
|
|
+ @FXML private TableColumn<TransactionRecord, String> allTransTimeCol;
|
|
|
|
|
+
|
|
|
|
|
+ private final BookService bookService = new BookService();
|
|
|
|
|
+ private final TransactionService transactionService = new TransactionService();
|
|
|
|
|
+ private final UserService userService = new UserService();
|
|
|
|
|
+ private final StatisticsService statisticsService = new StatisticsService();
|
|
|
|
|
+
|
|
|
|
|
+ private Book selectedBook;
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ public void initialize() {
|
|
|
|
|
+ User user = LoginUserHolder.get();
|
|
|
|
|
+ if (user != null) {
|
|
|
|
|
+ welcomeLabel.setText("欢迎," + (user.getNickname() != null ? user.getNickname() : user.getUsername()));
|
|
|
|
|
+ setupProfile(user);
|
|
|
|
|
+ if (user.getIsSeller() != 1) {
|
|
|
|
|
+ sellerTab.setDisable(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (user.getRole() != 1) {
|
|
|
|
|
+ adminTab.setDisable(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ categoryCombo.getItems().addAll("全部", "教材", "小说", "科技", "文学", "考试", "其他");
|
|
|
|
|
+ categoryCombo.getSelectionModel().select(0);
|
|
|
|
|
+ setupBrowseTable();
|
|
|
|
|
+ setupTransTable();
|
|
|
|
|
+ setupMyBookTable();
|
|
|
|
|
+ setupStatsTables();
|
|
|
|
|
+ setupAdminTables();
|
|
|
|
|
+ loadBooks();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setupBrowseTable() {
|
|
|
|
|
+ bookIdCol.setCellValueFactory(new PropertyValueFactory<>("bookId"));
|
|
|
|
|
+ titleCol.setCellValueFactory(new PropertyValueFactory<>("title"));
|
|
|
|
|
+ authorCol.setCellValueFactory(new PropertyValueFactory<>("author"));
|
|
|
|
|
+ categoryCol.setCellValueFactory(new PropertyValueFactory<>("category"));
|
|
|
|
|
+ priceCol.setCellValueFactory(new PropertyValueFactory<>("sellingPrice"));
|
|
|
|
|
+ stockCol.setCellValueFactory(new PropertyValueFactory<>("stock"));
|
|
|
|
|
+
|
|
|
|
|
+ bookTable.getSelectionModel().selectedItemProperty().addListener((obs, old, sel) -> {
|
|
|
|
|
+ if (sel != null) {
|
|
|
|
|
+ selectedBook = sel;
|
|
|
|
|
+ detailTitle.setText(sel.getTitle());
|
|
|
|
|
+ detailAuthor.setText(sel.getAuthor());
|
|
|
|
|
+ detailCategory.setText(sel.getCategory());
|
|
|
|
|
+ detailPrice.setText("¥" + sel.getSellingPrice());
|
|
|
|
|
+ detailStock.setText(String.valueOf(sel.getStock()));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setupTransTable() {
|
|
|
|
|
+ transIdCol.setCellValueFactory(new PropertyValueFactory<>("transId"));
|
|
|
|
|
+ transBookIdCol.setCellValueFactory(new PropertyValueFactory<>("bookId"));
|
|
|
|
|
+ transNumCol.setCellValueFactory(new PropertyValueFactory<>("transactionNum"));
|
|
|
|
|
+ transPriceCol.setCellValueFactory(new PropertyValueFactory<>("transactionPrice"));
|
|
|
|
|
+ transTimeCol.setCellValueFactory(new PropertyValueFactory<>("transactionTime"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setupMyBookTable() {
|
|
|
|
|
+ myBookIdCol.setCellValueFactory(new PropertyValueFactory<>("bookId"));
|
|
|
|
|
+ myBookTitleCol.setCellValueFactory(new PropertyValueFactory<>("title"));
|
|
|
|
|
+ myBookPriceCol.setCellValueFactory(new PropertyValueFactory<>("sellingPrice"));
|
|
|
|
|
+ myBookStockCol.setCellValueFactory(new PropertyValueFactory<>("stock"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setupStatsTables() {
|
|
|
|
|
+ deptNameCol.setCellValueFactory(new PropertyValueFactory<>("dept"));
|
|
|
|
|
+ deptSalesCol.setCellValueFactory(new PropertyValueFactory<>("salesAmount"));
|
|
|
|
|
+
|
|
|
|
|
+ hotBookIdCol.setCellValueFactory(new PropertyValueFactory<>("bookId"));
|
|
|
|
|
+ hotBookTitleCol.setCellValueFactory(new PropertyValueFactory<>("title"));
|
|
|
|
|
+ hotBookAuthorCol.setCellValueFactory(new PropertyValueFactory<>("author"));
|
|
|
|
|
+ hotBookSoldCol.setCellValueFactory(new PropertyValueFactory<>("totalSold"));
|
|
|
|
|
+
|
|
|
|
|
+ discountDeptCol.setCellValueFactory(new PropertyValueFactory<>("dept"));
|
|
|
|
|
+ discountRateCol.setCellValueFactory(new PropertyValueFactory<>("avgDiscountRate"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setupAdminTables() {
|
|
|
|
|
+ userIdCol.setCellValueFactory(new PropertyValueFactory<>("userid"));
|
|
|
|
|
+ userNameCol.setCellValueFactory(new PropertyValueFactory<>("username"));
|
|
|
|
|
+ userNicknameCol.setCellValueFactory(new PropertyValueFactory<>("nickname"));
|
|
|
|
|
+ userDeptCol.setCellValueFactory(new PropertyValueFactory<>("dept"));
|
|
|
|
|
+ userCreditCol.setCellValueFactory(new PropertyValueFactory<>("credit"));
|
|
|
|
|
+ userRoleCol.setCellValueFactory(new PropertyValueFactory<>("role"));
|
|
|
|
|
+ userSellerCol.setCellValueFactory(new PropertyValueFactory<>("isSeller"));
|
|
|
|
|
+
|
|
|
|
|
+ allTransIdCol.setCellValueFactory(new PropertyValueFactory<>("transId"));
|
|
|
|
|
+ allTransBookIdCol.setCellValueFactory(new PropertyValueFactory<>("bookId"));
|
|
|
|
|
+ allTransBuyerIdCol.setCellValueFactory(new PropertyValueFactory<>("buyerId"));
|
|
|
|
|
+ allTransNumCol.setCellValueFactory(new PropertyValueFactory<>("transactionNum"));
|
|
|
|
|
+ allTransPriceCol.setCellValueFactory(new PropertyValueFactory<>("transactionPrice"));
|
|
|
|
|
+ allTransTimeCol.setCellValueFactory(new PropertyValueFactory<>("transactionTime"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleSearch() {
|
|
|
|
|
+ loadBooks();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void loadBooks() {
|
|
|
|
|
+ String keyword = searchField.getText().trim();
|
|
|
|
|
+ String category = categoryCombo.getValue();
|
|
|
|
|
+ if ("全部".equals(category) || category == null || category.isBlank()) {
|
|
|
|
|
+ category = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ var result = bookService.search(keyword, category, 1, 50);
|
|
|
|
|
+ if (result.getCode() == 200 && result.getData() != null && result.getData().getRecords() != null) {
|
|
|
|
|
+ bookTable.setItems(FXCollections.observableArrayList(result.getData().getRecords()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handlePurchase() {
|
|
|
|
|
+ if (selectedBook == null) {
|
|
|
|
|
+ showAlert("请先选择一本书");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ int qty;
|
|
|
|
|
+ try {
|
|
|
|
|
+ qty = Integer.parseInt(quantityField.getText().trim());
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ showAlert("请输入有效数量");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (qty <= 0) {
|
|
|
|
|
+ showAlert("数量必须为正数");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ R<TransactionRecord> result = transactionService.purchase(
|
|
|
|
|
+ selectedBook.getBookId(),
|
|
|
|
|
+ LoginUserHolder.get().getUserid(),
|
|
|
|
|
+ qty);
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ showInfo("购买成功!");
|
|
|
|
|
+ loadBooks();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showAlert(result.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleLoadTransactions() {
|
|
|
|
|
+ R<List<TransactionRecord>> result = transactionService.getByUser(LoginUserHolder.get().getUserid());
|
|
|
|
|
+ if (result.getCode() == 200 && result.getData() != null) {
|
|
|
|
|
+ transTable.setItems(FXCollections.observableArrayList(result.getData()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleUpdateProfile() {
|
|
|
|
|
+ User user = LoginUserHolder.get();
|
|
|
|
|
+ user.setNickname(profileNickname.getText().trim());
|
|
|
|
|
+ user.setEmail(profileEmail.getText().trim());
|
|
|
|
|
+ user.setPhone(profilePhone.getText().trim());
|
|
|
|
|
+ user.setDept(profileDept.getText().trim());
|
|
|
|
|
+ R<User> result = userService.update(user.getUserid(), user);
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ showInfo("个人信息已更新");
|
|
|
|
|
+ LoginUserHolder.set(result.getData());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showAlert(result.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleLoadMyBooks() {
|
|
|
|
|
+ R<List<Book>> result = bookService.getMyBooks(LoginUserHolder.get().getUserid());
|
|
|
|
|
+ if (result.getCode() == 200 && result.getData() != null) {
|
|
|
|
|
+ myBookTable.setItems(FXCollections.observableArrayList(result.getData()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleAddBook() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Book book = new Book();
|
|
|
|
|
+ book.setSellerId(LoginUserHolder.get().getUserid());
|
|
|
|
|
+ book.setTitle(newTitle.getText().trim());
|
|
|
|
|
+ book.setAuthor(newAuthor.getText().trim());
|
|
|
|
|
+ book.setCategory(newCategory.getText().trim());
|
|
|
|
|
+ book.setOriginalPrice(new java.math.BigDecimal(newOriginalPrice.getText().trim()));
|
|
|
|
|
+ book.setSellingPrice(new java.math.BigDecimal(newSellingPrice.getText().trim()));
|
|
|
|
|
+ book.setStock(Integer.parseInt(newStock.getText().trim()));
|
|
|
|
|
+
|
|
|
|
|
+ R<Book> result = bookService.create(book);
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ showInfo("书籍已上架!");
|
|
|
|
|
+ clearBookForm();
|
|
|
|
|
+ handleLoadMyBooks();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showAlert(result.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ showAlert("输入无效:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleDeleteBook() {
|
|
|
|
|
+ Book sel = myBookTable.getSelectionModel().getSelectedItem();
|
|
|
|
|
+ if (sel == null) {
|
|
|
|
|
+ showAlert("请选择要删除的书籍");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ R<Void> result = bookService.delete(sel.getBookId());
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ showInfo("书籍已删除");
|
|
|
|
|
+ handleLoadMyBooks();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showAlert(result.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Statistics handlers
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleLoadStatistics() {
|
|
|
|
|
+ // Summary
|
|
|
|
|
+ R<StatisticsSummary> summaryResult = statisticsService.getSummary();
|
|
|
|
|
+ if (summaryResult.getCode() == 200 && summaryResult.getData() != null) {
|
|
|
|
|
+ statTotalAmount.setText("¥" + summaryResult.getData().getTotalAmount());
|
|
|
|
|
+ statTotalCount.setText(String.valueOf(summaryResult.getData().getTotalCount()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Top departments
|
|
|
|
|
+ R<List<DeptSalesDTO>> deptResult = statisticsService.getTopDepartments();
|
|
|
|
|
+ if (deptResult.getCode() == 200 && deptResult.getData() != null) {
|
|
|
|
|
+ deptTable.setItems(FXCollections.observableArrayList(deptResult.getData()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Top books
|
|
|
|
|
+ R<List<HotBookDTO>> bookResult = statisticsService.getTopBooks();
|
|
|
|
|
+ if (bookResult.getCode() == 200 && bookResult.getData() != null) {
|
|
|
|
|
+ hotBookTable.setItems(FXCollections.observableArrayList(bookResult.getData()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Discount rates
|
|
|
|
|
+ R<List<DeptDiscountDTO>> discountResult = statisticsService.getDiscountRates();
|
|
|
|
|
+ if (discountResult.getCode() == 200 && discountResult.getData() != null) {
|
|
|
|
|
+ discountTable.setItems(FXCollections.observableArrayList(discountResult.getData()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Admin handlers
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleLoadAllUsers() {
|
|
|
|
|
+ R<PageResult<User>> result = HttpClientUtil.get("/api/user?page=1&size=100",
|
|
|
|
|
+ new TypeReference<R<PageResult<User>>>() {});
|
|
|
|
|
+ if (result.getCode() == 200 && result.getData() != null && result.getData().getRecords() != null) {
|
|
|
|
|
+ userTable.setItems(FXCollections.observableArrayList(result.getData().getRecords()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleDeleteUser() {
|
|
|
|
|
+ User sel = userTable.getSelectionModel().getSelectedItem();
|
|
|
|
|
+ if (sel == null) {
|
|
|
|
|
+ showAlert("请选择要删除的用户");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ R<Void> result = userService.delete(sel.getUserid());
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ showInfo("用户已删除");
|
|
|
|
|
+ handleLoadAllUsers();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showAlert(result.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleLoadAllTransactions() {
|
|
|
|
|
+ R<PageResult<TransactionRecord>> result = HttpClientUtil.get("/api/transaction?page=1&size=100",
|
|
|
|
|
+ new TypeReference<R<PageResult<TransactionRecord>>>() {});
|
|
|
|
|
+ if (result.getCode() == 200 && result.getData() != null && result.getData().getRecords() != null) {
|
|
|
|
|
+ allTransTable.setItems(FXCollections.observableArrayList(result.getData().getRecords()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleDeleteTransaction() {
|
|
|
|
|
+ TransactionRecord sel = allTransTable.getSelectionModel().getSelectedItem();
|
|
|
|
|
+ if (sel == null) {
|
|
|
|
|
+ showAlert("请选择要删除的交易");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ R<Void> result = transactionService.delete(sel.getTransId());
|
|
|
|
|
+ if (result.getCode() == 200) {
|
|
|
|
|
+ showInfo("交易已删除");
|
|
|
|
|
+ handleLoadAllTransactions();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showAlert(result.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @FXML
|
|
|
|
|
+ private void handleLogout() {
|
|
|
|
|
+ LoginUserHolder.clear();
|
|
|
|
|
+ try {
|
|
|
|
|
+ App.showLoginScene();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ showAlert("错误:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setupProfile(User user) {
|
|
|
|
|
+ profileUsername.setText(user.getUsername());
|
|
|
|
|
+ profileNickname.setText(user.getNickname());
|
|
|
|
|
+ profileEmail.setText(user.getEmail());
|
|
|
|
|
+ profilePhone.setText(user.getPhone());
|
|
|
|
|
+ profileDept.setText(user.getDept());
|
|
|
|
|
+ profileCredit.setText(String.valueOf(user.getCredit()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void clearBookForm() {
|
|
|
|
|
+ newTitle.clear();
|
|
|
|
|
+ newAuthor.clear();
|
|
|
|
|
+ newCategory.clear();
|
|
|
|
|
+ newOriginalPrice.clear();
|
|
|
|
|
+ newSellingPrice.clear();
|
|
|
|
|
+ newStock.clear();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void showAlert(String message) {
|
|
|
|
|
+ Alert alert = new Alert(Alert.AlertType.WARNING);
|
|
|
|
|
+ alert.setTitle("提示");
|
|
|
|
|
+ alert.setHeaderText(null);
|
|
|
|
|
+ TextArea textArea = new TextArea(message);
|
|
|
|
|
+ textArea.setEditable(false);
|
|
|
|
|
+ textArea.setWrapText(true);
|
|
|
|
|
+ textArea.setPrefWidth(360);
|
|
|
|
|
+ textArea.setPrefHeight(80);
|
|
|
|
|
+ alert.getDialogPane().setContent(textArea);
|
|
|
|
|
+ alert.showAndWait();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void showInfo(String message) {
|
|
|
|
|
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
|
|
|
|
+ alert.setTitle("成功");
|
|
|
|
|
+ alert.setHeaderText(null);
|
|
|
|
|
+ TextArea textArea = new TextArea(message);
|
|
|
|
|
+ textArea.setEditable(false);
|
|
|
|
|
+ textArea.setWrapText(true);
|
|
|
|
|
+ textArea.setPrefWidth(360);
|
|
|
|
|
+ textArea.setPrefHeight(80);
|
|
|
|
|
+ alert.getDialogPane().setContent(textArea);
|
|
|
|
|
+ alert.showAndWait();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|