Compare commits

...

2 Commits

Author SHA1 Message Date
375de610ef refactor(client): 重构服务类继承关系并统一使用QueryService
重构所有服务类,使其继承自QueryService接口,统一数据查询逻辑。同时为服务类添加@Service注解,确保Spring容器管理。更新相关FXML文件的控制器路径,从manager.ds调整为controller目录结构。调整pom.xml版本号至0.0.84-SNAPSHOT。新增MessageNotitfication和SimpleMessage消息类,提供基础消息结构支持。
2025-09-11 00:06:22 +08:00
23e1f98ae5 feat: 实现基于JSON的登录API和安全认证
refactor: 重构登录逻辑和会话管理

fix: 修复会话ID类型和WebSocket连接问题

build: 更新项目版本号和添加Servlet API依赖

style: 清理无用导入和注释代码
2025-09-08 17:46:48 +08:00
171 changed files with 2474 additions and 713 deletions

View File

@@ -1,12 +1,22 @@
# server 模块
Java 21
Spring Boot 3.3.7
Spring Data JPA 3.3.7
JavaFX 21
ControlsFX 11.1.2
MySQL 8.0.33
Lombok 1.18.32
POI 5.2.5
PDFBox 3.0.1
Redis
# client 模块
Java 21
JavaFX 21
ControlsFX 11.1.2
Lombok 1.18.32
caffeine 3.1.8
.fxml 界面UI, /client/src/main/resources/ui/ 目录下
websocket 与 server 模块通信
ignore:
- .idea

View File

@@ -6,12 +6,12 @@
<parent>
<groupId>com.ecep.contract</groupId>
<artifactId>Contract-Manager</artifactId>
<version>0.0.58-SNAPSHOT</version>
<version>0.0.84-SNAPSHOT</version>
</parent>
<groupId>com.ecep.contract</groupId>
<artifactId>client</artifactId>
<version>0.0.58-SNAPSHOT</version>
<version>0.0.84-SNAPSHOT</version>
<properties>
<maven.compiler.source>${java.version}</maven.compiler.source>
@@ -22,7 +22,7 @@
<dependency>
<groupId>com.ecep.contract</groupId>
<artifactId>common</artifactId>
<version>0.0.58-SNAPSHOT</version>
<version>0.0.84-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
@@ -73,12 +73,6 @@
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
</dependency>
<!-- WebSocket for OkHttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-ws</artifactId>
<version>3.4.2</version>
</dependency>
</dependencies>
<build>
<plugins>

View File

@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import com.ecep.contract.controller.BaseController;
import com.ecep.contract.controller.HomeWindowController;
import com.ecep.contract.controller.OkHttpLoginController;
import com.ecep.contract.task.TaskMonitorCenter;
import com.ecep.contract.util.TextMessageHolder;
@@ -25,7 +26,7 @@ import com.ecep.contract.vm.CurrentEmployee;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
@@ -36,6 +37,12 @@ import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import lombok.Getter;
import lombok.Setter;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.WebSocket;
/**
* JavaFx 应用程序
@@ -63,9 +70,11 @@ public class Desktop extends Application {
private ScheduledExecutorService scheduledExecutorService = null;
private final TaskMonitorCenter taskMonitorCenter = new TaskMonitorCenter();
private final SimpleIntegerProperty sessionId = new SimpleIntegerProperty(0);
private final SimpleStringProperty sessionId = new SimpleStringProperty("");
@Getter
private final CurrentEmployee activeEmployee = new CurrentEmployee();
@Getter
private OkHttpClient httpClient;
public void setActiveEmployeeId(int activeEmployeeId) {
activeEmployee.getId().set(activeEmployeeId);
@@ -75,11 +84,11 @@ public class Desktop extends Application {
return activeEmployee.getId().get();
}
public int getSessionId() {
public String getSessionId() {
return sessionId.get();
}
public void setSessionId(int sessionId) {
public void setSessionId(String sessionId) {
this.sessionId.set(sessionId);
}
@@ -136,7 +145,6 @@ public class Desktop extends Application {
// 更新窗口标题
Node titleNode = root.lookup("#title");
if (titleNode != null) {
primaryStage.setTitle(((Text) titleNode).getText());
}
@@ -167,7 +175,7 @@ public class Desktop extends Application {
Properties properties = new Properties();
File configFile = new File("config.properties");
if (configFile.exists()) {
holder.debug("读取配置文件 " + configFile.getName() + "...");
holder.info("读取配置文件 " + configFile.getAbsolutePath() + "...");
try (FileInputStream input = new FileInputStream(configFile)) {
properties.load(input);
holder.info("配置文件读取成功.");
@@ -176,6 +184,8 @@ public class Desktop extends Application {
logger.error(e.getMessage(), e);
return;
}
} else {
logger.warn("配置文件{}不存在", configFile.getAbsolutePath());
}
runAsync(() -> {
@@ -187,16 +197,37 @@ public class Desktop extends Application {
});
try {
initHttpClient();
OkHttpLoginController controller = new OkHttpLoginController();
controller.setHttpClient(this.httpClient);
controller.setHolder(holder);
controller.setPrimaryStage(primaryStage);
controller.setProperties(properties);
while (true) {
controller.tryLogin();
if (getActiveEmployeeId() > 0) {
break;
// while (true) {
controller.tryLogin().whenComplete((v, e) -> {
if (e != null) {
holder.error("登录失败:" + e.getMessage());
} else {
holder.info("登录成功");
try {
while (!SpringApp.isRunning()) {
System.out.println("等待启动");
Thread.sleep(1000);
}
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
// 必须要等待启动成功后才能关闭主场景,否则进程结束程序退出
HomeWindowController.show().thenRun(() -> Platform.runLater(primaryStage::close));
}
});
// if (getActiveEmployeeId() > 0) {
// break;
// }
// }
} catch (Exception e) {
holder.error("登录失败:" + e.getMessage());
logger.error(e.getMessage(), e);
@@ -210,6 +241,26 @@ public class Desktop extends Application {
}
private void initHttpClient() {
this.httpClient = new OkHttpClient().newBuilder().cookieJar(new CookieJar() {
private final List<Cookie> cookies = new java.util.ArrayList<>();
@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
// 保存服务器返回的Cookie如JSESSIONID
this.cookies.addAll(cookies);
System.out.println("保存Cookie: " + cookies);
}
@Override
public List<Cookie> loadForRequest(HttpUrl url) {
// 请求时自动携带Cookie
return cookies;
}
}).build();
}
@Override
public void stop() throws Exception {
if (logger.isDebugEnabled()) {

View File

@@ -0,0 +1,278 @@
package com.ecep.contract;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ecep.contract.msg.SimpleMessage;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import lombok.Getter;
import lombok.Setter;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;
/**
* WebSocket消息服务
* 提供向服务器端发送WebSocket消息的功能
*/
@Service
public class WebSocketService {
private static final Logger logger = LoggerFactory.getLogger(WebSocketService.class);
@Getter
@Setter
private WebSocket webSocket;
@Autowired
private ObjectMapper objectMapper;
private static final int RECONNECT_DELAY_MS = 5000; // 重连延迟时间(毫秒)
private static final int HEARTBEAT_INTERVAL_MS = 30000; // 心跳间隔时间(毫秒)
private String webSocketUrl = "ws://localhost:8080/ws";
private boolean isActive = false; // 标记连接是否活跃
private ScheduledFuture<?> heartbeatTask; // 心跳任务
private ScheduledFuture<?> reconnectFuture; // 修改类型为CompletableFuture<Void>
private SimpleBooleanProperty online = new SimpleBooleanProperty(false);
private SimpleStringProperty message = new SimpleStringProperty("");
// 存储所有活跃的WebSocket会话
private final Map<String, CompletableFuture<JsonNode>> callbacks = Collections.synchronizedMap(new HashMap<>());
WebSocketListener listener = new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
Platform.runLater(() -> {
online.setValue(true);
message.setValue("已连接");
});
startHeartbeat(); // 启动心跳
}
@Override
public void onMessage(WebSocket webSocket, String text) {
// 处理收到的文本消息
logger.debug("收到WebSocket消息: {}", text);
// 这里可以根据需要处理从服务器接收的数据
if ("pong".equals(text)) {
// 收到pong响应说明连接正常
logger.debug("收到心跳响应");
return;
}
try {
JsonNode node = objectMapper.readTree(text);
if (node.has("messageId")) {
String messageId = node.get("messageId").asText();
CompletableFuture<JsonNode> future = callbacks.remove(messageId);
if (future != null) {
if (node.has("success")) {
if (!node.get("success").asBoolean()) {
future.completeExceptionally(
new RuntimeException("请求失败:" + node.get("message").asText()));
return;
}
}
// 使用具体类型后,这里不会再出现类型不匹配的错误
if (node.has("data")) {
future.complete(node.get("data"));
} else {
future.complete(node);
}
} else {
logger.error("未找到对应的回调future: {}", messageId);
}
}
} catch (Exception e) {
logger.error("处理WebSocket消息失败: {}", e.getMessage(), e);
}
}
@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);
stopHeartbeat(); // 停止心跳
}
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
logger.debug("WebSocket连接已关闭: 代码=" + code + ", 原因=" + reason);
stopHeartbeat(); // 停止心跳
// 处理重连逻辑
scheduleReconnect();
}
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
logger.error("WebSocket连接失败: " + t.getMessage());
Platform.runLater(() -> {
online.setValue(false);
message.set("连接失败: " + t.getMessage());
});
stopHeartbeat(); // 停止心跳
// 处理重连逻辑
scheduleReconnect();
}
};
public void send(String string) {
if (webSocket != null && webSocket.send(string)) {
logger.debug("send message success:{}", string);
} else if (webSocket == null) {
logger.warn("Failed to send message: WebSocket is not initialized");
}
}
public CompletableFuture<JsonNode> send(SimpleMessage msg) {
CompletableFuture<JsonNode> future = new CompletableFuture<>();
try {
if (webSocket == null) {
throw new IllegalStateException("WebSocket is not initialized");
}
String json = objectMapper.writeValueAsString(msg);
if (webSocket.send(json)) {
logger.debug("send message success:{}", json);
callbacks.put(msg.getMessageId(), future);
} else {
future.completeExceptionally(new RuntimeException("Failed to send WebSocket message"));
}
} catch (Exception e) {
logger.error("Failed to send WebSocket message: {}", e.getMessage());
future.completeExceptionally(e);
}
return future;
}
public void initWebSocket() {
isActive = true;
OkHttpClient httpClient = Desktop.instance.getHttpClient();
try {
// 构建WebSocket请求包含认证信息
Request request = new Request.Builder()
.url(webSocketUrl)
.build();
webSocket = httpClient.newWebSocket(request, listener);
} catch (Exception e) {
logger.error("建立WebSocket连接失败: " + e.getMessage());
Platform.runLater(() -> {
online.setValue(false);
message.set("连接失败: " + e.getMessage());
});
// 处理重连逻辑
scheduleReconnect();
}
}
/**
* 启动心跳任务定期发送ping消息保持连接
*/
private void startHeartbeat() {
// 先停止可能存在的心跳任务
stopHeartbeat();
ScheduledExecutorService executorService = Desktop.instance.getExecutorService();
heartbeatTask = executorService.scheduleAtFixedRate(this::heartbeat, RECONNECT_DELAY_MS, HEARTBEAT_INTERVAL_MS,
TimeUnit.MILLISECONDS);
}
void heartbeat() {
if (!isActive) {
return;
}
try {
if (webSocket != null) {
logger.debug("发送心跳 ping");
webSocket.send("ping");
}
} catch (Exception e) {
logger.error("发送心跳失败: {}", e.getMessage());
}
}
/**
* 停止心跳任务
*/
private void stopHeartbeat() {
if (heartbeatTask != null && !heartbeatTask.isCancelled()) {
heartbeatTask.cancel(true);
heartbeatTask = null;
}
}
/**
* 安排重连任务
*/
private void scheduleReconnect() {
if (!isActive) {
return; // 如果连接已被主动关闭,则不再重连
}
// 取消之前可能存在的重连任务
if (reconnectFuture != null && !reconnectFuture.isDone()) {
reconnectFuture.cancel(true);
}
// 创建新的重连任务s
logger.info("计划在 {} 毫秒后尝试重连WebSocket", RECONNECT_DELAY_MS);
reconnectFuture = Desktop.instance.getExecutorService().schedule(() -> {
if (isActive) {
logger.info("尝试重新连接WebSocket");
Platform.runLater(() -> {
online.setValue(false);
message.set("正在重新连接WebSocket...");
});
initWebSocket();
}
}, RECONNECT_DELAY_MS, TimeUnit.MILLISECONDS);
}
/**
* 关闭WebSocket连接
*/
public void closeWebSocket() {
isActive = false;
stopHeartbeat();
if (reconnectFuture != null && !reconnectFuture.isDone()) {
reconnectFuture.cancel(false);
reconnectFuture = null;
}
if (webSocket != null) {
webSocket.close(1000, "主动关闭连接");
webSocket = null;
}
}
public StringProperty getMessageProperty() {
return message;
}
public BooleanProperty getOnlineProperty() {
return online;
}
}

