소스 검색

fix:优化权限控制

Jerry Liang 5 달 전
부모
커밋
a78585c5aa
2개의 변경된 파일과 98개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      service/main.go
  2. 97 0
      service/repositories/mqtt/fwh_mqtt/fwh_mqtt_fault_record.go

+ 1 - 0
service/main.go

@@ -63,6 +63,7 @@ func main() {
 
 	// 初始化FWH MQTT客户端
 	repositories.FwhMqttInit(&cfg.FwhMqtt)
+	// repositories.FwhMqttFaultRecordChargeChannel(context.Background(), "10060005A03X25160385")
 
 	app := fiber.New()
 	app.Use(func(c *fiber.Ctx) error {

+ 97 - 0
service/repositories/mqtt/fwh_mqtt/fwh_mqtt_fault_record.go

@@ -0,0 +1,97 @@
+// fault record 故障录波请求
+package fwh_mqtt
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	"hash/crc32"
+	"strings"
+	"time"
+)
+
+type FaultRecordParaListItem struct {
+	Id     int    `json:"id"`
+	SetVal string `json:"setVal"`
+}
+
+type FaultRecordInfoItem struct {
+	Sn       string                    `json:"sn"` // aPower SN
+	ParaList []FaultRecordParaListItem `json:"paraList"`
+}
+
+type FaultRecordListItem struct {
+	Type string                `json:"type"`
+	Info []FaultRecordInfoItem `json:"info"`
+}
+
+type FaultRecordData struct {
+	List []FaultRecordListItem `json:"list"`
+}
+
+type FaultRecordDataArea struct {
+	Cmd  int             `json:"cmd"`
+	Data FaultRecordData `json:"data"`
+}
+
+type FaultRecordChannelConfig struct {
+	Sn       string                    `json:"sn"` // aPower SN
+	ParaList []FaultRecordParaListItem `json:"paraList"`
+}
+
+func ChargeChannel(ctx context.Context, sn string) error {
+	dataArea := map[string]interface{}{
+		"cmd": 1,
+		"data": map[string]interface{}{
+			"list": []interface{}{
+				map[string]interface{}{
+					"type": "pe",
+					"info": []interface{}{
+						map[string]interface{}{
+							"sn": "10050015A00X25070634",
+							"paraList": []interface{}{
+								map[string]interface{}{
+									"id":     6,
+									"setVal": "010300014252",
+								},
+								map[string]interface{}{
+									"id":     6,
+									"setVal": "020100014C14",
+								},
+								map[string]interface{}{
+									"id":     6,
+									"setVal": "030100013102",
+								},
+								map[string]interface{}{
+									"id":     6,
+									"setVal": "040100013103",
+								},
+							},
+						},
+					},
+				},
+			},
+		},
+	}
+
+	dataStr, err := json.Marshal(dataArea)
+	if err != nil {
+		return err
+	}
+
+	err = fwhMqttClient.sendMessageOnce(ctx, "fwh/s2c/mng/"+sn, FwhMqttMsg{
+		CmdType:   377, // 故障录波请求
+		Type:      0,   // IBG
+		Snno:      123,
+		TimeStamp: time.Now().Unix(),
+		EquipNo:   sn,
+		DataArea:  dataArea,
+		Len:       len(dataStr),
+		Crc:       strings.ToUpper(fmt.Sprintf("%08X", crc32.ChecksumIEEE(dataStr))),
+	})
+	if err != nil {
+		return err
+	}
+
+	return nil
+}