Browse Source

增加广东矿山上报单独的consumer

dev
zhangyuxiang 19 hours ago
parent
commit
63eb91e2af
  1. 285
      adaptors/安心云es主题to广东矿山监测.go
  2. 32
      configFiles/config_广州大宝山_广东矿山_大宝山矿业.json
  3. 26
      consumers/consumerCDJYSN.go
  4. 229
      consumers/consumerGDKS.go
  5. 3
      consumers/consumerManage.go
  6. 8
      consumers/consumerZWYHBJCAS.go

285
adaptors/安心云es主题to广东矿山监测.go

@ -0,0 +1,285 @@
package adaptors
import (
"encoding/json"
"fmt"
"goInOut/models"
"log"
"math"
"strings"
"time"
)
// Adaptor_AXYES_GDKS
type Adaptor_AXYES_GDKS struct {
//传感器code转换信息
GnssMap map[string]string
RainMap map[string]string
NBWYMap map[string]string
DXSWMap map[string]string
//一些必要信息
Info map[string]string
}
func (the Adaptor_AXYES_GDKS) Transform(rawMsg string) []byte {
esAggTop := models.EsAggTop{}
err := json.Unmarshal([]byte(rawMsg), &esAggTop)
if err != nil {
return nil
}
return the.EsAggTopToGDKS(esAggTop)
}
func (the Adaptor_AXYES_GDKS) EsAggTopToGDKS(esAggTop models.EsAggTop) (result []byte) {
//var transBytes []byte
fileContent := strings.Builder{}
//写入文本内容的固定头
contentHeader := the.getContentHeader()
fileContent.WriteString(contentHeader)
for _, bucket := range esAggTop.Aggregations.SensorId.Buckets {
for _, hit := range bucket.Last.Hits.Hits {
source := hit.Source
sensorContentTemplate := the.getTemplateStr(source)
sensorContentObj := the.getTemplateObj(source)
if len(sensorContentObj) == 0 {
continue
}
txt, err := templateWork(sensorContentTemplate, sensorContentObj)
if err != nil {
log.Printf("传感器[%s]数据生成出现异常,err=%s", source.SensorName, err.Error())
continue
}
fileContent.WriteString(txt)
}
}
//单个文本文件用“]]]”表示结束
fileContent.WriteString("]]]")
return []byte(fileContent.String())
}
func (the Adaptor_AXYES_GDKS) getTemplateStr(sensorData models.Source) string {
templateStr := ""
switch sensorData.Factor {
case models.AXY_FactorType_BMWY:
templateStr = "{{.structUploadCode}}{{.sensorType}}{{.sensorCode}};{{.sensorType}};{{.sensorName}};{{.longitude}};{{.latitude}};{{.height}};" +
"{{.x}}|{{.y}}|{{.z}}||||{{.xAcc}}|{{.yAcc}}|{{.zAcc}};{{.unit}};{{.state}};{{.time}}^"
case models.AXY_FactorType_Rain_New:
templateStr = "{{.structUploadCode}}{{.sensorType}}{{.sensorCode}};{{.sensorType}};{{.sensorName}};{{.longitude}};{{.latitude}};{{.height}};" +
"{{.totrainfall}};{{.unit}};{{.state}};{{.time}}^"
case models.AXY_FactorType_SBSPWY:
templateStr = "{{.structUploadCode}}{{.sensorType}}{{.sensorCode}};{{.sensorType}};{{.sensorName}};{{.longitude}};{{.latitude}};{{.height}};" +
"{{.x}}|{{.y}};{{.unit}};{{.state}};{{.time}}^"
case models.AXY_FactorType_DXSW:
templateStr = "{{.structUploadCode}}{{.sensorType}}{{.sensorCode}};{{.sensorType}};{{.sensorName}};{{.longitude}};{{.latitude}};{{.height}};" +
"{{.waterLevel}};{{.unit}};{{.state}};{{.time}}^"
}
return templateStr
}
// 广东矿山GNSS 表面唯一缓存,用于单次变化量
var cacheGDKS = make(map[string]float64)
func (the Adaptor_AXYES_GDKS) getTemplateObj(sensorData models.Source) map[string]string {
templateMap := make(map[string]string)
sensorCode, sensorType := the.getSensorCodeAndType(sensorData)
if sensorCode == "" {
return templateMap
}
for k, v := range the.Info {
templateMap[k] = v
}
templateMap["sensorCode"] = sensorCode
templateMap["sensorType"] = sensorType
templateMap["sensorName"] = sensorData.SensorName
longitude, latitude, height := the.getJWDbySensorName(sensorData)
templateMap["longitude"] = longitude
templateMap["latitude"] = latitude
templateMap["height"] = height
templateMap["state"] = "00000000"
templateMap["time"] = sensorData.CollectTime.Add(8 * time.Hour).Format("2006-01-02 15:04:05")
switch sensorData.Factor {
case models.AXY_FactorType_BMWY:
//templateMap["x"] = fmt.Sprintf("%.3f", sensorData.Data["x"])
//templateMap["y"] = fmt.Sprintf("%.3f", sensorData.Data["y"])
//templateMap["z"] = fmt.Sprintf("%.3f", sensorData.Data["z"])
templateMap["xAcc"] = "0"
templateMap["yAcc"] = "0"
templateMap["zAcc"] = "0"
xAcc := 0.0
yAcc := 0.0
zAcc := 0.0
cacheKey_x := fmt.Sprintf("%s_x", sensorData.SensorName)
cacheKey_y := fmt.Sprintf("%s_y", sensorData.SensorName)
cacheKey_z := fmt.Sprintf("%s_z", sensorData.SensorName)
xLast, isHave := cacheGDKS[cacheKey_x]
if isHave {
log.Printf("[%s]上次值 xLast=%.3f", sensorData.SensorName, xLast)
xAcc = sensorData.Data["x"] - xLast
}
yLast, isHave := cacheGDKS[cacheKey_y]
if isHave {
log.Printf("[%s]上次值 yLast=%.3f", sensorData.SensorName, yLast)
yAcc = sensorData.Data["y"] - yLast
}
zLast, isHave := cacheGDKS[cacheKey_z]
if isHave {
log.Printf("[%s]上次值 zLast=%.3f", sensorData.SensorName, zLast)
zAcc = sensorData.Data["z"] - zLast
}
templateMap["x"] = fmt.Sprintf("%.3f", xAcc)
templateMap["y"] = fmt.Sprintf("%.3f", yAcc)
templateMap["z"] = fmt.Sprintf("%.3f", zAcc)
templateMap["unit"] = "mm"
cacheGDKS[cacheKey_x] = sensorData.Data["x"]
cacheGDKS[cacheKey_y] = sensorData.Data["y"]
cacheGDKS[cacheKey_z] = sensorData.Data["z"]
case models.AXY_FactorType_SBSPWY:
templateMap["x"] = fmt.Sprintf("%.3f", sensorData.Data["x"])
templateMap["y"] = fmt.Sprintf("%.3f", sensorData.Data["y"])
templateMap["unit"] = "mm"
case models.AXY_FactorType_Rain_New:
templateMap["totrainfall"] = fmt.Sprintf("%.3f", sensorData.Data["totrainfall"])
templateMap["unit"] = "mm"
case models.AXY_FactorType_DXSW:
templateMap["waterLevel"] = fmt.Sprintf("%.3f", sensorData.Data["waterLevel"])
templateMap["unit"] = "m"
}
return templateMap
}
func (the Adaptor_AXYES_GDKS) getStructureId() string {
structureId, ok := the.Info["structureId"]
if !ok {
log.Panic("配置文件info中 无structureId")
}
return structureId
}
func (the Adaptor_AXYES_GDKS) getJWDbySensorName(sensorData models.Source) (longitude, latitude, height string) {
switch sensorData.Factor {
case models.AXY_FactorType_BMWY:
v, isValid := the.GnssMap[sensorData.SensorName]
if !isValid {
return
}
codeArr := strings.Split(v, ";")
if len(codeArr) != 4 {
return
}
longitude = codeArr[1]
latitude = codeArr[2]
height = codeArr[3]
case models.AXY_FactorType_Rain_New:
case models.AXY_FactorType_SBSPWY:
case models.AXY_FactorType_DXSW:
}
return
}
func (the Adaptor_AXYES_GDKS) getSensorCodeAndType(sensorData models.Source) (code, typeCode string) {
switch sensorData.Factor {
case models.AXY_FactorType_BMWY:
typeCode = "2001"
v, isValid := the.GnssMap[sensorData.SensorName]
if !isValid {
return
}
codeArr := strings.Split(v, ";")
code = codeArr[0]
case models.AXY_FactorType_Rain_New:
typeCode = "0030"
v, isValid := the.RainMap[sensorData.SensorName]
if !isValid {
code = ""
}
code = v
case models.AXY_FactorType_SBSPWY:
typeCode = "2002"
v, isValid := the.NBWYMap[sensorData.SensorName]
if !isValid {
code = ""
}
code = v
case models.AXY_FactorType_DXSW:
typeCode = "2302"
v, isValid := the.DXSWMap[sensorData.SensorName]
if !isValid {
code = ""
}
code = v
}
return
}
func (the Adaptor_AXYES_GDKS) getTimeBytes(sensorTime time.Time) []byte {
year := int8(sensorTime.Year() - 1900)
month := int8(sensorTime.Month())
day := int8(sensorTime.Day())
hour := int8(sensorTime.Hour())
minute := int8(sensorTime.Minute())
millisecond := uint16(sensorTime.Second()*1000 + sensorTime.Nanosecond()/1e6)
bytes := make([]byte, 0)
bytes = append(bytes,
byte(year),
byte(month),
byte(day),
byte(hour),
byte(minute),
byte(millisecond&0xFF),
byte(millisecond>>8),
)
return bytes
}
func (the Adaptor_AXYES_GDKS) getDatasBytes(datas []float32) []byte {
bytes := make([]byte, 0)
for _, data := range datas {
bits := math.Float32bits(data)
bytes = append(bytes,
byte(bits&0xFF),
byte(bits>>8&0xFF),
byte(bits>>16&0xFF),
byte(bits>>24&0xFF),
)
}
return bytes
}
// 实时数据文件
func (the Adaptor_AXYES_GDKS) getContentHeader() string {
header := the.Info["fileContentHeader"]
//数据上传时间
timeNow := time.Now().Format("2006-01-02 15:04:05")
header += fmt.Sprintf("%s^", timeNow)
return header
}
// 测点信息文件
func (the Adaptor_AXYES_GDKS) getInfoContentHeader() string {
header := the.Info["fileContentHeader"]
//安标有效期
vaildDate := "2026-12-30"
//数据上传时间
timeNow := time.Now().Format("2006-01-02 15:04:05")
header += fmt.Sprintf("%s;%s^", vaildDate, timeNow)
return header
}

