Compare commits

...

53 Commits

Author SHA1 Message Date
lucas2 4f09121f6f Merge pull request '合并最新dev' (#2) from dev into master 2 weeks ago
lucas 075f8b40d3 update 修改结构名称 2 weeks ago
lucas d4c10f1a10 update 限制单次最多查询200条 2 weeks ago
lucas b5925b054e update golang-builder-1-23 2 weeks ago
lucas d75d767904 update git branch: 'dev' 2 weeks ago
lucas e7cb98f992 update 重构 jenkinsfile 不再使用环境变量定义 git地址 ->避免改来改去 2 weeks ago
lucas c681f9e48e update 更新 最新 郑州旭宸 -司南gnss 上报 2 weeks ago
lucas 6d979cbe2c update gnss上报 优化处理 2 weeks ago
lucas 0ef19cf4f9 update 添加gnss 数据获取 2 weeks ago
lucas 0082f882ca update 更新 异常设备数据 添加errMsg 数据信息 1 month ago
lucas 35ad2d7295 update 取消非正常数据过滤 1 month ago
lucas 04e3f32654 update 添加指定设备日志 追踪 1 month ago
lucas 4f452dbfcd update 强制使用 8 时区 转换 1 month ago
lucas 4b8f5921f5 update 更新 raw 2 months ago
lucas dd1a3397e2 update 调整文件 2 months ago
lucas 3e0cd261e6 update 添加data=nil保护 2 months ago
lucas e586dbab16 update 通用化反序列对象 2 months ago
lucas 9067faeb58 update 支持多路由处理 2 months ago
lucas 507dc26e61 fix url追加问题 2 months ago
lucas da5078826c update 默认转发路由 沿用原有请求路由地址 2 months ago
lucas f3f164a36a Merge branch 'dev' of https://gitea.anxinyun.cn/lucas2/goUpload into dev 2 months ago
lucas bb15e9b7f9 update 添加 安全带状态数据转发处理 2 months ago
lucas 68b672cfcd update 版本默认采用go 1.22 增强路由 2 months ago
lucas c58ff60910 update collectTime -》 string 2 months ago
lucas 995aa2e415 update 修改CollectTime格式 2 months ago
lucas e5ea7a485a fix 日志中的返回信息 2 months ago
lucas 1e187bfdff update 添加过滤 诊断类数据 去除Meta为空的非数据 2 months ago
lucas 5c95f682a5 update 添加 es 写入返回纪录 2 months ago
lucas 0d195cb3a0 update 添加 es写入语句 指定 log打印 2 months ago
lucas 189692eade update 添加无设备信息日志 2 months ago
lucas e7c1fbec68 update 添加es 最新数据的指定设备的排查log 2 months ago
lucas cdcc7ddc28 update 保护字符截取边界 2 months ago
lucas 72d18dde47 update 振动数据处理 添加 振动转索力 支持 2 months ago
lucas 7b38baa228 update 添加光电挠度数据处理 2 months ago
lucas becd732f62 update 添加 光电扰度转路安to江苏省农村公路桥梁监测 的协议处理部分 2 months ago
lucas 14509000d6 update 修改数据输出 2 months ago
lucas 30316c6d6f update 添加bridgeCode 和 重命名 2 months ago
lucas be231c81bb update 添加 振动加速度上报 2 months ago
lucas 6c02504ccd update 倾斜数据处理 2 months ago
lucas bc2e575067 update 添加江苏质感的测试用例 修改数据大小端转换 2 months ago
lucas de9a85cfa0 update 使用异步sync.map 2 months ago
lucas b29428e567 update 更新功能说明 2 months ago
lucas d589c16790 update 添加redis 查询不到的保护处理 2 months ago
lucas 9ec508c38b update 更新 yaml 名称 2 months ago
lucas 86fda6ed1c update 添加 设备信息缓存 2 months ago
lucas 23d196993f clean 清理 无用配置 2 months ago
lucas 4a8f314727 更新 项目包名称为 goInOut 2 months ago
lucas 5dc6916de9 update 更新最新数据存储部分,默认定时30s存储数据 2 months ago
lucas 225129594a update 更新安心云最新设备数据 获取 2 months ago
lucas e59c21c27d update 匹配加上 通道 pos 3 months ago
lucas 93c974bddb update 更新 jenkinsfile_image 3 months ago
lucas 0592ec7e07 add app 3 months ago
lucas2 d42506f9a1 Merge pull request 'update jenkinsfile' (#1) from master into dev 3 months ago
  1. 1
      .gitignore
  2. 16
      README.md
  3. 4
      adaptors/光电光栅中科to明月峡.go
  4. 84
      adaptors/光电扰度转路安to江苏省农村公路桥梁监测.go
  5. 47
      adaptors/司南GNSS_MySql库to安心云.go
  6. 2
      adaptors/安心云es主题to河北矿山监测.go
  7. 148
      adaptors/安心云最新设备数据toES.go
  8. 4
      adaptors/振动to明月峡.go
  9. 132
      adaptors/振动to江苏省农村公路桥梁监测.go
  10. 2
      adaptors/振动to湘潭健康监测.go
  11. 6
      adaptors/振动to重庆资管.go
  12. 6
      adaptors/欧乐称重to重庆资管.go
  13. 4
      adaptors/知物云主题数据to广州高支模省平台.go
  14. 2
      adaptors/统一采集to明月峡.go
  15. 38
      adaptors/统一采集to江苏省农村公路桥梁监测.go
  16. 2
      adaptors/统一采集to湘潭健康监测.go
  17. 6
      adaptors/统一采集to重庆资管.go
  18. 5
      adaptors/视觉位移to魏家滑坡.go
  19. 2
      build/Dockerfile
  20. 4
      build/Dockerfile_app
  21. 16
      build/go_inout.yaml
  22. 6
      build/jenkinsfile
  23. 36
      build/jenkinsfile_image
  24. 24
      config/configStruct.go
  25. 17
      config/init.go
  26. 24
      configFiles/config_司南GnssMySQL.json
  27. 36
      configFiles/弃用备份/config_安心云设备数据_最新同步.json
  28. 2
      configFiles/弃用备份/config_承德金隅水泥_河北矿山_大斜阳.json
  29. 35
      configFiles/弃用备份/config_江苏农村公路桥梁.json
  30. 30
      configFiles/弃用备份/config_转发http2axy60000端口.json
  31. 0
      configFiles/弃用备份/config_魏家滑坡_视觉位移.json
  32. 1
      constKey/key.go
  33. 31
      consumers/AXYraw/config.go
  34. 2
      consumers/CDJYSN/config.go
  35. 2
      consumers/CQZG/config.go
  36. 2
      consumers/GZGZM/config.go
  37. 2
      consumers/HTJC/config.go
  38. 25
      consumers/HTTP_PRPXY/config.go
  39. 44
      consumers/HTTP_PRPXY/dataModel.go
  40. 9
      consumers/JSNCGLQL/config.go
  41. 2
      consumers/MYX/config.go
  42. 27
      consumers/SinoGnssMySQL/config.go
  43. 28
      consumers/SinoGnssMySQL/dataModel.go
  44. 2
      consumers/WJHP/config.go
  45. 162
      consumers/consumerAXYraw.go
  46. 18
      consumers/consumerCDJYSN.go
  47. 14
      consumers/consumerCQZG.go
  48. 14
      consumers/consumerGZGZM.go
  49. 14
      consumers/consumerHTJC.go
  50. 102
      consumers/consumerHTTP_PRPXY.go
  51. 33
      consumers/consumerJSNCGLQL.go
  52. 16
      consumers/consumerMYX.go
  53. 12
      consumers/consumerManage.go
  54. 174
      consumers/consumerSinoGnssMySQL.go
  55. 18
      consumers/consumerWJHP.go
  56. 38
      dbHelper/apiServer.go
  57. 4
      dbOperate/_kafka/consumerGroupHandler.go
  58. 0
      dbOperate/_kafka/kafkaHelper.go
  59. 0
      dbOperate/_kafka/kafka_test.go
  60. 0
      dbOperate/_kafka/producerHelper.go
  61. 58
      dbOperate/apiServerHelper.go
  62. 101
      dbOperate/dbHelper.go
  63. 37
      dbOperate/db_test.go
  64. 269
      dbOperate/elasticsearchHelper.go
  65. 2
      dbOperate/fileSaveHelper.go
  66. 45
      dbOperate/httpHelper.go
  67. 4
      dbOperate/influxDBHelper.go
  68. 11
      dbOperate/mqttHelper.go
  69. 133
      dbOperate/redisHelper.go
  70. 2
      dbOperate/udpHelper.go
  71. 37
      go.mod
  72. 91
      go.sum
  73. 18
      logs/logInfo.log
  74. 5
      main.go
  75. 25
      main_test.go
  76. 7
      models/GDND2LA.go
  77. 40
      models/IotaData.go
  78. 6
      models/aggWay.go
  79. 6
      models/constant.go
  80. 107
      models/deviceData.go
  81. 70
      models/deviceInfo.go
  82. 37
      models/esRaw.go
  83. 41
      models/esTheme.go
  84. 25
      models/iotaDevice.go
  85. 8
      models/savoirTheme.go
  86. 31
      models/structure.go
  87. 14
      monitors/commonMonitor.go
  88. 4
      monitors/httpMonitor.go
  89. 6
      testUnit/mqttPush_test.go
  90. 4
      testUnit/mqttRecv_test.go
  91. 4
      testUnit/udpPush_test.go
  92. 80
      testUnit/安心云http转发_test.go
  93. 82
      testUnit/江苏智感测试_test.go
  94. 2
      testUnit/湘潭监测测试_test.go
  95. 53
      utils/cacheFile.go
  96. 22
      utils/textTemplateHandler.go
  97. 2
      utils/valueHelper.go

1
.gitignore

@ -0,0 +1 @@
/logs/

16
README.md

@ -1,19 +1,21 @@
# goUpload # goInOut
## 功能说明: ## 功能说明:
功能:用于设备采集数据上报第三方。 功能:用于数据的输入输出处理,可应对各中数据处理场景,典型的设备采集数据上报第三方。
数据入口->各类本地采集软件 数据入口->各类本地采集软件
数据出口->各类第三方数据接口 数据出口->各类第三方数据接口
部署环境:用于windows环境 部署环境:用于windows环境或k8s 镜像部署
## 启用配置: ## 启用配置:
goUpload.exe + configFiles目录下的json配置 app.exe + configFiles目录下的json配置
(configFiles目录下有几个配置就会生效几个功能,实际部署时,不相干的项目配置不要放进去) (configFiles目录下有几个配置就会生效几个功能,实际部署时,不相干的项目配置不要放进去)
支持-软件列表: 支持-软件列表:
-------------------- --------------------
**统一采集软件** **统一采集软件_mqtt**
**DAAS振动软件** **DAAS振动软件_mqtt**
**称重软件** **称重软件_mqtt**
**中科-光电txt** **中科-光电txt**
**kafka**

4
adaptors/光电光栅中科to明月峡.go

@ -3,8 +3,8 @@ package adaptors
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"goUpload/consumers/MYX" "goInOut/consumers/MYX"
"goUpload/utils" "goInOut/utils"
"log" "log"
"strconv" "strconv"
"strings" "strings"

84
adaptors/光电扰度转路安to江苏省农村公路桥梁监测.go

@ -0,0 +1,84 @@
package adaptors
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"goInOut/models"
"goInOut/utils"
"log"
"time"
)
// Adaptor_GDND2LA_JSNCGLQL 光电挠度2路安数据 转换 江苏农村公路桥梁监测系统
type Adaptor_GDND2LA_JSNCGLQL struct {
IdMap map[string]string
BridgeCode string
}
func (the Adaptor_GDND2LA_JSNCGLQL) Transform(inTopic, rawMsg string) []NeedPush {
gdnd := models.GDND2luAn{}
json.Unmarshal([]byte(rawMsg), &gdnd)
return the.RawToJSNCGLQL(gdnd)
}
func (the Adaptor_GDND2LA_JSNCGLQL) RawToJSNCGLQL(raw models.GDND2luAn) (result []NeedPush) {
Atime, err := time.Parse("2006-01-02 15:04:05", raw.Time)
if err != nil {
log.Printf("光电扰度 设备[%s] 数据时间 %s 解析错误", raw.Id, raw.Time)
return
}
sensorDataList := raw.Value[raw.Id]
//获取对方系统 id
sensorCode := the.getSensorCode(raw.Id)
if sensorCode == "" {
log.Printf("光电扰度 设备[%s] 无匹配的 江苏农村公路桥梁监测系统 测点id,请检查配置文件", raw.Id)
return
}
topic := fmt.Sprintf("data/%s/%s", the.BridgeCode, sensorCode)
var transBytes []byte
//添加时间段
transBytes = append(transBytes, the.getTimeBytes(Atime)...)
for _, sensorData := range sensorDataList {
//添加数据值段
bs := utils.Float32ToBytes(sensorData)
transBytes = append(transBytes, bs...)
}
result = append(result, NeedPush{
Topic: topic,
Payload: transBytes,
})
return result
}
func (the Adaptor_GDND2LA_JSNCGLQL) getSensorCode(rawSensorName string) string {
v, isValid := the.IdMap[rawSensorName]
if !isValid {
v = ""
}
return v
}
func (the Adaptor_GDND2LA_JSNCGLQL) getTimeBytes(sensorTime time.Time) []byte {
year := uint16(sensorTime.Year())
month := int8(sensorTime.Month())
day := int8(sensorTime.Day())
hour := int8(sensorTime.Hour())
minute := int8(sensorTime.Minute())
second := int8(sensorTime.Second())
bytesBuffer := bytes.NewBuffer([]byte{})
binary.Write(bytesBuffer, binary.BigEndian, year)
binary.Write(bytesBuffer, binary.BigEndian, month)
binary.Write(bytesBuffer, binary.BigEndian, day)
binary.Write(bytesBuffer, binary.BigEndian, hour)
binary.Write(bytesBuffer, binary.BigEndian, minute)
binary.Write(bytesBuffer, binary.BigEndian, second)
return bytesBuffer.Bytes()
}

47
adaptors/司南GNSS_MySql库to安心云.go

@ -0,0 +1,47 @@
package adaptors
import (
"encoding/json"
"fmt"
"goInOut/consumers/SinoGnssMySQL"
"strconv"
)
// Adaptor_SINOMYSQL_AXYMQTT 数据 转换 江苏农村公路桥梁监测系统
type Adaptor_SINOMYSQL_AXYMQTT struct {
}
func (the Adaptor_SINOMYSQL_AXYMQTT) Transform(gnssDataList []SinoGnssMySQL.GnssData) []NeedPush {
var needPush []NeedPush
allDxFiles := make(map[string][]SinoGnssMySQL.DxFile)
for _, gnssData := range gnssDataList {
OnceDxFiles := allDxFiles[gnssData.GroupName]
OnceDxFiles = append(OnceDxFiles, SinoGnssMySQL.DxFile{
Module: gnssData.StationName,
Channel: 1,
Timespan: gnssData.Time.UnixMilli(),
//file_mqtt协议里面只解析RV, m=> mm
RawValue: []float64{gnssData.X * 1000, gnssData.Y * 1000, gnssData.H * 1000},
LimitValue: []float64{},
PhyValue: []float64{},
ThemeValue: []float64{},
})
allDxFiles[gnssData.GroupName] = OnceDxFiles
}
for groupName, groupFileList := range allDxFiles {
contentMap := make(map[string]string)
for i, file := range groupFileList {
bs, _ := json.Marshal(file)
contentMap[strconv.Itoa(i)] = string(bs)
}
gpContent, _ := json.Marshal(contentMap)
topic := fmt.Sprintf("SinoGnss/%s/", groupName)
needPush = append(needPush, NeedPush{
Topic: topic,
Payload: gpContent,
})
}
return needPush
}

2
adaptors/安心云es主题to河北矿山监测.go

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"goUpload/models" "goInOut/models"
"log" "log"
"math" "math"
"strings" "strings"

148
adaptors/安心云最新设备数据toES.go

@ -0,0 +1,148 @@
package adaptors
import (
"encoding/json"
"fmt"
"goInOut/consumers/AXYraw"
"goInOut/dbOperate"
"goInOut/models"
"log"
"sync"
"time"
)
// Adaptor_AXY_LastRAW 安心云 kafka iota数据 转换 es设备数据
type Adaptor_AXY_LastRAW struct {
AXYraw.Info
Redis *dbOperate.RedisHelper
}
func (the Adaptor_AXY_LastRAW) Transform(topic, rawMsg string) *models.EsRaw {
iotaData := models.IotaData{}
json.Unmarshal([]byte(rawMsg), &iotaData)
return the.raw2es(iotaData)
}
func (the Adaptor_AXY_LastRAW) raw2es(iotaData models.IotaData) *models.EsRaw {
if len(iotaData.Data.Data) == 0 {
return nil
}
if !iotaData.Data.Success() {
msg, _ := json.Marshal(iotaData.Data.Result)
iotaData.Data.Data["errMsg"] = string(msg)
}
//log.Printf("设备[%s] 数据时间 %s", iotaData.DeviceId, iotaData.TriggerTime)
deviceInfo := the.GetDeviceInfo(iotaData.DeviceId)
//查不到信息的数据
if deviceInfo.Name == "" {
log.Printf("设备[%s] 无deviceInfo信息 %s", iotaData.DeviceId, iotaData.TriggerTime)
return nil
}
dataType := ""
if _dataType, ok := iotaData.Data.Data["_data_type"]; ok {
if v, ok := _dataType.(string); ok {
dataType = v
}
}
devdata := &models.DeviceData{
DeviceId: iotaData.DeviceId,
Name: deviceInfo.Name,
ThingId: iotaData.ThingId,
StructId: deviceInfo.Structure.Id,
AcqTime: iotaData.TriggerTime,
RealTime: iotaData.RealTime,
ErrCode: 0,
Raw: iotaData.Data.Data,
DeviceInfo: deviceInfo,
DimensionId: iotaData.DimensionId,
DataType: dataType,
}
EsRaws := toEsRaw(devdata)
return EsRaws
}
var deviceInfoMap = map[string]models.DeviceInfo{}
var deviceInfoMap2 = sync.Map{}
func (the Adaptor_AXY_LastRAW) GetDeviceInfo(deviceId string) models.DeviceInfo {
if vObj, ok := deviceInfoMap2.Load(deviceId); ok {
if v, ok := vObj.(models.DeviceInfo); ok {
durationMin := time.Now().Sub(v.RefreshTime).Minutes()
if durationMin < 5 {
return v
}
}
}
v, err := the.GetDeviceInfoFromRedis(deviceId)
if err != nil {
log.Printf("设备%s 无法查询到对应信息", deviceId)
}
//deviceInfoMap[deviceId] = v
deviceInfoMap2.Store(deviceId, v)
return v
}
func (the Adaptor_AXY_LastRAW) GetDeviceInfoFromRedis(deviceId string) (models.DeviceInfo, error) {
Key_Iota_device := "iota_device"
key_Thing_struct := "thing_struct"
key_Iota_meta := "iota_meta"
k1 := fmt.Sprintf("%s:%s", Key_Iota_device, deviceId)
dev := models.IotaDevice{}
thingStruct := models.ThingStruct{}
devMeta := models.DeviceMeta{}
err1 := the.Redis.GetObj(k1, &dev)
if err1 != nil {
return models.DeviceInfo{RefreshTime: time.Now()}, err1
}
k2 := fmt.Sprintf("%s:%s", key_Thing_struct, dev.ThingId)
err2 := the.Redis.GetObj(k2, &thingStruct)
if err2 != nil {
return models.DeviceInfo{RefreshTime: time.Now()}, err2
}
k3 := fmt.Sprintf("%s:%s", key_Iota_meta, dev.DeviceMeta.Id)
err3 := the.Redis.GetObj(k3, &devMeta)
if err3 != nil {
return models.DeviceInfo{RefreshTime: time.Now()}, err3
}
//if err1 != nil || err2 != nil || err3 != nil {
// log.Printf("redis读取异常,err1=%s, err2=%s, err3=%s", err1, err2, err3)
// return models.DeviceInfo{}
//}
s := models.Structure{
ThingId: thingStruct.ThingId,
Id: thingStruct.Id,
Name: thingStruct.Name,
OrgId: thingStruct.OrgId,
}
return models.DeviceInfo{
Id: deviceId,
Name: dev.Name,
Structure: s,
DeviceMeta: devMeta,
RefreshTime: time.Now(),
}, nil
}
func toEsRaw(deviceData *models.DeviceData) *models.EsRaw {
if deviceData == nil {
return nil
}
var cstZone = time.FixedZone("CST", 8*3600) // 东八区 用以解决
dataOutMeta := deviceData.DeviceInfo.DeviceMeta.GetOutputProps()
createNativeRaw := models.EsRaw{
StructId: deviceData.StructId,
IotaDeviceName: deviceData.Name,
Data: deviceData.Raw,
CollectTime: deviceData.AcqTime.In(cstZone).Format("2006-01-02T15:04:05.000+0800"),
Meta: dataOutMeta,
IotaDevice: deviceData.DeviceId,
CreateTime: time.Now(),
}
return &createNativeRaw
}

4
adaptors/振动to明月峡.go

@ -3,8 +3,8 @@ package adaptors
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"goUpload/models" "goInOut/models"
"goUpload/utils" "goInOut/utils"
"log" "log"
"strings" "strings"
"time" "time"

132
adaptors/振动to江苏省农村公路桥梁监测.go

@ -0,0 +1,132 @@
package adaptors
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"goInOut/models"
"goInOut/utils"
"log"
"strconv"
"strings"
"time"
)
// Adaptor_ZD_JSNCGLQL 数据 转换 江苏农村公路桥梁监测系统
type Adaptor_ZD_JSNCGLQL struct {
IdMap map[string]string
BridgeCode string
}
func (the Adaptor_ZD_JSNCGLQL) Transform(inTopic, rawMsg string) []NeedPush {
zd := models.ZD{}
err := json.Unmarshal([]byte(rawMsg), &zd)
if err != nil {
return nil
}
lowerTopic := strings.ToLower(inTopic)
if strings.Contains(lowerTopic, "zdsl") ||
strings.Contains(lowerTopic, "cableforce") {
return the.ZDSLtoJSNCGLQL(zd)
}
return the.ZDtoJSNCGLQL(zd)
}
func (the Adaptor_ZD_JSNCGLQL) ZDtoJSNCGLQL(zd models.ZD) (result []NeedPush) {
Atime := time.UnixMilli(zd.Ticks)
sensorDataList := zd.AccValues
//获取对方系统 id
sensorCode := the.getSensorCode(zd.Module)
if sensorCode == "" {
log.Printf("振动 设备[%s] 无匹配的 江苏农村公路桥梁监测系统 测点id,请检查配置文件", zd.Module)
return
}
topic := fmt.Sprintf("data/%s/%s", the.BridgeCode, sensorCode)
//数据秒数
seconds := len(zd.AccValues) / zd.Frequency
for i := 0; i < seconds; i++ {
var transBytes []byte
onceTime := Atime.Add(time.Duration(i) * time.Second)
//1.添加时间段
transBytes = append(transBytes, the.getTimeBytes(onceTime)...)
startIndex := (0 + i) * zd.Frequency
endIndex := (1 + i) * zd.Frequency
if endIndex > len(sensorDataList) {
endIndex = len(sensorDataList)
}
subDataList := sensorDataList[startIndex:endIndex]
for _, sensorData := range subDataList {
//4.添加数据值段
bs := utils.Float32ToBytes(sensorData)
transBytes = append(transBytes, bs...)
}
result = append(result, NeedPush{
Topic: topic,
Payload: transBytes,
})
}
return result
}
func (the Adaptor_ZD_JSNCGLQL) ZDSLtoJSNCGLQL(zd models.ZD) (result []NeedPush) {
Atime := time.UnixMilli(zd.Ticks)
sensorDataList := zd.ThemeValue
//获取对方系统 id
sensorCode := the.getSensorCode(strconv.Itoa(zd.SensorId))
if sensorCode == "" {
log.Printf("振动索力 设备[%s] 无匹配的 江苏农村公路桥梁监测系统 测点id,请检查配置文件", zd.Module)
return
}
topic := fmt.Sprintf("data/%s/%s", the.BridgeCode, sensorCode)
var transBytes []byte
//1.添加时间段
transBytes = append(transBytes, the.getTimeBytes(Atime)...)
//数据值段
bs := utils.Float32ToBytes(sensorDataList[0])
transBytes = append(transBytes, bs...)
result = append(result, NeedPush{
Topic: topic,
Payload: transBytes,
})
return result
}
func (the Adaptor_ZD_JSNCGLQL) getSensorCode(rawSensorName string) string {
v, isValid := the.IdMap[rawSensorName]
if !isValid {
v = ""
}
return v
}
func (the Adaptor_ZD_JSNCGLQL) getTimeBytes(sensorTime time.Time) []byte {
year := uint16(sensorTime.Year())
month := int8(sensorTime.Month())
day := int8(sensorTime.Day())
hour := int8(sensorTime.Hour())
minute := int8(sensorTime.Minute())
second := int8(sensorTime.Second())
bytesBuffer := bytes.NewBuffer([]byte{})
binary.Write(bytesBuffer, binary.BigEndian, year)
binary.Write(bytesBuffer, binary.BigEndian, month)
binary.Write(bytesBuffer, binary.BigEndian, day)
binary.Write(bytesBuffer, binary.BigEndian, hour)
binary.Write(bytesBuffer, binary.BigEndian, minute)
binary.Write(bytesBuffer, binary.BigEndian, second)
return bytesBuffer.Bytes()
}

