fix(iot,ops): 确保信标相关审计事件包含orderId以支持工单关联查询
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled

修改内容:
1. BeaconDetectionRuleProcessor.publishAuditEvent 添加 orderId 参数
   - BEACON_ARRIVE_CONFIRMED 事件包含当前工单ID
   - BEACON_LEAVE_WARNING_SENT 事件从设备状态获取工单ID
   - TTS_REQUEST 事件不包含工单ID(非工单特定)

2. SignalLossRuleProcessor.publishAuditEvent 添加 orderId 参数
   - BEACON_COMPLETE_REQUESTED 事件包含当前工单ID
   - COMPLETE_SUPPRESSED_INVALID 事件从设备状态获取工单ID

3. CleanOrderAuditEventHandler 使用 EventLogRecord.builder()
   - 显式设置 targetId 和 targetType 字段
   - 确保 targetType="order" 当 orderId 存在时

影响范围:
- ops_business_event_log 表新增记录将正确包含 targetId 和 targetType
- 支持按工单ID查询所有相关审计日志
- 解决信标到岗/离岗/完成事件缺失工单关联的问题

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
lzh
2026-02-01 10:26:06 +08:00
parent fc1bc609e6
commit 46096a6e6b
4 changed files with 42 additions and 32 deletions

View File

@@ -1,16 +1,17 @@
package com.viewsh.module.ops.environment.integration.consumer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.viewsh.module.ops.environment.constants.CleanNotificationConstants;
import com.viewsh.module.ops.environment.integration.dto.CleanOrderAuditEventDTO;
import com.viewsh.module.ops.environment.service.voice.VoiceBroadcastService;
import com.viewsh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.viewsh.module.ops.dal.dataobject.workorder.OpsOrderDO;
import com.viewsh.module.ops.dal.mysql.workorder.OpsOrderMapper;
import com.viewsh.module.ops.enums.WorkOrderStatusEnum;
import com.viewsh.module.ops.environment.constants.CleanNotificationConstants;
import com.viewsh.module.ops.environment.integration.dto.CleanOrderAuditEventDTO;
import com.viewsh.module.ops.environment.service.voice.VoiceBroadcastService;
import com.viewsh.module.ops.infrastructure.log.enumeration.EventDomain;
import com.viewsh.module.ops.infrastructure.log.enumeration.EventLevel;
import com.viewsh.module.ops.infrastructure.log.recorder.EventLogRecord;
import com.viewsh.module.ops.infrastructure.log.recorder.EventLogRecorder;
import com.viewsh.framework.mybatis.core.query.LambdaQueryWrapperX;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
@@ -109,11 +110,18 @@ public class CleanOrderAuditEventHandler implements RocketMQListener<String> {
String eventType = event.getAuditType() != null ? event.getAuditType() : "AUDIT";
// 2. 记录审计日志
eventLogRecorder.info("clean", domain, eventType,
event.getMessage(),
event.getOrderId(),
event.getDeviceId(),
null);
eventLogRecorder.record(
EventLogRecord.builder()
.module("clean")
.domain(domain)
.eventType(eventType)
.message(event.getMessage())
.targetId(event.getOrderId())
.targetType(event.getOrderId() != null ? "order" : null)
.deviceId(event.getDeviceId())
.level(level)
.build()
);
log.debug("[CleanOrderAuditEventHandler] 审计日志已记录: eventId={}, auditType={}",
event.getEventId(), event.getAuditType());

View File

@@ -335,18 +335,10 @@ public class CleanOrderEndToEndTest {
// Verify
// 1. Log recorded
verify(eventLogRecorder).info(
eq("clean"),
any(),
eq("TTS_REQUEST"),
contains("TTS Message"),
any(),
eq(5001L),
any()
);
verify(eventLogRecorder).record(any());
// 2. TTS sent
verify(voiceBroadcastService).broadcast(eq(5001L), contains("请回到作业区域"), any(Long.class));
// 2. TTS sent (orderId can be null for TTS_REQUEST events)
verify(voiceBroadcastService).broadcast(eq(5001L), contains("请回到作业区域"), isNull());
}
// ==========================================