| | |
| | | // 生成一个包含楼层的人脸id,解析楼层 |
| | | // 使用48位源id, 其中前41位是imageid, 不可以修改 41-43位填 06 代表图像, +99 + 3位楼层(第一位0表示正,1表示负) |
| | | func GenerateFaceIdContainFloor(srcId, floorStr string) string { |
| | | floorNum, _ := parseFloor(floorStr) |
| | | floorNum, _ := ParseFloor(floorStr) |
| | | newId := srcId[0:43] + "99" + floorNum |
| | | //newId := srcId[0:43] + "99" + floorNum + snowflake.CreateRandomNumber(1) |
| | | |
| | |
| | | return "", fmt.Errorf("invalid flag %s", srcId[43:45]) |
| | | } |
| | | |
| | | return restoreFloor(srcId[45:48]) |
| | | return RestoreFloor(srcId[45:48]) |
| | | } |
| | | |
| | | // parseFloor parses the floor string and returns a three-character string |
| | | func parseFloor(floor string) (string, error) { |
| | | // ParseFloor parses the floor string and returns a three-character string |
| | | func ParseFloor(floor string) (string, error) { |
| | | var sign string |
| | | var number string |
| | | |
| | |
| | | return sign + formattedNumber, nil |
| | | } |
| | | |
| | | // restoreFloor restores the three-character string back to the original floor string |
| | | func restoreFloor(encoded string) (string, error) { |
| | | // RestoreFloor restores the three-character string back to the original floor string |
| | | func RestoreFloor(encoded string) (string, error) { |
| | | if len(encoded) != 3 { |
| | | return "", fmt.Errorf("encoded string must be 3 characters long") |
| | | } |
| | |
| | | |
| | | // 处理梯控填写的楼层信息 暂时使用otherFeature字段 |
| | | if face.OtherFeature != "" { |
| | | pd.CameraFloor = face.OtherFeature |
| | | pd.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature) |
| | | } |
| | | |
| | | // 尝试从faceId提取楼层 |
| | |
| | | |
| | | func (c CaptureRepository) VIIDFaceMsgForward(msg *vo.RequestFaceList) { |
| | | faceInfo := msg.FaceListObject.FaceObject[0] |
| | | // 匹配楼层 |
| | | faceAppearTime, err := time.ParseInLocation("20060102150405", faceInfo.FaceAppearTime, time.Local) |
| | | if err != nil { |
| | | logger.Warn("Parse face appear time error, %s", err.Error()) |
| | | faceAppearTime = time.Now() |
| | | } |
| | | |
| | | var devPos models.Positions |
| | | _ = devPos.FindPositionByTime(faceAppearTime.Unix() + 5) // 加5秒电梯关门的时间 |
| | | if devPos.Pos == "" { |
| | | devPos.Pos = "1F" |
| | | } |
| | | |
| | | for idx, face := range msg.FaceListObject.FaceObject { |
| | | msg.FaceListObject.FaceObject[idx].OtherFeature = devPos.Pos |
| | | if config.ClientConf.AddFloorToFaceId { |
| | | msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos) |
| | | // 判断是否开启了梯控 |
| | | if config.NVCSConf.Model != "" { |
| | | // 匹配楼层 |
| | | faceAppearTime, err := time.ParseInLocation("20060102150405", faceInfo.FaceAppearTime, time.Local) |
| | | if err != nil { |
| | | logger.Warn("Parse face appear time error, %s", err.Error()) |
| | | faceAppearTime = time.Now() |
| | | } |
| | | |
| | | var devPos models.Positions |
| | | _ = devPos.FindPositionByTime(faceAppearTime.Unix() + 5) // 加5秒电梯关门的时间 |
| | | if devPos.Pos == "" { |
| | | devPos.Pos = "1F" |
| | | } |
| | | |
| | | for idx, face := range msg.FaceListObject.FaceObject { |
| | | msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.ParseFloor(devPos.Pos) |
| | | if config.ClientConf.AddFloorToFaceId { |
| | | msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos) |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | b, _ := json.Marshal(msg) |
| | |
| | | |
| | | var cacheMod models.Cache |
| | | total, _ := cacheMod.Count() |
| | | logger.Debug("Start resend task. cache len:%d", total) |
| | | if total == 0 { |
| | | return |
| | | } |
| | | |
| | | logger.Info("Start resend task. cache len:%d", total) |
| | | |
| | | for i := 0; i < int(total); i++ { |
| | | var c models.Cache |