From 0d195cb3a02a10d6849a3631fda9928fc7214f61 Mon Sep 17 00:00:00 2001 From: lucas Date: Mon, 18 Nov 2024 11:36:35 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=B7=BB=E5=8A=A0=20es=E5=86=99?= =?UTF-8?q?=E5=85=A5=E8=AF=AD=E5=8F=A5=20=20=E6=8C=87=E5=AE=9A=20log?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adaptors/安心云最新设备数据toES.go | 5 ----- consumers/consumerAXYraw.go | 4 +++- dbHelper/elasticsearchHelper.go | 8 +++++++ main_test.go | 23 +++++++++++++++++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/adaptors/安心云最新设备数据toES.go b/adaptors/安心云最新设备数据toES.go index f1750a3..2ae9d3f 100644 --- a/adaptors/安心云最新设备数据toES.go +++ b/adaptors/安心云最新设备数据toES.go @@ -35,11 +35,6 @@ func (the Adaptor_AXY_LastRAW) raw2es(iotaData models.IotaData) *models.EsRaw { log.Printf("设备[%s] 无deviceInfo信息 %s", iotaData.DeviceId, iotaData.TriggerTime) return nil } - //log 日志排查 - logTagDeviceId := "91da4d1f-fbc7-4dad-bedd-f8ff05c0e0e0" - if iotaData.DeviceId == logTagDeviceId { - log.Printf("onData -> needPush 标记设备数据 [%s]", logTagDeviceId) - } dataType := "" if _dataType, ok := iotaData.Data.Data["_data_type"]; ok { diff --git a/consumers/consumerAXYraw.go b/consumers/consumerAXYraw.go index 46ab795..f52e5da 100644 --- a/consumers/consumerAXYraw.go +++ b/consumers/consumerAXYraw.go @@ -105,8 +105,10 @@ func (the *consumerAXYraw) toSink() { log.Printf("toSink -> Range 标记设备数据 [%s] %s ", logTagDeviceId, string(bs)) } return ok + } else { + log.Printf("!!! toSink -> Range 类型转换异常 [%v]", key) } - return false + return true }) if len(raws) > 0 { log.Printf("准备写入es %d条", len(raws)) diff --git a/dbHelper/elasticsearchHelper.go b/dbHelper/elasticsearchHelper.go index bc14491..7f0d512 100644 --- a/dbHelper/elasticsearchHelper.go +++ b/dbHelper/elasticsearchHelper.go @@ -196,6 +196,10 @@ func (the *ESHelper) BulkWrite(index, reqBody string) { } func (the *ESHelper) BulkWriteRaws2Es(index string, raws []models.EsRaw) { + + //log 测试用 + const logTagDeviceId = "91da4d1f-fbc7-4dad-bedd-f8ff05c0e0e0" + body := strings.Builder{} for _, raw := range raws { // scala => val id = UUID.nameUUIDFromBytes(s"${v.deviceId}-${v.acqTime.getMillis}".getBytes("UTF-8")).toString @@ -206,6 +210,10 @@ func (the *ESHelper) BulkWriteRaws2Es(index string, raws []models.EsRaw) { %s `, index, _id, source) body.WriteString(s) + + if raw.IotaDevice == logTagDeviceId { + log.Printf("BulkWriteRaws2Es 标记设备数据 [%s] %s ", logTagDeviceId, string(s)) + } } the.BulkWrite(index, body.String()) diff --git a/main_test.go b/main_test.go index 9e5ee23..26e5667 100644 --- a/main_test.go +++ b/main_test.go @@ -4,14 +4,17 @@ import ( "bytes" "crypto/rc4" "encoding/hex" + "fmt" "goInOut/utils" "log" + "sync" "testing" "text/template" "time" ) func TestCRC16CCITT(t *testing.T) { + hexs := "0a16080718a8ea8fab06620c0a0471bd54c11204e01d8641" hexs = "0a2f080210f8b6d5d01218b395bffec3313a1e0a08a75fed41a75fed41120892c5d64292c5d6421a08f6c8a74379c9a743" Hexdata, _ := hex.DecodeString(hexs) @@ -50,3 +53,23 @@ func TestTemplate(t *testing.T) { bs := b.String() log.Println(bs) } + +func TestRangeMap(t *testing.T) { + m := sync.Map{} + //存数据 + m.Store(1, 1) + m.Store(2, 2) + m.Store(3, 3) + m.Store(4, 4) + m.Store(5, 5) + + //遍历map + m.Range(func(key, value interface{}) bool { + log.Printf("开始遍历 %v", key) + if key.(int) == 2 { + return false + } + fmt.Println(key, value) + return true + }) +}