package gate_command import ( "context" "fmt" "git.getensh.com/common/gopkgs/database" "property-device/errors" dbmodel "property-device/model" "property-device/pb" pb_v1 "property-device/pb/v1" "property-device/utils/gate_utils" "time" ) type SaiboMqttv1Commander struct { GateInfo *dbmodel.TGate } func (p *SaiboMqttv1Commander) Open() error { now := time.Now() tgc := &dbmodel.TGateCommand{ CreatedAt: now, UpdatedAt: now, DeviceId: p.GateInfo.ID, //Param: req.CmdParams, Desc: gate_utils.CommandCodeMap[gate_utils.OpenCommand], Status: gate_utils.CommandStatusRuning, ResultStatus: 0, ResultStatusDesc: "", Code: gate_utils.OpenCommand, } db := database.DB().Begin() err := tgc.Insert(db) if err != nil { db.Rollback() return errors.DataBaseError } mreq := pb_v1.FaceOpenRequest{Sn: p.GateInfo.Sn, CmdId: fmt.Sprintf("%d", tgc.ID)} _, err = pb.Mqtt.FaceOpen(context.Background(), &mreq) if err != nil { db.Rollback() return err } db.Commit() return nil } func (p *SaiboMqttv1Commander) Reboot() error { now := time.Now() tgc := &dbmodel.TGateCommand{ CreatedAt: now, UpdatedAt: now, DeviceId: p.GateInfo.ID, //Param: req.CmdParams, Desc: gate_utils.CommandCodeMap[gate_utils.RebootCommand], Status: gate_utils.CommandStatusRuning, ResultStatus: 0, ResultStatusDesc: "", Code: gate_utils.RebootCommand, } db := database.DB().Begin() err := tgc.Insert(db) if err != nil { db.Rollback() return errors.DataBaseError } mreq := pb_v1.FaceRebootRequest{Sn: p.GateInfo.Sn, CmdId: fmt.Sprintf("%d", tgc.ID)} _, err = pb.Mqtt.FaceReboot(context.Background(), &mreq) if err != nil { db.Rollback() return err } db.Commit() return nil } func (p *SaiboMqttv1Commander) Command() bool { return false }