2
adaptors/振动to湘潭健康监测.go

@ -2,7 +2,7 @@ package adaptors
import ( import (
"encoding/json" "encoding/json"
"goUpload/models" "goInOut/models"
"log" "log"
"math" "math"
"time" "time"

6
adaptors/振动to重庆资管.go

@ -3,9 +3,9 @@ package adaptors
import ( import (
"crypto/rc4" "crypto/rc4"
"encoding/json" "encoding/json"
"goUpload/consumers/CQZG/protoFiles" "goInOut/consumers/CQZG/protoFiles"
"goUpload/models" "goInOut/models"
"goUpload/utils" "goInOut/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"log" "log"
) )

6
adaptors/欧乐称重to重庆资管.go

@ -4,9 +4,9 @@ import (
"crypto/rc4" "crypto/rc4"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"goUpload/consumers/CQZG/protoFiles" "goInOut/consumers/CQZG/protoFiles"
"goUpload/models" "goInOut/models"
"goUpload/utils" "goInOut/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"log" "log"
"strconv" "strconv"

4
adaptors/知物云主题数据to广州高支模省平台.go

@ -3,8 +3,8 @@ package adaptors
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"goUpload/consumers/GZGZM" "goInOut/consumers/GZGZM"
"goUpload/models" "goInOut/models"
"log" "log"
"math" "math"
"strconv" "strconv"

2
adaptors/统一采集to明月峡.go

@ -3,7 +3,7 @@ package adaptors
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"goUpload/models" "goInOut/models"
"log" "log"
"strings" "strings"
"time" "time"

38
adaptors/统一采集to江苏省农村公路桥梁监测.go

@ -1,20 +1,23 @@
package adaptors package adaptors
import ( import (
"bytes"
"encoding/binary"
"encoding/json" "encoding/json"
"fmt" "fmt"
"goUpload/models" "goInOut/models"
"goUpload/utils" "goInOut/utils"
"log" "log"
"time" "time"
) )
// Adaptor_TYCJ_JSNCGLQL 统一采集软件数据 转换 江苏农村公路桥梁监测系统 // Adaptor_TYCJ_JSNCGLQL 数据 转换 江苏农村公路桥梁监测系统
type Adaptor_TYCJ_JSNCGLQL struct { type Adaptor_TYCJ_JSNCGLQL struct {
IdMap map[string]string IdMap map[string]string
BridgeCode string
} }
func (the Adaptor_TYCJ_JSNCGLQL) Transform(rawMsg string) []NeedPush { func (the Adaptor_TYCJ_JSNCGLQL) Transform(inTopic, rawMsg string) []NeedPush {
tycj := models.TYCJ{} tycj := models.TYCJ{}
json.Unmarshal([]byte(rawMsg), &tycj) json.Unmarshal([]byte(rawMsg), &tycj)
return the.TYCJtoJSNCGLQL(tycj) return the.TYCJtoJSNCGLQL(tycj)
@ -47,13 +50,12 @@ func (the Adaptor_TYCJ_JSNCGLQL) TYCJtoJSNCGLQL(tycj models.TYCJ) (result []Need
log.Printf("统一采集 设备[%s] 无匹配的 江苏农村公路桥梁监测系统 测点id,请检查配置文件", tycj.SensorData.Name) log.Printf("统一采集 设备[%s] 无匹配的 江苏农村公路桥梁监测系统 测点id,请检查配置文件", tycj.SensorData.Name)
return return
} }
//todo 桥梁编码
bridgeCode := sensorCode topic := fmt.Sprintf("data/%s/%s", the.BridgeCode, sensorCode)
topic := fmt.Sprintf("data/%s/%s", bridgeCode, sensorCode)
for _, sensorData := range sensorDataList { for _, sensorData := range sensorDataList {
//4.添加数据值段 //添加数据值段
bs := utils.Float32ToBytes(sensorData) bs := utils.Float32ToBytes(sensorData)
transBytes = append(transBytes, bs...) transBytes = append(transBytes, bs...)
} }
@ -80,14 +82,12 @@ func (the Adaptor_TYCJ_JSNCGLQL) getTimeBytes(sensorTime time.Time) []byte {
hour := int8(sensorTime.Hour()) hour := int8(sensorTime.Hour())
minute := int8(sensorTime.Minute()) minute := int8(sensorTime.Minute())
second := int8(sensorTime.Second()) second := int8(sensorTime.Second())
bytes := make([]byte, 0) bytesBuffer := bytes.NewBuffer([]byte{})
bytes = append(bytes, binary.Write(bytesBuffer, binary.BigEndian, year)
byte(year), binary.Write(bytesBuffer, binary.BigEndian, month)
byte(month), binary.Write(bytesBuffer, binary.BigEndian, day)
byte(day), binary.Write(bytesBuffer, binary.BigEndian, hour)
byte(hour), binary.Write(bytesBuffer, binary.BigEndian, minute)
byte(minute), binary.Write(bytesBuffer, binary.BigEndian, second)
byte(second), return bytesBuffer.Bytes()
)
return bytes
} }

2
adaptors/统一采集to湘潭健康监测.go

@ -3,7 +3,7 @@ package adaptors
import ( import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"goUpload/models" "goInOut/models"
"log" "log"
"math" "math"
"time" "time"

6
adaptors/统一采集to重庆资管.go

@ -4,9 +4,9 @@ import (
"crypto/rc4" "crypto/rc4"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"goUpload/consumers/CQZG/protoFiles" "goInOut/consumers/CQZG/protoFiles"
"goUpload/models" "goInOut/models"
"goUpload/utils" "goInOut/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"log" "log"
"time" "time"

5
adaptors/视觉位移to魏家滑坡.go

@ -3,7 +3,7 @@ package adaptors
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"goUpload/consumers/WJHP" "goInOut/consumers/WJHP"
"log" "log"
"strconv" "strconv"
"time" "time"
@ -25,7 +25,8 @@ func (the Adaptor_SJWY_WJHP) GDRDtoUpload(devModule, rawRecords string) (result
return nil return nil
} }
sensorInfo := the.matchStationId(devModule) devId := fmt.Sprintf("%s-%s", devModule, d.Pos)
sensorInfo := the.matchStationId(devId)
if sensorInfo.StationId == 0 { if sensorInfo.StationId == 0 {
return nil return nil
} }

2
build/Dockerfile

@ -8,7 +8,7 @@ RUN go env -w GO111MODULE=on
RUN CGO_ENABLED=0 go build -a -v -o app.exe main.go RUN CGO_ENABLED=0 go build -a -v -o app.exe main.go
FROM registry.ngaiot.com/base-images/golang:1.20-fs-10 FROM registry.ngaiot.com/base-images/alpine_3.20_cst:7
WORKDIR /app/ WORKDIR /app/
COPY --from=0 /app/app.exe /app COPY --from=0 /app/app.exe /app
COPY --from=0 /app/configFiles /app COPY --from=0 /app/configFiles /app

4
build/Dockerfile_app

@ -0,0 +1,4 @@
FROM registry.ngaiot.com/base-images/alpine_3.20_cst:7
WORKDIR /app/
COPY *.exe configFiles /app/
CMD ["/app/app.exe"]

16
build/goupload.yaml → build/go_inout.yaml

@ -1,23 +1,23 @@
apiVersion: apps/v1 #指定API版本标签 apiVersion: apps/v1 #指定API版本标签
kind: Deployment #定义资源的类型/角色,deployment为控制器,service,endpoints kind: Deployment #定义资源的类型/角色,deployment为控制器,service,endpoints
metadata: #定义资源的元数据信息 metadata: #定义资源的元数据信息
name: goupload-deployment #定义资源的名称,在同一个namespace空间中必须是唯一的 name: goinout-deployment #定义资源的名称,在同一个namespace空间中必须是唯一的
namespace: lk #默认default namespace: lk #默认default
labels: #定义资源标签 labels: #定义资源标签
app: yaml-goupload-d app: yaml-goinout-d
spec: spec:
replicas: 1 #定义副本数量 replicas: 1 #定义副本数量
selector: #定义选择器 selector: #定义选择器
matchLabels: #匹配上边的标签 matchLabels: #匹配上边的标签
app: yaml-goupload-d #名称 app: yaml-goinout-d #名称
template: #定义模板 template: #定义模板
metadata: metadata:
labels: labels:
app: yaml-goupload-d app: yaml-goinout-d
spec: spec:
containers: containers:
- name: yaml-goupload #容器名,与标签名要相同 - name: yaml-goinout #容器名,与标签名要相同
image: registry.ngaiot.com/local/git-goupload-image:12 image: registry.ngaiot.com/local/in-out-image:24
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
volumeMounts: volumeMounts:
- name: config - name: config
@ -26,14 +26,14 @@ spec:
volumes: # volumes和container处于同一层级,别搞错了 volumes: # volumes和container处于同一层级,别搞错了
- name: config - name: config
configMap: configMap:
name: config-goupload name: config-goinout
--- ---
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: config-goupload name: config-goinout
namespace: lk namespace: lk
data: #监测因素 统计字段表 data: #监测因素 统计字段表
config.json: | config.json: |

6
build/jenkinsfile

@ -3,12 +3,12 @@ podTemplate {
env.IMAGE_NAME = "${IOT_IMAGES_REGISTRY}/${LOCAL}/${JOB_NAME}" env.IMAGE_NAME = "${IOT_IMAGES_REGISTRY}/${LOCAL}/${JOB_NAME}"
env.IMAGE_NAME_SHORT = "${LOCAL}/${JOB_NAME}" env.IMAGE_NAME_SHORT = "${LOCAL}/${JOB_NAME}"
env.CODE_ADDR = "${GIT_ADDRESS}/DevOps/goUpload.git" env.CODE_ADDR = "https://gitea.anxinyun.cn/lucas2/goInOut.git"
stage('Run shell') { stage('Run shell') {
git branch: 'develop', credentialsId: 'gitea-builder', url: "${CODE_ADDR}" git branch: 'dev', credentialsId: 'gitea-builder', url: "${CODE_ADDR}"
container('golang-builder-1-22') { container('golang-builder-1-23') {
sh''' sh'''
go env -w GOPROXY=https://goproxy.cn,direct go env -w GOPROXY=https://goproxy.cn,direct
go env -w GO111MODULE=on go env -w GO111MODULE=on

36
build/jenkinsfile_image

@ -1,24 +1,40 @@
podTemplate { podTemplate {
node('pod-templ-jenkins-slave-golang') { node('pod-templ-jenkins-slave-golang') {
env.IMAGE_NAME = "${IOT_IMAGES_REGISTRY}/${LOCAL}/${JOB_NAME}" env.IMAGE_NAME = "${IOT_IMAGES_REGISTRY}/${LOCAL}/${JOB_NAME}"
env.IMAGE_NAME_SHORT = "${LOCAL}/${JOB_NAME}" env.IMAGE_NAME_SHORT = "${LOCAL}/${JOB_NAME}"
env.CODE_ADDR = "https://gitea.anxinyun.cn/lucas2/goUpload.git" env.CODE_ADDR = "https://gitea.anxinyun.cn/lucas2/goUpload.git"
stage('Run shell') { stage('Run shell') {
git branch: 'dev', credentialsId: 'gitea-builder', url: "${CODE_ADDR}" git branch: 'dev', credentialsId: 'gitea-builder', url: "${CODE_ADDR}"
container('golang-builder-1-23') { container('golang-builder-1-23') {
sh''' sh'''
echo "当前目===" git version
pwd git config --global --add url."https://builder:Fs7595!EAT@gitea.anxinyun.cn/".insteadOf "https://gitea.anxinyun.cn/"
ls unset GOPROXY
echo "========" go env -w GOPROXY=https://goproxy.cn,direct
/kaniko/executor --context=${BUILD_WORKSPACE} --dockerfile=build/Dockerfile --destination=${IMAGE_NAME}:${IMAGE_VERSION} --cache=false --cleanup go env -w GO111MODULE=on
go env -w GOPRIVATE=gitea.ngaiot.com,gitea.anxinyun.cn
go env -w GOSUMDB=sum.golang.org
go env
go build -a -v -o app.exe main.go
tar -cvf app.tar *.exe configFiles
''' '''
} }
container('image-builder') {
sh'''
echo "当前目==="
pwd
ls
echo "========"
/kaniko/executor --context=${BUILD_WORKSPACE} --dockerfile=build/Dockerfile_app --destination=${IMAGE_NAME}:${IMAGE_VERSION} --cache=false --cleanup
'''
}
archiveArtifacts artifacts: 'app.tar', followSymlinks: false
buildName "${IMAGE_NAME_SHORT}:${IMAGE_VERSION}" buildName "${IMAGE_NAME_SHORT}:${IMAGE_VERSION}"
buildDescription "${IMAGE_NAME}:${IMAGE_VERSION}" buildDescription "${IMAGE_NAME}:${IMAGE_VERSION}"
} }
} }
} }

24
config/configStruct.go

@ -4,6 +4,11 @@ type Consumer struct {
Consumer string `json:"consumer"` Consumer string `json:"consumer"`
} }
type DbConfig struct {
Type string `json:"type"`
ConnStr string `json:"connStr"`
}
type MqttConfig struct { type MqttConfig struct {
Host string `json:"host"` Host string `json:"host"`
Port int `json:"port"` Port int `json:"port"`
@ -18,6 +23,16 @@ type KafkaConfig struct {
Topics []string `json:"topics"` Topics []string `json:"topics"`
} }
type EsConfig struct {
Address []string `json:"address"`
Index string `json:"index"`
Auth struct {
UserName string `json:"userName"`
Password string `json:"password"`
} `json:"auth"`
Interval int `json:"interval"`
}
type UdpConfig struct { type UdpConfig struct {
Host string `json:"host"` Host string `json:"host"`
Port int `json:"port"` Port int `json:"port"`
@ -29,6 +44,15 @@ type HttpConfig struct {
Token Token `json:"token,omitempty"` Token Token `json:"token,omitempty"`
} }
type ApiServerConfig struct {
Port uint `json:"port"`
Routers []Router `json:"routers"`
}
type Router struct {
Router string `json:"router"`
IdTemplate string `json:"idTemplate"`
}
type Token struct { type Token struct {
Static string `json:"static,omitempty"` Static string `json:"static,omitempty"`
RefreshInterval string `json:"refreshInterval,omitempty"` RefreshInterval string `json:"refreshInterval,omitempty"`

17
config/init.go

@ -8,7 +8,6 @@ import (
) )
func LoadConfigJson() map[string]string { func LoadConfigJson() map[string]string {
//加载目录下所有文件
allConfig := make(map[string]string) allConfig := make(map[string]string)
files, err := os.ReadDir("configFiles") files, err := os.ReadDir("configFiles")
@ -22,24 +21,16 @@ func LoadConfigJson() map[string]string {
log.Printf("非文件[%s]跳过", file.Name()) log.Printf("非文件[%s]跳过", file.Name())
continue continue
} }
// 读取mqtt配置 // 读取配置
configMqttBytes, _ := os.ReadFile(fmt.Sprintf("configFiles/%s", file.Name())) configBytes, _ := os.ReadFile(fmt.Sprintf("configFiles/%s", file.Name()))
consumer := new(Consumer) consumer := new(Consumer)
// 将 JSON 格式的数据解析到结构体中 // 将 JSON 格式的数据解析到结构体中
err = json.Unmarshal(configMqttBytes, &consumer) err = json.Unmarshal(configBytes, &consumer)
if err != nil { if err != nil {
log.Printf("读取配置文件[%s]异常 err=%v", consumer.Consumer, err.Error()) log.Printf("读取配置文件[%s]异常 err=%v", consumer.Consumer, err.Error())
continue continue
} }
allConfig[consumer.Consumer] = string(configMqttBytes) allConfig[consumer.Consumer] = string(configBytes)
//// 读取sensor配置
//configSensorBytes, _ := os.ReadFile("configSensor.json")
//// 将 JSON 格式的数据解析到结构体中
//err2 := json.Unmarshal(configSensorBytes, &userConfig.SensorConfig)
//if err2 != nil {
// log.Printf("读取mqtt配置异常 err=%v", err2.Error())
//}
//allConfig[]
} }
return allConfig return allConfig
} }

24
configFiles/config_司南GnssMySQL.json

@ -0,0 +1,24 @@
{
"consumer": "consumerSinoGnssMySQL",
"ioConfig": {
"in": {
"db": {
"type": "mysql",
"connStr": "root:Xuchen@2024@tcp(39.105.5.154:3306)/navi_cloud_sinognss?charset=utf8&parseTime=true"
},
"cronStr": "0/1 * * * *"
},
"out": {
"mqtt": {
"host": "10.8.30.160",
"port": 30883,
"userName": "upload",
"password": "",
"clientId": "goInOut_SinoGnssMySQL",
"Topics": []
}
}
},
"info": {
}
}

36
configFiles/弃用备份/config_安心云设备数据_最新同步.json

@ -0,0 +1,36 @@
{
"consumer": "consumerAXYraw",
"ioConfig": {
"in": {
"kafka": {
"brokers": [
"10.8.30.160:30992"
],
"groupId": "synchronizeRaw_50",
"topics": [
"RawData"
]
}
},
"out": {
"es": {
"address": ["http://10.8.30.160:30092"],
"index": "anxincloud_last_raw",
"auth": {
"userName": "post",
"password": "123"
},
"interval": 30
}
}
},
"info": {
"common": {
},
"queryComponent":{
"redis": {
"address": "10.8.30.142:30379"
}
}
}
}

2
configFiles/弃用备份/config_承德金隅水泥_河北矿山_大斜阳.json

@ -5,7 +5,7 @@
"http": { "http": {
"url": "https://esproxy.anxinyun.cn/anxincloud_themes/_search" "url": "https://esproxy.anxinyun.cn/anxincloud_themes/_search"
}, },
"cronStr": "18 0/1 * * *" "cronStr": "0/1 * * * *"
}, },
"out": { "out": {
"file": { "file": {

35
configFiles/弃用备份/config_江苏农村公路桥梁.json

@ -10,7 +10,9 @@
"clientId": "goUpload_JSNCGLQL", "clientId": "goUpload_JSNCGLQL",
"Topics": [ "Topics": [
"upload/uds/+", "upload/uds/+",
"upload/ZD/+" "upload/ZD/+",
"upload/ZDSL/+",
"upload/gdnd/+"
] ]
} }
}, },
@ -20,26 +22,31 @@
"port": 30883, "port": 30883,
"userName": "upload", "userName": "upload",
"password": "", "password": "",
"clientId": "upload1", "clientId": "goInOut",
"Topics": [ "Topics": [
"data/bridgeCode" "data/{{.bridgeCode}}/{{.sensorCode}}"
] ]
} }
} }
}, },
"info": { "info": {
"structUploadCode": "G2320281L0012" "bridgeCode": "G2320281L0012"
}, },
"sensorInfoMap": { "sensorInfo": {
"sensorMap": { "TYCJsensorMap": {
"TYCJsensorMap": { "m1c1": "JY-HSD-G05-001-01",
"m1c1": "JY-HSD-G05-001-01", "m1c2": "LHTDQ-RSG-L04-001-03"
"m1c2": "LHTDQ-RSG-L04-001-03" },
}, "ZDsensorMap": {
"ZDsensorMap": { "m1c1": "LHTDQ-VIB-C08-001-01",
"m1c1": "LHTDQ-VIB-C08-001-01", "m1c2": "LHTDQ-VIB-L03-001-01"
"m1c2": "LHTDQ-VIB-L03-001-01" },
} "ZDSLensorMap": {
"333701": "LHTDQ-SL-C08-001-01"
},
"GDNDsensorMap": {
"DY-DIS-ZG03-01": "LHTDQ-GDND-G03-003-01",
"m3c2": "LHTDQ-GDND-G03-003-02"
} }
} }
} }

