diff --git a/adaptors/统一采集to江苏省农村公路桥梁监测.go b/adaptors/统一采集to江苏省农村公路桥梁监测.go index 2f3d612..87f0a1e 100644 --- a/adaptors/统一采集to江苏省农村公路桥梁监测.go +++ b/adaptors/统一采集to江苏省农村公路桥梁监测.go @@ -1,6 +1,8 @@ package adaptors import ( + "bytes" + "encoding/binary" "encoding/json" "fmt" "goInOut/models" @@ -31,9 +33,6 @@ func (the Adaptor_TYCJ_JSNCGLQL) TYCJtoJSNCGLQL(tycj models.TYCJ) (result []Need switch tycj.SensorData.FactorType { case models.TYCJ_FactorType_YLYB, models.TYCJ_FactorType_DTQYB: //应变23,挡土墙应变13 FS-BM50 sensorDataList = append(sensorDataList, tycj.SensorData.Data.ThemeValues[0]) - case models.TYCJ_FactorType_QDQX: //桥墩倾斜20 X (mm) Y (mm) - sensorDataList = append(sensorDataList, tycj.SensorData.Data.ThemeValues[0]) - sensorDataList = append(sensorDataList, tycj.SensorData.Data.ThemeValues[1]) default: log.Printf("监测因素[%d] 无匹配", tycj.SensorData.FactorType) return @@ -80,14 +79,12 @@ func (the Adaptor_TYCJ_JSNCGLQL) getTimeBytes(sensorTime time.Time) []byte { hour := int8(sensorTime.Hour()) minute := int8(sensorTime.Minute()) second := int8(sensorTime.Second()) - bytes := make([]byte, 0) - bytes = append(bytes, - byte(year), - byte(month), - byte(day), - byte(hour), - byte(minute), - byte(second), - ) - return bytes + 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() } diff --git a/config/init.go b/config/init.go index 7fda0ab..9281734 100644 --- a/config/init.go +++ b/config/init.go @@ -8,7 +8,6 @@ import ( ) func LoadConfigJson() map[string]string { - //加载目录下所有文件 allConfig := make(map[string]string) files, err := os.ReadDir("configFiles") diff --git a/dbHelper/_kafka/consumerGroupHandler.go b/dbHelper/_kafka/consumerGroupHandler.go index 45da072..e10a27f 100644 --- a/dbHelper/_kafka/consumerGroupHandler.go +++ b/dbHelper/_kafka/consumerGroupHandler.go @@ -82,7 +82,7 @@ func (h *ConsumerGroupHandler) Worker() { config := sarama.NewConfig() config.Consumer.Return.Errors = false config.Version = sarama.V2_0_0_0 - config.Consumer.Offsets.Initial = sarama.OffsetNewest + config.Consumer.Offsets.Initial = sarama.OffsetOldest config.Consumer.Offsets.AutoCommit.Enable = true config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategyRoundRobin()} group, err := sarama.NewConsumerGroup(h.brokers, h.groupId, config) diff --git a/dbHelper/httpHelper.go b/dbHelper/httpHelper.go index 7232434..2475293 100644 --- a/dbHelper/httpHelper.go +++ b/dbHelper/httpHelper.go @@ -49,6 +49,8 @@ func (the *HttpHelper) HttpGetWithHeader(queryBody string, headerMap map[string] for k, v := range headerMap { req.Header.Set(k, v) } + //取消证书校验,避免证书过期问题 + client.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} resp, err := client.Do(req) if err != nil { diff --git a/main_test.go b/main_test.go index 4f8c711..9e5ee23 100644 --- a/main_test.go +++ b/main_test.go @@ -4,7 +4,7 @@ import ( "bytes" "crypto/rc4" "encoding/hex" - "goUpload/utils" + "goInOut/utils" "log" "testing" "text/template" diff --git a/testUnit/mqttPush_test.go b/testUnit/mqttPush_test.go index 07c19a5..6f8e051 100644 --- a/testUnit/mqttPush_test.go +++ b/testUnit/mqttPush_test.go @@ -2,8 +2,8 @@ package testUnit import ( "encoding/hex" - "goUpload/consumers/CQZG/protoFiles" - "goUpload/dbHelper" + "goInOut/consumers/CQZG/protoFiles" + "goInOut/dbHelper" "google.golang.org/protobuf/proto" "log" "testing" diff --git a/testUnit/mqttRecv_test.go b/testUnit/mqttRecv_test.go index 590f977..5f97174 100644 --- a/testUnit/mqttRecv_test.go +++ b/testUnit/mqttRecv_test.go @@ -1,7 +1,7 @@ package testUnit import ( - "goUpload/dbHelper" + "goInOut/dbHelper" "log" "testing" "time" diff --git a/testUnit/udpPush_test.go b/testUnit/udpPush_test.go index a229867..8aa1e09 100644 --- a/testUnit/udpPush_test.go +++ b/testUnit/udpPush_test.go @@ -1,7 +1,7 @@ package testUnit import ( - "goUpload/dbHelper" + "goInOut/dbHelper" "strconv" "testing" "time" diff --git a/testUnit/江苏质感测试_test.go b/testUnit/江苏质感测试_test.go new file mode 100644 index 0000000..a2bad59 --- /dev/null +++ b/testUnit/江苏质感测试_test.go @@ -0,0 +1,47 @@ +package testUnit + +import ( + "goInOut/adaptors" + "log" + "testing" +) + +func Test_江苏质感_应变(t *testing.T) { + + Msg := ` +{ + "dtuInfo": { + "id": 0, + "code": "COM3" + }, + "sensorData": { + "id": 25, + "name": "m1c1", + "module": "1", + "channel": "1", + "factorType": 23, + "productCode": "MD-BM15", + "structId": 0, + "data": { + "RawValues": [ + 880.05609130859375, + 17.250148773193359, + 426.63839721679687 + ], + "ThemeValues": [ + 1.254 + ] + }, + "time": "2022-01-06T14:30:00.000" + } +} +` + adp := adaptors.Adaptor_TYCJ_JSNCGLQL{ + IdMap: map[string]string{ + "m1c1": "JY-HSD-G05-001-01", + "m1c2": "LHTDQ-RSG-L04-001-03", + }, + } + bytes := adp.Transform(Msg) + log.Println(bytes) +} diff --git a/testUnit/湘潭监测测试_test.go b/testUnit/湘潭监测测试_test.go index 67be7a3..b8c6ffa 100644 --- a/testUnit/湘潭监测测试_test.go +++ b/testUnit/湘潭监测测试_test.go @@ -1,7 +1,7 @@ package testUnit import ( - "goUpload/adaptors" + "goInOut/adaptors" "log" "testing" ) diff --git a/utils/valueHelper.go b/utils/valueHelper.go index 505bf80..aeefa3e 100644 --- a/utils/valueHelper.go +++ b/utils/valueHelper.go @@ -41,6 +41,6 @@ func LimitStringLength(s string, maxLength int) string { func Float32ToBytes(float float32) []byte { bits := math.Float32bits(float) bytes := make([]byte, 4) - binary.LittleEndian.PutUint32(bytes, bits) + binary.BigEndian.PutUint32(bytes, bits) return bytes }