master
杜威垚 2 months ago
parent 4d3417a334
commit 8e65ff12dc

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DBNavigator.Project.DatabaseBrowserManager">
<autoscroll-to-editor value="false" />
<autoscroll-from-editor value="true" />
<show-object-properties value="true" />
<loaded-nodes />
</component>
<component name="DBNavigator.Project.DatabaseFileManager">
<open-files />
</component>

@ -1,4 +1,3 @@
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
@ -213,6 +212,9 @@ public class Main extends Application {
case "分类管理":
showCategoryManagementView();
break;
case "操作日志":
showOperationLogView();
break;
default:
// 其他菜单项的处理逻辑
break;
@ -248,6 +250,10 @@ public class Main extends Application {
CategoryManagementView categoryManagementView = new CategoryManagementView();
contentArea.setCenter(categoryManagementView);
}
private void showOperationLogView() {
OperationLogView operationLogView = new OperationLogView();
contentArea.setCenter(operationLogView);
}
public static void main(String[] args) {
launch(args);
}

@ -4,17 +4,21 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.LocalDateTime;
import java.util.stream.Collectors;
public class DataManager {
private static DataManager instance;
private Map<String, Goods> goodsMap;
private List<String> suppliers;
private Map<String, Integer> inventory;
private List<OperationLog> operationLogs;
private DataManager() {
goodsMap = new HashMap<>();
suppliers = new ArrayList<>();
inventory = new HashMap<>();
operationLogs = new ArrayList<>();
initializeData();
}
@ -107,4 +111,30 @@ public class DataManager {
public Map<String, Integer> getAllStock() {
return new HashMap<>(inventory);
}
public void addOperationLog(String operationType, String operationTarget, String operator, String details) {
String id = "LOG" + System.currentTimeMillis();
OperationLog log = new OperationLog(id, operationType, operationTarget,
operator, LocalDateTime.now(), details);
operationLogs.add(log);
}
public List<OperationLog> getOperationLogs() {
return new ArrayList<>(operationLogs);
}
public List<OperationLog> getFilteredOperationLogs(LocalDateTime startDate, LocalDateTime endDate, String operationType) {
return operationLogs.stream()
.filter(log -> {
boolean timeMatch = true;
if (startDate != null && endDate != null) {
timeMatch = !log.getOperationTime().isBefore(startDate) &&
!log.getOperationTime().isAfter(endDate);
}
boolean typeMatch = "全部".equals(operationType) ||
operationType.equals(log.getOperationType());
return timeMatch && typeMatch;
})
.collect(Collectors.toList());
}
}

@ -0,0 +1,41 @@
package model;
import java.time.LocalDateTime;
public class OperationLog {
private String id;
private String operationType; // 操作类型(入库、出库、修改等)
private String operationTarget; // 操作对象货物ID或名称
private String operator; // 操作人
private LocalDateTime operationTime; // 操作时间
private String details; // 操作详情
public OperationLog(String id, String operationType, String operationTarget,
String operator, LocalDateTime operationTime, String details) {
this.id = id;
this.operationType = operationType;
this.operationTarget = operationTarget;
this.operator = operator;
this.operationTime = operationTime;
this.details = details;
}
// Getters and Setters
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getOperationType() { return operationType; }
public void setOperationType(String operationType) { this.operationType = operationType; }
public String getOperationTarget() { return operationTarget; }
public void setOperationTarget(String operationTarget) { this.operationTarget = operationTarget; }
public String getOperator() { return operator; }
public void setOperator(String operator) { this.operator = operator; }
public LocalDateTime getOperationTime() { return operationTime; }
public void setOperationTime(LocalDateTime operationTime) { this.operationTime = operationTime; }
public String getDetails() { return details; }
public void setDetails(String details) { this.details = details; }
}

@ -202,6 +202,11 @@ public class InboundView extends BorderPane {
showAlert("成功", "入库记录已保存!");
// 在handleSave方法中添加日志记录
String details = String.format("入库货物:%s数量%d供应商%s",
goodsName, quantity, supplier);
DataManager.getInstance().addOperationLog("入库", goodsName, "当前用户", details);
} catch (Exception e) {
showAlert("错误", "保存失败:" + e.getMessage());
}

@ -0,0 +1,127 @@
package view;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.control.cell.PropertyValueFactory;
import model.DataManager;
import model.OperationLog;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class OperationLogView extends BorderPane {
private TableView<OperationLog> tableView;
private DatePicker startDatePicker;
private DatePicker endDatePicker;
private ComboBox<String> operationTypeComboBox;
public OperationLogView() {
initializeUI();
}
private void initializeUI() {
// 顶部搜索区域
VBox topArea = createTopArea();
setTop(topArea);
// 中间表格区域
tableView = createTableView();
setCenter(tableView);
// 加载日志数据
loadLogData();
}
private VBox createTopArea() {
VBox topArea = new VBox(10);
topArea.setPadding(new Insets(10));
// 搜索条件区域
GridPane searchArea = new GridPane();
searchArea.setHgap(10);
searchArea.setVgap(10);
// 时间范围选择
Label dateRangeLabel = new Label("时间范围:");
startDatePicker = new DatePicker();
Label toLabel = new Label("至");
endDatePicker = new DatePicker();
// 操作类型选择
Label operationTypeLabel = new Label("操作类型:");
operationTypeComboBox = new ComboBox<>();
operationTypeComboBox.getItems().addAll("全部", "入库", "出库", "修改");
operationTypeComboBox.setValue("全部");
// 搜索按钮
Button searchButton = new Button("搜索");
searchButton.setOnAction(e -> handleSearch());
// 添加到网格
searchArea.addRow(0, dateRangeLabel, startDatePicker, toLabel, endDatePicker);
searchArea.addRow(1, operationTypeLabel, operationTypeComboBox, searchButton);
topArea.getChildren().add(searchArea);
return topArea;
}
private TableView<OperationLog> createTableView() {
TableView<OperationLog> table = new TableView<>();
TableColumn<OperationLog, String> idCol = new TableColumn<>("日志ID");
idCol.setCellValueFactory(new PropertyValueFactory<>("id"));
TableColumn<OperationLog, String> typeCol = new TableColumn<>("操作类型");
typeCol.setCellValueFactory(new PropertyValueFactory<>("operationType"));
TableColumn<OperationLog, String> targetCol = new TableColumn<>("操作对象");
targetCol.setCellValueFactory(new PropertyValueFactory<>("operationTarget"));
TableColumn<OperationLog, String> operatorCol = new TableColumn<>("操作人");
operatorCol.setCellValueFactory(new PropertyValueFactory<>("operator"));
TableColumn<OperationLog, LocalDateTime> timeCol = new TableColumn<>("操作时间");
timeCol.setCellValueFactory(new PropertyValueFactory<>("operationTime"));
timeCol.setCellFactory(column -> new TableCell<OperationLog, LocalDateTime>() {
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
protected void updateItem(LocalDateTime item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
} else {
setText(formatter.format(item));
}
}
});
TableColumn<OperationLog, String> detailsCol = new TableColumn<>("操作详情");
detailsCol.setCellValueFactory(new PropertyValueFactory<>("details"));
table.getColumns().addAll(idCol, typeCol, targetCol, operatorCol, timeCol, detailsCol);
return table;
}
private void loadLogData() {
// 从DataManager获取日志数据
tableView.setItems(FXCollections.observableArrayList(
DataManager.getInstance().getOperationLogs()
));
}
private void handleSearch() {
// 根据搜索条件过滤日志数据
LocalDateTime startDate = startDatePicker.getValue() != null ?
startDatePicker.getValue().atStartOfDay() : null;
LocalDateTime endDate = endDatePicker.getValue() != null ?
endDatePicker.getValue().atTime(23, 59, 59) : null;
String operationType = operationTypeComboBox.getValue();
tableView.setItems(FXCollections.observableArrayList(
DataManager.getInstance().getFilteredOperationLogs(startDate, endDate, operationType)
));
}
}

@ -202,6 +202,11 @@ public class OutboundView extends BorderPane {
showAlert("成功", "出库记录已保存!");
// 在handleSave方法中添加日志记录
String details = String.format("出库货物:%s数量%d客户%s",
goodsName, quantity, customer);
DataManager.getInstance().addOperationLog("出库", goodsName, "当前用户", details);
} catch (Exception e) {
showAlert("错误", "保存失败:" + e.getMessage());
}

Loading…
Cancel
Save