32
configFiles/config_广州大宝山_广东矿山_大宝山矿业.json

@ -1,15 +1,15 @@
{
"consumer": "consumerCDJYSN",
"consumer": "consumerGDKS",
"ioConfig": {
"in": {
"http": {
"url": "https://esproxy.anxinyun.cn/anxincloud_themes/_search"
},
"cronStr": "48 0/1 * * *"
"cronStr": "38 0/1 * * *"
},
"out": {
"file": {
"directory": "G:\\工作记录\\每月任务需求\\202402需求\\河北矿山数据本地数据工具开发\\saveTxts2",
"directory": "E:\\01资料\\设备\\2025-12-11 数据上报\\dabaoshan",
"fileNameExtension": ".txt"
}
}
@ -21,19 +21,19 @@
"fileContentHeader": "440205005001;广东省大宝山矿业有限公司李屋排土场;"
},
"sensorMap": {
"NBWYSensorMap": {
"757_G1":"100011",
"757_G2":"100012",
"757_G3":"100021",
"757_G4":"100022",
"757_G5":"100031",
"757_G6":"100032",
"681_G1":"100071",
"681_G2":"100041",
"681_G3":"100042",
"625_G1":"100043",
"625_G2":"100051",
"625_G3":"100052"
"GnssSensorMap": {
"757_G1":"100011;113.71655000;24.55281252;767",
"757_G2":"100012;113.71533904;24.55295121;767",
"757_G3":"100021;113.71460937;24.55365389;767",
"757_G4":"100022;113.71425361;24.55447242;767",
"757_G5":"100031;113.71396365;24.55502772;767",
"757_G6":"100032;113.71318562;24.55588272;767",
"681_G1":"100071;113.71450034;24.55077052;681",
"681_G2":"100041;113.71363350;24.55145886;681",
"681_G3":"100042;113.71295301;24.55210073;681",
"625_G1":"100043;113.71642567;24.54860382;633",
"625_G2":"100051;113.71498554;24.54938638;633",
"625_G3":"100052;113.71398753;24.54990754;633"
}
}
}

26
consumers/consumerCDJYSN.go

@ -3,7 +3,6 @@ package consumers
import (
"encoding/json"
"fmt"
"github.com/robfig/cron/v3"
"goInOut/adaptors"
"goInOut/consumers/CDJYSN"
"goInOut/dbOperate"
@ -12,6 +11,8 @@ import (
"log"
"path"
"time"
"github.com/robfig/cron/v3"
)
type consumerCDJYSN struct {
@ -234,29 +235,6 @@ func (the *consumerCDJYSN) saveConfig() {
"^]]]"
contentConfig = contentConfigHead + contentConfigBody
}
case "3381": //广东省大宝山矿业有限公司李屋排土场在线监测
contentConfigHead := the.ConfigInfo.Info["fileContentHeader"] + //非煤矿山编码 440205005001,边坡名称
"LZJDBPJC;" + //系统型号
"广东省大宝山矿业有限公司李屋排土场在线监测系统;" + //系统名称
"广东省大宝山矿业有限公司;" + //生产厂家名称
"2030-12-30;" + //安标有效期
"2025-12-22 15:00:00" //数据上传时间
contentConfigBody := "" +
//测点编码;测点名称;系统编码;露天矿山编码;边坡编号;传感器类型;测点数值类型;测点数值单位;埋深;一级阈值;二级阈值;三级阈值;四级阈值;测点安装位置;位置X;位置Y;位置Z;安装日期;生产厂家;量程;在用状态;故障状态;数据时间
"^44020500500102100011;757_G1;01;440205005001;0201;02;;mm;;;;;;排土场;113.71655000;24.55281252;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100012;757_G2;01;440205005001;0201;02;;mm;;;;;;排土场;113.71533904;24.55295121;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100021;757_G3;01;440205005001;0201;02;;mm;;;;;;排土场;113.71460937;24.55365389;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100022;757_G4;01;440205005001;0201;02;;mm;;;;;;排土场;113.71425361;24.55447242;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100031;757_G5;01;440205005001;0201;02;;mm;;;;;;排土场;113.71396365;24.55502772;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100032;757_G6;01;440205005001;0201;02;;mm;;;;;;排土场;113.71318562;24.55588272;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100071;681_G1;01;440205005001;0201;02;;mm;;;;;;排土场;113.71450034;24.55077052;681;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100041;681_G2;01;440205005001;0201;02;;mm;;;;;;排土场;113.71363350;24.55145886;681;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100042;681_G3;01;440205005001;0201;02;;mm;;;;;;排土场;113.71295301;24.55210073;681;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100043;625_G1;01;440205005001;0201;02;;mm;;;;;;排土场;113.71642567;24.54860382;633;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100051;625_G2;01;440205005001;0201;02;;mm;;;;;;排土场;113.71498554;24.54938638;633;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100052;625_G3;01;440205005001;0201;02;;mm;;;;;;排土场;113.71398753;24.54990754;633;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^]]]"
contentConfig = contentConfigHead + contentConfigBody
}
fileName := fmt.Sprintf("%s_LTCDJC_%s.txt", the.ConfigInfo.Info["structUploadCode"], time.Now().Format("20060102150405"))
filePath := path.Join(the.ConfigInfo.IoConfig.Out.File.Directory, fileName)

229
consumers/consumerGDKS.go

@ -0,0 +1,229 @@
package consumers
import (
"encoding/json"
"fmt"
"goInOut/adaptors"
"goInOut/consumers/CDJYSN"
"goInOut/dbOperate"
"goInOut/monitors"
"goInOut/utils"
"log"
"path"
"time"
"github.com/robfig/cron/v3"
)
type consumerGDKS struct {
//数据缓存管道
dataCache chan []byte
//具体配置
ConfigInfo CDJYSN.ConfigFile
//InHttp *dbOperate.HttpHelper
OutFile *dbOperate.FileSaveHelper
InHttp monitors.HttpMonitor
configCron *cron.Cron
}
func (the *consumerGDKS) 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 *consumerGDKS) Initial(cfg string) error {
the.LoadConfigJson(cfg)
err := the.InputInitial()
if err != nil {
return err
}
err = the.OutputInitial()
return err
}
func (the *consumerGDKS) InputInitial() error {
the.dataCache = make(chan []byte, 200)
//数据入口
the.InHttp = monitors.HttpMonitor{
HttpClient: &dbOperate.HttpHelper{Url: the.ConfigInfo.IoConfig.In.Http.Url, Token: ""},
MonitorHelper: &monitors.MonitorHelper{CronStr: the.ConfigInfo.IoConfig.In.CronStr},
}
the.InHttp.Start()
the.InHttp.RegisterTask(the.ConfigInfo.IoConfig.In.CronStr, the.getEsData)
return nil
}
func (the *consumerGDKS) OutputInitial() error {
//数据出口
the.OutFile = &dbOperate.FileSaveHelper{
Directory: the.ConfigInfo.IoConfig.Out.File.Directory,
FilenameExtension: the.ConfigInfo.IoConfig.Out.File.FileNameExtension,
}
the.OutFile.Initial()
return nil
}
func (the *consumerGDKS) Work() {
//每次启动生成测点配置文件
the.saveConfig()
the.configCron = cron.New()
the.configCron.AddFunc("10 12 * * *", func() {
log.Println("执行每天刷新传感器基础配置任务:")
the.saveConfig()
})
go func() {
for {
pushBytes := <-the.dataCache
log.Printf("取出ch数据,剩余[%d] ", len(the.dataCache))
log.Printf("推送[%v]: len=%d", the.OutFile.Directory, len(pushBytes))
//hex.EncodeToString(pushBytes)
//非煤矿山编码_文件分类_时间.txt
fileName := fmt.Sprintf("%s_%s.txt", the.ConfigInfo.Info["fileNamePrefix"], time.Now().Format("20060102150405"))
filePath := path.Join(the.ConfigInfo.IoConfig.Out.File.Directory, fileName)
the.OutFile.Save(filePath, string(pushBytes))
time.Sleep(10 * time.Millisecond)
}
}()
}
func (the *consumerGDKS) getStructureId() string {
structureId, ok := the.ConfigInfo.Info["structureId"]
if !ok {
structureId = "3381"
}
return structureId
}
func (the *consumerGDKS) saveConfig() {
//130731030001;涿鹿金隅水泥大斜阳矿山;DXYKSJC;涿鹿金隅水泥大斜阳矿山安全监测;承德金隅水泥有限公司;2030-12-30;2024-02-06 11:39:02^13073103000103200001;雨量;01;130731030001;0101;03;;mm;;100;90;80;70;采场;115.244209;40.123344;1217;2020-07-01;武汉新普惠;4;1;0;2024-02-06 10:55:45^13073103000102100001;JC01;01;130731030001;0101;02;;mm;;100;90;80;70;排土1297平台;115.243554;40.114834;1297;2020-07-01;江西飞尚科技;1000;1;0;2024-02-06 10:55:45^13073103000102100002;JC02;01;130731030001;0101;02;;mm;;100;90;80;70;边坡1317平台;115.241985;40.115445;1317;2020-07-01;江西飞尚科技;1000;1;0;2024-02-06 10:55:45^13073103000102100003;JC03;01;130731030001;0101;02;;mm;;100;90;80;70;边坡1317平台;115.241080;40.115698;1317;2020-07-01;江西飞尚科技;1000;1;0;2024-02-06 10:55:45^]]]
//"structUploadCode": "130731030001",
//"fileNamePrefix": "130731030001_LTCDSS",
//"fileContentHeader": "130731030001;涿鹿金隅水泥大斜阳矿山;"
structureId := the.getStructureId()
contentConfig := ""
switch structureId {
case "3381": //广东省大宝山矿业有限公司李屋排土场在线监测
contentConfigHead := the.ConfigInfo.Info["fileContentHeader"] + //非煤矿山编码 440205005001,边坡名称
"LZJDBPJC;" + //系统型号
"广东省大宝山矿业有限公司李屋排土场在线监测系统;" + //系统名称
"广东省大宝山矿业有限公司;" + //生产厂家名称
"2030-12-30;" + //安标有效期
"2025-12-22 15:00:00" //数据上传时间
contentConfigBody := "" +
//测点编码;测点名称;系统编码;露天矿山编码;边坡编号;传感器类型;测点数值类型;测点数值单位;埋深;一级阈值;二级阈值;三级阈值;四级阈值;测点安装位置;位置X;位置Y;位置Z;安装日期;生产厂家;量程;在用状态;故障状态;数据时间
"^44020500500102100011;757_G1;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71655000;24.55281252;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100012;757_G2;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71533904;24.55295121;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100021;757_G3;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71460937;24.55365389;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100022;757_G4;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71425361;24.55447242;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100031;757_G5;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71396365;24.55502772;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100032;757_G6;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71318562;24.55588272;767;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100071;681_G1;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71450034;24.55077052;681;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100041;681_G2;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71363350;24.55145886;681;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100042;681_G3;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71295301;24.55210073;681;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100043;625_G1;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71642567;24.54860382;633;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100051;625_G2;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71498554;24.54938638;633;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^44020500500102100052;625_G3;01;440205005001;0201;2001;;mm;;;;;;排土场;113.71398753;24.54990754;633;2023-05-01;司南导航;15;1;0;2025-12-22 10:00:00" +
"^]]]"
contentConfig = contentConfigHead + contentConfigBody
}
fileName := fmt.Sprintf("%s_LTCDJC_%s.txt", the.ConfigInfo.Info["structUploadCode"], time.Now().Format("20060102150405"))
filePath := path.Join(the.ConfigInfo.IoConfig.Out.File.Directory, fileName)
the.OutFile.Save(filePath, contentConfig)
}
func (the *consumerGDKS) getEsData() {
structureId := the.getStructureId()
start, end := utils.GetTimeRangeByHour(-1)
log.Printf("查询数据时间范围 %s - %s", start, end)
//start := "2024-02-05T00:00:00.000+0800"
//end := "2024-02-05T23:59:59.999+0800"
esQuery := fmt.Sprintf(`
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"term": {
"structure": {
"value": %s
}
}
},
{
"range": {
"collect_time": {
"from": "%s",
"to": "%s"
}
}
}
]
}
},
"sort": [
{
"collect_time": {
"order": "desc"
}
}
],
"aggs": {
"gpBySensorId": {
"terms": {
"field": "sensor",
"size": 60
},
"aggs": {
"last": {
"top_hits": {
"size": 1,
"sort": [
{
"collect_time": {
"order": "desc"
}
}
]
}
}
}
}
}
}
`, structureId, start, end)
auth := map[string]string{"Authorization": "Bear 85a441d4-022b-4613-abba-aaa8e2693bf7"}
esAggResult := the.InHttp.HttpClient.HttpGetWithHeader(esQuery, auth)
var needPush []byte
adaptor := the.getAdaptor()
if adaptor != nil {
needPush = adaptor.Transform(esAggResult)
if len(needPush) > 0 {
the.dataCache <- needPush
}
}
}
func (the *consumerGDKS) getAdaptor() (adaptor adaptors.IAdaptor) {
//maps.Copy(the.ConfigInfo.SensorMap.GnssSensorMap, the.ConfigInfo.SensorMap.RainSensorMap)
return adaptors.Adaptor_AXYES_GDKS{
GnssMap: the.ConfigInfo.SensorMap.GnssSensorMap,
RainMap: the.ConfigInfo.SensorMap.RainSensorMap,
NBWYMap: the.ConfigInfo.SensorMap.NBWYSensorMap,
Info: the.ConfigInfo.Info,
}
}
// 获取 内部位移安装位置
func (the *consumerGDKS) getNBWYLocation(pointCode string) string {
platformCode := pointCode[:3]
location := fmt.Sprintf("排土%s平台", platformCode)
return location
}

3
consumers/consumerManage.go

@ -14,6 +14,9 @@ func GetConsumer(name string) (consumer IConsumer) {
case "consumerCDJYSN": //明月峡
consumer = new(consumerCDJYSN)
case "consumerGDKS": //广东矿山
consumer = new(consumerGDKS)
case "consumerWJHP": //魏家滑坡-视觉位移(光电扰度)
consumer = new(consumerWJHP)

8
consumers/consumerZWYHBJCAS.go

@ -7,8 +7,11 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/google/uuid"
"github.com/tjfoc/gmsm/sm3"
"gopkg.in/yaml.v3"
"goInOut/adaptors"
"goInOut/consumers/HBJCAS"
"goInOut/dbOperate"
@ -16,7 +19,6 @@ import (
"goInOut/models"
"goInOut/monitors"
"goInOut/utils"
"gopkg.in/yaml.v3"
"io"
"io/ioutil"
"log"
@ -367,7 +369,7 @@ func (the *consumerZWYHBJCAS) getStructureId() string {
return structureId
}
//获取配置在yaml文件中的cameraInfo对应的摄像机的状态
// 获取配置在yaml文件中的cameraInfo对应的摄像机的状态
func (the *consumerZWYHBJCAS) getCameraStatus() []interface{} {
cameraArr := the.Info.CameraInfo
cameras := make([]interface{}, 0)
@ -382,7 +384,7 @@ func (the *consumerZWYHBJCAS) getCameraStatus() []interface{} {
return cameras
}
//获取配置在yaml文件中的codeInfo对应的需要上报健康度的(桥梁|隧道|边坡)的健康度
// 获取配置在yaml文件中的codeInfo对应的需要上报健康度的(桥梁|隧道|边坡)的健康度
func (the *consumerZWYHBJCAS) getCodeStatus() []interface{} {
infoArr := the.Info.CodeInfo
res := make([]interface{}, 0)

Loading…
Cancel
Save