fix(ops): 启动时校准人员调度状态
- 为 UserDispatchStatusService 增加基于 DB 的重建能力\n- 扫描 Redis 中的人员调度 key,按实际活跃工单数修正 status、activeOrderCount、waitingTaskCount\n- 新增启动初始化器,服务启动时自动执行一次校准,缓解事件丢失导致的 BUSY 残留
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.viewsh.module.ops.framework.job.dispatch;
|
||||
|
||||
import com.viewsh.framework.tenant.core.util.TenantUtils;
|
||||
import com.viewsh.module.ops.service.dispatch.UserDispatchStatusService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 人员调度状态 Redis 启动校准器
|
||||
* <p>
|
||||
* 职责:服务启动时,扫描 Redis 中所有人员调度状态 key,
|
||||
* 与 DB 中的实际活跃工单比对,修正 status / activeOrderCount / waitingTaskCount。
|
||||
* <p>
|
||||
* 解决场景:
|
||||
* - 服务重启期间工单完成/取消事件丢失,导致人员状态卡在 BUSY
|
||||
* - 计数器漂移(increment/decrement 不对称)
|
||||
*
|
||||
* @author AI
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class UserDispatchStatusInitializer implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private UserDispatchStatusService userDispatchStatusService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
log.info("[初始化] 开始校准人员调度状态...");
|
||||
|
||||
try {
|
||||
TenantUtils.executeIgnore(() -> {
|
||||
int calibrated = userDispatchStatusService.calibrateFromDb();
|
||||
log.info("[初始化] 人员调度状态校准完成:修正 {} 个用户", calibrated);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("[初始化] 人员调度状态校准失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user