package mqtt_device import ( "context" "encoding/json" "fmt" "git.getensh.com/common/gopkgs/database" "git.getensh.com/common/gopkgs/logger" "go.uber.org/zap" "google.golang.org/grpc/status" dbmodel "property-device/model" pb_v1 "property-device/pb/v1" "property-device/utils/gate_utils" ) func MqttFaceGate(ctx context.Context, req *pb_v1.MqttFaceGateRequest) (reply *pb_v1.MqttFaceGateReply, err error) { reply = &pb_v1.MqttFaceGateReply{} // 捕获各个task中的异常并返回给调用者 defer func() { if r := recover(); r != nil { err = fmt.Errorf("%+v", r) e := &status.Status{} if er := json.Unmarshal([]byte(err.Error()), e); er != nil { logger.Error("err", zap.String("system_err", err.Error()), zap.Stack("stacktrace")) } } }() p := &dbmodel.TGate{} where := [][2]interface{}{} where = dbmodel.WhereAdd(where, "garden_id >", 1) where = dbmodel.WhereAdd(where, "protocol in", []int{gate_utils.GateProtocolSaiboMqttV1}) where = dbmodel.WhereAdd(where, "enable", 1) type IdObj struct { Sn string } ids := []IdObj{} err = p.SelectList(database.DB(), where, "sn", &ids) if err != nil { return nil, err } reply.Sns = make([]string, len(ids)) for i, v := range ids { reply.Sns[i] = v.Sn } return reply, nil }