package mqtt_utils import ( "fmt" "git.getensh.com/common/gopkgs/cache" "property-mqtt/utils" "time" ) const ( OpenCommand = 1 RebootCommand = 2 DownCommand = 3 DelCommand = 4 QueryCommand = 5 UpdatePicCommand = 6 AddPicCommand = 7 ) const ( GateProtocolSaiboHttpV1 = 1 GateProtocolSaiboMqttV1 = 2 GateProtocolYufanHttpV1 = 3 ) type CommandHandle func(commond string, res string) var CommandHandleMap = map[string]CommandHandle{ "EditPersonsNew-Ack": DownPersonCommandHandle, "RebootDevice-Ack": RebootCommandHandle, "Unlock-Ack": OpenCommandHandle, "DeletePersons-Ack": DelPersonCommandHandle, } const ( WaitMessagePrefix = "WaitFaceDevice_" // 部分命令需要得到响应后才能再次执行 WaitPrefex = "wait_face_common" ) func GenerateMsgId(faceId string) string { return fmt.Sprintf("%s-%d-%s", faceId, time.Now().Unix(), utils.GenerateRandomStr(10, "mix")) } func GenerateWaitKey(faceId string) string { return fmt.Sprintf("%s-%s", WaitPrefex, faceId) } // func Wait(faceid string) bool { key := GenerateWaitKey(faceid) for i := 0; i < 15; i++ { ret, err := cache.Redis().SetNxEx(key, 1, 5) if err != nil { return false } if ret { return ret } time.Sleep(1 * time.Second) } return false } func DelWait(faceid string) { key := GenerateWaitKey(faceid) cache.Redis().Del(key) }