feat: 实现员工同步任务的WebSocket支持及合同名称锁定功能
- 为EmployeesSyncTask添加WebSocket客户端和服务端支持,实现实时任务进度反馈 - 新增合同名称锁定功能,防止误修改重要合同名称 - 优化SmbFileService的连接异常处理,提高稳定性 - 重构ContractFilesRebuildTasker的任务执行逻辑,改进错误处理 - 更新tasker_mapper.json注册EmployeesSyncTask - 添加相关任务文档和验收报告 修复WebSocketClientSession的任务完成状态处理问题 改进UITools中任务执行的线程管理 优化DepartmentService的findByCode方法返回类型
This commit is contained in:
@@ -5,20 +5,22 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* WebSocket客户端任务接口
|
||||
* 定义了所有通过WebSocket与服务器通信的任务的通用方法
|
||||
* 包括任务名称、更新消息、更新标题、更新进度等操作
|
||||
*
|
||||
* <p>
|
||||
* 所有通过WebSocket与服务器通信的任务类都应实现此接口, 文档参考 .trace/rules/client_task_rules.md
|
||||
*/
|
||||
public interface WebSocketClientTasker {
|
||||
/**s
|
||||
/**
|
||||
* s
|
||||
* 获取任务名称
|
||||
* 任务名称用于唯一标识任务, 服务器端会根据任务名称来调用对应的任务处理函数
|
||||
*
|
||||
*
|
||||
* @return 任务名称
|
||||
*/
|
||||
String getTaskName();
|
||||
@@ -26,7 +28,7 @@ public interface WebSocketClientTasker {
|
||||
/**
|
||||
* 更新任务执行过程中的消息
|
||||
* 客户端可以通过此方法向用户展示任务执行过程中的重要信息或错误提示
|
||||
*
|
||||
*
|
||||
* @param level 消息级别, 用于区分不同类型的消息, 如INFO, WARNING, SEVERE等
|
||||
* @param message 消息内容, 可以是任意字符串, 用于展示给用户
|
||||
*/
|
||||
@@ -35,7 +37,7 @@ public interface WebSocketClientTasker {
|
||||
/**
|
||||
* 更新任务标题
|
||||
* 客户端可以通过此方法向用户展示任务的当前执行状态或重要信息
|
||||
*
|
||||
*
|
||||
* @param title 任务标题
|
||||
*/
|
||||
void updateTitle(String title);
|
||||
@@ -43,7 +45,7 @@ public interface WebSocketClientTasker {
|
||||
/**
|
||||
* 更新任务进度
|
||||
* 客户端可以通过此方法向用户展示任务的执行进度, 如文件上传进度、数据库操作进度等
|
||||
*
|
||||
*
|
||||
* @param current 当前进度
|
||||
* @param total 总进度
|
||||
*/
|
||||
@@ -55,12 +57,15 @@ public interface WebSocketClientTasker {
|
||||
*/
|
||||
default void cancelTask() {
|
||||
// 默认实现为空,由具体任务重写
|
||||
// 需要获取到 session
|
||||
// 发送 cancel 指令
|
||||
// 关闭 session.close()
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用远程WebSocket任务
|
||||
* 客户端可以通过此方法向服务器提交任务, 并等待服务器返回任务执行结果
|
||||
*
|
||||
*
|
||||
* @param holder 消息持有者,用于记录任务执行过程中的消息
|
||||
* @param locale 语言环境
|
||||
* @param args 任务参数
|
||||
@@ -76,22 +81,31 @@ public interface WebSocketClientTasker {
|
||||
return null;
|
||||
}
|
||||
|
||||
webSocketService.withSession(session -> {
|
||||
try {
|
||||
session.submitTask(this, locale, args);
|
||||
holder.info("已提交任务到服务器: " + getTaskName());
|
||||
} catch (JsonProcessingException e) {
|
||||
String errorMsg = "任务提交失败: " + e.getMessage();
|
||||
holder.warn(errorMsg);
|
||||
throw new RuntimeException("任务提交失败: " + e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
WebSocketClientSession session = webSocketService.createSession();
|
||||
try {
|
||||
session.submitTask(this, locale, args);
|
||||
holder.info("已提交任务到服务器: " + getTaskName());
|
||||
} catch (JsonProcessingException e) {
|
||||
String errorMsg = "任务提交失败: " + e.getMessage();
|
||||
holder.warn(errorMsg);
|
||||
throw new RuntimeException("任务提交失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
// while (!session.isDone()) {
|
||||
// // 使用TimeUnit
|
||||
// try {
|
||||
// TimeUnit.SECONDS.sleep(1);
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// }
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步调用远程WebSocket任务
|
||||
*
|
||||
*
|
||||
* @param holder 消息持有者,用于记录任务执行过程中的消息
|
||||
* @param locale 语言环境
|
||||
* @param args 任务参数
|
||||
@@ -113,7 +127,7 @@ public interface WebSocketClientTasker {
|
||||
|
||||
/**
|
||||
* 生成唯一的任务ID
|
||||
*
|
||||
*
|
||||
* @return 唯一的任务ID
|
||||
*/
|
||||
default String generateTaskId() {
|
||||
|
||||
Reference in New Issue
Block a user