30
configFiles/弃用备份/config_转发http2axy60000端口.json

@ -0,0 +1,30 @@
{
"consumer": "consumerHttpProxy",
"ioConfig": {
"in": {
"apiServer": {
"port": 7000,
"userName": "usr",
"password": "123",
"routers": [
{
"router": "POST /upload/work/ABStatus",
"idTemplate": "{{.values.ucId}}"
},
{
"router": "POST /upload/work/ABSHeart",
"idTemplate": "{{.Values.WorkId}}"
}
]
}
},
"out": {
"httpPost": {
"url": "http://218.3.126.49:60000",
"method": "post"
}
}
},
"info": {
}
}

0
configFiles/config_魏家滑坡_视觉位移.json → configFiles/弃用备份/config_魏家滑坡_视觉位移.json

1
constKey/key.go

@ -1 +0,0 @@
package constKey

31
consumers/AXYraw/config.go

@ -0,0 +1,31 @@
package AXYraw
import "goInOut/config"
type ConfigFile struct {
config.Consumer
IoConfig ioConfig `json:"ioConfig"`
Info Info `json:"info"`
}
type ioConfig struct {
In in `json:"in"`
Out out `json:"out"`
}
type in struct {
Kafka config.KafkaConfig `json:"kafka"`
}
type out struct {
Es config.EsConfig `json:"es"`
}
type Info struct {
Common map[string]string `json:"common"`
QueryComponent queryComponent `json:"queryComponent"`
}
type queryComponent struct {
Redis struct {
Address string `json:"address"`
} `json:"redis"`
}

2
consumers/CDJYSN/config.go