View File

@@ -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;
@@ -68,6 +71,8 @@ public class HomeWindowController extends BaseController {
public Button openCustomManagerWindow;
public TaskProgressView<Task<?>> taskProgressView;
public Label taskMonitorLabel;
public Label webSocketMonitorLabel;
public Glyph webSocketMonitorIcon;
public Label employeeStatusLabel;
public void initialize() {
@@ -95,6 +100,15 @@ public class HomeWindowController extends BaseController {
employeeStatusLabel.textProperty().bind(Desktop.instance.getActiveEmployee().getName());
Desktop.instance.getTaskMonitorCenter().bindStatusLabel(taskMonitorLabel);
Desktop.instance.getActiveEmployee().initialize();
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
@@ -129,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();
}
/**
* 打开 配置 窗口
*/
@@ -209,4 +215,12 @@ public class HomeWindowController extends BaseController {
public void onShowTaskMonitorWindowAction(ActionEvent event) {
showInOwner(TaskMonitorViewController.class);
}
@Override
public void onHidden(WindowEvent windowEvent) {
System.out.println("windowEvent = " + windowEvent);
WebSocketService webSocketService = getBean(WebSocketService.class);
webSocketService.closeWebSocket(); // 在窗口隐藏时关闭WebSocket连接
super.onHidden(windowEvent);
}
}

View File

@@ -524,7 +524,7 @@ public class LoginWidowController implements MessageHolder {
info("请稍后...");
}
Desktop.instance.setActiveEmployeeId(employeeInfo.employeeId);
Desktop.instance.setSessionId(employeeInfo.sessionId);
// Desktop.instance.setSessionId(employeeInfo.sessionId);
tryShowHomeWindow();
}

View File

@@ -18,11 +18,13 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.Desktop;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.SpringApp;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
@@ -34,16 +36,16 @@ import javafx.stage.Stage;
import lombok.Setter;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;
public class OkHttpLoginController implements MessageHolder {
private static final Logger logger = LoggerFactory.getLogger(OkHttpLoginController.class);
@@ -55,14 +57,30 @@ public class OkHttpLoginController implements MessageHolder {
private Stage primaryStage;
@Setter
private Properties properties;
@Setter
private OkHttpClient httpClient;
private WebSocket webSocket;
private String serverUrl;
private String webSocketUrl;
public OkHttpLoginController() {
this.httpClient = new OkHttpClient();
this.httpClient = new OkHttpClient().newBuilder().cookieJar(new CookieJar() {
private final List<Cookie> cookies = new java.util.ArrayList<>();
@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
// 保存服务器返回的Cookie如JSESSIONID
this.cookies.addAll(cookies);
System.out.println("保存Cookie: " + cookies);
}
@Override
public List<Cookie> loadForRequest(HttpUrl url) {
// 请求时自动携带Cookie
return cookies;
}
}).build();
}
@Override
@@ -79,20 +97,32 @@ public class OkHttpLoginController implements MessageHolder {
this.webSocketUrl = "ws://" + host + ":" + port + "/ws";
}
public void tryLogin() {
public CompletableFuture<Void> tryLogin() {
initServerUrls();
// 检查配置文件中是否保存用户名和密码
String userName = getUserName();
String password = getPassword();
CompletableFuture<Void> loginFuture = new CompletableFuture<>();
if (StringUtils.hasText(userName) && StringUtils.hasText(password)) {
login(userName, password);
login(userName, password).whenComplete((v, e) -> {
if (e != null) {
loginFuture.completeExceptionally(e);
} else {
loginFuture.complete(v);
}
});
} else {
Platform.runLater(() -> {
showLoginDialog();
if (!loginFuture.isDone()) {
loginFuture.complete(null);
}
});
}
return loginFuture;
}
private String getUserName() {
@@ -193,169 +223,109 @@ public class OkHttpLoginController implements MessageHolder {
}
// 执行登录
login(username, password);
login(username, password).whenComplete((v, e) -> {
if (e != null) {
Platform.runLater(() -> {
errorLabel.setText(e.getMessage());
errorLabel.setVisible(true);
// showError("登录失败", e.getMessage());
});
return;
}
Platform.runLater(() -> {
stage.close();
});
});
});
// 创建场景并设置到窗口
Scene scene = new Scene(borderPane, 400, 280);
stage.setScene(scene);
stage.setResizable(false);
stage.showAndWait();
System.out.println("登录窗口关闭");
}
private void login(String username, String password) {
private CompletableFuture<Void> login(String username, String password) {
// 添加详细日志记录服务器URL和请求准备情况
info("正在连接服务器: " + serverUrl);
logger.debug("login方法被调用用户名: " + username);
CompletableFuture<Void> future = new CompletableFuture<>();
try {
// 构建表单格式的登录请求
RequestBody body = new FormBody.Builder()
.add("username", username)
.add("password", password)
.build();
while (!SpringApp.isRunning()) {
holder.info("环境准备中,请稍后...");
Thread.sleep(1000);
}
ObjectMapper objectMapper = SpringApp.getBean(ObjectMapper.class);
ObjectNode objectNode = objectMapper.createObjectNode();
objectNode.put("username", username);
objectNode.put("password", password);
objectNode.put("type", "client");
// 将MacIP列表转换为Map<String, String>格式MAC地址->IP地址
List<MacIP> macIpList = getMacAndIP().join();
ObjectNode signNode = objectMapper.createObjectNode();
for (MacIP macIp : macIpList) {
signNode.put(macIp.mac, macIp.ip);
}
objectNode.set("sign", signNode);
// 构建JSON格式的登录请求
RequestBody body = RequestBody.create(objectNode.toString(), JSON);
// 构建并记录完整的请求URL
String loginUrl = serverUrl + "/api/login";
logger.debug("构建登录请求URL: " + loginUrl);
Request request = new Request.Builder()
.url(serverUrl + "/login")
.url(loginUrl)
.post(body)
.build();
httpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Platform.runLater(() -> {
error("登录失败: 无法连接到服务器 - " + e.getMessage());
showError("登录失败", "无法连接到服务器,请检查网络连接或服务器配置。");
});
future.completeExceptionally(
new IOException("登录失败: 无法连接到服务器,请检查网络连接或服务器配置 - " + e.getMessage(), e));
}
@Override
public void onResponse(Call call, Response response) throws IOException {
try {
if (!response.isSuccessful()) {
Platform.runLater(() -> {
error("登录失败: 服务器返回错误码 - " + response.code());
showError("登录失败", "用户名或密码错误,或服务器暂时不可用。");
});
future.completeExceptionally(
new IOException("登录失败: 服务器返回错误码 - " + response.toString()));
return;
}
ResponseBody body = response.body();
System.out.println("contentType = " + body.contentType());
JsonNode jsonNode = objectMapper.readTree(body.string());
try {
// 解析登录响应
String responseBody = response.body().string();
logger.debug("登录响应: " + responseBody);
// 这里需要根据实际的响应格式解析数据
// 假设响应包含employeeId和sessionId
int employeeId = extractEmployeeId(responseBody);
int sessionId = extractSessionId(responseBody);
if (employeeId > 0 && sessionId > 0) {
Platform.runLater(() -> {
info("登录成功正在建立WebSocket连接...");
// 登录成功后建立WebSocket连接
establishWebSocketConnection(employeeId, sessionId);
});
} else {
Platform.runLater(() -> {
error("登录失败: 无效的响应数据");
showError("登录失败", "服务器返回无效的响应数据。");
});
boolean success = jsonNode.get("success").asBoolean(false);
if (!success) {
future.completeExceptionally(
new IOException("登录失败: 服务器返回错误 - " + jsonNode.get("error").asText()));
return;
}
} catch (Exception e) {
Platform.runLater(() -> {
error("登录失败: 解析响应失败 - " + e.getMessage());
showError("登录失败", "解析服务器响应时发生错误。");
});
System.out.println("登录成功: " + jsonNode.toString());
// 登录成功后调用新的API端点获取用户信息
Desktop.instance.setActiveEmployeeId(jsonNode.get("employeeId").asInt());
Desktop.instance.setSessionId(jsonNode.get("sessionId").asText());
future.complete(null);
} finally {
// 确保主响应体被关闭
response.close();
}
}
});
} catch (Exception e) {
Platform.runLater(() -> {
error("登录过程中发生错误: " + e.getMessage());
showError("登录错误", e.getMessage());
});
future.completeExceptionally(new IOException("登录过程中发生错误: " + e.getMessage(), e));
}
}
private void establishWebSocketConnection(int employeeId, int sessionId) {
try {
// 构建WebSocket请求包含认证信息
Request request = new Request.Builder()
.url(webSocketUrl + "?employeeId=" + employeeId + "&sessionId=" + sessionId)
.build();
webSocket = httpClient.newWebSocket(request, new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
Platform.runLater(() -> {
info("WebSocket连接已建立");
// 登录成功后的处理
logined(employeeId, sessionId);
});
}
@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(() -> {
error("WebSocket连接失败: " + t.getMessage());
showError("连接错误", "与服务器的WebSocket连接失败。");
});
}
});
} catch (Exception e) {
logger.error("建立WebSocket连接失败: " + e.getMessage());
Platform.runLater(() -> {
error("建立WebSocket连接失败: " + e.getMessage());
showError("连接错误", "无法建立与服务器的WebSocket连接。");
});
}
}
private void logined(int employeeId, int sessionId) {
// 设置当前登录员工信息
Desktop.instance.setActiveEmployeeId(employeeId);
Desktop.instance.setSessionId(sessionId);
// 显示主窗口
tryShowHomeWindow();
}
void tryShowHomeWindow() {
try {
while (!SpringApp.isRunning()) {
System.out.println("等待启动");
Thread.sleep(1000);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// 必须要等待启动成功后才能关闭主场景,否则进程结束程序退出
HomeWindowController.show().thenRun(() -> Platform.runLater(primaryStage::close));
return future;
}
CompletableFuture<List<MacIP>> getMacAndIP() {
@@ -402,47 +372,6 @@ public class OkHttpLoginController implements MessageHolder {
});
}
// 辅助方法从响应中提取employeeId
private int extractEmployeeId(String responseBody) {
// 这里应该根据实际的响应格式进行解析
// 示例:假设响应格式是 {"employeeId": 123, "sessionId": 456}
try {
int start = responseBody.indexOf("employeeId") + 12;
int end = responseBody.indexOf(",", start);
if (end == -1) {
end = responseBody.indexOf("}", start);
}
return Integer.parseInt(responseBody.substring(start, end).trim());
} catch (Exception e) {
return -1;
}
}
// 辅助方法从响应中提取sessionId
private int extractSessionId(String responseBody) {
// 这里应该根据实际的响应格式进行解析
try {
int start = responseBody.indexOf("sessionId") + 11;
int end = responseBody.indexOf(",", start);
if (end == -1) {
end = responseBody.indexOf("}", start);
}
return Integer.parseInt(responseBody.substring(start, end).trim());
} catch (Exception e) {
return -1;
}
}
private void showError(String title, String message) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
});
}
// WebSocket消息发送方法
public void sendMessage(String message) {
if (webSocket != null) {

View File

@@ -11,10 +11,6 @@ import org.springframework.stereotype.Component;
import com.ecep.contract.constant.CompanyCustomerConstant;
import com.ecep.contract.constant.CompanyVendorConstant;
import com.ecep.contract.constant.ContractConstant;
import com.ecep.contract.service.CompanyCustomerFileService;
import com.ecep.contract.service.CompanyCustomerService;
import com.ecep.contract.service.ContractService;
import com.ecep.contract.service.YongYouU8Service;
import com.ecep.contract.util.StringConfig;
import jakarta.annotation.PreDestroy;

View File

@@ -28,27 +28,17 @@ public class YongYouU8ManagerSkin
extends
AbstEntityManagerSkin<CloudYu, CloudYuInfoViewModel, YongYouU8ManagerSkin, YongYouU8ManagerWindowController>
implements ManagerSkin {
@Setter
private YongYouU8Service u8Service;
@Setter
private CompanyService companyService;
public YongYouU8ManagerSkin(YongYouU8ManagerWindowController controller) {
super(controller);
}
YongYouU8Service getU8Service() {
if (u8Service == null) {
u8Service = SpringApp.getBean(YongYouU8Service.class);
}
return u8Service;
return getBean(YongYouU8Service.class);
}
CompanyService getCompanyService() {
if (companyService == null) {
companyService = SpringApp.getBean(CompanyService.class);
}
return companyService;
return getBean(CompanyService.class);
}
@Override

View File

@@ -10,7 +10,6 @@ import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.ecep.contract.util.ProxyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
@@ -35,6 +34,7 @@ import com.ecep.contract.service.CompanyVendorService;
import com.ecep.contract.service.ContractService;
import com.ecep.contract.task.Tasker;
import com.ecep.contract.util.ParamUtils;
import com.ecep.contract.util.ProxyUtils;
import lombok.Setter;

View File

@@ -2,16 +2,15 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Bank;
import com.ecep.contract.vm.BankViewModel;
public class BankService implements ViewModelService<Bank, BankViewModel> {
@Service
public class BankService extends QueryService<Bank, BankViewModel> {
public Bank findByName(String name) {
return null;
}
public List<Bank> search(String searchText) {
return null;
}
}

View File

@@ -4,6 +4,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.controlsfx.control.TaskProgressView;
import org.springframework.stereotype.Service;
import com.ecep.contract.Desktop;
import com.ecep.contract.MessageHolder;
@@ -17,7 +18,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javafx.concurrent.Task;
import lombok.Data;
public class CloudRkService implements ViewModelService<CloudRk, CloudRkViewModel> {
@Service
public class CloudRkService extends QueryService<CloudRk, CloudRkViewModel> {
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class EntInfo {
@@ -27,6 +29,7 @@ public class CloudRkService implements ViewModelService<CloudRk, CloudRkViewMode
private String name;
private boolean nowName;
}
/**
* 生成定时同步任务
*

View File

@@ -1,11 +1,8 @@
package com.ecep.contract.service;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.DesktopUtils;
@@ -18,7 +15,8 @@ import com.ecep.contract.vm.CloudTycInfoViewModel;
import javafx.application.Platform;
public class CloudTycService implements ViewModelService<CloudTyc, CloudTycInfoViewModel> {
@Service
public class CloudTycService extends QueryService<CloudTyc, CloudTycInfoViewModel> {
/**
* 天眼查报告,文件名中必须包含 天眼查 字样
*
@@ -58,36 +56,6 @@ public class CloudTycService implements ViewModelService<CloudTyc, CloudTycInfoV
}
@Override
public CloudTyc findById(Integer id) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findById'");
}
@Override
public CloudTyc save(CloudTyc entity) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'save'");
}
@Override
public void delete(CloudTyc entity) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'delete'");
}
@Override
public List<CloudTyc> findAll() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAll'");
}
@Override
public Page<CloudTyc> findAll(Map<String, Object> params, Pageable pageable) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAll'");
}
public CloudTyc getOrCreateCloudTyc(Company company) {
throw new UnsupportedOperationException("Unimplemented method 'getOrCreateCloudTyc'");
}

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyBankAccount;
import com.ecep.contract.vm.CompanyBankAccountViewModel;
public class CompanyBankAccountService implements ViewModelService<CompanyBankAccount, CompanyBankAccountViewModel> {
@Service
public class CompanyBankAccountService extends QueryService<CompanyBankAccount, CompanyBankAccountViewModel> {
public List<CompanyBankAccount> searchByCompany(Company company, String searchText) {
throw new UnsupportedOperationException("未实现");

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.CompanyBlackReason;
import com.ecep.contract.vm.CompanyBlackReasonViewModel;
@Service
public class CompanyBlackReasonService
implements ViewModelService<CompanyBlackReason, CompanyBlackReasonViewModel> {
extends QueryService<CompanyBlackReason, CompanyBlackReasonViewModel> {
}

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyContact;
import com.ecep.contract.vm.CompanyContactViewModel;
public class CompanyContactService implements ViewModelService<CompanyContact, CompanyContactViewModel> {
@Service
public class CompanyContactService extends QueryService<CompanyContact, CompanyContactViewModel> {
public List<CompanyContact> searchByCompany(Company company, String userText) {
// TODO Auto-generated method stub

View File

@@ -5,12 +5,14 @@ import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.CompanyCustomer;
import com.ecep.contract.model.CompanyCustomerEntity;
import com.ecep.contract.vm.CustomerEntityViewModel;
public class CompanyCustomerEntityService implements ViewModelService<CompanyCustomerEntity, CustomerEntityViewModel> {
@Service
public class CompanyCustomerEntityService extends QueryService<CompanyCustomerEntity, CustomerEntityViewModel> {
public List<CompanyCustomerEntity> findAllByCustomer(CompanyCustomer customer) {
throw new UnsupportedOperationException();
}

View File

@@ -6,6 +6,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.ecep.contract.CompanyCustomerFileType;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.CompanyCustomer;
@@ -14,7 +16,8 @@ import com.ecep.contract.model.CompanyCustomerFile;
import com.ecep.contract.model.CompanyCustomerFileTypeLocal;
import com.ecep.contract.vm.CompanyCustomerFileViewModel;
public class CompanyCustomerFileService implements ViewModelService<CompanyCustomerFile, CompanyCustomerFileViewModel> {
@Service
public class CompanyCustomerFileService extends QueryService<CompanyCustomerFile, CompanyCustomerFileViewModel> {
public List<CompanyCustomerEvaluationFormFile> findAllCustomerEvaluationFormFiles(CompanyCustomer customer) {
throw new UnsupportedOperationException();
}

View File

@@ -1,14 +1,17 @@
package com.ecep.contract.service;
import java.io.File;
import org.springframework.stereotype.Service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyCustomer;
import com.ecep.contract.model.CustomerCatalog;
import com.ecep.contract.vm.CompanyCustomerViewModel;
import java.io.File;
public class CompanyCustomerService implements ViewModelService<CompanyCustomer, CompanyCustomerViewModel> {
@Service
public class CompanyCustomerService extends QueryService<CompanyCustomer, CompanyCustomerViewModel> {
public CompanyCustomer findByCompany(Company company) {
// TODO Auto-generated method stub

View File

@@ -1,10 +1,13 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyExtendInfo;
import com.ecep.contract.vm.CompanyExtendInfoViewModel;
public class CompanyExtendInfoService implements ViewModelService<CompanyExtendInfo, CompanyExtendInfoViewModel> {
@Service
public class CompanyExtendInfoService extends QueryService<CompanyExtendInfo, CompanyExtendInfoViewModel> {
public CompanyExtendInfo findByCompany(Company company) {
throw new UnsupportedOperationException("Unimplemented method 'findByCompany'");
}

View File

@@ -5,6 +5,8 @@ import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import org.springframework.stereotype.Service;
import com.ecep.contract.CompanyFileType;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.Company;
@@ -14,7 +16,8 @@ import com.ecep.contract.vm.CompanyFileViewModel;
import javafx.collections.ObservableList;
public class CompanyFileService implements ViewModelService<CompanyFile, CompanyFileViewModel> {
@Service
public class CompanyFileService extends QueryService<CompanyFile, CompanyFileViewModel> {
public boolean reBuildingFiles(Company company, MessageHolder holder) {
// TODO Auto-generated method stub

View File

@@ -3,11 +3,14 @@ package com.ecep.contract.service;
import java.time.LocalDate;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyOldName;
import com.ecep.contract.vm.CompanyOldNameViewModel;
public class CompanyOldNameService implements ViewModelService<CompanyOldName, CompanyOldNameViewModel> {
@Service
public class CompanyOldNameService extends QueryService<CompanyOldName, CompanyOldNameViewModel> {
public boolean makePathAbsent(CompanyOldName companyOldName) {
// TODO Auto-generated method stub

View File

@@ -4,22 +4,25 @@ import java.io.File;
import java.time.LocalDate;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.Company;
import com.ecep.contract.vm.CompanyViewModel;
public class CompanyService implements ViewModelService<Company, CompanyViewModel> {
@Service
public class CompanyService extends QueryService<Company, CompanyViewModel> {
@Override
public String getBeanName() {
return "companyService";
}
public Company findByName(String name) {
// return companyRepository.findByName(name);
throw new UnsupportedOperationException("Unimplemented method 'findByName'");
}
public List<Company> search(String name) {
// return companyRepository.findByName(name);
throw new UnsupportedOperationException("Unimplemented method 'search'");
}
public List<Company> findAllByName(String name) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAllByName'");
@@ -60,5 +63,4 @@ public class CompanyService implements ViewModelService<Company, CompanyViewMode
throw new UnsupportedOperationException("Unimplemented method 'retrieveFromDownloadFiles'");
}
}

View File

@@ -1,11 +1,15 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.CompanyVendorApprovedFile;
import com.ecep.contract.model.CompanyVendorApprovedList;
import com.ecep.contract.vm.CompanyVendorApprovedFileViewModel;
public class CompanyVendorApprovedFileService implements ViewModelService<CompanyVendorApprovedFile, CompanyVendorApprovedFileViewModel> {
@Service
public class CompanyVendorApprovedFileService
extends QueryService<CompanyVendorApprovedFile, CompanyVendorApprovedFileViewModel> {
public CompanyVendorApprovedFile findByName(CompanyVendorApprovedList approvedList, String name) {
// TODO Auto-generated method stub

View File

@@ -2,12 +2,16 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.CompanyVendorApprovedItem;
import com.ecep.contract.model.CompanyVendorApprovedList;
import com.ecep.contract.vm.CompanyVendorApprovedItemViewModel;
public class CompanyVendorApprovedItemService implements ViewModelService<CompanyVendorApprovedItem, CompanyVendorApprovedItemViewModel> {
@Service
public class CompanyVendorApprovedItemService
extends QueryService<CompanyVendorApprovedItem, CompanyVendorApprovedItemViewModel> {
public List<CompanyVendorApprovedItem> findAllByListAndVendor(CompanyVendorApprovedList approvedList,
CompanyVendor vendor) {

View File

@@ -1,11 +1,14 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.CompanyVendorApprovedList;
import com.ecep.contract.vm.CompanyVendorApprovedListViewModel;
@Service
public class CompanyVendorApprovedListService
implements ViewModelService<CompanyVendorApprovedList, CompanyVendorApprovedListViewModel> {
extends QueryService<CompanyVendorApprovedList, CompanyVendorApprovedListViewModel> {
public boolean makePathAbsent(CompanyVendorApprovedList list) {
// TODO Auto-generated method stub

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.CompanyVendorEntity;
import com.ecep.contract.vm.CompanyVendorEntityViewModel;
public class CompanyVendorEntityService implements ViewModelService<CompanyVendorEntity, CompanyVendorEntityViewModel> {
@Service
public class CompanyVendorEntityService extends QueryService<CompanyVendorEntity, CompanyVendorEntityViewModel> {
}

View File

@@ -6,13 +6,16 @@ import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
import org.springframework.stereotype.Service;
import com.ecep.contract.CompanyVendorFileType;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.CompanyVendorFile;
import com.ecep.contract.model.CompanyVendorFileTypeLocal;
import com.ecep.contract.vm.CompanyVendorFileViewModel;
public class CompanyVendorFileService implements ViewModelService<CompanyVendorFile, CompanyVendorFileViewModel> {
@Service
public class CompanyVendorFileService extends QueryService<CompanyVendorFile, CompanyVendorFileViewModel> {
public LocalDate getNextSignDate(CompanyVendor companyVendor, Consumer<String> state) {
// TODO Auto-generated method stub

View File

@@ -5,6 +5,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.springframework.stereotype.Service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyVendor;
@@ -13,7 +15,8 @@ import com.ecep.contract.model.VendorCatalog;
import com.ecep.contract.model.VendorTypeLocal;
import com.ecep.contract.vm.CompanyVendorViewModel;
public class CompanyVendorService implements ViewModelService<CompanyVendor, CompanyVendorViewModel> {
@Service
public class CompanyVendorService extends QueryService<CompanyVendor, CompanyVendorViewModel> {
public VendorCatalog findCatalogById(Integer id) {
// TODO Auto-generated method stub

View File

@@ -2,12 +2,15 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Company;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.ContractBidVendor;
import com.ecep.contract.vm.ContractBidVendorViewModel;
public class ContractBidVendorService implements ViewModelService<ContractBidVendor, ContractBidVendorViewModel> {
@Service
public class ContractBidVendorService extends QueryService<ContractBidVendor, ContractBidVendorViewModel> {
public List<ContractBidVendor> findByContract(Contract contract) {
// TODO Auto-generated method stub

View File

@@ -3,13 +3,16 @@ package com.ecep.contract.service;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.ecep.contract.ContractFileType;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.ContractFile;
import com.ecep.contract.model.ContractFileTypeLocal;
import com.ecep.contract.vm.ContractFileViewModel;
public class ContractFileService implements ViewModelService<ContractFile, ContractFileViewModel> {
@Service
public class ContractFileService extends QueryService<ContractFile, ContractFileViewModel> {
public List<ContractFile> findAllByContract(Contract contract) {
// TODO Auto-generated method stub

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ContractGroup;
import com.ecep.contract.vm.ContractGroupViewModel;
public class ContractGroupService implements ViewModelService<ContractGroup, ContractGroupViewModel> {
@Service
public class ContractGroupService extends QueryService<ContractGroup, ContractGroupViewModel> {
public ContractGroup findByCode(String groupCode) {
// TODO Auto-generated method stub

View File

@@ -12,7 +12,7 @@ import com.ecep.contract.model.Inventory;
import com.ecep.contract.vm.ContractItemViewModel;
@Service
public class ContractItemService implements ViewModelService<ContractItem, ContractItemViewModel> {
public class ContractItemService extends QueryService<ContractItem, ContractItemViewModel> {
@Override
public ContractItem findById(Integer id) {

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ContractKind;
import com.ecep.contract.vm.ContractKindViewModel;
public class ContractKindService implements ViewModelService<ContractKind, ContractKindViewModel> {
@Service
public class ContractKindService extends QueryService<ContractKind, ContractKindViewModel> {
public ContractKind findByName(String name) {
throw new UnsupportedOperationException("Unimplemented method 'findByName'");

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.ContractPayPlan;
import com.ecep.contract.vm.ContractPayPlanViewModel;
public class ContractPayPlanService implements ViewModelService<ContractPayPlan, ContractPayPlanViewModel> {
@Service
public class ContractPayPlanService extends QueryService<ContractPayPlan, ContractPayPlanViewModel> {
public List<ContractPayPlan> findAllByContract(Contract contract) {
// TODO Auto-generated method stub

View File

@@ -4,6 +4,8 @@ import java.io.File;
import java.time.LocalDate;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.CompanyVendor;
import com.ecep.contract.model.Contract;
@@ -12,7 +14,8 @@ import com.ecep.contract.model.ContractGroup;
import com.ecep.contract.model.Project;
import com.ecep.contract.vm.ContractViewModel;
public class ContractService implements ViewModelService<Contract, ContractViewModel> {
@Service
public class ContractService extends QueryService<Contract, ContractViewModel> {
public boolean updateParentCode(Contract contract) {
// TODO Auto-generated method stub
@@ -28,10 +31,6 @@ public class ContractService implements ViewModelService<Contract, ContractViewM
throw new UnsupportedOperationException("Unimplemented method 'findByCode'");
}
public List<Contract> search(String searchText) {
throw new UnsupportedOperationException("Unimplemented method 'search'");
}
public Contract findByName(String name) {
throw new UnsupportedOperationException("Unimplemented method 'findByName'");
}

View File

@@ -1,20 +1,17 @@
package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ContractType;
import com.ecep.contract.vm.ContractTypeViewModel;
public class ContractTypeService implements ViewModelService<ContractType, ContractTypeViewModel> {
@Service
public class ContractTypeService extends QueryService<ContractType, ContractTypeViewModel> {
public ContractType findByName(String name) {
throw new UnsupportedOperationException("Unimplemented method 'findByName'");
}
public List<ContractType> search(String searchText) {
throw new UnsupportedOperationException("Unimplemented method 'search'");
}
public ContractType findByCode(String typeCode) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByCode'");

View File

@@ -1,8 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.CustomerSatisfactionSurvey;
import com.ecep.contract.vm.CustomerSatisfactionSurveyViewModel;
public class CustomerSatisfactionSurveyService implements ViewModelService<CustomerSatisfactionSurvey, CustomerSatisfactionSurveyViewModel> {
@Service
public class CustomerSatisfactionSurveyService
extends QueryService<CustomerSatisfactionSurvey, CustomerSatisfactionSurveyViewModel> {
}

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.DeliverySignMethod;
import com.ecep.contract.vm.DeliverySignMethodViewModel;
public class DeliverySignMethodService implements ViewModelService<DeliverySignMethod, DeliverySignMethodViewModel> {
@Service
public class DeliverySignMethodService extends QueryService<DeliverySignMethod, DeliverySignMethodViewModel> {
}

View File

@@ -1,15 +1,11 @@
package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Department;
import com.ecep.contract.vm.DepartmentViewModel;
public class DepartmentService implements ViewModelService<Department, DepartmentViewModel> {
public List<Department> search(String searchText) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'search'");
}
@Service
public class DepartmentService extends QueryService<Department, DepartmentViewModel> {
}

View File

@@ -3,11 +3,13 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.EmployeeAuthBind;
import com.ecep.contract.vm.EmployeeAuthBindViewModel;
public class EmployeeAuthBindService implements ViewModelService<EmployeeAuthBind, EmployeeAuthBindViewModel> {
@Service
public class EmployeeAuthBindService extends QueryService<EmployeeAuthBind, EmployeeAuthBindViewModel> {
public List<EmployeeAuthBind> findAllByEmployee(Object object, Sort unsorted) {
// TODO Auto-generated method stub

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.EmployeeLoginHistory;
import com.ecep.contract.vm.EmployeeLoginHistoryViewModel;
@Service
public class EmployeeLoginHistoryService
implements ViewModelService<EmployeeLoginHistory, EmployeeLoginHistoryViewModel> {
extends QueryService<EmployeeLoginHistory, EmployeeLoginHistoryViewModel> {
}

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.model.Function;
import com.ecep.contract.vm.EmployeeRoleViewModel;
public class EmployeeRoleService implements ViewModelService<EmployeeRole, EmployeeRoleViewModel> {
@Service
public class EmployeeRoleService extends QueryService<EmployeeRole, EmployeeRoleViewModel> {
public List<Function> getFunctionsByRoleId(int i) {
// TODO Auto-generated method stub

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Employee;
import com.ecep.contract.model.EmployeeRole;
import com.ecep.contract.vm.EmployeeViewModel;
public class EmployeeService implements ViewModelService<Employee, EmployeeViewModel> {
@Service
public class EmployeeService extends QueryService<Employee, EmployeeViewModel> {
public static final int DEFAULT_SYSTEM_EMPLOYEE_ID = 26;
@@ -24,12 +27,6 @@ public class EmployeeService implements ViewModelService<Employee, EmployeeViewM
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'updateActive'");
}
public List<Employee> search(String searchText) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'search'");
}
public Employee findByCode(String personCode) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByCode'");

View File

@@ -1,10 +1,13 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.ExtendVendorInfo;
import com.ecep.contract.vm.ExtendVendorInfoViewModel;
public class ExtendVendorInfoService implements ViewModelService<ExtendVendorInfo, ExtendVendorInfoViewModel> {
@Service
public class ExtendVendorInfoService extends QueryService<ExtendVendorInfo, ExtendVendorInfoViewModel> {
public ExtendVendorInfo findByContract(Contract contract) {
throw new UnsupportedOperationException("Unimplemented method 'findByContract'");

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Function;
import com.ecep.contract.vm.FunctionViewModel;
public class FunctionService implements ViewModelService<Function, FunctionViewModel> {
@Service
public class FunctionService extends QueryService<Function, FunctionViewModel> {
}

View File

@@ -2,19 +2,18 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.InventoryCatalog;
import com.ecep.contract.vm.InventoryCatalogViewModel;
public class InventoryCatalogService implements ViewModelService<InventoryCatalog, InventoryCatalogViewModel> {
@Service
public class InventoryCatalogService extends QueryService<InventoryCatalog, InventoryCatalogViewModel> {
public InventoryCatalog findByName(String v) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByName'");
}
public List<InventoryCatalog> search(String searchText) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAll'");
}
}

View File

@@ -1,11 +1,14 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Inventory;
import com.ecep.contract.model.InventoryHistoryPrice;
import com.ecep.contract.vm.InventoryHistoryPriceViewModel;
@Service
public class InventoryHistoryPriceService
implements ViewModelService<InventoryHistoryPrice, InventoryHistoryPriceViewModel> {
extends QueryService<InventoryHistoryPrice, InventoryHistoryPriceViewModel> {
public InventoryHistoryPrice[] findAllByInventory(Inventory parent) {
// TODO Auto-generated method stub

View File

@@ -1,12 +1,13 @@
package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.Inventory;
import com.ecep.contract.vm.InventoryViewModel;
public class InventoryService implements ViewModelService<Inventory, InventoryViewModel> {
@Service
public class InventoryService extends QueryService<Inventory, InventoryViewModel> {
public Inventory createNewInstance() {
// TODO Auto-generated method stub
@@ -18,11 +19,6 @@ public class InventoryService implements ViewModelService<Inventory, InventoryVi
throw new UnsupportedOperationException("Unimplemented method 'syncInventory'");
}
public List<Inventory> search(String searchText) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAllByProject'");
}
public Inventory findByCode(String code) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findByCode'");

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Invoice;
import com.ecep.contract.vm.InvoiceViewModel;
public class InvoiceService implements ViewModelService<Invoice, InvoiceViewModel> {
@Service
public class InvoiceService extends QueryService<Invoice, InvoiceViewModel> {
}

View File

@@ -2,10 +2,13 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Permission;
import com.ecep.contract.vm.PermissionViewModel;
public class PermissionService implements ViewModelService<Permission, PermissionViewModel> {
@Service
public class PermissionService extends QueryService<Permission, PermissionViewModel> {
public List<Permission> findByFunctionId(int i) {
// TODO Auto-generated method stub

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ProductType;
import com.ecep.contract.vm.ProductTypeViewModel;
public class ProductTypeService implements ViewModelService<ProductType, ProductTypeViewModel> {
@Service
public class ProductTypeService extends QueryService<ProductType, ProductTypeViewModel> {
public ProductType findByName(String name) {
// TODO Auto-generated method stub

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ProductUsage;
import com.ecep.contract.vm.ProductUsageViewModel;
public class ProductUsageService implements ViewModelService<ProductUsage, ProductUsageViewModel> {
@Service
public class ProductUsageService extends QueryService<ProductUsage, ProductUsageViewModel> {
}

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectBid;
import com.ecep.contract.vm.ProjectBidViewModel;
public class ProjectBidService implements ViewModelService<ProjectBid, ProjectBidViewModel> {
@Service
public class ProjectBidService extends QueryService<ProjectBid, ProjectBidViewModel> {
public List<ProjectBid> findAllByProject(Project project) {
// TODO Auto-generated method stub

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ProjectCost;
import com.ecep.contract.model.ProjectCostItem;
import com.ecep.contract.vm.ProjectCostItemViewModel;
public class ProjectCostItemService implements ViewModelService<ProjectCostItem, ProjectCostItemViewModel> {
@Service
public class ProjectCostItemService extends QueryService<ProjectCostItem, ProjectCostItemViewModel> {
public List<ProjectCostItem> findByCost(ProjectCost cost) {
// TODO Auto-generated method stub

View File

@@ -2,12 +2,15 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectCost;
import com.ecep.contract.vm.ProjectCostViewModel;
public class ProjectCostService implements ViewModelService<ProjectCost, ProjectCostViewModel> {
@Service
public class ProjectCostService extends QueryService<ProjectCost, ProjectCostViewModel> {
public ProjectCost findAutoCostByProject(Project project) {
// TODO Auto-generated method stub

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectFundPlan;
import com.ecep.contract.vm.ProjectFundPlanViewModel;
public class ProjectFundPlanService implements ViewModelService<ProjectFundPlan, ProjectFundPlanViewModel> {
@Service
public class ProjectFundPlanService extends QueryService<ProjectFundPlan, ProjectFundPlanViewModel> {
public List<ProjectFundPlan> findAllByProject(Project project) {
// TODO Auto-generated method stub

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ProjectIndustry;
import com.ecep.contract.vm.ProjectIndustryViewModel;
public class ProjectIndustryService implements ViewModelService<ProjectIndustry, ProjectIndustryViewModel> {
@Service
public class ProjectIndustryService extends QueryService<ProjectIndustry, ProjectIndustryViewModel> {
}

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectQuotation;
import com.ecep.contract.vm.ProjectQuotationViewModel;
public class ProjectQuotationService implements ViewModelService<ProjectQuotation, ProjectQuotationViewModel>{
@Service
public class ProjectQuotationService extends QueryService<ProjectQuotation, ProjectQuotationViewModel> {
public List<ProjectQuotation> findAllByProject(Project project) {
// TODO Auto-generated method stub

View File

@@ -2,25 +2,18 @@ package com.ecep.contract.service;
import java.util.List;
import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.model.ProjectSaleTypeRequireFileType;
import com.ecep.contract.vm.ProjectSaleTypeViewModel;
import org.springframework.stereotype.Service;
public class ProjectSaleTypeRequireFileTypeService implements ViewModelService<ProjectSaleType, ProjectSaleTypeViewModel>{
import com.ecep.contract.model.ProjectSaleTypeRequireFileType;
import com.ecep.contract.vm.ProjectSaleTypeRequireFileTypeViewModel;
@Service
public class ProjectSaleTypeRequireFileTypeService
extends QueryService<ProjectSaleTypeRequireFileType, ProjectSaleTypeRequireFileTypeViewModel> {
public List<ProjectSaleTypeRequireFileType> findBySaleTypeId(Integer id) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findBySaleTypeId'");
}
public void save(ProjectSaleTypeRequireFileType entity) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'save'");
}
public void delete(ProjectSaleTypeRequireFileType entity) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'delete'");
}
}

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.vm.ProjectSaleTypeViewModel;
public class ProjectSaleTypeService implements ViewModelService<ProjectSaleType, ProjectSaleTypeViewModel> {
@Service
public class ProjectSaleTypeService extends QueryService<ProjectSaleType, ProjectSaleTypeViewModel> {
public ProjectSaleType findByCode(String substring) {
// TODO Auto-generated method stub

View File

@@ -1,5 +1,7 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.Contract;
import com.ecep.contract.model.Project;
import com.ecep.contract.model.ProjectSaleType;
@@ -8,13 +10,10 @@ import com.ecep.contract.vm.ProjectViewModel;
import java.io.File;
import java.util.List;
public class ProjectService implements ViewModelService<Project, ProjectViewModel> {
@Service
public class ProjectService extends QueryService<Project, ProjectViewModel> {
public List<Project> search(String searchText) {
throw new UnsupportedOperationException();
}
public Project findByName(String name) {
throw new UnsupportedOperationException();
}

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ProjectType;
import com.ecep.contract.vm.ProjectTypeViewModel;
public class ProjectTypeService implements ViewModelService<ProjectType, ProjectTypeViewModel> {
@Service
public class ProjectTypeService extends QueryService<ProjectType, ProjectTypeViewModel> {
public ProjectType findByName(String name) {
// TODO Auto-generated method stub

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.PurchaseBillVoucherItem;
import com.ecep.contract.vm.PurchaseBillVoucherItemViewModel;
@Service
public class PurchaseBillVoucherItemService
implements ViewModelService<PurchaseBillVoucherItem, PurchaseBillVoucherItemViewModel> {
extends QueryService<PurchaseBillVoucherItem, PurchaseBillVoucherItemViewModel> {
}

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.PurchaseBillVoucher;
import com.ecep.contract.vm.PurchaseBillVoucherViewModel;
public class PurchaseBillVoucherService implements ViewModelService<PurchaseBillVoucher, PurchaseBillVoucherViewModel> {
@Service
public class PurchaseBillVoucherService extends QueryService<PurchaseBillVoucher, PurchaseBillVoucherViewModel> {
}

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.PurchaseOrderItem;
import com.ecep.contract.vm.PurchaseOrderItemViewModel;
public class PurchaseOrderItemService implements ViewModelService<PurchaseOrderItem, PurchaseOrderItemViewModel> {
@Service
public class PurchaseOrderItemService extends QueryService<PurchaseOrderItem, PurchaseOrderItemViewModel> {
}

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.PurchaseOrder;
import com.ecep.contract.vm.PurchaseOrderViewModel;
public class PurchaseOrdersService implements ViewModelService<PurchaseOrder, PurchaseOrderViewModel> {
@Service
public class PurchaseOrdersService extends QueryService<PurchaseOrder, PurchaseOrderViewModel> {
}

View File

@@ -0,0 +1,156 @@
package com.ecep.contract.service;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import com.ecep.contract.WebSocketService;
import com.ecep.contract.model.IdentityEntity;
import com.ecep.contract.msg.SimpleMessage;
import com.ecep.contract.vm.IdentityViewModel;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class QueryService<T extends IdentityEntity, TV extends IdentityViewModel<T>>
implements ViewModelService<T, TV> {
@Autowired
protected WebSocketService webSocketService;
@Autowired
protected ObjectMapper objectMapper;
private long readTimeout = 30000;
@SuppressWarnings("unchecked")
public TV createNewViewModel() {
try {
Type genericSuperclass = getClass().getGenericSuperclass();
System.out.println("genericSuperclass = " + genericSuperclass.getClass());
String typeName = genericSuperclass.getTypeName();
// System.out.println("typeName = " + typeName);
String clz = typeName.split("<")[1].split(">")[0].split(",")[1].trim();
// System.out.println("clz = " + clz);
Class<?> clazz = Class.forName(clz);
return (TV) clazz.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("无法创建ViewModel实例", e);
}
}
@SuppressWarnings("unchecked")
public T createNewEntity() {
try {
Type genericSuperclass = getClass().getGenericSuperclass();
String typeName = genericSuperclass.getTypeName();
// System.out.println("typeName = " + typeName);
String clz = typeName.split("<")[1].split(">")[0].split(",")[0].trim();
// System.out.println("clz = " + clz);
Class<?> clazz = Class.forName(clz);
return (T) clazz.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("无法创建Entity实例", e);
}
}
@Override
public T save(T entity) {
SimpleMessage msg = new SimpleMessage();
msg.setService(getBeanName());
msg.setMethod("save");
msg.setArguments(entity);
try {
Object response = webSocketService.send(msg).get(readTimeout, TimeUnit.MILLISECONDS);
if (response != null) {
objectMapper.updateValue(entity, response);
}
} catch (Exception e) {
e.printStackTrace();
}
return entity;
}
@Override
public void delete(T entity) {
SimpleMessage msg = new SimpleMessage();
msg.setService(getBeanName());
msg.setMethod("delete");
msg.setArguments(entity);
try {
JsonNode response = webSocketService.send(msg).get(readTimeout, TimeUnit.MILLISECONDS);
if (response != null) {
objectMapper.updateValue(entity, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public T findById(Integer id) {
SimpleMessage msg = new SimpleMessage();
msg.setService(getBeanName());
msg.setMethod("findById");
msg.setArguments(id);
try {
JsonNode response = webSocketService.send(msg).get(readTimeout, TimeUnit.MILLISECONDS);
if (response != null) {
T newEntity = createNewEntity();
objectMapper.updateValue(newEntity, response);
return newEntity;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public Page<T> findAll(Map<String, Object> params, Pageable pageable) {
SimpleMessage msg = new SimpleMessage();
msg.setService(getBeanName());
msg.setMethod("findAll");
msg.setArguments(params, pageable);
try {
JsonNode response = webSocketService.send(msg).get(readTimeout, TimeUnit.MILLISECONDS);
if (response != null) {
List<T> content = new ArrayList<>();
JsonNode contentNode = response.get("content");
if (contentNode != null && contentNode.isArray()) {
for (JsonNode node : contentNode) {
T newEntity = createNewEntity();
objectMapper.updateValue(newEntity, node);
content.add(newEntity);
}
}
JsonNode pageNode = response.get("page");
int total = pageNode.get("totalElements").asInt();
int totalPages = pageNode.get("totalPages").asInt();
int size = pageNode.get("size").asInt();
int number = pageNode.get("number").asInt();
PageRequest newPageable = PageRequest.of(number, size);
return new PageImpl<>(content, newPageable, total);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
public List<T> search(String searchText) {
Map<String, Object> params = getSpecification(searchText);
List<T> list = findAll(params, Pageable.ofSize(10)).getContent();
return list;
}
}

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.SalesOrder;
import com.ecep.contract.vm.SalesOrderViewModel;
public class SaleOrdersService implements ViewModelService<SalesOrder, SalesOrderViewModel> {
@Service
public class SaleOrdersService extends QueryService<SalesOrder, SalesOrderViewModel> {
}

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.ProjectSaleType;
import com.ecep.contract.vm.ProjectSaleTypeViewModel;
public class SaleTypeService implements ViewModelService<ProjectSaleType, ProjectSaleTypeViewModel> {
@Service
public class SaleTypeService extends QueryService<ProjectSaleType, ProjectSaleTypeViewModel> {
public ProjectSaleType findByName(String name) {
// TODO Auto-generated method stub

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.SalesBillVoucher;
import com.ecep.contract.vm.SalesBillVoucherViewModel;
public class SalesBillVoucherService implements ViewModelService<SalesBillVoucher, SalesBillVoucherViewModel> {
@Service
public class SalesBillVoucherService extends QueryService<SalesBillVoucher, SalesBillVoucherViewModel> {
}

View File

@@ -1,8 +1,11 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.SalesOrderItem;
import com.ecep.contract.vm.SalesOrderItemViewModel;
public class SalesOrderItemService implements ViewModelService<SalesOrderItem, SalesOrderItemViewModel> {
@Service
public class SalesOrderItemService extends QueryService<SalesOrderItem, SalesOrderItemViewModel> {
}

View File

@@ -5,9 +5,11 @@ import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.SysConf;
@Service
public class SysConfService {
public SysConf findById(String id) {

View File

@@ -2,11 +2,14 @@ package com.ecep.contract.service;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.VendorGroupRequireFileType;
import com.ecep.contract.vm.VendorGroupRequireFileTypeViewModel;
@Service
public class VendorGroupRequireFileTypeService
implements ViewModelService<VendorGroupRequireFileType, VendorGroupRequireFileTypeViewModel> {
extends QueryService<VendorGroupRequireFileType, VendorGroupRequireFileTypeViewModel> {
public List<VendorGroupRequireFileType> findByGroupId(Integer id) {
// TODO Auto-generated method stub

View File

@@ -1,9 +1,12 @@
package com.ecep.contract.service;
import org.springframework.stereotype.Service;
import com.ecep.contract.model.VendorGroup;
import com.ecep.contract.vm.VendorGroupViewModel;
public class VendorGroupService implements ViewModelService<VendorGroup, VendorGroupViewModel> {
@Service
public class VendorGroupService extends QueryService<VendorGroup, VendorGroupViewModel> {
public VendorGroup newInstance() {
// TODO Auto-generated method stub

View File

@@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -15,14 +16,27 @@ import com.ecep.contract.vm.IdentityViewModel;
/**
* 视图模型服务接口
*
* @param <T> 实体类型
* @param <TV> 视图模型类型
* @author 2025-08-02
* @pahor 2025-08-02
*/
public interface ViewModelService<T extends IdentityEntity, TV extends IdentityViewModel<T>>
extends IEntityService<T> {
// <ID, R extends MyRepository<T, ID>> R getRepository();
default String getBeanName() {
String className = getClass().getSimpleName();
// 按照Spring默认的bean命名规则转换
// 1. 如果类名长度大于1且首两个字符都是大写则不转换
// 2. 否则,将首字母转为小写,其余部分保持不变
if (className.length() > 1 && Character.isUpperCase(className.charAt(0))
&& Character.isUpperCase(className.charAt(1))) {
return className;
}
// 将首字母转为小写
if (className.length() > 0) {
className = Character.toLowerCase(className.charAt(0)) + className.substring(1);
}
return className;
}
default T findById(Integer id) {
return null;
@@ -74,7 +88,6 @@ public interface ViewModelService<T extends IdentityEntity, TV extends IdentityV
@Override
default T save(T entity) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'save'");
}
@@ -85,8 +98,7 @@ public interface ViewModelService<T extends IdentityEntity, TV extends IdentityV
@Override
default List<T> findAll() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'findAll'");
return findAll(null, Pageable.unpaged()).getContent();
}
default Page<T> findAll(Map<String, Object> params, Pageable pageable) {
@@ -105,5 +117,4 @@ public interface ViewModelService<T extends IdentityEntity, TV extends IdentityV
return params;
}
}

View File

@@ -4,6 +4,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.controlsfx.control.TaskProgressView;
import org.springframework.stereotype.Service;
import com.ecep.contract.Desktop;
import com.ecep.contract.model.CloudYu;
@@ -16,7 +17,8 @@ import com.ecep.contract.vm.CloudYuInfoViewModel;
import javafx.concurrent.Task;
public class YongYouU8Service implements ViewModelService<CloudYu, CloudYuInfoViewModel> {
@Service
public class YongYouU8Service extends QueryService<CloudYu, CloudYuInfoViewModel> {
/**
* 生成定时同步任务
@@ -51,4 +53,5 @@ public class YongYouU8Service implements ViewModelService<CloudYu, CloudYuInfoVi
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getOrCreateCloudYu'");
}
}

View File

@@ -157,7 +157,7 @@ public class CurrentEmployee extends EmployeeViewModel {
*/
executorService.scheduleWithFixedDelay(() -> {
try {
SpringApp.getBean(EmployeeService.class).updateActive(Desktop.instance.getSessionId());
// SpringApp.getBean(EmployeeService.class).updateActive(Desktop.instance.getSessionId());
} catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("updateActive:{}", e.getMessage(), e);

View File

@@ -3,7 +3,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.VBox?>
<VBox prefHeight="400.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.cloud.u8.YongYouU8ManagerWindowController">
fx:controller="com.ecep.contract.controller.YongYouU8ManagerWindowController">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>
@@ -45,7 +45,6 @@
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" onAction="#onDateTransferAction" text="数据迁移"/>
<MenuItem mnemonicParsing="false" text="About MyHelloApp"/>
</items>
</Menu>

View File

@@ -7,7 +7,7 @@
<?import javafx.scene.text.Font?>
<BorderPane fx:id="root" maxHeight="900" maxWidth="1024" minHeight="300" minWidth="200" prefHeight="600.0"
prefWidth="800.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.bank_account.BankAccountWindowController">
fx:controller="com.ecep.contract.controller.bank.account.BankAccountWindowController">
<center>
<TabPane fx:id="tabPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="150.0"
tabClosingPolicy="UNAVAILABLE" tabMaxWidth="100.0" tabMinWidth="40.0">

View File

@@ -3,7 +3,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="680.0" prefWidth="737.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyManagerWindowController">
fx:controller="com.ecep.contract.controller.company.CompanyManagerWindowController">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>

View File

@@ -3,7 +3,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyTabSkinBankAccount">
fx:controller="com.ecep.contract.controller.company.CompanyTabSkinBankAccount">
<HBox spacing="3.0">
<children>
<TextField fx:id="bankAccountSearchKeyField" promptText="检索关键字"/>

View File

@@ -3,7 +3,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyTabSkinBlackReason">
fx:controller="com.ecep.contract.controller.tab.CompanyTabSkinBlackReason">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -3,7 +3,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyTabSkinContact">
fx:controller="com.ecep.contract.controller.company.CompanyTabSkinContact">
<HBox spacing="3.0">
<children>
<TextField fx:id="contactSearchKeyField" promptText="检索关键字"/>

View File

@@ -11,7 +11,7 @@
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.MenuItem?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyTabSkinContract">
fx:controller="com.ecep.contract.controller.tab.CompanyTabSkinContract">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -10,7 +10,7 @@
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Separator?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyTabSkinFile">
fx:controller="com.ecep.contract.controller.tab.CompanyTabSkinFile">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -3,7 +3,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyTabSkinInvoice">
fx:controller="com.ecep.contract.controller.tab.CompanyTabSkinInvoice">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -3,7 +3,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyTabSkinOldName">
fx:controller="com.ecep.contract.controller.tab.CompanyTabSkinOldName">
<HBox spacing="3.0">
<children>
<TextField fx:id="oldNameSearchKeyField" promptText="检索关键字"/>

View File

@@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<ScrollPane fitToWidth="true" minHeight="300.0" minWidth="400.0" xmlns="http://javafx.com/javafx/22"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyTabSkinOther">
fx:controller="com.ecep.contract.controller.tab.CompanyTabSkinOther">
<content>
<VBox spacing="5.0">
<children>

View File

@@ -7,7 +7,7 @@
<?import javafx.scene.text.Font?>
<BorderPane fx:id="root" prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/22"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.company.controller.CompanyWindowController">
fx:controller="com.ecep.contract.controller.company.CompanyWindowController">
<top>
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>

View File

@@ -4,7 +4,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="680.0" prefWidth="1120.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.vendor.controller.CompanyVendorManagerWindowController">
fx:controller="com.ecep.contract.controller.vendor.CompanyVendorManagerWindowController">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>

View File

@@ -20,7 +20,7 @@
<?import javafx.scene.paint.Color?>
<?import javafx.scene.text.Font?>
<BorderPane fx:id="root" maxHeight="900" maxWidth="1024" minHeight="300" minWidth="200" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ecep.contract.manager.ds.company.controller.contact.CompanyContactWindowController">
<BorderPane fx:id="root" maxHeight="900" maxWidth="1024" minHeight="300" minWidth="200" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ecep.contract.ds.company.controller.contact.CompanyContactWindowController">
<center>
<TabPane fx:id="tabPane" tabClosingPolicy="UNAVAILABLE" tabMaxWidth="100.0" tabMinWidth="40.0">
<tabs>
@@ -114,3 +114,4 @@
</HBox>
</bottom>
</BorderPane>

View File

@@ -4,7 +4,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="680.0" prefWidth="1120.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.contract.controller.ContractManagerWindowController">
fx:controller="com.ecep.contract.controller.contract.ContractManagerWindowController">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>

View File

@@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"
xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.contract.controller.ContractTabSkinVendorBid">
fx:controller="com.ecep.contract.controller.contract.ContractTabSkinVendorBid">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -11,7 +11,7 @@
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<ScrollPane pannable="true" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ecep.contract.manager.ds.contract.controller.ContractTabSkinExtendVendorInfo">
<ScrollPane pannable="true" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ecep.contract.controller.contract.ContractTabSkinExtendVendorInfo">
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="100.0">
<children>

View File

@@ -4,7 +4,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.contract.controller.ContractTabSkinFiles">
fx:controller="com.ecep.contract.controller.contract.ContractTabSkinFiles">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.contract.controller.ContractTabSkinItemsV2">
fx:controller="com.ecep.contract.controller.contract.ContractTabSkinItemsV2">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.contract.controller.ContractTabSkinItems">
fx:controller="com.ecep.contract.controller.contract.ContractTabSkinItems">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.contract.controller.ContractTabSkinPayPlan">
fx:controller="com.ecep.contract.controller.contract.ContractTabSkinPayPlan">
<children>
<HBox spacing="3.0">
<children>

View File

@@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="400.0" prefWidth="600.0"
xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.ecep.contract.manager.ds.contract.controller.ContractTabSkinPurchaseOrders"
fx:controller="com.ecep.contract.controller.contract.ContractTabSkinPurchaseOrders"
>
<children>
<HBox spacing="3.0">

Some files were not shown because too many files have changed in this diff Show More