فهرست منبع

fix:修复MQTT报文列表行key重复导致的Duplicate keys告警

Jerry Liang 1 هفته پیش
والد
کامیت
a10cbda78f

+ 3 - 0
service/domain/esMqttDomain.go

@@ -122,6 +122,7 @@ type MqttMessageItem struct {
 	EquipNo   string         `json:"equipNo"`
 	CmdType   int64          `json:"cmdType"`
 	Event     map[string]any `json:"event,omitempty"`
+	DocID     string         `json:"docId"` // ES 文档唯一标识 "_index/_id"(非 _source 字段,查询时填充)
 }
 
 // MessagePage 逐条报文查询的分页结果
@@ -142,6 +143,8 @@ type EsHitsTotal struct {
 
 // EsMessageHit 单条命中
 type EsMessageHit struct {
+	Index  string          `json:"_index"`
+	ID     string          `json:"_id"`
 	Source MqttMessageItem `json:"_source"`
 }
 

+ 4 - 1
service/repositories/api/fwh_es_mqtt/fwh_es_mqtt.go

@@ -454,7 +454,10 @@ func QueryMessages(param QueryMessageParam) (*domain.MessagePage, error) {
 		out.Total = res.Hits.Total.Value
 		out.Items = make([]domain.MqttMessageItem, 0, len(res.Hits.Hits))
 		for _, h := range res.Hits.Hits {
-			out.Items = append(out.Items, h.Source)
+			item := h.Source
+			// _id 仅在单个索引内唯一,跨日索引查询时需带上索引名
+			item.DocID = h.Index + "/" + h.ID
+			out.Items = append(out.Items, item)
 		}
 	}
 	return out, nil

+ 1 - 0
src/service/mqttDataManage/interface.ts

@@ -47,6 +47,7 @@ export interface MqttMessageItem {
   equipNo: string
   cmdType: number
   event?: Record<string, unknown>
+  docId: string // ES 文档唯一标识 "_index/_id"
 }
 
 // 逐条报文查询分页

+ 2 - 1
src/views/mqtt-data-manage/list/index.vue

@@ -138,7 +138,8 @@ const realTotal = ref(0)
 // 是否被窗口截断(真实总数超过可翻页范围)
 const isTruncated = computed(() => realTotal.value > MAX_WINDOW)
 
-const tableRowKey = (row: MqttMessageItem) => `${row.equipNo}-${row.timeStamp}-${row.cmdType}`
+// 同设备同秒同 cmdType 可能有多条报文,需用 ES 文档 ID 作为唯一 key
+const tableRowKey = (row: MqttMessageItem) => row.docId
 
 // 时区统一 UTC。
 // 记录展示:timeStamp(秒) 为 UTC 绝对时刻,用 UTC getter 显示其 UTC 墙钟时间。