@ -1,6 +1,6 @@
package CDJYSN package CDJYSN
import "goUpload/config" import "goInOut/config"
type ConfigFile struct { type ConfigFile struct {
config.Consumer config.Consumer

2
consumers/CQZG/config.go

@ -1,6 +1,6 @@
package CQZG package CQZG
import "goUpload/config" import "goInOut/config"
type ConfigFile struct { type ConfigFile struct {
config.Consumer config.Consumer

2
consumers/GZGZM/config.go

@ -1,6 +1,6 @@
package GZGZM package GZGZM
import "goUpload/config" import "goInOut/config"
type ConfigFile struct { type ConfigFile struct {
config.Consumer config.Consumer

2
consumers/HTJC/config.go

@ -1,6 +1,6 @@
package HTJC package HTJC
import "goUpload/config" import "goInOut/config"
type ConfigFile struct { type ConfigFile struct {
config.Consumer config.Consumer

25
consumers/HTTP_PRPXY/config.go

@ -0,0 +1,25 @@
package HTTP_PRPXY
import "goInOut/config"
type ConfigFile struct {
config.Consumer
IoConfig ioConfig `json:"ioConfig"`
OtherInfo map[string]string `json:"info"`
}
type ioConfig struct {
In In `json:"in"`
Out OUT `json:"out"`
}
type In struct {
ApiServer config.ApiServerConfig `json:"apiServer"`
}
type OUT struct {
HttpPost config.HttpConfig `json:"httpPost"`
}
type SensorInfo struct {
Name string `json:"name"` //测点名称
Code string `json:"code"` //测点编号 宜由“桥名简称-监测类别简称-构件类型编码-截面序号-构件序号-测点编号”组成
}

44
consumers/HTTP_PRPXY/dataModel.go

@ -0,0 +1,44 @@
package HTTP_PRPXY
type ABStatus struct {
Values ABStatusValues `json:"values"`
Secret string `json:"secret"`
Type string `json:"type"`
}
type ABStatusValues struct {
CreateTime int64 `json:"createTime"`
Updater string `json:"updater"`
Deleted bool `json:"deleted"`
Id string `json:"id"`
WorkId string `json:"workId"`
UcId string `json:"ucId"`
DeviceCode string `json:"deviceCode"`
UserId string `json:"userId"`
UserName string `json:"userName"`
DataTime int64 `json:"dataTime"`
BeltStatus string `json:"beltStatus"`
DeviceStatus string `json:"deviceStatus"`
StartDate int64 `json:"startDate"`
EndDate int64 `json:"endDate"`
MainVol int `json:"mainVol"`
AscendWorkCertificate string `json:"ascend_work_certificate"`
BeltPoseLeft string `json:"beltPoseLeft"`
BeltPoseRight string `json:"beltPoseRight"`
BeltStatusLeft string `json:"beltStatusLeft"`
BeltStatusRight string `json:"beltStatusRight"`
TickbVol int `json:"tickbVol"`
//Avatar interface{} `json:"avatar"`
//AlarmType interface{} `json:"alarmType"`
//Identity interface{} `json:"identity"`
//IdentityImg interface{} `json:"identityImg"`
//IdentityImgF interface{} `json:"identityImgF"`
//Phone interface{} `json:"phone"`
Versions int `json:"versions"`
//Team interface{} `json:"team"`
Longitude string `json:"longitude"`
Latitude string `json:"latitude"`
Outsource string `json:"outsource"`
LocTime int64 `json:"locTime"`
//WorkLen interface{} `json:"workLen"`
}

9
consumers/JSNCGLQL/config.go

@ -1,11 +1,12 @@
package JSNCGLQL package JSNCGLQL
import "goUpload/config" import "goInOut/config"
type ConfigFile struct { type ConfigFile struct {
config.Consumer config.Consumer
IoConfig ioConfig `json:"ioConfig"` IoConfig ioConfig `json:"ioConfig"`
SensorConfig SensorConfig `json:"sensorInfo"`
OtherInfo map[string]string `json:"info"`
} }
type ioConfig struct { type ioConfig struct {
In In `json:"in"` In In `json:"in"`
@ -22,6 +23,8 @@ type OUT struct {
type SensorConfig struct { type SensorConfig struct {
TYCJsensorMap map[string]string `json:"TYCJsensorMap"` TYCJsensorMap map[string]string `json:"TYCJsensorMap"`
ZDsensorMap map[string]string `json:"ZDsensorMap"` ZDsensorMap map[string]string `json:"ZDsensorMap"`
GDNDsensorMap map[string]string `json:"GDNDsensorMap"`
ZDSLensorMap map[string]string `json:"ZDSLensorMap"`
} }
type SensorInfo struct { type SensorInfo struct {

2
consumers/MYX/config.go

@ -1,6 +1,6 @@
package MYX package MYX
import "goUpload/config" import "goInOut/config"
type ConfigFile struct { type ConfigFile struct {
config.Consumer config.Consumer

27
consumers/SinoGnssMySQL/config.go

@ -0,0 +1,27 @@
package SinoGnssMySQL
import "goInOut/config"
type ConfigFile struct {
config.Consumer
IoConfig ioConfig `json:"ioConfig"`
OtherInfo map[string]string `json:"info"`
}
type ioConfig struct {
In In `json:"in"`
Out OUT `json:"out"`
}
type In struct {
Db config.DbConfig `json:"db"`
CronStr string `json:"cronStr"`
}
type OUT struct {
Mqtt config.MqttConfig `json:"mqtt"`
}
// 缓存用
type RecordInfo struct {
Id int64 `json:"id"`
TableName string `json:"table_name"`
}

28
consumers/SinoGnssMySQL/dataModel.go

@ -0,0 +1,28 @@
package SinoGnssMySQL
import "time"
type GnssData struct {
Id int64 `json:"id" db:"id"`
StationName string `json:"station_name" db:"station_name"`
GroupName string `json:"group_name" db:"group_name"`
Time time.Time `json:"time" db:"time"`
X float64 `json:"x" db:"x"`
Y float64 `json:"y" db:"y"`
H float64 `json:"h" db:"h"`
}
type DxFile struct {
SensorId int `json:"S"`
Module string `json:"M"`
Channel int `json:"C"`
Error int `json:"R"`
Round int64 `json:"N"`
Timespan int64 `json:"T"`
Req []string `json:"Q"`
Acq []string `json:"A"`
RawValue []float64 `json:"RV"`
LimitValue []float64 `json:"LV"`
PhyValue []float64 `json:"PV"`
ThemeValue []float64 `json:"TV"`
}

2
consumers/WJHP/config.go

@ -1,6 +1,6 @@
package WJHP package WJHP
import "goUpload/config" import "goInOut/config"
type ConfigFile struct { type ConfigFile struct {
config.Consumer config.Consumer

162
consumers/consumerAXYraw.go

@ -0,0 +1,162 @@
package consumers
import (
"encoding/json"
"goInOut/adaptors"
"goInOut/consumers/AXYraw"
"goInOut/dbOperate"
"goInOut/dbOperate/_kafka"
"goInOut/models"
"log"
"sync"
"time"
)
type consumerAXYraw struct {
//数据缓存管道
dataCache chan *models.EsRaw
//具体配置
ConfigInfo AXYraw.ConfigFile
InKafka _kafka.KafkaHelper
OutEs dbOperate.ESHelper
infoRedis *dbOperate.RedisHelper
sinkRawMap sync.Map
lock sync.Mutex
}
func (the *consumerAXYraw) LoadConfigJson(cfgStr string) {
// 将 JSON 格式的数据解析到结构体中
err := json.Unmarshal([]byte(cfgStr), &the.ConfigInfo)
if err != nil {
log.Printf("读取配置文件[%s]异常 err=%v", cfgStr, err.Error())
panic(err)
}
}
func (the *consumerAXYraw) Initial(cfg string) error {
the.sinkRawMap = sync.Map{}
the.dataCache = make(chan *models.EsRaw, 200)
the.LoadConfigJson(cfg)
err := the.inputInitial()
if err != nil {
return err
}
err = the.outputInitial()
if err != nil {
return err
}
err = the.infoComponentInitial()
return err
}
func (the *consumerAXYraw) inputInitial() error {
//数据入口
the.InKafka = _kafka.KafkaHelper{
Brokers: the.ConfigInfo.IoConfig.In.Kafka.Brokers,
GroupId: the.ConfigInfo.IoConfig.In.Kafka.GroupId,
}
the.InKafka.Initial()
for _, inTopic := range the.ConfigInfo.IoConfig.In.Kafka.Topics {
the.InKafka.Subscribe(inTopic, the.onData)
}
the.InKafka.Worker()
return nil
}
func (the *consumerAXYraw) outputInitial() error {
//数据出口
the.OutEs = *dbOperate.NewESHelper(
the.ConfigInfo.IoConfig.Out.Es.Address,
the.ConfigInfo.IoConfig.Out.Es.Auth.UserName,
the.ConfigInfo.IoConfig.Out.Es.Auth.Password,
)
return nil
}
func (the *consumerAXYraw) infoComponentInitial() error {
//数据出口
addr := the.ConfigInfo.Info.QueryComponent.Redis.Address
the.infoRedis = dbOperate.NewRedisHelper("", addr)
return nil
}
func (the *consumerAXYraw) sinkTask() {
intervalSec := the.ConfigInfo.IoConfig.Out.Es.Interval
ticker := time.NewTicker(time.Duration(intervalSec) * time.Second)
defer ticker.Stop()
for {
<-ticker.C
the.toSink()
}
}
func (the *consumerAXYraw) toSink() {
var raws []models.EsRaw
the.lock.Lock()
defer the.lock.Unlock()
the.sinkRawMap.Range(func(key, value any) bool {
if v, ok := value.(*models.EsRaw); ok {
raws = append(raws, *v)
//零时打日志用
if v.IotaDevice == logTagDeviceId {
bs, _ := json.Marshal(v)
log.Printf("toSink -> Range 标记设备数据 [%s] %s ", logTagDeviceId, string(bs))
}
return ok
} else {
log.Printf("!!! toSink -> Range 类型转换异常 [%v]", key)
}
return true
})
if len(raws) > 0 {
log.Printf("准备写入es %d条", len(raws))
index := the.ConfigInfo.IoConfig.Out.Es.Index
the.OutEs.BulkWriteRaws2Es(index, raws)
the.sinkRawMap.Clear()
}
}
const logTagDeviceId = "91da4d1f-fbc7-4dad-bedd-f8ff05c0e0e0"
func (the *consumerAXYraw) Work() {
go the.sinkTask()
go func() {
for {
pushEsRaw := <-the.dataCache
if pushEsRaw.IotaDevice == logTagDeviceId {
bs, _ := json.Marshal(pushEsRaw)
log.Printf("存储 标记设备数据 [%s] %s ", logTagDeviceId, string(bs))
}
//有效数据存入缓存
the.lock.Lock()
the.sinkRawMap.Store(pushEsRaw.IotaDevice, pushEsRaw)
the.lock.Unlock()
}
}()
}
func (the *consumerAXYraw) onData(topic string, msg string) bool {
//if len(msg) > 80 {
// log.Printf("recv:[%s]:%s ...", topic, msg[:80])
//}
adaptor := adaptors.Adaptor_AXY_LastRAW{
Redis: the.infoRedis,
}
needPush := adaptor.Transform(topic, msg)
if needPush != nil && len(needPush.Meta) > 0 && needPush.Data != nil {
//日志标记
if needPush.IotaDevice == logTagDeviceId {
bs, _ := json.Marshal(needPush)
log.Printf("onData -> needPush 标记设备数据 [%s] %s ", logTagDeviceId, string(bs))
}
the.dataCache <- needPush
}
return true
}

18
consumers/consumerCDJYSN.go

@ -4,11 +4,11 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
"goUpload/adaptors" "goInOut/adaptors"
"goUpload/consumers/CDJYSN" "goInOut/consumers/CDJYSN"
"goUpload/dbHelper" "goInOut/dbOperate"
"goUpload/monitors" "goInOut/monitors"
"goUpload/utils" "goInOut/utils"
"log" "log"
"path" "path"
"time" "time"
@ -19,8 +19,8 @@ type consumerCDJYSN struct {
dataCache chan []byte dataCache chan []byte
//具体配置 //具体配置
ConfigInfo CDJYSN.ConfigFile ConfigInfo CDJYSN.ConfigFile
//InHttp *dbHelper.HttpHelper //InHttp *dbOperate.HttpHelper
OutFile *dbHelper.FileSaveHelper OutFile *dbOperate.FileSaveHelper
InHttp monitors.HttpMonitor InHttp monitors.HttpMonitor
configCron *cron.Cron configCron *cron.Cron
} }
@ -47,7 +47,7 @@ func (the *consumerCDJYSN) InputInitial() error {
the.dataCache = make(chan []byte, 200) the.dataCache = make(chan []byte, 200)
//数据入口 //数据入口
the.InHttp = monitors.HttpMonitor{ the.InHttp = monitors.HttpMonitor{
HttpClient: &dbHelper.HttpHelper{Url: the.ConfigInfo.IoConfig.In.Http.Url, Token: ""}, HttpClient: &dbOperate.HttpHelper{Url: the.ConfigInfo.IoConfig.In.Http.Url, Token: ""},
MonitorHelper: &monitors.MonitorHelper{CronStr: the.ConfigInfo.IoConfig.In.CronStr}, MonitorHelper: &monitors.MonitorHelper{CronStr: the.ConfigInfo.IoConfig.In.CronStr},
} }
@ -57,7 +57,7 @@ func (the *consumerCDJYSN) InputInitial() error {
} }
func (the *consumerCDJYSN) OutputInitial() error { func (the *consumerCDJYSN) OutputInitial() error {
//数据出口 //数据出口
the.OutFile = &dbHelper.FileSaveHelper{ the.OutFile = &dbOperate.FileSaveHelper{
Directory: the.ConfigInfo.IoConfig.Out.File.Directory, Directory: the.ConfigInfo.IoConfig.Out.File.Directory,
FilenameExtension: the.ConfigInfo.IoConfig.Out.File.FileNameExtension, FilenameExtension: the.ConfigInfo.IoConfig.Out.File.FileNameExtension,
} }

14
consumers/consumerCQZG.go

@ -2,9 +2,9 @@ package consumers
import ( import (
"encoding/json" "encoding/json"
"goUpload/adaptors" "goInOut/adaptors"
"goUpload/consumers/CQZG" "goInOut/consumers/CQZG"
"goUpload/dbHelper" "goInOut/dbOperate"
"log" "log"
"os" "os"
"strings" "strings"
@ -16,8 +16,8 @@ type consumerCQZG struct {
ch_t500101 chan []byte ch_t500101 chan []byte
//具体配置 //具体配置
Info CQZG.ConfigFile Info CQZG.ConfigFile
InMqtt *dbHelper.MqttHelper InMqtt *dbOperate.MqttHelper
outMqtt *dbHelper.MqttHelper outMqtt *dbOperate.MqttHelper
} }
func (the *consumerCQZG) LoadConfigJson(cfgStr string) { func (the *consumerCQZG) LoadConfigJson(cfgStr string) {
@ -43,7 +43,7 @@ func (the *consumerCQZG) InputInitial() error {
log.Printf("RC4Key=%s", the.Info.Config.Rc4key) log.Printf("RC4Key=%s", the.Info.Config.Rc4key)
the.ch_t500101 = make(chan []byte, 200) the.ch_t500101 = make(chan []byte, 200)
//数据入口 //数据入口
the.InMqtt = dbHelper.MqttInitial( the.InMqtt = dbOperate.MqttInitial(
the.Info.Config.InMqtt.Host, the.Info.Config.InMqtt.Host,
the.Info.Config.InMqtt.Port, the.Info.Config.InMqtt.Port,
the.Info.Config.InMqtt.ClientId, the.Info.Config.InMqtt.ClientId,
@ -58,7 +58,7 @@ func (the *consumerCQZG) InputInitial() error {
} }
func (the *consumerCQZG) OutputInitial() error { func (the *consumerCQZG) OutputInitial() error {
//数据出口 //数据出口
the.outMqtt = dbHelper.MqttInitial( the.outMqtt = dbOperate.MqttInitial(
the.Info.Config.OutMqtt.Host, the.Info.Config.OutMqtt.Host,
the.Info.Config.OutMqtt.Port, the.Info.Config.OutMqtt.Port,
the.Info.Config.OutMqtt.ClientId, the.Info.Config.OutMqtt.ClientId,

14
consumers/consumerGZGZM.go

@ -4,10 +4,10 @@ import (
"crypto/md5" "crypto/md5"
"encoding/json" "encoding/json"
"fmt" "fmt"
"goUpload/adaptors" "goInOut/adaptors"
"goUpload/consumers/GZGZM" "goInOut/consumers/GZGZM"
"goUpload/dbHelper" "goInOut/dbOperate"
"goUpload/dbHelper/_kafka" "goInOut/dbOperate/_kafka"
"io" "io"
"log" "log"
"math/rand" "math/rand"
@ -20,7 +20,7 @@ type consumerGZGZM struct {
//具体配置 //具体配置
ConfigInfo GZGZM.ConfigFile ConfigInfo GZGZM.ConfigFile
InKafka _kafka.KafkaHelper InKafka _kafka.KafkaHelper
OutHttp *dbHelper.HttpHelper OutHttp *dbOperate.HttpHelper
} }
func (the *consumerGZGZM) RegisterPoint(thirdId string, sensorInfo GZGZM.SensorInfo) error { func (the *consumerGZGZM) RegisterPoint(thirdId string, sensorInfo GZGZM.SensorInfo) error {
@ -91,7 +91,7 @@ func (the *consumerGZGZM) inputInitial() error {
} }
func (the *consumerGZGZM) outputInitial() error { func (the *consumerGZGZM) outputInitial() error {
//数据出口 //数据出口
the.OutHttp = &dbHelper.HttpHelper{ the.OutHttp = &dbOperate.HttpHelper{
Url: the.ConfigInfo.IoConfig.Out.Http.Url, Url: the.ConfigInfo.IoConfig.Out.Http.Url,
} }
the.OutHttp.Initial() the.OutHttp.Initial()
@ -135,7 +135,7 @@ func (the *consumerGZGZM) tokenRefresh() {
fmt.Sprintf("&random=%s", randomStr16) + fmt.Sprintf("&random=%s", randomStr16) +
fmt.Sprintf("&timestamp=%d", timestamp) + fmt.Sprintf("&timestamp=%d", timestamp) +
fmt.Sprintf("&secret=%s", secret) fmt.Sprintf("&secret=%s", secret)
tokenHttp := &dbHelper.HttpHelper{ tokenHttp := &dbOperate.HttpHelper{
Url: queryUrl, Url: queryUrl,
} }
tokenHttp.Initial() tokenHttp.Initial()

14
consumers/consumerHTJC.go

@ -2,9 +2,9 @@ package consumers
import ( import (
"encoding/json" "encoding/json"
"goUpload/adaptors" "goInOut/adaptors"
"goUpload/consumers/HTJC" "goInOut/consumers/HTJC"
"goUpload/dbHelper" "goInOut/dbOperate"
"log" "log"
"strings" "strings"
"time" "time"
@ -15,8 +15,8 @@ type consumerHTJC struct {
dataCache chan []byte dataCache chan []byte
//具体配置 //具体配置
Info HTJC.ConfigFile Info HTJC.ConfigFile
InMqtt *dbHelper.MqttHelper InMqtt *dbOperate.MqttHelper
outUdp *dbHelper.UdpHelper outUdp *dbOperate.UdpHelper
} }
func (the *consumerHTJC) LoadConfigJson(cfgStr string) { func (the *consumerHTJC) LoadConfigJson(cfgStr string) {
@ -40,7 +40,7 @@ func (the *consumerHTJC) Initial(cfg string) error {
func (the *consumerHTJC) InputInitial() error { func (the *consumerHTJC) InputInitial() error {
the.dataCache = make(chan []byte, 1000) the.dataCache = make(chan []byte, 1000)
//数据入口 //数据入口
the.InMqtt = dbHelper.MqttInitial( the.InMqtt = dbOperate.MqttInitial(
the.Info.Config.InMqtt.Host, the.Info.Config.InMqtt.Host,
the.Info.Config.InMqtt.Port, the.Info.Config.InMqtt.Port,
the.Info.Config.InMqtt.ClientId, the.Info.Config.InMqtt.ClientId,
@ -55,7 +55,7 @@ func (the *consumerHTJC) InputInitial() error {
} }
func (the *consumerHTJC) OutputInitial() error { func (the *consumerHTJC) OutputInitial() error {
//数据出口 //数据出口
the.outUdp = &dbHelper.UdpHelper{ the.outUdp = &dbOperate.UdpHelper{
Host: the.Info.Config.OutUdp.Host, Host: the.Info.Config.OutUdp.Host,
Port: the.Info.Config.OutUdp.Port, Port: the.Info.Config.OutUdp.Port,
} }

102
consumers/consumerHTTP_PRPXY.go

@ -0,0 +1,102 @@
package consumers
import (
"encoding/json"
"fmt"
"goInOut/config"
"goInOut/consumers/HTTP_PRPXY"
"goInOut/dbOperate"
"goInOut/utils"
"io"
"log"
"net/http"
)
type consumerHttpProxy struct {
//数据缓存管道
routes map[string]config.Router
//具体配置
Info HTTP_PRPXY.ConfigFile
InApiServer *dbOperate.ApiServerHelper
outHttpPost *dbOperate.HttpHelper
}
func (the *consumerHttpProxy) LoadConfigJson(cfgStr string) {
// 将 JSON 格式的数据解析到结构体中
err := json.Unmarshal([]byte(cfgStr), &the.Info)
if err != nil {
log.Printf("读取配置文件[%s]异常 err=%v", cfgStr, err.Error())
panic(err)
}
}
func (the *consumerHttpProxy) Initial(cfg string) error {
the.routes = map[string]config.Router{}
the.LoadConfigJson(cfg)
err := the.InputInitial()
if err != nil {
return err
}
err = the.OutputInitial()
return err
}
func (the *consumerHttpProxy) InputInitial() error {
//数据入口
the.InApiServer = dbOperate.NewApiServer(
the.Info.IoConfig.In.ApiServer.Port,
the.Info.IoConfig.In.ApiServer.Routers,
)
the.InApiServer.Initial()
return nil
}
func (the *consumerHttpProxy) OutputInitial() error {
//数据出口
the.outHttpPost = &dbOperate.HttpHelper{
Url: the.Info.IoConfig.Out.HttpPost.Url,
}
the.outHttpPost.Initial()
return nil
}
func (the *consumerHttpProxy) Work() {
go func() {
for _, router := range the.Info.IoConfig.In.ApiServer.Routers {
the.InApiServer.RouteRegister(router.Router, the.onData)
the.routes[router.Router] = router
}
the.InApiServer.Run()
}()
}
func (the *consumerHttpProxy) onData(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
body, err := io.ReadAll(r.Body)
log.Printf("收到 %s 请求 %s", r.RequestURI, body)
bodyObj := map[string]any{}
err = json.Unmarshal(body, &bodyObj)
if err != nil {
log.Printf("body 解析失败,请检查 %s", err.Error())
return
}
routePath := fmt.Sprintf("%s %s", r.Method, r.RequestURI)
idTemplate := the.routes[routePath]
id, err := utils.TextTemplateMatch(bodyObj, idTemplate.IdTemplate)
if err != nil {
log.Printf("解析id 失败,请检查 %s", err.Error())
}
params := map[string]string{
"id": id,
}
resp := ""
//沿用请求路由
newUrl := the.outHttpPost.Url + r.URL.String()
resp, err = the.outHttpPost.HttpPostWithParams(newUrl, string(body), params)
if err != nil {
return
}
log.Printf("应答: %s", resp)
defer fmt.Fprintf(w, resp)
}

33
consumers/consumerJSNCGLQL.go

@ -2,9 +2,9 @@ package consumers
import ( import (
"encoding/json" "encoding/json"
"goUpload/adaptors" "goInOut/adaptors"
"goUpload/consumers/JSNCGLQL" "goInOut/consumers/JSNCGLQL"
"goUpload/dbHelper" "goInOut/dbOperate"
"log" "log"
"strings" "strings"
"time" "time"
@ -15,8 +15,8 @@ type consumerJSNCGLQL struct {
ch chan []adaptors.NeedPush ch chan []adaptors.NeedPush
//具体配置 //具体配置
Info JSNCGLQL.ConfigFile Info JSNCGLQL.ConfigFile
InMqtt *dbHelper.MqttHelper InMqtt *dbOperate.MqttHelper
outMqtt *dbHelper.MqttHelper outMqtt *dbOperate.MqttHelper
} }
func (the *consumerJSNCGLQL) LoadConfigJson(cfgStr string) { func (the *consumerJSNCGLQL) LoadConfigJson(cfgStr string) {
@ -40,7 +40,7 @@ func (the *consumerJSNCGLQL) Initial(cfg string) error {
func (the *consumerJSNCGLQL) InputInitial() error { func (the *consumerJSNCGLQL) InputInitial() error {
the.ch = make(chan []adaptors.NeedPush, 200) the.ch = make(chan []adaptors.NeedPush, 200)
//数据入口 //数据入口
the.InMqtt = dbHelper.MqttInitial( the.InMqtt = dbOperate.MqttInitial(
the.Info.IoConfig.In.Mqtt.Host, the.Info.IoConfig.In.Mqtt.Host,
the.Info.IoConfig.In.Mqtt.Port, the.Info.IoConfig.In.Mqtt.Port,
the.Info.IoConfig.In.Mqtt.ClientId, the.Info.IoConfig.In.Mqtt.ClientId,
@ -55,7 +55,7 @@ func (the *consumerJSNCGLQL) InputInitial() error {
} }
func (the *consumerJSNCGLQL) OutputInitial() error { func (the *consumerJSNCGLQL) OutputInitial() error {
//数据出口 //数据出口
the.outMqtt = dbHelper.MqttInitial( the.outMqtt = dbOperate.MqttInitial(
the.Info.IoConfig.Out.Mqtt.Host, the.Info.IoConfig.Out.Mqtt.Host,
the.Info.IoConfig.Out.Mqtt.Port, the.Info.IoConfig.Out.Mqtt.Port,
the.Info.IoConfig.Out.Mqtt.ClientId, the.Info.IoConfig.Out.Mqtt.ClientId,
@ -95,20 +95,33 @@ func (the *consumerJSNCGLQL) onData(inTopic string, Msg string) {
matchTopic := inTopic[:topicPrefixIndex] matchTopic := inTopic[:topicPrefixIndex]
adaptor := the.getAdaptor(matchTopic) adaptor := the.getAdaptor(matchTopic)
if adaptor != nil { if adaptor != nil {
needPush := adaptor.Transform(inTopic, Msg) needPush := adaptor.Transform(matchTopic, Msg)
if len(needPush) > 0 { if len(needPush) > 0 {
the.ch <- needPush the.ch <- needPush
} }
} }
} }
func (the *consumerJSNCGLQL) getAdaptor(flag string) (adaptor adaptors.IAdaptor4) { func (the *consumerJSNCGLQL) getAdaptor(flag string) (adaptor adaptors.IAdaptor4) {
bridgeCode := ""
if v, ok := the.Info.OtherInfo["bridgeCode"]; ok {
bridgeCode = v
}
if bridgeCode == "" {
panic("无正确的 bridgeCode")
}
switch flag { switch flag {
case "upload/uds": case "upload/uds":
log.Printf("[统一采集软件]-上报,准备处理") log.Printf("[统一采集软件]-上报,准备处理")
//adaptor = adaptors.Adaptor_TYCJ_JSNCGLQL{IdMap: the.Info.TYCJsensorMap} adaptor = adaptors.Adaptor_TYCJ_JSNCGLQL{IdMap: the.Info.TYCJsensorMap, BridgeCode: bridgeCode}
case "upload/ZD": case "upload/ZD":
log.Printf("[振动软件]-上报,准备处理") log.Printf("[振动软件]-上报,准备处理")
//adaptor = adaptors.Adaptor_ZD_CQZG{IdMap: the.Info.SensorMap.ZDsensorMCMap, RC4Key: RC4Key} adaptor = adaptors.Adaptor_ZD_JSNCGLQL{IdMap: the.Info.ZDsensorMap, BridgeCode: bridgeCode}
case "upload/ZDSL":
log.Printf("[振动索力软件]-上报,准备处理")
adaptor = adaptors.Adaptor_ZD_JSNCGLQL{IdMap: the.Info.ZDSLensorMap, BridgeCode: bridgeCode}
case "upload/gdnd":
log.Printf("[光电挠度]-上报,准备处理")
adaptor = adaptors.Adaptor_GDND2LA_JSNCGLQL{IdMap: the.Info.GDNDsensorMap, BridgeCode: bridgeCode}
default: default:
log.Printf("[无匹配 %s],不处理", flag) log.Printf("[无匹配 %s],不处理", flag)
} }

16
consumers/consumerMYX.go

@ -5,10 +5,10 @@ import (
"encoding/csv" "encoding/csv"
"encoding/json" "encoding/json"
"fmt" "fmt"
"goUpload/adaptors" "goInOut/adaptors"
"goUpload/consumers/MYX" "goInOut/consumers/MYX"
"goUpload/dbHelper" "goInOut/dbOperate"
"goUpload/monitors" "goInOut/monitors"
"golang.org/x/text/encoding/unicode" "golang.org/x/text/encoding/unicode"
"log" "log"
"os" "os"
@ -22,9 +22,9 @@ type consumerMYX struct {
dataCache chan []byte dataCache chan []byte
//具体配置 //具体配置
Info MYX.ConfigFile Info MYX.ConfigFile
InMqtt *dbHelper.MqttHelper InMqtt *dbOperate.MqttHelper
InFileMonitor *monitors.FileMonitor InFileMonitor *monitors.FileMonitor
outHttpPost *dbHelper.HttpHelper outHttpPost *dbOperate.HttpHelper
} }
func (the *consumerMYX) LoadConfigJson(cfgStr string) { func (the *consumerMYX) LoadConfigJson(cfgStr string) {
@ -48,7 +48,7 @@ func (the *consumerMYX) Initial(cfg string) error {
func (the *consumerMYX) InputInitial() error { func (the *consumerMYX) InputInitial() error {
the.dataCache = make(chan []byte, 200) the.dataCache = make(chan []byte, 200)
//mqtt数据入口 //mqtt数据入口
the.InMqtt = dbHelper.MqttInitial( the.InMqtt = dbOperate.MqttInitial(
the.Info.IOConfig.InMqtt.Host, the.Info.IOConfig.InMqtt.Host,
the.Info.IOConfig.InMqtt.Port, the.Info.IOConfig.InMqtt.Port,
the.Info.IOConfig.InMqtt.ClientId, the.Info.IOConfig.InMqtt.ClientId,
@ -71,7 +71,7 @@ func (the *consumerMYX) InputInitial() error {
} }
func (the *consumerMYX) OutputInitial() error { func (the *consumerMYX) OutputInitial() error {
//数据出口 //数据出口
the.outHttpPost = &dbHelper.HttpHelper{ the.outHttpPost = &dbOperate.HttpHelper{
Url: the.Info.IOConfig.OutHttpPost.Url, Url: the.Info.IOConfig.OutHttpPost.Url,
} }
the.outHttpPost.Initial() the.outHttpPost.Initial()

12
consumers/consumerManage.go

@ -19,6 +19,18 @@ func GetConsumer(name string) (consumer IConsumer) {
case "consumerGZGZM": //工迅-广州高支模平台 case "consumerGZGZM": //工迅-广州高支模平台
consumer = new(consumerGZGZM) consumer = new(consumerGZGZM)
case "consumerAXYraw": //工迅-广州高支模平台
consumer = new(consumerAXYraw)
case "consumerJSNCGLQL": //工迅-广州高支模平台
consumer = new(consumerJSNCGLQL)
case "consumerHttpProxy":
consumer = new(consumerHttpProxy)
case "consumerSinoGnssMySQL":
consumer = new(consumerSinoGnssMySQL)
default: default:
consumer = nil consumer = nil
} }

174
consumers/consumerSinoGnssMySQL.go

@ -0,0 +1,174 @@
package consumers
import (
"encoding/json"
"fmt"
"goInOut/adaptors"
"goInOut/consumers/SinoGnssMySQL"
"goInOut/dbOperate"
"goInOut/monitors"
"goInOut/utils"
"log"
"os"
"time"
)
type consumerSinoGnssMySQL struct {
//数据缓存管道
ch chan []adaptors.NeedPush
//具体配置
Info SinoGnssMySQL.ConfigFile
InDB *dbOperate.DBHelper
outMqtt *dbOperate.MqttHelper
monitor *monitors.CommonMonitor
}
func (the *consumerSinoGnssMySQL) LoadConfigJson(cfgStr string) {
// 将 JSON 格式的数据解析到结构体中
err := json.Unmarshal([]byte(cfgStr), &the.Info)
if err != nil {
log.Printf("读取配置文件[%s]异常 err=%v", cfgStr, err.Error())
panic(err)
}
}
func (the *consumerSinoGnssMySQL) Initial(cfg string) error {
the.LoadConfigJson(cfg)
err := the.InputInitial()
if err != nil {
return err
}
err = the.OutputInitial()
return err
}
func (the *consumerSinoGnssMySQL) InputInitial() error {
the.ch = make(chan []adaptors.NeedPush, 200)
//数据入口
the.InDB = dbOperate.NewDBHelper(
the.Info.IoConfig.In.Db.Type,
the.Info.IoConfig.In.Db.ConnStr)
the.monitor = &monitors.CommonMonitor{
MonitorHelper: &monitors.MonitorHelper{CronStr: the.Info.IoConfig.In.CronStr},
}
the.monitor.Start()
the.monitor.RegisterFun(the.onData)
return nil
}
func (the *consumerSinoGnssMySQL) OutputInitial() error {
//数据出口
the.outMqtt = dbOperate.MqttInitial(
the.Info.IoConfig.Out.Mqtt.Host,
the.Info.IoConfig.Out.Mqtt.Port,
the.Info.IoConfig.Out.Mqtt.ClientId,
the.Info.IoConfig.Out.Mqtt.UserName,
the.Info.IoConfig.Out.Mqtt.Password,
false, //按照具体项目来
"")
return nil
}
func (the *consumerSinoGnssMySQL) Work() {
go func() {
for {
needPushList := <-the.ch
if len(the.ch) > 0 {
log.Printf("取出ch数据,剩余[%d] ", len(the.ch))
}
for _, push := range needPushList {
if push.Topic != "" {
the.outMqtt.Publish(push.Topic, push.Payload)
}
}
time.Sleep(100 * time.Millisecond)
}
}()
}
func (the *consumerSinoGnssMySQL) onData() {
recordInfo, err := readRecord()
if err != nil {
log.Printf("读取 缓存异常,err=%v", err.Error())
return
}
sql := fmt.Sprintf(`select d.id,d.station_name,p.group_name,d.time,d.x,d.y,d.h from %s as d
LEFT JOIN datasolution as p
ON d.station_name=p.sn
where p.group_name is not null
and d.id > %d and d.id <= %d
ORDER BY p.group_name;`, recordInfo.TableName, recordInfo.Id, recordInfo.Id+200)
var GnssDatas []SinoGnssMySQL.GnssData
err = the.InDB.Query(&GnssDatas, sql)
if err != nil || len(GnssDatas) == 0 {
log.Printf("当前批次无数据,跳过")
return
}
maxId := MaxId(GnssDatas)
log.Printf("当前批次id=%d => %d", recordInfo.Id, maxId)
recordInfo.Id = maxId
adaptor := the.getAdaptor()
needPush := adaptor.Transform(GnssDatas)
if len(needPush) > 0 {
the.ch <- needPush
}
fileName := "cache.inout"
//发现新月新纪录
newTableName := tableNameNow()
if recordInfo.TableName != newTableName {
recordInfo.TableName = newTableName
recordInfo.Id = 0
}
cacheStr, _ := json.Marshal(recordInfo)
err = utils.SaveCache2File(string(cacheStr), fileName)
if err != nil {
log.Panicf("record id to file,error: %v", err.Error())
}
}
func (the *consumerSinoGnssMySQL) getAdaptor() (adaptor adaptors.Adaptor_SINOMYSQL_AXYMQTT) {
return adaptors.Adaptor_SINOMYSQL_AXYMQTT{}
}
func readRecord() (SinoGnssMySQL.RecordInfo, error) {
fileName := "cache.inout"
//文件存在?
isExist := utils.FileExists(fileName)
if !isExist {
// 文件不存在,创建文件
file, err := os.Create(fileName)
if err != nil {
log.Panicf("Error creating file: %v", err)
}
defaultRecord := SinoGnssMySQL.RecordInfo{
Id: 0,
TableName: tableNameNow(),
}
str, _ := json.Marshal(defaultRecord)
_, err = file.WriteString(string(str))
if err != nil {
log.Panicf("file write error: %v", err.Error())
return SinoGnssMySQL.RecordInfo{}, err
}
}
recordStr, err := utils.ReadCache2File(fileName)
if err != nil {
panic("")
}
record := SinoGnssMySQL.RecordInfo{}
err = json.Unmarshal([]byte(recordStr), &record)
return record, err
}
func MaxId(GnssDatas []SinoGnssMySQL.GnssData) int64 {
maxId := GnssDatas[0].Id
for _, data := range GnssDatas {
if data.Id > maxId {
maxId = data.Id
}
}
return maxId
}
func tableNameNow() string {
return "data_gnss_" + time.Now().Format("200601")
}

18
consumers/consumerWJHP.go

@ -2,10 +2,10 @@ package consumers
import ( import (
"encoding/json" "encoding/json"
"goUpload/adaptors" "goInOut/adaptors"
"goUpload/consumers/WJHP" "goInOut/consumers/WJHP"
"goUpload/dbHelper" "goInOut/dbOperate"
"goUpload/monitors" "goInOut/monitors"
"log" "log"
"strings" "strings"
"time" "time"
@ -16,9 +16,9 @@ type consumerWJHP struct {
dataCache chan []byte dataCache chan []byte
//具体配置 //具体配置
Info WJHP.ConfigFile Info WJHP.ConfigFile
InMqtt *dbHelper.MqttHelper InMqtt *dbOperate.MqttHelper
InFileMonitor *monitors.FileMonitor InFileMonitor *monitors.FileMonitor
outHttpPost *dbHelper.HttpHelper outHttpPost *dbOperate.HttpHelper
} }
func (the *consumerWJHP) LoadConfigJson(cfgStr string) { func (the *consumerWJHP) LoadConfigJson(cfgStr string) {
@ -42,7 +42,7 @@ func (the *consumerWJHP) Initial(cfg string) error {
func (the *consumerWJHP) InputInitial() error { func (the *consumerWJHP) InputInitial() error {
the.dataCache = make(chan []byte, 200) the.dataCache = make(chan []byte, 200)
//mqtt数据入口 //mqtt数据入口
the.InMqtt = dbHelper.MqttInitial( the.InMqtt = dbOperate.MqttInitial(
the.Info.IOConfig.InMqtt.Host, the.Info.IOConfig.InMqtt.Host,
the.Info.IOConfig.InMqtt.Port, the.Info.IOConfig.InMqtt.Port,
the.Info.IOConfig.InMqtt.ClientId, the.Info.IOConfig.InMqtt.ClientId,
@ -58,7 +58,7 @@ func (the *consumerWJHP) InputInitial() error {
} }
func (the *consumerWJHP) OutputInitial() error { func (the *consumerWJHP) OutputInitial() error {
//数据出口 //数据出口
the.outHttpPost = &dbHelper.HttpHelper{ the.outHttpPost = &dbOperate.HttpHelper{
Url: the.Info.IOConfig.OutHttpPost.Url, Url: the.Info.IOConfig.OutHttpPost.Url,
} }
the.outHttpPost.Initial() the.outHttpPost.Initial()
@ -78,7 +78,7 @@ func (the *consumerWJHP) Work() {
} }
func (the *consumerWJHP) onData(Topic string, Msg string) { func (the *consumerWJHP) onData(Topic string, Msg string) {
if len(Msg) > 80 { if len(Msg) > 80 {
log.Printf("mqtt-recv:[%s]:%s ...", Topic, Msg[:100]) log.Printf("mqtt-recv:[%s]:%s ...", Topic, Msg[:80])
} }
var needPush []byte var needPush []byte
topicPrefixIndex := strings.LastIndex(Topic, "/") topicPrefixIndex := strings.LastIndex(Topic, "/")

38
dbHelper/apiServer.go

@ -1,38 +0,0 @@
package dbHelper
import (
"fmt"
"github.com/gin-gonic/gin"
"log"
"net/http"
"time"
)
type RouterFunc struct {
relativePath string //相对路由 如/gzm/data/upload
funcType string // 方法类型 如 post ,get
fun func(c *gin.Context) //方法
}
type ApiServerHelper struct {
Port uint16
RoutFun map[string]RouterFunc
}
func (the *ApiServerHelper) Initial() {
router := gin.Default()
for name, routerFunc := range the.RoutFun {
switch routerFunc.funcType {
case http.MethodGet:
router.GET(routerFunc.relativePath, routerFunc.fun)
case http.MethodPost:
router.GET(routerFunc.relativePath, routerFunc.fun)
default:
log.Printf("不支持的 [%s]方法类型 %s", routerFunc.relativePath, routerFunc.funcType)
continue
}
log.Printf("注册路由 %s,监听地址=%s", name, routerFunc.relativePath)
}
router.Run(fmt.Sprintf("0.0.0.0:%d", the.Port))
time.Sleep(time.Second * 1)
}

4
dbHelper/_kafka/consumerGroupHandler.go → dbOperate/_kafka/consumerGroupHandler.go

@ -48,7 +48,7 @@ func (h *ConsumerGroupHandler) SubscribeRaw(topic string, fun func(*sarama.Consu
func (h *ConsumerGroupHandler) decorateSubscribeString(handler func(string, string) bool) func(*sarama.ConsumerMessage) bool { func (h *ConsumerGroupHandler) decorateSubscribeString(handler func(string, string) bool) func(*sarama.ConsumerMessage) bool {
f := func(cm *sarama.ConsumerMessage) bool { f := func(cm *sarama.ConsumerMessage) bool {
msg := string(cm.Value) msg := string(cm.Value)
log.Printf("处理topic[%s]数据 offset=[%d]", cm.Topic, cm.Offset) //log.Printf("处理topic[%s]数据 offset=[%d]", cm.Topic, cm.Offset)
return handler(cm.Topic, msg) return handler(cm.Topic, msg)
} }
return f return f
@ -82,7 +82,7 @@ func (h *ConsumerGroupHandler) Worker() {
config := sarama.NewConfig() config := sarama.NewConfig()
config.Consumer.Return.Errors = false config.Consumer.Return.Errors = false
config.Version = sarama.V2_0_0_0 config.Version = sarama.V2_0_0_0
config.Consumer.Offsets.Initial = sarama.OffsetOldest config.Consumer.Offsets.Initial = sarama.OffsetNewest
config.Consumer.Offsets.AutoCommit.Enable = true config.Consumer.Offsets.AutoCommit.Enable = true
config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategyRoundRobin()} config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategyRoundRobin()}
group, err := sarama.NewConsumerGroup(h.brokers, h.groupId, config) group, err := sarama.NewConsumerGroup(h.brokers, h.groupId, config)

0
dbHelper/_kafka/kafkaHelper.go → dbOperate/_kafka/kafkaHelper.go

0
dbHelper/_kafka/kafka_test.go → dbOperate/_kafka/kafka_test.go

0
dbHelper/_kafka/producerHelper.go → dbOperate/_kafka/producerHelper.go

58
dbOperate/apiServerHelper.go

@ -0,0 +1,58 @@
package dbOperate
import (
"fmt"
"goInOut/config"
"log"
"net/http"
)
type ApiServerHelper struct {
mux *http.ServeMux
routes []config.Router
port uint
server http.Server
}
func NewApiServer(port uint, routes []config.Router) *ApiServerHelper {
return &ApiServerHelper{
mux: http.NewServeMux(),
routes: routes,
port: port,
}
}
func (the *ApiServerHelper) Initial() {
the.mux = http.NewServeMux()
// 创建 HTTP 服务器
the.server = http.Server{
Handler: the.mux,
Addr: fmt.Sprintf(":%d", the.port),
}
//the.routeRegister()
}
func (the *ApiServerHelper) Run() {
log.Printf("apiServer监听端口 %d", the.port)
the.server.ListenAndServe()
}
func (the *ApiServerHelper) routeRegister() {
for _, route := range the.routes {
the.mux.HandleFunc(route.Router, func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
s := fmt.Sprintf(`{"route":"%s","resp":"安全带状态应答"}`, route)
println("收到请求", route.Router)
fmt.Fprintf(w, s)
})
log.Printf("注册路由 %s", route)
}
}
func (the *ApiServerHelper) RouteRegister(route string, handler func(w http.ResponseWriter, r *http.Request)) {
the.mux.HandleFunc(route, handler)
log.Printf("注册路由 %s", route)
}

101
dbOperate/dbHelper.go

@ -0,0 +1,101 @@
package dbOperate
import (
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
"log"
"time"
)
const (
postgres = iota + 1
sqlite3
)
type DBHelper struct {
dbClient *sqlx.DB
dbType string
ConnectStr string
}
func NewDBHelper(dbType string, connectStr string) *DBHelper {
the := &DBHelper{}
switch dbType {
case "postgres":
fallthrough
case "mysql":
fallthrough
case "sqlite3":
fallthrough
case "有效的数据库类型":
the.dbType = dbType
the.ConnectStr = connectStr
default:
log.Panicf("不支持的数据库类型=> %s", dbType)
}
return the
}
// sqlite3 => connectStr := os.Getwd() + "/db/cz.db"
// mysql => "user:password@tcp(127.0.0.1:3306)/databaseName"
// pg => "host=192.168.10.64 port=5432 user=postgres password=123456 dbname=headscale sslmode=disable"
func (the *DBHelper) dbOpen() error {
var err error
tdb, err := sqlx.Open(the.dbType, the.ConnectStr)
if err != nil {
return err
}
if err = tdb.Ping(); err != nil {
return err
}
the.dbClient = tdb
return nil
}
func (the *DBHelper) Exec(dbRecordSQL string) error {
if the.dbClient == nil {
if openErr := the.dbOpen(); openErr != nil {
//logger.Info("[%s]数据库链接失败,err=%v\n", time.Now().Format("2006-01-02 15:04:05.000"), openErr)
return openErr
}
}
execResult, execErr := the.dbClient.Exec(dbRecordSQL)
defer the.dbClient.Close()
if execErr != nil {
return execErr
}
if n, err := execResult.RowsAffected(); n > 0 {
return nil
} else {
log.Printf("[%s]执行sql[%s]失败\n", time.Now().Format("2006-01-02 15:04:05.000"), dbRecordSQL)
return err
}
}
func (the *DBHelper) Query(dest any, sql string) error {
start := time.Now()
if the.dbClient == nil {
if err := the.dbOpen(); err != nil {
log.Printf("数据库链接失败:%s", err.Error())
return err
}
}
err := the.dbClient.Select(dest, sql)
if err != nil {
log.Printf("数据库查询失败:%s,\n sql=%s", err.Error(), sql)
}
durTime := time.Since(start).Seconds()
log.Printf("查询耗时:%v s", durTime)
return err
}
func (the *DBHelper) Close() error {
return the.Close()
}

37
dbOperate/db_test.go

@ -0,0 +1,37 @@
package dbOperate
import (
"goInOut/models"
"testing"
)
type res struct {
RLLYCJ string `json:"LLYCJ"`
RLLCacheMap string `json:"LLCacheMap"`
}
func TestRedis(t *testing.T) {
addr := "10.8.30.160:30379"
redis := NewRedisHelper("", addr)
key1 := "RLLYCJ"
//v := redis.Get(key1)
//println(v)
key2 := "RLLCacheMap"
res1 := res{}
v2 := redis.MGet(&res1, key1, key2)
println(v2)
}
func TestPg(t *testing.T) {
dbType := "postgres"
connectStr := "host=10.8.30.32 port=5432 user=postgres password=123 dbname=NBJJ1215-T sslmode=disable"
db := NewDBHelper(dbType, connectStr)
sql := "select * from t_agg_way"
var r []models.AggWay
db.Query(&r, sql)
println("===")
}

269
dbOperate/elasticsearchHelper.go

@ -0,0 +1,269 @@
package dbOperate
import (
"bytes"
"context"
"encoding/json"
"fmt"
elasticsearch6 "github.com/elastic/go-elasticsearch/v6"
"github.com/elastic/go-elasticsearch/v6/esapi"
"goInOut/models"
"io"
"log"
"strings"
)
type ESHelper struct {
addresses []string
//org string
esClient *elasticsearch6.Client
}
func NewESHelper(addresses []string, user, pwd string) *ESHelper {
es, _ := elasticsearch6.NewClient(elasticsearch6.Config{
Addresses: addresses,
Username: user,
Password: pwd,
})
res, err := es.Info()
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
log.Printf("链接到es[%s]info=%v", elasticsearch6.Version, res)
return &ESHelper{
addresses: addresses,
esClient: es,
}
}
func (the *ESHelper) SearchRaw(index, reqBody string) []models.HitRaw {
body := &bytes.Buffer{}
body.WriteString(reqBody)
response, err := the.esClient.Search(
the.esClient.Search.WithIndex(index),
the.esClient.Search.WithBody(body),
)
defer response.Body.Close()
if err != nil {
return nil
}
r := models.EsRawResp{}
// Deserialize the response into a map.
if err := json.NewDecoder(response.Body).Decode(&r); err != nil {
log.Fatalf("Error parsing the response body: %s", err)
}
return r.Hits.Hits
}
func (the *ESHelper) Search(index, reqBody string) {
body := &bytes.Buffer{}
body.WriteString(reqBody)
response, err := the.esClient.Search(
the.esClient.Search.WithIndex(index),
the.esClient.Search.WithBody(body),
)
if err != nil {
//return nil, err
}
log.Println(response.Status())
var r map[string]any
// Deserialize the response into a map.
if err := json.NewDecoder(response.Body).Decode(&r); err != nil {
log.Fatalf("Error parsing the response body: %s", err)
}
// Print the response status, number of results, and request duration.
log.Printf(
"[%s] %d hits; took: %dms",
response.Status(),
int(r["hits"].(map[string]any)["total"].(float64)),
int(r["took"].(float64)),
)
for _, hit := range r["hits"].(map[string]any)["hits"].([]any) {
source := hit.(map[string]any)["_source"]
log.Printf(" * ID=%s, %s", hit.(map[string]any)["_id"], source)
}
log.Println(strings.Repeat("=", 37))
}
func (the *ESHelper) request(index, reqBody string) (map[string]any, error) {
// Set up the request object.
req := esapi.IndexRequest{
Index: index,
//DocumentID: strconv.Itoa(i + 1),
Body: strings.NewReader(reqBody),
Refresh: "true",
}
// Perform the request with the client.
res, err := req.Do(context.Background(), the.esClient)
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
defer res.Body.Close()
var r map[string]any
if res.IsError() {
log.Printf("[%s] Error indexing document ID=%d", res.Status(), 0)
} else {
// Deserialize the response into a map.
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
log.Printf("Error parsing the response body: %s", err)
} else {
// Print the response status and indexed document version.
log.Printf("[%s] %s; version=%d", res.Status(), r["result"], int(r["_version"].(float64)))
}
}
return r, err
}
func (the *ESHelper) searchRaw(index, reqBody string) (models.IotaData, error) {
respmap, err := the.request(index, reqBody)
if respmap != nil {
}
iotaDatas := models.IotaData{}
return iotaDatas, err
}
func (the *ESHelper) searchThemes(index, reqBody string) (models.EsThemeResp, error) {
body := &bytes.Buffer{}
body.WriteString(reqBody)
response, err := the.esClient.Search(
the.esClient.Search.WithIndex(index),
the.esClient.Search.WithBody(body),
)
defer response.Body.Close()
if err != nil {
//return nil, err
}
log.Println(response.Status())
r := models.EsThemeResp{}
// Deserialize the response into a map.
if err := json.NewDecoder(response.Body).Decode(&r); err != nil {
log.Fatalf("Error parsing the response body: %s", err)
}
return r, err
}
func (the *ESHelper) SearchLatestStationData(index string, sensorId int) (models.EsTheme, error) {
//sensorId := 178
queryBody := fmt.Sprintf(`{
"size": 1,
"query": {
"term": {
"sensor": {
"value": %d
}
}
},
"sort": [
{
"collect_time": {
"order": "desc"
}
}
]
}`, sensorId)
//index := "go_native_themes"
themes, err := the.searchThemes(index, queryBody)
var theme models.EsTheme
if len(themes.Hits.Hits) > 0 {
theme = themes.Hits.Hits[0].Source
}
return theme, err
}
func (the *ESHelper) BulkWrite(index, reqBody string) {
body := &bytes.Buffer{}
body.WriteString(reqBody)
bulkRequest := esapi.BulkRequest{
Index: index,
Body: body,
DocumentType: "_doc",
}
res, err := bulkRequest.Do(context.Background(), the.esClient)
defer res.Body.Close()
if err != nil {
log.Panicf("es 写入[%s],err=%s", index, err.Error())
return
}
respBody, _ := io.ReadAll(res.Body)
if res.StatusCode != 200 && res.StatusCode != 201 {
log.Panicf("es 写入失败,err=%s \n body=%s", string(respBody), reqBody)
}
//log.Printf("es 写入[%s],完成,res=%s ", index, respBody)
}
func (the *ESHelper) BulkWriteWithLog(index, reqBody string) {
body := &bytes.Buffer{}
body.WriteString(reqBody)
bulkRequest := esapi.BulkRequest{
Index: index,
Body: body,
DocumentType: "_doc",
}
res, err := bulkRequest.Do(context.Background(), the.esClient)
defer res.Body.Close()
if err != nil {
log.Panicf("es 写入[%s],err=%s", index, err.Error())
return
}
respBody, _ := io.ReadAll(res.Body)
if res.StatusCode != 200 && res.StatusCode != 201 {
log.Panicf("es 写入失败,err=%s \n body=%s", string(respBody), reqBody)
}
log.Printf("es 写入[%s],完成,res=%s ", index, respBody)
}
func (the *ESHelper) BulkWriteRaws2Es(index string, raws []models.EsRaw) {
//log 测试用
const logTagDeviceId = "91da4d1f-fbc7-4dad-bedd-f8ff05c0e0e0"
logTag := false
body := strings.Builder{}
for _, raw := range raws {
// scala => val id = UUID.nameUUIDFromBytes(s"${v.deviceId}-${v.acqTime.getMillis}".getBytes("UTF-8")).toString
source, _ := json.Marshal(raw)
_id := raw.IotaDevice
s := fmt.Sprintf(
`{"index": {"_index": "%s","_id": "%s"}}
%s
`, index, _id, source)
body.WriteString(s)
if raw.IotaDevice == logTagDeviceId {
log.Printf("BulkWriteRaws2Es 标记设备数据 [%s] %s ", logTagDeviceId, string(s))
logTag = true
}
}
if logTag { //追踪数据
the.BulkWriteWithLog(index, body.String())
} else {
the.BulkWrite(index, body.String())
}
}
func (the *ESHelper) BulkWriteRaws2EsLast(index string, raws []models.EsRaw) {
body := strings.Builder{}
for _, raw := range raws {
source, _ := json.Marshal(raw)
_id := raw.IotaDevice
s := fmt.Sprintf(
`{"index": {"_index": "%s","_id": "%s"}}
%s
`, index, _id, source)
body.WriteString(s)
}
the.BulkWrite(index, body.String())
}
func (the *ESHelper) Close() {
}

2
dbHelper/fileSaveHelper.go → dbOperate/fileSaveHelper.go

@ -1,4 +1,4 @@
package dbHelper package dbOperate
import ( import (
"io" "io"

45
dbHelper/httpHelper.go → dbOperate/httpHelper.go

@ -1,4 +1,4 @@
package dbHelper package dbOperate
import ( import (
"bytes" "bytes"
@ -8,9 +8,9 @@ import (
"log" "log"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/url"
"os" "os"
"strings" "strings"
"time"
) )
type HttpHelper struct { type HttpHelper struct {
@ -23,8 +23,6 @@ type HttpHelper struct {
func (the *HttpHelper) Initial() { func (the *HttpHelper) Initial() {
the.client = http.Client{} the.client = http.Client{}
time.Sleep(time.Second * 1)
} }
func (the *HttpHelper) HttpGet(queryBody string) string { func (the *HttpHelper) HttpGet(queryBody string) string {
url := the.Url url := the.Url
@ -49,6 +47,8 @@ func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string]
for k, v := range headerMap { for k, v := range headerMap {
req.Header.Set(k, v) req.Header.Set(k, v)
} }
//取消证书校验,避免证书过期问题
client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
@ -93,6 +93,37 @@ func (the *HttpHelper) PublishWithHeader(messageBytes []byte, headers map[string
} }
return resp, err return resp, err
} }
func (the *HttpHelper) HttpPostWithParams(urlStr, queryBody string, params map[string]string) (string, error) {
tr := &http.Transport{
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
UrlParams := url.Values{}
for k, v := range params {
UrlParams.Set(k, v)
}
targetUrl, _ := url.ParseRequestURI(urlStr)
targetUrl.RawQuery = UrlParams.Encode()
req, err := http.NewRequest("POST", targetUrl.String(), strings.NewReader(queryBody))
req.Header.Set("Content-Type", "application/json")
log.Printf("http post 开始请求,%s", targetUrl)
resp, err := client.Do(req)
if err != nil {
fmt.Println("请求POST异常 ", err, resp)
return "", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("请求ReadAll异常 ", err, resp)
return "", err
}
return string(body), err
}
// 静态方法 // 静态方法
func HttpGet(url string, queryBody string) string { func HttpGet(url string, queryBody string) string {
@ -109,6 +140,7 @@ func HttpGet(url string, queryBody string) string {
return string(body) return string(body)
} }
// 静态方法
func HttpPost(url string, queryBody string) (string, error) { func HttpPost(url string, queryBody string) (string, error) {
client := &http.Client{} client := &http.Client{}
req, err := http.NewRequest("POST", url, strings.NewReader(queryBody)) req, err := http.NewRequest("POST", url, strings.NewReader(queryBody))
@ -129,6 +161,7 @@ func HttpPost(url string, queryBody string) (string, error) {
return string(body), err return string(body), err
} }
// 静态方法
func HttpPostWithHeader(url string, queryBody string, headers map[string]string) (string, error) { func HttpPostWithHeader(url string, queryBody string, headers map[string]string) (string, error) {
tr := &http.Transport{ tr := &http.Transport{
DisableKeepAlives: true, DisableKeepAlives: true,
@ -160,6 +193,7 @@ func HttpPostWithHeader(url string, queryBody string, headers map[string]string)
return string(body), err return string(body), err
} }
// 静态方法
func HttpPostFormDataWithHeader(url string, queryBody string, headers map[string]string) (string, error) { func HttpPostFormDataWithHeader(url string, queryBody string, headers map[string]string) (string, error) {
tr := &http.Transport{ tr := &http.Transport{
DisableKeepAlives: true, DisableKeepAlives: true,
@ -173,7 +207,7 @@ func HttpPostFormDataWithHeader(url string, queryBody string, headers map[string
req.Header.Add(k, v) req.Header.Add(k, v)
} }
fmt.Printf("http post 开始请求,%s,\n,%s \n", url, req) fmt.Printf("http post 开始请求,%s,\n,%v \n", url, req)
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
fmt.Println("请求POST异常 ", err, resp) fmt.Println("请求POST异常 ", err, resp)
@ -191,6 +225,7 @@ func HttpPostFormDataWithHeader(url string, queryBody string, headers map[string
return string(body), err return string(body), err
} }
// 静态方法
func UploadFile(url string, headers map[string]string, bodyParams map[string]string, fileName string) ([]byte, error) { func UploadFile(url string, headers map[string]string, bodyParams map[string]string, fileName string) ([]byte, error) {
body := new(bytes.Buffer) body := new(bytes.Buffer)
// 创建 multipart writer // 创建 multipart writer

4
dbHelper/influxDBHelper.go → dbOperate/influxDBHelper.go

@ -1,4 +1,4 @@
package dbHelper package dbOperate
import ( import (
"context" "context"
@ -85,7 +85,7 @@ from(bucket:"%v")
} }
// check for an error // check for an error
if result.Err() != nil { if result.Err() != nil {
fmt.Printf("query parsing error: %\n", result.Err().Error()) fmt.Printf("query parsing error: %s \n", result.Err().Error())
} }
} else { } else {
log.Printf("influxDB 查询异常 %s", err.Error()) log.Printf("influxDB 查询异常 %s", err.Error())

11
dbHelper/mqttHelper.go → dbOperate/mqttHelper.go

@ -1,4 +1,4 @@
package dbHelper package dbOperate
import ( import (
"crypto/tls" "crypto/tls"
@ -25,7 +25,7 @@ type subscribeCall struct {
} }
func (the *MqttHelper) reConn2Subscribe(client mqtt.Client) { func (the *MqttHelper) reConn2Subscribe(client mqtt.Client) {
log.Println("mqtt触发重连后的重订阅") log.Println("mqtt触发链接后的自动订阅")
for _, call := range the.subscribeCalls { for _, call := range the.subscribeCalls {
the.Subscribe(call.topic, call.f) the.Subscribe(call.topic, call.f)
} }
@ -83,19 +83,18 @@ func NewTlsConfig(sslPath string) *tls.Config {
func (the *MqttHelper) Publish(topic string, messageBytes []byte) { func (the *MqttHelper) Publish(topic string, messageBytes []byte) {
if the.client != nil { if the.client != nil {
token := the.client.Publish(topic, 0, false, messageBytes) token := the.client.Publish(topic, 1, false, messageBytes)
token.Wait() token.Wait()
//the.client.Disconnect(200) //the.client.Disconnect(200)
fmt.Printf("[%s] -[%v]推送Msg 长度=%d \n", topic, the.client.IsConnected(), len(messageBytes)) log.Printf("[%s] -[%v]推送Msg 长度=%d \n", topic, the.client.IsConnected(), len(messageBytes))
} }
} }
func (the *MqttHelper) Subscribe(topic string, myCallback func(topic string, callMsg string)) { func (the *MqttHelper) Subscribe(topic string, myCallback func(topic string, callMsg string)) {
var callback mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) { var callback mqtt.MessageHandler = func(client mqtt.Client, msg mqtt.Message) {
log.Printf("收到数据 [%v] TOPIC: %s,MSGLen: %v", msg.MessageID(), msg.Topic(), len(msg.Payload())) //log.Printf("收到数据 [%v] TOPIC: %s,MSGLen: %v", msg.MessageID(), msg.Topic(), len(msg.Payload()))
Msg := string(msg.Payload()) Msg := string(msg.Payload())
myCallback(msg.Topic(), Msg) myCallback(msg.Topic(), Msg)
//log.Println("消息处理结束")
} }
log.Printf("=================开始订阅 %s [%s]=================", the.Host, topic) log.Printf("=================开始订阅 %s [%s]=================", the.Host, topic)
t := the.client.Subscribe(topic, 1, callback) t := the.client.Subscribe(topic, 1, callback)

133
dbOperate/redisHelper.go

@ -0,0 +1,133 @@
package dbOperate
import (
"context"
"encoding/json"
"errors"
"github.com/redis/go-redis/v9"
"log"
"time"
)
type RedisHelper struct {
rdb redis.UniversalClient
isReady bool
ctx context.Context
}
func NewRedisHelper(master string, address ...string) *RedisHelper {
r := &RedisHelper{ctx: context.Background()}
r.InitialCluster(master, address...)
return r
}
func (the *RedisHelper) InitialCluster(master string, address ...string) {
the.rdb = redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: address,
MasterName: master,
})
log.Printf("redis 初始化完成 %s", address)
the.isReady = true
}
func (the *RedisHelper) Get(key string) string {
val, err := the.rdb.Get(the.ctx, key).Result()
if errors.Is(err, redis.Nil) {
log.Printf("%s does not exist", key)
} else if err != nil {
panic(err)
} else {
//log.Printf("get key => %s =%s", key, val)
}
return val
}
func (the *RedisHelper) GetObj(keys string, addr any) error {
err := the.rdb.Get(the.ctx, keys).Scan(addr)
if errors.Is(err, redis.Nil) {
log.Printf("%s does not exist", keys)
} else if err != nil {
es := err.Error()
log.Printf("err=%s ", es)
return err
}
return nil
}
func (the *RedisHelper) SetObj(keys string, obj any) error {
rs, err := the.rdb.Set(the.ctx, keys, obj, time.Minute*5).Result()
log.Printf("rs=%s ", rs)
if err != nil {
log.Printf("err=%s ", err.Error())
}
return err
}
func (the *RedisHelper) GetLRange(keys string, addr any) error {
err := the.rdb.LRange(the.ctx, keys, 0, -1).ScanSlice(addr)
if errors.Is(err, redis.Nil) {
log.Printf("%s does not exist", keys)
} else if err != nil {
log.Printf("err=%s ", err.Error())
return err
}
return nil
}
func (the *RedisHelper) MGet(addr any, keys ...string) error {
err := the.rdb.MGet(the.ctx, keys...).Scan(addr)
if errors.Is(err, redis.Nil) {
log.Printf("%s does not exist", keys)
} else if err != nil {
log.Printf("err=%s ", err.Error())
return err
}
return err
}
func (the *RedisHelper) MGetObj(addr any, keys ...string) error {
err := the.rdb.MGet(the.ctx, keys...).Scan(addr)
if errors.Is(err, redis.Nil) {
log.Printf("%s does not exist", keys)
} else if err != nil {
log.Printf("err=%s ", err.Error())
return err
}
return nil
}
func (the *RedisHelper) HMGetObj(addr any, key, field string) error {
rp, err := the.rdb.HMGet(the.ctx, key, field).Result()
if errors.Is(err, redis.Nil) {
log.Printf("%s does not exist", key)
return err
} else if err != nil {
log.Printf("err=%s ", err.Error())
return err
}
for _, i := range rp {
if v, ok := i.(string); ok {
err := json.Unmarshal([]byte(v), addr)
if err != nil {
return err
}
}
}
//todo scan有问题 后续待排查
return nil
//err := the.rdb.HMGet(the.ctx, key, field).Scan(addr)
//if errors.Is(err, redis.Nil) {
// log.Printf("%s does not exist", key)
//} else if err != nil {
// log.Printf("err=%s ", err.Error())
// return err
//}
//return nil
}
func (the *RedisHelper) SRem(key string, members ...string) int64 {
return the.rdb.SRem(the.ctx, key, members).Val()
}
func (the *RedisHelper) SAdd(key string, members ...string) int64 {
return the.rdb.SAdd(the.ctx, key, members).Val()
}

2
dbHelper/udpHelper.go → dbOperate/udpHelper.go

@ -1,4 +1,4 @@
package dbHelper package dbOperate
import ( import (
"fmt" "fmt"

37
go.mod

@ -1,12 +1,17 @@
module goUpload module goInOut
go 1.21 go 1.23
require ( require (
github.com/IBM/sarama v1.43.3 github.com/IBM/sarama v1.43.3
github.com/eclipse/paho.mqtt.golang v1.4.3 github.com/eclipse/paho.mqtt.golang v1.4.3
github.com/gin-gonic/gin v1.9.1 github.com/elastic/go-elasticsearch/v6 v6.8.10
github.com/go-sql-driver/mysql v1.8.1
github.com/influxdata/influxdb-client-go/v2 v2.13.0 github.com/influxdata/influxdb-client-go/v2 v2.13.0
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.24
github.com/redis/go-redis/v9 v9.7.0
github.com/robfig/cron/v3 v3.0.1 github.com/robfig/cron/v3 v3.0.1
golang.org/x/text v0.17.0 golang.org/x/text v0.17.0
google.golang.org/protobuf v1.31.0 google.golang.org/protobuf v1.31.0
@ -14,20 +19,14 @@ require (
) )
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/bytedance/sonic v1.10.0-rc3 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/eapache/go-resiliency v1.7.0 // indirect github.com/eapache/go-resiliency v1.7.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect github.com/eapache/queue v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.1 // indirect github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect
@ -40,25 +39,11 @@ require (
github.com/jcmturner/gofork v1.7.6 // indirect github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oapi-codegen/runtime v1.0.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.4.0 // indirect
golang.org/x/crypto v0.26.0 // indirect golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

91
go.sum

@ -1,23 +1,22 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/IBM/sarama v1.43.3 h1:Yj6L2IaNvb2mRBop39N7mmJAHBVY3dTPncr3qGVkxPA= github.com/IBM/sarama v1.43.3 h1:Yj6L2IaNvb2mRBop39N7mmJAHBVY3dTPncr3qGVkxPA=
github.com/IBM/sarama v1.43.3/go.mod h1:FVIRaLrhK3Cla/9FfRF5X9Zua2KpS3SYIXxhac1H+FQ= github.com/IBM/sarama v1.43.3/go.mod h1:FVIRaLrhK3Cla/9FfRF5X9Zua2KpS3SYIXxhac1H+FQ=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bytedance/sonic v1.10.0-rc3 h1:uNSnscRapXTwUgTyOF0GVljYD08p9X/Lbr9MweSV3V0= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bytedance/sonic v1.10.0-rc3/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo=
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA= github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA=
github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws= github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws=
@ -26,30 +25,17 @@ github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik= github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik=
github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE= github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE=
github.com/elastic/go-elasticsearch/v6 v6.8.10 h1:2lN0gJ93gMBXvkhwih5xquldszpm8FlUwqG5sPzr6a8=
github.com/elastic/go-elasticsearch/v6 v6.8.10/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k=
github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
@ -79,64 +65,40 @@ github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh6
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/oapi-codegen/runtime v1.0.0 h1:P4rqFX5fMFWqRzY9M/3YF9+aPSPPB06IzP2P7oOxrWo= github.com/oapi-codegen/runtime v1.0.0 h1:P4rqFX5fMFWqRzY9M/3YF9+aPSPPB06IzP2P7oOxrWo=
github.com/oapi-codegen/runtime v1.0.0/go.mod h1:LmCUMQuPB4M/nLXilQXhHw+BLZdDb18B34OO356yJ/A= github.com/oapi-codegen/runtime v1.0.0/go.mod h1:LmCUMQuPB4M/nLXilQXhHw+BLZdDb18B34OO356yJ/A=
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc=
golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
@ -161,9 +123,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@ -184,13 +143,9 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

18
logs/logInfo.log

@ -1,18 +0,0 @@
2024/10/17 11:33:20.528503 main.go:24: =================log start=================
2024/10/17 11:33:20.540075 main.go:25: ==>
2024/10/17 11:33:20.540075 main.go:30: 进程启动
2024/10/17 11:33:20.540075 init.go:20: 加载配置文件:config_魏家滑坡_视觉位移.json
2024/10/17 11:33:20.540592 init.go:20: 加载配置文件:弃用备份
2024/10/17 11:33:20.540592 init.go:22: 非文件[弃用备份]跳过
2024/10/17 11:33:22.546148 mqttHelper.go:48: mqtt连接状态异常 tcp://10.8.30.160:1883(u:wjhp-sjwy-upload,p:123456,cid:wjhp-sjwy-upload) [err=network Error : dial tcp 10.8.30.160:1883: connectex: No connection could be made because the target machine actively refused it.]
2024/10/17 11:33:22.546148 mqttHelper.go:49: mqtt重连,30s后尝试,剩余次数=3
2024/10/17 11:33:53.265276 main.go:24: =================log start=================
2024/10/17 11:33:53.285624 main.go:25: ==>
2024/10/17 11:33:53.285624 main.go:30: 进程启动
2024/10/17 11:33:53.286127 init.go:20: 加载配置文件:config_魏家滑坡_视觉位移.json
2024/10/17 11:33:53.286698 init.go:20: 加载配置文件:弃用备份
2024/10/17 11:33:53.286698 init.go:22: 非文件[弃用备份]跳过
2024/10/17 11:33:53.289208 mqttHelper.go:28: mqtt触发重连后的重订阅
2024/10/17 11:33:55.290027 mqttHelper.go:100: =================开始订阅 10.8.30.160 [/fs-flexometer/admin123]=================
2024/10/17 11:34:12.251376 mqttHelper.go:28: mqtt触发重连后的重订阅
2024/10/17 11:34:12.251376 mqttHelper.go:100: =================开始订阅 10.8.30.160 [/fs-flexometer/admin123]=================

5
main.go

@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"goUpload/config" "goInOut/config"
"goUpload/consumers" "goInOut/consumers"
"gopkg.in/natefinch/lumberjack.v2" "gopkg.in/natefinch/lumberjack.v2"
"io" "io"
"log" "log"
@ -22,7 +22,6 @@ func init() {
log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds) log.SetFlags(log.LstdFlags | log.Lshortfile | log.Lmicroseconds)
log.SetOutput(multiWriter) log.SetOutput(multiWriter)
log.Println("=================log start=================") log.Println("=================log start=================")
log.Println("==>")
} }
func main() { func main() {

25
main_test.go

@ -4,14 +4,17 @@ import (
"bytes" "bytes"
"crypto/rc4" "crypto/rc4"
"encoding/hex" "encoding/hex"
"goUpload/utils" "fmt"
"goInOut/utils"
"log" "log"
"sync"
"testing" "testing"
"text/template" "text/template"
"time" "time"
) )
func TestCRC16CCITT(t *testing.T) { func TestCRC16CCITT(t *testing.T) {
hexs := "0a16080718a8ea8fab06620c0a0471bd54c11204e01d8641" hexs := "0a16080718a8ea8fab06620c0a0471bd54c11204e01d8641"
hexs = "0a2f080210f8b6d5d01218b395bffec3313a1e0a08a75fed41a75fed41120892c5d64292c5d6421a08f6c8a74379c9a743" hexs = "0a2f080210f8b6d5d01218b395bffec3313a1e0a08a75fed41a75fed41120892c5d64292c5d6421a08f6c8a74379c9a743"
Hexdata, _ := hex.DecodeString(hexs) Hexdata, _ := hex.DecodeString(hexs)
@ -50,3 +53,23 @@ func TestTemplate(t *testing.T) {
bs := b.String() bs := b.String()
log.Println(bs) 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
})
}

7
models/GDND2LA.go

@ -0,0 +1,7 @@
package models
type GDND2luAn struct {
Id string `json:"id"`
Time string `json:"time"`
Value map[string][]float32 `json:"value"`
}

40
models/IotaData.go

@ -0,0 +1,40 @@
package models
import (
"time"
)
type IotaData struct {
UserId string `json:"userId"`
ThingId string `json:"thingId"`
DimensionId string `json:"dimensionId"`
DimCapId string `json:"dimCapId"`
CapId string `json:"capId"`
DeviceId string `json:"deviceId"`
ScheduleId string `json:"scheduleId"`
TaskId string `json:"taskId"`
JobId int `json:"jobId"`
JobRepeatId int `json:"jobRepeatId"`
TriggerTime time.Time `json:"triggerTime"`
RealTime time.Time `json:"realTime"`
FinishTime time.Time `json:"finishTime"`
Seq int `json:"seq"`
Released bool `json:"released"`
Data Data `json:"data"`
}
type Data struct {
Type int `json:"type"`
Data map[string]any `json:"data"`
Result struct {
Code int `json:"code"`
Msg string `json:"msg"`
Detail string `json:"detail"`
ErrTimes int `json:"errTimes"`
Dropped bool `json:"dropped"`
} `json:"result"`
}
func (the *Data) Success() bool {
return the.Result.Code == 0
}

6
models/aggWay.go

@ -0,0 +1,6 @@
package models
type AggWay struct {
Id int64 `db:"id"`
Name string `db:"name"`
}

6
models/constant.go

@ -0,0 +1,6 @@
package models
const (
RawTypeVib = "vib"
RawTypeDiag = "diag"
)

107
models/deviceData.go

@ -0,0 +1,107 @@
package models
import (
"time"
)
type DeviceData struct {
DeviceId string
Name string
ThingId string
StructId int
TaskId string
AcqTime time.Time
RealTime time.Time
ErrCode int
Raw map[string]any
RawUnit map[string]string
DeviceInfo DeviceInfo
DimensionId string
//数据类型 常见有 comm="" ,RawTypeVib="vib"
DataType string
}
func (d *DeviceData) GetVibrationData() VibrationData {
vibData := VibrationData{}
if d.DataType == RawTypeVib {
if v, ok := d.Raw["filterFreq"]; ok {
if vv, ok := v.(float64); ok {
vibData.FilterFreq = vv
}
}
if v, ok := d.Raw["sampleFreq"]; ok {
if vv, ok := v.(float64); ok {
vibData.SampleFreq = vv
}
}
if v, ok := d.Raw["gainAmplifier"]; ok {
if vv, ok := v.(float64); ok {
vibData.GainAmplifier = byte(vv)
}
}
if v, ok := d.Raw["version"]; ok {
if vv, ok := v.(float64); ok {
vibData.Version = byte(vv)
}
}
if v, ok := d.Raw["triggerType"]; ok {
if vv, ok := v.(float64); ok {
vibData.TriggerType = byte(vv)
}
}
if v, ok := d.Raw["physicalvalue"]; ok {
if vSlice, ok := v.([]any); ok {
for _, vObj := range vSlice {
if vv, ok := vObj.(float64); ok {
vibData.Data = append(vibData.Data, vv)
}
}
}
//去直流
if len(vibData.Data) > 0 {
avg := func(dataArray []float64) float64 {
sum := 0.0
for _, f := range dataArray {
sum += f
}
return sum / float64(len(dataArray))
}(vibData.Data) //common_calc.GetAvg(vibData.Data)
for i := 0; i < len(vibData.Data); i++ {
vibData.Data[i] = vibData.Data[i] - avg
}
}
}
}
return vibData
}
// VibrationData 振动数据
type VibrationData struct {
Version byte
SampleFreq float64
FilterFreq float64
GainAmplifier byte
TriggerType byte
Data []float64 // 原始波形数据
Unit string
}
func (v *VibrationData) FormatParams() map[string]any {
return map[string]any{
"sampleFreq": v.SampleFreq,
"version": v.Version,
"filterFreq": v.FilterFreq,
"gainAmplifier": v.GainAmplifier,
"triggerType": v.TriggerType,
}
}

70
models/deviceInfo.go

@ -0,0 +1,70 @@
package models
import (
"encoding/json"
"fmt"
"time"
)
type DeviceInfo struct {
Id string `json:"id"`
Name string `json:"name"`
Structure Structure `json:"structure"`
DeviceMeta DeviceMeta `json:"device_meta"`
RefreshTime time.Time
}
type DeviceMeta struct {
Id string `json:"id"`
Name string `json:"name"`
Model string `json:"model"`
Properties []IotaProperty `json:"properties"`
Capabilities []IotaCapability `json:"capabilities"`
}
func (m *DeviceMeta) GetOutputProps() (out map[string]string) {
out = make(map[string]string)
if len(m.Capabilities) == 0 {
return
}
for _, property := range m.Capabilities[0].Properties {
info := fmt.Sprintf("%s(%s)", property.ShowName, property.Unit)
out[property.Name] = info
}
return
}
func (m *DeviceMeta) GetOutputUnit() (out map[string]string) {
out = make(map[string]string)
if len(m.Capabilities) == 0 {
return
}
for _, property := range m.Capabilities[0].Properties {
out[property.Name] = property.Unit
}
return
}
// redis序列化
func (m *DeviceMeta) MarshalBinary() (data []byte, err error) {
return json.Marshal(m)
}
// redis序列化
func (m *DeviceMeta) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, m)
}
type IotaCapability struct {
CapabilityCategoryId int `json:"capabilityCategoryId"`
Id string `json:"id"`
Name string `json:"name"`
Properties []IotaProperty `json:"properties"`
}
type IotaProperty struct {
Category string `json:"category"`
Name string `json:"name"`
ShowName string `json:"showName"`
Unit string `json:"unit"`
}

37
models/esRaw.go

@ -0,0 +1,37 @@
package models
import "time"
type EsRaw struct {
StructId int `json:"structId"`
IotaDeviceName string `json:"iota_device_name"`
Data map[string]any `json:"data"`
CollectTime string `json:"collect_time"`
Meta map[string]string `json:"meta"`
IotaDevice string `json:"iota_device"`
CreateTime time.Time `json:"create_time"`
}
type EsRawResp struct {
Took int `json:"took"`
TimedOut bool `json:"timed_out"`
Shards struct {
Total int `json:"total"`
Successful int `json:"successful"`
Skipped int `json:"skipped"`
Failed int `json:"failed"`
} `json:"_shards"`
Hits struct {
Total int `json:"total"`
MaxScore float64 `json:"max_score"`
Hits []HitRaw `json:"hits"`
} `json:"hits"`
}
type HitRaw struct {
Index string `json:"_index"`
Type string `json:"_type"`
Id string `json:"_id"`
Score float64 `json:"_score"`
Source EsRaw `json:"_source"`
}

41
models/esTheme.go

@ -0,0 +1,41 @@
package models
import "time"
type EsTheme struct {
SensorName string `json:"sensor_name"`
FactorName string `json:"factor_name"`
FactorProtoCode string `json:"factor_proto_code"`
Data map[string]any `json:"data"`
FactorProtoName string `json:"factor_proto_name"`
Factor int `json:"factor"`
CollectTime time.Time `json:"collect_time"`
Sensor int `json:"sensor"`
Structure int `json:"structure"`
IotaDevice []string `json:"iota_device"`
CreateTime time.Time `json:"create_time"`
}
type EsThemeResp struct {
Took int `json:"took"`
TimedOut bool `json:"timed_out"`
Shards struct {
Total int `json:"total"`
Successful int `json:"successful"`
Skipped int `json:"skipped"`
Failed int `json:"failed"`
} `json:"_shards"`
Hits struct {
Total int `json:"total"`
MaxScore float64 `json:"max_score"`
Hits []HitTheme `json:"hits"`
} `json:"hits"`
}
type HitTheme struct {
Index string `json:"_index"`
Type string `json:"_type"`
Id string `json:"_id"`
Score float64 `json:"_score"`
Source EsTheme `json:"_source"`
}

25
models/iotaDevice.go

@ -0,0 +1,25 @@
package models
import (
"encoding/json"
)
type IotaDevice struct {
Id string `json:"id"`
Name string `json:"name"`
Properties string `json:"properties"`
DeviceMetaId string `json:"deviceMetaId"`
ThingId string `json:"thingId"`
DeviceMeta DeviceMeta `json:"deviceMeta"`
}
// redis序列化
func (m *IotaDevice) MarshalBinary() (data []byte, err error) {
return json.Marshal(m)
}
// redis序列化
func (m *IotaDevice) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, m)
}

8
models/savoirTheme.go

@ -47,11 +47,3 @@ type SavoirTheme struct {
DataEmpty bool `json:"dataEmpty"` DataEmpty bool `json:"dataEmpty"`
RawAgg bool `json:"rawAgg"` RawAgg bool `json:"rawAgg"`
} }
type Structure struct {
ThingId string `json:"thingId"`
Id int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
OrgId int `json:"orgId"`
}

31
models/structure.go

@ -0,0 +1,31 @@
package models
import (
"encoding/json"
)
type Structure struct {
ThingId string `json:"thingId"`
Id int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
OrgId int `json:"orgId"`
}
type ThingStruct struct {
ThingId string `json:"thingId"`
Id int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
OrgId int `json:"orgId"`
}
// redis序列化
func (m *ThingStruct) MarshalBinary() (data []byte, err error) {
return json.Marshal(m)
}
// redis序列化
func (m *ThingStruct) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, m)
}

14
monitors/commonMonitor.go

@ -0,0 +1,14 @@
package monitors
type CommonMonitor struct {
*MonitorHelper
}
func (the *CommonMonitor) RegisterFun(fun func()) {
the.registerFun(fun)
}
func (the *CommonMonitor) Start() {
the.initial()
the.monitorStart()
}

4
monitors/httpMonitor.go

@ -1,9 +1,9 @@
package monitors package monitors
import "goUpload/dbHelper" import "goInOut/dbOperate"
type HttpMonitor struct { type HttpMonitor struct {
HttpClient *dbHelper.HttpHelper HttpClient *dbOperate.HttpHelper
*MonitorHelper *MonitorHelper
} }

6
testUnit/mqttPush_test.go

@ -2,8 +2,8 @@ package testUnit
import ( import (
"encoding/hex" "encoding/hex"
"goUpload/consumers/CQZG/protoFiles" "goInOut/consumers/CQZG/protoFiles"
"goUpload/dbHelper" "goInOut/dbOperate"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"log" "log"
"testing" "testing"
@ -34,7 +34,7 @@ func TestMqttUpload(t *testing.T) {
hexStr := hex.EncodeToString(dataStr) hexStr := hex.EncodeToString(dataStr)
log.Println(err, hexStr) log.Println(err, hexStr)
mqHelpers := dbHelper.MqttHelper{ mqHelpers := dbOperate.MqttHelper{
Host: "mqtt.datahub.anxinyun.cn", Host: "mqtt.datahub.anxinyun.cn",
Port: 1883, Port: 1883,
ClientId: "lzwjdq500101-lk", ClientId: "lzwjdq500101-lk",

4
testUnit/mqttRecv_test.go

@ -1,14 +1,14 @@
package testUnit package testUnit
import ( import (
"goUpload/dbHelper" "goInOut/dbOperate"
"log" "log"
"testing" "testing"
"time" "time"
) )
func TestMqttRecv(t *testing.T) { func TestMqttRecv(t *testing.T) {
mqHelpers := dbHelper.MqttHelper{ mqHelpers := dbOperate.MqttHelper{
Host: "10.8.30.160", Host: "10.8.30.160",
Port: 30883, Port: 30883,
ClientId: "lzwjdq500101-lk", ClientId: "lzwjdq500101-lk",

4
testUnit/udpPush_test.go

@ -1,14 +1,14 @@
package testUnit package testUnit
import ( import (
"goUpload/dbHelper" "goInOut/dbOperate"
"strconv" "strconv"
"testing" "testing"
"time" "time"
) )
func TestUDP_push(t *testing.T) { func TestUDP_push(t *testing.T) {
udp := dbHelper.UdpHelper{ udp := dbOperate.UdpHelper{
Host: "10.8.30.110", Host: "10.8.30.110",
Port: 8888, Port: 8888,
} }

80
testUnit/安心云http转发_test.go

@ -0,0 +1,80 @@
package testUnit
import (
"encoding/json"
"fmt"
"goInOut/models"
"goInOut/utils"
"testing"
"time"
)
// 定义一个结构体,包含嵌套的结构体字段
type Person struct {
Name Name `json:"name"`
}
type Name struct {
First string `json:"first"`
Last string `json:"last"`
}
func Test_httpProxy(t *testing.T) {
}
func Test_template(t *testing.T) {
// 创建一个Person实例
person := Person{
Name: Name{
First: "John",
Last: "Doe",
},
}
templateStr := "Hello, {{.Name.First}} !"
sbs, err := utils.TextTemplateMatch(person, templateStr)
println(sbs)
if err != nil {
fmt.Println(err.Error())
}
}
func Test_timeHandler(t *testing.T) {
rawMsg := `{
"userId": "ce2d7eb2-e56e-422e-8bbe-95dfa18e32f8",
"thingId": "14862308-083e-46e1-a422-d7d6a1e2825d",
"dimensionId": "47386f69-c5aa-4ae7-b6cc-0490a1dc0b14",
"dimCapId": "0d561c0b-4dca-4104-abc0-1f0c40a71382",
"capId": "d4965875-354b-4294-87f4-c4ba9f9260ab",
"deviceId": "9c43a09c-3c65-42d3-9a54-42b87e0e5af2",
"scheduleId": "1cfebf18-81a2-489e-bcfb-efc294d8ce3d",
"taskId": "b58858ed-9e23-4ac9-9f9c-44f9e057aee9",
"jobId": 1,
"jobRepeatId": 1,
"triggerTime": "2024-12-04T18:23:04+16:00",
"realTime": "0001-01-01T00:00:00Z",
"finishTime": "2024-12-04T10:23:07.909922675+08:00",
"seq": 0,
"released": false,
"data": {
"type": 1,
"data": {
"physicalvalue": 0
},
"result": {
"code": 0,
"msg": "",
"detail": null,
"errTimes": 0,
"dropped": false
}
}
}`
iotaData := models.IotaData{}
json.Unmarshal([]byte(rawMsg), &iotaData)
var cstZone = time.FixedZone("CST", 8*3600) // 东八区
time := iotaData.TriggerTime.In(cstZone).Format("2006-01-02T15:04:05.000+0800")
println(time)
}

82
testUnit/江苏智感测试_test.go

File diff suppressed because one or more lines are too long

2
testUnit/湘潭监测测试_test.go

@ -1,7 +1,7 @@
package testUnit package testUnit
import ( import (
"goUpload/adaptors" "goInOut/adaptors"
"log" "log"
"testing" "testing"
) )

53
utils/cacheFile.go

@ -0,0 +1,53 @@
package utils
import (
"fmt"
"log"
"os"
)
func SaveCache2File(cacheStr string, fileName string) error {
// 打开文件,如果文件不存在则创建
file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
log.Println("Error opening file:", err)
return err
}
defer file.Close()
// 将变量写入文件
_, err = file.WriteString(cacheStr)
if err != nil {
log.Println("Error writing to file:", err)
}
return err
}
func ReadCache2File(fileName string) (string, error) {
// 打开文件
file, err := os.Open(fileName)
if err != nil {
log.Println("Error opening file:", err)
return "", err
}
defer file.Close()
// 读取文件内容
var content string
_, err = fmt.Fscanf(file, "%s", &content)
if err != nil {
log.Println("Error reading from file:", err)
}
return content, err
}
func FileExists(filePath string) bool {
_, err := os.Stat(filePath)
if err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}

22
utils/textTemplateHandler.go

@ -0,0 +1,22 @@
package utils
import (
"strings"
"text/template"
)
func TextTemplateMatch(obj any, textTemplate string) (string, error) {
// 定义模板字符串
tmpl, err := template.New("template").Parse(textTemplate)
if err != nil {
panic(err)
}
sb := strings.Builder{}
err = tmpl.Execute(&sb, obj)
if err != nil {
return "", err
}
sbs := sb.String()
return sbs, err
}

2
utils/valueHelper.go

@ -41,6 +41,6 @@ func LimitStringLength(s string, maxLength int) string {
func Float32ToBytes(float float32) []byte { func Float32ToBytes(float float32) []byte {
bits := math.Float32bits(float) bits := math.Float32bits(float)
bytes := make([]byte, 4) bytes := make([]byte, 4)
binary.LittleEndian.PutUint32(bytes, bits) binary.BigEndian.PutUint32(bytes, bits)
return bytes return bytes
} }

Loading…
Cancel
Save