Browse Source

update 添加 es写入语句 指定 log打印

pull/2/head
lucas 2 months ago
parent
commit
0d195cb3a0
  1. 5
      adaptors/安心云最新设备数据toES.go
  2. 4
      consumers/consumerAXYraw.go
  3. 8
      dbHelper/elasticsearchHelper.go
  4. 23
      main_test.go

5
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 {

4
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))

8
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())

23
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
})
}

Loading…
Cancel
Save