refactor(client): 重构服务类继承关系并统一使用QueryService
重构所有服务类,使其继承自QueryService接口,统一数据查询逻辑。同时为服务类添加@Service注解,确保Spring容器管理。更新相关FXML文件的控制器路径,从manager.ds调整为controller目录结构。调整pom.xml版本号至0.0.84-SNAPSHOT。新增MessageNotitfication和SimpleMessage消息类,提供基础消息结构支持。
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.ecep.contract.controller;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.controlsfx.control.TaskProgressView;
|
||||
import org.controlsfx.glyphfont.Glyph;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -16,6 +18,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ecep.contract.Desktop;
|
||||
import com.ecep.contract.DesktopUtils;
|
||||
import com.ecep.contract.WebSocketService;
|
||||
import com.ecep.contract.controller.bank.BankManagerWindowController;
|
||||
import com.ecep.contract.controller.company.CompanyManagerWindowController;
|
||||
import com.ecep.contract.controller.contract.ContractManagerWindowController;
|
||||
@@ -34,7 +37,6 @@ import com.ecep.contract.util.FxmlPath;
|
||||
import com.ecep.contract.util.FxmlUtils;
|
||||
import com.ecep.contract.vm.CurrentEmployee;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.Node;
|
||||
@@ -47,12 +49,6 @@ import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.WindowEvent;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.WebSocket;
|
||||
import okhttp3.WebSocketListener;
|
||||
import okio.ByteString;
|
||||
|
||||
@Lazy
|
||||
@Scope("prototype")
|
||||
@@ -75,11 +71,10 @@ public class HomeWindowController extends BaseController {
|
||||
public Button openCustomManagerWindow;
|
||||
public TaskProgressView<Task<?>> taskProgressView;
|
||||
public Label taskMonitorLabel;
|
||||
public Label webSocketMonitorLabel;
|
||||
public Glyph webSocketMonitorIcon;
|
||||
public Label employeeStatusLabel;
|
||||
|
||||
private WebSocket webSocket;
|
||||
private String webSocketUrl = "ws://localhost:8080/ws";
|
||||
|
||||
public void initialize() {
|
||||
openCompanyManagerWindow.setOnAction(event -> showInOwner(CompanyManagerWindowController.class));
|
||||
openProjectManagerWindow.setOnAction(event -> showInOwner(ProjectManagerWindowController.class));
|
||||
@@ -105,7 +100,15 @@ public class HomeWindowController extends BaseController {
|
||||
employeeStatusLabel.textProperty().bind(Desktop.instance.getActiveEmployee().getName());
|
||||
Desktop.instance.getTaskMonitorCenter().bindStatusLabel(taskMonitorLabel);
|
||||
Desktop.instance.getActiveEmployee().initialize();
|
||||
initWebSocket();
|
||||
|
||||
WebSocketService webSocketService = getBean(WebSocketService.class);
|
||||
webSocketMonitorIcon.iconProperty()
|
||||
.bind(webSocketService.getOnlineProperty().map(b -> b ? "CHAIN" : "CHAIN_BROKEN"));
|
||||
webSocketMonitorLabel.textProperty().bind(webSocketService.getMessageProperty());
|
||||
webSocketMonitorLabel.setOnMouseClicked(event -> {
|
||||
webSocketService.send("webSocketUrl - " + LocalDateTime.now().toString());
|
||||
});
|
||||
webSocketService.initWebSocket();
|
||||
}
|
||||
|
||||
@EventListener
|
||||
@@ -140,14 +143,6 @@ public class HomeWindowController extends BaseController {
|
||||
// scheduledExecutorService.shutdownNow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHidden(WindowEvent windowEvent) {
|
||||
System.out.println("windowEvent = " + windowEvent);
|
||||
super.onHidden(windowEvent);
|
||||
|
||||
// Platform.exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开 配置 窗口
|
||||
*/
|
||||
@@ -221,63 +216,11 @@ public class HomeWindowController extends BaseController {
|
||||
showInOwner(TaskMonitorViewController.class);
|
||||
}
|
||||
|
||||
private void initWebSocket() {
|
||||
|
||||
OkHttpClient httpClient = Desktop.instance.getHttpClient();
|
||||
|
||||
try {
|
||||
// 构建WebSocket请求,包含认证信息
|
||||
Request request = new Request.Builder()
|
||||
.url(webSocketUrl)
|
||||
.build();
|
||||
|
||||
webSocket = httpClient.newWebSocket(request, new WebSocketListener() {
|
||||
@Override
|
||||
public void onOpen(WebSocket webSocket, Response response) {
|
||||
Platform.runLater(() -> {
|
||||
setStatus("WebSocket连接已建立");
|
||||
// 登录成功后的处理
|
||||
System.out.println("WebSocket连接已建立");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(WebSocket webSocket, String text) {
|
||||
// 处理收到的文本消息
|
||||
logger.debug("收到WebSocket消息: " + text);
|
||||
// 这里可以根据需要处理从服务器接收的数据
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(WebSocket webSocket, ByteString bytes) {
|
||||
// 处理收到的二进制消息
|
||||
logger.debug("收到二进制WebSocket消息,长度: " + bytes.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosing(WebSocket webSocket, int code, String reason) {
|
||||
logger.debug("WebSocket连接正在关闭: 代码=" + code + ", 原因=" + reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed(WebSocket webSocket, int code, String reason) {
|
||||
logger.debug("WebSocket连接已关闭: 代码=" + code + ", 原因=" + reason);
|
||||
// 可以在这里处理重连逻辑
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
|
||||
logger.error("WebSocket连接失败: " + t.getMessage());
|
||||
Platform.runLater(() -> {
|
||||
setStatus("WebSocket连接失败: " + t.getMessage());
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("建立WebSocket连接失败: " + e.getMessage());
|
||||
Platform.runLater(() -> {
|
||||
setStatus("建立WebSocket连接失败: " + e.getMessage());
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void onHidden(WindowEvent windowEvent) {
|
||||
System.out.println("windowEvent = " + windowEvent);
|
||||
WebSocketService webSocketService = getBean(WebSocketService.class);
|
||||
webSocketService.closeWebSocket(); // 在窗口隐藏时关闭WebSocket连接
|
||||
super.onHidden(windowEvent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user